Struct CFA

Source
pub struct CFA {
    pub name: String,
    pub width: usize,
    pub height: usize,
    /* private fields */
}
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§

Source§

impl CFA

Source

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).

Source

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.

Source

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);
Source

pub fn is_valid(&self) -> bool

Test if this is actually a valid CFA pattern

§Example
use rawloader::CFA;
let cfa = CFA::new("RGGB");
assert!(cfa.is_valid());

let cfa = CFA::new("");
assert!(!cfa.is_valid());
Source

pub fn to_string(&self) -> String

Convert the CFA back into a pattern string

§Example
use rawloader::CFA;
let cfa = CFA::new("RGGB");
assert_eq!(cfa.to_string(), "RGGB");

let shifted = cfa.shift(1,1);
assert_eq!(shifted.to_string(), "BGGR");

Trait Implementations§

Source§

impl Clone for CFA

Source§

fn clone(&self) -> CFA

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CFA

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for CFA

§

impl RefUnwindSafe for CFA

§

impl Send for CFA

§

impl Sync for CFA

§

impl Unpin for CFA

§

impl UnwindSafe for CFA

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.