gardesk/garbg / 85f4ab7

Browse files

use fast filter and parallel thread::scope for animation frame scaling

Authored by espadonne
SHA
85f4ab7278e108b543e971571d696a54cfcf8ea7
Parents
4fe782c
Tree
4987200

1 changed file

StatusFile+-
M garbg/src/daemon/state.rs 14 6
garbg/src/daemon/state.rsmodified
@@ -10,7 +10,7 @@ use crate::cache::DiskCache;
1010
 use crate::config::{Config, ScaleMode};
1111
 use crate::ipc::{Command, GarEvent, GarIpcClient, IpcServer, Response};
1212
 use crate::ipc::server::IpcClient;
13
-use crate::media::{scale_image, AnimatedGif, AnimatedPng, AnimatedWebP, AnimationFrame, ImageLoader};
13
+use crate::media::{scale_image, scale_image_fast, AnimatedGif, AnimatedPng, AnimatedWebP, AnimationFrame, ImageLoader};
1414
 #[cfg(feature = "video")]
1515
 use crate::media::{VideoDecoder, is_video_file};
1616
 use crate::state::{detect_source_type, PlaylistState};
@@ -93,7 +93,7 @@ pub struct ActiveAnimation {
9393
 }
9494
 
9595
 impl ActiveAnimation {
96
-    /// Create from animation frames
96
+    /// Create from animation frames (scales in parallel with fast filter)
9797
     fn from_frames(
9898
         frames: &[AnimationFrame],
9999
         renderer: AnimationRenderer,
@@ -103,10 +103,18 @@ impl ActiveAnimation {
103103
         screen_width: u32,
104104
         screen_height: u32,
105105
     ) -> Self {
106
-        let scaled_frames: Vec<image::RgbaImage> = frames
107
-            .iter()
108
-            .map(|frame| scale_image(&frame.image, screen_width, screen_height, scale_mode))
109
-            .collect();
106
+        // Scale frames in parallel using thread::scope for multi-core speedup
107
+        let scaled_frames: Vec<image::RgbaImage> = std::thread::scope(|s| {
108
+            let handles: Vec<_> = frames
109
+                .iter()
110
+                .map(|frame| {
111
+                    s.spawn(move || {
112
+                        scale_image_fast(&frame.image, screen_width, screen_height, scale_mode)
113
+                    })
114
+                })
115
+                .collect();
116
+            handles.into_iter().map(|h| h.join().unwrap()).collect()
117
+        });
110118
 
111119
         let frame_delays: Vec<Duration> = frames
112120
             .iter()