Skip to content

LR-IMP-FORMATS: uncompressed Leaf MOS is a raw, the Hasselblad Lunar decodes as an ARW - #1324

Merged
bflatastic merged 1 commit into
storytold:mainfrom
AlexChambers:raw-probe-leaf-lunar
Oct 13, 2026
Merged

bflatastic merged 1 commit into
storytold:mainfrom
AlexChambers:raw-probe-leaf-lunar

Conversation

@AlexChambers

Copy link
Copy Markdown
Contributor

Fixes #1275

What was wrong

lightcraft_raw::probe misrouted two kinds of CC0 raw.pixls.us files on main at 25ef65c.

  • Uncompressed Leaf MOS (Aptus 22, 3197). IFD0 is the 16-bit mosaic itself: compression 1, BlackIsZero, one sample per pixel, no Make tag, no CFA photometric. Only Leaf's private block, tag 0x8606 (LeafData), says it is a raw. probe returned None, so the file imported as a 4008 x 5344 greyscale image of its mosaic: dark, sideways, no colour.
  • Hasselblad Lunar ARW (4051). A Sony NEX-7 ARW under Make HASSELBLAD, Model Lunar. Only make.starts_with("SONY") reached the ARW reader, so the file fell through to OtherTiff and opened as its 1616 x 1080 preview.

The fix

  • probe (crates/raw/src/lib.rs): an IFD0 that carries 0x8606 and has one sample per pixel is a raw. It is OtherTiff, preview only with the existing reason, as the lossless-JPEG MOS (3196) already is. The same grey IFD without the block, or a rendered RGB image that kept it, stays an ordinary image.
  • probe: a HASSELBLAD file with Sony's raw coding goes to the ARW reader. The evidence is an IFD with compression 32767 (Sony ARW compressed) or the tone-curve tag 0x7010; no 3FR or FFF has either.
  • vendor/arw.rs: the only table there keyed by model, the Tag2010 white-balance fallback, now takes the body from the maker note's SonyModelID (0xb001, ExifTool Sony tag-name documentation) when the file isn't Sony-branded. It lists the IDs of the Sony bodies Hasselblad rebadged: 289 NEX-7 (Lunar), 294 SLT-A99 (HV), 297 DSC-RX100 (Stellar), 308 DSC-RX100M2 (Stellar II). Only the Lunar is measured; the other three IDs come from the documentation, with no public sample to check them. The Lunar itself doesn't need the fallback: like a NEX-7, it reads its white balance from the SR2SubIFD.
  • RENDER_CACHE_VERSION 61 to 62 (crates/engine/src/media.rs): a Lunar's cached thumbnails were rendered from its preview.
  • Docs: the Lunar is marked verified in docs/raw/evidence.tsv and coverage.tsv is regenerated (236 verified, 232 preview). Also docs/raw-parity.md (headline, maker table, ARW and MOS rows), the LR-IMP-FORMATS row of docs/parity-checklist.md, gap 10 in docs/gaps.md, and docs/whats-new.md. lightcraft-raw has no README.

The MOS mosaic itself is still not decoded; that needs the CFA phase and orientation from the Leaf data, a separate task.

Measurements

Release builds of main (25ef65c) and this branch. Renders are lightcraft-cli render FILE --size 1200, compared with the camera's embedded JPEG at 200 px wide with the comparison the sweep behind #1275 used (ΔE76, ΔL*, chroma ratio, luma correlation).

File main This branch
Leaf Aptus 22, uncompressed (3197) probe None OtherTiff
import (catalog.query) kind: image, 4008 x 5344, previewOnly: null kind: raw, 332 x 244, previewOnly: "OtherTiff files are not decoded yet"
render against the embedded preview ΔE76 78.3, ΔL* −74.6, chroma ×0.00: the grey mosaic, sideways ΔE76 0.56, ΔL* −0.01, chroma ×1.00: the preview
Leaf Aptus 22, lossless JPEG (3196) OtherTiff, preview unchanged
Hasselblad Lunar (4051) probe OtherTiff Arw
import preview only, 1616 x 1080 from sensor data, 6000 x 4000
render against the camera JPEG the preview itself (ΔE76 0.40) decoded, camera look accepted: ΔE76 3.17, ΔL* +0.03, chroma ×0.99, luma r 0.988

The Lunar against a real NEX-7 (raw.pixls.us data/Sony/NEX-7/RAW_SONY_NEX7.ARW, decoded by main):

Lunar, this branch NEX-7, main
Sensor data 6048 x 4024, ARW2, 14-bit, RGGB the same
Black level 512 512
White level 16383 16383
Crop 6000 x 4000 at (0, 0) the same
White balance SR2SubIFD WB_RGGBLevels 2544 1024 1024 1484: R 2.484, B 1.449 SR2SubIFD 2808 1024 1024 1416: R 2.742, B 1.383

On the white level: #1275 lists the SR2SubIFD's 15360 (0x787f, on both files). The ARW reader doesn't read that tag for any body, so a NEX-7 decodes with 16383 on main and the Lunar does the same. Reading it would change every ARW2 body, so it isn't part of this PR.

