diff options
-rw-r--r-- | lri-rs/src/block.rs | 10 | ||||
-rw-r--r-- | lri-rs/src/fine.rs | 144 | ||||
-rw-r--r-- | lri-rs/src/lib.rs | 13 | ||||
-rw-r--r-- | lri-study/.gitignore | 1 | ||||
-rw-r--r-- | lri-study/src/main.rs | 11 |
5 files changed, 173 insertions, 6 deletions
diff --git a/lri-rs/src/block.rs b/lri-rs/src/block.rs index 19e7294..d973430 100644 --- a/lri-rs/src/block.rs +++ b/lri-rs/src/block.rs @@ -6,7 +6,8 @@ use lri_proto::{ }; use crate::{ - CameraId, CameraInfo, ColorInfo, DataFormat, HdrMode, RawData, RawImage, SceneMode, SensorModel, + fine::Signature, CameraId, CameraInfo, ColorInfo, DataFormat, HdrMode, RawData, RawImage, + SceneMode, SensorModel, }; pub(crate) struct Block<'lri> { @@ -45,6 +46,7 @@ impl<'lri> Block<'lri> { images: &mut Vec<RawImage<'lri>>, colors: &mut Vec<ColorInfo>, infos: &mut Vec<CameraInfo>, + sig: &mut Signature, ) { let LightHeader { mut hw_info, @@ -54,8 +56,10 @@ impl<'lri> Block<'lri> { device_fw_version, image_focal_length, af_info, + mut view_preferences, .. } = if let Message::LightHeader(lh) = self.message() { + sig.merge(&lh); lh } else if let Message::ViewPreferences(vp) = self.message() { self.extract_view(vp, ext); @@ -76,6 +80,10 @@ impl<'lri> Block<'lri> { } } + if let Some(vp) = view_preferences.take() { + self.extract_view(vp, ext); + } + // Color information for the Camera moduels. for mcal in module_calibration { let camera = mcal.camera_id().into(); diff --git a/lri-rs/src/fine.rs b/lri-rs/src/fine.rs new file mode 100644 index 0000000..52b2527 --- /dev/null +++ b/lri-rs/src/fine.rs @@ -0,0 +1,144 @@ +use std::collections::HashMap; + +use lri_proto::{lightheader::LightHeader, view_preferences::ViewPreferences}; + +#[derive(Debug)] +pub struct Signature { + pub lh: HashMap<&'static str, Vec<String>>, + pub vp: HashMap<&'static str, Vec<String>>, +} + +impl Signature { + pub fn new() -> Self { + Self { + lh: HashMap::new(), + vp: HashMap::new(), + } + } + + pub fn merge(&mut self, lh: &LightHeader) { + let LightHeader { + image_unique_id_low, + image_unique_id_high, + image_time_stamp, + image_focal_length, + image_reference_camera, + device_unique_id_low, + device_unique_id_high, + device_model_name, + device_fw_version, + device_asic_fw_version, + device_temperature, + modules, + module_calibration, + device_calibration, + gold_cc, + sensor_data, + tof_range, + hw_info, + view_preferences, + proximity_sensors, + flash_data, + imu_data, + af_info, + gps_data, + compatibility, + face_data, + special_fields, + } = lh; + + macro_rules! hh { + ($field:ident) => { + let i = match $field { + Some(v) => vec![v.to_string()], + None => vec![], + }; + + self.lh + .entry(stringify!($field)) + .and_modify(|v| v.extend_from_slice(&i)) + .or_insert(i); + }; + } + + macro_rules! mf { + ($field:ident) => { + let add = if $field.is_some() { 1 } else { 0 }; + + self.lh + .entry(stringify!($field)) + .and_modify(|count| *count += add) + .or_insert(add); + }; + } + + macro_rules! hv { + ($field:ident) => { + let add = $field.len(); + + self.lh + .entry(stringify!($field)) + .and_modify(|count| *count += add) + .or_insert(add); + }; + } + + hh!(image_unique_id_low); + hh!(image_unique_id_high); + mf!(image_time_stamp); + hh!(image_focal_length); + hh!(image_reference_camera); + hh!(device_unique_id_low); + hh!(device_unique_id_high); + hh!(device_model_name); + hh!(device_fw_version); + hh!(device_asic_fw_version); + mf!(device_temperature); + hv!(modules); + hv!(module_calibration); + mf!(device_calibration); + hv!(gold_cc); + hv!(sensor_data); + hh!(tof_range); + mf!(hw_info); + mf!(view_preferences); + mf!(proximity_sensors); + mf!(flash_data); + hv!(imu_data); + mf!(af_info); + mf!(gps_data); + mf!(compatibility); + hv!(face_data); + } + + pub fn vp(&mut self, vp: &ViewPreferences) {} +} + +/* +optional uint64 image_unique_id_low = 1; +optional uint64 image_unique_id_high = 2; +optional TimeStamp image_time_stamp = 3; +optional int32 image_focal_length = 4; +optional CameraID image_reference_camera = 5; +optional uint64 device_unique_id_low = 6; +optional uint64 device_unique_id_high = 7; +optional string device_model_name = 8; +optional string device_fw_version = 9; +optional string device_asic_fw_version = 10; +optional DeviceTemp device_temperature = 11; +repeated CameraModule modules = 12; +repeated FactoryModuleCalibration module_calibration = 13; +optional FactoryDeviceCalibration device_calibration = 14; +repeated ColorCalibrationGold gold_cc = 15; +repeated SensorData sensor_data = 16; +optional float tof_range = 17; +optional HwInfo hw_info = 18; +optional ViewPreferences view_preferences = 19; +optional ProximitySensors proximity_sensors = 20; +optional FlashData flash_data = 22; +repeated IMUData imu_data = 23; +optional AFDebugInfo af_info = 24; +optional GPSData gps_data = 25; +optional Compatibility compatibility = 26; +repeated FaceData face_data = 27; +*/ diff --git a/lri-rs/src/lib.rs b/lri-rs/src/lib.rs index ee1b928..c136669 100644 --- a/lri-rs/src/lib.rs +++ b/lri-rs/src/lib.rs @@ -1,6 +1,7 @@ use std::{fmt, time::Duration}; use block::{Block, ExtractedData, Header}; +use fine::Signature; use lri_proto::{ camera_id::CameraID as PbCameraID, camera_module::camera_module::surface::FormatType, color_calibration::color_calibration::IlluminantType, @@ -8,6 +9,7 @@ use lri_proto::{ }; mod block; +mod fine; pub struct LriFile<'lri> { pub image_reference_camera: Option<CameraId>, @@ -23,6 +25,7 @@ pub struct LriFile<'lri> { pub hdr: Option<HdrMode>, pub scene: Option<SceneMode>, pub on_tripod: Option<bool>, + pub sig: Signature, } impl<'lri> LriFile<'lri> { @@ -33,6 +36,7 @@ impl<'lri> LriFile<'lri> { let mut camera_infos = vec![]; let mut ext = ExtractedData::default(); + let mut sig = Signature::new(); // Read data blocks and extract informtion we care about loop { @@ -51,7 +55,13 @@ impl<'lri> LriFile<'lri> { data: block_data, }; - block.extract_meaningful_data(&mut ext, &mut images, &mut colors, &mut camera_infos); + block.extract_meaningful_data( + &mut ext, + &mut images, + &mut colors, + &mut camera_infos, + &mut sig, + ); } // Further fill in the RawImage's we extracted @@ -83,6 +93,7 @@ impl<'lri> LriFile<'lri> { hdr: ext.hdr, scene: ext.scene, on_tripod: ext.on_tripod, + sig, } } diff --git a/lri-study/.gitignore b/lri-study/.gitignore new file mode 100644 index 0000000..f923e39 --- /dev/null +++ b/lri-study/.gitignore @@ -0,0 +1 @@ +dbg \ No newline at end of file diff --git a/lri-study/src/main.rs b/lri-study/src/main.rs index ac14c45..962fc26 100644 --- a/lri-study/src/main.rs +++ b/lri-study/src/main.rs @@ -7,8 +7,6 @@ use camino::Utf8PathBuf; use lri_rs::{DataFormat, HdrMode, LriFile, SceneMode, SensorModel}; use owo_colors::OwoColorize; -const DATA: &'static str = "/Users/gen/thanks_lak"; - fn main() { match std::env::args().nth(1).as_deref() { Some("gather") => gather(), @@ -17,7 +15,8 @@ fn main() { } fn gather() -> ! { - let data_dir = Utf8PathBuf::from(DATA); + let path = std::env::args().nth(2).unwrap(); + let data_dir = Utf8PathBuf::from(path); let mut files: HashMap<String, Photo> = HashMap::new(); for entry in data_dir.read_dir_utf8().unwrap() { @@ -51,7 +50,7 @@ fn gather() -> ! { let mut photos: Vec<Photo> = files.into_values().collect(); photos.sort_by(|a, b| a.lri.as_deref().unwrap().cmp(b.lri.as_deref().unwrap())); - for photo in photos { + for (idx, photo) in photos.into_iter().enumerate() { let lri_path = match photo.lri { Some(p) => p, None => continue, @@ -67,6 +66,10 @@ fn gather() -> ! { print!("{} - ", lri_path.file_stem().unwrap()); + let path = format!("{}_{idx}", lri_path.file_stem().unwrap_or_default()); + let dbg = format!("{:#?}", lri.sig); + std::fs::write(path, dbg.as_bytes()).unwrap(); + if let Some(fwv) = lri.firmware_version.as_ref() { print!( "[{}] focal:{:<3} iit:{:>2}ms gain:{:2.0} ", |