mirror of
https://github.com/danbulant/pngjs
synced 2026-07-07 12:10:59 +00:00
bg spec
This commit is contained in:
parent
5310b0ed5f
commit
a5b282356b
7 changed files with 42 additions and 28 deletions
|
|
@ -46,6 +46,7 @@
|
||||||
"url": "https://github.com/lukeapage/pngjs2/issues"
|
"url": "https://github.com/lukeapage/pngjs2/issues"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
"buffer-equal": "0.0.1",
|
||||||
"connect": "^3.4.0",
|
"connect": "^3.4.0",
|
||||||
"coveralls": "^2.11.3",
|
"coveralls": "^2.11.3",
|
||||||
"eslint": "^1.0.0",
|
"eslint": "^1.0.0",
|
||||||
|
|
|
||||||
1
test/.gitignore
vendored
Normal file
1
test/.gitignore
vendored
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
bg.png
|
||||||
BIN
test/bg-ref.png
Normal file
BIN
test/bg-ref.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 119 B |
39
test/bg-spec.js
Normal file
39
test/bg-spec.js
Normal 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();
|
||||||
|
});
|
||||||
|
});
|
||||||
27
test/bg.js
27
test/bg.js
|
|
@ -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'));
|
|
||||||
BIN
test/bg.png
BIN
test/bg.png
Binary file not shown.
|
Before Width: | Height: | Size: 93 B After Width: | Height: | Size: 119 B |
|
|
@ -13,7 +13,7 @@ try {
|
||||||
console.log("Comparing in PhantomJS");
|
console.log("Comparing in PhantomJS");
|
||||||
|
|
||||||
childProcess.execFile(binPath, childArgs, function (err, stdout, stderr) {
|
childProcess.execFile(binPath, childArgs, function (err, stdout, stderr) {
|
||||||
|
|
||||||
// handle results
|
// handle results
|
||||||
console.log("Comparison Test Results:");
|
console.log("Comparison Test Results:");
|
||||||
console.log(stdout);
|
console.log(stdout);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue