Repository navigation
LRC-LIB-CATALOG-IMPORT: describe raws from their headers without reading pixel data (step 1 of #832) - #961
Merged
Conversation
…ing pixel data `lightcraft_raw::sparse::header_plan` says which byte ranges of a raw file the header probe (`probe_info`, `lightcraft_meta::extract`) reads, given a buffer of the file's length in which only some ranges are loaded: everything but the bulk sample data (large TIFF strips/tiles minus the first chunk's coding headers, a CR3's image tracks minus the raw track's CRX headers and QP maps, a RAF's CFA strip, an RW2's raw data). `preview_plan` also reads what `embedded_preview` needs, for raws shown from their preview. NEF, ORF and PEF (their header probe looks at samples) and anything else are read whole. The corpus test checks, for every raw.pixls.us sample the plan describes, that probing the partly loaded buffer gives exactly what the whole file gives, with the skipped bytes zero and again 0xFF: CR3 2.7 %, DNG 2.4 %, CR2 3 %, RAF 6 %, RW2 7 %, ARW 8 % of their bytes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 11, 2026
Merged
lzjtugjc
added a commit
to lzjtugjc/lightcraft
that referenced
this pull request
Oct 11, 2026
…lan's ranges The header-only path added in storytold#755 answers for a Fuji RAF, whose preview pointer sits in the first bytes. A Canon CR3 keeps its preview in a JPEG track, and a TIFF raw (CR2, ARW, DNG, RW2, 3FR …) can keep its preview tag in an IFD the prefix cuts short: both fell back to `std::fs::read` of the whole file — tens of megabytes for a JPEG of a few, on the format of the largest bucket in gaps.md (Canon, 33 % of photographers). `preview_window` now asks `lightcraft_raw::sparse::preview_plan` — the module storytold#961 added for the import path, which had no production caller — which ranges `embedded_preview` reads, and reads exactly those: `planned_preview` fills a buffer of the file's length, reads the ranges the plan names and asks again until it says `Ready`. The buffer is the file's length, which the memory gate counted already, and its untouched pages stay zero, so what this path costs is the bytes read — on macOS a freed buffer of that size may sit in the allocator's cache rather than go back to the OS (measured on a 38k-photo import, storytold#832). The loop gives up past 60 % of the file, the bound step 2's partial read uses, and a plan that does not fit, a file past 1 GiB or a window that does not decode all end in the whole-file fallback. The quick path hands the JPEG to the decoder alone, so two container facts the whole-file path applies have to be visible in the bytes it is handed, or the file declines and the whole file keeps the preview: - a preview colour space of Adobe RGB (`decode_raw_preview` applies it; a JPEG-only decode has the JPEG's own space, else sRGB). A container that says sRGB does not decline — that is what the decode assumes anyway, and declining it took the fast path away from a real Sony ARW; - the file's own EXIF orientation, when the preview JPEG carries none of its own: the plan's header is a bounded 64 KiB (the header route grows its prefix to the preview's declared extent instead), and an orientation tag it cannot see would show the preview unrotated. Measured over the whole CC0 corpus (111 raws): 52 files take this route, reading a median 7.8 % of their bytes (0.9-27.7 %) — RW2 3.3 %, Leica RWL 4.1 %, ARW 7.5 %, CR3 8.4 %, DNG 9.7 %, CR2 14.3 % — while the 21 RAFs stay on the header route (median 4.5 %). The other 38 read whole: NEF, NRW, ORF, PEF and SRW because the planner does not describe them (an SRW plans to the whole file, which the 60 % budget then declines), plus the ARWs, CR2s, CR3s and DNGs that declare Adobe RGB or whose plan wants more than that budget — the bytes they read are the ones the plan would have read anyway. Across all 111 files the plan handed on the same preview as the whole file, with the skipped bytes zeroed and again 0xFF. `LIGHTCRAFT_PROFILE=1` prints [profile] preview …/arw-sony-a7rm4a-compressed.arw: read 688128 of 61832192 bytes (plan, window 483441) Tests: a synthetic TIFF/DNG whose preview only its tags locate (identical pixels to the whole-file path, the CFA strip unread), the same structure without the tag that makes it a raw, a file whose orientation only the whole file shows, and a file that states Adobe RGB against one that states sRGB; the opt-in real-file test reports which path answered. Co-Authored-By: DeepSeek V3.2 <noreply@deepseek.com>
bogusyogi
pushed a commit
to Orthic-Labs/ember
that referenced
this pull request
Oct 14, 2026
…lan's ranges The header-only path added in storytold#755 answers for a Fuji RAF, whose preview pointer sits in the first bytes. A Canon CR3 keeps its preview in a JPEG track, and a TIFF raw (CR2, ARW, DNG, RW2, 3FR …) can keep its preview tag in an IFD the prefix cuts short: both fell back to `std::fs::read` of the whole file — tens of megabytes for a JPEG of a few, on the format of the largest bucket in gaps.md (Canon, 33 % of photographers). `preview_window` now asks `lightcraft_raw::sparse::preview_plan` — the module storytold#961 added for the import path, which had no production caller — which ranges `embedded_preview` reads, and reads exactly those: `planned_preview` fills a buffer of the file's length, reads the ranges the plan names and asks again until it says `Ready`. The buffer is the file's length, which the memory gate counted already, and its untouched pages stay zero, so what this path costs is the bytes read — on macOS a freed buffer of that size may sit in the allocator's cache rather than go back to the OS (measured on a 38k-photo import, storytold#832). The loop gives up past 60 % of the file, the bound step 2's partial read uses, and a plan that does not fit, a file past 1 GiB or a window that does not decode all end in the whole-file fallback. The quick path hands the JPEG to the decoder alone, so two container facts the whole-file path applies have to be visible in the bytes it is handed, or the file declines and the whole file keeps the preview: - a preview colour space of Adobe RGB (`decode_raw_preview` applies it; a JPEG-only decode has the JPEG's own space, else sRGB). A container that says sRGB does not decline — that is what the decode assumes anyway, and declining it took the fast path away from a real Sony ARW; - the file's own EXIF orientation, when the preview JPEG carries none of its own: the plan's header is a bounded 64 KiB (the header route grows its prefix to the preview's declared extent instead), and an orientation tag it cannot see would show the preview unrotated. Measured over the whole CC0 corpus (111 raws): 52 files take this route, reading a median 7.8 % of their bytes (0.9-27.7 %) — RW2 3.3 %, Leica RWL 4.1 %, ARW 7.5 %, CR3 8.4 %, DNG 9.7 %, CR2 14.3 % — while the 21 RAFs stay on the header route (median 4.5 %). The other 38 read whole: NEF, NRW, ORF, PEF and SRW because the planner does not describe them (an SRW plans to the whole file, which the 60 % budget then declines), plus the ARWs, CR2s, CR3s and DNGs that declare Adobe RGB or whose plan wants more than that budget — the bytes they read are the ones the plan would have read anyway. Across all 111 files the plan handed on the same preview as the whole file, with the skipped bytes zeroed and again 0xFF. `LIGHTCRAFT_PROFILE=1` prints [profile] preview …/arw-sony-a7rm4a-compressed.arw: read 688128 of 61832192 bytes (plan, window 483441) Tests: a synthetic TIFF/DNG whose preview only its tags locate (identical pixels to the whole-file path, the CFA strip unread), the same structure without the tag that makes it a raw, a file whose orientation only the whole file shows, and a file that states Adobe RGB against one that states sRGB; the opt-in real-file test reports which path answered. Co-Authored-By: DeepSeek V3.2 <noreply@deepseek.com> (cherry picked from commit 3c7f450)
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.
What this does
Step 1 of the two proposed in #832: a self-contained building block, no behaviour change yet.
lightcraft_raw::sparse::header_plan(bytes, loaded)says which byte ranges of a raw fileprobe_infoandlightcraft_meta::extractread. It is asked about a buffer of the file's full length in which only the ranges inloadedhold the file's bytes (the rest is zeros). The caller loads the ranges it names and asks again; once it answersReady, probing the buffer gives what probing the whole file gives.preview_planalso covers whatembedded_previewreads, for raws shown from their embedded preview.Nothing calls it yet. Step 2, the batched catalog import from #832, will probe originals with it, and #755's preview loader could use
preview_plan.What is left out
Only bulk sample data:
RawDataOffsetto the end.moov, the XMPuuidbox, the first sample of each CTMD track (the as-shot white balance lives there) and the main raw track's CRX headers and QP maps (crx::header_ranges: the bytescrx::validatereads).Whole. So is a structure that is incomplete, inconsistent, or keeps IFD tables or out-of-line values inside sample data. The plan never guesses.The TIFF IFD walk mirrors
lightcraft_tiff's reader (chain, SubIFDs, Exif, GPS, Interop, same bounds) and asks for every IFD table and for the values that locate IFDs and chunks. The CR3 box walk mirrorsparse_cr3.Equivalence
crates/raw/tests/sparse_corpus.rsruns every corpus raw (raw.pixls.us and the Leica set) through the plan twice, with the skipped bytes 0 and again 0xFF. For each file the plan describes,probe_info,lightcraft_meta::extractand the embedded XMP must equal the whole file's; withpreview_planalsoembedded_preview. A reader that looked at skipped bytes would fail it.Through step 2's probe, 961 files from my own catalog (842 EOS R5 Mark II CR3, 24 Leica M11-P DNG, 74 JPEG, 21 ORF) also gave an identical
ProbeInfo, the content hash aside.Unit tests cover the
Rangesarithmetic and hostile input (self-referencing IFDs, oversized counts, CR3 boxes past the end of the file, a RAF container outside it): each ends with an answer, never a panic.Small changes outside the module
crx::header_ranges(new,pub(crate));vendor::cr3::main_track,vendor::raf::raw_ifdandvendor::rw2::RAW_OFFSETbecomepub(crate).lightcraft_meta::cr3::XMP_UUIDis public; theparse_cr3doc says which top-level boxes it reads (the CR3 plan relies on that, and the corpus test guards it).Verification
cargo xtask cion this branch: fmt, clippy, heif, parity, layers, assets and wasm pass;cargo test --workspace --no-fail-fastpasses exceptexport_progress_and_cancel(#674), which also fails on main.Related
crx.rs; with it the R5 Mark II C-RAW files that open as previews today plan as raws too.🤖 Generated with Claude Code