From 6f1351cfd8c9b1150b7c65452c4fba8194cdebd3 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 2 Dec 2024 16:06:11 -0800 Subject: [PATCH] Removed IMG_Init() and IMG_Quit() IMG_Init() and IMG_Quit() are no longer necessary. If an image format requires dynamically loading a support library, that will be done automatically. --- docs/README-migration.md | 6 ++ include/SDL3_image/SDL_image.h | 101 --------------------------------- src/IMG.c | 65 --------------------- src/IMG.h | 38 ------------- src/IMG_ImageIO.m | 36 ------------ src/IMG_WIC.c | 41 ++----------- src/IMG_avif.c | 29 ++++------ src/IMG_bmp.c | 1 - src/IMG_gif.c | 1 - src/IMG_jpg.c | 36 +++--------- src/IMG_jxl.c | 25 +++----- src/IMG_lbm.c | 1 - src/IMG_pcx.c | 1 - src/IMG_png.c | 36 +++--------- src/IMG_pnm.c | 1 - src/IMG_qoi.c | 1 - src/IMG_stb.c | 1 - src/IMG_svg.c | 1 - src/IMG_tga.c | 1 - src/IMG_tif.c | 23 +++----- src/IMG_webp.c | 33 ++++------- src/IMG_xcf.c | 1 - src/IMG_xpm.c | 1 - src/IMG_xv.c | 1 - src/IMG_xxx.c | 1 - src/SDL_image.sym | 2 - test/main.c | 56 ------------------ 27 files changed, 65 insertions(+), 475 deletions(-) create mode 100644 docs/README-migration.md delete mode 100644 src/IMG.h diff --git a/docs/README-migration.md b/docs/README-migration.md new file mode 100644 index 000000000..56b690c1b --- /dev/null +++ b/docs/README-migration.md @@ -0,0 +1,6 @@ + +# Migrating to SDL_image 3.0 + +This guide provides useful information for migrating applications from SDL_image 2.0 to SDL_image 3.0. + +IMG_Init() and IMG_Quit() are no longer necessary. If an image format requires dynamically loading a support library, that will be done automatically. diff --git a/include/SDL3_image/SDL_image.h b/include/SDL3_image/SDL_image.h index e5ff0835c..ae1fd3470 100644 --- a/include/SDL3_image/SDL_image.h +++ b/include/SDL3_image/SDL_image.h @@ -67,107 +67,6 @@ extern "C" { */ extern SDL_DECLSPEC int SDLCALL IMG_Version(void); -/** - * Initialization flags - */ -typedef Uint32 IMG_InitFlags; - -#define IMG_INIT_JPG 0x00000001 -#define IMG_INIT_PNG 0x00000002 -#define IMG_INIT_TIF 0x00000004 -#define IMG_INIT_WEBP 0x00000008 -#define IMG_INIT_JXL 0x00000010 -#define IMG_INIT_AVIF 0x00000020 - -/** - * Initialize SDL_image. - * - * This function loads dynamic libraries that SDL_image needs, and prepares - * them for use. This must be the first function you call in SDL_image, and if - * it fails you should not continue with the library. - * - * Flags should be one or more flags from IMG_InitFlags OR'd together. It - * returns the flags successfully initialized, or 0 on failure. - * - * Currently, these flags are: - * - * - `IMG_INIT_JPG` - * - `IMG_INIT_PNG` - * - `IMG_INIT_TIF` - * - `IMG_INIT_WEBP` - * - `IMG_INIT_JXL` - * - `IMG_INIT_AVIF` - * - * More flags may be added in a future SDL_image release. - * - * This function may need to load external shared libraries to support various - * codecs, which means this function can fail to initialize that support on an - * otherwise-reasonable system if the library isn't available; this is not - * just a question of exceptional circumstances like running out of memory at - * startup! - * - * Note that you may call this function more than once to initialize with - * additional flags. The return value will reflect both new flags that - * successfully initialized, and also include flags that had previously been - * initialized as well. - * - * As this will return previously-initialized flags, it's legal to call this - * with zero (no flags set). This is a safe no-op that can be used to query - * the current initialization state without changing it at all. - * - * Since this returns previously-initialized flags as well as new ones, and - * you can call this with zero, you should not check for a zero return value - * to determine an error condition. Instead, you should check to make sure all - * the flags you require are set in the return value. If you have a game with - * data in a specific format, this might be a fatal error. If you're a generic - * image displaying app, perhaps you are fine with only having JPG and PNG - * support and can live without WEBP, even if you request support for - * everything. - * - * Unlike other SDL satellite libraries, calls to IMG_Init do not stack; a - * single call to IMG_Quit() will deinitialize everything and does not have to - * be paired with a matching IMG_Init call. For that reason, it's considered - * best practices to have a single IMG_Init and IMG_Quit call in your program. - * While this isn't required, be aware of the risks of deviating from that - * behavior. - * - * After initializing SDL_image, the app may begin to load images into - * SDL_Surfaces or SDL_Textures. - * - * \param flags initialization flags, OR'd together. - * \returns all currently initialized flags. - * - * \since This function is available since SDL_image 3.0.0. - * - * \sa IMG_Quit - */ -extern SDL_DECLSPEC IMG_InitFlags SDLCALL IMG_Init(IMG_InitFlags flags); - -/** - * Deinitialize SDL_image. - * - * This should be the last function you call in SDL_image, after freeing all - * other resources. This will unload any shared libraries it is using for - * various codecs. - * - * After this call, a call to IMG_Init(0) will return 0 (no codecs loaded). - * - * You can safely call IMG_Init() to reload various codec support after this - * call. - * - * Unlike other SDL satellite libraries, calls to IMG_Init do not stack; a - * single call to IMG_Quit() will deinitialize everything and does not have to - * be paired with a matching IMG_Init call. For that reason, it's considered - * best practices to have a single IMG_Init and IMG_Quit call in your program. - * While this isn't required, be aware of the risks of deviating from that - * behavior. - * - * \since This function is available since SDL_image 3.0.0. - * - * \sa IMG_Init - */ -extern SDL_DECLSPEC void SDLCALL IMG_Quit(void); - /** * Load an image from an SDL data source into a software surface. * diff --git a/src/IMG.c b/src/IMG.c index b32adc33b..1b4de2a57 100644 --- a/src/IMG.c +++ b/src/IMG.c @@ -22,7 +22,6 @@ /* A simple library to load images of various formats as SDL surfaces */ #include -#include "IMG.h" #ifdef __EMSCRIPTEN__ #include @@ -89,70 +88,6 @@ int IMG_Version(void) return SDL_IMAGE_VERSION; } -static IMG_InitFlags initialized = 0; - -IMG_InitFlags IMG_Init(IMG_InitFlags flags) -{ - IMG_InitFlags result = 0; - - if (flags & IMG_INIT_AVIF) { - if ((initialized & IMG_INIT_AVIF) || IMG_InitAVIF() == 0) { - result |= IMG_INIT_AVIF; - } - } - if (flags & IMG_INIT_JPG) { - if ((initialized & IMG_INIT_JPG) || IMG_InitJPG() == 0) { - result |= IMG_INIT_JPG; - } - } - if (flags & IMG_INIT_JXL) { - if ((initialized & IMG_INIT_JXL) || IMG_InitJXL() == 0) { - result |= IMG_INIT_JXL; - } - } - if (flags & IMG_INIT_PNG) { - if ((initialized & IMG_INIT_PNG) || IMG_InitPNG() == 0) { - result |= IMG_INIT_PNG; - } - } - if (flags & IMG_INIT_TIF) { - if ((initialized & IMG_INIT_TIF) || IMG_InitTIF() == 0) { - result |= IMG_INIT_TIF; - } - } - if (flags & IMG_INIT_WEBP) { - if ((initialized & IMG_INIT_WEBP) || IMG_InitWEBP() == 0) { - result |= IMG_INIT_WEBP; - } - } - initialized |= result; - - return initialized; -} - -void IMG_Quit(void) -{ - if (initialized & IMG_INIT_AVIF) { - IMG_QuitAVIF(); - } - if (initialized & IMG_INIT_JPG) { - IMG_QuitJPG(); - } - if (initialized & IMG_INIT_JXL) { - IMG_QuitJXL(); - } - if (initialized & IMG_INIT_PNG) { - IMG_QuitPNG(); - } - if (initialized & IMG_INIT_TIF) { - IMG_QuitTIF(); - } - if (initialized & IMG_INIT_WEBP) { - IMG_QuitWEBP(); - } - initialized = 0; -} - #if !defined(__APPLE__) || defined(SDL_IMAGE_USE_COMMON_BACKEND) /* Load an image from a file */ SDL_Surface *IMG_Load(const char *file) diff --git a/src/IMG.h b/src/IMG.h deleted file mode 100644 index 02208d5cc..000000000 --- a/src/IMG.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - SDL_image: An example image loading library for use with SDL - Copyright (C) 1997-2024 Sam Lantinga - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -#ifndef SDLIMAGE_IMG_H -#define SDLIMAGE_IMG_H - -extern int IMG_InitAVIF(void); -extern void IMG_QuitAVIF(void); -extern int IMG_InitJPG(void); -extern void IMG_QuitJPG(void); -extern int IMG_InitJXL(void); -extern void IMG_QuitJXL(void); -extern int IMG_InitPNG(void); -extern void IMG_QuitPNG(void); -extern int IMG_InitTIF(void); -extern void IMG_QuitTIF(void); -extern int IMG_InitWEBP(void); -extern void IMG_QuitWEBP(void); - -#endif diff --git a/src/IMG_ImageIO.m b/src/IMG_ImageIO.m index 2d6eef012..317de5e92 100644 --- a/src/IMG_ImageIO.m +++ b/src/IMG_ImageIO.m @@ -10,7 +10,6 @@ #if defined(__APPLE__) && !defined(SDL_IMAGE_USE_COMMON_BACKEND) #include -#include "IMG.h" // Used because CGDataProviderCreate became deprecated in 10.5 #include @@ -356,41 +355,6 @@ static CFDictionaryRef CreateHintDictionary(CFStringRef uti_string_hint) } -#ifdef JPG_USES_IMAGEIO - -int IMG_InitJPG(void) -{ - return 0; -} - -void IMG_QuitJPG(void) -{ -} - -#endif /* JPG_USES_IMAGEIO */ - -#ifdef PNG_USES_IMAGEIO - -int IMG_InitPNG(void) -{ - return 0; -} - -void IMG_QuitPNG(void) -{ -} - -#endif /* PNG_USES_IMAGEIO */ - -int IMG_InitTIF(void) -{ - return 0; -} - -void IMG_QuitTIF(void) -{ -} - static bool Internal_isType (SDL_IOStream *rw_ops, CFStringRef uti_string_to_test) { bool is_type = false; diff --git a/src/IMG_WIC.c b/src/IMG_WIC.c index a4762144c..36649efe5 100644 --- a/src/IMG_WIC.c +++ b/src/IMG_WIC.c @@ -22,14 +22,13 @@ #if defined(SDL_IMAGE_USE_WIC_BACKEND) #include -#include "IMG.h" #define COBJMACROS #include #include static IWICImagingFactory* wicFactory = NULL; -static int WIC_Init(void) +static bool WIC_Init(void) { if (wicFactory == NULL) { HRESULT hr = CoCreateInstance( @@ -40,49 +39,21 @@ static int WIC_Init(void) (void**)&wicFactory ); if (FAILED(hr)) { - return -1; + return false; } } - return 0; + return true; } +#if 0 static void WIC_Quit(void) { if (wicFactory) { IWICImagingFactory_Release(wicFactory); } } - -int IMG_InitPNG(void) -{ - return WIC_Init(); -} - -void IMG_QuitPNG(void) -{ - WIC_Quit(); -} - -int IMG_InitJPG(void) -{ - return WIC_Init(); -} - -void IMG_QuitJPG(void) -{ - WIC_Quit(); -} - -int IMG_InitTIF(void) -{ - return WIC_Init(); -} - -void IMG_QuitTIF(void) -{ - WIC_Quit(); -} +#endif // 0 bool IMG_isPNG(SDL_IOStream *src) { @@ -214,7 +185,7 @@ static SDL_Surface* WIC_LoadImage(SDL_IOStream *src) IWICFormatConverter* formatConverter = NULL; UINT width, height; - if (wicFactory == NULL && (WIC_Init() < 0)) { + if (!WIC_Init()) { SDL_SetError("WIC failed to initialize!"); return NULL; } diff --git a/src/IMG_avif.c b/src/IMG_avif.c index 96e1ca5be..1e74c663f 100644 --- a/src/IMG_avif.c +++ b/src/IMG_avif.c @@ -22,7 +22,6 @@ /* This is a AVIF image file loading framework */ #include -#include "IMG.h" /* We'll have AVIF save support by default */ #if !defined(SDL_IMAGE_SAVE_AVIF) @@ -77,24 +76,24 @@ static struct { #ifdef LOAD_AVIF_DYNAMIC #define FUNCTION_LOADER(FUNC, SIG) \ lib.FUNC = (SIG) SDL_LoadFunction(lib.handle, #FUNC); \ - if (lib.FUNC == NULL) { SDL_UnloadObject(lib.handle); return -1; } + if (lib.FUNC == NULL) { SDL_UnloadObject(lib.handle); return false; } #else #define FUNCTION_LOADER(FUNC, SIG) \ lib.FUNC = FUNC; \ - if (lib.FUNC == NULL) { SDL_SetError("Missing avif.framework"); return -1; } + if (lib.FUNC == NULL) { return SDL_SetError("Missing avif.framework"); } #endif #ifdef __APPLE__ /* Need to turn off optimizations so weak framework load check works */ __attribute__ ((optnone)) #endif -int IMG_InitAVIF(void) +static bool IMG_InitAVIF(void) { if ( lib.loaded == 0 ) { #ifdef LOAD_AVIF_DYNAMIC lib.handle = SDL_LoadObject(LOAD_AVIF_DYNAMIC); if ( lib.handle == NULL ) { - return -1; + return false; } #endif FUNCTION_LOADER(avifDecoderCreate, avifDecoder * (*)(void)) @@ -117,8 +116,9 @@ int IMG_InitAVIF(void) } ++lib.loaded; - return 0; + return false; } +#if 0 void IMG_QuitAVIF(void) { if ( lib.loaded == 0 ) { @@ -131,6 +131,7 @@ void IMG_QuitAVIF(void) } --lib.loaded; } +#endif // 0 static bool ReadAVIFHeader(SDL_IOStream *src, Uint8 **header_data, size_t *header_size) { @@ -211,7 +212,7 @@ bool IMG_isAVIF(SDL_IOStream *src) is_AVIF = false; if (ReadAVIFHeader(src, &data, &size)) { /* This might be AVIF, do more thorough checks */ - if ((IMG_Init(IMG_INIT_AVIF) & IMG_INIT_AVIF) != 0) { + if (IMG_InitAVIF()) { avifROData header; header.data = data; @@ -365,7 +366,7 @@ SDL_Surface *IMG_LoadAVIF_IO(SDL_IOStream *src) } start = SDL_TellIO(src); - if ((IMG_Init(IMG_INIT_AVIF) & IMG_INIT_AVIF) == 0) { + if ((IMG_InitAVIF()) { return NULL; } @@ -532,7 +533,7 @@ static bool IMG_SaveAVIF_IO_libavif(SDL_Surface *surface, SDL_IOStream *dst, int SDL_PropertiesID props; bool result = false; - if (!IMG_Init(IMG_INIT_AVIF)) { + if (!IMG_InitAVIF()) { return false; } @@ -710,16 +711,6 @@ static bool IMG_SaveAVIF_IO_libavif(SDL_Surface *surface, SDL_IOStream *dst, int #pragma warning(disable : 4100) /* warning C4100: 'op' : unreferenced formal parameter */ #endif -int IMG_InitAVIF(void) -{ - SDL_SetError("AVIF images are not supported"); - return -1; -} - -void IMG_QuitAVIF(void) -{ -} - /* See if an image is contained in a data source */ bool IMG_isAVIF(SDL_IOStream *src) { diff --git a/src/IMG_bmp.c b/src/IMG_bmp.c index 4386896a1..18ef6adb8 100644 --- a/src/IMG_bmp.c +++ b/src/IMG_bmp.c @@ -31,7 +31,6 @@ */ #include -#include "IMG.h" #ifdef LOAD_BMP diff --git a/src/IMG_gif.c b/src/IMG_gif.c index 4825eec97..06858f6f6 100644 --- a/src/IMG_gif.c +++ b/src/IMG_gif.c @@ -22,7 +22,6 @@ /* This is a GIF image file loading framework */ #include -#include "IMG.h" #ifdef LOAD_GIF diff --git a/src/IMG_jpg.c b/src/IMG_jpg.c index d7a3e05fa..b6f408fdc 100644 --- a/src/IMG_jpg.c +++ b/src/IMG_jpg.c @@ -22,7 +22,6 @@ /* This is a JPEG image file loading framework */ #include -#include "IMG.h" #include #include @@ -89,19 +88,19 @@ static struct { #ifdef LOAD_JPG_DYNAMIC #define FUNCTION_LOADER(FUNC, SIG) \ lib.FUNC = (SIG) SDL_LoadFunction(lib.handle, #FUNC); \ - if (lib.FUNC == NULL) { SDL_UnloadObject(lib.handle); return -1; } + if (lib.FUNC == NULL) { SDL_UnloadObject(lib.handle); return false; } #else #define FUNCTION_LOADER(FUNC, SIG) \ lib.FUNC = FUNC; #endif -int IMG_InitJPG(void) +static bool IMG_InitJPG(void) { if ( lib.loaded == 0 ) { #ifdef LOAD_JPG_DYNAMIC lib.handle = SDL_LoadObject(LOAD_JPG_DYNAMIC); if ( lib.handle == NULL ) { - return -1; + return false; } #endif FUNCTION_LOADER(jpeg_calc_output_dimensions, void (*) (j_decompress_ptr cinfo)) @@ -123,8 +122,9 @@ int IMG_InitJPG(void) } ++lib.loaded; - return 0; + return true; } +#if 0 void IMG_QuitJPG(void) { if ( lib.loaded == 0 ) { @@ -137,6 +137,7 @@ void IMG_QuitJPG(void) } --lib.loaded; } +#endif // 0 /* See if an image is contained in a data source */ bool IMG_isJPG(SDL_IOStream *src) @@ -357,7 +358,7 @@ SDL_Surface *IMG_LoadJPG_IO(SDL_IOStream *src) } start = SDL_TellIO(src); - if ( (IMG_Init(IMG_INIT_JPG) & IMG_INIT_JPG) == 0 ) { + if (!IMG_InitJPG()) { return NULL; } @@ -538,7 +539,7 @@ static bool IMG_SaveJPG_IO_jpeglib(SDL_Surface *surface, SDL_IOStream *dst, int SDL_Surface* jpeg_surface = surface; bool result; - if (!IMG_Init(IMG_INIT_JPG)) { + if (!IMG_InitJPG()) { return false; } @@ -563,17 +564,6 @@ static bool IMG_SaveJPG_IO_jpeglib(SDL_Surface *surface, SDL_IOStream *dst, int extern SDL_Surface *IMG_LoadSTB_IO(SDL_IOStream *src); -int IMG_InitJPG(void) -{ - /* Nothing to load */ - return 0; -} - -void IMG_QuitJPG(void) -{ - /* Nothing to unload */ -} - /* FIXME: This is a copypaste from JPEGLIB! Pull that out of the ifdefs */ /* Define this for quicker (but less perfect) JPEG identification */ #define FAST_IS_JPEG @@ -659,16 +649,6 @@ SDL_Surface *IMG_LoadJPG_IO(SDL_IOStream *src) #pragma warning(disable : 4100) /* warning C4100: 'op' : unreferenced formal parameter */ #endif -int IMG_InitJPG(void) -{ - SDL_SetError("JPEG images are not supported"); - return -1; -} - -void IMG_QuitJPG(void) -{ -} - /* See if an image is contained in a data source */ bool IMG_isJPG(SDL_IOStream *src) { diff --git a/src/IMG_jxl.c b/src/IMG_jxl.c index 0c5c91c11..e193019eb 100644 --- a/src/IMG_jxl.c +++ b/src/IMG_jxl.c @@ -22,7 +22,6 @@ /* This is a JXL image file loading framework */ #include -#include "IMG.h" #ifdef LOAD_JXL @@ -45,24 +44,24 @@ static struct { #ifdef LOAD_JXL_DYNAMIC #define FUNCTION_LOADER(FUNC, SIG) \ lib.FUNC = (SIG) SDL_LoadFunction(lib.handle, #FUNC); \ - if (lib.FUNC == NULL) { SDL_UnloadObject(lib.handle); return -1; } + if (lib.FUNC == NULL) { SDL_UnloadObject(lib.handle); return false; } #else #define FUNCTION_LOADER(FUNC, SIG) \ lib.FUNC = FUNC; \ - if (lib.FUNC == NULL) { SDL_SetError("Missing jxl.framework"); return -1; } + if (lib.FUNC == NULL) { return SDL_SetError("Missing jxl.framework"); } #endif #ifdef __APPLE__ /* Need to turn off optimizations so weak framework load check works */ __attribute__ ((optnone)) #endif -int IMG_InitJXL(void) +static bool IMG_InitJXL(void) { if ( lib.loaded == 0 ) { #ifdef LOAD_JXL_DYNAMIC lib.handle = SDL_LoadObject(LOAD_JXL_DYNAMIC); if ( lib.handle == NULL ) { - return -1; + return false; } #endif FUNCTION_LOADER(JxlDecoderCreate, JxlDecoder* (*)(const JxlMemoryManager* memory_manager)) @@ -76,8 +75,9 @@ int IMG_InitJXL(void) } ++lib.loaded; - return 0; + return true; } +#if 0 void IMG_QuitJXL(void) { if ( lib.loaded == 0 ) { @@ -90,6 +90,7 @@ void IMG_QuitJXL(void) } --lib.loaded; } +#endif // 0 /* See if an image is contained in a data source */ bool IMG_isJXL(SDL_IOStream *src) @@ -146,7 +147,7 @@ SDL_Surface *IMG_LoadJXL_IO(SDL_IOStream *src) } start = SDL_TellIO(src); - if ((IMG_Init(IMG_INIT_JXL) & IMG_INIT_JXL) == 0) { + if (!IMG_InitJXL()) { return NULL; } @@ -254,16 +255,6 @@ SDL_Surface *IMG_LoadJXL_IO(SDL_IOStream *src) #pragma warning(disable : 4100) /* warning C4100: 'op' : unreferenced formal parameter */ #endif -int IMG_InitJXL(void) -{ - SDL_SetError("JXL images are not supported"); - return -1; -} - -void IMG_QuitJXL(void) -{ -} - /* See if an image is contained in a data source */ bool IMG_isJXL(SDL_IOStream *src) { diff --git a/src/IMG_lbm.c b/src/IMG_lbm.c index 5031fa0e7..e1765fd22 100644 --- a/src/IMG_lbm.c +++ b/src/IMG_lbm.c @@ -32,7 +32,6 @@ #include #include -#include "IMG.h" #ifdef LOAD_LBM diff --git a/src/IMG_pcx.c b/src/IMG_pcx.c index 8cfe8db02..2be548b96 100644 --- a/src/IMG_pcx.c +++ b/src/IMG_pcx.c @@ -36,7 +36,6 @@ #include #include -#include "IMG.h" #ifdef LOAD_PCX diff --git a/src/IMG_png.c b/src/IMG_png.c index dbebcfa37..6e26ba9f5 100644 --- a/src/IMG_png.c +++ b/src/IMG_png.c @@ -22,7 +22,6 @@ /* This is a PNG image file loading framework */ #include -#include "IMG.h" /* We'll have PNG save support by default */ #if !defined(SDL_IMAGE_SAVE_PNG) @@ -132,19 +131,19 @@ static struct { #ifdef LOAD_PNG_DYNAMIC #define FUNCTION_LOADER(FUNC, SIG) \ lib.FUNC = (SIG) SDL_LoadFunction(lib.handle, #FUNC); \ - if (lib.FUNC == NULL) { SDL_UnloadObject(lib.handle); return -1; } + if (lib.FUNC == NULL) { SDL_UnloadObject(lib.handle); return false; } #else #define FUNCTION_LOADER(FUNC, SIG) \ lib.FUNC = FUNC; #endif -int IMG_InitPNG(void) +static bool IMG_InitPNG(void) { if ( lib.loaded == 0 ) { #ifdef LOAD_PNG_DYNAMIC lib.handle = SDL_LoadObject(LOAD_PNG_DYNAMIC); if ( lib.handle == NULL ) { - return -1; + return false; } #endif FUNCTION_LOADER(png_create_info_struct, png_infop (*) (png_noconst15_structrp png_ptr)) @@ -185,8 +184,9 @@ int IMG_InitPNG(void) } ++lib.loaded; - return 0; + return true; } +#if 0 void IMG_QuitPNG(void) { if ( lib.loaded == 0 ) { @@ -199,6 +199,7 @@ void IMG_QuitPNG(void) } --lib.loaded; } +#endif // 0 /* See if an image is contained in a data source */ bool IMG_isPNG(SDL_IOStream *src) @@ -470,7 +471,7 @@ SDL_Surface *IMG_LoadPNG_IO(SDL_IOStream *src) return NULL; } - if ( (IMG_Init(IMG_INIT_PNG) & IMG_INIT_PNG) == 0 ) { + if (!IMG_InitPNG()) { return NULL; } @@ -503,17 +504,6 @@ SDL_Surface *IMG_LoadPNG_IO(SDL_IOStream *src) extern SDL_Surface *IMG_LoadSTB_IO(SDL_IOStream *src); -int IMG_InitPNG(void) -{ - /* Nothing to load */ - return 0; -} - -void IMG_QuitPNG(void) -{ - /* Nothing to unload */ -} - /* FIXME: This is a copypaste from LIBPNG! Pull that out of the ifdefs */ /* See if an image is contained in a data source */ bool IMG_isPNG(SDL_IOStream *src) @@ -553,16 +543,6 @@ SDL_Surface *IMG_LoadPNG_IO(SDL_IOStream *src) #pragma warning(disable : 4100) /* warning C4100: 'op' : unreferenced formal parameter */ #endif -int IMG_InitPNG(void) -{ - SDL_SetError("PNG images are not supported"); - return -1; -} - -void IMG_QuitPNG(void) -{ -} - /* See if an image is contained in a data source */ bool IMG_isPNG(SDL_IOStream *src) { @@ -711,7 +691,7 @@ static bool IMG_SavePNG_IO_libpng(SDL_Surface *surface, SDL_IOStream *dst) struct savepng_vars vars; bool result; - if (!IMG_Init(IMG_INIT_PNG)) { + if (!IMG_InitPNG()) { return false; } diff --git a/src/IMG_pnm.c b/src/IMG_pnm.c index 21b0fbf92..6ed6104ac 100644 --- a/src/IMG_pnm.c +++ b/src/IMG_pnm.c @@ -28,7 +28,6 @@ */ #include -#include "IMG.h" #ifdef LOAD_PNM diff --git a/src/IMG_qoi.c b/src/IMG_qoi.c index 3c0ba3141..e6a6c95f0 100644 --- a/src/IMG_qoi.c +++ b/src/IMG_qoi.c @@ -24,7 +24,6 @@ */ #include -#include "IMG.h" #include /* for INT_MAX */ #ifdef LOAD_QOI diff --git a/src/IMG_stb.c b/src/IMG_stb.c index ff8cab4c0..77622fd80 100644 --- a/src/IMG_stb.c +++ b/src/IMG_stb.c @@ -20,7 +20,6 @@ */ #include -#include "IMG.h" #ifdef USE_STBIMAGE diff --git a/src/IMG_svg.c b/src/IMG_svg.c index a042f2cba..7582ddc89 100644 --- a/src/IMG_svg.c +++ b/src/IMG_svg.c @@ -24,7 +24,6 @@ */ #include -#include "IMG.h" #ifdef LOAD_SVG diff --git a/src/IMG_tga.c b/src/IMG_tga.c index 270c7945c..65501724e 100644 --- a/src/IMG_tga.c +++ b/src/IMG_tga.c @@ -26,7 +26,6 @@ #include #include -#include "IMG.h" #ifdef LOAD_TGA diff --git a/src/IMG_tif.c b/src/IMG_tif.c index a405c7cc6..cfe786f61 100644 --- a/src/IMG_tif.c +++ b/src/IMG_tif.c @@ -24,7 +24,6 @@ /* This is a TIFF image file loading framework */ #include -#include "IMG.h" #ifdef LOAD_TIF @@ -43,19 +42,19 @@ static struct { #ifdef LOAD_TIF_DYNAMIC #define FUNCTION_LOADER(FUNC, SIG) \ lib.FUNC = (SIG) SDL_LoadFunction(lib.handle, #FUNC); \ - if (lib.FUNC == NULL) { SDL_UnloadObject(lib.handle); return -1; } + if (lib.FUNC == NULL) { SDL_UnloadObject(lib.handle); return false; } #else #define FUNCTION_LOADER(FUNC, SIG) \ lib.FUNC = FUNC; #endif -int IMG_InitTIF(void) +static bool IMG_InitTIF(void) { if ( lib.loaded == 0 ) { #ifdef LOAD_TIF_DYNAMIC lib.handle = SDL_LoadObject(LOAD_TIF_DYNAMIC); if ( lib.handle == NULL ) { - return -1; + return false; } #endif FUNCTION_LOADER(TIFFClientOpen, TIFF * (*)(const char*, const char*, thandle_t, TIFFReadWriteProc, TIFFReadWriteProc, TIFFSeekProc, TIFFCloseProc, TIFFSizeProc, TIFFMapFileProc, TIFFUnmapFileProc)) @@ -66,8 +65,9 @@ int IMG_InitTIF(void) } ++lib.loaded; - return 0; + return true; } +#if 0 void IMG_QuitTIF(void) { if ( lib.loaded == 0 ) { @@ -80,6 +80,7 @@ void IMG_QuitTIF(void) } --lib.loaded; } +#endif // 0 /* * These are the thunking routine to use the SDL_IOStream* routines from @@ -180,7 +181,7 @@ SDL_Surface* IMG_LoadTIF_IO(SDL_IOStream * src) } start = SDL_TellIO(src); - if ( (IMG_Init(IMG_INIT_TIF) & IMG_INIT_TIF) == 0 ) { + if (!IMG_InitTIF()) { return NULL; } @@ -221,16 +222,6 @@ SDL_Surface* IMG_LoadTIF_IO(SDL_IOStream * src) #pragma warning(disable : 4100) /* warning C4100: 'op' : unreferenced formal parameter */ #endif -int IMG_InitTIF(void) -{ - SDL_SetError("TIFF images are not supported"); - return -1; -} - -void IMG_QuitTIF(void) -{ -} - /* See if an image is contained in a data source */ bool IMG_isTIF(SDL_IOStream *src) { diff --git a/src/IMG_webp.c b/src/IMG_webp.c index 0b2bbfea3..2541d8683 100644 --- a/src/IMG_webp.c +++ b/src/IMG_webp.c @@ -22,7 +22,6 @@ /* This is a WEBP image file loading framework */ #include -#include "IMG.h" #ifdef LOAD_WEBP @@ -59,34 +58,34 @@ static struct { #if defined(LOAD_WEBP_DYNAMIC) && defined(LOAD_WEBPDEMUX_DYNAMIC) #define FUNCTION_LOADER_LIBWEBP(FUNC, SIG) \ lib.FUNC = (SIG) SDL_LoadFunction(lib.handle_libwebp, #FUNC); \ - if (lib.FUNC == NULL) { SDL_UnloadObject(lib.handle_libwebp); return -1; } + if (lib.FUNC == NULL) { SDL_UnloadObject(lib.handle_libwebp); return false; } #define FUNCTION_LOADER_LIBWEBPDEMUX(FUNC, SIG) \ lib.FUNC = (SIG) SDL_LoadFunction(lib.handle_libwebpdemux, #FUNC); \ - if (lib.FUNC == NULL) { SDL_UnloadObject(lib.handle_libwebpdemux); return -1; } + if (lib.FUNC == NULL) { SDL_UnloadObject(lib.handle_libwebpdemux); return false; } #else #define FUNCTION_LOADER_LIBWEBP(FUNC, SIG) \ lib.FUNC = FUNC; \ - if (lib.FUNC == NULL) { SDL_SetError("Missing webp.framework"); return -1; } + if (lib.FUNC == NULL) { return SDL_SetError("Missing webp.framework"); } #define FUNCTION_LOADER_LIBWEBPDEMUX(FUNC, SIG) \ lib.FUNC = FUNC; \ - if (lib.FUNC == NULL) { SDL_SetError("Missing webpdemux.framework"); return -1; } + if (lib.FUNC == NULL) { return SDL_SetError("Missing webpdemux.framework"); } #endif #ifdef __APPLE__ /* Need to turn off optimizations so weak framework load check works */ __attribute__ ((optnone)) #endif -int IMG_InitWEBP(void) +static bool IMG_InitWEBP(void) { if (lib.loaded == 0) { #if defined(LOAD_WEBP_DYNAMIC) && defined(LOAD_WEBPDEMUX_DYNAMIC) lib.handle_libwebpdemux = SDL_LoadObject(LOAD_WEBPDEMUX_DYNAMIC); if (lib.handle_libwebpdemux == NULL) { - return -1; + return false; } lib.handle_libwebp = SDL_LoadObject(LOAD_WEBP_DYNAMIC); if (lib.handle_libwebp == NULL) { - return -1; + return false; } #endif FUNCTION_LOADER_LIBWEBP(WebPGetFeaturesInternal, VP8StatusCode (*) (const uint8_t *data, size_t data_size, WebPBitstreamFeatures* features, int decoder_abi_version)) @@ -99,8 +98,9 @@ int IMG_InitWEBP(void) } ++lib.loaded; - return 0; + return false; } +#if 0 void IMG_QuitWEBP(void) { if (lib.loaded == 0) { @@ -114,6 +114,7 @@ void IMG_QuitWEBP(void) } --lib.loaded; } +#endif // 0 static bool webp_getinfo(SDL_IOStream *src, size_t *datasize) { @@ -179,7 +180,7 @@ SDL_Surface *IMG_LoadWEBP_IO(SDL_IOStream *src) start = SDL_TellIO(src); - if ((IMG_Init(IMG_INIT_WEBP) & IMG_INIT_WEBP) == 0) { + if (!IMG_InitWEBP()) { goto error; } @@ -283,7 +284,7 @@ IMG_Animation *IMG_LoadWEBPAnimation_IO(SDL_IOStream *src) start = SDL_TellIO(src); - if ((IMG_Init(IMG_INIT_WEBP) & IMG_INIT_WEBP) == 0) { + if (!IMG_InitWEBP()) { goto error; } @@ -385,16 +386,6 @@ IMG_Animation *IMG_LoadWEBPAnimation_IO(SDL_IOStream *src) #pragma warning(disable : 4100) /* warning C4100: 'op' : unreferenced formal parameter */ #endif -int IMG_InitWEBP(void) -{ - SDL_SetError("WEBP images are not supported"); - return -1; -} - -void IMG_QuitWEBP(void) -{ -} - /* See if an image is contained in a data source */ bool IMG_isWEBP(SDL_IOStream *src) { diff --git a/src/IMG_xcf.c b/src/IMG_xcf.c index cd9912a82..e3d321eda 100644 --- a/src/IMG_xcf.c +++ b/src/IMG_xcf.c @@ -23,7 +23,6 @@ #include #include -#include "IMG.h" #ifdef LOAD_XCF diff --git a/src/IMG_xpm.c b/src/IMG_xpm.c index 11193ce2e..987493fa2 100644 --- a/src/IMG_xpm.c +++ b/src/IMG_xpm.c @@ -46,7 +46,6 @@ */ #include -#include "IMG.h" #ifdef LOAD_XPM diff --git a/src/IMG_xv.c b/src/IMG_xv.c index 8cedc3eeb..1ac7b77d9 100644 --- a/src/IMG_xv.c +++ b/src/IMG_xv.c @@ -22,7 +22,6 @@ /* This is a XV thumbnail image file loading framework */ #include -#include "IMG.h" #ifdef LOAD_XV diff --git a/src/IMG_xxx.c b/src/IMG_xxx.c index 889c45d93..4be1d43d1 100644 --- a/src/IMG_xxx.c +++ b/src/IMG_xxx.c @@ -22,7 +22,6 @@ /* This is a generic "format not supported" image framework */ #include -#include "IMG.h" #ifdef LOAD_XXX diff --git a/src/SDL_image.sym b/src/SDL_image.sym index 236b3b80b..c7b7a3387 100644 --- a/src/SDL_image.sym +++ b/src/SDL_image.sym @@ -1,7 +1,6 @@ SDL3_image_0.0.0 { global: IMG_FreeAnimation; - IMG_Init; IMG_Version; IMG_Load; IMG_LoadAVIF_IO; @@ -34,7 +33,6 @@ SDL3_image_0.0.0 { IMG_LoadXPM_IO; IMG_LoadXV_IO; IMG_Load_IO; - IMG_Quit; IMG_ReadXPMFromArray; IMG_ReadXPMFromArrayToRGB888; IMG_SaveJPG; diff --git a/test/main.c b/test/main.c index 4a89769af..16bce71b6 100644 --- a/test/main.c +++ b/test/main.c @@ -112,7 +112,6 @@ typedef struct int w; int h; int tolerance; - int initFlag; bool canLoad; bool canSave; bool (SDLCALL * checkFunction)(SDL_IOStream *src); @@ -128,7 +127,6 @@ static const Format formats[] = 23, 42, 300, - IMG_INIT_AVIF, #ifdef LOAD_AVIF true, #else @@ -145,7 +143,6 @@ static const Format formats[] = 23, 42, 0, /* lossless */ - 0, /* no initialization */ #ifdef LOAD_BMP true, #else @@ -162,7 +159,6 @@ static const Format formats[] = 23, 42, 0, /* lossless */ - 0, /* no initialization */ #ifdef LOAD_BMP true, #else @@ -179,7 +175,6 @@ static const Format formats[] = 23, 42, 0, /* lossless */ - 0, /* no initialization */ #if USING_IMAGEIO || defined(LOAD_GIF) true, #else @@ -196,7 +191,6 @@ static const Format formats[] = 23, 42, 0, /* lossless */ - 0, /* no initialization */ #ifdef LOAD_BMP true, #else @@ -213,7 +207,6 @@ static const Format formats[] = 23, 42, 100, - IMG_INIT_JPG, #if (USING_IMAGEIO && defined(JPG_USES_IMAGEIO)) || defined(SDL_IMAGE_USE_WIC_BACKEND) || defined(LOAD_JPG) true, #else @@ -230,7 +223,6 @@ static const Format formats[] = 23, 42, 300, - IMG_INIT_JXL, #ifdef LOAD_JXL true, #else @@ -248,7 +240,6 @@ static const Format formats[] = 23, 42, 0, /* lossless? */ - 0, /* no initialization */ #ifdef LOAD_LBM true, #else @@ -266,7 +257,6 @@ static const Format formats[] = 23, 42, 0, /* lossless? */ - 0, /* no initialization */ #ifdef LOAD_PCX true, #else @@ -283,7 +273,6 @@ static const Format formats[] = 23, 42, 0, /* lossless */ - IMG_INIT_PNG, #if (USING_IMAGEIO && defined(PNG_USES_IMAGEIO)) || defined(SDL_IMAGE_USE_WIC_BACKEND) || defined(LOAD_PNG) true, #else @@ -300,7 +289,6 @@ static const Format formats[] = 23, 42, 0, /* lossless */ - 0, /* no initialization */ #ifdef LOAD_PNM true, #else @@ -317,7 +305,6 @@ static const Format formats[] = 23, 42, 0, /* lossless */ - 0, /* no initialization */ #ifdef LOAD_QOI true, #else @@ -334,7 +321,6 @@ static const Format formats[] = 32, 32, 100, - 0, /* no initialization */ #ifdef LOAD_SVG true, #else @@ -351,7 +337,6 @@ static const Format formats[] = 64, 64, 100, - 0, /* no initialization */ #ifdef LOAD_SVG true, #else @@ -368,7 +353,6 @@ static const Format formats[] = 82, 82, 0, /* lossless? */ - 0, /* no initialization */ #ifdef LOAD_SVG true, #else @@ -385,7 +369,6 @@ static const Format formats[] = 23, 42, 0, /* lossless? */ - 0, /* no initialization */ #if USING_IMAGEIO || defined(LOAD_TGA) true, #else @@ -402,7 +385,6 @@ static const Format formats[] = 23, 42, 0, /* lossless */ - IMG_INIT_TIF, #if USING_IMAGEIO || defined(SDL_IMAGE_USE_WIC_BACKEND) || defined(LOAD_TIF) true, #else @@ -419,7 +401,6 @@ static const Format formats[] = 23, 42, 0, /* lossless */ - IMG_INIT_WEBP, #ifdef LOAD_WEBP true, #else @@ -436,7 +417,6 @@ static const Format formats[] = 23, 42, 0, /* lossless */ - 0, /* no initialization */ #ifdef LOAD_XCF true, #else @@ -453,7 +433,6 @@ static const Format formats[] = 23, 42, 0, /* lossless */ - 0, /* no initialization */ #ifdef LOAD_XPM true, #else @@ -471,7 +450,6 @@ static const Format formats[] = 23, 42, 0, /* lossless? */ - 0, /* no initialization */ #ifdef LOAD_XV true, #else @@ -622,7 +600,6 @@ FormatLoadTest(const Format *format, SDL_IOStream *src = NULL; char *filename = NULL; char *refFilename = NULL; - int initResult = 0; int diff; SDL_ClearError(); @@ -662,19 +639,6 @@ FormatLoadTest(const Format *format, #endif } - if (format->initFlag) { - SDL_ClearError(); - initResult = IMG_Init(format->initFlag); - if (!SDLTest_AssertCheck(initResult != 0, - "Initialization should succeed (%s)", - SDL_GetError())) { - goto out; - } - SDLTest_AssertCheck(initResult & format->initFlag, - "Expected at least bit 0x%x set, got 0x%x", - format->initFlag, initResult); - } - if (mode != LOAD_CONVENIENCE) { SDL_ClearError(); src = SDL_IOFromFile(filename, "rb"); @@ -783,9 +747,6 @@ FormatLoadTest(const Format *format, if (filename != NULL) { SDL_free(filename); } - if (initResult) { - IMG_Quit(); - } } static void @@ -797,7 +758,6 @@ FormatSaveTest(const Format *format, SDL_Surface *reference = NULL; SDL_Surface *surface = NULL; SDL_IOStream *dest = NULL; - int initResult = 0; int diff; bool result; @@ -822,19 +782,6 @@ FormatSaveTest(const Format *format, goto out; } - if (format->initFlag) { - SDL_ClearError(); - initResult = IMG_Init(format->initFlag); - if (!SDLTest_AssertCheck(initResult != 0, - "Initialization should succeed (%s)", - SDL_GetError())) { - goto out; - } - SDLTest_AssertCheck(initResult & format->initFlag, - "Expected at least bit 0x%x set, got 0x%x", - format->initFlag, initResult); - } - SDL_ClearError(); if (SDL_strcmp (format->name, "AVIF") == 0) { if (rw) { @@ -906,9 +853,6 @@ FormatSaveTest(const Format *format, if (refFilename != NULL) { SDL_free(refFilename); } - if (initResult) { - IMG_Quit(); - } } static void