From 30c84b80bf19a427567ae69702e9a9c619c7a26f Mon Sep 17 00:00:00 2001 From: Giraut <> Date: Thu, 7 Mar 2024 11:27:31 +0200 Subject: [PATCH 1/2] Correctly scale images up as well as down, in case they're smaller than the target key display size --- streamdeck_ui/display/image_filter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/streamdeck_ui/display/image_filter.py b/streamdeck_ui/display/image_filter.py index a569fb18..a57c2dc5 100644 --- a/streamdeck_ui/display/image_filter.py +++ b/streamdeck_ui/display/image_filter.py @@ -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) From ee817c67b62d009eb2e36079a716a231a9160261 Mon Sep 17 00:00:00 2001 From: Giraut <> Date: Thu, 7 Mar 2024 17:44:28 +0200 Subject: [PATCH 2/2] Initialize one separate EmptyFilter instance per DisplayGrid instance instead of a single EmptyFilter for all the DisplayGrid instances, so the key images are displayed with the correct size on all the Stream Decks if more than one Stream Deck is connected and the Stream Decks have different image sizes for the keys --- streamdeck_ui/display/display_grid.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/streamdeck_ui/display/display_grid.py b/streamdeck_ui/display/display_grid.py index f173fdf7..824cfcac 100644 --- a/streamdeck_ui/display/display_grid.py +++ b/streamdeck_ui/display/display_grid.py @@ -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 @@ -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)