From 2ef55a521966454b35e7a38d9cfc694607eea013 Mon Sep 17 00:00:00 2001 From: kdmukai Date: Mon, 12 Jul 2021 20:16:15 -0500 Subject: [PATCH] Hide image edges; improved QR template --- docs/qr_code_template.py | 67 ++++++++++++-- docs/qr_code_template_25x25.html | 71 ++++++++++++++- docs/qr_code_template_29x29.html | 110 ++++++++++++++++++++++- src/seedsigner/controller.py | 4 +- src/seedsigner/helpers/camera_process.py | 6 +- src/seedsigner/views/seed_tools_view.py | 22 ++++- src/seedsigner/views/view.py | 13 +-- 7 files changed, 269 insertions(+), 24 deletions(-) diff --git a/docs/qr_code_template.py b/docs/qr_code_template.py index a70916b4..0ddd092f 100644 --- a/docs/qr_code_template.py +++ b/docs/qr_code_template.py @@ -1,6 +1,13 @@ import math def generate_qr_template(qr_size, block_size=5, show_timing_marks=False): + if qr_size == 29: + num_words = 24 + word_cols = 2 + else: + num_words = 12 + word_cols = 1 + html = """ @@ -9,6 +16,7 @@ def generate_qr_template(qr_size, block_size=5, show_timing_marks=False): """ - if qr_size == 21: - html += f"""
{qr_size}x{qr_size} QR Code
""" - elif qr_size == 25: - html += f"""
12-word Seed
""" - else: - html += f"""
24-word Seed
""" + + html += """ + + + +
+ """ + for i in range(1, num_words + 1): + if i == 13: + html += """ + + """ + html += f"""
+ {i}: ____________________________ +
+ """ + html += "
" y_names = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,X,Y,Z" - html += """""" + html += """
""" html += f"""""" for j in range(0, math.ceil(qr_size/block_size)): html += f"""""" diff --git a/docs/qr_code_template_25x25.html b/docs/qr_code_template_25x25.html index a2cb69e0..01999e17 100644 --- a/docs/qr_code_template_25x25.html +++ b/docs/qr_code_template_25x25.html @@ -6,6 +6,7 @@ -
12-word Seed
{j + 1}
+ +
12345
+ +
+
+ 1: ____________________________ +
+
+ 2: ____________________________ +
+
+ 3: ____________________________ +
+
+ 4: ____________________________ +
+
+ 5: ____________________________ +
+
+ 6: ____________________________ +
+
+ 7: ____________________________ +
+
+ 8: ____________________________ +
+
+ 9: ____________________________ +
+
+ 10: ____________________________ +
+
+ 11: ____________________________ +
+
+ 12: ____________________________ +
+
diff --git a/docs/qr_code_template_29x29.html b/docs/qr_code_template_29x29.html index 7767c9fd..281d8c85 100644 --- a/docs/qr_code_template_29x29.html +++ b/docs/qr_code_template_29x29.html @@ -6,6 +6,7 @@ -
24-word Seed
12345
A
+ +
123456
+ + +
+
+ 1: ____________________________ +
+
+ 2: ____________________________ +
+
+ 3: ____________________________ +
+
+ 4: ____________________________ +
+
+ 5: ____________________________ +
+
+ 6: ____________________________ +
+
+ 7: ____________________________ +
+
+ 8: ____________________________ +
+
+ 9: ____________________________ +
+
+ 10: ____________________________ +
+
+ 11: ____________________________ +
+
+ 12: ____________________________ +
+ +
+
+ 13: ____________________________ +
+
+ 14: ____________________________ +
+
+ 15: ____________________________ +
+
+ 16: ____________________________ +
+
+ 17: ____________________________ +
+
+ 18: ____________________________ +
+
+ 19: ____________________________ +
+
+ 20: ____________________________ +
+
+ 21: ____________________________ +
+
+ 22: ____________________________ +
+
+ 23: ____________________________ +
+
+ 24: ____________________________ +
+
diff --git a/src/seedsigner/controller.py b/src/seedsigner/controller.py index eca9db68..421dcfae 100644 --- a/src/seedsigner/controller.py +++ b/src/seedsigner/controller.py @@ -266,8 +266,8 @@ class Controller: if ret_val == True: break else: - # no-op; can't back out of the seed phrase view - pass + # Start over + return self.show_create_seed_with_image_tool() # Ask to save seed if self.storage.slot_avaliable(): diff --git a/src/seedsigner/helpers/camera_process.py b/src/seedsigner/helpers/camera_process.py index 490c504c..d0021421 100644 --- a/src/seedsigner/helpers/camera_process.py +++ b/src/seedsigner/helpers/camera_process.py @@ -62,13 +62,11 @@ class CameraProcess(): def capture_single_frame(in_queue, out_queue): from PIL import Image - from PIL.ImageOps import autocontrast import picamera print("Instantiate PiCamera start") start_time = int(time.time() * 1000) - # camera = picamera.PiCamera(resolution=(512, 384),framerate=12) - camera = picamera.PiCamera(resolution=(480, 480), framerate=8) + camera = picamera.PiCamera(resolution=(720, 480), framerate=8) end_time = int(time.time() * 1000) print(f"Instantiate PiCamera finish: {end_time - start_time}ms") @@ -106,7 +104,7 @@ class CameraProcess(): # "Rewind" the stream to the beginning so we can read its content stream.seek(0) - out_queue.put([autocontrast(Image.open(stream), cutoff=2).rotate(90)]) + out_queue.put([Image.open(stream)]) except Exception as e: traceback.print_exc() diff --git a/src/seedsigner/views/seed_tools_view.py b/src/seedsigner/views/seed_tools_view.py index 23dde26a..79fff5fb 100644 --- a/src/seedsigner/views/seed_tools_view.py +++ b/src/seedsigner/views/seed_tools_view.py @@ -2,6 +2,7 @@ from embit import bip39 from embit.bip39 import mnemonic_to_bytes, mnemonic_from_bytes from PIL import ImageDraw, Image +from PIL.ImageOps import autocontrast import hashlib import math import time @@ -1500,12 +1501,25 @@ class SeedToolsView(View): self.words = [] return self.words - # Resize and display + # Prep a copy of the image for display. The actual image data is 720x480 + # Present just a center crop to fit the screen and to keep some of the + # data hidden. + display_version = autocontrast( + self.seed_entropy_image, cutoff=2 + ).rotate( + 90 + ).crop( + (120, 0, 600, 480) + ).resize( + (View.canvas_width, View.canvas_height), Image.BICUBIC + ) + View.DispShowImageWithText( - self.seed_entropy_image.resize((View.canvas_width, View.canvas_height), Image.BICUBIC), - text="<= reshoot | accept =>", + display_version, + text=" < reshoot | accept > ", font=View.ROBOTOCONDENSED_REGULAR_22, - text_color=View.color + text_color=View.color, + text_background=(0,0,0,225) ) input = self.buttons.wait_for([B.KEY_LEFT, B.KEY_RIGHT]) diff --git a/src/seedsigner/views/view.py b/src/seedsigner/views/view.py index 53dfcc57..f11e4f30 100644 --- a/src/seedsigner/views/view.py +++ b/src/seedsigner/views/view.py @@ -128,15 +128,18 @@ class View: def DispShowImageWithText(image, text, font=None, text_color="GREY", text_background=None): - image_copy = image.copy() + image_copy = image.copy().convert("RGBA") draw = ImageDraw.Draw(image_copy) + + text_overlay = Image.new("RGBA", (View.canvas_width, View.canvas_height), (255,255,255,0)) + text_overlay_draw = ImageDraw.Draw(text_overlay) if not font: font = View.COURIERNEW14 - tw, th = draw.textsize(text, font=font) + tw, th = text_overlay_draw.textsize(text, font=font) if text_background: - draw.rectangle(((240 - tw) / 2 - 3, 240 - th, (240 - tw) / 2 + tw + 3, 240), fill=text_background) - draw.text(((240 - tw) / 2, 240 - th - 1), text, fill=text_color, font=font) - View.disp.ShowImage(image_copy, 0, 0) + text_overlay_draw.rectangle(((240 - tw) / 2 - 3, 240 - th, (240 - tw) / 2 + tw + 3, 240), fill=text_background) + text_overlay_draw.text(((240 - tw) / 2, 240 - th - 1), text, fill=text_color, font=font) + View.DispShowImage(image_copy, alpha_overlay=text_overlay) def draw_modal(self, lines = [], title = "", bottom = "") -> None:
123456
A