simplify and hopefully fix a crash
This commit is contained in:
@@ -232,8 +232,7 @@ SDL_Surface *SDL_CreateRGBSurfaceSane
|
|||||||
return SDL_CreateRGBSurface(flags, width, height, depth,
|
return SDL_CreateRGBSurface(flags, width, height, depth,
|
||||||
Rmask, Gmask, Bmask, Amask);
|
Rmask, Gmask, Bmask, Amask);
|
||||||
}
|
}
|
||||||
|
static void FindAlphaRGB(const SDL_Surface *img, Uint8 &r, Uint8 &g, Uint8 &b, bool reverse)
|
||||||
static void FindAlphaRGB(SDL_Surface *img, Uint8 &r, Uint8 &g, Uint8 &b, bool reverse)
|
|
||||||
{
|
{
|
||||||
/* If we have no alpha or no color key, there's no alpha color. */
|
/* If we have no alpha or no color key, there's no alpha color. */
|
||||||
if(img->format->BitsPerPixel == 8 && !(img->flags & SDL_SRCCOLORKEY))
|
if(img->format->BitsPerPixel == 8 && !(img->flags & SDL_SRCCOLORKEY))
|
||||||
@@ -247,26 +246,18 @@ static void FindAlphaRGB(SDL_Surface *img, Uint8 &r, Uint8 &g, Uint8 &b, bool re
|
|||||||
{
|
{
|
||||||
Uint8 *row = (Uint8 *)img->pixels + img->pitch*y;
|
Uint8 *row = (Uint8 *)img->pixels + img->pitch*y;
|
||||||
if(reverse)
|
if(reverse)
|
||||||
row += img->format->BytesPerPixel * img->w;
|
row += img->format->BytesPerPixel * (img->w-1);
|
||||||
|
|
||||||
for(int x = 0; x < img->w; ++x)
|
for(int x = 0; x < img->w; ++x)
|
||||||
{
|
{
|
||||||
if(img->format->BitsPerPixel == 8 && img->format->colorkey != *row)
|
|
||||||
{
|
|
||||||
/* This color isn't the color key, so grab it. */
|
|
||||||
r = img->format->palette->colors[*row].r;
|
|
||||||
g = img->format->palette->colors[*row].g;
|
|
||||||
b = img->format->palette->colors[*row].b;
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
Uint32 val = decodepixel(row, img->format->BytesPerPixel);
|
Uint32 val = decodepixel(row, img->format->BytesPerPixel);
|
||||||
if(val & img->format->Amask)
|
if((img->format->BitsPerPixel == 8 && val != img->format->colorkey) ||
|
||||||
|
(img->format->BitsPerPixel != 8 && val & img->format->Amask))
|
||||||
{
|
{
|
||||||
/* This color isn't fully transparent, so grab it. */
|
/* This color isn't fully transparent, so grab it. */
|
||||||
SDL_GetRGB(val, img->format, &r, &g, &b);
|
SDL_GetRGB(val, img->format, &r, &g, &b);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(reverse)
|
if(reverse)
|
||||||
row -= img->format->BytesPerPixel;
|
row -= img->format->BytesPerPixel;
|
||||||
@@ -281,7 +272,7 @@ static void FindAlphaRGB(SDL_Surface *img, Uint8 &r, Uint8 &g, Uint8 &b, bool re
|
|||||||
|
|
||||||
/* Set the underlying RGB values of all pixels in 'img' that are
|
/* Set the underlying RGB values of all pixels in 'img' that are
|
||||||
* completely transparent. */
|
* completely transparent. */
|
||||||
static void SetAlphaRGB(SDL_Surface *img, Uint8 r, Uint8 g, Uint8 b)
|
static void SetAlphaRGB(const SDL_Surface *img, Uint8 r, Uint8 g, Uint8 b)
|
||||||
{
|
{
|
||||||
/* If it's a paletted surface, all we have to do is change the
|
/* If it's a paletted surface, all we have to do is change the
|
||||||
* colorkey, if any. */
|
* colorkey, if any. */
|
||||||
|
|||||||
Reference in New Issue
Block a user