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)
71 lines • 2.21 kB
JavaScript
import { BitUtils } from '../../common/bit-utils.js';
export class VP8LMultipliers {
constructor() {
this._data = new Uint8Array(3);
}
get greenToRed() {
return this._data[0];
}
set greenToRed(v) {
this._data[0] = v;
}
get greenToBlue() {
return this._data[1];
}
set greenToBlue(v) {
this._data[1] = v;
}
get redToBlue() {
return this._data[2];
}
set redToBlue(v) {
this._data[2] = v;
}
get colorCode() {
return (0xff000000 | (this._data[2] << 16) | (this._data[1] << 8) | this._data[0]);
}
set colorCode(v) {
this._data[0] = (v >>> 0) & 0xff;
this._data[1] = (v >>> 8) & 0xff;
this._data[2] = (v >>> 16) & 0xff;
}
clear() {
this._data[0] = 0;
this._data[1] = 0;
this._data[2] = 0;
}
transformColor(argb, inverse) {
const green = (argb >>> 8) & 0xff;
const red = (argb >>> 16) & 0xff;
let newRed = red;
let newBlue = argb & 0xff;
if (inverse) {
const g = this.colorTransformDelta(this.greenToRed, green);
newRed = (newRed + g) & 0xffffffff;
newRed &= 0xff;
newBlue =
(newBlue + this.colorTransformDelta(this.greenToBlue, green)) &
0xffffffff;
newBlue =
(newBlue + this.colorTransformDelta(this.redToBlue, newRed)) &
0xffffffff;
newBlue &= 0xff;
}
else {
newRed -= this.colorTransformDelta(this.greenToRed, green);
newRed &= 0xff;
newBlue -= this.colorTransformDelta(this.greenToBlue, green);
newBlue -= this.colorTransformDelta(this.redToBlue, red);
newBlue &= 0xff;
}
const c = (argb & 0xff00ff00) | ((newRed << 16) & 0xffffffff) | newBlue;
return c;
}
colorTransformDelta(colorPred, color) {
const a = BitUtils.uint8ToInt8(colorPred);
const b = BitUtils.uint8ToInt8(color);
const d = BitUtils.int32ToUint32(a * b);
return d >>> 5;
}
}
//# sourceMappingURL=vp8l-multipliers.js.map