src/video/SDL_surface.c
changeset 5438 b705640cb34a
parent 5375 16877f74123c
child 5499 2b8e6d1e3817
equal deleted inserted replaced
5437:ce10653e370c 5438:b705640cb34a
    73             SDL_AllocPalette((1 << surface->format->BitsPerPixel));
    73             SDL_AllocPalette((1 << surface->format->BitsPerPixel));
    74         if (!palette) {
    74         if (!palette) {
    75             SDL_FreeSurface(surface);
    75             SDL_FreeSurface(surface);
    76             return NULL;
    76             return NULL;
    77         }
    77         }
    78         if (Rmask || Bmask || Gmask) {
    78         if (palette->ncolors == 2) {
    79             const SDL_PixelFormat *format = surface->format;
       
    80 
       
    81             /* create palette according to masks */
       
    82             int i;
       
    83             int Rm = 0, Gm = 0, Bm = 0;
       
    84             int Rw = 0, Gw = 0, Bw = 0;
       
    85 
       
    86             if (Rmask) {
       
    87                 Rw = 8 - format->Rloss;
       
    88                 for (i = format->Rloss; i > 0; i -= Rw)
       
    89                     Rm |= 1 << i;
       
    90             }
       
    91             if (Gmask) {
       
    92                 Gw = 8 - format->Gloss;
       
    93                 for (i = format->Gloss; i > 0; i -= Gw)
       
    94                     Gm |= 1 << i;
       
    95             }
       
    96             if (Bmask) {
       
    97                 Bw = 8 - format->Bloss;
       
    98                 for (i = format->Bloss; i > 0; i -= Bw)
       
    99                     Bm |= 1 << i;
       
   100             }
       
   101             for (i = 0; i < palette->ncolors; ++i) {
       
   102                 int r, g, b;
       
   103                 r = (i & Rmask) >> format->Rshift;
       
   104                 r = (r << format->Rloss) | ((r * Rm) >> Rw);
       
   105                 palette->colors[i].r = r;
       
   106 
       
   107                 g = (i & Gmask) >> format->Gshift;
       
   108                 g = (g << format->Gloss) | ((g * Gm) >> Gw);
       
   109                 palette->colors[i].g = g;
       
   110 
       
   111                 b = (i & Bmask) >> format->Bshift;
       
   112                 b = (b << format->Bloss) | ((b * Bm) >> Bw);
       
   113                 palette->colors[i].b = b;
       
   114             }
       
   115         } else if (palette->ncolors == 2) {
       
   116             /* Create a black and white bitmap palette */
    79             /* Create a black and white bitmap palette */
   117             palette->colors[0].r = 0xFF;
    80             palette->colors[0].r = 0xFF;
   118             palette->colors[0].g = 0xFF;
    81             palette->colors[0].g = 0xFF;
   119             palette->colors[0].b = 0xFF;
    82             palette->colors[0].b = 0xFF;
   120             palette->colors[1].r = 0x00;
    83             palette->colors[1].r = 0x00;