about summary refs log tree commit diff
path: root/prism
diff options
context:
space:
mode:
authorgennyble <gen@nyble.dev>2023-09-12 00:33:06 -0500
committergennyble <gen@nyble.dev>2023-09-12 00:33:06 -0500
commitcd7c97658279901120ede3d579de0322e4e5a6d2 (patch)
tree3516b20479e1ac72ac19917590cff54fdc9996d7 /prism
parentd451c304b76ce525cf9dfc9e2e2fee13f1b0f135 (diff)
downloadlri-rs-cd7c97658279901120ede3d579de0322e4e5a6d2.tar.gz
lri-rs-cd7c97658279901120ede3d579de0322e4e5a6d2.zip
before
Diffstat (limited to 'prism')
-rw-r--r--prism/Cargo.toml2
-rw-r--r--prism/src/main.rs68
2 files changed, 66 insertions, 4 deletions
diff --git a/prism/Cargo.toml b/prism/Cargo.toml
index 4601f43..d296b79 100644
--- a/prism/Cargo.toml
+++ b/prism/Cargo.toml
@@ -11,3 +11,5 @@ png = "0.17.10"
 rawproc = { git = "https://github.com/eclecticnybles/gaze" }
 rawloader = "0.37.1"
 nalgebra = "0.31.4"
+mozjpeg = "0.10.1"
+zune-jpeg = "0.3.17"
diff --git a/prism/src/main.rs b/prism/src/main.rs
index 5f4af1c..60baa18 100644
--- a/prism/src/main.rs
+++ b/prism/src/main.rs
@@ -1,4 +1,4 @@
-use lri_rs::{LriFile, RawImage, Whitepoint};
+use lri_rs::{DataFormat, LriFile, RawImage, Whitepoint};
 use nalgebra::{Matrix3, Matrix3x1};
 
 mod rotate;
@@ -15,7 +15,7 @@ fn main() {
 		.map(|raw| make(raw, String::from("reference.png")));
 
 	for (idx, img) in lri.images().enumerate() {
-		for color in &img.color {
+		/*for color in &img.color {
 			println!(
 				"{:?} rg = {}  bg = {}",
 				color.whitepoint, color.rg, color.bg
@@ -31,10 +31,11 @@ fn main() {
 			println!("\twhite: x = {} y = {} z = {}", white_x, white_y, white_z);
 
 			println!("\t{:?}", color.forward_matrix);
-		}
+		}*/
 		//std::process::exit(0);
 
 		make(img, format!("image_{idx}.png"));
+		return;
 	}
 }
 
@@ -48,7 +49,7 @@ fn make(img: &RawImage, path: String) {
 		width,
 		height,
 		format,
-		data,
+		mut data,
 		sbro,
 		color,
 	} = img;
@@ -58,6 +59,65 @@ fn make(img: &RawImage, path: String) {
 		sbro.0, sbro.1
 	);
 
+	let stem = &path[..path.len() - 4];
+
+	if *format == DataFormat::BayerJpeg {
+		//FF d9 | 42 4A 50 47
+		let bjp_end = &[0xFF, 0xd9, 0x42, 0x4A, 0x50, 0x47];
+		let jfif_start = &[0xFF, 0xD8, 0xFF, 0xE0];
+		let jfif_end = &[0xFF, 0xD9];
+
+		for idx in 0..data.len() {
+			if &data[idx..idx + 6] == bjp_end {
+				data = &data[..idx + 2];
+				break;
+			}
+		}
+
+		let mut start = None;
+		let mut idx = 0;
+		let mut jfif_count = 0;
+		loop {
+			if idx >= data.len() {
+				break;
+			}
+
+			match start {
+				None => {
+					if &data[idx..idx + 4] == jfif_start {
+						start = Some(idx);
+
+						if jfif_count == 0 {
+							let path = format!("{stem}_only.bjp");
+							let out = &data[..idx];
+							std::fs::write(path, out).unwrap();
+						}
+
+						idx += 4;
+						continue;
+					}
+				}
+				Some(start_idx) => {
+					if &data[idx..idx + 2] == jfif_end {
+						let path = format!("{stem}_{jfif_count}.jpg");
+						let out = &data[start_idx..idx + 2];
+						std::fs::write(path, out).unwrap();
+
+						start = None;
+						jfif_count += 1;
+						idx += 2;
+						continue;
+					}
+				}
+			}
+
+			idx += 1;
+		}
+
+		std::fs::write(format!("{}.bjp", &path[..path.len() - 4]), data).unwrap();
+		return;
+	}
+
 	// Assume 10-bit
 	let size = width * height;
 	let mut ten_data = vec![0; size];