mirror of
https://github.com/storytold/lightcraft.git
synced 2026-10-25 02:30:15 -06:00
`header` accepts a lossless frame but the decoder routing only sent CMYK/cropped/12-bit/non-interleaved files to jpeg-decoder: an 8-bit SOF3 file went to zune-jpeg, which refuses lossless, so a listed file could not open at all. The files that did reach jpeg-decoder were wrong too: jpeg-decoder emits its lossless samples native-endian (its `to_ne_bytes`), so `from_be_bytes` swapped every sample (a 12-bit 2048 decoded as 8), the raw `precision`-bit value was never left-justified into the 16-bit range `Buf::U16` feeds onward, and a 3- or 4-component frame over 8 bits still reports `RGB24`/`CMYK32` while holding two bytes per sample, so it was wrapped as 8-bit data over double-length rows. `scale()` (a DCT size, not a lossless resample) also cut a lossless frame to the top-left when a thumbnail box was requested. Every SOF3 file now routes to jpeg-decoder; lossless frames skip `scale` (`finish` scales after); lossless samples are read native-endian and left-justified; high-precision RGB/CMYK become `Buf::U16`. Four hand-built SOF3 regression tests (12-bit gray, 12-bit RGB, 12-bit CMYK, and 8-bit through the public `decode`); all four fail before the fix (byte-swapped samples, U8-wrapped high-precision buffers, and the zune refusal) and pass after. The crate's other tests stay green.