Skip to content

Commit 2db2662

Browse files
authored
Merge pull request #917 from zbjornson/nbytes-regression
Fix 2.0 regression, warnings, v8 memory dealloc hint
2 parents 6b72722 + 198a61d commit 2db2662

File tree

6 files changed

+25
-25
lines changed

6 files changed

+25
-25
lines changed

src/Canvas.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ class Canvas: public Nan::ObjectWrap {
8585

8686
inline uint8_t *data(){ return cairo_image_surface_get_data(surface()); }
8787
inline int stride(){ return cairo_image_surface_get_stride(surface()); }
88-
inline int nBytes(){ return backend()->getWidth() * stride(); }
88+
inline int nBytes(){ return getHeight() * stride(); }
8989

9090
inline int getWidth() { return backend()->getWidth(); }
9191
inline int getHeight() { return backend()->getHeight(); }

src/CanvasRenderingContext2d.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -745,8 +745,8 @@ NAN_METHOD(Context2d::GetImageData) {
745745
Local<Int32> shHandle = Nan::New(sh);
746746
Local<Value> argv[argc] = { clampedArray, swHandle, shHandle };
747747

748-
Local<Function> constructor = Nan::GetFunction(Nan::New(ImageData::constructor)).ToLocalChecked();
749-
Local<Object> instance = Nan::NewInstance(constructor, argc, argv).ToLocalChecked();
748+
Local<Function> ctor = Nan::GetFunction(Nan::New(ImageData::constructor)).ToLocalChecked();
749+
Local<Object> instance = Nan::NewInstance(ctor, argc, argv).ToLocalChecked();
750750

751751
info.GetReturnValue().Set(instance);
752752
}

src/Image.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ Image::decodeJPEGBufferIntoMimeSurface(uint8_t *buf, unsigned len) {
810810

811811
void
812812
clearMimeData(void *closure) {
813-
Nan::AdjustExternalMemory(-((read_closure_t *)closure)->len);
813+
Nan::AdjustExternalMemory(-static_cast<int>(((read_closure_t *)closure)->len));
814814
free(((read_closure_t *) closure)->buf);
815815
free(closure);
816816
}

src/backend/Backend.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ Backend::~Backend()
1616
}
1717

1818

19-
void Backend::setCanvas(Canvas* canvas)
19+
void Backend::setCanvas(Canvas* _canvas)
2020
{
21-
this->canvas = canvas;
21+
this->canvas = _canvas;
2222
}
2323

2424

@@ -53,19 +53,19 @@ int Backend::getWidth()
5353
{
5454
return this->width;
5555
}
56-
void Backend::setWidth(int width)
56+
void Backend::setWidth(int width_)
5757
{
58-
this->width = width;
58+
this->width = width_;
5959
this->recreateSurface();
6060
}
6161

6262
int Backend::getHeight()
6363
{
6464
return this->height;
6565
}
66-
void Backend::setHeight(int height)
66+
void Backend::setHeight(int height_)
6767
{
68-
this->height = height;
68+
this->height = height_;
6969
this->recreateSurface();
7070
}
7171

src/toBuffer.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*/
1010

1111
cairo_status_t
12-
toBuffer(void *c, const uint8_t *data, unsigned len) {
12+
toBuffer(void *c, const uint8_t *odata, unsigned len) {
1313
closure_t *closure = (closure_t *) c;
1414

1515
if (closure->len + len > closure->max_len) {
@@ -26,7 +26,7 @@ toBuffer(void *c, const uint8_t *data, unsigned len) {
2626
closure->max_len = max;
2727
}
2828

29-
memcpy(closure->data + closure->len, data, len);
29+
memcpy(closure->data + closure->len, odata, len);
3030
closure->len += len;
3131

3232
return CAIRO_STATUS_SUCCESS;

test/canvas.test.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('Canvas', function () {
1919
});
2020

2121
it('.version', function () {
22-
assert.ok(/^\d+\.\d+\.\d+$/.test(Canvas.version));
22+
assert.ok(/^\d+\.\d+\.\d+(-(alpha|beta)\.\d+)?$/.test(Canvas.version));
2323
});
2424

2525
it('.cairoVersion', function () {
@@ -386,10 +386,10 @@ describe('Canvas', function () {
386386
});
387387

388388
describe('#toBuffer("raw")', function() {
389-
var canvas = new Canvas(10, 10)
389+
var canvas = new Canvas(11, 10)
390390
, ctx = canvas.getContext('2d');
391391

392-
ctx.clearRect(0, 0, 10, 10);
392+
ctx.clearRect(0, 0, 11, 10);
393393

394394
ctx.fillStyle = 'rgba(200, 200, 200, 0.505)';
395395
ctx.fillRect(0, 0, 5, 5);
@@ -404,16 +404,16 @@ describe('Canvas', function () {
404404
ctx.fillRect(5, 5, 4, 5);
405405

406406
/** Output:
407-
* *****RRRRR
408-
* *****RRRRR
409-
* *****RRRRR
410-
* *****RRRRR
411-
* *****RRRRR
412-
* GGGGGBBBB-
413-
* GGGGGBBBB-
414-
* GGGGGBBBB-
415-
* GGGGGBBBB-
416-
* GGGGGBBBB-
407+
* *****RRRRR-
408+
* *****RRRRR-
409+
* *****RRRRR-
410+
* *****RRRRR-
411+
* *****RRRRR-
412+
* GGGGGBBBB--
413+
* GGGGGBBBB--
414+
* GGGGGBBBB--
415+
* GGGGGBBBB--
416+
* GGGGGBBBB--
417417
*/
418418

419419
var buf = canvas.toBuffer('raw');

0 commit comments

Comments
 (0)