Skip to content

Commit 2de754a

Browse files
authored
Merge pull request #1107 from pnngocdoan/fix-mask
Add error check for pixelDensity in mask()
2 parents 6b906c2 + bf58dc1 commit 2de754a

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

core/src/processing/core/PImage.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,14 @@ public void mask(int[] maskArray) { // ignore
866866
*/
867867
public void mask(PImage img) {
868868
img.loadPixels();
869+
if (this.pixelWidth != img.pixelWidth || this.pixelHeight != img.pixelHeight) {
870+
if (this.pixelDensity != img.pixelDensity) {
871+
throw new IllegalArgumentException("mask() requires the mask image to have the same pixel size after adjusting for pixelDensity.");
872+
}
873+
else if (this.width != img.width || this.height != img.height) {
874+
throw new IllegalArgumentException("mask() requires the mask image to have the same width and height.");
875+
}
876+
}
869877
mask(img.pixels);
870878
}
871879

0 commit comments

Comments
 (0)