Browse files

integrated buffer helpers

  • Loading branch information...
1 parent b86cfa6 commit 477a84c1d1e53ae6caf991b9cfcb2ba42062ffa9 @elbart elbart committed Apr 26, 2011
Showing with 13 additions and 10 deletions.
  1. +5 −4 src/dynamic_jpeg_stack.cpp
  2. +4 −3 src/fixed_jpeg_stack.cpp
  3. +4 −3 src/jpeg.cpp
View
9 src/dynamic_jpeg_stack.cpp
@@ -7,6 +7,7 @@
#include "common.h"
#include "dynamic_jpeg_stack.h"
#include "jpeg_encoder.h"
+#include "buffer_compat.h"
using namespace v8;
using namespace node;
@@ -71,7 +72,7 @@ DynamicJpegStack::JpegEncodeSync()
jpeg_encoder.encode();
int jpeg_len = jpeg_encoder.get_jpeg_len();
Buffer *retbuf = Buffer::New(jpeg_len);
- memcpy(retbuf->data(), jpeg_encoder.get_jpeg(), jpeg_len);
+ memcpy(BufferData(retbuf), jpeg_encoder.get_jpeg(), jpeg_len);
return scope.Close(retbuf->handle_);
}
catch (const char *err) {
@@ -294,7 +295,7 @@ DynamicJpegStack::Push(const Arguments &args)
if (y+h > jpeg->bg_height)
return VException("Pushed fragment exceeds DynamicJpegStack's height.");
- jpeg->Push((unsigned char *)data_buf->data(), x, y, w, h);
+ jpeg->Push((unsigned char *)BufferData(data_buf), x, y, w, h);
return Undefined();
}
@@ -324,7 +325,7 @@ DynamicJpegStack::SetBackground(const Arguments &args)
return VException("Coordinate y smaller than 0.");
try {
- jpeg->SetBackground((unsigned char *)data_buf->data(), w, h);
+ jpeg->SetBackground((unsigned char *)BufferData(data_buf), w, h);
}
catch (const char *err) {
return VException(err);
@@ -422,7 +423,7 @@ DynamicJpegStack::EIO_JpegEncodeAfter(eio_req *req)
}
else {
Buffer *buf = Buffer::New(enc_req->jpeg_len);
- memcpy(buf->data(), enc_req->jpeg, enc_req->jpeg_len);
+ memcpy(BufferData(buf), enc_req->jpeg, enc_req->jpeg_len);
argv[0] = buf->handle_;
argv[1] = jpeg->Dimensions();
argv[2] = Undefined();
View
7 src/fixed_jpeg_stack.cpp
@@ -7,6 +7,7 @@
#include "common.h"
#include "fixed_jpeg_stack.h"
#include "jpeg_encoder.h"
+#include "buffer_compat.h"
using namespace v8;
using namespace node;
@@ -42,7 +43,7 @@ FixedJpegStack::JpegEncodeSync()
jpeg_encoder.encode();
int jpeg_len = jpeg_encoder.get_jpeg_len();
Buffer *retbuf = Buffer::New(jpeg_len);
- memcpy(retbuf->data(), jpeg_encoder.get_jpeg(), jpeg_len);
+ memcpy(BufferData(retbuf), jpeg_encoder.get_jpeg(), jpeg_len);
return scope.Close(retbuf->handle_);
}
catch (const char *err) {
@@ -217,7 +218,7 @@ FixedJpegStack::Push(const Arguments &args)
if (y+h > jpeg->height)
return VException("Pushed fragment exceeds FixedJpegStack's height.");
- jpeg->Push((unsigned char *)data_buf->data(), x, y, w, h);
+ jpeg->Push((unsigned char *)BufferData(data_buf), x, y, w, h);
return Undefined();
}
@@ -288,7 +289,7 @@ FixedJpegStack::EIO_JpegEncodeAfter(eio_req *req)
}
else {
Buffer *buf = Buffer::New(enc_req->jpeg_len);
- memcpy(buf->data(), enc_req->jpeg, enc_req->jpeg_len);
+ memcpy(BufferData(buf), enc_req->jpeg, enc_req->jpeg_len);
argv[0] = buf->handle_;
argv[1] = Undefined();
}
View
7 src/jpeg.cpp
@@ -7,6 +7,7 @@
#include "common.h"
#include "jpeg.h"
#include "jpeg_encoder.h"
+#include "buffer_compat.h"
using namespace v8;
using namespace node;
@@ -25,7 +26,7 @@ Jpeg::Initialize(v8::Handle<v8::Object> target)
}
Jpeg::Jpeg(Buffer *ddata, int wwidth, int hheight, buffer_type bbuf_type) :
- jpeg_encoder((unsigned char *)ddata->data(), wwidth, hheight, 60, bbuf_type) {}
+ jpeg_encoder((unsigned char *)BufferData(ddata), wwidth, hheight, 60, bbuf_type) {}
Handle<Value>
Jpeg::JpegEncodeSync()
@@ -41,7 +42,7 @@ Jpeg::JpegEncodeSync()
int jpeg_len = jpeg_encoder.get_jpeg_len();
Buffer *retbuf = Buffer::New(jpeg_len);
- memcpy(retbuf->data(), jpeg_encoder.get_jpeg(), jpeg_len);
+ memcpy(BufferData(retbuf), jpeg_encoder.get_jpeg(), jpeg_len);
return scope.Close(retbuf->handle_);
}
@@ -177,7 +178,7 @@ Jpeg::EIO_JpegEncodeAfter(eio_req *req)
}
else {
Buffer *buf = Buffer::New(enc_req->jpeg_len);
- memcpy(buf->data(), enc_req->jpeg, enc_req->jpeg_len);
+ memcpy(BufferData(buf), enc_req->jpeg, enc_req->jpeg_len);
argv[0] = buf->handle_;
argv[1] = Undefined();
}

0 comments on commit 477a84c

Please sign in to comment.