[whatwg] "offscreen canvas" /Access to canvas functionality from a worker
Oliver Hunt
oliver at apple.com
Thu Dec 10 13:36:45 PST 2009
Ideally if we were to have a graphics context in a worker we'd want it to be the standard CanvasRenderingContext2D, the only real problem is that CanvasRenderingContext2D references the parent canvas element which clearly won't fly in a worker.
I've been thinking of creating something like a WorkerCanvas which is basically a DOM-less CanvasRenderingContext2D, so you can do
var canvas = new WorkerCanvas(width, height);
canvas.putImageData(myData);
I have a vague desire to allow a ImageData to be provided as a backing store, but then you may hit perf or consistency issues on UAs that use premultiplied alpha backing stores.
Additionally there's the question of origin tainting -- is it possible to taint the origin in a worker? you don;t have image elements, you can't xhr unsafely to other origins, but maybe i'm missing something?
--Oliver
On Dec 10, 2009, at 12:45 AM, Franz Buchinger wrote:
> Hi Sigbjorn,
>
> Does this mean that I have to implement my own image scaling method in Javascript when using web workers, instead of using the scale() method of CanvasRenderingContext2D?
>
> If so, I'd have to manually iterate over all pixels of the image, perform some nearest-neighbour calculation and create a new ImageData Object with the result...
> This will be magnitudes sloooooooooower than scale() :(
>
> I'd really appreciate if the "scale-images-before-upload" use case would be considered better in the HTML5 spec. After all, images are the most frequently uploaded file type and it has always been a hassle for users to scale down their multi-megapixel photos manually before uploading them. Now that we have the chance to solve this issue with pure-browser techniques, we stop half-way.
>
> Franz
>
> 2009/12/7 Sigbjorn Finne <sigbjorn.finne at gmail.com>
> On 12/5/2009 13:24, Franz Buchinger wrote:
> > Gears introduced the concept of an "offscreen canvas" that doesn't draw
> > anything in the browser window, but can be used to manipulate images in a
> > web worker.
> >
> > I used this functionality to implement a "resize-before-upload" feature in
> > my photo gallery uploader. Now I'm trying to port my uploader to HTML5 but
> > there seems no way to delegate the scaling work to a HTML5 web worker.
> > Surely I could use the DOM canvas to scale down the photos in the main
> > "browser thread", but this means that the UI gets blocked during this
> > process.
> >
> > If the user chooses more than a few multi-megapixel photos, the
> > CPU-intensive downscaling will likely freeze the browser and trigger a
> > script abortion warning.
> >
> > Are there plans to introduce an "offscreen canvas" in html5? If not, which
> > workarounds are possible?
> >
> Hi Franz,
>
> ImageData is cloneable via postMessage(), so you could perform some
> forms of image processing that way.
>
> --sigbjorn <sof at opera.com>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/attachments/20091210/f3a161e6/attachment.htm>
More information about the whatwg
mailing list