feat: YCbCr chroma subsampling for non-JPEG compression#388
Open
aarshivv wants to merge 2 commits into
Open
Conversation
Add YCbCrUpsamplingReader that converts chroma-subsampled YCbCr block data to full-resolution 3-bytes-per-pixel output. Each block of h×v pixels stores h*v Y samples plus one shared Cb and Cr sample; the reader expands these into per-pixel (Y, Cb, Cr) triples. This enables decoding YCbCr TIFFs with any supported compression method (uncompressed, LZW, Deflate, etc.), not just JPEG. Two more libtiffpic test images now decode with verified hashes: - dscf0013.tif (uncompressed YCbCr 2,1 subsampling) - ycbcr-cat.tif (LZW-compressed YCbCr 2,2 subsampling) The remaining two YCbCr test images (smallliz.tif, zackthecat.tif) use Old JPEG compression (type 6) which is a separate unsupported feature.
… tests The YCbCr upsampling pipeline applies predictor reversal after the upsampling reader, so a non-None predictor ends up being reversed on the expanded pixel layout rather than the stored MCU-block layout it was encoded against. Reject the combination with ChromaSubsampling until prediction can run before the upsampling step. Add unit tests covering the YCbCrUpsamplingReader in isolation: (2,2), (2,1), (1,2), and (4,4) factors, plus non-divisible width and height cases where the final block column/row is clipped.
Author
|
CI failure here is unrelated — src/decoder/logluv.rs:95 trips a new clippy lint (while_let_loop, enabled by default in Rust 1.95). Main fails the same check on my machine. Happy to open a separate PR for the one-line fix. |
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.
Follow-up to #387. Brings back 83409cb (reverted in 85215e8) with two extra patches to address gaps.
First commit is a clean cherry-pick of 83409cb —
YCbCrUpsamplingReaderthat converts MCU-block layout into full-res YCbCr triples, wired into expand_chunk for non-JPEG YCbCr. Libtiffpic hashes updated fortests/libtiffpic/dscf0013.tif(uncompressed 4:2:2) andtests/libtiffpic/ycbcr-cat.tif(LZW 4:2:0).Second commit does two things:
Planar YCbCr + subsampling stays rejected as in the cherry-pick.
cargo test, cargo clippy --all-targets, cargo test --test decode_libtiffpic all green (61/61).