Skip to main content

rawshift_image/transforms/
cfa.rs

1//! Color Filter Array (CFA) Demosaicing.
2//!
3//! This transform module acts as a high-level wrapper around the demosaicing algorithms
4//! defined in [`crate::processing::demosaic`]. It handles the selection of the appropriate
5//! algorithm and manages the conversion from raw sensor data to RGB image buffers.
6
7use crate::core::image::{RawImage, RgbImage};
8use crate::error::RawResult;
9use crate::processing::demosaic::DemosaicMethod;
10
11/// Demosaicing transform pipeline step.
12pub struct CfaTransform {
13    method: DemosaicMethod,
14}
15
16impl CfaTransform {
17    /// Create a new CFA transform with the specified demosaicing method.
18    pub fn new(method: DemosaicMethod) -> Self {
19        Self { method }
20    }
21
22    /// Apply demosaicing to a RawImage, producing an RgbImage.
23    pub fn apply(&self, raw: &RawImage) -> RawResult<RgbImage> {
24        let demosaic = self.method.to_demosaic();
25        Ok(demosaic.demosaic(raw))
26    }
27}
28
29impl Default for CfaTransform {
30    fn default() -> Self {
31        Self::new(DemosaicMethod::default())
32    }
33}