<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">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.<div><br></div><div>I've been thinking of creating something like a WorkerCanvas which is basically a DOM-less CanvasRenderingContext2D, so you can do</div><div><br></div><div>var canvas = new WorkerCanvas(width, height);</div><div>canvas.putImageData(myData);</div><div><br></div><div>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.</div><div><br></div><div>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?</div><div><br></div><div>--Oliver</div><div><br><div><div>On Dec 10, 2009, at 12:45 AM, Franz Buchinger wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite">Hi Sigbjorn,<br><br>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?<br><br>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...  <br>
This will be magnitudes sloooooooooower than scale() :(<br><br>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. <br>
<br>Franz<br><br><div class="gmail_quote">2009/12/7 Sigbjorn Finne <span dir="ltr"><<a href="mailto:sigbjorn.finne@gmail.com" target="_blank">sigbjorn.finne@gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div><div></div><div>On 12/5/2009 13:24, Franz Buchinger wrote:<br>
> Gears introduced the concept of an "offscreen canvas" that doesn't draw<br>
> anything in the browser window, but can be used to manipulate images in a<br>
> web worker.<br>
><br>
> I used this functionality to implement a "resize-before-upload" feature in<br>
> my photo gallery uploader. Now I'm trying to port my uploader to HTML5 but<br>
> there seems no way to delegate the scaling work to a HTML5 web worker.<br>
> Surely I could use the DOM canvas to scale down the photos in the main<br>
> "browser thread", but this means that the UI gets blocked during this<br>
> process.<br>
><br>
> If the user chooses more than a few multi-megapixel photos, the<br>
> CPU-intensive downscaling will likely freeze the browser and trigger a<br>
> script abortion warning.<br>
><br>
> Are there plans to introduce an "offscreen canvas" in html5? If not, which<br>
> workarounds are possible?<br>
><br>
</div></div>Hi Franz,<br>
<br>
ImageData is cloneable via postMessage(), so you could perform some<br>
forms of image processing that way.<br>
<br>
--sigbjorn <<a href="mailto:sof@opera.com" target="_blank">sof@opera.com</a>><br>
<br>
</blockquote></div><br>
</blockquote></div><br></div></body></html>