Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ of it. Full standard: `../craftrules/standards/never-crash.md`
`colormatrices.c`, basecurves.
- Camera matrices are **never harvested from Adobe-converted DNGs**: check the DNG's `Software` tag (Adobe DNG
Converter, Lightroom, Camera Raw) and reject those. Camera-native DNGs (written by the camera itself) are fine.
- A person's **own** `.dcp` camera profiles and XMP looks may be imported at run time (`camera.importDcp`,
`profile.import`; maintainer decision 2026-10-18). None is ever committed, bundled or used as a test fixture: tests
build their bytes in code.
- Every PR that adds an algorithm has a **"Sources:"** line naming what it was built from: a paper, a prose spec, or
"own design".
- No GPL/LGPL/AGPL/MPL dependency may enter the build; `cargo deny` enforces the licence allow-list.
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ The milestone estimates in the table above were made before work started and are

- **AI features** (subject/sky/people masks, generative remove) need model weights with licences we can ship; classical
fallbacks first. No permissively licensed sky-segmentation or raw-denoise model was found — we may need to train our own.
- **Camera colour and lens data** is a data problem: we never use Adobe's matrices, DCPs or LCPs. DNG-embedded data first,
- **Camera colour and lens data** is a data problem: we never ship Adobe's matrices, DCPs or LCPs (a person's own `.dcp` files can be imported at run time, `camera.importDcp`; none is bundled). DNG-embedded data first,
then our own calibration; long-tail camera/lens coverage grows over time.
- **Raw-format sources:** decided 2026-10-05: decoders are written from *prose* format descriptions (even ones
published alongside GPL code); decoder source is never read. Still open: freedom-to-operate review for local
Expand Down
4 changes: 2 additions & 2 deletions apps/web/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ impl Originals {
/// Engine hooks that decode/probe from memory.
pub fn hooks(&self) -> (FileLoader, FileProbe) {
let s = self.clone();
let loader: FileLoader = Arc::new(move |path: &str, max_edge: usize, outliers: bool| {
let loader: FileLoader = Arc::new(move |path: &str, max_edge: usize, options| {
let bytes = s.get(path).ok_or_else(|| format!("{path}: the original is still loading from browser storage"))?;
load_bytes_with(&bytes, max_edge, outliers)
load_bytes_with(&bytes, max_edge, options)
});
let s = self.clone();
let probe: FileProbe = Arc::new(move |path: &str| {
Expand Down
10 changes: 5 additions & 5 deletions apps/web/src/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::sync::{Arc, Weak};

use lcc_engine::catalog::Source;
use lcc_engine::develop::{DevelopSettings, EmbeddedLens};
use lcc_engine::media::{DecodedSource, MediaCache, RenderJob, SourceLevel, SourceRef};
use lcc_engine::media::{DecodedSource, LoadOptions, MediaCache, RenderJob, SourceLevel, SourceRef};
use lcc_engine::pipeline::{Quality, RenderRequest, Rendered, SourceInfo, StageCache};
use lcc_preview::{Hash128, Lru, PreviewCache};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -131,7 +131,7 @@ impl WireJob {
fn source_key(&self) -> String {
match &self.origin {
Source::File { path } => {
format!("{}:{:?}:{}:{}:{path}", self.cache_generation, self.source_identity, self.max_edge, self.settings.detail.nr_outliers)
format!("{}:{:?}:{}:{:?}:{path}", self.cache_generation, self.source_identity, self.max_edge, LoadOptions::of(&self.settings))
}
Source::Demo { scene } => format!("{}:{:?}:{}:demo:{scene}", self.cache_generation, self.source_identity, self.max_edge),
}
Expand Down Expand Up @@ -184,9 +184,9 @@ impl WorkerCore {
None => {
let src = match (&job.origin, original) {
(Source::File { .. }, Some(bytes)) => {
let outliers = job.settings.detail.nr_outliers;
let (image, info) = lcc_engine::files::load_bytes_with(bytes, job.max_edge, outliers)?;
DecodedSource { outliers, ..DecodedSource::new(Arc::new(image), Some(info)) }
let options = LoadOptions::of(&job.settings);
let (image, info) = lcc_engine::files::load_bytes_with(bytes, job.max_edge, options.clone())?;
DecodedSource { options, ..DecodedSource::new(Arc::new(image), Some(info)) }
}
(Source::File { path }, None) => return Err(format!("{path}: original not found in browser storage")),
(origin @ Source::Demo { .. }, _) => self.media.origin_ref(origin, job.max_edge).load_source()?,
Expand Down
3 changes: 2 additions & 1 deletion crates/catalog/src/journal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
//! | 10 | video clips: VideoMeta, trim, poster | `Op::SetVideoMeta`, `Op::SetVideoTrim`, `Op::SetVideoPoster`, `Photo.video` |
//! | 11 | History cursor: Go to History Step adds no step | `Op::SetHistoryCursor`, `Photo.history_cursor` |
//! | 12 | upstream merge: preview-only recheck (upstream's 9, #662), the camera's focus point (#1480) | `Photo.preview_checked`, `Op::SetContent.preview_checked`, `Meta.focus` |
//! | 13 | a cleared GPS position stays cleared in the sidecar (upstream PR #2088) | `Meta.gps_removed` |
//!
//! Rules:
//! - **Bump [`VERSION`]** (and add a row above) in the change that adds an [`Op`] variant or a
Expand All @@ -81,7 +82,7 @@ pub(crate) const FORMAT: &str = "lcc-catalog";
pub(crate) const V4_FORMAT: &str = "lcc-catalog-db";
/// The catalog format this build writes (and the newest it reads). See the module docs →
/// *Format versions*; bump it whenever an [`Op`] variant or a serialized field is added.
pub const VERSION: u32 = 12;
pub const VERSION: u32 = 13;

/// When [`Journal::wants_snapshot`] says it's time to compact the log.
#[derive(Clone, Copy, Debug)]
Expand Down
7 changes: 6 additions & 1 deletion crates/catalog/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,13 @@ impl Catalog {
let old_edit = std::mem::replace(&mut p.edited, edited);
Op::SetDevelop { id, settings: old, label, edited: old_edit }
}
Op::SetMeta { id, meta } => {
Op::SetMeta { id, mut meta } => {
let p = self.photo_mut(id)?;
meta.gps_removed = match (p.meta.gps, meta.gps) {
(_, Some(_)) => None,
(Some(was), None) => Some(was),
(None, None) => p.meta.gps_removed,
};
Op::SetMeta { id, meta: Box::new(std::mem::replace(&mut p.meta, *meta)) }
}
Op::SetDeleted { id, deleted } => {
Expand Down
24 changes: 21 additions & 3 deletions crates/catalog/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ pub struct Meta {
pub state: String,
pub country: String,
pub gps: Option<(f64, f64)>,
/// The position (latitude, longitude) that was cleared from [`Meta::gps`], while it stays cleared: saving the
/// sidecar removes the GPS tags it still states for that very position (a different one was written by another
/// application later, and stays). The catalog keeps it in step on [`crate::Op::SetMeta`]: clearing a position
/// remembers it, setting any position forgets it, so undo and redo bring it back with the position.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub gps_removed: Option<(f64, f64)>,
pub title: String,
pub caption: String,
/// Accessibility text and long description.
Expand Down Expand Up @@ -444,7 +450,16 @@ pub fn relative_wb_format(format: &str) -> bool {
/// whatever the file's fit gives (upstream #730). A camera in `lcc_raw::kelvin_presets` does the same through
/// its own presets. The engine's render path (`files.rs`) decides the same way from the file; both must agree.
pub fn relative_wb_camera(format: &str, camera: &str) -> bool {
relative_wb_format(format) && lcc_raw::spectral::find_camera(camera).is_none() && !lcc_raw::kelvin_presets::covers_camera(camera)
relative_wb_camera_as(format, camera, "")
}

/// [`relative_wb_camera`] for a photo whose camera-profile choice is `choice` (`profile.camera`): a raw
/// developed through a `.dcp` has colour matrices and edits in Kelvin.
pub fn relative_wb_camera_as(format: &str, camera: &str, choice: &str) -> bool {
relative_wb_format(format)
&& lcc_raw::dcp::resolve_camera(choice, camera).is_none()
&& lcc_raw::spectral::find_camera(camera).is_none()
&& !lcc_raw::kelvin_presets::covers_camera(camera)
}

/// This build's version: what a photo's [`Photo::preview_checked`] stamp is compared with. Every
Expand Down Expand Up @@ -529,13 +544,16 @@ impl Photo {
/// WB multipliers, no colour matrices in the file; RWL and RAW are Leica's and the oldest Panasonic bodies'
/// names for RW2 files). The engine's `camera_preview::file_local_look` covers the same formats.
pub fn fitted_look(&self) -> bool {
self.develops_raw() && relative_wb_format(&self.format)
// (a raw developed through a `.dcp` takes its colour from the profile instead)
self.develops_raw()
&& relative_wb_format(&self.format)
&& lcc_raw::dcp::resolve_camera(&self.develop.profile.camera, &self.meta.camera).is_none()
}
/// White balance relative to the camera's as-shot look, as for rendered photographs: a
/// [`Photo::fitted_look`] raw whose camera has no colour matrices measured either
/// ([`relative_wb_camera`]). Other raws edit white balance in Kelvin.
pub fn relative_wb(&self) -> bool {
self.develops_raw() && relative_wb_camera(&self.format, &self.meta.camera)
self.develops_raw() && relative_wb_camera_as(&self.format, &self.meta.camera, &self.develop.profile.camera)
}
/// The develop settings import gave this photo: [`Photo::camera_defaults`], or the user's
/// default preset applied on top of them ([`Photo::import_look`]). Like the camera defaults,
Expand Down
39 changes: 37 additions & 2 deletions crates/catalog/src/tests_format_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,43 @@ fn op_variants_are_versioned() {
Op::SetHistoryCursor { .. } => 11,
}
}
/// v12: `Photo.preview_checked`, `Op::SetContent.preview_checked` and `Meta.focus`.
const NEWEST_FIELDS: u32 = 12;
/// v13: `Meta.gps_removed`.
const NEWEST_FIELDS: u32 = 13;
let newest = since(&Op::SetHistoryCursor { id: crate::PhotoId(1), cursor: None });
assert_eq!(newest.max(NEWEST_FIELDS), VERSION, "the newest op's or fields' version must be the current format version");
}

/// A cleared position is remembered by the catalog itself, whoever sets the metadata, and comes back with the position
/// on undo; setting any position forgets it. A library from before the field opens with nothing remembered.
#[test]
fn a_cleared_gps_position_is_remembered_and_undone_with_it() {
let mut c = Catalog::new();
let op = photo(&mut c);
c.apply(op).unwrap();
let id = c.photos().next().unwrap().id;
let set = |c: &mut Catalog, gps: Option<(f64, f64)>| {
let meta = Meta { gps, ..c.photo(id).unwrap().meta.clone() };
c.apply(Op::SetMeta { id, meta: Box::new(meta) }).unwrap()
};
let state = |c: &Catalog| (c.photo(id).unwrap().meta.gps, c.photo(id).unwrap().meta.gps_removed);
set(&mut c, Some((10.5, 20.25)));
assert_eq!(state(&c), (Some((10.5, 20.25)), None));
let undo_clear = set(&mut c, None);
assert_eq!(state(&c), (None, Some((10.5, 20.25))), "the position that was cleared");
set(&mut c, None);
assert_eq!(state(&c), (None, Some((10.5, 20.25))), "other edits keep it");
c.apply(undo_clear).unwrap();
assert_eq!(state(&c), (Some((10.5, 20.25)), None), "undo brings the position back and forgets the removal");
set(&mut c, None);
set(&mut c, Some((1.0, 2.0)));
assert_eq!(state(&c), (Some((1.0, 2.0)), None), "a new position forgets it");

// a library saved by the previous format has no such field and no removal
let snap = c.to_snapshot();
assert!(!snap.contains("gps_removed"), "unset, it is not written");
let m = MemStore::new();
m.set(SNAPSHOT, format!("{{\"format\":\"lcc-catalog\",\"version\":12,\"seq\":2,\"catalog\":{snap}}}\n").into_bytes());
let (_, loaded, r) = Journal::open(Box::new(m.clone())).unwrap();
assert_eq!(loaded.photo(id).unwrap().meta.gps_removed, None);
assert_eq!((r.upgraded_from, snapshot_version(&m)), (Some(12), u64::from(VERSION)));
}
40 changes: 40 additions & 0 deletions crates/develop/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,46 @@ mod tests {
assert_ne!(read.hash64(), DevelopSettings::for_raw(5500.0, 10.0).hash64(), "cached renders are told apart");
}

/// The Camera colour option is left out of the JSON while it is Auto (settings from before it keep their hash, and
/// every cached preview stays valid); Colorimetric is stored, read back, and changes the hash.
#[test]
fn camera_colour_is_stored_only_when_it_is_not_auto() {
let auto = DevelopSettings::default();
assert!(!auto.to_json().to_string().contains("camera_colour"));
let mut colorimetric = auto.clone();
colorimetric.profile.camera_colour = CameraColour::Colorimetric;
let v = colorimetric.to_json();
assert_eq!(v["profile"]["camera_colour"], json!("colorimetric"));
assert_eq!(DevelopSettings::from_json(&v).unwrap().profile.camera_colour, CameraColour::Colorimetric);
assert_ne!(colorimetric.hash64(), auto.hash64());
// a merge can set it back by name
let back: Profile = serde_json::from_value(json!({"camera_colour": "auto"})).unwrap();
assert!(back.camera_colour.is_auto());
}

/// A preset or sync of the Profile group carries the Camera colour both ways: Colorimetric onto an Auto photo,
/// and Auto back onto a Colorimetric one.
#[test]
fn the_profile_group_carries_the_camera_colour_both_ways() {
let auto = DevelopSettings::default();
let mut colorimetric = auto.clone();
colorimetric.profile.camera_colour = CameraColour::Colorimetric;
let on = extract_groups(&colorimetric, &[SettingsGroup::Profile]);
let off = extract_groups(&auto, &[SettingsGroup::Profile]);
assert_eq!(apply_partial(&auto, &on, 1.0).profile.camera_colour, CameraColour::Colorimetric);
assert_eq!(apply_partial(&colorimetric, &off, 1.0).profile.camera_colour, CameraColour::Auto);
// and a preset of the group still applies at a low amount (where discrete fields already take the preset's)
let mut lighter = colorimetric.clone();
lighter.light.exposure = 1.0;
let both = extract_groups(&lighter, &[SettingsGroup::Light, SettingsGroup::Profile]);
let weak = apply_partial(&auto, &both, 0.3);
assert!((weak.light.exposure - 0.3).abs() < 1e-9, "the preset applied: exposure {}", weak.light.exposure);
assert_eq!(weak.profile.camera_colour, CameraColour::Colorimetric, "a discrete field takes the preset's at any amount above 0");
// other groups leave it alone
let light = extract_groups(&auto, &[SettingsGroup::Light]);
assert_eq!(apply_partial(&colorimetric, &light, 1.0).profile.camera_colour, CameraColour::Colorimetric);
}

#[test]
fn serde_roundtrip_default_and_edited() {
let mut s = DevelopSettings::default();
Expand Down
5 changes: 5 additions & 0 deletions crates/develop/src/presets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ pub fn extract_groups(s: &DevelopSettings, groups: &[SettingsGroup]) -> Value {
}
}
}
// the Camera colour is left out of the settings while it is Auto; a preset or a sync of the Profile group still
// carries it, so that applying it turns a Colorimetric photo back to Auto
if let Some(Value::Object(profile)) = out.get_mut("profile") {
profile.entry("camera_colour").or_insert_with(|| serde_json::to_value(s.profile.camera_colour).unwrap_or(Value::Null));
}
Value::Object(out)
}

Expand Down
31 changes: 30 additions & 1 deletion crates/develop/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,40 @@ pub struct Profile {
/// settings without it keep their JSON (and hash).
#[serde(skip_serializing_if = "std::ops::Not::not")]
pub camera_local_tone: bool,
/// Where a raw without colour matrices of its own takes its starting colour from
/// (`docs/camera-preview-colour.md`). Omitted when [`CameraColour::Auto`], so settings without
/// it keep their JSON (and hash).
#[serde(skip_serializing_if = "CameraColour::is_auto")]
pub camera_colour: CameraColour,
/// How a raw's colour model is chosen: empty for its camera's default, `lc` for the app's own
/// colour, `dcp:<id>` for an imported `.dcp` camera profile. Omitted when empty, so settings
/// without it keep their JSON (and hash).
#[serde(default, skip_serializing_if = "String::is_empty")]
pub camera: String,
}

impl Default for Profile {
fn default() -> Self {
Self { id: "lc.color".into(), amount: 100.0, camera_local_tone: false }
Self { id: "lc.color".into(), amount: 100.0, camera_local_tone: false, camera_colour: CameraColour::Auto, camera: String::new() }
}
}

/// The starting colour of a raw that carries no colour matrices (NEF, ARW, CR3, …).
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum CameraColour {
/// The first available of: a camera profile with tone fitted to the file's JPEG, a look fitted
/// to the file's JPEG, the model's spectral matrices, the neutral fallback.
#[default]
Auto,
/// The model's matrices from measured spectral sensitivities with the app's default tone
/// curve, never the embedded JPEG; [`CameraColour::Auto`] for a model without them.
Colorimetric,
}

impl CameraColour {
pub fn is_auto(&self) -> bool {
*self == CameraColour::Auto
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/engine/examples/render_bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn main() {
}
println!(" {:<36} {}", "load_bytes(2560):", best(n, || drop(lcc_engine::files::load_bytes(&bytes, 2560).expect("load"))));
let (loader, _) = lcc_engine::files::fs_hooks();
println!(" {:<36} {}", "fs loader (2560, read+load):", best(n, || drop(loader(path, 2560, false).expect("load"))));
println!(" {:<36} {}", "fs loader (2560, read+load):", best(n, || drop(loader(path, 2560, Default::default()).expect("load"))));
}
return;
}
Expand Down
Loading
Loading