Fixed type of func argument of Filter::new() method.

This commit is contained in:
Kirill Kuzminykh
2024-02-07 21:18:13 +03:00
parent c9167d61a4
commit 3ee194273a
4 changed files with 22 additions and 22 deletions
+1 -1
View File
@@ -1,4 +1,4 @@
## [3.0.1] - 2024-02-04
## [Unreleased] - ReleaseDate
### Added
+17 -17
View File
@@ -2,28 +2,28 @@ use std::f64::consts::PI;
use std::fmt::{Debug, Formatter};
use thiserror::Error;
type FilterFn<'a> = &'a dyn Fn(f64) -> f64;
type FilterFn = fn(f64) -> f64;
/// Description of custom filter for image convolution.
#[derive(Clone, Copy)]
pub struct Filter<'f> {
pub struct Filter {
/// Name of filter
name: &'static str,
/// Filter function
func: FilterFn<'f>,
func: FilterFn,
/// Minimal "radius" of kernel in pixels
support: f64,
}
impl<'f> PartialEq for Filter<'f> {
impl PartialEq for Filter {
fn eq(&self, other: &Self) -> bool {
self.support == other.support && self.name == other.name
}
}
impl<'f> Eq for Filter<'f> {}
impl Eq for Filter {}
impl<'f> Debug for Filter<'f> {
impl Debug for Filter {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Filter")
.field("name", &self.name)
@@ -39,7 +39,7 @@ pub enum CreateFilterError {
InvalidSupport,
}
impl<'f> Filter<'f> {
impl Filter {
/// # Arguments
///
/// * `name` - Name of filter
@@ -47,7 +47,7 @@ impl<'f> Filter<'f> {
/// * `support` - Minimal "radius" of kernel in pixels
pub fn new(
name: &'static str,
func: FilterFn<'f>,
func: FilterFn,
support: f64,
) -> Result<Self, CreateFilterError> {
if support.is_finite() && support > 0.0 {
@@ -139,7 +139,7 @@ pub enum FilterType {
/// }
///
/// let lanczos4 = FilterType::Custom(
/// Filter::new("Lanczos4", &lanczos4_filter, 4.0).unwrap()
/// Filter::new("Lanczos4", lanczos4_filter, 4.0).unwrap()
/// );
///
/// assert_eq!(
@@ -147,19 +147,19 @@ pub enum FilterType {
/// "Custom(Filter { name: \"Lanczos4\", support: 4.0 })"
/// );
/// ```
Custom(Filter<'static>),
Custom(Filter),
}
/// Returns reference to filter function and value of `filter_support`.
#[inline]
pub(crate) fn get_filter_func(filter_type: FilterType) -> (FilterFn<'static>, f64) {
pub(crate) fn get_filter_func(filter_type: FilterType) -> (FilterFn, f64) {
match filter_type {
FilterType::Box => (&box_filter, 0.5),
FilterType::Bilinear => (&bilinear_filter, 1.0),
FilterType::Hamming => (&hamming_filter, 1.0),
FilterType::CatmullRom => (&catmul_filter, 2.0),
FilterType::Mitchell => (&mitchell_filter, 2.0),
FilterType::Lanczos3 => (&lanczos_filter, 3.0),
FilterType::Box => (box_filter, 0.5),
FilterType::Bilinear => (bilinear_filter, 1.0),
FilterType::Hamming => (hamming_filter, 1.0),
FilterType::CatmullRom => (catmul_filter, 2.0),
FilterType::Mitchell => (mitchell_filter, 2.0),
FilterType::Lanczos3 => (lanczos_filter, 3.0),
FilterType::Custom(custom) => (custom.func, custom.support),
}
}
+1 -1
View File
@@ -90,7 +90,7 @@ pub(crate) fn precompute_coefficients(
in0: f64, // Left border for cropping
in1: f64, // Right border for cropping
out_size: NonZeroU32,
filter: &dyn Fn(f64) -> f64,
filter: fn(f64) -> f64,
filter_support: f64,
) -> Coefficients {
let in_size = in_size.get();
+3 -3
View File
@@ -1004,10 +1004,10 @@ mod u8x4 {
}
for bad_support in [0.0, -1.0, f64::NAN, f64::INFINITY, f64::NEG_INFINITY] {
assert!(Filter::new("bad_support", &lanczos3_filter, bad_support).is_err());
assert!(Filter::new("bad_support", lanczos3_filter, bad_support).is_err());
}
let my_lanczos3 = Filter::new("MyLanczos3", &lanczos3_filter, 3.0).unwrap();
let my_lanczos3 = Filter::new("MyLanczos3", lanczos3_filter, 3.0).unwrap();
P::downscale_test(
ResizeAlg::Convolution(FilterType::Custom(my_lanczos3)),
CpuExtensions::None,
@@ -1022,7 +1022,7 @@ mod u8x4 {
}
}
let my_lanczos4 = Filter::new("MyLanczos4", &lanczos4_filter, 4.0).unwrap();
let my_lanczos4 = Filter::new("MyLanczos4", lanczos4_filter, 4.0).unwrap();
P::downscale_test(
ResizeAlg::Convolution(FilterType::Custom(my_lanczos4)),
CpuExtensions::None,