src/video/SDL_pixels.c
changeset 5436 29977c050731
parent 5433 1b6eee840e26
child 5437 ce10653e370c
equal deleted inserted replaced
5435:3de226f0cc06 5436:29977c050731
   766         v = (pixel & format->Gmask) >> format->Gshift;
   766         v = (pixel & format->Gmask) >> format->Gshift;
   767         *g = (v << format->Gloss) + (v >> (8 - (format->Gloss << 1)));
   767         *g = (v << format->Gloss) + (v >> (8 - (format->Gloss << 1)));
   768         v = (pixel & format->Bmask) >> format->Bshift;
   768         v = (pixel & format->Bmask) >> format->Bshift;
   769         *b = (v << format->Bloss) + (v >> (8 - (format->Bloss << 1)));
   769         *b = (v << format->Bloss) + (v >> (8 - (format->Bloss << 1)));
   770     } else {
   770     } else {
   771         *r = format->palette->colors[pixel].r;
   771         if (pixel < format->palette->ncolors) {
   772         *g = format->palette->colors[pixel].g;
   772             *r = format->palette->colors[pixel].r;
   773         *b = format->palette->colors[pixel].b;
   773             *g = format->palette->colors[pixel].g;
       
   774             *b = format->palette->colors[pixel].b;
       
   775         } else {
       
   776             *r = *g = *b = 0;
       
   777         }
   774     }
   778     }
   775 }
   779 }
   776 
   780 
   777 void
   781 void
   778 SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat * format,
   782 SDL_GetRGBA(Uint32 pixel, const SDL_PixelFormat * format,
   800             *a = (v << format->Aloss) + (v >> (8 - (format->Aloss << 1)));
   804             *a = (v << format->Aloss) + (v >> (8 - (format->Aloss << 1)));
   801         } else {
   805         } else {
   802             *a = SDL_ALPHA_OPAQUE;
   806             *a = SDL_ALPHA_OPAQUE;
   803         }
   807         }
   804     } else {
   808     } else {
   805         *r = format->palette->colors[pixel].r;
   809         if (pixel < format->palette->ncolors) {
   806         *g = format->palette->colors[pixel].g;
   810             *r = format->palette->colors[pixel].r;
   807         *b = format->palette->colors[pixel].b;
   811             *g = format->palette->colors[pixel].g;
   808         *a = SDL_ALPHA_OPAQUE;
   812             *b = format->palette->colors[pixel].b;
       
   813             *a = SDL_ALPHA_OPAQUE;
       
   814         } else {
       
   815             *r = *g = *b = *a = 0;
       
   816         }
   809     }
   817     }
   810 }
   818 }
   811 
   819 
   812 /* Map from Palette to Palette */
   820 /* Map from Palette to Palette */
   813 static Uint8 *
   821 static Uint8 *