Skip to content

Commit

Permalink
Raw-rs: Fix naming convention of matrices (#2071)
Browse files Browse the repository at this point in the history
Fix naming convention of matrices
  • Loading branch information
elbertronnie authored Oct 25, 2024
1 parent 442937c commit 36fe9bf
Show file tree
Hide file tree
Showing 47 changed files with 54 additions and 59 deletions.
2 changes: 1 addition & 1 deletion libraries/raw-rs/build-camera-data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn build_camera_data(_: TokenStream) -> TokenStream {

let mut values: Table = toml::from_str(&fs::read_to_string(model_path).unwrap()).unwrap();

if let Some(val) = values.get_mut("camera_to_xyz") {
if let Some(val) = values.get_mut("xyz_to_camera") {
*val = Value::Array(val.as_array().unwrap().iter().map(|x| Value::Integer((x.as_float().unwrap() * 10_000.) as i64)).collect());
}

Expand Down
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/DSLR-A100.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.9437, -0.2812, -0.0774, -0.8405, 1.6215, 0.2291, -0.0709, 0.0596, 0.7181]
xyz_to_camera = [0.9437, -0.2812, -0.0774, -0.8405, 1.6215, 0.2291, -0.0709, 0.0596, 0.7181]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/DSLR-A200.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.9847, -0.3091, -0.0929, -0.8485, 1.6346, 0.2225, -0.0714, 0.0595, 0.7103]
xyz_to_camera = [0.9847, -0.3091, -0.0929, -0.8485, 1.6346, 0.2225, -0.0714, 0.0595, 0.7103]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/DSLR-A300.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.9847, -0.3091, -0.0929, -0.8485, 1.6346, 0.2225, -0.0714, 0.0595, 0.7103]
xyz_to_camera = [0.9847, -0.3091, -0.0929, -0.8485, 1.6346, 0.2225, -0.0714, 0.0595, 0.7103]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/DSLR-A330.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.9847, -0.3091, -0.0929, -0.8485, 1.6346, 0.2225, -0.0714, 0.0595, 0.7103]
xyz_to_camera = [0.9847, -0.3091, -0.0929, -0.8485, 1.6346, 0.2225, -0.0714, 0.0595, 0.7103]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/DSLR-A350.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.6038, -0.1484, -0.0579, -0.9145, 1.6746, 0.2512, -0.0875, 0.0746, 0.7218]
xyz_to_camera = [0.6038, -0.1484, -0.0579, -0.9145, 1.6746, 0.2512, -0.0875, 0.0746, 0.7218]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/DSLR-A550.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.4950, -0.0580, -0.0103, -0.5228, 1.2542, 0.3029, -0.0709, 0.1435, 0.7371]
xyz_to_camera = [0.4950, -0.0580, -0.0103, -0.5228, 1.2542, 0.3029, -0.0709, 0.1435, 0.7371]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/DSLR-A700.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.5775, -0.0805, -0.0359, -0.8573, 1.6294, 0.2391, -0.1943, 0.2342, 0.7249]
xyz_to_camera = [0.5775, -0.0805, -0.0359, -0.8573, 1.6294, 0.2391, -0.1943, 0.2342, 0.7249]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/DSLR-A850.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.5413, -0.1162, -0.0365, -0.5665, 1.3098, 0.2866, -0.0608, 0.1179, 0.8440]
xyz_to_camera = [0.5413, -0.1162, -0.0365, -0.5665, 1.3098, 0.2866, -0.0608, 0.1179, 0.8440]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/DSLR-A900.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.5209, -0.1072, -0.0397, -0.8845, 1.6121, 0.2919, -0.1618, 0.1802, 0.8654]
xyz_to_camera = [0.5209, -0.1072, -0.0397, -0.8845, 1.6121, 0.2919, -0.1618, 0.1802, 0.8654]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCA-68.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.6435, -0.1903, -0.0536, -0.4722, 1.2449, 0.2550, -0.0663, 0.1363, 0.6517]
xyz_to_camera = [0.6435, -0.1903, -0.0536, -0.4722, 1.2449, 0.2550, -0.0663, 0.1363, 0.6517]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCA-99M2.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.6660, -0.1918, -0.0471, -0.4613, 1.2398, 0.2485, -0.0649, 0.1433, 0.6447]
xyz_to_camera = [0.6660, -0.1918, -0.0471, -0.4613, 1.2398, 0.2485, -0.0649, 0.1433, 0.6447]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-1.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.8161, -0.2947, -0.0739, -0.4811, 1.2668, 0.2389, -0.0437, 0.1229, 0.6524]
xyz_to_camera = [0.8161, -0.2947, -0.0739, -0.4811, 1.2668, 0.2389, -0.0437, 0.1229, 0.6524]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-5100.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.5991, -0.1456, -0.0455, -0.4764, 1.2135, 0.2980, -0.0707, 0.1425, 0.6701]
xyz_to_camera = [0.5991, -0.1456, -0.0455, -0.4764, 1.2135, 0.2980, -0.0707, 0.1425, 0.6701]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-6000.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.5991, -0.1456, -0.0455, -0.4764, 1.2135, 0.2980, -0.0707, 0.1425, 0.6701]
xyz_to_camera = [0.5991, -0.1456, -0.0455, -0.4764, 1.2135, 0.2980, -0.0707, 0.1425, 0.6701]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-6100.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.7657, -0.2847, -0.0607, -0.4083, 1.1966, 0.2389, -0.0684, 0.1418, 0.5844]
xyz_to_camera = [0.7657, -0.2847, -0.0607, -0.4083, 1.1966, 0.2389, -0.0684, 0.1418, 0.5844]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-6300.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.5973, -0.1695, -0.0419, -0.3826, 1.1797, 0.2293, -0.0639, 0.1398, 0.5789]
xyz_to_camera = [0.5973, -0.1695, -0.0419, -0.3826, 1.1797, 0.2293, -0.0639, 0.1398, 0.5789]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-6400.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.7657, -0.2847, -0.0607, -0.4083, 1.1966, 0.2389, -0.0684, 0.1418, 0.5844]
xyz_to_camera = [0.7657, -0.2847, -0.0607, -0.4083, 1.1966, 0.2389, -0.0684, 0.1418, 0.5844]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-6500.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.5973, -0.1695, -0.0419, -0.3826, 1.1797, 0.2293, -0.0639, 0.1398, 0.5789]
xyz_to_camera = [0.5973, -0.1695, -0.0419, -0.3826, 1.1797, 0.2293, -0.0639, 0.1398, 0.5789]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-6600.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.7657, -0.2847, -0.0607, -0.4083, 1.1966, 0.2389, -0.0684, 0.1418, 0.5844]
xyz_to_camera = [0.7657, -0.2847, -0.0607, -0.4083, 1.1966, 0.2389, -0.0684, 0.1418, 0.5844]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-6700.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.6972, -0.2408, -0.0600, -0.4330, 1.2101, 0.2515, -0.0388, 0.1277, 0.5847]
xyz_to_camera = [0.6972, -0.2408, -0.0600, -0.4330, 1.2101, 0.2515, -0.0388, 0.1277, 0.5847]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-7CM2.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.7460, -0.2365, -0.0588, -0.5687, 1.3442, 0.2474, -0.0624, 0.1156, 0.6584]
xyz_to_camera = [0.7460, -0.2365, -0.0588, -0.5687, 1.3442, 0.2474, -0.0624, 0.1156, 0.6584]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-7CR.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.8200, -0.2976, -0.0719, -0.4296, 1.2053, 0.2532, -0.0429, 0.1282, 0.5774]
xyz_to_camera = [0.8200, -0.2976, -0.0719, -0.4296, 1.2053, 0.2532, -0.0429, 0.1282, 0.5774]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-7M2.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.5271, -0.0712, -0.0347, -0.6153, 1.3653, 0.2763, -0.1601, 0.2366, 0.7242]
xyz_to_camera = [0.5271, -0.0712, -0.0347, -0.6153, 1.3653, 0.2763, -0.1601, 0.2366, 0.7242]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-7M3.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.7374, -0.2389, -0.0551, -0.5435, 1.3162, 0.2519, -0.1006, 0.1795, 0.6552]
xyz_to_camera = [0.7374, -0.2389, -0.0551, -0.5435, 1.3162, 0.2519, -0.1006, 0.1795, 0.6552]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-7RM3.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.6640, -0.1847, -0.0503, -0.5238, 1.3010, 0.2474, -0.0993, 0.1673, 0.6527]
xyz_to_camera = [0.6640, -0.1847, -0.0503, -0.5238, 1.3010, 0.2474, -0.0993, 0.1673, 0.6527]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-7RM4.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.7662, -0.2686, -0.0660, -0.5240, 1.2965, 0.2530, -0.0796, 0.1508, 0.6167]
xyz_to_camera = [0.7662, -0.2686, -0.0660, -0.5240, 1.2965, 0.2530, -0.0796, 0.1508, 0.6167]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-7RM5.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.8200, -0.2976, -0.0719, -0.4296, 1.2053, 0.2532, -0.0429, 0.1282, 0.5774]
xyz_to_camera = [0.8200, -0.2976, -0.0719, -0.4296, 1.2053, 0.2532, -0.0429, 0.1282, 0.5774]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-7SM2.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.5838, -0.1430, -0.0246, -0.3497, 1.1477, 0.2297, -0.0748, 0.1885, 0.5778]
xyz_to_camera = [0.5838, -0.1430, -0.0246, -0.3497, 1.1477, 0.2297, -0.0748, 0.1885, 0.5778]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-9.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.6389, -0.1703, -0.0378, -0.4562, 1.2265, 0.2587, -0.0670, 0.1489, 0.6550]
xyz_to_camera = [0.6389, -0.1703, -0.0378, -0.4562, 1.2265, 0.2587, -0.0670, 0.1489, 0.6550]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-9M2.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.6389, -0.1703, -0.0378, -0.4562, 1.2265, 0.2587, -0.0670, 0.1489, 0.6550]
xyz_to_camera = [0.6389, -0.1703, -0.0378, -0.4562, 1.2265, 0.2587, -0.0670, 0.1489, 0.6550]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ILCE-9M3.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.9811, -0.3908, -0.0752, -0.3704, 1.1577, 0.2417, -0.0073, 0.0950, 0.5980]
xyz_to_camera = [0.9811, -0.3908, -0.0752, -0.3704, 1.1577, 0.2417, -0.0073, 0.0950, 0.5980]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/NEX-3.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.6549, -0.1550, -0.0436, -0.4880, 1.2435, 0.2753, -0.0854, 0.1868, 0.6976]
xyz_to_camera = [0.6549, -0.1550, -0.0436, -0.4880, 1.2435, 0.2753, -0.0854, 0.1868, 0.6976]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/NEX-3N.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.6129, -0.1545, -0.0418, -0.4930, 1.2490, 0.2743, -0.0977, 0.1693, 0.6615]
xyz_to_camera = [0.6129, -0.1545, -0.0418, -0.4930, 1.2490, 0.2743, -0.0977, 0.1693, 0.6615]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/NEX-5R.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.6129, -0.1545, -0.0418, -0.4930, 1.2490, 0.2743, -0.0977, 0.1693, 0.6615]
xyz_to_camera = [0.6129, -0.1545, -0.0418, -0.4930, 1.2490, 0.2743, -0.0977, 0.1693, 0.6615]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/NEX-6.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.6129, -0.1545, -0.0418, -0.4930, 1.2490, 0.2743, -0.0977, 0.1693, 0.6615]
xyz_to_camera = [0.6129, -0.1545, -0.0418, -0.4930, 1.2490, 0.2743, -0.0977, 0.1693, 0.6615]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/NEX-7.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.5491, -0.1192, -0.0363, -0.4951, 1.2342, 0.2948, -0.0911, 0.1722, 0.7192]
xyz_to_camera = [0.5491, -0.1192, -0.0363, -0.4951, 1.2342, 0.2948, -0.0911, 0.1722, 0.7192]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ZV-1.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.8280, -0.2987, -0.0703, -0.3531, 1.1645, 0.2133, -0.0550, 0.1542, 0.5312]
xyz_to_camera = [0.8280, -0.2987, -0.0703, -0.3531, 1.1645, 0.2133, -0.0550, 0.1542, 0.5312]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ZV-1M2.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.8280, -0.2987, -0.0703, -0.3531, 1.1645, 0.2133, -0.0550, 0.1542, 0.5312]
xyz_to_camera = [0.8280, -0.2987, -0.0703, -0.3531, 1.1645, 0.2133, -0.0550, 0.1542, 0.5312]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ZV-E1.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.6912, -0.2127, -0.0469, -0.4470, 1.2175, 0.2587, -0.0398, 0.1478, 0.6492]
xyz_to_camera = [0.6912, -0.2127, -0.0469, -0.4470, 1.2175, 0.2587, -0.0398, 0.1478, 0.6492]
2 changes: 1 addition & 1 deletion libraries/raw-rs/camera_data/Sony/ZV-E10.toml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
camera_to_xyz = [0.6355, -0.2067, -0.0490, -0.3653, 1.1542, 0.2400, -0.0406, 0.1258, 0.5506]
xyz_to_camera = [0.6355, -0.2067, -0.0490, -0.3653, 1.1542, 0.2400, -0.0406, 0.1258, 0.5506]
1 change: 0 additions & 1 deletion libraries/raw-rs/src/decoder/arw1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ pub fn decode_a100<R: Read + Seek>(ifd: Ifd, file: &mut TiffRead<R>) -> RawImage
camera_white_balance: None,
white_balance: None,
camera_to_rgb: None,
rgb_to_camera: None,
}
}

Expand Down
1 change: 0 additions & 1 deletion libraries/raw-rs/src/decoder/arw2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ pub fn decode<R: Read + Seek>(ifd: Ifd, file: &mut TiffRead<R>) -> RawImage {
camera_white_balance: ifd.white_balance_levels.map(|arr| arr.map(|x| x as f64)),
white_balance: None,
camera_to_rgb: None,
rgb_to_camera: None,
}
}

Expand Down
1 change: 0 additions & 1 deletion libraries/raw-rs/src/decoder/uncompressed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,5 @@ pub fn decode<R: Read + Seek>(ifd: Ifd, file: &mut TiffRead<R>) -> RawImage {
camera_white_balance: ifd.white_balance_levels.map(|arr| arr.map(|x| x as f64)),
white_balance: None,
camera_to_rgb: None,
rgb_to_camera: None,
}
}
1 change: 0 additions & 1 deletion libraries/raw-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ pub struct RawImage {
pub camera_white_balance: Option<[f64; 4]>,
pub white_balance: Option<[f64; 4]>,
pub camera_to_rgb: Option<[[f64; 3]; 3]>,
pub rgb_to_camera: Option<[[f64; 3]; 3]>,
}

pub struct Image<T> {
Expand Down
23 changes: 11 additions & 12 deletions libraries/raw-rs/src/metadata/camera_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ use build_camera_data::build_camera_data;
pub struct CameraData {
pub black: u16,
pub maximum: u16,
pub camera_to_xyz: [i16; 9],
pub xyz_to_camera: [i16; 9],
}

impl CameraData {
const DEFAULT: CameraData = CameraData {
black: 0,
maximum: 0,
camera_to_xyz: [0; 9],
xyz_to_camera: [0; 9],
};
}

const CAMERA_DATA: [(&str, CameraData); 40] = build_camera_data!();

const XYZ_TO_RGB: [[f64; 3]; 3] = [
const RGB_TO_XYZ: [[f64; 3]; 3] = [
// Matrix:
[0.412453, 0.357580, 0.180423],
[0.212671, 0.715160, 0.072169],
Expand All @@ -29,26 +29,26 @@ impl RawImage {
let Some(ref camera_model) = self.camera_model else { return };
let camera_name_needle = camera_model.make.to_owned() + " " + &camera_model.model;

let camera_to_xyz = CAMERA_DATA
let xyz_to_camera = CAMERA_DATA
.iter()
.find(|(camera_name_haystack, _)| camera_name_needle == *camera_name_haystack)
.map(|(_, data)| data.camera_to_xyz.map(|x| (x as f64) / 10_000.));
let Some(camera_to_xyz) = camera_to_xyz else { return };
.map(|(_, data)| data.xyz_to_camera.map(|x| (x as f64) / 10_000.));
let Some(xyz_to_camera) = xyz_to_camera else { return };

let mut camera_to_rgb = [[0.; 3]; 3];
let mut rgb_to_camera = [[0.; 3]; 3];
for i in 0..3 {
for j in 0..3 {
for k in 0..3 {
camera_to_rgb[i][j] += camera_to_xyz[i * 3 + k] * XYZ_TO_RGB[k][j];
rgb_to_camera[i][j] += RGB_TO_XYZ[k][j] * xyz_to_camera[i * 3 + k];
}
}
}

let white_balance_multiplier = camera_to_rgb.map(|x| 1. / x.iter().sum::<f64>());
for (index, row) in camera_to_rgb.iter_mut().enumerate() {
let white_balance_multiplier = rgb_to_camera.map(|x| 1. / x.iter().sum::<f64>());
for (index, row) in rgb_to_camera.iter_mut().enumerate() {
*row = row.map(|x| x * white_balance_multiplier[index]);
}
let rgb_to_camera = transpose(pseudoinverse(camera_to_rgb));
let camera_to_rgb = transpose(pseudoinverse(rgb_to_camera));

let cfa_white_balance_multiplier = if let Some(white_balance) = self.camera_white_balance {
white_balance
Expand All @@ -58,7 +58,6 @@ impl RawImage {

self.white_balance = Some(cfa_white_balance_multiplier);
self.camera_to_rgb = Some(camera_to_rgb);
self.rgb_to_camera = Some(rgb_to_camera);
}
}

Expand Down
4 changes: 2 additions & 2 deletions libraries/raw-rs/src/postprocessing/convert_to_rgb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use crate::{Pixel, RawImage, CHANNELS_IN_RGB};

impl RawImage {
pub fn convert_to_rgb_fn(&self) -> impl Fn(Pixel) -> [u16; CHANNELS_IN_RGB] {
let Some(rgb_to_camera) = self.rgb_to_camera else { todo!() };
let Some(camera_to_rgb) = self.camera_to_rgb else { todo!() };

move |pixel: Pixel| {
std::array::from_fn(|i| i)
.map(|i| rgb_to_camera[i].iter().zip(pixel.values.iter()).map(|(&coeff, &value)| coeff * value as f64).sum())
.map(|i| camera_to_rgb[i].iter().zip(pixel.values.iter()).map(|(&coeff, &value)| coeff * value as f64).sum())
.map(|x: f64| (x as u16).clamp(0, u16::MAX))
}
}
Expand Down

0 comments on commit 36fe9bf

Please sign in to comment.