Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ workspace = { members = ["fuzz", "app/accelerate", "app"] }

[package]
name = "libblur"
version = "0.19.2"
version = "0.19.3"
edition = "2021"
description = "Fast image blurring in pure Rust"
readme = "./README.md"
Expand All @@ -28,6 +28,7 @@ image = { version = "0.25", optional = true, default-features = false }
rustfft = { version = "6.3", optional = true }
fast_transpose = { version = "0.2.5", optional = true }
num-complex = "0.4"
novtb = "^0.1.4"

[features]
default = ["avx", "sse", "rdm", "neon"]
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ Example comparison time for blurring image 3000x4000 RGB 8-bit in multithreaded

| | time(NEON) | time(SSE) |
|---------|:----------:|:---------:|
| libblur | 5.11ms | 5.30ms |
| libblur | 4.95ms | 5.30ms |
| OpenCV | 8.43ms | 10.36ms |

Example comparison time for blurring image 2828x4242 RGBA 8-bit in multithreaded mode with 77 radius.

| | time(NEON) | time(SSE) |
|---------|:----------:|:---------:|
| libblur | 5.31ms | 5.48ms |
| libblur | 4.97ms | 5.48ms |
| OpenCV | 8.00ms | 8.55ms |

### Fast gaussian
Expand Down
2 changes: 1 addition & 1 deletion app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
colorutils-rs = "0.7.0"
half = "2.4.1"
image = "0.25.5"
libblur = { path = "../", features = ["image", "fft", "rdm", "neon", "sse", "avx", "nightly_avx512", "nightly_fcma"], default-features = false }
libblur = { path = "../", features = ["image", "fft", "rdm", "neon", "sse", "avx", "nightly_avx512"], default-features = false }
accelerate = { path = "accelerate" }
rayon = "1.10.0"
fast_transpose = "0.2.5"
Expand Down
2 changes: 1 addition & 1 deletion app/benches/gauss/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
})
});

