W3C home > Mailing lists > Public > whatwg@whatwg.org > April 2006

[whatwg] proposed canvas 2d API additions

From: Ian Hickson <ian@hixie.ch>
Date: Wed, 26 Apr 2006 19:37:08 +0000 (UTC)
Message-ID: <Pine.LNX.4.62.0604261907090.21459@dhalsim.dreamhost.com>
On Mon, 24 Apr 2006, Vladimir Vukicevic wrote:
> 
> The use case that I'm thinking of is essentially:
> 
> pixels = c.getPixels(x, y, width, height);
> /* manipulate pixels here */
> c.putPixels(pixels, x, y, width, height);
> 
> That is, direct pixel manipulation, for performing some operation that
> can't be done using the context API.

Ok. That is helpful, because there have been several use cases thrown 
about and it wasn't clear to me which use case we actually cared about.

It seems to me that a critical requirement of the use case you describe is 
that the result of the following script:

   pixels = c.getPixels(x, y, width, height);
   /* do nothing here */
   c.putPixels(pixels, x, y, width, height);

...be a (possibly expensive) no-op. That is, you should not lose image 
data -- the above should not corrupt your picture. This means the pixel 
data returned must be native resolution data.

How about:

   interface ImageData {
     readonly attribute long int width;
     readonly attribute long int height;
     readonly attribute Array data;
   }

   ImageData getImageData(in float x, in float y, in float w, in float h);
   void drawImageData(in float x, in float y, in ImageData d);

...where getImageData() returns an object implementing the ImageData 
interface which contains the actual pixel data for the backing store of 
the canvas, with the width and height attributes giving the number of 
actual data pixels returned? The array would contain, as in your proposal, 
4*width*height values, giving the R, G, B, and A components of each pixel 
in the image, row by row.

In the ECMAScript binding we could make the ImageData object have the 
"data" field as its default so it could be dereferenced directly as if the 
ImageData object itself were the array.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'
Received on Wednesday, 26 April 2006 12:37:08 UTC

This archive was generated by hypermail 2.4.0 : Wednesday, 22 January 2020 16:58:46 UTC