Permalink
Browse files

Revert "DynamicPngStack now returns Buffer instead of binary string"

This reverts commit 339c531.
  • Loading branch information...
1 parent 339c531 commit e0cc940d3807b5519d36def5e10edc12b9f7c2b9 @pkrumins committed Aug 18, 2010
Showing with 20 additions and 14 deletions.
  1. +2 −2 src/common.h
  2. +18 −12 src/dynamic_png_stack.cpp
View
4 src/common.h
@@ -2,7 +2,6 @@
#define COMMON_H
#include <node.h>
-#include <node_buffer.h>
#include <cstring>
v8::Handle<v8::Value> ErrorException(const char *msg);
@@ -28,7 +27,8 @@ typedef enum { BUF_RGB, BUF_BGR, BUF_RGBA, BUF_BGRA } buffer_type;
struct encode_request {
v8::Persistent<v8::Function> callback;
void *png_obj;
- node::Buffer *png_buf;
+ char *png;
+ int png_len;
char *error;
};
View
30 src/dynamic_png_stack.cpp
@@ -106,13 +106,10 @@ DynamicPngStack::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();
+ PngEncoder p(data, width, height, pbt);
+ p.encode();
free(data);
- 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_);
+ return scope.Close(Encode((char *)p.get_png(), p.get_png_len(), BINARY));
}
catch (const char *err) {
return VException(err);
@@ -248,12 +245,18 @@ DynamicPngStack::EIO_PngEncode(eio_req *req)
BUF_BGRA : BUF_RGBA;
try {
- PngEncoder encoder(data, png->width, png->height, pbt);
- encoder.encode();
+ PngEncoder p(data, png->width, png->height, pbt);
+ p.encode();
free(data);
- 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);
+ 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 DynamicPngStack::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);
@@ -279,7 +282,7 @@ DynamicPngStack::EIO_PngEncodeAfter(eio_req *req)
argv[2] = 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] = png->Dimensions();
argv[2] = Undefined();
}
@@ -292,6 +295,7 @@ DynamicPngStack::EIO_PngEncodeAfter(eio_req *req)
FatalException(try_catch);
enc_req->callback.Dispose();
+ free(enc_req->png);
free(enc_req->error);
png->Unref();
@@ -320,6 +324,8 @@ DynamicPngStack::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 e0cc940

Please sign in to comment.