From 69fad49286a6363d3f0193234d0a7b409f6a5968 Mon Sep 17 00:00:00 2001 From: Robert Garrett Date: Thu, 9 May 2024 14:26:08 -0500 Subject: [PATCH] Fix previous pixel test The previous pixel needs to be captured before the iterator is advanced. Otherwise it's just getting the same pixel back out, and all that's tested is the assignment operator. The expected alpha value for the first OP_RGBA was set wrong. The OP_LUMA was missing whole bits. SMH my head. After changing the prev-pixel check order, the final OP_RGBA *is* required. Include that in the expected output. --- src/main.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index e2e13e5..73644e7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -473,7 +473,7 @@ mod test { QOI_OP_RGBA, 0x20, 0x20, 0x20, 0x20, (QOI_OP_INDEX | 1), (QOI_OP_DIFF | 0b0011_1111), - (QOI_OP_LUMA | 0b0011_111), 0b0011_1111, + (QOI_OP_LUMA | 0b0011_1111), 0b1111_1111, (QOI_OP_RUN | 2), QOI_OP_RGBA, 0xFF, 0xFF, 0xFF, 0xFF, ]; @@ -481,23 +481,22 @@ mod test { let expected = [ PixelRGBA::new(0, 0, 0, 0xFF), // init PixelRGBA::new(0x10, 0x10, 0x10, 0xFF), // RGB - PixelRGBA::new(0x20, 0x20, 0x20, 0xFF), // RGBA + PixelRGBA::new(0x20, 0x20, 0x20, 0x20), // RGBA PixelRGBA::new(0, 0, 0, 0), // INDEX -- this doubles as a small test for the backbuffer operation PixelRGBA::new(0x1, 0x1, 0x1, 0x0), // DIFF PixelRGBA::new(0x27, 0x20, 0x27, 0x0), // LUMA PixelRGBA::new(0x27, 0x20, 0x27, 0x0), // RUN 1 PixelRGBA::new(0x27, 0x20, 0x27, 0x0), // RUN 2 PixelRGBA::new(0x27, 0x20, 0x27, 0x0), // RUN 3 - // final OP_RGBA is just to flush out the OP_RUN prev_pixel value + PixelRGBA::new(0xFF, 0xFF, 0xFF, 0xFF) ]; let mut decoder = Decoder::new(compressed.into_iter()); let mut result = Vec::::new(); loop { - if let Some(_) = decoder.next() { - result.push(*decoder.peek_prev_pixel()); - } else { + result.push(*decoder.peek_prev_pixel()); + if let None = decoder.next() { break; } }