Uint8 alpha = 0;
if(request.alpha != 1.0)
{
+#if SDL_VERSION_ATLEAST(1,3,0)
+ Uint8 tmp;
+ SDL_GetSurfaceAlphaMod (transform, &alpha);
+ tmp = (Uint8) (((double) alpha) * request.alpha + .5);
+ SDL_SetSurfaceAlphaMod (transform, tmp);
+#else
if(!transform->format->Amask)
{
if(transform->flags & SDL_SRCALPHA)
{
transform = apply_alpha(transform, request.alpha);
}*/
+#endif
}
SDL_BlitSurface(transform, src_rect, screen, &dst_rect);
{
if(transform->flags & SDL_SRCALPHA)
{
+#if SDL_VERSION_ATLEAST(1,3,0)
+ SDL_GetSurfaceAlphaMod (transform, &alpha);
+#else
alpha = transform->format->alpha;
+#endif
}
else
{
} // namespace
#endif
+static void surface_copy_alpha (SDL_Surface *dst, SDL_Surface *src)
+{
+#if SDL_VERSION_ATLEAST(1,3,0)
+ Uint8 alpha;
+ int status;
+
+ alpha = 255;
+ status = SDL_GetSurfaceAlphaMod (src, &alpha);
+ if (status == 0)
+ SDL_SetSurfaceAlphaMod (dst, alpha);
+#else
+ SDL_SetAlpha(dst, SDL_SRCALPHA | SDL_RLEACCEL, src->format->alpha);
+#endif
+}
+
+static void surface_copy_colorkey (SDL_Surface *dst, SDL_Surface *src)
+{
+#if SDL_VERSION_ATLEAST(1,3,0)
+ Uint32 colorkey;
+ int status;
+
+ colorkey = 0;
+ /* Returns non-zero if color key is disabled. */
+ status = SDL_GetColorKey (src, &colorkey);
+ if (status == 0)
+ SDL_SetColorKey (dst, /* enabled = */ 1, colorkey);
+#else
+ SDL_SetColorKey(dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, src->format->colorkey);
+#endif
+}
+
#ifdef BILINEAR
void getpixel(SDL_Surface *src, int srcx, int srcy, Uint8 color[4])
{
{
if(src->flags & SDL_SRCALPHA)
{
- SDL_SetAlpha(dst, SDL_SRCALPHA | SDL_RLEACCEL, src->format->alpha);
+ surface_copy_alpha (dst, src);
}
if(src->flags & SDL_SRCCOLORKEY)
{
- SDL_SetColorKey(dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, src->format->colorkey);
+ surface_copy_colorkey (dst, src);
}
}
return dst;
}
}
-#endif
+#endif /* BILINEAR */
SDL_Surface *horz_flip(SDL_Surface *src)
{
{
if(src->flags & SDL_SRCALPHA)
{
- SDL_SetAlpha(dst, SDL_SRCALPHA | SDL_RLEACCEL, src->format->alpha);
+ surface_copy_alpha (dst, src);
}
if(src->flags & SDL_SRCCOLORKEY)
{
- SDL_SetColorKey(dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, src->format->colorkey);
+ surface_copy_colorkey (dst, src);
}
}
return dst;
{
if(src->flags & SDL_SRCALPHA)
{
- SDL_SetAlpha(dst, SDL_SRCALPHA | SDL_RLEACCEL, src->format->alpha);
+ surface_copy_alpha (dst, src);
}
if(src->flags & SDL_SRCCOLORKEY)
{
- SDL_SetColorKey(dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, src->format->colorkey);
+ surface_copy_colorkey (dst, src);
}
}
return dst;
SDL_Surface *colorize(SDL_Surface *src, const Color &color)
{
+ SDL_Surface *dst = SDL_CreateRGBSurface(src->flags, src->w, src->h, src->format->BitsPerPixel, src->format->Rmask, src->format->Gmask, src->format->Bmask, src->format->Amask);
+#if SDL_VERSION_ATLEAST(1,3,0)
+ assert ((color.red >= 0) && (color.red <= 1.0));
+ assert ((color.green >= 0) && (color.green <= 1.0));
+ assert ((color.blue >= 0) && (color.blue <= 1.0));
+ assert(color.red != 1.0 || color.green != 1.0 || color.blue != 1.0);
+ Uint8 red = (Uint8) (color.red * 255.0);
+ Uint8 green = (Uint8) (color.green * 255.0);
+ Uint8 blue = (Uint8) (color.blue * 255.0);
+
+ SDL_SetSurfaceColorMod (dst, red, green, blue);
+#else
// FIXME: This is really slow
assert(color.red != 1.0 || color.green != 1.0 || color.blue != 1.0);
int red = (int) (color.red * 256);
int green = (int) (color.green * 256);
int blue = (int) (color.blue * 256);
- SDL_Surface *dst = SDL_CreateRGBSurface(src->flags, src->w, src->h, src->format->BitsPerPixel, src->format->Rmask, src->format->Gmask, src->format->Bmask, src->format->Amask);
int bpp = dst->format->BytesPerPixel;
if(SDL_MUSTLOCK(src))
{
}
}
}
+#endif /* SDL version < 1.3.0 */
if(SDL_MUSTLOCK(dst))
{
SDL_UnlockSurface(dst);
{
if(src->flags & SDL_SRCALPHA)
{
- SDL_SetAlpha(dst, SDL_SRCALPHA | SDL_RLEACCEL, src->format->alpha);
+ surface_copy_alpha (dst, src);
}
if(src->flags & SDL_SRCCOLORKEY)
{
- SDL_SetColorKey(dst, SDL_SRCCOLORKEY | SDL_RLEACCEL, src->format->colorkey);
+ surface_copy_colorkey (dst, src);
}
}
return dst;