From 384fef5a816854f52572b18bf010dc3b8894b2ef Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Sun, 17 Mar 2024 00:50:51 +0100 Subject: [PATCH] svg-filters(primitives): start with feComponentTransfer --- crates/svg-filters/src/types/nodes.rs | 19 ++++++++++++++++--- .../nodes/primitives/component_transfer.rs | 10 +++++----- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/crates/svg-filters/src/types/nodes.rs b/crates/svg-filters/src/types/nodes.rs index b24251f..a1ca752 100644 --- a/crates/svg-filters/src/types/nodes.rs +++ b/crates/svg-filters/src/types/nodes.rs @@ -6,6 +6,7 @@ use self::{ primitives::{ blend::{Blend, BlendMode}, color_matrix::{ColorMatrix, ColorMatrixType}, + component_transfer::{ComponentTransfer, TransferFn}, composite::{Composite, CompositeOperator}, gaussian_blur::GaussianBlur, offset::Offset, @@ -145,9 +146,7 @@ impl Node { } pub fn composite_arithmetic(k1: f32, k2: f32, k3: f32, k4: f32) -> Self { - Self::simple(FePrimitive::Composite(Composite::arithmetic( - k1, k2, k3, k4, - ))) + Self::composite(CompositeOperator::Arithmetic { k1, k2, k3, k4 }) } pub fn gaussian_blur(v: u16) -> Self { @@ -161,4 +160,18 @@ impl Node { pub fn offset(dx: f32, dy: f32) -> Self { Self::simple(FePrimitive::Offset(Offset::new(dx, dy))) } + + pub fn component_transfer_rgba( + r: TransferFn, + g: TransferFn, + b: TransferFn, + a: TransferFn, + ) -> Self { + Self::simple(FePrimitive::ComponentTransfer(ComponentTransfer { + func_r: r, + func_g: g, + func_b: b, + func_a: a, + })) + } } diff --git a/crates/svg-filters/src/types/nodes/primitives/component_transfer.rs b/crates/svg-filters/src/types/nodes/primitives/component_transfer.rs index 3ccc039..abfd5a0 100644 --- a/crates/svg-filters/src/types/nodes/primitives/component_transfer.rs +++ b/crates/svg-filters/src/types/nodes/primitives/component_transfer.rs @@ -1,15 +1,15 @@ /// [feComponentTransfer](https://www.w3.org/TR/SVG11/filters.html#feComponentTransferElement) #[derive(Debug)] pub struct ComponentTransfer { - func_r: TransferFunction, - func_g: TransferFunction, - func_b: TransferFunction, - func_a: TransferFunction, + pub func_r: TransferFn, + pub func_g: TransferFn, + pub func_b: TransferFn, + pub func_a: TransferFn, } /// [transfer functions](https://www.w3.org/TR/SVG11/filters.html#transferFuncElements) #[derive(Debug)] -enum TransferFunction { +pub enum TransferFn { Identity, Table { table_values: Vec,