diff --git a/README.md b/README.md index 3bb8c8c..e22c03c 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,14 @@ Based on [pngjs](https://github.com/niegowski/node-pngjs) with the follow enhanc * Support for reading 1,2,4 & 16 bit files * Support for reading interlace files * Support for reading `tTRNS` transparent colours + * Support for writing colortype 2 (RGB) and colortype 6 (RGBA) * Sync interface as well as async * API compatible with pngjs and node-pngjs Known lack of support for: * Extended PNG e.g. Animation - * Writing in different formats + * Writing in different formats, colortype 0 (greyscale), colortype 3 (indexed color), colortype 4 (greyscale with alpha) * Synchronous write Requirements diff --git a/lib/chunkstream.js b/lib/chunkstream.js index 59292c5..56719bd 100644 --- a/lib/chunkstream.js +++ b/lib/chunkstream.js @@ -199,11 +199,11 @@ ChunkStream.prototype._process = function() { } } - if (this._buffers && this._buffers.length > 0 && this._buffers[0] == null) { + if (this._buffers && this._buffers.length > 0 && this._buffers[0] === null) { this._end(); } } - catch(ex) { + catch (ex) { this.emit('error', ex); } }; diff --git a/lib/filter-pack.js b/lib/filter-pack.js index dd2f368..94dab44 100644 --- a/lib/filter-pack.js +++ b/lib/filter-pack.js @@ -42,7 +42,7 @@ function filterSumSub(pxData, pxPos, byteWidth, BPP) { return sum; } -function filterUp(pxData, pxPos, byteWidth, rawData, rawPos, BPP) { +function filterUp(pxData, pxPos, byteWidth, rawData, rawPos) { for (var x = 0; x < byteWidth; x++) { @@ -53,7 +53,7 @@ function filterUp(pxData, pxPos, byteWidth, rawData, rawPos, BPP) { } } -function filterSumUp(pxData, pxPos, byteWidth, BPP) { +function filterSumUp(pxData, pxPos, byteWidth) { var sum = 0; var length = pxPos + byteWidth; diff --git a/lib/packer.js b/lib/packer.js index abc0091..e342cc8 100644 --- a/lib/packer.js +++ b/lib/packer.js @@ -8,8 +8,8 @@ var filter = require('./filter-pack'); var CrcStream = require('./crc'); var constants = require('./constants'); -var COLOR_TYPE_TRUECOLOR = 2; -var COLOR_TYPE_TRUECOLOR_WITH_ALPHA = 6; +var COLORTYPE_TRUECOLOR = 2; +var COLORTYPE_TRUECOLOR_ALPHA = 6; var Packer = module.exports = function(options) { Stream.call(this); @@ -17,11 +17,11 @@ var Packer = module.exports = function(options) { this._options = options; options.deflateChunkSize = options.deflateChunkSize || 32 * 1024; - options.deflateLevel = options.deflateLevel != null ? options.deflateLevel : 9; - options.deflateStrategy = options.deflateStrategy != null ? options.deflateStrategy : 3; + options.deflateLevel = options.deflateLevel !== null ? options.deflateLevel : 9; + options.deflateStrategy = options.deflateStrategy !== null ? options.deflateStrategy : 3; options.deflateFactory = options.deflateFactory || zlib.createDeflate; options.bitDepth = options.bitDepth || 8; - options.colorType = (typeof options.colorType=="number") ? options.colorType : COLOR_TYPE_TRUECOLOR_WITH_ALPHA; + options.colorType = (typeof options.colorType === 'number') ? options.colorType : COLORTYPE_TRUECOLOR_ALPHA; this.readable = true; }; @@ -39,7 +39,7 @@ Packer.prototype.pack = function(data, width, height, gamma) { // filter pixel data var bpp = 4; - if (this._options.colorType === COLOR_TYPE_TRUECOLOR) { + if (this._options.colorType === COLORTYPE_TRUECOLOR) { bpp = 3; } var filteredData = filter(data, width, height, this._options, bpp); diff --git a/lib/png.js b/lib/png.js index c60778e..b4663c8 100644 --- a/lib/png.js +++ b/lib/png.js @@ -15,8 +15,8 @@ var PNG = exports.PNG = function(options) { this.width = options.width || 0; this.height = options.height || 0; - this.data = this.width > 0 && this.height > 0 - ? new Buffer(4 * this.width * this.height) : null; + this.data = this.width > 0 && this.height > 0 ? + new Buffer(4 * this.width * this.height) : null; if (options.fill && this.data) { this.data.fill(0); diff --git a/package.json b/package.json index d64ffa1..7976497 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,8 @@ "Luke Page", "Pietajan De Potter", "Steven Sojka", - "liangzeng" + "liangzeng", + "Michael Vogt" ], "homepage": "https://github.com/lukeapage/pngjs2", "keywords": [ diff --git a/test/bg.png b/test/bg.png index e4361e0..b1885d9 100644 Binary files a/test/bg.png and b/test/bg.png differ