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)

64 lines 2.04 kB
import { IfdValue } from './ifd-value.js'; import { IfdValueType } from '../ifd-value-type.js'; import { BitUtils } from '../../common/bit-utils.js'; import { Rational } from '../../common/rational.js'; import { ArrayUtils } from '../../common/array-utils.js'; export class IfdSRationalValue extends IfdValue { get type() { return IfdValueType.sRational; } get length() { return this._value.length; } constructor(value) { super(); if (value instanceof Rational) { this._value = [value]; } else { this._value = value; } } static data(data, length) { const array = new Array(); for (let i = 0; i < length; i++) { const r = new Rational(data.readInt32(), data.readInt32()); array.push(r); } return new IfdSRationalValue(array); } static from(other) { const r = new Rational(other.numerator, other.denominator); return new IfdSRationalValue(r); } toInt(index = 0) { return this._value[index].toInt; } toDouble(index = 0) { return this._value[index].toDouble; } toRational(index = 0) { return this._value[index]; } write(out) { for (const v of this._value) { out.writeUint32(BitUtils.int32ToUint32(v.numerator)); out.writeUint32(BitUtils.int32ToUint32(v.denominator)); } } setRational(numerator, denomitator, index = 0) { this._value[index] = new Rational(numerator, denomitator); } equals(other) { return (other instanceof IfdSRationalValue && this.length === other.length && ArrayUtils.equalsRationalArray(this._value, other._value)); } clone() { return new IfdSRationalValue(this._value); } toString() { return `${this.constructor.name} (${this._value.length === 1 ? `${this._value[0]}` : `${this._value}`})`; } } //# sourceMappingURL=ifd-srational-value.js.map