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: f32Standard 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.
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
color: AlphaColor<Srgb>Shadow color with alpha channel. Alpha controls shadow opacity.
DropShadowOnly
Same as FilterPrimitive::DropShadow, but without compositing the original
layer on top of it.
Fields
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.
ColorMatrix
Matrix-based color transformation.
Applies a 4x5 matrix transformation to colors, allowing arbitrary color space transformations, hue shifts, and color adjustments.
Fields
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
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: CompositeOperatorPorter-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.).
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: MorphologyOperatorMorphological operator determining whether to erode or dilate.
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: ConvolutionKernelConvolution 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
turbulence_type: TurbulenceTypeType 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
x_channel: ColorChannelColor channel from the displacement map used for X-axis displacement.
y_channel: ColorChannelColor 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
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
light_source: LightSourceConfiguration 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
specular_exponent: f32Specular reflection exponent. Controls highlight sharpness (higher = sharper).
light_source: LightSourceConfiguration of the light source (point, distant, or spot).
Implementations§
Source§impl FilterPrimitive
impl FilterPrimitive
Sourcepub fn filter_expansion(&self) -> Rect
pub fn filter_expansion(&self) -> Rect
The filter expansion of the primitive, see Filter::filter_expansion.
Sourcepub fn source_expansion(&self) -> Rect
pub fn source_expansion(&self) -> Rect
The source expansion of the primitive, see Filter::source_expansion.
Trait Implementations§
Source§impl Clone for FilterPrimitive
impl Clone for FilterPrimitive
Source§fn clone(&self) -> FilterPrimitive
fn clone(&self) -> FilterPrimitive
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for FilterPrimitive
impl Debug for FilterPrimitive
Source§impl PartialEq for FilterPrimitive
impl PartialEq for FilterPrimitive
Source§fn eq(&self, other: &FilterPrimitive) -> bool
fn eq(&self, other: &FilterPrimitive) -> bool
self and other values to be equal, and is used by ==.