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).
Members
kernel_widthkernel_heightkerneldivisorbiasclamp_edgespreserve_alphaMAX_SIDEMAX_ELEMENTSnewelement_countelementstargetgainweightcorrelation_kernelapply_to_premultiplied_rgba8
kernel_width
kernel_width: u32
The number of columns of the kernel, 1 to MAX_SIDE.
kernel_height
kernel_height: u32
The number of rows of the kernel, 1 to MAX_SIDE.
kernel
kernel: [f32; 25]
The elements of the kernel row by row; the first
kernel_width * kernel_height are used, the rest are 0.
divisor
divisor: f32
What the weighted sum is divided by (default 1; 0 is taken as 1).
bias
bias: f32
What is added to the result, on the scale of a channel from 0 to 1 (default 0).
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).
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).
MAX_SIDE
const MAX_SIDE: u32
The largest number of rows or columns of a kernel.
MAX_ELEMENTS
const MAX_ELEMENTS: usize
The most elements of a kernel.
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.
element_count
fn element_count(self: &Self) -> usize
The number of elements of the kernel that are used.
elements
fn elements(self: &Self) -> &[f32]
The elements of the kernel that are used, row by row.
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.
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).
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).
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.
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.
Trait implementations
SendSyncFreezeUnsafeUnpinUnpinUnwindSafeRefUnwindSafePropertyValueAnyValueClassDefaultsBorrow<T>BorrowMut<T>CloneToUninitInto<U>From<T>TryInto<U>TryFrom<U>AnyToOwnedErasedDestructorIntoEitherCloneCopyDebugStructuralPartialEqPartialEqDefault
Availability
Extracted for aarch64-apple-darwin. Cargo features are listed in the crate index.