Skip to content
Browse files

this test uses async version of encode

  • Loading branch information...
1 parent 5259567 commit fc98430262454dc6a93d334a71f7bfa5fac9892a @pkrumins committed Aug 5, 2010
Showing with 33 additions and 0 deletions.
  1. +33 −0 tests/fixed-png-stack-async.js
View
33 tests/fixed-png-stack-async.js
@@ -0,0 +1,33 @@
+var PngLib = require('png');
+var fs = require('fs');
+var sys = require('sys');
+var Buffer = require('buffer').Buffer;
+
+var pngStack = new PngLib.FixedPngStack(720, 400, 'rgba');
+
+function rectDim(fileName) {
+ var m = fileName.match(/^\d+-rgba-(\d+)-(\d+)-(\d+)-(\d+).dat$/);
+ var dim = [m[1], m[2], m[3], m[4]].map(function (n) {
+ return parseInt(n, 10);
+ });
+ return { x: dim[0], y: dim[1], w: dim[2], h: dim[3] }
+}
+
+var files = fs.readdirSync('./push-data');
+
+files.forEach(function(file) {
+ var dim = rectDim(file);
+ var rgba = fs.readFileSync('./push-data/' + file, 'binary');
+ var buf = new Buffer(rgba.length);
+ buf.write(rgba, 'binary');
+ pngStack.push(buf, dim.x, dim.y, dim.w, dim.h);
+});
+
+pngStack.encode(function (data, error) {
+ if (error) {
+ console.log("Error: " + error);
+ process.exit(1);
+ }
+ fs.writeFileSync('fixed-async.png', data, 'binary');
+});
+

0 comments on commit fc98430

Please sign in to comment.
Something went wrong with that request. Please try again.