|
@@ -0,0 +1,180 @@
|
|
|
+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};
|
|
|
+
|
|
|
+fn test_unary_format<UIS: UnaryInputSpec, Format: PixelFormatSpec>(n: usize) {
|
|
|
+ let gen = UIS::gen();
|
|
|
+ let mut ctx = generate::Context::default();
|
|
|
+
|
|
|
+ let op = UIS::build();
|
|
|
+ if op.is_generic::<Format>() {
|
|
|
+ // println!("Skipping generic implementation {}", Format::NAME);
|
|
|
+ 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 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);
|
|
|
+
|
|
|
+ assert_eq!(specific_img, generic_img);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+fn test_unary<UIS: UnaryInputSpec>(n: usize) {
|
|
|
+ test_unary_format::<UIS, formats::A8>(n);
|
|
|
+ test_unary_format::<UIS, formats::Abgr32>(n);
|
|
|
+ test_unary_format::<UIS, formats::Bgr24>(n);
|
|
|
+ test_unary_format::<UIS, formats::Bgr32>(n);
|
|
|
+ test_unary_format::<UIS, formats::Rgb24>(n);
|
|
|
+ test_unary_format::<UIS, formats::Rgb32>(n);
|
|
|
+ test_unary_format::<UIS, formats::Rgba32>(n);
|
|
|
+}
|
|
|
+
|
|
|
+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
|
|
|
+ } else {
|
|
|
+ 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 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");
|
|
|
+
|
|
|
+ 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);
|
|
|
+
|
|
|
+ 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();
|
|
|
+ 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()));
|
|
|
+ }
|
|
|
+
|
|
|
+ assert_eq!(specific_dst_img, generic_dst_img);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+fn test_binary<BIS: BinaryInputSpec>(n: usize) {
|
|
|
+ test_binary_format::<BIS, formats::A8, formats::A8>(n);
|
|
|
+ test_binary_format::<BIS, formats::A8, formats::Abgr32>(n);
|
|
|
+ test_binary_format::<BIS, formats::A8, formats::Bgr24>(n);
|
|
|
+ test_binary_format::<BIS, formats::A8, formats::Bgr32>(n);
|
|
|
+ test_binary_format::<BIS, formats::A8, formats::Rgb24>(n);
|
|
|
+ test_binary_format::<BIS, formats::A8, formats::Rgb32>(n);
|
|
|
+ test_binary_format::<BIS, formats::A8, formats::Rgba32>(n);
|
|
|
+
|
|
|
+ test_binary_format::<BIS, formats::Abgr32, formats::A8>(n);
|
|
|
+ test_binary_format::<BIS, formats::Abgr32, formats::Abgr32>(n);
|
|
|
+ test_binary_format::<BIS, formats::Abgr32, formats::Bgr24>(n);
|
|
|
+ test_binary_format::<BIS, formats::Abgr32, formats::Bgr32>(n);
|
|
|
+ test_binary_format::<BIS, formats::Abgr32, formats::Rgb24>(n);
|
|
|
+ test_binary_format::<BIS, formats::Abgr32, formats::Rgb32>(n);
|
|
|
+ test_binary_format::<BIS, formats::Abgr32, formats::Rgba32>(n);
|
|
|
+
|
|
|
+ test_binary_format::<BIS, formats::Bgr24, formats::A8>(n);
|
|
|
+ test_binary_format::<BIS, formats::Bgr24, formats::Abgr32>(n);
|
|
|
+ test_binary_format::<BIS, formats::Bgr24, formats::Bgr24>(n);
|
|
|
+ test_binary_format::<BIS, formats::Bgr24, formats::Bgr32>(n);
|
|
|
+ test_binary_format::<BIS, formats::Bgr24, formats::Rgb24>(n);
|
|
|
+ test_binary_format::<BIS, formats::Bgr24, formats::Rgb32>(n);
|
|
|
+ test_binary_format::<BIS, formats::Bgr24, formats::Rgba32>(n);
|
|
|
+
|
|
|
+ test_binary_format::<BIS, formats::Bgr32, formats::A8>(n);
|
|
|
+ test_binary_format::<BIS, formats::Bgr32, formats::Abgr32>(n);
|
|
|
+ test_binary_format::<BIS, formats::Bgr32, formats::Bgr24>(n);
|
|
|
+ test_binary_format::<BIS, formats::Bgr32, formats::Bgr32>(n);
|
|
|
+ test_binary_format::<BIS, formats::Bgr32, formats::Rgb24>(n);
|
|
|
+ test_binary_format::<BIS, formats::Bgr32, formats::Rgb32>(n);
|
|
|
+ test_binary_format::<BIS, formats::Bgr32, formats::Rgba32>(n);
|
|
|
+
|
|
|
+ test_binary_format::<BIS, formats::Rgb24, formats::A8>(n);
|
|
|
+ test_binary_format::<BIS, formats::Rgb24, formats::Abgr32>(n);
|
|
|
+ test_binary_format::<BIS, formats::Rgb24, formats::Bgr24>(n);
|
|
|
+ test_binary_format::<BIS, formats::Rgb24, formats::Bgr32>(n);
|
|
|
+ test_binary_format::<BIS, formats::Rgb24, formats::Rgb24>(n);
|
|
|
+ test_binary_format::<BIS, formats::Rgb24, formats::Rgb32>(n);
|
|
|
+ test_binary_format::<BIS, formats::Rgb24, formats::Rgba32>(n);
|
|
|
+
|
|
|
+ test_binary_format::<BIS, formats::Rgb32, formats::A8>(n);
|
|
|
+ test_binary_format::<BIS, formats::Rgb32, formats::Abgr32>(n);
|
|
|
+ test_binary_format::<BIS, formats::Rgb32, formats::Bgr24>(n);
|
|
|
+ test_binary_format::<BIS, formats::Rgb32, formats::Bgr32>(n);
|
|
|
+ test_binary_format::<BIS, formats::Rgb32, formats::Rgb24>(n);
|
|
|
+ test_binary_format::<BIS, formats::Rgb32, formats::Rgb32>(n);
|
|
|
+ test_binary_format::<BIS, formats::Rgb32, formats::Rgba32>(n);
|
|
|
+
|
|
|
+ test_binary_format::<BIS, formats::Rgba32, formats::A8>(n);
|
|
|
+ test_binary_format::<BIS, formats::Rgba32, formats::Abgr32>(n);
|
|
|
+ test_binary_format::<BIS, formats::Rgba32, formats::Bgr24>(n);
|
|
|
+ test_binary_format::<BIS, formats::Rgba32, formats::Bgr32>(n);
|
|
|
+ test_binary_format::<BIS, formats::Rgba32, formats::Rgb24>(n);
|
|
|
+ test_binary_format::<BIS, formats::Rgba32, formats::Rgb32>(n);
|
|
|
+ test_binary_format::<BIS, formats::Rgba32, formats::Rgba32>(n);
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn fill_op() {
|
|
|
+ test_unary::<FillOp>(100);
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn fill_region_op() {
|
|
|
+ test_unary::<FillRegionOp>(100);
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn fill_region_masked_op() {
|
|
|
+ test_unary::<FillRegionMaskedOp>(40);
|
|
|
+}
|
|
|
+
|
|
|
+#[test]
|
|
|
+fn copy_from_op() {
|
|
|
+ test_binary::<CopyFromOp>(20);
|
|
|
+}
|