use std::io::Read;
use byteorder::{BigEndian,LittleEndian,ReadBytesExt};
use ::BayerResult;
#[derive(Clone,Copy,Debug,Eq,PartialEq)]
pub enum CFA {
BGGR,
GBRG,
GRBG,
RGGB,
}
#[derive(Clone,Copy,Debug,Eq,PartialEq)]
pub enum BayerDepth {
Depth8,
Depth16BE,
Depth16LE,
}
pub trait BayerRead8 {
fn read_line(&self, r: &mut Read, dst: &mut [u8]) -> BayerResult<()>;
}
pub trait BayerRead16 {
fn read_line(&self, r: &mut Read, dst: &mut [u16]) -> BayerResult<()>;
}
pub fn read_exact_u8(r: &mut Read, buf: &mut [u8])
-> BayerResult<()> {
r.read_exact(buf)?;
Ok(())
}
pub fn read_exact_u16be(r: &mut Read, buf: &mut [u16])
-> BayerResult<()> {
for i in 0..buf.len() {
buf[i] = r.read_u16::<BigEndian>()?;
}
Ok(())
}
pub fn read_exact_u16le(r: &mut Read, buf: &mut [u16])
-> BayerResult<()> {
for i in 0..buf.len() {
buf[i] = r.read_u16::<LittleEndian>()?;
}
Ok(())
}
impl CFA {
pub fn next_x(self) -> Self {
match self {
CFA::BGGR => CFA::GBRG,
CFA::GBRG => CFA::BGGR,
CFA::GRBG => CFA::RGGB,
CFA::RGGB => CFA::GRBG,
}
}
pub fn next_y(self) -> Self {
match self {
CFA::BGGR => CFA::GRBG,
CFA::GBRG => CFA::RGGB,
CFA::GRBG => CFA::BGGR,
CFA::RGGB => CFA::GBRG,
}
}
}