From d024c724d10c2e77d08fe473260bf38759ed1cf8 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Thu, 5 Jan 2017 08:16:39 -0800 Subject: [PATCH] Fixed signedness issue when blitting on a big endian platform, as reported by capehill For example, if sR is 0 and dR is 255, we will get -255*sA casted to an unsigned value. Basically results are quite large numbers instead of the expected 0-255 range. --- src/video/SDL_blit.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/video/SDL_blit.h b/src/video/SDL_blit.h index a4c0f4b1c..ad705d1fe 100644 --- a/src/video/SDL_blit.h +++ b/src/video/SDL_blit.h @@ -443,19 +443,19 @@ do { \ /* Blend the RGB values of two pixels with an alpha value */ #define ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB) \ do { \ - dR = ((((unsigned)(sR-dR)*(unsigned)A)/255)+dR); \ - dG = ((((unsigned)(sG-dG)*(unsigned)A)/255)+dG); \ - dB = ((((unsigned)(sB-dB)*(unsigned)A)/255)+dB); \ + dR = (Uint8)((((int)(sR-dR)*A)/255)+dR); \ + dG = (Uint8)((((int)(sG-dG)*A)/255)+dG); \ + dB = (Uint8)((((int)(sB-dB)*A)/255)+dB); \ } while(0) /* Blend the RGBA values of two pixels */ #define ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA) \ do { \ - dR = ((((unsigned)(sR-dR)*(unsigned)sA)/255)+dR); \ - dG = ((((unsigned)(sG-dG)*(unsigned)sA)/255)+dG); \ - dB = ((((unsigned)(sB-dB)*(unsigned)sA)/255)+dB); \ - dA = ((unsigned)sA+(unsigned)dA-((unsigned)sA*dA)/255); \ + dR = (Uint8)((((int)(sR-dR)*sA)/255)+dR); \ + dG = (Uint8)((((int)(sG-dG)*sA)/255)+dG); \ + dB = (Uint8)((((int)(sB-dB)*sA)/255)+dB); \ + dA = (Uint8)((int)sA+dA-((int)sA*dA)/255); \ } while(0)