Stop doing color conversion when decoding JPEG compressed images (#274)

This commit is contained in:
Jonathan Behrens authored and GitHub committed 2025-06-22 16:19:36 -07:00
1 parent 140f2788de
commit 7648317643
1 file changed
+7 -25
+7 -25
View File
@@ -370,7 +370,6 @@ impl Image {
fn create_reader<'r, R: 'r + Read>( fn create_reader<'r, R: 'r + Read>(
reader: R, reader: R,
#[allow(unused_variables)] photometric_interpretation: PhotometricInterpretation,
compression_method: CompressionMethod, compression_method: CompressionMethod,
compressed_length: u64, compressed_length: u64,
#[allow(unused_variables)] jpeg_tables: Option<&[u8]>, #[allow(unused_variables)] jpeg_tables: Option<&[u8]>,
@@ -427,30 +426,14 @@ impl Image {
let mut decoder = zune_jpeg::JpegDecoder::new(jpeg_data); let mut decoder = zune_jpeg::JpegDecoder::new(jpeg_data);
let mut options: zune_core::options::DecoderOptions = Default::default(); let mut options: zune_core::options::DecoderOptions = Default::default();
match photometric_interpretation {
PhotometricInterpretation::RGB => { // Disable color conversion by setting the output colorspace to the input
options = // colorspace.
options.jpeg_set_out_colorspace(zune_core::colorspace::ColorSpace::RGB); decoder.decode_headers()?;
} if let Some(colorspace) = decoder.get_input_colorspace() {
PhotometricInterpretation::CMYK => { options = options.jpeg_set_out_colorspace(colorspace);
options = options
.jpeg_set_out_colorspace(zune_core::colorspace::ColorSpace::CMYK);
}
PhotometricInterpretation::YCbCr => {
options = options
.jpeg_set_out_colorspace(zune_core::colorspace::ColorSpace::YCbCr);
}
PhotometricInterpretation::WhiteIsZero
| PhotometricInterpretation::BlackIsZero
| PhotometricInterpretation::TransparencyMask => {}
PhotometricInterpretation::RGBPalette | PhotometricInterpretation::CIELab => {
return Err(TiffError::UnsupportedError(
TiffUnsupportedError::UnsupportedInterpretation(
photometric_interpretation,
),
));
}
} }
decoder.set_options(options); decoder.set_options(options);
let data = decoder.decode()?; let data = decoder.decode()?;
@@ -653,7 +636,6 @@ impl Image {
let mut reader = Self::create_reader( let mut reader = Self::create_reader(
reader, reader,
photometric_interpretation,
compression_method, compression_method,
*compressed_bytes, *compressed_bytes,
self.jpeg_tables.as_deref().map(|a| &**a), self.jpeg_tables.as_deref().map(|a| &**a),