Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "bayer"
version = "0.1.5"
version = "0.2.0"
edition = "2021"
authors = ["David Wang <millimillenary@gmail.com>"]
homepage = "https://github.com/wangds/libbayer.git"
repository = "https://github.com/wangds/libbayer.git"
Expand All @@ -23,14 +24,14 @@ default = ["rayon"]
bench = []

[dependencies]
byteorder = "1.1"
libc = "0.2"
rayon = { version = "0.8", optional = true }
quick-error = "1.2"
byteorder = "1.4.3"
libc = "0.2.138"
rayon = { version = "1.6.1", optional = true }
quick-error = "2"

[dev-dependencies]
flic = "0.1"
sdl2 = { version = "0.30", features = ["image"] }
flic = "0.1.6"
sdl2 = { version = "0.35.2", features = ["image"] }

[badges]
travis-ci = { repository = "wangds/libbayer" }
travis-ci = { repository = "virtualritz/libbayer" }
58 changes: 16 additions & 42 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,25 @@
# `bayer`

LibBayer [![Version][version-img]][version-url] [![Status][travis-ci-img]][travis-ci-url]
========
[![Version][version-img]][version-url] [![Status][travis-ci-img]][travis-ci-url]

Routines for demosaicing Bayer sensor (RAW) images.

About
-----
Both 8-bit and 16-bit images are supported.

LibBayer provides routines for demosaicing Bayer (raw) images.

The library supports 8-bit and 16-bit images.

Several demosaicing algorithms are available. See the src/demosaic
Several demosaicing algorithms are available. See the `src/demosaic`
directory for a list and their individual descriptions. Pixels on the
border of the image are retained by replicating or mirroring the data
in the neighbourhood.

LibBayer is written entirely in Rust. C bindings to the underlying
The crate is written entirely in Rust. C bindings to the underlying
algorithms are provided.

## Examples

Examples
--------

An example program is provided in the `examples/` directory:

* _showbayer_ - a simple Bayer file viewer.
* _writebayer_ - converts an image to a raw Bayer image file.

To clone this repository, run:
* `showbayer` – a simple Bayer file viewer.
* `writebayer` – converts an image to a raw Bayer image file.

```sh
git clone https://github.com/wangds/libbayer.git
```

Then build the library and run the example programs using Cargo.
Run the examples programs using `cargo`.

```sh
cargo build --release --example showbayer
Expand All @@ -48,24 +34,15 @@ cargo run --release --example showbayer <width> <height> <depth> <example.raw>
Change the colour filter array (CFA) pattern and the demosaicing
algorithm from inside the example program.

## Basic Usage


Basic Usage
-----------

Add LibBayer as a dependency to your project's Cargo.toml:
Add `bayer` as a dependency to your project's `Cargo.toml`:

```toml
[dependencies]
bayer = "0.1"
```

Import the library in your project, e.g.:

```rust
extern crate bayer;
```

Open a Bayer file from disk.

```rust
Expand All @@ -84,6 +61,7 @@ let img_h = 200;
let depth = bayer::RasterDepth::Depth8;
let bytes_per_pixel = 3;
let mut buf = vec![0; bytes_per_pixel * img_w * img_h];

let mut dst = bayer::RasterMut::new(img_w, img_h, depth, &mut buf);
```

Expand All @@ -92,26 +70,22 @@ Then run the demosaicing process:
```rust
let cfa = bayer::CFA::RGGB;
let alg = bayer::Demosaic::Linear;

