diff --git a/src/formats/tiff/tiff-entry.ts b/src/formats/tiff/tiff-entry.ts index 1d86aad..50381da 100644 --- a/src/formats/tiff/tiff-entry.ts +++ b/src/formats/tiff/tiff-entry.ts @@ -10,6 +10,7 @@ import { IfdDoubleValue } from '../../exif/ifd-value/ifd-double-value'; import { IfdLongValue } from '../../exif/ifd-value/ifd-long-value'; import { IfdRationalValue } from '../../exif/ifd-value/ifd-rational-value'; import { IfdSByteValue } from '../../exif/ifd-value/ifd-sbyte-value'; +import { IfdShortValue } from '../../exif/ifd-value/ifd-short-value'; import { IfdSingleValue } from '../../exif/ifd-value/ifd-single-value'; import { IfdSLongValue } from '../../exif/ifd-value/ifd-slong-value'; import { IfdSRationalValue } from '../../exif/ifd-value/ifd-srational-value'; @@ -91,7 +92,7 @@ export class TiffEntry { case IfdValueType.undefined: return (this._value = IfdByteValue.data(data, this._count)); case IfdValueType.short: - return (this._value = IfdSShortValue.data(data, this._count)); + return (this._value = IfdShortValue.data(data, this._count)); case IfdValueType.long: return (this._value = IfdLongValue.data(data, this._count)); case IfdValueType.rational: diff --git a/src/formats/tiff/tiff-image.ts b/src/formats/tiff/tiff-image.ts index 4e8b9e6..0556fb3 100644 --- a/src/formats/tiff/tiff-image.ts +++ b/src/formats/tiff/tiff-image.ts @@ -655,16 +655,8 @@ export class TiffImage { ); } - for ( - let y = 0, py = outY; - y < this._tileHeight && py < this._height; - ++y, ++py - ) { - for ( - let x = 0, px = outX; - x < this._tileWidth && px < this._width; - ++x, ++px - ) { + for (let y = 0, py = outY; y < this._tileHeight; ++y, ++py) { + for (let x = 0, px = outX; x < this._tileWidth; ++x, ++px) { if (this._samplesPerPixel === 1) { if (this._sampleFormat === TiffFormat.float) { let sample = 0; @@ -675,7 +667,9 @@ export class TiffImage { } else if (this._bitsPerSample === 16) { sample = Float16.float16ToDouble(byteData.readUint16()); } - image.setPixelR(px, py, sample); + if (px < this._width && py < this._height) { + image.setPixelR(px, py, sample); + } } else { let sample = 0; if (this._bitsPerSample === 8) { @@ -700,7 +694,9 @@ export class TiffImage { sample = mx - sample; } - image.setPixelR(px, py, sample); + if (px < this._width && py < this._height) { + image.setPixelR(px, py, sample); + } } } else if (this._samplesPerPixel === 2) { let gray = 0; @@ -734,7 +730,9 @@ export class TiffImage { : byteData.readUint32(); } - image.setPixelRgb(px, py, gray, alpha, 0); + if (px < this._width && py < this._height) { + image.setPixelRgb(px, py, gray, alpha, 0); + } } else if (this._samplesPerPixel === 3) { if (this._sampleFormat === TiffFormat.float) { let r = 0.0; @@ -753,7 +751,9 @@ export class TiffImage { g = Float16.float16ToDouble(byteData.readUint16()); b = Float16.float16ToDouble(byteData.readUint16()); } - image.setPixelRgb(px, py, r, g, b); + if (px < this._width && py < this._height) { + image.setPixelRgb(px, py, r, g, b); + } } else { let r = 0; let g = 0; @@ -799,7 +799,9 @@ export class TiffImage { : byteData.readUint32(); } - image.setPixelRgb(px, py, r, g, b); + if (px < this._width && py < this._height) { + image.setPixelRgb(px, py, r, g, b); + } } } else if (this._samplesPerPixel >= 4) { if (this._sampleFormat === TiffFormat.float) { @@ -823,7 +825,9 @@ export class TiffImage { b = Float16.float16ToDouble(byteData.readUint16()); a = Float16.float16ToDouble(byteData.readUint16()); } - image.setPixelRgba(px, py, r, g, b, a); + if (px < this._width && py < this._height) { + image.setPixelRgba(px, py, r, g, b, a); + } } else { let r = 0; let g = 0; @@ -890,7 +894,9 @@ export class TiffImage { a = Math.trunc(image.maxChannelValue); } - image.setPixelRgba(px, py, r, g, b, a); + if (px < this._width && py < this._height) { + image.setPixelRgba(px, py, r, g, b, a); + } } } }