From c8d43262e9e65d76aaf5bcf80d964183903b5670 Mon Sep 17 00:00:00 2001 From: Stephen Judkins Date: Fri, 1 Nov 2024 15:06:18 -0700 Subject: [PATCH] Simplify decoder Reuse the allocation of bits for every row though --- src/decoder/stream.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/decoder/stream.rs b/src/decoder/stream.rs index fd5623f..4ecbd5e 100644 --- a/src/decoder/stream.rs +++ b/src/decoder/stream.rs @@ -310,11 +310,6 @@ impl Group4Reader { 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 Read for Group4Reader { .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(); } } }