src/video/SDL_pixels.c
changeset 7023 1d49dc7b5ce9
parent 6885 700f1b25f77f
child 7024 72cb3e205571
     1.1 --- a/src/video/SDL_pixels.c	Sat Mar 23 13:03:36 2013 -0700
     1.2 +++ b/src/video/SDL_pixels.c	Sun Mar 24 09:51:01 2013 -0700
     1.3 @@ -762,12 +762,12 @@
     1.4   * Match an RGB value to a particular palette index
     1.5   */
     1.6  Uint8
     1.7 -SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b)
     1.8 +SDL_FindColor(SDL_Palette * pal, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
     1.9  {
    1.10      /* Do colorspace distance matching */
    1.11      unsigned int smallest;
    1.12      unsigned int distance;
    1.13 -    int rd, gd, bd;
    1.14 +    int rd, gd, bd, ad;
    1.15      int i;
    1.16      Uint8 pixel = 0;
    1.17  
    1.18 @@ -776,7 +776,8 @@
    1.19          rd = pal->colors[i].r - r;
    1.20          gd = pal->colors[i].g - g;
    1.21          bd = pal->colors[i].b - b;
    1.22 -        distance = (rd * rd) + (gd * gd) + (bd * bd);
    1.23 +        ad = pal->colors[i].unused - a;
    1.24 +        distance = (rd * rd) + (gd * gd) + (bd * bd) + (ad * ad);
    1.25          if (distance < smallest) {
    1.26              pixel = i;
    1.27              if (distance == 0) {        /* Perfect match! */
    1.28 @@ -797,7 +798,7 @@
    1.29              | (g >> format->Gloss) << format->Gshift
    1.30              | (b >> format->Bloss) << format->Bshift | format->Amask;
    1.31      } else {
    1.32 -        return SDL_FindColor(format->palette, r, g, b);
    1.33 +        return SDL_FindColor(format->palette, r, g, b, SDL_ALPHA_OPAQUE);
    1.34      }
    1.35  }
    1.36  
    1.37 @@ -812,7 +813,7 @@
    1.38              | (b >> format->Bloss) << format->Bshift
    1.39              | ((a >> format->Aloss) << format->Ashift & format->Amask);
    1.40      } else {
    1.41 -        return SDL_FindColor(format->palette, r, g, b);
    1.42 +        return SDL_FindColor(format->palette, r, g, b, a);
    1.43      }
    1.44  }
    1.45  
    1.46 @@ -858,7 +859,7 @@
    1.47              *r = format->palette->colors[pixel].r;
    1.48              *g = format->palette->colors[pixel].g;
    1.49              *b = format->palette->colors[pixel].b;
    1.50 -            *a = SDL_ALPHA_OPAQUE;
    1.51 +            *a = format->palette->colors[pixel].unused;
    1.52          } else {
    1.53              *r = *g = *b = *a = 0;
    1.54          }
    1.55 @@ -894,7 +895,7 @@
    1.56      for (i = 0; i < src->ncolors; ++i) {
    1.57          map[i] = SDL_FindColor(dst,
    1.58                                 src->colors[i].r, src->colors[i].g,
    1.59 -                               src->colors[i].b);
    1.60 +                               src->colors[i].b, src->colors[i].unused);
    1.61      }
    1.62      return (map);
    1.63  }
    1.64 @@ -918,10 +919,10 @@
    1.65  
    1.66      /* We memory copy to the pixel map so the endianness is preserved */
    1.67      for (i = 0; i < pal->ncolors; ++i) {
    1.68 -        Uint8 A = Amod;
    1.69          Uint8 R = (Uint8) ((pal->colors[i].r * Rmod) / 255);
    1.70          Uint8 G = (Uint8) ((pal->colors[i].g * Gmod) / 255);
    1.71          Uint8 B = (Uint8) ((pal->colors[i].b * Bmod) / 255);
    1.72 +        Uint8 A = (Uint8) ((pal->colors[i].unused * Amod) / 255);
    1.73          ASSEMBLE_RGBA(&map[i * bpp], dst->BytesPerPixel, dst, R, G, B, A);
    1.74      }
    1.75      return (map);