[cairo] cairo anti aliasing
Bill Spitzak
spitzak at d2.com
Fri Feb 18 17:38:06 PST 2005
Tim Janik wrote:
> there is one major essential feature i currently see cairo
> lacking for that though.
> adjusting the amount of anti-aliasing:
> currently, i can render rectangles with varying amounts of smoothness at
> the edges, similar to the "Feather Edge" feature of the gimp "rectangle
> select" command. this is essentially adjusting the radius of a 2D
> gaussian
> curve in pixels, used to smooth the figure edges.
> as an example, i have attached an image, containing 4 times the same
> rectangle, rendered with feather edges of 0, 1, 2 and 3 from left to
> right.
>
> to adress this issues, i'd like to know:
> where in cairo or pixman is the current anti-aliasing amount encoded
> (approximately 1.5 pixels feather edge if comapared to my example picture)
> and what is required to make that configurable?
Large smooth shapes *can* be antialiased by instead drawing a 1-pixel
thick ramp centered on the edge, and point-sampling the resulting image.
This technique is often used as it is easy to implement if you can
already point-sample shapes with gradients (I use it in our own
software). This appears to be what Gimp is doing. And because of how the
math is done, it is almost free to make the ramp thicker and thus use
the code to produce "blurry" images.
Unfortunatly this is not the best algorithim, it does not work on
concave shapes and does not work on anything thinner than one pixel. It
also can produce Mach banding (that's the "points" you see on the
corners of the right-most rectangle). It's also not very fast. It is
probably not a good idea to assumme Cairo is using this.
Also I suspect you want the blur to remain the same size when drawn on
different devices. So even if this algorithim is used, you want the ramp
to be 3 units wide, not 3 pixels. However for the correct "1" value you
want 1 pixel, not 1 unit. So if there is some kind of control it either
has to add to the base control so that 0 means normal antialiasing, or
it would have to be non-linear, so that 0-1 are in pixels while 1-n are
(n-1)*units+1pixel.
It may be better to describe the desired result directly. The rectangle
on the right, including the Mach banding points, can be replicated in
existing Cairo as a smaller white rectangle and 4 thin trapazoids drawn
around the edges with a gradient ramp, white on the inside touching the
rectangle and black on the outside. More complex shapes would, I think,
be possible with Cairo's path-enumeration, but obviously more difficult.
More information about the cairo
mailing list