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) 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)