Skip to content

Commit

Permalink
Updated for SDL 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Jan 23, 2012
1 parent f857577 commit 974e6ae
Show file tree
Hide file tree
Showing 18 changed files with 219 additions and 247 deletions.
35 changes: 34 additions & 1 deletion IMG.c
Expand Up @@ -155,7 +155,7 @@ static int IMG_string_equals(const char *str1, const char *str2)
}

/* Load an image from an SDL datasource, optionally specifying the type */
SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, char *type)
SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, const char *type)
{
int i;
SDL_Surface *image;
Expand Down Expand Up @@ -203,6 +203,39 @@ SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, char *type)
return NULL;
}

SDL_Texture *IMG_LoadTexture(SDL_Renderer *renderer, const char *file)
{
SDL_Texture *texture = NULL;
SDL_Surface *surface = IMG_Load(file);
if (surface) {
texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_FreeSurface(surface);
}
return texture;
}

SDL_Texture *IMG_LoadTexture_RW(SDL_Renderer *renderer, SDL_RWops *src, int freesrc)
{
SDL_Texture *texture = NULL;
SDL_Surface *surface = IMG_Load_RW(src, freesrc);
if (surface) {
texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_FreeSurface(surface);
}
return texture;
}

SDL_Texture *IMG_LoadTextureTyped_RW(SDL_Renderer *renderer, SDL_RWops *src, int freesrc, const char *type)
{
SDL_Texture *texture = NULL;
SDL_Surface *surface = IMG_LoadTyped_RW(src, freesrc, type);
if (surface) {
texture = SDL_CreateTextureFromSurface(renderer, surface);
SDL_FreeSurface(surface);
}
return texture;
}

/* Invert the alpha of a surface for use with OpenGL
This function is a no-op and only kept for backwards compatibility.
*/
Expand Down
2 changes: 1 addition & 1 deletion IMG_gif.c
Expand Up @@ -81,7 +81,7 @@ int IMG_isGIF(SDL_RWops *src)

#define Image SDL_Surface
#define RWSetMsg IMG_SetError
#define ImageNewCmap(w, h, s) SDL_AllocSurface(SDL_SWSURFACE,w,h,8,0,0,0,0)
#define ImageNewCmap(w, h, s) SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,8,0,0,0,0)
#define ImageSetCmap(s, i, R, G, B) do { \
s->format->palette->colors[i].r = R; \
s->format->palette->colors[i].g = G; \
Expand Down
2 changes: 1 addition & 1 deletion IMG_jpg.c
Expand Up @@ -416,7 +416,7 @@ SDL_Surface *IMG_LoadJPG_RW(SDL_RWops *src)
lib.jpeg_calc_output_dimensions(&cinfo);

/* Allocate an output surface to hold the image */
surface = SDL_AllocSurface(SDL_SWSURFACE,
surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
cinfo.output_width, cinfo.output_height, 32,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
Expand Down
2 changes: 1 addition & 1 deletion IMG_lbm.c
Expand Up @@ -253,7 +253,7 @@ SDL_Surface *IMG_LoadLBM_RW( SDL_RWops *src )
goto done;

if ( bmhd.mask & 2 ) /* There is a transparent color */
SDL_SetColorKey( Image, SDL_SRCCOLORKEY, bmhd.tcolor );
SDL_SetColorKey( Image, SDL_TRUE, bmhd.tcolor );

/* Update palette informations */

Expand Down
2 changes: 1 addition & 1 deletion IMG_pcx.c
Expand Up @@ -140,7 +140,7 @@ SDL_Surface *IMG_LoadPCX_RW(SDL_RWops *src)
error = "unsupported PCX format";
goto done;
}
surface = SDL_AllocSurface(SDL_SWSURFACE, width, height,
surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
bits, Rmask, Gmask, Bmask, Amask);
if ( surface == NULL )
goto done;
Expand Down
2 changes: 1 addition & 1 deletion IMG_png.c
Expand Up @@ -467,7 +467,7 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)
Amask = 0x000000FF >> s;
}
}
surface = SDL_AllocSurface(SDL_SWSURFACE, width, height,
surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
bit_depth*num_channels, Rmask,Gmask,Bmask,Amask);
if ( surface == NULL ) {
error = "Out of memory";
Expand Down
4 changes: 2 additions & 2 deletions IMG_pnm.c
Expand Up @@ -149,7 +149,7 @@ SDL_Surface *IMG_LoadPNM_RW(SDL_RWops *src)

if(kind == PPM) {
/* 24-bit surface in R,G,B byte order */
surface = SDL_AllocSurface(SDL_SWSURFACE, width, height, 24,
surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 24,
#if SDL_BYTEORDER == SDL_LIL_ENDIAN
0x000000ff, 0x0000ff00, 0x00ff0000,
#else
Expand All @@ -158,7 +158,7 @@ SDL_Surface *IMG_LoadPNM_RW(SDL_RWops *src)
0);
} else {
/* load PBM/PGM as 8-bit indexed images */
surface = SDL_AllocSurface(SDL_SWSURFACE, width, height, 8,
surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 8,
0, 0, 0, 0);
}
if ( surface == NULL )
Expand Down
2 changes: 1 addition & 1 deletion IMG_tif.c
Expand Up @@ -235,7 +235,7 @@ SDL_Surface* IMG_LoadTIF_RW(SDL_RWops* src)
Gmask = 0x0000FF00;
Bmask = 0x00FF0000;
Amask = 0xFF000000;
surface = SDL_AllocSurface(SDL_SWSURFACE, img_width, img_height, 32,
surface = SDL_CreateRGBSurface(SDL_SWSURFACE, img_width, img_height, 32,
Rmask, Gmask, Bmask, Amask);
if(!surface)
goto error;
Expand Down
3 changes: 2 additions & 1 deletion IMG_webp.c
Expand Up @@ -228,7 +228,8 @@ SDL_Surface *IMG_LoadWEBP_RW(SDL_RWops *src)
Bmask = 0x00FF0000;
Amask = features.has_alpha?0xFF000001:0;

surface = SDL_AllocSurface(SDL_SWSURFACE, features.width, features.height,
surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
features.width, features.height,
features.has_alpha?32:24, Rmask,Gmask,Bmask,Amask);

if ( surface == NULL ) {
Expand Down
6 changes: 3 additions & 3 deletions IMG_xcf.c
Expand Up @@ -709,7 +709,7 @@ SDL_Surface *IMG_LoadXCF_RW(SDL_RWops *src)
}

/* Create the surface of the appropriate type */
surface = SDL_AllocSurface(SDL_SWSURFACE, head->width, head->height, 32,
surface = SDL_CreateRGBSurface(SDL_SWSURFACE, head->width, head->height, 32,
0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);

if ( surface == NULL ) {
Expand All @@ -727,7 +727,7 @@ SDL_Surface *IMG_LoadXCF_RW(SDL_RWops *src)
}
fp = SDL_RWtell (src);

lays = SDL_AllocSurface(SDL_SWSURFACE, head->width, head->height, 32,
lays = SDL_CreateRGBSurface(SDL_SWSURFACE, head->width, head->height, 32,
0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);

if ( lays == NULL ) {
Expand Down Expand Up @@ -774,7 +774,7 @@ SDL_Surface *IMG_LoadXCF_RW(SDL_RWops *src)
if (chnls) {
SDL_Surface * chs;

chs = SDL_AllocSurface(SDL_SWSURFACE, head->width, head->height, 32,
chs = SDL_CreateRGBSurface(SDL_SWSURFACE, head->width, head->height, 32,
0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);

if (chs == NULL) {
Expand Down
2 changes: 1 addition & 1 deletion IMG_xpm.c
Expand Up @@ -431,7 +431,7 @@ static SDL_Surface *load_xpm(char **xpm, SDL_RWops *src)
add_colorhash(colors, nextkey, cpp, pixel);
nextkey += cpp;
if(rgb == 0xffffffff)
SDL_SetColorKey(image, SDL_SRCCOLORKEY, pixel);
SDL_SetColorKey(image, SDL_TRUE, pixel);
break;
}
}
Expand Down
4 changes: 1 addition & 3 deletions Makefile.in
Expand Up @@ -52,7 +52,7 @@ am__aclocal_m4_deps = $(top_srcdir)/acinclude/libtool.m4 \
$(top_srcdir)/acinclude/ltsugar.m4 \
$(top_srcdir)/acinclude/ltversion.m4 \
$(top_srcdir)/acinclude/lt~obsolete.m4 \
$(top_srcdir)/acinclude/pkg.m4 $(top_srcdir)/acinclude/sdl.m4 \
$(top_srcdir)/acinclude/pkg.m4 $(top_srcdir)/acinclude/sdl2.m4 \
$(top_srcdir)/configure.in
am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
$(ACLOCAL_M4)
Expand Down Expand Up @@ -293,8 +293,6 @@ EXTRA_DIST = \
VisualCE \
Xcode \
Xcode-iOS \
MPWmake.sea.bin \
Watcom-OS2.zip \
IMG_xxx.c \
IMG_UIImage.m \
SDL_image.spec \
Expand Down
8 changes: 7 additions & 1 deletion SDL_image.h
Expand Up @@ -80,11 +80,17 @@ extern DECLSPEC void SDLCALL IMG_Quit(void);
surface afterwards by calling:
SDL_SetColorKey(image, SDL_RLEACCEL, image->format->colorkey);
*/
extern DECLSPEC SDL_Surface * SDLCALL IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, char *type);
extern DECLSPEC SDL_Surface * SDLCALL IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, const char *type);
/* Convenience functions */
extern DECLSPEC SDL_Surface * SDLCALL IMG_Load(const char *file);
extern DECLSPEC SDL_Surface * SDLCALL IMG_Load_RW(SDL_RWops *src, int freesrc);

/* Load an image directly into a render texture.
*/
extern DECLSPEC SDL_Texture * SDLCALL IMG_LoadTexture(SDL_Renderer *renderer, const char *file);
extern DECLSPEC SDL_Texture * SDLCALL IMG_LoadTexture_RW(SDL_Renderer *renderer, SDL_RWops *src, int freesrc);
extern DECLSPEC SDL_Texture * SDLCALL IMG_LoadTextureTyped_RW(SDL_Renderer *renderer, SDL_RWops *src, int freesrc, const char *type);

/* Invert the alpha of a surface for use with OpenGL
This function is now a no-op, and only provided for backwards compatibility.
*/
Expand Down
37 changes: 18 additions & 19 deletions acinclude/sdl.m4 → acinclude/sdl2.m4
Expand Up @@ -5,12 +5,14 @@
# stolen from Manish Singh
# Shamelessly stolen from Owen Taylor

# serial 1

dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
dnl
AC_DEFUN([AM_PATH_SDL],
[dnl
dnl Get the cflags and libraries from the sdl-config script
dnl Get the cflags and libraries from the sdl2-config script
dnl
AC_ARG_WITH(sdl-prefix,[ --with-sdl-prefix=PFX Prefix where SDL is installed (optional)],
sdl_prefix="$withval", sdl_prefix="")
Expand All @@ -19,40 +21,37 @@ AC_ARG_WITH(sdl-exec-prefix,[ --with-sdl-exec-prefix=PFX Exec prefix where SDL
AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run a test SDL program],
, enable_sdltest=yes)
min_sdl_version=ifelse([$1], ,1.2.0,$1)
min_sdl_version=ifelse([$1], ,0.9.0,$1)
if test "x$sdl_prefix$sdl_exec_prefix" = x ; then
PKG_CHECK_MODULES(SDL, [sdl >= $min_sdl_version],
PKG_CHECK_MODULES([SDL], [sdl2 >= $min_sdl_version],
[sdl_pc=yes],
[dnl
AC_MSG_RESULT(no)
sdl_pc=no
])
[sdl_pc=no])
else
sdl_pc=no
if test x$sdl_exec_prefix != x ; then
sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix"
if test x${SDL_CONFIG+set} != xset ; then
SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
SDL_CONFIG=$sdl_exec_prefix/bin/sdl2-config
fi
fi
if test x$sdl_prefix != x ; then
sdl_config_args="$sdl_config_args --prefix=$sdl_prefix"
if test x${SDL_CONFIG+set} != xset ; then
SDL_CONFIG=$sdl_prefix/bin/sdl-config
SDL_CONFIG=$sdl_prefix/bin/sdl2-config
fi
fi
fi
if test "x$sdl_pc" = xyes ; then
no_sdl=""
SDL_CONFIG="pkg-config sdl"
SDL_CONFIG="pkg-config sdl2"
else
as_save_PATH="$PATH"
if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
PATH="$prefix/bin:$prefix/usr/bin:$PATH"
fi
AC_PATH_PROG(SDL_CONFIG, sdl-config, no, [$PATH])
AC_PATH_PROG(SDL_CONFIG, sdl2-config, no, [$PATH])
PATH="$as_save_PATH"
AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
no_sdl=""
Expand All @@ -78,7 +77,7 @@ AC_ARG_ENABLE(sdltest, [ --disable-sdltest Do not try to compile and run
LIBS="$LIBS $SDL_LIBS"
dnl
dnl Now check if the installed SDL is sufficiently new. (Also sanity
dnl checks the results of sdl-config to some extent
dnl checks the results of sdl2-config to some extent
dnl
rm -f conf.sdltest
AC_TRY_RUN([
Expand Down Expand Up @@ -128,11 +127,11 @@ int main (int argc, char *argv[])
}
else
{
printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro);
printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro);
printf("*** best to upgrade to the required version.\n");
printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n");
printf("*** to point to the correct copy of sdl-config, and remove the file\n");
printf("*** If sdl2-config was wrong, set the environment variable SDL_CONFIG\n");
printf("*** to point to the correct copy of sdl2-config, and remove the file\n");
printf("*** config.cache before re-running configure\n");
return 1;
}
Expand All @@ -154,10 +153,10 @@ int main (int argc, char *argv[])
ifelse([$2], , :, [$2])
else
if test "$SDL_CONFIG" = "no" ; then
echo "*** The sdl-config script installed by SDL could not be found"
echo "*** The sdl2-config script installed by SDL could not be found"
echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
echo "*** your path, or set the SDL_CONFIG environment variable to the"
echo "*** full path to sdl-config."
echo "*** full path to sdl2-config."
else
if test -f conf.sdltest ; then
:
Expand Down Expand Up @@ -187,7 +186,7 @@ int main(int argc, char *argv[])
[ echo "*** The test program failed to compile or link. See the file config.log for the"
echo "*** exact error that occured. This usually means SDL was incorrectly installed"
echo "*** or that you have moved SDL since it was installed. In the latter case, you"
echo "*** may want to edit the sdl-config script: $SDL_CONFIG" ])
echo "*** may want to edit the sdl2-config script: $SDL_CONFIG" ])
CFLAGS="$ac_save_CFLAGS"
CXXFLAGS="$ac_save_CXXFLAGS"
LIBS="$ac_save_LIBS"
Expand Down
2 changes: 1 addition & 1 deletion aclocal.m4
Expand Up @@ -965,4 +965,4 @@ m4_include([acinclude/ltsugar.m4])
m4_include([acinclude/ltversion.m4])
m4_include([acinclude/lt~obsolete.m4])
m4_include([acinclude/pkg.m4])
m4_include([acinclude/sdl.m4])
m4_include([acinclude/sdl2.m4])

0 comments on commit 974e6ae

Please sign in to comment.