[whatwg] proposed canvas 2d API additions

Ian Hickson ian at hixie.ch
Wed Apr 26 12:37:08 PDT 2006


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.   `._.-(,_..'--(,_..'`-.;.'



More information about the whatwg mailing list