Skip to content
Snippets Groups Projects
Verified Commit 71b5d0d9 authored by João Magalhães's avatar João Magalhães :rocket:
Browse files

chore: comparison of instr_timing image

Also added support for image saving.
parent ca57680c
No related branches found
No related tags found
No related merge requests found
Pipeline #3005 passed
frontends/sdl/res/test/blargg/instr_timing/instr_timing.png

1.51 KiB

use image::io::Reader as ImageReader; use image::{io::Reader as ImageReader, ImageBuffer, Rgb};
pub fn compare_images(source_pixels: &[u8], target_path: &str) -> bool { pub fn compare_images(source_pixels: &[u8], target_path: &str) -> bool {
let image_buffer = ImageReader::open(target_path) let image_buffer = ImageReader::open(target_path)
...@@ -23,6 +23,19 @@ pub fn compare_images(source_pixels: &[u8], target_path: &str) -> bool { ...@@ -23,6 +23,19 @@ pub fn compare_images(source_pixels: &[u8], target_path: &str) -> bool {
true true
} }
pub fn save_image(pixels: &[u8], width: u32, height: u32, file_path: &str) {
let mut image_buffer: ImageBuffer<Rgb<u8>, Vec<u8>> = ImageBuffer::new(width, height);
for (x, y, pixel) in image_buffer.enumerate_pixels_mut() {
let base = ((y * width + x) * 3) as usize;
*pixel = Rgb([pixels[base], pixels[base + 1], pixels[base + 2]]);
}
image_buffer
.save_with_format(file_path, image::ImageFormat::Png)
.unwrap();
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use boytacean::{ use boytacean::{
...@@ -31,7 +44,7 @@ mod tests { ...@@ -31,7 +44,7 @@ mod tests {
test::{run_image_test, TestOptions}, test::{run_image_test, TestOptions},
}; };
use super::compare_images; use super::{compare_images, save_image};
#[test] #[test]
fn test_blargg_cpu_instrs() { fn test_blargg_cpu_instrs() {
...@@ -44,6 +57,18 @@ mod tests { ...@@ -44,6 +57,18 @@ mod tests {
assert_eq!(image_result, true); assert_eq!(image_result, true);
} }
#[test]
fn test_blargg_instr_timing() {
let result: [u8; FRAME_BUFFER_SIZE] = run_image_test(
"../../res/roms/test/blargg/instr_timing/instr_timing.gb",
Some(50000000),
TestOptions::default(),
);
compare_images(&result, "res/test/blargg/instr_timing/instr_timing.png");
let image_result = compare_images(&result, "res/test/blargg/instr_timing/instr_timing.png");
assert_eq!(image_result, true);
}
#[test] #[test]
fn test_dmg_acid2() { fn test_dmg_acid2() {
let result: [u8; FRAME_BUFFER_SIZE] = run_image_test( let result: [u8; FRAME_BUFFER_SIZE] = run_image_test(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment