src/video/SDL_surface.c
changeset 7601 fdf89883bbaa
parent 7511 4ce3cc948a00
child 7602 9829fb1aeac7
equal deleted inserted replaced
7600:55afbc8f2a65 7601:fdf89883bbaa
   253         {
   253         {
   254             Uint16 *row, *spot;
   254             Uint16 *row, *spot;
   255             Uint16 ckey = (Uint16) surface->map->info.colorkey;
   255             Uint16 ckey = (Uint16) surface->map->info.colorkey;
   256             Uint16 mask = (Uint16) (~surface->format->Amask);
   256             Uint16 mask = (Uint16) (~surface->format->Amask);
   257 
   257 
       
   258             /* Ignore alpha in colorkey comparison */
       
   259             ckey &= mask;
   258             row = (Uint16 *) surface->pixels;
   260             row = (Uint16 *) surface->pixels;
   259             for (y = surface->h; y--;) {
   261             for (y = surface->h; y--;) {
   260                 spot = row;
   262                 spot = row;
   261                 for (x = surface->w; x--;) {
   263                 for (x = surface->w; x--;) {
   262                     if (*spot == ckey) {
   264                     if ((*spot & mask) == ckey) {
   263                         *spot &= mask;
   265                         *spot &= mask;
   264                     }
   266                     }
   265                     ++spot;
   267                     ++spot;
   266                 }
   268                 }
   267                 row += surface->pitch / 2;
   269                 row += surface->pitch / 2;
   275         {
   277         {
   276             Uint32 *row, *spot;
   278             Uint32 *row, *spot;
   277             Uint32 ckey = surface->map->info.colorkey;
   279             Uint32 ckey = surface->map->info.colorkey;
   278             Uint32 mask = ~surface->format->Amask;
   280             Uint32 mask = ~surface->format->Amask;
   279 
   281 
       
   282             /* Ignore alpha in colorkey comparison */
       
   283             ckey &= mask;
   280             row = (Uint32 *) surface->pixels;
   284             row = (Uint32 *) surface->pixels;
   281             for (y = surface->h; y--;) {
   285             for (y = surface->h; y--;) {
   282                 spot = row;
   286                 spot = row;
   283                 for (x = surface->w; x--;) {
   287                 for (x = surface->w; x--;) {
       
   288                     if ((*spot & mask) == ckey) {
   284                     if (*spot == ckey) {
   289                     if (*spot == ckey) {
   285                         *spot &= mask;
   290                         *spot &= mask;
   286                     }
   291                     }
   287                     ++spot;
   292                     ++spot;
   288                 }
   293                 }
   800 SDL_ConvertSurface(SDL_Surface * surface, SDL_PixelFormat * format,
   805 SDL_ConvertSurface(SDL_Surface * surface, SDL_PixelFormat * format,
   801                    Uint32 flags)
   806                    Uint32 flags)
   802 {
   807 {
   803     SDL_Surface *convert;
   808     SDL_Surface *convert;
   804     Uint32 copy_flags;
   809     Uint32 copy_flags;
       
   810     SDL_Color copy_color;
   805     SDL_Rect bounds;
   811     SDL_Rect bounds;
   806 
   812 
   807     /* Check for empty destination palette! (results in empty image) */
   813     /* Check for empty destination palette! (results in empty image) */
   808     if (format->palette != NULL) {
   814     if (format->palette != NULL) {
   809         int i;
   815         int i;
   836         convert->format->palette->ncolors = format->palette->ncolors;
   842         convert->format->palette->ncolors = format->palette->ncolors;
   837     }
   843     }
   838 
   844 
   839     /* Save the original copy flags */
   845     /* Save the original copy flags */
   840     copy_flags = surface->map->info.flags;
   846     copy_flags = surface->map->info.flags;
       
   847     copy_color.r = surface->map->info.r;
       
   848     copy_color.g = surface->map->info.g;
       
   849     copy_color.b = surface->map->info.b;
       
   850     copy_color.a = surface->map->info.a;
       
   851     surface->map->info.r = 0xFF;
       
   852     surface->map->info.g = 0xFF;
       
   853     surface->map->info.b = 0xFF;
       
   854     surface->map->info.a = 0xFF;
   841     surface->map->info.flags = 0;
   855     surface->map->info.flags = 0;
       
   856     SDL_InvalidateMap(surface->map);
   842 
   857 
   843     /* Copy over the image data */
   858     /* Copy over the image data */
   844     bounds.x = 0;
   859     bounds.x = 0;
   845     bounds.y = 0;
   860     bounds.y = 0;
   846     bounds.w = surface->w;
   861     bounds.w = surface->w;
   847     bounds.h = surface->h;
   862     bounds.h = surface->h;
   848     SDL_LowerBlit(surface, &bounds, convert, &bounds);
   863     SDL_LowerBlit(surface, &bounds, convert, &bounds);
   849 
   864 
   850     /* Clean up the original surface, and update converted surface */
   865     /* Clean up the original surface, and update converted surface */
   851     convert->map->info.r = surface->map->info.r;
   866     convert->map->info.r = copy_color.r;
   852     convert->map->info.g = surface->map->info.g;
   867     convert->map->info.g = copy_color.g;
   853     convert->map->info.b = surface->map->info.b;
   868     convert->map->info.b = copy_color.b;
   854     convert->map->info.a = surface->map->info.a;
   869     convert->map->info.a = copy_color.a;
   855     convert->map->info.flags =
   870     convert->map->info.flags =
   856         (copy_flags &
   871         (copy_flags &
   857          ~(SDL_COPY_COLORKEY | SDL_COPY_BLEND
   872          ~(SDL_COPY_COLORKEY | SDL_COPY_BLEND
   858            | SDL_COPY_RLE_DESIRED | SDL_COPY_RLE_COLORKEY |
   873            | SDL_COPY_RLE_DESIRED | SDL_COPY_RLE_COLORKEY |
   859            SDL_COPY_RLE_ALPHAKEY));
   874            SDL_COPY_RLE_ALPHAKEY));
       
   875     surface->map->info.r = copy_color.r;
       
   876     surface->map->info.g = copy_color.g;
       
   877     surface->map->info.b = copy_color.b;
       
   878     surface->map->info.a = copy_color.a;
   860     surface->map->info.flags = copy_flags;
   879     surface->map->info.flags = copy_flags;
       
   880     SDL_InvalidateMap(surface->map);
   861     if (copy_flags & SDL_COPY_COLORKEY) {
   881     if (copy_flags & SDL_COPY_COLORKEY) {
   862         SDL_bool set_colorkey_by_color = SDL_FALSE;
   882         SDL_bool set_colorkey_by_color = SDL_FALSE;
   863 
   883 
   864         if (surface->format->palette) {
   884         if (surface->format->palette) {
   865             if (format->palette &&
   885             if (format->palette &&