rawshift_image/processing/options.rs
1//! Processing options for the raw image pipeline.
2
3use crate::processing::demosaic::DemosaicMethod;
4use crate::transforms::BadPixelCorrectionMode;
5
6/// Options for processing a raw image.
7///
8/// This struct controls the entire pipeline from raw data to the final exported image:
9/// 1. Bad pixel correction (optional, on raw CFA data)
10/// 2. Demosaicing (Raw -> RGB)
11/// 3. White Balance
12/// 4. Color Matrix
13/// 5. Noise reduction (optional, on RGB data)
14/// 6. Chromatic aberration correction (optional, on RGB data)
15/// 7. Gamma Correction
16#[derive(Clone, Debug, Default)]
17#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
18pub struct ProcessingOptions {
19 /// The demosaicing method to use.
20 pub demosaic: DemosaicMethod,
21 /// White balance multipliers (R, G, B).
22 pub white_balance: Option<(f32, f32, f32)>,
23 /// Color matrix (3x3 row-major) to transform from Camera RGB to output space (e.g. sRGB).
24 pub color_matrix: Option<[f32; 9]>,
25 /// Gamma correction value (e.g. 2.2).
26 pub gamma: Option<f32>,
27 /// Bad pixel correction mode.
28 ///
29 /// When `Some`, bad pixels are detected and corrected on the raw CFA data
30 /// before demosaicing. Uses a threshold factor of 0.5.
31 pub bad_pixel_correction: Option<BadPixelCorrectionMode>,
32 /// Noise reduction bilateral filter sigma.
33 ///
34 /// When `Some`, a bilateral filter is applied to the RGB image after
35 /// demosaicing. The value is used as both the spatial sigma (in pixels)
36 /// and a scaled range sigma (`sigma * 10000`). A typical value is `2.0`.
37 pub denoise_sigma: Option<f32>,
38 /// Chromatic aberration correction scale factors `(red_scale, blue_scale)`.
39 ///
40 /// When `Some`, the R and B channels are rescaled relative to the image
41 /// centre to correct lateral chromatic aberration. Values near `1.0` make
42 /// small corrections (e.g. `(0.999, 1.001)`).
43 pub ca_correction: Option<(f32, f32)>,
44}
45
46impl ProcessingOptions {
47 /// Create a new builder for ProcessingOptions.
48 pub fn new() -> Self {
49 Self::default()
50 }
51
52 /// Set the demosaicing method.
53 pub fn demosaic(mut self, method: DemosaicMethod) -> Self {
54 self.demosaic = method;
55 self
56 }
57
58 /// Set white balance multipliers.
59 pub fn white_balance(mut self, r: f32, g: f32, b: f32) -> Self {
60 self.white_balance = Some((r, g, b));
61 self
62 }
63
64 /// Set the color matrix.
65 pub fn color_matrix(mut self, matrix: [f32; 9]) -> Self {
66 self.color_matrix = Some(matrix);
67 self
68 }
69
70 /// Set the gamma value.
71 pub fn gamma(mut self, gamma: f32) -> Self {
72 self.gamma = Some(gamma);
73 self
74 }
75
76 /// Enable bad pixel correction with the given mode.
77 pub fn bad_pixel_correction(mut self, mode: BadPixelCorrectionMode) -> Self {
78 self.bad_pixel_correction = Some(mode);
79 self
80 }
81
82 /// Enable bilateral noise reduction with the given spatial sigma.
83 pub fn denoise(mut self, sigma: f32) -> Self {
84 self.denoise_sigma = Some(sigma);
85 self
86 }
87
88 /// Enable chromatic aberration correction with per-channel scale factors.
89 pub fn ca_correction(mut self, red_scale: f32, blue_scale: f32) -> Self {
90 self.ca_correction = Some((red_scale, blue_scale));
91 self
92 }
93}