Skip to content

Commit b3ffff7

Browse files
committed
feat: add support for uncompressed RGB data
1 parent f5db214 commit b3ffff7

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/tiffDecoder.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,20 @@ class TIFFDecoder extends IOBuffer {
119119
}
120120
switch (ifd.type) {
121121
case 1: // BlackIsZero
122-
this.decodeBilevelOrGrey(ifd);
122+
case 2: // RGB
123+
this.readStripData(ifd);
123124
break;
124125
default:
125126
unsupported('image type', ifd.type);
126127
break;
127128
}
128129
}
129130

130-
decodeBilevelOrGrey(ifd) {
131+
readStripData(ifd) {
131132
const width = ifd.width;
132133
const height = ifd.height;
133134

134-
const bitDepth = ifd.bitsPerSample;
135+
const bitDepth = validateBitDepth(ifd.bitsPerSample);
135136
const sampleFormat = ifd.sampleFormat;
136137
let size = width * height;
137138
const data = getDataArray(size, 1, bitDepth, sampleFormat);
@@ -213,3 +214,16 @@ function fillFloat32(dataTo, dataFrom, index, length, littleEndian) {
213214
function unsupported(type, value) {
214215
throw new Error('Unsupported ' + type + ': ' + value);
215216
}
217+
218+
function validateBitDepth(bitDepth) {
219+
if (bitDepth.length) {
220+
const bitDepthArray = bitDepth;
221+
bitDepth = bitDepthArray[0];
222+
for (var i = 0; i < bitDepthArray.length; i++) {
223+
if (bitDepthArray[i] !== bitDepth) {
224+
unsupported('bit depth', bitDepthArray);
225+
}
226+
}
227+
}
228+
return bitDepth;
229+
}

test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const fs = require('fs');
44
const should = require('should');
55
const tiff = require('..');
66

7-
const files = ['grey8.tif', 'grey16.tif'];
7+
const files = ['grey8.tif', 'grey16.tif', 'color8.tif', 'color16.tif'];
88
const dir = __dirname + '/img/';
99
const contents = files.map(file => fs.readFileSync(dir + file));
1010

0 commit comments

Comments
 (0)