From ad283925ab29377f0afaa55a93d6a0ab1e155168 Mon Sep 17 00:00:00 2001 From: Radzivon Bartoshyk Date: Sun, 29 Mar 2026 14:10:25 +0100 Subject: [PATCH] Gauss improvements --- Cargo.toml | 2 +- app/src/main.rs | 40 +++++++++---------- src/filter1d/avx/filter_column_symm_approx.rs | 12 +++--- .../avx/filter_column_symm_approx_x2.rs | 8 ++-- src/filter1d/avx/filter_row_symm_u16.rs | 10 ++--- src/filter1d/avx/filter_row_symm_uq15_u16.rs | 8 ++-- src/filter1d/avx/row_symm_approx_binter.rs | 8 ++-- .../avx/row_symm_approx_binter3_uq0_7.rs | 8 ++-- .../avx/row_symm_approx_binter5_uq0_7.rs | 8 ++-- .../avx/row_symm_approx_binter_uq0_7.rs | 8 ++-- 10 files changed, 56 insertions(+), 56 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fe04801c..4b1db0f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ workspace = { members = ["app/accelerate", "app"], exclude = ["fuzz"] } [package] name = "libblur" -version = "0.23.2" +version = "0.23.3" edition = "2021" description = "Fast image blurring in pure Rust" readme = "./README.md" diff --git a/app/src/main.rs b/app/src/main.rs index c811a96d..eab01962 100644 --- a/app/src/main.rs +++ b/app/src/main.rs @@ -124,12 +124,12 @@ fn main() { // FastBlurChannels::Channels4, // ); - let mut z0 = v_vec - .iter() - .map(|&x| (x as f32 * (1. / 255.))) - .collect::>(); - let mut cvt = BlurImageMut::borrow( - &mut z0, + // let mut z0 = v_vec + // .iter() + // .map(|&x| (x as f32 * (1. / 255.))) + // .collect::>(); + let mut cvt = BlurImage::borrow( + &mut v_vec, dyn_image.width(), dyn_image.height(), FastBlurChannels::Channels3, @@ -148,7 +148,7 @@ fn main() { let gaussian_kernel = gaussian_kernel_2d(500., 500 / 2); // let gaussian_kernel = complex_gaussian_kernel(500., 0.75, 5.); - // let mut dst_image = BlurImageMut::default(); //cvt.clone_as_mut(); + let mut dst_image = BlurImageMut::default(); //cvt.clone_as_mut(); // gaussian_blur( // &cvt, @@ -160,17 +160,17 @@ fn main() { // ) // .unwrap(); // - // gaussian_blur( - // &cvt, - // &mut dst_image, - // GaussianBlurParams::new_from_sigma(500.), - // EdgeMode::Reflect.as_2d(), - // ThreadingPolicy::Single, - // ConvolutionMode::Exact, - // ) - // .unwrap(); + gaussian_blur( + &cvt, + &mut dst_image, + GaussianBlurParams::new_from_sigma(31.), + EdgeMode::Reflect.as_2d(), + ThreadingPolicy::Single, + ConvolutionMode::Exact, + ) + .unwrap(); - stack_blur_f32(&mut cvt, AnisotropicRadius::new(8), ThreadingPolicy::Single).unwrap(); + // stack_blur_f32(&mut cvt, AnisotropicRadius::new(8), ThreadingPolicy::Single).unwrap(); // filter_2d_rgb_fft::( // &cvt, @@ -238,12 +238,12 @@ fn main() { // dst_image = vzd.gamma8(TransferFunction::Srgb, false).unwrap(); // - dst_bytes = cvt + dst_bytes = dst_image .data .borrow_mut() .iter() - // .map(|&x| x) - .map(|&x| (x * 255f32).round() as u8) + .map(|&x| x) + // .map(|&x| (x * 255f32).round() as u8) // .map(|&x| (x >> 8) as u8) .collect::>(); diff --git a/src/filter1d/avx/filter_column_symm_approx.rs b/src/filter1d/avx/filter_column_symm_approx.rs index 00a10486..5995d619 100644 --- a/src/filter1d/avx/filter_column_symm_approx.rs +++ b/src/filter1d/avx/filter_column_symm_approx.rs @@ -107,7 +107,7 @@ unsafe fn filter_column_avx_symm_u8_i32_impl( let coeff = _mm256_set1_epi32(*v_prepared.get_unchecked(half_len)); - while cx + 128 < image_width { + while cx + 128 <= image_width { let v_src = ref0.get_unchecked(cx..); let source = _mm256_load_pack_x4(v_src.as_ptr()); @@ -146,7 +146,7 @@ unsafe fn filter_column_avx_symm_u8_i32_impl( cx += 128; } - while cx + 64 < image_width { + while cx + 64 <= image_width { let v_src = ref0.get_unchecked(cx..); let source = _mm256_load_pack_x2(v_src.as_ptr()); @@ -176,7 +176,7 @@ unsafe fn filter_column_avx_symm_u8_i32_impl( cx += 64; } - while cx + 32 < image_width { + while cx + 32 <= image_width { let v_src = ref0.get_unchecked(cx..); let source = _mm256_loadu_si256(v_src.as_ptr() as *const __m256i); @@ -202,7 +202,7 @@ unsafe fn filter_column_avx_symm_u8_i32_impl( cx += 32; } - while cx + 16 < image_width { + while cx + 16 <= image_width { let v_src = ref0.get_unchecked(cx..); let source = _mm_loadu_si128(v_src.as_ptr() as *const __m128i); @@ -228,7 +228,7 @@ unsafe fn filter_column_avx_symm_u8_i32_impl( cx += 16; } - while cx + 8 < image_width { + while cx + 8 <= image_width { let v_src = ref0.get_unchecked(cx..); let source = _mm_loadu_si64(v_src.as_ptr() as *const _); @@ -254,7 +254,7 @@ unsafe fn filter_column_avx_symm_u8_i32_impl( cx += 8; } - while cx + 4 < image_width { + while cx + 4 <= image_width { let v_src = ref0.get_unchecked(cx..); let source = _mm_loadu_si32(v_src.as_ptr() as *const _); diff --git a/src/filter1d/avx/filter_column_symm_approx_x2.rs b/src/filter1d/avx/filter_column_symm_approx_x2.rs index a47ad832..68b24a23 100644 --- a/src/filter1d/avx/filter_column_symm_approx_x2.rs +++ b/src/filter1d/avx/filter_column_symm_approx_x2.rs @@ -97,7 +97,7 @@ unsafe fn filter_column_avx_symm_u8_i32_impl_x2( let coeff = _mm256_set1_epi32(*v_prepared.get_unchecked(half_len)); - while cx + 64 < image_width { + while cx + 64 <= image_width { let v_src0 = ref0.get_unchecked(cx..); let v_src1 = ref1.get_unchecked(cx..); @@ -153,7 +153,7 @@ unsafe fn filter_column_avx_symm_u8_i32_impl_x2( cx += 64; } - while cx + 32 < image_width { + while cx + 32 <= image_width { let v_src0 = ref0.get_unchecked(cx..); let v_src1 = ref1.get_unchecked(cx..); @@ -231,7 +231,7 @@ unsafe fn filter_column_avx_symm_u8_i32_impl_x2( cx += 16; } - while cx + 8 < image_width { + while cx + 8 <= image_width { let v_src0 = ref0.get_unchecked(cx..); let v_src1 = ref1.get_unchecked(cx..); @@ -269,7 +269,7 @@ unsafe fn filter_column_avx_symm_u8_i32_impl_x2( cx += 8; } - while cx + 4 < image_width { + while cx + 4 <= image_width { let v_src0 = ref0.get_unchecked(cx..); let v_src1 = ref1.get_unchecked(cx..); diff --git a/src/filter1d/avx/filter_row_symm_u16.rs b/src/filter1d/avx/filter_row_symm_u16.rs index cc669139..fd7b6f5c 100644 --- a/src/filter1d/avx/filter_row_symm_u16.rs +++ b/src/filter1d/avx/filter_row_symm_u16.rs @@ -147,7 +147,7 @@ impl RowSymmExecutionUnit { let coeff = _mm256_set1_ps(scanned_kernel.get_unchecked(half_len).weight); - while cx + 64 < max_width { + while cx + 64 <= max_width { let shifted_src = local_src.get_unchecked(cx..); let source = @@ -184,7 +184,7 @@ impl RowSymmExecutionUnit { cx += 64; } - while cx + 32 < max_width { + while cx + 32 <= max_width { let shifted_src = local_src.get_unchecked(cx..); let source = @@ -212,7 +212,7 @@ impl RowSymmExecutionUnit { cx += 32; } - while cx + 16 < max_width { + while cx + 16 <= max_width { let shifted_src = local_src.get_unchecked(cx..); let source = @@ -235,7 +235,7 @@ impl RowSymmExecutionUnit { cx += 16; } - while cx + 8 < max_width { + while cx + 8 <= max_width { let shifted_src = local_src.get_unchecked(cx..); let source = @@ -258,7 +258,7 @@ impl RowSymmExecutionUnit { cx += 8; } - while cx + 4 < max_width { + while cx + 4 <= max_width { let shifted_src = local_src.get_unchecked(cx..); let source = diff --git a/src/filter1d/avx/filter_row_symm_uq15_u16.rs b/src/filter1d/avx/filter_row_symm_uq15_u16.rs index 39bb4c80..ada73605 100644 --- a/src/filter1d/avx/filter_row_symm_uq15_u16.rs +++ b/src/filter1d/avx/filter_row_symm_uq15_u16.rs @@ -86,7 +86,7 @@ unsafe fn filter_row_avx_symm_uq15_u16_impl( let coeff = _mm256_set1_epi32(scanned_kernel.get_unchecked(half_len).weight as i32); - while cx + 64 < max_width { + while cx + 64 <= max_width { let shifted_src = local_src.get_unchecked(cx..); let source = @@ -123,7 +123,7 @@ unsafe fn filter_row_avx_symm_uq15_u16_impl( cx += 64; } - while cx + 32 < max_width { + while cx + 32 <= max_width { let shifted_src = local_src.get_unchecked(cx..); let source = @@ -177,7 +177,7 @@ unsafe fn filter_row_avx_symm_uq15_u16_impl( cx += 16; } - while cx + 8 < max_width { + while cx + 8 <= max_width { let shifted_src = local_src.get_unchecked(cx..); let source = @@ -199,7 +199,7 @@ unsafe fn filter_row_avx_symm_uq15_u16_impl( cx += 8; } - while cx + 4 < max_width { + while cx + 4 <= max_width { let shifted_src = local_src.get_unchecked(cx..); let source = _mm_loadu_si64(shifted_src.get_unchecked(half_len * N..).as_ptr() as *const _); diff --git a/src/filter1d/avx/row_symm_approx_binter.rs b/src/filter1d/avx/row_symm_approx_binter.rs index 6aec14da..9c53cfa9 100644 --- a/src/filter1d/avx/row_symm_approx_binter.rs +++ b/src/filter1d/avx/row_symm_approx_binter.rs @@ -132,7 +132,7 @@ impl ExecutionUnit { let coeff = _mm256_set1_epi32(*v_prepared.get_unchecked(half_len)); - while m_cx + 32 < max_width { + while m_cx + 32 <= max_width { let cx = m_cx - s_half; let shifted_src = src.get_unchecked(cx..); @@ -158,7 +158,7 @@ impl ExecutionUnit { m_cx += 32; } - while m_cx + 16 < max_width { + while m_cx + 16 <= max_width { let cx = m_cx - s_half; let shifted_src = src.get_unchecked(cx..); @@ -182,7 +182,7 @@ impl ExecutionUnit { m_cx += 16; } - while m_cx + 8 < max_width { + while m_cx + 8 <= max_width { let cx = m_cx - s_half; let shifted_src = src.get_unchecked(cx..); @@ -206,7 +206,7 @@ impl ExecutionUnit { m_cx += 8; } - while m_cx + 4 < max_width { + while m_cx + 4 <= max_width { let cx = m_cx - s_half; let shifted_src = src.get_unchecked(cx..); diff --git a/src/filter1d/avx/row_symm_approx_binter3_uq0_7.rs b/src/filter1d/avx/row_symm_approx_binter3_uq0_7.rs index 368e6f5a..ad0c7719 100644 --- a/src/filter1d/avx/row_symm_approx_binter3_uq0_7.rs +++ b/src/filter1d/avx/row_symm_approx_binter3_uq0_7.rs @@ -121,7 +121,7 @@ impl ExecutionUnit { let m_right = width.saturating_sub(half_len); let max_width = m_right * N; - while m_cx + 32 < max_width { + while m_cx + 32 <= max_width { let cx = m_cx - s_half; let shifted_src = src.get_unchecked(cx..); @@ -158,7 +158,7 @@ impl ExecutionUnit { m_cx += 32; } - while m_cx + 16 < max_width { + while m_cx + 16 <= max_width { let cx = m_cx - s_half; let shifted_src = src.get_unchecked(cx..); @@ -206,7 +206,7 @@ impl ExecutionUnit { m_cx += 16; } - while m_cx + 8 < max_width { + while m_cx + 8 <= max_width { let cx = m_cx - s_half; let shifted_src = src.get_unchecked(cx..); @@ -241,7 +241,7 @@ impl ExecutionUnit { m_cx += 8; } - while m_cx + 4 < max_width { + while m_cx + 4 <= max_width { let cx = m_cx - s_half; let shifted_src = src.get_unchecked(cx..); diff --git a/src/filter1d/avx/row_symm_approx_binter5_uq0_7.rs b/src/filter1d/avx/row_symm_approx_binter5_uq0_7.rs index 3cef5e60..cd29ee58 100644 --- a/src/filter1d/avx/row_symm_approx_binter5_uq0_7.rs +++ b/src/filter1d/avx/row_symm_approx_binter5_uq0_7.rs @@ -128,7 +128,7 @@ impl ExecutionUnit { let m_right = width.saturating_sub(half_len); let max_width = m_right * N; - while m_cx + 32 < max_width { + while m_cx + 32 <= max_width { let cx = m_cx - s_half; let shifted_src = src.get_unchecked(cx..); @@ -179,7 +179,7 @@ impl ExecutionUnit { m_cx += 32; } - while m_cx + 16 < max_width { + while m_cx + 16 <= max_width { let cx = m_cx - s_half; let shifted_src = src.get_unchecked(cx..); @@ -247,7 +247,7 @@ impl ExecutionUnit { m_cx += 16; } - while m_cx + 8 < max_width { + while m_cx + 8 <= max_width { let cx = m_cx - s_half; let shifted_src = src.get_unchecked(cx..); @@ -295,7 +295,7 @@ impl ExecutionUnit { m_cx += 8; } - while m_cx + 4 < max_width { + while m_cx + 4 <= max_width { let cx = m_cx - s_half; let shifted_src = src.get_unchecked(cx..); diff --git a/src/filter1d/avx/row_symm_approx_binter_uq0_7.rs b/src/filter1d/avx/row_symm_approx_binter_uq0_7.rs index 28849010..5946ba3d 100644 --- a/src/filter1d/avx/row_symm_approx_binter_uq0_7.rs +++ b/src/filter1d/avx/row_symm_approx_binter_uq0_7.rs @@ -144,7 +144,7 @@ impl ExecutionUnit { let coeff = _mm256_set1_epi32(*v_prepared.get_unchecked(half_len)); let rnd = _mm256_set1_epi16(1 << 6); - while m_cx + 32 < max_width { + while m_cx + 32 <= max_width { let cx = m_cx - s_half; let shifted_src = src.get_unchecked(cx..); @@ -193,7 +193,7 @@ impl ExecutionUnit { m_cx += 32; } - while m_cx + 16 < max_width { + while m_cx + 16 <= max_width { let cx = m_cx - s_half; let shifted_src = src.get_unchecked(cx..); @@ -240,7 +240,7 @@ impl ExecutionUnit { m_cx += 16; } - while m_cx + 8 < max_width { + while m_cx + 8 <= max_width { let cx = m_cx - s_half; let shifted_src = src.get_unchecked(cx..); @@ -278,7 +278,7 @@ impl ExecutionUnit { m_cx += 8; } - while m_cx + 4 < max_width { + while m_cx + 4 <= max_width { let cx = m_cx - s_half; let shifted_src = src.get_unchecked(cx..);