Table of Contents

Class ErrorDiffusionKernel

Namespace
Egami.Quantization
Assembly
Egami.dll

A custom error-diffusion kernel for Kernel: how much of each pixel's error goes to which neighbours. Row 0 of Weights is the current row, with the current pixel at column Origin; the following rows are the rows below. Only entries to the right of the current pixel on row 0, and every entry below, may be non-zero, since the rest have been mapped already.

public sealed class ErrorDiffusionKernel
Inheritance
ErrorDiffusionKernel
Inherited Members

Examples

// A custom error-diffusion kernel: half the error to the right, a quarter down and a quarter down-left, at 80% strength,
// scanning every other row backwards.
ErrorDiffusionKernel kernel = new(new[,] { { 0, 0, 2 }, { 1, 1, 0 } }, divisor: 4, origin: 1);
photo.Apply(ops => ops.Quantize(new PaletteOptions { MaxColors = 8, Kernel = kernel, DitherStrength = 0.8f, Serpentine = true }), Ct);

Constructors

ErrorDiffusionKernel(int[,], int, int)

Creates a kernel.

public ErrorDiffusionKernel(int[,] weights, int divisor, int origin)

Parameters

weights int[,]

The weights, at most 8 rows and 16 columns; row 0 is the current row.

divisor int

What the weights are divided by: their sum spreads the whole error, a larger divisor less of it.

origin int

The column of weights where the current pixel is.

Exceptions

ArgumentNullException

weights is null.

ArgumentException

The weights are empty, too large or negative, put weight on the current pixel or before it, or sum to more than the divisor.

ArgumentOutOfRangeException

divisor is less than 1, or origin is outside the columns.

Properties

Divisor

Gets the divisor.

public int Divisor { get; }

Property Value

int

Origin

Gets the column of the current pixel.

public int Origin { get; }

Property Value

int

Weights

Gets a copy of the weights.

public int[,] Weights { get; }

Property Value

int[,]