Skip to content

Commit a94e88d

Browse files
committed
Fixed gaps in line and simplified code
In some cases when adding extra pixel between steep and non-steep aaline, one extra pixel is not enough, causing gaps to appear between aalines Instead both endpoint pixels are needed This allowed to merge extra pixel handling with endpoint handling
1 parent 5daf458 commit a94e88d

File tree

1 file changed

+7
-54
lines changed

1 file changed

+7
-54
lines changed

src_c/draw.c

Lines changed: 7 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,7 +1329,6 @@ draw_aaline(SDL_Surface *surf, Uint32 color, float from_x, float from_y,
13291329
Uint32 pixel_color;
13301330
float x_gap, y_endpoint, clip_left, clip_right, clip_top, clip_bottom;
13311331
int steep, y;
1332-
int line_inverted;
13331332

13341333
dx = to_x - from_x;
13351334
dy = to_y - from_y;
@@ -1362,7 +1361,6 @@ draw_aaline(SDL_Surface *surf, Uint32 color, float from_x, float from_y,
13621361
swap(&clip_right, &clip_bottom);
13631362
}
13641363
if (dx < 0) {
1365-
line_inverted = 1;
13661364
swap(&from_x, &to_x);
13671365
swap(&from_y, &to_y);
13681366
dx = -dx;
@@ -1427,9 +1425,11 @@ draw_aaline(SDL_Surface *surf, Uint32 color, float from_x, float from_y,
14271425

14281426
/* Handle endpoints separately.
14291427
* The line is not a mathematical line of thickness zero. The same
1430-
* goes for the endpoints. The have a height and width of one pixel. */
1428+
* goes for the endpoints. The have a height and width of one pixel.
1429+
* Extra pixel drawing is requested externally from aalines.
1430+
* It is drawn only when one line is steep and other is not.*/
14311431
/* First endpoint */
1432-
if (!disable_first_endpoint) {
1432+
if (!disable_first_endpoint || extra_pixel_for_aalines) {
14331433
x_pixel_start = (int)from_x;
14341434
y_endpoint = intersect_y =
14351435
from_y + gradient * (x_pixel_start - from_x);
@@ -1463,38 +1463,14 @@ draw_aaline(SDL_Surface *surf, Uint32 color, float from_x, float from_y,
14631463
x_pixel_start++;
14641464
}
14651465
}
1466-
else {
1467-
/* Handle extra pixel for aalines.
1468-
* It is drawn only when one line is steep and other is not.*/
1469-
if (extra_pixel_for_aalines && !line_inverted) {
1470-
x_pixel_start = (int)from_x;
1471-
y_endpoint = intersect_y =
1472-
from_y + gradient * (x_pixel_start - from_x);
1473-
if (to_x > clip_left + 1.0f) {
1474-
x_gap = 1 + x_pixel_start - from_x;
1475-
brightness = y_endpoint - (int)y_endpoint;
1476-
if (steep) {
1477-
x = (int)y_endpoint;
1478-
y = x_pixel_start;
1479-
}
1480-
else {
1481-
x = x_pixel_start;
1482-
y = (int)y_endpoint;
1483-
}
1484-
if ((int)y_endpoint < y_endpoint) {
1485-
pixel_color = get_antialiased_color(surf, x, y, color,
1486-
brightness * x_gap);
1487-
set_and_check_rect(surf, x, y, pixel_color, drawn_area);
1488-
}
1489-
}
1490-
}
1491-
/* To be sure main loop skips first endpoint.*/
1466+
/* To be sure main loop skips first endpoint.*/
1467+
if (disable_first_endpoint) {
14921468
x_pixel_start = (int)ceil(from_x);
14931469
intersect_y = from_y + gradient * (x_pixel_start - from_x);
14941470
}
14951471
/* Second endpoint */
14961472
x_pixel_end = (int)ceil(to_x);
1497-
if (!disable_second_endpoint) {
1473+
if (!disable_second_endpoint || extra_pixel_for_aalines) {
14981474
if (from_x < clip_right - 1.0f) {
14991475
y_endpoint = to_y + gradient * (x_pixel_end - to_x);
15001476
x_gap = 1 - x_pixel_end + to_x;
@@ -1524,29 +1500,6 @@ draw_aaline(SDL_Surface *surf, Uint32 color, float from_x, float from_y,
15241500
set_and_check_rect(surf, x, y, pixel_color, drawn_area);
15251501
}
15261502
}
1527-
else {
1528-
/* Handle extra pixel for aalines.
1529-
* It is drawn only when one line is steep and other is not.*/
1530-
if (extra_pixel_for_aalines && line_inverted) {
1531-
if (from_x < clip_right - 1.0f) {
1532-
y_endpoint = to_y + gradient * (x_pixel_end - to_x);
1533-
x_gap = 1 - x_pixel_end + to_x;
1534-
brightness = y_endpoint - (int)y_endpoint;
1535-
if (steep) {
1536-
x = (int)y_endpoint - 1;
1537-
y = x_pixel_end;
1538-
}
1539-
else {
1540-
x = x_pixel_end;
1541-
y = (int)y_endpoint - 1;
1542-
}
1543-
brightness = 1 - brightness;
1544-
pixel_color = get_antialiased_color(surf, x, y, color,
1545-
brightness * x_gap);
1546-
set_and_check_rect(surf, x, y, pixel_color, drawn_area);
1547-
}
1548-
}
1549-
}
15501503

15511504
/* main line drawing loop */
15521505
for (x = x_pixel_start; x < x_pixel_end; x++) {

0 commit comments

Comments
 (0)