Expand description
Representation of the color filter array pattern in raw cameras
Example
use rawloader::CFA;
let cfa = CFA::new("RGGB");
assert_eq!(cfa.color_at(0,0), 0);
assert_eq!(cfa.color_at(0,1), 1);
assert_eq!(cfa.color_at(1,0), 1);
assert_eq!(cfa.color_at(1,1), 2);
You will almost always get your CFA struct from a RawImage decode, already fully initialized and ready to be used in processing. The color_at() implementation is designed to be fast so it can be called inside the inner loop of demosaic or other color-aware algorithms that work on pre-demosaic data
Fields
name: String
CFA pattern as a String
width: usize
Width of the repeating pattern
height: usize
Height of the repeating pattern
Implementations
sourceimpl CFA
impl CFA
sourcepub fn new(patname: &str) -> CFA
pub fn new(patname: &str) -> CFA
Create a new CFA from a string describing it. For simplicity the pattern is specified as each pixel being one of R/G/B/E representing the 0/1/2/3 colors in a 4 color image. The pattern is specified as the colors in each row concatenated so RGGB means that the first row is RG and the second row GB. Row size is determined by pattern size (e.g., the xtrans pattern is 6x6 and thus 36 characters long). In theory this could lead to confusion between different pattern sizes but in practice there are only a few oddball cameras no one cares about that do anything but 2x2 and 6x6 (and those work fine with this as well).
sourcepub fn color_at(&self, row: usize, col: usize) -> usize
pub fn color_at(&self, row: usize, col: usize) -> usize
Get the color index at the given position. Designed to be fast so it can be called from inner loops without performance issues.
sourcepub fn shift(&self, x: usize, y: usize) -> CFA
pub fn shift(&self, x: usize, y: usize) -> CFA
Shift the pattern left and/or down. This is useful when cropping the image to get the equivalent pattern of the crop when it’s not a multiple of the pattern size.
Example
use rawloader::CFA;
let cfa = CFA::new("RGGB");
assert_eq!(cfa.color_at(0,0), 0);
assert_eq!(cfa.color_at(0,1), 1);
assert_eq!(cfa.color_at(1,0), 1);
assert_eq!(cfa.color_at(1,1), 2);
let shifted = cfa.shift(1,1);
assert_eq!(shifted.color_at(0,0), 2);
assert_eq!(shifted.color_at(0,1), 1);
assert_eq!(shifted.color_at(1,0), 1);
assert_eq!(shifted.color_at(1,1), 0);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for CFA
impl Send for CFA
impl Sync for CFA
impl Unpin for CFA
impl UnwindSafe for CFA
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> Pointable for T
impl<T> Pointable for T
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more