Repository navigation
LR-IMP-FORMATS: decode Hasselblad lossless JPEG with selection value 8 (FFF, H3D/H4D/CFV-50c 3FR) - #555
Merged
Conversation
…8 (FFF, H3D/H4D/CFV-50c 3FR) Lossless JPEG scans whose SOS gives predictor selection value 8 (which T.81 leaves undefined) are read as Hasselblad codes them (ljpeg::decode_hasselblad): 32-bit little-endian words read from their most significant bit, no byte stuffing; each row in pairs of samples, both Huffman categories before both differences; category 16 is followed by 16 ignored bits and means -32768; each sample is the previous sample of its column parity in the row plus the difference, modulo 2^16, both starting at 32768 on every row. Only the layout measured is accepted (one component, 16 bits, no point transform or restarts, even width); other layouts and selection values above 8 stay Unsupported. The rule was measured on 14 CC0 files with the ljpeg-explorer tool. RENDER_CACHE_VERSION 23.
…lad-p8 (render cache version 23, as storytold#448 has 22) # Conflicts: # crates/engine/src/media.rs # docs/parity.md
… render cache version 23, as main is at 22) # Conflicts: # docs/parity.md
…nance Merge origin/main into storytold#555. The decode_hasselblad doc comment records how the coding rule was established (first hypothesis recalled by the AI author from training data that includes other converters, corrected for byte order and confirmed by a black-box search over 17,280 layout hypotheses on the CC0 files; the code is original). The LR-IMP-FORMATS row on main's text now lists the decoded FFF and lossless-JPEG 3FR files instead of preview-only. RENDER_CACHE_VERSION 37 -> 38. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
|
Thank you @radialmonster! The Hasselblad decoder landed in #692. I added a short provenance note to the Please join our Discord if you haven't already: https://discord.gg/artcraft |
emmertex
added a commit
to Kaan88/lightcraft
that referenced
this pull request
Oct 26, 2026
LR-PROF-CAMERACOLOR: bundled X20, X100T, X-T1, D700 and D70 profiles (upstream storytold#2160)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR: LightCraft now decodes the Hasselblad raws that store their sensor data in Hasselblad's own
variant of lossless JPEG: every FFF file and the H3D, H4D and CFV-50c 3FR files (the other 14 of the 20 CC0
Hasselblad samples on raw.pixls.us, so all 20 now decode). The coding rule was first recalled by the AI model that wrote this change,
then tested against 17,279 alternatives per file with a tool built for the purpose, and confirmed by
measurements on the files. The measurements corrected the recalled rule in one respect (byte order).
Follows #448 (uncompressed 3FR, now on
main); together they cover all 20 CC0 Hasselblad samples. Part of #420.Change
crates/raw/src/ljpeg.rs: a lossless-JPEG scan whose SOS header gives predictor selection value 8 (which theJPEG standard, T.81, does not define) is decoded with Hasselblad's rule (
decode_hasselblad):(FF bytes are ordinary data);
both start at 32768 at the beginning of every row.
restart markers, even width. Anything else with selection value 8, and any selection value above 8, stays an
"unsupported" error and the file stays preview-only, as before.
Bitstrait), so the existing T.81 path isunchanged.
RENDER_CACHE_VERSION22 to 23 (these files now render from the raw data).docs/parity.md: the LR-IMP-FORMATS row lists the newly supported files.Provenance
This needs to be stated plainly. The AI model that wrote this change (Claude) recalled the outline of this
coding from its training data, which includes other raw converters' code. It said so before any work started,
and the work was stopped until the contributor directing it (not a LightCraft maintainer) decided how to proceed. The terms were: the rule must
be proven from the files by a tool we build; the recalled rule may be one candidate among many; no other
converter's source may be consulted; and nothing may be copied from memory as code.
That is what was done. No other converter's source, documentation or web page was opened, and no code was
copied. The recalled rule was treated as one hypothesis, tested against alternatives with the verification
tool described below, and corrected where the measurements disagreed with it. The decoder was written fresh
from the measured rule, in the style of the existing lossless-JPEG code.
How the rule was verified
ljpeg-exploreris a standalone Rust command-line tool written for this (its own Cargo project, not part of theproduct or of this pull request; I can share it and the full per-file hypothesis table if that helps review). It reads the JPEG markers, decodes the T.81 Huffman categories, and decodes a scan under any
combination of:
running predictors with 1, 2 or 4 lanes started from several values or from the row above.
That is 576 x 30 = 17,280 hypotheses per file. For each one the tool reports only scores computed from the file:
It ran on all 14 files, full frames (243,298 rows logged).
What the scores cannot pin down, said plainly:
the value range in files that reach them. For example, the X1D II's fill columns equal 65535, exactly as in its
uncompressed siblings, only at 32768; dark and saturated samples elsewhere wrap one step either side.
relatives (shot at other ISOs) favours the rule in only 6 of 8 files.
Results
fitted render): RGGB is the best phase in every file, and the preview covers the default crop.
from LightCraft's flatter neutral rendering. No row bands or colour casts.
DNG including Hasselblad L1D/L2D, the 6 uncompressed 3FR). 20 more fail identically on both.
Tests
Hand-made byte streams in
ljpeg.rs:selection_value_8_known_answer: a 4 x 2 frame written out bit by bit (category 16 with two different ignoredpayloads, modular wrap, per-row restart, the FF FD bytes that a stuffing reader would take for a marker).
selection_value_8_reads_little_endian_words: the same bits in plain byte order are a different stream.selection_value_8_round_trips_through_the_test_writer: a test-only writer of the rule, with extremes.selection_value_8_rejects_bad_streams: truncated data, a category above 16, an odd width, other precisions,selection value 9, and every prefix of a stream fail cleanly without a panic.
lib.rs,selection_value_8_cfa_tiff_decodeschecks the 3FR/FFF layout end to end, and theunknown-predictor test now uses selection value 9.
The three decode tests fail without the change.
CI
cargo fmt --check: clean.cargo clippy --workspace --all-targets -D warnings: clean.cargo test --workspace --no-fail-fast: 1,394 passed, 0 failed, 14 ignored in the 67 test binaries thatcompleted. The ui-egui library binary (its headless tests are known to be flaky under load) had 4 headless
failures in the full run and stopped without a summary. Run alone it passed: 363 passed, 2 ignored.
cargo xtask parity,layers,assets,wasm: OK.After merging current
maininto the branch (the diff is nowljpeg.rs,raw/src/lib.rs,media.rsand the parity row):cargo fmt --check,cargo clippy -p lightcraft-raw -p lightcraft-engine --all-targets -D warnings,cargo test -p lightcraft-rawandcargo test -p lightcraft-engine --libpass (one engine test known to be flaky under load,tests_denoise::model_installation_…, failed in the full run and passed alone), andcargo xtask paritypasses with the same "summary is stale" note asmain.