Skip to main content

bayer/
lib.rs

1//! This crate provides routines for demosaicing Bayer raw images.
2
3extern crate byteorder;
4extern crate libc;
5
6#[cfg(feature = "rayon")]
7extern crate rayon;
8
9#[macro_use]
10extern crate quick_error;
11
12use std::io::Read;
13
14pub use bayer::BayerDepth;
15pub use bayer::CFA;
16pub use demosaic::Demosaic;
17pub use errcode::BayerError;
18pub use errcode::BayerResult;
19pub use raster::RasterDepth;
20
21/// Mutable raster structure.
22pub struct RasterMut<'a> {
23    x: usize,
24    y: usize,
25    w: usize,
26    h: usize,
27    stride: usize,
28    depth: RasterDepth,
29    buf: &'a mut [u8],
30}
31
32pub mod demosaic;
33pub mod ffi;
34
35mod bayer;
36mod border_mirror;
37mod border_none;
38mod border_replicate;
39mod errcode;
40mod raster;
41
42/// Run the demosaicing algorithm on the Bayer image.
43///
44/// # Example
45///
46/// ```
47/// use std::io::Cursor;
48///
49/// let width: usize = 320;
50/// let height: usize = 200;
51/// let img = vec![0; width * height];
52/// let mut buf = vec![0; 3 * width * height];
53///
54/// let mut dst = bayer::RasterMut::new(
55///         width, height, bayer::RasterDepth::Depth8,
56///         &mut buf);
57/// bayer::run_demosaic(&mut Cursor::new(&img[..]),
58///         bayer::BayerDepth::Depth8,
59///         bayer::CFA::RGGB,
60///         bayer::Demosaic::None,
61///         &mut dst);
62/// ```
63pub fn run_demosaic(r: &mut Read,
64        depth: BayerDepth, cfa: CFA, alg: Demosaic,
65        dst: &mut RasterMut)
66        -> BayerResult<()> {
67    match alg {
68        Demosaic::None => demosaic::none::run(r, depth, cfa, dst),
69        Demosaic::NearestNeighbour => demosaic::nearestneighbour::run(r, depth, cfa, dst),
70        Demosaic::Linear => demosaic::linear::run(r, depth, cfa, dst),
71        Demosaic::Cubic => demosaic::cubic::run(r, depth, cfa, dst),
72    }
73}