From dcbb2f11a8c9c7ac1a00d8bfdc7597f3ec78f2c2 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 19 Oct 2024 20:18:21 -0700
Subject: [PATCH] Clamp the texture alpha and color modulation values to 0-255
---
src/render/SDL_render.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/render/SDL_render.c b/src/render/SDL_render.c
index f96e6194e44e4..23518cbafbac6 100644
--- a/src/render/SDL_render.c
+++ b/src/render/SDL_render.c
@@ -1812,13 +1812,13 @@ bool SDL_GetTextureColorMod(SDL_Texture *texture, Uint8 *r, Uint8 *g, Uint8 *b)
}
if (r) {
- *r = (Uint8)(fR * 255.0f);
+ *r = (Uint8)SDL_roundf(SDL_clamp(fR, 0.0f, 1.0f) * 255.0f);
}
if (g) {
- *g = (Uint8)(fG * 255.0f);
+ *g = (Uint8)SDL_roundf(SDL_clamp(fG, 0.0f, 1.0f) * 255.0f);
}
if (b) {
- *b = (Uint8)(fB * 255.0f);
+ *b = (Uint8)SDL_roundf(SDL_clamp(fB, 0.0f, 1.0f) * 255.0f);
}
return true;
}
@@ -1883,7 +1883,7 @@ bool SDL_GetTextureAlphaMod(SDL_Texture *texture, Uint8 *alpha)
}
if (alpha) {
- *alpha = (Uint8)(fA * 255.0f);
+ *alpha = (Uint8)SDL_roundf(SDL_clamp(fA, 0.0f, 1.0f) * 255.0f);
}
return true;
}