Drop bitvec dependency
This commit is contained in:
1 parent
c8d43262e9
commit
b5afb8cca4
2 files changed
+32
-18
No files matched your search
@@ -25,7 +25,6 @@ flate2 = { version = "1.0.20", optional = true }
|
|||||||
weezl = { version = "0.1.10", optional = true }
|
weezl = { version = "0.1.10", optional = true }
|
||||||
zstd = { version = "0.13", optional = true }
|
zstd = { version = "0.13", optional = true }
|
||||||
zune-jpeg = { version = "0.4.17", optional = true }
|
zune-jpeg = { version = "0.4.17", optional = true }
|
||||||
bitvec = "1.0.1"
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
criterion = "0.3.1"
|
criterion = "0.3.1"
|
||||||
|
|||||||
+32
-17
@@ -1,7 +1,4 @@
|
|||||||
//! All IO functionality needed for TIFF decoding
|
//! All IO functionality needed for TIFF decoding
|
||||||
|
|
||||||
#[cfg(feature = "fax")]
|
|
||||||
use std::collections::VecDeque;
|
|
||||||
use std::io::{self, BufRead, BufReader, Read, Seek, Take};
|
use std::io::{self, BufRead, BufReader, Read, Seek, Take};
|
||||||
|
|
||||||
/// Byte order of the TIFF file.
|
/// Byte order of the TIFF file.
|
||||||
@@ -281,8 +278,7 @@ impl<R: Read> Read for PackBitsReader<R> {
|
|||||||
#[cfg(feature = "fax")]
|
#[cfg(feature = "fax")]
|
||||||
pub struct Group4Reader<R: Read> {
|
pub struct Group4Reader<R: Read> {
|
||||||
decoder: fax::decoder::Group4Decoder<io::Bytes<io::Take<R>>>,
|
decoder: fax::decoder::Group4Decoder<io::Bytes<io::Take<R>>>,
|
||||||
bits: bitvec::vec::BitVec<u8, bitvec::prelude::Msb0>,
|
line_buf: io::Cursor<Vec<u8>>,
|
||||||
byte_buf: VecDeque<u8>,
|
|
||||||
height: u16,
|
height: u16,
|
||||||
width: u16,
|
width: u16,
|
||||||
y: u16,
|
y: u16,
|
||||||
@@ -303,8 +299,7 @@ impl<R: Read> Group4Reader<R> {
|
|||||||
reader.take(compressed_length).bytes(),
|
reader.take(compressed_length).bytes(),
|
||||||
width,
|
width,
|
||||||
)?,
|
)?,
|
||||||
bits: bitvec::vec::BitVec::new(),
|
line_buf: io::Cursor::new(Vec::with_capacity(width.into())),
|
||||||
byte_buf: VecDeque::new(),
|
|
||||||
width: width,
|
width: width,
|
||||||
height: height,
|
height: height,
|
||||||
y: 0,
|
y: 0,
|
||||||
@@ -315,27 +310,47 @@ impl<R: Read> Group4Reader<R> {
|
|||||||
#[cfg(feature = "fax")]
|
#[cfg(feature = "fax")]
|
||||||
impl<R: Read> Read for Group4Reader<R> {
|
impl<R: Read> Read for Group4Reader<R> {
|
||||||
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||||
if self.byte_buf.is_empty() && self.y < self.height {
|
// Either we have not read any line or we are at the end of a line.
|
||||||
let next = self
|
if self.line_buf.position() as usize == self.line_buf.get_ref().len()
|
||||||
.decoder
|
&& self.y < self.height
|
||||||
.advance()
|
{
|
||||||
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
|
let next = self.decoder.advance().map_err(std::io::Error::other)?;
|
||||||
|
|
||||||
match next {
|
match next {
|
||||||
fax::decoder::DecodeStatus::End => (),
|
fax::decoder::DecodeStatus::End => (),
|
||||||
fax::decoder::DecodeStatus::Incomplete => {
|
fax::decoder::DecodeStatus::Incomplete => {
|
||||||
self.y += 1;
|
self.y += 1;
|
||||||
|
|
||||||
|
// We known `transitions` yields exactly `self.width` items (per doc).
|
||||||
let transitions = fax::decoder::pels(self.decoder.transition(), self.width);
|
let transitions = fax::decoder::pels(self.decoder.transition(), self.width);
|
||||||
self.bits.extend(transitions.map(|c| match c {
|
|
||||||
|
let buffer = self.line_buf.get_mut();
|
||||||
|
buffer.resize(usize::from(self.width).div_ceil(8), 0u8);
|
||||||
|
|
||||||
|
let target = &mut buffer[..];
|
||||||
|
|
||||||
|
let mut bits = transitions.map(|c| match c {
|
||||||
fax::Color::Black => true,
|
fax::Color::Black => true,
|
||||||
fax::Color::White => false,
|
fax::Color::White => false,
|
||||||
}));
|
});
|
||||||
self.byte_buf.extend(self.bits.as_raw_slice());
|
|
||||||
self.bits.clear();
|
// Assemble bits in MSB as per our library representation for buffer.
|
||||||
|
for byte in target {
|
||||||
|
let mut val = 0;
|
||||||
|
|
||||||
|
for (idx, bit) in bits.by_ref().take(8).enumerate() {
|
||||||
|
val |= u8::from(bit) << (7 - idx % 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
*byte = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
self.line_buf.set_position(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.byte_buf.read(buf)
|
|
||||||
|
self.line_buf.read(buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user