src/video/SDL_surface.c
changeset 7023 1d49dc7b5ce9
parent 6920 a966229b4107
child 7024 72cb3e205571
equal deleted inserted replaced
7022:d9f3d2e3bd07 7023:1d49dc7b5ce9
   185 
   185 
   186     flags = surface->map->info.flags;
   186     flags = surface->map->info.flags;
   187     if (flag) {
   187     if (flag) {
   188         surface->map->info.flags |= SDL_COPY_COLORKEY;
   188         surface->map->info.flags |= SDL_COPY_COLORKEY;
   189         surface->map->info.colorkey = key;
   189         surface->map->info.colorkey = key;
       
   190         if (surface->format->palette) {
       
   191             surface->format->palette->colors[surface->map->info.colorkey].unused = SDL_ALPHA_TRANSPARENT;
       
   192         }
   190     } else {
   193     } else {
       
   194         if (surface->format->palette) {
       
   195             surface->format->palette->colors[surface->map->info.colorkey].unused = SDL_ALPHA_OPAQUE;
       
   196         }
   191         surface->map->info.flags &= ~SDL_COPY_COLORKEY;
   197         surface->map->info.flags &= ~SDL_COPY_COLORKEY;
   192     }
   198     }
   193     if (surface->map->info.flags != flags) {
   199     if (surface->map->info.flags != flags) {
   194         SDL_InvalidateMap(surface->map);
   200         SDL_InvalidateMap(surface->map);
   195     }
   201     }
   841          ~(SDL_COPY_COLORKEY | SDL_COPY_BLEND
   847          ~(SDL_COPY_COLORKEY | SDL_COPY_BLEND
   842            | SDL_COPY_RLE_DESIRED | SDL_COPY_RLE_COLORKEY |
   848            | SDL_COPY_RLE_DESIRED | SDL_COPY_RLE_COLORKEY |
   843            SDL_COPY_RLE_ALPHAKEY));
   849            SDL_COPY_RLE_ALPHAKEY));
   844     surface->map->info.flags = copy_flags;
   850     surface->map->info.flags = copy_flags;
   845     if (copy_flags & SDL_COPY_COLORKEY) {
   851     if (copy_flags & SDL_COPY_COLORKEY) {
   846         Uint8 keyR, keyG, keyB, keyA;
   852         SDL_bool set_colorkey_by_color = SDL_FALSE;
   847 
   853 
   848         SDL_GetRGBA(surface->map->info.colorkey, surface->format, &keyR,
   854         if (surface->format->palette) {
   849                     &keyG, &keyB, &keyA);
   855             if (format->palette && 
   850         SDL_SetColorKey(convert, 1,
   856                 surface->format->palette->ncolors <= format->palette->ncolors &&
   851                         SDL_MapRGBA(convert->format, keyR, keyG, keyB, keyA));
   857                 (SDL_memcmp(surface->format->palette->colors, format->palette->colors,
   852         /* This is needed when converting for 3D texture upload */
   858                   surface->format->palette->ncolors * sizeof(SDL_Color)) == 0)) {
   853         SDL_ConvertColorkeyToAlpha(convert);
   859                 /* The palette is identical, just set the same colorkey */
       
   860                 SDL_SetColorKey(convert, 1, surface->map->info.colorkey);
       
   861             } else if (format->Amask) {
       
   862                 /* The alpha was set in the destination from the palette */
       
   863             } else {
       
   864                 set_colorkey_by_color = SDL_TRUE;
       
   865             }
       
   866         } else {
       
   867             set_colorkey_by_color = SDL_TRUE;
       
   868         }
       
   869 
       
   870         if (set_colorkey_by_color) {
       
   871             /* Set the colorkey by color, which needs to be unique */
       
   872             Uint8 keyR, keyG, keyB, keyA;
       
   873 
       
   874             SDL_GetRGBA(surface->map->info.colorkey, surface->format, &keyR,
       
   875                         &keyG, &keyB, &keyA);
       
   876             SDL_SetColorKey(convert, 1,
       
   877                             SDL_MapRGBA(convert->format, keyR, keyG, keyB, keyA));
       
   878             /* This is needed when converting for 3D texture upload */
       
   879             SDL_ConvertColorkeyToAlpha(convert);
       
   880         }
   854     }
   881     }
   855     SDL_SetClipRect(convert, &surface->clip_rect);
   882     SDL_SetClipRect(convert, &surface->clip_rect);
   856 
   883 
   857     /* Enable alpha blending by default if the new surface has an
   884     /* Enable alpha blending by default if the new surface has an
   858      * alpha channel or alpha modulation */
   885      * alpha channel or alpha modulation */