From 23c1f33d3244772f4e1f9f5f8a507694f8f4b833 Mon Sep 17 00:00:00 2001 From: lashman Date: Fri, 6 Mar 2026 14:51:17 +0200 Subject: [PATCH] Support per-format conversion mapping in processing pipeline Build FormatMapping when per-format overrides are set in the convert step advanced options, falling back to SingleFormat when no overrides are configured. --- pixstrip-gtk/src/app.rs | 46 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/pixstrip-gtk/src/app.rs b/pixstrip-gtk/src/app.rs index 9f33ee3..5cc34b9 100644 --- a/pixstrip-gtk/src/app.rs +++ b/pixstrip-gtk/src/app.rs @@ -1147,8 +1147,50 @@ fn run_processing(_window: &adw::ApplicationWindow, ui: &WizardUi) { } } - if cfg.convert_enabled && let Some(fmt) = cfg.convert_format { - job.convert = Some(pixstrip_core::operations::ConvertConfig::SingleFormat(fmt)); + if cfg.convert_enabled { + // Check if any per-format mappings are set (non-zero = overridden) + let has_mapping = cfg.format_mapping_jpeg > 0 + || cfg.format_mapping_png > 0 + || cfg.format_mapping_webp > 0 + || cfg.format_mapping_tiff > 0; + + if has_mapping { + let mapping_to_format = |idx: u32, default: Option| -> Option { + match idx { + 1 => Some(pixstrip_core::types::ImageFormat::Jpeg), + 2 => Some(pixstrip_core::types::ImageFormat::Png), + 3 => Some(pixstrip_core::types::ImageFormat::WebP), + 4 => Some(pixstrip_core::types::ImageFormat::Avif), + 5 => None, // Keep Original + _ => default, // "Same as above" - use global format + } + }; + + let global = cfg.convert_format; + let mut map = Vec::new(); + + // For each input format, determine output + let input_formats = [ + (pixstrip_core::types::ImageFormat::Jpeg, cfg.format_mapping_jpeg), + (pixstrip_core::types::ImageFormat::Png, cfg.format_mapping_png), + (pixstrip_core::types::ImageFormat::WebP, cfg.format_mapping_webp), + (pixstrip_core::types::ImageFormat::Tiff, cfg.format_mapping_tiff), + ]; + + for (input_fmt, mapping_idx) in input_formats { + if let Some(output_fmt) = mapping_to_format(mapping_idx, global) { + if output_fmt != input_fmt { + map.push((input_fmt, output_fmt)); + } + } + } + + if !map.is_empty() { + job.convert = Some(pixstrip_core::operations::ConvertConfig::FormatMapping(map)); + } + } else if let Some(fmt) = cfg.convert_format { + job.convert = Some(pixstrip_core::operations::ConvertConfig::SingleFormat(fmt)); + } } if cfg.compress_enabled {