Do not carry tag values from previous images
This commit is contained in:
1 parent
458a713827
commit
3e5f977460
1 file changed
+32
-25
+32
-25
@@ -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
|
|
||||||
.into_iter()
|
|
||||||
.map(SampleFormat::from_u16_exhaustive)
|
|
||||||
.collect();
|
|
||||||
|
|
||||||
// TODO: for now, only homogenous formats across samples are supported.
|
self.samples = self.find_tag_unsigned(Tag::SamplesPerPixel)?.unwrap_or(1);
|
||||||
if !self.sample_format.windows(2).all(|s| s[0] == s[1]) {
|
|
||||||
return Err(TiffUnsupportedError::UnsupportedSampleFormat(
|
self.sample_format = match self.find_tag_unsigned_vec(Tag::SampleFormat)? {
|
||||||
self.sample_format.clone(),
|
Some(vals) => {
|
||||||
)
|
let sample_format: Vec<_> = vals
|
||||||
.into());
|
.into_iter()
|
||||||
}
|
.map(SampleFormat::from_u16_exhaustive)
|
||||||
}
|
.collect();
|
||||||
match self.samples {
|
|
||||||
1 | 3 | 4 => {
|
// TODO: for now, only homogenous formats across samples are supported.
|
||||||
if let Some(val) = self.find_tag_unsigned_vec(Tag::BitsPerSample)? {
|
if !sample_format.windows(2).all(|s| s[0] == s[1]) {
|
||||||
self.bits_per_sample = val;
|
return Err(TiffUnsupportedError::UnsupportedSampleFormat(
|
||||||
|
self.sample_format.clone(),
|
||||||
|
)
|
||||||
|
.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sample_format
|
||||||
}
|
}
|
||||||
|
None => vec![SampleFormat::Uint],
|
||||||
|
};
|
||||||
|
|
||||||
|
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 (
|
||||||
|
|||||||
Reference in new issue
Block a user