From 71f3aa8b15d85bbe8f98ac969204d96c2652f84a Mon Sep 17 00:00:00 2001 From: Andrew Champion Date: Mon, 10 Feb 2020 13:12:50 +0000 Subject: [PATCH] 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. --- src/decoder/mod.rs | 12 +++++------- src/error.rs | 4 ++-- src/tags.rs | 2 +- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/decoder/mod.rs b/src/decoder/mod.rs index f4d00f1..398280e 100644 --- a/src/decoder/mod.rs +++ b/src/decoder/mod.rs @@ -423,15 +423,13 @@ impl Decoder { 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::>()?; + 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 Decoder { )) } }, - format => Err(TiffUnsupportedError::UnsupportedSampleFormat(vec![format.to_u16()]).into()), + format => Err(TiffUnsupportedError::UnsupportedSampleFormat(vec![format.clone()]).into()), } } diff --git a/src/error.rs b/src/error.rs index 4c965fd..a86f404 100644 --- a/src/error.rs +++ b/src/error.rs @@ -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), + UnsupportedSampleFormat(Vec), UnsupportedColorType(ColorType), UnsupportedBitsPerChannel(u8), UnsupportedPlanarConfig(Option), diff --git a/src/tags.rs b/src/tags.rs index e4813ef..f13034d 100644 --- a/src/tags.rs +++ b/src/tags.rs @@ -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,