From fa225e820b96bef35f01bf4685654beeb4a8df0c Mon Sep 17 00:00:00 2001 From: "A. Molzer" <5550310+197g@users.noreply.github.com> Date: Mon, 5 Jan 2026 21:38:32 +0100 Subject: [PATCH] Exempt JPEG compression from upsampling restriction I didn't realize we support this in a slightly weird manner where the tag is completely ignored and zune-jpeg performs the upsampling as indicated in the JPEG stream. This is a recurring problem with the compression scheme and tags in TIFF. In the end, decoder can only handle the data as indicated by the JPEG steam and while the specification requires the tags to be consistent with the underlying data, sometimes they are not. The useful fallback is of course to ignore the tag. Ignoring the tag of course buts us in a weird spot for zero-copy decoding since the buffer indication to the caller will be incorrect. For now, maybe the best way of treating subsampling is to upsample all the cases when we add support. --- src/decoder/image.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/decoder/image.rs b/src/decoder/image.rs index 70573d8..0150e4d 100644 --- a/src/decoder/image.rs +++ b/src/decoder/image.rs @@ -738,9 +738,13 @@ impl Image { // Only this color type interprets the tag, which is defined with a default of (2, 2) if matches!(color, ColorType::YCbCr(_)) && self.chroma_subsampling != (1, 1) { - return Err(TiffError::UnsupportedError( - TiffUnsupportedError::ChromaSubsampling, - )); + // The JPEG library does upsampling for us and defines its buffers correctly + // (presumably). All other compression schemes are not supported.. + if !matches!(self.compression_method, CompressionMethod::ModernJPEG) { + return Err(TiffError::UnsupportedError( + TiffUnsupportedError::ChromaSubsampling, + )); + } } Ok(ReadoutLayout {