Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Revert "FixedPngStack now returns Buffer instead of binary string"

This reverts commit 71c83b2.
  • Loading branch information...
commit 8ae3b0a58495b4253f9306d1499d30c500d24d2a 1 parent e0cc940
@pkrumins authored
Showing with 18 additions and 12 deletions.
  1. +18 −12 src/fixed_png_stack.cpp
View
30 src/fixed_png_stack.cpp
@@ -56,12 +56,9 @@ FixedPngStack::PngEncodeSync()
buffer_type pbt = (buf_type == BUF_BGR || buf_type == BUF_BGRA) ? BUF_BGRA : BUF_RGBA;
try {
- PngEncoder encoder(data, width, height, pbt);
- encoder.encode();
- int png_len = encoder.get_png_len();
- Buffer *retbuf = Buffer::New(png_len);
- memcpy(retbuf->data(), encoder.get_png(), png_len);
- return scope.Close(retbuf->handle_);
+ PngEncoder p(data, width, height, pbt);
+ p.encode();
+ return scope.Close(Encode((char *)p.get_png(), p.get_png_len(), BINARY));
}
catch (const char *err) {
return VException(err);
@@ -178,11 +175,17 @@ FixedPngStack::EIO_PngEncode(eio_req *req)
FixedPngStack *png = (FixedPngStack *)enc_req->png_obj;
try {
- PngEncoder encoder(png->data, png->width, png->height, png->buf_type);
- encoder.encode();
- int png_len = encoder.get_png_len();
- enc_req->png_buf = Buffer::New(png_len);
- memcpy(enc_req->png_buf->data(), encoder.get_png(), png_len);
+ PngEncoder p(png->data, png->width, png->height, png->buf_type);
+ p.encode();
+ enc_req->png_len = p.get_png_len();
+ enc_req->png = (char *)malloc(sizeof(*enc_req->png)*enc_req->png_len);
+ if (!enc_req->png) {
+ enc_req->error = strdup("malloc in FixedPngStack::EIO_PngEncode failed.");
+ return 0;
+ }
+ else {
+ memcpy(enc_req->png, p.get_png(), enc_req->png_len);
+ }
}
catch (const char *err) {
enc_req->error = strdup(err);
@@ -206,7 +209,7 @@ FixedPngStack::EIO_PngEncodeAfter(eio_req *req)
argv[1] = ErrorException(enc_req->error);
}
else {
- argv[0] = enc_req->png_buf->handle_;
+ argv[0] = Local<Value>::New(Encode(enc_req->png, enc_req->png_len, BINARY));
argv[1] = Undefined();
}
@@ -218,6 +221,7 @@ FixedPngStack::EIO_PngEncodeAfter(eio_req *req)
FatalException(try_catch);
enc_req->callback.Dispose();
+ free(enc_req->png);
free(enc_req->error);
((FixedPngStack *)enc_req->png_obj)->Unref();
@@ -246,6 +250,8 @@ FixedPngStack::PngEncodeAsync(const Arguments &args)
enc_req->callback = Persistent<Function>::New(callback);
enc_req->png_obj = png;
+ enc_req->png = NULL;
+ enc_req->png_len = 0;
enc_req->error = NULL;
eio_custom(EIO_PngEncode, EIO_PRI_DEFAULT, EIO_PngEncodeAfter, enc_req);
Please sign in to comment.
Something went wrong with that request. Please try again.