UNPKG

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)

459 lines (458 loc) 20.2 kB
/** * @format */ import { InputBuffer } from '../../common/input-buffer.js'; /** * Class representing the VP8 filter operations. */ export declare class VP8Filter { constructor(); /** * Multiplies two numbers and shifts the result right by 16 bits. * @param {number} a - The first number. * @param {number} b - The second number. * @returns {number} The result of the multiplication shifted right by 16 bits. */ private static mul; /** * Stores a value in the destination buffer after clipping. * @param {InputBuffer<Uint8Array>} dst - The destination buffer. * @param {number} di - The destination index. * @param {number} x - The x-coordinate. * @param {number} y - The y-coordinate. * @param {number} v - The value to store. */ private static store; /** * Stores values in the destination buffer for a 2x2 block. * @param {InputBuffer<Uint8Array>} dst - The destination buffer. * @param {number} y - The y-coordinate. * @param {number} dc - The DC value. * @param {number} d - The D value. * @param {number} c - The C value. */ private static store2; /** * Initializes the lookup tables used for filtering. */ private static initTables; /** * Clips a value to the range [0, 255]. * @param {number} v - The value to clip. * @returns {number} The clipped value. */ private static clip8b; /** * Computes the average of three numbers. * @param {number} a - The first number. * @param {number} b - The second number. * @param {number} c - The third number. * @returns {number} The average of the three numbers. */ private static avg3; /** * Computes the average of two numbers. * @param {number} a - The first number. * @param {number} b - The second number. * @returns {number} The average of the two numbers. */ private static avg2; /** * Vertical edge filtering for a 4x4 block. * @param {InputBuffer<Uint8Array>} dst - The destination buffer. */ private static ve4; /** * Horizontal edge filtering for a 4x4 block. * @param {InputBuffer<Uint8Array>} dst - The destination buffer. */ private static he4; /** * DC edge filtering for a 4x4 block. * @param {InputBuffer<Uint8Array>} dst - The destination buffer. */ private static dc4; /** * True motion filtering for a block of given size. * @param {InputBuffer<Uint8Array>} dst - The destination buffer. * @param {number} size - The size of the block. */ private static trueMotion; /** * True motion filtering for a 4x4 block. * @param {InputBuffer<Uint8Array>} dst - The destination buffer. */ private static tm4; /** * True motion filtering for an 8x8 block. * @param {InputBuffer<Uint8Array>} dst - The destination buffer. */ private static tm8uv; /** * True motion filtering for a 16x16 block. * @param {InputBuffer<Uint8Array>} dst - The destination buffer. */ private static tm16; /** * Computes the destination index for a given x and y coordinate. * @param {number} x - The x-coordinate. * @param {number} y - The y-coordinate. * @returns {number} The destination index. */ private static dst; /** * Down-right filtering for a 4x4 block. * @param {InputBuffer<Uint8Array>} dst - The destination buffer. */ private static rd4; /** * Down-left filtering for a 4x4 block. * @param {InputBuffer<Uint8Array>} dst - The destination buffer. */ private static ld4; /** * Vertical-right filtering for a 4x4 block. * @param {InputBuffer<Uint8Array>} dst - The destination buffer. */ private static vr4; /** * Vertical-left filtering for a 4x4 block. * @param {InputBuffer<Uint8Array>} dst - The destination buffer. */ private static vl4; /** * Horizontal-up filtering for a 4x4 block. * @param {InputBuffer<Uint8Array>} dst - The destination buffer. */ private static hu4; /** * Applies a horizontal-down filter to the destination buffer. * * @param {InputBuffer<Uint8Array>} dst - The destination buffer of type InputBuffer containing Uint8Array. */ private static hd4; /** * Applies a filter to the input buffer based on specified thresholds and strides. * * @param {InputBuffer<Uint8Array>} p - The input buffer containing the data to be filtered. * @param {number} hstride - The horizontal stride, which determines the step size in the horizontal direction. * @param {number} vstride - The vertical stride, which determines the step size in the vertical direction. * @param {number} size - The number of elements to process in the buffer. * @param {number} thresh - The threshold value used to determine if filtering is needed. * @param {number} ithresh - The inner threshold value used in the filtering decision process. * @param {number} hevThresh - The high edge variance threshold used to decide between different filtering methods. */ private filterLoop26; /** * Filters a loop with specific parameters. * @param {InputBuffer<Uint8Array>} p - The input buffer. * @param {number} hstride - Horizontal stride. * @param {number} vstride - Vertical stride. * @param {number} size - Size of the loop. * @param {number} thresh - Threshold value. * @param {number} ithresh - Inner threshold value. * @param {number} hevThresh - HEV threshold value. */ private filterLoop24; /** * Applies a 2-pixel filter. * @param {InputBuffer<Uint8Array>} p - The input buffer. * @param {number} step - Step size. */ private doFilter2; /** * Applies a 4-pixel filter. * @param {InputBuffer<Uint8Array>} p - The input buffer. * @param {number} step - Step size. */ private doFilter4; /** * Applies a 6-pixel filter. * @param {InputBuffer<Uint8Array>} p - The input buffer. * @param {number} step - Step size. */ private doFilter6; /** * Determines if high edge variance (HEV) is present. * @param {InputBuffer<Uint8Array>} p - The input buffer. * @param {number} step - Step size. * @param {number} thresh - Threshold value. * @returns {boolean} True if HEV is present, false otherwise. */ private hev; /** * Determines if filtering is needed. * @param {InputBuffer<Uint8Array>} p - The input buffer. * @param {number} step - Step size. * @param {number} thresh - Threshold value. * @returns {boolean} True if filtering is needed, false otherwise. */ private needsFilter; /** * Determines if filtering is needed with additional parameters. * @param {InputBuffer<Uint8Array>} p - The input buffer. * @param {number} step - Step size. * @param {number} t - Threshold value. * @param {number} it - Inner threshold value. * @returns {boolean} True if filtering is needed, false otherwise. */ private needsFilter2; /** * Applies a simple vertical filter on 16 pixels. * @param {InputBuffer<Uint8Array>} p - The input buffer. * @param {number} stride - Stride value. * @param {number} threshold - Threshold value. */ simpleVFilter16(p: InputBuffer<Uint8Array>, stride: number, threshold: number): void; /** * Applies a simple horizontal filter on 16 pixels. * @param {InputBuffer<Uint8Array>} p - The input buffer. * @param {number} stride - Stride value. * @param {number} threshold - Threshold value. */ simpleHFilter16(p: InputBuffer<Uint8Array>, stride: number, threshold: number): void; /** * Applies a simple vertical filter on 16 pixels with inner edges. * @param {InputBuffer<Uint8Array>} p - The input buffer. * @param {number} stride - Stride value. * @param {number} threshold - Threshold value. */ simpleVFilter16i(p: InputBuffer<Uint8Array>, stride: number, threshold: number): void; /** * Applies a simple horizontal filter on 16 pixels with inner edges. * @param {InputBuffer<Uint8Array>} p - The input buffer. * @param {number} stride - Stride value. * @param {number} threshold - Threshold value. */ simpleHFilter16i(p: InputBuffer<Uint8Array>, stride: number, threshold: number): void; /** * Applies a vertical filter on macroblock edges. * @param {InputBuffer<Uint8Array>} p - The input buffer. * @param {number} stride - Stride value. * @param {number} thresh - Threshold value. * @param {number} iThreshold - Inner threshold value. * @param {number} hevThreshold - HEV threshold value. */ vFilter16(p: InputBuffer<Uint8Array>, stride: number, thresh: number, iThreshold: number, hevThreshold: number): void; /** * Applies a horizontal filter on macroblock edges. * @param {InputBuffer<Uint8Array>} p - The input buffer. * @param {number} stride - Stride value. * @param {number} thresh - Threshold value. * @param {number} iThreshold - Inner threshold value. * @param {number} hevThreshold - HEV threshold value. */ hFilter16(p: InputBuffer<Uint8Array>, stride: number, thresh: number, iThreshold: number, hevThreshold: number): void; /** * Applies a vertical filter on three inner edges. * @param {InputBuffer<Uint8Array>} p - The input buffer. * @param {number} stride - Stride value. * @param {number} thresh - Threshold value. * @param {number} iThreshold - Inner threshold value. * @param {number} hevThreshold - HEV threshold value. */ vFilter16i(p: InputBuffer<Uint8Array>, stride: number, thresh: number, iThreshold: number, hevThreshold: number): void; /** * Applies a horizontal filter on three inner edges. * @param {InputBuffer<Uint8Array>} p - The input buffer. * @param {number} stride - Stride value. * @param {number} thresh - Threshold value. * @param {number} iThreshold - Inner threshold value. * @param {number} hevThreshold - HEV threshold value. */ hFilter16i(p: InputBuffer<Uint8Array>, stride: number, thresh: number, iThreshold: number, hevThreshold: number): void; /** * Applies an 8-pixel wide vertical filter for chroma filtering. * @param {InputBuffer<Uint8Array>} u - The U component input buffer. * @param {InputBuffer<Uint8Array>} v - The V component input buffer. * @param {number} stride - Stride value. * @param {number} thresh - Threshold value. * @param {number} iThreshold - Inner threshold value. * @param {number} hevThreshold - HEV threshold value. */ vFilter8(u: InputBuffer<Uint8Array>, v: InputBuffer<Uint8Array>, stride: number, thresh: number, iThreshold: number, hevThreshold: number): void; /** * Applies an 8-pixel wide horizontal filter for chroma filtering. * @param {InputBuffer<Uint8Array>} u - The U component input buffer. * @param {InputBuffer<Uint8Array>} v - The V component input buffer. * @param {number} stride - Stride value. * @param {number} thresh - Threshold value. * @param {number} iThreshold - Inner threshold value. * @param {number} hevThreshold - HEV threshold value. */ hFilter8(u: InputBuffer<Uint8Array>, v: InputBuffer<Uint8Array>, stride: number, thresh: number, iThreshold: number, hevThreshold: number): void; /** * Applies an 8-pixel wide vertical filter on inner edges for chroma filtering. * @param {InputBuffer<Uint8Array>} u - The U component input buffer. * @param {InputBuffer<Uint8Array>} v - The V component input buffer. * @param {number} stride - Stride value. * @param {number} thresh - Threshold value. * @param {number} iThreshold - Inner threshold value. * @param {number} hevThreshold - HEV threshold value. */ vFilter8i(u: InputBuffer<Uint8Array>, v: InputBuffer<Uint8Array>, stride: number, thresh: number, iThreshold: number, hevThreshold: number): void; /** * Applies an 8-pixel wide horizontal filter on inner edges for chroma filtering. * @param {InputBuffer<Uint8Array>} u - The U component input buffer. * @param {InputBuffer<Uint8Array>} v - The V component input buffer. * @param {number} stride - Stride value. * @param {number} thresh - Threshold value. * @param {number} iThreshold - Inner threshold value. * @param {number} hevThreshold - HEV threshold value. */ hFilter8i(u: InputBuffer<Uint8Array>, v: InputBuffer<Uint8Array>, stride: number, thresh: number, iThreshold: number, hevThreshold: number): void; /** * Transforms a block of data from the source buffer to the destination buffer. * @param {InputBuffer<Int16Array>} src - The source buffer containing Int16Array data. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. */ transformOne(src: InputBuffer<Int16Array>, dst: InputBuffer<Uint8Array>): void; /** * Transforms a block of data from the source buffer to the destination buffer. * Optionally performs the transformation twice. * @param {InputBuffer<Int16Array>} src - The source buffer containing Int16Array data. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. * @param {boolean} doTwo - A boolean flag indicating whether to perform the transformation twice. */ transform(src: InputBuffer<Int16Array>, dst: InputBuffer<Uint8Array>, doTwo: boolean): void; /** * Transforms UV components of a block of data from the source buffer to the destination buffer. * @param {InputBuffer<Int16Array>} src - The source buffer containing Int16Array data. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. */ transformUV(src: InputBuffer<Int16Array>, dst: InputBuffer<Uint8Array>): void; /** * Transforms DC components of a block of data from the source buffer to the destination buffer. * @param {InputBuffer<Int16Array>} src - The source buffer containing Int16Array data. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. */ transformDC(src: InputBuffer<Int16Array>, dst: InputBuffer<Uint8Array>): void; /** * Transforms DC and UV components of a block of data from the source buffer to the destination buffer. * @param {InputBuffer<Int16Array>} src - The source buffer containing Int16Array data. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. */ transformDCUV(src: InputBuffer<Int16Array>, dst: InputBuffer<Uint8Array>): void; /** * Simplified transform when only src.getByte(0), src.getByte(1) and src.getByte(4) are non-zero. * @param {InputBuffer<Int16Array>} src - The source buffer containing Int16Array data. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. */ transformAC3(src: InputBuffer<Int16Array>, dst: InputBuffer<Uint8Array>): void; /** * Performs a vertical edge filtering on a 16x16 block. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. */ static ve16(dst: InputBuffer<Uint8Array>): void; /** * Performs a horizontal edge filtering on a 16x16 block. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. */ static he16(dst: InputBuffer<Uint8Array>): void; /** * Fills a 16x16 block with a specified value. * @param {number} v - The value to fill the block with. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. */ static put16(v: number, dst: InputBuffer<Uint8Array>): void; /** * Computes the DC value for a 16x16 block and fills the block with it. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. */ static dc16(dst: InputBuffer<Uint8Array>): void; /** * Computes the DC value for a 16x16 block with top samples not available and fills the block with it. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. */ static dc16NoTop(dst: InputBuffer<Uint8Array>): void; /** * Computes the DC value for a 16x16 block with left samples not available and fills the block with it. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. */ static dc16NoLeft(dst: InputBuffer<Uint8Array>): void; /** * Fills a 16x16 block with a default value when no top and left samples are available. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. */ static dc16NoTopLeft(dst: InputBuffer<Uint8Array>): void; /** * Performs a vertical edge filtering on an 8x8 UV block. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. */ static ve8uv(dst: InputBuffer<Uint8Array>): void; /** * Performs a horizontal edge filtering on an 8x8 UV block. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. */ static he8uv(dst: InputBuffer<Uint8Array>): void; /** * Helper for chroma-DC predictions. Fills an 8x8 UV block with a specified value. * @param {number} value - The value to fill the block with. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. */ static put8x8uv(value: number, dst: InputBuffer<Uint8Array>): void; /** * Computes the DC value for an 8x8 UV block and fills the block with it. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. */ static dc8uv(dst: InputBuffer<Uint8Array>): void; /** * Computes the DC value for an 8x8 UV block with no left samples and fills the block with it. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. */ static dc8uvNoLeft(dst: InputBuffer<Uint8Array>): void; /** * Computes the DC value for an 8x8 UV block with no top samples and fills the block with it. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. */ static dc8uvNoTop(dst: InputBuffer<Uint8Array>): void; /** * Fills an 8x8 UV block with a default value when no top and left samples are available. * @param {InputBuffer<Uint8Array>} dst - The destination buffer to store Uint8Array data. */ static dc8uvNoTopLeft(dst: InputBuffer<Uint8Array>): void; /** * Constant value kC1 used in calculations. */ private static readonly kC1; /** * Constant value kC2 used in calculations. */ private static readonly kC2; /** * Array representing the absolute values of integers. */ private static abs0; /** * Array representing the absolute values of integers shifted right by 1. */ private static abs1; /** * Array that clips values in the range [-1020, 1020] to [-128, 127]. */ private static sclip1; /** * Array that clips values in the range [-112, 112] to [-16, 15]. */ private static sclip2; /** * Array that clips values in the range [-255, 510] to [0, 255]. */ private static clip1; /** * Flag indicating whether the tables have been initialized. */ private static tablesInitialized; /** * Array of prediction functions for Luma 4x4 blocks. */ static readonly predLuma4: (typeof VP8Filter.dc4)[]; /** * Array of prediction functions for Luma 16x16 blocks. */ static readonly predLuma16: (typeof VP8Filter.dc16)[]; /** * Array of prediction functions for Chroma 8x8 blocks. */ static readonly predChroma8: (typeof VP8Filter.dc8uv)[]; }