Render transformation matrix

Keith Packard keithp at keithp.com
Wed Jan 26 07:18:14 PST 2005


Around 14 o'clock on Jan 26, Damien Ciabrini wrote:

> 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 }
>    }};

(First an explanation of homogenous transforms, then a fix for the 
representation)

Not quite.  It's a homogeneous transform from dest to source (the
transformation are defined by mapping a destination pixel back to the 
relevant source pixels).

So, the X server constructs a 3 vector from the destination pixel as

 [ x y 1 ]

and multiplies it by the transformation (I have no idea if this is 
backwards or not):

	[ x y 1 ] | a b c | = [ (ax + dy + g) (bx + ey + h) (cx + fy + i) ]
		  | d e f |   
		  | g h i |

To normalize this new vector back to the screen space, we divide the
coordinates in the vector by the third:

	  (ax + dy + g)  (bx + ey + h)
        [ -------------  -------------  1 ]
          (cx + fy + i)  (cx + fy + i)

So, in your sample, the second transform would be:

	{ 0.5f, 0.0f, 0.0f },
	{ 0.0f, 0.5f, 0.0f },
	{ 0.0f, 0.0f, 1.0f }

Two homogenous transforms which differ by a constant factor are equivalent.

> Now here comes my problem. When doing the composite in software (Kdrive 
> Xvesa server), the scaling does not occur if I use floating point values 
> such as:
>    XTransform xform = {{
> 	{ 1.0f, 0.0f, 0.0f },
> 	{ 0.0f, 1.0f, 0.0f },
> 	{ 0.0f, 0.0f, 2.3f }     <-- 2.3
>    }};

That's because the transform is represented in 16.16 fixed point.  I 
selected fixed point for the wire representation as it eliminates 
questions about floating point representation and computation.  It's 
probably just a reaction to the horror known as PEX which provided 
multiple wire representation for floating point values.

Just convert these floating point values with DoubleToFixed and you should 
be all set.

-keith


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 228 bytes
Desc: not available
URL: <http://lists.x.org/archives/xorg/attachments/20050126/c0e3f5ad/attachment.pgp>


More information about the xorg mailing list