Skip to content

Export: each format's bit depth, alpha and HDR behaviour come from one table, and the colour profile and metadata are put together in one place - #1843

Merged
emmertex merged 2 commits into
emmertex:stagingfrom
blwfish:fix/fx-236-237-export-depth-and-profile
Dec 2, 2026
Merged

emmertex merged 2 commits into
emmertex:stagingfrom
blwfish:fix/fx-236-237-export-depth-and-profile

Conversation

@blwfish

@blwfish blwfish commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

Part of #1838 (entries 17 and 18).

In short: export decided a format's bit depth, alpha and HDR in half a dozen separate places, and they disagreed in one case that shows: for Render to DNG with HDR on, the file keeps highlights above white, but the Export preview said the format was SDR and the dialog summary left out "HDR". Now ExportFormat::caps() is the one table and each place reads it. The colour profile, Exif block and XMP packet were also put together at seven separate sites (four in export, three in Edit In); one function does it now, with no change to what is embedded.

Change

  • One table: ExportFormat::caps() returns the depths a format offers, the depth used for a request (the documented "closest depth" fallback), whether it keeps alpha, and its HDR kind. effective_depth, bit_depths, hdr_output, gain_map, keeps_alpha, the HDR part of effective_space and two inline matches! read it. The sites that drop a bit depth the format can't take already shared one function and are unchanged.
  • The one visible difference: hdr_output() is true for Render to DNG with HDR on (it was false while effective_depth said 32-bit float). The file written is unchanged; the Export preview and the dialog summary now treat it as HDR. Over about 1,000 answers (11 formats, 8 depth requests, 3 HDR settings, 4 outputs) compared old and new, that is the only one that changed.
  • One builder: export::Embedded puts together the profile and EncodeMeta for all seven sites. Nothing else changes: 900 encodes across 9 formats, 5 colour spaces, with and without metadata, 5 depth/HDR settings and gain map on and off were byte-identical before and after.
  • The dialog still has its own lists in a few places (the HDR checkbox's formats, the preview line's wording, which omits EXR); they are left alone. What's new and changelog entries.

How it was checked

every_format_answers_depth_hdr_alpha_and_space_from_one_table goes over every format, depth request and HDR setting, the depths offered, alpha, and "float HDR depth iff HDR output (minus gain map)", and that Edit In's depths equal export's; it fails on the old code at the Render to DNG row. A new test pins the embedded profile, Exif and XMP; it passes before and after on purpose, and catches two deliberate mutations. The export-preview UI tests still pass.

Question: see the umbrella (entry 17): Render to DNG with HDR on, HDR or SDR-only?

  • cargo xtask ci --quick --base origin/staging on this branch (macOS, staging d4c89211f merged): fmt, brand, quarantine, docs, notes, i18n, windows, clippy and stamp pass. Tests of lcc-engine: all pass except device_sync::tests::a_shared_collection_brings_photos_files_and_edits_both_ways (environmental on that machine) and run_presets::tests::a_run_makes_previous_export_and_runs_the_plugin_hooks_and_destination ("plug-in busy" on a loaded run; passes alone, and fails on the first run after a fresh build of plain staging too). Parity, layers, assets, wasm and deny: pass.

  • The five branches of this batch (this one and its neighbours) were also merged together on current staging and gated as one: fmt, brand, quarantine, docs, notes, i18n, windows, clippy, heif, stamp, parity, layers, assets, wasm and deny pass; the tests fail only where plain staging fails too (device_sync, translated_catalogs_do_not_use_missing_menu_triangles, tests_phone_menus), plus one timing test in io_sched that passes alone.

🤖 Generated with Claude Code

blwfish and others added 2 commits December 2, 2026 08:21
… from one table

Seven functions and two inline matches each re-derived what a format does with bit
depth, alpha and HDR. They agreed except in one place: Render to DNG with `hdr` on was
written as a float HDR render (`effective_depth` = F32Hdr, which the format's own
introduction says is intended: highlights above white are kept) while `hdr_output()`
said it was not an HDR output, so the Export preview and the dialog's summary treated
the file as SDR (the preview offered no HDR rendition and said the format was SDR).
`effective_depth` also mapped requests `bit_depths` doesn't list (PNG 32, AVIF 16,
JPEG XL 10) by rules held in separate match arms, and two encoders retyped
`keeps_alpha` as `matches!(Png | Tiff [| Webp])`.

Change: `ExportFormat::caps()` is the one table (offered depths, the sample format a
request is written as, keeps alpha, how HDR is written, whether an HDR file is Rec.
2020). `effective_depth`, `bit_depths`, `hdr_output`, `gain_map`, `keeps_alpha`, the
HDR arm of `effective_space` and the two inline matches read it. `effective_depth` is
now "gain map: 8-bit; HDR output: float HDR; else the format's rule for the request",
so it cannot disagree with `hdr_output` again. Render to DNG is marked as an HDR float
format, so `hdr_output()` is true for it; the file written does not change. For the
other ten formats every answer is identical to before (220 combinations compared
against the old functions). The stored-`bitDepth` drop (`drop_unfit_depth`) already
had one rule, `bit_depths`; its four call sites differ only in when the format is
known, and are unchanged.

Test: `every_format_answers_depth_hdr_alpha_and_space_from_one_table` pins every format
x request (None, 0, 8, 10, 12, 16, 32, 255) x HDR off / single layer / gain map for
depth written, HDR output, gain map and output space, plus offered depths, alpha, the
rule "float HDR depth <=> HDR output without a gain map", and that Edit In offers the
depths Export does. It fails with the old functions on the Render to DNG row.

Manual: output/export-formats

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…r in one place

The embedded-metadata block (colour profile + Exif block + XMP packet -> `EncodeMeta`)
was built four times in export (8-bit, gain map JPEG, AVIF/JPEG XL gain map, deep
samples) and three more times in Edit In (float TIFF, 8/16-bit TIFF, PNG), each with
its own copy of "which profile": the named profile of the output space in three, the
render's linear matrix profile or the named one of `img.space` in the deep encoder, and
the render's own profile or the named one in Edit In. Any rule on what goes into a file
(a strip, a size rule) had to be repeated seven times, and the two JPEG file-size
budgets each re-added the profile, Exif and XMP lengths by hand.

Change: `export::Embedded` (`new` for parts already built, `of_metadata` for a
`Metadata`, `encode_meta()` for the codecs, `len()` for a file-size limit) is the one
place; the seven sites call it. No input gets a different profile: the same choice is
made at each site, now passed as (space, the render's own profile if any). Before the
refactor the output of all 900 combinations of nine formats, five spaces, with and
without metadata, five depths/HDR settings and gain map on/off was hashed; after it,
every hash is identical (a one-off check, not committed).

Tests: `every_encode_path_embeds_the_profile_of_the_space_it_wrote_and_the_metadata_it_was_given`
(pins, on the old code too, the profile, Exif and XMP of 8-bit JPEG/PNG/TIFF, 16-bit
PNG/TIFF, float TIFF and gain map JPEG in five spaces, with and without metadata, and
the JFIF density) and `embedded_parts_are_what_the_encoders_get_and_what_a_size_limit_counts`.
They pass before and after the change by design (they pin it); the first fails when
the float profile or the gain map's space is changed at the new call site.

Manual: none, no user-visible change

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@emmertex
emmertex merged commit 50cbd53 into emmertex:staging Dec 2, 2026
3 checks passed
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.

2 participants