Skip to content

Issue #1852: Smart albums test size before the crop, bit depth and source colour - #1853

Merged
emmertex merged 1 commit into
emmertex:stagingfrom
clydecbrown:classic/smart-album-size-colour-criteria
Dec 2, 2026
Merged

emmertex merged 1 commit into
emmertex:stagingfrom
clydecbrown:classic/smart-album-size-colour-criteria

Conversation

@clydecbrown

Copy link
Copy Markdown
Collaborator

Fixes #1852

Problem

Lightroom's smart collections can test the size of the frame before and after the crop, and the file's bits per channel, colour mode and colour profile. Chromaforge's smart albums had one set of size fields, where Width and Height read the uncropped frame but Long Edge, Short Edge and Megapixels read the cropped one, and nothing kept what a file says about its colour, so those Lightroom collections imported as static ones.

Change

  • Width and Height now match the cropped frame like the other size fields; five new fields (Long Edge, Short Edge, Width, Height, Megapixels, uncropped) match the frame before the crop. The What's New entry says Width and Height changed.
  • New fields Bits Per Channel, Source Color Mode (RGB, Grayscale, CMYK, Lab, Raw, Other) and Source Color Profile. The value is read from the file (JPEG, PNG, WebP, GIF, BMP, PSD, TIFF, EXR, HEIF/AVIF, JPEG XL; raws by their header) at import, and for photos imported earlier by a background pass: a "Reading source colours" row in the activity stack (cancellable, paced like focus points), once per library opening and by photo.readSourceColour (Metadata menu). It keeps its state in the photo's own metadata (meta.source_colour, catalog format 25): none means unread, a value with empty parts means read and nothing found, an unreadable file stays unread and is tried again. No side file is written.
  • The Lightroom importer maps the ten size criteria, bitDepth, colorMode (2 and 32803) and colorProfile; any other colour-mode number stays a static collection.

Not in this PR: Lightroom's own bit depths for raws (15 for DNG, 16 for CR3) are not reproduced; a rule written for them imports as written and matches what this app reads. A raw is read whole once by the background pass. The catalog format moves to 25, so an older build refuses a library this one has upgraded.

