[cairo] PATCH cairo-www: Simpler explanation for how to get sharp, single-pixel-wide lines

Lawrence D'Oliveiro ldo at geek-central.gen.nz
Wed May 17 10:50:01 UTC 2017


On Wed, 17 May 2017 12:29:15 +0200, Guillermo Rodriguez wrote:

> It occurs because integer coordinates map to points half way
> between sample point locations ...

That’s a common misconception. Sampling doesn’t work that way. Whether
you label the sample points as integer “n” or “n + ½”, the problem still
happens.

Cairo’s stroked and filled shapes have infinitely sharp edges. That
means they have an infinite spatial frequency spectrum, well beyond any
finite Nyquist limit. Such shapes are impossible to represent, in
general, on a finite sampled grid. Anti-aliasing removes the
frequencies beyond this limit; this avoids the sampling artifacts at the
cost of introducing blurriness into the edges of the shape.

It just so happens the blurriness becomes less noticeable for exactly
horizontal or vertical edges if you place these edges between rows or
columns of pixels. But these are also the situations where the aliasing
artifacts are minimized.

And if you turn off anti-aliasing, the precise placement of the edge no
longer becomes critical--anywhere between pixels will do. In
particular, the whole n-versus-n-plus-½ nonsense becomes irrelevant.

Anti-aliasing is not magic, it’s just a tool, to be used when
appropriate and set aside when not. Don’t be superstitious about it.


More information about the cairo mailing list