diff --git a/src/main.rs b/src/main.rs index 9b241ba..34d4f30 100644 --- a/src/main.rs +++ b/src/main.rs @@ -160,7 +160,10 @@ where #[cfg(test)] mod test { use super::*; - impl Decoder where I: Iterator { + impl Decoder + where + I: Iterator, + { // A hack to unit test the index lookup behavior. A partial test can be done // to verify the basic indexing principles by preloading a known buffer and // then extracting back-referenced data out of it. A complete test should @@ -479,26 +482,38 @@ mod test { #[test] fn decoder_prev_pixel_verify() { let compressed = [ - QOI_OP_RGB, 0x10, 0x10, 0x10, - QOI_OP_RGBA, 0x20, 0x20, 0x20, 0x20, + QOI_OP_RGB, + 0x10, + 0x10, + 0x10, + QOI_OP_RGBA, + 0x20, + 0x20, + 0x20, + 0x20, (QOI_OP_INDEX | 1), (QOI_OP_DIFF | 0b0011_1111), - (QOI_OP_LUMA | 0b0011_1111), 0b1111_1111, + (QOI_OP_LUMA | 0b0011_1111), + 0b1111_1111, (QOI_OP_RUN | 2), - QOI_OP_RGBA, 0xFF, 0xFF, 0xFF, 0xFF, + QOI_OP_RGBA, + 0xFF, + 0xFF, + 0xFF, + 0xFF, ]; let expected = [ PixelRGBA::new(0, 0, 0, 0xFF), // init - PixelRGBA::new(0x10, 0x10, 0x10, 0xFF), // RGB + PixelRGBA::new(0x10, 0x10, 0x10, 0xFF), // RGB 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 - PixelRGBA::new(0xFF, 0xFF, 0xFF, 0xFF) + 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 + PixelRGBA::new(0xFF, 0xFF, 0xFF, 0xFF), ]; let mut decoder = Decoder::new(compressed.into_iter()); @@ -516,21 +531,37 @@ mod test { #[test] fn decoder_backbuffer_verify() { let compressed = [ - QOI_OP_RGB, 0x10, 0x10, 0x10, - QOI_OP_RGBA, 0x20, 0x20, 0x20, 0x20, - QOI_OP_RGBA, 0x03, 0x01, 0x01, 0x04, // filler to populate backbuffer[1] for the next OP_INDEX + QOI_OP_RGB, + 0x10, + 0x10, + 0x10, + QOI_OP_RGBA, + 0x20, + 0x20, + 0x20, + 0x20, + QOI_OP_RGBA, + 0x03, + 0x01, + 0x01, + 0x04, // filler to populate backbuffer[1] for the next OP_INDEX (QOI_OP_INDEX | 1), - (QOI_OP_DIFF | 0b0011_1111), // + Pix (1, 1, 1, 0) - (QOI_OP_LUMA | 0b0011_1111), 0b1111_1111, // + Pix (38, 31, 38) + (QOI_OP_DIFF | 0b0011_1111), // + Pix (1, 1, 1, 0) + (QOI_OP_LUMA | 0b0011_1111), + 0b1111_1111, // + Pix (38, 31, 38) (QOI_OP_RUN | 2), - QOI_OP_RGBA, 0xFF, 0xFF, 0xFF, 0xFF, + QOI_OP_RGBA, + 0xFF, + 0xFF, + 0xFF, + 0xFF, ]; // these are the indices where we're expecting each pixel to land. // Each pixel gets put into this backbuffer as it's en/de-coded. // For RGB and RGBA, it'll simply assign a value into the index. - + // For INDEX, the write can be skipped, and the expected index will be - // the same as the one in the op code. + // the same as the one in the op code. // *however* it's possible for an index to refer to a value that shouldn't // hash to that location. The backbuffer initialization will cause this // scenario. @@ -549,7 +580,7 @@ mod test { 1, // Pix (3, 1, 1, 4) 16, // Pix (4, 2, 2, 4) 39, // Pix (42, 33, 40, 4) - 39, // run x1 + 39, // run x1 39, // run x2 39, // run x3 38, // final RGBA @@ -562,7 +593,7 @@ mod test { // query it out: let stored_px = decoder.peek_backbuffer(indices[iters]); - + // and compare it to the value returned from iteration assert_eq!(&pixel, stored_px); } else {