Skip to main content

FilterEffect

Enum FilterEffect 

Source
pub enum FilterEffect {
Show 16 variants Flood(AlphaColor<Srgb>), GaussianBlur(GaussianBlurFilter), DropShadow(DropShadow), ColorMatrix(ColorMatrix), Offset(Vec2), Composite(CompositeOperator), Blend(BlendMode), Morphology(MorphologyFilter), ConvolveMatrix(ConvolutionKernel), Turbulence(TurbulenceFilter), DisplacementMap(DisplacementMapFilter), ComponentTransfer(ComponentTransferFilter), Image(ExternalImageSource), Tile, DiffuseLighting(DiffuseLightingFilter), SpecularLighting(SpecularLightingFilter),
}
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(AlphaColor<Srgb>)

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).

§

GaussianBlur(GaussianBlurFilter)

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.

§

DropShadow(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

§

ColorMatrix(ColorMatrix)

Matrix-based color transformation.

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

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(Vec2)

Geometric offset/translation.

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

Positive values shift right or down.

§

Composite(CompositeOperator)

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.

§

Blend(BlendMode)

Blend two inputs using blend modes.

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

§

Morphology(MorphologyFilter)

Morphological operations (dilate/erode).

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

§

ConvolveMatrix(ConvolutionKernel)

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.

§

Turbulence(TurbulenceFilter)

Generate Perlin noise/turbulence patterns.

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

§

DisplacementMap(DisplacementMapFilter)

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.

§

ComponentTransfer(ComponentTransferFilter)

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.

§

Image(ExternalImageSource)

§

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(DiffuseLightingFilter)

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.

§

SpecularLighting(SpecularLightingFilter)

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.

Implementations§

Source§

impl FilterEffect

Source

pub fn blur(radius: f32) -> Self

Gaussian blur effect.

Applies a Gaussian blur to the input image. Larger radius values produce more blur. The blur is applied equally in all directions.

Source

pub fn drop_shadow( dx: f32, dy: f32, std_deviation: f32, color: AlphaColor<Srgb>, ) -> Self

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

Source

pub fn opacity(amount: f32) -> Self

Construct a CSS opacity() filter effect

Source

pub fn invert(amount: f32) -> Self

Construct a CSS invert() filter effect

Source

pub fn brightness(amount: f32) -> Self

Construct a CSS brightness() filter effect

Source

pub fn contrast(amount: f32) -> Self

Construct a CSS contrast() filter effect

Source

pub fn hue_rotate(angle_radians: f32) -> Self

Construct a CSS hue-rotate() filter effect

Source

pub fn saturate(amount: f32) -> Self

Construct a CSS saturate() filter effect

Source

pub fn sepia(amount: f32) -> Self

Construct a CSS sepia() filter effect

Source

pub fn grayscale(amount: f32) -> Self

Construct a CSS grayscale() filter effect

Source

pub fn expansion_rect(&self) -> Rect

Calculate the bounds expansion as a Rect in user space.

Returns a rectangle centered at the origin representing how much the filter expands the processing region in each direction. The rect coordinates are:

  • x0: negative left expansion
  • y0: negative top expansion
  • x1: positive right expansion
  • y1: positive bottom expansion

A Rect::ZERO means no expansion. This representation allows the expansion to be correctly transformed (including rotation) using standard rect transforms.

For example, a blur filter needs additional pixels around the edges (3*sigma). Most filters that don’t sample neighboring pixels return Rect::ZERO.

Trait Implementations§

Source§

impl Clone for FilterEffect

Source§

fn clone(&self) -> FilterEffect

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 FilterEffect

Source§

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

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

impl PartialEq for FilterEffect

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FilterEffect

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> 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.
Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,