Skip to content

Commit

Permalink
image: add a to_rgb() function that runs the pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrocr committed Jan 21, 2017
1 parent b31c9ab commit 3f87859
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ use std::io::prelude::*;
use std::io::BufWriter;

extern crate rawloader;
use rawloader::decoders;

fn main() {
let args: Vec<_> = env::args().collect();
Expand Down Expand Up @@ -110,7 +109,7 @@ To do the image decoding decode the image the same way but then do:
// Decode to the largest image that fits in 1080p size. If the original image is
// smaller this will not scale up but otherwise you will get an image that is either
// 1920 pixels wide or 1080 pixels tall and maintains the image ratio.
let decoded = imageops::simple_decode(&image, 1920, 1080);
let decoded = image.to_rgb(1920, 1080).unwrap();

let mut f = BufWriter::new(File::create(format!("{}.ppm",file)).unwrap());
let preamble = format!("P6 {} {} {}\n", decoded.width, decoded.height, 255).into_bytes();
Expand Down
18 changes: 18 additions & 0 deletions src/decoders/image.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use decoders::*;
use decoders::cfa::*;
use imageops;

#[derive(Debug, Clone)]
pub struct RawImage {
Expand All @@ -19,6 +20,13 @@ pub struct RawImage {
pub crops: [usize;4],
}

#[derive(Debug, Clone)]
pub struct RGBImage {
pub width: usize,
pub height: usize,
pub data: Vec<f32>,
}

impl RawImage {
pub fn new(camera: &Camera, width: usize, height: usize, wb_coeffs: [f32;4], image: Vec<u16>) -> RawImage {
let blacks = if camera.blackareah.1 != 0 || camera.blackareav.1 != 0 {
Expand Down Expand Up @@ -170,4 +178,14 @@ impl RawImage {

out
}

pub fn to_rgb(&self, maxwidth: usize, maxheight: usize) -> Result<RGBImage,String> {
let buffer = imageops::simple_decode(self, maxwidth, maxheight);

Ok(RGBImage{
width: buffer.width,
height: buffer.height,
data: buffer.data,
})
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern crate itertools;
#[doc(hidden)] pub mod decoders;
pub use decoders::RawImage;
pub use decoders::cfa::CFA;
pub use decoders::RGBImage;
#[doc(hidden)] pub mod imageops;

lazy_static! {
Expand Down
3 changes: 1 addition & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::io::BufWriter;
extern crate time;
extern crate toml;
extern crate rawloader;
use rawloader::imageops;

fn usage() {
println!("rawloader <file> [outfile]");
Expand Down Expand Up @@ -65,7 +64,7 @@ fn main() {
println!("Image min: {}", min);
println!("Image max: {}", max);

let decoded = imageops::simple_decode(&image, 0, 0);
let decoded = image.to_rgb(0, 0).unwrap();

let uf = match File::create(outfile) {
Ok(val) => val,
Expand Down

0 comments on commit 3f87859

Please sign in to comment.