Skip to content

Commit 7648317

Browse files
authored
Stop doing color conversion when decoding JPEG compressed images (#274)
1 parent 140f278 commit 7648317

File tree

1 file changed

+7
-25
lines changed

1 file changed

+7
-25
lines changed

src/decoder/image.rs

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,6 @@ impl Image {
370370

371371
fn create_reader<'r, R: 'r + Read>(
372372
reader: R,
373-
#[allow(unused_variables)] photometric_interpretation: PhotometricInterpretation,
374373
compression_method: CompressionMethod,
375374
compressed_length: u64,
376375
#[allow(unused_variables)] jpeg_tables: Option<&[u8]>,
@@ -427,30 +426,14 @@ impl Image {
427426

428427
let mut decoder = zune_jpeg::JpegDecoder::new(jpeg_data);
429428
let mut options: zune_core::options::DecoderOptions = Default::default();
430-
match photometric_interpretation {
431-
PhotometricInterpretation::RGB => {
432-
options =
433-
options.jpeg_set_out_colorspace(zune_core::colorspace::ColorSpace::RGB);
434-
}
435-
PhotometricInterpretation::CMYK => {
436-
options = options
437-
.jpeg_set_out_colorspace(zune_core::colorspace::ColorSpace::CMYK);
438-
}
439-
PhotometricInterpretation::YCbCr => {
440-
options = options
441-
.jpeg_set_out_colorspace(zune_core::colorspace::ColorSpace::YCbCr);
442-
}
443-
PhotometricInterpretation::WhiteIsZero
444-
| PhotometricInterpretation::BlackIsZero
445-
| PhotometricInterpretation::TransparencyMask => {}
446-
PhotometricInterpretation::RGBPalette | PhotometricInterpretation::CIELab => {
447-
return Err(TiffError::UnsupportedError(
448-
TiffUnsupportedError::UnsupportedInterpretation(
449-
photometric_interpretation,
450-
),
451-
));
452-
}
429+
430+
// Disable color conversion by setting the output colorspace to the input
431+
// colorspace.
432+
decoder.decode_headers()?;
433+
if let Some(colorspace) = decoder.get_input_colorspace() {
434+
options = options.jpeg_set_out_colorspace(colorspace);
453435
}
436+
454437
decoder.set_options(options);
455438

456439
let data = decoder.decode()?;
@@ -653,7 +636,6 @@ impl Image {
653636

654637
let mut reader = Self::create_reader(
655638
reader,
656-
photometric_interpretation,
657639
compression_method,
658640
*compressed_bytes,
659641
self.jpeg_tables.as_deref().map(|a| &**a),

0 commit comments

Comments
 (0)