Permalink
Browse files

FixedJpegStack now returns Buffer

  • Loading branch information...
1 parent 7104754 commit 1b2ac0c36b64ee00a5eea07893e74422de275124 @pkrumins committed Aug 18, 2010
Showing with 13 additions and 14 deletions.
  1. +3 −5 examples/fixed-jpeg-stack-async.js
  2. +3 −5 examples/fixed-jpeg-stack.js
  3. +7 −4 src/fixed_jpeg_stack.cpp
@@ -17,13 +17,11 @@ 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');
- jpegStack.push(buf, dim.x, dim.y, dim.w, dim.h);
+ var rgba = fs.readFileSync('./push-data/' + file);
+ jpegStack.push(rgba, dim.x, dim.y, dim.w, dim.h);
});
jpegStack.encode(function (image) {
- fs.writeFileSync('fixed-async.jpg', image, 'binary');
+ fs.writeFileSync('fixed-async.jpg', image.toString('binary'), 'binary');
});
@@ -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');
- jpegStack.push(buf, dim.x, dim.y, dim.w, dim.h);
+ var rgba = fs.readFileSync('./push-data/' + file);
+ jpegStack.push(rgba, dim.x, dim.y, dim.w, dim.h);
});
-fs.writeFileSync('fixed.jpg', jpegStack.encodeSync(), 'binary');
+fs.writeFileSync('fixed.jpg', jpegStack.encodeSync().toString('binary'), 'binary');
@@ -40,9 +40,10 @@ FixedJpegStack::JpegEncodeSync()
try {
JpegEncoder jpeg_encoder(data, width, height, quality, BUF_RGB);
jpeg_encoder.encode();
- return scope.Close(
- Encode(jpeg_encoder.get_jpeg(), jpeg_encoder.get_jpeg_len(), BINARY)
- );
+ int jpeg_len = jpeg_encoder.get_jpeg_len();
+ Buffer *retbuf = Buffer::New(jpeg_len);
+ memcpy(retbuf->data(), jpeg_encoder.get_jpeg(), jpeg_len);
+ return scope.Close(retbuf->handle_);
}
catch (const char *err) {
return VException(err);
@@ -286,7 +287,9 @@ FixedJpegStack::EIO_JpegEncodeAfter(eio_req *req)
argv[1] = ErrorException(enc_req->error);
}
else {
- argv[0] = Local<Value>::New(Encode(enc_req->jpeg, enc_req->jpeg_len, BINARY));
+ Buffer *buf = Buffer::New(enc_req->jpeg_len);
+ memcpy(buf->data(), enc_req->jpeg, enc_req->jpeg_len);
+ argv[0] = buf->handle_;
argv[1] = Undefined();
}

0 comments on commit 1b2ac0c

Please sign in to comment.