image-in-browser
Version:
Package for encoding / decoding images, transforming images, applying filters, drawing primitives on images on the client side (no need for server Node.js)
87 lines (86 loc) • 3.37 kB
TypeScript
/** @format */
import { Channel } from '../color/channel.js';
import { MemoryImage } from '../image/image.js';
/**
* Options for applying a separable kernel.
*/
export interface SeparableKernelApplyOptions {
/** Source image. */
src: MemoryImage;
/** Destination image. */
dst: MemoryImage;
/** Apply horizontally if true, otherwise vertically. */
horizontal?: boolean;
/** Channel to use for masking. */
maskChannel?: Channel;
/** Optional mask image. */
mask?: MemoryImage;
}
/**
* A kernel object to use with **separableConvolution** filter.
*/
export declare class SeparableKernel {
/** Coefficients of the kernel. */
private readonly _coefficients;
/** Size of the kernel. */
private readonly _size;
/**
* Get the number of coefficients in the kernel.
*
* @returns {number} The number of coefficients.
*/
get length(): number;
/**
* Create a separable convolution kernel for the given **size**.
* @param {number} size - The size of the kernel.
*/
constructor(size: number);
/**
* Reflect the index within the bounds of the image.
* @param {number} max - The maximum index.
* @param {number} x - The current index.
* @returns {number} The reflected index.
*/
private reflect;
/**
* Apply the kernel coefficients to a line of pixels.
* @param {MemoryImage} src - Source image.
* @param {MemoryImage} dst - Destination image.
* @param {number} y - The y-coordinate of the line.
* @param {number} width - The width of the line.
* @param {boolean} horizontal - Apply horizontally if true, otherwise vertically.
* @param {Channel} maskChannel - Channel to use for masking.
* @param {MemoryImage} [mask] - Optional mask image.
*/
private applyCoefficientsLine;
/**
* Get a coefficient from the kernel.
* @param {number} index - The index of the coefficient.
* @returns {number} The coefficient value.
*/
getCoefficient(index: number): number;
/**
* Set a coefficient in the kernel.
* @param {number} index - The index of the coefficient.
* @param {number} c - The coefficient value.
*/
setCoefficient(index: number, c: number): void;
/**
* Apply the kernel to the **src** image, storing the results in **dst**,
* for a single dimension. If **horizontal** is true, the filter will be
* applied to the horizontal axis, otherwise it will be applied to the
* vertical axis.
* @param {SeparableKernelApplyOptions} opt - Options for applying the kernel.
* @param {MemoryImage} opt.src - The source image to which the kernel is applied.
* @param {MemoryImage} opt.dst - The destination image where the results are stored.
* @param {boolean} [opt.horizontal=true] - A boolean indicating whether to apply the filter horizontally. Defaults to true.
* @param {Channel} [opt.maskChannel=Channel.luminance] - The channel to use for the mask. Defaults to Channel.luminance.
* @param {MemoryImage} [opt.mask] - An optional mask to apply during the filtering process.
*/
apply(opt: SeparableKernelApplyOptions): void;
/**
* Scale all of the coefficients by **s**.
* @param {number} s - The scale factor.
*/
scaleCoefficients(s: number): void;
}