diff --git a/src/CanvasRenderingContext2d.cc b/src/CanvasRenderingContext2d.cc index c7fc99abb..3978cffc7 100644 --- a/src/CanvasRenderingContext2d.cc +++ b/src/CanvasRenderingContext2d.cc @@ -1011,14 +1011,18 @@ Context2d::GetImageData(const Napi::CallbackInfo& info) { sh = -sh; } + // Width and height to actually copy int cw = sw; int ch = sh; + // Offsets in the destination image int ox = 0; int oy = 0; + // Clamp the copy width and height if the copy would go outside the image if (sx + sw > width) cw = width - sx; if (sy + sh > height) ch = height - sy; + // Clamp the copy origin if the copy would go outside the image if (sx < 0) { ox = -sx; cw += sx; @@ -1030,10 +1034,6 @@ Context2d::GetImageData(const Napi::CallbackInfo& info) { sy = 0; } - // WebKit/moz functionality. node-canvas used to return in either case. - if (sw <= 0) sw = 1; - if (sh <= 0) sh = 1; - int srcStride = canvas->stride(); int bpp = srcStride / width; int size = sw * sh * bpp;