Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

factor the encode_request out to common.h

  • Loading branch information...
commit f513634e749b7d83a21f5a084ad8e1bb1a8fe8a5 1 parent 861e395
@pkrumins authored
View
8 src/common.h
@@ -27,5 +27,13 @@ unsigned char *bgr_to_rgb(const unsigned char *rgb, int rgb_size);
typedef enum { BUF_RGB, BUF_BGR, BUF_RGBA, BUF_BGRA } buffer_type;
+struct encode_request {
+ v8::Persistent<v8::Function> callback;
+ void *png_obj;
+ char *png;
+ int png_len;
+ char *error;
+};
+
#endif
View
15 src/dynamic_png_stack.cpp
@@ -217,19 +217,11 @@ DynamicPngStack::PngEncodeSync(const Arguments &args)
return scope.Close(png_stack->PngEncodeSync());
}
-struct encode_request {
- Persistent<Function> callback;
- DynamicPngStack *png_obj;
- char *png;
- int png_len;
- char *error;
-};
-
int
DynamicPngStack::EIO_PngEncode(eio_req *req)
{
encode_request *enc_req = (encode_request *)req->data;
- DynamicPngStack *png = enc_req->png_obj;
+ DynamicPngStack *png = (DynamicPngStack *)enc_req->png_obj;
std::pair<Point, Point> optimal = png->optimal_dimension();
Point top = optimal.first, bot = optimal.second;
@@ -280,6 +272,7 @@ DynamicPngStack::EIO_PngEncodeAfter(eio_req *req)
ev_unref(EV_DEFAULT_UC);
encode_request *enc_req = (encode_request *)req->data;
+ DynamicPngStack *png = (DynamicPngStack *)enc_req->png_obj;
Handle<Value> argv[3];
@@ -290,7 +283,7 @@ DynamicPngStack::EIO_PngEncodeAfter(eio_req *req)
}
else {
argv[0] = Local<Value>::New(Encode(enc_req->png, enc_req->png_len, BINARY));
- argv[1] = enc_req->png_obj->Dimensions();
+ argv[1] = png->Dimensions();
argv[2] = Undefined();
}
@@ -305,7 +298,7 @@ DynamicPngStack::EIO_PngEncodeAfter(eio_req *req)
free(enc_req->png);
free(enc_req->error);
- enc_req->png_obj->Unref();
+ png->Unref();
free(enc_req);
return 0;
View
12 src/fixed_png_stack.cpp
@@ -168,19 +168,11 @@ FixedPngStack::PngEncodeSync(const Arguments &args)
return png_stack->PngEncodeSync();
}
-struct encode_request {
- Persistent<Function> callback;
- FixedPngStack *png_obj;
- char *png;
- int png_len;
- char *error;
-};
-
int
FixedPngStack::EIO_PngEncode(eio_req *req)
{
encode_request *enc_req = (encode_request *)req->data;
- FixedPngStack *png = enc_req->png_obj;
+ FixedPngStack *png = (FixedPngStack *)enc_req->png_obj;
try {
PngEncoder p(png->data, png->width, png->height, png->buf_type);
@@ -232,7 +224,7 @@ FixedPngStack::EIO_PngEncodeAfter(eio_req *req)
free(enc_req->png);
free(enc_req->error);
- enc_req->png_obj->Unref();
+ ((FixedPngStack *)enc_req->png_obj)->Unref();
free(enc_req);
return 0;
View
12 src/nodepng.cpp
@@ -97,19 +97,11 @@ Png::PngEncodeSync(const Arguments &args)
return scope.Close(png->PngEncodeSync());
}
-struct encode_request {
- Persistent<Function> callback;
- Png *png_obj;
- char *png;
- int png_len;
- char *error;
-};
-
int
Png::EIO_PngEncode(eio_req *req)
{
encode_request *enc_req = (encode_request *)req->data;
- Png *png = enc_req->png_obj;
+ Png *png = (Png *)enc_req->png_obj;
try {
PngEncoder p((unsigned char *)png->data->data(), png->width, png->height, png->buf_type);
@@ -161,7 +153,7 @@ Png::EIO_PngEncodeAfter(eio_req *req)
free(enc_req->png);
free(enc_req->error);
- enc_req->png_obj->Unref();
+ ((Png *)enc_req->png_obj)->Unref();
free(enc_req);
return 0;
Please sign in to comment.
Something went wrong with that request. Please try again.