From a201a714427e1ab186fb2e79f3dad0b92c66c2fb Mon Sep 17 00:00:00 2001 From: Ngoc Doan Date: Sat, 17 May 2025 04:01:48 -0700 Subject: [PATCH] Add error check for pixelDesity in mask() --- core/src/processing/core/PImage.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/core/src/processing/core/PImage.java b/core/src/processing/core/PImage.java index 666061ee9..e464058c2 100644 --- a/core/src/processing/core/PImage.java +++ b/core/src/processing/core/PImage.java @@ -840,6 +840,15 @@ public void mask(int[] maskArray) { // ignore */ public void mask(PImage img) { img.loadPixels(); + this.loadPixels(); + if (this.pixelWidth != img.pixelWidth || this.pixelHeight != img.pixelHeight) { + if (this.pixelDensity != img.pixelDensity) { + throw new IllegalArgumentException("mask() requires the mask image to have the same pixel size after adjusting for pixelDensity."); + } + else if (this.width != img.width || this.height != img.height) { + throw new IllegalArgumentException("mask() requires the mask image to have the same width and height."); + } + } mask(img.pixels); }