FerroUI/ docs

Search guides, controls, Rust APIs, and XAML.

    GitHub ↗

    ConvolveMatrix

    struct · ferroui-base · v0.5.0

    struct ConvolveMatrix
    

    A matrix convolution of the pixels of a layer (Win2D ConvolveMatrixEffect, the SVG feConvolveMatrix filter primitive): each output pixel is the sum of the pixels around it weighted by the kernel, divided by the divisor, plus the bias.

    The kernel is applied as SVG and Direct2D apply it, turned by half a turn: with w and h the width and height of the kernel and (cx, cy) = (w / 2, h / 2) (rounded down) its target element, the output at (x, y) is

    sum over row i < h, column j < w of
        source(x - cx + j, y - cy + i) * kernel[(h - 1 - i) * w + (w - 1 - j)]
    

    divided by divisor and plus bias. The kernel steps over device pixels (Skia's matrix convolution does too).

    View source

    Members

    kernel_width

    kernel_width: u32
    

    The number of columns of the kernel, 1 to MAX_SIDE.

    Source

    kernel_height

    kernel_height: u32
    

    The number of rows of the kernel, 1 to MAX_SIDE.

    Source

    kernel

    kernel: [f32; 25]
    

    The elements of the kernel row by row; the first kernel_width * kernel_height are used, the rest are 0.

    Source

    divisor

    divisor: f32
    

    What the weighted sum is divided by (default 1; 0 is taken as 1).

    Source

    bias

    bias: f32
    

    What is added to the result, on the scale of a channel from 0 to 1 (default 0).

    Source

    clamp_edges

    clamp_edges: bool
    

    Whether the pixels beyond the edges of the layer are its edge pixels repeated (Win2D's Hard border mode) rather than transparent (the Soft mode, the default).

    Source

    preserve_alpha

    preserve_alpha: bool
    

    Whether the alpha is kept and the colours are convolved un-premultiplied (Win2D's PreserveAlpha); otherwise the four premultiplied channels are convolved (the default).

    Source

    MAX_SIDE

    const MAX_SIDE: u32
    

    The largest number of rows or columns of a kernel.

    Source

    MAX_ELEMENTS

    const MAX_ELEMENTS: usize
    

    The most elements of a kernel.

    Source

    new

    fn new(kernel_width: u32, kernel_height: u32, elements: &[f32]) -> Option<ConvolveMatrix>
    

    A kernel of kernel_width by kernel_height elements, elements row by row, with a divisor of 1, no bias, soft edges and the alpha convolved; None when a side is not 1 to MAX_SIDE or elements has another length.

    Source

    element_count

    fn element_count(self: &Self) -> usize
    

    The number of elements of the kernel that are used.

    Source

    elements

    fn elements(self: &Self) -> &[f32]
    

    The elements of the kernel that are used, row by row.

    Source

    target

    fn target(self: &Self) -> (u32, u32)
    

    The target element of the kernel, (w / 2, h / 2): the column and row of the kernel over the output pixel.

    Source

    gain

    fn gain(self: &Self) -> f32
    

    The factor of the weighted sum: one over the divisor (one for a divisor of 0 or not a number).

    Source

    weight

    fn weight(self: &Self, row: usize, column: usize) -> f32
    

    The weight of the source pixel column - cx pixels to the right and row - cy pixels below the output pixel: the element turned by half a turn (see the type).

    Source

    correlation_kernel

    fn correlation_kernel(self: &Self) -> Vec<f32>
    

    The elements in the order of a correlation (Skia's matrix convolution): the weight of row i, column j at i * w + j.

    Source

    apply_to_premultiplied_rgba8

    fn apply_to_premultiplied_rgba8(self: &Self, pixels: &mut [u8], width: usize, height: usize)
    

    Convolves premultiplied RGBA pixels of eight bits a channel (width by height, row by row), in place: the CPU reference of the drawing contexts. The edges of the pixels are the edges of the layer.

    Source

    Trait implementations

    • Send
    • Sync
    • Freeze
    • UnsafeUnpin
    • Unpin
    • UnwindSafe
    • RefUnwindSafe
    • PropertyValue
    • AnyValue
    • ClassDefaults
    • Borrow<T>
    • BorrowMut<T>
    • CloneToUninit
    • Into<U>
    • From<T>
    • TryInto<U>
    • TryFrom<U>
    • Any
    • ToOwned
    • ErasedDestructor
    • IntoEither
    • Clone
    • Copy
    • Debug
    • StructuralPartialEq
    • PartialEq
    • Default

    Availability

    Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.