From 1b99895d81a0163c5c5a1f8fe366283b7e3ce0f7 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 26 Sep 2024 22:28:21 -0700
Subject: [PATCH] Use the real alpha value passed in for foreground and
background colors
Fixes https://github.com/libsdl-org/SDL_ttf/issues/271
---
examples/glfont.c | 4 ++--
examples/showfont.c | 8 ++++----
src/SDL_ttf.c | 20 +-------------------
3 files changed, 7 insertions(+), 25 deletions(-)
diff --git a/examples/glfont.c b/examples/glfont.c
index e8c9d339..b017c880 100644
--- a/examples/glfont.c
+++ b/examples/glfont.c
@@ -169,8 +169,8 @@ int main(int argc, char *argv[])
SDL_Surface *text = NULL;
int ptsize;
int i, done;
- SDL_Color white = { 0xFF, 0xFF, 0xFF, 0 };
- SDL_Color black = { 0x00, 0x00, 0x00, 0 };
+ SDL_Color white = { 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE };
+ SDL_Color black = { 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE };
SDL_Color *forecol;
SDL_Color *backcol;
GLenum gl_error;
diff --git a/examples/showfont.c b/examples/showfont.c
index 64f6eed0..6e6e4f8e 100644
--- a/examples/showfont.c
+++ b/examples/showfont.c
@@ -79,8 +79,8 @@ int main(int argc, char *argv[])
Scene scene;
int ptsize;
int i, done;
- SDL_Color white = { 0xFF, 0xFF, 0xFF, 0 };
- SDL_Color black = { 0x00, 0x00, 0x00, 0 };
+ SDL_Color white = { 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE };
+ SDL_Color black = { 0x00, 0x00, 0x00, SDL_ALPHA_OPAQUE };
SDL_Color *forecol;
SDL_Color *backcol;
SDL_Event event;
@@ -151,7 +151,7 @@ int main(int argc, char *argv[])
dump = 1;
} else
if (SDL_strcmp(argv[i], "-fgcol") == 0) {
- int r, g, b, a = 0xFF;
+ int r, g, b, a = SDL_ALPHA_OPAQUE;
if (SDL_sscanf(argv[++i], "%d,%d,%d,%d", &r, &g, &b, &a) < 3) {
SDL_Log(TTF_SHOWFONT_USAGE, argv0);
return(1);
@@ -162,7 +162,7 @@ int main(int argc, char *argv[])
forecol->a = (Uint8)a;
} else
if (SDL_strcmp(argv[i], "-bgcol") == 0) {
- int r, g, b, a = 0xFF;
+ int r, g, b, a = SDL_ALPHA_OPAQUE;
if (SDL_sscanf(argv[++i], "%d,%d,%d,%d", &r, &g, &b, &a) < 3) {
SDL_Log(TTF_SHOWFONT_USAGE, argv0);
return(1);
diff --git a/src/SDL_ttf.c b/src/SDL_ttf.c
index 42100ee7..0bb24b91 100644
--- a/src/SDL_ttf.c
+++ b/src/SDL_ttf.c
@@ -379,7 +379,7 @@ static void BG_Blended_Color(const TTF_Image *image, Uint32 *destination, Sint32
Uint32 width = image->width;
Uint32 height = image->rows;
- if (fg_alpha == 0) { /* SDL_ALPHA_OPAQUE */
+ if (fg_alpha == SDL_ALPHA_OPAQUE) {
while (height--) {
/* *INDENT-OFF* */
DUFFS_LOOP4(
@@ -1571,11 +1571,6 @@ static SDL_Surface *Create_Surface_Blended(int width, int height, SDL_Color fg,
if (textbuf == NULL) {
return NULL;
}
-
- /* Support alpha blending */
- if (fg.a != SDL_ALPHA_OPAQUE) {
- SDL_SetSurfaceBlendMode(textbuf, SDL_BLENDMODE_BLEND);
- }
}
return textbuf;
@@ -1598,11 +1593,6 @@ static SDL_Surface* Create_Surface_LCD(int width, int height, SDL_Color fg, SDL_
if (textbuf == NULL) {
return NULL;
}
-
- /* Support alpha blending */
- if (bg.a != SDL_ALPHA_OPAQUE) {
- SDL_SetSurfaceBlendMode(textbuf, SDL_BLENDMODE_BLEND);
- }
}
return textbuf;
@@ -3292,10 +3282,6 @@ static SDL_Surface* TTF_Render_Internal(TTF_Font *font, const char *text, size_t
goto failure;
}
- /* Support alpha blending */
- fg.a = fg.a ? fg.a : SDL_ALPHA_OPAQUE;
- bg.a = bg.a ? bg.a : SDL_ALPHA_OPAQUE;
-
/* Create surface for rendering */
if (render_mode == RENDER_SOLID) {
textbuf = Create_Surface_Solid(width, height, fg, &color);
@@ -3582,10 +3568,6 @@ static SDL_Surface* TTF_Render_Wrapped_Internal(TTF_Font *font, const char *text
}
height = rowHeight + lineskip * (numLines - 1);
- /* Support alpha blending */
- fg.a = fg.a ? fg.a : SDL_ALPHA_OPAQUE;
- bg.a = bg.a ? bg.a : SDL_ALPHA_OPAQUE;
-
/* Create surface for rendering */
if (render_mode == RENDER_SOLID) {
textbuf = Create_Surface_Solid(width, height, fg, &color);