Skip to content
Browse files

Revert "Png now returns Buffer instead of binary string"

This reverts commit 82942bf.
  • Loading branch information...
1 parent 8ae3b0a commit a2bfa5fe001db5dd68f98b1015e4b5d924debcf8 @pkrumins committed Aug 18, 2010
Showing with 18 additions and 12 deletions.
  1. +18 −12 src/png.cpp
View
30 src/png.cpp
@@ -28,12 +28,9 @@ Png::PngEncodeSync()
HandleScope scope;
try {
- PngEncoder encoder((unsigned char *)data->data(), width, height, buf_type);
- 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((unsigned char *)data->data(), width, height, buf_type);
+ p.encode();
+ return scope.Close(Encode((char *)p.get_png(), p.get_png_len(), BINARY));
}
catch (const char *err) {
return VException(err);
@@ -107,11 +104,17 @@ Png::EIO_PngEncode(eio_req *req)
Png *png = (Png *)enc_req->png_obj;
try {
- PngEncoder encoder((unsigned char *)png->data->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((unsigned char *)png->data->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 Png::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);
@@ -135,7 +138,7 @@ Png::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();
}
@@ -147,6 +150,7 @@ Png::EIO_PngEncodeAfter(eio_req *req)
FatalException(try_catch);
enc_req->callback.Dispose();
+ free(enc_req->png);
free(enc_req->error);
((Png *)enc_req->png_obj)->Unref();
@@ -175,6 +179,8 @@ Png::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);

0 comments on commit a2bfa5f

Please sign in to comment.
Something went wrong with that request. Please try again.