Skip to content

Commit

Permalink
Improve parallelization
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Apr 25, 2024
1 parent 0303515 commit a57fd31
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -13,15 +13,23 @@ 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<u8> = Vec::with_capacity(dimensions.1 as usize * stride);
for i in 0..dimensions.1 as usize * stride {
bytes.push(src_bytes[i]);
}
let mut dst_bytes: Vec<u8> = 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,
Expand All @@ -33,28 +41,28 @@ 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
println!("Elapsed time: {:.2?}", elapsed_time);

image::save_buffer(
"blurred.png",
dst_bytes.as_bytes(),
bytes.as_bytes(),
dimensions.0,
dimensions.1,
image::ExtendedColorType::Rgb8,
image::ExtendedColorType::Rgba8,
)
.unwrap();
}

0 comments on commit a57fd31

Please sign in to comment.