[whatwg] proposed canvas 2d API additions

On 4/26/06, Ian Hickson <ian at hixie.ch> wrote:
> 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;
>    }

I have a nagging feeling that this is a bad idea, but I can't explain
why, because I do like the idea.  If we do this, let's advance it a
bit:

interface ImageData {
  readonly attribute string format; /* only "rgba" is valid for now */
  readonly attribute long int width;
  readonly attribute long int height;
  readonly attribute Array data;
}

format would specify the type of data that is in data; only "rgba"
would be valid for now, but we this gives us a way to extend that
later on.

and also add:

ImageData createImageData(in string format, in string width, in string
height, in Array data);

for creating "ImageData" out of an arbitrary set of generated data
(e.g. evaluating some function, drawing the results).  This would be
especially needed because you can't assign to data in an ImageData
structure (since you have it readonly); can only change the values of
its members.

>    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);

I would keep x/y/w/h as integers, and explicitly specify that they're
not affected by the CTM.  If they are, you can't guarantee a lossless
round-trip (since if you shift over by half a pixel you have to do
lots of resampling, etc.).

   - Vlad

Received on Friday, 28 April 2006 13:34:03 UTC