From a57fd314b09eb463e8e869a8e05336a53f8f5eaf Mon Sep 17 00:00:00 2001 From: awxkee Date: Fri, 26 Apr 2024 00:38:39 +0100 Subject: [PATCH] Improve parallelization --- src/main.rs | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/main.rs b/src/main.rs index 07b98e7..c3f68f2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,7 +4,7 @@ use libblur::FastBlurChannels; use std::time::Instant; fn main() { - let img = ImageReader::open("assets/test_image_1.jpg") + let img = ImageReader::open("assets/test_image_3.png") .unwrap() .decode() .unwrap(); @@ -13,7 +13,7 @@ fn main() { println!("{:?}", img.color()); let src_bytes = img.as_bytes(); - let stride = dimensions.0 as usize * 3; + let stride = dimensions.0 as usize * 4; let mut bytes: Vec = Vec::with_capacity(dimensions.1 as usize * stride); for i in 0..dimensions.1 as usize * stride { bytes.push(src_bytes[i]); @@ -21,7 +21,15 @@ fn main() { let mut dst_bytes: Vec = Vec::with_capacity(dimensions.1 as usize * stride); dst_bytes.resize(dimensions.1 as usize * stride, 0); let start_time = Instant::now(); - // libblur::fast_gaussian_next(&mut bytes, stride as u32, dimensions.0, dimensions.1, 212, FastBlurChannels::Channels3); + + libblur::fast_gaussian( + &mut bytes, + stride as u32, + dimensions.0, + dimensions.1, + 212, + FastBlurChannels::Channels4, + ); // libblur::gaussian_blur( // &bytes, // stride as u32, @@ -33,17 +41,17 @@ fn main() { // 171f32 / 3f32, // FastBlurChannels::Channels3, // ); - libblur::median_blur( - &bytes, - stride as u32, - &mut dst_bytes, - stride as u32, - dimensions.0, - dimensions.1, - 36, - FastBlurChannels::Channels3, - ); - // libblur::gaussian_box_blur(&bytes, stride as u32, &mut dst_bytes, stride as u32, dimensions.0, dimensions.1, 128, FastBlurChannels::Channels3); + // libblur::median_blur( + // &bytes, + // stride as u32, + // &mut dst_bytes, + // stride as u32, + // dimensions.0, + // dimensions.1, + // 36, + // FastBlurChannels::Channels3, + // ); + // libblur::gaussian_box_blur(&bytes, stride as u32, &mut dst_bytes, stride as u32, dimensions.0, dimensions.1, 128, FastBlurChannels::Channels4); let elapsed_time = start_time.elapsed(); // Print the elapsed time in milliseconds @@ -51,10 +59,10 @@ fn main() { image::save_buffer( "blurred.png", - dst_bytes.as_bytes(), + bytes.as_bytes(), dimensions.0, dimensions.1, - image::ExtendedColorType::Rgb8, + image::ExtendedColorType::Rgba8, ) .unwrap(); }