This commit is contained in:
Luke Page 2015-08-06 13:23:33 +01:00
parent 5310b0ed5f
commit a5b282356b
7 changed files with 42 additions and 28 deletions

View file

@ -46,6 +46,7 @@
"url": "https://github.com/lukeapage/pngjs2/issues"
},
"devDependencies": {
"buffer-equal": "0.0.1",
"connect": "^3.4.0",
"coveralls": "^2.11.3",
"eslint": "^1.0.0",

1
test/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
bg.png

BIN
test/bg-ref.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 119 B

39
test/bg-spec.js Normal file
View file

@ -0,0 +1,39 @@
#!/usr/bin/env node
var fs = require('fs');
var PNG = require('../lib/png').PNG;
var test = require('tape');
var bufferEqual = require('buffer-equal');
test('outputs background, created from scratch', function (t) {
var png = new PNG({
width: 10,
height: 10,
filterType: -1
});
for (var y = 0; y < png.height; y++) {
for (var x = 0; x < png.width; x++) {
var idx = (png.width * y + x) << 2;
var col = x < (png.width >> 1) ^ y < (png.height >> 1) ? 0xe5 : 0xff;
png.data[idx] = col;
png.data[idx + 1] = col;
png.data[idx + 2] = col;
png.data[idx + 3] = 0xff;
}
}
png.pack().pipe(fs.createWriteStream(__dirname + '/bg.png'))
.on("finish", function () {
var out = fs.readFileSync(__dirname + '/bg.png');
var ref = fs.readFileSync(__dirname + '/bg-ref.png');
t.ok(bufferEqual(out, ref), "compares with working file ok");
t.end();
});
});

View file

@ -1,27 +0,0 @@
#!/usr/bin/env node
var fs = require('fs'),
PNG = require('pngjs').PNG;
var png = new PNG({
width: 10,
height: 10,
filterType: -1
});
for (var y = 0; y < png.height; y++) {
for (var x = 0; x < png.width; x++) {
var idx = (png.width * y + x) << 2;
var col = x < (png.width >> 1) ^ y < (png.height >> 1) ? 0xe5 : 0xff;
png.data[idx] = col;
png.data[idx + 1] = col;
png.data[idx + 2] = col;
png.data[idx + 3] = 0xff;
}
}
png.pack().pipe(fs.createWriteStream(__dirname + '/bg.png'));

Binary file not shown.

Before

Width:  |  Height:  |  Size: 93 B

After

Width:  |  Height:  |  Size: 119 B

View file

@ -13,7 +13,7 @@ try {
console.log("Comparing in PhantomJS");
childProcess.execFile(binPath, childArgs, function (err, stdout, stderr) {
// handle results
console.log("Comparison Test Results:");
console.log(stdout);