Mason Wheeler - 2009-06-10 06:29:45 PDT
authorSam Lantinga <slouken@libsdl.org>
Sat, 26 Sep 2009 09:09:53 +0000
changeset 2050aa18e250940
parent 204 dcb38b0e78a6
child 206 4dcd1d3c3636
Mason Wheeler - 2009-06-10 06:29:45 PDT
* Added IMG_Init()/IMG_Quit() to prevent constantly loading and unloading DLLs
CHANGES
IMG.c
IMG_jpg.c
IMG_png.c
IMG_tif.c
SDL_image.h
     1.1 --- a/CHANGES	Sat Sep 26 08:54:15 2009 +0000
     1.2 +++ b/CHANGES	Sat Sep 26 09:09:53 2009 +0000
     1.3 @@ -1,4 +1,6 @@
     1.4  1.2.8:
     1.5 +Mason Wheeler - 2009-06-10 06:29:45 PDT 
     1.6 + * Added IMG_Init()/IMG_Quit() to prevent constantly loading and unloading DLLs
     1.7  Couriersud - Mon, 12 Jan 2009 17:21:13 -0800
     1.8   * Added support for ICO and CUR image files
     1.9  Eric Wing - Fri, 2 Jan 2009 02:01:16 -0800
     2.1 --- a/IMG.c	Sat Sep 26 08:54:15 2009 +0000
     2.2 +++ b/IMG.c	Sat Sep 26 09:09:53 2009 +0000
     2.3 @@ -60,6 +60,53 @@
     2.4  	return(&linked_version);
     2.5  }
     2.6  
     2.7 +extern int IMG_InitJPG();
     2.8 +extern int IMG_QuitJPG();
     2.9 +extern int IMG_InitPNG();
    2.10 +extern int IMG_QuitPNG();
    2.11 +extern int IMG_InitTIF();
    2.12 +extern int IMG_QuitTIF();
    2.13 +
    2.14 +static int initialized = 0;
    2.15 +
    2.16 +int IMG_Init(int flags)
    2.17 +{
    2.18 +	int result = 0;
    2.19 +
    2.20 +	if ((flags & IMG_INIT_JPG) && !(initialized & IMG_INIT_JPG)) {
    2.21 +		if (IMG_InitJPG() == 0) {
    2.22 +			result |= IMG_INIT_JPG;
    2.23 +		}
    2.24 +	}
    2.25 +	if ((flags & IMG_INIT_PNG) && !(initialized & IMG_INIT_PNG)) {
    2.26 +		if (IMG_InitPNG() == 0) {
    2.27 +			result |= IMG_INIT_PNG;
    2.28 +		}
    2.29 +	}
    2.30 +	if ((flags & IMG_INIT_TIF) && !(initialized & IMG_INIT_TIF)) {
    2.31 +		if (IMG_InitTIF() == 0) {
    2.32 +			result |= IMG_INIT_TIF;
    2.33 +		}
    2.34 +	}
    2.35 +	initialized |= result;
    2.36 +
    2.37 +	return (result);
    2.38 +}
    2.39 +
    2.40 +void IMG_Quit()
    2.41 +{
    2.42 +	if (initialized & IMG_INIT_JPG) {
    2.43 +		IMG_QuitJPG();
    2.44 +	}
    2.45 +	if (initialized & IMG_INIT_PNG) {
    2.46 +		IMG_QuitPNG();
    2.47 +	}
    2.48 +	if (initialized & IMG_INIT_TIF) {
    2.49 +		IMG_QuitTIF();
    2.50 +	}
    2.51 +	initialized = 0;
    2.52 +}
    2.53 +
    2.54  #if !defined(__APPLE__) || defined(SDL_IMAGE_USE_COMMON_BACKEND)
    2.55  /* Load an image from a file */
    2.56  SDL_Surface *IMG_Load(const char *file)
     3.1 --- a/IMG_jpg.c	Sat Sep 26 08:54:15 2009 +0000
     3.2 +++ b/IMG_jpg.c	Sat Sep 26 09:09:53 2009 +0000
     3.3 @@ -53,7 +53,7 @@
     3.4  } lib;
     3.5  
     3.6  #ifdef LOAD_JPG_DYNAMIC
     3.7 -static int IMG_InitJPG()
     3.8 +int IMG_InitJPG()
     3.9  {
    3.10  	if ( lib.loaded == 0 ) {
    3.11  		lib.handle = SDL_LoadObject(LOAD_JPG_DYNAMIC);
    3.12 @@ -128,7 +128,7 @@
    3.13  
    3.14  	return 0;
    3.15  }
    3.16 -static void IMG_QuitJPG()
    3.17 +void IMG_QuitJPG()
    3.18  {
    3.19  	if ( lib.loaded == 0 ) {
    3.20  		return;
    3.21 @@ -139,7 +139,7 @@
    3.22  	--lib.loaded;
    3.23  }
    3.24  #else
    3.25 -static int IMG_InitJPG()
    3.26 +int IMG_InitJPG()
    3.27  {
    3.28  	if ( lib.loaded == 0 ) {
    3.29  		lib.jpeg_calc_output_dimensions = jpeg_calc_output_dimensions;
    3.30 @@ -156,7 +156,7 @@
    3.31  
    3.32  	return 0;
    3.33  }
    3.34 -static void IMG_QuitJPG()
    3.35 +void IMG_QuitJPG()
    3.36  {
    3.37  	if ( lib.loaded == 0 ) {
    3.38  		return;
    3.39 @@ -465,6 +465,16 @@
    3.40  
    3.41  #else
    3.42  
    3.43 +int IMG_InitJPG()
    3.44 +{
    3.45 +	IMG_SetError("JPEG images are not supported");
    3.46 +	return(-1);
    3.47 +}
    3.48 +
    3.49 +void IMG_QuitJPG()
    3.50 +{
    3.51 +}
    3.52 +
    3.53  /* See if an image is contained in a data source */
    3.54  int IMG_isJPG(SDL_RWops *src)
    3.55  {
     4.1 --- a/IMG_png.c	Sat Sep 26 08:54:15 2009 +0000
     4.2 +++ b/IMG_png.c	Sat Sep 26 09:09:53 2009 +0000
     4.3 @@ -92,7 +92,7 @@
     4.4  } lib;
     4.5  
     4.6  #ifdef LOAD_PNG_DYNAMIC
     4.7 -static int IMG_InitPNG()
     4.8 +int IMG_InitPNG()
     4.9  {
    4.10  	if ( lib.loaded == 0 ) {
    4.11  		lib.handle = SDL_LoadObject(LOAD_PNG_DYNAMIC);
    4.12 @@ -216,7 +216,7 @@
    4.13  
    4.14  	return 0;
    4.15  }
    4.16 -static void IMG_QuitPNG()
    4.17 +void IMG_QuitPNG()
    4.18  {
    4.19  	if ( lib.loaded == 0 ) {
    4.20  		return;
    4.21 @@ -227,7 +227,7 @@
    4.22  	--lib.loaded;
    4.23  }
    4.24  #else
    4.25 -static int IMG_InitPNG()
    4.26 +int IMG_InitPNG()
    4.27  {
    4.28  	if ( lib.loaded == 0 ) {
    4.29  		lib.png_create_info_struct = png_create_info_struct;
    4.30 @@ -251,7 +251,7 @@
    4.31  
    4.32  	return 0;
    4.33  }
    4.34 -static void IMG_QuitPNG()
    4.35 +void IMG_QuitPNG()
    4.36  {
    4.37  	if ( lib.loaded == 0 ) {
    4.38  		return;
    4.39 @@ -507,6 +507,16 @@
    4.40  
    4.41  #else
    4.42  
    4.43 +int IMG_InitPNG()
    4.44 +{
    4.45 +	IMG_SetError("PNG images are not supported");
    4.46 +	return(-1);
    4.47 +}
    4.48 +
    4.49 +void IMG_QuitPNG()
    4.50 +{
    4.51 +}
    4.52 +
    4.53  /* See if an image is contained in a data source */
    4.54  int IMG_isPNG(SDL_RWops *src)
    4.55  {
     5.1 --- a/IMG_tif.c	Sat Sep 26 08:54:15 2009 +0000
     5.2 +++ b/IMG_tif.c	Sat Sep 26 09:09:53 2009 +0000
     5.3 @@ -41,7 +41,7 @@
     5.4  } lib;
     5.5  
     5.6  #ifdef LOAD_TIF_DYNAMIC
     5.7 -static int IMG_InitTIF()
     5.8 +int IMG_InitTIF()
     5.9  {
    5.10  	if ( lib.loaded == 0 ) {
    5.11  		lib.handle = SDL_LoadObject(LOAD_TIF_DYNAMIC);
    5.12 @@ -88,7 +88,7 @@
    5.13  
    5.14  	return 0;
    5.15  }
    5.16 -static void IMG_QuitTIF()
    5.17 +void IMG_QuitTIF()
    5.18  {
    5.19  	if ( lib.loaded == 0 ) {
    5.20  		return;
    5.21 @@ -99,7 +99,7 @@
    5.22  	--lib.loaded;
    5.23  }
    5.24  #else
    5.25 -static int IMG_InitTIF()
    5.26 +int IMG_InitTIF()
    5.27  {
    5.28  	if ( lib.loaded == 0 ) {
    5.29  		lib.TIFFClientOpen = TIFFClientOpen;
    5.30 @@ -112,7 +112,7 @@
    5.31  
    5.32  	return 0;
    5.33  }
    5.34 -static void IMG_QuitTIF()
    5.35 +void IMG_QuitTIF()
    5.36  {
    5.37  	if ( lib.loaded == 0 ) {
    5.38  		return;
    5.39 @@ -272,6 +272,16 @@
    5.40  
    5.41  #else
    5.42  
    5.43 +int IMG_InitTIF()
    5.44 +{
    5.45 +	IMG_SetError("TIFF images are not supported");
    5.46 +	return(-1);
    5.47 +}
    5.48 +
    5.49 +void IMG_QuitTIF()
    5.50 +{
    5.51 +}
    5.52 +
    5.53  /* See if an image is contained in a data source */
    5.54  int IMG_isTIF(SDL_RWops *src)
    5.55  {
     6.1 --- a/SDL_image.h	Sat Sep 26 08:54:15 2009 +0000
     6.2 +++ b/SDL_image.h	Sat Sep 26 09:09:53 2009 +0000
     6.3 @@ -56,6 +56,20 @@
     6.4   */
     6.5  extern DECLSPEC const SDL_version * SDLCALL IMG_Linked_Version(void);
     6.6  
     6.7 +typedef enum
     6.8 +{
     6.9 +    IMG_INIT_JPG = 0x00000001,
    6.10 +    IMG_INIT_PNG = 0x00000002,
    6.11 +    IMG_INIT_TIF = 0x00000004,
    6.12 +} IMG_InitFlags;
    6.13 +
    6.14 +/* Loads dynamic libraries and prepares them for use.  Flags should be
    6.15 +   one or more flags from IMG_InitFlags OR'd together */
    6.16 +extern DECLSPEC int SDLCALL IMG_Init(int flags);
    6.17 +
    6.18 +/* Unloads libraries loaded with IMG_Init */
    6.19 +extern DECLSPEC void SDLCALL IMG_Quit();
    6.20 +
    6.21  /* Load an image from an SDL data source.
    6.22     The 'type' may be one of: "BMP", "GIF", "PNG", etc.
    6.23