Permalink
Browse files

FixedPngStack now returns a Buffer again (ok way in sync interface an…

…d lousy way in async interface)
  • Loading branch information...
1 parent 2b89cf5 commit 589ec45dbf9f86230147babab53f9d17755ffef8 @pkrumins committed Aug 18, 2010
Showing with 15 additions and 14 deletions.
  1. +9 −4 src/fixed_png_stack.cpp
  2. +3 −5 tests/fixed-png-stack-async.js
  3. +3 −5 tests/fixed-png-stack.js
View
@@ -56,9 +56,12 @@ FixedPngStack::PngEncodeSync()
buffer_type pbt = (buf_type == BUF_BGR || buf_type == BUF_BGRA) ? BUF_BGRA : BUF_RGBA;
try {
- PngEncoder p(data, width, height, pbt);
- p.encode();
- return scope.Close(Encode((char *)p.get_png(), p.get_png_len(), BINARY));
+ PngEncoder encoder(data, width, height, pbt);
+ encoder.encode();
+ int png_len = encoder.get_png_len();
+ Buffer *retbuf = Buffer::New(png_len);
+ memcpy(retbuf->data(), encoder.get_png(), png_len);
+ return scope.Close(retbuf->handle_);
}
catch (const char *err) {
return VException(err);
@@ -209,7 +212,9 @@ FixedPngStack::EIO_PngEncodeAfter(eio_req *req)
argv[1] = ErrorException(enc_req->error);
}
else {
- argv[0] = Local<Value>::New(Encode(enc_req->png, enc_req->png_len, BINARY));
+ Buffer *buf = Buffer::New(enc_req->png_len);
+ memcpy(buf->data(), enc_req->png, enc_req->png_len);
+ argv[0] = buf->handle_;
argv[1] = Undefined();
}
@@ -17,17 +17,15 @@ 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);
+ var rgba = fs.readFileSync('./push-data/' + file);
+ pngStack.push(rgba, 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');
+ fs.writeFileSync('fixed-async.png', data.toString('binary'), 'binary');
});
View
@@ -17,11 +17,9 @@ 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);
+ var rgba = fs.readFileSync('./push-data/' + file);
+ pngStack.push(rgba, dim.x, dim.y, dim.w, dim.h);
});
-fs.writeFileSync('fixed.png', pngStack.encodeSync(), 'binary');
+fs.writeFileSync('fixed.png', pngStack.encodeSync().toString('binary'), 'binary');

0 comments on commit 589ec45

Please sign in to comment.