Skip to content

Commit cf0a595

Browse files
stephenjudkins197g
authored andcommitted
Simplify decoder
Reuse the allocation of bits for every row though
1 parent 9b709b6 commit cf0a595

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

src/decoder/stream.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -310,11 +310,6 @@ impl<R: Read> Group4Reader<R> {
310310
y: 0,
311311
})
312312
}
313-
314-
pub fn dump_bits(&mut self) -> () {
315-
self.byte_buf.extend(self.bits.as_raw_slice());
316-
self.bits.clear()
317-
}
318313
}
319314

320315
#[cfg(feature = "fax")]
@@ -325,17 +320,18 @@ impl<R: Read> Read for Group4Reader<R> {
325320
.decoder
326321
.advance()
327322
.map_err(|e| std::io::Error::new(std::io::ErrorKind::Other, e))?;
323+
328324
match next {
329-
fax::decoder::DecodeStatus::End => self.dump_bits(),
325+
fax::decoder::DecodeStatus::End => (),
330326
fax::decoder::DecodeStatus::Incomplete => {
331327
self.y += 1;
332-
for c in fax::decoder::pels(self.decoder.transition(), self.width) {
333-
self.bits.push(match c {
334-
fax::Color::Black => true,
335-
fax::Color::White => false,
336-
});
337-
}
338-
self.dump_bits();
328+
let transitions = fax::decoder::pels(self.decoder.transition(), self.width);
329+
self.bits.extend(transitions.map(|c| match c {
330+
fax::Color::Black => true,
331+
fax::Color::White => false,
332+
}));
333+
self.byte_buf.extend(self.bits.as_raw_slice());
334+
self.bits.clear();
339335
}
340336
}
341337
}

0 commit comments

Comments
 (0)