Cargo format
No, car go road
This commit is contained in:
67
src/main.rs
67
src/main.rs
@@ -160,7 +160,10 @@ where
|
|||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
impl <I> Decoder <I> where I: Iterator<Item=u8> {
|
impl<I> Decoder<I>
|
||||||
|
where
|
||||||
|
I: Iterator<Item = u8>,
|
||||||
|
{
|
||||||
// A hack to unit test the index lookup behavior. A partial test can be done
|
// 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
|
// to verify the basic indexing principles by preloading a known buffer and
|
||||||
// then extracting back-referenced data out of it. A complete test should
|
// then extracting back-referenced data out of it. A complete test should
|
||||||
@@ -479,26 +482,38 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn decoder_prev_pixel_verify() {
|
fn decoder_prev_pixel_verify() {
|
||||||
let compressed = [
|
let compressed = [
|
||||||
QOI_OP_RGB, 0x10, 0x10, 0x10,
|
QOI_OP_RGB,
|
||||||
QOI_OP_RGBA, 0x20, 0x20, 0x20, 0x20,
|
0x10,
|
||||||
|
0x10,
|
||||||
|
0x10,
|
||||||
|
QOI_OP_RGBA,
|
||||||
|
0x20,
|
||||||
|
0x20,
|
||||||
|
0x20,
|
||||||
|
0x20,
|
||||||
(QOI_OP_INDEX | 1),
|
(QOI_OP_INDEX | 1),
|
||||||
(QOI_OP_DIFF | 0b0011_1111),
|
(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_RUN | 2),
|
||||||
QOI_OP_RGBA, 0xFF, 0xFF, 0xFF, 0xFF,
|
QOI_OP_RGBA,
|
||||||
|
0xFF,
|
||||||
|
0xFF,
|
||||||
|
0xFF,
|
||||||
|
0xFF,
|
||||||
];
|
];
|
||||||
|
|
||||||
let expected = [
|
let expected = [
|
||||||
PixelRGBA::new(0, 0, 0, 0xFF), // init
|
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(0x20, 0x20, 0x20, 0x20), // RGBA
|
||||||
PixelRGBA::new(0, 0, 0, 0), // INDEX -- this doubles as a small test for the backbuffer operation
|
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(0x1, 0x1, 0x1, 0x0), // DIFF
|
||||||
PixelRGBA::new(0x27, 0x20, 0x27, 0x0), // LUMA
|
PixelRGBA::new(0x27, 0x20, 0x27, 0x0), // LUMA
|
||||||
PixelRGBA::new(0x27, 0x20, 0x27, 0x0), // RUN 1
|
PixelRGBA::new(0x27, 0x20, 0x27, 0x0), // RUN 1
|
||||||
PixelRGBA::new(0x27, 0x20, 0x27, 0x0), // RUN 2
|
PixelRGBA::new(0x27, 0x20, 0x27, 0x0), // RUN 2
|
||||||
PixelRGBA::new(0x27, 0x20, 0x27, 0x0), // RUN 3
|
PixelRGBA::new(0x27, 0x20, 0x27, 0x0), // RUN 3
|
||||||
PixelRGBA::new(0xFF, 0xFF, 0xFF, 0xFF)
|
PixelRGBA::new(0xFF, 0xFF, 0xFF, 0xFF),
|
||||||
];
|
];
|
||||||
|
|
||||||
let mut decoder = Decoder::new(compressed.into_iter());
|
let mut decoder = Decoder::new(compressed.into_iter());
|
||||||
@@ -516,14 +531,30 @@ mod test {
|
|||||||
#[test]
|
#[test]
|
||||||
fn decoder_backbuffer_verify() {
|
fn decoder_backbuffer_verify() {
|
||||||
let compressed = [
|
let compressed = [
|
||||||
QOI_OP_RGB, 0x10, 0x10, 0x10,
|
QOI_OP_RGB,
|
||||||
QOI_OP_RGBA, 0x20, 0x20, 0x20, 0x20,
|
0x10,
|
||||||
QOI_OP_RGBA, 0x03, 0x01, 0x01, 0x04, // filler to populate backbuffer[1] for the next OP_INDEX
|
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_INDEX | 1),
|
||||||
(QOI_OP_DIFF | 0b0011_1111), // + Pix (1, 1, 1, 0)
|
(QOI_OP_DIFF | 0b0011_1111), // + Pix (1, 1, 1, 0)
|
||||||
(QOI_OP_LUMA | 0b0011_1111), 0b1111_1111, // + Pix (38, 31, 38)
|
(QOI_OP_LUMA | 0b0011_1111),
|
||||||
|
0b1111_1111, // + Pix (38, 31, 38)
|
||||||
(QOI_OP_RUN | 2),
|
(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.
|
// 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.
|
// Each pixel gets put into this backbuffer as it's en/de-coded.
|
||||||
|
|||||||
Reference in New Issue
Block a user