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)

55 lines 1.64 kB
import { IfdValue } from './ifd-value.js'; import { IfdValueType } from '../ifd-value-type.js'; import { BitUtils } from '../../common/bit-utils.js'; import { ArrayUtils } from '../../common/array-utils.js'; export class IfdSLongValue extends IfdValue { get type() { return IfdValueType.sLong; } get length() { return this._value.length; } constructor(value) { super(); if (typeof value === 'number') { this._value = new Int32Array(1); this._value[0] = value; } else { this._value = Int32Array.from(value); } } static data(data, length) { const array = new Int32Array(length); for (let i = 0; i < length; ++i) { array[i] = data.readInt32(); } return new IfdSLongValue(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.writeUint32(BitUtils.int32ToUint32(this._value[i])); } } setInt(v, index = 0) { this._value[index] = v; } equals(other) { return (other instanceof IfdSLongValue && this.length === other.length && ArrayUtils.equals(this._value, other._value)); } clone() { return new IfdSLongValue(this._value); } toString() { return `${this.constructor.name} (${this._value.length === 1 ? `${this._value[0]}` : `${this._value}`})`; } } //# sourceMappingURL=ifd-slong-value.js.map