mirror of
https://github.com/Cykooz/fast_image_resize.git
synced 2026-10-08 01:11:09 +00:00
Added Gaussian filter for convolution algorythm.
This commit is contained in:
+10
-4
@@ -1,5 +1,15 @@
|
||||
## [Unreleased] - ReleaseDate
|
||||
|
||||
### Added
|
||||
|
||||
- Added Gaussian filter for convolution algorythm.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed dividing image by alpha channel.
|
||||
|
||||
### Changed
|
||||
|
||||
A lot of breaking changes have been done in this release:
|
||||
|
||||
- Structures `ImageView` and `ImageViewMut` have been removed. They always
|
||||
@@ -32,10 +42,6 @@ A lot of breaking changes have been done in this release:
|
||||
type from the `image` crate. It allows you to use `DynamicImage` instances
|
||||
as arguments for `Resize::resize()` method.
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fixed dividing image by alpha channel.
|
||||
|
||||
## [3.0.4] - 2024-02-15
|
||||
|
||||
### Fixed
|
||||
|
||||
@@ -107,6 +107,10 @@ pub enum FilterType {
|
||||
///
|
||||
/// Minimal kernel size 4x4 px.
|
||||
Mitchell,
|
||||
/// Gaussian filter with a standard deviation of 0.5.
|
||||
///
|
||||
/// Minimal kernel size 6x6 px.
|
||||
Gaussian,
|
||||
/// Lanczos3 filter calculate the output pixel value using a high-quality
|
||||
/// Lanczos filter (a truncated sinc) on all pixels that may contribute
|
||||
/// to the output value.
|
||||
@@ -159,6 +163,7 @@ pub(crate) fn get_filter_func(filter_type: FilterType) -> (FilterFn, f64) {
|
||||
FilterType::Hamming => (hamming_filter, 1.0),
|
||||
FilterType::CatmullRom => (catmul_filter, 2.0),
|
||||
FilterType::Mitchell => (mitchell_filter, 2.0),
|
||||
FilterType::Gaussian => (gaussian_filter, 3.0),
|
||||
FilterType::Lanczos3 => (lanczos_filter, 3.0),
|
||||
FilterType::Custom(custom) => (custom.func, custom.support),
|
||||
}
|
||||
@@ -225,6 +230,22 @@ fn mitchell_filter(mut x: f64) -> f64 {
|
||||
}
|
||||
}
|
||||
|
||||
/// The Gaussian Function.
|
||||
/// `r` is the standard deviation.
|
||||
fn gaussian(x: f64, r: f64) -> f64 {
|
||||
((2.0 * PI).sqrt() * r).recip() * (-x.powi(2) / (2.0 * r.powi(2))).exp()
|
||||
}
|
||||
|
||||
/// Calculate the gaussian function with a
|
||||
/// standard deviation of 0.5.
|
||||
fn gaussian_filter(x: f64) -> f64 {
|
||||
if (-3.0..3.0).contains(&x) {
|
||||
gaussian(x, 0.5)
|
||||
} else {
|
||||
0.0
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn sinc_filter(mut x: f64) -> f64 {
|
||||
if x == 0.0 {
|
||||
|
||||
+1
-1
@@ -69,7 +69,7 @@ impl MulDiv {
|
||||
#[cfg(feature = "only_u8x4")]
|
||||
match src_pixel_type {
|
||||
PixelType::U8x4 => self.multiply::<U8x4>(src_image, dst_image),
|
||||
_ => Err(MulDivImagesError::SrcImageError(
|
||||
_ => Err(MulDivImagesError::ImageError(
|
||||
ImageError::UnsupportedPixelType,
|
||||
)),
|
||||
}
|
||||
|
||||
@@ -307,6 +307,7 @@ where
|
||||
FilterType::Hamming => "hamming",
|
||||
FilterType::Mitchell => "mitchell",
|
||||
FilterType::CatmullRom => "catmullrom",
|
||||
FilterType::Gaussian => "gaussian",
|
||||
FilterType::Lanczos3 => "lanczos3",
|
||||
_ => "unknown",
|
||||
},
|
||||
@@ -915,6 +916,12 @@ mod u8x4 {
|
||||
cpu_extensions_vec.push(CpuExtensions::Simd128);
|
||||
}
|
||||
for cpu_extensions in cpu_extensions_vec {
|
||||
P::downscale_test(
|
||||
ResizeAlg::Convolution(FilterType::Gaussian),
|
||||
cpu_extensions,
|
||||
[2939881, 2946811, 2884299, 6122867],
|
||||
);
|
||||
|
||||
P::downscale_test(
|
||||
ResizeAlg::Convolution(FilterType::Lanczos3),
|
||||
cpu_extensions,
|
||||
|
||||
Reference in New Issue
Block a user