Replace lzw decoder with weezl

This commit is contained in:
Andreas Molzer committed 2020-09-05 21:57:51 +02:00
1 parent e48691ca32
commit 49b1f78ce5
3 files changed
+22 -7

No files matched your search

+2 -1
View File
@@ -17,7 +17,8 @@ repository = "https://github.com/image-rs/image-tiff"
exclude = ["tests/images/*", "tests/fuzz_images/*"]
[dependencies]
lzw = "0.10"
weezl = "0.1.0"
[dependencies.miniz_oxide]
version = "0.4.1"
features = ["no_extern_crate_alloc"]
+19 -5
View File
@@ -2,7 +2,6 @@
use crate::bytecast;
use crate::error::{TiffError, TiffResult};
use lzw;
use miniz_oxide::inflate;
use std::io::{self, Read, Seek};
@@ -244,12 +243,27 @@ impl LZWReader {
let mut compressed = vec![0; compressed_length as usize];
reader.read_exact(&mut compressed[..])?;
let mut uncompressed = Vec::with_capacity(max_uncompressed_length);
let mut decoder = lzw::DecoderEarlyChange::new(lzw::MsbReader::new(), 8);
let mut decoder = weezl::decode::Decoder::with_tiff_size_switch(weezl::BitOrder::Msb, 8);
let mut bytes_read = 0;
while bytes_read < compressed_length && uncompressed.len() < max_uncompressed_length {
let (len, bytes) = decoder.decode_bytes(&compressed[bytes_read..])?;
bytes_read += len;
uncompressed.extend_from_slice(bytes);
let bytes_written = uncompressed.len();
uncompressed.reserve(1 << 12);
let buffer_space = uncompressed.capacity();
uncompressed.resize(buffer_space, 0u8);
let result = decoder.decode_bytes(&compressed[bytes_read..], &mut uncompressed[bytes_written..]);
bytes_read += result.consumed_in;
uncompressed.truncate(bytes_written + result.consumed_out);
match result.status {
Ok(weezl::LzwStatus::Ok) => {},
Ok(weezl::LzwStatus::Done) => break,
Ok(weezl::LzwStatus::NoProgress) => return Err(io::Error::new(
io::ErrorKind::UnexpectedEof,
"no lzw end code found",
)),
Err(err) => return Err(io::Error::new(io::ErrorKind::InvalidData, err)),
}
}
let bytes = uncompressed.len();
+1 -1
View File
@@ -6,7 +6,7 @@
//! # Related Links
//! * <https://www.adobe.io/open/standards/TIFF.html> - The TIFF specification
extern crate lzw;
extern crate weezl;
extern crate miniz_oxide;
mod bytecast;