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)

54 lines 1.56 kB
import { IfdValue } from './ifd-value.js'; import { IfdValueType } from '../ifd-value-type.js'; import { ArrayUtils } from '../../common/array-utils.js'; export class IfdShortValue extends IfdValue { get type() { return IfdValueType.short; } get length() { return this._value.length; } constructor(value) { super(); if (typeof value === 'number') { this._value = new Uint16Array(1); this._value[0] = value; } else { this._value = Uint16Array.from(value); } } static data(data, length) { const array = new Uint16Array(length); for (let i = 0; i < length; ++i) { array[i] = data.readUint16(); } return new IfdShortValue(array); } toInt(index = 0) { return this._value[index]; } toData() { return new Uint8Array(this._value.buffer); } write(out) { for (let i = 0, l = this._value.length; i < l; ++i) { out.writeUint16(this._value[i]); } } setInt(v, index = 0) { this._value[index] = v; } equals(other) { return (other instanceof IfdShortValue && this.length === other.length && ArrayUtils.equals(this._value, other._value)); } clone() { return new IfdShortValue(this._value); } toString() { return `${this.constructor.name} (${this._value.length === 1 ? `${this._value[0]}` : `${this._value}`})`; } } //# sourceMappingURL=ifd-short-value.js.map