diff --git a/README.md b/README.md index 3684994..077e06a 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ 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 transparent colours + * Support for reading `tTRNS` transparent colours * Sync interface as well as async * API compatible with pngjs and node-pngjs @@ -14,13 +14,39 @@ Known lack of support for: * Animation * Gamma correction in 16 bit files + +Comparison Table +================ + +Name | Forked From | Sync | Async | 16 Bit | 1/2/4 Bit | Interlace | Gamma | Encodes | Tested +---------|--------------|------|-------|--------|-----------|-----------|-------|---------|-------- +pngjs2 | pngjs | Read | Yes | Yes | Yes | Yes | Yes | Yes | Yes +node-png | pngjs | No | Yes | No | No | No | Hidden| Yes | Manual +pngjs | | No | Yes | No | No | No | Hidden| Yes | Manual +png-coder| pngjs | No | Yes | Yes | No | No | Hidden| Yes | Manual +pngparse | | No | Yes | No | Yes | No | No | No | Yes +pngparse-sync | pngparse| Yes | No | No | Yes | No | No | No | Yes +png-async| | No | Yes | No | No | No | No | Yes | Yes +png-js | | No | Yes | No | No | No | No | No | No + + +Native C++ node decoders: + * png + * png-sync (sync version of above) + * pixel-png + * png-img Tests ===== - Tested using [PNG Suite](http://www.schaik.com/pngsuite/). +Tested using [PNG Suite](http://www.schaik.com/pngsuite/). We read every file into pngjs2, output it in standard 8bit colour, synchronously and asynchronously, then compare the original +with the newly saved images. + +To run the tests, run `node test`. + +The only thing not converted is gamma correction - this is because multiple vendors will do gamma correction differently, so the tests will have different results on different browsers. - To run the tests in phantomjs, run `node test`. +In addition we use a tolerance of 3 for 16 bit images in PhantomJS because PhantomJS seems to have non-compliant rules for downscaling 16 bit images. TODO: How to run the gamma tests TODO: How to run the tests in chrome diff --git a/package.json b/package.json index 1a36f95..41c6b69 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,16 @@ ], "homepage": "https://github.com/lukeapage/pngjs2", "keywords": [ - "png" + "png", + "PNG", + "parser", + "encoder", + "decoder", + "pngjs", + "node-png", + "png-parse", + "png-js", + "js-png" ], "engines": { "node": "0.10.x" diff --git a/test/convert-images.js b/test/convert-images.js index 59d5a5b..e009573 100644 --- a/test/convert-images.js +++ b/test/convert-images.js @@ -13,18 +13,23 @@ module.exports = function(done) { console.log("Converting images"); - var asyncSaved = 0; + var completed = 0; + var expected = files.length * 2; + function complete() { + completed++; + if (expected === completed) { + done(); + } + } files.forEach(function (file) { - - var expectedError = false; if (file.match(/^x/)) { expectedError = true; } - var syncError = true; + var syncError = false; var data = fs.readFileSync(__dirname + '/in/' + file); try { var png = PNG.sync.read(data); @@ -33,22 +38,28 @@ module.exports = function(done) { console.log("Unexpected error parsing.." + file); console.log(e); console.log(e.stack); - syncError = true; } + syncError = true; + complete(); } if (!syncError) { if (expectedError) { console.log("Error expected, parsed fine ..", file); - } + complete(); + } else { - var outpng = new PNG(); - //PNG.adjustGamma(png); - outpng.data = png.data; - outpng.width = png.width; - outpng.height = png.height; - outpng.pack() - .pipe(fs.createWriteStream(__dirname + '/outsync/' + file)); + var outpng = new PNG(); + //PNG.adjustGamma(png); + outpng.data = png.data; + outpng.width = png.width; + outpng.height = png.height; + outpng.pack() + .pipe(fs.createWriteStream(__dirname + '/outsync/' + file) + .on("finish", function () { + complete(); + })); + } } fs.createReadStream(__dirname + '/in/' + file) @@ -57,10 +68,7 @@ module.exports = function(done) { if (!expectedError) { console.log("Error reading " + file, err); } - asyncSaved++; - if (asyncSaved === files.length) { - done(); - } + complete(); }) .on('parsed', function () { @@ -70,13 +78,11 @@ module.exports = function(done) { //this.adjustGamma(); this.pack() - .on("end", function() { - asyncSaved++; - if (asyncSaved === files.length) { - done(); - } - }) - .pipe(fs.createWriteStream(__dirname + '/out/' + file)) + .pipe( + fs.createWriteStream(__dirname + '/out/' + file) + .on("finish", function() { + complete(); + })); }); diff --git a/test/phantom-compare.js b/test/phantom-compare.js index ca961b8..7d2a731 100644 --- a/test/phantom-compare.js +++ b/test/phantom-compare.js @@ -16,11 +16,21 @@ setInterval(function() { if (results) { var success = true; + var successes = [], + failures = []; for(var i = 0; i < results.length; i++) { var result = results[i]; - console.log(result.name, result.success); + if (result.success) { + successes.push(result.name); + } else { + failures.push(result.name); + } success = success && result.success; } + console.log("Success:", successes.join(", ")); + if (failures.length) { + console.log("Failure:", failures.join(", ")); + } phantom.exit(success ? 0 : 1); return;