00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103 #include "camtypes.h"
00104
00106
00107
00108
00110
00111 #include <math.h>
00112 #include "gwinding.h"
00113
00116
00117 INT32 GWSgnMulSubMul( INT32 A, INT32 B, INT32 C, INT32 D )
00118 {
00119 #if defined(__WXMSW__)
00120 UINT32 temp ;
00121 __asm {
00122 mov eax,A
00123 imul B
00124 mov ebx,eax
00125 mov ecx,edx
00126 mov eax,C
00127 imul D
00128 sub ebx,eax
00129 sbb ecx,edx
00130 jne returnecx
00131 or ecx,ebx
00132 jns returnecx
00133 not ecx
00134 returnecx:
00135 mov temp,ecx
00136 }
00137 return temp;
00138 #else
00139 XLONG X = (XLONG)A*B-(XLONG)C*D;
00140 return X>0 ? 1 : X<0 ? -1 : 0 ;
00141 #endif
00142 }
00143
00145
00146 PPOINT Points ;
00147 PPOINT StartPoint ;
00148
00149 POINT BottomLeft ;
00150 POINT PrevPoint ;
00151 POINT LastPoint ;
00152 POINT OldPoint ;
00153
00154 POINT Prev_Point ;
00155 POINT Next_Point ;
00156
00157 INT32 Flags ;
00158
00159 UINT32 Flatness ;
00160 UINT32 BottomLeftOffset ;
00161
00163
00164 void DoLine( POINT P )
00165 {
00166 if ( (Flags & 04) && ( OldPoint.x!=LastPoint.x || OldPoint.y!=LastPoint.y ) )
00167 {
00168 PrevPoint = LastPoint ;
00169 Flags &= ~04 ;
00170 }
00171 if ( P.x+P.y > BottomLeft.x+BottomLeft.y ||
00172 (P.x+P.y == BottomLeft.x+BottomLeft.y &&
00173 P.y >= BottomLeft.y) )
00174 {
00175 if ( (Flags & 02) && ( P.x!=BottomLeft.x ||
00176 P.y!=BottomLeft.y ) )
00177 {
00178 Next_Point = P ;
00179 Flags &= ~02 ;
00180 }
00181 Flags |= 04 ;
00182 }
00183 else
00184 {
00185 Prev_Point = PrevPoint ;
00186 BottomLeft = P ;
00187 BottomLeftOffset = Points-StartPoint ;
00188 Flags = 02 ;
00189 PrevPoint = P ;
00190 }
00191 OldPoint = LastPoint ;
00192 LastPoint = P ;
00193 }
00194
00196
00197 void FlattenSplit( POINT P0, POINT P1, POINT P2, POINT P3 ) ;
00198
00199 void FlattenCurve( POINT P0, POINT P1, POINT P2, POINT P3 )
00200 {
00201 UINT32 dx,dy ;
00202 dx = abs(P1.x*3 - P0.x*2 - P3.x) ;
00203 dy = abs(P1.y*3 - P0.y*2 - P3.y) ;
00204 if ( (dx>=dy ? 3*dx+dy : dx+3*dy) > Flatness )
00205 FlattenSplit(P0,P1,P2,P3) ;
00206 else
00207 {
00208 dx = abs(P2.x*3 - P0.x - P3.x*2) ;
00209 dy = abs(P2.y*3 - P0.y - P3.y*2) ;
00210 if ( (dx>=dy ? 3*dx+dy : dx+3*dy) > Flatness )
00211 FlattenSplit(P0,P1,P2,P3) ;
00212 else
00213 DoLine(P3) ;
00214 }
00215 }
00216
00217
00218 void FlattenSplit( POINT P0, POINT P1, POINT P2, POINT P3 )
00219 {
00220 POINT L1, L2, M, R1, R2 ;
00221 L1.x = (P0.x + P1.x)/2;
00222 L1.y = (P0.y + P1.y)/2;
00223 L2.x = (P0.x + 2*P1.x + P2.x)/4;
00224 L2.y = (P0.y + 2*P1.y + P2.y)/4;
00225 M.x = (P0.x + 3*P1.x + 3*P2.x + P3.x)/8;
00226 M.y = (P0.y + 3*P1.y + 3*P2.y + P3.y)/8;
00227 R1.x = (P1.x + 2*P2.x + P3.x)/4;
00228 R1.y = (P1.y + 2*P2.y + P3.y)/4;
00229 R2.x = (P2.x + P3.x)/2;
00230 R2.y = (P2.y + P3.y)/2;
00231 FlattenCurve(P0, L1, L2, M) ;
00232 FlattenCurve(M, R1, R2, P3) ;
00233 }
00234
00236
00237 BOOL GWinding(
00238 PPOINT pPoints,
00239 PBYTE Types,
00240 INT32 Length,
00241 UINT32 pFlatness,
00242 UINT32 &pBottomLeftOffset,
00243 POINT &pBottomLeft
00244 )
00245 {
00246 Flatness = pFlatness*27/2 ;
00247 StartPoint = Points = pPoints ;
00248 BottomLeft = PrevPoint = LastPoint = *Points++ ; Types++ ; --Length ;
00249 BottomLeftOffset = 0 ;
00250 Flags = 03 ;
00251 while ( Length>0 )
00252 {
00253 if ( (*Types & PT_MOVETO)==PT_LINETO )
00254 {
00255 DoLine( Points[0] ) ;
00256 Points++ ; Types++ ; --Length ;
00257 }
00258 else
00259 {
00260 FlattenCurve( Points[-1],Points[0],Points[1],Points[2] ) ;
00261 Points+=3 ; Types+=3 ; Length-=3 ;
00262 }
00263 }
00264 if ( BottomLeft.x!=LastPoint.x || BottomLeft.y!=LastPoint.y )
00265 PrevPoint = LastPoint ;
00266 if ( Flags & 01 )
00267 Prev_Point = PrevPoint ;
00268 else if ( Flags & 02 )
00269 Next_Point = *StartPoint ;
00270 pBottomLeftOffset = BottomLeftOffset ;
00271 pBottomLeft = BottomLeft ;
00272 INT32 Sgn = GWSgnMulSubMul( Next_Point.x-BottomLeft.x, Prev_Point.y-BottomLeft.y,
00273 Prev_Point.x-BottomLeft.x, Next_Point.y-BottomLeft.y ) ;
00274 if ( Sgn )
00275 return Sgn<0 ;
00276 Sgn = Next_Point.x-Prev_Point.x ;
00277 if ( Sgn )
00278 return Sgn<0 ;
00279 Sgn = Prev_Point.y-Next_Point.y ;
00280 return Sgn<0 ;
00281 }
00282