@@ -1296,7 +1296,7 @@ inline static void gdImageSetAAPixelColor(gdImagePtr im, int x, int y, int color
1296
1296
void gdImageAALine (gdImagePtr im , int x1 , int y1 , int x2 , int y2 , int col )
1297
1297
{
1298
1298
/* keep them as 32bits */
1299
- long x , y , inc ;
1299
+ long x , y , inc , frac ;
1300
1300
long dx , dy ,tmp ;
1301
1301
1302
1302
if (y1 < 0 && y2 < 0 ) {
@@ -1366,16 +1366,22 @@ void gdImageAALine (gdImagePtr im, int x1, int y1, int x2, int y2, int col)
1366
1366
dx = x2 - x1 ;
1367
1367
dy = y2 - y1 ;
1368
1368
}
1369
- x = x1 << 16 ;
1370
- y = y1 << 16 ;
1369
+ y = y1 ;
1371
1370
inc = (dy * 65536 ) / dx ;
1372
- while ((x >> 16 ) <= x2 ) {
1373
- gdImageSetAAPixelColor (im , x >> 16 , y >> 16 , col , (y >> 8 ) & 0xFF );
1374
- if ((y >> 16 ) + 1 < im -> sy ) {
1375
- gdImageSetAAPixelColor (im , x >> 16 , (y >> 16 ) + 1 ,col , (~y >> 8 ) & 0xFF );
1371
+ frac = 0 ;
1372
+ for (x = x1 ; x <= x2 ; x ++ ) {
1373
+ gdImageSetAAPixelColor (im , x , y , col , (frac >> 8 ) & 0xFF );
1374
+ if (y + 1 < im -> sy ) {
1375
+ gdImageSetAAPixelColor (im , x , y + 1 , col , (~frac >> 8 ) & 0xFF );
1376
+ }
1377
+ frac += inc ;
1378
+ if (frac >= 65536 ) {
1379
+ frac -= 65536 ;
1380
+ y ++ ;
1381
+ } else if (frac < 0 ) {
1382
+ frac += 65536 ;
1383
+ y -- ;
1376
1384
}
1377
- x += (1 << 16 );
1378
- y += inc ;
1379
1385
}
1380
1386
} else {
1381
1387
if (dy < 0 ) {
@@ -1388,16 +1394,22 @@ void gdImageAALine (gdImagePtr im, int x1, int y1, int x2, int y2, int col)
1388
1394
dx = x2 - x1 ;
1389
1395
dy = y2 - y1 ;
1390
1396
}
1391
- x = x1 << 16 ;
1392
- y = y1 << 16 ;
1397
+ x = x1 ;
1393
1398
inc = (dx * 65536 ) / dy ;
1394
- while ((y >>16 ) <= y2 ) {
1395
- gdImageSetAAPixelColor (im , x >> 16 , y >> 16 , col , (x >> 8 ) & 0xFF );
1396
- if ((x >> 16 ) + 1 < im -> sx ) {
1397
- gdImageSetAAPixelColor (im , (x >> 16 ) + 1 , (y >> 16 ),col , (~x >> 8 ) & 0xFF );
1399
+ frac = 0 ;
1400
+ for (y = y1 ; y <= y2 ; y ++ ) {
1401
+ gdImageSetAAPixelColor (im , x , y , col , (frac >> 8 ) & 0xFF );
1402
+ if (x + 1 < im -> sx ) {
1403
+ gdImageSetAAPixelColor (im , x + 1 , y , col , (~frac >> 8 ) & 0xFF );
1404
+ }
1405
+ frac += inc ;
1406
+ if (frac >= 65536 ) {
1407
+ frac -= 65536 ;
1408
+ x ++ ;
1409
+ } else if (frac < 0 ) {
1410
+ frac += 65536 ;
1411
+ x -- ;
1398
1412
}
1399
- x += inc ;
1400
- y += (1 <<16 );
1401
1413
}
1402
1414
}
1403
1415
}
0 commit comments