fix PImage.get() issue with width or height < 0

This commit is contained in:
benfry
2012-03-23 15:30:09 +00:00
parent 46a470eaf2
commit ea8edb4803

View File

@@ -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);
}