Skip to content

Commit 7937fea

Browse files
ppoundclaude
andcommitted
LR-PROF-CAMERA: fitted looks for the Fujifilm X-T5's eleven colour film simulations
assets/camera-looks/X-T5.json holds the X-T5's eleven colour film simulations (the X-T4's nine plus REALA ACE and Nostalgic Neg.) in storytold#2445's look format, listed under "X-T5 looks, fitted". They are fitted to the camera's own conversions (X RAW STUDIO, which converts on the connected camera) of 80 of the contributor's X-T5 raws from 58 shoots, every raw converted in every simulation at DR100: 62 to fit, 18 from 12 other shoots held out. - examples/bake_look.rs bakes a per-simulation profile (matrix, hue/saturation table, pooled tone and chroma curves) into a look file: the starting grid. - examples/probe_look.rs swaps a look for one whose nodes hold their own CIELAB, so a 32-bit linear export through it is the colour the app hands the look per pixel; tools/fit_look.py then fits every node by least squares to the camera's conversions, with second-difference smoothing and the starting grid as a weak prior. - A look file may name the raw exposure bias its looks were made at (`raw_exposure_bias`); a raw with another bias is brightened by the difference (camera_looks::exposure), else by the dynamic range as before (the X-T4's file). X-T5 frames at ISO 125 and 200 (bias -0.72, not -1.72) had rendered a stop bright. Held-out raws, median of per-photo mean dE2000 at 200 px against the camera's conversion: 0.97 to 1.40 per look (starting grid 2.05 to 3.72, LightCraft's starting look 3.79 to 7.21). Method and table: docs/camera-preview-colour.md, "Fitted looks (Fujifilm X-T5)". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 0a572fe commit 7937fea

11 files changed

Lines changed: 568 additions & 12 deletions

File tree

