Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added img/female.tiff
Binary file not shown.
Binary file added img/jellybeans.tiff
Binary file not shown.
34 changes: 33 additions & 1 deletion src/__tests__/decode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,22 @@ const files: TiffFile[] = [
components: 1,
alpha: false,
},
{
name: 'jellybeans.tiff',
width: 256,
height: 256,
bitsPerSample: 8,
components: 3,
alpha: false,
},
{
name: 'female.tiff',
width: 256,
height: 256,
bitsPerSample: 8,
components: 3,
alpha: false,
},
// Checks only the first frame of the image.
{
name: 'dog.tiff',
Expand Down Expand Up @@ -385,7 +401,7 @@ test('should decode image compressed with deflate algorithm', () => {
});
});

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

expect(decoded).toHaveLength(1);
Expand Down Expand Up @@ -500,3 +516,19 @@ test('should decode multiframe image', () => {
expect(decoded[1].samplesPerPixel).toBe(2);
expect(decoded[1].data.slice(352, 384)).toStrictEqual(secondFrameTwelvethRow);
});

test('should decode image with undefined rowsPerStrip', () => {
const decodedFemale = decode(readImage('female.tiff'));

expect(decodedFemale[0].rowsPerStrip).toStrictEqual(2 ** 32 - 1);
expect(decodedFemale[0].data.slice(0, 10)).toStrictEqual(
new Uint8Array([94, 0, 115, 27, 61, 103, 26, 60, 104, 27]),
);

const decodedJellybeans = decode(readImage('jellybeans.tiff'));

expect(decodedJellybeans[0].rowsPerStrip).toStrictEqual(2 ** 32 - 1);
expect(decodedJellybeans[0].data.slice(0, 10)).toStrictEqual(
new Uint8Array([139, 132, 90, 141, 136, 92, 142, 131, 89, 143]),
);
});
2 changes: 2 additions & 0 deletions src/tiff_decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ export default class TIFFDecoder extends IOBuffer {
ifd.bitsPerSample !== 1
? width * ifd.samplesPerPixel * height
: Math.ceil((width * ifd.samplesPerPixel) / 8) * height;

// Compressed Strip Layout
const stripOffsets = ifd.stripOffsets;
const stripByteCounts = ifd.stripByteCounts || guessStripByteCounts(ifd);
Expand All @@ -302,6 +303,7 @@ export default class TIFFDecoder extends IOBuffer {
ifd.bitsPerSample !== 1
? width * ifd.samplesPerPixel * ifd.rowsPerStrip
: Math.ceil((width * ifd.samplesPerPixel) / 8) * ifd.rowsPerStrip;

const readSamples = this.createSampleReader(
ifd.sampleFormat,
ifd.bitsPerSample,
Expand Down
2 changes: 1 addition & 1 deletion src/tiff_ifd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default class TiffIfd extends Ifd {
return this.get('SamplesPerPixel') || 1;
}
public get rowsPerStrip(): number {
return this.get('RowsPerStrip');
return this.get('RowsPerStrip') || 2 ** 32 - 1;
}
public get stripByteCounts(): number[] {
return alwaysArray(this.get('StripByteCounts'));
Expand Down
Loading