Filter Weighting Functions API
Weighting functions are responsive for pixel color weights, depending on how far pixels are from EWA ellipse center.
WeightingFunction interface
ts
interface WeightingFunction {
(x: number, support: number, windowSupport: number): number;
}
WeightingFunctionFactory interface
WeightingFunctionFactory
interface creates weighting functions.
ts
interface WeightingFunctionFactory<FactoryArgs extends number[] = number[]> {
create(...args: FactoryArgs): WeightingFunction;
}
The create()
method of weighting function factory may accept arguments which may be used to calculate weighting function arguments.
Example from lens source - CubicBC()
function factory:
ts
export class CubicBCFactory
implements WeightingFunctionFactory<[number, number]>
{
/**
* Creates cubicBC() function.
*
* @param b B value.
* @param c C value.
*/
create(b: number, c: number): WeightingFunction {
const p0 = (6 - 2 * b) / 6;
// const p1 = 0;
const p2 = (-18 + 12 * b + 6 * c) / 6;
const p3 = (12 - 9 * b - 6 * c) / 6;
const q0 = (8 * b + 24 * c) / 6;
const q1 = (-12 * b - 48 * c) / 6;
const q2 = (6 * b + 30 * c) / 6;
const q3 = (-1 * b - 6 * c) / 6;
return function cubicBC(x?: number): number {
if (typeof x === "number") {
if (x < 1) {
return p0 + x * (x * (p2 + x * p3));
} else if (x < 2) {
return q0 + x * (q1 + x * (q2 + x * q3));
}
}
return 0;
};
}
}
WeightingFunctionFactoryPool type
Pool of WeightingFunctionFactory
implementations, which keys are WeightingFunctionName enum values.
ts
interface WeightingFunctionFactoriesPoolKeyMap {
[WeightingFunctionName.BOX]: BoxFactory;
[WeightingFunctionName.CUBIC_BC]: CubicBCFactory;
[key: string]: WeightingFunctionFactory;
}
type WeightingFunctionFactoriesPool = Pool<
WeightingFunctionFactory,
WeightingFunctionFactoriesPoolKeyMap
>;