|
| 1 | +//! ConvertOptions builder functions. |
| 2 | +
|
| 3 | +use std::path::PathBuf; |
| 4 | + |
| 5 | +/// Build a ConvertOptions struct with all options including GPU control |
| 6 | +/// |
| 7 | +/// This is the canonical function for building ConvertOptions with all |
| 8 | +/// pipeline defaults, making it reusable across CLI and GUI applications. |
| 9 | +#[allow(clippy::too_many_arguments)] |
| 10 | +pub fn build_convert_options_full_with_gpu( |
| 11 | + input: PathBuf, |
| 12 | + output_dir: PathBuf, |
| 13 | + export: &str, |
| 14 | + colorspace: String, |
| 15 | + base_estimation: Option<invers_core::models::BaseEstimation>, |
| 16 | + film_preset: Option<invers_core::models::FilmPreset>, |
| 17 | + scan_profile: Option<invers_core::models::ScanProfile>, |
| 18 | + no_tonecurve: bool, |
| 19 | + no_colormatrix: bool, |
| 20 | + exposure: f32, |
| 21 | + inversion_mode: Option<invers_core::models::InversionMode>, |
| 22 | + no_auto_levels: bool, |
| 23 | + preserve_headroom: bool, |
| 24 | + no_clip: bool, |
| 25 | + auto_wb: bool, |
| 26 | + auto_wb_strength: f32, |
| 27 | + debug: bool, |
| 28 | + use_gpu: bool, |
| 29 | +) -> Result<invers_core::models::ConvertOptions, String> { |
| 30 | + let config_handle = invers_core::config::pipeline_config_handle(); |
| 31 | + let defaults = config_handle.config.defaults.clone(); |
| 32 | + |
| 33 | + // Parse output format |
| 34 | + let output_format = match export { |
| 35 | + "tiff16" | "tiff" => invers_core::models::OutputFormat::Tiff16, |
| 36 | + "dng" => invers_core::models::OutputFormat::LinearDng, |
| 37 | + _ => return Err(format!("Unknown export format: {}", export)), |
| 38 | + }; |
| 39 | + |
| 40 | + // Use provided inversion mode, or scan profile preference, or fall back to config default |
| 41 | + let inversion_mode = inversion_mode |
| 42 | + .or_else(|| { |
| 43 | + scan_profile |
| 44 | + .as_ref() |
| 45 | + .and_then(|sp| sp.preferred_inversion_mode) |
| 46 | + }) |
| 47 | + .unwrap_or(defaults.inversion_mode); |
| 48 | + |
| 49 | + // Auto-levels: disabled if --no-auto-levels is set |
| 50 | + let enable_auto_levels = !no_auto_levels && defaults.enable_auto_levels; |
| 51 | + |
| 52 | + Ok(invers_core::models::ConvertOptions { |
| 53 | + input_paths: vec![input], |
| 54 | + output_dir, |
| 55 | + output_format, |
| 56 | + working_colorspace: colorspace, |
| 57 | + bit_depth_policy: invers_core::models::BitDepthPolicy::Force16Bit, |
| 58 | + film_preset, |
| 59 | + scan_profile, |
| 60 | + base_estimation, |
| 61 | + num_threads: None, |
| 62 | + skip_tone_curve: no_tonecurve || defaults.skip_tone_curve, |
| 63 | + skip_color_matrix: no_colormatrix || defaults.skip_color_matrix, |
| 64 | + exposure_compensation: defaults.exposure_compensation * exposure, |
| 65 | + debug, |
| 66 | + enable_auto_levels, |
| 67 | + auto_levels_clip_percent: defaults.auto_levels_clip_percent, |
| 68 | + preserve_headroom: preserve_headroom || defaults.preserve_headroom, |
| 69 | + enable_auto_color: defaults.enable_auto_color, |
| 70 | + auto_color_strength: defaults.auto_color_strength, |
| 71 | + auto_color_min_gain: defaults.auto_color_min_gain, |
| 72 | + auto_color_max_gain: defaults.auto_color_max_gain, |
| 73 | + auto_color_max_divergence: defaults.auto_color_max_divergence, |
| 74 | + base_brightest_percent: defaults.base_brightest_percent, |
| 75 | + base_sampling_mode: defaults.base_sampling_mode, |
| 76 | + base_estimation_method: invers_core::models::BaseEstimationMethod::default(), |
| 77 | + auto_levels_mode: invers_core::models::AutoLevelsMode::default(), |
| 78 | + inversion_mode, |
| 79 | + shadow_lift_mode: defaults.shadow_lift_mode, |
| 80 | + shadow_lift_value: defaults.shadow_lift_value, |
| 81 | + highlight_compression: defaults.highlight_compression, |
| 82 | + enable_auto_exposure: defaults.enable_auto_exposure, |
| 83 | + auto_exposure_target_median: defaults.auto_exposure_target_median, |
| 84 | + auto_exposure_strength: defaults.auto_exposure_strength, |
| 85 | + auto_exposure_min_gain: defaults.auto_exposure_min_gain, |
| 86 | + auto_exposure_max_gain: defaults.auto_exposure_max_gain, |
| 87 | + no_clip, |
| 88 | + enable_auto_wb: auto_wb, |
| 89 | + auto_wb_strength, |
| 90 | + auto_wb_mode: invers_core::models::AutoWbMode::default(), |
| 91 | + use_gpu, |
| 92 | + // Research pipeline options (defaults for now, CLI args coming soon) |
| 93 | + pipeline_mode: invers_core::models::PipelineMode::Legacy, |
| 94 | + density_balance: None, |
| 95 | + neutral_point: None, |
| 96 | + density_balance_red: None, |
| 97 | + density_balance_blue: None, |
| 98 | + tone_curve_override: None, |
| 99 | + // CB-style pipeline options |
| 100 | + cb_options: None, |
| 101 | + }) |
| 102 | +} |
0 commit comments