From 414629833d9c14cb4147455e1eca880d78838030 Mon Sep 17 00:00:00 2001 From: MightyJosip Date: Mon, 6 Nov 2023 10:20:12 +0100 Subject: [PATCH 1/4] Remove blend from draw.aaline --- src_c/draw.c | 54 +++++++++++++++++++--------------------------------- 1 file changed, 20 insertions(+), 34 deletions(-) diff --git a/src_c/draw.c b/src_c/draw.c index d24f84fffd..fccf10df08 100644 --- a/src_c/draw.c +++ b/src_c/draw.c @@ -973,36 +973,23 @@ compare_int(const void *a, const void *b) static Uint32 get_antialiased_color(SDL_Surface *surf, int x, int y, Uint32 original_color, - float brightness, int blend) + float brightness) { Uint8 color_part[4], background_color[4]; Uint32 *pixels = (Uint32 *)surf->pixels; SDL_GetRGBA(original_color, surf->format, &color_part[0], &color_part[1], &color_part[2], &color_part[3]); - if (blend) { - if (x < surf->clip_rect.x || - x >= surf->clip_rect.x + surf->clip_rect.w || - y < surf->clip_rect.y || - y >= surf->clip_rect.y + surf->clip_rect.h) - return original_color; - SDL_GetRGBA(pixels[(y * surf->w) + x], surf->format, - &background_color[0], &background_color[1], - &background_color[2], &background_color[3]); - color_part[0] = (Uint8)(brightness * color_part[0] + - (1 - brightness) * background_color[0]); - color_part[1] = (Uint8)(brightness * color_part[1] + - (1 - brightness) * background_color[1]); - color_part[2] = (Uint8)(brightness * color_part[2] + - (1 - brightness) * background_color[2]); - color_part[3] = (Uint8)(brightness * color_part[3] + - (1 - brightness) * background_color[3]); - } - else { - color_part[0] = (Uint8)(brightness * color_part[0]); - color_part[1] = (Uint8)(brightness * color_part[1]); - color_part[2] = (Uint8)(brightness * color_part[2]); - color_part[3] = (Uint8)(brightness * color_part[3]); - } + SDL_GetRGBA(pixels[(y * surf->w) + x], surf->format, + &background_color[0], &background_color[1], + &background_color[2], &background_color[3]); + color_part[0] = (Uint8)(brightness * color_part[0] + + (1 - brightness) * background_color[0]); + color_part[1] = (Uint8)(brightness * color_part[1] + + (1 - brightness) * background_color[1]); + color_part[2] = (Uint8)(brightness * color_part[2] + + (1 - brightness) * background_color[2]); + color_part[3] = (Uint8)(brightness * color_part[3] + + (1 - brightness) * background_color[3]); original_color = SDL_MapRGBA(surf->format, color_part[0], color_part[1], color_part[2], color_part[3]); return original_color; @@ -1123,7 +1110,6 @@ draw_aaline(SDL_Surface *surf, Uint32 color, float from_x, float from_y, Uint32 pixel_color; float x_gap, y_endpoint, clip_left, clip_right, clip_top, clip_bottom; int steep, y; - int blend = 1; dx = to_x - from_x; dy = to_y - from_y; @@ -1133,7 +1119,7 @@ draw_aaline(SDL_Surface *surf, Uint32 color, float from_x, float from_y, if (fabs(dx) < 0.0001 && fabs(dy) < 0.0001) { pixel_color = get_antialiased_color(surf, (int)floor(from_x + 0.5), - (int)floor(from_y + 0.5), color, 1, blend); + (int)floor(from_y + 0.5), color, 1); set_and_check_rect(surf, (int)floor(from_x + 0.5), (int)floor(from_y + 0.5), pixel_color, drawn_area); return; @@ -1237,7 +1223,7 @@ draw_aaline(SDL_Surface *surf, Uint32 color, float from_x, float from_y, } if ((int)y_endpoint < y_endpoint) { pixel_color = get_antialiased_color(surf, x, y, color, - brightness * x_gap, blend); + brightness * x_gap); set_and_check_rect(surf, x, y, pixel_color, drawn_area); } if (steep) { @@ -1248,7 +1234,7 @@ draw_aaline(SDL_Surface *surf, Uint32 color, float from_x, float from_y, } brightness = 1 - brightness; pixel_color = get_antialiased_color(surf, x, y, color, - brightness * x_gap, blend); + brightness * x_gap); set_and_check_rect(surf, x, y, pixel_color, drawn_area); intersect_y += gradient; x_pixel_start++; @@ -1269,7 +1255,7 @@ draw_aaline(SDL_Surface *surf, Uint32 color, float from_x, float from_y, } if ((int)y_endpoint < y_endpoint) { pixel_color = get_antialiased_color(surf, x, y, color, - brightness * x_gap, blend); + brightness * x_gap); set_and_check_rect(surf, x, y, pixel_color, drawn_area); } if (steep) { @@ -1290,24 +1276,24 @@ draw_aaline(SDL_Surface *surf, Uint32 color, float from_x, float from_y, if (steep) { brightness = 1 - intersect_y + y; pixel_color = get_antialiased_color(surf, y - 1, x, color, - brightness, blend); + brightness); set_and_check_rect(surf, y - 1, x, pixel_color, drawn_area); if (y < intersect_y) { brightness = 1 - brightness; pixel_color = get_antialiased_color(surf, y, x, color, - brightness, blend); + brightness); set_and_check_rect(surf, y, x, pixel_color, drawn_area); } } else { brightness = 1 - intersect_y + y; pixel_color = get_antialiased_color(surf, x, y - 1, color, - brightness, blend); + brightness); set_and_check_rect(surf, x, y - 1, pixel_color, drawn_area); if (y < intersect_y) { brightness = 1 - brightness; pixel_color = get_antialiased_color(surf, x, y, color, - brightness, blend); + brightness); set_and_check_rect(surf, x, y, pixel_color, drawn_area); } } From 45fce7b25f01df6d17e7ad0905c05ee4ed7a739b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josip=20Komljenovi=C4=87?= Date: Mon, 6 Nov 2023 10:40:49 +0100 Subject: [PATCH 2/4] Remove blend from draw.aaline --- src_c/draw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src_c/draw.c b/src_c/draw.c index fccf10df08..b6b4dbfc0f 100644 --- a/src_c/draw.c +++ b/src_c/draw.c @@ -1266,7 +1266,7 @@ draw_aaline(SDL_Surface *surf, Uint32 color, float from_x, float from_y, } brightness = 1 - brightness; pixel_color = get_antialiased_color(surf, x, y, color, - brightness * x_gap, blend); + brightness * x_gap); set_and_check_rect(surf, x, y, pixel_color, drawn_area); } From b91bfbc9c19c29c1c841ba50901266be10aa4450 Mon Sep 17 00:00:00 2001 From: MightyJosip Date: Mon, 6 Nov 2023 21:12:54 +0100 Subject: [PATCH 3/4] Remove blend from draw.aaline --- src_c/draw.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src_c/draw.c b/src_c/draw.c index b6b4dbfc0f..a392e44390 100644 --- a/src_c/draw.c +++ b/src_c/draw.c @@ -979,9 +979,9 @@ get_antialiased_color(SDL_Surface *surf, int x, int y, Uint32 original_color, Uint32 *pixels = (Uint32 *)surf->pixels; SDL_GetRGBA(original_color, surf->format, &color_part[0], &color_part[1], &color_part[2], &color_part[3]); - SDL_GetRGBA(pixels[(y * surf->w) + x], surf->format, - &background_color[0], &background_color[1], - &background_color[2], &background_color[3]); + SDL_GetRGBA(pixels[(y * surf->w) + x], surf->format, &background_color[0], + &background_color[1], &background_color[2], + &background_color[3]); color_part[0] = (Uint8)(brightness * color_part[0] + (1 - brightness) * background_color[0]); color_part[1] = (Uint8)(brightness * color_part[1] + @@ -1222,8 +1222,8 @@ draw_aaline(SDL_Surface *surf, Uint32 color, float from_x, float from_y, y = (int)y_endpoint; } if ((int)y_endpoint < y_endpoint) { - pixel_color = get_antialiased_color(surf, x, y, color, - brightness * x_gap); + pixel_color = + get_antialiased_color(surf, x, y, color, brightness * x_gap); set_and_check_rect(surf, x, y, pixel_color, drawn_area); } if (steep) { @@ -1233,8 +1233,8 @@ draw_aaline(SDL_Surface *surf, Uint32 color, float from_x, float from_y, y--; } brightness = 1 - brightness; - pixel_color = get_antialiased_color(surf, x, y, color, - brightness * x_gap); + pixel_color = + get_antialiased_color(surf, x, y, color, brightness * x_gap); set_and_check_rect(surf, x, y, pixel_color, drawn_area); intersect_y += gradient; x_pixel_start++; @@ -1254,8 +1254,8 @@ draw_aaline(SDL_Surface *surf, Uint32 color, float from_x, float from_y, y = (int)y_endpoint; } if ((int)y_endpoint < y_endpoint) { - pixel_color = get_antialiased_color(surf, x, y, color, - brightness * x_gap); + pixel_color = + get_antialiased_color(surf, x, y, color, brightness * x_gap); set_and_check_rect(surf, x, y, pixel_color, drawn_area); } if (steep) { @@ -1265,8 +1265,8 @@ draw_aaline(SDL_Surface *surf, Uint32 color, float from_x, float from_y, y--; } brightness = 1 - brightness; - pixel_color = get_antialiased_color(surf, x, y, color, - brightness * x_gap); + pixel_color = + get_antialiased_color(surf, x, y, color, brightness * x_gap); set_and_check_rect(surf, x, y, pixel_color, drawn_area); } @@ -1275,25 +1275,25 @@ draw_aaline(SDL_Surface *surf, Uint32 color, float from_x, float from_y, y = (int)intersect_y; if (steep) { brightness = 1 - intersect_y + y; - pixel_color = get_antialiased_color(surf, y - 1, x, color, - brightness); + pixel_color = + get_antialiased_color(surf, y - 1, x, color, brightness); set_and_check_rect(surf, y - 1, x, pixel_color, drawn_area); if (y < intersect_y) { brightness = 1 - brightness; - pixel_color = get_antialiased_color(surf, y, x, color, - brightness); + pixel_color = + get_antialiased_color(surf, y, x, color, brightness); set_and_check_rect(surf, y, x, pixel_color, drawn_area); } } else { brightness = 1 - intersect_y + y; - pixel_color = get_antialiased_color(surf, x, y - 1, color, - brightness); + pixel_color = + get_antialiased_color(surf, x, y - 1, color, brightness); set_and_check_rect(surf, x, y - 1, pixel_color, drawn_area); if (y < intersect_y) { brightness = 1 - brightness; - pixel_color = get_antialiased_color(surf, x, y, color, - brightness); + pixel_color = + get_antialiased_color(surf, x, y, color, brightness); set_and_check_rect(surf, x, y, pixel_color, drawn_area); } } From 02cf4f493b357ac78429cbe83c0e74b4cb3ffe92 Mon Sep 17 00:00:00 2001 From: MightyJosip Date: Tue, 7 Nov 2023 21:16:23 +0100 Subject: [PATCH 4/4] Remove blend from draw.aaline --- src_c/draw.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src_c/draw.c b/src_c/draw.c index a392e44390..4414dbb3b4 100644 --- a/src_c/draw.c +++ b/src_c/draw.c @@ -979,6 +979,9 @@ get_antialiased_color(SDL_Surface *surf, int x, int y, Uint32 original_color, Uint32 *pixels = (Uint32 *)surf->pixels; SDL_GetRGBA(original_color, surf->format, &color_part[0], &color_part[1], &color_part[2], &color_part[3]); + if (x < surf->clip_rect.x || x >= surf->clip_rect.x + surf->clip_rect.w || + y < surf->clip_rect.y || y >= surf->clip_rect.y + surf->clip_rect.h) + return original_color; SDL_GetRGBA(pixels[(y * surf->w) + x], surf->format, &background_color[0], &background_color[1], &background_color[2], &background_color[3]);