Render transformation matrix

David Reveman davidr at novell.com
Wed Jan 26 08:39:47 PST 2005


On Wed, 2005-01-26 at 08:53 -0500, Owen Taylor wrote:
> On Wed, 2005-01-26 at 14:35 +0100, Damien Ciabrini wrote:
> 
> > I'm trying to add support for the Render transformation matrix for the 
> > Kdrive mga driver, and I'd like to know if I understood the problem 
> > correctly.
> > 
> > In a user program, I want to composite a Picture with a certain zoom 
> > factor. I do it with the following piece of code:
> > 
> >   XRenderSetPictureTransform(dpy,icon_pic,&xform);
> >   // XRenderSetPictureFilter(dpy,icon_pic,FilterBilinear, 0, 0);
> >   XRenderComposite(dpy,composite_op,icon_pic, 0, back_buffer_pic,
> >                    0, 0, 0, 0, zoomed_x[i],zoomed_y[i],
> > 		  zoomed_size[i],zoomed_size[i]);
> > and this is my transformation matrix:
> >    XTransform xform = {{
> > 	{ 1.0f, 0.0f, 0.0f },
> > 	{ 0.0f, 1.0f, 0.0f },
> > 	{ 0.0f, 0.0f, 2.0f }
> >    }};
> > I assume it would give the same result with the following matrix:
> >    XTransform xform = {{
> > 	{ 2.0f, 0.0f, 0.0f },
> > 	{ 0.0f, 2.0f, 0.0f },
> > 	{ 0.0f, 0.0f, 1.0f }
> >    }};
> 
> Are you actually passing in floating point values, or is the
> above just a shorthand? (the code above will give you matrices that 
> are off by a factor of 65536.. you need to use XDoubleToFixed)
> 
> But in any case, the two matrices aren't equivalent ... I'm pretty
> sure that the code just ignores the 3rd line of the transform,
> since the code isn't really dealing with homogeneous coordinates,
> but if it wasn't, then the first matrix applied to [1,0,1] would
> give [1,0,2] which is equivalent to [0.5,0,1]. The second 
> gives [2,0,1].

The code is actually dealing with homogeneous coordinates and the 3rd
line of the transform. But you're right the two matrices above are not
equivalent.
[ 1, 0, 0 ]
[ 0, 1, 0 ]
[ 0, 0, 2 ]
is equivalent to
[ 1/2,   0, 0 ]
[   0, 1/2, 0 ]
[   0,   0, 1 ]

> 
> So, this may not be your question, but if I wanted to zoom a picture
> by a factor of s, I'd use the matrix
> 
>  DoubleToFixed(1/s), 0,                  0
>  0,                  DoubleToFixed(1/s), 0
>  0,                  0,                  1

rather

DoubleToFixed(1/s), 0,                  0
0,                  DoubleToFixed(1/s), 0
0,                  0,                  DoubleToFixed(1)

as the 3rd line is not ignored.

-David




More information about the xorg mailing list