Skip to content

Commit fa225e8

Browse files
committed
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.
1 parent ea373ba commit fa225e8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/decoder/image.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -738,9 +738,13 @@ impl Image {
738738

739739
// Only this color type interprets the tag, which is defined with a default of (2, 2)
740740
if matches!(color, ColorType::YCbCr(_)) && self.chroma_subsampling != (1, 1) {
741-
return Err(TiffError::UnsupportedError(
742-
TiffUnsupportedError::ChromaSubsampling,
743-
));
741+
// The JPEG library does upsampling for us and defines its buffers correctly
742+
// (presumably). All other compression schemes are not supported..
743+
if !matches!(self.compression_method, CompressionMethod::ModernJPEG) {
744+
return Err(TiffError::UnsupportedError(
745+
TiffUnsupportedError::ChromaSubsampling,
746+
));
747+
}
744748
}
745749

746750
Ok(ReadoutLayout {

0 commit comments

Comments
 (0)