Added implementation From trait to convert DynamicImageViewMut into DynamicImageView.

This commit is contained in:
Kirill Kuzminykh
2022-12-11 19:09:19 +04:00
parent 4afa17d599
commit f5c7c7937c
5 changed files with 39 additions and 14 deletions
+3 -2
View File
@@ -60,11 +60,12 @@ pub fn bench_downscale_la(bench: &mut Bench) {
}
_ => {
task.iter(|| {
let mut premultiplied_view = premultiplied_src_image.view_mut();
mul_div
.multiply_alpha(&src_view, &mut premultiplied_src_image.view_mut())
.multiply_alpha(&src_view, &mut premultiplied_view)
.unwrap();
fast_resizer
.resize(&premultiplied_src_image.view(), &mut dst_view)
.resize(&premultiplied_view.into(), &mut dst_view)
.unwrap();
mul_div.divide_alpha_inplace(&mut dst_view).unwrap();
});
+3 -2
View File
@@ -59,11 +59,12 @@ pub fn bench_downscale_la16(bench: &mut Bench) {
fast_resizer.resize(&src_view, &mut dst_view).unwrap();
}
_ => {
let mut premultiplied_view = premultiplied_src_image.view_mut();
mul_div
.multiply_alpha(&src_view, &mut premultiplied_src_image.view_mut())
.multiply_alpha(&src_view, &mut premultiplied_view)
.unwrap();
fast_resizer
.resize(&premultiplied_src_image.view(), &mut dst_view)
.resize(&premultiplied_view.into(), &mut dst_view)
.unwrap();
mul_div.divide_alpha_inplace(&mut dst_view).unwrap();
}
+3 -2
View File
@@ -97,11 +97,12 @@ pub fn bench_downscale_rgba(bench: &mut Bench) {
fast_resizer.resize(&src_view, &mut dst_view).unwrap();
}
_ => {
let mut premultiplied_view = premultiplied_src_image.view_mut();
mul_div
.multiply_alpha(&src_view, &mut premultiplied_src_image.view_mut())
.multiply_alpha(&src_view, &mut premultiplied_view)
.unwrap();
fast_resizer
.resize(&premultiplied_src_image.view(), &mut dst_view)
.resize(&premultiplied_view.into(), &mut dst_view)
.unwrap();
mul_div.divide_alpha_inplace(&mut dst_view).unwrap();
}
+12 -8
View File
@@ -53,7 +53,7 @@ pub fn bench_downscale_rgba16(bench: &mut Bench) {
}
// fast_image_resize crate;
let src_image = U16x4::load_big_src_image();
let src_image_data = U16x4::load_big_src_image();
let mut cpu_ext_and_name = vec![(CpuExtensions::None, "rust")];
#[cfg(target_arch = "x86_64")]
{
@@ -73,7 +73,13 @@ pub fn bench_downscale_rgba16(bench: &mut Bench) {
"Lanczos3" => ResizeAlg::Convolution(FilterType::Lanczos3),
_ => return,
};
let mut dst_image = Image::new(new_width, new_height, src_image.pixel_type());
let src_view = src_image_data.view();
let mut premultiplied_src_image = Image::new(
NonZeroU32::new(src_image.width()).unwrap(),
NonZeroU32::new(src_image.height()).unwrap(),
src_view.pixel_type(),
);
let mut dst_image = Image::new(new_width, new_height, src_view.pixel_type());
let mut dst_view = dst_image.view_mut();
let mut mul_div = MulDiv::default();
@@ -90,19 +96,17 @@ pub fn bench_downscale_rgba16(bench: &mut Bench) {
|task| match resize_alg {
ResizeAlg::Nearest => {
task.iter(|| {
fast_resizer
.resize(&src_image.view(), &mut dst_view)
.unwrap();
fast_resizer.resize(&src_view, &mut dst_view).unwrap();
});
}
_ => {
let mut work_image = src_image.copy();
task.iter(|| {
let mut premultiplied_view = premultiplied_src_image.view_mut();
mul_div
.multiply_alpha_inplace(&mut work_image.view_mut())
.multiply_alpha(&src_view, &mut premultiplied_view)
.unwrap();
fast_resizer
.resize(&work_image.view(), &mut dst_view)
.resize(&premultiplied_view.into(), &mut dst_view)
.unwrap();
mul_div.divide_alpha_inplace(&mut dst_view).unwrap();
});
+18
View File
@@ -213,3 +213,21 @@ pub fn change_type_of_pixel_components_dyn(
);
Ok(())
}
impl<'a> From<DynamicImageViewMut<'a>> for DynamicImageView<'a> {
fn from(dyn_view: DynamicImageViewMut<'a>) -> Self {
use DynamicImageViewMut::*;
match dyn_view {
U8(typed_view) => DynamicImageView::U8(typed_view.into()),
U8x2(typed_view) => DynamicImageView::U8x2(typed_view.into()),
U8x3(typed_view) => DynamicImageView::U8x3(typed_view.into()),
U8x4(typed_view) => DynamicImageView::U8x4(typed_view.into()),
U16(typed_view) => DynamicImageView::U16(typed_view.into()),
U16x2(typed_view) => DynamicImageView::U16x2(typed_view.into()),
U16x3(typed_view) => DynamicImageView::U16x3(typed_view.into()),
U16x4(typed_view) => DynamicImageView::U16x4(typed_view.into()),
I32(typed_view) => DynamicImageView::I32(typed_view.into()),
F32(typed_view) => DynamicImageView::F32(typed_view.into()),
}
}
}