Removed unwrap and set colour transform with Jpeg compressed tiffs

This commit is contained in:
Alan Race committed 2022-11-22 14:31:33 +01:00
1 parent 9333d99c92
commit 7307e96782
3 files changed
+62 -71

No files matched your search

+27
View File
@@ -4,6 +4,8 @@ use std::io;
use std::str;
use std::string;
use jpeg::UnsupportedFeature;
use crate::decoder::{ifd::Value, ChunkType};
use crate::tags::{
CompressionMethod, PhotometricInterpretation, PlanarConfiguration, SampleFormat, Tag,
@@ -146,6 +148,10 @@ pub enum TiffUnsupportedError {
UnsupportedBitsPerChannel(u8),
UnsupportedPlanarConfig(Option<PlanarConfiguration>),
UnsupportedDataType,
UnsupportedJpegFeature(UnsupportedFeature),
#[doc(hidden)]
/// Do not match against this variant. It may get removed.
__NonExhaustive,
}
impl fmt::Display for TiffUnsupportedError {
@@ -191,6 +197,10 @@ impl fmt::Display for TiffUnsupportedError {
write!(fmt, "Unsupported planar configuration “{:?}”.", config)
}
UnsupportedDataType => write!(fmt, "Unsupported data type."),
UnsupportedJpegFeature(ref unsupported_feature) => {
write!(fmt, "Unsupported JPEG feature {:?}", unsupported_feature)
}
__NonExhaustive => unreachable!(),
}
}
}
@@ -310,5 +320,22 @@ impl From<LzwError> for TiffError {
}
}
impl From<jpeg::Error> for TiffError {
fn from(error: jpeg::Error) -> Self {
match error {
jpeg::Error::Format(format) => {
TiffError::FormatError(TiffFormatError::Format(format!("JPEG format: {}", format)))
}
jpeg::Error::Unsupported(unsupported) => TiffError::UnsupportedError(
TiffUnsupportedError::UnsupportedJpegFeature(unsupported),
),
jpeg::Error::Io(io_error) => TiffError::IoError(io_error),
jpeg::Error::Internal(internal) => {
panic!("According to jpeg create, this is not used, so this shouldn't be reached..")
}
}
}
}
/// Result of an image decoding/encoding process
pub type TiffResult<T> = Result<T, TiffError>;