TransferFunction Class

A function that gives a new value to a component of each pixel: a feFuncR, feFuncG, feFuncB or feFuncA element of SVG.

public sealed class TransferFunction

Remarks

The function takes the value C of a straight color or of the alpha, as a fraction of one, and its result is clamped to the range from 0 to 1. With n values v0 to v(n-1): a table gives vk + (C - k / (n - 1)) (n - 1) (v(k+1) - vk) with k = floor(C (n - 1)) (v(n-1) for C = 1); a discrete table gives vk with k = floor(C n) (v(n-1) for C = 1); a linear function gives slope C + intercept; a gamma function gives amplitude C^exponent + offset, with Math.Pow. A table without values is the identity. Transfer functions are immutable and thread-safe.

Properties

NameDescription
AmplitudeGets the amplitude of a gamma function.
ExponentGets the exponent of a gamma function.
IdentityGets the function that changes nothing.
InterceptGets the intercept of a linear function.
KindGets the kind of the function.
OffsetGets the offset of a gamma function.
SlopeGets the slope of a linear function.
ValuesGets the values of a table: tableValues.

Gets the amplitude of a gamma function.

public double Amplitude { get; }

Property value

double

Gets the exponent of a gamma function.

public double Exponent { get; }

Property value

double

Gets the function that changes nothing.

public static TransferFunction Identity { get; }

Property value

TransferFunction

Gets the intercept of a linear function.

public double Intercept { get; }

Property value

double

Gets the kind of the function.

public TransferFunctionKind Kind { get; }

Property value

TransferFunctionKind

Gets the offset of a gamma function.

public double Offset { get; }

Property value

double

Gets the slope of a linear function.

public double Slope { get; }

Property value

double

Gets the values of a table: tableValues.

public IReadOnlyList<double> Values { get; }

Property value

IReadOnlyList<double>

Methods

NameDescription
CreateDiscrete(ReadOnlySpan<double>)Creates a function of steps: type="discrete".
CreateGamma(double, double, double)Creates a gamma function: type="gamma".
CreateLinear(double, double)Creates a linear function: type="linear".
CreateTable(ReadOnlySpan<double>)Creates a function that interpolates in a table: type="table".

CreateDiscrete(ReadOnlySpan<double>)

TransferFunction.cs

Creates a function of steps: type="discrete".

public static TransferFunction CreateDiscrete(params scoped ReadOnlySpan<double> values)

Parameters

values ReadOnlySpan<double>
The values of the steps, from 0 to 1. They are copied; without values, the function is the identity.

Returns

TransferFunction The function.

Exceptions

ArgumentException
A value is not a finite number.

CreateGamma(double, double, double)

TransferFunction.cs

Creates a gamma function: type="gamma".

public static TransferFunction CreateGamma(double amplitude, double exponent, double offset)

Parameters

amplitude double
The factor of the power.
exponent double
The exponent.
offset double
The value added.

Returns

TransferFunction The function.

Exceptions

ArgumentException
A parameter is not a finite number.

CreateLinear(double, double)

TransferFunction.cs

Creates a linear function: type="linear".

public static TransferFunction CreateLinear(double slope, double intercept)

Parameters

slope double
The factor of the value.
intercept double
The value added.

Returns

TransferFunction The function.

Exceptions

ArgumentException
A parameter is not a finite number.

CreateTable(ReadOnlySpan<double>)

TransferFunction.cs

Creates a function that interpolates in a table: type="table".

public static TransferFunction CreateTable(params scoped ReadOnlySpan<double> values)

Parameters

values ReadOnlySpan<double>
The values, spread evenly from 0 to 1. They are copied; without values, the function is the identity.

Returns

TransferFunction The function.

Exceptions

ArgumentException
A value is not a finite number.