use crate::{BayerPattern, ColorSpace, PixelType};
pub trait BayerShift {
fn shift(&self, x: usize, y: usize) -> Self;
fn flip_horizontal(&self) -> Self;
fn flip_vertical(&self) -> Self;
}
impl BayerShift for BayerPattern {
fn shift(&self, x: usize, y: usize) -> Self {
match self {
BayerPattern::Rggb => match (x % 2, y % 2) {
(0, 0) => BayerPattern::Rggb,
(1, 0) => BayerPattern::Gbrg,
(0, 1) => BayerPattern::Grbg,
(1, 1) => BayerPattern::Bggr,
_ => unreachable!(),
},
BayerPattern::Gbrg => match (x % 2, y % 2) {
(0, 0) => BayerPattern::Gbrg,
(1, 0) => BayerPattern::Rggb,
(0, 1) => BayerPattern::Bggr,
(1, 1) => BayerPattern::Grbg,
_ => unreachable!(),
},
BayerPattern::Grbg => match (x % 2, y % 2) {
(0, 0) => BayerPattern::Grbg,
(1, 0) => BayerPattern::Bggr,
(0, 1) => BayerPattern::Rggb,
(1, 1) => BayerPattern::Gbrg,
_ => unreachable!(),
},
BayerPattern::Bggr => match (x % 2, y % 2) {
(0, 0) => BayerPattern::Bggr,
(1, 0) => BayerPattern::Grbg,
(0, 1) => BayerPattern::Gbrg,
(1, 1) => BayerPattern::Rggb,
_ => unreachable!(),
},
}
}
fn flip_horizontal(&self) -> Self {
match self {
BayerPattern::Rggb => BayerPattern::Grbg,
BayerPattern::Gbrg => BayerPattern::Bggr,
BayerPattern::Grbg => BayerPattern::Rggb,
BayerPattern::Bggr => BayerPattern::Gbrg,
}
}
fn flip_vertical(&self) -> Self {
match self {
BayerPattern::Rggb => BayerPattern::Gbrg,
BayerPattern::Gbrg => BayerPattern::Rggb,
BayerPattern::Grbg => BayerPattern::Bggr,
BayerPattern::Bggr => BayerPattern::Grbg,
}
}
}
pub trait PixelData {
fn as_raw_u8(&self) -> &[u8];
fn as_raw_u8_checked(&self) -> Option<&[u8]>;
fn as_slice_u8(&self) -> Option<&[u8]>;
fn as_slice_u16(&self) -> Option<&[u16]>;
fn as_slice_f32(&self) -> Option<&[f32]>;
fn as_mut_slice_u8(&mut self) -> Option<&mut [u8]>;
fn as_mut_slice_u16(&mut self) -> Option<&mut [u16]>;
fn as_mut_slice_f32(&mut self) -> Option<&mut [f32]>;
}
pub trait ImageProps {
fn width(&self) -> usize;
fn height(&self) -> usize;
fn channels(&self) -> u8;
fn color_space(&self) -> ColorSpace;
fn pixel_type(&self) -> PixelType;
fn len(&self) -> usize;
fn is_empty(&self) -> bool;
}