[cairo] Turning off antialiasing
Carl Worth
cworth at cworth.org
Tue Oct 19 08:54:21 PDT 2004
On Mon, 18 Oct 2004 11:39:48 -0700, Bill Spitzak wrote:
> I do not think the proposed solution in the FAQ will do the job. First it
> does not work if you do any scaling, making it impossible to make sharp
> outlined rectangles at any transform other than the identity.
The hard part about this is what effect does the user want? If I
introduce a "scale by 1.5" should these magic lines now be 2 pixels wide?
Still 1 pixel? What about a scale by 5 or 50?
This is a similar concern to Owen's misgivings about the default matrix
and the scaling it introduces when DPI increases.
> My proposal is that Cairo must support a special mode for stroking the path.
> The requirements of this mode are:
It is clear that cairo should help users draw graphics aligned to
device-pixel boundaries. It's not just about horizontal and vertical
elements though, and it's not just about stroking either. I was playing
with small-radius, filled circles yesterday, (for the dot in the center
of the radio button). The alignment of that circle with the device-pixel
edges makes a huge difference in the perceived quality.
> 1. Lines drawn parallel with the pixel rows and columns must be 100% opaque
> and positioned so that they completely obscure the antialiased edge made by
> filling the same path.
This seems like a reasonable desire. I'm quoting it here
only to reference it later.
> 3. If the user translates one unit in a direction parallel to the pixel grid
> and draws perpendicular lines they will touch or overlap such that no
> partially transparent pixels are between them. Drawing a row of dots 1 unit
> apart must also produce a solid line. I think this means it must be able to
> draw integer thicknesses greater than 1 and that dots must be rectangles.
It seems this requirement would cause some strange behavior with
non-identity transforms, (particularly with diverse horizontal and
vertical scale factors).
> I believe this can be done by setting the line width to the larger of the
> horizontal or vertical scale of the current transform and adjusting the end
> points of horizontal and vertical lines and dots to lie 1/2 line width from
> an integer, then doing the normal stroke algorithim.
It's not a simple matter to make this adjustment satisfy requirement #1.
Imagine the following shape to be filled then stroked, with integer
x,y,width,height and real-valued epsilon within (0.5,1):
cairo_rectangle (cr, x, y, width - epsilon, height - epsilon);
If the adjustment involves adding 0.5 to all values and then rounding to
the nearest half-integer, then the stroke will not completely obscure
the edge of the fill. In order to satisfy requirement #1, the points
would have to be adjusted toward the interior of the object, which
sounds hard.
> I think API's where you use different calls to construct the path, or use a
> different call to draw the horizontal and vertical lines, while sensible,
> would be much too difficult to emulate existing API's on top of.
Since I think there's a bigger issue here than horizontal/vertical
edges and stroking, I think I might like a call that "snaps" the
current path according to some criteria. For example, it could align
horizontal/vertical edges with pixel boundaries, and it might do the
same with the extremal points of curves. The snapping desired is
different for stroking and filling, but a sequence of:
calling cairo_stroke_path, cairo_snap_path, cairo_fill
in place of cairo_stroke would address that. Now, that certainly
wouldn't meet the needs of fixing our #1 frequently-asked-question, so
we might also need a mode bit in the graphics state to do these
operations implicitly for every stroke.
One other interesting aspect here is that the cairo_snap_path could
accept some guidance from the user. As Keith described, scene-level
information is really needed in order to get the best results. So
Keith has suggested in conversation with me recently that cairo might
accept a list of "snap points" from the user. I'm intrigued by this
idea and would like to hear more discussion of it.
-Carl
More information about the cairo
mailing list