Skip to content

Commit

Permalink
don't allocate for every row
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenjudkins committed Nov 1, 2024
1 parent ce025bc commit 5255371
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/decoder/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ impl<R: Read> Read for PackBitsReader<R> {

pub struct Group4Reader<R: Read> {
decoder: Group4Decoder<std::io::Bytes<std::io::Take<R>>>,
bits: BitVec<u8, Msb0>,
byte_buf: VecDeque<u8>,
height: u16,
width: u16,
Expand All @@ -278,6 +279,7 @@ impl<R: Read> Group4Reader<R> {

Ok(Self {
decoder: Group4Decoder::new(reader.take(compressed_length).bytes(), width)?,
bits: BitVec::new(),
byte_buf: VecDeque::new(),
width: width,
height: height,
Expand Down Expand Up @@ -306,12 +308,12 @@ impl<R: Read> Read for Group4Reader<R> {
fax::Color::White => 0x00,
}))
} else {
let mut bits: BitVec<u8, Msb0> = BitVec::new();
bits.extend(transitions.map(|c| match c {
self.bits.extend(transitions.map(|c| match c {
fax::Color::Black => true,
fax::Color::White => false,
}));
self.byte_buf.extend(bits.as_raw_slice());
self.byte_buf.extend(self.bits.as_raw_slice());
self.bits.clear();
}
}
}
Expand Down

0 comments on commit 5255371

Please sign in to comment.