author Sam Lantinga Thu, 05 Jan 2017 08:16:39 -0800 changeset 10754 6285a56f6729 parent 10753 220a81177cfb child 10755 43953bdaa3ee
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 file | annotate | diff | comparison | revisions
```     1.1 --- a/src/video/SDL_blit.h	Thu Jan 05 02:53:29 2017 -0800
1.2 +++ b/src/video/SDL_blit.h	Thu Jan 05 08:16:39 2017 -0800
1.3 @@ -443,19 +443,19 @@
1.4  /* Blend the RGB values of two pixels with an alpha value */
1.5  #define ALPHA_BLEND_RGB(sR, sG, sB, A, dR, dG, dB)                      \
1.6  do {                                                                    \
1.7 -    dR = ((((unsigned)(sR-dR)*(unsigned)A)/255)+dR);                    \
1.8 -    dG = ((((unsigned)(sG-dG)*(unsigned)A)/255)+dG);                    \
1.9 -    dB = ((((unsigned)(sB-dB)*(unsigned)A)/255)+dB);                    \
1.10 +    dR = (Uint8)((((int)(sR-dR)*A)/255)+dR);                            \
1.11 +    dG = (Uint8)((((int)(sG-dG)*A)/255)+dG);                            \
1.12 +    dB = (Uint8)((((int)(sB-dB)*A)/255)+dB);                            \
1.13  } while(0)
1.14
1.15
1.16  /* Blend the RGBA values of two pixels */
1.17  #define ALPHA_BLEND_RGBA(sR, sG, sB, sA, dR, dG, dB, dA)                \
1.18  do {                                                                    \
1.19 -    dR = ((((unsigned)(sR-dR)*(unsigned)sA)/255)+dR);                   \
1.20 -    dG = ((((unsigned)(sG-dG)*(unsigned)sA)/255)+dG);                   \
1.21 -    dB = ((((unsigned)(sB-dB)*(unsigned)sA)/255)+dB);                   \
1.22 -    dA = ((unsigned)sA+(unsigned)dA-((unsigned)sA*dA)/255);             \
1.23 +    dR = (Uint8)((((int)(sR-dR)*sA)/255)+dR);                           \
1.24 +    dG = (Uint8)((((int)(sG-dG)*sA)/255)+dG);                           \
1.25 +    dB = (Uint8)((((int)(sB-dB)*sA)/255)+dB);                           \
1.26 +    dA = (Uint8)((int)sA+dA-((int)sA*dA)/255);                          \
1.27  } while(0)
1.28
1.29
```