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

Key image size bug fixes #377

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 6 additions & 5 deletions streamdeck_ui/display/display_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ class DisplayGrid:
filters for one individual button display.
"""

_empty_filter: EmptyFilter = EmptyFilter()
"Static instance of EmptyFilter shared by all pipelines"

def __init__(self, lock: threading.Lock, streamdeck: StreamDeck, pages: int, cpu_callback: Callable[[str, int], None], fps: int = 25):
"""Creates a new display instance

Expand Down Expand Up @@ -69,12 +66,16 @@ def __init__(self, lock: threading.Lock, streamdeck: StreamDeck, pages: int, cpu
self.sync = threading.Event()
self.cpu_callback = cpu_callback
# The sync event allows a caller to wait until all the buttons have been processed
DisplayGrid._empty_filter.initialize(self.size)

self._empty_filter: EmptyFilter = EmptyFilter()
self._empty_filter.initialize(self.size)
# Instance of EmptyFilter shared by all pipelines related to this
# DisplayGrid instance

def replace(self, page: int, button: int, filters: List[Filter]):
with self.lock:
pipeline = Pipeline()
pipeline.add(DisplayGrid._empty_filter)
pipeline.add(self._empty_filter)
for filter in filters:
filter.initialize(self.size)
pipeline.add(filter)
Expand Down
4 changes: 2 additions & 2 deletions streamdeck_ui/display/image_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ def initialize(self, size: Tuple[int, int]):
# Scale all the frames to the target size
self.frames = []
for frame, milliseconds, hashcode in zip(frames, frame_duration, frame_hash):
frame = frame.copy()
frame.thumbnail(size, Image.LANCZOS)
scale_factor = min(size[0] / frame.size[0], size[1] / frame.size[1])
frame = frame.resize((int(v * scale_factor) for v in frame.size), Image.LANCZOS)
self.frames.append((frame, milliseconds, hashcode))

self.frame_cycle = itertools.cycle(self.frames)
Expand Down