Crates.io | rawloader |
lib.rs | rawloader |
version | 0.37.1 |
source | src |
created_at | 2016-08-23 19:05:29.173356 |
updated_at | 2022-04-15 23:49:13.341175 |
description | A library to extract the data from camera raw formats |
homepage | |
repository | https://github.com/pedrocr/rawloader |
max_upload_size | |
id | 6086 |
size | 411,859 |
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 a work in process with the following formats already implemented:
1 DNG is a 101 page overambitious spec that tries to be an interchange format for processed images, complete with image transformation operations. We just implement enough of the spec so that actual raw files from DNG producing cameras or the Adobe DNG converter can be read.
2 Files that are just the raw data itself with no metadata whatsoever. The most common of these are the files generated by the Canon CHDK hacked firmware. Later versions produced actual DNG files but the first ones just did a dump of the raw data next to the JPG and assumed the user would use the JPG for the metadata. We match them by the filesize itself which means that if you feed rawloader with a file that has the exact same bytecount as these files you'll get a nice garbage output...
Here's a simple sample program that uses this library:
use std::env;
use std::fs::File;
use std::io::prelude::*;
use std::io::BufWriter;
fn main() {
let args: Vec<_> = env::args().collect();
if args.len() != 2 {
println!("Usage: {} <file>", args[0]);
std::process::exit(2);
}
let file = &args[1];
let image = rawloader::decode_file(file).unwrap();
// Write out the image as a grayscale PPM
let mut f = BufWriter::new(File::create(format!("{}.ppm",file)).unwrap());
let preamble = format!("P6 {} {} {}\n", image.width, image.height, 65535).into_bytes();
f.write_all(&preamble).unwrap();
if let rawloader::RawImageData::Integer(data) = image.data {
for pix in data {
// Do an extremely crude "demosaic" by setting R=G=B
let pixhigh = (pix>>8) as u8;
let pixlow = (pix&0x0f) as u8;
f.write_all(&[pixhigh, pixlow, pixhigh, pixlow, pixhigh, pixlow]).unwrap()
}
} else {
eprintln!("Don't know how to process non-integer raw files");
}
}
Bug reports and pull requests welcome at https://github.com/pedrocr/rawloader
Meet us at #chimper on irc.libera.chat if you need to discuss a feature or issue in detail or even just for general chat.