1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
use std::collections::HashMap;
use camino::Utf8PathBuf;
use lri_rs::{AwbGain, CameraId, LriFile, RawData, RawImage, SensorModel, Whitepoint};
use nalgebra::{Matrix3, Matrix3x1};
mod output;
mod rotate;
pub struct Entry {
sensor: SensorModel,
count: usize,
}
fn main() {
let args = std::env::args().skip(1);
if args.len() != 2 {
eprintln!("Usage: prism <lri_file> <output_directory>");
std::process::exit(1);
}
let file_name = std::env::args().nth(1).unwrap();
let directory = Utf8PathBuf::from(std::env::args().nth(2).unwrap());
if !directory.exists() {
std::fs::create_dir_all(&directory).unwrap();
}
let bytes = std::fs::read(file_name).unwrap();
let lri = LriFile::decode(&bytes);
let gain = lri.awb_gain.unwrap();
println!("{} images", lri.image_count());
if let Some(refimg) = lri.reference_image() {
output::make_png(refimg, directory.join("reference.png"), gain);
}
let mut set: HashMap<CameraId, Entry> = HashMap::new();
for img in lri.images() {
set.entry(img.camera)
.and_modify(|e| e.count += 1)
.or_insert(Entry {
sensor: img.sensor,
count: 1,
});
}
/*set.into_iter().for_each(|kv| {
println!("{} {:?} {}", kv.0, kv.1.sensor, kv.1.count);
});*/
for (idx, img) in lri.images().enumerate() {
output::make_png(img, directory.join(format!("image_{idx}.png")), gain);
}
}
|