bayer::run_demosaic(&mut file, bayer::BayerDepth:Depth8, cfa, alg, &mut dst);
```

Note that many cameras will capture 12-bits per pixel (channel), but
store the data as 16-bits per pixel. These should be treated as
16-bits per pixel for the purposes of this library.


Documentation
-------------
## Documentation

* [Documentation][documentation].


Author
------
## Author

David Wang


[documentation]: https://docs.rs/bayer/
[travis-ci-img]: https://travis-ci.org/wangds/libbayer.svg?branch=master
[travis-ci-url]: https://travis-ci.org/wangds/libbayer
Expand Down
117 changes: 81 additions & 36 deletions benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@

#[cfg(all(feature = "bench", test))]
mod bench {
extern crate bayer;
extern crate test;

use std::io::Cursor;
use self::bayer::*;
use std::io::Cursor;

const IMG_W: usize = 128;
const IMG_H: usize = 128;
Expand All @@ -20,65 +17,113 @@ mod bench {

#[bench]
fn bench_none_u8(b: &mut test::Bencher) {
let mut dst = unsafe{ RasterMut::new(
IMG_W, IMG_H, RasterDepth::Depth8, &mut BUF_U8) };
b.iter(|| run_demosaic(&mut Cursor::new(&SRC_U8[..]),
BayerDepth::Depth8, CFA::RGGB, Demosaic::None, &mut dst));
let mut dst = unsafe { RasterMut::new(IMG_W, IMG_H, RasterDepth::Depth8, &mut BUF_U8) };
b.iter(|| {
run_demosaic(
&mut Cursor::new(&SRC_U8[..]),
BayerDepth::Depth8,
CFA::RGGB,
Demosaic::None,
&mut dst,
)
});
}

#[bench]
fn bench_none_u16(b: &mut test::Bencher) {
let mut dst = unsafe{ RasterMut::new(
IMG_W, IMG_H, RasterDepth::Depth16, &mut BUF_U16) };
b.iter(|| run_demosaic(&mut Cursor::new(&SRC_U16[..]),
BayerDepth::Depth16LE, CFA::RGGB, Demosaic::None, &mut dst));
let mut dst = unsafe { RasterMut::new(IMG_W, IMG_H, RasterDepth::Depth16, &mut BUF_U16) };
b.iter(|| {
run_demosaic(
&mut Cursor::new(&SRC_U16[..]),
BayerDepth::Depth16LE,
CFA::RGGB,
Demosaic::None,
&mut dst,
)
});
}

#[bench]
fn bench_nearest_neighbour_u8(b: &mut test::Bencher) {
let mut dst = unsafe{ RasterMut::new(
IMG_W, IMG_H, RasterDepth::Depth8, &mut BUF_U8) };
b.iter(|| run_demosaic(&mut Cursor::new(&SRC_U8[..]),
BayerDepth::Depth8, CFA::RGGB, Demosaic::NearestNeighbour, &mut dst));
let mut dst = unsafe { RasterMut::new(IMG_W, IMG_H, RasterDepth::Depth8, &mut BUF_U8) };
b.iter(|| {
run_demosaic(
&mut Cursor::new(&SRC_U8[..]),
BayerDepth::Depth8,
CFA::RGGB,
Demosaic::NearestNeighbour,
&mut dst,
)
});
}

#[bench]
fn bench_nearest_neighbour_u16(b: &mut test::Bencher) {
let mut dst = unsafe{ RasterMut::new(
IMG_W, IMG_H, RasterDepth::Depth16, &mut BUF_U16) };
b.iter(|| run_demosaic(&mut Cursor::new(&SRC_U16[..]),
BayerDepth::Depth16LE, CFA::RGGB, Demosaic::NearestNeighbour, &mut dst));
let mut dst = unsafe { RasterMut::new(IMG_W, IMG_H, RasterDepth::Depth16, &mut BUF_U16) };
b.iter(|| {
run_demosaic(
&mut Cursor::new(&SRC_U16[..]),
BayerDepth::Depth16LE,
CFA::RGGB,
Demosaic::NearestNeighbour,
&mut dst,
)
});
}

#[bench]
fn bench_linear_u8(b: &mut test::Bencher) {
let mut dst = unsafe{ RasterMut::new(
IMG_W, IMG_H, RasterDepth::Depth8, &mut BUF_U8) };
b.iter(|| run_demosaic(&mut Cursor::new(&SRC_U8[..]),
BayerDepth::Depth8, CFA::RGGB, Demosaic::Linear, &mut dst));
let mut dst = unsafe { RasterMut::new(IMG_W, IMG_H, RasterDepth::Depth8, &mut BUF_U8) };
b.iter(|| {
run_demosaic(
&mut Cursor::new(&SRC_U8[..]),
BayerDepth::Depth8,
CFA::RGGB,
Demosaic::Linear,
&mut dst,
)
});
}

#[bench]
fn bench_linear_u16(b: &mut test::Bencher) {
let mut dst = unsafe{ RasterMut::new(
IMG_W, IMG_H, RasterDepth::Depth16, &mut BUF_U16) };
b.iter(|| run_demosaic(&mut Cursor::new(&SRC_U16[..]),
BayerDepth::Depth16LE, CFA::RGGB, Demosaic::Linear, &mut dst));
let mut dst = unsafe { RasterMut::new(IMG_W, IMG_H, RasterDepth::Depth16, &mut BUF_U16) };
b.iter(|| {
run_demosaic(
&mut Cursor::new(&SRC_U16[..]),
BayerDepth::Depth16LE,
CFA::RGGB,
Demosaic::Linear,
&mut dst,
)
});
}

#[bench]
fn bench_cubic_u8(b: &mut test::Bencher) {
let mut dst = unsafe{ RasterMut::new(
IMG_W, IMG_H, RasterDepth::Depth8, &mut BUF_U8) };
b.iter(|| run_demosaic(&mut Cursor::new(&SRC_U8[..]),
BayerDepth::Depth8, CFA::RGGB, Demosaic::Cubic, &mut dst));
let mut dst = unsafe { RasterMut::new(IMG_W, IMG_H, RasterDepth::Depth8, &mut BUF_U8) };
b.iter(|| {
run_demosaic(
&mut Cursor::new(&SRC_U8[..]),
BayerDepth::Depth8,
CFA::RGGB,
Demosaic::Cubic,
&mut dst,
)
});
}

#[bench]
fn bench_cubic_u16(b: &mut test::Bencher) {
let mut dst = unsafe{ RasterMut::new(
IMG_W, IMG_H, RasterDepth::Depth16, &mut BUF_U16) };
b.iter(|| run_demosaic(&mut Cursor::new(&SRC_U16[..]),
BayerDepth::Depth16LE, CFA::RGGB, Demosaic::Cubic, &mut dst));
let mut dst = unsafe { RasterMut::new(IMG_W, IMG_H, RasterDepth::Depth16, &mut BUF_U16) };
b.iter(|| {
run_demosaic(
&mut Cursor::new(&SRC_U16[..]),
BayerDepth::Depth16LE,
CFA::RGGB,
Demosaic::Cubic,
&mut dst,
)
});
}
}
Loading