Updated for SDL 2.0
authorSam Lantinga <slouken@libsdl.org>
Sun, 22 Jan 2012 21:52:00 -0500
changeset 320aa5d55b11751
parent 319 e7feb0dbe64f
child 321 fd488b9e71e0
Updated for SDL 2.0
IMG.c
IMG_gif.c
IMG_jpg.c
IMG_lbm.c
IMG_pcx.c
IMG_png.c
IMG_pnm.c
IMG_tif.c
IMG_webp.c
IMG_xcf.c
IMG_xpm.c
Makefile.in
SDL_image.h
acinclude/sdl.m4
acinclude/sdl2.m4
aclocal.m4
configure
configure.in
showimage.c
     1.1 --- a/IMG.c	Sun Jan 22 20:11:17 2012 -0500
     1.2 +++ b/IMG.c	Sun Jan 22 21:52:00 2012 -0500
     1.3 @@ -155,7 +155,7 @@
     1.4  }
     1.5  
     1.6  /* Load an image from an SDL datasource, optionally specifying the type */
     1.7 -SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, char *type)
     1.8 +SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, const char *type)
     1.9  {
    1.10  	int i;
    1.11  	SDL_Surface *image;
    1.12 @@ -203,6 +203,39 @@
    1.13  	return NULL;
    1.14  }
    1.15  
    1.16 +SDL_Texture *IMG_LoadTexture(SDL_Renderer *renderer, const char *file)
    1.17 +{
    1.18 +    SDL_Texture *texture = NULL;
    1.19 +    SDL_Surface *surface = IMG_Load(file);
    1.20 +    if (surface) {
    1.21 +        texture = SDL_CreateTextureFromSurface(renderer, surface);
    1.22 +        SDL_FreeSurface(surface);
    1.23 +    }
    1.24 +    return texture;
    1.25 +}
    1.26 +
    1.27 +SDL_Texture *IMG_LoadTexture_RW(SDL_Renderer *renderer, SDL_RWops *src, int freesrc)
    1.28 +{
    1.29 +    SDL_Texture *texture = NULL;
    1.30 +    SDL_Surface *surface = IMG_Load_RW(src, freesrc);
    1.31 +    if (surface) {
    1.32 +        texture = SDL_CreateTextureFromSurface(renderer, surface);
    1.33 +        SDL_FreeSurface(surface);
    1.34 +    }
    1.35 +    return texture;
    1.36 +}
    1.37 +
    1.38 +SDL_Texture *IMG_LoadTextureTyped_RW(SDL_Renderer *renderer, SDL_RWops *src, int freesrc, const char *type)
    1.39 +{
    1.40 +    SDL_Texture *texture = NULL;
    1.41 +    SDL_Surface *surface = IMG_LoadTyped_RW(src, freesrc, type);
    1.42 +    if (surface) {
    1.43 +        texture = SDL_CreateTextureFromSurface(renderer, surface);
    1.44 +        SDL_FreeSurface(surface);
    1.45 +    }
    1.46 +    return texture;
    1.47 +}
    1.48 +
    1.49  /* Invert the alpha of a surface for use with OpenGL
    1.50     This function is a no-op and only kept for backwards compatibility.
    1.51   */
     2.1 --- a/IMG_gif.c	Sun Jan 22 20:11:17 2012 -0500
     2.2 +++ b/IMG_gif.c	Sun Jan 22 21:52:00 2012 -0500
     2.3 @@ -81,7 +81,7 @@
     2.4  
     2.5  #define Image			SDL_Surface
     2.6  #define RWSetMsg		IMG_SetError
     2.7 -#define ImageNewCmap(w, h, s)	SDL_AllocSurface(SDL_SWSURFACE,w,h,8,0,0,0,0)
     2.8 +#define ImageNewCmap(w, h, s)	SDL_CreateRGBSurface(SDL_SWSURFACE,w,h,8,0,0,0,0)
     2.9  #define ImageSetCmap(s, i, R, G, B) do { \
    2.10  				s->format->palette->colors[i].r = R; \
    2.11  				s->format->palette->colors[i].g = G; \
     3.1 --- a/IMG_jpg.c	Sun Jan 22 20:11:17 2012 -0500
     3.2 +++ b/IMG_jpg.c	Sun Jan 22 21:52:00 2012 -0500
     3.3 @@ -416,7 +416,7 @@
     3.4  		lib.jpeg_calc_output_dimensions(&cinfo);
     3.5  
     3.6  		/* Allocate an output surface to hold the image */
     3.7 -		surface = SDL_AllocSurface(SDL_SWSURFACE,
     3.8 +		surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
     3.9  		        cinfo.output_width, cinfo.output_height, 32,
    3.10  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
    3.11  		                   0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
     4.1 --- a/IMG_lbm.c	Sun Jan 22 20:11:17 2012 -0500
     4.2 +++ b/IMG_lbm.c	Sun Jan 22 21:52:00 2012 -0500
     4.3 @@ -253,7 +253,7 @@
     4.4  	   goto done;
     4.5  
     4.6  	if ( bmhd.mask & 2 )               /* There is a transparent color */
     4.7 -		SDL_SetColorKey( Image, SDL_SRCCOLORKEY, bmhd.tcolor );
     4.8 +		SDL_SetColorKey( Image, SDL_TRUE, bmhd.tcolor );
     4.9  
    4.10  	/* Update palette informations */
    4.11  
     5.1 --- a/IMG_pcx.c	Sun Jan 22 20:11:17 2012 -0500
     5.2 +++ b/IMG_pcx.c	Sun Jan 22 21:52:00 2012 -0500
     5.3 @@ -140,7 +140,7 @@
     5.4  		error = "unsupported PCX format";
     5.5  		goto done;
     5.6  	}
     5.7 -	surface = SDL_AllocSurface(SDL_SWSURFACE, width, height,
     5.8 +	surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
     5.9  				   bits, Rmask, Gmask, Bmask, Amask);
    5.10  	if ( surface == NULL )
    5.11  		goto done;
     6.1 --- a/IMG_png.c	Sun Jan 22 20:11:17 2012 -0500
     6.2 +++ b/IMG_png.c	Sun Jan 22 21:52:00 2012 -0500
     6.3 @@ -467,7 +467,7 @@
     6.4  			Amask = 0x000000FF >> s;
     6.5  		}
     6.6  	}
     6.7 -	surface = SDL_AllocSurface(SDL_SWSURFACE, width, height,
     6.8 +	surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height,
     6.9  			bit_depth*num_channels, Rmask,Gmask,Bmask,Amask);
    6.10  	if ( surface == NULL ) {
    6.11  		error = "Out of memory";
     7.1 --- a/IMG_pnm.c	Sun Jan 22 20:11:17 2012 -0500
     7.2 +++ b/IMG_pnm.c	Sun Jan 22 21:52:00 2012 -0500
     7.3 @@ -149,7 +149,7 @@
     7.4  
     7.5  	if(kind == PPM) {
     7.6  		/* 24-bit surface in R,G,B byte order */
     7.7 -		surface = SDL_AllocSurface(SDL_SWSURFACE, width, height, 24,
     7.8 +		surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 24,
     7.9  #if SDL_BYTEORDER == SDL_LIL_ENDIAN
    7.10  					   0x000000ff, 0x0000ff00, 0x00ff0000,
    7.11  #else
    7.12 @@ -158,7 +158,7 @@
    7.13  					   0);
    7.14  	} else {
    7.15  		/* load PBM/PGM as 8-bit indexed images */
    7.16 -		surface = SDL_AllocSurface(SDL_SWSURFACE, width, height, 8,
    7.17 +		surface = SDL_CreateRGBSurface(SDL_SWSURFACE, width, height, 8,
    7.18  					   0, 0, 0, 0);
    7.19  	}
    7.20  	if ( surface == NULL )
     8.1 --- a/IMG_tif.c	Sun Jan 22 20:11:17 2012 -0500
     8.2 +++ b/IMG_tif.c	Sun Jan 22 21:52:00 2012 -0500
     8.3 @@ -235,7 +235,7 @@
     8.4  	Gmask = 0x0000FF00;
     8.5  	Bmask = 0x00FF0000;
     8.6  	Amask = 0xFF000000;
     8.7 -	surface = SDL_AllocSurface(SDL_SWSURFACE, img_width, img_height, 32,
     8.8 +	surface = SDL_CreateRGBSurface(SDL_SWSURFACE, img_width, img_height, 32,
     8.9  		Rmask, Gmask, Bmask, Amask);
    8.10  	if(!surface)
    8.11  		goto error;
     9.1 --- a/IMG_webp.c	Sun Jan 22 20:11:17 2012 -0500
     9.2 +++ b/IMG_webp.c	Sun Jan 22 21:52:00 2012 -0500
     9.3 @@ -228,7 +228,8 @@
     9.4  	Bmask = 0x00FF0000;
     9.5  	Amask = features.has_alpha?0xFF000001:0;
     9.6  
     9.7 -	surface = SDL_AllocSurface(SDL_SWSURFACE, features.width, features.height,
     9.8 +	surface = SDL_CreateRGBSurface(SDL_SWSURFACE,
     9.9 +            features.width, features.height,
    9.10  			features.has_alpha?32:24, Rmask,Gmask,Bmask,Amask);
    9.11  
    9.12  	if ( surface == NULL ) {
    10.1 --- a/IMG_xcf.c	Sun Jan 22 20:11:17 2012 -0500
    10.2 +++ b/IMG_xcf.c	Sun Jan 22 21:52:00 2012 -0500
    10.3 @@ -709,7 +709,7 @@
    10.4    }
    10.5  
    10.6    /* Create the surface of the appropriate type */
    10.7 -  surface = SDL_AllocSurface(SDL_SWSURFACE, head->width, head->height, 32,
    10.8 +  surface = SDL_CreateRGBSurface(SDL_SWSURFACE, head->width, head->height, 32,
    10.9  			     0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
   10.10  
   10.11    if ( surface == NULL ) {
   10.12 @@ -727,7 +727,7 @@
   10.13    }
   10.14    fp = SDL_RWtell (src);
   10.15   
   10.16 -  lays = SDL_AllocSurface(SDL_SWSURFACE, head->width, head->height, 32,
   10.17 +  lays = SDL_CreateRGBSurface(SDL_SWSURFACE, head->width, head->height, 32,
   10.18  			  0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
   10.19  
   10.20    if ( lays == NULL ) {
   10.21 @@ -774,7 +774,7 @@
   10.22    if (chnls) {
   10.23      SDL_Surface * chs;
   10.24  
   10.25 -    chs = SDL_AllocSurface(SDL_SWSURFACE, head->width, head->height, 32,
   10.26 +    chs = SDL_CreateRGBSurface(SDL_SWSURFACE, head->width, head->height, 32,
   10.27  			   0x00FF0000,0x0000FF00,0x000000FF,0xFF000000);
   10.28  
   10.29      if (chs == NULL) {
    11.1 --- a/IMG_xpm.c	Sun Jan 22 20:11:17 2012 -0500
    11.2 +++ b/IMG_xpm.c	Sun Jan 22 21:52:00 2012 -0500
    11.3 @@ -431,7 +431,7 @@
    11.4  			add_colorhash(colors, nextkey, cpp, pixel);
    11.5  			nextkey += cpp;
    11.6  			if(rgb == 0xffffffff)
    11.7 -				SDL_SetColorKey(image, SDL_SRCCOLORKEY, pixel);
    11.8 +				SDL_SetColorKey(image, SDL_TRUE, pixel);
    11.9  			break;
   11.10  		}
   11.11  	}
    12.1 --- a/Makefile.in	Sun Jan 22 20:11:17 2012 -0500
    12.2 +++ b/Makefile.in	Sun Jan 22 21:52:00 2012 -0500
    12.3 @@ -52,7 +52,7 @@
    12.4  	$(top_srcdir)/acinclude/ltsugar.m4 \
    12.5  	$(top_srcdir)/acinclude/ltversion.m4 \
    12.6  	$(top_srcdir)/acinclude/lt~obsolete.m4 \
    12.7 -	$(top_srcdir)/acinclude/pkg.m4 $(top_srcdir)/acinclude/sdl.m4 \
    12.8 +	$(top_srcdir)/acinclude/pkg.m4 $(top_srcdir)/acinclude/sdl2.m4 \
    12.9  	$(top_srcdir)/configure.in
   12.10  am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
   12.11  	$(ACLOCAL_M4)
   12.12 @@ -293,8 +293,6 @@
   12.13  	VisualCE		\
   12.14  	Xcode			\
   12.15  	Xcode-iOS		\
   12.16 -	MPWmake.sea.bin		\
   12.17 -	Watcom-OS2.zip		\
   12.18  	IMG_xxx.c		\
   12.19  	IMG_UIImage.m		\
   12.20  	SDL_image.spec		\
    13.1 --- a/SDL_image.h	Sun Jan 22 20:11:17 2012 -0500
    13.2 +++ b/SDL_image.h	Sun Jan 22 21:52:00 2012 -0500
    13.3 @@ -80,11 +80,17 @@
    13.4     surface afterwards by calling:
    13.5  	SDL_SetColorKey(image, SDL_RLEACCEL, image->format->colorkey);
    13.6   */
    13.7 -extern DECLSPEC SDL_Surface * SDLCALL IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, char *type);
    13.8 +extern DECLSPEC SDL_Surface * SDLCALL IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, const char *type);
    13.9  /* Convenience functions */
   13.10  extern DECLSPEC SDL_Surface * SDLCALL IMG_Load(const char *file);
   13.11  extern DECLSPEC SDL_Surface * SDLCALL IMG_Load_RW(SDL_RWops *src, int freesrc);
   13.12  
   13.13 +/* Load an image directly into a render texture.
   13.14 + */
   13.15 +extern DECLSPEC SDL_Texture * SDLCALL IMG_LoadTexture(SDL_Renderer *renderer, const char *file);
   13.16 +extern DECLSPEC SDL_Texture * SDLCALL IMG_LoadTexture_RW(SDL_Renderer *renderer, SDL_RWops *src, int freesrc);
   13.17 +extern DECLSPEC SDL_Texture * SDLCALL IMG_LoadTextureTyped_RW(SDL_Renderer *renderer, SDL_RWops *src, int freesrc, const char *type);
   13.18 +
   13.19  /* Invert the alpha of a surface for use with OpenGL
   13.20     This function is now a no-op, and only provided for backwards compatibility.
   13.21  */
    14.1 --- a/acinclude/sdl.m4	Sun Jan 22 20:11:17 2012 -0500
    14.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    14.3 @@ -1,203 +0,0 @@
    14.4 -# Configure paths for SDL
    14.5 -# Sam Lantinga 9/21/99
    14.6 -# stolen from Manish Singh
    14.7 -# stolen back from Frank Belew
    14.8 -# stolen from Manish Singh
    14.9 -# Shamelessly stolen from Owen Taylor
   14.10 -
   14.11 -dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
   14.12 -dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
   14.13 -dnl
   14.14 -AC_DEFUN([AM_PATH_SDL],
   14.15 -[dnl 
   14.16 -dnl Get the cflags and libraries from the sdl-config script
   14.17 -dnl
   14.18 -AC_ARG_WITH(sdl-prefix,[  --with-sdl-prefix=PFX   Prefix where SDL is installed (optional)],
   14.19 -            sdl_prefix="$withval", sdl_prefix="")
   14.20 -AC_ARG_WITH(sdl-exec-prefix,[  --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)],
   14.21 -            sdl_exec_prefix="$withval", sdl_exec_prefix="")
   14.22 -AC_ARG_ENABLE(sdltest, [  --disable-sdltest       Do not try to compile and run a test SDL program],
   14.23 -		    , enable_sdltest=yes)
   14.24 -
   14.25 -  min_sdl_version=ifelse([$1], ,1.2.0,$1)
   14.26 -
   14.27 -  if test "x$sdl_prefix$sdl_exec_prefix" = x ; then
   14.28 -    PKG_CHECK_MODULES(SDL, [sdl >= $min_sdl_version],
   14.29 -           [sdl_pc=yes],
   14.30 -           [dnl
   14.31 -             AC_MSG_RESULT(no)
   14.32 -             sdl_pc=no
   14.33 -           ])
   14.34 -  else
   14.35 -    sdl_pc=no
   14.36 -    if test x$sdl_exec_prefix != x ; then
   14.37 -      sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix"
   14.38 -      if test x${SDL_CONFIG+set} != xset ; then
   14.39 -        SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
   14.40 -      fi
   14.41 -    fi
   14.42 -    if test x$sdl_prefix != x ; then
   14.43 -      sdl_config_args="$sdl_config_args --prefix=$sdl_prefix"
   14.44 -      if test x${SDL_CONFIG+set} != xset ; then
   14.45 -        SDL_CONFIG=$sdl_prefix/bin/sdl-config
   14.46 -      fi
   14.47 -    fi
   14.48 -  fi
   14.49 -
   14.50 -  if test "x$sdl_pc" = xyes ; then
   14.51 -    no_sdl=""
   14.52 -    SDL_CONFIG="pkg-config sdl"
   14.53 -  else
   14.54 -    as_save_PATH="$PATH"
   14.55 -    if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
   14.56 -      PATH="$prefix/bin:$prefix/usr/bin:$PATH"
   14.57 -    fi
   14.58 -    AC_PATH_PROG(SDL_CONFIG, sdl-config, no, [$PATH])
   14.59 -    PATH="$as_save_PATH"
   14.60 -    AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
   14.61 -    no_sdl=""
   14.62 -
   14.63 -    if test "$SDL_CONFIG" = "no" ; then
   14.64 -      no_sdl=yes
   14.65 -    else
   14.66 -      SDL_CFLAGS=`$SDL_CONFIG $sdl_config_args --cflags`
   14.67 -      SDL_LIBS=`$SDL_CONFIG $sdl_config_args --libs`
   14.68 -
   14.69 -      sdl_major_version=`$SDL_CONFIG $sdl_config_args --version | \
   14.70 -             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
   14.71 -      sdl_minor_version=`$SDL_CONFIG $sdl_config_args --version | \
   14.72 -             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
   14.73 -      sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
   14.74 -             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
   14.75 -      if test "x$enable_sdltest" = "xyes" ; then
   14.76 -        ac_save_CFLAGS="$CFLAGS"
   14.77 -        ac_save_CXXFLAGS="$CXXFLAGS"
   14.78 -        ac_save_LIBS="$LIBS"
   14.79 -        CFLAGS="$CFLAGS $SDL_CFLAGS"
   14.80 -        CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
   14.81 -        LIBS="$LIBS $SDL_LIBS"
   14.82 -dnl
   14.83 -dnl Now check if the installed SDL is sufficiently new. (Also sanity
   14.84 -dnl checks the results of sdl-config to some extent
   14.85 -dnl
   14.86 -      rm -f conf.sdltest
   14.87 -      AC_TRY_RUN([
   14.88 -#include <stdio.h>
   14.89 -#include <stdlib.h>
   14.90 -#include <string.h>
   14.91 -#include "SDL.h"
   14.92 -
   14.93 -char*
   14.94 -my_strdup (char *str)
   14.95 -{
   14.96 -  char *new_str;
   14.97 -  
   14.98 -  if (str)
   14.99 -    {
  14.100 -      new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
  14.101 -      strcpy (new_str, str);
  14.102 -    }
  14.103 -  else
  14.104 -    new_str = NULL;
  14.105 -  
  14.106 -  return new_str;
  14.107 -}
  14.108 -
  14.109 -int main (int argc, char *argv[])
  14.110 -{
  14.111 -  int major, minor, micro;
  14.112 -  char *tmp_version;
  14.113 -
  14.114 -  /* This hangs on some systems (?)
  14.115 -  system ("touch conf.sdltest");
  14.116 -  */
  14.117 -  { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); }
  14.118 -
  14.119 -  /* HP/UX 9 (%@#!) writes to sscanf strings */
  14.120 -  tmp_version = my_strdup("$min_sdl_version");
  14.121 -  if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
  14.122 -     printf("%s, bad version string\n", "$min_sdl_version");
  14.123 -     exit(1);
  14.124 -   }
  14.125 -
  14.126 -   if (($sdl_major_version > major) ||
  14.127 -      (($sdl_major_version == major) && ($sdl_minor_version > minor)) ||
  14.128 -      (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro)))
  14.129 -    {
  14.130 -      return 0;
  14.131 -    }
  14.132 -  else
  14.133 -    {
  14.134 -      printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
  14.135 -      printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro);
  14.136 -      printf("*** best to upgrade to the required version.\n");
  14.137 -      printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n");
  14.138 -      printf("*** to point to the correct copy of sdl-config, and remove the file\n");
  14.139 -      printf("*** config.cache before re-running configure\n");
  14.140 -      return 1;
  14.141 -    }
  14.142 -}
  14.143 -
  14.144 -],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
  14.145 -        CFLAGS="$ac_save_CFLAGS"
  14.146 -        CXXFLAGS="$ac_save_CXXFLAGS"
  14.147 -        LIBS="$ac_save_LIBS"
  14.148 -      fi
  14.149 -    fi
  14.150 -    if test "x$no_sdl" = x ; then
  14.151 -      AC_MSG_RESULT(yes)
  14.152 -    else
  14.153 -      AC_MSG_RESULT(no)
  14.154 -    fi
  14.155 -  fi
  14.156 -  if test "x$no_sdl" = x ; then
  14.157 -     ifelse([$2], , :, [$2])
  14.158 -  else
  14.159 -     if test "$SDL_CONFIG" = "no" ; then
  14.160 -       echo "*** The sdl-config script installed by SDL could not be found"
  14.161 -       echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
  14.162 -       echo "*** your path, or set the SDL_CONFIG environment variable to the"
  14.163 -       echo "*** full path to sdl-config."
  14.164 -     else
  14.165 -       if test -f conf.sdltest ; then
  14.166 -        :
  14.167 -       else
  14.168 -          echo "*** Could not run SDL test program, checking why..."
  14.169 -          CFLAGS="$CFLAGS $SDL_CFLAGS"
  14.170 -          CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
  14.171 -          LIBS="$LIBS $SDL_LIBS"
  14.172 -          AC_TRY_LINK([
  14.173 -#include <stdio.h>
  14.174 -#include "SDL.h"
  14.175 -
  14.176 -int main(int argc, char *argv[])
  14.177 -{ return 0; }
  14.178 -#undef  main
  14.179 -#define main K_and_R_C_main
  14.180 -],      [ return 0; ],
  14.181 -        [ echo "*** The test program compiled, but did not run. This usually means"
  14.182 -          echo "*** that the run-time linker is not finding SDL or finding the wrong"
  14.183 -          echo "*** version of SDL. If it is not finding SDL, you'll need to set your"
  14.184 -          echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
  14.185 -          echo "*** to the installed location  Also, make sure you have run ldconfig if that"
  14.186 -          echo "*** is required on your system"
  14.187 -	  echo "***"
  14.188 -          echo "*** If you have an old version installed, it is best to remove it, although"
  14.189 -          echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
  14.190 -        [ echo "*** The test program failed to compile or link. See the file config.log for the"
  14.191 -          echo "*** exact error that occured. This usually means SDL was incorrectly installed"
  14.192 -          echo "*** or that you have moved SDL since it was installed. In the latter case, you"
  14.193 -          echo "*** may want to edit the sdl-config script: $SDL_CONFIG" ])
  14.194 -          CFLAGS="$ac_save_CFLAGS"
  14.195 -          CXXFLAGS="$ac_save_CXXFLAGS"
  14.196 -          LIBS="$ac_save_LIBS"
  14.197 -       fi
  14.198 -     fi
  14.199 -     SDL_CFLAGS=""
  14.200 -     SDL_LIBS=""
  14.201 -     ifelse([$3], , :, [$3])
  14.202 -  fi
  14.203 -  AC_SUBST(SDL_CFLAGS)
  14.204 -  AC_SUBST(SDL_LIBS)
  14.205 -  rm -f conf.sdltest
  14.206 -])
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/acinclude/sdl2.m4	Sun Jan 22 21:52:00 2012 -0500
    15.3 @@ -0,0 +1,202 @@
    15.4 +# Configure paths for SDL
    15.5 +# Sam Lantinga 9/21/99
    15.6 +# stolen from Manish Singh
    15.7 +# stolen back from Frank Belew
    15.8 +# stolen from Manish Singh
    15.9 +# Shamelessly stolen from Owen Taylor
   15.10 +
   15.11 +# serial 1
   15.12 +
   15.13 +dnl AM_PATH_SDL([MINIMUM-VERSION, [ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]]])
   15.14 +dnl Test for SDL, and define SDL_CFLAGS and SDL_LIBS
   15.15 +dnl
   15.16 +AC_DEFUN([AM_PATH_SDL],
   15.17 +[dnl 
   15.18 +dnl Get the cflags and libraries from the sdl2-config script
   15.19 +dnl
   15.20 +AC_ARG_WITH(sdl-prefix,[  --with-sdl-prefix=PFX   Prefix where SDL is installed (optional)],
   15.21 +            sdl_prefix="$withval", sdl_prefix="")
   15.22 +AC_ARG_WITH(sdl-exec-prefix,[  --with-sdl-exec-prefix=PFX Exec prefix where SDL is installed (optional)],
   15.23 +            sdl_exec_prefix="$withval", sdl_exec_prefix="")
   15.24 +AC_ARG_ENABLE(sdltest, [  --disable-sdltest       Do not try to compile and run a test SDL program],
   15.25 +		    , enable_sdltest=yes)
   15.26 +
   15.27 +  min_sdl_version=ifelse([$1], ,0.9.0,$1)
   15.28 +
   15.29 +  if test "x$sdl_prefix$sdl_exec_prefix" = x ; then
   15.30 +    PKG_CHECK_MODULES([SDL], [sdl2 >= $min_sdl_version],
   15.31 +           [sdl_pc=yes],
   15.32 +           [sdl_pc=no])
   15.33 +  else
   15.34 +    sdl_pc=no
   15.35 +    if test x$sdl_exec_prefix != x ; then
   15.36 +      sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix"
   15.37 +      if test x${SDL_CONFIG+set} != xset ; then
   15.38 +        SDL_CONFIG=$sdl_exec_prefix/bin/sdl2-config
   15.39 +      fi
   15.40 +    fi
   15.41 +    if test x$sdl_prefix != x ; then
   15.42 +      sdl_config_args="$sdl_config_args --prefix=$sdl_prefix"
   15.43 +      if test x${SDL_CONFIG+set} != xset ; then
   15.44 +        SDL_CONFIG=$sdl_prefix/bin/sdl2-config
   15.45 +      fi
   15.46 +    fi
   15.47 +  fi
   15.48 +
   15.49 +  if test "x$sdl_pc" = xyes ; then
   15.50 +    no_sdl=""
   15.51 +    SDL_CONFIG="pkg-config sdl2"
   15.52 +  else
   15.53 +    as_save_PATH="$PATH"
   15.54 +    if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
   15.55 +      PATH="$prefix/bin:$prefix/usr/bin:$PATH"
   15.56 +    fi
   15.57 +    AC_PATH_PROG(SDL_CONFIG, sdl2-config, no, [$PATH])
   15.58 +    PATH="$as_save_PATH"
   15.59 +    AC_MSG_CHECKING(for SDL - version >= $min_sdl_version)
   15.60 +    no_sdl=""
   15.61 +
   15.62 +    if test "$SDL_CONFIG" = "no" ; then
   15.63 +      no_sdl=yes
   15.64 +    else
   15.65 +      SDL_CFLAGS=`$SDL_CONFIG $sdl_config_args --cflags`
   15.66 +      SDL_LIBS=`$SDL_CONFIG $sdl_config_args --libs`
   15.67 +
   15.68 +      sdl_major_version=`$SDL_CONFIG $sdl_config_args --version | \
   15.69 +             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\1/'`
   15.70 +      sdl_minor_version=`$SDL_CONFIG $sdl_config_args --version | \
   15.71 +             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\2/'`
   15.72 +      sdl_micro_version=`$SDL_CONFIG $sdl_config_args --version | \
   15.73 +             sed 's/\([[0-9]]*\).\([[0-9]]*\).\([[0-9]]*\)/\3/'`
   15.74 +      if test "x$enable_sdltest" = "xyes" ; then
   15.75 +        ac_save_CFLAGS="$CFLAGS"
   15.76 +        ac_save_CXXFLAGS="$CXXFLAGS"
   15.77 +        ac_save_LIBS="$LIBS"
   15.78 +        CFLAGS="$CFLAGS $SDL_CFLAGS"
   15.79 +        CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
   15.80 +        LIBS="$LIBS $SDL_LIBS"
   15.81 +dnl
   15.82 +dnl Now check if the installed SDL is sufficiently new. (Also sanity
   15.83 +dnl checks the results of sdl2-config to some extent
   15.84 +dnl
   15.85 +      rm -f conf.sdltest
   15.86 +      AC_TRY_RUN([
   15.87 +#include <stdio.h>
   15.88 +#include <stdlib.h>
   15.89 +#include <string.h>
   15.90 +#include "SDL.h"
   15.91 +
   15.92 +char*
   15.93 +my_strdup (char *str)
   15.94 +{
   15.95 +  char *new_str;
   15.96 +  
   15.97 +  if (str)
   15.98 +    {
   15.99 +      new_str = (char *)malloc ((strlen (str) + 1) * sizeof(char));
  15.100 +      strcpy (new_str, str);
  15.101 +    }
  15.102 +  else
  15.103 +    new_str = NULL;
  15.104 +  
  15.105 +  return new_str;
  15.106 +}
  15.107 +
  15.108 +int main (int argc, char *argv[])
  15.109 +{
  15.110 +  int major, minor, micro;
  15.111 +  char *tmp_version;
  15.112 +
  15.113 +  /* This hangs on some systems (?)
  15.114 +  system ("touch conf.sdltest");
  15.115 +  */
  15.116 +  { FILE *fp = fopen("conf.sdltest", "a"); if ( fp ) fclose(fp); }
  15.117 +
  15.118 +  /* HP/UX 9 (%@#!) writes to sscanf strings */
  15.119 +  tmp_version = my_strdup("$min_sdl_version");
  15.120 +  if (sscanf(tmp_version, "%d.%d.%d", &major, &minor, &micro) != 3) {
  15.121 +     printf("%s, bad version string\n", "$min_sdl_version");
  15.122 +     exit(1);
  15.123 +   }
  15.124 +
  15.125 +   if (($sdl_major_version > major) ||
  15.126 +      (($sdl_major_version == major) && ($sdl_minor_version > minor)) ||
  15.127 +      (($sdl_major_version == major) && ($sdl_minor_version == minor) && ($sdl_micro_version >= micro)))
  15.128 +    {
  15.129 +      return 0;
  15.130 +    }
  15.131 +  else
  15.132 +    {
  15.133 +      printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
  15.134 +      printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro);
  15.135 +      printf("*** best to upgrade to the required version.\n");
  15.136 +      printf("*** If sdl2-config was wrong, set the environment variable SDL_CONFIG\n");
  15.137 +      printf("*** to point to the correct copy of sdl2-config, and remove the file\n");
  15.138 +      printf("*** config.cache before re-running configure\n");
  15.139 +      return 1;
  15.140 +    }
  15.141 +}
  15.142 +
  15.143 +],, no_sdl=yes,[echo $ac_n "cross compiling; assumed OK... $ac_c"])
  15.144 +        CFLAGS="$ac_save_CFLAGS"
  15.145 +        CXXFLAGS="$ac_save_CXXFLAGS"
  15.146 +        LIBS="$ac_save_LIBS"
  15.147 +      fi
  15.148 +    fi
  15.149 +    if test "x$no_sdl" = x ; then
  15.150 +      AC_MSG_RESULT(yes)
  15.151 +    else
  15.152 +      AC_MSG_RESULT(no)
  15.153 +    fi
  15.154 +  fi
  15.155 +  if test "x$no_sdl" = x ; then
  15.156 +     ifelse([$2], , :, [$2])
  15.157 +  else
  15.158 +     if test "$SDL_CONFIG" = "no" ; then
  15.159 +       echo "*** The sdl2-config script installed by SDL could not be found"
  15.160 +       echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
  15.161 +       echo "*** your path, or set the SDL_CONFIG environment variable to the"
  15.162 +       echo "*** full path to sdl2-config."
  15.163 +     else
  15.164 +       if test -f conf.sdltest ; then
  15.165 +        :
  15.166 +       else
  15.167 +          echo "*** Could not run SDL test program, checking why..."
  15.168 +          CFLAGS="$CFLAGS $SDL_CFLAGS"
  15.169 +          CXXFLAGS="$CXXFLAGS $SDL_CFLAGS"
  15.170 +          LIBS="$LIBS $SDL_LIBS"
  15.171 +          AC_TRY_LINK([
  15.172 +#include <stdio.h>
  15.173 +#include "SDL.h"
  15.174 +
  15.175 +int main(int argc, char *argv[])
  15.176 +{ return 0; }
  15.177 +#undef  main
  15.178 +#define main K_and_R_C_main
  15.179 +],      [ return 0; ],
  15.180 +        [ echo "*** The test program compiled, but did not run. This usually means"
  15.181 +          echo "*** that the run-time linker is not finding SDL or finding the wrong"
  15.182 +          echo "*** version of SDL. If it is not finding SDL, you'll need to set your"
  15.183 +          echo "*** LD_LIBRARY_PATH environment variable, or edit /etc/ld.so.conf to point"
  15.184 +          echo "*** to the installed location  Also, make sure you have run ldconfig if that"
  15.185 +          echo "*** is required on your system"
  15.186 +	  echo "***"
  15.187 +          echo "*** If you have an old version installed, it is best to remove it, although"
  15.188 +          echo "*** you may also be able to get things to work by modifying LD_LIBRARY_PATH"],
  15.189 +        [ echo "*** The test program failed to compile or link. See the file config.log for the"
  15.190 +          echo "*** exact error that occured. This usually means SDL was incorrectly installed"
  15.191 +          echo "*** or that you have moved SDL since it was installed. In the latter case, you"
  15.192 +          echo "*** may want to edit the sdl2-config script: $SDL_CONFIG" ])
  15.193 +          CFLAGS="$ac_save_CFLAGS"
  15.194 +          CXXFLAGS="$ac_save_CXXFLAGS"
  15.195 +          LIBS="$ac_save_LIBS"
  15.196 +       fi
  15.197 +     fi
  15.198 +     SDL_CFLAGS=""
  15.199 +     SDL_LIBS=""
  15.200 +     ifelse([$3], , :, [$3])
  15.201 +  fi
  15.202 +  AC_SUBST(SDL_CFLAGS)
  15.203 +  AC_SUBST(SDL_LIBS)
  15.204 +  rm -f conf.sdltest
  15.205 +])
    16.1 --- a/aclocal.m4	Sun Jan 22 20:11:17 2012 -0500
    16.2 +++ b/aclocal.m4	Sun Jan 22 21:52:00 2012 -0500
    16.3 @@ -965,4 +965,4 @@
    16.4  m4_include([acinclude/ltversion.m4])
    16.5  m4_include([acinclude/lt~obsolete.m4])
    16.6  m4_include([acinclude/pkg.m4])
    16.7 -m4_include([acinclude/sdl.m4])
    16.8 +m4_include([acinclude/sdl2.m4])
    17.1 --- a/configure	Sun Jan 22 20:11:17 2012 -0500
    17.2 +++ b/configure	Sun Jan 22 21:52:00 2012 -0500
    17.3 @@ -12799,7 +12799,7 @@
    17.4      done
    17.5  }
    17.6  
    17.7 -SDL_VERSION=1.2.10
    17.8 +SDL_VERSION=2.0.0
    17.9  
   17.10  
   17.11  
   17.12 @@ -12958,12 +12958,12 @@
   17.13          pkg_cv_SDL_CFLAGS="$SDL_CFLAGS"
   17.14      else
   17.15          if test -n "$PKG_CONFIG" && \
   17.16 -    { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"sdl >= \$min_sdl_version\"") >&5
   17.17 -  ($PKG_CONFIG --exists --print-errors "sdl >= $min_sdl_version") 2>&5
   17.18 +    { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"sdl2 >= \$min_sdl_version\"") >&5
   17.19 +  ($PKG_CONFIG --exists --print-errors "sdl2 >= $min_sdl_version") 2>&5
   17.20    ac_status=$?
   17.21    echo "$as_me:$LINENO: \$? = $ac_status" >&5
   17.22    (exit $ac_status); }; then
   17.23 -  pkg_cv_SDL_CFLAGS=`$PKG_CONFIG --cflags "sdl >= $min_sdl_version" 2>/dev/null`
   17.24 +  pkg_cv_SDL_CFLAGS=`$PKG_CONFIG --cflags "sdl2 >= $min_sdl_version" 2>/dev/null`
   17.25  else
   17.26    pkg_failed=yes
   17.27  fi
   17.28 @@ -12976,12 +12976,12 @@
   17.29          pkg_cv_SDL_LIBS="$SDL_LIBS"
   17.30      else
   17.31          if test -n "$PKG_CONFIG" && \
   17.32 -    { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"sdl >= \$min_sdl_version\"") >&5
   17.33 -  ($PKG_CONFIG --exists --print-errors "sdl >= $min_sdl_version") 2>&5
   17.34 +    { (echo "$as_me:$LINENO: \$PKG_CONFIG --exists --print-errors \"sdl2 >= \$min_sdl_version\"") >&5
   17.35 +  ($PKG_CONFIG --exists --print-errors "sdl2 >= $min_sdl_version") 2>&5
   17.36    ac_status=$?
   17.37    echo "$as_me:$LINENO: \$? = $ac_status" >&5
   17.38    (exit $ac_status); }; then
   17.39 -  pkg_cv_SDL_LIBS=`$PKG_CONFIG --libs "sdl >= $min_sdl_version" 2>/dev/null`
   17.40 +  pkg_cv_SDL_LIBS=`$PKG_CONFIG --libs "sdl2 >= $min_sdl_version" 2>/dev/null`
   17.41  else
   17.42    pkg_failed=yes
   17.43  fi
   17.44 @@ -13000,24 +13000,18 @@
   17.45          _pkg_short_errors_supported=no
   17.46  fi
   17.47          if test $_pkg_short_errors_supported = yes; then
   17.48 -	        SDL_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "sdl >= $min_sdl_version"`
   17.49 +	        SDL_PKG_ERRORS=`$PKG_CONFIG --short-errors --errors-to-stdout --print-errors "sdl2 >= $min_sdl_version"`
   17.50          else
   17.51 -	        SDL_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "sdl >= $min_sdl_version"`
   17.52 +	        SDL_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "sdl2 >= $min_sdl_version"`
   17.53          fi
   17.54  	# Put the nasty error message in config.log where it belongs
   17.55  	echo "$SDL_PKG_ERRORS" >&5
   17.56  
   17.57  	{ echo "$as_me:$LINENO: result: no" >&5
   17.58  echo "${ECHO_T}no" >&6; }
   17.59 -                             { echo "$as_me:$LINENO: result: no" >&5
   17.60 -echo "${ECHO_T}no" >&6; }
   17.61 -             sdl_pc=no
   17.62 -
   17.63 +                sdl_pc=no
   17.64  elif test $pkg_failed = untried; then
   17.65 -	             { echo "$as_me:$LINENO: result: no" >&5
   17.66 -echo "${ECHO_T}no" >&6; }
   17.67 -             sdl_pc=no
   17.68 -
   17.69 +	sdl_pc=no
   17.70  else
   17.71  	SDL_CFLAGS=$pkg_cv_SDL_CFLAGS
   17.72  	SDL_LIBS=$pkg_cv_SDL_LIBS
   17.73 @@ -13030,27 +13024,27 @@
   17.74      if test x$sdl_exec_prefix != x ; then
   17.75        sdl_config_args="$sdl_config_args --exec-prefix=$sdl_exec_prefix"
   17.76        if test x${SDL_CONFIG+set} != xset ; then
   17.77 -        SDL_CONFIG=$sdl_exec_prefix/bin/sdl-config
   17.78 +        SDL_CONFIG=$sdl_exec_prefix/bin/sdl2-config
   17.79        fi
   17.80      fi
   17.81      if test x$sdl_prefix != x ; then
   17.82        sdl_config_args="$sdl_config_args --prefix=$sdl_prefix"
   17.83        if test x${SDL_CONFIG+set} != xset ; then
   17.84 -        SDL_CONFIG=$sdl_prefix/bin/sdl-config
   17.85 +        SDL_CONFIG=$sdl_prefix/bin/sdl2-config
   17.86        fi
   17.87      fi
   17.88    fi
   17.89  
   17.90    if test "x$sdl_pc" = xyes ; then
   17.91      no_sdl=""
   17.92 -    SDL_CONFIG="pkg-config sdl"
   17.93 +    SDL_CONFIG="pkg-config sdl2"
   17.94    else
   17.95      as_save_PATH="$PATH"
   17.96      if test "x$prefix" != xNONE && test "$cross_compiling" != yes; then
   17.97        PATH="$prefix/bin:$prefix/usr/bin:$PATH"
   17.98      fi
   17.99 -    # Extract the first word of "sdl-config", so it can be a program name with args.
  17.100 -set dummy sdl-config; ac_word=$2
  17.101 +    # Extract the first word of "sdl2-config", so it can be a program name with args.
  17.102 +set dummy sdl2-config; ac_word=$2
  17.103  { echo "$as_me:$LINENO: checking for $ac_word" >&5
  17.104  echo $ECHO_N "checking for $ac_word... $ECHO_C" >&6; }
  17.105  if test "${ac_cv_path_SDL_CONFIG+set}" = set; then
  17.106 @@ -13171,11 +13165,11 @@
  17.107      }
  17.108    else
  17.109      {
  17.110 -      printf("\n*** 'sdl-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
  17.111 -      printf("*** of SDL required is %d.%d.%d. If sdl-config is correct, then it is\n", major, minor, micro);
  17.112 +      printf("\n*** 'sdl2-config --version' returned %d.%d.%d, but the minimum version\n", $sdl_major_version, $sdl_minor_version, $sdl_micro_version);
  17.113 +      printf("*** of SDL required is %d.%d.%d. If sdl2-config is correct, then it is\n", major, minor, micro);
  17.114        printf("*** best to upgrade to the required version.\n");
  17.115 -      printf("*** If sdl-config was wrong, set the environment variable SDL_CONFIG\n");
  17.116 -      printf("*** to point to the correct copy of sdl-config, and remove the file\n");
  17.117 +      printf("*** If sdl2-config was wrong, set the environment variable SDL_CONFIG\n");
  17.118 +      printf("*** to point to the correct copy of sdl2-config, and remove the file\n");
  17.119        printf("*** config.cache before re-running configure\n");
  17.120        return 1;
  17.121      }
  17.122 @@ -13233,10 +13227,10 @@
  17.123       :
  17.124    else
  17.125       if test "$SDL_CONFIG" = "no" ; then
  17.126 -       echo "*** The sdl-config script installed by SDL could not be found"
  17.127 +       echo "*** The sdl2-config script installed by SDL could not be found"
  17.128         echo "*** If SDL was installed in PREFIX, make sure PREFIX/bin is in"
  17.129         echo "*** your path, or set the SDL_CONFIG environment variable to the"
  17.130 -       echo "*** full path to sdl-config."
  17.131 +       echo "*** full path to sdl2-config."
  17.132       else
  17.133         if test -f conf.sdltest ; then
  17.134          :
  17.135 @@ -13302,7 +13296,7 @@
  17.136  	 echo "*** The test program failed to compile or link. See the file config.log for the"
  17.137            echo "*** exact error that occured. This usually means SDL was incorrectly installed"
  17.138            echo "*** or that you have moved SDL since it was installed. In the latter case, you"
  17.139 -          echo "*** may want to edit the sdl-config script: $SDL_CONFIG"
  17.140 +          echo "*** may want to edit the sdl2-config script: $SDL_CONFIG"
  17.141  fi
  17.142  
  17.143  rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
    18.1 --- a/configure.in	Sun Jan 22 20:11:17 2012 -0500
    18.2 +++ b/configure.in	Sun Jan 22 21:52:00 2012 -0500
    18.3 @@ -113,7 +113,7 @@
    18.4  }
    18.5  
    18.6  dnl Check for SDL
    18.7 -SDL_VERSION=1.2.10
    18.8 +SDL_VERSION=2.0.0
    18.9  AC_SUBST(SDL_VERSION)
   18.10  AM_PATH_SDL($SDL_VERSION,
   18.11              :,
    19.1 --- a/showimage.c	Sun Jan 22 20:11:17 2012 -0500
    19.2 +++ b/showimage.c	Sun Jan 22 21:52:00 2012 -0500
    19.3 @@ -26,191 +26,132 @@
    19.4  #include "SDL.h"
    19.5  #include "SDL_image.h"
    19.6  
    19.7 -/* #define XPM_INCLUDED and supply picture.xpm to test the XPM inclusion
    19.8 -   feature */
    19.9 -
   19.10 -#ifdef XPM_INCLUDED
   19.11 -#include "picture.xpm"
   19.12 -#endif
   19.13  
   19.14  /* Draw a Gimpish background pattern to show transparency in the image */
   19.15 -static void draw_background(SDL_Surface *screen)
   19.16 +static void draw_background(SDL_Renderer *renderer, int w, int h)
   19.17  {
   19.18 -    Uint8 *dst = screen->pixels;
   19.19 -    int x, y;
   19.20 -    int bpp = screen->format->BytesPerPixel;
   19.21 -    Uint32 col[2];
   19.22 -    col[0] = SDL_MapRGB(screen->format, 0x66, 0x66, 0x66);
   19.23 -    col[1] = SDL_MapRGB(screen->format, 0x99, 0x99, 0x99);
   19.24 -    for(y = 0; y < screen->h; y++) {
   19.25 -	for(x = 0; x < screen->w; x++) {
   19.26 -	    /* use an 8x8 checkerboard pattern */
   19.27 -	    Uint32 c = col[((x ^ y) >> 3) & 1];
   19.28 -	    switch(bpp) {
   19.29 -	    case 1:
   19.30 -		dst[x] = (Uint8)c;
   19.31 -		break;
   19.32 -	    case 2:
   19.33 -		((Uint16 *)dst)[x] = (Uint16)c;
   19.34 -		break;
   19.35 -	    case 3:
   19.36 -#if SDL_BYTEORDER == SDL_LIL_ENDIAN
   19.37 -		dst[x * 3]     = (Uint8)(c);
   19.38 -		dst[x * 3 + 1] = (Uint8)(c >> 8);
   19.39 -		dst[x * 3 + 2] = (Uint8)(c >> 16);
   19.40 -#else
   19.41 -		dst[x * 3]     = (Uint8)(c >> 16);
   19.42 -		dst[x * 3 + 1] = (Uint8)(c >> 8);
   19.43 -		dst[x * 3 + 2] = (Uint8)(c);
   19.44 -#endif
   19.45 -		break;
   19.46 -	    case 4:
   19.47 -		((Uint32 *)dst)[x] = c;
   19.48 -		break;
   19.49 -	    }
   19.50 -	}
   19.51 -	dst += screen->pitch;
   19.52 +    SDL_Color col[2] = {
   19.53 +        { 0x66, 0x66, 0x66, 0xff },
   19.54 +        { 0x99, 0x99, 0x99, 0xff },
   19.55 +    };
   19.56 +    int i, x, y;
   19.57 +    SDL_Rect rect;
   19.58 +
   19.59 +    rect.w = 8;
   19.60 +    rect.h = 8;
   19.61 +    for (y = 0; y < h; y += rect.h) {
   19.62 +        for (x = 0; x < w; x += rect.w) {
   19.63 +            /* use an 8x8 checkerboard pattern */
   19.64 +            i = (((x ^ y) >> 3) & 1);
   19.65 +            SDL_SetRenderDrawColor(renderer, col[i].r, col[i].g, col[i].b, col[i].unused);
   19.66 +
   19.67 +            rect.x = x;
   19.68 +            rect.y = y;
   19.69 +            SDL_RenderFillRect(renderer, &rect);
   19.70 +        }
   19.71      }
   19.72  }
   19.73  
   19.74  int main(int argc, char *argv[])
   19.75  {
   19.76 -	Uint32 flags;
   19.77 -	SDL_Surface *screen, *image;
   19.78 -	int i, depth, done;
   19.79 -	SDL_Event event;
   19.80 -#if 0
   19.81 -	SDL_RWops* rw_ops;
   19.82 -#endif
   19.83 +    SDL_Window *window;
   19.84 +    SDL_Renderer *renderer;
   19.85 +    SDL_Texture *texture;
   19.86 +    Uint32 flags;
   19.87 +    int i, w, h, done;
   19.88 +    SDL_Event event;
   19.89  
   19.90 -	/* Check command line usage */
   19.91 -	if ( ! argv[1] ) {
   19.92 -		fprintf(stderr, "Usage: %s <image_file>\n", argv[0]);
   19.93 -		return(1);
   19.94 -	}
   19.95 +    /* Check command line usage */
   19.96 +    if ( ! argv[1] ) {
   19.97 +        fprintf(stderr, "Usage: %s [-fullscreen] <image_file> ...\n", argv[0]);
   19.98 +        return(1);
   19.99 +    }
  19.100  
  19.101 -	/* Initialize the SDL library */
  19.102 -	if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) {
  19.103 -		fprintf(stderr, "Couldn't initialize SDL: %s\n",SDL_GetError());
  19.104 -		return(255);
  19.105 -	}
  19.106 +    flags = SDL_WINDOW_HIDDEN;
  19.107 +    for ( i=1; argv[i]; ++i ) {
  19.108 +        if ( strcmp(argv[i], "-fullscreen") == 0 ) {
  19.109 +            SDL_ShowCursor(0);
  19.110 +            flags |= SDL_WINDOW_FULLSCREEN;
  19.111 +        }
  19.112 +    }
  19.113 +    
  19.114 +    if (SDL_CreateWindowAndRenderer(0, 0, flags, &window, &renderer) < 0) {
  19.115 +        fprintf(stderr, "SDL_CreateWindowAndRenderer() failed: %s\n", SDL_GetError());
  19.116 +        return(2);
  19.117 +    }
  19.118  
  19.119 -	flags = SDL_SWSURFACE;
  19.120 -	for ( i=1; argv[i]; ++i ) {
  19.121 -		if ( strcmp(argv[i], "-fullscreen") == 0 ) {
  19.122 -			SDL_ShowCursor(0);
  19.123 -			flags |= SDL_FULLSCREEN;
  19.124 -			continue;
  19.125 -		}
  19.126 -#if 0
  19.127 -		rw_ops = SDL_RWFromFile(argv[1], "r");
  19.128 -		
  19.129 -		fprintf(stderr, "BMP:\t%d\n", IMG_isBMP(rw_ops));
  19.130 -		fprintf(stderr, "GIF:\t%d\n", IMG_isGIF(rw_ops));
  19.131 -		fprintf(stderr, "JPG:\t%d\n", IMG_isJPG(rw_ops));
  19.132 -		fprintf(stderr, "PNG:\t%d\n", IMG_isPNG(rw_ops));
  19.133 -		fprintf(stderr, "TIF:\t%d\n", IMG_isTIF(rw_ops));
  19.134 -		/* fprintf(stderr, "TGA:\t%d\n", IMG_isTGA(rw_ops)); */
  19.135 -		fprintf(stderr, "PCX:\t%d\n", IMG_isPCX(rw_ops));
  19.136 -#endif
  19.137 +    for ( i=1; argv[i]; ++i ) {
  19.138 +        if ( strcmp(argv[i], "-fullscreen") == 0 ) {
  19.139 +            continue;
  19.140 +        }
  19.141  
  19.142 -		/* Open the image file */
  19.143 -#ifdef XPM_INCLUDED
  19.144 -		image = IMG_ReadXPMFromArray(picture_xpm);
  19.145 -#else
  19.146 -		image = IMG_Load(argv[i]);
  19.147 -#endif
  19.148 -		if ( image == NULL ) {
  19.149 -			fprintf(stderr, "Couldn't load %s: %s\n",
  19.150 -			        argv[i], SDL_GetError());
  19.151 -			continue;
  19.152 -		}
  19.153 -		SDL_WM_SetCaption(argv[i], "showimage");
  19.154 +        /* Open the image file */
  19.155 +        texture = IMG_LoadTexture(renderer, argv[i]);
  19.156 +        if (!texture) {
  19.157 +            fprintf(stderr, "Couldn't load %s: %s\n", argv[i], SDL_GetError());
  19.158 +            continue;
  19.159 +        }
  19.160 +        SDL_QueryTexture(texture, NULL, NULL, &w, &h);
  19.161  
  19.162 -		/* Create a display for the image */
  19.163 -		depth = SDL_VideoModeOK(image->w, image->h, 32, flags);
  19.164 -		/* Use the deepest native mode, except that we emulate 32bpp
  19.165 -		   for viewing non-indexed images on 8bpp screens */
  19.166 -		if ( depth == 0 ) {
  19.167 -			if ( image->format->BytesPerPixel > 1 ) {
  19.168 -				depth = 32;
  19.169 -			} else {
  19.170 -				depth = 8;
  19.171 -			}
  19.172 -		} else
  19.173 -		if ( (image->format->BytesPerPixel > 1) && (depth == 8) ) {
  19.174 -	    		depth = 32;
  19.175 -		}
  19.176 -		if(depth == 8)
  19.177 -			flags |= SDL_HWPALETTE;
  19.178 -		screen = SDL_SetVideoMode(image->w, image->h, depth, flags);
  19.179 -		if ( screen == NULL ) {
  19.180 -			fprintf(stderr,"Couldn't set %dx%dx%d video mode: %s\n",
  19.181 -				image->w, image->h, depth, SDL_GetError());
  19.182 -			continue;
  19.183 -		}
  19.184 +        /* Show the window */
  19.185 +        SDL_SetWindowTitle(window, argv[i]);
  19.186 +        SDL_SetWindowSize(window, w, h);
  19.187 +        SDL_ShowWindow(window);
  19.188  
  19.189 -		/* Set the palette, if one exists */
  19.190 -		if ( image->format->palette ) {
  19.191 -			SDL_SetColors(screen, image->format->palette->colors,
  19.192 -			              0, image->format->palette->ncolors);
  19.193 -		}
  19.194 +        /* Draw a background pattern in case the image has transparency */
  19.195 +        draw_background(renderer, w, h);
  19.196  
  19.197 -		/* Draw a background pattern if the surface has transparency */
  19.198 -		if(image->flags & (SDL_SRCALPHA | SDL_SRCCOLORKEY))
  19.199 -	    		draw_background(screen);
  19.200 +        /* Display the image */
  19.201 +        SDL_RenderCopy(renderer, texture, NULL, NULL);
  19.202 +        SDL_RenderPresent(renderer);
  19.203  
  19.204 -		/* Display the image */
  19.205 -		SDL_BlitSurface(image, NULL, screen, NULL);
  19.206 -		SDL_UpdateRect(screen, 0, 0, 0, 0);
  19.207 +        done = 0;
  19.208 +        while ( ! done ) {
  19.209 +            if ( SDL_PollEvent(&event) ) {
  19.210 +                switch (event.type) {
  19.211 +                    case SDL_KEYUP:
  19.212 +                        switch (event.key.keysym.sym) {
  19.213 +                            case SDLK_LEFT:
  19.214 +                                if ( i > 1 ) {
  19.215 +                                    i -= 2;
  19.216 +                                    done = 1;
  19.217 +                                }
  19.218 +                                break;
  19.219 +                            case SDLK_RIGHT:
  19.220 +                                if ( argv[i+1] ) {
  19.221 +                                    done = 1;
  19.222 +                                }
  19.223 +                                break;
  19.224 +                            case SDLK_ESCAPE:
  19.225 +                            case SDLK_q:
  19.226 +                                argv[i+1] = NULL;
  19.227 +                            /* Drop through to done */
  19.228 +                            case SDLK_SPACE:
  19.229 +                            case SDLK_TAB:
  19.230 +                            done = 1;
  19.231 +                            break;
  19.232 +                            default:
  19.233 +                            break;
  19.234 +                        }
  19.235 +                        break;
  19.236 +                    case SDL_MOUSEBUTTONDOWN:
  19.237 +                        done = 1;
  19.238 +                        break;
  19.239 +                    case SDL_QUIT:
  19.240 +                        argv[i+1] = NULL;
  19.241 +                        done = 1;
  19.242 +                        break;
  19.243 +                    default:
  19.244 +                        break;
  19.245 +                }
  19.246 +            } else {
  19.247 +                SDL_Delay(10);
  19.248 +            }
  19.249 +        }
  19.250 +        SDL_DestroyTexture(texture);
  19.251 +    }
  19.252  
  19.253 -		done = 0;
  19.254 -		while ( ! done ) {
  19.255 -			if ( SDL_PollEvent(&event) ) {
  19.256 -				switch (event.type) {
  19.257 -				    case SDL_KEYUP:
  19.258 -					switch (event.key.keysym.sym) {
  19.259 -					    case SDLK_LEFT:
  19.260 -						if ( i > 1 ) {
  19.261 -							i -= 2;
  19.262 -							done = 1;
  19.263 -						}
  19.264 -						break;
  19.265 -					    case SDLK_RIGHT:
  19.266 -						if ( argv[i+1] ) {
  19.267 -							done = 1;
  19.268 -						}
  19.269 -						break;
  19.270 -					    case SDLK_ESCAPE:
  19.271 -					    case SDLK_q:
  19.272 -						argv[i+1] = NULL;
  19.273 -						/* Drop through to done */
  19.274 -					    case SDLK_SPACE:
  19.275 -					    case SDLK_TAB:
  19.276 -						done = 1;
  19.277 -						break;
  19.278 -					    default:
  19.279 -						break;
  19.280 -					}
  19.281 -					break;
  19.282 -				    case SDL_MOUSEBUTTONDOWN:
  19.283 -					done = 1;
  19.284 -					break;
  19.285 -                                    case SDL_QUIT:
  19.286 -					argv[i+1] = NULL;
  19.287 -					done = 1;
  19.288 -					break;
  19.289 -				    default:
  19.290 -					break;
  19.291 -				}
  19.292 -			} else {
  19.293 -				SDL_Delay(10);
  19.294 -			}
  19.295 -		}
  19.296 -		SDL_FreeSurface(image);
  19.297 -	}
  19.298 -
  19.299 -	/* We're done! */
  19.300 -	SDL_Quit();
  19.301 -	return(0);
  19.302 +    /* We're done! */
  19.303 +    SDL_Quit();
  19.304 +    return(0);
  19.305  }