Slide 19
Slide 19 text
#[no_mangle]
pub extern fn pixelmatch(img1: *mut u8, img2: *mut u8, width: u32,
height: u32, output: *mut u8) -> u32 {
let buf1: &mut [u8] =
unsafe { core::slice::from_raw_parts_mut(img1, (width * height * 4) as usize) };
let buf2: &mut [u8] =
unsafe { core::slice::from_raw_parts_mut(img2, (width * height * 4) as usize) };
let out: &mut [u8] =
unsafe { core::slice::from_raw_parts_mut(output, (width * height * 4) as usize) };
let max_delta = 35215.0 * 0.1 * 0.1;
let mut diff_count = 0;
for y in 0..height {
for x in 0..width {
let pos = ((y * width + x) * 4) as u32;
let delta = color_delta(buf1, buf2, pos, pos, false);
if delta > max_delta {
draw_pixel(out, pos, 255, 0, 0, 255);
diff_count += 1;
} else {
let y = gray_pixel(buf1, pos, 0.1);
draw_pixel(out, pos, y, y, y, 255);
}
}
}
diff_count
}
3VTU