| ... | ... | @@ -27,7 +27,7 @@ pub struct ExportOptions { |
| 27 | 27 | pub hiq: bool, |
| 28 | 28 | /// Proxy downscale factor (`1` = full resolution). |
| 29 | 29 | pub proxy_scale: u32, |
| 30 | | /// Number of background PNG encoder threads (`0` = automatic 2..=16, bounded by frame count). |
| 30 | /// Number of background PNG encoder threads (`0` = automatic 2..=24, bounded by frame count). |
| 31 | 31 | pub png_workers: usize, |
| 32 | 32 | } |
| 33 | 33 | |
| ... | ... | @@ -188,7 +188,8 @@ fn resolve_output_path(saver: &SaverSpec, frame: i64, out_dir_override: Option<& |
| 188 | 188 | } |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | | /// Encodes an RGBA8 image into `out` as a lossless fast-compressed PNG (clearing `out` first). |
| 191 | /// Encodes an RGBA8 image into `out` as a lossless PNG matching Fusion's default |
| 192 | /// libpng compression (`Compression::Balanced` = zlib level 6 + `Filter::Adaptive`). |
| 192 | 193 | pub fn encode_png_rgba8_into(size: [u32; 2], pixels: &[u8], out: &mut Vec<u8>) -> Result<(), String> { |
| 193 | 194 | out.clear(); |
| 194 | 195 | if out.capacity() == 0 { |
| ... | ... | @@ -197,8 +198,8 @@ pub fn encode_png_rgba8_into(size: [u32; 2], pixels: &[u8], out: &mut Vec<u8>) - |
| 197 | 198 | let mut enc = png::Encoder::new(&mut *out, size[0], size[1]); |
| 198 | 199 | enc.set_color(png::ColorType::Rgba); |
| 199 | 200 | enc.set_depth(png::BitDepth::Eight); |
| 200 | | enc.set_compression(png::Compression::Fastest); |
| 201 | | enc.set_filter(png::Filter::Up); |
| 201 | enc.set_compression(png::Compression::Balanced); |
| 202 | enc.set_filter(png::Filter::Adaptive); |
| 202 | 203 | let mut png_w = enc |
| 203 | 204 | .write_header() |
| 204 | 205 | .map_err(|e| format!("failed to write PNG header: {e}"))?; |
| ... | ... | @@ -281,10 +282,10 @@ pub fn export_saver_png_sequence_with_progress( |
| 281 | 282 | |
| 282 | 283 | let total = (end - start + 1) as usize; |
| 283 | 284 | let workers = if opts.png_workers > 0 { |
| 284 | | opts.png_workers.clamp(1, 16) |
| 285 | opts.png_workers.clamp(1, 24) |
| 285 | 286 | } else { |
| 286 | 287 | std::thread::available_parallelism() |
| 287 | | .map(|n| n.get().clamp(2, 16)) |
| 288 | .map(|n| n.get().clamp(2, 24)) |
| 288 | 289 | .unwrap_or(4) |
| 289 | 290 | } |
| 290 | 291 | .min(total.max(1)); |
| ... | ... | @@ -299,7 +300,7 @@ pub fn export_saver_png_sequence_with_progress( |
| 299 | 300 | let cancelled = Arc::new(AtomicBool::new(false)); |
| 300 | 301 | |
| 301 | 302 | let eval_result: Result<(), String> = std::thread::scope(|scope| { |
| 302 | | let queue_cap = (workers * 2).clamp(16, 32); |
| 303 | let queue_cap = (workers * 2).clamp(16, 48); |
| 303 | 304 | let (tx, rx) = mpsc::sync_channel::<EncodeJob>(queue_cap); |
| 304 | 305 | let (recycle_tx, recycle_rx) = mpsc::sync_channel::<Vec<u8>>(queue_cap + workers); |
| 305 | 306 | let shared_rx = Arc::new(Mutex::new(rx)); |