diff --git a/README.md b/README.md index 89307ae..3684994 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,12 @@ Known lack of support for: Tests ===== - Tested using [PNG Suite](http://www.schaik.com/pngsuite/). To see tests, run `node test/test` and `view test/list.html`. + Tested using [PNG Suite](http://www.schaik.com/pngsuite/). + + To run the tests in phantomjs, run `node test`. + + TODO: How to run the gamma tests + TODO: How to run the tests in chrome Installation =============== diff --git a/lib/parser-async.js b/lib/parser-async.js index 93bc41c..7561747 100644 --- a/lib/parser-async.js +++ b/lib/parser-async.js @@ -100,12 +100,17 @@ ParserAsync.prototype._finished = function(data) { ParserAsync.prototype._complete = function(data, width, height) { - data = bitmapper.dataToBitMap(data, width, height, - this._bpp, - this._depth, - this._interlace); + try { + data = bitmapper.dataToBitMap(data, width, height, + this._bpp, + this._depth, + this._interlace); - data = this._parser.reverseFiltered(data, this._depth, width, height); + data = this._parser.reverseFiltered(data, this._depth, width, height); + } + catch(e) { + this.emit('error', e); + } this.emit('parsed', data); }; diff --git a/package.json b/package.json index 6ed6b83..1a36f95 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,15 @@ "name": "pngjs2", "version": "0.0.2", "description": "Pure JS PNG encoder/decoder", - "contributors": ["Kuba Niegowski", "Luke Page", "Pietajan De Potter", "Steven Sojka", "Alexandre Paré", "Gaurav Mali", "liangzeng"], + "contributors": [ + "Alexandre Paré", + "Gaurav Mali", + "Kuba Niegowski", + "Luke Page", + "Pietajan De Potter", + "Steven Sojka", + "liangzeng" + ], "homepage": "https://github.com/lukeapage/pngjs2", "keywords": [ "png" @@ -24,5 +32,10 @@ "license": "MIT", "bugs": { "url": "https://github.com/lukeapage/pngjs2/issues" + }, + "devDependencies": { + "connect": "^3.4.0", + "phantomjs": "^1.9.17", + "serve-static": "^1.10.0" } } diff --git a/test/convert-images.js b/test/convert-images.js new file mode 100644 index 0000000..59d5a5b --- /dev/null +++ b/test/convert-images.js @@ -0,0 +1,85 @@ + +var fs = require('fs'), + PNG = require('../lib/png').PNG; + +module.exports = function(done) { + + fs.readdir(__dirname + '/in/', function (err, files) { + if (err) throw err; + + files = files.filter(function(file) { + return Boolean(file.match(/\.png$/i)); + }); + + console.log("Converting images"); + + var asyncSaved = 0; + + files.forEach(function (file) { + + + + var expectedError = false; + if (file.match(/^x/)) { + expectedError = true; + } + + var syncError = true; + var data = fs.readFileSync(__dirname + '/in/' + file); + try { + var png = PNG.sync.read(data); + } catch (e) { + if (!expectedError) { + console.log("Unexpected error parsing.." + file); + console.log(e); + console.log(e.stack); + syncError = true; + } + } + + if (!syncError) { + if (expectedError) { + console.log("Error expected, parsed fine ..", 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)); + } + + fs.createReadStream(__dirname + '/in/' + file) + .pipe(new PNG()) + .on('error', function (err) { + if (!expectedError) { + console.log("Error reading " + file, err); + } + asyncSaved++; + if (asyncSaved === files.length) { + done(); + } + }) + .on('parsed', function () { + + if (expectedError) { + console.log("Error expected, parsed fine", file); + } + //this.adjustGamma(); + + this.pack() + .on("end", function() { + asyncSaved++; + if (asyncSaved === files.length) { + done(); + } + }) + .pipe(fs.createWriteStream(__dirname + '/out/' + file)) + + }); + + }); + }); +} diff --git a/test/http-server.js b/test/http-server.js new file mode 100644 index 0000000..711c87b --- /dev/null +++ b/test/http-server.js @@ -0,0 +1,14 @@ +var serveStatic = require('serve-static'); +//var serveIndex = require('serve-index'); +var http = require('http'); +var connect = require('connect'); + +var app = connect(); +server = http.createServer(app); + +app.use(serveStatic('test')); +//app.use(serveIndex('test')); + +server.listen(8000); + +console.log("Tests available at http://localhost:8000/"); diff --git a/test/list.html b/test/index.html similarity index 95% rename from test/list.html rename to test/index.html index 3b02def..fa20506 100644 --- a/test/list.html +++ b/test/index.html @@ -198,7 +198,32 @@