From f4eef2f8635e1b6c301d1090d7d0a090ed44f7e2 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Mon, 14 Oct 2024 15:45:44 -0500 Subject: [PATCH] Relocate the old Decoder::new method to mod test The old `Decoder::new()` method would not pull the image header out of the iterator. This was fine for the design then, but I've just decided that I want to collect this info and store it in the Decoder struct. I've moved the old method down into the test module so that I can still use it to test the decoder parts alone. Same philosophy as the `new_with_previous_pixel()` and `new_with_backbuffer()` methods. --- src/decoder.rs | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/decoder.rs b/src/decoder.rs index 26fdc30..fea0900 100644 --- a/src/decoder.rs +++ b/src/decoder.rs @@ -89,20 +89,6 @@ where run_len: 0, }) } - - fn new(bytes: I) -> Self { - Self { - back_buffer: [PixelRGBA::zero(); 64], - prev_pixel: PixelRGBA { - r: 0, - g: 0, - b: 0, - a: 255, - }, - bytes, - run_len: 0, - } - } } impl<'input, I> Iterator for Decoder @@ -230,6 +216,23 @@ mod test { } } + // The decoder includes image metadata, now, and construction attempts + // to extract it from the input iterator. For the decoder tests, this + // needs to be skipped. Thus, we get *another* magic constructor + // available only to the test module. + fn new_with_no_metadata(bytes: I) -> Self { + Self { + width: 0, + height: 0, + channels: 4, + colorspace: 0, + back_buffer: [PixelRGBA::zero(); 64], + prev_pixel: PixelRGBA { r: 0, g: 0, b: 0, a: 255 }, + bytes, + run_len: 0, + } + } + fn peek_prev_pixel(&self) -> &PixelRGBA { &self.prev_pixel }