Skip to content

Commit

Permalink
support node lastest
Browse files Browse the repository at this point in the history
  • Loading branch information
oxUnd committed Jan 10, 2014
1 parent 8f2cc80 commit 0ba6e49
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 37 deletions.
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('bindings')('gif');
module.exports = require('./build/Release/gif.node');
40 changes: 26 additions & 14 deletions src/async_animated_gif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ AsyncAnimatedGif::AsyncAnimatedGif(int wwidth, int hheight, buffer_type bbuf_typ
push_id(0), fragment_id(0) {}

void
AsyncAnimatedGif::EIO_Push(eio_req *req)
AsyncAnimatedGif::EIO_Push(uv_work_t *req)
{
push_request *push_req = (push_request *)req->data;

Expand Down Expand Up @@ -78,16 +78,15 @@ AsyncAnimatedGif::EIO_Push(eio_req *req)
return;
}

int
AsyncAnimatedGif::EIO_PushAfter(eio_req *req)
void
AsyncAnimatedGif::EIO_PushAfter(uv_work_t *req, int status)
{
ev_unref(EV_DEFAULT_UC);
//ev_unref(EV_DEFAULT_UC);

push_request *push_req = (push_request *)req->data;
free(push_req->data);
free(push_req);

return 0;
}

Handle<Value>
Expand All @@ -101,6 +100,8 @@ AsyncAnimatedGif::Push(unsigned char *data_buf, int x, int y, int w, int h)
if (output_file.empty())
throw "Output file is not set. Use .setOutputFile to set it before pushing.";

uv_work_t * req = new uv_work_t;

push_request *push_req = (push_request *)malloc(sizeof(*push_req));
if (!push_req)
throw "malloc in AsyncAnimatedGif::Push failed.";
Expand All @@ -121,8 +122,11 @@ AsyncAnimatedGif::Push(unsigned char *data_buf, int x, int y, int w, int h)
push_req->w = w;
push_req->h = h;

eio_custom(EIO_Push, EIO_PRI_DEFAULT, EIO_PushAfter, push_req);
ev_ref(EV_DEFAULT_UC);
req->data = push_req;

//eio_custom(EIO_Push, EIO_PRI_DEFAULT, EIO_PushAfter, push_req);
uv_queue_work(uv_default_loop(), req, &EIO_Push, &EIO_PushAfter);
//ev_ref(EV_DEFAULT_UC);

return Undefined();
}
Expand Down Expand Up @@ -314,7 +318,7 @@ AsyncAnimatedGif::rect_dims(const char *fragment_name)
}

void
AsyncAnimatedGif::EIO_Encode(eio_req *req)
AsyncAnimatedGif::EIO_Encode(uv_work_t *req)
{
async_encode_request *enc_req = (async_encode_request *)req->data;
AsyncAnimatedGif *gif = (AsyncAnimatedGif *)enc_req->gif_obj;
Expand Down Expand Up @@ -380,12 +384,12 @@ AsyncAnimatedGif::EIO_Encode(eio_req *req)
return;
}

int
AsyncAnimatedGif::EIO_EncodeAfter(eio_req *req)
void
AsyncAnimatedGif::EIO_EncodeAfter(uv_work_t *req, int status)
{
HandleScope scope;

ev_unref(EV_DEFAULT_UC);
//ev_unref(EV_DEFAULT_UC);
async_encode_request *enc_req = (async_encode_request *)req->data;

Handle<Value> argv[2];
Expand All @@ -411,7 +415,7 @@ AsyncAnimatedGif::EIO_EncodeAfter(eio_req *req)
enc_req->gif_obj->Unref();
free(enc_req);

return 0;
//return 0;
}

Handle<Value>
Expand All @@ -427,18 +431,26 @@ AsyncAnimatedGif::Encode(const Arguments &args)

Local<Function> callback = Local<Function>::Cast(args[0]);
AsyncAnimatedGif *gif = ObjectWrap::Unwrap<AsyncAnimatedGif>(args.This());

uv_work_t *req = new uv_work_t;

async_encode_request *enc_req = (async_encode_request *)malloc(sizeof(*enc_req));


if (!enc_req)
return VException("malloc in AsyncAnimatedGif::Encode failed.");

enc_req->callback = Persistent<Function>::New(callback);
enc_req->gif_obj = gif;
enc_req->error = NULL;

eio_custom(EIO_Encode, EIO_PRI_DEFAULT, EIO_EncodeAfter, enc_req);
req->data = enc_req;

//eio_custom(EIO_Encode, EIO_PRI_DEFAULT, EIO_EncodeAfter, enc_req);

ev_ref(EV_DEFAULT_UC);
uv_queue_work(uv_default_loop(), req, &EIO_Encode, &EIO_EncodeAfter);
//ev_ref(EV_DEFAULT_UC);

gif->Ref();

