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:
Andrew Champion committed 2020-02-10 13:21:16 +00:00
1 parent 0ec8e14910
commit 71f3aa8b15
3 files changed
+8 -10

No files matched your search

+5 -7
View File
@@ -423,15 +423,13 @@ impl<R: Read + Seek> Decoder<R> {
self.samples = val; self.samples = val;
} }
if let Some(vals) = self.find_tag_unsigned_vec(Tag::SampleFormat)? { if let Some(vals) = self.find_tag_unsigned_vec(Tag::SampleFormat)? {
self.sample_format = vals.iter() self.sample_format = vals.into_iter()
.map(|&v| SampleFormat::from_u16(v) .map(SampleFormat::from_u16_exhaustive)
.ok_or_else(|| TiffUnsupportedError::UnsupportedSampleFormat(vals.clone())) .collect();
)
.collect::<Result<_, _>>()?;
// 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 !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 { 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
View File
@@ -4,7 +4,7 @@ use std::io;
use std::string; use std::string;
use decoder::ifd::{Value}; use decoder::ifd::{Value};
use tags::{CompressionMethod, PhotometricInterpretation, PlanarConfiguration, Tag}; use tags::{CompressionMethod, PhotometricInterpretation, PlanarConfiguration, SampleFormat, Tag};
use miniz_oxide::inflate::TINFLStatus; use miniz_oxide::inflate::TINFLStatus;
use ColorType; use ColorType;
@@ -114,7 +114,7 @@ pub enum TiffUnsupportedError {
UnknownCompressionMethod, UnknownCompressionMethod,
UnsupportedCompressionMethod(CompressionMethod), UnsupportedCompressionMethod(CompressionMethod),
UnsupportedSampleDepth(u8), UnsupportedSampleDepth(u8),
UnsupportedSampleFormat(Vec<u16>), UnsupportedSampleFormat(Vec<SampleFormat>),
UnsupportedColorType(ColorType), UnsupportedColorType(ColorType),
UnsupportedBitsPerChannel(u8), UnsupportedBitsPerChannel(u8),
UnsupportedPlanarConfig(Option<PlanarConfiguration>), UnsupportedPlanarConfig(Option<PlanarConfiguration>),
+1 -1
View File
@@ -188,7 +188,7 @@ pub enum ResolutionUnit(u16) {
} }
tags! { tags! {
pub enum SampleFormat(u16) { pub enum SampleFormat(u16) unknown("An unknown extension sample format") {
Uint = 1, Uint = 1,
Int = 2, Int = 2,
IEEEFP = 3, IEEEFP = 3,