From ea8edb4803ccd795ba0300017fcfdc62ab4d425f Mon Sep 17 00:00:00 2001 From: benfry Date: Fri, 23 Mar 2012 15:30:09 +0000 Subject: [PATCH] fix PImage.get() issue with width or height < 0 --- core/src/processing/core/PImage.java | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/core/src/processing/core/PImage.java b/core/src/processing/core/PImage.java index fd3e0899b..52a3112fc 100644 --- a/core/src/processing/core/PImage.java +++ b/core/src/processing/core/PImage.java @@ -699,18 +699,6 @@ public class PImage implements PConstants, Cloneable { * @param h height of pixel rectangle to get */ public PImage get(int x, int y, int w, int h) { - /* - if (imageMode == CORNERS) { // if CORNER, do nothing - //x2 += x1; y2 += y1; - // w/h are x2/y2 in this case, bring em down to size - w = (w - x); - h = (h - y); - } else if (imageMode == CENTER) { - x -= w/2; - y -= h/2; - } - */ - if (x < 0) { w += x; // clip off the left edge x = 0; @@ -719,10 +707,17 @@ public class PImage implements PConstants, Cloneable { h += y; // clip off some of the height y = 0; } - + if (x + w > width) w = width - x; if (y + h > height) h = height - y; + if (w < 0) { + w = 0; + } + if (h < 0) { + h = 0; + } + return getImpl(x, y, w, h); }