Skip to content

Commit

Permalink
Mason Wheeler - 2009-06-10 06:29:45 PDT
Browse files Browse the repository at this point in the history
 * Added IMG_Init()/IMG_Quit() to prevent constantly loading and unloading DLLs
  • Loading branch information
slouken committed Sep 26, 2009
1 parent ef19b69 commit 5b22cba
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGES
@@ -1,4 +1,6 @@
1.2.8:
Mason Wheeler - 2009-06-10 06:29:45 PDT
* Added IMG_Init()/IMG_Quit() to prevent constantly loading and unloading DLLs
Couriersud - Mon, 12 Jan 2009 17:21:13 -0800
* Added support for ICO and CUR image files
Eric Wing - Fri, 2 Jan 2009 02:01:16 -0800
Expand Down
47 changes: 47 additions & 0 deletions IMG.c
Expand Up @@ -60,6 +60,53 @@ const SDL_version *IMG_Linked_Version(void)
return(&linked_version);
}

extern int IMG_InitJPG();
extern int IMG_QuitJPG();
extern int IMG_InitPNG();
extern int IMG_QuitPNG();
extern int IMG_InitTIF();
extern int IMG_QuitTIF();

static int initialized = 0;

int IMG_Init(int flags)
{
int result = 0;

if ((flags & IMG_INIT_JPG) && !(initialized & IMG_INIT_JPG)) {
if (IMG_InitJPG() == 0) {
result |= IMG_INIT_JPG;
}
}
if ((flags & IMG_INIT_PNG) && !(initialized & IMG_INIT_PNG)) {
if (IMG_InitPNG() == 0) {
result |= IMG_INIT_PNG;
}
}
if ((flags & IMG_INIT_TIF) && !(initialized & IMG_INIT_TIF)) {
if (IMG_InitTIF() == 0) {
result |= IMG_INIT_TIF;
}
}
initialized |= result;

return (result);
}

void IMG_Quit()
{
if (initialized & IMG_INIT_JPG) {
IMG_QuitJPG();
}
if (initialized & IMG_INIT_PNG) {
IMG_QuitPNG();
}
if (initialized & IMG_INIT_TIF) {
IMG_QuitTIF();
}
initialized = 0;
}

#if !defined(__APPLE__) || defined(SDL_IMAGE_USE_COMMON_BACKEND)
/* Load an image from a file */
SDL_Surface *IMG_Load(const char *file)
Expand Down
18 changes: 14 additions & 4 deletions IMG_jpg.c
Expand Up @@ -53,7 +53,7 @@ static struct {
} lib;