c.bench_function("RGB f32 gauss blur edge clamp: rad 51", |b| {
c.bench_function("RGB f32 gauss blur edge clamp: rad 25", |b| {
let mut dst_bytes = BlurImageMut::default();
let src_bytes = img
.as_bytes()
Expand Down
71 changes: 41 additions & 30 deletions app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,18 @@ mod split;
use image::{EncodableLayout, GenericImageView, ImageReader};
use libblur::{
bilateral_filter, complex_gaussian_kernel, fast_bilateral_filter, fast_bilateral_filter_u16,
filter_1d_complex, filter_1d_complex_fixed_point, filter_2d_rgba_fft, gaussian_kernel_1d,
lens_kernel, sigma_size, AnisotropicRadius, BilateralBlurParams, BlurImage, BlurImageMut,
EdgeMode, FastBlurChannels, KernelShape, Scalar, ThreadingPolicy, TransferFunction,
filter_1d_complex, filter_1d_complex_fixed_point, filter_2d_rgba_fft, gaussian_blur,
gaussian_kernel_1d, lens_kernel, sigma_size, AnisotropicRadius, BilateralBlurParams, BlurImage,
BlurImageMut, BoxBlurParameters, CLTParameters, ConvolutionMode, EdgeMode, FastBlurChannels,
GaussianBlurParams, KernelShape, Scalar, ThreadingPolicy, TransferFunction,
};
use num_complex::Complex;
use rayon::prelude::{IntoParallelIterator, ParallelIterator};
use std::any::Any;
use std::fs;
use std::fs::File;
use std::io::{BufReader, Read};
use std::time::Instant;
use rayon::prelude::{IntoParallelIterator, ParallelIterator};

#[allow(dead_code)]
fn f32_to_f16(bytes: Vec<f32>) -> Vec<u16> {
Expand Down Expand Up @@ -119,10 +120,22 @@ fn main() {
// let bokeh = generate_complex_bokeh_kernel(35, 30.);
let start_time = Instant::now();
// let gaussian_kernel = gaussian_kernel_1d(31, sigma_size(31.)).iter().map(|&x| Complex::new(x, 0.0)).collect::<Vec<Complex<f32>>>();
let gaussian_kernel = complex_gaussian_kernel(51., 0.75, 25.);
let gaussian_kernel = complex_gaussian_kernel(51., 0.75, 5.);

let mut dst_image = cvt.clone_as_mut();

// gaussian_blur(
// &cvt,
// &mut dst_image,
// GaussianBlurParams::new_from_kernel(15.),
// EdgeMode::Clamp,
// ThreadingPolicy::Single,
// ConvolutionMode::FixedPoint,
// )
// .unwrap();

// filter_2d_rgba_fft::<u16, f32, f32>(
// &image,
// filter_2d_rgba_fft::<u8, f32, f32>(
// &cvt,
// &mut dst_image,
// &motion,
// KernelShape::new(151, 151),
Expand All @@ -142,44 +155,42 @@ fn main() {

// }

// libblur::gaussian_blur(
// &image,
libblur::bilateral_filter(
&cvt,
&mut dst_image,
BilateralBlurParams {
kernel_size: 15,
spatial_sigma: 5.,
range_sigma: 5.,
},
EdgeMode::Clamp,
Scalar::default(),
ThreadingPolicy::Single,
)
.unwrap();

// libblur::stack_blur(
// &mut dst_image,
// GaussianBlurParams {
// x_kernel: 7,
// x_sigma: 0.,
// y_kernel: 9,
// y_sigma: 0.,
// },
// EdgeMode::Clamp,
// AnisotropicRadius::create(35, 35),
// ThreadingPolicy::Single,
// ConvolutionMode::FixedPoint,
// )
// .unwrap();

// libblur::fast_gaussian_next_f32(
// &mut dst_image,
// AnisotropicRadius::create(8, 35),
// ThreadingPolicy::Single,
// EdgeMode::Clamp,
// )
// .unwrap();

// libblur::motion_blur(
// &image,
// &cvt,
// &mut dst_image,
// 35.,
// 15,
// 21,
// EdgeMode::Clamp,
// Scalar::new(0.0, 0.0, 0.0, 0.0),
// ThreadingPolicy::Single,
// ThreadingPolicy::Adaptive,
// )
// .unwrap();

// let j_dag = dst_image.to_immutable_ref();
// let gamma = j_dag.gamma8(TransferFunction::Srgb, true).unwrap();

/* dst_bytes = dst_image
dst_bytes = dst_image
.data
.borrow_mut()
.iter()
Expand Down Expand Up @@ -234,5 +245,5 @@ fn main() {
},
)
.unwrap();
}*/
}
}
9 changes: 8 additions & 1 deletion fuzz/bilateral/bilateral.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub struct SrcImage {
pub channels: u8,
pub kernel_size: u8,
pub angle: f32,
pub multi_threading: bool,
}

fuzz_target!(|data: SrcImage| {
Expand Down Expand Up @@ -71,6 +72,7 @@ fuzz_target!(|data: SrcImage| {
data.angle,
channels,
edge_mode,
data.multi_threading,
);
});

Expand All @@ -81,6 +83,7 @@ fn fuzz_8bit(
sigma: f32,
channels: FastBlurChannels,
edge_mode: EdgeMode,
multi_threading: bool,
) {
if width == 0 || height == 0 || radius == 0 {
return;
Expand All @@ -101,7 +104,11 @@ fn fuzz_8bit(
},
edge_mode,
Scalar::new(0.0, 0.0, 0.0, 0.0),
ThreadingPolicy::Single,
if multi_threading {
ThreadingPolicy::Adaptive
} else {
ThreadingPolicy::Single
},
)
.unwrap();
}
9 changes: 8 additions & 1 deletion fuzz/fast_gaussian/fast_gaussian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub struct SrcImage {
pub x_radius: u8,
pub y_radius: u8,
pub plane: u8,
pub threading: bool,
}

fuzz_target!(|data: SrcImage| {
Expand All @@ -69,6 +70,11 @@ fuzz_target!(|data: SrcImage| {
plane_match,
edge_mode,
data.value,
if data.threading {
ThreadingPolicy::Adaptive
} else {
ThreadingPolicy::Single
},
);
});

Expand All @@ -80,6 +86,7 @@ fn fuzz_image(
channels: FastBlurChannels,
edge_mode: EdgeMode,
data: u8,
threading_policy: ThreadingPolicy,
) {
if width == 0 || height == 0 {
return;
Expand All @@ -91,7 +98,7 @@ fn fuzz_image(
fast_gaussian(
&mut dst_image,
AnisotropicRadius::create(x_radius as u32, y_radius as u32),
ThreadingPolicy::Single,
threading_policy,
edge_mode,
)
.unwrap();
Expand Down
9 changes: 8 additions & 1 deletion fuzz/fast_gaussian_next/fast_gaussian_next.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct SrcImage {
pub x_radius: u8,
pub y_radius: u8,
pub plane: u8,
pub threading: bool,
}

fuzz_target!(|data: SrcImage| {
Expand All @@ -70,6 +71,11 @@ fuzz_target!(|data: SrcImage| {
plane_match,
edge_mode,
data.value,
if data.threading {
ThreadingPolicy::Adaptive
} else {
ThreadingPolicy::Single
},
);
});

Expand All @@ -81,6 +87,7 @@ fn fuzz_image(
channels: FastBlurChannels,
edge_mode: EdgeMode,
value: u8,
threading_policy: ThreadingPolicy,
) {
if width == 0 || height == 0 {
return;
Expand All @@ -91,7 +98,7 @@ fn fuzz_image(
fast_gaussian_next(
&mut dst_image,
AnisotropicRadius::create(x_radius as u32, y_radius as u32),
ThreadingPolicy::Single,
threading_policy,
edge_mode,
)
.unwrap();
Expand Down
Loading