Include unknown variant for sample format
Since it is known that libtiff produces other sample format variants we do not support, represent these as variants. This also allows returning the sample formats in errors so that composition of formats and known and unknown formats are clearly reported.
This commit is contained in:
1 parent
0ec8e14910
commit
71f3aa8b15
3 files changed
+8
-10
No files matched your search
+5
-7
@@ -423,15 +423,13 @@ impl<R: Read + Seek> Decoder<R> {
|
||||
self.samples = val;
|
||||
}
|
||||
if let Some(vals) = self.find_tag_unsigned_vec(Tag::SampleFormat)? {
|
||||
self.sample_format = vals.iter()
|
||||
.map(|&v| SampleFormat::from_u16(v)
|
||||
.ok_or_else(|| TiffUnsupportedError::UnsupportedSampleFormat(vals.clone()))
|
||||
)
|
||||
.collect::<Result<_, _>>()?;
|
||||
self.sample_format = vals.into_iter()
|
||||
.map(SampleFormat::from_u16_exhaustive)
|
||||
.collect();
|
||||
|
||||
// TODO: for now, only homogenous formats across samples are supported.
|
||||
if !self.sample_format.windows(2).all(|s| s[0] == s[1]) {
|
||||
return Err(TiffUnsupportedError::UnsupportedSampleFormat(vals).into())
|
||||
return Err(TiffUnsupportedError::UnsupportedSampleFormat(self.sample_format.clone()).into())
|
||||
}
|
||||
}
|
||||
match self.samples {
|
||||
@@ -905,7 +903,7 @@ impl<R: Read + Seek> Decoder<R> {
|
||||
))
|
||||
}
|
||||
},
|
||||
format => Err(TiffUnsupportedError::UnsupportedSampleFormat(vec![format.to_u16()]).into()),
|
||||
format => Err(TiffUnsupportedError::UnsupportedSampleFormat(vec![format.clone()]).into()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@ use std::io;
|
||||
use std::string;
|
||||
|
||||
use decoder::ifd::{Value};
|
||||
use tags::{CompressionMethod, PhotometricInterpretation, PlanarConfiguration, Tag};
|
||||
use tags::{CompressionMethod, PhotometricInterpretation, PlanarConfiguration, SampleFormat, Tag};
|
||||
use miniz_oxide::inflate::TINFLStatus;
|
||||
use ColorType;
|
||||
|
||||
@@ -114,7 +114,7 @@ pub enum TiffUnsupportedError {
|
||||
UnknownCompressionMethod,
|
||||
UnsupportedCompressionMethod(CompressionMethod),
|
||||
UnsupportedSampleDepth(u8),
|
||||
UnsupportedSampleFormat(Vec<u16>),
|
||||
UnsupportedSampleFormat(Vec<SampleFormat>),
|
||||
UnsupportedColorType(ColorType),
|
||||
UnsupportedBitsPerChannel(u8),
|
||||
UnsupportedPlanarConfig(Option<PlanarConfiguration>),
|
||||
|
||||
+1
-1
@@ -188,7 +188,7 @@ pub enum ResolutionUnit(u16) {
|
||||
}
|
||||
|
||||
tags! {
|
||||
pub enum SampleFormat(u16) {
|
||||
pub enum SampleFormat(u16) unknown("An unknown extension sample format") {
|
||||
Uint = 1,
|
||||
Int = 2,
|
||||
IEEEFP = 3,
|
||||
|
||||
Reference in new issue
Block a user