UNPKG

@alttiri/image-hash

Version:

Alt-Image-Hash. An alternative image hashing library.

31 lines (30 loc) 1.46 kB
import { GrayImageData } from "./mono-image-data.js"; import { GrayScalingOpt, ImageDataLike } from "./types.js"; /** * Using of 1 `getUint32` is faster than 3 accesses by index (`array[N]`). * * `getCalculateBT601` is faster than: * `array[i / 4] = data[i] * 0.299 + data[i + 1] * 0.587 + data[i + 2] * 0.114;` * or `getCalculateAverage` is faster than: * `array[i / 4] = (data[i] + data[i + 1] + data[i + 2]) / 3;` * * Using `dw.getUint32` inside the function is faster, * than using `dw.getUint32` in a loop and passing `uint` directly to the function. * * Do not change the get functions' signature. */ export declare const getCalculateBT601: typeof getCalculateBT601_Optimized; /** Note: It's without rounding. It works as with Math.trunc/Math.floor. */ export declare function getCalculateBT601_Original(dw: DataView): (i: number) => number; /** Faster version of BT601 with very similar results * (only 0.05 % difference no more than by 1 in comparison with the rounded version). */ export declare function getCalculateBT601_Optimized(dw: DataView): (i: number) => number; export declare function getCalculateAverage(dw: DataView): (i: number) => number; export declare function getCalculateBT709(dw: DataView): (i: number) => number; /** * `getFunc`: * - `getCalculateBT601` * - `getCalculateAverage` * - `getCalculateBT709` */ export declare function getGrayData(imageData: ImageDataLike, getFunc?: GrayScalingOpt): GrayImageData;