mirror of
https://github.com/processing/processing4.git
synced 2026-02-11 17:40:48 +01:00
fix PImage.get() issue with width or height < 0
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user