Image is now mapped to a pixel-identical image

This commit is contained in:
2024-04-07 15:49:37 -07:00
parent d04ec371d9
commit 5c70367116
4 changed files with 147 additions and 2 deletions

View File

@ -70,7 +70,7 @@ fn save_image(width: usize, height: usize, image: Vec<Vec<u8>>) {
assert_eq!(image.len(), 3);
let mut encoder = png::Encoder::new(
File::create("outputs/avatar2.png").unwrap(),
File::create("outputs/avatar2_out.png").unwrap(),
width as u32, height as u32,
);
encoder.set_color(ColorType::Rgb);

View File

@ -37,4 +37,35 @@ fn transform(data: &mut [i32], zero: usize, stride: usize, divisor: i32) {
for i in 0..TILE_SZ {
data[ix(GRAY[i])] = row[i] / divisor;
}
}
}
#[cfg(test)]
mod tests {
use quickcheck::{quickcheck, Arbitrary};
use crate::{constants::TILE_SZ, transform::{decode, encode}};
#[derive(Clone, Debug)]
struct Encodable { args: [i32; TILE_SZ] }
impl Arbitrary for Encodable {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
let mut args = [0; TILE_SZ];
for i in 0..TILE_SZ {
args[i] = i16::arbitrary(g) as i32;
}
return Encodable { args };
}
}
quickcheck! {
fn reversible(xs: Encodable) -> bool {
let orig = xs.args;
let mut enc = orig.clone();
encode(&mut enc, 0, 1);
let mut dec = enc.clone();
decode(&mut dec, 0, 1);
orig == dec
}
}
}