Fixed bug with converting colorkey surface to texture
--HG-- extra : convert_revision : svn%3Ac70aab31-4412-0410-b14c-859654838e24/trunk%403246
This commit is contained in:
parent
f341bd32dd
commit
de690ebe5d
2 changed files with 70 additions and 0 deletions
|
@ -269,6 +269,72 @@ SDL_SetColorKey(SDL_Surface * surface, Uint32 flag, Uint32 key)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* This is a fairly slow function to switch from colorkey to alpha */
|
||||||
|
void
|
||||||
|
SDL_ConvertColorkeyToAlpha(SDL_Surface *surface)
|
||||||
|
{
|
||||||
|
int x, y;
|
||||||
|
|
||||||
|
if (!surface) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(surface->map->info.flags & SDL_COPY_COLORKEY) ||
|
||||||
|
!surface->format->Amask) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_LockSurface(surface);
|
||||||
|
|
||||||
|
switch (surface->format->BytesPerPixel) {
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
Uint16 *row, *spot;
|
||||||
|
Uint16 ckey = (Uint16)surface->map->info.colorkey;
|
||||||
|
Uint16 mask = (Uint16)(~surface->format->Amask);
|
||||||
|
|
||||||
|
row = (Uint16 *)surface->pixels;
|
||||||
|
for (y = surface->h; y--; ) {
|
||||||
|
spot = row;
|
||||||
|
for (x = surface->w; x--; ) {
|
||||||
|
if (*spot == ckey) {
|
||||||
|
*spot &= mask;
|
||||||
|
}
|
||||||
|
++spot;
|
||||||
|
}
|
||||||
|
row += surface->pitch / 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
/* FIXME */
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
{
|
||||||
|
Uint32 *row, *spot;
|
||||||
|
Uint32 ckey = surface->map->info.colorkey;
|
||||||
|
Uint32 mask = ~surface->format->Amask;
|
||||||
|
|
||||||
|
row = (Uint32 *)surface->pixels;
|
||||||
|
for (y = surface->h; y--; ) {
|
||||||
|
spot = row;
|
||||||
|
for (x = surface->w; x--; ) {
|
||||||
|
if (*spot == ckey) {
|
||||||
|
*spot &= mask;
|
||||||
|
}
|
||||||
|
++spot;
|
||||||
|
}
|
||||||
|
row += surface->pitch / 4;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
SDL_UnlockSurface(surface);
|
||||||
|
|
||||||
|
SDL_SetColorKey(surface, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
SDL_SetSurfaceColorMod(SDL_Surface * surface, Uint8 r, Uint8 g, Uint8 b)
|
SDL_SetSurfaceColorMod(SDL_Surface * surface, Uint8 r, Uint8 g, Uint8 b)
|
||||||
{
|
{
|
||||||
|
|
|
@ -46,6 +46,9 @@
|
||||||
#endif
|
#endif
|
||||||
#endif /* SDL_VIDEO_OPENGL */
|
#endif /* SDL_VIDEO_OPENGL */
|
||||||
|
|
||||||
|
/* From SDL_surface.c */
|
||||||
|
extern void SDL_ConvertColorkeyToAlpha(SDL_Surface *surface);
|
||||||
|
|
||||||
/* Available video drivers */
|
/* Available video drivers */
|
||||||
static VideoBootStrap *bootstrap[] = {
|
static VideoBootStrap *bootstrap[] = {
|
||||||
#if SDL_VIDEO_DRIVER_COCOA
|
#if SDL_VIDEO_DRIVER_COCOA
|
||||||
|
@ -1585,6 +1588,7 @@ SDL_CreateTextureFromSurface(Uint32 format, SDL_Surface * surface)
|
||||||
}
|
}
|
||||||
dst = SDL_ConvertSurface(surface, dst_fmt, 0);
|
dst = SDL_ConvertSurface(surface, dst_fmt, 0);
|
||||||
if (dst) {
|
if (dst) {
|
||||||
|
SDL_ConvertColorkeyToAlpha(dst);
|
||||||
SDL_UpdateTexture(textureID, NULL, dst->pixels, dst->pitch);
|
SDL_UpdateTexture(textureID, NULL, dst->pixels, dst->pitch);
|
||||||
SDL_FreeSurface(dst);
|
SDL_FreeSurface(dst);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue