views:

132

answers:

2

I have a BitmapData object with an alpha channel. I'd like to know the fastet way to offset that alpha channel in ActionScript3 (FlashPlayer10). By offsetting I mean shifting all pixels of that channel in one direction (wrapping around the image borders) while leaving the color channels as they were.

Is there a good way to apply a such a transform to one channel only?

A: 

You would use Adobe PixelBender for this kind of operation or write this manually (using getVector/setVector) in ActionScript. However, shifting the alpha channel sounds like a bad idea since all colors are stored with premultiplied alpha.

This means you will have a continous loss in precision.

Joa Ebert
hmm, never heard of the pre-multiplied alpha trick before. Thanks for pointing it out. I wonder whether it really benefits performance much though. Seems like a debatable trade-off when modifying the bitmaps becomes much more expensive because of it...
BuschnicK
A: 

I think how I would tackle this is to create a clone() of the original bitmapData object. Leave the original intact. With the clone, shift all the pixels the way you want. There's no built in "scroll with carry" but it's not too hard. Here's some code for one, but you can simplify it a lot if you only do one direction:

http://www.actionscript.org/forums/showthread.php3?p=767722

AFter scrolling, use copyChannel() to copy the alpha channel from your scrolled clone back to the original.

justkevin
thanks, works beautifully
BuschnicK