From e5d2e7862c8338091b606ec2718e4bd235bf3873 Mon Sep 17 00:00:00 2001 From: Andrew Champion Date: Wed, 11 Dec 2019 15:03:05 +0000 Subject: [PATCH] Parse all homogeneous bit depth RGB(A) color types Make the behavior of RGB and RGBA like Gray in returning ColorTypes for all homogeneous bit depths, even if those depths are not 8, 16, 32 or 64. Note that this does not change which color types can actually be decoded. --- src/decoder/mod.rs | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index fd75e1c..5bd3a81 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -353,15 +353,9 @@ impl Decoder { match self.photometric_interpretation { // TODO: catch also [ 8, 8, 8, _] this does not work due to a bug in rust atm PhotometricInterpretation::RGB => { - match self.bits_per_sample.as_slice() { - [8, 8, 8] => Ok(ColorType::RGB(8)), - [8, 8, 8, 8] => Ok(ColorType::RGBA(8)), - [16, 16, 16] => Ok(ColorType::RGB(16)), - [16, 16, 16, 16] => Ok(ColorType::RGBA(16)), - [32, 32, 32] => Ok(ColorType::RGB(32)), - [32, 32, 32, 32] => Ok(ColorType::RGBA(32)), - [64, 64, 64] => Ok(ColorType::RGB(64)), - [64, 64, 64, 64] => Ok(ColorType::RGBA(64)), + match self.bits_per_sample[..] { + [r, g, b] if [r, r] == [g, b] => Ok(ColorType::RGB(r)), + [r, g, b, a] if [r, r, r] == [g, b, a] => Ok(ColorType::RGBA(r)), _ => Err(TiffError::UnsupportedError( TiffUnsupportedError::InterpretationWithBits( self.photometric_interpretation,