unpack accepted a bit depth of 0: the input requirement became zero bytes,
so one source byte produced a header-sized buffer of zero samples. Depths
outside 1..=16 (the u16 output range) are now rejected up front.
- raw: a lossy JPEG tile must have as many components as SamplesPerPixel.
- process::develop_with: use the opcode lists only when apply_opcodes is set.
- writer: lossy_jpeg returns an error instead of an empty chunk or an encoder panic; new try_write rejects unsupported sample counts and bits/CFA options for lossy JPEG.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Problem: lossy DNGs (DNG 1.4 Compression 34892, used for proxy and
"lossy compressed" DNGs, 8-bit LinearRaw tiles usually with a
LinearizationTable) were refused as unsupported.
Fix: decode each tile or strip with the baseline JPEG decoder the
workspace already depends on (`image` with only its jpeg feature, as in
crates/codecs and crates/media; no new crate in Cargo.lock, builds for
wasm32), one component as greyscale or three as colour, the samples
filling the chunk in raster order as with lossless JPEG. As the spec
allows it only for 8-bit LinearRaw, CFA or other depths are refused with
a message naming lossy JPEG. The decoder runs under catch_unwind with an
allocation limit, its picture must match the chunk, and a tiny file
cannot claim a huge picture (at least two bits per 8 x 8 block). Info
reports "lossy JPEG". The test writer gains a lossy JPEG path through
`image`'s encoder.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Problem: a 4096 x 2160 12-bit lossless-JPEG CinemaDNG frame took about
50 ms (tiles) to 115 ms (one strip) on 16 threads and about 200 ms on
one, too slow for smooth 4K playback, and every frame was developed at
full size even for small monitors and proxies.
Fix, without changing the output (f32 bit patterns compared):
- Lossless JPEG: one 13-bit lookup gives a code and its difference
bits together; the bit reader takes eight bytes at once when they
hold no 0xFF; per-predictor line loops.
- Tiles decode in parallel by bands straight into place; a single
strip covering the image is used without a copy.
- Normalisation: without black-level deltas, a lookup table per
CFA / black-level site replaces the per-sample float arithmetic
(each entry computed by the same expression).
- Demosaic, crop and colour run row by row from the normalised plane
(no padded copy, no RGB intermediate), with 5 x 5 windows sliding
along the five mirrored rows; the bilinear (Fast) Bayer demosaic
sums in the reference order.
- ProcessOptions::target_size now develops Bayer, LinearRaw and mono
pictures at 1/2, 1/4 or 1/8 size (the smallest covering the
target) by averaging each colour over the blocks, without demosaic.
The first version is kept as `reference` (feature `writer`, tests and
benchmarks only): tests/equivalence.rs checks identical raw samples and
developed bits over all Bayer phases, both qualities, odd crops,
active areas, linearisation, black deltas, codes above the bit depth,
LinearRaw, mono, other CFAs and tiny pictures; examples/bench.rs times
both interleaved at 1/4/16 threads. Best of 9 under load ~12: tiles
2.5x (1 thread) to 2.9x (16), one strip 2.1-2.6x; half size 3-4x.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* dng: bound lossless-JPEG decoding by the data it has and reject shared tile bytes (#2776)
Remaining amplification holes after the decoded-sample cap: the per-chunk
decode cap had 256 Ki samples of slack on top of the chunk's size, a patched
frame header could ask for far more samples than the entropy-coded bytes can
hold (zero bits were fed past the end), and strips/tiles pointing at the same
bytes were each decoded in full.
ljpeg::decode now fails with Truncated when width*height*components needs more
than one bit per sample of the remaining data, the caller caps at exactly the
chunk's sample count, and raw::chunks rejects overlapping strip/tile ranges.
Tested with a tiny lj92 stream whose SOF is patched to 512x512 and a tiled
file whose second tile reuses the first tile's bytes.
Fixes#2776
* dng: keep the slack for a lossless JPEG coded larger than its chunk
The entropy-length bound already caps the allocation; a last strip coded at
full RowsPerStrip holds more samples than the chunk needs and is truncated.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Brandon Thomas <echelon@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Problem: camera RAW is at 0% (docs/codec-parity.md, #383). CinemaDNG,
the one cinema RAW format with a public specification, could not be
read at all.
Fix: new L0 crate filmcraft-dng, written from the public DNG 1.4-1.7,
TIFF 6.0 / TIFF-EP, ITU-T T.81 and CinemaDNG specifications only (no
other decoder's source read; editions in the crate README):
- TIFF container with SubIFDs, bounded (64 IFDs, 4 levels, cycles end
the walk) and checked offsets; the main raw IFD is the largest
NewSubFileType 0 CFA / LinearRaw image.
- Raw data: 1-16-bit uncompressed (MSB-first packing) and lossless JPEG
(process 14, predictors 1-7, 1-4 components, point transform, line
restarts), strips and tiles, tiles decoded in parallel; allocations
capped by size and by the data present.
- Processing per the DNG model: ActiveArea, LinearizationTable, per-site
black levels with deltas, white levels, as-shot white balance with
neutral highlight clipping, Malvar-He-Cutler Bayer demosaic (bilinear
for other patterns), DefaultCrop, ColorMatrix / CameraCalibration /
ForwardMatrix with illuminant interpolation, Bradford to linear
Rec. 709, BaselineExposure; output scene-linear RGBA floats.
- CinemaDNG FrameRate, TimeCodes and ReelName tags.
- A test-only writer (feature `writer`) synthesises DNGs. Tests: raw
samples bit-exact for every depth / predictor / layout, processing
against hand-computed values, hostile files (every truncation, 12k
mutations, cyclic IFDs, huge sizes, bad offsets), and LibRaw's
unprocessed_raw as an external oracle reading the same samples
(skipped when not installed).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>