Replace lzw decoder with weezl
This commit is contained in:
1 parent
e48691ca32
commit
49b1f78ce5
3 files changed
+22
-7
No files matched your search
+2
-1
@@ -17,7 +17,8 @@ repository = "https://github.com/image-rs/image-tiff"
|
|||||||
exclude = ["tests/images/*", "tests/fuzz_images/*"]
|
exclude = ["tests/images/*", "tests/fuzz_images/*"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lzw = "0.10"
|
weezl = "0.1.0"
|
||||||
|
|
||||||
[dependencies.miniz_oxide]
|
[dependencies.miniz_oxide]
|
||||||
version = "0.4.1"
|
version = "0.4.1"
|
||||||
features = ["no_extern_crate_alloc"]
|
features = ["no_extern_crate_alloc"]
|
||||||
|
|||||||
+19
-5
@@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use crate::bytecast;
|
use crate::bytecast;
|
||||||
use crate::error::{TiffError, TiffResult};
|
use crate::error::{TiffError, TiffResult};
|
||||||
use lzw;
|
|
||||||
use miniz_oxide::inflate;
|
use miniz_oxide::inflate;
|
||||||
use std::io::{self, Read, Seek};
|
use std::io::{self, Read, Seek};
|
||||||
|
|
||||||
@@ -244,12 +243,27 @@ impl LZWReader {
|
|||||||
let mut compressed = vec![0; compressed_length as usize];
|
let mut compressed = vec![0; compressed_length as usize];
|
||||||
reader.read_exact(&mut compressed[..])?;
|
reader.read_exact(&mut compressed[..])?;
|
||||||
let mut uncompressed = Vec::with_capacity(max_uncompressed_length);
|
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;
|
let mut bytes_read = 0;
|
||||||
while bytes_read < compressed_length && uncompressed.len() < max_uncompressed_length {
|
while bytes_read < compressed_length && uncompressed.len() < max_uncompressed_length {
|
||||||
let (len, bytes) = decoder.decode_bytes(&compressed[bytes_read..])?;
|
let bytes_written = uncompressed.len();
|
||||||
bytes_read += len;
|
uncompressed.reserve(1 << 12);
|
||||||
uncompressed.extend_from_slice(bytes);
|
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();
|
let bytes = uncompressed.len();
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
//! # Related Links
|
//! # Related Links
|
||||||
//! * <https://www.adobe.io/open/standards/TIFF.html> - The TIFF specification
|
//! * <https://www.adobe.io/open/standards/TIFF.html> - The TIFF specification
|
||||||
|
|
||||||
extern crate lzw;
|
extern crate weezl;
|
||||||
extern crate miniz_oxide;
|
extern crate miniz_oxide;
|
||||||
|
|
||||||
mod bytecast;
|
mod bytecast;
|
||||||
|
|||||||
Reference in new issue
Block a user