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)
63 lines • 1.93 kB
JavaScript
import { IfdValue } from './ifd-value.js';
import { IfdValueType } from '../ifd-value-type.js';
import { Rational } from '../../common/rational.js';
import { ArrayUtils } from '../../common/array-utils.js';
export class IfdRationalValue extends IfdValue {
get type() {
return IfdValueType.rational;
}
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.readUint32(), data.readUint32());
array.push(r);
}
return new IfdRationalValue(array);
}
static from(other) {
const r = new Rational(other.numerator, other.denominator);
return new IfdRationalValue(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(v.numerator);
out.writeUint32(v.denominator);
}
}
setRational(numerator, denominator, index = 0) {
this._value[index] = new Rational(numerator, denominator);
}
equals(other) {
return (other instanceof IfdRationalValue &&
this.length === other.length &&
ArrayUtils.equalsRationalArray(this._value, other._value));
}
clone() {
return new IfdRationalValue(this._value);
}
toString() {
return `${this.constructor.name} (${this._value.length === 1 ? `${this._value[0]}` : `${this._value}`})`;
}
}
//# sourceMappingURL=ifd-rational-value.js.map