This is a rust library to extract the raw data and some metadata from digital camera images. Given an image in a supported format and camera you will be able to get everything needed to process the image:
The library is still in its very beginning with only the simple Minolta MRW format implemented.
Here's a simple sample program that uses this library:
```rust use std::env; use std::fs::File; use std::io::prelude::*;
extern crate rawloader; use rawloader::decoders;
fn main() {
let args: Vec<_> = env::args().collect();
if args.len() != 2 {
println!("Usage: {}
let mut f = File::open(file).unwrap(); let mut buffer = Vec::new(); f.readtoend(&mut buffer).unwrap();
let rawloader = decoders::RawLoader::new(); let decoder = rawloader.get_decoder(&buffer).unwrap(); let camera = decoder.identify().unwrap(); println!("Found camera \"{}\" model \"{}\"", camera.make, camera.model);
let image = decoder.image(); println!("Image size is {}x{}", image.width, image.height); println!("WB coeffs are {},{},{},{}", image.wbcoeffs[0], image.wbcoeffs[1], image.wbcoeffs[2], image.wbcoeffs[3]);
// Write out the image as a grayscale PPM in an extremely inneficient way let mut f = File::create(format!("{}.ppm",file)).unwrap(); let preamble = format!("P6 {} {} {}\n", image.width, image.height, 4095).intobytes(); f.writeall(&preamble).unwrap(); for row in 0..image.height { let from: usize = (row as usize) * (image.width as usize); let to: usize = ((row+1) as usize) * (image.width as usize); let imgline = &image.data[from .. to];
for pixel in imgline {
// Do an extremely crude "demosaic" by setting R=G=B
let bytes = [(pixel>>4) as u8, (pixel&0x0f) as u8, (pixel>>4) as u8, (pixel&0x0f) as u8, (pixel>>4) as u8, (pixel&0x0f) as u8];
f.write_all(&bytes).unwrap();
}
} } ```
Bug reports and pull requests welcome at https://github.com/pedrocr/rawloader