Optimized the copy blitters a little bit
authorSam Lantinga
Mon, 28 Aug 2006 14:10:46 +0000
changeset 19895b5f5de5433f
parent 1988 1ee02169bbb0
child 1990 7b573c59cb1f
Optimized the copy blitters a little bit
src/video/SDL_rendercopy.c
src/video/SDL_rendercopy.h
src/video/SDL_renderer_sw.c
src/video/sdlgenblit.pl
     1.1 --- a/src/video/SDL_rendercopy.c	Mon Aug 28 04:39:37 2006 +0000
     1.2 +++ b/src/video/SDL_rendercopy.c	Mon Aug 28 14:10:46 2006 +0000
     1.3 @@ -215,11 +215,20 @@
     1.4              dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
     1.5              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
     1.6                  /* This goes away if we ever use premultiplied alpha */
     1.7 -                srcR = (srcR * srcA) / 255;
     1.8 -                srcG = (srcG * srcA) / 255;
     1.9 -                srcB = (srcB * srcA) / 255;
    1.10 -            }
    1.11 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
    1.12 +                if (srcA < 255) {
    1.13 +                    srcR = (srcR * srcA) / 255;
    1.14 +                    srcG = (srcG * srcA) / 255;
    1.15 +                    srcB = (srcB * srcA) / 255;
    1.16 +                }
    1.17 +            }
    1.18 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
    1.19 +            case SDL_RENDERCOPY_MASK:
    1.20 +                if (srcA) {
    1.21 +                    dstR = srcR;
    1.22 +                    dstG = srcG;
    1.23 +                    dstB = srcB;
    1.24 +                }
    1.25 +                break;
    1.26              case SDL_RENDERCOPY_BLEND:
    1.27                  dstR = srcR + ((255 - srcA) * dstR) / 255;
    1.28                  dstG = srcG + ((255 - srcA) * dstG) / 255;
    1.29 @@ -287,11 +296,20 @@
    1.30              dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
    1.31              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
    1.32                  /* This goes away if we ever use premultiplied alpha */
    1.33 -                srcR = (srcR * srcA) / 255;
    1.34 -                srcG = (srcG * srcA) / 255;
    1.35 -                srcB = (srcB * srcA) / 255;
    1.36 -            }
    1.37 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
    1.38 +                if (srcA < 255) {
    1.39 +                    srcR = (srcR * srcA) / 255;
    1.40 +                    srcG = (srcG * srcA) / 255;
    1.41 +                    srcB = (srcB * srcA) / 255;
    1.42 +                }
    1.43 +            }
    1.44 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
    1.45 +            case SDL_RENDERCOPY_MASK:
    1.46 +                if (srcA) {
    1.47 +                    dstR = srcR;
    1.48 +                    dstG = srcG;
    1.49 +                    dstB = srcB;
    1.50 +                }
    1.51 +                break;
    1.52              case SDL_RENDERCOPY_BLEND:
    1.53                  dstR = srcR + ((255 - srcA) * dstR) / 255;
    1.54                  dstG = srcG + ((255 - srcA) * dstG) / 255;
    1.55 @@ -341,6 +359,9 @@
    1.56                  G = (G * modulateG) / 255;
    1.57                  B = (B * modulateB) / 255;
    1.58              }
    1.59 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
    1.60 +                A = (A * modulateA) / 255;
    1.61 +            }
    1.62              pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
    1.63              *dst = pixel;
    1.64              ++src;
    1.65 @@ -395,6 +416,9 @@
    1.66                  G = (G * modulateG) / 255;
    1.67                  B = (B * modulateB) / 255;
    1.68              }
    1.69 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
    1.70 +                A = (A * modulateA) / 255;
    1.71 +            }
    1.72              pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
    1.73              *dst = pixel;
    1.74              posx += incx;
    1.75 @@ -437,11 +461,20 @@
    1.76              }
    1.77              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
    1.78                  /* This goes away if we ever use premultiplied alpha */
    1.79 -                srcR = (srcR * srcA) / 255;
    1.80 -                srcG = (srcG * srcA) / 255;
    1.81 -                srcB = (srcB * srcA) / 255;
    1.82 -            }
    1.83 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
    1.84 +                if (srcA < 255) {
    1.85 +                    srcR = (srcR * srcA) / 255;
    1.86 +                    srcG = (srcG * srcA) / 255;
    1.87 +                    srcB = (srcB * srcA) / 255;
    1.88 +                }
    1.89 +            }
    1.90 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
    1.91 +            case SDL_RENDERCOPY_MASK:
    1.92 +                if (srcA) {
    1.93 +                    dstR = srcR;
    1.94 +                    dstG = srcG;
    1.95 +                    dstB = srcB;
    1.96 +                }
    1.97 +                break;
    1.98              case SDL_RENDERCOPY_BLEND:
    1.99                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.100                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.101 @@ -521,11 +554,20 @@
   1.102              }
   1.103              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.104                  /* This goes away if we ever use premultiplied alpha */
   1.105 -                srcR = (srcR * srcA) / 255;
   1.106 -                srcG = (srcG * srcA) / 255;
   1.107 -                srcB = (srcB * srcA) / 255;
   1.108 -            }
   1.109 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.110 +                if (srcA < 255) {
   1.111 +                    srcR = (srcR * srcA) / 255;
   1.112 +                    srcG = (srcG * srcA) / 255;
   1.113 +                    srcB = (srcB * srcA) / 255;
   1.114 +                }
   1.115 +            }
   1.116 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.117 +            case SDL_RENDERCOPY_MASK:
   1.118 +                if (srcA) {
   1.119 +                    dstR = srcR;
   1.120 +                    dstG = srcG;
   1.121 +                    dstB = srcB;
   1.122 +                }
   1.123 +                break;
   1.124              case SDL_RENDERCOPY_BLEND:
   1.125                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.126                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.127 @@ -641,11 +683,20 @@
   1.128              dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
   1.129              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.130                  /* This goes away if we ever use premultiplied alpha */
   1.131 -                srcR = (srcR * srcA) / 255;
   1.132 -                srcG = (srcG * srcA) / 255;
   1.133 -                srcB = (srcB * srcA) / 255;
   1.134 -            }
   1.135 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.136 +                if (srcA < 255) {
   1.137 +                    srcR = (srcR * srcA) / 255;
   1.138 +                    srcG = (srcG * srcA) / 255;
   1.139 +                    srcB = (srcB * srcA) / 255;
   1.140 +                }
   1.141 +            }
   1.142 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.143 +            case SDL_RENDERCOPY_MASK:
   1.144 +                if (srcA) {
   1.145 +                    dstR = srcR;
   1.146 +                    dstG = srcG;
   1.147 +                    dstB = srcB;
   1.148 +                }
   1.149 +                break;
   1.150              case SDL_RENDERCOPY_BLEND:
   1.151                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.152                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.153 @@ -713,11 +764,20 @@
   1.154              dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
   1.155              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.156                  /* This goes away if we ever use premultiplied alpha */
   1.157 -                srcR = (srcR * srcA) / 255;
   1.158 -                srcG = (srcG * srcA) / 255;
   1.159 -                srcB = (srcB * srcA) / 255;
   1.160 -            }
   1.161 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.162 +                if (srcA < 255) {
   1.163 +                    srcR = (srcR * srcA) / 255;
   1.164 +                    srcG = (srcG * srcA) / 255;
   1.165 +                    srcB = (srcB * srcA) / 255;
   1.166 +                }
   1.167 +            }
   1.168 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.169 +            case SDL_RENDERCOPY_MASK:
   1.170 +                if (srcA) {
   1.171 +                    dstR = srcR;
   1.172 +                    dstG = srcG;
   1.173 +                    dstB = srcB;
   1.174 +                }
   1.175 +                break;
   1.176              case SDL_RENDERCOPY_BLEND:
   1.177                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.178                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.179 @@ -767,6 +827,9 @@
   1.180                  G = (G * modulateG) / 255;
   1.181                  B = (B * modulateB) / 255;
   1.182              }
   1.183 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
   1.184 +                A = (A * modulateA) / 255;
   1.185 +            }
   1.186              pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
   1.187              *dst = pixel;
   1.188              ++src;
   1.189 @@ -821,6 +884,9 @@
   1.190                  G = (G * modulateG) / 255;
   1.191                  B = (B * modulateB) / 255;
   1.192              }
   1.193 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
   1.194 +                A = (A * modulateA) / 255;
   1.195 +            }
   1.196              pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
   1.197              *dst = pixel;
   1.198              posx += incx;
   1.199 @@ -863,11 +929,20 @@
   1.200              }
   1.201              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.202                  /* This goes away if we ever use premultiplied alpha */
   1.203 -                srcR = (srcR * srcA) / 255;
   1.204 -                srcG = (srcG * srcA) / 255;
   1.205 -                srcB = (srcB * srcA) / 255;
   1.206 -            }
   1.207 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.208 +                if (srcA < 255) {
   1.209 +                    srcR = (srcR * srcA) / 255;
   1.210 +                    srcG = (srcG * srcA) / 255;
   1.211 +                    srcB = (srcB * srcA) / 255;
   1.212 +                }
   1.213 +            }
   1.214 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.215 +            case SDL_RENDERCOPY_MASK:
   1.216 +                if (srcA) {
   1.217 +                    dstR = srcR;
   1.218 +                    dstG = srcG;
   1.219 +                    dstB = srcB;
   1.220 +                }
   1.221 +                break;
   1.222              case SDL_RENDERCOPY_BLEND:
   1.223                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.224                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.225 @@ -947,11 +1022,20 @@
   1.226              }
   1.227              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.228                  /* This goes away if we ever use premultiplied alpha */
   1.229 -                srcR = (srcR * srcA) / 255;
   1.230 -                srcG = (srcG * srcA) / 255;
   1.231 -                srcB = (srcB * srcA) / 255;
   1.232 -            }
   1.233 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.234 +                if (srcA < 255) {
   1.235 +                    srcR = (srcR * srcA) / 255;
   1.236 +                    srcG = (srcG * srcA) / 255;
   1.237 +                    srcB = (srcB * srcA) / 255;
   1.238 +                }
   1.239 +            }
   1.240 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.241 +            case SDL_RENDERCOPY_MASK:
   1.242 +                if (srcA) {
   1.243 +                    dstR = srcR;
   1.244 +                    dstG = srcG;
   1.245 +                    dstB = srcB;
   1.246 +                }
   1.247 +                break;
   1.248              case SDL_RENDERCOPY_BLEND:
   1.249                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.250                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.251 @@ -1067,11 +1151,20 @@
   1.252              dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
   1.253              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.254                  /* This goes away if we ever use premultiplied alpha */
   1.255 -                srcR = (srcR * srcA) / 255;
   1.256 -                srcG = (srcG * srcA) / 255;
   1.257 -                srcB = (srcB * srcA) / 255;
   1.258 -            }
   1.259 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.260 +                if (srcA < 255) {
   1.261 +                    srcR = (srcR * srcA) / 255;
   1.262 +                    srcG = (srcG * srcA) / 255;
   1.263 +                    srcB = (srcB * srcA) / 255;
   1.264 +                }
   1.265 +            }
   1.266 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.267 +            case SDL_RENDERCOPY_MASK:
   1.268 +                if (srcA) {
   1.269 +                    dstR = srcR;
   1.270 +                    dstG = srcG;
   1.271 +                    dstB = srcB;
   1.272 +                }
   1.273 +                break;
   1.274              case SDL_RENDERCOPY_BLEND:
   1.275                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.276                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.277 @@ -1139,11 +1232,20 @@
   1.278              dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
   1.279              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.280                  /* This goes away if we ever use premultiplied alpha */
   1.281 -                srcR = (srcR * srcA) / 255;
   1.282 -                srcG = (srcG * srcA) / 255;
   1.283 -                srcB = (srcB * srcA) / 255;
   1.284 -            }
   1.285 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.286 +                if (srcA < 255) {
   1.287 +                    srcR = (srcR * srcA) / 255;
   1.288 +                    srcG = (srcG * srcA) / 255;
   1.289 +                    srcB = (srcB * srcA) / 255;
   1.290 +                }
   1.291 +            }
   1.292 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.293 +            case SDL_RENDERCOPY_MASK:
   1.294 +                if (srcA) {
   1.295 +                    dstR = srcR;
   1.296 +                    dstG = srcG;
   1.297 +                    dstB = srcB;
   1.298 +                }
   1.299 +                break;
   1.300              case SDL_RENDERCOPY_BLEND:
   1.301                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.302                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.303 @@ -1193,6 +1295,9 @@
   1.304                  G = (G * modulateG) / 255;
   1.305                  B = (B * modulateB) / 255;
   1.306              }
   1.307 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
   1.308 +                A = (A * modulateA) / 255;
   1.309 +            }
   1.310              pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
   1.311              *dst = pixel;
   1.312              ++src;
   1.313 @@ -1247,6 +1352,9 @@
   1.314                  G = (G * modulateG) / 255;
   1.315                  B = (B * modulateB) / 255;
   1.316              }
   1.317 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
   1.318 +                A = (A * modulateA) / 255;
   1.319 +            }
   1.320              pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
   1.321              *dst = pixel;
   1.322              posx += incx;
   1.323 @@ -1289,11 +1397,20 @@
   1.324              }
   1.325              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.326                  /* This goes away if we ever use premultiplied alpha */
   1.327 -                srcR = (srcR * srcA) / 255;
   1.328 -                srcG = (srcG * srcA) / 255;
   1.329 -                srcB = (srcB * srcA) / 255;
   1.330 -            }
   1.331 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.332 +                if (srcA < 255) {
   1.333 +                    srcR = (srcR * srcA) / 255;
   1.334 +                    srcG = (srcG * srcA) / 255;
   1.335 +                    srcB = (srcB * srcA) / 255;
   1.336 +                }
   1.337 +            }
   1.338 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.339 +            case SDL_RENDERCOPY_MASK:
   1.340 +                if (srcA) {
   1.341 +                    dstR = srcR;
   1.342 +                    dstG = srcG;
   1.343 +                    dstB = srcB;
   1.344 +                }
   1.345 +                break;
   1.346              case SDL_RENDERCOPY_BLEND:
   1.347                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.348                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.349 @@ -1373,11 +1490,20 @@
   1.350              }
   1.351              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.352                  /* This goes away if we ever use premultiplied alpha */
   1.353 -                srcR = (srcR * srcA) / 255;
   1.354 -                srcG = (srcG * srcA) / 255;
   1.355 -                srcB = (srcB * srcA) / 255;
   1.356 -            }
   1.357 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.358 +                if (srcA < 255) {
   1.359 +                    srcR = (srcR * srcA) / 255;
   1.360 +                    srcG = (srcG * srcA) / 255;
   1.361 +                    srcB = (srcB * srcA) / 255;
   1.362 +                }
   1.363 +            }
   1.364 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.365 +            case SDL_RENDERCOPY_MASK:
   1.366 +                if (srcA) {
   1.367 +                    dstR = srcR;
   1.368 +                    dstG = srcG;
   1.369 +                    dstB = srcB;
   1.370 +                }
   1.371 +                break;
   1.372              case SDL_RENDERCOPY_BLEND:
   1.373                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.374                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.375 @@ -1464,11 +1590,20 @@
   1.376              dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
   1.377              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.378                  /* This goes away if we ever use premultiplied alpha */
   1.379 -                srcR = (srcR * srcA) / 255;
   1.380 -                srcG = (srcG * srcA) / 255;
   1.381 -                srcB = (srcB * srcA) / 255;
   1.382 -            }
   1.383 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.384 +                if (srcA < 255) {
   1.385 +                    srcR = (srcR * srcA) / 255;
   1.386 +                    srcG = (srcG * srcA) / 255;
   1.387 +                    srcB = (srcB * srcA) / 255;
   1.388 +                }
   1.389 +            }
   1.390 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.391 +            case SDL_RENDERCOPY_MASK:
   1.392 +                if (srcA) {
   1.393 +                    dstR = srcR;
   1.394 +                    dstG = srcG;
   1.395 +                    dstB = srcB;
   1.396 +                }
   1.397 +                break;
   1.398              case SDL_RENDERCOPY_BLEND:
   1.399                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.400                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.401 @@ -1536,11 +1671,20 @@
   1.402              dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
   1.403              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.404                  /* This goes away if we ever use premultiplied alpha */
   1.405 -                srcR = (srcR * srcA) / 255;
   1.406 -                srcG = (srcG * srcA) / 255;
   1.407 -                srcB = (srcB * srcA) / 255;
   1.408 -            }
   1.409 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.410 +                if (srcA < 255) {
   1.411 +                    srcR = (srcR * srcA) / 255;
   1.412 +                    srcG = (srcG * srcA) / 255;
   1.413 +                    srcB = (srcB * srcA) / 255;
   1.414 +                }
   1.415 +            }
   1.416 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.417 +            case SDL_RENDERCOPY_MASK:
   1.418 +                if (srcA) {
   1.419 +                    dstR = srcR;
   1.420 +                    dstG = srcG;
   1.421 +                    dstB = srcB;
   1.422 +                }
   1.423 +                break;
   1.424              case SDL_RENDERCOPY_BLEND:
   1.425                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.426                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.427 @@ -1590,6 +1734,9 @@
   1.428                  G = (G * modulateG) / 255;
   1.429                  B = (B * modulateB) / 255;
   1.430              }
   1.431 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
   1.432 +                A = (A * modulateA) / 255;
   1.433 +            }
   1.434              pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
   1.435              *dst = pixel;
   1.436              ++src;
   1.437 @@ -1644,6 +1791,9 @@
   1.438                  G = (G * modulateG) / 255;
   1.439                  B = (B * modulateB) / 255;
   1.440              }
   1.441 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
   1.442 +                A = (A * modulateA) / 255;
   1.443 +            }
   1.444              pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
   1.445              *dst = pixel;
   1.446              posx += incx;
   1.447 @@ -1686,11 +1836,20 @@
   1.448              }
   1.449              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.450                  /* This goes away if we ever use premultiplied alpha */
   1.451 -                srcR = (srcR * srcA) / 255;
   1.452 -                srcG = (srcG * srcA) / 255;
   1.453 -                srcB = (srcB * srcA) / 255;
   1.454 -            }
   1.455 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.456 +                if (srcA < 255) {
   1.457 +                    srcR = (srcR * srcA) / 255;
   1.458 +                    srcG = (srcG * srcA) / 255;
   1.459 +                    srcB = (srcB * srcA) / 255;
   1.460 +                }
   1.461 +            }
   1.462 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.463 +            case SDL_RENDERCOPY_MASK:
   1.464 +                if (srcA) {
   1.465 +                    dstR = srcR;
   1.466 +                    dstG = srcG;
   1.467 +                    dstB = srcB;
   1.468 +                }
   1.469 +                break;
   1.470              case SDL_RENDERCOPY_BLEND:
   1.471                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.472                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.473 @@ -1770,11 +1929,20 @@
   1.474              }
   1.475              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.476                  /* This goes away if we ever use premultiplied alpha */
   1.477 -                srcR = (srcR * srcA) / 255;
   1.478 -                srcG = (srcG * srcA) / 255;
   1.479 -                srcB = (srcB * srcA) / 255;
   1.480 -            }
   1.481 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.482 +                if (srcA < 255) {
   1.483 +                    srcR = (srcR * srcA) / 255;
   1.484 +                    srcG = (srcG * srcA) / 255;
   1.485 +                    srcB = (srcB * srcA) / 255;
   1.486 +                }
   1.487 +            }
   1.488 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.489 +            case SDL_RENDERCOPY_MASK:
   1.490 +                if (srcA) {
   1.491 +                    dstR = srcR;
   1.492 +                    dstG = srcG;
   1.493 +                    dstB = srcB;
   1.494 +                }
   1.495 +                break;
   1.496              case SDL_RENDERCOPY_BLEND:
   1.497                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.498                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.499 @@ -1890,11 +2058,20 @@
   1.500              dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
   1.501              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.502                  /* This goes away if we ever use premultiplied alpha */
   1.503 -                srcR = (srcR * srcA) / 255;
   1.504 -                srcG = (srcG * srcA) / 255;
   1.505 -                srcB = (srcB * srcA) / 255;
   1.506 -            }
   1.507 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.508 +                if (srcA < 255) {
   1.509 +                    srcR = (srcR * srcA) / 255;
   1.510 +                    srcG = (srcG * srcA) / 255;
   1.511 +                    srcB = (srcB * srcA) / 255;
   1.512 +                }
   1.513 +            }
   1.514 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.515 +            case SDL_RENDERCOPY_MASK:
   1.516 +                if (srcA) {
   1.517 +                    dstR = srcR;
   1.518 +                    dstG = srcG;
   1.519 +                    dstB = srcB;
   1.520 +                }
   1.521 +                break;
   1.522              case SDL_RENDERCOPY_BLEND:
   1.523                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.524                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.525 @@ -1962,11 +2139,20 @@
   1.526              dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
   1.527              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.528                  /* This goes away if we ever use premultiplied alpha */
   1.529 -                srcR = (srcR * srcA) / 255;
   1.530 -                srcG = (srcG * srcA) / 255;
   1.531 -                srcB = (srcB * srcA) / 255;
   1.532 -            }
   1.533 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.534 +                if (srcA < 255) {
   1.535 +                    srcR = (srcR * srcA) / 255;
   1.536 +                    srcG = (srcG * srcA) / 255;
   1.537 +                    srcB = (srcB * srcA) / 255;
   1.538 +                }
   1.539 +            }
   1.540 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.541 +            case SDL_RENDERCOPY_MASK:
   1.542 +                if (srcA) {
   1.543 +                    dstR = srcR;
   1.544 +                    dstG = srcG;
   1.545 +                    dstB = srcB;
   1.546 +                }
   1.547 +                break;
   1.548              case SDL_RENDERCOPY_BLEND:
   1.549                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.550                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.551 @@ -2016,6 +2202,9 @@
   1.552                  G = (G * modulateG) / 255;
   1.553                  B = (B * modulateB) / 255;
   1.554              }
   1.555 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
   1.556 +                A = (A * modulateA) / 255;
   1.557 +            }
   1.558              pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
   1.559              *dst = pixel;
   1.560              ++src;
   1.561 @@ -2070,6 +2259,9 @@
   1.562                  G = (G * modulateG) / 255;
   1.563                  B = (B * modulateB) / 255;
   1.564              }
   1.565 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
   1.566 +                A = (A * modulateA) / 255;
   1.567 +            }
   1.568              pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
   1.569              *dst = pixel;
   1.570              posx += incx;
   1.571 @@ -2112,11 +2304,20 @@
   1.572              }
   1.573              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.574                  /* This goes away if we ever use premultiplied alpha */
   1.575 -                srcR = (srcR * srcA) / 255;
   1.576 -                srcG = (srcG * srcA) / 255;
   1.577 -                srcB = (srcB * srcA) / 255;
   1.578 -            }
   1.579 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.580 +                if (srcA < 255) {
   1.581 +                    srcR = (srcR * srcA) / 255;
   1.582 +                    srcG = (srcG * srcA) / 255;
   1.583 +                    srcB = (srcB * srcA) / 255;
   1.584 +                }
   1.585 +            }
   1.586 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.587 +            case SDL_RENDERCOPY_MASK:
   1.588 +                if (srcA) {
   1.589 +                    dstR = srcR;
   1.590 +                    dstG = srcG;
   1.591 +                    dstB = srcB;
   1.592 +                }
   1.593 +                break;
   1.594              case SDL_RENDERCOPY_BLEND:
   1.595                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.596                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.597 @@ -2196,11 +2397,20 @@
   1.598              }
   1.599              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.600                  /* This goes away if we ever use premultiplied alpha */
   1.601 -                srcR = (srcR * srcA) / 255;
   1.602 -                srcG = (srcG * srcA) / 255;
   1.603 -                srcB = (srcB * srcA) / 255;
   1.604 -            }
   1.605 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.606 +                if (srcA < 255) {
   1.607 +                    srcR = (srcR * srcA) / 255;
   1.608 +                    srcG = (srcG * srcA) / 255;
   1.609 +                    srcB = (srcB * srcA) / 255;
   1.610 +                }
   1.611 +            }
   1.612 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.613 +            case SDL_RENDERCOPY_MASK:
   1.614 +                if (srcA) {
   1.615 +                    dstR = srcR;
   1.616 +                    dstG = srcG;
   1.617 +                    dstB = srcB;
   1.618 +                }
   1.619 +                break;
   1.620              case SDL_RENDERCOPY_BLEND:
   1.621                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.622                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.623 @@ -2316,11 +2526,20 @@
   1.624              dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
   1.625              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.626                  /* This goes away if we ever use premultiplied alpha */
   1.627 -                srcR = (srcR * srcA) / 255;
   1.628 -                srcG = (srcG * srcA) / 255;
   1.629 -                srcB = (srcB * srcA) / 255;
   1.630 -            }
   1.631 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.632 +                if (srcA < 255) {
   1.633 +                    srcR = (srcR * srcA) / 255;
   1.634 +                    srcG = (srcG * srcA) / 255;
   1.635 +                    srcB = (srcB * srcA) / 255;
   1.636 +                }
   1.637 +            }
   1.638 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.639 +            case SDL_RENDERCOPY_MASK:
   1.640 +                if (srcA) {
   1.641 +                    dstR = srcR;
   1.642 +                    dstG = srcG;
   1.643 +                    dstB = srcB;
   1.644 +                }
   1.645 +                break;
   1.646              case SDL_RENDERCOPY_BLEND:
   1.647                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.648                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.649 @@ -2388,11 +2607,20 @@
   1.650              dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
   1.651              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.652                  /* This goes away if we ever use premultiplied alpha */
   1.653 -                srcR = (srcR * srcA) / 255;
   1.654 -                srcG = (srcG * srcA) / 255;
   1.655 -                srcB = (srcB * srcA) / 255;
   1.656 -            }
   1.657 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.658 +                if (srcA < 255) {
   1.659 +                    srcR = (srcR * srcA) / 255;
   1.660 +                    srcG = (srcG * srcA) / 255;
   1.661 +                    srcB = (srcB * srcA) / 255;
   1.662 +                }
   1.663 +            }
   1.664 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.665 +            case SDL_RENDERCOPY_MASK:
   1.666 +                if (srcA) {
   1.667 +                    dstR = srcR;
   1.668 +                    dstG = srcG;
   1.669 +                    dstB = srcB;
   1.670 +                }
   1.671 +                break;
   1.672              case SDL_RENDERCOPY_BLEND:
   1.673                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.674                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.675 @@ -2442,6 +2670,9 @@
   1.676                  G = (G * modulateG) / 255;
   1.677                  B = (B * modulateB) / 255;
   1.678              }
   1.679 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
   1.680 +                A = (A * modulateA) / 255;
   1.681 +            }
   1.682              pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
   1.683              *dst = pixel;
   1.684              ++src;
   1.685 @@ -2496,6 +2727,9 @@
   1.686                  G = (G * modulateG) / 255;
   1.687                  B = (B * modulateB) / 255;
   1.688              }
   1.689 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
   1.690 +                A = (A * modulateA) / 255;
   1.691 +            }
   1.692              pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
   1.693              *dst = pixel;
   1.694              posx += incx;
   1.695 @@ -2538,11 +2772,20 @@
   1.696              }
   1.697              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.698                  /* This goes away if we ever use premultiplied alpha */
   1.699 -                srcR = (srcR * srcA) / 255;
   1.700 -                srcG = (srcG * srcA) / 255;
   1.701 -                srcB = (srcB * srcA) / 255;
   1.702 -            }
   1.703 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.704 +                if (srcA < 255) {
   1.705 +                    srcR = (srcR * srcA) / 255;
   1.706 +                    srcG = (srcG * srcA) / 255;
   1.707 +                    srcB = (srcB * srcA) / 255;
   1.708 +                }
   1.709 +            }
   1.710 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.711 +            case SDL_RENDERCOPY_MASK:
   1.712 +                if (srcA) {
   1.713 +                    dstR = srcR;
   1.714 +                    dstG = srcG;
   1.715 +                    dstB = srcB;
   1.716 +                }
   1.717 +                break;
   1.718              case SDL_RENDERCOPY_BLEND:
   1.719                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.720                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.721 @@ -2622,11 +2865,20 @@
   1.722              }
   1.723              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.724                  /* This goes away if we ever use premultiplied alpha */
   1.725 -                srcR = (srcR * srcA) / 255;
   1.726 -                srcG = (srcG * srcA) / 255;
   1.727 -                srcB = (srcB * srcA) / 255;
   1.728 -            }
   1.729 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.730 +                if (srcA < 255) {
   1.731 +                    srcR = (srcR * srcA) / 255;
   1.732 +                    srcG = (srcG * srcA) / 255;
   1.733 +                    srcB = (srcB * srcA) / 255;
   1.734 +                }
   1.735 +            }
   1.736 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.737 +            case SDL_RENDERCOPY_MASK:
   1.738 +                if (srcA) {
   1.739 +                    dstR = srcR;
   1.740 +                    dstG = srcG;
   1.741 +                    dstB = srcB;
   1.742 +                }
   1.743 +                break;
   1.744              case SDL_RENDERCOPY_BLEND:
   1.745                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.746                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.747 @@ -2742,11 +2994,20 @@
   1.748              dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
   1.749              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.750                  /* This goes away if we ever use premultiplied alpha */
   1.751 -                srcR = (srcR * srcA) / 255;
   1.752 -                srcG = (srcG * srcA) / 255;
   1.753 -                srcB = (srcB * srcA) / 255;
   1.754 -            }
   1.755 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.756 +                if (srcA < 255) {
   1.757 +                    srcR = (srcR * srcA) / 255;
   1.758 +                    srcG = (srcG * srcA) / 255;
   1.759 +                    srcB = (srcB * srcA) / 255;
   1.760 +                }
   1.761 +            }
   1.762 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.763 +            case SDL_RENDERCOPY_MASK:
   1.764 +                if (srcA) {
   1.765 +                    dstR = srcR;
   1.766 +                    dstG = srcG;
   1.767 +                    dstB = srcB;
   1.768 +                }
   1.769 +                break;
   1.770              case SDL_RENDERCOPY_BLEND:
   1.771                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.772                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.773 @@ -2814,11 +3075,20 @@
   1.774              dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
   1.775              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.776                  /* This goes away if we ever use premultiplied alpha */
   1.777 -                srcR = (srcR * srcA) / 255;
   1.778 -                srcG = (srcG * srcA) / 255;
   1.779 -                srcB = (srcB * srcA) / 255;
   1.780 -            }
   1.781 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.782 +                if (srcA < 255) {
   1.783 +                    srcR = (srcR * srcA) / 255;
   1.784 +                    srcG = (srcG * srcA) / 255;
   1.785 +                    srcB = (srcB * srcA) / 255;
   1.786 +                }
   1.787 +            }
   1.788 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.789 +            case SDL_RENDERCOPY_MASK:
   1.790 +                if (srcA) {
   1.791 +                    dstR = srcR;
   1.792 +                    dstG = srcG;
   1.793 +                    dstB = srcB;
   1.794 +                }
   1.795 +                break;
   1.796              case SDL_RENDERCOPY_BLEND:
   1.797                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.798                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.799 @@ -2868,6 +3138,9 @@
   1.800                  G = (G * modulateG) / 255;
   1.801                  B = (B * modulateB) / 255;
   1.802              }
   1.803 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
   1.804 +                A = (A * modulateA) / 255;
   1.805 +            }
   1.806              pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
   1.807              *dst = pixel;
   1.808              ++src;
   1.809 @@ -2922,6 +3195,9 @@
   1.810                  G = (G * modulateG) / 255;
   1.811                  B = (B * modulateB) / 255;
   1.812              }
   1.813 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
   1.814 +                A = (A * modulateA) / 255;
   1.815 +            }
   1.816              pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
   1.817              *dst = pixel;
   1.818              posx += incx;
   1.819 @@ -2964,11 +3240,20 @@
   1.820              }
   1.821              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.822                  /* This goes away if we ever use premultiplied alpha */
   1.823 -                srcR = (srcR * srcA) / 255;
   1.824 -                srcG = (srcG * srcA) / 255;
   1.825 -                srcB = (srcB * srcA) / 255;
   1.826 -            }
   1.827 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.828 +                if (srcA < 255) {
   1.829 +                    srcR = (srcR * srcA) / 255;
   1.830 +                    srcG = (srcG * srcA) / 255;
   1.831 +                    srcB = (srcB * srcA) / 255;
   1.832 +                }
   1.833 +            }
   1.834 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.835 +            case SDL_RENDERCOPY_MASK:
   1.836 +                if (srcA) {
   1.837 +                    dstR = srcR;
   1.838 +                    dstG = srcG;
   1.839 +                    dstB = srcB;
   1.840 +                }
   1.841 +                break;
   1.842              case SDL_RENDERCOPY_BLEND:
   1.843                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.844                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.845 @@ -3048,11 +3333,20 @@
   1.846              }
   1.847              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.848                  /* This goes away if we ever use premultiplied alpha */
   1.849 -                srcR = (srcR * srcA) / 255;
   1.850 -                srcG = (srcG * srcA) / 255;
   1.851 -                srcB = (srcB * srcA) / 255;
   1.852 -            }
   1.853 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.854 +                if (srcA < 255) {
   1.855 +                    srcR = (srcR * srcA) / 255;
   1.856 +                    srcG = (srcG * srcA) / 255;
   1.857 +                    srcB = (srcB * srcA) / 255;
   1.858 +                }
   1.859 +            }
   1.860 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.861 +            case SDL_RENDERCOPY_MASK:
   1.862 +                if (srcA) {
   1.863 +                    dstR = srcR;
   1.864 +                    dstG = srcG;
   1.865 +                    dstB = srcB;
   1.866 +                }
   1.867 +                break;
   1.868              case SDL_RENDERCOPY_BLEND:
   1.869                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.870                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.871 @@ -3168,11 +3462,20 @@
   1.872              dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
   1.873              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.874                  /* This goes away if we ever use premultiplied alpha */
   1.875 -                srcR = (srcR * srcA) / 255;
   1.876 -                srcG = (srcG * srcA) / 255;
   1.877 -                srcB = (srcB * srcA) / 255;
   1.878 -            }
   1.879 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.880 +                if (srcA < 255) {
   1.881 +                    srcR = (srcR * srcA) / 255;
   1.882 +                    srcG = (srcG * srcA) / 255;
   1.883 +                    srcB = (srcB * srcA) / 255;
   1.884 +                }
   1.885 +            }
   1.886 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.887 +            case SDL_RENDERCOPY_MASK:
   1.888 +                if (srcA) {
   1.889 +                    dstR = srcR;
   1.890 +                    dstG = srcG;
   1.891 +                    dstB = srcB;
   1.892 +                }
   1.893 +                break;
   1.894              case SDL_RENDERCOPY_BLEND:
   1.895                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.896                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.897 @@ -3240,11 +3543,20 @@
   1.898              dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
   1.899              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.900                  /* This goes away if we ever use premultiplied alpha */
   1.901 -                srcR = (srcR * srcA) / 255;
   1.902 -                srcG = (srcG * srcA) / 255;
   1.903 -                srcB = (srcB * srcA) / 255;
   1.904 -            }
   1.905 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.906 +                if (srcA < 255) {
   1.907 +                    srcR = (srcR * srcA) / 255;
   1.908 +                    srcG = (srcG * srcA) / 255;
   1.909 +                    srcB = (srcB * srcA) / 255;
   1.910 +                }
   1.911 +            }
   1.912 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.913 +            case SDL_RENDERCOPY_MASK:
   1.914 +                if (srcA) {
   1.915 +                    dstR = srcR;
   1.916 +                    dstG = srcG;
   1.917 +                    dstB = srcB;
   1.918 +                }
   1.919 +                break;
   1.920              case SDL_RENDERCOPY_BLEND:
   1.921                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.922                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.923 @@ -3294,6 +3606,9 @@
   1.924                  G = (G * modulateG) / 255;
   1.925                  B = (B * modulateB) / 255;
   1.926              }
   1.927 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
   1.928 +                A = (A * modulateA) / 255;
   1.929 +            }
   1.930              pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
   1.931              *dst = pixel;
   1.932              ++src;
   1.933 @@ -3348,6 +3663,9 @@
   1.934                  G = (G * modulateG) / 255;
   1.935                  B = (B * modulateB) / 255;
   1.936              }
   1.937 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
   1.938 +                A = (A * modulateA) / 255;
   1.939 +            }
   1.940              pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
   1.941              *dst = pixel;
   1.942              posx += incx;
   1.943 @@ -3390,11 +3708,20 @@
   1.944              }
   1.945              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.946                  /* This goes away if we ever use premultiplied alpha */
   1.947 -                srcR = (srcR * srcA) / 255;
   1.948 -                srcG = (srcG * srcA) / 255;
   1.949 -                srcB = (srcB * srcA) / 255;
   1.950 -            }
   1.951 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.952 +                if (srcA < 255) {
   1.953 +                    srcR = (srcR * srcA) / 255;
   1.954 +                    srcG = (srcG * srcA) / 255;
   1.955 +                    srcB = (srcB * srcA) / 255;
   1.956 +                }
   1.957 +            }
   1.958 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.959 +            case SDL_RENDERCOPY_MASK:
   1.960 +                if (srcA) {
   1.961 +                    dstR = srcR;
   1.962 +                    dstG = srcG;
   1.963 +                    dstB = srcB;
   1.964 +                }
   1.965 +                break;
   1.966              case SDL_RENDERCOPY_BLEND:
   1.967                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.968                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.969 @@ -3474,11 +3801,20 @@
   1.970              }
   1.971              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.972                  /* This goes away if we ever use premultiplied alpha */
   1.973 -                srcR = (srcR * srcA) / 255;
   1.974 -                srcG = (srcG * srcA) / 255;
   1.975 -                srcB = (srcB * srcA) / 255;
   1.976 -            }
   1.977 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.978 +                if (srcA < 255) {
   1.979 +                    srcR = (srcR * srcA) / 255;
   1.980 +                    srcG = (srcG * srcA) / 255;
   1.981 +                    srcB = (srcB * srcA) / 255;
   1.982 +                }
   1.983 +            }
   1.984 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
   1.985 +            case SDL_RENDERCOPY_MASK:
   1.986 +                if (srcA) {
   1.987 +                    dstR = srcR;
   1.988 +                    dstG = srcG;
   1.989 +                    dstB = srcB;
   1.990 +                }
   1.991 +                break;
   1.992              case SDL_RENDERCOPY_BLEND:
   1.993                  dstR = srcR + ((255 - srcA) * dstR) / 255;
   1.994                  dstG = srcG + ((255 - srcA) * dstG) / 255;
   1.995 @@ -3594,11 +3930,20 @@
   1.996              dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
   1.997              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
   1.998                  /* This goes away if we ever use premultiplied alpha */
   1.999 -                srcR = (srcR * srcA) / 255;
  1.1000 -                srcG = (srcG * srcA) / 255;
  1.1001 -                srcB = (srcB * srcA) / 255;
  1.1002 -            }
  1.1003 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1004 +                if (srcA < 255) {
  1.1005 +                    srcR = (srcR * srcA) / 255;
  1.1006 +                    srcG = (srcG * srcA) / 255;
  1.1007 +                    srcB = (srcB * srcA) / 255;
  1.1008 +                }
  1.1009 +            }
  1.1010 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1011 +            case SDL_RENDERCOPY_MASK:
  1.1012 +                if (srcA) {
  1.1013 +                    dstR = srcR;
  1.1014 +                    dstG = srcG;
  1.1015 +                    dstB = srcB;
  1.1016 +                }
  1.1017 +                break;
  1.1018              case SDL_RENDERCOPY_BLEND:
  1.1019                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  1.1020                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  1.1021 @@ -3666,11 +4011,20 @@
  1.1022              dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
  1.1023              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
  1.1024                  /* This goes away if we ever use premultiplied alpha */
  1.1025 -                srcR = (srcR * srcA) / 255;
  1.1026 -                srcG = (srcG * srcA) / 255;
  1.1027 -                srcB = (srcB * srcA) / 255;
  1.1028 -            }
  1.1029 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1030 +                if (srcA < 255) {
  1.1031 +                    srcR = (srcR * srcA) / 255;
  1.1032 +                    srcG = (srcG * srcA) / 255;
  1.1033 +                    srcB = (srcB * srcA) / 255;
  1.1034 +                }
  1.1035 +            }
  1.1036 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1037 +            case SDL_RENDERCOPY_MASK:
  1.1038 +                if (srcA) {
  1.1039 +                    dstR = srcR;
  1.1040 +                    dstG = srcG;
  1.1041 +                    dstB = srcB;
  1.1042 +                }
  1.1043 +                break;
  1.1044              case SDL_RENDERCOPY_BLEND:
  1.1045                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  1.1046                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  1.1047 @@ -3720,6 +4074,9 @@
  1.1048                  G = (G * modulateG) / 255;
  1.1049                  B = (B * modulateB) / 255;
  1.1050              }
  1.1051 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
  1.1052 +                A = (A * modulateA) / 255;
  1.1053 +            }
  1.1054              pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
  1.1055              *dst = pixel;
  1.1056              ++src;
  1.1057 @@ -3774,6 +4131,9 @@
  1.1058                  G = (G * modulateG) / 255;
  1.1059                  B = (B * modulateB) / 255;
  1.1060              }
  1.1061 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
  1.1062 +                A = (A * modulateA) / 255;
  1.1063 +            }
  1.1064              pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
  1.1065              *dst = pixel;
  1.1066              posx += incx;
  1.1067 @@ -3816,11 +4176,20 @@
  1.1068              }
  1.1069              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
  1.1070                  /* This goes away if we ever use premultiplied alpha */
  1.1071 -                srcR = (srcR * srcA) / 255;
  1.1072 -                srcG = (srcG * srcA) / 255;
  1.1073 -                srcB = (srcB * srcA) / 255;
  1.1074 -            }
  1.1075 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1076 +                if (srcA < 255) {
  1.1077 +                    srcR = (srcR * srcA) / 255;
  1.1078 +                    srcG = (srcG * srcA) / 255;
  1.1079 +                    srcB = (srcB * srcA) / 255;
  1.1080 +                }
  1.1081 +            }
  1.1082 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1083 +            case SDL_RENDERCOPY_MASK:
  1.1084 +                if (srcA) {
  1.1085 +                    dstR = srcR;
  1.1086 +                    dstG = srcG;
  1.1087 +                    dstB = srcB;
  1.1088 +                }
  1.1089 +                break;
  1.1090              case SDL_RENDERCOPY_BLEND:
  1.1091                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  1.1092                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  1.1093 @@ -3900,11 +4269,20 @@
  1.1094              }
  1.1095              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
  1.1096                  /* This goes away if we ever use premultiplied alpha */
  1.1097 -                srcR = (srcR * srcA) / 255;
  1.1098 -                srcG = (srcG * srcA) / 255;
  1.1099 -                srcB = (srcB * srcA) / 255;
  1.1100 -            }
  1.1101 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1102 +                if (srcA < 255) {
  1.1103 +                    srcR = (srcR * srcA) / 255;
  1.1104 +                    srcG = (srcG * srcA) / 255;
  1.1105 +                    srcB = (srcB * srcA) / 255;
  1.1106 +                }
  1.1107 +            }
  1.1108 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1109 +            case SDL_RENDERCOPY_MASK:
  1.1110 +                if (srcA) {
  1.1111 +                    dstR = srcR;
  1.1112 +                    dstG = srcG;
  1.1113 +                    dstB = srcB;
  1.1114 +                }
  1.1115 +                break;
  1.1116              case SDL_RENDERCOPY_BLEND:
  1.1117                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  1.1118                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  1.1119 @@ -4020,11 +4398,20 @@
  1.1120              dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
  1.1121              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
  1.1122                  /* This goes away if we ever use premultiplied alpha */
  1.1123 -                srcR = (srcR * srcA) / 255;
  1.1124 -                srcG = (srcG * srcA) / 255;
  1.1125 -                srcB = (srcB * srcA) / 255;
  1.1126 -            }
  1.1127 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1128 +                if (srcA < 255) {
  1.1129 +                    srcR = (srcR * srcA) / 255;
  1.1130 +                    srcG = (srcG * srcA) / 255;
  1.1131 +                    srcB = (srcB * srcA) / 255;
  1.1132 +                }
  1.1133 +            }
  1.1134 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1135 +            case SDL_RENDERCOPY_MASK:
  1.1136 +                if (srcA) {
  1.1137 +                    dstR = srcR;
  1.1138 +                    dstG = srcG;
  1.1139 +                    dstB = srcB;
  1.1140 +                }
  1.1141 +                break;
  1.1142              case SDL_RENDERCOPY_BLEND:
  1.1143                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  1.1144                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  1.1145 @@ -4092,11 +4479,20 @@
  1.1146              dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
  1.1147              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
  1.1148                  /* This goes away if we ever use premultiplied alpha */
  1.1149 -                srcR = (srcR * srcA) / 255;
  1.1150 -                srcG = (srcG * srcA) / 255;
  1.1151 -                srcB = (srcB * srcA) / 255;
  1.1152 -            }
  1.1153 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1154 +                if (srcA < 255) {
  1.1155 +                    srcR = (srcR * srcA) / 255;
  1.1156 +                    srcG = (srcG * srcA) / 255;
  1.1157 +                    srcB = (srcB * srcA) / 255;
  1.1158 +                }
  1.1159 +            }
  1.1160 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1161 +            case SDL_RENDERCOPY_MASK:
  1.1162 +                if (srcA) {
  1.1163 +                    dstR = srcR;
  1.1164 +                    dstG = srcG;
  1.1165 +                    dstB = srcB;
  1.1166 +                }
  1.1167 +                break;
  1.1168              case SDL_RENDERCOPY_BLEND:
  1.1169                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  1.1170                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  1.1171 @@ -4146,6 +4542,9 @@
  1.1172                  G = (G * modulateG) / 255;
  1.1173                  B = (B * modulateB) / 255;
  1.1174              }
  1.1175 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
  1.1176 +                A = (A * modulateA) / 255;
  1.1177 +            }
  1.1178              pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
  1.1179              *dst = pixel;
  1.1180              ++src;
  1.1181 @@ -4200,6 +4599,9 @@
  1.1182                  G = (G * modulateG) / 255;
  1.1183                  B = (B * modulateB) / 255;
  1.1184              }
  1.1185 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
  1.1186 +                A = (A * modulateA) / 255;
  1.1187 +            }
  1.1188              pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
  1.1189              *dst = pixel;
  1.1190              posx += incx;
  1.1191 @@ -4242,11 +4644,20 @@
  1.1192              }
  1.1193              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
  1.1194                  /* This goes away if we ever use premultiplied alpha */
  1.1195 -                srcR = (srcR * srcA) / 255;
  1.1196 -                srcG = (srcG * srcA) / 255;
  1.1197 -                srcB = (srcB * srcA) / 255;
  1.1198 -            }
  1.1199 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1200 +                if (srcA < 255) {
  1.1201 +                    srcR = (srcR * srcA) / 255;
  1.1202 +                    srcG = (srcG * srcA) / 255;
  1.1203 +                    srcB = (srcB * srcA) / 255;
  1.1204 +                }
  1.1205 +            }
  1.1206 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1207 +            case SDL_RENDERCOPY_MASK:
  1.1208 +                if (srcA) {
  1.1209 +                    dstR = srcR;
  1.1210 +                    dstG = srcG;
  1.1211 +                    dstB = srcB;
  1.1212 +                }
  1.1213 +                break;
  1.1214              case SDL_RENDERCOPY_BLEND:
  1.1215                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  1.1216                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  1.1217 @@ -4326,11 +4737,20 @@
  1.1218              }
  1.1219              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
  1.1220                  /* This goes away if we ever use premultiplied alpha */
  1.1221 -                srcR = (srcR * srcA) / 255;
  1.1222 -                srcG = (srcG * srcA) / 255;
  1.1223 -                srcB = (srcB * srcA) / 255;
  1.1224 -            }
  1.1225 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1226 +                if (srcA < 255) {
  1.1227 +                    srcR = (srcR * srcA) / 255;
  1.1228 +                    srcG = (srcG * srcA) / 255;
  1.1229 +                    srcB = (srcB * srcA) / 255;
  1.1230 +                }
  1.1231 +            }
  1.1232 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1233 +            case SDL_RENDERCOPY_MASK:
  1.1234 +                if (srcA) {
  1.1235 +                    dstR = srcR;
  1.1236 +                    dstG = srcG;
  1.1237 +                    dstB = srcB;
  1.1238 +                }
  1.1239 +                break;
  1.1240              case SDL_RENDERCOPY_BLEND:
  1.1241                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  1.1242                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  1.1243 @@ -4446,11 +4866,20 @@
  1.1244              dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
  1.1245              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
  1.1246                  /* This goes away if we ever use premultiplied alpha */
  1.1247 -                srcR = (srcR * srcA) / 255;
  1.1248 -                srcG = (srcG * srcA) / 255;
  1.1249 -                srcB = (srcB * srcA) / 255;
  1.1250 -            }
  1.1251 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1252 +                if (srcA < 255) {
  1.1253 +                    srcR = (srcR * srcA) / 255;
  1.1254 +                    srcG = (srcG * srcA) / 255;
  1.1255 +                    srcB = (srcB * srcA) / 255;
  1.1256 +                }
  1.1257 +            }
  1.1258 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1259 +            case SDL_RENDERCOPY_MASK:
  1.1260 +                if (srcA) {
  1.1261 +                    dstR = srcR;
  1.1262 +                    dstG = srcG;
  1.1263 +                    dstB = srcB;
  1.1264 +                }
  1.1265 +                break;
  1.1266              case SDL_RENDERCOPY_BLEND:
  1.1267                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  1.1268                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  1.1269 @@ -4518,11 +4947,20 @@
  1.1270              dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
  1.1271              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
  1.1272                  /* This goes away if we ever use premultiplied alpha */
  1.1273 -                srcR = (srcR * srcA) / 255;
  1.1274 -                srcG = (srcG * srcA) / 255;
  1.1275 -                srcB = (srcB * srcA) / 255;
  1.1276 -            }
  1.1277 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1278 +                if (srcA < 255) {
  1.1279 +                    srcR = (srcR * srcA) / 255;
  1.1280 +                    srcG = (srcG * srcA) / 255;
  1.1281 +                    srcB = (srcB * srcA) / 255;
  1.1282 +                }
  1.1283 +            }
  1.1284 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1285 +            case SDL_RENDERCOPY_MASK:
  1.1286 +                if (srcA) {
  1.1287 +                    dstR = srcR;
  1.1288 +                    dstG = srcG;
  1.1289 +                    dstB = srcB;
  1.1290 +                }
  1.1291 +                break;
  1.1292              case SDL_RENDERCOPY_BLEND:
  1.1293                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  1.1294                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  1.1295 @@ -4572,6 +5010,9 @@
  1.1296                  G = (G * modulateG) / 255;
  1.1297                  B = (B * modulateB) / 255;
  1.1298              }
  1.1299 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
  1.1300 +                A = (A * modulateA) / 255;
  1.1301 +            }
  1.1302              pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
  1.1303              *dst = pixel;
  1.1304              ++src;
  1.1305 @@ -4626,6 +5067,9 @@
  1.1306                  G = (G * modulateG) / 255;
  1.1307                  B = (B * modulateB) / 255;
  1.1308              }
  1.1309 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
  1.1310 +                A = (A * modulateA) / 255;
  1.1311 +            }
  1.1312              pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
  1.1313              *dst = pixel;
  1.1314              posx += incx;
  1.1315 @@ -4668,11 +5112,20 @@
  1.1316              }
  1.1317              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
  1.1318                  /* This goes away if we ever use premultiplied alpha */
  1.1319 -                srcR = (srcR * srcA) / 255;
  1.1320 -                srcG = (srcG * srcA) / 255;
  1.1321 -                srcB = (srcB * srcA) / 255;
  1.1322 -            }
  1.1323 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1324 +                if (srcA < 255) {
  1.1325 +                    srcR = (srcR * srcA) / 255;
  1.1326 +                    srcG = (srcG * srcA) / 255;
  1.1327 +                    srcB = (srcB * srcA) / 255;
  1.1328 +                }
  1.1329 +            }
  1.1330 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1331 +            case SDL_RENDERCOPY_MASK:
  1.1332 +                if (srcA) {
  1.1333 +                    dstR = srcR;
  1.1334 +                    dstG = srcG;
  1.1335 +                    dstB = srcB;
  1.1336 +                }
  1.1337 +                break;
  1.1338              case SDL_RENDERCOPY_BLEND:
  1.1339                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  1.1340                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  1.1341 @@ -4752,11 +5205,20 @@
  1.1342              }
  1.1343              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
  1.1344                  /* This goes away if we ever use premultiplied alpha */
  1.1345 -                srcR = (srcR * srcA) / 255;
  1.1346 -                srcG = (srcG * srcA) / 255;
  1.1347 -                srcB = (srcB * srcA) / 255;
  1.1348 -            }
  1.1349 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1350 +                if (srcA < 255) {
  1.1351 +                    srcR = (srcR * srcA) / 255;
  1.1352 +                    srcG = (srcG * srcA) / 255;
  1.1353 +                    srcB = (srcB * srcA) / 255;
  1.1354 +                }
  1.1355 +            }
  1.1356 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1357 +            case SDL_RENDERCOPY_MASK:
  1.1358 +                if (srcA) {
  1.1359 +                    dstR = srcR;
  1.1360 +                    dstG = srcG;
  1.1361 +                    dstB = srcB;
  1.1362 +                }
  1.1363 +                break;
  1.1364              case SDL_RENDERCOPY_BLEND:
  1.1365                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  1.1366                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  1.1367 @@ -4872,11 +5334,20 @@
  1.1368              dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
  1.1369              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
  1.1370                  /* This goes away if we ever use premultiplied alpha */
  1.1371 -                srcR = (srcR * srcA) / 255;
  1.1372 -                srcG = (srcG * srcA) / 255;
  1.1373 -                srcB = (srcB * srcA) / 255;
  1.1374 -            }
  1.1375 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1376 +                if (srcA < 255) {
  1.1377 +                    srcR = (srcR * srcA) / 255;
  1.1378 +                    srcG = (srcG * srcA) / 255;
  1.1379 +                    srcB = (srcB * srcA) / 255;
  1.1380 +                }
  1.1381 +            }
  1.1382 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1383 +            case SDL_RENDERCOPY_MASK:
  1.1384 +                if (srcA) {
  1.1385 +                    dstR = srcR;
  1.1386 +                    dstG = srcG;
  1.1387 +                    dstB = srcB;
  1.1388 +                }
  1.1389 +                break;
  1.1390              case SDL_RENDERCOPY_BLEND:
  1.1391                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  1.1392                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  1.1393 @@ -4944,11 +5415,20 @@
  1.1394              dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
  1.1395              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
  1.1396                  /* This goes away if we ever use premultiplied alpha */
  1.1397 -                srcR = (srcR * srcA) / 255;
  1.1398 -                srcG = (srcG * srcA) / 255;
  1.1399 -                srcB = (srcB * srcA) / 255;
  1.1400 -            }
  1.1401 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1402 +                if (srcA < 255) {
  1.1403 +                    srcR = (srcR * srcA) / 255;
  1.1404 +                    srcG = (srcG * srcA) / 255;
  1.1405 +                    srcB = (srcB * srcA) / 255;
  1.1406 +                }
  1.1407 +            }
  1.1408 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1409 +            case SDL_RENDERCOPY_MASK:
  1.1410 +                if (srcA) {
  1.1411 +                    dstR = srcR;
  1.1412 +                    dstG = srcG;
  1.1413 +                    dstB = srcB;
  1.1414 +                }
  1.1415 +                break;
  1.1416              case SDL_RENDERCOPY_BLEND:
  1.1417                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  1.1418                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  1.1419 @@ -4998,6 +5478,9 @@
  1.1420                  G = (G * modulateG) / 255;
  1.1421                  B = (B * modulateB) / 255;
  1.1422              }
  1.1423 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
  1.1424 +                A = (A * modulateA) / 255;
  1.1425 +            }
  1.1426              pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
  1.1427              *dst = pixel;
  1.1428              ++src;
  1.1429 @@ -5052,6 +5535,9 @@
  1.1430                  G = (G * modulateG) / 255;
  1.1431                  B = (B * modulateB) / 255;
  1.1432              }
  1.1433 +            if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
  1.1434 +                A = (A * modulateA) / 255;
  1.1435 +            }
  1.1436              pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
  1.1437              *dst = pixel;
  1.1438              posx += incx;
  1.1439 @@ -5094,11 +5580,20 @@
  1.1440              }
  1.1441              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
  1.1442                  /* This goes away if we ever use premultiplied alpha */
  1.1443 -                srcR = (srcR * srcA) / 255;
  1.1444 -                srcG = (srcG * srcA) / 255;
  1.1445 -                srcB = (srcB * srcA) / 255;
  1.1446 -            }
  1.1447 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1448 +                if (srcA < 255) {
  1.1449 +                    srcR = (srcR * srcA) / 255;
  1.1450 +                    srcG = (srcG * srcA) / 255;
  1.1451 +                    srcB = (srcB * srcA) / 255;
  1.1452 +                }
  1.1453 +            }
  1.1454 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1455 +            case SDL_RENDERCOPY_MASK:
  1.1456 +                if (srcA) {
  1.1457 +                    dstR = srcR;
  1.1458 +                    dstG = srcG;
  1.1459 +                    dstB = srcB;
  1.1460 +                }
  1.1461 +                break;
  1.1462              case SDL_RENDERCOPY_BLEND:
  1.1463                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  1.1464                  dstG = srcG + ((255 - srcA) * dstG) / 255;
  1.1465 @@ -5178,11 +5673,20 @@
  1.1466              }
  1.1467              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
  1.1468                  /* This goes away if we ever use premultiplied alpha */
  1.1469 -                srcR = (srcR * srcA) / 255;
  1.1470 -                srcG = (srcG * srcA) / 255;
  1.1471 -                srcB = (srcB * srcA) / 255;
  1.1472 -            }
  1.1473 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1474 +                if (srcA < 255) {
  1.1475 +                    srcR = (srcR * srcA) / 255;
  1.1476 +                    srcG = (srcG * srcA) / 255;
  1.1477 +                    srcB = (srcB * srcA) / 255;
  1.1478 +                }
  1.1479 +            }
  1.1480 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
  1.1481 +            case SDL_RENDERCOPY_MASK:
  1.1482 +                if (srcA) {
  1.1483 +                    dstR = srcR;
  1.1484 +                    dstG = srcG;
  1.1485 +                    dstB = srcB;
  1.1486 +                }
  1.1487 +                break;
  1.1488              case SDL_RENDERCOPY_BLEND:
  1.1489                  dstR = srcR + ((255 - srcA) * dstR) / 255;
  1.1490                  dstG = srcG + ((255 - srcA) * dstG) / 255;
     2.1 --- a/src/video/SDL_rendercopy.h	Mon Aug 28 04:39:37 2006 +0000
     2.2 +++ b/src/video/SDL_rendercopy.h	Mon Aug 28 14:10:46 2006 +0000
     2.3 @@ -26,9 +26,10 @@
     2.4  
     2.5  #define SDL_RENDERCOPY_MODULATE_COLOR   0x0001
     2.6  #define SDL_RENDERCOPY_MODULATE_ALPHA   0x0002
     2.7 -#define SDL_RENDERCOPY_BLEND            0x0010
     2.8 -#define SDL_RENDERCOPY_ADD              0x0020
     2.9 -#define SDL_RENDERCOPY_MOD              0x0040
    2.10 +#define SDL_RENDERCOPY_MASK             0x0010
    2.11 +#define SDL_RENDERCOPY_BLEND            0x0020
    2.12 +#define SDL_RENDERCOPY_ADD              0x0040
    2.13 +#define SDL_RENDERCOPY_MOD              0x0080
    2.14  #define SDL_RENDERCOPY_NEAREST          0x0100
    2.15  
    2.16  typedef struct {
     3.1 --- a/src/video/SDL_renderer_sw.c	Mon Aug 28 04:39:37 2006 +0000
     3.2 +++ b/src/video/SDL_renderer_sw.c	Mon Aug 28 14:10:46 2006 +0000
     3.3 @@ -628,9 +628,9 @@
     3.4                  copydata.flags |= SDL_RENDERCOPY_MODULATE_ALPHA;
     3.5                  copydata.a = texture->a;
     3.6              }
     3.7 -            if (texture->
     3.8 -                blendMode & (SDL_TEXTUREBLENDMODE_MASK |
     3.9 -                             SDL_TEXTUREBLENDMODE_BLEND)) {
    3.10 +            if (texture->blendMode & SDL_TEXTUREBLENDMODE_MASK) {
    3.11 +                copydata.flags |= SDL_RENDERCOPY_MASK;
    3.12 +            } else if (texture->blendMode & SDL_TEXTUREBLENDMODE_BLEND) {
    3.13                  copydata.flags |= SDL_RENDERCOPY_BLEND;
    3.14              } else if (texture->blendMode & SDL_TEXTUREBLENDMODE_ADD) {
    3.15                  copydata.flags |= SDL_RENDERCOPY_ADD;
     4.1 --- a/src/video/sdlgenblit.pl	Mon Aug 28 04:39:37 2006 +0000
     4.2 +++ b/src/video/sdlgenblit.pl	Mon Aug 28 14:10:46 2006 +0000
     4.3 @@ -125,9 +125,10 @@
     4.4      print FILE <<__EOF__;
     4.5  #define SDL_RENDERCOPY_MODULATE_COLOR   0x0001
     4.6  #define SDL_RENDERCOPY_MODULATE_ALPHA   0x0002
     4.7 -#define SDL_RENDERCOPY_BLEND            0x0010
     4.8 -#define SDL_RENDERCOPY_ADD              0x0020
     4.9 -#define SDL_RENDERCOPY_MOD              0x0040
    4.10 +#define SDL_RENDERCOPY_MASK             0x0010
    4.11 +#define SDL_RENDERCOPY_BLEND            0x0020
    4.12 +#define SDL_RENDERCOPY_ADD              0x0040
    4.13 +#define SDL_RENDERCOPY_MOD              0x0080
    4.14  #define SDL_RENDERCOPY_NEAREST          0x0100
    4.15  
    4.16  typedef struct {
    4.17 @@ -214,19 +215,35 @@
    4.18      my $dst = shift;
    4.19      my $modulate = shift;
    4.20      my $blend = shift;
    4.21 +    my $s = "";
    4.22 +    my $d = "";
    4.23 +
    4.24 +    # Nice and easy...
    4.25 +    if ( $src eq $dst && !$modulate && !$blend ) {
    4.26 +        print FILE <<__EOF__;
    4.27 +            *dst = *src;
    4.28 +__EOF__
    4.29 +        return;
    4.30 +    }
    4.31 +        
    4.32 +    if ( $blend ) {
    4.33 +        get_rgba("src", $src);
    4.34 +        get_rgba("dst", $dst);
    4.35 +        $s = "src";
    4.36 +        $d = "dst";
    4.37 +    } else {
    4.38 +        get_rgba("", $src);
    4.39 +    }
    4.40 +
    4.41      if ( $modulate ) {
    4.42          print FILE <<__EOF__;
    4.43              if (flags & SDL_RENDERCOPY_MODULATE_COLOR) {
    4.44 -                ${src}R = (${src}R * modulateR) / 255;
    4.45 -                ${src}G = (${src}G * modulateG) / 255;
    4.46 -                ${src}B = (${src}B * modulateB) / 255;
    4.47 +                ${s}R = (${s}R * modulateR) / 255;
    4.48 +                ${s}G = (${s}G * modulateG) / 255;
    4.49 +                ${s}B = (${s}B * modulateB) / 255;
    4.50              }
    4.51 -__EOF__
    4.52 -    }
    4.53 -    if ( $modulate && $blend ) {
    4.54 -        print FILE <<__EOF__;
    4.55              if (flags & SDL_RENDERCOPY_MODULATE_ALPHA) {
    4.56 -                ${src}A = (${src}A * modulateA) / 255;
    4.57 +                ${s}A = (${s}A * modulateA) / 255;
    4.58              }
    4.59  __EOF__
    4.60      }
    4.61 @@ -234,29 +251,43 @@
    4.62          print FILE <<__EOF__;
    4.63              if (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD)) {
    4.64                  /* This goes away if we ever use premultiplied alpha */
    4.65 -                ${src}R = (${src}R * ${src}A) / 255;
    4.66 -                ${src}G = (${src}G * ${src}A) / 255;
    4.67 -                ${src}B = (${src}B * ${src}A) / 255;
    4.68 +                if (${s}A < 255) {
    4.69 +                    ${s}R = (${s}R * ${s}A) / 255;
    4.70 +                    ${s}G = (${s}G * ${s}A) / 255;
    4.71 +                    ${s}B = (${s}B * ${s}A) / 255;
    4.72 +                }
    4.73              }
    4.74 -            switch (flags & (SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
    4.75 +            switch (flags & (SDL_RENDERCOPY_MASK|SDL_RENDERCOPY_BLEND|SDL_RENDERCOPY_ADD|SDL_RENDERCOPY_MOD)) {
    4.76 +            case SDL_RENDERCOPY_MASK:
    4.77 +                if (${s}A) {
    4.78 +                    ${d}R = ${s}R;
    4.79 +                    ${d}G = ${s}G;
    4.80 +                    ${d}B = ${s}B;
    4.81 +                }
    4.82 +                break;
    4.83              case SDL_RENDERCOPY_BLEND:
    4.84 -                ${dst}R = ${src}R + ((255 - ${src}A) * ${dst}R) / 255;
    4.85 -                ${dst}G = ${src}G + ((255 - ${src}A) * ${dst}G) / 255;
    4.86 -                ${dst}B = ${src}B + ((255 - ${src}A) * ${dst}B) / 255;
    4.87 +                ${d}R = ${s}R + ((255 - ${s}A) * ${d}R) / 255;
    4.88 +                ${d}G = ${s}G + ((255 - ${s}A) * ${d}G) / 255;
    4.89 +                ${d}B = ${s}B + ((255 - ${s}A) * ${d}B) / 255;
    4.90                  break;
    4.91              case SDL_RENDERCOPY_ADD:
    4.92 -                ${dst}R = ${src}R + ${dst}R; if (${dst}R > 255) ${dst}R = 255;
    4.93 -                ${dst}G = ${src}G + ${dst}G; if (${dst}G > 255) ${dst}G = 255;
    4.94 -                ${dst}B = ${src}B + ${dst}B; if (${dst}B > 255) ${dst}B = 255;
    4.95 +                ${d}R = ${s}R + ${d}R; if (${d}R > 255) ${d}R = 255;
    4.96 +                ${d}G = ${s}G + ${d}G; if (${d}G > 255) ${d}G = 255;
    4.97 +                ${d}B = ${s}B + ${d}B; if (${d}B > 255) ${d}B = 255;
    4.98                  break;
    4.99              case SDL_RENDERCOPY_MOD:
   4.100 -                ${dst}R = (${src}R * ${dst}R) / 255;
   4.101 -                ${dst}G = (${src}G * ${dst}G) / 255;
   4.102 -                ${dst}B = (${src}B * ${dst}B) / 255;
   4.103 +                ${d}R = (${s}R * ${d}R) / 255;
   4.104 +                ${d}G = (${s}G * ${d}G) / 255;
   4.105 +                ${d}B = (${s}B * ${d}B) / 255;
   4.106                  break;
   4.107              }
   4.108  __EOF__
   4.109      }
   4.110 +    if ( $blend ) {
   4.111 +        set_rgba("dst", $dst);
   4.112 +    } else {
   4.113 +        set_rgba("", $dst);
   4.114 +    }
   4.115  }
   4.116  
   4.117  sub output_copyfunc
   4.118 @@ -325,20 +356,7 @@
   4.119          print FILE <<__EOF__;
   4.120              }
   4.121  __EOF__
   4.122 -        if ( $blend ) {
   4.123 -            get_rgba("src", $src);
   4.124 -            get_rgba("dst", $dst);
   4.125 -            output_copycore("src", "dst", $modulate, $blend);
   4.126 -            set_rgba("dst", $dst);
   4.127 -        } elsif ( $modulate || $src ne $dst ) {
   4.128 -            get_rgba("", $src);
   4.129 -            output_copycore("", "", $modulate, $blend);
   4.130 -            set_rgba("", $dst);
   4.131 -        } else {
   4.132 -            print FILE <<__EOF__;
   4.133 -            *dst = *src;
   4.134 -__EOF__
   4.135 -        }
   4.136 +        output_copycore($src, $dst, $modulate, $blend);
   4.137          print FILE <<__EOF__;
   4.138              posx += incx;
   4.139              ++dst;
   4.140 @@ -356,20 +374,7 @@
   4.141          int n = data->dst_w;
   4.142          while (n--) {
   4.143  __EOF__
   4.144 -        if ( $blend ) {
   4.145 -            get_rgba("src", $src);
   4.146 -            get_rgba("dst", $dst);
   4.147 -            output_copycore("src", "dst", $modulate, $blend);
   4.148 -            set_rgba("dst", $dst);
   4.149 -        } elsif ( $modulate || $src ne $dst ) {
   4.150 -            get_rgba("", $src);
   4.151 -            output_copycore("", "", $modulate, $blend);
   4.152 -            set_rgba("", $dst);
   4.153 -        } else {
   4.154 -            print FILE <<__EOF__;
   4.155 -            *dst = *src;
   4.156 -__EOF__
   4.157 -        }
   4.158 +        output_copycore($src, $dst, $modulate, $blend);
   4.159          print FILE <<__EOF__;
   4.160              ++src;
   4.161              ++dst;