@@ -1184,7 +1184,7 @@ inline static void gdImageSetAAPixelColor(gdImagePtr im, int x, int y, int color
1184
1184
void gdImageAALine (gdImagePtr im , int x1 , int y1 , int x2 , int y2 , int col )
1185
1185
{
1186
1186
/* keep them as 32bits */
1187
- long x , y , inc ;
1187
+ long x , y , inc , frac ;
1188
1188
long dx , dy ,tmp ;
1189
1189
1190
1190
if (y1 < 0 && y2 < 0 ) {
@@ -1254,16 +1254,22 @@ void gdImageAALine (gdImagePtr im, int x1, int y1, int x2, int y2, int col)
1254
1254
dx = x2 - x1 ;
1255
1255
dy = y2 - y1 ;
1256
1256
}
1257
- x = x1 << 16 ;
1258
- y = y1 << 16 ;
1257
+ y = y1 ;
1259
1258
inc = (dy * 65536 ) / dx ;
1260
- while ((x >> 16 ) <= x2 ) {
1261
- gdImageSetAAPixelColor (im , x >> 16 , y >> 16 , col , (y >> 8 ) & 0xFF );
1262
- if ((y >> 16 ) + 1 < im -> sy ) {
1263
- gdImageSetAAPixelColor (im , x >> 16 , (y >> 16 ) + 1 ,col , (~y >> 8 ) & 0xFF );
1259
+ frac = 0 ;
1260
+ for (x = x1 ; x <= x2 ; x ++ ) {
1261
+ gdImageSetAAPixelColor (im , x , y , col , (frac >> 8 ) & 0xFF );
1262
+ if (y + 1 < im -> sy ) {
1263
+ gdImageSetAAPixelColor (im , x , y + 1 , col , (~frac >> 8 ) & 0xFF );
1264
+ }
1265
+ frac += inc ;
1266
+ if (frac >= 65536 ) {
1267
+ frac -= 65536 ;
1268
+ y ++ ;
1269
+ } else if (frac < 0 ) {
1270
+ frac += 65536 ;
1271
+ y -- ;
1264
1272
}
1265
- x += (1 << 16 );
1266
- y += inc ;
1267
1273
}
1268
1274
} else {
1269
1275
if (dy < 0 ) {
@@ -1276,16 +1282,22 @@ void gdImageAALine (gdImagePtr im, int x1, int y1, int x2, int y2, int col)
1276
1282
dx = x2 - x1 ;
1277
1283
dy = y2 - y1 ;
1278
1284
}
1279
- x = x1 << 16 ;
1280
- y = y1 << 16 ;
1285
+ x = x1 ;
1281
1286
inc = (dx * 65536 ) / dy ;
1282
- while ((y >>16 ) <= y2 ) {
1283
- gdImageSetAAPixelColor (im , x >> 16 , y >> 16 , col , (x >> 8 ) & 0xFF );
1284
- if ((x >> 16 ) + 1 < im -> sx ) {
1285
- gdImageSetAAPixelColor (im , (x >> 16 ) + 1 , (y >> 16 ),col , (~x >> 8 ) & 0xFF );
1287
+ frac = 0 ;
1288
+ for (y = y1 ; y <= y2 ; y ++ ) {
1289
+ gdImageSetAAPixelColor (im , x , y , col , (frac >> 8 ) & 0xFF );
1290
+ if (x + 1 < im -> sx ) {
1291
+ gdImageSetAAPixelColor (im , x + 1 , y , col , (~frac >> 8 ) & 0xFF );
1292
+ }
1293
+ frac += inc ;
1294
+ if (frac >= 65536 ) {
1295
+ frac -= 65536 ;
1296
+ x ++ ;
1297
+ } else if (frac < 0 ) {
1298
+ frac += 65536 ;
1299
+ x -- ;
1286
1300
}
1287
- x += inc ;
1288
- y += (1 <<16 );
1289
1301
}
1290
1302
}
1291
1303
}
0 commit comments