@alttiri/image-hash
Version:
Alt-Image-Hash. An alternative image hashing library.
32 lines (31 loc) • 911 B
JavaScript
/** ImageData fot only one channel (luminance). */
export class MonoImageData {
constructor(data, width, height) {
this.channels = 1;
const mult = width * height;
if (mult !== data.length || !mult) {
throw new Error("Incorrect data");
}
this.data = data;
this.width = width;
this.height = height;
}
newInstance(data, width, height) {
// @ts-ignore
return new this.constructor(data, width, height);
}
}
/** "binary"/"black-white" image pixels (`0` and `255` values) */
export class BiImageData extends MonoImageData {
constructor() {
super(...arguments);
this.type = "binary";
}
}
/** "gray-scaled" image pixels (values from `0` up to `255`) */
export class GrayImageData extends MonoImageData {
constructor() {
super(...arguments);
this.type = "gray-scaled";
}
}