I&#39;m talking about this code, from <a href="http://source.winehq.org/source/dlls/gdi32/bitblt.c">http://source.winehq.org/source/dlls/gdi32/bitblt.c</a>, in function PlgBlt :<div><br></div><div><span class="Apple-style-span" style="font-family: &#39;Times New Roman&#39;; font-size: medium; "><pre>
<a name="L577" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L577">577</a>     rect[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a> = nXSrc;
<a name="L578" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L578">578</a>     rect[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a> = nYSrc;
<a name="L579" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L579">579</a>     rect[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a> = nXSrc + nWidth;
<a name="L580" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L580">580</a>     rect[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a> = nYSrc;
<a name="L581" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L581">581</a>     rect[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a> = nXSrc;
<a name="L582" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L582">582</a>     rect[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a> = nYSrc + nHeight;
<a name="L583" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L583">583</a>     <b><i>/* calc XFORM matrix to transform hdcDest -&gt; hdcSrc (parallelogram to rectangle) */</i></b>
<a name="L584" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L584">584</a>     <b><i>/* determinant */</i></b>
<a name="L585" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L585">585</a>     det = rect[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>*(rect[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a> - rect[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>) - rect[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>*(rect[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a> - rect[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>) - rect[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>*(rect[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a> - rect[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>);
<a name="L586" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L586">586</a> 
<a name="L587" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L587">587</a>     if (fabs(det) &lt; 1e-5)
<a name="L588" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L588">588</a>     {
<a name="L589" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L589">589</a>         <a href="http://source.winehq.org/source/dlls/gdi32/ident?i=SetGraphicsMode">SetGraphicsMode</a>(hdcDest,oldgMode);
<a name="L590" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L590">590</a>         return <a href="http://source.winehq.org/source/dlls/gdi32/ident?i=FALSE">FALSE</a>;
<a name="L591" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L591">591</a>     }
<a name="L592" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L592">592</a> 
<a name="L593" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L593">593</a>     <a href="http://source.winehq.org/source/dlls/gdi32/ident?i=TRACE">TRACE</a>(<i>&quot;hdcSrc=%p %d,%d,%dx%d -&gt; hdcDest=%p %d,%d,%d,%d,%d,%d\n&quot;</i>,
<a name="L594" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L594">594</a>         hdcSrc, nXSrc, nYSrc, nWidth, nHeight, hdcDest, plg[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>, plg[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>, plg[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>, plg[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>, plg[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>, plg[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>);
<a name="L595" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L595">595</a> 
<a name="L596" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L596">596</a>     <b><i>/* X components */</i></b>
<a name="L597" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L597">597</a>     xf.eM11 = (plg[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>*(rect[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a> - rect[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>) - plg[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>*(rect[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a> - rect[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>) - plg[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>*(rect[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a> - rect[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>)) / det;
<a name="L598" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L598">598</a>     xf.eM21 = (rect[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>*(plg[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a> - plg[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>) - rect[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>*(plg[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a> - plg[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>) - rect[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>*(plg[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a> - plg[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>)) / det;
<a name="L599" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L599">599</a>     xf.eDx  = (rect[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>*(rect[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>*plg[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a> - rect[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>*plg[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>) -
<a name="L600" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L600">600</a>                rect[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>*(rect[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>*plg[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a> - rect[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>*plg[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>) +
<a name="L601" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L601">601</a>                rect[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>*(rect[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>*plg[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a> - rect[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>*plg[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>)
<a name="L602" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L602">602</a>                ) / det;
<a name="L603" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L603">603</a> 
<a name="L604" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L604">604</a>     <b><i>/* Y components */</i></b>
<a name="L605" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L605">605</a>     xf.eM12 = (plg[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>*(rect[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a> - rect[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>) - plg[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>*(rect[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a> - rect[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>) - plg[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>*(rect[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a> - rect[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>)) / det;
<a name="L606" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L606">606</a>     xf.eM22 = (plg[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>*(rect[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a> - rect[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>) - plg[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>*(rect[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a> - rect[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>) - plg[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>*(rect[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a> - rect[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>)) / det;
<a name="L607" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L607">607</a>     xf.eDy  = (rect[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>*(rect[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>*plg[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a> - rect[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>*plg[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>) -
<a name="L608" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L608">608</a>                rect[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>*(rect[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>*plg[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a> - rect[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>*plg[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>) +
<a name="L609" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L609">609</a>                rect[2].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=x">x</a>*(rect[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>*plg[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a> - rect[1].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>*plg[0].<a href="http://source.winehq.org/source/dlls/gdi32/ident?i=y">y</a>)
<a name="L610" href="http://source.winehq.org/source/dlls/gdi32/source/dlls/gdi32/bitblt.c#L610">610</a>                ) / det;
</pre><div><font class="Apple-style-span" face="monospace"><span class="Apple-style-span" style="white-space: pre;"><br></span></font></div><div><font class="Apple-style-span" face="monospace"><span class="Apple-style-span" style="white-space: pre;"><br>
</span></font></div><div><font class="Apple-style-span" face="monospace"><span class="Apple-style-span" style="white-space: pre;">I have a formula that so far seems to give always the correct matrix:</span></font></div><div>
<font class="Apple-style-span" face="monospace"><span class="Apple-style-span" style="white-space: pre;"><br></span></font></div><div><font class="Apple-style-span" face="monospace"><span class="Apple-style-span" style="white-space: pre;"><div>
<span class="Apple-tab-span" style="white-space:pre">        </span>xf.eM11 = (FLOAT) -(rect[1].y*plg[2].x+rect[0].y*(plg[1].x-plg[2].x)-rect[2].y*plg[1].x+plg[0].x*(rect[2].y-rect[1].y)) /(rect[0].y*(rect[2].x-rect[1].x)-rect[1].y*rect[2].x+rect[2].y*rect[1].x+(rect[1].y-rect[2].y)*rect[0].x);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>xf.eM12 = (FLOAT) -(rect[1].y*(plg[2].y-plg[0].y)+rect[0].y*(plg[1].y-plg[2].y)+rect[2].y*(plg[0].y-plg[1].y)) /(rect[0].y*(rect[2].x-rect[1].x)-rect[1].y*rect[2].x+rect[2].y*rect[1].x+(rect[1].y-rect[2].y)*rect[0].x);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>xf.eM21 = (FLOAT) (plg[0].x*(rect[2].x-rect[1].x)-plg[1].x*rect[2].x+plg[2].x*rect[1].x+(plg[1].x-plg[2].x)*rect[0].x) /(rect[0].y*(rect[2].x-rect[1].x)-rect[1].y*rect[2].x+rect[2].y*rect[1].x+(rect[1].y-rect[2].y)*rect[0].x);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>xf.eM22 = (FLOAT) ((plg[0].y-plg[1].y)*rect[2].x+(plg[2].y-plg[0].y)*rect[1].x+(plg[1].y-plg[2].y)*rect[0].x) /(rect[0].y*(rect[2].x-rect[1].x)-rect[1].y*rect[2].x+rect[2].y*rect[1].x+(rect[1].y-rect[2].y)*rect[0].x);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>xf.eDx = (FLOAT) -(rect[0].y*(plg[2].x*rect[1].x-plg[1].x*rect[2].x)+plg[0].x*(rect[1].y*rect[2].x-rect[2].y*rect[1].x)+(rect[2].y*plg[1].x-rect[1].y*plg[2].x)*rect[0].x) /(rect[0].y*(rect[2].x-rect[1].x)-rect[1].y*rect[2].x+rect[2].y*rect[1].x+(rect[1].y-rect[2].y)*rect[0].x);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>xf.eDy = (FLOAT) (rect[0].y*(plg[1].y*rect[2].x-plg[2].y*rect[1].x)-rect[1].y*plg[0].y*rect[2].x+rect[2].y*plg[0].y*rect[1].x+(rect[1].y*plg[2].y-rect[2].y*plg[1].y)*rect[0].x) /(rect[0].y*(rect[2].x-rect[1].x)-rect[1].y*rect[2].x+rect[2].y*rect[1].x+(rect[1].y-rect[2].y)*rect[0].x);</div>
<div><br></div><div><br></div><div>The rect and plg arrays must be of FLOAT points for the formula to work well, like</div><div><br></div><div>struct</div><div>{</div><div>double x;</div><div>double y;</div><div>}</div><div>
<br></div><div>Otherwise sometimes the compiler will decide to divide integers.</div><div><br></div><div>I found out about the bug by converting the rect points using the XFORM matrix, and checking that their the same as the plg points.</div>
<div><br></div></span></font></div></span></div>