1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
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,
}
}
}