Skip to content

Commit

Permalink
Improvements, bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
awxkee committed Jul 2, 2024
1 parent 88a7f82 commit 89931dc
Show file tree
Hide file tree
Showing 14 changed files with 329 additions and 421 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ You may receive gaussian blur in 100 FPS for 4K photo.

Much faster than `image` default blur.

When 4-channels mode is in use that always considered thad alpha channel is the last.
When 4-channels mode is in use that always considered that alpha channel is the last.

Also there are some available options to perform blurring in linear colorspace, or if methods do not fit you `f32`
options also available
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "libblur"
version = "0.12.1"
version = "0.12.2"
edition = "2021"
description = "Fast image blurring in pure Rust"
readme = "../../README.md"
Expand Down
316 changes: 254 additions & 62 deletions src/lib/fast_gaussian.rs

Large diffs are not rendered by default.

61 changes: 40 additions & 21 deletions src/lib/gaussian/gaussian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use rayon::ThreadPool;

use crate::channels_configuration::FastBlurChannels;
use crate::edge_mode::EdgeMode;
use crate::gaussian::gaussian_f16::gaussian_f16::gaussian_blur_impl_f16;
use crate::gaussian::gaussian_filter::create_filter;
use crate::gaussian::gaussian_horizontal::gaussian_blur_horizontal_pass_impl;
use crate::gaussian::gaussian_kernel::get_gaussian_kernel_1d;
Expand All @@ -54,7 +53,7 @@ use crate::unsafe_slice::UnsafeSlice;
use crate::ThreadingPolicy;

fn gaussian_blur_horizontal_pass<
T: FromPrimitive + Default + Into<f32> + Send + Sync,
T: FromPrimitive + Default + Send + Sync,
const CHANNEL_CONFIGURATION: usize,
const EDGE_MODE: usize,
>(
Expand All @@ -69,7 +68,7 @@ fn gaussian_blur_horizontal_pass<
thread_pool: &ThreadPool,
thread_count: u32,
) where
T: std::ops::AddAssign + std::ops::SubAssign + Copy + 'static,
T: std::ops::AddAssign + std::ops::SubAssign + Copy + 'static + AsPrimitive<f32>,
f32: AsPrimitive<T> + ToStorage<T>,
{
let mut _dispatcher: fn(
Expand Down Expand Up @@ -126,7 +125,7 @@ fn gaussian_blur_horizontal_pass<
}

fn gaussian_blur_vertical_pass_impl<
T: FromPrimitive + Default + Into<f32> + Send + Sync,
T: FromPrimitive + Default + Send + Sync,
const CHANNEL_CONFIGURATION: usize,
const EDGE_MODE: usize,
>(
Expand All @@ -141,7 +140,7 @@ fn gaussian_blur_vertical_pass_impl<
start_y: u32,
end_y: u32,
) where
T: std::ops::AddAssign + std::ops::SubAssign + Copy + 'static,
T: std::ops::AddAssign + std::ops::SubAssign + Copy + 'static + AsPrimitive<f32>,
f32: AsPrimitive<T> + ToStorage<T>,
{
gaussian_blur_vertical_pass_c_impl::<T, CHANNEL_CONFIGURATION, EDGE_MODE>(
Expand All @@ -159,7 +158,7 @@ fn gaussian_blur_vertical_pass_impl<
}

fn gaussian_blur_vertical_pass<
T: FromPrimitive + Default + Into<f32> + Send + Sync,
T: FromPrimitive + Default + Send + Sync,
const CHANNEL_CONFIGURATION: usize,
const EDGE_MODE: usize,
>(
Expand All @@ -174,7 +173,7 @@ fn gaussian_blur_vertical_pass<
thread_pool: &ThreadPool,
thread_count: u32,
) where
T: std::ops::AddAssign + std::ops::SubAssign + Copy + 'static,
T: std::ops::AddAssign + std::ops::SubAssign + Copy + 'static + AsPrimitive<f32>,
f32: AsPrimitive<T> + ToStorage<T>,
{
let mut _dispatcher: fn(
Expand Down Expand Up @@ -234,7 +233,7 @@ fn gaussian_blur_vertical_pass<
}

fn gaussian_blur_impl<
T: FromPrimitive + Default + Into<f32> + Send + Sync,
T: FromPrimitive + Default + Send + Sync,
const CHANNEL_CONFIGURATION: usize,
>(
src: &[T],
Expand All @@ -248,7 +247,7 @@ fn gaussian_blur_impl<
threading_policy: ThreadingPolicy,
edge_mode: EdgeMode,
) where
T: std::ops::AddAssign + std::ops::SubAssign + Copy + 'static,
T: std::ops::AddAssign + std::ops::SubAssign + Copy + 'static + AsPrimitive<f32>,
f32: AsPrimitive<T> + ToStorage<T>,
{
if kernel_size % 2 == 0 {
Expand Down Expand Up @@ -608,6 +607,7 @@ pub fn gaussian_blur_f32(
/// * `kernel_size` - Length of gaussian kernel. Panic if kernel size is not odd, even kernels with unbalanced center is not accepted.
/// * `sigma` - Sigma for a gaussian kernel, corresponds to kernel flattening level. Default - kernel_size / 6
/// * `channels` - Count of channels in the image
/// * `edge_mode` - Rule to handle edge mode
/// * `threading_policy` - Threading policy according to *ThreadingPolicy*
///
/// # Panics
Expand All @@ -620,18 +620,37 @@ pub fn gaussian_blur_f16(
kernel_size: u32,
sigma: f32,
channels: FastBlurChannels,
edge_mode: EdgeMode,
threading_policy: ThreadingPolicy,
) {
gaussian_blur_impl_f16(
src,
width * channels.get_channels() as u32,
dst,
width * channels.get_channels() as u32,
width,
height,
kernel_size,
sigma,
channels,
threading_policy,
);
match channels {
FastBlurChannels::Channels3 => {
gaussian_blur_impl::<half::f16, 3>(
unsafe { std::mem::transmute(src) },
width * channels.get_channels() as u32,
unsafe { std::mem::transmute(dst) },
width * channels.get_channels() as u32,
width,
height,
kernel_size,
sigma,
threading_policy,
edge_mode,
);
}
FastBlurChannels::Channels4 => {
gaussian_blur_impl::<half::f16, 4>(
unsafe { std::mem::transmute(src) },
width * channels.get_channels() as u32,
unsafe { std::mem::transmute(dst) },
width * channels.get_channels() as u32,
width,
height,
kernel_size,
sigma,
threading_policy,
edge_mode,
);
}
}
}
Loading

0 comments on commit 89931dc

Please sign in to comment.