Skip to main content

ImageFilter

Enum ImageFilter 

Source
pub enum ImageFilter {
    Blur {
        sigma_x: f64,
        sigma_y: f64,
        bounds: Option<Rect>,
    },
    Color(ColorFilter),
    Compose {
        outer: Arc<ImageFilter>,
        inner: Arc<ImageFilter>,
    },
    Matrix {
        data: Matrix4,
        filter_quality: FilterQuality,
    },
    Shader {
        shader: RuntimeShader,
        filter_quality: FilterQuality,
    },
}
Expand description

A filter operation to apply to a raster image.

See also:

  • BackdropFilter, a widget that applies ImageFilter to its rendering.
  • ImageFiltered, a widget that applies ImageFilter to its children.
  • SceneBuilder.pushBackdropFilter, which is the low-level API for using this class as a backdrop filter.
  • SceneBuilder.pushImageFilter, which is the low-level API for using this class as a child layer filter.

Variants§

§

Blur

A Gaussian blur; Dart’s _GaussianBlurImageFilter.

Fields

§sigma_x: f64

The standard deviation along the horizontal axis.

§sigma_y: f64

The standard deviation along the vertical axis.

§bounds: Option<Rect>

The area the blur is confined to, when given.

§

Color(ColorFilter)

A ColorFilter used as an image filter; Dart’s ColorFilter implements ImageFilter.

§

Compose

outer applied to the result of inner; Dart’s _ComposeImageFilter.

Fields

§outer: Arc<ImageFilter>

The filter that receives the filtered result of inner.

§inner: Arc<ImageFilter>

The filter that receives the original input.

§

Matrix

The input moved by a matrix; Dart’s _MatrixImageFilter, made by ImageFilter::matrix.

Fields

§data: Matrix4

The matrix that moves the input.

§filter_quality: FilterQuality

The quality the moved input is sampled at.

§

Shader

A FragmentShader’s program run over the input; Dart’s _FragmentShaderImageFilter, made by ImageFilter::shader.

Fields

§shader: RuntimeShader

The shader’s uniforms and images as they were when the filter was made, its first image left for the input, which is sampled at filter_quality.

§filter_quality: FilterQuality

The quality the input is sampled at.

Implementations§

Source§

impl ImageFilter

Source

pub const fn blur(sigma_x: f64, sigma_y: f64) -> ImageFilter

Creates an image filter that applies a Gaussian blur.

Source

pub fn bounds(self, bounds: Rect) -> ImageFilter

Dart ImageFilter.blur(bounds:).

Source

pub const fn matrix( matrix4: Matrix4, filter_quality: FilterQuality, ) -> ImageFilter

Creates an image filter that applies a matrix transformation.

For example, applying a positive scale matrix (see Matrix4.diagonal3) when used with BackdropFilter would magnify the background image.

The filter_quality argument sets the quality level the moved input is sampled at; Flutter’s default is FilterQuality::Medium.

Source

pub fn compose(outer: ImageFilter, inner: ImageFilter) -> ImageFilter

Composes the inner filter with outer, to combine their effects.

Creates a single ImageFilter that when applied, has the same effect as subsequently applying inner and outer, i.e., result = outer(inner(source)).

Source

pub fn shader( shader: &FragmentShader, filter_quality: FilterQuality, ) -> ImageFilter

Creates an image filter from a FragmentShader.

The fragment shader provided here has additional requirements to be used by the engine for filtering. The first uniform value must be a vec2, this will be set by the engine to the size of the bound texture. There must also be at least one image, the first of which will be set by the engine to contain the filter input.

The filter_quality argument sets the quality level used to sample the filter input; Flutter’s default is FilterQuality::None.

For example, the following is a valid fragment shader that can be used with this API. Note that the uniform names are not required to have any particular value.

struct Uniforms { u_size: vec2<f32>, u_time: f32 }
@group(2) @binding(0) var<uniform> u: Uniforms;
@group(1) @binding(0) var u_texture_input: texture_2d<f32>;
@group(1) @binding(1) var u_texture_input_sampler: sampler;

fn shade(position: vec2<f32>) -> vec4<f32> {
    let uv = position / u.u_size;
    return textureSampleLevel(u_texture_input, u_texture_input_sampler, uv, 0.0) * u.u_time;
}

The uniforms and images are those shader has now; setting them afterwards changes the filter made next, not this one.

§Panics

Where the shader’s first uniform is not a vec2 or it has no image, as Dart throws a StateError.

Source

pub const fn is_shader_filter_supported() -> bool

Whether ImageFilter::shader is supported on the current backend: always, as valo runs every shader the way Impeller does.

Source

pub fn debug_short_description(&self) -> String

Dart’s debugShortDescription.

Source§

impl ImageFilter

Source

pub fn to_valo(&self) -> ImageFilter

The valo filter that replays this one, step for step and in the same order.

Trait Implementations§

Source§

impl Clone for ImageFilter

Source§

fn clone(&self) -> Self

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 ImageFilter

Source§

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

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

impl Display for ImageFilter

Source§

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

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

impl PartialEq for ImageFilter

Source§

fn eq(&self, other: &Self) -> 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 ImageFilter

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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