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
28 changes: 14 additions & 14 deletions .github/workflows/build_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: rustup target add aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu i686-unknown-linux-gnu powerpc-unknown-linux-gnu armv7-unknown-linux-gnueabi
- run: RUSTFLAGS="-C target-feature=+neon" cargo build --target aarch64-unknown-linux-gnu --features image
Expand All @@ -43,7 +43,7 @@ jobs:
os: [ ubuntu-latest, macos-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
- run: rustup component add clippy
- run: cargo clippy --all-features -- -D warnings
Expand All @@ -52,7 +52,7 @@ jobs:
name: Clippy WASM
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@stable
- run: rustup target add wasm32-unknown-unknown
- run: rustup component add clippy
Expand All @@ -65,7 +65,7 @@ jobs:
matrix:
feature: [ neon, rdm, "" ]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- run: cargo test --features "${{ matrix.feature }}" --features fft --no-default-features

Expand All @@ -76,7 +76,7 @@ jobs:
feature: [ sse, avx, "" ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- run: cargo test --features "${{ matrix.feature }}" --features fft --no-default-features

Expand All @@ -87,7 +87,7 @@ jobs:
matrix:
feature: [ neon, rdm, "" ]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- run: cargo install cargo-fuzz
- run: cargo fuzz run box --features "${{ matrix.feature }}" -- -max_total_time=14
Expand All @@ -101,7 +101,7 @@ jobs:
feature: [ avx, sse ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- run: cargo install cargo-fuzz
- run: cargo fuzz run box --features "${{ matrix.feature }}" -- -max_total_time=14
Expand All @@ -115,7 +115,7 @@ jobs:
matrix:
feature: [ neon, rdm ]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- run: cargo install cargo-fuzz
- run: cargo fuzz run gauss --features ${{ matrix.feature }} -- -max_total_time=17
Expand All @@ -130,7 +130,7 @@ jobs:
name: Fuzzing Filter 1D/2D ARM FCMA
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- run: cargo install cargo-fuzz
- run: cargo fuzz run filter_complex --features neon,nightly_fcma -- -max_total_time=17
Expand All @@ -143,7 +143,7 @@ jobs:
feature: [ "", sse, avx ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- run: cargo install cargo-fuzz
- run: cargo fuzz run gauss --features "${{ matrix.feature }}" -- -max_total_time=17
Expand All @@ -161,7 +161,7 @@ jobs:
matrix:
feature: [ neon, rdm ]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- run: cargo install cargo-fuzz
- run: cargo fuzz run stack_blur --features ${{ matrix.feature }} -- -max_total_time=17
Expand All @@ -175,7 +175,7 @@ jobs:
feature: [ sse, avx, "" ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- run: cargo install cargo-fuzz
- run: cargo fuzz run stack_blur --features "${{ matrix.feature }}" -- -max_total_time=17
Expand All @@ -189,7 +189,7 @@ jobs:
matrix:
feature: [ neon, rdm ]
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- run: cargo install cargo-fuzz
- run: cargo fuzz run fast_gaussian --features ${{ matrix.feature }} -- -max_total_time=14
Expand All @@ -206,7 +206,7 @@ jobs:
feature: [ sse, avx, "" ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: dtolnay/rust-toolchain@nightly
- run: cargo install cargo-fuzz
- run: cargo fuzz run fast_gaussian --features "${{ matrix.feature }}" -- -max_total_time=14
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/mirroring.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Mirror to GitLab and Codeberg

on:
push:
branches: [ 'master' ]
tags:
- '*'

jobs:
mirror:
runs-on: ubuntu-latest
environment: mirroring
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0

- name: Mirror to GitLab
run: |
git remote add gitlab https://oauth2:${{ secrets.GITLAB_TOKEN }}@gitlab.com/awxkee/libblur
git remote add codeberg https://awxkee:${{ secrets.CODEBERG_TOKEN }}@codeberg.org/awxkee/libblur.git
git push gitlab --all
git push gitlab --tags
git push codeberg --all
git push codeberg --tags
2 changes: 1 addition & 1 deletion .github/workflows/publish_release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
environment: Cargo
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: rustup target add aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu i686-unknown-linux-gnu powerpc-unknown-linux-gnu armv7-unknown-linux-gnueabi
- run: RUSTFLAGS="-C target-feature=+neon" cargo build --target aarch64-unknown-linux-gnu --features image
Expand Down
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ workspace = { members = ["app/accelerate", "app"], exclude = ["fuzz"] }

[package]
name = "libblur"
version = "0.23.3"
edition = "2021"
version = "0.24.0"
edition = "2024"
description = "Fast image blurring in pure Rust"
readme = "./README.md"
keywords = ["blur", "gauss_blur", "image_blur", "fast_blur", "stack_blur"]
Expand All @@ -15,7 +15,7 @@ homepage = "https://github.com/awxkee/libblur"
repository = "https://github.com/awxkee/libblur.git"
exclude = ["*.jpg", "./assets/*", "*.png"]
include = ["/src/", "/README.md", "/LICENSE.md", "/LICENSE-APACHE.md"]
rust-version = "1.82.0"
rust-version = "1.89.0"

[lib]
name = "libblur"
Expand All @@ -36,7 +36,7 @@ fft = ["dep:zaft"]
# Enables NEON RDM intrinsics
rdm = ["neon"]
# Enables AVX-512. Requires nightly on rust compiler before 1.89.
nightly_avx512 = []
avx512 = []
# Enables NEON fcma, used in FFT and filter 1d complex. Requires nightly.
nightly_fcma = ["zaft?/fcma"]
# Enables core::f16 support. Requires nightly.
Expand Down
2 changes: 1 addition & 1 deletion app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ edition = "2021"
[dependencies]
half = "2.4.1"
image = "0.25.5"
libblur = { path = "../", features = ["nightly_f16", "sse", "avx", "fft", "neon", "rdm", "nightly_avx512", "nightly_fcma", "image"], default-features = false }
libblur = { path = "../", features = ["nightly_f16", "sse", "avx", "fft", "neon", "rdm", "avx512", "nightly_fcma", "image"], default-features = false }
accelerate = { path = "accelerate" }
rayon = "1.10.0"
num-complex = "0.4"
Expand Down
40 changes: 38 additions & 2 deletions app/benches/gauss/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ pub fn criterion_benchmark(c: &mut Criterion) {
FastBlurChannels::Channels4,
);

c.bench_function("RGBA gauss blur kernel clip: 3", |b| {
opencv::core::set_num_threads(1).unwrap();

c.bench_function("RGBA gauss blur kernel clip Single Thread: 3", |b| {
let mut dst_bytes =
BlurImageMut::alloc(img.width(), img.height(), FastBlurChannels::Channels4);
b.iter(|| {
Expand All @@ -61,7 +63,7 @@ pub fn criterion_benchmark(c: &mut Criterion) {
&mut dst_bytes,
GaussianBlurParams::new_from_kernel(3.),
EdgeMode::Clamp.as_2d(),
ThreadingPolicy::Adaptive,
ThreadingPolicy::Single,
ConvolutionMode::FixedPoint,
)
.unwrap();
Expand All @@ -83,6 +85,40 @@ pub fn criterion_benchmark(c: &mut Criterion) {
)
.unwrap();

c.bench_function("OpenCV RGBA Gaussian Single Thread: 3", |b| {
b.iter(|| {
let mut dst = Mat::default();
opencv::imgproc::gaussian_blur(
&src,
&mut dst,
Size::new(3, 3),
3.,
3.,
BORDER_DEFAULT,
AlgorithmHint::ALGO_HINT_ACCURATE,
)
.unwrap();
})
});

opencv::core::set_num_threads(-1).unwrap();

c.bench_function("RGBA gauss blur kernel clip: 3", |b| {
let mut dst_bytes =
BlurImageMut::alloc(img.width(), img.height(), FastBlurChannels::Channels4);
b.iter(|| {
libblur::gaussian_blur(
&src_image,
&mut dst_bytes,
GaussianBlurParams::new_from_kernel(3.),
EdgeMode::Clamp.as_2d(),
ThreadingPolicy::Adaptive,
ConvolutionMode::FixedPoint,
)
.unwrap();
})
});

c.bench_function("OpenCV RGBA Gaussian: 3", |b| {
b.iter(|| {
let mut dst = Mat::default();
Expand Down
26 changes: 13 additions & 13 deletions app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ fn main() {
// .iter()
// .map(|&x| (x as f32 * (1. / 255.)))
// .collect::<Vec<_>>();
let mut cvt = BlurImage::borrow(
let mut cvt = BlurImageMut::borrow(
&mut v_vec,
dyn_image.width(),
dyn_image.height(),
Expand All @@ -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,
Expand All @@ -160,17 +160,17 @@ fn main() {
// )
// .unwrap();
//
gaussian_blur(
&cvt,
&mut dst_image,
GaussianBlurParams::new_from_sigma(31.),
EdgeMode::Reflect.as_2d(),
ThreadingPolicy::Single,
ConvolutionMode::Exact,
)
.unwrap();
// gaussian_blur(
// &cvt,
// &mut dst_image,
// GaussianBlurParams::new_from_kernel(3.),
// EdgeMode::Reflect.as_2d(),
// ThreadingPolicy::Single,
// ConvolutionMode::FixedPoint,
// )
// .unwrap();

// stack_blur_f32(&mut cvt, AnisotropicRadius::new(8), ThreadingPolicy::Single).unwrap();
stack_blur(&mut cvt, AnisotropicRadius::new(8), ThreadingPolicy::Single).unwrap();

// filter_2d_rgb_fft::<u8, f32>(
// &cvt,
Expand Down Expand Up @@ -238,7 +238,7 @@ fn main() {

// dst_image = vzd.gamma8(TransferFunction::Srgb, false).unwrap();
//
dst_bytes = dst_image
dst_bytes = cvt
.data
.borrow_mut()
.iter()
Expand Down
2 changes: 1 addition & 1 deletion fuzz/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ neon = ["libblur/neon"]
avx = ["libblur/avx"]
sse = ["libblur/sse"]
rdm = ["libblur/rdm", "neon"]
avx512 = ["libblur/nightly_avx512"]
avx512 = ["libblur/avx512"]
nightly_fcma = ["libblur/nightly_fcma"]

[[bin]]
Expand Down
10 changes: 5 additions & 5 deletions src/adaptive_blur.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
#![allow(clippy::manual_clamp)]

use crate::{
filter_2d, filter_2d_fft, gaussian_blur, stack_blur, AnisotropicRadius, BlurError, BlurImage,
BlurImageMut, ConvolutionMode, EdgeMode, EdgeMode2D, FastBlurChannels, GaussianBlurParams,
KernelShape, Scalar, ThreadingPolicy, TransferFunction,
AnisotropicRadius, BlurError, BlurImage, BlurImageMut, ConvolutionMode, EdgeMode, EdgeMode2D,
FastBlurChannels, GaussianBlurParams, KernelShape, Scalar, ThreadingPolicy, TransferFunction,
filter_2d, filter_2d_fft, gaussian_blur, stack_blur,
};
use num_traits::AsPrimitive;
use std::fmt::Debug;
Expand Down Expand Up @@ -123,7 +123,7 @@ impl Blur<u8> for u8 {
channels: FastBlurChannels,
) {
let mut rad = (radius / 2).saturating_sub(1).max(1);
if rad % 2 == 0 {
if rad.is_multiple_of(2) {
rad += 1;
}
let src = BlurImage::borrow(image, width as u32, height as u32, channels);
Expand Down Expand Up @@ -249,7 +249,7 @@ impl Edges<u8> for u8 {
let mut dst = vec![0u8; width * height];

let mut radius = radius;
if radius % 2 == 0 {
if radius.is_multiple_of(2) {
radius += 1;
}

Expand Down
Loading