fix(image): fix pixelDensity idempotence and high-DPI canvas resize - #9167
fix(image): fix pixelDensity idempotence and high-DPI canvas resize#9167Pcmhacker-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! |
| a = imgOrCol[3]; | ||
| //this.updatePixels.call(this); | ||
| } | ||
| } else if (imgOrCol instanceof p5.Color) { |
There was a problem hiding this comment.
@limzykenneth I wanted to get your thoughts on this: if we want to have the ability to load all modules as separate files in the future then we may want to use p5. prefixes more to avoid imports, but if we're thinking of implementing different combinations of modules as separate single-file builds then switching to imports like this makes sense. It's a little confusing if we have both, e.g. for WebGPU where that feels like it should be a separate file, because it means using a different convention in one spot than another, but maybe that's ok?
Continuous ReleaseCDN linkPublished PackagesCommit hash: 0fb2274 Previous deploymentsThis is an automated message. |
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.