Re: [whatwg] Proposal: ImageData constructor or factory method with preexisting data

On Mon, Mar 11, 2013 at 8:00 PM, Rik Cabanier <cabanier@gmail.com> wrote:

> Do you expect that createImageData creates an internal copy of the
> Uint8ClampedArray object
> or is it live?
>

That only matters if the referenced data is writable, in which case there
probably should be an internal copy.  That is not necessarily the
motivation behind this proposal (Ken?)

The use cases I see for this new interface is for relaying image data, that
is *not* generated in JS.  For example, suppose a chunk of image data is
 generated on the server side and sent to the client via WebSocket. On the
client side, you just want to copy the data field of the message event onto
a 2D canvas. With the current API, an intermediate copy is required in
order to wrap the incoming data into an ImageData object.

 -Justin


>
> On Mon, Mar 11, 2013 at 4:28 PM, Kenneth Russell <kbr@google.com> wrote:
>
> > It would be useful to be able to create an ImageData [1] object with
> > preexisting data. The main use case is to display arbitrary data in
> > the 2D canvas context with no data copies.
> >
> > Proposed IDL:
> >
> > [NoInterfaceObject]
> > interface ImageDataFactories {
> >   ImageData createImageData(Uint8ClampedArray data, double sw, double
> sh);
> > };
> > Window implements ImageDataFactories;
> > WorkerGlobalScope implements ImageDataFactories;
> >
> > createImageData would throw an exception if the length of the
> > Uint8ClampedArray was not equal to 4 * floor(sw) * floor(sh), or at
> > least, if the length of the array was less than this value. (Similar
> > wording would be used to that of CanvasRenderingContext2D's
> > createImageData.)
> >
> > I don't think it is necessary to provide a createImageDataHD in this
> > interface. The caller will know the devicePixelRatio and determine
> > whether to generate high-DPI data.
> >
> > [1]
> >
> http://www.whatwg.org/specs/web-apps/current-work/multipage/the-canvas-element.html#imagedata
> >
> > Comments?
> >
> > Thanks,
> >
> > -Ken
> >
>

Received on Tuesday, 12 March 2013 02:49:14 UTC