Merge branch 'master' into inversion
This commit is contained in:
commit
65832e01bd
5 files changed
+15
-75
No files matched your search
+5
-13
@@ -1125,7 +1125,7 @@ impl<R: Read + Seek> Decoder<R> {
|
||||
|
||||
// Read into output buffer.
|
||||
{
|
||||
let buffer = match &mut buffer {
|
||||
let mut buffer = match &mut buffer {
|
||||
DecodingBuffer::U8(buf) => &mut *buf,
|
||||
DecodingBuffer::I8(buf) => bytecast::i8_as_ne_mut_bytes(buf),
|
||||
DecodingBuffer::U16(buf) => bytecast::u16_as_ne_mut_bytes(buf),
|
||||
@@ -1138,16 +1138,8 @@ impl<R: Read + Seek> Decoder<R> {
|
||||
DecodingBuffer::F64(buf) => bytecast::f64_as_ne_mut_bytes(buf),
|
||||
};
|
||||
|
||||
let mut bytes_written = 0;
|
||||
while bytes_written < buffer.len() {
|
||||
match reader.read(&mut buffer[bytes_written..]) {
|
||||
Ok(0) => break,
|
||||
Ok(n) => bytes_written += n,
|
||||
Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {}
|
||||
Err(e) => Err(e)?,
|
||||
}
|
||||
}
|
||||
for b in &mut buffer[bytes_written..] {
|
||||
std::io::copy(&mut reader.take(buffer.len() as u64), &mut buffer)?;
|
||||
for b in buffer {
|
||||
*b = 0;
|
||||
}
|
||||
}
|
||||
@@ -1252,8 +1244,8 @@ impl<R: Read + Seek> Decoder<R> {
|
||||
CompressionMethod::PackBits => {
|
||||
Box::new(PackBitsReader::new(reader, usize::try_from(compressed_length)?)?.1)
|
||||
}
|
||||
CompressionMethod::OldDeflate => {
|
||||
Box::new(DeflateReader::new(reader, samples * byte_len)?.1)
|
||||
CompressionMethod::Deflate | CompressionMethod::OldDeflate => {
|
||||
Box::new(DeflateReader::new(reader))
|
||||
}
|
||||
method => {
|
||||
return Err(TiffError::UnsupportedError(
|
||||
|
||||
+1
-38
@@ -1,7 +1,5 @@
|
||||
//! All IO functionality needed for TIFF decoding
|
||||
|
||||
use crate::error::{TiffError, TiffResult};
|
||||
use miniz_oxide::inflate;
|
||||
use std::io::{self, Read, Seek};
|
||||
|
||||
/// Byte order of the TIFF file.
|
||||
@@ -126,42 +124,7 @@ pub trait EndianReader: Read {
|
||||
/// ## Deflate Reader
|
||||
///
|
||||
|
||||
/// Reader that decompresses DEFLATE streams
|
||||
pub struct DeflateReader {
|
||||
buffer: io::Cursor<Vec<u8>>,
|
||||
}
|
||||
|
||||
impl DeflateReader {
|
||||
pub fn new<R: Read + Seek>(
|
||||
reader: &mut SmartReader<R>,
|
||||
max_uncompressed_length: usize,
|
||||
) -> TiffResult<(usize, Self)> {
|
||||
let mut compressed = Vec::new();
|
||||
reader.read_to_end(&mut compressed)?;
|
||||
|
||||
// TODO: Implement streaming compression, and remove this (temporary) and somewhat
|
||||
// misleading workaround.
|
||||
if compressed.len() > max_uncompressed_length {
|
||||
return Err(TiffError::LimitsExceeded);
|
||||
}
|
||||
|
||||
let uncompressed =
|
||||
inflate::decompress_to_vec_zlib(&compressed).map_err(TiffError::from_inflate_status)?;
|
||||
|
||||
Ok((
|
||||
uncompressed.len(),
|
||||
Self {
|
||||
buffer: io::Cursor::new(uncompressed),
|
||||
},
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl Read for DeflateReader {
|
||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
self.buffer.read(buf)
|
||||
}
|
||||
}
|
||||
pub type DeflateReader<'r, R> = flate2::read::ZlibDecoder<&'r mut SmartReader<R>>;
|
||||
|
||||
///
|
||||
/// ## LZW Reader
|
||||
|
||||
+4
-16
@@ -9,7 +9,6 @@ use crate::tags::{
|
||||
CompressionMethod, PhotometricInterpretation, PlanarConfiguration, SampleFormat, Tag,
|
||||
};
|
||||
use crate::ColorType;
|
||||
use miniz_oxide::inflate::TINFLStatus;
|
||||
|
||||
/// Tiff error kinds.
|
||||
#[derive(Debug)]
|
||||
@@ -62,6 +61,7 @@ pub enum TiffFormatError {
|
||||
ByteExpected(Value),
|
||||
UnsignedIntegerExpected(Value),
|
||||
SignedIntegerExpected(Value),
|
||||
#[allow(deprecated)]
|
||||
InflateError(InflateError),
|
||||
Format(String),
|
||||
RequiredTagEmpty(Tag),
|
||||
@@ -123,21 +123,9 @@ impl fmt::Display for TiffFormatError {
|
||||
|
||||
/// Decompression failed due to faulty compressed data.
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
pub struct InflateError {
|
||||
status: TINFLStatus,
|
||||
}
|
||||
|
||||
impl InflateError {
|
||||
pub(crate) fn new(status: TINFLStatus) -> Self {
|
||||
Self { status }
|
||||
}
|
||||
}
|
||||
|
||||
impl TiffError {
|
||||
pub(crate) fn from_inflate_status(status: TINFLStatus) -> Self {
|
||||
TiffError::FormatError(TiffFormatError::InflateError(InflateError::new(status)))
|
||||
}
|
||||
}
|
||||
#[allow(deprecated)]
|
||||
#[deprecated = "This type is not used anymore: deflate errors are now propagated as regular `io::Error`s"]
|
||||
pub struct InflateError(());
|
||||
|
||||
/// The Decoder does not support features required by the image.
|
||||
///
|
||||
|
||||
+4
-4
@@ -7,7 +7,6 @@
|
||||
//! * <https://www.adobe.io/open/standards/TIFF.html> - The TIFF specification
|
||||
|
||||
extern crate jpeg;
|
||||
extern crate miniz_oxide;
|
||||
extern crate weezl;
|
||||
|
||||
mod bytecast;
|
||||
@@ -16,9 +15,10 @@ pub mod encoder;
|
||||
mod error;
|
||||
pub mod tags;
|
||||
|
||||
pub use self::error::{
|
||||
InflateError, TiffError, TiffFormatError, TiffResult, TiffUnsupportedError, UsageError,
|
||||
};
|
||||
pub use self::error::{TiffError, TiffFormatError, TiffResult, TiffUnsupportedError, UsageError};
|
||||
|
||||
#[allow(deprecated)]
|
||||
pub use self::error::InflateError;
|
||||
|
||||
/// An enumeration over supported color types and their bit depths
|
||||
#[derive(Copy, PartialEq, Eq, Debug, Clone, Hash)]
|
||||
|
||||
Reference in new issue
Block a user