|
@@ -1,12 +1,12 @@
|
|
|
+use crate::bitmap::{BitmapAccess, BitmapMutAccess};
|
|
|
use crate::formats::{self, PixelFormatSpec};
|
|
|
-use crate::bitmap::{BitmapAccess,BitmapMutAccess};
|
|
|
|
|
|
use super::copy_from::CopyFromOp;
|
|
|
use super::fill::FillOp;
|
|
|
use super::fill_region::FillRegionOp;
|
|
|
use super::fill_region_masked::FillRegionMaskedOp;
|
|
|
-use super::{GenericUnary,GenericBinary,UnaryOpSpec,BinaryOpSpec};
|
|
|
-use super::generate::{UnaryInputSpec,BinaryInputSpec,ValueGeneratorList, self};
|
|
|
+use super::generate::{self, BinaryInputSpec, UnaryInputSpec, ValueGeneratorList};
|
|
|
+use super::{BinaryOpSpec, GenericBinary, GenericUnary, UnaryOpSpec};
|
|
|
|
|
|
fn test_unary_format<UIS: UnaryInputSpec, Format: PixelFormatSpec>(n: usize) {
|
|
|
let gen = UIS::gen();
|
|
@@ -15,22 +15,27 @@ fn test_unary_format<UIS: UnaryInputSpec, Format: PixelFormatSpec>(n: usize) {
|
|
|
let op = UIS::build();
|
|
|
if op.is_generic::<Format>() {
|
|
|
// println!("Skipping generic implementation {}", Format::NAME);
|
|
|
- return
|
|
|
+ return;
|
|
|
} else {
|
|
|
println!("Testing specific implementation {}", Format::NAME);
|
|
|
}
|
|
|
|
|
|
for _ in 0..n {
|
|
|
- let mut specific_img = generate::dst_image_generator::<Format>(&mut ctx).expect("could not generate image");
|
|
|
- let params = gen.generate(&mut ctx).expect("could not generate parameters");
|
|
|
+ let mut specific_img =
|
|
|
+ generate::dst_image_generator::<Format>(&mut ctx).expect("could not generate image");
|
|
|
+ let params = gen
|
|
|
+ .generate(&mut ctx)
|
|
|
+ .expect("could not generate parameters");
|
|
|
let mut generic_img = specific_img.clone();
|
|
|
|
|
|
op.select::<Format>()(specific_img.data_mut(), ¶ms);
|
|
|
- <UIS as GenericUnary<UIS::Params::<'static>>>::perform::<Format>(generic_img.data_mut(), ¶ms);
|
|
|
+ <UIS as GenericUnary<UIS::Params<'static>>>::perform::<Format>(
|
|
|
+ generic_img.data_mut(),
|
|
|
+ ¶ms,
|
|
|
+ );
|
|
|
|
|
|
assert_eq!(specific_img, generic_img);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
fn test_unary<UIS: UnaryInputSpec>(n: usize) {
|
|
@@ -43,58 +48,92 @@ fn test_unary<UIS: UnaryInputSpec>(n: usize) {
|
|
|
test_unary_format::<UIS, formats::Rgba32>(n);
|
|
|
}
|
|
|
|
|
|
-fn test_binary_format<BIS: BinaryInputSpec, DstFormat: PixelFormatSpec, SrcFormat: PixelFormatSpec>(n: usize) {
|
|
|
+fn test_binary_format<
|
|
|
+ BIS: BinaryInputSpec,
|
|
|
+ DstFormat: PixelFormatSpec,
|
|
|
+ SrcFormat: PixelFormatSpec,
|
|
|
+>(
|
|
|
+ n: usize,
|
|
|
+) {
|
|
|
let gen = BIS::gen();
|
|
|
let mut ctx = generate::Context::default();
|
|
|
|
|
|
let op = BIS::build();
|
|
|
if op.is_generic::<DstFormat, SrcFormat>() {
|
|
|
- println!("Skipping generic implementation ({},{})", DstFormat::NAME, SrcFormat::NAME);
|
|
|
- return
|
|
|
+ println!(
|
|
|
+ "Skipping generic implementation ({},{})",
|
|
|
+ DstFormat::NAME,
|
|
|
+ SrcFormat::NAME
|
|
|
+ );
|
|
|
+ return;
|
|
|
} else {
|
|
|
- println!("Testing specific implementation ({},{})", DstFormat::NAME, SrcFormat::NAME);
|
|
|
+ println!(
|
|
|
+ "Testing specific implementation ({},{})",
|
|
|
+ DstFormat::NAME,
|
|
|
+ SrcFormat::NAME
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
for _ in 0..n {
|
|
|
- let dst_img = generate::dst_image_generator::<DstFormat>(&mut ctx).expect("could not generate image");
|
|
|
- let src_img = generate::src_image_generator::<SrcFormat>(&mut ctx).expect("could not generate image");
|
|
|
+ let dst_img =
|
|
|
+ generate::dst_image_generator::<DstFormat>(&mut ctx).expect("could not generate image");
|
|
|
+ let src_img =
|
|
|
+ generate::src_image_generator::<SrcFormat>(&mut ctx).expect("could not generate image");
|
|
|
let mut specific_dst_img = dst_img.clone();
|
|
|
let mut generic_dst_img = dst_img.clone();
|
|
|
|
|
|
- let params = gen.generate(&mut ctx).expect("could not generate parameters");
|
|
|
+ let params = gen
|
|
|
+ .generate(&mut ctx)
|
|
|
+ .expect("could not generate parameters");
|
|
|
|
|
|
op.select::<DstFormat, SrcFormat>()(specific_dst_img.data_mut(), src_img.data(), ¶ms);
|
|
|
- <BIS as GenericBinary<BIS::Params::<'static>>>::perform::<DstFormat, SrcFormat>(generic_dst_img.data_mut(), src_img.data(), ¶ms);
|
|
|
+ <BIS as GenericBinary<BIS::Params<'static>>>::perform::<DstFormat, SrcFormat>(
|
|
|
+ generic_dst_img.data_mut(),
|
|
|
+ src_img.data(),
|
|
|
+ ¶ms,
|
|
|
+ );
|
|
|
|
|
|
if specific_dst_img != generic_dst_img {
|
|
|
let mut path = std::path::PathBuf::new();
|
|
|
path.push(env!("CARGO_MANIFEST_DIR"));
|
|
|
path.push("test_failure");
|
|
|
println!("path: {:?}", path.as_path().to_str());
|
|
|
- std::fs::write(path, format!(
|
|
|
- concat!(
|
|
|
- "dst: {dst_img:?}\n",
|
|
|
- "src: {src_img:?}\n",
|
|
|
- "dst data: ({dst_fmt}) {dst_data}\n",
|
|
|
- "src data: ({src_fmt}) {src_data}\n",
|
|
|
- "generic output: {generic_data}\n",
|
|
|
- "specific output: {specific_data}\n",
|
|
|
- ),
|
|
|
- dst_img = dst_img,
|
|
|
- src_img = src_img,
|
|
|
- dst_fmt = DstFormat::NAME,
|
|
|
- src_fmt = SrcFormat::NAME,
|
|
|
- dst_data = hex::encode(dst_img.data().data()),
|
|
|
- src_data = hex::encode(src_img.data().data()),
|
|
|
- generic_data = hex::encode(generic_dst_img.data().data()),
|
|
|
- specific_data = hex::encode(specific_dst_img.data().data())).as_str()).unwrap();
|
|
|
+ std::fs::write(
|
|
|
+ path,
|
|
|
+ format!(
|
|
|
+ concat!(
|
|
|
+ "dst: {dst_img:?}\n",
|
|
|
+ "src: {src_img:?}\n",
|
|
|
+ "dst data: ({dst_fmt}) {dst_data}\n",
|
|
|
+ "src data: ({src_fmt}) {src_data}\n",
|
|
|
+ "generic output: {generic_data}\n",
|
|
|
+ "specific output: {specific_data}\n",
|
|
|
+ ),
|
|
|
+ dst_img = dst_img,
|
|
|
+ src_img = src_img,
|
|
|
+ dst_fmt = DstFormat::NAME,
|
|
|
+ src_fmt = SrcFormat::NAME,
|
|
|
+ dst_data = hex::encode(dst_img.data().data()),
|
|
|
+ src_data = hex::encode(src_img.data().data()),
|
|
|
+ generic_data = hex::encode(generic_dst_img.data().data()),
|
|
|
+ specific_data = hex::encode(specific_dst_img.data().data())
|
|
|
+ )
|
|
|
+ .as_str(),
|
|
|
+ )
|
|
|
+ .unwrap();
|
|
|
println!("image mismatch");
|
|
|
println!("dst parameters: {:?}", dst_img);
|
|
|
println!("src parameters: {:?}", src_img);
|
|
|
println!("dst data: {}", hex::encode(dst_img.data().data()));
|
|
|
println!("src data: {}", hex::encode(src_img.data().data()));
|
|
|
- println!("specific output: {}", hex::encode(specific_dst_img.data().data()));
|
|
|
- println!("generic output: {}", hex::encode(generic_dst_img.data().data()));
|
|
|
+ println!(
|
|
|
+ "specific output: {}",
|
|
|
+ hex::encode(specific_dst_img.data().data())
|
|
|
+ );
|
|
|
+ println!(
|
|
|
+ "generic output: {}",
|
|
|
+ hex::encode(generic_dst_img.data().data())
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
assert_eq!(specific_dst_img, generic_dst_img);
|