W3C home > Mailing lists > Public > whatwg@whatwg.org > August 2013

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

From: Kenneth Russell <kbr@google.com>
Date: Tue, 13 Aug 2013 14:25:45 -0700
Message-ID: <CAMYvS2dPknmZgKokZCvL-rwWt30jP_UBLdiMrFcWJ6jRJd8ONA@mail.gmail.com>
To: Ian Hickson <ian@hixie.ch>
Cc: WHAT Working Group <whatwg@whatwg.org>, Rik Cabanier <cabanier@gmail.com>
On Tue, Aug 13, 2013 at 11:57 AM, Ian Hickson <ian@hixie.ch> wrote:
> On Mon, 12 Aug 2013, Kenneth Russell wrote:
>>
>> The use case is the passing of ImageData objects back and forth to
>> workers to fill and refill with data.
>>
>> An ImageData is essentially a wrapper for the underlying
>> Uint8ClampedArray, providing an associated width and height. However,
>> the only way to draw raw pixels into a Canvas is using an ImageData.
>>
>> Currently a Unit8ClampedArray can be constructed, but the only way to
>> create an ImageData is to ask a Canvas for one, and there's no way to
>> associate it with a pre-allocated Uint8ClampedArray.
>
> Why can't you just send an ImageData over?
>
>
>> This means that if you want to pass an ImageData to a worker for
>> filling, transferring the underlying Uint8ClampedArray, you need to be
>> very careful about bookkeeping, and to not lose the reference to the
>> ImageData object.
>
> Sure. Just send the ImageData over. That seems relatively
> straight-forward. What am I missing?
>
>
>> IMO there ought to be a factory method for ImageData taking a
>> Uint8ClampedArray, width, height, and possibly resolution (or a
>> dictionary?), which validates the width, height and resolution against
>> the size of the Uint8ClampedArray, and makes a new ImageData object.
>> This would ease management of ImageData instances.
>
> We could have a constructor for ImageData objects, sure. That would be
> relatively easy to add, if it's really needed. I don't understand why it's
> hard to keep track of ImageData objects, though. Can you elaborate?

I have in mind new APIs for typed arrays which allow sharding of typed
arrays to workers and re-assembly of the component pieces when the
work is complete. This would involve multiple manipulations of the
ArrayBuffer and its views. It would be most convenient if the result
could be wrapped in an ImageData if it's destined to be drawn to a
Canvas. Otherwise it's likely that a data copy will need to be
incurred.

-Ken
Received on Tuesday, 13 August 2013 21:26:09 UTC

This archive was generated by hypermail 2.3.1 : Monday, 13 April 2015 23:09:23 UTC