Cargo Format

This commit is contained in:
2024-05-07 09:27:04 -05:00
parent 85ad2fa252
commit 62b35b5aba

View File

@@ -120,7 +120,7 @@ where
b: self.bytes.next()?, b: self.bytes.next()?,
a: self.prev_pixel.a, a: self.prev_pixel.a,
}); });
}else if byte == QOI_OP_RGBA { } else if byte == QOI_OP_RGBA {
return Some(PixelRGBA { return Some(PixelRGBA {
r: self.bytes.next()?, r: self.bytes.next()?,
g: self.bytes.next()?, g: self.bytes.next()?,
@@ -132,7 +132,7 @@ where
QOI_OP_INDEX => { QOI_OP_INDEX => {
let idx = (byte & !QOI_OP_SMALL_MASK) as usize; let idx = (byte & !QOI_OP_SMALL_MASK) as usize;
return Some(self.back_buffer[idx]); return Some(self.back_buffer[idx]);
}, }
QOI_OP_DIFF => { QOI_OP_DIFF => {
let dr = ((byte & 0b0011_0000) >> 4) - 2; let dr = ((byte & 0b0011_0000) >> 4) - 2;
let dg = ((byte & 0b0000_1100) >> 2) - 2; let dg = ((byte & 0b0000_1100) >> 2) - 2;
@@ -143,7 +143,7 @@ where
b: self.prev_pixel.b + db, b: self.prev_pixel.b + db,
a: self.prev_pixel.a, a: self.prev_pixel.a,
}); });
}, }
QOI_OP_LUMA => { QOI_OP_LUMA => {
let dg = (byte & !QOI_OP_SMALL_MASK) - 32; let dg = (byte & !QOI_OP_SMALL_MASK) - 32;
let packed = self.bytes.next()?; let packed = self.bytes.next()?;
@@ -157,7 +157,7 @@ where
b: self.prev_pixel.b + db, b: self.prev_pixel.b + db,
a: self.prev_pixel.a, a: self.prev_pixel.a,
}); });
}, }
QOI_OP_RUN => { QOI_OP_RUN => {
self.run_len = byte & !QOI_OP_SMALL_MASK; self.run_len = byte & !QOI_OP_SMALL_MASK;
// storage bias of -1, so a +1 should be on the end here. // storage bias of -1, so a +1 should be on the end here.
@@ -165,8 +165,8 @@ where
// and returning a PixelRGBA, so the count is also immediatly // and returning a PixelRGBA, so the count is also immediatly
// dropped by 1 // dropped by 1
return Some(self.prev_pixel); return Some(self.prev_pixel);
}, }
_ => panic!("bad op code{}", byte) _ => panic!("bad op code{}", byte),
} }
} }
} }
@@ -406,12 +406,15 @@ mod test {
fn decoder_unpack_luma_rollover() { fn decoder_unpack_luma_rollover() {
let init_pixel = PixelRGBA::new(255, 255, 255, 255); let init_pixel = PixelRGBA::new(255, 255, 255, 255);
let compressed = [ let compressed = [
(QOI_OP_LUMA | 0b0011_1111), (0b1111_1111), // Diff (31, 7, 7) -> Pix (38, 31, 38) (QOI_OP_LUMA | 0b0011_1111),
(0b1111_1111), // Diff (31, 7, 7) -> Pix (38, 31, 38)
]; ];
let expected = PixelRGBA::new(37, 30, 37, 255); let expected = PixelRGBA::new(37, 30, 37, 255);
let mut decoder = Decoder::new_with_previous_pixel(compressed.into_iter(), init_pixel); let mut decoder = Decoder::new_with_previous_pixel(compressed.into_iter(), init_pixel);
let result = decoder.next().expect("Oops, didn't get a Pixel back from the Decoder"); let result = decoder
.next()
.expect("Oops, didn't get a Pixel back from the Decoder");
assert_eq!(result, expected); assert_eq!(result, expected);
} }
@@ -419,12 +422,15 @@ mod test {
fn decoder_unpack_luma_rollunder() { fn decoder_unpack_luma_rollunder() {
let init_pixel = PixelRGBA::new(0, 0, 0, 255); let init_pixel = PixelRGBA::new(0, 0, 0, 255);
let compressed = [ let compressed = [
(QOI_OP_LUMA | 0b0001_0011), (0b1100_0011) // Diff(-13, 4, -5) -> Pix (-9, -13, -18) (QOI_OP_LUMA | 0b0001_0011),
(0b1100_0011), // Diff(-13, 4, -5) -> Pix (-9, -13, -18)
]; ];
let expected = PixelRGBA::new(247, 243, 238, 255); let expected = PixelRGBA::new(247, 243, 238, 255);
let mut decoder = Decoder::new_with_previous_pixel(compressed.into_iter(), init_pixel); let mut decoder = Decoder::new_with_previous_pixel(compressed.into_iter(), init_pixel);
let result = decoder.next().expect("Oops, didn't get a Pixel back from the Decoder"); let result = decoder
.next()
.expect("Oops, didn't get a Pixel back from the Decoder");
assert_eq!(result, expected); assert_eq!(result, expected);
} }