Comparing version 0.0.1 to 0.0.2
@@ -20,4 +20,3 @@ var interlaceUtils = require('./interlace'); | ||
i++; | ||
byte = Math.floor((((byte << 8) + byte2) * 255) / (Math.pow(2, 16) - 1) + 0.5); | ||
leftOver.push(byte); | ||
leftOver.push(((byte << 8) + byte2)); | ||
break; | ||
@@ -74,4 +73,10 @@ case 4: | ||
} | ||
var pxData = new Buffer(width * height * 4); | ||
var maxBit = depth >= 8 ? 255 : (Math.pow(2, depth) - 1); | ||
var pxData; | ||
if (depth <= 8) { | ||
pxData = new Buffer(width * height * 4); | ||
} else { | ||
// TODO: could be more effecient and use a buffer but change how we write to use 16 bit write methods with index * 2 | ||
pxData = new Array(width * height * 4); | ||
} | ||
var maxBit = Math.pow(2, depth) - 1; | ||
var rawPos = 0; | ||
@@ -95,14 +100,6 @@ var pixelData; | ||
for (var y = 0; y < height; y++) { | ||
for (var x = 0; x < width; x++) { | ||
pxData[(y * 4 * width) + (x * 4) + 0] = 255; | ||
pxData[(y * 4 * width) + (x * 4) + 1] = 0; | ||
pxData[(y * 4 * width) + (x * 4) + 2] = 0; | ||
pxData[(y * 4 * width) + (x * 4) + 3] = 255; | ||
} | ||
} | ||
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++) { | ||
@@ -113,3 +110,3 @@ for (var x = 0; x < imageWidth; x++) { | ||
} | ||
var pxPos = getPxPos(x, y, imageIndex); | ||
var pxPos = getPxPos(x, y, imagePass); | ||
//console.log(x,y,imageIndex, pxPos); | ||
@@ -116,0 +113,0 @@ for (var i = 0; i < 4; i++) { |
@@ -28,3 +28,3 @@ exports.getImagePasses = function(width, height) { | ||
if (passWidth > 0 && passHeight > 0) { | ||
images.push({ width: passWidth, height: passHeight}); | ||
images.push({ width: passWidth, height: passHeight, index: i}); | ||
} | ||
@@ -31,0 +31,0 @@ } |
@@ -190,3 +190,4 @@ // Copyright (c) 2012 Kuba Niegowski | ||
this.createData(width, height, colorTypeToBppMap[this._colorType], depth, interlace); | ||
var bpp = colorTypeToBppMap[this._colorType]; | ||
this.createData(width, height, bpp, depth, interlace); | ||
@@ -199,2 +200,3 @@ this._hasIHDR = true; | ||
depth: depth, | ||
interlace: interlace, | ||
palette: !!(colorType & constants.COLOR_PALETTE), | ||
@@ -255,2 +257,9 @@ color: !!(colorType & constants.COLOR_COLOR), | ||
// there might be one gray/color defined as transparent | ||
if (this._colorType === 0) { | ||
// grey, 2 bytes | ||
this._transColor = [data.readUInt16BE(0)]; | ||
} | ||
if (this._colorType === 2) { | ||
this._transColor = [data.readUInt16BE(0), data.readUInt16BE(2), data.readUInt16BE(4)]; | ||
} | ||
@@ -304,4 +313,6 @@ this._handleChunkEnd(); | ||
Parser.prototype.reverseFiltered = function(data, depth, width, height) { | ||
Parser.prototype.reverseFiltered = function(indata, depth, width, height) { | ||
var outdata = indata; // only different for 16 bits | ||
if (this._colorType == 3) { // paletted | ||
@@ -317,26 +328,59 @@ //console.log("paletted"); | ||
var pxPos = pxRowPos + (x << 2), | ||
color = this._palette[data[pxPos]]; | ||
color = this._palette[indata[pxPos]]; | ||
if (!color) { | ||
throw new Error("index " + indata[pxPos] + " not in palette"); | ||
} | ||
for (var i = 0; i < 4; i++) | ||
data[pxPos + i] = color[i]; | ||
indata[pxPos + i] = color[i]; | ||
} | ||
} | ||
} else if (depth < 8) { | ||
//console.log("adjusting"); | ||
} else { | ||
var pxLineLength = width << 2; | ||
var maxOutSample = 255; | ||
var maxInSample = Math.pow(2, depth) - 1; | ||
for (var y = 0; y < height; y++) { | ||
var pxRowPos = y * pxLineLength; | ||
if (this._transColor) { | ||
for (var y = 0; y < height; y++) { | ||
var pxRowPos = y * pxLineLength; | ||
for (var x = 0; x < width; x++) { | ||
var pxPos = pxRowPos + (x << 2); | ||
for (var i = 0; i < 4; i++) | ||
data[pxPos + i] = Math.floor((data[pxPos + i] * maxOutSample) / maxInSample + 0.5); | ||
for (var x = 0; x < width; x++) { | ||
var pxPos = pxRowPos + (x << 2); | ||
var makeTrans = false; | ||
//console.log(pxPos); | ||
if (this._transColor.length === 1) { | ||
if (this._transColor[0] === indata[pxPos]) { | ||
makeTrans = true; | ||
} | ||
} else if (this._transColor[0] === indata[pxPos] && this._transColor[1] === indata[pxPos + 1] && this._transColor[2] === indata[pxPos + 2]) { | ||
makeTrans = true; | ||
} | ||
if (makeTrans) { | ||
for (var i = 0; i < 4; i++) { | ||
indata[pxPos + i] = 0; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
if (depth !== 8) { | ||
if (depth === 16) { | ||
outdata = new Buffer(width * height * 4); | ||
} | ||
//console.log("adjusting"); | ||
var maxOutSample = 255; | ||
var maxInSample = Math.pow(2, depth) - 1; | ||
for (var y = 0; y < height; y++) { | ||
var pxRowPos = y * pxLineLength; | ||
for (var x = 0; x < width; x++) { | ||
var pxPos = pxRowPos + (x << 2); | ||
for (var i = 0; i < 4; i++) | ||
outdata[pxPos + i] = Math.floor((indata[pxPos + i] * maxOutSample) / maxInSample + 0.5); | ||
} | ||
} | ||
} | ||
} | ||
return data; | ||
return outdata; | ||
}; | ||
{ | ||
"name": "pngjs2", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Pure JS PNG encoder/decoder", | ||
@@ -5,0 +5,0 @@ "contributors": ["Kuba Niegowski", "Luke Page", "Pietajan De Potter", "Steven Sojka", "Alexandre Paré", "Gaurav Mali", "liangzeng"], |
@@ -9,5 +9,11 @@ About | ||
* Support for reading interlace files | ||
* Support for reading transparent colours | ||
* Sync interface as well as async | ||
* API compatible with pngjs and node-pngjs | ||
Known lack of support for: | ||
* Animation | ||
* Gamma correction in 16 bit files | ||
Tests | ||
@@ -87,2 +93,3 @@ ===== | ||
- `alpha` image contains alpha channel | ||
- `interlace` image is interlaced | ||
@@ -158,2 +165,5 @@ | ||
### 0.0.2 - 02/08/2015 | ||
- Bugfixes to interlacing, support for transparent colours | ||
### 0.0.1 - 02/08/2015 | ||
@@ -160,0 +170,0 @@ - Initial release, see pngjs for older changelog. |
@@ -10,3 +10,3 @@ | ||
if (!file.match(/.*\.png$/i)) | ||
if (!file.match(/\.png$/i)) | ||
return; | ||
@@ -13,0 +13,0 @@ |
Sorry, the diff of this file is not supported yet
Possible typosquat attack
Supply chain riskThere is a package with a similar name that is downloaded much more often.
Did you mean |
---|
pngjs |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
15646988
208
2267
191
1
5