svg-filters(primitives): start with feComponentTransfer

This commit is contained in:
Schrottkatze 2024-03-17 00:50:51 +01:00
parent 77bcb54b5e
commit 384fef5a81
No known key found for this signature in database
2 changed files with 21 additions and 8 deletions

View file

@ -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,
}))
}
}

View file

@ -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<f32>,