views:

196

answers:

2

Hello,

I'm looking for a good way to antialias a bitmap i'm generating with actionscript3. My goal would be to achieve this processing from scratch.

I read a lot on the subject but the most common algorithm are looking too loud (means it's freaky cpu-intensive) to work properly within my swf, because i'm using a scale2x algorithm to smooth the edges of my shape. It doesn't have to be colorfull, since my shape is black and white !

Any hint would be appreciated, thanks :)

+2  A: 

Xiaolin Wu's line algorithm is what you could use. It is fast and easy to implement.

Joa Ebert
It looks like Xiaolin Wu's line algorithm needs to know the coordinates of the line, which doesnt fit directly with what i need because i'm planning to smooth a totally random 'blob' shape - i should look on what i can do with it anyway.The wikipedia article pointed me on Graphics Gems book which is readable on googlebooks : http://bit.ly/cfJW5NThanks Joa
y_nk
@y_nk: you could use SVG. there are several as3 renderers around the web. you could modify them to render into bitmaps and include the antialiasing. also, it think there's already an implementation for antialiased drawing on bitmaps somewhere in sephiroth's or senocular's libraries. can't find it right now, but I'm pretty sure I saw it there (I guess it was sephiroth).
back2dos
@back2dos: i'm not sure of knowing exactly what you're talking about. Do you mean drawing the bitmap in a shape with beginBitmapFill with enabling smoothing ?My random shape is made only with pure black and white pixels, and i'd like to create some grey pixels around to make it smoothier.I'm gonna look into sephiroth/senocular's libs anyway. Thanks for the hint back2dos !
y_nk
@y_nk: What I mean is the following: I assumed, that you load the shapes at runtime and SVG would give you more control to do that, because you can render it manually, in any way you see fit. If you really "generate" them at runtime, you can render lines straight with an antialiasing algorithm (the lib I mentioned also supports beziers if I remember correctly). if there are no shapes involved and you really just generate pixels, then scale2x (with smoothing) helps. also, before rendering back down, you could apply a slight blur filter.
back2dos
+1  A: 

Draw your shape at 2x the size, then simply scale it down to 1/2 the size, relying on Flash itself to do the smoothing. If you need more smoothing, increase the factors (3x + 1/3, etc). You didn't give very many details on what exactly you are drawing, so this may or may not be fast enough, you'll have to try it out.

PS: In the future, if you want more answers to your questions, don't mark one of the answers as accepted. People will skip your question if they see you already accepted one answer.

davr
thanks for the advice. i'll try this as soon as possible
y_nk