mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2025-07-07 15:55:00 +00:00
Raw-rs: Fix naming convention of matrices (#2071)
Fix naming convention of matrices
This commit is contained in:
parent
442937c13f
commit
36fe9bf31b
47 changed files with 54 additions and 59 deletions
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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> {
|
||||
|
|
|
@ -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],
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue