Skip to main content

FilterPrimitive

Enum FilterPrimitive 

Source
pub enum FilterPrimitive {
Show 17 variants Flood { color: AlphaColor<Srgb>, }, GaussianBlur { std_deviation: f32, edge_mode: EdgeMode, }, DropShadow { dx: f32, dy: f32, std_deviation: f32, color: AlphaColor<Srgb>, edge_mode: EdgeMode, }, DropShadowOnly { dx: f32, dy: f32, std_deviation: f32, color: AlphaColor<Srgb>, edge_mode: EdgeMode, }, ColorMatrix { matrix: [f32; 20], }, Offset { dx: f32, dy: f32, }, Composite { operator: CompositeOperator, }, Blend { mode: BlendMode, }, Morphology { operator: MorphologyOperator, radius: f32, }, ConvolveMatrix { kernel: ConvolutionKernel, }, Turbulence { base_frequency: f32, num_octaves: u32, seed: u32, turbulence_type: TurbulenceType, }, DisplacementMap { scale: f32, x_channel: ColorChannel, y_channel: ColorChannel, }, ComponentTransfer { red_function: Option<TransferFunction>, green_function: Option<TransferFunction>, blue_function: Option<TransferFunction>, alpha_function: Option<TransferFunction>, }, Image { image_id: u32, transform: Option<[f32; 6]>, }, Tile, DiffuseLighting { surface_scale: f32, diffuse_constant: f32, kernel_unit_length: f32, light_source: LightSource, }, SpecularLighting { surface_scale: f32, specular_constant: f32, specular_exponent: f32, kernel_unit_length: f32, light_source: LightSource, },
}
Expand description

Low-level filter primitives for granular control (SVG filter primitives).

These are the building blocks for complex filter effects, corresponding to SVG filter primitives. They can be combined in a FilterGraph to create sophisticated visual effects.

See: https://drafts.fxtf.org/filter-effects/#FilterPrimitivesOverview

Variants§

§

Flood

Generate a solid color fill.

Creates a rectangle filled with the specified color, typically used as input to other filter operations (e.g., for colored shadows).

Fields

§color: AlphaColor<Srgb>

Fill color with alpha channel.

§

GaussianBlur

Gaussian blur filter.

Applies a Gaussian blur using the specified standard deviation (σ). The effective blur range (distance over which pixels are sampled) is approximately 3 × std_deviation, as this captures ~99.7% of the Gaussian distribution.

Fields

§std_deviation: f32

Standard deviation for the blur kernel. Larger values create more blur. Must be non-negative. A value of 0 means no blur.

This directly corresponds to the σ (sigma) parameter in the Gaussian function. The visible blur effect extends approximately 3σ in each direction.

TODO: Per the W3C specification, this should support separate x and y values. The spec allows stdDeviation to be either one number (applied to both axes) or two numbers (first for x-axis, second for y-axis). Currently only uniform blur is supported. Consider changing to (f32, f32) or a dedicated type.

§edge_mode: EdgeMode

Edge mode determining how pixels beyond the input bounds are handled.

§

DropShadow

Drop shadow effect (compound primitive).

Creates a drop shadow by blurring the input’s alpha channel, offsetting it, and compositing it with the original. This is a compound operation that combines multiple primitive operations into one.

See: https://drafts.fxtf.org/filter-effects-2/#feDropShadowElement

Fields

§dx: f32

Horizontal offset of the shadow in pixels. Positive values shift right.

§dy: f32

Vertical offset of the shadow in pixels. Positive values shift down.

§std_deviation: f32

Blur standard deviation for the shadow. Larger values create softer shadows.

§color: AlphaColor<Srgb>

Shadow color with alpha channel. Alpha controls shadow opacity.

§edge_mode: EdgeMode

Edge mode for handling boundaries during blur operation. Default is EdgeMode::None per SVG spec.

§

DropShadowOnly

Same as FilterPrimitive::DropShadow, but without compositing the original layer on top of it.

Fields

§dx: f32

Horizontal offset of the shadow in pixels. Positive values shift right.

§dy: f32

Vertical offset of the shadow in pixels. Positive values shift down.

§std_deviation: f32

Blur standard deviation for the shadow. Larger values create softer shadows.

§color: AlphaColor<Srgb>

Color applied to the blurred, offset input alpha mask. The input’s color channels are ignored, and this color’s alpha controls shadow opacity.

§edge_mode: EdgeMode

Edge mode for handling boundaries during blur operation.

§

ColorMatrix

Matrix-based color transformation.

Applies a 4x5 matrix transformation to colors, allowing arbitrary color space transformations, hue shifts, and color adjustments.

Fields

§matrix: [f32; 20]

4x5 color transformation matrix: 4 rows (R,G,B,A) × 5 columns (R,G,B,A,offset). Each output channel is computed as a linear combination of input channels plus offset.

§

Offset

Geometric offset/translation.

Shifts the input image by the specified offset. Useful for creating shadow effects or positioning elements in a filter graph.

Fields

§dx: f32

Horizontal offset in pixels. Positive values shift right.

§dy: f32

Vertical offset in pixels. Positive values shift down.

§

Composite

Composite two inputs using Porter-Duff compositing operations.

Combines two input images using standard compositing operators (over, in, out, atop, xor) or custom arithmetic combination.

Fields

§operator: CompositeOperator

Porter-Duff compositing operator to apply.

§

Blend

Blend two inputs using blend modes.

Combines two input images using Photoshop-style blend modes (multiply, screen, overlay, etc.).

Fields

§mode: BlendMode

Blend mode determining how colors are combined.

§

Morphology

Morphological operations (dilate/erode).

Expands (dilate) or contracts (erode) the shapes in the input image. Useful for creating outline effects or cleaning up edges.

Fields

§operator: MorphologyOperator

Morphological operator determining whether to erode or dilate.

§radius: f32

Operation radius in pixels. Larger values create stronger effects.

§

ConvolveMatrix

Custom convolution kernel for image processing.

Applies a custom convolution matrix to the input image, enabling effects like sharpening, edge detection, embossing, and custom filters.

Fields

§kernel: ConvolutionKernel

Convolution kernel specification including size, values, and normalization.

§

Turbulence

Generate Perlin noise/turbulence patterns.

Creates procedural noise patterns useful for textures, clouds, marble effects, and other organic-looking randomness.

Fields

§base_frequency: f32

Base frequency for noise generation. Higher values create finer detail.

§num_octaves: u32

Number of octaves for fractal noise. More octaves add finer detail.

§seed: u32

Random seed for reproducible noise generation.

§turbulence_type: TurbulenceType

Type of noise: smooth fractal or more chaotic turbulence.

§

DisplacementMap

Displace pixels using a displacement map.

Uses the color values from a second input to spatially displace pixels in the primary input, creating warping and distortion effects.

Fields

§scale: f32

Scale factor controlling the displacement intensity.

§x_channel: ColorChannel

Color channel from the displacement map used for X-axis displacement.

§y_channel: ColorChannel

Color channel from the displacement map used for Y-axis displacement.

§

ComponentTransfer

Per-channel component transfer using lookup tables or functions.

Applies independent transfer functions to each color channel, enabling color corrections, gamma adjustments, and custom mappings.

Fields

§red_function: Option<TransferFunction>

Transfer function applied to the red channel (None = identity).

§green_function: Option<TransferFunction>

Transfer function applied to the green channel (None = identity).

§blue_function: Option<TransferFunction>

Transfer function applied to the blue channel (None = identity).

§alpha_function: Option<TransferFunction>

Transfer function applied to the alpha channel (None = identity).

§

Image

Reference an external image as filter input.

Allows using pre-existing images (from an atlas or resource) as input to filter operations, useful for texturing and overlays.

Fields

§image_id: u32

Identifier referencing an image in the resource atlas.

§transform: Option<[f32; 6]>

Optional 2D affine transformation matrix [a, b, c, d, e, f]. Transforms the image before using it as filter input.

§

Tile

Tile the input to fill the filter region.

Repeats the input image to fill the entire filter primitive subregion, creating a tiling/repeating pattern.

§

DiffuseLighting

Diffuse lighting simulation.

Creates a lighting effect by treating the input’s alpha channel as a height map and calculating diffuse (matte) reflection from a light source.

Fields

§surface_scale: f32

Surface scale factor for converting alpha values to heights.

§diffuse_constant: f32

Diffuse reflection constant (kd). Controls lighting intensity.

§kernel_unit_length: f32

Kernel unit length for gradient calculations in user space.

§light_source: LightSource

Configuration of the light source (point, distant, or spot).

§

SpecularLighting

Specular lighting simulation.

Creates a lighting effect by treating the input’s alpha channel as a height map and calculating specular (shiny) reflection highlights from a light source.

Fields

§surface_scale: f32

Surface scale factor for converting alpha values to heights.

§specular_constant: f32

Specular reflection constant (ks). Controls highlight intensity.

§specular_exponent: f32

Specular reflection exponent. Controls highlight sharpness (higher = sharper).

§kernel_unit_length: f32

Kernel unit length for gradient calculations in user space.

§light_source: LightSource

Configuration of the light source (point, distant, or spot).

Implementations§

Source§

impl FilterPrimitive

Source

pub fn filter_expansion(&self) -> Rect

The filter expansion of the primitive, see Filter::filter_expansion.

Source

pub fn source_expansion(&self) -> Rect

The source expansion of the primitive, see Filter::source_expansion.

Trait Implementations§

Source§

impl Clone for FilterPrimitive

Source§

fn clone(&self) -> FilterPrimitive

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for FilterPrimitive

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for FilterPrimitive

Source§

fn eq(&self, other: &FilterPrimitive) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for FilterPrimitive

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.