diff --git a/src/decoder/stream.rs b/src/decoder/stream.rs index 38b5efe..9c795f6 100644 --- a/src/decoder/stream.rs +++ b/src/decoder/stream.rs @@ -259,6 +259,7 @@ impl Read for PackBitsReader { pub struct Group4Reader { decoder: Group4Decoder>>, + bits: BitVec, byte_buf: VecDeque, height: u16, width: u16, @@ -278,6 +279,7 @@ impl Group4Reader { Ok(Self { decoder: Group4Decoder::new(reader.take(compressed_length).bytes(), width)?, + bits: BitVec::new(), byte_buf: VecDeque::new(), width: width, height: height, @@ -306,12 +308,12 @@ impl Read for Group4Reader { fax::Color::White => 0x00, })) } else { - let mut bits: BitVec = 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(); } } }