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)

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