Control set: the decode facts (format, header probe, sensor size, CFA, black and white levels, crop, orientation, white balance, matrix source, sample statistics, preview size) of 158 files, main against this branch. They are the 111 RAW_SAMPLES corpus files (27 ARW, 21 RAF, 13 RW2 and 3 RAW / RWL, 10 CR3, 9 CR2, 9 DNG, 8 NEF / NRW, 5 ORF, 3 PEF, 3 SRW), the 46 files kept from the sweep (both MOS, 3 FFF and the Lunar among them) and the NEX-7. 156 are identical; the 2 that change are 3197 and 4051.

Tests

New, each a synthetic file:

  • crates/raw/src/lib.rs: uncompressed_leaf_mos_is_a_raw (a 16-bit BlackIsZero IFD0 with a 0x8606 entry is OtherTiff and refuses to decode; without the block, or as RGB, it is not a raw) and hasselblad_make_with_sony_raw_coding_is_arw (compression 32767 or 0x7010 under HASSELBLAD reaches the ARW reader and decodes; compression 1 or 7 without them doesn't).
  • crates/raw/src/vendor/arw.rs: rebadged_body_takes_its_tag2010_layout_from_the_sony_model_id (HASSELBLAD / Lunar with SonyModelID 289 reads the NEX-7 layout; no ID, an unlisted ID, or a Sony file with another model don't).
  • crates/engine/src/files.rs: uncompressed_leaf_mos_imports_as_a_preview_only_raw (imports as MediaKind::Raw, preview only, at the preview's size; the same file without the block imports as an image).

On main (the tests copied onto 25ef65c, with the two tag constants they name), all four fail at their first assertion: probe gives None for the MOS (expected OtherTiff) and OtherTiff for the Lunar-style files (expected Arw), and the engine imports the MOS as (Image, "MOS", 16, 12) instead of (Raw, "MOS", 40, 30).

cargo test -p lightcraft-raw --tests with the 111-file corpus: the unit tests, corpus (24), cr3_corpus (9), dng and robust pass. sparse_corpus fails on arw6-sony-ilce7rm6-apsc-land-hq.arw ("differs from the whole file"), exactly as it does on main; it is the ARW6 header plan, untouched here.

CI

cargo xtask ci on macOS, run with the two macOS build fixes of #990 and #997 applied temporarily (reverted afterwards, not part of this branch; #990's shortened line in tests_lock.rs was run through rustfmt for the run):

  • fmt, clippy (-D warnings) and heif pass. cargo fmt --check also passes on the branch itself.
  • test stops at the known engine failures. The full cargo test --workspace --no-fail-fast run: 3031 passed, 12 failed, exactly the 12 known ones: the ten sidecar::tests_repair_* tests, tests_lightroom_folder::odd_folders_never_fail_the_check and tests_dialog_fit::export_dialog_is_unchanged_in_a_tall_window. The new tests pass.
  • parity, layers, assets and wasm (28 packages) pass. Parity keeps its non-failing stale-summary note, which main prints too.

Overlapping PRs

The branch is on 25ef65c and merges cleanly with main at 701f78e (0.7.1). Test merges of this branch into each PR's head (git merge-tree):

🤖 Generated with Claude Code

…decodes as an ARW (storytold#1275)

An uncompressed Leaf Aptus 22 MOS keeps its 16-bit mosaic in IFD0
(compression 1, BlackIsZero, one sample per pixel) with no Make tag and
no CFA photometric, so `probe` returned None and the file imported as a
greyscale image of the mosaic. Leaf's data block, tag 0x8606 (LeafData
in the ExifTool EXIF tag-name documentation), now marks such an IFD0 as
a raw: OtherTiff, preview only with the reason, as the lossless-JPEG MOS
already is. A rendered RGB image that kept the block stays an image.

The Hasselblad Lunar is a Sony NEX-7 that writes an ARW under Make
HASSELBLAD; only SONY files reached the ARW reader, so it opened as its
preview. A HASSELBLAD file with Sony's raw coding (an IFD with
compression 32767 or the tone-curve tag 0x7010, which no 3FR / FFF has)
now goes there and decodes like a NEX-7: black 512, the SR2SubIFD white
balance. The Tag2010 white-balance fallback, the one table arw.rs keys
by model, takes the body from the maker note's SonyModelID (0xb001)
when the file is not Sony-branded.

Docs: the Lunar is verified in docs/raw/evidence.tsv (236 verified),
raw-parity.md, parity-checklist.md, gaps.md and whats-new.md.
RENDER_CACHE_VERSION 61 -> 62: a Lunar's thumbnails were rendered from
its preview.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@bflatastic

Copy link
Copy Markdown
Member

Landed on main in #1431. Thank you, @AlexChambers!


Generated by Claude Code

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.

Raw recognition: an uncompressed Leaf Aptus 22 MOS opens as a greyscale image of its mosaic, and the Hasselblad Lunar ARW opens preview-only

2 participants