Cargo format
No, car go road
This commit is contained in:
77
src/main.rs
77
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,21 +531,37 @@ 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.
|
||||||
// For RGB and RGBA, it'll simply assign a value into the index.
|
// 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
|
// 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
|
// *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
|
// hash to that location. The backbuffer initialization will cause this
|
||||||
// scenario.
|
// scenario.
|
||||||
@@ -549,7 +580,7 @@ mod test {
|
|||||||
1, // Pix (3, 1, 1, 4)
|
1, // Pix (3, 1, 1, 4)
|
||||||
16, // Pix (4, 2, 2, 4)
|
16, // Pix (4, 2, 2, 4)
|
||||||
39, // Pix (42, 33, 40, 4)
|
39, // Pix (42, 33, 40, 4)
|
||||||
39, // run x1
|
39, // run x1
|
||||||
39, // run x2
|
39, // run x2
|
||||||
39, // run x3
|
39, // run x3
|
||||||
38, // final RGBA
|
38, // final RGBA
|
||||||
@@ -562,7 +593,7 @@ mod test {
|
|||||||
|
|
||||||
// query it out:
|
// query it out:
|
||||||
let stored_px = decoder.peek_backbuffer(indices[iters]);
|
let stored_px = decoder.peek_backbuffer(indices[iters]);
|
||||||
|
|
||||||
// and compare it to the value returned from iteration
|
// and compare it to the value returned from iteration
|
||||||
assert_eq!(&pixel, stored_px);
|
assert_eq!(&pixel, stored_px);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user