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.58 kB
JavaScript
import { IfdValue } from './ifd-value.js';
import { IfdValueType } from '../ifd-value-type.js';
import { ArrayUtils } from '../../common/array-utils.js';
export class IfdDoubleValue extends IfdValue {
get type() {
return IfdValueType.double;
}
get length() {
return this._value.length;
}
constructor(value) {
super();
if (typeof value === 'number') {
this._value = new Float64Array(1);
this._value[0] = value;
}
else {
this._value = Float64Array.from(value);
}
}
static data(data, length) {
const array = new Float64Array(length);
for (let i = 0; i < length; ++i) {
array[i] = data.readFloat64();
}
return new IfdDoubleValue(array);
}
toDouble(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.writeFloat64(this._value[i]);
}
}
setDouble(v, index = 0) {
this._value[index] = v;
}
equals(other) {
return (other instanceof IfdDoubleValue &&
this.length === other.length &&
ArrayUtils.equals(this._value, other._value));
}
clone() {
return new IfdDoubleValue(this._value);
}
toString() {
return `${this.constructor.name} (${this._value.length === 1 ? `${this._value[0]}` : `${this._value}`})`;
}
}
//# sourceMappingURL=ifd-double-value.js.map