Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
39e0b73
LR-EDIT-OPTICS-PROFILE: add Nikon lens measurement probes
AlexChambers Nov 5, 2026
76e378f
LR-EDIT-OPTICS-PROFILE: bound and validate Nikon measurement inputs
AlexChambers Nov 5, 2026
1fc1070
LR-EDIT-OPTICS-PROFILE: respect Nikon distortion correction modes
AlexChambers Nov 5, 2026
374f0c5
LR-EDIT-OPTICS-PROFILE: enable validated Nikon Z 6 and Z 7 distortion
AlexChambers Nov 5, 2026
7cd55dc
LR-EDIT-OPTICS-PROFILE: fix reconnect rebuilds and reserve cache vers…
AlexChambers Nov 5, 2026
4c70016
LR-EDIT-OPTICS-PROFILE: merge current main for final Nikon validation
AlexChambers Nov 5, 2026
622c345
LR-EDIT-OPTICS-PROFILE: harden lens measurement tooling
AlexChambers Nov 5, 2026
6391274
LR-EDIT-OPTICS-PROFILE: merge main after tooling review
AlexChambers Nov 5, 2026
d1ed0ac
LR-EDIT-OPTICS-PROFILE: key sweep caches by input digest
AlexChambers Nov 5, 2026
898005a
LR-EDIT-OPTICS-PROFILE: merge main and preserve gap notes
AlexChambers Nov 5, 2026
a91f835
LR-EDIT-OPTICS-PROFILE: merge main with process V5
AlexChambers Nov 5, 2026
0d58ca9
LR-EDIT-OPTICS-PROFILE: merge main and retain reserved cache version
AlexChambers Nov 5, 2026
5d96141
LR-EDIT-OPTICS-PROFILE: merge onboarding updates and preserve harness…
AlexChambers Nov 5, 2026
a6c1370
LR-EDIT-OPTICS-PROFILE: merge current main 92adb0478
AlexChambers Nov 6, 2026
eae8538
LR-EDIT-OPTICS-PROFILE: refresh the parity summary after the merge
AlexChambers Nov 6, 2026
c808ee3
LR-EDIT-OPTICS-PROFILE: merge current main 8a0b91a95
AlexChambers Nov 6, 2026
ce0638a
LR-EDIT-OPTICS-PROFILE: the wire job test is main's again, which #378…
AlexChambers Nov 6, 2026
5d5291b
LR-EDIT-OPTICS-PROFILE: merge current main 1a301fc2d (Lens Blur, High…
AlexChambers Nov 11, 2026
44b3d91
LR-EDIT-OPTICS-PROFILE: LOOK_VERSION 28, since open #3943 takes 26 an…
AlexChambers Nov 11, 2026
d15357d
LR-EDIT-OPTICS-PROFILE: merge current main fd0b914e6 (security batch,…
AlexChambers Nov 13, 2026
09c9a68
LR-EDIT-OPTICS-PROFILE: the Nikon lens test uses craft_tiff (main mov…
AlexChambers Nov 13, 2026
4b9699e
LR-EDIT-OPTICS-PROFILE: merge current main f72ba11a2 (craft-raw cutov…
AlexChambers Nov 14, 2026
19d6c7d
LR-EDIT-OPTICS-PROFILE: take craft-libs a207d20 for the Nikon Z 6 and…
AlexChambers Nov 14, 2026
3c9764a
LR-EDIT-OPTICS-PROFILE: the Nikon doc drops its Last updated header a…
AlexChambers Nov 14, 2026
20d1c3b
LR-EDIT-OPTICS-PROFILE: merge current main 6b2b7e6d1 (TIFF, JPEG and …
AlexChambers Nov 14, 2026
f26d2eb
LR-EDIT-OPTICS-PROFILE: retry CI (the Linux gate's only failure was a…
AlexChambers Nov 15, 2026
14f3ff9
Merge remote-tracking branch 'origin/main' into t3/nikon-lens-correct…
AlexChambers Nov 15, 2026
fc807b4
Merge remote-tracking branch 'origin/main' into t3/nikon-lens-correct…
AlexChambers Nov 15, 2026
60792f5
Merge remote-tracking branch 'origin/main' into t3/nikon-lens-correct…
AlexChambers Nov 16, 2026
372212f
Merge remote-tracking branch 'origin/main' into t3/nikon-lens-correct…
AlexChambers Nov 16, 2026
57d788c
Merge commit '6be64516e250d7d588bd5d4ba7f734e04a1df32f' (origin/main)…
AlexChambers Nov 16, 2026
b31282b
Merge remote-tracking branch 'origin/main' into t3/nikon-lens-correct…
AlexChambers Nov 16, 2026
78a065b
Merge remote-tracking branch 'origin/main' into t3/nikon-lens-correct…
AlexChambers Nov 18, 2026
5bc6142
Merge remote-tracking branch 'origin/main' into t3/nikon-lens-correct…
AlexChambers Nov 18, 2026
9daf437
LR-EDIT-OPTICS-PROFILE: keep Nikon distortion decoding in craft-raw
AlexChambers Nov 25, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions apps/lightcraft-web/src/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ mod tests {
}

#[test]
fn wire_job_renders_like_the_engine() {
fn wire_job_renders_like_the_engine_cpu() {
let mut s = Session::with_demo();
let id = s.visible_cloned()[0];
s.execute("library.select", &serde_json::json!({"ids": [id.0]})).unwrap();
Expand All @@ -468,7 +468,10 @@ mod tests {
let mut core = WorkerCore::default();
assert_eq!(core.needs_original(&wire), None, "demo scenes are generated");
let a = core.render(&wire, None).unwrap();
let b = job.run().rendered.unwrap();
// Keep the wire round-trip comparison exact on the same backend. The window test above
// compares the worker with a native job, which can use the GPU and its rounding budget.
let source = job.source.load_source().unwrap();
let b = lightcraft_engine::pipeline::render(&source.image, &source.info_or(job.info.clone()), &job.settings, &job.request);
assert_eq!((a.image.width, a.image.height), (b.image.width, b.image.height));
assert_eq!(a.image.data, b.image.data);
assert_eq!(a.histogram, b.histogram);
Expand Down
136 changes: 136 additions & 0 deletions crates/engine/examples/nikon_lens_probe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
//! Measurement only: dump an uncorrected quarter-size camera-RGB proxy and render the current source.
//!
//! `cargo run --release -p lightcraft-engine --example nikon_lens_probe -- IN OUT_DIR [OPCODES.json]`
//! Optional JSON is an array of experimental `OpcodeList3` lens opcodes. It replaces the lens description
//! after source loading, without changing the decoder, saved settings, or camera-look fit. Candidate renders
//! therefore isolate optics; they do not predict a future camera-look refit. See docs/raw/nikon_lens_probe.py.
#![forbid(unsafe_code)]
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]

use std::io::{Read, Write};
use std::path::Path;

use lightcraft_develop::DevelopSettings;
use lightcraft_engine::files;
use lightcraft_pipeline::{RenderRequest, SourceInfo};
use lightcraft_raster::Rgb32f;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let args: Vec<_> = std::env::args_os().skip(1).collect();
let input = args.first().ok_or("usage: nikon_lens_probe IN OUT_DIR [OPCODES.json]")?;
let dir = Path::new(args.get(1).ok_or("missing OUT_DIR")?);
std::fs::create_dir_all(dir)?;
let bytes = std::fs::read(input)?;
let mut raw = lightcraft_raw::decode(&bytes)?;
let mut header = raw.info();
std::fs::write(dir.join("raw.json"), serde_json::to_vec_pretty(&header)?)?;
raw.opcodes.list3.clear();
let proxy = raw.develop_binned(4, 1.0)?.ok_or("cannot bin this raw")?;
let mut out = std::io::BufWriter::new(std::fs::File::create(dir.join("camera-rgb.f32"))?);
out.write_all(&u32::try_from(proxy.width)?.to_le_bytes())?;
out.write_all(&u32::try_from(proxy.height)?.to_le_bytes())?;
for pixel in &proxy.data {
for value in pixel {
out.write_all(&value.to_le_bytes())?;
}
}
out.flush()?;
drop(raw);
let (source, mut info) = files::load_bytes(&bytes, 1200)?;
let mut settings = DevelopSettings::default();
settings.wb.temp = info.as_shot_temp;
settings.wb.tint = info.as_shot_tint;
settings.optics.lens_profile = info.lens.is_some();
render(&source, &info, &settings, &dir.join("baseline.png"))?;
if let Some(path) = args.get(2) {
let data = read_candidates(std::fs::File::open(path)?)?;
header.opcodes.list3 = serde_json::from_slice(&data)?;
validate_candidates(&header.opcodes.list3)?;
info.lens = files::embedded_lens(&header);
settings.optics.lens_profile = info.lens.is_some();
render(&source, &info, &settings, &dir.join("candidate.png"))?;
}
Ok(())
}

/// Read one byte beyond the limit to distinguish a complete input from an oversized one.
fn read_candidates(reader: impl Read) -> std::io::Result<Vec<u8>> {
let mut data = Vec::new();
reader.take(65_537).read_to_end(&mut data)?;
if data.len() > 65_536 {
return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "candidate opcodes exceed 64 KiB"));
}
Ok(data)
}

/// Diagnostic inputs have a deliberately small range; reject arbitrary operations and invalid gains.
fn validate_candidates(ops: &[lightcraft_raw::Opcode]) -> Result<(), &'static str> {
use lightcraft_raw::Opcode;
if ops.is_empty() || ops.len() > 2 {
return Err("provide one or two lens opcodes");
}
if ops.iter().filter(|op| matches!(op, Opcode::WarpRectilinear { .. })).count() > 1
|| ops.iter().filter(|op| matches!(op, Opcode::FixVignetteRadial { .. })).count() > 1
{
return Err("provide at most one warp and one radial vignette");
}
for op in ops {
let center = match op {
Opcode::WarpRectilinear { planes, center } if planes.len() == 1 && planes.iter().flatten().all(|v| v.is_finite() && v.abs() <= 16.0) => {
center
}
Opcode::FixVignetteRadial { k, center } if k.iter().all(|v| v.is_finite() && v.abs() <= 16.0) => {
for i in 0..=256 {
let r2 = (f64::from(i) / 256.0).powi(2);
let gain = 1.0 + r2 * (k[0] + r2 * (k[1] + r2 * (k[2] + r2 * (k[3] + r2 * k[4]))));
if !gain.is_finite() || !(0.01..=16.0).contains(&gain) {
return Err("candidate vignette gain is outside 0.01 to 16");
}
}
center
}
_ => return Err("candidate must be a bounded single-plane warp or radial vignette"),
};
if !center.iter().all(|v| v.is_finite() && (0.0..=1.0).contains(v)) {
return Err("candidate center must be inside the active area");
}
}
Ok(())
}

/// Use the same CPU renderer and PNG encoder as the app, with no catalog or filesystem hooks.
fn render(source: &Rgb32f, info: &SourceInfo, settings: &DevelopSettings, path: &Path) -> Result<(), Box<dyn std::error::Error>> {
let rendered = lightcraft_pipeline::render(source, info, settings, &RenderRequest::fit(1200, 1200));
let image = lightcraft_codecs::encode::EncodeImage::rgba8(&rendered.image);
std::fs::write(path, lightcraft_codecs::encode::encode_png(&image, &Default::default())?)?;
Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn candidates_reject_duplicate_kinds_and_accept_one_of_each() {
use lightcraft_raw::Opcode;
let warp = Opcode::WarpRectilinear { planes: vec![[1.0, 0.0, 0.0, 0.0, 0.0, 0.0]], center: [0.5, 0.5] };
let vignette = Opcode::FixVignetteRadial { k: [0.0; 5], center: [0.5, 0.5] };
assert!(validate_candidates(std::slice::from_ref(&warp)).is_ok());
assert!(validate_candidates(std::slice::from_ref(&vignette)).is_ok());
assert!(validate_candidates(&[warp.clone(), vignette.clone()]).is_ok());
assert!(validate_candidates(&[vignette.clone(), warp.clone()]).is_ok());
assert_eq!(validate_candidates(&[warp.clone(), warp]), Err("provide at most one warp and one radial vignette"));
assert_eq!(validate_candidates(&[vignette.clone(), vignette]), Err("provide at most one warp and one radial vignette"));
}

/// A hostile stream must be rejected after at most limit + 1 bytes, without reading to EOF.
#[test]
fn candidate_reader_bounds_the_read_and_accepts_the_exact_limit() {
let mut endless = std::io::repeat(b' ');
let mut counted = (&mut endless).take(1_000_000);
let error = read_candidates(&mut counted).unwrap_err();
assert_eq!(error.kind(), std::io::ErrorKind::InvalidData);
assert_eq!(counted.limit(), 1_000_000 - 65_537);
assert_eq!(read_candidates(std::io::repeat(b' ').take(65_536)).unwrap().len(), 65_536);
}
}
4 changes: 3 additions & 1 deletion crates/engine/src/camera_preview.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ use tone::{HighlightCheck, ToneFit, fit_tone, fit_tone_conditional, highlights};
/// 13: the sensor proxy of every per-file fit gets the embedded vignetting correction the render applies (Fujifilm
/// RAF; other makes with a lens database), so the render no longer applies it twice, at the position a lens warp samples;
/// the warped candidate's alignment leaves out the pixels outside the sensor instead of reading them as black.
pub const LOOK_VERSION: u32 = 13;
/// 26: Nikon Z 6 / Z 7 distortion enters the fitting geometry; Nikon mode 2 Off no longer supplies a warp.
/// Versions through 25 are assigned by other open PRs. Later look changes must renumber above the landed version.
pub const LOOK_VERSION: u32 = 26;

#[derive(Clone, Debug)]
pub(crate) struct CameraLook {
Expand Down
12 changes: 9 additions & 3 deletions crates/engine/src/media/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,17 @@ impl MediaCache {
self.source_ref_with(p, level, false)
}

/// [`Self::source_ref`] without the photo's imported camera profile (keeping its denoised picture): a smart
/// preview keeps the file's own colour, and a cached source developed with the profile doesn't stand in for it.
/// The original without an imported camera profile, keeping denoise and hot-pixel settings.
/// Smart-preview builds must retry the file after reconnect, independently of cached decoded
/// proxies or offline availability. A cached look must never be stamped as the current fit.
#[cfg(not(target_arch = "wasm32"))]
pub fn source_ref_without_profile(&mut self, p: &Photo, level: SourceLevel) -> SourceRef {
self.source_ref_for(p, level, true, None)
let mut source = self.origin_ref(&p.source, level.max_edge());
if let SourceRef::File { denoise, outliers, .. } = &mut source {
*outliers = p.develop.removes_hot_pixels();
*denoise = self.denoise.get(p.id).map(|(spec, loader)| (spec.clone(), loader.clone()));
}
source
}

fn source_ref_with(&mut self, p: &Photo, level: SourceLevel, cached: bool) -> SourceRef {
Expand Down
3 changes: 2 additions & 1 deletion crates/engine/src/media/source.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use super::{Arc, DcpProfile, Deserialize, DevelopSettings, MediaKind, Photo, Rgb32f, Rgba8, Serialize, SourceInfo};

/// Bump when the pipeline's output changes, to invalidate cached thumbnails.
pub const RENDER_CACHE_VERSION: u64 = 76;
/// Above all open-PR assignments checked on 2026-11-05, including #160's `8 | (2 << 32)`.
pub const RENDER_CACHE_VERSION: u64 = 8_589_934_601;

/// Thumbnails render at one of these long edges (so window/cell size changes reuse the cache).
pub const THUMB_SIZES: [usize; 4] = [128, 256, 384, 512];
Expand Down
1 change: 1 addition & 0 deletions crates/engine/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ mod mask_effects;
mod mask_geometry;
mod merge;
mod move_to_share;
mod nikon_lens;
mod organize;
mod persist;
mod prefs;
Expand Down
6 changes: 5 additions & 1 deletion crates/engine/src/tests/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2674,7 +2674,11 @@ fn a_stale_refresh_never_rebuilds_a_proxy_from_itself() {
let pixels = lightcraft_raster::Rgb32f::from_fn(48, 32, |x, y| [0.02 + (x % 9) as f32 * 0.05, 0.03 + (y % 7) as f32 * 0.04, 0.06]);
let info = lightcraft_pipeline::SourceInfo { raw: true, as_shot_temp: 5200.0, as_shot_tint: 6.0, ..Default::default() };
let (p, i) = (pixels.clone(), info.clone());
s.media.file_loader = Some(std::sync::Arc::new(move |_path, _max_edge, _| Ok((p.clone(), i.clone()))));
s.media.file_loader = Some(std::sync::Arc::new(move |path, _max_edge, _| {
// A fresh attempt must fail while the original is offline, as a real decoder would.
std::fs::metadata(path).map_err(|error| error.to_string())?;
Ok((p.clone(), i.clone()))
}));
s.execute("library.import", &json!({"paths": [src.join("a.png").to_string_lossy()]})).unwrap();
let id = s.active().unwrap();
// a raw that takes the per-file camera look, so an older fit makes its proxy stale
Expand Down
Loading
Loading