src/video/SDL_surface.c
branchSDL-1.3
changeset 1670 eef792d31de8
parent 1668 4da1ee79c9af
child 1672 8e754b82cecc
     1.1 --- a/src/video/SDL_surface.c	Mon May 29 05:08:33 2006 +0000
     1.2 +++ b/src/video/SDL_surface.c	Wed Jun 07 16:10:28 2006 +0000
     1.3 @@ -43,6 +43,7 @@
     1.4      SDL_Surface *screen;
     1.5      SDL_Surface *surface;
     1.6  
     1.7 +    /* FIXME!! */
     1.8      /* Make sure the size requested doesn't overflow our datatypes */
     1.9      /* Next time I write a library like SDL, I'll use int for size. :) */
    1.10      if (width >= 16384 || height >= 65536) {
    1.11 @@ -50,52 +51,13 @@
    1.12          return (NULL);
    1.13      }
    1.14  
    1.15 -    /* Check to see if we desire the surface in video memory */
    1.16 -    if (_this) {
    1.17 -        screen = SDL_PublicSurface;
    1.18 -    } else {
    1.19 -        screen = NULL;
    1.20 -    }
    1.21 -    if (screen && ((screen->flags & SDL_HWSURFACE) == SDL_HWSURFACE)) {
    1.22 -        if ((flags & (SDL_SRCCOLORKEY | SDL_SRCALPHA)) != 0) {
    1.23 -            flags |= SDL_HWSURFACE;
    1.24 -        }
    1.25 -        if ((flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
    1.26 -            if (!_this->info.blit_hw_CC) {
    1.27 -                flags &= ~SDL_HWSURFACE;
    1.28 -            }
    1.29 -        }
    1.30 -        if ((flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
    1.31 -            if (!_this->info.blit_hw_A) {
    1.32 -                flags &= ~SDL_HWSURFACE;
    1.33 -            }
    1.34 -        }
    1.35 -    } else {
    1.36 -        flags &= ~SDL_HWSURFACE;
    1.37 -    }
    1.38 -
    1.39      /* Allocate the surface */
    1.40      surface = (SDL_Surface *) SDL_malloc(sizeof(*surface));
    1.41      if (surface == NULL) {
    1.42          SDL_OutOfMemory();
    1.43          return (NULL);
    1.44      }
    1.45 -    surface->flags = SDL_SWSURFACE;
    1.46 -    if ((flags & SDL_HWSURFACE) == SDL_HWSURFACE) {
    1.47 -        if ((Amask) && (_this->displayformatalphapixel)) {
    1.48 -            depth = _this->displayformatalphapixel->BitsPerPixel;
    1.49 -            Rmask = _this->displayformatalphapixel->Rmask;
    1.50 -            Gmask = _this->displayformatalphapixel->Gmask;
    1.51 -            Bmask = _this->displayformatalphapixel->Bmask;
    1.52 -            Amask = _this->displayformatalphapixel->Amask;
    1.53 -        } else {
    1.54 -            depth = screen->format->BitsPerPixel;
    1.55 -            Rmask = screen->format->Rmask;
    1.56 -            Gmask = screen->format->Gmask;
    1.57 -            Bmask = screen->format->Bmask;
    1.58 -            Amask = screen->format->Amask;
    1.59 -        }
    1.60 -    }
    1.61 +    surface->flags = 0;
    1.62      surface->format = SDL_AllocFormat(depth, Rmask, Gmask, Bmask, Amask);
    1.63      if (surface->format == NULL) {
    1.64          SDL_free(surface);
    1.65 @@ -108,27 +70,22 @@
    1.66      surface->h = height;
    1.67      surface->pitch = SDL_CalculatePitch(surface);
    1.68      surface->pixels = NULL;
    1.69 -    surface->offset = 0;
    1.70      surface->hwdata = NULL;
    1.71      surface->locked = 0;
    1.72      surface->map = NULL;
    1.73 -    surface->unused1 = 0;
    1.74      SDL_SetClipRect(surface, NULL);
    1.75      SDL_FormatChanged(surface);
    1.76  
    1.77      /* Get the pixels */
    1.78 -    if (((flags & SDL_HWSURFACE) == SDL_SWSURFACE) ||
    1.79 -        (_this->AllocHWSurface(_this, surface) < 0)) {
    1.80 -        if (surface->w && surface->h) {
    1.81 -            surface->pixels = SDL_malloc(surface->h * surface->pitch);
    1.82 -            if (surface->pixels == NULL) {
    1.83 -                SDL_FreeSurface(surface);
    1.84 -                SDL_OutOfMemory();
    1.85 -                return (NULL);
    1.86 -            }
    1.87 -            /* This is important for bitmaps */
    1.88 -            SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
    1.89 +    if (surface->w && surface->h) {
    1.90 +        surface->pixels = SDL_malloc(surface->h * surface->pitch);
    1.91 +        if (surface->pixels == NULL) {
    1.92 +            SDL_FreeSurface(surface);
    1.93 +            SDL_OutOfMemory();
    1.94 +            return NULL;
    1.95          }
    1.96 +        /* This is important for bitmaps */
    1.97 +        SDL_memset(surface->pixels, 0, surface->h * surface->pitch);
    1.98      }
    1.99  
   1.100      /* Allocate an empty mapping */
   1.101 @@ -167,7 +124,72 @@
   1.102          surface->pitch = pitch;
   1.103          SDL_SetClipRect(surface, NULL);
   1.104      }
   1.105 -    return (surface);
   1.106 +    return surface;
   1.107 +}
   1.108 +
   1.109 +SDL_Surface *
   1.110 +SDL_CreateRGBSurfaceFromTexture(SDL_TextureID textureID)
   1.111 +{
   1.112 +    SDL_Surface *surface;
   1.113 +    Uint32 format;
   1.114 +    int w, h;
   1.115 +    int bpp;
   1.116 +    Uint32 Rmask, Gmask, Bmask, Amask;
   1.117 +
   1.118 +    if (SDL_QueryTexture(textureID, &format, NULL, &w, &h) < 0) {
   1.119 +        return NULL;
   1.120 +    }
   1.121 +
   1.122 +    if (!SDL_PixelFormatEnumToMasks
   1.123 +        (format, &bpp, &Rmask, &Gmask, &Bmask, &Amask)) {
   1.124 +        SDL_SetError("Unknown texture format");
   1.125 +        return NULL;
   1.126 +    }
   1.127 +
   1.128 +    surface = SDL_CreateRGBSurface(SDL_SWSURFACE, 0, 0, bpp,
   1.129 +                                   Rmask, Gmask, Bmask, Amask);
   1.130 +    if (surface != NULL) {
   1.131 +        surface->flags |= (SDL_HWSURFACE | SDL_PREALLOC);
   1.132 +        surface->w = width;
   1.133 +        surface->h = height;
   1.134 +        SDL_SetClipRect(surface, NULL);
   1.135 +    }
   1.136 +    return surface;
   1.137 +}
   1.138 +
   1.139 +/*
   1.140 + * Set the palette in a blittable surface
   1.141 + */
   1.142 +int
   1.143 +SDL_SetColors(SDL_Surface * surface, SDL_Color * colors, int firstcolor,
   1.144 +              int ncolors)
   1.145 +{
   1.146 +    SDL_Palette *pal;
   1.147 +    int gotall;
   1.148 +    int palsize;
   1.149 +
   1.150 +    /* Verify the parameters */
   1.151 +    pal = surface->format->palette;
   1.152 +    if (!pal) {
   1.153 +        return 0;               /* not a palettized surface */
   1.154 +    }
   1.155 +    gotall = 1;
   1.156 +    palsize = 1 << surface->format->BitsPerPixel;
   1.157 +    if (ncolors > (palsize - firstcolor)) {
   1.158 +        ncolors = (palsize - firstcolor);
   1.159 +        gotall = 0;
   1.160 +    }
   1.161 +
   1.162 +    if (colors != (pal->colors + firstcolor)) {
   1.163 +        SDL_memcpy(pal->colors + firstcolor, colors,
   1.164 +                   ncolors * sizeof(*colors));
   1.165 +    }
   1.166 +    SDL_FormatChanged(surface);
   1.167 +
   1.168 +    if (surface->flags & (SDL_SHADOW_SURFACE | SDL_SCREEN_SURFACE)) {
   1.169 +        gotall &= SDL_SetScreenColors(surface, colors, firstcolor, ncolors);
   1.170 +    }
   1.171 +    return gotall;
   1.172  }
   1.173  
   1.174  /*