mod common;
use common::compare::load;
use heic_rs::{DecodeOptions, PixelLayout};
const CORPUS: [&str; 4] = [
"photo-2048.heic",
"checker-1024.heic",
"gradient-512.heic",
"flat-64.heic",
];
fn decode(name: &str, threads: Option<usize>, layout: PixelLayout) -> heic_rs::Image {
let options = DecodeOptions::default()
.with_layout(layout)
.with_threads(threads);
heic_rs::decode(&load(name), &options).unwrap_or_else(|e| panic!("{name} {threads:?}: {e}"))
}
#[test]
fn every_thread_count_produces_the_same_bytes() {
for name in CORPUS {
let serial = decode(name, Some(1), PixelLayout::Rgb8);
for threads in [Some(2), Some(3), Some(16), None] {
let other = decode(name, threads, PixelLayout::Rgb8);
assert_eq!(
(other.width, other.height),
(serial.width, serial.height),
"{name} at {threads:?}"
);
assert!(
other.data == serial.data,
"{name} at {threads:?} differs from the serial decode"
);
}
}
}
#[test]
fn every_layout_is_thread_independent_too() {
let name = "photo-2048.heic";
for layout in [
PixelLayout::Rgb8,
PixelLayout::Rgba8,
PixelLayout::Bgr8,
PixelLayout::Bgra8,
PixelLayout::Gray8,
PixelLayout::Rgb16,
PixelLayout::Rgba16,
] {
let serial = decode(name, Some(1), layout);
let pooled = decode(name, None, layout);
assert!(pooled.data == serial.data, "{layout:?} differs");
}
}
#[test]
fn zero_threads_means_this_thread() {
let name = "checker-1024.heic";
let serial = decode(name, Some(1), PixelLayout::Rgb8);
let zero = decode(name, Some(0), PixelLayout::Rgb8);
assert!(zero.data == serial.data);
}