Skip to content

Support pixel density on p5.Image #6114

@davepagurek

Description

@davepagurek

Increasing Access

Currently, if you call .get() on a p5.Graphics, it creates a p5.Image out of the contents of the graphics object. However, if you are using a high dpi display (e.g. most phones now), the resulting image will look blurry compared to the original p5.Graphics because images currently have a hardcoded pixel density of 1.

Calling .get() on a p5.Graphics is useful for performance in WebGL: if you want to use it as a texture and know the p5.Graphics won't change, it will be faster to turn it into an image so p5 knows it doesn't need to send its data to the GPU every frame. This can make WebGL sketches run much more smoothly. Unfortunately, it is currently not easy to use this performance enhancement and also not lose visual quality (it's possible but requires accessing the undocumented internals of p5.Image). Allowing it would help make for a better viewing experience on phones.

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build Process
  • Unit Testing
  • Internalization
  • Friendly Errors
  • Other (specify if possible)

Feature enhancement details

Implementing this change might be as small as letting us set the (currently hardcoded to 1) _pixelDensity property on a p5.Image:

this._pixelDensity = 1;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status

    DONE! 🎉

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions