diff -u -r tworld-1.2.1/configure.in tworld-1.2.1-translucent/configure.in --- tworld-1.2.1/configure.in 2004-09-25 13:14:54.000000000 +0100 +++ tworld-1.2.1-translucent/configure.in 2005-12-30 14:49:39.000000000 +0000 @@ -47,6 +47,14 @@ OSHWDIR="sdl" fi]) +dnl SDL_Image support, added by Chris E. + +SDL_IMAGE="no" + +AC_ARG_WITH(sdlimage, + [ --with-sdlimage Use SDL_Image (default=no)], + [SDL_IMAGE="$withval"]) + if test -d "oshw-$OSHWDIR" ; then echo using $OSHWDIR for OS/hardware layer ... rm -f oshw @@ -63,6 +71,10 @@ CFLAGS=$CFLAGS' $(shell sdl-config --cflags)' OSHWCFLAGS=$OSHWCFLAGS' $(shell sdl-config --cflags)' LOADLIBES=$LOADLIBES' $(shell sdl-config --libs)' + if test "$SDL_IMAGE" = yes ; then + OSHWCFLAGS="$OSHWCFLAGS -DHAVE_SDLIMAGE" + LOADLIBES="$LOADLIBES -lSDL_image" + fi fi dnl diff -u -r tworld-1.2.1/oshw-sdl/sdltile.c tworld-1.2.1-translucent/oshw-sdl/sdltile.c --- tworld-1.2.1/oshw-sdl/sdltile.c 2004-10-04 06:49:20.000000000 +0100 +++ tworld-1.2.1-translucent/oshw-sdl/sdltile.c 2005-12-30 14:49:39.000000000 +0000 @@ -9,6 +9,12 @@ #include #include #include "SDL.h" +#ifdef HAVE_SDLIMAGE +#include "SDL_image.h" +#else +#define IMG_Load SDL_LoadBMP +#define IMG_GetError SDL_GetError +#endif #include "sdlgen.h" #include "../err.h" #include "../state.h" @@ -449,6 +455,7 @@ /* Create a new surface containing a single tile with transparent * pixels, as indicated by the given color key. */ +/* Chris E.: Alpha is used instead if available */ static SDL_Surface *extractkeyedtile(SDL_Surface *src, int ximg, int yimg, int wimg, int himg, Uint32 transpclr) @@ -456,17 +463,28 @@ SDL_Surface *dest; SDL_Surface *temp; SDL_Rect rect; + int hasalpha; dest = newsurface(wimg, himg, TRUE); - SDL_FillRect(dest, NULL, SDL_MapRGBA(dest->format, - 0, 0, 0, SDL_ALPHA_TRANSPARENT)); - SDL_SetColorKey(src, SDL_SRCCOLORKEY, transpclr); + hasalpha = (src->flags & SDL_SRCALPHA) == SDL_SRCALPHA; + if(hasalpha) { + if(SDL_SetAlpha(dest, SDL_SRCALPHA, src->format->alpha) == -1 || /* Copy per-surface alpha value */ + SDL_SetAlpha(src, 0, 0) == -1) /* Copy alpha data rather than merging */ + die("SDL_SetAlpha", SDL_GetError()); + } else { + SDL_FillRect(dest, NULL, SDL_MapRGBA(dest->format, + 0, 0, 0, SDL_ALPHA_TRANSPARENT)); + SDL_SetColorKey(src, SDL_SRCCOLORKEY, transpclr); + } rect.x = ximg; rect.y = yimg; rect.w = dest->w; rect.h = dest->h; SDL_BlitSurface(src, &rect, dest, NULL); - SDL_SetColorKey(src, 0, 0); + if(hasalpha) + SDL_SetAlpha(src, SDL_SRCALPHA, dest->format->alpha); /* Restore alpha settings */ + else + SDL_SetColorKey(src, 0, 0); /* Remove color key */ temp = dest; dest = SDL_DisplayFormatAlpha(temp); @@ -520,7 +538,7 @@ SDL_Surface *temp; SDL_Rect rect; unsigned char *s, *d; - Uint32 transp, black; + Uint8 r, g, b, a; int x, y; rect.x = ximg; @@ -530,9 +548,6 @@ dest = newsurface(rect.w, rect.h, TRUE); SDL_BlitSurface(src, &rect, dest, NULL); - black = SDL_MapRGB(src->format, 0, 0, 0); - transp = SDL_MapRGBA(dest->format, 0, 0, 0, SDL_ALPHA_TRANSPARENT); - if (SDL_MUSTLOCK(src)) SDL_LockSurface(src); if (SDL_MUSTLOCK(dest)) @@ -542,8 +557,10 @@ + xmask * src->format->BytesPerPixel; for (y = 0 ; y < dest->h ; ++y) { for (x = 0 ; x < dest->w ; ++x) { - if (pixelat(src, xmask + x, ymask + y) == black) - ((Uint32*)d)[x] = transp; + SDL_GetRGB(pixelat(src, xmask + x, ymask + y), src->format, &r, &g, &b); + a = (r + g + b) / 3; + SDL_GetRGB(((Uint32*)d)[x], dest->format, &r, &g, &b); + ((Uint32*)d)[x] = SDL_MapRGBA(dest->format, r, g, b, a); } s += src->pitch; d += dest->pitch; @@ -593,7 +610,6 @@ return FALSE; remembersurface(s); tileptr[id].celcount = 1; - tileptr[id].opaque[0] = NULL; tileptr[id].transp[0] = s; } else if (tileidmap[n].xopaque >= 0) { s = extractopaquetile(tiles, tileidmap[n].xopaque * sdlg.wtile, @@ -604,7 +620,6 @@ remembersurface(s); tileptr[id].celcount = 1; tileptr[id].opaque[0] = s; - tileptr[id].transp[0] = NULL; } } @@ -1067,10 +1082,10 @@ SDL_Surface *tiles = NULL; int f, w, h; - tiles = SDL_LoadBMP(filename); + tiles = IMG_Load(filename); if (!tiles) { if (complain) - errmsg(filename, "cannot read bitmap: %s", SDL_GetError()); + errmsg(filename, "cannot read tile images: %s", IMG_GetError()); return FALSE; } if (tiles->format->palette && sdlg.screen->format->palette)