[cairo] Drawing diagonal lines with antialiasing off

Carl Worth cworth at cworth.org
Tue Oct 18 12:23:46 PDT 2005

On Tue, 18 Oct 2005 15:02:36 -0400, "Jonathan S. Chambers" wrote:
> 3) Appropriately careful rasterization. There are some edge conditions
>    that need to be just right here. I don't know that the depth 1
>    rasterization implementation has ever been carefully examined to
>    provide the result you'll want here.
> Point 3 is where I could use some advice, if anyone is offering.

It's a matter of getting out the graph paper and then following things
through the code rather carefully.

Let's look back at your original code:

	cairo_set_line_width (cr, 1);
	cairo_move_to (cr, 5, 5);
	cairo_line_to (cr, 10, 10);
	cairo_stroke (cr);

At this point you've defined a rectangle that has vertical edges at
4.5 and at 5.5. Then, the code will sample pixels to determine how
much they are "inside" the shape. With an A1 mask, (which is what you
get with ANTIALIAS_NONE), the inside-ness is a binary decision. The
single sampling point should be half-way between integer coordinates,
though it currently isn't, but see the bug report and patch here:


Once that issue is fixed you'll be looking at pixel sample locations
at 4.5 and 5.5, or exactly on the perimeter of your shape of
interest. In this boundary case, only one of each of these pixels in
each row should be considered "inside".

For example, a sample point colinear with a trapezoid's left edge
could be considered "inside" while a sample point colinear with a
trapezoid's right edge could be considered "outside". (It could be the
other way too---the important thing is that no sample point can be
"double counted" as inside two disjoint trapezoids that share a common

If there is a bug here, the relevant code can be found in
cairo/pixman/src as follows:

	fbRasterizeTrapezoid (fbtrap.c)
	  fbRasterizeEdges (fbedge.c)
	    fbRasterizeEdges1 (#define from rasterizeEdges in fbedge.c)
	      rasterizeEdges (fbedgeimp.h)

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/cairo/attachments/20051018/6b3c0aee/attachment.pgp

More information about the cairo mailing list