Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Live preview speedup #413

Merged
merged 9 commits into from
Jul 31, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Renderer support for max speed
  • Loading branch information
kdmukai committed Jul 25, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit b01a4c068aa1ee7d1233bb472bc0657f40bc5da4
7 changes: 6 additions & 1 deletion src/seedsigner/gui/renderer.py
Original file line number Diff line number Diff line change
@@ -34,7 +34,12 @@ def configure_instance(cls):
renderer.draw = ImageDraw.Draw(renderer.canvas)


def show_image(self, image=None, alpha_overlay=None):
def show_image(self, image=None, alpha_overlay=None, show_direct=False):
if show_direct:
# Use the incoming image as the canvas and immediately render
self.disp.ShowImage(image, 0, 0)
return

if alpha_overlay:
if image == None:
image = self.canvas
14 changes: 7 additions & 7 deletions src/seedsigner/gui/screens/scan_screens.py
Original file line number Diff line number Diff line change
@@ -44,7 +44,7 @@ class ScanScreen(BaseScreen):
decoder: DecodeQR = None
instructions_text: str = "< back | Scan a QR code"
resolution: tuple[int,int] = (480, 480)
framerate: int = 5 # TODO: alternate optimization for Pi Zero 2W
framerate: int = 5 # TODO: alternate optimization for Pi Zero 2W?
render_rect: tuple[int,int,int,int] = None


@@ -110,18 +110,20 @@ def run(self):
if frame.width > self.render_width or frame.height > self.render_height:
frame = frame.resize(
(self.render_width, self.render_height),
resample=Image.NEAREST
resample=Image.NEAREST # Use nearest neighbor for max speed
)

draw = ImageDraw.Draw(frame)

if scan_text:
# Note: shadowed text (adding a 'stroke' outline) can
# significantly slow down the rendering.
# Temp solution: render a slight 1px shadow behind the text
# TODO: Replace the instructions_text with a disappearing
# toast/popup (see: QR Brightness UI)?
draw.text(xy=(
int(self.renderer.canvas_width/2 + 1),
self.renderer.canvas_height - GUIConstants.EDGE_PADDING + 1
int(self.renderer.canvas_width/2 + 2),
self.renderer.canvas_height - GUIConstants.EDGE_PADDING + 2
),
text=scan_text,
fill="black",
@@ -138,7 +140,7 @@ def run(self):
font=instructions_font,
anchor="ms")

self.renderer.disp.ShowImage(frame, 0, 0)
self.renderer.show_image(frame, show_direct=True)
# print(f" {cur_fps:0.2f} | {self.decoder_fps}")

if self.camera._video_stream is None:
@@ -156,7 +158,6 @@ def _run(self):
while True:
frame = self.camera.read_video_stream()
if frame is not None:
# print("Decoder checking next frame")
status = self.decoder.add_image(frame)

num_frames += 1
@@ -167,7 +168,6 @@ def _run(self):
self.camera.stop_video_stream_mode()
break

# TODO: KEY_UP gives control to NavBar; use its back arrow to cancel
if self.hw_inputs.check_for_low(HardwareButtonsConstants.KEY_RIGHT) or self.hw_inputs.check_for_low(HardwareButtonsConstants.KEY_LEFT):
self.camera.stop_video_stream_mode()
break