Browse Source

Clamp the texture alpha and color modulation values to 0-255

Sam Lantinga 10 months ago
parent
commit
dcbb2f11a8
1 changed files with 4 additions and 4 deletions
  1. 4 4
      src/render/SDL_render.c

+ 4 - 4
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;
 }