Acceptance criteria

  • AC-1: Width and Height match the cropped frame (Photo::shown_size), like Long Edge, Short Edge and Megapixels. A saved rule on width / height now reads the cropped frame (decided: matches Lightroom; the What's New entry says so). — verified by width_and_height_follow_the_crop_and_the_uncropped_fields_do_not (lcc-catalog); seen failing with the matcher on the source size
  • AC-2: New fields Uncropped Long Edge, Short Edge, Width, Height and Megapixels match the source frame (turned by orientation, not cut by the crop). Aspect Ratio stays on the cropped frame, as Lightroom's does. — same test; Aspect Ratio untouched
  • AC-3: The importer maps Lightroom's longEdgeCropped, shortEdgeCropped, widthCropped, heightCropped, megapixelsCropped to the cropped fields and longEdge, shortEdge, width, height, megapixels to the uncropped ones; none of them falls back to a static collection any more. — verified by the importer tests and the SC-SIZE-* rows of lightroom_smart_rows.tsv (blessed, reviewed row by row); seen failing with the mapping removed (colour-mode case: criteria_map_to_their_fields_or_stay_static and the rows test)
  • AC-4: The catalog keeps, per photo, what the source file says about its bit depth per channel, colour model and embedded ICC profile name, as one optional field (#[serde(default)]): none means not read yet, and a value with empty parts means read and nothing found (no profile, an unreadable header). A background pass modelled on focus_scan.rs (header reads only, one worker, an activity-stack row that can be cancelled, paced by the UI) fills the photos still unread: it starts by itself once per library opening and on demand by command, and runs on import for new photos. A file that can't be read (offline drive, file gone) stays unread and is tried again at the next opening. No sidecar record file is written to the library folder; a version inside the field lets a reader that learns more formats look again at photos recorded as nothing found. Older catalogs open (the plan confirms what an older build does with the field); never an error. — verified by tests_source_colour_scan (fill, nothing-found, unreadable stays unread and is read once back, video, older reader version read again, once-per-opening start, no undo step, older-format metadata reads as unread); seen failing with the older-version re-read turned off
  • AC-5: Bits Per Channel matches the source file's bit depth per channel (JPEG 8; PNG, TIFF, PSD and EXR as stored; a raw file's sensor depth). Lightroom's own numbers for raws (15 for the test DNGs, 16 for the CR3s) are not reproduced; a rule bitDepth == 16 imports as written and matches what this app reads. — verified by source_colour/tests.rs (engine; real JPEG, PNG, TIFF, PSD, WebP, EXR, JXL, AVIF and DNG output) and rules.rs tests; seen failing with the JPEG depth off by one
  • AC-6: Source Color Mode matches the source file's colour model. Lightroom stores the TIFF photometric number (seen in the test catalogs: 2 = RGB for JPEG and TIFF, 32803 = colour filter array for DNG and CR3, -1 for video), so the choices are RGB, Grayscale, CMYK, Lab, Raw (colour filter array) and Other; the importer maps only the numbers seen (2 and 32803) and leaves any other value as a static collection until it is checked against a catalog. — verified by the same reader tests, rules.rs tests and the importer rows (only 2 and 32803 map, 5 stays static)
  • AC-7: Source Color Profile matches the embedded ICC profile's name as a text rule; a file read with no profile matches Untagged, as Lightroom shows it (sRGB IEC61966-2.1 for the test JPEG). The importer maps colorProfile (the text operations it already maps, as any in the test catalogs), colorMode and bitDepth; a criterion with a value this app can't express still imports as a static collection. — verified by source_colour_fields_follow_what_the_file_said (Untagged for an empty profile) and the SC-COLORPROFILE row
  • AC-8: Hostile input (truncated or malformed headers, oversized ICC tags) never panics: table-driven no-panic test. — verified by unknown_data_is_none_and_no_prefix_of_any_file_panics and counts_and_sizes_larger_than_the_file_are_not_followed (every prefix and damaged byte of JPEG, PNG, TIFF, PSD, HEIF and EXR; oversized TIFF counts and offsets, EXR sizes and 5000 channels); seen failing with the channel cap turned into a refusal
  • AC-9: Each field and each importer mapping has a test, seen failing first; the manual page (library/collections), the Lightroom import page (docs/lightroom-catalog-import.md:222 no longer lists "uncropped and cropped width and height") and a What's New entry are updated. — each field and mapping has its test; manual page, import page, What's New, changelog and command docs updated; the rule editor was run headless and screenshotted with the new fields

How it was checked

  • cargo xtask ci --quick and cargo test -p for the touched crates pass on this branch, up to date with staging (merged in, not rebased)
    • The gate passed (ci --quick plus parity, layers, assets, deny, wasm and android; two known local failures, device_sync and a_cancelled_export); the branch is 18 commits behind staging and merges cleanly (it touches the same locale files, without conflict).
  • A test that fails without this change: each new test was seen failing with its behaviour turned off (the width/height matcher, the colour-mode mapping, the older-reader re-read, the JPEG depth, the EXR channel cap), and the fix's tests are new API, so they can't run on staging.
  • User-visible change: ran the rule editor headless with the new fields and looked at the screenshot (the fields, operators and choices show and test as expected).

Merging

  • Overlap: none found.
  • Existing edits and libraries: a saved rule on Width or Height now reads the cropped frame (said in What's New); photos imported earlier have no colour value until the background pass reads it, and match no colour rule meanwhile.
  • Shared numbers taken: catalog format VERSION 25. If another pull request lands with it first, take one past staging's when merging.
  • Where it came from: own design; the Lightroom values (colorMode photometric numbers, "Untagged") were observed in a test catalog.
  • New dependencies, unsafe, build scripts, network access, spawned processes, deleted files, CI or xtask gate changes: none (see Runs on CI).

Runs on CI

Nothing beyond the touched crates' own tests; no workflow, build-script, packaging or dependency changes. The new tests write only to temp folders.

Checklist

  • No new panic path in non-test code: the readers use get, checked_add and capped loops, and the new work is under catch_unwind; hostile-input tests cover JPEG, PNG, TIFF, PSD, HEIF and EXR
  • New text on screen goes through tr() and has its key in crates/ui-egui/locales/*.json (all 17 languages)
  • The feature's rows in docs/parity-checklist.md are updated
  • User-visible change: the manual is updated in the same commit (docs/manual-site/; pages: library/collections)
  • New code has a caller: the command, the pump, the import path and the rule fields
  • Every new image, icon or other asset has its entry in assets/ATTRIBUTION.md: none added
  • Ready to merge

Manual: library/collections.

Sources: own design.

🤖 Generated with Claude Code

…el and source colour

Width and Height now follow the crop like the other size fields, and five
uncropped size fields give the frame before it. Bits Per Channel, Source Color
Mode and Source Color Profile come from the file, read at import and, for photos
imported earlier, by a background pass with an activity row and a command
(photo.readSourceColour). The value lives in the photo's metadata (catalog
format 25); a file that can't be read stays unread and is tried again.
Lightroom smart collections that use these import as smart albums.

Manual: library/collections.

Sources: own design.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@emmertex
emmertex merged commit be3971a into emmertex:staging Dec 2, 2026
3 checks passed
@clydecbrown
clydecbrown deleted the classic/smart-album-size-colour-criteria branch December 2, 2026 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Smart collection criteria: uncropped size, bit depth and colour source

2 participants