Make those tests pass!
I want to refactor this at some point, but at least it passes the tests.
This commit is contained in:
19
src/main.rs
19
src/main.rs
@@ -116,30 +116,37 @@ where
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
if self.run_len > 0 {
|
||||
self.run_len -= 1;
|
||||
return Some(self.prev_pixel);
|
||||
Some(self.prev_pixel)
|
||||
} else {
|
||||
// Two kinds of patterns to match:
|
||||
// 1. Whole byte tag -- RGB and RGBA
|
||||
// 2. Partial byte tag -- 2 front bits of Index, Diff, Luma, and Run
|
||||
let byte = self.bytes.next()?;
|
||||
if byte == QOI_OP_RGB {
|
||||
return Some(PixelRGBA {
|
||||
let result = PixelRGBA {
|
||||
r: self.bytes.next()?,
|
||||
g: self.bytes.next()?,
|
||||
b: self.bytes.next()?,
|
||||
a: self.prev_pixel.a,
|
||||
});
|
||||
};
|
||||
self.prev_pixel = result;
|
||||
self.back_buffer[codec_utils::hash(result) as usize] = result;
|
||||
return Some(result);
|
||||
} else if byte == QOI_OP_RGBA {
|
||||
return Some(PixelRGBA {
|
||||
let result = PixelRGBA {
|
||||
r: self.bytes.next()?,
|
||||
g: self.bytes.next()?,
|
||||
b: self.bytes.next()?,
|
||||
a: self.bytes.next()?,
|
||||
});
|
||||
};
|
||||
self.prev_pixel = result;
|
||||
self.back_buffer[codec_utils::hash(result) as usize] = result;
|
||||
return Some(result);
|
||||
} else {
|
||||
match byte & QOI_OP_SMALL_MASK {
|
||||
QOI_OP_INDEX => {
|
||||
let idx = (byte & !QOI_OP_SMALL_MASK) as usize;
|
||||
self.prev_pixel = self.back_buffer[idx];
|
||||
return Some(self.back_buffer[idx]);
|
||||
}
|
||||
QOI_OP_DIFF => {
|
||||
@@ -153,6 +160,7 @@ where
|
||||
a: self.prev_pixel.a,
|
||||
};
|
||||
self.prev_pixel = result;
|
||||
self.back_buffer[codec_utils::hash(result) as usize] = result;
|
||||
return Some(result);
|
||||
}
|
||||
QOI_OP_LUMA => {
|
||||
@@ -169,6 +177,7 @@ where
|
||||
a: self.prev_pixel.a,
|
||||
};
|
||||
self.prev_pixel = result;
|
||||
self.back_buffer[codec_utils::hash(result) as usize] = result;
|
||||
return Some(result);
|
||||
}
|
||||
QOI_OP_RUN => {
|
||||
|
||||
Reference in New Issue
Block a user