1 个不稳定版本
0.6.0 | 2024年1月6日 |
---|
#580 在 图像
1MB
26K SLoC
Rawler
数字相机原始格式库
什么是 Rawler?
Rawler 解析原始文件格式并提供对像素和所有元数据的访问。
为什么命名为 Rawler?
它是一个 (c)rawler,专门用于原始文件结构。
为什么还要另一个原始库?
- 有一些库处理元数据(exiv2)和像素(rawspeed,libraw),但没有同时处理两者的。每个库都带有自己的文件结构解析器。
- rawloader,这个库是这个库的基础,是一个相当好的库,但缺乏对元数据的支持。
- 为了乐趣。
lib.rs
:
一个用于从数字相机图像中提取原始数据和一些元数据的库。给定一个支持格式的图像和相机,您将能够获得处理图像所需的一切
示例
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 = rawler::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 rawler::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");
}
}
依赖项
~24–32MB
~317K SLoC