Skip to content

Commit a201a71

Browse files
committed
Add error check for pixelDesity in mask()
1 parent d7717e2 commit a201a71

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

core/src/processing/core/PImage.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,15 @@ public void mask(int[] maskArray) { // ignore
840840
*/
841841
public void mask(PImage img) {
842842
img.loadPixels();
843+
this.loadPixels();
844+
if (this.pixelWidth != img.pixelWidth || this.pixelHeight != img.pixelHeight) {
845+
if (this.pixelDensity != img.pixelDensity) {
846+
throw new IllegalArgumentException("mask() requires the mask image to have the same pixel size after adjusting for pixelDensity.");
847+
}
848+
else if (this.width != img.width || this.height != img.height) {
849+
throw new IllegalArgumentException("mask() requires the mask image to have the same width and height.");
850+
}
851+
}
843852
mask(img.pixels);
844853
}
845854

0 commit comments

Comments
 (0)