#ifdef LOAD_JPG_DYNAMIC
static int IMG_InitJPG()
int IMG_InitJPG()
{
if ( lib.loaded == 0 ) {
lib.handle = SDL_LoadObject(LOAD_JPG_DYNAMIC);
Expand Down Expand Up @@ -128,7 +128,7 @@ static int IMG_InitJPG()

return 0;
}
static void IMG_QuitJPG()
void IMG_QuitJPG()
{
if ( lib.loaded == 0 ) {
return;
Expand All @@ -139,7 +139,7 @@ static void IMG_QuitJPG()
--lib.loaded;
}
#else
static int IMG_InitJPG()
int IMG_InitJPG()
{
if ( lib.loaded == 0 ) {
lib.jpeg_calc_output_dimensions = jpeg_calc_output_dimensions;
Expand All @@ -156,7 +156,7 @@ static int IMG_InitJPG()

return 0;
}
static void IMG_QuitJPG()
void IMG_QuitJPG()
{
if ( lib.loaded == 0 ) {
return;
Expand Down Expand Up @@ -465,6 +465,16 @@ SDL_Surface *IMG_LoadJPG_RW(SDL_RWops *src)

#else

int IMG_InitJPG()
{
IMG_SetError("JPEG images are not supported");
return(-1);
}

void IMG_QuitJPG()
{
}

/* See if an image is contained in a data source */
int IMG_isJPG(SDL_RWops *src)
{
Expand Down
18 changes: 14 additions & 4 deletions IMG_png.c
Expand Up @@ -92,7 +92,7 @@ static struct {
} lib;

#ifdef LOAD_PNG_DYNAMIC
static int IMG_InitPNG()
int IMG_InitPNG()
{
if ( lib.loaded == 0 ) {
lib.handle = SDL_LoadObject(LOAD_PNG_DYNAMIC);
Expand Down Expand Up @@ -216,7 +216,7 @@ static int IMG_InitPNG()

return 0;
}
static void IMG_QuitPNG()
void IMG_QuitPNG()
{
if ( lib.loaded == 0 ) {
return;
Expand All @@ -227,7 +227,7 @@ static void IMG_QuitPNG()
--lib.loaded;
}
#else
static int IMG_InitPNG()
int IMG_InitPNG()
{
if ( lib.loaded == 0 ) {
lib.png_create_info_struct = png_create_info_struct;
Expand All @@ -251,7 +251,7 @@ static int IMG_InitPNG()

return 0;
}
static void IMG_QuitPNG()
void IMG_QuitPNG()
{
if ( lib.loaded == 0 ) {
return;
Expand Down Expand Up @@ -507,6 +507,16 @@ SDL_Surface *IMG_LoadPNG_RW(SDL_RWops *src)

#else

int IMG_InitPNG()
{
IMG_SetError("PNG images are not supported");
return(-1);
}

void IMG_QuitPNG()
{
}

/* See if an image is contained in a data source */
int IMG_isPNG(SDL_RWops *src)
{
Expand Down
18 changes: 14 additions & 4 deletions IMG_tif.c
Expand Up @@ -41,7 +41,7 @@ static struct {
} lib;

#ifdef LOAD_TIF_DYNAMIC
static int IMG_InitTIF()
int IMG_InitTIF()
{
if ( lib.loaded == 0 ) {
lib.handle = SDL_LoadObject(LOAD_TIF_DYNAMIC);
Expand Down Expand Up @@ -88,7 +88,7 @@ static int IMG_InitTIF()

return 0;
}
static void IMG_QuitTIF()
void IMG_QuitTIF()
{
if ( lib.loaded == 0 ) {
return;
Expand All @@ -99,7 +99,7 @@ static void IMG_QuitTIF()
--lib.loaded;
}
#else
static int IMG_InitTIF()
int IMG_InitTIF()
{
if ( lib.loaded == 0 ) {
lib.TIFFClientOpen = TIFFClientOpen;
Expand All @@ -112,7 +112,7 @@ static int IMG_InitTIF()

return 0;
}
static void IMG_QuitTIF()
void IMG_QuitTIF()
{
if ( lib.loaded == 0 ) {
return;
Expand Down Expand Up @@ -272,6 +272,16 @@ SDL_Surface* IMG_LoadTIF_RW(SDL_RWops* src)

#else

int IMG_InitTIF()
{
IMG_SetError("TIFF images are not supported");
return(-1);
}

void IMG_QuitTIF()
{
}

/* See if an image is contained in a data source */
int IMG_isTIF(SDL_RWops *src)
{
Expand Down
14 changes: 14 additions & 0 deletions SDL_image.h
Expand Up @@ -56,6 +56,20 @@ extern "C" {
*/
extern DECLSPEC const SDL_version * SDLCALL IMG_Linked_Version(void);

typedef enum
{
IMG_INIT_JPG = 0x00000001,
IMG_INIT_PNG = 0x00000002,
IMG_INIT_TIF = 0x00000004,
} IMG_InitFlags;

/* Loads dynamic libraries and prepares them for use. Flags should be
one or more flags from IMG_InitFlags OR'd together */
extern DECLSPEC int SDLCALL IMG_Init(int flags);

/* Unloads libraries loaded with IMG_Init */
extern DECLSPEC void SDLCALL IMG_Quit();

/* Load an image from an SDL data source.
The 'type' may be one of: "BMP", "GIF", "PNG", etc.
Expand Down

0 comments on commit 5b22cba

Please sign in to comment.