Permalink
Browse files

upgrade to node 0.3

  • Loading branch information...
1 parent 9b3af33 commit 8be64dc83dd39af890e4c89a4baf3dace7d2092e @mnutt mnutt committed Mar 18, 2011
Showing with 142 additions and 43 deletions.
  1. +3 −0 .gitignore
  2. +10 −8 src/animated_gif.cpp
  3. +12 −10 src/async_animated_gif.cpp
  4. +58 −0 src/buffer_compat.cpp
  5. +15 −0 src/buffer_compat.h
  6. +1 −0 src/common.h
  7. +13 −9 src/dynamic_gif_stack.cpp
  8. +1 −1 src/dynamic_gif_stack.h
  9. +26 −11 src/gif.cpp
  10. +1 −2 src/gif.h
  11. +2 −2 wscript
View
@@ -0,0 +1,3 @@
+/gif.node
+/build/
+.lock-wscript
View
@@ -3,6 +3,7 @@
#include "common.h"
#include "gif_encoder.h"
#include "animated_gif.h"
+#include "buffer_compat.h"
using namespace v8;
using namespace node;
@@ -105,7 +106,7 @@ AnimatedGif::New(const Arguments &args)
{
return VException("Third argument must be 'rgb', 'bgr', 'rgba' or 'bgra'.");
}
-
+
if (str_eq(*bts, "rgb"))
buf_type = BUF_RGB;
else if (str_eq(*bts, "bgr"))
@@ -148,7 +149,6 @@ AnimatedGif::Push(const Arguments &args)
return VException("Fifth argument must be integer h.");
AnimatedGif *gif = ObjectWrap::Unwrap<AnimatedGif>(args.This());
- Buffer *data_buf = ObjectWrap::Unwrap<Buffer>(args[0]->ToObject());
int x = args[1]->Int32Value();
int y = args[2]->Int32Value();
int w = args[3]->Int32Value();
@@ -162,17 +162,19 @@ AnimatedGif::Push(const Arguments &args)
return VException("Width smaller than 0.");
if (h < 0)
return VException("Height smaller than 0.");
- if (x >= gif->width)
+ if (x >= gif->width)
return VException("Coordinate x exceeds AnimatedGif's dimensions.");
- if (y >= gif->height)
+ if (y >= gif->height)
return VException("Coordinate y exceeds AnimatedGif's dimensions.");
- if (x+w > gif->width)
+ if (x+w > gif->width)
return VException("Pushed fragment exceeds AnimatedGif's width.");
- if (y+h > gif->height)
+ if (y+h > gif->height)
return VException("Pushed fragment exceeds AnimatedGif's height.");
try {
- gif->Push((unsigned char *)data_buf->data(), x, y, w, h);
+ char *buf_data = BufferData(args[0]->ToObject());
+
+ gif->Push((unsigned char*)buf_data, x, y, w, h);
}
catch (const char *err) {
return VException(err);
@@ -206,7 +208,7 @@ AnimatedGif::GetGif(const Arguments &args)
gif->gif_encoder.finish();
int gif_len = gif->gif_encoder.get_gif_len();
Buffer *retbuf = Buffer::New(gif_len);
- memcpy(retbuf->data(), gif->gif_encoder.get_gif(), gif_len);
+ memcpy(BufferData(retbuf), gif->gif_encoder.get_gif(), gif_len);
return scope.Close(retbuf->handle_);
}
View
@@ -5,6 +5,7 @@
#include "utils.h"
#include "gif_encoder.h"
#include "async_animated_gif.h"
+#include "buffer_compat.h"
#include "loki/ScopeGuard.h"
@@ -81,7 +82,7 @@ int
AsyncAnimatedGif::EIO_PushAfter(eio_req *req)
{
ev_unref(EV_DEFAULT_UC);
-
+
push_request *push_req = (push_request *)req->data;
free(push_req->data);
free(push_req);
@@ -156,7 +157,7 @@ AsyncAnimatedGif::New(const Arguments &args)
{
return VException("Third argument must be 'rgb', 'bgr', 'rgba' or 'bgra'.");
}
-
+
if (str_eq(*bts, "rgb"))
buf_type = BUF_RGB;
else if (str_eq(*bts, "bgr"))
@@ -199,8 +200,8 @@ AsyncAnimatedGif::Push(const Arguments &args)
return VException("Fifth argument must be integer h.");
AsyncAnimatedGif *gif = ObjectWrap::Unwrap<AsyncAnimatedGif>(args.This());
- Buffer *data_buf = ObjectWrap::Unwrap<Buffer>(args[0]->ToObject());
- unsigned char *buf = (unsigned char *)data_buf->data();
+ // Buffer *data_buf = ObjectWrap::Unwrap<Buffer>(args[0]->ToObject());
+ // unsigned char *buf = (unsigned char *)data_buf->data();
int x = args[1]->Int32Value();
int y = args[2]->Int32Value();
int w = args[3]->Int32Value();
@@ -214,17 +215,18 @@ AsyncAnimatedGif::Push(const Arguments &args)
return VException("Width smaller than 0.");
if (h < 0)
return VException("Height smaller than 0.");
- if (x >= gif->width)
+ if (x >= gif->width)
return VException("Coordinate x exceeds AsyncAnimatedGif's dimensions.");
- if (y >= gif->height)
+ if (y >= gif->height)
return VException("Coordinate y exceeds AsyncAnimatedGif's dimensions.");
- if (x+w > gif->width)
+ if (x+w > gif->width)
return VException("Pushed fragment exceeds AsyncAnimatedGif's width.");
- if (y+h > gif->height)
+ if (y+h > gif->height)
return VException("Pushed fragment exceeds AsyncAnimatedGif's height.");
try {
- gif->Push(buf, x, y, w, h);
+ char *buf_data = BufferData(args[0]->ToObject());
+ gif->Push((unsigned char*)buf_data, x, y, w, h);
}
catch (const char *err) {
return VException(err);
@@ -368,7 +370,7 @@ AsyncAnimatedGif::EIO_Encode(eio_req *req)
return 0;
}
Rect dims = rect_dims(fragments[i]);
- push_fragment(frame, gif->width, gif->height, gif->buf_type,
+ push_fragment(frame, gif->width, gif->height, gif->buf_type,
data, dims.x, dims.y, dims.w, dims.h);
}
encoder.new_frame(frame);
View
@@ -0,0 +1,58 @@
+#include <node.h>
+#include <node_buffer.h>
+#include <node_version.h>
+#include <v8.h>
+#include "buffer_compat.h"
+
+
+#if NODE_MINOR_VERSION < 3
+
+
+char *BufferData(node::Buffer *b) {
+ return b->data();
+}
+
+
+size_t BufferLength(node::Buffer *b) {
+ return b->length();
+}
+
+
+char *BufferData(v8::Local<v8::Object> buf_obj) {
+ v8::HandleScope scope;
+ node::Buffer *buf = node::ObjectWrap::Unwrap<node::Buffer>(buf_obj);
+ return buf->data();
+}
+
+
+size_t BufferLength(v8::Local<v8::Object> buf_obj) {
+ v8::HandleScope scope;
+ node::Buffer *buf = node::ObjectWrap::Unwrap<node::Buffer>(buf_obj);
+ return buf->length();
+}
+
+#else // NODE_VERSION
+
+
+char *BufferData(node::Buffer *b) {
+ return node::Buffer::Data(b->handle_);
+}
+
+
+size_t BufferLength(node::Buffer *b) {
+ return node::Buffer::Length(b->handle_);
+}
+
+
+char *BufferData(v8::Local<v8::Object> buf_obj) {
+ v8::HandleScope scope;
+ return node::Buffer::Data(buf_obj);
+}
+
+
+size_t BufferLength(v8::Local<v8::Object> buf_obj) {
+ v8::HandleScope scope;
+ return node::Buffer::Length(buf_obj);
+}
+
+#endif // NODE_VERSION
View
@@ -0,0 +1,15 @@
+#ifndef buffer_compat_h
+#define buffer_compat_h
+
+#include <node.h>
+#include <node_buffer.h>
+#include <v8.h>
+
+char *BufferData(node::Buffer *b);
+size_t BufferLength(node::Buffer *b);
+
+char *BufferData(v8::Local<v8::Object> buf_obj);
+size_t BufferLength(v8::Local<v8::Object> buf_obj);
+
+
+#endif // buffer_compat_h
View
@@ -38,6 +38,7 @@ struct encode_request {
char *gif;
int gif_len;
char *error;
+ char *buf_data;
};
#endif
View
@@ -1,6 +1,7 @@
#include "common.h"
#include "gif_encoder.h"
#include "dynamic_gif_stack.h"
+#include "buffer_compat.h"
using namespace v8;
using namespace node;
@@ -93,11 +94,10 @@ DynamicGifStack::~DynamicGifStack()
}
Handle<Value>
-DynamicGifStack::Push(Buffer *buf, int x, int y, int w, int h)
+DynamicGifStack::Push(unsigned char *buf_data, size_t buf_len, int x, int y, int w, int h)
{
try {
- GifUpdate *gif_update =
- new GifUpdate((unsigned char *)buf->data(), buf->length(), x, y, w, h);
+ GifUpdate *gif_update = new GifUpdate(buf_data, buf_len, x, y, w, h);
gif_stack.push_back(gif_update);
return Undefined();
}
@@ -137,7 +137,7 @@ DynamicGifStack::GifEncodeSync()
free(data);
int gif_len = encoder.get_gif_len();
Buffer *retbuf = Buffer::New(gif_len);
- memcpy(retbuf->data(), encoder.get_gif(), gif_len);
+ memcpy(BufferData(retbuf), encoder.get_gif(), gif_len);
return scope.Close(retbuf->handle_);
}
catch (const char *err) {
@@ -175,7 +175,7 @@ DynamicGifStack::New(const Arguments &args)
{
return VException("First argument must be 'rgb', 'bgr', 'rgba' or 'bgra'.");
}
-
+
if (str_eq(*bts, "rgb"))
buf_type = BUF_RGB;
else if (str_eq(*bts, "bgr"))
@@ -209,7 +209,6 @@ DynamicGifStack::Push(const Arguments &args)
if (!args[4]->IsInt32())
return VException("Fifth argument must be integer h.");
- Buffer *data = ObjectWrap::Unwrap<Buffer>(args[0]->ToObject());
int x = args[1]->Int32Value();
int y = args[2]->Int32Value();
int w = args[3]->Int32Value();
@@ -225,7 +224,12 @@ DynamicGifStack::Push(const Arguments &args)
return VException("Height smaller than 0.");
DynamicGifStack *gif_stack = ObjectWrap::Unwrap<DynamicGifStack>(args.This());
- return scope.Close(gif_stack->Push(data, x, y, w, h));
+
+ Local<Object> buf_obj = args[0]->ToObject();
+ char *buf_data = BufferData(buf_obj);
+ size_t buf_len = BufferLength(buf_obj);
+
+ return scope.Close(gif_stack->Push((unsigned char*)buf_data, buf_len, x, y, w, h));
}
Handle<Value>
@@ -299,7 +303,7 @@ DynamicGifStack::EIO_GifEncode(eio_req *req)
return 0;
}
-int
+int
DynamicGifStack::EIO_GifEncodeAfter(eio_req *req)
{
HandleScope scope;
@@ -317,7 +321,7 @@ DynamicGifStack::EIO_GifEncodeAfter(eio_req *req)
}
else {
Buffer *buf = Buffer::New(enc_req->gif_len);
- memcpy(buf->data(), enc_req->gif, enc_req->gif_len);
+ memcpy(BufferData(buf), enc_req->gif, enc_req->gif_len);
argv[0] = buf->handle_;
argv[1] = gif->Dimensions();
argv[2] = Undefined();
View
@@ -48,7 +48,7 @@ class DynamicGifStack : public node::ObjectWrap {
DynamicGifStack(buffer_type bbuf_type);
~DynamicGifStack();
- v8::Handle<v8::Value> Push(node::Buffer *buf, int x, int y, int w, int h);
+ v8::Handle<v8::Value> Push(unsigned char *buf_data, size_t buf_len, int x, int y, int w, int h);
v8::Handle<v8::Value> Dimensions();
v8::Handle<v8::Value> GifEncodeSync();
Oops, something went wrong.

0 comments on commit 8be64dc

Please sign in to comment.