Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

DynamicJpegStack now returns Buffer

  • Loading branch information...
commit 7090e1bbb2075aa09e41381b866db72b591fa9be 1 parent 1b2ac0c
Peteris Krumins authored August 18, 2010
8  examples/dynamic-jpeg-stack-async.js
@@ -22,14 +22,12 @@ var files = fs.readdirSync('./push-data');
22 22
 
23 23
 files.forEach(function(file) {
24 24
     var dim = rectDim(file);
25  
-    var rgba = fs.readFileSync('./push-data/' + file, 'binary');
26  
-    var buf = new Buffer(rgba.length);
27  
-    buf.write(rgba, 'binary');
28  
-    jpegStack.push(buf, dim.x, dim.y, dim.w, dim.h);
  25
+    var rgba = fs.readFileSync('./push-data/' + file);
  26
+    jpegStack.push(rgba, dim.x, dim.y, dim.w, dim.h);
29 27
 });
30 28
 
31 29
 jpegStack.encode(function (image, dims) {
32  
-    fs.writeFileSync('dynamic-async.jpg', image, 'binary');
  30
+    fs.writeFileSync('dynamic-async.jpg', image.toString('binary'), 'binary');
33 31
     sys.puts("x: " + dims.x + ", y: " + dims.y + ", w: " + dims.width + ", h: " + dims.height);
34 32
 });
35 33
 
8  examples/dynamic-jpeg-stack.js
@@ -22,13 +22,11 @@ var files = fs.readdirSync('./push-data');
22 22
 
23 23
 files.forEach(function(file) {
24 24
     var dim = rectDim(file);
25  
-    var rgba = fs.readFileSync('./push-data/' + file, 'binary');
26  
-    var buf = new Buffer(rgba.length);
27  
-    buf.write(rgba, 'binary');
28  
-    jpegStack.push(buf, dim.x, dim.y, dim.w, dim.h);
  25
+    var rgba = fs.readFileSync('./push-data/' + file);
  26
+    jpegStack.push(rgba, dim.x, dim.y, dim.w, dim.h);
29 27
 });
30 28
 
31  
-fs.writeFileSync('dynamic.jpg', jpegStack.encodeSync(), 'binary');
  29
+fs.writeFileSync('dynamic.jpg', jpegStack.encodeSync().toString('binary'), 'binary');
32 30
 
33 31
 var dims = jpegStack.dimensions();
34 32
 
11  src/dynamic_jpeg_stack.cpp
@@ -69,9 +69,10 @@ DynamicJpegStack::JpegEncodeSync()
69 69
         JpegEncoder jpeg_encoder(data, bg_width, bg_height, quality, BUF_RGB);
70 70
         jpeg_encoder.setRect(Rect(dyn_rect.x, dyn_rect.y, dyn_rect.w, dyn_rect.h));
71 71
         jpeg_encoder.encode();
72  
-        return scope.Close(
73  
-            Encode(jpeg_encoder.get_jpeg(), jpeg_encoder.get_jpeg_len(), BINARY)
74  
-        );
  72
+        int jpeg_len = jpeg_encoder.get_jpeg_len();
  73
+        Buffer *retbuf = Buffer::New(jpeg_len);
  74
+        memcpy(retbuf->data(), jpeg_encoder.get_jpeg(), jpeg_len);
  75
+        return scope.Close(retbuf->handle_); 
75 76
     }
76 77
     catch (const char *err) {
77 78
         return VException(err);
@@ -420,7 +421,9 @@ DynamicJpegStack::EIO_JpegEncodeAfter(eio_req *req)
420 421
         argv[2] = ErrorException(enc_req->error);
421 422
     }
422 423
     else {
423  
-        argv[0] = Local<Value>::New(Encode(enc_req->jpeg, enc_req->jpeg_len, BINARY));
  424
+        Buffer *buf = Buffer::New(enc_req->jpeg_len);
  425
+        memcpy(buf->data(), enc_req->jpeg, enc_req->jpeg_len);
  426
+        argv[0] = buf->handle_;
424 427
         argv[1] = jpeg->Dimensions();
425 428
         argv[2] = Undefined();
426 429
     }

0 notes on commit 7090e1b

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