fix(image): fix pixelDensity idempotence and high-DPI canvas resize - #9167
Open
Pcmhacker-piro wants to merge 2 commits into
Open
fix(image): fix pixelDensity idempotence and high-DPI canvas resize#9167Pcmhacker-piro wants to merge 2 commits into
Pcmhacker-piro wants to merge 2 commits into
Conversation
…rocessing#9152) - Derive logical dimensions from physical canvas dimensions and pixel density in pixelDensity() so repeated calls are idempotent and resetting to 1 restores original size - Scale backing canvas by pixel density in resize() to preserve high-DPI resolution - Fix Color reference in Image.prototype.set() - Add unit tests for pixelDensity and high-DPI resize
|
🎉 Thanks for opening this pull request! For guidance on contributing, check out our contributor guidelines and other resources for contributors! Thank You! |
19 tasks
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #9152
Changes:
src/image/p5.Image.js, fixedpixelDensity(density)to derive logical dimensions from physical canvas dimensions (this.width = this.canvas.width / density,this.height = this.canvas.height / density). This makes repeated calls idempotent (no compounding dimension shrinkage) and allows resettingpixelDensity(1)to accurately restore original dimensions.src/image/p5.Image.js, fixedresize(width, height)to scale the backing canvas and temporary canvas bythis._pixelDensity(width * pd,height * pd). This prevents high-DPI images from having their canvas backing store downscaled to logical size, which caused subsequentget()calls to return[0, 0, 0, 0]as out-of-bounds andset()to fail writes.Colorreference inImage.prototype.set().test/unit/image/p5.Image.jscovering:pixelDensity()getter and setter behaviorpixelDensity()idempotence and restoring dimensionspixelDensity > 1inresize()get()andset()after resizing a high-DPI imagePR Checklist
npm run lintpassesAI Usage Disclosure
AI tools were used assistively to help write unit test cases and verify edge cases. The changes have been tested and reviewed locally.