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)

118 lines 3.51 kB
import { Format } from '../color/format.js'; import { Float16 } from '../common/float16.js'; export class PaletteFloat16 { get data() { return this._data; } get numColors() { return this._numColors; } get numChannels() { return this._numChannels; } get byteLength() { return this.data.byteLength; } get buffer() { return this.data.buffer; } get format() { return Format.float16; } get maxChannelValue() { return 1; } constructor(numColors, numChannels, data) { this._numColors = numColors; this._numChannels = numChannels; this._data = data !== null && data !== void 0 ? data : new Uint16Array(numColors * numChannels); } static from(other) { return new PaletteFloat16(other.numColors, other.numChannels, other.data); } setRgb(index, r, g, b) { let _index = index; _index *= this._numChannels; this._data[_index] = Float16.doubleToFloat16(r); if (this._numChannels > 1) { this._data[_index + 1] = Float16.doubleToFloat16(g); if (this._numChannels > 2) { this._data[_index + 2] = Float16.doubleToFloat16(b); } } } setRgba(index, r, g, b, a) { let _index = index; _index *= this._numChannels; this._data[_index] = Float16.doubleToFloat16(r); if (this._numChannels > 1) { this._data[_index + 1] = Float16.doubleToFloat16(g); if (this._numChannels > 2) { this._data[_index + 2] = Float16.doubleToFloat16(b); if (this._numChannels > 3) { this._data[_index + 3] = Float16.doubleToFloat16(a); } } } } set(index, channel, value) { let _index = index; if (channel < this._numChannels) { _index *= this._numChannels; this._data[_index + channel] = Float16.doubleToFloat16(value); } } get(index, channel) { return channel < this._numChannels ? Float16.float16ToDouble(this._data[index * this._numChannels + channel]) : 0; } getRed(index) { let _index = index; _index *= this._numChannels; return Float16.float16ToDouble(this._data[_index]); } getGreen(index) { let _index = index; if (this._numChannels < 2) { return 0; } _index *= this._numChannels; return Float16.float16ToDouble(this._data[_index + 1]); } getBlue(index) { let _index = index; if (this._numChannels < 3) { return 0; } _index *= this._numChannels; return Float16.float16ToDouble(this._data[_index + 2]); } getAlpha(index) { let _index = index; if (this._numChannels < 4) { return 255; } _index *= this._numChannels; return Float16.float16ToDouble(this._data[_index + 3]); } setRed(index, value) { this.set(index, 0, value); } setGreen(index, value) { this.set(index, 1, value); } setBlue(index, value) { this.set(index, 2, value); } setAlpha(index, value) { this.set(index, 3, value); } clone() { return PaletteFloat16.from(this); } toUint8Array() { return new Uint8Array(this.buffer); } } //# sourceMappingURL=palette-float16.js.map