return Undefined();
Expand Down
8 changes: 4 additions & 4 deletions src/async_animated_gif.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class AsyncAnimatedGif : public node::ObjectWrap {
unsigned int push_id, fragment_id;
std::string tmp_dir, output_file;

static void EIO_Push(eio_req *req);
static int EIO_PushAfter(eio_req *req);
static void EIO_Push(uv_work_t *req);
static void EIO_PushAfter(uv_work_t *req, int status);

static void EIO_Encode(eio_req *req);
static int EIO_EncodeAfter(eio_req *req);
static void EIO_Encode(uv_work_t *req);
static void EIO_EncodeAfter(uv_work_t *req, int status);

static unsigned char *init_frame(int width, int height, Color &transparency_color);
static void push_fragment(unsigned char *frame, int width, int height, buffer_type buf_type,
Expand Down
18 changes: 11 additions & 7 deletions src/dynamic_gif_stack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ DynamicGifStack::GifEncodeSync(const Arguments &args)
}

void
DynamicGifStack::EIO_GifEncode(eio_req *req)
DynamicGifStack::EIO_GifEncode(uv_work_t *req)
{
encode_request *enc_req = (encode_request *)req->data;
DynamicGifStack *gif = (DynamicGifStack *)enc_req->gif_obj;
Expand Down Expand Up @@ -303,12 +303,13 @@ DynamicGifStack::EIO_GifEncode(eio_req *req)
return;
}

int
DynamicGifStack::EIO_GifEncodeAfter(eio_req *req)
void
DynamicGifStack::EIO_GifEncodeAfter(uv_work_t *req, int status)
{
HandleScope scope;

ev_unref(EV_DEFAULT_UC);
//ev_unref(EV_DEFAULT_UC);

encode_request *enc_req = (encode_request *)req->data;
DynamicGifStack *gif = (DynamicGifStack *)enc_req->gif_obj;

Expand Down Expand Up @@ -341,7 +342,7 @@ DynamicGifStack::EIO_GifEncodeAfter(eio_req *req)
gif->Unref();
free(enc_req);

return 0;
//return 0;
}

Handle<Value>
Expand All @@ -368,9 +369,12 @@ DynamicGifStack::GifEncodeAsync(const Arguments &args)
enc_req->gif_len = 0;
enc_req->error = NULL;

eio_custom(EIO_GifEncode, EIO_PRI_DEFAULT, EIO_GifEncodeAfter, enc_req);
uv_work_t * req = new uv_work_t;
req->data = enc_req;

ev_ref(EV_DEFAULT_UC);
//eio_custom(EIO_GifEncode, EIO_PRI_DEFAULT, EIO_GifEncodeAfter, enc_req);
uv_queue_work(uv_default_loop(), req, &EIO_GifEncode, &EIO_GifEncodeAfter);
//ev_ref(EV_DEFAULT_UC);
gif->Ref();

return Undefined();
Expand Down
4 changes: 2 additions & 2 deletions src/dynamic_gif_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ class DynamicGifStack : public node::ObjectWrap {

std::pair<Point, Point> optimal_dimension();

static void EIO_GifEncode(eio_req *req);
static int EIO_GifEncodeAfter(eio_req *req);
static void EIO_GifEncode(uv_work_t *req);
static void EIO_GifEncodeAfter(uv_work_t *req, int status);
void construct_gif_data(unsigned char *data, Point &top);

public:
Expand Down
21 changes: 14 additions & 7 deletions src/gif.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ Gif::SetTransparencyColor(const Arguments &args)
}

void
Gif::EIO_GifEncode(eio_req *req)
Gif::EIO_GifEncode(uv_work_t *req)
{
encode_request *enc_req = (encode_request *)req->data;
Gif *gif = (Gif *)enc_req->gif_obj;
Expand Down Expand Up @@ -174,12 +174,12 @@ Gif::EIO_GifEncode(eio_req *req)
return;
}

int
Gif::EIO_GifEncodeAfter(eio_req *req)
void
Gif::EIO_GifEncodeAfter(uv_work_t *req, int status)
{
HandleScope scope;

ev_unref(EV_DEFAULT_UC);
//ev_unref(EV_DEFAULT_UC);
encode_request *enc_req = (encode_request *)req->data;

Handle<Value> argv[2];
Expand Down Expand Up @@ -209,7 +209,7 @@ Gif::EIO_GifEncodeAfter(eio_req *req)
((Gif *)enc_req->gif_obj)->Unref();
free(enc_req);

return 0;
//return 0;
}

Handle<Value>
Expand Down Expand Up @@ -242,9 +242,16 @@ Gif::GifEncodeAsync(const Arguments &args)

enc_req->buf_data = BufferData(buf_val->ToObject());

eio_custom(EIO_GifEncode, EIO_PRI_DEFAULT, EIO_GifEncodeAfter, enc_req);
uv_work_t *req = new uv_work_t;

req->data = enc_req;

//eio_custom(EIO_GifEncode, EIO_PRI_DEFAULT, EIO_GifEncodeAfter, enc_req);

uv_queue_work(uv_default_loop(), req, EIO_GifEncode, EIO_GifEncodeAfter);

ev_ref(EV_DEFAULT_UC);
//ev_ref(EV_DEFAULT_UC);

gif->Ref();

return Undefined();
Expand Down
4 changes: 2 additions & 2 deletions src/gif.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class Gif : public node::ObjectWrap {
buffer_type buf_type;
Color transparency_color;

static void EIO_GifEncode(eio_req *req);
static int EIO_GifEncodeAfter(eio_req *req);
static void EIO_GifEncode(uv_work_t *req);
static void EIO_GifEncodeAfter(uv_work_t *req, int status);

public:
static void Initialize(v8::Handle<v8::Object> target);
Expand Down
6 changes: 6 additions & 0 deletions src/module.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ init(Handle<Object> target)
AsyncAnimatedGif::Initialize(target);
}


void RegisterModule(Handle<Object> target) {
init(target);
}

NODE_MODULE(gif, RegisterModule);

0 comments on commit 0ba6e49

Please sign in to comment.