Skip to content
This repository
Browse code

Revert "FixedPngStack now returns Buffer instead of binary string"

This reverts commit 71c83b2.
  • Loading branch information...
commit 8ae3b0a58495b4253f9306d1499d30c500d24d2a 1 parent e0cc940
Peteris Krumins authored

Showing 1 changed file with 18 additions and 12 deletions. Show diff stats Hide diff stats

  1. +18 12 src/fixed_png_stack.cpp
30 src/fixed_png_stack.cpp
@@ -56,12 +56,9 @@ FixedPngStack::PngEncodeSync()
56 56 buffer_type pbt = (buf_type == BUF_BGR || buf_type == BUF_BGRA) ? BUF_BGRA : BUF_RGBA;
57 57
58 58 try {
59   - PngEncoder encoder(data, width, height, pbt);
60   - encoder.encode();
61   - int png_len = encoder.get_png_len();
62   - Buffer *retbuf = Buffer::New(png_len);
63   - memcpy(retbuf->data(), encoder.get_png(), png_len);
64   - return scope.Close(retbuf->handle_);
  59 + PngEncoder p(data, width, height, pbt);
  60 + p.encode();
  61 + return scope.Close(Encode((char *)p.get_png(), p.get_png_len(), BINARY));
65 62 }
66 63 catch (const char *err) {
67 64 return VException(err);
@@ -178,11 +175,17 @@ FixedPngStack::EIO_PngEncode(eio_req *req)
178 175 FixedPngStack *png = (FixedPngStack *)enc_req->png_obj;
179 176
180 177 try {
181   - PngEncoder encoder(png->data, png->width, png->height, png->buf_type);
182   - encoder.encode();
183   - int png_len = encoder.get_png_len();
184   - enc_req->png_buf = Buffer::New(png_len);
185   - memcpy(enc_req->png_buf->data(), encoder.get_png(), png_len);
  178 + PngEncoder p(png->data, png->width, png->height, png->buf_type);
  179 + p.encode();
  180 + enc_req->png_len = p.get_png_len();
  181 + enc_req->png = (char *)malloc(sizeof(*enc_req->png)*enc_req->png_len);
  182 + if (!enc_req->png) {
  183 + enc_req->error = strdup("malloc in FixedPngStack::EIO_PngEncode failed.");
  184 + return 0;
  185 + }
  186 + else {
  187 + memcpy(enc_req->png, p.get_png(), enc_req->png_len);
  188 + }
186 189 }
187 190 catch (const char *err) {
188 191 enc_req->error = strdup(err);
@@ -206,7 +209,7 @@ FixedPngStack::EIO_PngEncodeAfter(eio_req *req)
206 209 argv[1] = ErrorException(enc_req->error);
207 210 }
208 211 else {
209   - argv[0] = enc_req->png_buf->handle_;
  212 + argv[0] = Local<Value>::New(Encode(enc_req->png, enc_req->png_len, BINARY));
210 213 argv[1] = Undefined();
211 214 }
212 215
@@ -218,6 +221,7 @@ FixedPngStack::EIO_PngEncodeAfter(eio_req *req)
218 221 FatalException(try_catch);
219 222
220 223 enc_req->callback.Dispose();
  224 + free(enc_req->png);
221 225 free(enc_req->error);
222 226
223 227 ((FixedPngStack *)enc_req->png_obj)->Unref();
@@ -246,6 +250,8 @@ FixedPngStack::PngEncodeAsync(const Arguments &args)
246 250
247 251 enc_req->callback = Persistent<Function>::New(callback);
248 252 enc_req->png_obj = png;
  253 + enc_req->png = NULL;
  254 + enc_req->png_len = 0;
249 255 enc_req->error = NULL;
250 256
251 257 eio_custom(EIO_PngEncode, EIO_PRI_DEFAULT, EIO_PngEncodeAfter, enc_req);

0 comments on commit 8ae3b0a

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