diff options
-rw-r--r-- | lri-rs/Cargo.toml | 4 | ||||
-rw-r--r-- | lri-rs/build.rs | 86 | ||||
-rw-r--r-- | src/main.rs | 84 |
3 files changed, 127 insertions, 47 deletions
diff --git a/lri-rs/Cargo.toml b/lri-rs/Cargo.toml index a93f7a3..844806b 100644 --- a/lri-rs/Cargo.toml +++ b/lri-rs/Cargo.toml @@ -7,10 +7,10 @@ edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -protobuf = { version = "2.22.0", features = ["with-bytes"] } +protobuf = { version = "3.2", features = ["with-bytes"] } serde = "1.0" image = "0.23.14" anyhow = "1.0" [build-dependencies] -protobuf-codegen-pure = "2.22.0" +protobuf-codegen = "3" diff --git a/lri-rs/build.rs b/lri-rs/build.rs index 559ba5c..35ae756 100644 --- a/lri-rs/build.rs +++ b/lri-rs/build.rs @@ -1,52 +1,50 @@ use std::fs; -use protobuf_codegen_pure::Customize; +use protobuf_codegen::Customize; use std::path::Path; fn main() { - let proto_dir = "src/proto"; + let proto_dir = "src/proto"; - if Path::new(&proto_dir).exists() { - fs::remove_dir_all(&proto_dir).unwrap(); - } - fs::create_dir(&proto_dir).unwrap(); + if Path::new(&proto_dir).exists() { + fs::remove_dir_all(&proto_dir).unwrap(); + } + fs::create_dir(&proto_dir).unwrap(); - protobuf_codegen_pure::Codegen::new() - .customize(Customize { - gen_mod_rs: Some(true), - ..Default::default() - }) - .out_dir(proto_dir) - .input("proto/camera_id.proto") - .input("proto/camera_module.proto") - .input("proto/color_calibration.proto") - .input("proto/dead_pixel_map.proto") - .input("proto/device_temp.proto") - .input("proto/distortion.proto") - .input("proto/face_data.proto") - .input("proto/flash_calibration.proto") - .input("proto/geometric_calibration.proto") - .input("proto/gps_data.proto") - .input("proto/hot_pixel_map.proto") - .input("proto/hw_info.proto") - .input("proto/imu_data.proto") - .input("proto/lightheader.proto") - .input("proto/matrix3x3f.proto") - .input("proto/matrix4x4f.proto") - .input("proto/mirror_system.proto") - .input("proto/point2f.proto") - .input("proto/point2i.proto") - .input("proto/point3f.proto") - .input("proto/proximity_sensors.proto") - .input("proto/range2f.proto") - .input("proto/rectanglei.proto") - .input("proto/sensor_characterization.proto") - .input("proto/sensor_type.proto") - .input("proto/time_stamp.proto") - .input("proto/tof_calibration.proto") - .input("proto/view_preferences.proto") - .input("proto/vignetting_characterization.proto") - .include("proto") - .run() - .unwrap(); + protobuf_codegen::Codegen::new() + .pure() + .customize(Customize::default().gen_mod_rs(true)) + .out_dir(proto_dir) + .input("proto/camera_id.proto") + .input("proto/camera_module.proto") + .input("proto/color_calibration.proto") + .input("proto/dead_pixel_map.proto") + .input("proto/device_temp.proto") + .input("proto/distortion.proto") + .input("proto/face_data.proto") + .input("proto/flash_calibration.proto") + .input("proto/geometric_calibration.proto") + .input("proto/gps_data.proto") + .input("proto/hot_pixel_map.proto") + .input("proto/hw_info.proto") + .input("proto/imu_data.proto") + .input("proto/lightheader.proto") + .input("proto/matrix3x3f.proto") + .input("proto/matrix4x4f.proto") + .input("proto/mirror_system.proto") + .input("proto/point2f.proto") + .input("proto/point2i.proto") + .input("proto/point3f.proto") + .input("proto/proximity_sensors.proto") + .input("proto/range2f.proto") + .input("proto/rectanglei.proto") + .input("proto/sensor_characterization.proto") + .input("proto/sensor_type.proto") + .input("proto/time_stamp.proto") + .input("proto/tof_calibration.proto") + .input("proto/view_preferences.proto") + .input("proto/vignetting_characterization.proto") + .include("proto") + .run() + .unwrap(); } diff --git a/src/main.rs b/src/main.rs index 60045b1..7a2634b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,7 +39,7 @@ fn main() { if block.is_sensor() { println!("\nIDX {idx}"); block.header.print_info(); - println!(""); + fuckwithsensordata(block, idx); } else { block.header.nice_info(); } @@ -164,6 +164,88 @@ fn main() { }*/ } +fn fuckwithsensordata(block: &Block, idx: usize) { + let Block { header, data } = block; + + let clen = header.combined_length; + let hlen = header.header_length; + let mlen = header.message_length; + + println!("\n== Fuck With Sensor Data {idx} =="); + + println!("Combined: {clen}"); + println!("Header: {hlen}"); + println!("Message: {mlen}\n"); + + let width = 4160; + let height = 3120; + let pixel_count = width * height; + let packed_count = ((pixel_count as f32 * 10.0) / 8.0) as usize; + + println!("Assuming {width}x{height} [{pixel_count}] [packed: {packed_count}]"); + + let mut data = block.body(); + // I'm lazy and don't want to manually increment + for x in 0..10 { + let fname = format!("block{idx}_image{x}.png"); + + // Use my really efficient (read that sarcastically, please) 10-bit unpacker + let mut up = Unpacker::new(); + for idx in (0..packed_count).rev() { + up.push(data[idx]); + } + up.finish(); + + // Sixteen - eightbits + let mut imgdata = vec![]; + for chnk in up.out.chunks(2) { + let sixteen = (u16::from_le_bytes([chnk[0], chnk[1]]) as f32 / 1024.0) * 255.0; + + imgdata.push(sixteen.min(255.0) as u8); + } + + // we want it to be RGB not weird bayer + let rawimg: Image<u8, BayerRgb> = Image::from_raw_parts( + width, + height, + // use mostly fake data except the CFA + RawMetadata { + whitebalance: [1.0, 1.0, 1.0], + whitelevels: [1024, 1024, 1024], + crop: None, + cfa: CFA::new("BGGR"), + cam_to_xyz: Matrix3::new(1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0), + }, + imgdata, + ); + let img = rawimg.debayer(); + + // Yay PNG + make_png( + &fname, + width, + height, + ColorType::Rgb, + BitDepth::Eight, + &img.data, + ); + println!("Wrote file {fname}"); + + let skip = packed_count + mlen as usize; + if data.len() <= skip + packed_count { + println!( + "Only {} bytes will be left in data after output! Which is not enough", + data.len() - skip + ); + break; + } else { + data = &data[skip..] + } + } + + println!("===================================\n"); +} + fn dump(data: &[u8], path: &str) { let mut file = File::create(&path).unwrap(); file.write_all(data).unwrap(); |