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