About:

GNUGoS60 is a port of the FSF's GNU Go game engine to Nokia's S60 smartphone platform running on SymbianOS.

It is Free Software.

Thursday, November 29, 2007

Anti-aliasing in Symbian



As you can see in this zoomed image, the stones in GNUGoS60 are more like octagons than actual circles. This is is to be somehow expected given the resolution, and not completely bad, all things considered. There is a certain old skool charm about the crappiness of the graphics :)

Still, some people may prefer their stones round, and anti-aliasing is the term in computer graphics for doing our best to hide the visual limitations of CG renderings. Like octagonal circles, sor instance. Symbian do not provide any such functions that I can see. The Symbian Graphics Context, CWindowGc, doesn't seem to provide any way to draw anti-aliased circles (or anti-aliased anything).

All is not lost though, since it's pretty easy to draw a circle all by ourselves, one pixel at a time. As everyone surely heard at least once in school, the equation for a circle at origin is:

x2 + y2 = r2

or more generically, where cx, cy are the coordinates of the circle's center:

(x - cx)2 + (y - cy)2 = r2

Knowing this, and that each pixel has an x and y coordinate, we can define 2 concentric circles. The outer one equal to the radius we want the stones to be draw. The inner one some tunable factor smaller than that, typically somewhere in the range 0.0 .. 2.0. Given these 2 circles,we can say that, depending on x,y coordinate values, there are three types of pixel:
  1. Pixels outside the outer circle, which are not forming any part of the stone.
  2. Pixels inside the inner circle, which are 100% part of the stone.
  3. Pixels in between the two, which are some measurable percentage both part of the stone and not part of the stone.
Type 1 pixels get no color when drawing the stone. Type 2 pixels get the stone color, black or white, as appropriate. Type 3 pixels again get black or white as appropriate, but also get a transparency value, where it is set transparent to the extent that it is outside the stone. This will have the effect that it will blur the edge pixels reasonably well against the background and give the impression of the stone being rounder (and blurrier :).

Anyway, after all that geometry, Below is the end result. I'm not sure which is actually better, and it may be a matter of taste (and screen resolution), so I'll keep an option to switch between the two.

176x208 resolution


240x320 resolution


352x416 resolution:



One thing making direct comparison difficult is that the anti-aliased ones don't have the black outline for the white stones. Originally I thought that this wasn't needed, but looking at the images side by side, I think that it's probably better to have it. Unfortunately though such an outline would require another funciton to draw an anti-aliased circle outline, which ought to be straightforward, but I haven't done it yet.

I wonder are there any (L)GPL libraries for 2d graphics in Symbian that support anti-aliasing. Adding an extra library is a bit much for the limited amount of drawing in GNUGoS60 though.

0 comments: