[cairo] Transparent pattern may be wrong
Bill Spitzak
spitzak at d2.com
Fri Feb 25 12:31:20 PST 2005
In an anti-aliased system such as Cairo specifying patterns as having
transparent edges may be the wrong thing to do. The problem is
double-premultiply:
It would be very common for a user to draw a rectangle exactly the same
size as the area of their source image. However if the transformation is
such that the rectangle does not land on pixel boundaries, the edge
pixels will be antialiased and thus the pattern pixels will be
multiplied by this antialias value. But the pattern itself is also
filtered, so if the edge is transparent, the pixel will already be
multiplied by the fraction that is inside. Thus it will be multiplied by
the coverage twice, producing a black border around the rectangle. The
effect is subtle but can get really annoying fast. This is especially
bad if various other errors cause the rectangle to not exactly line up
with the image edge.
I do not think an operation with such unexpected side effects should be
the default. In fact the only operations without unexpected effects is
nearest-pixel and a "mirror" repeat of the image. I recommend
nearest-pixel be the default. This also has the convient effect of being
the expected value for gradients.
There is no need to support transparent edge. The transparent edge can
be exactly emulated by making the pattern be 1 pixel larger on all
sides, with a border of transparent pixels, and using nearest-pixel for
the outside. Hardware mipmap implementation of transparent edge *has* to
do this anyway, so it may be more efficient to move this up to the Cairo
API because the pattern can be loaded directly into the texture.
Transparent edge can also be emulated for most operators by making a
clip region of the proper rectangle.
More information about the cairo
mailing list