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
4 changes: 2 additions & 2 deletions app/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ fn main() {
median_blur(
&cvt.to_immutable_ref(),
&mut dst_image,
25,
35,
ThreadingPolicy::Single,
)
.unwrap();
Expand Down Expand Up @@ -340,7 +340,7 @@ fn main() {

if components == 3 {
image::save_buffer(
"blurred_stack_next15_2.jpg",
"blurred_stack_next35_2.jpg",
bytes.as_bytes(),
dimensions.0,
dimensions.1,
Expand Down
28 changes: 25 additions & 3 deletions fuzz/box/box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
#![no_main]

use arbitrary::Arbitrary;
use libblur::{BlurImage, BlurImageMut, BoxBlurParameters, FastBlurChannels, ThreadingPolicy};
use libblur::{
BlurImage, BlurImageMut, BoxBlurParameters, BufferStore, FastBlurChannels, ThreadingPolicy,
};
use libfuzzer_sys::fuzz_target;

#[derive(Clone, Debug, Arbitrary)]
Expand All @@ -43,6 +45,7 @@ pub struct SrcImage {
pub y_kernel_size: u8,
pub plane: u8,
pub threading: bool,
pub additional_padding: u8,
}

fuzz_target!(|data: SrcImage| {
Expand Down Expand Up @@ -71,6 +74,7 @@ fuzz_target!(|data: SrcImage| {
} else {
ThreadingPolicy::Single
},
data.additional_padding as usize % 50,
);
});

Expand All @@ -81,12 +85,30 @@ fn fuzz_8bit(
y_kernel_size: usize,
channels: FastBlurChannels,
threading: ThreadingPolicy,
additional_padding: usize,
) {
if width == 0 || height == 0 || x_kernel_size == 0 || y_kernel_size == 0 {
return;
}
let mut dst_image = BlurImageMut::alloc(width as u32, height as u32, channels);
let src_image = BlurImage::alloc(width as u32, height as u32, channels);

let stride = (width as u32 + additional_padding as u32) * channels.channels() as u32;
let src_image = vec![0u8; stride as usize * (height - 1) + width * channels.channels()];
let dst_image = vec![0u8; stride as usize * (height - 1) + width * channels.channels()];

let src_image = BlurImage {
data: std::borrow::Cow::Borrowed(&src_image),
width: width as u32,
height: height as u32,
stride,
channels,
};
let mut dst_image = BlurImageMut {
data: BufferStore::Owned(dst_image),
width: width as u32,
height: height as u32,
stride,
channels,
};

libblur::box_blur(
&src_image,
Expand Down
19 changes: 15 additions & 4 deletions fuzz/fast_gaussian/fast_gaussian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

use arbitrary::Arbitrary;
use libblur::{
fast_gaussian, AnisotropicRadius, BlurImageMut, EdgeMode, EdgeMode2D, FastBlurChannels,
ThreadingPolicy,
fast_gaussian, AnisotropicRadius, BlurImageMut, BufferStore, EdgeMode, EdgeMode2D,
FastBlurChannels, ThreadingPolicy,
};
use libfuzzer_sys::fuzz_target;

Expand All @@ -46,6 +46,7 @@ pub struct SrcImage {
pub y_radius: u8,
pub plane: u8,
pub threading: bool,
pub additional_padding: u8,
}

fuzz_target!(|data: SrcImage| {
Expand Down Expand Up @@ -76,6 +77,7 @@ fuzz_target!(|data: SrcImage| {
} else {
ThreadingPolicy::Single
},
data.additional_padding as usize % 50,
);
});

Expand All @@ -88,13 +90,22 @@ fn fuzz_image(
edge_mode: EdgeMode,
data: u8,
threading_policy: ThreadingPolicy,
additional_padding: usize,
) {
if width == 0 || height == 0 {
return;
}

let mut dst_image = BlurImageMut::alloc(width as u32, height as u32, channels);
dst_image.data.borrow_mut().fill(data);
let stride = (width as u32 + additional_padding as u32) * channels.channels() as u32;
let dst_image = vec![data; stride as usize * (height - 1) + width * channels.channels()];

let mut dst_image = BlurImageMut {
data: BufferStore::Owned(dst_image),
width: width as u32,
height: height as u32,
stride,
channels,
};

fast_gaussian(
&mut dst_image,
Expand Down
19 changes: 15 additions & 4 deletions fuzz/fast_gaussian_next/fast_gaussian_next.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

use arbitrary::Arbitrary;
use libblur::{
fast_gaussian_next, AnisotropicRadius, BlurImageMut, EdgeMode, EdgeMode2D, FastBlurChannels,
ThreadingPolicy,
fast_gaussian_next, AnisotropicRadius, BlurImageMut, BufferStore, EdgeMode, EdgeMode2D,
FastBlurChannels, ThreadingPolicy,
};
use libfuzzer_sys::fuzz_target;

Expand All @@ -46,6 +46,7 @@ pub struct SrcImage {
pub y_radius: u8,
pub plane: u8,
pub threading: bool,
pub additional_padding: u8,
}

fuzz_target!(|data: SrcImage| {
Expand Down Expand Up @@ -76,6 +77,7 @@ fuzz_target!(|data: SrcImage| {
} else {
ThreadingPolicy::Single
},
data.additional_padding as usize % 50,
);
});

Expand All @@ -88,12 +90,21 @@ fn fuzz_image(
edge_mode: EdgeMode,
value: u8,
threading_policy: ThreadingPolicy,
additional_padding: usize,
) {
if width == 0 || height == 0 {
return;
}
let mut dst_image = BlurImageMut::alloc(width as u32, height as u32, channels);
dst_image.data.borrow_mut().fill(value);
let stride = (width as u32 + additional_padding as u32) * channels.channels() as u32;
let dst_image = vec![value; stride as usize * (height - 1) + width * channels.channels()];

let mut dst_image = BlurImageMut {
data: BufferStore::Owned(dst_image),
width: width as u32,
height: height as u32,
stride,
channels,
};

fast_gaussian_next(
&mut dst_image,
Expand Down
28 changes: 25 additions & 3 deletions fuzz/gauss/gauss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

use arbitrary::Arbitrary;
use libblur::{
BlurImage, BlurImageMut, ConvolutionMode, EdgeMode, EdgeMode2D, FastBlurChannels,
BlurImage, BlurImageMut, BufferStore, ConvolutionMode, EdgeMode, EdgeMode2D, FastBlurChannels,
GaussianBlurParams, ThreadingPolicy,
};
use libfuzzer_sys::fuzz_target;
Expand All @@ -45,6 +45,7 @@ pub struct SrcImage {
pub edge_mode_vertical: u8,
pub x_kernel_size: u8,
pub y_kernel_size: u8,
pub additional_padding: u8,
}

fuzz_target!(|data: SrcImage| {
Expand Down Expand Up @@ -76,6 +77,7 @@ fuzz_target!(|data: SrcImage| {
data.y_kernel_size as usize,
FastBlurChannels::Channels4,
EdgeMode2D::anisotropy(edge_mode_horizontal, edge_mode_vertical),
data.additional_padding as usize % 50,
);
fuzz_8bit(
data.src_width as usize,
Expand All @@ -84,6 +86,7 @@ fuzz_target!(|data: SrcImage| {
data.y_kernel_size as usize,
FastBlurChannels::Channels3,
EdgeMode2D::anisotropy(edge_mode_horizontal, edge_mode_vertical),
data.additional_padding as usize % 50,
);
fuzz_8bit(
data.src_width as usize,
Expand All @@ -92,6 +95,7 @@ fuzz_target!(|data: SrcImage| {
data.y_kernel_size as usize,
FastBlurChannels::Plane,
EdgeMode2D::anisotropy(edge_mode_horizontal, edge_mode_vertical),
data.additional_padding as usize % 50,
);
});

Expand All @@ -102,12 +106,30 @@ fn fuzz_8bit(
y_kernel_size: usize,
channels: FastBlurChannels,
edge_mode: EdgeMode2D,
additional_padding: usize,
) {
if width == 0 || height == 0 || x_kernel_size == 0 || y_kernel_size == 0 {
return;
}
let src_image = BlurImage::alloc(width as u32, height as u32, channels);
let mut dst_image = BlurImageMut::alloc(width as u32, height as u32, channels);

let stride = (width as u32 + additional_padding as u32) * channels.channels() as u32;
let src_image = vec![0u8; stride as usize * (height - 1) + width * channels.channels()];
let dst_image = vec![0u8; stride as usize * (height - 1) + width * channels.channels()];

let src_image = BlurImage {
data: std::borrow::Cow::Borrowed(&src_image),
width: width as u32,
height: height as u32,
stride,
channels,
};
let mut dst_image = BlurImageMut {
data: BufferStore::Owned(dst_image),
width: width as u32,
height: height as u32,
stride,
channels,
};

libblur::gaussian_blur(
&src_image,
Expand Down
29 changes: 25 additions & 4 deletions fuzz/gauss_f32/gauss_f32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@

use arbitrary::Arbitrary;
use libblur::{
BlurImage, BlurImageMut, EdgeMode, EdgeMode2D, FastBlurChannels, GaussianBlurParams,
IeeeBinaryConvolutionMode, ThreadingPolicy,
BlurImage, BlurImageMut, BufferStore, EdgeMode, EdgeMode2D, FastBlurChannels,
GaussianBlurParams, IeeeBinaryConvolutionMode, ThreadingPolicy,
};
use libfuzzer_sys::fuzz_target;

Expand All @@ -46,6 +46,7 @@ pub struct SrcImage {
pub x_kernel_size: u8,
pub y_kernel_size: u8,
pub double_precision: bool,
pub additional_padding: u8,
}

fuzz_target!(|data: SrcImage| {
Expand Down Expand Up @@ -77,6 +78,7 @@ fuzz_target!(|data: SrcImage| {
channels,
edge_mode,
data.double_precision,
data.additional_padding as usize % 50,
);
});

Expand All @@ -88,12 +90,31 @@ fn fuzz_f32(
channels: FastBlurChannels,
edge_mode: EdgeMode,
double_precision: bool,
additional_padding: usize,
) {
if width == 0 || height == 0 || x_kernel_size == 0 || y_kernel_size == 0 {
return;
}
let src_image = BlurImage::alloc(width as u32, height as u32, channels);
let mut dst_image = BlurImageMut::alloc(width as u32, height as u32, channels);

let stride = (width as u32 + additional_padding as u32) * channels.channels() as u32;
let src_image = vec![0.; stride as usize * (height - 1) + width * channels.channels()];
let dst_image = vec![0.; stride as usize * (height - 1) + width * channels.channels()];

let src_image = BlurImage {
data: std::borrow::Cow::Borrowed(&src_image),
width: width as u32,
height: height as u32,
stride,
channels,
};
let mut dst_image = BlurImageMut {
data: BufferStore::Owned(dst_image),
width: width as u32,
height: height as u32,
stride,
channels,
};

libblur::gaussian_blur_f32(
&src_image,
&mut dst_image,
Expand Down
26 changes: 23 additions & 3 deletions fuzz/gauss_small_kernel/gauss_small_kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

use arbitrary::Arbitrary;
use libblur::{
BlurImage, BlurImageMut, ConvolutionMode, EdgeMode, EdgeMode2D, FastBlurChannels,
BlurImage, BlurImageMut, BufferStore, ConvolutionMode, EdgeMode, EdgeMode2D, FastBlurChannels,
GaussianBlurParams, ThreadingPolicy,
};
use libfuzzer_sys::fuzz_target;
Expand All @@ -47,6 +47,7 @@ pub struct SrcImage {
pub y_kernel_size: u8,
pub channels: u8,
pub multithreaded: bool,
pub additional_padding: u8,
}

fuzz_target!(|data: SrcImage| {
Expand Down Expand Up @@ -84,6 +85,7 @@ fuzz_target!(|data: SrcImage| {
channels,
EdgeMode2D::anisotropy(edge_mode_horizontal, edge_mode_vertical),
data.multithreaded,
data.additional_padding as usize % 50,
);
});

Expand All @@ -95,12 +97,30 @@ fn fuzz_8bit(
channels: FastBlurChannels,
edge_mode: EdgeMode2D,
multithreaded: bool,
additional_padding: usize,
) {
if width == 0 || height == 0 {
return;
}
let src_image = BlurImage::alloc(width as u32, height as u32, channels);
let mut dst_image = BlurImageMut::alloc(width as u32, height as u32, channels);

let stride = (width as u32 + additional_padding as u32) * channels.channels() as u32;
let src_image = vec![0u8; stride as usize * (height - 1) + width * channels.channels()];
let dst_image = vec![0u8; stride as usize * (height - 1) + width * channels.channels()];

let src_image = BlurImage {
data: std::borrow::Cow::Borrowed(&src_image),
width: width as u32,
height: height as u32,
stride,
channels,
};
let mut dst_image = BlurImageMut {
data: BufferStore::Owned(dst_image),
width: width as u32,
height: height as u32,
stride,
channels,
};

libblur::gaussian_blur(
&src_image,
Expand Down
Loading