-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Conversation
🎉 Thanks for opening this pull request! Please check out our contributing guidelines if you haven't already. And be sure to add yourself to the list of contributors on the readme page! |
Potential changes needed:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking this on! I think those two ideas you mentioned would be great, and a test will help make sure we don't accidentally break this again in the future. We have a new visual test system (https://github.com/processing/p5.js/blob/main/contributor_docs/unit_testing.md#visual-tests), maybe that could be a good fit for a test for this?
if (p5Image instanceof p5.Renderer) { | ||
scaleFactor = p5Image._pInst._pixelDensity; | ||
maskScaleFactor = p5Image._pInst._pixelDensity; |
There was a problem hiding this comment.
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?
Line 150 in 37d3324
this._pixelDensity = 1; |
I'm trying to set up and test masking when manually changing the pixel density, but things keep bugging out. Looking into the code for Lines 256 to 260 in 304ee90
If the original pixel density is 2, and we want to make it 4, it seems setting |
I think the idea is that when you import e.g. an 800x800 image from a file, we have no idea what the density is, so we assume 1x density. But if we tell p5 that actually it should be treated like a 400x400 image at 2x density, then it will change its width and height to accommodate. So in this code path, we don't want to change any of the underlying pixels, just reinterpret it. I'll be different if you create it from a So for tests, I think you'd either (1) make a graphic at the size and density you want and then turn it into an image with |
Hi team! Wondering if there's a plan to integrate this update into the newest release of p5. Would be grateful! Thank you!! |
@Papershine are you interested in continuing to finish up the tests? No worries if not, we can always continue development from what you've started! |
Hey @davepagurek, sorry about the delay! I've been extremely busy with school and still doing exams right now, it would be great if anybody interested could take over and finish this PR, thank you so much! If nobody is interested, I could work on the tests in a week when my exams are done. |
A test for pixel density 2, as well as a test for the case where pixel densities aren't the same, have been added. Do we also want to have a test with |
Thanks @Papershine, the tests so far look great! A |
Just added that! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the code and the tests!
@all-contributors please add @Papershine for code, test |
I've put up a pull request to add @Papershine! 🎉 |
Resolves #6770
Changes:
Previously, image pixel densities were hard coded to be 1, but when image pixel densities were changed to be variable, the mask function was not updated, resulting in incorrectly sized images being masked. By taking into account the pixel density when calculating the actual pixel width and height for masking, the issue should be fixed.
Screenshots of the change:
On a high pixel density display, the previous behaviour of the code snippet in #6770 has been restored:
PR Checklist
npm run lint
passes