src/video/SDL_video.c
changeset 2267 c785543d1843
parent 2266 e61ad15a205f
child 2324 3202e4826c57
     1.1 --- a/src/video/SDL_video.c	Sat Aug 18 01:44:21 2007 +0000
     1.2 +++ b/src/video/SDL_video.c	Sat Aug 18 05:39:09 2007 +0000
     1.3 @@ -1552,7 +1552,9 @@
     1.4              return 0;
     1.5          }
     1.6      } else {
     1.7 -        if (surface->format->Amask || !(flags & (SDL_COPY_COLORKEY|SDL_COPY_MASK|SDL_COPY_BLEND))) {
     1.8 +        if (surface->format->Amask
     1.9 +            || !(surface->map->info.flags &
    1.10 +                 (SDL_COPY_COLORKEY | SDL_COPY_MASK | SDL_COPY_BLEND))) {
    1.11              bpp = fmt->BitsPerPixel;
    1.12              Rmask = fmt->Rmask;
    1.13              Gmask = fmt->Gmask;
    1.14 @@ -1602,31 +1604,34 @@
    1.15          dst_fmt = SDL_AllocFormat(bpp, Rmask, Gmask, Bmask, Amask);
    1.16          if (dst_fmt) {
    1.17              if (SDL_ISPIXELFORMAT_INDEXED(format)) {
    1.18 -                dst_fmt->palette = SDL_AllocPalette((1 << SDL_BITSPERPIXEL(format)));
    1.19 +                dst_fmt->palette =
    1.20 +                    SDL_AllocPalette((1 << SDL_BITSPERPIXEL(format)));
    1.21                  if (dst_fmt->palette) {
    1.22 -                    if (fmt->palette) {
    1.23 -fixme
    1.24 -                    } else {
    1.25 -                        SDL_DitherColors(dst_fmt->palette->colors, SDL_BITSPERPIXEL(format));
    1.26 -                    }
    1.27 -                }
    1.28 -                if (fmt->palette) {
    1.29 -                    dst_fmt->palette = fmt->palette;
    1.30 -                } else {
    1.31 +                    /* FIXME: Should we try to copy fmt->palette? */
    1.32 +                    SDL_DitherColors(dst_fmt->palette->colors,
    1.33 +                                     SDL_BITSPERPIXEL(format));
    1.34                  }
    1.35              }
    1.36  
    1.37 -            cvt = SDL_ConvertSurface(surface, fmt, 0);
    1.38 -            if (cvt) {
    1.39 -                SDL_UpdateTexture(textureID, NULL, cvt->pixels, cvt->pitch);
    1.40 -                SDL_FreeSurface(cvt);
    1.41 +            dst = SDL_ConvertSurface(surface, dst_fmt, 0);
    1.42 +            if (dst) {
    1.43 +                SDL_UpdateTexture(textureID, NULL, dst->pixels, dst->pitch);
    1.44 +                SDL_FreeSurface(dst);
    1.45              }
    1.46 -            SDL_FreeFormat(fmt);
    1.47 +            if (dst_fmt->palette) {
    1.48 +                SDL_FreePalette(dst_fmt->palette);
    1.49 +            }
    1.50 +            SDL_FreeFormat(dst_fmt);
    1.51 +        }
    1.52 +        if (!dst) {
    1.53 +            SDL_DestroyTexture(textureID);
    1.54 +            return 0;
    1.55          }
    1.56      }
    1.57  
    1.58      if (SDL_ISPIXELFORMAT_INDEXED(format) && fmt->palette) {
    1.59 -        SDL_SetTexturePalette(textureID, fmt->palette->colors, 0, fmt->palette->ncolors);
    1.60 +        SDL_SetTexturePalette(textureID, fmt->palette->colors, 0,
    1.61 +                              fmt->palette->ncolors);
    1.62      }
    1.63  
    1.64      return textureID;