[cairo] [pixman] fix pixel offsets in rotated image sources

Bill Spitzak spitzak at d2.com
Thu Sep 15 18:06:23 PDT 2005

I'm not sure if it is relevant, but this is how I fixed the XRender 
backend of our code to handle the fact that it thinks 0,0 is at the 
center of the pixel and not at the corner. It turned out the adjustment 
is much simpler than expected.

After calculating the XRender transformation matrix as though integers 
were where I wanted (at the pixel corners), the following code fixes it 
before using it to transform an image. This is the same as concatenating 
the transform to move the image by .5,.5, the original transform, and 
another transform by -.5,-.5:

   xtransform.matrix[0][2] +=
   xtransform.matrix[1][2] +=

I was rather suprised that this could be done with just this code, but 
that actually is how it works out if you figure it out algebraically. 
Note that 0x10000 is 1.0 in XRender matrix integers and >>1 is a 

Bertram Felgenhauer wrote:

> 1st issue. The rendering code uses (0, 0) as a reference point for the
> pixel (0,0). This leads to rounding errors for transformations that are
> close to the unit transformation - consider the identity transform and
> a translation by (-epsilon, -epsilon) - and a bias to the upper left
> of the pixel when rendering. A better choice seems to be to sample at
> the center of the pixel, which has coordinates (1/2, 1/2).

More information about the cairo mailing list