LR-PROF-CAMERACOLOR: built-in ILCE-7M4 camera profile (#202)
A built-in Sony ILCE-7M4 colour profile (assets/camera-profiles/ILCE-7M4.json, compact JSON, 39 KB), fitted by lightcraft-cli calibrate to the contributor's own 597 raw photos against their in-camera JPEGs; aggregate colour statistics only, MIT OR Apache-2.0. Compiled in via camera_profiles::BUNDLED; a local profile replaces it. Co-authored-by: Harald Hoyer <harald@hoyer.xyz> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
fb9fb7717e
commit
707138f3fe
|
|
@ -10,6 +10,7 @@ covers a whole directory), or if a licence file referenced in the Licence column
|
|||
|---|---|---|---|---|---|---|
|
||||
| `assets/fonts/Inter-*.ttf` (Regular, Medium, SemiBold) | Inter | Rasmus Andersson | https://github.com/rsms/inter | SIL Open Font License 1.1 (`assets/fonts/OFL-Inter.txt`) | 2026-09-30 | none |
|
||||
| `assets/app-icon/` (`lightcraft.svg` and the PNG/ICNS/ICO/SVG files derived from it) | LightCraft app icon (lynx) | LightCraft project owner (drawn in ArtCraft) | original work (vectorised from the owner's drawing; see `assets/app-icon/README.md`) | MIT OR Apache-2.0 (`assets/app-icon/LICENSE.txt`) | 2026-10-02 | vectorised to SVG; rendered to PNG/ICNS/ICO by `packaging/icons.sh` |
|
||||
| `assets/camera-profiles/*.json` | Camera colour profiles (matrix + hue/saturation/value table), built into LightCraft | ILCE-7M4: Harald Hoyer | original work: fitted by `lightcraft-cli calibrate` to the contributor's own raw photos and their in-camera JPEGs (597 ILCE-7M4 photos, 2026); aggregate colour statistics only, no image content; no Adobe or third-party profile data | MIT OR Apache-2.0 | 2026-10-07 | none |
|
||||
| `crates/scenes/` (generated images) | Procedural demo photographs | LightCraft contributors | original work (generated at runtime, no source imagery) | MIT OR Apache-2.0 | 2026-09-30 | n/a |
|
||||
| `crates/ui-egui/src/icons.rs` | UI icons drawn as vector paths in code | LightCraft contributors | original work | MIT OR Apache-2.0 | 2026-09-30 | n/a |
|
||||
| `docs/images/*-tetons.jpg`, `docs/images/grid-pd.jpg` (screenshots containing it) | "The Tetons and the Snake River" | Ansel Adams (1942), U.S. National Archives | https://commons.wikimedia.org/wiki/File:Adams_The_Tetons_and_the_Snake_River.jpg | Public domain (U.S. federal government work) | 2026-09-30 | developed in LightCraft; shown inside app screenshots |
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -7,7 +7,8 @@
|
|||
//! table; photos of that model then only fit their tone and chroma curves.
|
||||
//!
|
||||
//! Profiles are JSON files (`<model>.json`) in [`dir`]: `LIGHTCRAFT_CAMERA_PROFILES`, else
|
||||
//! `<config>/camera-profiles`. They are read once per process; a damaged or hostile file is
|
||||
//! `<config>/camera-profiles`; a local profile replaces the one built in ([`BUNDLED`], from
|
||||
//! `assets/camera-profiles/`). They are read once per process; a damaged or hostile file is
|
||||
//! ignored with a warning. They hold aggregate colour statistics only, never image content.
|
||||
use lightcraft_color::Mat3;
|
||||
use lightcraft_raw::profile::HsvTable;
|
||||
|
|
@ -21,6 +22,10 @@ const VERSION: u32 = 1;
|
|||
/// Largest profile file read (a 5 × 72 × 5 table is ~60 KB of JSON).
|
||||
const MAX_FILE: u64 = 4 << 20;
|
||||
|
||||
/// Profiles built into LightCraft (`assets/camera-profiles/`, see `assets/ATTRIBUTION.md`):
|
||||
/// `(model, JSON)`.
|
||||
pub const BUNDLED: &[(&str, &str)] = &[("ILCE-7M4", include_str!("../../../assets/camera-profiles/ILCE-7M4.json"))];
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct CameraProfile {
|
||||
pub version: u32,
|
||||
|
|
@ -88,13 +93,24 @@ pub fn load(path: &Path) -> Result<CameraProfile, String> {
|
|||
return Err(format!("{}: {size} bytes is too large for a camera profile", path.display()));
|
||||
}
|
||||
let bytes = std::fs::read(path).map_err(|e| format!("{}: {e}", path.display()))?;
|
||||
let profile: CameraProfile = serde_json::from_slice(&bytes).map_err(|e| format!("{}: {e}", path.display()))?;
|
||||
parse(&bytes, &path.display().to_string())
|
||||
}
|
||||
|
||||
/// Parse and validate a profile's JSON (`origin` names it in errors).
|
||||
fn parse(json: &[u8], origin: &str) -> Result<CameraProfile, String> {
|
||||
let profile: CameraProfile = serde_json::from_slice(json).map_err(|e| format!("{origin}: {e}"))?;
|
||||
if !profile.valid() {
|
||||
return Err(format!("{}: not a usable camera profile (version {}, model {:?})", path.display(), profile.version, profile.model));
|
||||
return Err(format!("{origin}: not a usable camera profile (version {}, model {:?})", profile.version, profile.model));
|
||||
}
|
||||
Ok(profile)
|
||||
}
|
||||
|
||||
/// The built-in profile for `model`, if any.
|
||||
fn bundled(model: &str) -> Option<CameraProfile> {
|
||||
let (_, json) = BUNDLED.iter().find(|(m, _)| *m == model)?;
|
||||
parse(json.as_bytes(), &format!("built-in profile {model}")).inspect_err(|e| eprintln!("lightcraft: ignoring camera profile {e}")).ok()
|
||||
}
|
||||
|
||||
/// Write `profile` to `dir` (created if needed) as `<model>.json`; returns the path.
|
||||
pub fn save(profile: &CameraProfile, dir: &Path) -> Result<PathBuf, String> {
|
||||
std::fs::create_dir_all(dir).map_err(|e| format!("{}: {e}", dir.display()))?;
|
||||
|
|
@ -111,7 +127,7 @@ fn cache() -> &'static Mutex<HashMap<String, Option<Arc<CameraProfile>>>> {
|
|||
CACHE.get_or_init(Default::default)
|
||||
}
|
||||
|
||||
/// The profile for camera `model` from [`dir`], read once per process.
|
||||
/// The profile for camera `model`: from [`dir`], else built in; read once per process.
|
||||
pub fn get(model: &str) -> Option<Arc<CameraProfile>> {
|
||||
let model = model.trim();
|
||||
if model.is_empty() {
|
||||
|
|
@ -136,6 +152,7 @@ pub fn get(model: &str) -> Option<Arc<CameraProfile>> {
|
|||
},
|
||||
_ => None,
|
||||
};
|
||||
let profile = profile.or_else(|| bundled(model).map(Arc::new));
|
||||
cache.insert(model.to_owned(), profile.clone());
|
||||
profile
|
||||
}
|
||||
|
|
@ -145,8 +162,10 @@ pub fn get(model: &str) -> Option<Arc<CameraProfile>> {
|
|||
pub fn cache_key() -> u64 {
|
||||
static KEY: OnceLock<u64> = OnceLock::new();
|
||||
*KEY.get_or_init(|| {
|
||||
let Some(entries) = dir().and_then(|d| std::fs::read_dir(d).ok()) else { return 0 };
|
||||
let entries = dir().and_then(|d| std::fs::read_dir(d).ok());
|
||||
let mut files: Vec<(String, u64, u64)> = entries
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.flatten()
|
||||
.filter(|e| e.path().extension().is_some_and(|x| x == "json"))
|
||||
.filter_map(|e| {
|
||||
|
|
@ -160,6 +179,9 @@ pub fn cache_key() -> u64 {
|
|||
for (name, len, modified) in &files {
|
||||
h.str(name).u64(*len).u64(*modified);
|
||||
}
|
||||
for (model, json) in BUNDLED {
|
||||
h.str(model).str(json);
|
||||
}
|
||||
h.finish().0 as u64
|
||||
})
|
||||
}
|
||||
|
|
@ -258,6 +280,18 @@ mod tests {
|
|||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bundled_profiles_are_valid_and_named_after_their_model() {
|
||||
assert!(!BUNDLED.is_empty());
|
||||
for (model, json) in BUNDLED {
|
||||
let p = parse(json.as_bytes(), model).unwrap();
|
||||
assert_eq!(p.model, *model);
|
||||
assert!(p.files >= 5 && p.hue_sat.is_some(), "{model}: {} photos", p.files);
|
||||
assert_eq!(bundled(model), Some(p));
|
||||
}
|
||||
assert!(bundled("No Such Camera").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn file_names_are_safe() {
|
||||
assert_eq!(file_name("ILCE-7M4"), "ILCE-7M4.json");
|
||||
|
|
|
|||
|
|
@ -46,5 +46,5 @@ This is a per-file camera-look estimate, **not measured spectral calibration or
|
|||
|
||||
One photo can show too little of a colour for its own fit to learn it: in a second shot of the lime shirt only a few dozen proxy pixels show it, next to a hillside of foliage at the same hue that the camera renders differently, and the shirt stayed yellow (hue 68° against the JPEG's 82°; a 192-pixel proxy only reached 74°). `lightcraft-cli calibrate [--max N] [--out DIR] FOLDERS…` therefore pools the colour pairs of many ARWs per camera model — each against its own embedded JPEG, at a 192-pixel proxy, at most 4000 pairs per photo, files spread evenly over the folders — and fits one matrix (from white-balanced camera RGB, so no single photo's white point is baked in) and one hue/saturation/value table. Models need at least 5 usable photos.
|
||||
|
||||
Profiles are JSON files `<model>.json` in `$LIGHTCRAFT_CAMERA_PROFILES`, else `<config>/camera-profiles` (macOS `~/Library/Application Support/LightCraft/camera-profiles`). They hold aggregate colour statistics only. A photo of a profiled model takes its colour from the profile and fits only its own tone and chroma curves (DRO and picture styles vary per shot); the acceptance gates still apply, and a rejected fit falls back as before. Files are read once per process and validated (version, bounded invertible matrix, table shape and finite data); a damaged file is ignored with a warning. The profiles folder's contents are part of the render cache keys, so thumbnails rendered before a profile existed are redone; smart previews built before keep their colour until rebuilt.
|
||||
Profiles are JSON files `<model>.json` in `$LIGHTCRAFT_CAMERA_PROFILES`, else `<config>/camera-profiles` (macOS `~/Library/Application Support/LightCraft/camera-profiles`); a local profile replaces a built-in one. Built-in profiles live in `assets/camera-profiles/` (listed in `assets/ATTRIBUTION.md`) and are compiled in, so the app, CLI and web build share them: ILCE-7M4, fitted to 597 photos (2.2 million colour pairs) shot in 2026, mostly with the Standard creative style and DRO Auto. They hold aggregate colour statistics only. A photo of a profiled model takes its colour from the profile and fits only its own tone and chroma curves (DRO and picture styles vary per shot); the acceptance gates still apply, and a rejected fit falls back as before. Files are read once per process and validated (version, bounded invertible matrix, table shape and finite data); a damaged file is ignored with a warning. The profiles folder's contents are part of the render cache keys, so thumbnails rendered before a profile existed are redone; smart previews built before keep their colour until rebuilt.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue