views:

178

answers:

1

I'm using the standard ActionScript blur filter to blur an image. The image will later be used as a texture map on a cylinder, i.e. it's left and right edges will meet in 3D. This looks bad because the blur filter has discontinuities at the image edges. I'd like to set it so it'll wrap around the image so that instead of truncating the filter kernel it'll do a modulo operation to get the pixel from the other end. Is that at all possible?

If not - what's the best way to write such functions yourself in ActionScript? I'd imagine using getPixel32 and setPixel32 would be prohibitively slow for larger images?

A: 

Option one: create an image extended by the radius of the blur. So you do something like buffer = new BitmapData(src.width + 2 * radius, src.height + 2 * radius, src.transparent, 0) then you draw the src onto the buffer with a translated matrix by radius. Like m = new Matrix() and then m.translate(radius, radius) and finally buffer.draw(src, m) now you just have to call buffer.applyFilter with new BlurFilter(radius, radius) and call copyPixels with new Rectangle(radius, radius, src.width, src.height) and you are done.

Option two: Use Adobe PixelBender if your blur radius does not change. You can write the modulo yourself and this should not be to hard.

Option three: Implement your own Gauss kernel -- this will never be as fast as option one but faster than option two since you can always buffer n-1 columns of the matrix for a blur and just calculate the n+1th colum. However you would use BitmapData.getVector to get a pixel buffer once instead of calling getPixel32 repeateadly.

Joa Ebert
Thanks Joa, I have implemented your option one. Wastes quite a bit of CPU copying the channels of huge images around, but works. Coming from C++ my ActionScript experience is limited, but so far I find I'm paying a lot for "leaky abstractions". I.e. the libraries are fine as far as they go, but once you need to implement some low level stuff support seems extraordinarily cumbersome and slow.
BuschnicK
Another option would be to use always the bigger BitmapData so you do not waste any resources and change your UV maps according. You basically have to offset all uv-coordinates by radius.
Joa Ebert