Skip to content

Commit

Permalink
feat: add support for uncompressed RGB data
Browse files Browse the repository at this point in the history
  • Loading branch information
targos committed Nov 5, 2016
1 parent f5db214 commit b3ffff7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/tiffDecoder.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,19 +119,20 @@ class TIFFDecoder extends IOBuffer {
}
switch (ifd.type) {
case 1: // BlackIsZero
this.decodeBilevelOrGrey(ifd);
case 2: // RGB
this.readStripData(ifd);
break;
default:
unsupported('image type', ifd.type);
break;
}
}

decodeBilevelOrGrey(ifd) {
readStripData(ifd) {
const width = ifd.width;
const height = ifd.height;

const bitDepth = ifd.bitsPerSample;
const bitDepth = validateBitDepth(ifd.bitsPerSample);
const sampleFormat = ifd.sampleFormat;
let size = width * height;
const data = getDataArray(size, 1, bitDepth, sampleFormat);
Expand Down Expand Up @@ -213,3 +214,16 @@ function fillFloat32(dataTo, dataFrom, index, length, littleEndian) {
function unsupported(type, value) {
throw new Error('Unsupported ' + type + ': ' + value);
}

function validateBitDepth(bitDepth) {
if (bitDepth.length) {
const bitDepthArray = bitDepth;
bitDepth = bitDepthArray[0];
for (var i = 0; i < bitDepthArray.length; i++) {
if (bitDepthArray[i] !== bitDepth) {
unsupported('bit depth', bitDepthArray);
}
}
}
return bitDepth;
}
2 changes: 1 addition & 1 deletion test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const fs = require('fs');
const should = require('should');
const tiff = require('..');

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

Expand Down

0 comments on commit b3ffff7

Please sign in to comment.