Simplify decoder

Reuse the allocation of bits for every row though
This commit is contained in:
Stephen Judkins authored and Aurelia Molzer committed 2025-08-31 01:25:51 +02:00
1 parent 80ce77190e
commit c8d43262e9
1 file changed
+9 -13
+9 -13
View File
@@ -310,11 +310,6 @@ impl<R: Read> Group4Reader<R> {
y: 0,
})
}
pub fn dump_bits(&mut self) -> () {
self.byte_buf.extend(self.bits.as_raw_slice());
self.bits.clear()
}
}
#[cfg(feature = "fax")]
@@ -325,17 +320,18 @@ impl<R: Read> Read for Group4Reader<R> {
.decoder
.advance()
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
match next {
fax::decoder::DecodeStatus::End => self.dump_bits(),
fax::decoder::DecodeStatus::End => (),
fax::decoder::DecodeStatus::Incomplete => {
self.y += 1;
for c in fax::decoder::pels(self.decoder.transition(), self.width) {
self.bits.push(match c {
fax::Color::Black => true,
fax::Color::White => false,
});
}
self.dump_bits();
let transitions = fax::decoder::pels(self.decoder.transition(), self.width);
self.bits.extend(transitions.map(|c| match c {
fax::Color::Black => true,
fax::Color::White => false,
}));
self.byte_buf.extend(self.bits.as_raw_slice());
self.bits.clear();
}
}
}