Share pixbufs between frames panel and scrub bar — single disk read per frame
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -131,24 +131,39 @@ class ScrubBar(Gtk.DrawingArea):
|
||||
self.queue_draw()
|
||||
|
||||
def add_frame(self, timestamp: float, path: str) -> None:
|
||||
"""Add a single frame thumbnail incrementally."""
|
||||
"""Add a single frame thumbnail from file path."""
|
||||
if not Path(path).exists():
|
||||
return
|
||||
thumb_h = BAR_HEIGHT - 4
|
||||
thumb_w = int(thumb_h * 16 / 9)
|
||||
try:
|
||||
pixbuf = GdkPixbuf.Pixbuf.new_from_file_at_scale(path, thumb_w, thumb_h, True)
|
||||
surface = self._pixbuf_to_surface(pixbuf)
|
||||
self._frame_thumbs.append({
|
||||
"timestamp": timestamp,
|
||||
"surface": surface,
|
||||
"width": pixbuf.get_width(),
|
||||
"height": pixbuf.get_height(),
|
||||
})
|
||||
self.queue_draw()
|
||||
self.add_frame_from_pixbuf(timestamp, pixbuf)
|
||||
except Exception as e:
|
||||
log.debug("Thumb load failed for %s: %s", path, e)
|
||||
|
||||
def add_frame_from_pixbuf(self, timestamp: float, pixbuf) -> None:
|
||||
"""Add a single frame thumbnail from an already-loaded pixbuf (shared with frames panel)."""
|
||||
thumb_h = BAR_HEIGHT - 4
|
||||
thumb_w = int(thumb_h * 16 / 9)
|
||||
scaled = pixbuf.scale_simple(thumb_w, thumb_h, GdkPixbuf.InterpType.BILINEAR)
|
||||
surface = self._pixbuf_to_surface(scaled)
|
||||
self._frame_thumbs.append({
|
||||
"timestamp": timestamp,
|
||||
"surface": surface,
|
||||
"width": scaled.get_width(),
|
||||
"height": scaled.get_height(),
|
||||
})
|
||||
self.queue_draw()
|
||||
|
||||
def set_frames_from_pixbufs(self, frames: list[dict]) -> None:
|
||||
"""Bulk set thumbnails from already-loaded pixbufs. Each dict: {timestamp, pixbuf}."""
|
||||
self._frame_thumbs = []
|
||||
for f in frames:
|
||||
self.add_frame_from_pixbuf(f["timestamp"], f["pixbuf"])
|
||||
# queue_draw already called per frame, but one more to be safe
|
||||
self.queue_draw()
|
||||
|
||||
@staticmethod
|
||||
def _pixbuf_to_surface(pixbuf):
|
||||
"""Convert a GdkPixbuf to a cairo ImageSurface."""
|
||||
|
||||
Reference in New Issue
Block a user