mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-25 03:53:53 +01:00
LR-META-EXIF-FULL: merge current main 487833ad1 (shutter times kept exactly through catalog and export, HDR PNG through the shared encoder) (#693)
This commit is contained in:
commit
ea5416d2e9
19 files changed
+474
-77
No files matched your search
Generated
+120
-7
@@ -641,6 +641,12 @@ dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "bit_field"
|
||||
version = "0.10.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb2907cc03d08cdb1c6724ad0670ce67c4a71e1c45a6d7635224011714cfc4b1"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "1.3.2"
|
||||
@@ -1184,7 +1190,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-crw"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=b77af389f30bb10de10d8436ca9b39fe94e3bb67#b77af389f30bb10de10d8436ca9b39fe94e3bb67"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18#f0f4758c01581d79577b9bf5046c06f4e77b1f18"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
@@ -1248,6 +1254,37 @@ dependencies = [
|
||||
"writeable",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-image-codecs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18#f0f4758c01581d79577b9bf5046c06f4e77b1f18"
|
||||
dependencies = [
|
||||
"craft-jpeg",
|
||||
"craft-metadata",
|
||||
"exr",
|
||||
"flate2",
|
||||
"half",
|
||||
"image",
|
||||
"image-webp",
|
||||
"jpeg-encoder 0.6.1",
|
||||
"png",
|
||||
"rayon",
|
||||
"serde_json",
|
||||
"thiserror 2.0.21",
|
||||
"tiff",
|
||||
"zune-core",
|
||||
"zune-jpeg",
|
||||
"zune-jpegxl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-jpeg"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18#f0f4758c01581d79577b9bf5046c06f4e77b1f18"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "craft-jxl"
|
||||
version = "0.1.0"
|
||||
@@ -1261,7 +1298,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-metadata"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=b77af389f30bb10de10d8436ca9b39fe94e3bb67#b77af389f30bb10de10d8436ca9b39fe94e3bb67"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18#f0f4758c01581d79577b9bf5046c06f4e77b1f18"
|
||||
dependencies = [
|
||||
"brotli-decompressor 6.0.1",
|
||||
"chrono",
|
||||
@@ -1284,7 +1321,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-raw"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=b77af389f30bb10de10d8436ca9b39fe94e3bb67#b77af389f30bb10de10d8436ca9b39fe94e3bb67"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18#f0f4758c01581d79577b9bf5046c06f4e77b1f18"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"craft-crw",
|
||||
@@ -1302,7 +1339,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-tiff"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=b77af389f30bb10de10d8436ca9b39fe94e3bb67#b77af389f30bb10de10d8436ca9b39fe94e3bb67"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=f0f4758c01581d79577b9bf5046c06f4e77b1f18#f0f4758c01581d79577b9bf5046c06f4e77b1f18"
|
||||
dependencies = [
|
||||
"serde",
|
||||
"thiserror 2.0.21",
|
||||
@@ -2060,6 +2097,22 @@ dependencies = [
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "exr"
|
||||
version = "1.74.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cb29d0be702adf92c645d9b2f93472906ba83d400e59f98adb3770ce5c18c2f6"
|
||||
dependencies = [
|
||||
"bit_field",
|
||||
"half",
|
||||
"lebe",
|
||||
"miniz_oxide 0.8.9",
|
||||
"multiversion",
|
||||
"rayon-core",
|
||||
"smallvec",
|
||||
"zune-inflate",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "faer-core"
|
||||
version = "0.17.1"
|
||||
@@ -3223,6 +3276,7 @@ dependencies = [
|
||||
"moxcms 0.8.1",
|
||||
"num-traits",
|
||||
"png",
|
||||
"qoi",
|
||||
"tiff",
|
||||
"zune-core",
|
||||
"zune-jpeg",
|
||||
@@ -3400,6 +3454,12 @@ dependencies = [
|
||||
"rayon",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "jpeg-encoder"
|
||||
version = "0.6.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b454d911ac55068f53495488d8ccd0646eaa540c033a28ee15b07838afafb01f"
|
||||
|
||||
[[package]]
|
||||
name = "jpeg-encoder"
|
||||
version = "0.7.1"
|
||||
@@ -3651,6 +3711,12 @@ dependencies = [
|
||||
"spin",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "lebe"
|
||||
version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7a79a3332a6609480d7d0c9eab957bca6b455b91bb84e66d19f5ff66294b85b8"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.191"
|
||||
@@ -3771,13 +3837,14 @@ dependencies = [
|
||||
"craft-gainmap",
|
||||
"craft-gif",
|
||||
"craft-heif",
|
||||
"craft-image-codecs",
|
||||
"craft-jxl",
|
||||
"craft-psd",
|
||||
"dhat",
|
||||
"image",
|
||||
"image-webp",
|
||||
"jpeg-decoder",
|
||||
"jpeg-encoder",
|
||||
"jpeg-encoder 0.7.1",
|
||||
"jxl-oxide",
|
||||
"lightcraft-color",
|
||||
"lightcraft-geom",
|
||||
@@ -4048,7 +4115,7 @@ dependencies = [
|
||||
name = "lightcraft-preview"
|
||||
version = "0.21.1"
|
||||
dependencies = [
|
||||
"jpeg-encoder",
|
||||
"jpeg-encoder 0.7.1",
|
||||
"lightcraft-raster",
|
||||
"log",
|
||||
"siphasher",
|
||||
@@ -4076,7 +4143,7 @@ dependencies = [
|
||||
"craft-raw",
|
||||
"craft-tiff",
|
||||
"dhat",
|
||||
"jpeg-encoder",
|
||||
"jpeg-encoder 0.7.1",
|
||||
"lightcraft-color",
|
||||
"lightcraft-geom",
|
||||
"lightcraft-meta",
|
||||
@@ -4395,6 +4462,28 @@ dependencies = [
|
||||
"windows-sys 0.61.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "multiversion"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eb8a68be21d0755f83bfe47e79b896cc732687cf1903f0e50585e8d6ecc53076"
|
||||
dependencies = [
|
||||
"multiversion-macros",
|
||||
"target-features",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "multiversion-macros"
|
||||
version = "0.8.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a05e0c3c3e4edaa21d87c645852ed0b0c3663752bcc6ec43353bd6189dce35e1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
"target-features",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "multiversion_no_op"
|
||||
version = "1.0.0"
|
||||
@@ -5569,6 +5658,15 @@ version = "0.1.30"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d55d956fa96f5ec02be2e13af0e20391a5aa83d6a074e3ad368959d0fab299ea"
|
||||
|
||||
[[package]]
|
||||
name = "qoi"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-error"
|
||||
version = "1.2.3"
|
||||
@@ -6655,6 +6753,12 @@ dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "target-features"
|
||||
version = "0.1.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c1bbb9f3c5c463a01705937a24fdabc5047929ac764b2d5b9cf681c1f5041ed5"
|
||||
|
||||
[[package]]
|
||||
name = "tempfile"
|
||||
version = "3.27.0"
|
||||
@@ -8329,6 +8433,15 @@ version = "0.5.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d56377fd46368984a170bc5aac5567e52ca5da874caa60bea39fcbca78fb658b"
|
||||
|
||||
[[package]]
|
||||
name = "zune-inflate"
|
||||
version = "0.2.54"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73ab332fe2f6680068f3582b16a24f90ad7096d5d39b974d1c0aff0125116f02"
|
||||
dependencies = [
|
||||
"simd-adler32",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zune-jpeg"
|
||||
version = "0.5.15"
|
||||
|
||||
+5
-4
@@ -13,11 +13,12 @@ repository = "https://github.com/storytold/lightcraft"
|
||||
craft-ui = { git = "https://github.com/storytold/craft-libs", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7", features = ["serde"] }
|
||||
craft-docpath = { version = "0.1.0", git = "https://github.com/storytold/craft-libs", rev = "c5a1cbfb5f9049f9270955caffb5bee5997aebf7" }
|
||||
# Canon CRW decoder shared with the other Craft apps
|
||||
craft-crw = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f30bb10de10d8436ca9b39fe94e3bb67" }
|
||||
craft-crw = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" }
|
||||
craft-gif = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f30bb10de10d8436ca9b39fe94e3bb67", features = ["frames"] }
|
||||
craft-jxl = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f30bb10de10d8436ca9b39fe94e3bb67", default-features = false, features = ["decode", "encode"] }
|
||||
# Photo metadata: EXIF, IPTC-IIM, XMP packets and GPX track logs (craft-libs#949)
|
||||
craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f30bb10de10d8436ca9b39fe94e3bb67" }
|
||||
craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" }
|
||||
craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" }
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f30bb10de10d8436ca9b39fe94e3bb67" }
|
||||
# craft-update: app-specific pretend versions apply to startup and manual checks.
|
||||
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "6e03f65bf45181db77ba6229716e6624db9eb25b", features = ["egui"] }
|
||||
@@ -36,10 +37,10 @@ lightcraft-wincolor = { path = "crates/wincolor" }
|
||||
lightcraft-color = { path = "crates/color" }
|
||||
lightcraft-raster = { path = "crates/raster" }
|
||||
# TIFF/IFD: the shared reader and writer (moved from crates/tiff; craft-libs#783).
|
||||
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f30bb10de10d8436ca9b39fe94e3bb67" }
|
||||
craft-tiff = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" }
|
||||
# Camera raw files, the format layer: every maker but CR3, ARW, RAF, RW2 and ORF (craft-libs#862 and the maker PRs).
|
||||
# On the same commit as craft-tiff: its errors and IFDs are shared.
|
||||
craft-raw = { git = "https://github.com/storytold/craft-libs", rev = "b77af389f30bb10de10d8436ca9b39fe94e3bb67" }
|
||||
craft-raw = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" }
|
||||
lightcraft-raw = { path = "crates/raw" }
|
||||
lightcraft-codecs = { path = "crates/codecs" }
|
||||
lightcraft-meta = { path = "crates/meta" }
|
||||
|
||||
@@ -180,7 +180,13 @@ pub struct Meta {
|
||||
pub lens_make: String,
|
||||
pub focal_mm: Option<f32>,
|
||||
pub aperture: Option<f32>,
|
||||
/// Shutter speed for display, from [`lightcraft_meta::format_exposure_time`] (`1/3`, `0.3571`, `2.5`).
|
||||
pub shutter: String,
|
||||
/// The file's exact exposure time in seconds, kept beside the rounded `shutter` text so export
|
||||
/// writes the original duration; read through [`Meta::shutter_seconds`]. Left out of the catalog
|
||||
/// JSON when unknown, so older catalogs read unchanged.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub exposure_time: Option<f64>,
|
||||
pub iso: Option<u32>,
|
||||
/// Whether the flash fired, from Exif `Flash`.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
@@ -224,6 +230,16 @@ pub struct Meta {
|
||||
pub focus: Option<lightcraft_meta::FocusPoint>,
|
||||
}
|
||||
|
||||
impl Meta {
|
||||
/// Shutter speed in seconds: the exact [`Meta::exposure_time`] while `shutter` still shows it,
|
||||
/// otherwise whatever `shutter` says (set by hand, or a catalog from before the exact time was kept).
|
||||
pub fn shutter_seconds(&self) -> Option<f64> {
|
||||
self.exposure_time
|
||||
.filter(|t| lightcraft_meta::format_exposure_time(*t).is_some_and(|text| text == self.shutter.trim()))
|
||||
.or_else(|| parse_shutter_seconds(&self.shutter))
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Version {
|
||||
pub name: String,
|
||||
@@ -761,7 +777,28 @@ mod edited_tests {
|
||||
|
||||
#[cfg(test)]
|
||||
mod shutter_tests {
|
||||
use super::parse_shutter_seconds;
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn shutter_seconds_prefers_the_exact_time_while_the_text_still_shows_it() {
|
||||
let mut m = Meta { shutter: "0.3571".into(), exposure_time: Some(1.0 / 2.8), ..Default::default() };
|
||||
assert_eq!(m.shutter_seconds(), Some(1.0 / 2.8));
|
||||
m.shutter = "1/3".into();
|
||||
m.exposure_time = Some(1.0 / 3.0);
|
||||
assert_eq!(m.shutter_seconds(), Some(1.0 / 3.0));
|
||||
// the text no longer matches the stored time (edited elsewhere): the text wins
|
||||
m.shutter = "1/250".into();
|
||||
assert_eq!(m.shutter_seconds(), Some(1.0 / 250.0));
|
||||
// an older catalog without the exact time
|
||||
m.exposure_time = None;
|
||||
m.shutter = "2.5".into();
|
||||
assert_eq!(m.shutter_seconds(), Some(2.5));
|
||||
// the exact time stays out of the JSON when unknown, and round-trips when known
|
||||
assert!(!serde_json::to_string(&m).unwrap().contains("exposure_time"));
|
||||
m.exposure_time = Some(2.5);
|
||||
let back: Meta = serde_json::from_str(&serde_json::to_string(&m).unwrap()).unwrap();
|
||||
assert_eq!(back.exposure_time, Some(2.5));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_fraction_needs_a_positive_numerator_and_denominator() {
|
||||
|
||||
@@ -1100,6 +1100,8 @@ impl Rule {
|
||||
"captureDate" => date_op(op, p.captured.as_deref(), value),
|
||||
"importDate" => date_op(op, Some(&p.imported), value),
|
||||
"editDate" => date_op(op, p.edited.as_deref(), value),
|
||||
// (the shown shutter text, not the exact time kept for export: a rule matches the value the
|
||||
// photo shows, `1/3` or `0.3571`, at every op, including `is` and the edges of a range)
|
||||
"shutterSpeed" => num_op(op, crate::parse_shutter_seconds(&m.shutter), &shutter_value(value)),
|
||||
"iso" => num_op(op, m.iso.map(|v| v as f64), value),
|
||||
"flash" => yes(m.flash.unwrap_or(false)),
|
||||
|
||||
@@ -795,3 +795,19 @@ fn file_path_contains_finds_every_piece_of_a_long_path() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shutter_speed_rules_match_the_shown_value() {
|
||||
let cat = Catalog::new();
|
||||
let mut p = photo(1);
|
||||
let m =
|
||||
|p: &Photo, op: &str, value: serde_json::Value| rs(json!({"rules": [{"field": "shutterSpeed", "op": op, "value": value}]})).matches(p, &cat);
|
||||
p.meta.exposure_time = Some(1.0 / 2.8);
|
||||
p.meta.shutter = "0.3571".into();
|
||||
assert!(m(&p, "is", json!("0.3571")) && !m(&p, "isNot", json!("0.3571")), "1/2.8 s is the 0.3571 it shows");
|
||||
assert!(m(&p, "lte", json!("0.3571")) && m(&p, "gte", json!("0.3571")));
|
||||
p.meta.exposure_time = Some(3333.0 / 10000.0);
|
||||
p.meta.shutter = "1/3".into();
|
||||
assert!(m(&p, "is", json!("1/3")) && !m(&p, "isNot", json!("1/3")), "3333/10000 s is the 1/3 it shows");
|
||||
assert!(m(&p, "gte", json!("1/3")) && m(&p, "lte", json!("1/3")) && !m(&p, "lt", json!("1/3")));
|
||||
}
|
||||
@@ -260,7 +260,7 @@ impl Catalog {
|
||||
.filter(|p| !p.deleted && !merged(p))
|
||||
.filter_map(|p| {
|
||||
let t = iso_seconds(p.captured.as_deref()?)?;
|
||||
let s = crate::model::parse_shutter_seconds(&p.meta.shutter)?;
|
||||
let s = p.meta.shutter_seconds()?;
|
||||
let n = p.meta.aperture.filter(|n| n.is_finite() && *n > 0.0).unwrap_or(1.0) as f64;
|
||||
let iso = p.meta.iso.filter(|i| *i > 0).unwrap_or(100) as f64;
|
||||
Some((t, p.file_name.as_str(), p.id, s, (s * iso / (n * n)).log2()))
|
||||
|
||||
@@ -13,6 +13,7 @@ lightcraft-geom = { workspace = true }
|
||||
lightcraft-color = { workspace = true }
|
||||
lightcraft-raster = { workspace = true }
|
||||
craft-gainmap = { workspace = true }
|
||||
craft-image-codecs = { workspace = true }
|
||||
craft-gif = { workspace = true }
|
||||
craft-psd = { workspace = true }
|
||||
craft-heif = { workspace = true, optional = true }
|
||||
|
||||
+14
-40
@@ -598,48 +598,22 @@ pub fn encode_avif_hdr(width: u32, height: u32, rgb: &[f32], quality: u8, speed:
|
||||
pub fn encode_png_pq(width: u32, height: u32, rgb: &[f32], meta: &EncodeMeta) -> Result<Vec<u8>> {
|
||||
let (w, h) = (width as usize, height as usize);
|
||||
let n = w.checked_mul(h).ok_or_else(|| Error::Encode("image too large".into()))?;
|
||||
if n == 0 || n.checked_mul(3).is_none_or(|need| rgb.len() < need) {
|
||||
let samples = n.checked_mul(3).ok_or_else(|| Error::Encode("image too large".into()))?;
|
||||
if n == 0 || rgb.len() < samples {
|
||||
return Err(Error::Encode("HDR PNG: sample buffer too short".into()));
|
||||
}
|
||||
const K: [f32; 3] = [0.2627, 0.6780, 0.0593]; // BT.2020 luminance
|
||||
let mut max_nits = 0f32;
|
||||
let mut sum_nits = 0f64;
|
||||
let mut bytes = Vec::with_capacity(n * 6);
|
||||
for c in rgb.as_chunks::<3>().0.iter().take(n) {
|
||||
let nits = c.map(|v| (if v.is_finite() { v.max(0.0) } else { 0.0 }) * HDR_REFERENCE_WHITE_NITS);
|
||||
max_nits = max_nits.max(nits[0].max(nits[1]).max(nits[2]));
|
||||
sum_nits += (K[0] * nits[0] + K[1] * nits[1] + K[2] * nits[2]) as f64;
|
||||
for v in nits {
|
||||
bytes.extend_from_slice(&((pq_encode(v) * 65535.0).round().clamp(0.0, 65535.0) as u16).to_be_bytes());
|
||||
}
|
||||
}
|
||||
let cll = (max_nits.ceil().clamp(1.0, 10_000.0) as u32, ((sum_nits / n as f64).ceil().clamp(1.0, 10_000.0)) as u32);
|
||||
let mut info = png::Info::with_size(width, height);
|
||||
info.color_type = png::ColorType::Rgb;
|
||||
info.bit_depth = png::BitDepth::Sixteen;
|
||||
info.exif_metadata = meta.exif.map(|b| b.to_vec().into());
|
||||
info.pixel_dims = meta.ppi.filter(|p| *p > 0).map(|p| {
|
||||
let ppm = (p as f64 / 0.0254).round() as u32;
|
||||
png::PixelDimensions { xppu: ppm, yppu: ppm, unit: png::Unit::Meter }
|
||||
});
|
||||
let mut out = Vec::new();
|
||||
let e = |e: png::EncodingError| Error::Encode(e.to_string());
|
||||
{
|
||||
let mut enc = png::Encoder::with_info(&mut out, info).map_err(e)?;
|
||||
enc.set_compression(png::Compression::Fast);
|
||||
if let Some(xmp) = meta.xmp {
|
||||
enc.add_itxt_chunk("XML:com.adobe.xmp".into(), xmp.into()).map_err(e)?;
|
||||
}
|
||||
let mut wr = enc.write_header().map_err(e)?;
|
||||
// BT.2020 primaries (9), PQ (16), RGB (0), full range (1)
|
||||
wr.write_chunk(png::chunk::ChunkType(*b"cICP"), &[9, 16, 0, 1]).map_err(e)?;
|
||||
// MaxCLL and MaxFALL in units of 0.0001 cd/m²
|
||||
let clli = [(cll.0 * 10_000).to_be_bytes(), (cll.1 * 10_000).to_be_bytes()].concat();
|
||||
wr.write_chunk(png::chunk::ChunkType(*b"cLLI"), &clli).map_err(e)?;
|
||||
wr.write_image_data(&bytes).map_err(e)?;
|
||||
wr.finish().map_err(e)?;
|
||||
}
|
||||
Ok(out)
|
||||
let mut image = craft_image_codecs::Image::from_f32(
|
||||
width,
|
||||
height,
|
||||
craft_image_codecs::ChannelLayout::Rgb,
|
||||
rgb.get(..samples).ok_or_else(|| Error::Encode("HDR PNG: sample buffer too short".into()))?,
|
||||
)
|
||||
.map_err(|e| Error::Encode(e.to_string()))?;
|
||||
image.meta.exif = meta.exif.map(ToOwned::to_owned);
|
||||
image.meta.xmp = meta.xmp.map(ToOwned::to_owned);
|
||||
image.meta.dpi = meta.ppi.filter(|&ppi| ppi > 0).map(|ppi| (f32::from(ppi), f32::from(ppi)));
|
||||
let options = craft_image_codecs::EncodeOptions { png_compression: craft_image_codecs::PngCompression::Fast, ..Default::default() };
|
||||
craft_image_codecs::encode_png_pq(&image, &options).map_err(|e| Error::Encode(e.to_string()))
|
||||
}
|
||||
|
||||
/// 16-bit RGB(A) → 10-bit BT.601 full-range YCbCr planes (the matrix `ravif` uses for 8-bit input).
|
||||
|
||||
@@ -749,12 +749,17 @@ fn pq_png_is_16_bit_rec2020_pq_with_cicp_and_content_light() {
|
||||
})
|
||||
.collect();
|
||||
let xmp = r#"<x:xmpmeta xmlns:x="adobe:ns:meta/"/>"#;
|
||||
let bytes = encode_png_pq(w, h, &rgb, &EncodeMeta { xmp: Some(xmp), ppi: Some(240), ..Default::default() }).unwrap();
|
||||
let exif = minimal_exif(1);
|
||||
let bytes = encode_png_pq(w, h, &rgb, &EncodeMeta { exif: Some(&exif), xmp: Some(xmp), ppi: Some(240), ..Default::default() }).unwrap();
|
||||
let mut r = png::Decoder::new(std::io::Cursor::new(bytes.as_slice())).read_info().unwrap();
|
||||
let cicp = r.info().coding_independent_code_points.expect("cICP");
|
||||
assert_eq!((cicp.color_primaries, cicp.transfer_function), (9, 16), "BT.2020, PQ");
|
||||
let ppi = r.info().pixel_dims.expect("pHYs");
|
||||
assert_eq!((ppi.xppu, ppi.yppu), (9449, 9449), "240 PPI converted to pixels per meter");
|
||||
assert_eq!(ppi.unit, png::Unit::Meter);
|
||||
let mut buf = vec![0; r.output_buffer_size().unwrap()];
|
||||
let f = r.next_frame(&mut buf).unwrap();
|
||||
assert!(r.info().exif_metadata.is_some(), "EXIF kept");
|
||||
assert_eq!((f.bit_depth, f.color_type, f.width, f.height), (png::BitDepth::Sixteen, png::ColorType::Rgb, w, h));
|
||||
// every sample decodes back to its luminance
|
||||
for x in [0usize, 20, 63] {
|
||||
@@ -770,6 +775,12 @@ fn pq_png_is_16_bit_rec2020_pq_with_cicp_and_content_light() {
|
||||
let max_cll = u32::from_be_bytes(bytes[at + 4..at + 8].try_into().unwrap()) as f32 / 10_000.0;
|
||||
let brightest = rgb.iter().copied().fold(0.0f32, f32::max) * HDR_REFERENCE_WHITE_NITS;
|
||||
assert!((max_cll - brightest.ceil()).abs() <= 1.0, "{max_cll} vs {brightest}");
|
||||
let max_fall = u32::from_be_bytes(bytes[at + 8..at + 12].try_into().unwrap()) / 10_000;
|
||||
let expected_max_fall =
|
||||
(rgb.as_chunks::<3>().0.iter().map(|p| f64::from(p.iter().copied().fold(0.0f32, f32::max) * HDR_REFERENCE_WHITE_NITS)).sum::<f64>()
|
||||
/ f64::from(w * h))
|
||||
.ceil() as u32;
|
||||
assert_eq!(max_fall, expected_max_fall, "MaxFALL uses CTA-861.3-A's per-pixel maximum channel");
|
||||
assert!(bytes.windows(17).any(|w| w == b"XML:com.adobe.xmp"), "XMP kept");
|
||||
assert!(bytes.windows(4).any(|w| w == b"pHYs"), "print resolution kept");
|
||||
assert!(!bytes.windows(4).any(|w| w == b"iCCP"), "no ICC profile next to cICP");
|
||||
|
||||
@@ -241,6 +241,9 @@ fn fill_missing_meta(id: lightcraft_catalog::PhotoId, ph: &lightcraft_catalog::P
|
||||
}
|
||||
if m.shutter.is_empty() {
|
||||
m.shutter = src.shutter.clone();
|
||||
m.exposure_time = src.exposure_time;
|
||||
} else {
|
||||
repair_legacy_shutter(&mut m, src);
|
||||
}
|
||||
m.focal_mm = m.focal_mm.or(src.focal_mm);
|
||||
m.aperture = m.aperture.or(src.aperture);
|
||||
@@ -265,6 +268,26 @@ fn fill_missing_meta(id: lightcraft_catalog::PhotoId, ph: &lightcraft_catalog::P
|
||||
ops
|
||||
}
|
||||
|
||||
/// Repair only the shutter data an old import wrote, keeping independently edited metadata.
|
||||
fn repair_legacy_shutter(m: &mut lightcraft_catalog::Meta, src: &lightcraft_catalog::Meta) -> bool {
|
||||
if m.exposure_time.is_none()
|
||||
&& let Some(t) = src.exposure_time
|
||||
&& (m.shutter.trim() == src.shutter || legacy_shutter_text(t).is_some_and(|old| m.shutter.trim() == old))
|
||||
{
|
||||
m.shutter = src.shutter.clone();
|
||||
m.exposure_time = Some(t);
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
/// The shutter text an import wrote before the exact exposure time was kept (#1619): whole seconds at
|
||||
/// one second and over, otherwise `1/n` with `n` rounded. Only for recognising such a text again.
|
||||
fn legacy_shutter_text(t: f64) -> Option<String> {
|
||||
(t.is_finite() && t > 0.0).then(|| if t >= 1.0 { format!("{t:.0}") } else { format!("1/{:.0}", 1.0 / t) })
|
||||
}
|
||||
|
||||
/// Ops that give a photo the lens data its file carries now (`info`, a fresh probe), or none when
|
||||
/// it already has them. A catalog from before the lens data was read at import has none, so such a
|
||||
/// photo's correction stayed off. When the photo gains lens data and its develop settings are still
|
||||
@@ -314,8 +337,16 @@ pub(crate) fn reload_ops(
|
||||
}
|
||||
// virtual copies share the file
|
||||
for c in cat.photos().filter(|c| c.copy_of == Some(id)) {
|
||||
let theirs: Vec<Op> =
|
||||
content_op(c.id, c, info.clone()).into_iter().chain(lens_ops(c.id, c, info)).chain(as_shot_wb_op(c.id, c, info)).collect();
|
||||
let mut meta = c.meta.clone();
|
||||
// Copies share the source file but may have independently edited metadata. Repair only
|
||||
// recognizable legacy shutter values, not every missing field on the copy.
|
||||
let shutter_op = repair_legacy_shutter(&mut meta, &info.meta).then(|| Op::SetMeta { id: c.id, meta: Box::new(meta) });
|
||||
let theirs: Vec<Op> = content_op(c.id, c, info.clone())
|
||||
.into_iter()
|
||||
.chain(shutter_op)
|
||||
.chain(lens_ops(c.id, c, info))
|
||||
.chain(as_shot_wb_op(c.id, c, info))
|
||||
.collect();
|
||||
if !theirs.is_empty() {
|
||||
ops.extend(theirs);
|
||||
changed.push(c.id);
|
||||
@@ -441,6 +472,78 @@ mod tests {
|
||||
assert!(fill_missing_meta(PhotoId(1), &ph, &info).is_empty());
|
||||
}
|
||||
|
||||
/// Reload from Disk repairs a shutter speed an older import rounded (0.4 s stored as `1/2`, with no
|
||||
/// exact time): the photo takes the file's exact time and today's text. A shutter speed set by hand
|
||||
/// that is not what an import wrote, and one that already has its exact time, are kept.
|
||||
#[test]
|
||||
fn reload_repairs_a_shutter_speed_an_older_import_rounded() {
|
||||
let mut ph = Photo::new(PhotoId(1), Source::File { path: "/x.nef".into() }, "x.nef", "NEF", 6000, 4000, "2026-10-06T00:00:00");
|
||||
ph.captured = Some("2026-10-04T08:16:11".into());
|
||||
let mut info = crate::media::ProbeInfo { captured: ph.captured.clone(), ..Default::default() };
|
||||
for (t, legacy, shown) in [(0.4, "1/2", "0.4"), (2.5, "2", "2.5"), (1.0 / 2.8, "1/3", "0.3571"), (1.0 / 250.0, "1/250", "1/250")] {
|
||||
info.meta.exposure_time = Some(t);
|
||||
info.meta.shutter = lightcraft_meta::format_exposure_time(t).unwrap();
|
||||
ph.meta.shutter = legacy.into();
|
||||
ph.meta.exposure_time = None;
|
||||
let ops = fill_missing_meta(PhotoId(1), &ph, &info);
|
||||
let Some(Op::SetMeta { meta, .. }) = ops.first() else { panic!("{t}: {ops:?}") };
|
||||
assert_eq!((meta.shutter.as_str(), meta.exposure_time), (shown, Some(t)), "{t}");
|
||||
assert_eq!(meta.shutter_seconds(), Some(t), "{t}");
|
||||
// repaired → nothing more to do
|
||||
ph.meta = (**meta).clone();
|
||||
assert!(fill_missing_meta(PhotoId(1), &ph, &info).is_empty(), "{t}");
|
||||
}
|
||||
// typed by hand, not what any import wrote for this file
|
||||
info.meta.exposure_time = Some(0.4);
|
||||
info.meta.shutter = "0.4".into();
|
||||
ph.meta.shutter = "1/8".into();
|
||||
ph.meta.exposure_time = None;
|
||||
assert!(fill_missing_meta(PhotoId(1), &ph, &info).is_empty(), "a hand-set shutter speed is kept");
|
||||
// already has an exact time (the text was edited afterwards): kept
|
||||
ph.meta.shutter = "1/2".into();
|
||||
ph.meta.exposure_time = Some(0.4);
|
||||
assert!(fill_missing_meta(PhotoId(1), &ph, &info).is_empty(), "a photo with an exact time is left alone");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reload_repairs_legacy_shutter_on_copies_without_replacing_edits() {
|
||||
let mut cat = lightcraft_catalog::Catalog::new();
|
||||
let mut source = Photo::new(PhotoId(1), Source::File { path: "/x.nef".into() }, "x.nef", "NEF", 6000, 4000, "");
|
||||
source.meta.shutter = "1/2".into();
|
||||
cat.apply(Op::AddPhoto { photo: Box::new(source.clone()) }).unwrap();
|
||||
for (id, text, exact) in [(2, "1/2", None), (3, "0.4", None), (4, "1/8", None), (5, "1/2", Some(0.4))] {
|
||||
let mut copy = source.clone();
|
||||
copy.id = PhotoId(id);
|
||||
copy.copy_of = Some(source.id);
|
||||
copy.meta.shutter = text.into();
|
||||
copy.meta.exposure_time = exact;
|
||||
copy.meta.title = "My copy".into();
|
||||
cat.apply(Op::AddPhoto { photo: Box::new(copy) }).unwrap();
|
||||
}
|
||||
let mut info = crate::media::ProbeInfo::default();
|
||||
info.meta.shutter = "0.4".into();
|
||||
info.meta.exposure_time = Some(0.4);
|
||||
info.meta.title = "File title".into();
|
||||
let mut ops = Vec::new();
|
||||
let mut changed = Vec::new();
|
||||
reload_ops(&cat, source.id, &info, &mut ops, &mut changed);
|
||||
for op in ops {
|
||||
cat.apply(op).unwrap();
|
||||
}
|
||||
for id in [1, 2, 3] {
|
||||
let m = &cat.photo(PhotoId(id)).unwrap().meta;
|
||||
assert_eq!((m.shutter.as_str(), m.exposure_time), ("0.4", Some(0.4)));
|
||||
assert_eq!(m.shutter_seconds(), Some(0.4));
|
||||
}
|
||||
for (id, text, exact) in [(4, "1/8", None), (5, "1/2", Some(0.4))] {
|
||||
let m = &cat.photo(PhotoId(id)).unwrap().meta;
|
||||
assert_eq!((m.shutter.as_str(), m.exposure_time), (text, exact));
|
||||
}
|
||||
for id in [2, 3, 4, 5] {
|
||||
assert_eq!(cat.photo(PhotoId(id)).unwrap().meta.title, "My copy");
|
||||
}
|
||||
}
|
||||
|
||||
/// Reload from Disk gives a photo imported before focus points were read its camera focus point,
|
||||
/// and never replaces one it has.
|
||||
#[test]
|
||||
|
||||
@@ -1277,10 +1277,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
// log2 of the light the photo gathered (shutter s × ISO / f-number²)
|
||||
let gathered = |s: &Session, id: PhotoId| -> Option<f64> {
|
||||
let m = &s.catalog.photo(id)?.meta;
|
||||
let t = match m.shutter.split_once('/') {
|
||||
Some((a, b)) => a.trim().parse::<f64>().ok()? / b.trim().parse::<f64>().ok()?,
|
||||
None => m.shutter.trim().trim_end_matches('s').trim().parse::<f64>().ok()?,
|
||||
};
|
||||
let t = m.shutter_seconds()?;
|
||||
let (n, iso) = (m.aperture? as f64, m.iso? as f64);
|
||||
(t > 0.0 && n > 0.0 && iso > 0.0).then(|| (t * iso / (n * n)).log2())
|
||||
};
|
||||
|
||||
@@ -342,7 +342,7 @@ pub fn export_metadata(photo: &lightcraft_catalog::Photo, catalog: &lightcraft_c
|
||||
out.lens_model = text(&m.lens);
|
||||
out.focal_length = m.focal_mm.map(f64::from);
|
||||
out.f_number = m.aperture.map(f64::from);
|
||||
out.exposure_time = lightcraft_catalog::parse_shutter_seconds(&m.shutter);
|
||||
out.exposure_time = m.shutter_seconds();
|
||||
out.iso = m.iso;
|
||||
}
|
||||
Some(out)
|
||||
|
||||
@@ -3,7 +3,8 @@ use super::preview::embedded_preview_size;
|
||||
use super::{MediaKind, Meta, Orientation, ProbeInfo};
|
||||
|
||||
pub(super) fn meta_of(m: &lightcraft_meta::Metadata) -> (Meta, Option<String>) {
|
||||
let shutter = m.exposure_time.map(|t| if t >= 1.0 { format!("{t:.0}") } else { format!("1/{:.0}", 1.0 / t) }).unwrap_or_default();
|
||||
let exposure_time = m.exposure_time.filter(|t| t.is_finite() && *t > 0.0);
|
||||
let shutter = exposure_time.and_then(lightcraft_meta::format_exposure_time).unwrap_or_default();
|
||||
let camera = [m.make.clone().unwrap_or_default(), m.model.clone().unwrap_or_default()].join(" ").trim().to_string();
|
||||
let meta = Meta {
|
||||
camera,
|
||||
@@ -14,6 +15,7 @@ pub(super) fn meta_of(m: &lightcraft_meta::Metadata) -> (Meta, Option<String>) {
|
||||
focal_mm: m.focal_length.map(|f| f as f32),
|
||||
aperture: m.f_number.map(|f| f as f32),
|
||||
shutter,
|
||||
exposure_time,
|
||||
iso: m.iso,
|
||||
flash: m.flash.map(|f| f.fired),
|
||||
exposure_bias: m.exposure_bias.map(|v| v as f32),
|
||||
|
||||
@@ -1851,6 +1851,44 @@ fn existing_photo_settings_are_not_rewritten() {
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn imported_shutter_times_survive_catalog_and_export_metadata() {
|
||||
use lightcraft_catalog::{Catalog, Photo, PhotoId};
|
||||
for (t, shown) in [
|
||||
(0.3, "0.3"),
|
||||
(0.4, "0.4"),
|
||||
(0.6, "0.6"),
|
||||
(0.8, "0.8"),
|
||||
(1.3, "1.3"),
|
||||
(1.6, "1.6"),
|
||||
(2.5, "2.5"),
|
||||
(3.2, "3.2"),
|
||||
(30.0, "30"),
|
||||
(0.625, "0.625"),
|
||||
(1.0 / 2.8, "0.3571"),
|
||||
(1.0 / 3.0, "1/3"),
|
||||
(0.003, "0.003"),
|
||||
(1.0 / 250.0, "1/250"),
|
||||
(1.0 / 8000.0, "1/8000"),
|
||||
] {
|
||||
let original = lightcraft_meta::Metadata { exposure_time: Some(t), ..Default::default() };
|
||||
let (meta, _) = meta_of(&original);
|
||||
// the catalog shows a short shutter speed, never the raw f64 (`0.35714285714285715`)
|
||||
assert_eq!(meta.shutter, shown, "{t}");
|
||||
// Exercise the persisted catalog JSON, not a value kept alongside it in memory.
|
||||
let meta: Meta = serde_json::from_str(&serde_json::to_string(&meta).unwrap()).unwrap();
|
||||
let mut photo = Photo::new(PhotoId(1), lightcraft_catalog::Source::Demo { scene: 0 }, "capture.jpg", "JPEG", 2, 2, "");
|
||||
photo.meta = meta;
|
||||
let exported = crate::export::export_metadata(&photo, &Catalog::new(), &crate::export::ExportOptions::default()).unwrap();
|
||||
assert_eq!(exported.exposure_time, Some(t));
|
||||
let bytes =
|
||||
crate::export::encode_with_metadata(&lightcraft_raster::Rgba8::new(2, 2), &crate::export::ExportOptions::default(), Some(&exported))
|
||||
.unwrap();
|
||||
let back = lightcraft_meta::extract(&bytes);
|
||||
assert!((back.exposure_time.unwrap() - t).abs() < 0.000001, "{t}: {:?}", back.exposure_time);
|
||||
}
|
||||
}
|
||||
|
||||
/// Issue #1632: a DNG's `ProfileToneCurve` is the finish stage's camera curve, so process V5 extends
|
||||
/// it past its last point (the sensor's white, scene 1.0) with the stop roll-off as well. A curve
|
||||
/// that reaches white there renders as under V4 up to it and white past it; one that ends below
|
||||
|
||||
@@ -756,4 +756,14 @@ mod write_tests {
|
||||
assert!((1.0 / got - den).abs() < 0.5, "1/{den} s came back as 1/{}", 1.0 / got);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn written_shutter_speeds_show_as_the_same_reciprocal() {
|
||||
// #1619 / #2542: the exact time is what export writes, and it reads back as the text shown
|
||||
for (t, want) in [(1.0 / 3.0, "1/3"), (1.0 / 250.0, "1/250"), (1.0 / 12_800.0, "1/12800"), (0.3, "0.3"), (1.0 / 2.8, "0.3571")] {
|
||||
let back = read_exif(&write_exif(&Metadata { exposure_time: Some(t), ..Default::default() }));
|
||||
let got = back.exposure_time.unwrap();
|
||||
assert_eq!(crate::format_exposure_time(got).as_deref(), Some(want), "{t} came back as {got}");
|
||||
}
|
||||
}
|
||||
}
|
||||
+72
-12
@@ -178,6 +178,29 @@ macro_rules! overlay {
|
||||
($self:ident, $o:ident, $($f:ident),*) => { $( if $o.$f.is_some() { $self.$f = $o.$f.clone(); } )* };
|
||||
}
|
||||
|
||||
/// How far (relative) a duration may be from an exact `1/n` second and still be shown as `1/n`:
|
||||
/// absorbs decimal EXIF rationals such as `3333/10000` for 1/3 s without turning 0.3 s or
|
||||
/// 1/2.8 s into a reciprocal they aren't.
|
||||
pub const RECIPROCAL_TOLERANCE: f64 = 1e-3;
|
||||
|
||||
/// The one shutter-speed formatter for display (catalog `shutter`, Info panel, All Metadata):
|
||||
/// a near-exact `1/n` second as `1/n` (`1/3`, `1/250`), anything else rounded to four
|
||||
/// significant digits with trailing zeros dropped (`0.3`, `0.3571`, `2.5`, `30`). Display only:
|
||||
/// export writes the exact duration. `None` for a time that isn't positive and finite.
|
||||
pub fn format_exposure_time(t: f64) -> Option<String> {
|
||||
if !t.is_finite() || t <= 0.0 {
|
||||
return None;
|
||||
}
|
||||
let n = (1.0 / t).round();
|
||||
if n >= 2.0 && n.is_finite() && (1.0 / (n * t) - 1.0).abs() <= RECIPROCAL_TOLERANCE {
|
||||
return Some(format!("1/{n}"));
|
||||
}
|
||||
// four significant digits; whole seconds never lose digits
|
||||
let decimals = (3 - t.log10().floor() as i32).max(0) as usize;
|
||||
let text = format!("{t:.decimals$}");
|
||||
Some(if text.contains('.') { text.trim_end_matches('0').trim_end_matches('.').to_string() } else { text })
|
||||
}
|
||||
|
||||
impl Metadata {
|
||||
/// Fill every empty field of `self` from `other`.
|
||||
pub fn fill_missing(&mut self, other: &Metadata) {
|
||||
@@ -261,19 +284,10 @@ impl Metadata {
|
||||
}
|
||||
}
|
||||
|
||||
/// Exposure time formatted like cameras show it: `1/250`, `0.5`, `2″`.
|
||||
/// Exposure time formatted like cameras show it: `1/250`, `0.3571`, `2.5″` (see [`format_exposure_time`]).
|
||||
pub fn exposure_display(&self) -> Option<String> {
|
||||
let t = self.exposure_time?;
|
||||
if t.is_nan() || t <= 0.0 {
|
||||
return None;
|
||||
}
|
||||
Some(if t < 0.3 {
|
||||
format!("1/{}", (1.0 / t).round())
|
||||
} else if t < 1.0 {
|
||||
format!("{}", (t * 10.0).round() / 10.0)
|
||||
} else {
|
||||
format!("{}″", (t * 10.0).round() / 10.0)
|
||||
})
|
||||
format_exposure_time(t).map(|text| if t >= 1.0 { format!("{text}″") } else { text })
|
||||
}
|
||||
|
||||
/// Human name of the metering mode.
|
||||
@@ -452,12 +466,58 @@ mod tests {
|
||||
assert_eq!(parse_number("inf"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exposure_time_formats_reciprocals_and_significant_digits() {
|
||||
for (t, want) in [
|
||||
(1.0 / 3.0, "1/3"),
|
||||
(1.0 / 250.0, "1/250"),
|
||||
(1.0 / 8000.0, "1/8000"),
|
||||
(0.5, "1/2"),
|
||||
(0.3, "0.3"),
|
||||
(0.4, "0.4"),
|
||||
(1.0 / 2.8, "0.3571"),
|
||||
(0.625, "0.625"),
|
||||
(0.003, "0.003"),
|
||||
(1.0, "1"),
|
||||
(1.3, "1.3"),
|
||||
(2.5, "2.5"),
|
||||
(30.0, "30"),
|
||||
(9.99996, "10"),
|
||||
(1800.0, "1800"),
|
||||
] {
|
||||
assert_eq!(format_exposure_time(t).as_deref(), Some(want), "{t}");
|
||||
}
|
||||
for t in [0.0, -1.0, f64::NAN, f64::INFINITY, f64::NEG_INFINITY] {
|
||||
assert_eq!(format_exposure_time(t), None, "{t}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exposure_time_reciprocal_tolerance() {
|
||||
// a camera's decimal rational for 1/3 s, and times just inside the tolerance either side
|
||||
assert_eq!(format_exposure_time(3333.0 / 10000.0).as_deref(), Some("1/3"));
|
||||
// a microsecond-level rational error still reads as 1/8000; above ~1/1000 s every time is
|
||||
// within the tolerance of some 1/n, which is how cameras show those speeds anyway
|
||||
assert_eq!(format_exposure_time(1.0 / 8000.0 * (1.0 + 1e-5)).as_deref(), Some("1/8000"));
|
||||
for n in [3.0, 10.0, 250.0] {
|
||||
let inside = 0.9 * RECIPROCAL_TOLERANCE;
|
||||
let outside = 1.1 * RECIPROCAL_TOLERANCE;
|
||||
let want = format!("1/{n}");
|
||||
assert_eq!(format_exposure_time(1.0 / n * (1.0 + inside)).as_deref(), Some(want.as_str()), "{n} +inside");
|
||||
assert_eq!(format_exposure_time(1.0 / n * (1.0 - inside)).as_deref(), Some(want.as_str()), "{n} -inside");
|
||||
assert_ne!(format_exposure_time(1.0 / n * (1.0 + outside)).as_deref(), Some(want.as_str()), "{n} +outside");
|
||||
assert_ne!(format_exposure_time(1.0 / n * (1.0 - outside)).as_deref(), Some(want.as_str()), "{n} -outside");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exposure_display() {
|
||||
let mut m = Metadata { exposure_time: Some(1.0 / 250.0), ..Default::default() };
|
||||
assert_eq!(m.exposure_display().as_deref(), Some("1/250"));
|
||||
m.exposure_time = Some(0.5);
|
||||
assert_eq!(m.exposure_display().as_deref(), Some("0.5"));
|
||||
assert_eq!(m.exposure_display().as_deref(), Some("1/2"));
|
||||
m.exposure_time = Some(0.3);
|
||||
assert_eq!(m.exposure_display().as_deref(), Some("0.3"));
|
||||
m.exposure_time = Some(2.0);
|
||||
assert_eq!(m.exposure_display().as_deref(), Some("2″"));
|
||||
m.exposure_time = Some(0.0);
|
||||
|
||||
+26
-1
@@ -250,7 +250,10 @@ fn value_text(group: &str, tag: u16, v: &Value) -> String {
|
||||
// exposure time as a fraction of a second
|
||||
let (n, d) = a[0];
|
||||
let s = n as f64 / d as f64;
|
||||
if s >= 1.0 || n == 0 { format!("{} s", rational(n as f64, d as f64)) } else { format!("1/{} s", (1.0 / s).round()) }
|
||||
match crate::format_exposure_time(s) {
|
||||
Some(text) => format!("{text} s"),
|
||||
None => format!("{} s", rational(n as f64, d as f64)),
|
||||
}
|
||||
}
|
||||
Value::Rational(a) if tag == 0x829d && group != "GPS" && a.len() == 1 => format!("f/{}", rational(a[0].0 as f64, a[0].1 as f64)),
|
||||
Value::Rational(a) if tag == 0x920a && group != "GPS" && a.len() == 1 => format!("{} mm", rational(a[0].0 as f64, a[0].1 as f64)),
|
||||
@@ -380,6 +383,28 @@ pub fn file_tag_rows(bytes: &[u8]) -> Vec<TagRow> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
#[test]
|
||||
fn exposure_rows_do_not_round_third_stop_times() {
|
||||
for (n, d, expected) in [
|
||||
(3, 10, "0.3 s"),
|
||||
(4, 10, "0.4 s"),
|
||||
(6, 10, "0.6 s"),
|
||||
(8, 10, "0.8 s"),
|
||||
(13, 10, "1.3 s"),
|
||||
(16, 10, "1.6 s"),
|
||||
(25, 10, "2.5 s"),
|
||||
(32, 10, "3.2 s"),
|
||||
(5, 8, "0.625 s"),
|
||||
(1, 3, "1/3 s"),
|
||||
(10, 28, "0.3571 s"),
|
||||
(1, 250, "1/250 s"),
|
||||
(1, 8000, "1/8000 s"),
|
||||
(30, 1, "30 s"),
|
||||
] {
|
||||
assert_eq!(value_text("EXIF", 0x829a, &Value::Rational(vec![(n, d)])), expected);
|
||||
}
|
||||
}
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -170,7 +170,7 @@ differences and missing bindings are in [ui-parity.md](ui-parity.md#shortcuts).
|
||||
| LR-META-LOCATION | Location editing | P2 | 🟡 | `cmd:photo.setMeta` (`location`, `city`, `state`, `country`, `gps`), `cmd:metadata.reverseGeocode` | place fields and GPS (decimal or degrees / minutes / seconds) edited in Info, read/written as IPTC Core / Photoshop / EXIF XMP; typed GPS consumes the full expression, accepts case-insensitive axis-appropriate hemisphere markers, and refuses malformed text or DMS minutes/seconds outside [0,60) before changing metadata; Show on Map opens OpenStreetMap; Fill Location fills empty City / State / Country from GPS offline (GeoNames, downloaded on request: `cmd:metadata.downloadPlaceNames`); no embedded map |
|
||||
| LR-META-COPYPASTE | Copy / paste metadata | P2 | ✅ | `cmd:photo.copyMetadata`, `cmd:photo.pasteMetadata` | title, caption, alt text, extended description, copyright (notice, status, usage terms, info URL), creator, place fields, keywords; `fields` picks a subset |
|
||||
| LR-META-XMP | XMP read/write | P0 | ✅ | `cmd:photo.saveMetadataToFile`, `cmd:photo.readMetadataFromFile`, `cmd:library.xmpPreferences`, `crates/engine/src/sidecar.rs`, `docs/xmp-interop.md` | manual rereading also reads sidecar-free JPEG embedded XMP (first complete standard APP1 before SOS/EOI, within 16 MiB of headers and 4096 marker/fill steps; no extended assembly or between-scan packets, not strict whole-JPEG validation; reader cases in `crates/engine/src/sidecar.rs`); a discovered unreadable sidecar fails without embedded fallback; procedural refresh/undo, non-UTF-8 sidecar and two explicit malformed fixtures in `crates/engine/src/tests/xmp.rs` (file-write checks use auto-write off); sidecar wins for metadata; a sidecar capture time (`exif:DateTimeOriginal` / `photoshop:DateCreated` / `xmp:CreateDate`) fills in only when the file has none; keywords are saved as names in `dc:subject` and paths in `lr:hierarchicalSubject` (`keywords::to_file`; before, paths went into `dc:subject`); saving merges into an existing sidecar (the `lightcraft_meta::merge_xmp` adapter in `crates/meta/src/lib.rs` delegates to shared `craft_metadata::merge_xmp`): another app's `crs:`, `xmpMM:History` and unknown namespaces are kept byte for byte (ownership follows namespace URI: foreign namespaces using `lc:` or `xmp:` cannot supply native settings or ratings and survive saving), an unreadable sidecar is backed up first; with stem naming, files sharing a stem (raw + JPEG) get separate sidecars (`<file>.xmp` for all but the raw; an import ranks the files it is adding the same way, so a TIFF or JPEG arriving beside its raw reads its own `<file>.xmp` and never the raw's `IMG_0001.xmp`, issue #1905); a `crs:` custom white balance on a relative-WB raw is shifted from `crs:AsShotTemperature` rather than read as Kelvin, or kept As Shot and reported when the packet has no as-shot white (issue #510); heal and clone spots (`crs:RetouchAreas`, legacy `crs:RetouchInfo`) are read into our spots (`crates/engine/src/crs_masks.rs`, see `docs/xmp-interop.md` → Spot removal); radial masks (`Mask/CircularGradient`) keep Lightroom's inside / outside: `crs:Flipped="true"` is the effect-inside flag of current masks and of the legacy Radial Filter, `crs:MaskInverted` the inversion, checked against Lightroom Classic's renders (issue #1815); Read Metadata from File never writes the sidecar back, even with auto-write on, so another app's later `crs:` edits are still read (issue #934); settings Lightroom writes only for itself (`CompatibleVersion`, the profile digests, the lens profile's name / file / setup, `CropConstrainToUnitSquare`, the lens profile's strength at 100 %) are not reported as unimported (`crates/engine/src/crs.rs`); malformed XMP capture-time values remain in the raw property map and are not projected, allowing the next valid field to supply the capture time |
|
||||
| LR-META-EXIF-FULL | Full EXIF/IPTC [Classic] | P1 | ✅ | `cmd:photo.allMetadata`, `cmd:dialog.allMetadata`, `crates/meta/src/tags.rs`, `crates/meta/src/exif.rs`, `crates/meta/src/iptc.rs`, `crates/meta/src/heif.rs` | `photo.allMetadata` reuses loaded original bytes for embedded XMP and keeps sidecar precedence (`crates/engine/src/tests/xmp.rs`); read and written on export; Info ▸ All Metadata…: every TIFF / EXIF / GPS / interop tag (named, common values spelled out) and the XMP fields, searchable; PSD/PSB EXIF resource 1058 and XMP resource 1060 feed the same metadata rows and preserve sidecar precedence; metadata presets; malformed EXIF clocks with extra components are rejected so valid DateTimeDigitized, IFD0 DateTime or XMP fallbacks apply, while raw values stay visible in All Metadata (`crates/meta/src/exif.rs`, `crates/engine/src/tests/import.rs`); HEIC, HEIF and AVIF: the primary image's `Exif` and XMP items (or those of its grid or `iden` inputs) are read from the container alone, in builds with or without the HEIC decoder (issue #693); camera civil time and UTC offset are retained, including evening shots, and EXIF orientation does not rotate HEIC pixels again (`crates/engine/src/tests/import.rs`, issue #2284) |
|
||||
| LR-META-EXIF-FULL | Full EXIF/IPTC [Classic] | P1 | ✅ | `cmd:photo.allMetadata`, `cmd:dialog.allMetadata`, `crates/meta/src/tags.rs`, `crates/meta/src/exif.rs`, `crates/meta/src/iptc.rs`, `crates/meta/src/heif.rs` | `photo.allMetadata` reuses loaded original bytes for embedded XMP and keeps sidecar precedence (`crates/engine/src/tests/xmp.rs`); read and written on export; Info ▸ All Metadata…: every TIFF / EXIF / GPS / interop tag (named, common values spelled out) and the XMP fields, searchable; PSD/PSB EXIF resource 1058 and XMP resource 1060 feed the same metadata rows and preserve sidecar precedence; metadata presets; malformed EXIF clocks with extra components are rejected so valid DateTimeDigitized, IFD0 DateTime or XMP fallbacks apply, while raw values stay visible in All Metadata (`crates/meta/src/exif.rs`, `crates/engine/src/tests/import.rs`); HEIC, HEIF and AVIF: the primary image's `Exif` and XMP items (or those of its grid or `iden` inputs) are read from the container alone, in builds with or without the HEIC decoder (issue #693); camera civil time and UTC offset are retained, including evening shots, and EXIF orientation does not rotate HEIC pixels again (`crates/engine/src/tests/import.rs`, issue #2284); shutter display uses 1/n or four significant digits; exact exposure duration is preserved in the catalog and exports (#1619) |
|
||||
|
||||
## F. Edit panel — global adjustments (EDIT)
|
||||
|
||||
@@ -400,7 +400,7 @@ differences and missing bindings are in [ui-parity.md](ui-parity.md#shortcuts).
|
||||
| LR-EXP-COLORSPACE | Output colour space | P0 | ✅ | `cmd:app.export` (`colorSpace`), `crates/pipeline/src/output.rs`, `crates/engine/src/export.rs` | sRGB, Display P3, Adobe RGB (1998) compatible, ProPhoto RGB, Rec. 2020: rendered from the working space with gamut mapping into the target gamut (CPU + GPU), own ICC profile embedded; AVIF stays sRGB (muxer has no ICC); lossy JPEG XL declares sRGB / P3 / Rec. 2020 (Adobe RGB and ProPhoto written as Rec. 2020), lossless JPEG XL embeds the profile |
|
||||
| LR-EXP-HDR | HDR output | P2 | 🟡 | `cmd:app.export`, `crates/ui-egui/src/dialogs.rs` | HDR output checkbox in the export dialog: gain map JPEG, PQ or HLG AVIF, PQ PNG, PQ JPEG XL, float TIFF; no HDR presets yet |
|
||||
| LR-EXP-SHARPEN | Output sharpening | P1 | ✅ | `cmd:app.export` (`sharpen`, `sharpenAmount`) | |
|
||||
| LR-EXP-METADATA | Metadata policy | P1 | ✅ | `cmd:app.export` (`metadata`, `removeLocation`) | Original export is refused when Remove Location Info is on and the source embeds GPS or a nonblank sublocation, city, state or country; for HEIF, HEIC and AVIF, `lightcraft_meta::embeds_location` also checks every EXIF and XMP item, including auxiliary images, and an unreadable item counts as a location; rendered exports and XMP sidecars remove those modeled fields |
|
||||
| LR-EXP-METADATA | Metadata policy | P1 | ✅ | `cmd:app.export` (`metadata`, `removeLocation`) | Original export is refused when Remove Location Info is on and the source embeds GPS or a nonblank sublocation, city, state or country; for HEIF, HEIC and AVIF, `lightcraft_meta::embeds_location` also checks every EXIF and XMP item, including auxiliary images, and an unreadable item counts as a location; rendered exports and XMP sidecars remove those modeled fields; Export writes the exact exposure time kept in the catalog beside the rounded shutter text (#1619); a photo imported earlier, whose shutter text is still the rounded one import wrote then, gets the exact time and current text from Reload from Disk; a shutter speed set by hand is kept. Smart-album Shutter Speed rules compare the shown value. |
|
||||
| LR-EXP-WATERMARK | Watermark | P1 | 🟡 | `cmd:app.export` (`watermark`: text, or `{text, vertical, size, opacity, anchor, insetX, insetY, inset, rotation, color, shadow, image, imageWidth}`), `crates/engine/src/export.rs` (`Watermark`, `WATERMARK_PARAMS`) | text uses Inter SemiBold, the existing Mincho-first CJK chain, then Thai faces from `CRAFT_FONTS_DIR`, shared with contact-sheet captions and slideshow overlays (#2052, partial). Decomposed (NFD) text, as macOS often writes file names, is composed to NFC first, so Hangul syllables and Vietnamese letters draw whole instead of as loose jamo and marks; CJK compatibility ideographs keep their code points (issue #3480, #3277; `decomposed_hangul_draws_whole_syllables`, `decomposed_vietnamese_draws_its_composed_letters`, `compatibility_ideographs_keep_their_code_points`). Horizontal Thai mark positioning remains incomplete. Arabic export fallback is deferred until joining and bidi reordering exist; UI font fallback is unchanged. Text (`size` = height as a fraction of the short edge, 0.005..0.5, default 0.035; `color` sRGB `[r,g,b]`; `shadow`; Japanese vertical glyph forms and origins, tested by `biz_ud_vertical_watermarks_place_punctuation_at_the_top_right`; extended grapheme cells keep decomposed dakuten/handakuten and Latin accents together, tested by `vertical_watermarks_keep_combining_marks_in_one_cell` and `upright_watermark_cell_retains_multiple_glyphs` (see `docs/vertical-watermarks.md`)) or a graphic with transparency (EXIF orientation applied before sizing; oversized graphics fit the rotated image bounds without stretching, tested by `graphic_watermark_honours_exif_orientation` and `graphic_watermark_keeps_aspect_when_fitted_and_rotated`; `image` path, `imageWidth` = fraction of the photo's width, 0.01..1, converted to the output colour space); `anchor` (nine positions), `insetX` / `insetY` (margins from the side and from the top/bottom edges, each a fraction of the short edge, 0..0.4; the Export dialog's Horizontal and Vertical inset sliders, as in Lightroom Classic; the older single `inset` still reads as both; tested by `watermark_insets_are_horizontal_and_vertical`), `rotation` (0, 90, 180 or 270 degrees clockwise, the Export dialog's Rotate row, as Lightroom Classic's rotate buttons; sized before it is turned, placed and inset by the turned box; tested by `watermark_rotation_turns_the_text_in_its_corner` and `graphic_watermark_is_placed_scaled_and_blended`), `opacity` 0..1. Unknown keys and out-of-range values are errors (issue #183). The Export dialog previews it on the first exported photo's thumbnail (`draw_watermark_preview` scales the 6 px minimum text size to the preview so it matches the file), tested by `watermark_preview_scales_the_minimum_text_size` and `export_dialog_previews_the_watermark` |
|
||||
| LR-EXP-NAMING | File naming | P1 | ✅ | `cmd:app.export` (`naming`, `startNumber`), `crates/engine/src/rename.rs` (`expand_tokens`) | one template language for export, Rename Photos and import renaming: `{name}`, `{num}` (number at the end of the name), `{seq}` / `{seq:N}`, `{date}` / `{date:%Y-%m-%d}`, `{folder}`, `{camera}`, `{lens}`, `{iso}`, `{rating}`, `{title}`, `{creator}`, `{ext}`; free-form template rather than a list of named schemes |
|
||||
| LR-EXP-LOCATION | Destination folder | P0 | ✅ | `cmd:app.export` (`dir`, `destinationMode`: specificFolder / sameAsOriginal, `subfolder`, `conflict`: unique / overwrite / skip), `cmd:export.checkTarget`, `crates/ui-egui/src/dialogs.rs` (Choose… folder picker), `crates/engine/src/originals.rs`, `crates/catalog/src/safe_file.rs` | folder picker on the desktop; Export to: Specific folder or Same folder as original photo (each photo into its original's folder + the subfolder; a demo/browser photo or a missing folder is that photo's error, issue #956); existing files get `-2`, `-3`… by default; the policy covers a file and its sidecars together; a catalogued original (or its sidecar) is never written over, whatever the policy or an exact `path` (export, `ui.render`, MCP `render_photo`, merge `previewPath`, `lightcraft-cli render`); files are written to a temp file and renamed into place (issue #93; not synced file by file — exports can be made again, issue #134) |
|
||||
@@ -826,6 +826,7 @@ Latin stays upright. Advanced Japanese composition remains open. Regression cove
|
||||
| 2026-10-24 | minor | LR-EDIT-DETAIL-DENOISE: the built-in denoiser measures noise by colour channel and ignores texture, and its strength follows the measured noise; status and counts unchanged |
|
||||
| 2026-10-24 | minor | LR-EDIT-DETAIL-DENOISE: the built-in denoiser filters with block-matching collaborative filtering instead of non-local means, and runs that filter on the graphics card where there is one; status and counts unchanged |
|
||||
| 2026-10-23 | minor | LR-EDIT-DETAIL-DENOISE: built-in denoiser, no model needed |
|
||||
| 2026-10-25 | patch | LR-META-EXIF-FULL, LR-EXP-METADATA: shutter speeds shown as 1/n or four significant digits; the exact duration is kept in the catalog (optional `exposure_time`, older catalogs read unchanged) and written on export (#1619). Statuses and feature counts unchanged. |
|
||||
| 2026-10-25 | patch | LR-BEHAV-TITLEBAR: the top bar's title-bar gestures come from craft-window's `title_bar`: a double-click follows the system setting, and a press on a button, the search field or a panel floating over the bar never moves the window; status counts unchanged |
|
||||
| 2026-10-24 | minor | KEYC-METADATA, LRC-LIB-KEYWORDS: ⌘⌥K / Ctrl+Alt+K (`tool.enablePainting`, Photo ▸ Enable Painting) paints the painter box's keyword or stops painting; status counts unchanged (KEYC-METADATA stays 🟡) |
|
||||
| 2026-10-24 | minor | KEYC-METADATA: ⌘⇧K / Ctrl+Shift+K (`panel.editKeywords`, Edit Keywords) shows the Keywords panel with its Keyword List open and opens the picked keyword in Edit Keyword Tag; status counts unchanged (KEYC-METADATA stays 🟡) |
|
||||
|
||||
@@ -273,6 +273,12 @@ mod tests {
|
||||
assert!(!p.rust(), "only files something compiles in");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn app_icon_changes_retest_both_hosts_and_the_update_prompt() {
|
||||
let users: Vec<_> = embedders("assets/app-icon/hicolor/128x128/apps/ai.storyteller.lightcraft.png").collect();
|
||||
assert_eq!(users, ["lightcraft", "lightcraft-ui-egui"]);
|
||||
}
|
||||
|
||||
/// Every `include_str!` / `include_bytes!` of a file outside its package, and every `"../…"`
|
||||
/// path in a build script, is listed in `EMBEDDED` for that package.
|
||||
#[test]
|
||||
|
||||
Reference in new issue
Block a user