Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Account for pixel density when masking images #6788

Merged
merged 10 commits into from
May 3, 2024
17 changes: 9 additions & 8 deletions src/image/p5.Image.js
Original file line number Diff line number Diff line change
Expand Up @@ -878,21 +878,22 @@ p5.Image = class {
}
const currBlend = this.drawingContext.globalCompositeOperation;

let scaleFactor = 1;
let imgScaleFactor = this._pixelDensity;
let maskScaleFactor = 1;
if (p5Image instanceof p5.Renderer) {
scaleFactor = p5Image._pInst._pixelDensity;
maskScaleFactor = p5Image._pInst._pixelDensity;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p5.Image also has a pixel density too now, maybe we can add a branch to handle when the input is an image too?

this._pixelDensity = 1;

}

const copyArgs = [
p5Image,
0,
0,
scaleFactor * p5Image.width,
scaleFactor * p5Image.height,
maskScaleFactor * p5Image.width,
Papershine marked this conversation as resolved.
Show resolved Hide resolved
maskScaleFactor * p5Image.height,
0,
0,
this.width,
this.height
imgScaleFactor * this.width,
imgScaleFactor * this.height
];

this.drawingContext.globalCompositeOperation = 'destination-in';
Expand All @@ -907,8 +908,8 @@ p5.Image = class {
this.gifProperties.frames[i].image = this.drawingContext.getImageData(
0,
0,
this.width,
this.height
imgScaleFactor * this.width,
imgScaleFactor * this.height
);
}
this.drawingContext.putImageData(
Expand Down