Skip to content
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