[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Public WebGL] How to set a canvas backing store to display units?

On 6/18/12 11:42 PM, Gregg Tavares (社用) wrote:
My understanding is getImageData is supposed to give you CSS pixels

http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#dom-context-2d-getimagedata says:

  ImageData objects must be initialized so that their width attribute
  is set to w, the number of physical device pixels per row in the
  image data, their height attribute is set to h, the number of rows
  in the image data

and then much later:

  Note: This implies that the data returned by getImageData() is at
  the resolution of the canvas backing store. This is likely to not
  be one device pixel to each CSS pixel if the display used is a
  high resolution display.

I believe the claim was that Apple's implementation does in fact have
this behavior.

Or in other words, per canvas spec if I have a <canvas width="100"
height="100"> and I call getImageData(1, 3, 5, 7) on it and the backing
store is using 2 device pixels per CSS pixel, then I will get an
ImageData object whose .data Uint8ClampedArray of length 5*7*4 = 140
which represents the 10x14 piece of backing store whose top-left corner
is at coordinates (2, 6) in the backing store pixel space (which are
(1,3) in the CSS-pixel-based canvas coordinate space).  The objects
.width and .height will be 10 and 14 respectively.

Now the canvas spec doesn't define what size backing store the UA is to
use, of course; in practice Gecko always sizes the backing store so that
one backing store pixel is one CSS pixel, precisely to avoid issues with
scripts using imageData.....


You are currently subscribed to public_webgl@khronos.org.
To unsubscribe, send an email to majordomo@khronos.org with
the following command in the body of your email:
unsubscribe public_webgl