import BitmapFilter from "./BitmapFilter"; declare namespace openfl.filters { /** * The ConvolutionFilter class applies a matrix convolution filter effect. A * convolution combines pixels in the input image with neighboring pixels to * produce an image. A wide variety of image effects can be achieved through * convolutions, including blurring, edge detection, sharpening, embossing, * and beveling. You can apply the filter to any display object (that is, * objects that inherit from the DisplayObject class), such as MovieClip, * SimpleButton, TextField, and Video objects, as well as to BitmapData * objects. * * To create a convolution filter, use the syntax `new ConvolutionFilter()`. * The use of filters depends on the object to which you apply the filter: * * * To apply filters to movie clips, text fields, buttons, and video, use * the `filters` property (inherited from DisplayObject). Setting the * `filters` property of an object does not modify the object, and you can * remove the filter by clearing the `filters` property. * * To apply filters to BitmapData objects, use the * `BitmapData.applyFilter()` method. Calling `applyFilter()` on a BitmapData * object takes the source BitmapData object and the filter object and * generates a filtered image as a result. * * If you apply a filter to a display object, the value of the * `cacheAsBitmap` property of the object is set to `true`. If you clear all * filters, the original value of `cacheAsBitmap` is restored. * * A filter is not applied if the resulting image exceeds the maximum * dimensions. In AIR 1.5 and Flash Player 10, the maximum is 8,191 pixels in * width or height, and the total number of pixels cannot exceed 16,777,215 * pixels. (So, if an image is 8,191 pixels wide, it can only be 2,048 pixels * high.) In Flash Player 9 and earlier and AIR 1.1 and earlier, the * limitation is 2,880 pixels in height and 2,880 pixels in width. For * example, if you zoom in on a large movie clip with a filter applied, the * filter is turned off if the resulting image exceeds maximum dimensions. * * @see `openfl.display.DisplayObject.filters` * @see `openfl.display.BitmapData.applyFilter` * */ export class ConvolutionFilter extends BitmapFilter { /** * Initializes a ConvolutionFilter instance with the specified * parameters. * * @param matrixX The _x_ dimension of the matrix (the number of * columns in the matrix). The default value is 0. * @param matrixY The _y_ dimension of the matrix (the number of * rows in the matrix). The default value is 0. * @param divisor The divisor used during matrix transformation. * The default value is 1. A divisor that is the sum * of all the matrix values evens out the overall * color intensity of the result. A value of 0 is * ignored and the default is used instead. * @param bias The bias to add to the result of the matrix * transformation. The default value is 0. * @param preserveAlpha A value of `false` indicates that the alpha value * is not preserved and that the convolution applies * to all channels, including the alpha channel. A * value of `true` indicates that the convolution * applies only to the color channels. The default * value is `true`. * @param clamp For pixels that are off the source image, a value * of `true` indicates that the input image is * extended along each of its borders as necessary * by duplicating the color values at the given edge * of the input image. A value of `false` indicates * that another color should be used, as specified * in the `color` and `alpha` properties. The * default is `true`. * @param color The hexadecimal color to substitute for pixels * that are off the source image. * @param alpha The alpha of the substitute color. * */ constructor(matrixX?: number, matrixY?: number, matrix?: Array, divisor?: number, bias?: number, preserveAlpha?: boolean, clamp?: boolean, color?: number, alpha?: number); /** * The alpha transparency value of the substitute color. Valid values are * 0 to 1.0. The default is 0. For example, .25 sets a transparency value * of 25%. * */ alpha: number; /** * The amount of bias to add to the result of the matrix transformation. * The bias increases the color value of each channel, so that dark * colors appear brighter. The default value is 0. * */ bias: number; /** * Indicates whether the image should be clamped. For pixels off the * source image, a value of `true` indicates that the input image is * extended along each of its borders as necessary by duplicating the * color values at each respective edge of the input image. A value of * `false` indicates that another color should be used, as specified in * the `color` and `alpha` properties. The default is `true`. * */ clamp: boolean; /** * The hexadecimal color to substitute for pixels that are off the source * image. It is an RGB value with no alpha component. The default is 0. * */ color: number; /** * The divisor used during matrix transformation. The default value is 1. * A divisor that is the sum of all the matrix values smooths out the * overall color intensity of the result. A value of 0 is ignored and the * default is used instead. * */ divisor: number; /** * An array of values used for matrix transformation. The number of items * in the array must equal `matrixX * matrixY`. * A matrix convolution is based on an _n_ x _m_ matrix, which describes * how a given pixel value in the input image is combined with its * neighboring pixel values to produce a resulting pixel value. Each * result pixel is determined by applying the matrix to the corresponding * source pixel and its neighboring pixels. * * For a 3 x 3 matrix convolution, the following formula is used for each * independent color channel: * * ``` * dst (x, y) = ((src (x-1, y-1) * a0 + src(x, y-1) * a1.... * src(x, y+1) * a7 + src (x+1,y+1) * a8) / divisor) + bias * ``` * * Certain filter specifications perform faster when run by a processor * that offers SSE (Streaming SIMD Extensions). The following are * criteria for faster convolution operations: * * * The filter must be a 3x3 filter. * * All the filter terms must be integers between -127 and +127. * * The sum of all the filter terms must not have an absolute value * greater than 127. * * If any filter term is negative, the divisor must be between 2.00001 * and 256. * * If all filter terms are positive, the divisor must be between 1.1 * and 256. * * The bias must be an integer. * * **Note:** If you create a ConvolutionFilter instance using the * constructor without parameters, the order you assign values to matrix * properties affects the behavior of the filter. In the following case, * the matrix array is assigned while the `matrixX` and `matrixY` * properties are still set to `0` (the default value): * * ```haxe * public var myfilter = new ConvolutionFilter(); * myfilter.matrix = [0, 0, 0, 0, 1, 0, 0, 0, 0]; * myfilter.matrixX = 3; * myfilter.matrixY = 3; * ``` * * In the following case, the matrix array is assigned while the * `matrixX` and `matrixY` properties are set to `3`: * * ```haxe * public var myfilter = new ConvolutionFilter(); * myfilter.matrixX = 3; * myfilter.matrixY = 3; * myfilter.matrix = [0, 0, 0, 0, 1, 0, 0, 0, 0]; * ``` * * @throws TypeError The Array is null when being set * */ get matrix(): Array; set matrix(value: Array) /** * The _x_ dimension of the matrix (the number of columns in the matrix). * The default value is 0. * */ matrixX: number; /** * The _y_ dimension of the matrix (the number of rows in the matrix). * The default value is 0. * */ matrixY: number; /** * Indicates if the alpha channel is preserved without the filter effect * or if the convolution filter is applied to the alpha channel as well * as the color channels. A value of `false` indicates that the * convolution applies to all channels, including the alpha channel. A * value of `true` indicates that the convolution applies only to the * color channels. The default value is `true`. * */ preserveAlpha: boolean; override clone(): BitmapFilter; } } export default openfl.filters.ConvolutionFilter;