diff --git a/lib/bitmapper.js b/lib/bitmapper.js index 6fa1823..a55c715 100644 --- a/lib/bitmapper.js +++ b/lib/bitmapper.js @@ -98,12 +98,13 @@ exports.dataToBitMap = function(data, width, height, bpp, depth, interlace) { for(var imageIndex = 0; imageIndex < images.length; imageIndex++) { var imageWidth = images[imageIndex].width; var imageHeight = images[imageIndex].height; + var imagePass = images[imageIndex].index; for (var y = 0; y < imageHeight; y++) { for (var x = 0; x < imageWidth; x++) { if (depth !== 8) { pixelData = bits.get(bpp); } - var pxPos = getPxPos(x, y, imageIndex); + var pxPos = getPxPos(x, y, imagePass); //console.log(x,y,imageIndex, pxPos); for (var i = 0; i < 4; i++) { var idx = pixelBppMap[bpp][i]; diff --git a/lib/interlace.js b/lib/interlace.js index 47ba8fa..bf867e7 100644 --- a/lib/interlace.js +++ b/lib/interlace.js @@ -25,7 +25,7 @@ exports.getImagePasses = function(width, height) { } } if (passWidth > 0 && passHeight > 0) { - images.push({ width: passWidth, height: passHeight}); + images.push({ width: passWidth, height: passHeight, index: i}); } } return images; diff --git a/lib/parser.js b/lib/parser.js index 72bb3c5..c8b5593 100644 --- a/lib/parser.js +++ b/lib/parser.js @@ -323,6 +323,10 @@ Parser.prototype.reverseFiltered = function(indata, depth, width, height) { var pxPos = pxRowPos + (x << 2), color = this._palette[indata[pxPos]]; + if (!color) { + throw new Error("index " + indata[pxPos] + " not in palette"); + } + for (var i = 0; i < 4; i++) indata[pxPos + i] = color[i]; }