Better naming for the blit permutation variables
authorSylvain Becker <sylvain.becker@gmail.com>
Sat, 09 Feb 2019 17:40:32 +0100
changeset 1260948e26b5d4f56
parent 12608 b3a02787a4dd
child 12610 587922004ea0
Better naming for the blit permutation variables
src/video/SDL_blit_N.c
     1.1 --- a/src/video/SDL_blit_N.c	Sat Feb 09 17:20:53 2019 +0100
     1.2 +++ b/src/video/SDL_blit_N.c	Sat Feb 09 17:40:32 2019 +0100
     1.3 @@ -2152,53 +2152,54 @@
     1.4  /* permutation for mapping srcfmt to dstfmt, overloading or not the alpha channel */
     1.5  static void
     1.6  get_permutation(SDL_PixelFormat *srcfmt, SDL_PixelFormat *dstfmt,
     1.7 -        int *_r , int *_g, int *_b, int *_a, int *_missing)
     1.8 +        int *_p0 , int *_p1, int *_p2, int *_p3, int *_alpha_channel)
     1.9  {
    1.10 -    int missing = 0, r, g, b, a = 0;
    1.11 +    int alpha_channel = 0, p0, p1, p2, p3;
    1.12      int Pixel = 0x04030201; /* identity permutation */
    1.13  
    1.14      if (srcfmt->Amask) {
    1.15 -        RGBA_FROM_PIXEL(Pixel, srcfmt, r, g, b, a);
    1.16 +        RGBA_FROM_PIXEL(Pixel, srcfmt, p0, p1, p2, p3);
    1.17      } else {
    1.18 -        RGB_FROM_PIXEL(Pixel, srcfmt, r, g, b);
    1.19 +        RGB_FROM_PIXEL(Pixel, srcfmt, p0, p1, p2);
    1.20 +        p3 = 0;
    1.21      }
    1.22  
    1.23      if (dstfmt->Amask) {
    1.24          if (srcfmt->Amask) {
    1.25 -            PIXEL_FROM_RGBA(Pixel, dstfmt, r, g, b, a);
    1.26 +            PIXEL_FROM_RGBA(Pixel, dstfmt, p0, p1, p2, p3);
    1.27          } else {
    1.28 -            PIXEL_FROM_RGBA(Pixel, dstfmt, r, g, b, 0);
    1.29 +            PIXEL_FROM_RGBA(Pixel, dstfmt, p0, p1, p2, 0);
    1.30          }
    1.31      } else {
    1.32 -        PIXEL_FROM_RGB(Pixel, dstfmt, r, g, b);
    1.33 +        PIXEL_FROM_RGB(Pixel, dstfmt, p0, p1, p2);
    1.34      }
    1.35  
    1.36 -    r = Pixel & 0xFF;
    1.37 -    g = (Pixel >> 8) & 0xFF;
    1.38 -    b = (Pixel >> 16) & 0xFF;
    1.39 -    a = (Pixel >> 24) & 0xFF;
    1.40 +    p0 = Pixel & 0xFF;
    1.41 +    p1 = (Pixel >> 8) & 0xFF;
    1.42 +    p2 = (Pixel >> 16) & 0xFF;
    1.43 +    p3 = (Pixel >> 24) & 0xFF;
    1.44  
    1.45 -    if (r == 0) {
    1.46 -        r = 1;
    1.47 -        missing = 0;
    1.48 -    } else if (g == 0) {
    1.49 -        g = 1;
    1.50 -        missing = 1;
    1.51 -    } else if (b == 0) {
    1.52 -        b = 1;
    1.53 -        missing = 2;
    1.54 -    } else if (a == 0) {
    1.55 -        a = 1;
    1.56 -        missing = 3;
    1.57 +    if (p0 == 0) {
    1.58 +        p0 = 1;
    1.59 +        alpha_channel = 0;
    1.60 +    } else if (p1 == 0) {
    1.61 +        p1 = 1;
    1.62 +        alpha_channel = 1;
    1.63 +    } else if (p2 == 0) {
    1.64 +        p2 = 1;
    1.65 +        alpha_channel = 2;
    1.66 +    } else if (p3 == 0) {
    1.67 +        p3 = 1;
    1.68 +        alpha_channel = 3;
    1.69      }
    1.70  
    1.71 -    *_r = r - 1;
    1.72 -    *_g = g - 1;
    1.73 -    *_b = b - 1;
    1.74 -    *_a = a - 1;
    1.75 +    *_p0 = p0 - 1;
    1.76 +    *_p1 = p1 - 1;
    1.77 +    *_p2 = p2 - 1;
    1.78 +    *_p3 = p3 - 1;
    1.79  
    1.80 -    if (_missing) {
    1.81 -        *_missing = missing;
    1.82 +    if (_alpha_channel) {
    1.83 +        *_alpha_channel = alpha_channel;
    1.84      }
    1.85      return;
    1.86  }
    1.87 @@ -2228,8 +2229,8 @@
    1.88          Uint32 *dst32 = (Uint32*)dst;
    1.89  
    1.90          /* Find the appropriate permutation */
    1.91 -        int missing = 0, r, g, b, a;
    1.92 -        get_permutation(srcfmt, dstfmt, &r, &g, &b, &a, &missing);
    1.93 +        int alpha_channel, p0, p1, p2, p3;
    1.94 +        get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel);
    1.95  
    1.96          while (height--) {
    1.97              /* *INDENT-OFF* */
    1.98 @@ -2237,11 +2238,11 @@
    1.99              {
   1.100                  Uint8 *s8 = (Uint8 *)src32;
   1.101                  Uint8 *d8 = (Uint8 *)dst32;
   1.102 -                d8[0] = s8[r];
   1.103 -                d8[1] = s8[g];
   1.104 -                d8[2] = s8[b];
   1.105 -                d8[3] = s8[a];
   1.106 -                d8[missing] = alpha;
   1.107 +                d8[0] = s8[p0];
   1.108 +                d8[1] = s8[p1];
   1.109 +                d8[2] = s8[p2];
   1.110 +                d8[3] = s8[p3];
   1.111 +                d8[alpha_channel] = alpha;
   1.112                  ++src32;
   1.113                  ++dst32;
   1.114              }, width);
   1.115 @@ -2259,17 +2260,17 @@
   1.116          Uint32 *src32 = (Uint32*)src;
   1.117  
   1.118          /* Find the appropriate permutation */
   1.119 -        int r, g, b, a;
   1.120 -        get_permutation(srcfmt, dstfmt, &r, &g, &b, &a, NULL);
   1.121 +        int p0, p1, p2, p3;
   1.122 +        get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL);
   1.123  
   1.124          while (height--) {
   1.125              /* *INDENT-OFF* */
   1.126              DUFFS_LOOP(
   1.127              {
   1.128                  Uint8 *s8 = (Uint8 *)src32;
   1.129 -                dst[0] = s8[r];
   1.130 -                dst[1] = s8[g];
   1.131 -                dst[2] = s8[b];
   1.132 +                dst[0] = s8[p0];
   1.133 +                dst[1] = s8[p1];
   1.134 +                dst[2] = s8[p2];
   1.135                  ++src32;
   1.136                  dst += 3;
   1.137              }, width);
   1.138 @@ -2287,19 +2288,19 @@
   1.139          Uint32 *dst32 = (Uint32*)dst;
   1.140  
   1.141          /* Find the appropriate permutation */
   1.142 -        int missing = 0, r, g, b, a;
   1.143 -        get_permutation(srcfmt, dstfmt, &r, &g, &b, &a, &missing);
   1.144 +        int alpha_channel, p0, p1, p2, p3;
   1.145 +        get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel);
   1.146  
   1.147          while (height--) {
   1.148              /* *INDENT-OFF* */
   1.149              DUFFS_LOOP(
   1.150              {
   1.151                  Uint8 *d8 = (Uint8 *)dst32;
   1.152 -                d8[0] = src[r];
   1.153 -                d8[1] = src[g];
   1.154 -                d8[2] = src[b];
   1.155 -                d8[3] = src[a];
   1.156 -                d8[missing] = alpha;
   1.157 +                d8[0] = src[p0];
   1.158 +                d8[1] = src[p1];
   1.159 +                d8[2] = src[p2];
   1.160 +                d8[3] = src[p3];
   1.161 +                d8[alpha_channel] = alpha;
   1.162                  src += 3;
   1.163                  ++dst32;
   1.164              }, width);
   1.165 @@ -2354,8 +2355,8 @@
   1.166          Uint32 *dst32 = (Uint32*)dst;
   1.167  
   1.168          /* Find the appropriate permutation */
   1.169 -        int r, g, b, a;
   1.170 -        get_permutation(srcfmt, dstfmt, &r, &g, &b, &a, NULL);
   1.171 +        int p0, p1, p2, p3;
   1.172 +        get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL);
   1.173  
   1.174          while (height--) {
   1.175              /* *INDENT-OFF* */
   1.176 @@ -2363,10 +2364,10 @@
   1.177              {
   1.178                  Uint8 *s8 = (Uint8 *)src32;
   1.179                  Uint8 *d8 = (Uint8 *)dst32;
   1.180 -                d8[0] = s8[r];
   1.181 -                d8[1] = s8[g];
   1.182 -                d8[2] = s8[b];
   1.183 -                d8[3] = s8[a];
   1.184 +                d8[0] = s8[p0];
   1.185 +                d8[1] = s8[p1];
   1.186 +                d8[2] = s8[p2];
   1.187 +                d8[3] = s8[p3];
   1.188                  ++src32;
   1.189                  ++dst32;
   1.190              }, width);
   1.191 @@ -2566,8 +2567,8 @@
   1.192          Uint32 *dst32 = (Uint32*)dst;
   1.193  
   1.194          /* Find the appropriate permutation */
   1.195 -        int missing = 0, r, g, b, a;
   1.196 -        get_permutation(srcfmt, dstfmt, &r, &g, &b, &a, &missing);
   1.197 +        int alpha_channel, p0, p1, p2, p3;
   1.198 +        get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel);
   1.199  
   1.200          while (height--) {
   1.201              /* *INDENT-OFF* */
   1.202 @@ -2576,11 +2577,11 @@
   1.203                  if ((*src32 & rgbmask) != ckey) {
   1.204                      Uint8 *s8 = (Uint8 *)src32;
   1.205                      Uint8 *d8 = (Uint8 *)dst32;
   1.206 -                    d8[0] = s8[r];
   1.207 -                    d8[1] = s8[g];
   1.208 -                    d8[2] = s8[b];
   1.209 -                    d8[3] = s8[a];
   1.210 -                    d8[missing] = alpha;
   1.211 +                    d8[0] = s8[p0];
   1.212 +                    d8[1] = s8[p1];
   1.213 +                    d8[2] = s8[p2];
   1.214 +                    d8[3] = s8[p3];
   1.215 +                    d8[alpha_channel] = alpha;
   1.216                  }
   1.217                  ++src32;
   1.218                  ++dst32;
   1.219 @@ -2663,8 +2664,8 @@
   1.220          Uint32 *src32 = (Uint32*)src;
   1.221  
   1.222          /* Find the appropriate permutation */
   1.223 -        int r, g, b, a;
   1.224 -        get_permutation(srcfmt, dstfmt, &r, &g, &b, &a, NULL);
   1.225 +        int p0, p1, p2, p3;
   1.226 +        get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL);
   1.227  
   1.228          while (height--) {
   1.229              /* *INDENT-OFF* */
   1.230 @@ -2672,9 +2673,9 @@
   1.231              {
   1.232                  if ((*src32 & rgbmask) != ckey) {
   1.233                      Uint8 *s8 = (Uint8 *)src32;
   1.234 -                    dst[0] = s8[r];
   1.235 -                    dst[1] = s8[g];
   1.236 -                    dst[2] = s8[b];
   1.237 +                    dst[0] = s8[p0];
   1.238 +                    dst[1] = s8[p1];
   1.239 +                    dst[2] = s8[p2];
   1.240                  }
   1.241                  ++src32;
   1.242                  dst += 3;
   1.243 @@ -2697,8 +2698,8 @@
   1.244          Uint8 k2 = (ckey >> 16) & 0xFF;
   1.245  
   1.246          /* Find the appropriate permutation */
   1.247 -        int missing = 0, r, g, b, a;
   1.248 -        get_permutation(srcfmt, dstfmt, &r, &g, &b, &a, &missing);
   1.249 +        int alpha_channel, p0, p1, p2, p3;
   1.250 +        get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel);
   1.251  
   1.252          while (height--) {
   1.253              /* *INDENT-OFF* */
   1.254 @@ -2710,11 +2711,11 @@
   1.255  
   1.256                  if (k0 != s0 || k1 != s1 || k2 != s2) {
   1.257                      Uint8 *d8 = (Uint8 *)dst32;
   1.258 -                    d8[0] = src[r];
   1.259 -                    d8[1] = src[g];
   1.260 -                    d8[2] = src[b];
   1.261 -                    d8[3] = src[a];
   1.262 -                    d8[missing] = alpha;
   1.263 +                    d8[0] = src[p0];
   1.264 +                    d8[1] = src[p1];
   1.265 +                    d8[2] = src[p2];
   1.266 +                    d8[3] = src[p3];
   1.267 +                    d8[alpha_channel] = alpha;
   1.268                  }
   1.269                  src += 3;
   1.270                  ++dst32;
   1.271 @@ -2812,8 +2813,8 @@
   1.272          Uint32 *dst32 = (Uint32*)dst;
   1.273  
   1.274          /* Find the appropriate permutation */
   1.275 -        int r, g, b, a;
   1.276 -        get_permutation(srcfmt, dstfmt, &r, &g, &b, &a, NULL);
   1.277 +        int p0, p1, p2, p3;
   1.278 +        get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL);
   1.279  
   1.280          while (height--) {
   1.281              /* *INDENT-OFF* */
   1.282 @@ -2822,10 +2823,10 @@
   1.283                  if ((*src32 & rgbmask) != ckey) {
   1.284                      Uint8 *s8 = (Uint8 *)src32;
   1.285                      Uint8 *d8 = (Uint8 *)dst32;
   1.286 -                    d8[0] = s8[r];
   1.287 -                    d8[1] = s8[g];
   1.288 -                    d8[2] = s8[b];
   1.289 -                    d8[3] = s8[a];
   1.290 +                    d8[0] = s8[p0];
   1.291 +                    d8[1] = s8[p1];
   1.292 +                    d8[2] = s8[p2];
   1.293 +                    d8[3] = s8[p3];
   1.294                  }
   1.295                  ++src32;
   1.296                  ++dst32;