Skip to content

Commit f841abb

Browse files
committed
test higher pixel densities in mask
1 parent 2e2abf5 commit f841abb

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

test/unit/image/p5.Image.js

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,40 @@ suite('p5.Image', function() {
5151
});
5252

5353
suite('p5.Image.prototype.mask', function() {
54-
test('it should mask the image', function() {
55-
let img = myp5.createImage(10, 10);
56-
img.loadPixels();
57-
for (let i = 0; i < img.height; i++) {
58-
for (let j = 0; j < img.width; j++) {
59-
let alpha = i < 5 ? 255 : 0;
60-
img.set(i, j, myp5.color(0, 0, 0, alpha));
54+
for (const density of [1, 2]) {
55+
test(`it should mask the image at pixel density ${density}`, function() {
56+
let img = myp5.createImage(10, 10);
57+
img.pixelDensity(density);
58+
img.loadPixels();
59+
for (let i = 0; i < img.height; i++) {
60+
for (let j = 0; j < img.width; j++) {
61+
let alpha = i < 5 ? 255 : 0;
62+
img.set(i, j, myp5.color(0, 0, 0, alpha));
63+
}
6164
}
62-
}
63-
img.updatePixels();
65+
img.updatePixels();
6466

65-
let mask = myp5.createImage(10, 10);
66-
mask.loadPixels();
67-
for (let i = 0; i < mask.width; i++) {
68-
for (let j = 0; j < mask.height; j++) {
69-
let alpha = j < 5 ? 255 : 0;
70-
mask.set(i, j, myp5.color(0, 0, 0, alpha));
67+
let mask = myp5.createImage(10, 10);
68+
mask.pixelDensity(density);
69+
mask.loadPixels();
70+
for (let i = 0; i < mask.width; i++) {
71+
for (let j = 0; j < mask.height; j++) {
72+
let alpha = j < 5 ? 255 : 0;
73+
mask.set(i, j, myp5.color(0, 0, 0, alpha));
74+
}
7175
}
72-
}
73-
mask.updatePixels();
76+
mask.updatePixels();
7477

75-
img.mask(mask);
76-
img.loadPixels();
77-
for (let i = 0; i < img.width; i++) {
78-
for (let j = 0; j < img.height; j++) {
79-
let alpha = i < 5 && j < 5 ? 255 : 0;
80-
assert.strictEqual(img.get(i, j)[3], alpha);
78+
img.mask(mask);
79+
img.loadPixels();
80+
for (let i = 0; i < img.width; i++) {
81+
for (let j = 0; j < img.height; j++) {
82+
let alpha = i < 5 && j < 5 ? 255 : 0;
83+
assert.strictEqual(img.get(i, j)[3], alpha);
84+
}
8185
}
82-
}
83-
});
86+
});
87+
}
8488

8589
test('it should mask the animated gif image', function() {
8690
const imagePath = 'unit/assets/nyan_cat.gif';

0 commit comments

Comments
 (0)