From 9b06e3726d78aaeef92bc32c728f223dd375e353 Mon Sep 17 00:00:00 2001 From: Jonathan Behrens Date: Sat, 23 Mar 2024 13:51:19 -0700 Subject: [PATCH] Sample format should not be a Vec (#226) --- src/decoder/image.rs | 6 +++--- src/decoder/mod.rs | 11 +++-------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/decoder/image.rs b/src/decoder/image.rs index 55e1e99..731c8fb 100644 --- a/src/decoder/image.rs +++ b/src/decoder/image.rs @@ -67,7 +67,7 @@ pub(crate) struct Image { pub bits_per_sample: u8, #[allow(unused)] pub samples: u16, - pub sample_format: Vec, + pub sample_format: SampleFormat, pub photometric_interpretation: PhotometricInterpretation, pub compression_method: CompressionMethod, pub predictor: Predictor, @@ -155,9 +155,9 @@ impl Image { return Err(TiffUnsupportedError::UnsupportedSampleFormat(sample_format).into()); } - sample_format + sample_format[0] } - None => vec![SampleFormat::Uint], + None => SampleFormat::Uint, }; let bits_per_sample: Vec = tag_reader diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index cf2c18e..ccdacf7 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -574,7 +574,7 @@ impl Decoder { height: 0, bits_per_sample: 1, samples: 1, - sample_format: vec![SampleFormat::Uint], + sample_format: SampleFormat::Uint, photometric_interpretation: PhotometricInterpretation::BlackIsZero, compression_method: CompressionMethod::None, jpeg_tables: None, @@ -1065,12 +1065,7 @@ impl Decoder { }; let max_sample_bits = self.image().bits_per_sample; - match self - .image() - .sample_format - .first() - .unwrap_or(&SampleFormat::Uint) - { + match self.image().sample_format { SampleFormat::Uint => match max_sample_bits { n if n <= 8 => DecodingResult::new_u8(buffer_size, &self.limits), n if n <= 16 => DecodingResult::new_u16(buffer_size, &self.limits), @@ -1096,7 +1091,7 @@ impl Decoder { TiffUnsupportedError::UnsupportedBitsPerChannel(n), )), }, - format => Err(TiffUnsupportedError::UnsupportedSampleFormat(vec![*format]).into()), + format => Err(TiffUnsupportedError::UnsupportedSampleFormat(vec![format]).into()), } }