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
//! This crate provides routines for demosaicing Bayer raw images.

extern crate byteorder;
extern crate libc;

#[cfg(feature = "rayon")]
extern crate rayon;

#[macro_use]
extern crate quick_error;

use std::io::Read;

pub use bayer::BayerDepth;
pub use bayer::CFA;
pub use demosaic::Demosaic;
pub use errcode::BayerError;
pub use errcode::BayerResult;
pub use raster::RasterDepth;

/// Mutable raster structure.
pub struct RasterMut<'a> {
    x: usize,
    y: usize,
    w: usize,
    h: usize,
    stride: usize,
    depth: RasterDepth,
    buf: &'a mut [u8],
}

pub mod demosaic;
pub mod ffi;

mod bayer;
mod border_mirror;
mod border_none;
mod border_replicate;
mod errcode;
mod raster;

/// Run the demosaicing algorithm on the Bayer image.
///
/// # Example
///
/// ```
/// use std::io::Cursor;
///
/// let width: usize = 320;
/// let height: usize = 200;
/// let img = vec![0; width * height];
/// let mut buf = vec![0; 3 * width * height];
///
/// let mut dst = bayer::RasterMut::new(
///         width, height, bayer::RasterDepth::Depth8,
///         &mut buf);
/// bayer::run_demosaic(&mut Cursor::new(&img[..]),
///         bayer::BayerDepth::Depth8,
///         bayer::CFA::RGGB,
///         bayer::Demosaic::None,
///         &mut dst);
/// ```
pub fn run_demosaic(r: &mut Read,
        depth: BayerDepth, cfa: CFA, alg: Demosaic,
        dst: &mut RasterMut)
        -> BayerResult<()> {
    match alg {
        Demosaic::None => demosaic::none::run(r, depth, cfa, dst),
        Demosaic::NearestNeighbour => demosaic::nearestneighbour::run(r, depth, cfa, dst),
        Demosaic::Linear => demosaic::linear::run(r, depth, cfa, dst),
        Demosaic::Cubic => demosaic::cubic::run(r, depth, cfa, dst),
    }
}