Migrate from String to properly typed TiffUnsupportedError

This commit is contained in:
Felix Schütt committed 2018-09-13 13:44:16 +02:00
1 parent 2c6ca5459a
commit 0089e93b49
4 files changed
+60 -43

No files matched your search

+38 -2
View File
@@ -3,6 +3,8 @@ use std::fmt;
use std::io;
use decoder::ifd::{Tag, Value};
use decoder::{PhotometricInterpretation, CompressionMethod, PlanarConfiguration};
use ColorType;
/// Tiff error kinds.
#[derive(Debug)]
@@ -11,13 +13,13 @@ pub enum TiffError {
FormatError(TiffFormatError),
/// The Decoder does not support this image format
UnsupportedError(String),
UnsupportedError(TiffUnsupportedError),
/// An I/O Error occurred while decoding the image
IoError(io::Error),
}
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TiffFormatError {
TiffSignatureNotFound,
TiffSignatureInvalid,
@@ -41,6 +43,40 @@ impl fmt::Display for TiffFormatError {
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum TiffUnsupportedError {
HorizontalPredictor(ColorType),
InterpretationWithBits(PhotometricInterpretation, Vec<u8>),
UnknownInterpretation,
UnknownCompressionMethod,
UnsupportedCompressionMethod(CompressionMethod),
UnsupportedSampleDepth(u8),
UnsupportedColorType(ColorType),
UnsupportedBitsPerChannel(u8),
UnsupportedPlanarConfig(Option<PlanarConfiguration>),
UnsupportedDataType,
}
impl fmt::Display for TiffUnsupportedError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
use self::TiffUnsupportedError::*;
match *self {
HorizontalPredictor(color_type) => write!(fmt, "Horizontal predictor for {:?} is unsupported.", color_type),
InterpretationWithBits(ref photometric_interpretation, ref bits_per_sample) => {
write!(fmt, "{:?} with {:?} bits per sample is unsupported", photometric_interpretation, bits_per_sample)
},
UnknownInterpretation => write!(fmt, "The image is using an unknown photometric interpretation."),
UnknownCompressionMethod => write!(fmt, "Unknown compression method."),
UnsupportedCompressionMethod(method) => write!(fmt, "Compression method {:?} is unsupported", method),
UnsupportedSampleDepth(samples) => write!(fmt, "{} samples per pixel is supported.", samples),
UnsupportedColorType(color_type) => write!(fmt, "Color type {:?} is unsupported", color_type),
UnsupportedBitsPerChannel(bits) => write!(fmt, "{} bits per channel not supported", bits),
UnsupportedPlanarConfig(config) => write!(fmt, "Unsupported planar configuration “{:?}”.", config),
UnsupportedDataType => write!(fmt, "Unsupported data type."),
}
}
}
impl fmt::Display for TiffError {
fn fmt(&self, fmt: &mut fmt::Formatter) -> Result<(), fmt::Error> {
match *self {