]> pilppa.org Git - familiar-h63xx-build.git/blob - org.handhelds.familiar/packages/qte/qte-2.3.10/improve-calibration-r0.patch
OE tree imported from monotone branch org.openembedded.oz354fam083 at revision 8b12e3...
[familiar-h63xx-build.git] / org.handhelds.familiar / packages / qte / qte-2.3.10 / improve-calibration-r0.patch
1 Index: qt-2.3.10/src/kernel/qwsmouse_qws.cpp
2 ===================================================================
3 --- qt-2.3.10.orig/src/kernel/qwsmouse_qws.cpp  2005-08-31 13:44:12.000000000 +0000
4 +++ qt-2.3.10/src/kernel/qwsmouse_qws.cpp       2005-09-01 19:38:27.000000000 +0000
5 @@ -14,10 +14,6 @@
6  ** Foundation and appearing in the file LICENSE.GPL included in the
7  ** packaging of this file.
8  **
9 -** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
10 -** licenses for Qt/Embedded may use this file in accordance with the
11 -** Qt Embedded Commercial License Agreement provided with the Software.
12 -**
13  ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
14  ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
15  **
16 @@ -30,6 +26,12 @@
17  **
18  **********************************************************************/
19  
20 +/* 
21 + *  The 5 point algorithim in QTSLibHandlerPrivate::calibrate() is
22 + *  GPL only code and Copyright (C) 2001 Russel King.
23 + *
24 + *  Taken from ts_calibrate.c from tslib
25 + */
26  #include "qwindowsystem_qws.h"
27  #include "qsocketnotifier.h"
28  #include "qwsevent_qws.h"
29 @@ -1813,6 +1815,7 @@
30  
31  void QTSLibHandlerPrivate::calibrate( QWSPointerCalibrationData * cd)
32  {
33 +#ifdef ORIG_CALIBRATE
34      QPoint dev_tl = cd->devPoints[ QWSPointerCalibrationData::TopLeft ];
35      QPoint dev_br = cd->devPoints[ QWSPointerCalibrationData::BottomRight ];
36      QPoint screen_tl = cd->screenPoints[ QWSPointerCalibrationData::TopLeft ];
37 @@ -1843,6 +1846,122 @@
38      {
39          qDebug( "Could not save calibration: %s", calFile.latin1() );
40      }
41 +
42 +#else
43 +    int j;
44 +    float n, x, y, x2, y2, xy, z, zx, zy;
45 +    float det, cal_a, cal_b, cal_c, cal_d, cal_e, cal_f, cal_i;
46 +    float scaling = 65536.0;
47 +    int cal_x[5], cal_xfb[5], cal_y[5], cal_yfb[5], cal_o[7];
48 +
49 +    cal_x[0]=cd->devPoints[ QWSPointerCalibrationData::TopLeft ].x();
50 +    cal_y[0]=cd->devPoints[ QWSPointerCalibrationData::TopLeft ].y();
51 +    cal_x[1]=cd->devPoints[ QWSPointerCalibrationData::TopRight ].x();
52 +    cal_y[1]=cd->devPoints[ QWSPointerCalibrationData::TopRight ].y();
53 +    cal_x[2]=cd->devPoints[ QWSPointerCalibrationData::BottomLeft ].x();
54 +    cal_y[2]=cd->devPoints[ QWSPointerCalibrationData::BottomLeft ].y();
55 +    cal_x[3]=cd->devPoints[ QWSPointerCalibrationData::BottomRight ].x();
56 +    cal_y[3]=cd->devPoints[ QWSPointerCalibrationData::BottomRight ].y();
57 +    cal_x[4]=cd->devPoints[ QWSPointerCalibrationData::Center ].x();
58 +    cal_y[4]=cd->devPoints[ QWSPointerCalibrationData::Center ].y();
59 +
60 +    cal_xfb[0]=cd->screenPoints[ QWSPointerCalibrationData::TopLeft ].x();
61 +    cal_yfb[0]=cd->screenPoints[ QWSPointerCalibrationData::TopLeft ].y();
62 +    cal_xfb[1]=cd->screenPoints[ QWSPointerCalibrationData::TopRight ].x();
63 +    cal_yfb[1]=cd->screenPoints[ QWSPointerCalibrationData::TopRight ].y();
64 +    cal_xfb[2]=cd->screenPoints[ QWSPointerCalibrationData::BottomLeft ].x();
65 +    cal_yfb[2]=cd->screenPoints[ QWSPointerCalibrationData::BottomLeft ].y();
66 +    cal_xfb[3]=cd->screenPoints[ QWSPointerCalibrationData::BottomRight ].x();
67 +    cal_yfb[3]=cd->screenPoints[ QWSPointerCalibrationData::BottomRight ].y();
68 +    cal_xfb[4]=cd->screenPoints[ QWSPointerCalibrationData::Center ].x();
69 +    cal_yfb[4]=cd->screenPoints[ QWSPointerCalibrationData::Center ].y();
70 +
71 +    //qDebug("Top left : X = %4d Y = %4d", cal_x[0], cal_y[0]);
72 +    //qDebug("Top right: X = %4d Y = %4d", cal_x[1], cal_y[1]);
73 +    //qDebug("Bot left : X = %4d Y = %4d", cal_x[2], cal_y[2]);
74 +    //qDebug("Bot right: X = %4d Y = %4d", cal_x[3], cal_y[3]);
75 +    //qDebug("Middle: X = %4d Y = %4d", cal_x[4], cal_y[4]);
76 +
77 +    // Get sums for matrix
78 +    n = x = y = x2 = y2 = xy = 0;
79 +    for(j=0;j<5;j++) {
80 +        n += 1.0;
81 +        x += (float)cal_x[j];
82 +        y += (float)cal_y[j];
83 +        x2 += (float)(cal_x[j]*cal_x[j]);
84 +        y2 += (float)(cal_y[j]*cal_y[j]);
85 +        xy += (float)(cal_x[j]*cal_y[j]);
86 +    }
87 +
88 +    // Get determinant of matrix -- check if determinant is too small
89 +    det = n*(x2*y2 - xy*xy) + x*(xy*y - x*y2) + y*(x*xy - y*x2);
90 +    if(det < 0.1 && det > -0.1) {
91 +        qDebug("determinant is too small -- %f",det);
92 +        return;// false;
93 +    }
94 +
95 +    // Get elements of inverse matrix
96 +    cal_a = (x2*y2 - xy*xy)/det;
97 +    cal_b = (xy*y - x*y2)/det;
98 +    cal_c = (x*xy - y*x2)/det;
99 +    cal_e = (n*y2 - y*y)/det;
100 +    cal_f = (x*y - n*xy)/det;
101 +    cal_i = (n*x2 - x*x)/det;
102 +
103 +    // Get sums for x calibration
104 +    z = zx = zy = 0;
105 +    for(j=0;j<5;j++) {
106 +        z += (float)cal_xfb[j];
107 +        zx += (float)(cal_xfb[j]*cal_x[j]);
108 +        zy += (float)(cal_xfb[j]*cal_y[j]);
109 +    }
110 +
111 +    // Now multiply out to get the calibration for framebuffer x coord
112 +    cal_o[0] = (int)((cal_a*z + cal_b*zx + cal_c*zy)*(scaling));
113 +    cal_o[1] = (int)((cal_b*z + cal_e*zx + cal_f*zy)*(scaling));
114 +    cal_o[2] = (int)((cal_c*z + cal_f*zx + cal_i*zy)*(scaling));
115 +
116 +    qDebug("%f %f %f",(cal_a*z + cal_b*zx + cal_c*zy), (cal_b*z + cal_e*zx + cal_f*zy), (cal_c*z + cal_f*zx + cal_i*zy));
117 +
118 +    // Get sums for y calibration
119 +    z = zx = zy = 0;
120 +    for (j=0;j<5;j++) {
121 +        z += (float)cal_yfb[j];
122 +        zx += (float)(cal_yfb[j]*cal_x[j]);
123 +        zy += (float)(cal_yfb[j]*cal_y[j]);
124 +    }
125 +
126 +    // Now multiply out to get the calibration for framebuffer y coord
127 +    cal_o[3] = (int)((cal_a*z + cal_b*zx + cal_c*zy)*(scaling));
128 +    cal_o[4] = (int)((cal_b*z + cal_e*zx + cal_f*zy)*(scaling));
129 +    cal_o[5] = (int)((cal_c*z + cal_f*zx + cal_i*zy)*(scaling));
130 +
131 +    qDebug("%f %f %f",(cal_a*z + cal_b*zx + cal_c*zy), (cal_b*z + cal_e*zx + cal_f*zy), (cal_c*z + cal_f*zx + cal_i*zy));
132 +
133 +
134 +    // If we got here, we're OK, so assign scaling to a[6] and return
135 +    cal_o[6] = (int) scaling;
136 +
137 +    qDebug("Calibration constants: %d %d %d %d %d %d %d",
138 +        cal_o[0], cal_o[1], cal_o[2],
139 +        cal_o[3], cal_o[4], cal_o[5],
140 +        cal_o[6]);
141 +
142 +    QString calFile = "/etc/pointercal";
143 +#ifndef QT_NO_TEXTSTREAM
144 +    QFile file( calFile );
145 +    if ( file.open( IO_WriteOnly ) ) {
146 +        QTextStream t( &file );
147 +        t << cal_o[1] << " " << cal_o[2] << " " << cal_o[0] << " ";
148 +        t << cal_o[4] << " " << cal_o[5] << " " << cal_o[3] << " " << cal_o[6];
149 +       file.flush(); closeTs();
150 +       openTs();
151 +    } else
152 +#endif
153 +    {
154 +        qDebug( "Could not save calibration: %s", calFile.latin1() );
155 +    }
156 +#endif
157  }
158  
159  void QTSLibHandlerPrivate::readMouseData()