‎assets/ATTRIBUTION.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ covers a whole directory), or if a licence file referenced in the Licence column
2323
| `assets/camera-profiles/NIKON_Z_8.json` | Nikon Z 8 camera colour profile (matrix + hue/saturation/value table), built into LightCraft | Michael Anderson (@endthestart) | original work: fitted by `lightcraft-cli calibrate` to 261 usable Z 8 NEFs of my own (of 278, 2023 and 2026, nearly all Standard picture control, lossless 14-bit; NIKKOR Z 24-120mm f/4 S and AF-S 70-200mm f/2.8G on the FTZ) and their in-camera JPEGs; aggregate colour statistics only, no image content; no Adobe or third-party profile data | MIT OR Apache-2.0 | 2026-10-13 | none |
2424
| `assets/camera-profiles/NIKON_D5300.json` | Nikon D5300 camera colour profile (matrix + hue/saturation/value table), built into LightCraft | Michael Anderson (@endthestart) | original work: fitted by `lightcraft-cli calibrate` to 264 usable D5300 NEFs of my own (of 273, 2014 to 2017, mostly Standard picture control, lossy 12-bit, mostly the AF-S DX 35mm f/1.8G) and their in-camera JPEGs; aggregate colour statistics only, no image content; no Adobe or third-party profile data | MIT OR Apache-2.0 | 2026-10-13 | none |
2525
| `assets/camera-profiles/ILCE-7RM5.json` | Sony ILCE-7RM5 camera colour profile (matrix + hue/saturation/value table), built into LightCraft | Yule (Brian) Wang (@peaperfish) | original work: fitted by `lightcraft-cli calibrate` to 220 usable ILCE-7RM5 ARWs of my own (of 241, 2025 to 2026, Standard creative style; Sigma 24-70mm F2.8 DG DN II Art and Sony FE 200-600mm F5.6-6.3 G OSS) and their in-camera JPEGs; aggregate colour statistics only, no image content; no Adobe or third-party profile data | MIT OR Apache-2.0 | 2026-10-26 | none |
26+
| `assets/camera-looks/X-T5.json` | Fujifilm X-T5 film simulation looks, fitted: eleven colour film simulations as 3D lookups in the X-T4 file's format | Paul Pound | original work: fitted to 62 of the contributor's own X-T5 raws and the camera's conversion of each in every simulation (X RAW STUDIO, which converts on the connected camera): per-simulation starting lookups baked from fitted profiles (`crates/engine/examples/bake_look.rs`), then every node fitted by least squares to the conversions' colours against the look input LightCraft computes for each pixel (`crates/engine/examples/probe_look.rs`, `tools/fit_look.py`); aggregate colour statistics only, no image content; no Fujifilm data, profile or code is included (X RAW STUDIO only had the camera convert the raws) | MIT OR Apache-2.0 | 2026-10-28 | none |
2627
| `assets/camera-looks/X-T4.json` | Fujifilm X-T4 film simulation looks, measured: one 3D lookup per colour film simulation (nine), from white-balanced camera RGB to the camera's output, built into LightCraft | @JackalCOB | original work: measured by having an X-T4 convert, in its USB raw conversion mode, synthetic charts made from the CC0 raw.pixls.us X-T4 file 3913 (https://raw.pixls.us, its sensor data replaced by patches of known colour) into each film simulation, and fitting a lookup to the charts; camera output measured, no Fujifilm data, profile or software and no image content | MIT OR Apache-2.0 | 2026-10-20 | none |
2728
| `crates/raw/src/spectral_table.rs` | Camera colour matrices (DNG ColorMatrix1/2 and ForwardMatrix1/2 for Standard Illuminant A and D65) for 52 camera models, and the model alias list | Derived by LightCraft contributors from rawtoaces-data (Academy Software Foundation): camera spectral sensitivities measured by Weta Digital (44 cameras), scitech (7) and Jonathon Irons at the National Physical Laboratory (Nikon D5100); training reflectances; CIE 1931 colour-matching functions (CIE, CC-BY-4.0, as shipped in rawtoaces-data) | https://github.com/AcademySoftwareFoundation/rawtoaces-data, tag v1.1.0, commit 5cfa53707b053594b2d0d48e8019fb56e6582d6c | Apache-2.0 (`LICENSE-APACHE`); the colour-matching functions CC-BY-4.0 | 2026-10-08 | generated by `tools/spectral_camera_table.py`: a 3×3 matrix per illuminant fitted to the spectral data (no measurement copied verbatim); aliases copied from `data/aliases.json`; no Adobe or third-party camera matrix |
2829
| `assets/camera-tone/sony-dro-off.json` | Sony global tone curve with the Dynamic Range Optimizer off (32 knots), built into LightCraft for ARWs shot with DRO on | LightCraft contributors; source photographs by raw.pixls.us contributors | original work: tone curve quantile-matched over the pooled pixel pairs of 12 CC0 raw.pixls.us ARWs (DRO off, Standard creative style; ILCE-3500, -5000, -6600, -7CR, -7M3 ×3, -7S, -9M2, ILCA-77M2, SLT-A57, NEX-F3) and their embedded camera JPEGs; the file lists each source URL and SHA-256 and how the curve was derived (see also `docs/camera-preview-colour.md`); aggregate tone statistics only, no image content; no Adobe or third-party profile data | MIT OR Apache-2.0 (sources CC0) | 2026-10-09 | none |

