use ArithmeticImageFilterFPInputs for specifying the parameters to the Arithmetic filter
@@ -4,26 +4,42 @@ use skia_bindings::{C_SkArithmeticImageFilter_Make, SkImageFilter};
pub enum ArithmeticImageFilter {}
+#[derive(Clone, Debug)]
+pub struct ArithmeticImageFilterFPInputs {
+ pub k: [f32; 4],
+ pub enforce_pm_color: bool,
+}
+
+impl From<([f32; 4], bool)> for ArithmeticImageFilterFPInputs {
+ fn from((k, enforce_pm_color): ([f32; 4], bool)) -> Self {
+ ArithmeticImageFilterFPInputs {
+ k,
+ enforce_pm_color,
+ }
+ }
+}
+
impl ArithmeticImageFilter {
#[allow(clippy::new_ret_no_self)]
#[allow(clippy::too_many_arguments)]
- pub fn new<'a, CR: Into<Option<&'a ImageFilterCropRect>>>(
- k1: f32,
- k2: f32,
- k3: f32,
- k4: f32,
- enforce_pm_color: bool,
+ pub fn new<
+ 'a,
+ II: Into<ArithmeticImageFilterFPInputs>,
+ CR: Into<Option<&'a ImageFilterCropRect>>,
+ >(
+ inputs: II,
background: &ImageFilter,
foreground: &ImageFilter,
crop_rect: CR,
) -> Option<ImageFilter> {
+ let inputs = inputs.into();
ImageFilter::from_ptr(unsafe {
C_SkArithmeticImageFilter_Make(
- k1,
- k2,
- k3,
- k4,
- enforce_pm_color,
+ inputs.k[0],
+ inputs.k[1],
+ inputs.k[2],
+ inputs.k[3],
+ inputs.enforce_pm_color,
background.shared_native(),
foreground.shared_native(),
crop_rect.into().native_ptr_or_null(),
@@ -34,25 +50,16 @@ impl ArithmeticImageFilter {
impl RCHandle<SkImageFilter> {
#[allow(clippy::too_many_arguments)]
- pub fn arithmetic<'a, CR: Into<Option<&'a ImageFilterCropRect>>>(
- k1: f32,
- k2: f32,
- k3: f32,
- k4: f32,
- enforce_pm_color: bool,
+ pub fn arithmetic<
+ 'a,
+ II: Into<ArithmeticImageFilterFPInputs>,
+ CR: Into<Option<&'a ImageFilterCropRect>>,
+ >(
+ inputs: II,
background: &Self,
foreground: &Self,
crop_rect: CR,
) -> Option<Self> {
- ArithmeticImageFilter::new(
- k1,
- k2,
- k3,
- k4,
- enforce_pm_color,
- background,
- foreground,
- crop_rect,
- )
+ ArithmeticImageFilter::new(inputs, background, foreground, crop_rect)
}
}
