Image is now mapped to a pixel-identical image
This commit is contained in:
@ -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);
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user