You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
2.3 KiB
59 lines
2.3 KiB
1 year ago
|
From 1269c1210c88a5adfcc8104b5d41e6706d06607b Mon Sep 17 00:00:00 2001
|
||
|
From: Jonathan Behrens <fintelia@gmail.com>
|
||
|
Date: Sat, 13 Jan 2024 19:52:12 -0500
|
||
|
Subject: [PATCH] Fix reference tests on big endian (#2099)
|
||
|
|
||
|
---
|
||
|
tests/reference_images.rs | 28 +++++++++++++++++++++++++---
|
||
|
1 file changed, 25 insertions(+), 3 deletions(-)
|
||
|
|
||
|
diff --git a/tests/reference_images.rs b/tests/reference_images.rs
|
||
|
index d07423f23f..015d6a6e09 100644
|
||
|
--- a/tests/reference_images.rs
|
||
|
+++ b/tests/reference_images.rs
|
||
|
@@ -1,4 +1,5 @@
|
||
|
//! Compares the decoding results with reference renderings.
|
||
|
+use std::convert::TryInto;
|
||
|
use std::fs;
|
||
|
use std::io;
|
||
|
use std::path::PathBuf;
|
||
|
@@ -270,14 +271,35 @@ fn check_references() {
|
||
|
|
||
|
let test_crc_actual = {
|
||
|
let mut hasher = Crc32::new();
|
||
|
- hasher.update(test_img.as_bytes());
|
||
|
+ match test_img {
|
||
|
+ DynamicImage::ImageLuma8(_)
|
||
|
+ | DynamicImage::ImageLumaA8(_)
|
||
|
+ | DynamicImage::ImageRgb8(_)
|
||
|
+ | DynamicImage::ImageRgba8(_) => hasher.update(test_img.as_bytes()),
|
||
|
+ DynamicImage::ImageLuma16(_)
|
||
|
+ | DynamicImage::ImageLumaA16(_)
|
||
|
+ | DynamicImage::ImageRgb16(_)
|
||
|
+ | DynamicImage::ImageRgba16(_) => {
|
||
|
+ for v in test_img.as_bytes().chunks(2) {
|
||
|
+ hasher.update(&u16::from_ne_bytes(v.try_into().unwrap()).to_le_bytes());
|
||
|
+ }
|
||
|
+ }
|
||
|
+ DynamicImage::ImageRgb32F(_) | DynamicImage::ImageRgba32F(_) => {
|
||
|
+ for v in test_img.as_bytes().chunks(4) {
|
||
|
+ hasher.update(&f32::from_ne_bytes(v.try_into().unwrap()).to_le_bytes());
|
||
|
+ }
|
||
|
+ }
|
||
|
+ _ => panic!("Unsupported image format"),
|
||
|
+ }
|
||
|
hasher.finalize()
|
||
|
};
|
||
|
|
||
|
if test_crc_actual != case.crc {
|
||
|
panic!(
|
||
|
- "The decoded image's hash does not match (expected = {:08x}, actual = {:08x}).",
|
||
|
- case.crc, test_crc_actual
|
||
|
+ "{}: The decoded image's hash does not match (expected = {:08x}, actual = {:08x}).",
|
||
|
+ img_path.display(),
|
||
|
+ case.crc,
|
||
|
+ test_crc_actual
|
||
|
);
|
||
|
}
|
||
|
|