From 6dd46242bb42f3bcbcebdfb43857bc3de0987706 Mon Sep 17 00:00:00 2001 From: Philippe Plantier Date: Sun, 8 Jan 2023 10:41:21 +0100 Subject: [PATCH] remove dead code, add comments --- src/CanvasRenderingContext2d.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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;