Do not carry tag values from previous images

This commit is contained in:
Christopher Gundler committed 2021-06-14 20:21:51 +02:00
1 parent 458a713827
commit 3e5f977460
1 file changed
+24 -17
+24 -17
View File
@@ -668,35 +668,42 @@ impl<R: Read + Seek> Decoder<R> {
.and_then(PhotometricInterpretation::from_u16) .and_then(PhotometricInterpretation::from_u16)
.ok_or(TiffUnsupportedError::UnknownInterpretation)?; .ok_or(TiffUnsupportedError::UnknownInterpretation)?;
if let Some(val) = self.find_tag_unsigned(Tag::Compression)? { // Try to parse both the compression method and the number, format, and bits of the included samples.
self.compression_method = CompressionMethod::from_u16(val) // If they are not explicitly specified, those tags are reset to their default values and not carried from previous images.
.ok_or(TiffUnsupportedError::UnknownCompressionMethod)?; self.compression_method = match self.find_tag_unsigned(Tag::Compression)? {
} Some(val) => CompressionMethod::from_u16(val)
if let Some(val) = self.find_tag_unsigned(Tag::SamplesPerPixel)? { .ok_or(TiffUnsupportedError::UnknownCompressionMethod)?,
self.samples = val; None => CompressionMethod::None,
} };
if let Some(vals) = self.find_tag_unsigned_vec(Tag::SampleFormat)? {
self.sample_format = vals self.samples = self.find_tag_unsigned(Tag::SamplesPerPixel)?.unwrap_or(1);
self.sample_format = match self.find_tag_unsigned_vec(Tag::SampleFormat)? {
Some(vals) => {
let sample_format: Vec<_> = vals
.into_iter() .into_iter()
.map(SampleFormat::from_u16_exhaustive) .map(SampleFormat::from_u16_exhaustive)
.collect(); .collect();
// TODO: for now, only homogenous formats across samples are supported. // TODO: for now, only homogenous formats across samples are supported.
if !self.sample_format.windows(2).all(|s| s[0] == s[1]) { if !sample_format.windows(2).all(|s| s[0] == s[1]) {
return Err(TiffUnsupportedError::UnsupportedSampleFormat( return Err(TiffUnsupportedError::UnsupportedSampleFormat(
self.sample_format.clone(), self.sample_format.clone(),
) )
.into()); .into());
} }
sample_format
} }
match self.samples { None => vec![SampleFormat::Uint],
1 | 3 | 4 => { };
if let Some(val) = self.find_tag_unsigned_vec(Tag::BitsPerSample)? {
self.bits_per_sample = val; self.bits_per_sample = match self.samples {
} 1 | 3 | 4 => self
} .find_tag_unsigned_vec(Tag::BitsPerSample)?
.unwrap_or_else(|| vec![1]),
_ => return Err(TiffUnsupportedError::UnsupportedSampleDepth(self.samples).into()), _ => return Err(TiffUnsupportedError::UnsupportedSampleDepth(self.samples).into()),
} };
self.chunk_type = self.chunk_type =
match ( match (