‎assets/camera-looks/X-T5.json‎

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
//! Bake per-film-simulation camera profiles into a look file (`assets/camera-looks/<model>.json`,
2+
//! `lightcraft_pipeline::looks`), as the starting point of `tools/fit_look.py`. A profile is JSON with the `matrix` and
3+
//! `hue_sat` of a `lightcraft-cli calibrate` profile, fitted to raws shot in one film simulation, and a `tone`
4+
//! (`CameraTone`: tone curve knots and chroma curve) pooled over them; the X-T5 file started from such profiles.
5+
//!
6+
//! A look is the whole rendering from white-balanced camera RGB: each grid node (CIELAB through the forward matrix)
7+
//! is rendered the way the finishing stage renders a starting look (matrix, hue/saturation table, tone map on
8+
//! luminance, chroma curve, highlights desaturated to white) and stored as Adobe RGB. A look takes camera RGB with
9+
//! only the dynamic range gain, so the tone curve is placed for raw exposure bias `BIAS` (the curves are pooled on
10+
//! the bias-corrected scale): -1.72 for an X-T5 at DR100 from ISO 250.
11+
//!
12+
//! usage: cargo run --release -p lightcraft-engine --example bake_look -- OUT.json MODEL GROUP BIAS ID=NAME=PROFILE.json…
13+
//! Prints, per look, how far the baked grid is from rendering the profile directly (CIE76 dE over camera colours).
14+
use lightcraft_color::{ADOBE_RGB, D50, D65, Mat3, REC2020, bradford, luminance_2020};
15+
use lightcraft_pipeline::hue_sat::HueSat;
16+
use lightcraft_pipeline::looks::{Axis, Look};
17+
use lightcraft_pipeline::tone::{CameraTone, ToneMap};
18+
use lightcraft_raw::profile::HsvTable;
19+
20+
const ADOBE_GAMMA: f32 = 563.0 / 256.0;
21+
/// The grid and node encoding of the X-T4 file, so both read alike.
22+
const LIGHTNESS: (f64, f64, usize) = (0.0, 100.0, 17);
23+
const AB: (f64, f64, usize) = (-168.0, 168.0, 29);
24+
const NODE_OFFSET: f64 = -4.0;
25+
const NODE_STEP: f64 = 1.0 / 8192.0;
26+
const WHITE: [f64; 3] = [0.96422, 1.0, 0.82521];
27+
28+
#[derive(serde::Deserialize)]
29+
struct Profile {
30+
matrix: [[f64; 3]; 3],
31+
hue_sat: Option<HsvTable>,
32+
tone: CameraTone,
33+
}
34+
35+
/// One profile as the finishing stage renders it from white-balanced camera RGB.
36+
struct Render<'a> {
37+
matrix: [[f32; 3]; 3],
38+
hue_sat: Option<HueSat<'a>>,
39+
tone: ToneMap,
40+
}
41+
42+
impl Render<'_> {
43+
/// Display-linear Rec.2020 of camera RGB `cam` (as `finish.rs`' `base_render`, peak 1).
44+
fn apply(&self, cam: [f32; 3]) -> [f32; 3] {
45+
let m = &self.matrix;
46+
let mut c: [f32; 3] = std::array::from_fn(|i| m[i][0] * cam[0] + m[i][1] * cam[1] + m[i][2] * cam[2]);
47+
if let Some(h) = &self.hue_sat {
48+
c = h.apply(c);
49+
}
50+
let yl = luminance_2020(c);
51+
let o = self.tone.apply(yl);
52+
let mut d = if yl > 1e-9 { c.map(|v| v * o / yl) } else { [0.0; 3] };
53+
let k = self.tone.chroma_scale(o);
54+
if k != 1.0 {
55+
d = d.map(|v| o + (v - o) * k);
56+
}
57+
let mx = d[0].max(d[1]).max(d[2]);
58+
if mx > 1.0 {
59+
let t = ((mx - 1.0) / (mx - o).max(1e-6)).clamp(0.0, 1.0);
60+
d = d.map(|v| v + (o - v) * t);
61+
}
62+
d
63+
}
64+
}
65+
66+
fn mul(m: &[[f32; 3]; 3], v: [f32; 3]) -> [f32; 3] {
67+
std::array::from_fn(|i| m[i][0] * v[0] + m[i][1] * v[1] + m[i][2] * v[2])
68+
}
69+
70+
fn lab_to_xyz(lab: [f64; 3]) -> [f64; 3] {
71+
let fy = (lab[0] + 16.0) / 116.0;
72+
let (fx, fz) = (fy + lab[1] / 500.0, fy - lab[2] / 200.0);
73+
let inv = |f: f64| if f > 6.0 / 29.0 { f * f * f } else { 3.0 * (6.0f64 / 29.0).powi(2) * (f - 4.0 / 29.0) };
74+
[inv(fx) * WHITE[0], inv(fy) * WHITE[1], inv(fz) * WHITE[2]]
75+
}
76+
77+
/// CIELAB (D65 white) of display-linear Rec.2020 `c`, for comparing renders.
78+
fn lab_of(c: [f32; 3]) -> [f64; 3] {
79+
let xyz = REC2020.to_xyz().apply(c.map(f64::from));
80+
let w = lightcraft_color::D65.to_xyz();
81+
let f = |t: f64| if t > (6.0f64 / 29.0).powi(3) { t.cbrt() } else { t / (3.0 * (6.0f64 / 29.0).powi(2)) + 4.0 / 29.0 };
82+
let [fx, fy, fz] = std::array::from_fn(|i| f(xyz[i] / w[i]));
83+
[116.0 * fy - 16.0, 500.0 * (fx - fy), 200.0 * (fy - fz)]
84+
}
85+
86+
fn main() -> Result<(), String> {
87+
let args: Vec<String> = std::env::args().skip(1).collect();
88+
let [out, model, group, bias, entries @ ..] = args.as_slice() else {
89+
return Err("usage: bake_look OUT.json MODEL GROUP BIAS ID=NAME=PROFILE.json…".into());
90+
};
91+
let bias: f32 = bias.parse().map_err(|_| "BIAS is a number of EV")?;
92+
let to_adobe = REC2020.to_space(&ADOBE_RGB).to_f32();
93+
let mut profiles = Vec::new();
94+
for entry in entries {
95+
let mut parts = entry.splitn(3, '=');
96+
let (Some(id), Some(name), Some(path)) = (parts.next(), parts.next(), parts.next()) else {
97+
return Err(format!("`{entry}` is not ID=NAME=PROFILE.json"));
98+
};
99+
let json = std::fs::read_to_string(path).map_err(|e| format!("{path}: {e}"))?;
100+
let p: Profile = serde_json::from_str(&json).map_err(|e| format!("{path}: {e}"))?;
101+
profiles.push((id, name, path, p));
102+
}
103+
// one forward matrix for the file (its format has one): the first profile's colour, so its greys sit on the grid's
104+
// neutral axis; every node is rendered through its own profile's matrix whatever it is
105+
let first = profiles.first().ok_or("no profiles given")?;
106+
let forward = bradford(D65, D50).mul(&REC2020.to_xyz()).mul(&Mat3(first.3.matrix));
107+
let back = forward.inverse().ok_or("the first profile's matrix is not invertible")?;
108+
let mut looks = Vec::new();
109+
for (id, name, path, p) in &profiles {
110+
// the curve takes the raw with its bias undone; a look's camera RGB keeps it
111+
let scale = bias.exp2();
112+
let curve = CameraTone::new(p.tone.knots().map(|[x, y]| [x * scale, y]))
113+
.and_then(|t| t.with_chroma(*p.tone.chroma()))
114+
.ok_or(format!("{path}: the curve doesn't scale by {scale}"))?;
115+
let render = Render {
116+
matrix: Mat3(p.matrix).to_f32(),
117+
hue_sat: p.hue_sat.as_ref().and_then(HueSat::new),
118+
tone: ToneMap::camera(&curve, 0.0, 0.0, 0.0),
119+
};
120+
let node = |l: usize, a: usize, b: usize| {
121+
let at = |(lo, hi, n): (f64, f64, usize), i: usize| lo + (hi - lo) * i as f64 / (n - 1) as f64;
122+
let cam = back.apply(lab_to_xyz([at(LIGHTNESS, l), at(AB, a), at(AB, b)])).map(|v| v as f32);
123+
let d = render.apply(cam.map(|v| v.max(0.0)));
124+
mul(&to_adobe, d).map(|v| v.clamp(0.0, 1.0).powf(1.0 / ADOBE_GAMMA))
125+
};
126+
let (nl, nab) = (LIGHTNESS.2, AB.2);
127+
let mut nodes = Vec::with_capacity(nl * nab * nab);
128+
let mut hex = String::with_capacity(nl * nab * nab * 12);
129+
for l in 0..nl {
130+
for a in 0..nab {
131+
for b in 0..nab {
132+
let v = node(l, a, b);
133+
let q = v.map(|c| ((f64::from(c) - NODE_OFFSET) / NODE_STEP).round().clamp(0.0, 65535.0) as u16);
134+
for c in q {
135+
hex.push_str(&format!("{c:04x}"));
136+
}
137+
nodes.push(q.map(|c| (f64::from(c) * NODE_STEP + NODE_OFFSET) as f32));
138+
}
139+
}
140+
}
141+
// how much the grid loses against rendering the profile itself, over camera colours of photos
142+
let axis = |(lo, hi, n): (f64, f64, usize)| Axis { min: lo as f32, max: hi as f32, n };
143+
let look = Look::new(&format!("look:{id}"), model, name, group, "", forward.0, WHITE, axis(LIGHTNESS), axis(AB), nodes)?;
144+
let mut des = Vec::new();
145+
let mut seed = 0x2545_f491u32;
146+
let mut rnd = || {
147+
seed ^= seed << 13;
148+
seed ^= seed >> 17;
149+
seed ^= seed << 5;
150+
seed as f32 / u32::MAX as f32
151+
};
152+
for _ in 0..20000 {
153+
let y = 0.002 * (9.0f32 * rnd()).exp2();
154+
let cam = [y * (0.3 + 1.4 * rnd()), y, y * (0.3 + 1.4 * rnd())];
155+
let (a, b) = (lab_of(look.apply(cam)), lab_of(render.apply(cam)));
156+
des.push(((a[0] - b[0]).powi(2) + (a[1] - b[1]).powi(2) + (a[2] - b[2]).powi(2)).sqrt());
157+
}
158+
des.sort_by(f64::total_cmp);
159+
let mean = des.iter().sum::<f64>() / des.len() as f64;
160+
eprintln!("{id}: baked vs direct dE mean {mean:.2}, median {:.2}, 95th {:.2}", des[des.len() / 2], des[des.len() * 95 / 100]);
161+
looks.push(serde_json::json!({
162+
"id": id,
163+
"name": name,
164+
"description": format!("Fitted to the {model}'s own {name} conversions. Not made or endorsed by Fujifilm."),
165+
"nodes": hex,
166+
}));
167+
}
168+
let file = serde_json::json!({
169+
"version": 1,
170+
"model": model,
171+
"group": group,
172+
"input": {
173+
"forward_matrix": forward.0,
174+
"white": WHITE,
175+
"lightness": LIGHTNESS,
176+
"ab": AB,
177+
},
178+
"output": "Adobe RGB (1998), encoded with gamma 563/256",
179+
"node_offset": NODE_OFFSET,
180+
"node_step": NODE_STEP,
181+
// the bias the curves were placed for: a raw with another bias is brightened by the difference
182+
"raw_exposure_bias": bias,
183+
"looks": looks,
184+
});
185+
std::fs::write(out, serde_json::to_string(&file).map_err(|e| e.to_string())?).map_err(|e| format!("{out}: {e}"))?;
186+
Ok(())
187+
}
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//! Write, per raw, the CIELAB colour each pixel hands a measured look, as the app renders the photo: the input of a
2+
//! fitted look (`tools/fit_look.py` pairs it with the camera's conversion of the same raw).
3+
//!
4+
//! The look `ID` (a built-in look of the raws' camera, e.g. `look:x-t5/provia`) is swapped, in this process only, for
5+
//! a probe whose nodes hold their own CIELAB coordinates, scaled to 0..1: trilinear interpolation reproduces a linear
6+
//! function exactly, so a 32-bit linear Adobe RGB export of the photo with that profile holds, per pixel,
7+
//! `((L/100, (a-min)/(max-min), (b-min)/(max-min)))^(563/256)`, clamped to the grid as the look clamps it.
8+
//!
9+
//! usage: cargo run --release -p lightcraft-engine --example probe_look -- ID LONG_EDGE OUT_DIR RAF…
10+
//! Writes OUT_DIR/<raf stem>.tif (float32 RGB); inputs are only read.
11+
use lightcraft_engine::Session;
12+
use lightcraft_engine::catalog::PhotoId;
13+
use lightcraft_engine::export::{ExportOptions, export_photo};
14+
use lightcraft_pipeline::looks::{self, Axis, Look};
15+
use serde_json::json;
16+
17+
const LIGHTNESS: Axis = Axis { min: 0.0, max: 100.0, n: 17 };
18+
const AB: Axis = Axis { min: -168.0, max: 168.0, n: 29 };
19+
20+
fn main() -> Result<(), String> {
21+
let args: Vec<String> = std::env::args().skip(1).collect();
22+
let [id, edge, out, rafs @ ..] = args.as_slice() else {
23+
return Err("usage: probe_look ID LONG_EDGE OUT_DIR RAF…".into());
24+
};
25+
let edge: u64 = edge.parse().map_err(|_| "LONG_EDGE is a number")?;
26+
let real = lightcraft_engine::camera_looks::find(id).ok_or(format!("{id}: not a built-in look"))?;
27+
let at = |a: Axis, i: usize| a.min + (a.max - a.min) * i as f32 / (a.n - 1) as f32;
28+
let mut nodes = Vec::new();
29+
for l in 0..LIGHTNESS.n {
30+
for a in 0..AB.n {
31+
for b in 0..AB.n {
32+
let unit = |x: Axis, i: usize| (at(x, i) - x.min) / (x.max - x.min);
33+
nodes.push([unit(LIGHTNESS, l), unit(AB, a), unit(AB, b)]);
34+
}
35+
}
36+
}
37+
// the look file's camera colour (the input every look of the model shares)
38+
let file = lightcraft_engine::camera_looks::BUNDLED.iter().find(|(m, _)| real.fits(m)).ok_or("no look file")?.1;
39+
let v: serde_json::Value = serde_json::from_str(file).map_err(|e| e.to_string())?;
40+
let forward: [[f64; 3]; 3] = serde_json::from_value(v["input"]["forward_matrix"].clone()).map_err(|e| e.to_string())?;
41+
let white: [f64; 3] = serde_json::from_value(v["input"]["white"].clone()).map_err(|e| e.to_string())?;
42+
let probe = Look::new(id, &real.model, &real.name, &real.group, "probe", forward, white, LIGHTNESS, AB, nodes)?;
43+
looks::register(probe);
44+
std::fs::create_dir_all(out).map_err(|e| format!("{out}: {e}"))?;
45+
let o =
46+
ExportOptions::from_params(&json!({"format": "tiff", "bitDepth": 32, "colorSpace": "adobeRgb", "longEdge": edge, "tiffCompression": "none"}))
47+
.map_err(|e| e.to_string())?;
48+
for raf in rafs {
49+
let path = std::fs::canonicalize(raf).map_err(|e| format!("{raf}: {e}"))?.to_string_lossy().to_string();
50+
let mut s = Session::new().with_fs();
51+
let r = s.execute("library.import", &json!({"paths": [path]})).map_err(|e| e.to_string())?;
52+
let pid = r["imported"][0].as_u64().ok_or(format!("{raf}: not imported"))?;
53+
s.execute("library.select", &json!({"ids": [pid], "active": pid})).map_err(|e| e.to_string())?;
54+
s.execute("develop.merge", &json!({"settings": {"profile": {"id": id, "amount": 100}}})).map_err(|e| e.to_string())?;
55+
let e = export_photo(&mut s, PhotoId(pid), &o, 1)?;
56+
let stem = std::path::Path::new(raf).file_stem().map(|s| s.to_string_lossy().to_string()).unwrap_or_default();
57+
let dst = std::path::Path::new(out).join(format!("{stem}.tif"));
58+
std::fs::write(&dst, &e.bytes).map_err(|err| format!("{}: {err}", dst.display()))?;
59+
eprintln!("{stem}: {}x{}", e.width, e.height);
60+
}
61+
Ok(())
62+
}

0 commit comments

Comments
 (0)