Skip to content

Commit 7abbe97

Browse files
fix: fix bug with rowsPerStrip (#79)
1 parent 67169f9 commit 7abbe97

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

img/female.tiff

192 KB
Binary file not shown.

img/jellybeans.tiff

192 KB
Binary file not shown.

src/__tests__/decode.test.ts

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,22 @@ const files: TiffFile[] = [
207207
components: 1,
208208
alpha: false,
209209
},
210+
{
211+
name: 'jellybeans.tiff',
212+
width: 256,
213+
height: 256,
214+
bitsPerSample: 8,
215+
components: 3,
216+
alpha: false,
217+
},
218+
{
219+
name: 'female.tiff',
220+
width: 256,
221+
height: 256,
222+
bitsPerSample: 8,
223+
components: 3,
224+
alpha: false,
225+
},
210226
// Checks only the first frame of the image.
211227
{
212228
name: 'dog.tiff',
@@ -385,7 +401,7 @@ test('should decode image compressed with deflate algorithm', () => {
385401
});
386402
});
387403

388-
test('should decode basic 2x2 1-bit image ', () => {
404+
test('should decode basic 2x2 1-bit image', () => {
389405
const decoded = decode(readImage('bw1bit.tif'));
390406

391407
expect(decoded).toHaveLength(1);
@@ -500,3 +516,19 @@ test('should decode multiframe image', () => {
500516
expect(decoded[1].samplesPerPixel).toBe(2);
501517
expect(decoded[1].data.slice(352, 384)).toStrictEqual(secondFrameTwelvethRow);
502518
});
519+
520+
test('should decode image with undefined rowsPerStrip', () => {
521+
const decodedFemale = decode(readImage('female.tiff'));
522+
523+
expect(decodedFemale[0].rowsPerStrip).toStrictEqual(2 ** 32 - 1);
524+
expect(decodedFemale[0].data.slice(0, 10)).toStrictEqual(
525+
new Uint8Array([94, 0, 115, 27, 61, 103, 26, 60, 104, 27]),
526+
);
527+
528+
const decodedJellybeans = decode(readImage('jellybeans.tiff'));
529+
530+
expect(decodedJellybeans[0].rowsPerStrip).toStrictEqual(2 ** 32 - 1);
531+
expect(decodedJellybeans[0].data.slice(0, 10)).toStrictEqual(
532+
new Uint8Array([139, 132, 90, 141, 136, 92, 142, 131, 89, 143]),
533+
);
534+
});

src/tiff_decoder.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ export default class TIFFDecoder extends IOBuffer {
293293
ifd.bitsPerSample !== 1
294294
? width * ifd.samplesPerPixel * height
295295
: Math.ceil((width * ifd.samplesPerPixel) / 8) * height;
296+
296297
// Compressed Strip Layout
297298
const stripOffsets = ifd.stripOffsets;
298299
const stripByteCounts = ifd.stripByteCounts || guessStripByteCounts(ifd);
@@ -302,6 +303,7 @@ export default class TIFFDecoder extends IOBuffer {
302303
ifd.bitsPerSample !== 1
303304
? width * ifd.samplesPerPixel * ifd.rowsPerStrip
304305
: Math.ceil((width * ifd.samplesPerPixel) / 8) * ifd.rowsPerStrip;
306+
305307
const readSamples = this.createSampleReader(
306308
ifd.sampleFormat,
307309
ifd.bitsPerSample,

src/tiff_ifd.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export default class TiffIfd extends Ifd {
9191
return this.get('SamplesPerPixel') || 1;
9292
}
9393
public get rowsPerStrip(): number {
94-
return this.get('RowsPerStrip');
94+
return this.get('RowsPerStrip') || 2 ** 32 - 1;
9595
}
9696
public get stripByteCounts(): number[] {
9797
return alwaysArray(this.get('StripByteCounts'));

0 commit comments

Comments
 (0)