ConvolveMatrixPrimitive Class
A primitive that computes each pixel from the pixels around it with a matrix of weights: feConvolveMatrix of SVG.
public sealed class ConvolveMatrixPrimitive : FilterPrimitiveRemarks
With a matrix of orderX columns and orderY rows and a target (tx, ty), a pixel of the result is sum(I(x - tx + j, y - ty + i) K(orderX - j - 1, orderY - i - 1)) / divisor + bias: the matrix is turned by a half turn, as in SVG. The weights are one pixel of the canvas apart, whatever the transformation. What is read beyond the subregion of the primitive is given by ConvolveMatrixPrimitive.EdgeMode (the nearest pixel by default, as in SVG); inside it, an input is transparent outside its own subregion, so that a bias colors the pixels around a smaller input, as browsers do.
The bias is added to every component. Without ConvolveMatrixPrimitive.PreserveAlpha, the four components, the colors multiplied by their alpha, are computed, the alpha is clamped to the range from 0 to 1 and each color to the range from 0 to the alpha. With it, the straight colors are computed and clamped to the range from 0 to 1, and the pixel keeps its alpha.
- Inheritance
FilterPrimitiveConvolveMatrixPrimitive
Constructors
| Name | Description |
|---|---|
| ConvolveMatrixPrimitive(int, int, ReadOnlySpan<double>) | Initializes a new instance of the ConvolveMatrixPrimitive class. |
ConvolveMatrixPrimitive(int, int, ReadOnlySpan<double>)
ConvolveMatrixPrimitive.csInitializes a new instance of the ConvolveMatrixPrimitive class.
public ConvolveMatrixPrimitive(int orderX, int orderY, ReadOnlySpan<double> kernel)Parameters
orderXint- The number of columns of the matrix:
order. Must be between 1 and 255. orderYint- The number of rows of the matrix. Must be between 1 and 255.
kernelReadOnlySpan<double>- The weights, row by row:
kernelMatrix. They are copied.
Exceptions
ArgumentOutOfRangeException- An order is not between 1 and 255.
ArgumentException- The number of weights is not
orderX orderY, or a weight is not a finite number.
Properties
| Name | Description |
|---|---|
| Bias | Gets what is added to every component of the result: bias. |
| Divisor | Gets what the sum is divided by: divisor. Defaults to null: the sum of the weights, or 1 when it is zero. |
| EdgeMode | Gets what is read beyond the subregion of the primitive: edgeMode. Defaults to FilterEdgeMode.Duplicate. |
| Input | Gets the input: in. |
| Kernel | Gets the weights, row by row. |
| OrderX | Gets the number of columns of the matrix. |
| OrderY | Gets the number of rows of the matrix. |
| PreserveAlpha | Gets a value indicating whether the colors are computed without their alpha, which each pixel keeps: preserveAlpha. |
| TargetX | Gets the column of the matrix that is on the pixel: targetX. Defaults to floor(orderX / 2). |
| TargetY | Gets the row of the matrix that is on the pixel: targetY. Defaults to floor(orderY / 2). |
Gets what is added to every component of the result: bias.
public double Bias { get; init; }Divisor
ConvolveMatrixPrimitive.csGets what the sum is divided by: divisor. Defaults to null: the sum of the weights, or 1 when it is zero.
public double? Divisor { get; init; }EdgeMode
ConvolveMatrixPrimitive.csGets what is read beyond the subregion of the primitive: edgeMode. Defaults to FilterEdgeMode.Duplicate.
public FilterEdgeMode EdgeMode { get; init; }PreserveAlpha
ConvolveMatrixPrimitive.csTargetX
ConvolveMatrixPrimitive.csGets the column of the matrix that is on the pixel: targetX. Defaults to floor(orderX / 2).
public int TargetX { get; init; }TargetY
ConvolveMatrixPrimitive.csGets the row of the matrix that is on the pixel: targetY. Defaults to floor(orderY / 2).
public int TargetY { get; init; }