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.
This commit is contained in:
11
src/main.rs
11
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::<PixelRGBA>::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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user