- From: Oliver Hunt <oliver@apple.com>
- Date: Wed, 23 Jan 2008 11:28:46 -0800
On 23/01/2008, at 5:44 AM, Philip Taylor wrote: > On 23/01/2008, Oliver Hunt <oliver at apple.com> wrote: >> It would be great if putImageData >> could take a source region, in addition to the destination. One of >> the primary reasons for using get/putImageData is to allow JS to >> rapidly blit data to the screen, however without an ability to blit >> only a subregion of the image data the only available options are to >> either re-blit the entire imagedata region (which can be expensive >> due >> to the need for [un]premultiplying in some (all?) implementations), > > ((Opera does non-premultiplied colour internally.)) Righto. There's still the necessary type/range checking involved at some point. > >> or create and populate a new ImageData object which still requires >> more >> work than would ideally be necessary. > > You can also create a temporary canvas and putImageData once onto > that, and then drawImage sections onto the screen as they are needed. > That lets you draw lots of sections lots of times quickly (since > you're mostly drawing from the optimised canvas surface format, not > from a JS array), which perhaps helps in some (most?) of the cases. > (You still have to do a single putImageData of the whole data to get > it onto the temporary canvas, but if there are parts of the data you > aren't ever using then you just should make the ImageData smaller and > cut out the unused bits.) Yes, there are many ways you can resolve this if you're willing to copy data around in JS, which is far less efficient than letting you use your single backing buffer, but only (effectively) repainting part of it. Using a separate canvas also works, but still requires additional copying, much more memory, and the use of drawImage which doesn't have the same semantics as putImageData. --Oliver > > -- > Philip Taylor > excors at gmail.com
Received on Wednesday, 23 January 2008 11:28:46 UTC