Skip to content

Commit ee36dc7

Browse files
authored
Merge pull request #926 from emmertex/upstream-pr-review-2026-11-08c
Upstream intake round 2 port pass (2026-11-08): 13 adopted
2 parents add6663 + 48a4aeb commit ee36dc7

44 files changed

Lines changed: 1946 additions & 703 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Cargo.lock‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/actions/src/lib.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ pub fn is_navigation(id: &str) -> bool {
146146
| "library.selectNone"
147147
| "library.next"
148148
| "library.previous"
149+
| "library.nextUnrated"
150+
| "library.prevUnrated"
149151
| "library.first"
150152
| "library.last"
151153
| "library.source"

‎crates/catalog/src/model.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,20 @@ pub struct Meta {
198198
/// two bodies of one model apart for their own camera profiles ([`Meta::camera_model`] says the model).
199199
#[serde(skip_serializing_if = "String::is_empty")]
200200
pub camera_serial: String,
201+
/// The lens maker (Exif `LensMake`), written back on export. Left out of the catalog JSON when empty.
202+
#[serde(skip_serializing_if = "String::is_empty")]
203+
pub lens_make: String,
201204
pub lens: String,
202205
pub focal_mm: Option<f32>,
203206
pub aperture: Option<f32>,
204207
pub shutter: String,
205208
pub iso: Option<u32>,
209+
/// Whether the flash fired (Exif `Flash`); `None` when the file does not say.
210+
#[serde(skip_serializing_if = "Option::is_none")]
211+
pub flash: Option<bool>,
212+
/// Exposure compensation in EV (Exif `ExposureBiasValue`).
213+
#[serde(skip_serializing_if = "Option::is_none")]
214+
pub exposure_bias: Option<f32>,
206215
/// The lens's focal range (mm, shortest and longest), from the file's LensSpecification: the loupe's shot info
207216
/// adds it to a lens name that doesn't say it (OneSlips PERF-CULL-7 a5f6da85e). Left out of the catalog JSON when
208217
/// unknown, so older catalogs read unchanged.

‎crates/catalog/src/rules.rs‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ pub const FIELDS: &[(&str, &str, Kind)] = &[
110110
("aperture", "Aperture", Kind::Number),
111111
("shutterSpeed", "Shutter Speed", Kind::Number),
112112
("iso", "ISO Speed", Kind::Number),
113+
("flash", "Flash", Kind::Bool),
114+
("exposureBias", "Exposure Bias", Kind::Number),
115+
("cameraSerial", "Camera Serial Number", Kind::Text),
113116
// Location
114117
("location", "Location", Kind::Text),
115118
("sublocation", "Sublocation", Kind::Text),
@@ -149,7 +152,7 @@ pub const FIELD_GROUPS: &[(&str, &[&str])] = &[
149152
("Date", &["captureDate", "importDate", "editDate"]),
150153
("Keywords & People", &["keywords", "keywordCount", "person", "personCount", "faceCount"]),
151154
("Description", &["title", "caption", "altText", "creator", "copyright", "usageTerms", "copyrightStatus"]),
152-
("Camera Info", &["camera", "lens", "focalLength", "aperture", "shutterSpeed", "iso"]),
155+
("Camera Info", &["camera", "lens", "focalLength", "aperture", "shutterSpeed", "iso", "flash", "exposureBias", "cameraSerial"]),
153156
("Location", &["location", "sublocation", "city", "state", "country", "countryCode", "hasGps"]),
154157
("Size", &["longEdge", "shortEdge", "width", "height", "aspect", "megapixels"]),
155158
("Develop", &["edited", "cropped", "treatment"]),
@@ -1103,6 +1106,9 @@ impl Rule {
11031106
"editDate" => date_op(op, p.edited.as_deref(), value),
11041107
"shutterSpeed" => num_op(op, crate::parse_shutter_seconds(&m.shutter), &shutter_value(value)),
11051108
"iso" => num_op(op, m.iso.map(|v| v as f64), value),
1109+
"flash" => yes(m.flash.unwrap_or(false)),
1110+
"exposureBias" => num_op32(op, m.exposure_bias, value),
1111+
"cameraSerial" => text(&m.camera_serial),
11061112
"aperture" => num_op32(op, m.aperture, value),
11071113
"focalLength" => num_op32(op, m.focal_mm, value),
11081114
"longEdge" | "shortEdge" => {
@@ -1387,6 +1393,21 @@ mod tests {
13871393
yes(json!({"rules": [{"field": "filePath", "op": "isEmpty"}]}));
13881394
yes(json!({"rules": [{"field": "camera", "op": "contains", "value": "x2"}, {"field": "title", "op": "isEmpty"}]}));
13891395
yes(json!({"rules": [{"field": "iso", "op": "between", "value": [800, 3200]}, {"field": "aperture", "op": "lte", "value": "f/4"}]}));
1396+
// flash, exposure bias and camera serial (ported from upstream #3821): unrecorded is "no flash", no bias, empty
1397+
no(json!({"rules": [{"field": "flash", "op": "is", "value": true}]}));
1398+
no(json!({"rules": [{"field": "exposureBias", "op": "lt", "value": 0}]}));
1399+
no(json!({"rules": [{"field": "cameraSerial", "op": "contains", "value": "x2"}]}));
1400+
let mut fl = photo(2);
1401+
fl.meta.flash = Some(true);
1402+
fl.meta.exposure_bias = Some(-0.67);
1403+
fl.meta.camera_serial = "SN-X2".into();
1404+
let flm = |v: serde_json::Value| rs(v).matches(&fl, &cat);
1405+
assert!(flm(json!({"rules": [{"field": "flash", "op": "is", "value": true}]})));
1406+
assert!(!flm(json!({"rules": [{"field": "flash", "op": "is", "value": false}]})));
1407+
assert!(flm(json!({"rules": [{"field": "exposureBias", "op": "lt", "value": 0}]})));
1408+
assert!(flm(json!({"rules": [{"field": "exposureBias", "op": "between", "value": [-1.0, -0.3]}]})));
1409+
assert!(flm(json!({"rules": [{"field": "cameraSerial", "op": "contains", "value": "x2"}]})));
1410+
assert_eq!(field_group("exposureBias"), Some("Camera Info"));
13901411
yes(json!({"rules": [{"field": "megapixels", "op": "gte", "value": 24}]}));
13911412
yes(
13921413
json!({"rules": [{"field": "captureDate", "op": "is", "value": "2026-08"}, {"field": "captureDate", "op": "before", "value": "2026-09-01"}]}),

‎crates/codecs/src/jxl.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ pub(crate) fn decode(bytes: &[u8], opts: &DecodeOptions) -> Result<Decoded> {
131131
meta.icc = icc;
132132
}
133133
if let Ok(AuxBoxData::Data(ex)) = img.aux_boxes().first_exif() {
134-
meta.exif = Some(ex.payload().to_vec());
134+
// The box declares where the TIFF header starts inside its payload; skip any prefix before it.
135+
meta.exif = usize::try_from(ex.tiff_header_offset()).ok().and_then(|offset| ex.payload().get(offset..)).map(<[u8]>::to_vec);
135136
}
136137
if let AuxBoxData::Data(x) = img.aux_boxes().first_xml() {
137138
meta.xmp = Some(String::from_utf8_lossy(x).trim_end_matches('\0').to_string());

‎crates/codecs/tests/it/jxl_streaming.rs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,29 @@ fn progressive_truncation_matches_builder() {
9494
}
9595
}
9696
}
97+
98+
#[test]
99+
fn exif_payload_starts_at_declared_tiff_header() {
100+
let pixels = Rgba8::from_fn(8, 8, |x, y| [(x * 20) as u8, (y * 20) as u8, 80, 255]);
101+
let encoded = encode_jxl(&EncodeImage::rgba8(&pixels), &JxlOptions { lossless: true, ..Default::default() }, &EncodeMeta::default()).unwrap();
102+
let raw = codestream(&encoded);
103+
let exif = minimal_exif(1);
104+
for offset in [0u32, 6, 64] {
105+
let mut exif_box = offset.to_be_bytes().to_vec();
106+
exif_box.resize(4 + offset as usize, 0xab);
107+
exif_box.extend_from_slice(&exif);
108+
let mut bytes = b"\0\0\0\x0cJXL \x0d\x0a\x87\x0a".to_vec();
109+
box_bytes(&mut bytes, b"ftyp", b"jxl \0\0\0\0jxl ");
110+
box_bytes(&mut bytes, b"jxlc", &raw);
111+
box_bytes(&mut bytes, b"Exif", &exif_box);
112+
let decoded = decode(&bytes, DecodeOptions::default()).unwrap();
113+
assert_eq!(decoded.exif.as_deref(), Some(exif.as_slice()), "offset {offset}");
114+
}
115+
// an offset past the payload must not panic and yields no Exif
116+
let mut bytes = b"\0\0\0\x0cJXL \x0d\x0a\x87\x0a".to_vec();
117+
box_bytes(&mut bytes, b"ftyp", b"jxl \0\0\0\0jxl ");
118+
box_bytes(&mut bytes, b"jxlc", &raw);
119+
box_bytes(&mut bytes, b"Exif", &[0xff, 0xff, 0xff, 0xff, 1, 2]);
120+
let decoded = decode(&bytes, DecodeOptions::default()).unwrap();
121+
assert!(decoded.exif.is_none());
122+
}

‎crates/codecs/tests/it/main.rs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ mod heif;
1111
#[cfg(all(feature = "jxl", not(target_arch = "wasm32")))]
1212
mod jxl_streaming;
1313
mod roundtrip;
14+
mod tiff_zip;

‎crates/codecs/tests/it/tiff_zip.rs‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
//! Noisy 8/16-bit ZIP TIFFs stay within their uncompressed size (issue #2882), using the Deflate backend the
2+
//! application dependency graph selects (no test-only backend is forced), so a dependency switching it shows up.
3+
4+
use lcc_codecs::*;
5+
6+
/// A deterministic value in -0.5..0.5 per position and channel.
7+
fn hash(x: u32, y: u32, c: u32) -> f64 {
8+
let mut z = (x as u64) << 32 ^ (y as u64) << 2 ^ c as u64 ^ 0x2882;
9+
z = (z ^ (z >> 33)).wrapping_mul(0xff51_afd7_ed55_8ccd);
10+
z = (z ^ (z >> 33)).wrapping_mul(0xc4ce_b9fe_1a85_ec53);
11+
(z ^ (z >> 33)) as f64 / u64::MAX as f64 - 0.5
12+
}
13+
14+
/// 16-bit RGB: smooth gradients plus noise of `noise` codes peak to peak (a clean to a high-ISO photo's low bits).
15+
fn noisy16(w: u32, h: u32, noise: f64) -> Vec<u16> {
16+
let mut v = Vec::with_capacity((w * h * 3) as usize);
17+
for y in 0..h {
18+
for x in 0..w {
19+
let (u, t) = (x as f64 / w as f64, y as f64 / h as f64);
20+
let base = [0.10 + 0.5 * u, 0.15 + 0.4 * t, 0.3 + 0.3 * u * t];
21+
for c in 0..3 {
22+
v.push((base[c as usize] * 65535.0 + noise * hash(x, y, c)).clamp(0.0, 65535.0) as u16);
23+
}
24+
}
25+
}
26+
v
27+
}
28+
29+
/// Both depths must actually use Deflate and decode at the original dimensions.
30+
fn checked_zip_size(img: &EncodeImage<'_>) -> usize {
31+
let bytes = encode_tiff(img, TiffCompression::Deflate, &EncodeMeta::default()).unwrap();
32+
let mut decoder = tiff::decoder::Decoder::new(std::io::Cursor::new(&bytes)).unwrap();
33+
let compression = decoder.get_tag_u32(tiff::tags::Tag::Compression).unwrap();
34+
assert!(matches!(compression, 8 | 32946), "Compression tag {compression} is not Deflate");
35+
let decoded = decode(&bytes, DecodeOptions::default()).unwrap();
36+
assert_eq!((decoded.image.width, decoded.image.height), (img.width as usize, img.height as usize));
37+
bytes.len()
38+
}
39+
40+
/// The shipped backend keeps noisy 16-bit ZIP exports smaller than uncompressed TIFFs.
41+
#[test]
42+
fn sixteen_bit_zip_tiff_is_never_larger_than_uncompressed() {
43+
let (w, h) = (512, 384);
44+
for noise in [0.0, 200.0, 1300.0, 4000.0, 13000.0] {
45+
let px = noisy16(w, h, noise);
46+
let img = EncodeImage::new(w, h, 3, Samples::U16(&px));
47+
let none = encode_tiff(&img, TiffCompression::None, &EncodeMeta::default()).unwrap().len();
48+
let zip = checked_zip_size(&img);
49+
eprintln!("noise {noise} codes: none {none} B, ZIP {zip} B ({:+.1} %)", 100.0 * (zip as f64 / none as f64 - 1.0));
50+
assert!(zip <= none, "noise {noise}: 16-bit ZIP {zip} B is larger than uncompressed {none} B");
51+
}
52+
}
53+
54+
/// The same size guarantee holds for 8-bit ZIP exports across several noise levels.
55+
#[test]
56+
fn eight_bit_zip_tiff_is_never_larger_than_uncompressed() {
57+
let (w, h) = (512, 384);
58+
for noise in [0.0, 4.0, 20.0, 60.0] {
59+
let px: Vec<u8> = noisy16(w, h, noise * 257.0).iter().map(|v| (v >> 8) as u8).collect();
60+
let img = EncodeImage::new(w, h, 3, Samples::U8(&px));
61+
let none = encode_tiff(&img, TiffCompression::None, &EncodeMeta::default()).unwrap().len();
62+
let zip = checked_zip_size(&img);
63+
eprintln!("8-bit noise {noise}: none {none} B, ZIP {zip} B ({:+.1} %)", 100.0 * (zip as f64 / none as f64 - 1.0));
64+
assert!(zip <= none, "8-bit noise {noise}: ZIP {zip} B is larger than uncompressed {none} B");
65+
}
66+
}
67+
68+
/// What ZIP costs at 24 MP, 16 bit (ignored by default):
69+
/// `cargo test --release -p lcc-codecs --test it tiff_zip::bench -- --ignored --nocapture`
70+
#[test]
71+
#[ignore]
72+
fn bench_24mp_16_bit_zip() {
73+
let (w, h) = (6000, 4000);
74+
for noise in [200.0, 1300.0, 4000.0] {
75+
let px = noisy16(w, h, noise);
76+
let img = EncodeImage::new(w, h, 3, Samples::U16(&px));
77+
for c in [TiffCompression::None, TiffCompression::Deflate, TiffCompression::Lzw] {
78+
let t = std::time::Instant::now();
79+
let n = encode_tiff(&img, c, &EncodeMeta::default()).unwrap().len();
80+
println!("noise {noise:>6} {c:?}: {:>7.1} MB in {:>6.0} ms", n as f64 / 1e6, t.elapsed().as_secs_f64() * 1e3);
81+
}
82+
}
83+
}

0 commit comments

Comments
 (0)