From f9726bc12392dc8796c8711ad768fdc2dd081b26 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 2 Dec 2024 16:06:11 -0800 Subject: [PATCH 1/3] 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. --- cmake/test/main.c | 19 +------ 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 ------------------ 28 files changed, 66 insertions(+), 493 deletions(-) create mode 100644 docs/README-migration.md delete mode 100644 src/IMG.h diff --git a/cmake/test/main.c b/cmake/test/main.c index 8eb21937..0b57b50e 100644 --- a/cmake/test/main.c +++ b/cmake/test/main.c @@ -2,22 +2,6 @@ #include #include -#define TEST_INIT_FLAG(FLAG) do { \ - if ((IMG_Init(FLAG) & FLAG) == FLAG) { \ - SDL_Log("IMG_Init("#FLAG") succeeded"); \ - } else { \ - SDL_Log("IMG_Init("#FLAG") failed"); \ - } \ - } while (0); - -#define FOREACH_INIT_FLAGS(X) \ - X(IMG_INIT_JPG) \ - X(IMG_INIT_PNG) \ - X(IMG_INIT_TIF) \ - X(IMG_INIT_WEBP) \ - X(IMG_INIT_JXL) \ - X(IMG_INIT_AVIF) \ - int main(int argc, char *argv[]) { if (!SDL_Init(0)) { @@ -25,9 +9,8 @@ int main(int argc, char *argv[]) return 1; } - FOREACH_INIT_FLAGS(TEST_INIT_FLAG) + IMG_Version(); - IMG_Quit(); SDL_Quit(); return 0; } diff --git a/docs/README-migration.md b/docs/README-migration.md new file mode 100644 index 00000000..56b690c1 --- /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 e5ff0835..ae1fd347 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 b32adc33..1b4de2a5 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 02208d5c..00000000 --- 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 2d6eef01..317de5e9 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 a4762144..36649efe 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 96e1ca5b..ec4035c6 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 true; } +#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 4386896a..18ef6adb 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 4825eec9..06858f6f 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 d7a3e05f..b6f408fd 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 0c5c91c1..e193019e 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 5031fa0e..e1765fd2 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 8cfe8db0..2be548b9 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 dbebcfa3..6e26ba9f 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 21b0fbf9..6ed6104a 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 3c0ba314..e6a6c95f 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 ff8cab4c..77622fd8 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 a042f2cb..7582ddc8 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 270c7945..65501724 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 a405c7cc..cfe786f6 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 0b2bbfea..57e76d3a 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 true; } +#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 cd9912a8..e3d321ed 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 11193ce2..987493fa 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 8cedc3ee..1ac7b77d 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 889c45d9..4be1d43d 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 236b3b80..c7b7a338 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 4a89769a..16bce71b 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 From 6b4b4921a5564a50c3f5ca35550598a236b7a3e4 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 2 Dec 2024 16:08:17 -0800 Subject: [PATCH 2/3] Fixed warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'int' --- src/IMG_ImageIO.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/IMG_ImageIO.m b/src/IMG_ImageIO.m index 317de5e9..0bd4edb5 100644 --- a/src/IMG_ImageIO.m +++ b/src/IMG_ImageIO.m @@ -323,7 +323,7 @@ static CFDictionaryRef CreateHintDictionary(CFStringRef uti_string_hint) if (num_entries > (size_t)palette->ncolors) { num_entries = (size_t)palette->ncolors; } - palette->ncolors = num_entries; + palette->ncolors = (int)num_entries; for (i = 0, entry = entries; i < num_entries; ++i) { palette->colors[i].r = entry[0]; palette->colors[i].g = entry[1]; From 88034a12260f8399e604c41ccf3e8c71a23d4ec6 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Mon, 2 Dec 2024 16:14:56 -0800 Subject: [PATCH 3/3] Fixed warning: empty expression statement has no effect; remove unnecessary ';' to silence this warning --- src/miniz.h | 44 +++++++++++++++++++++++++------------------- src/stb_image.h | 24 ++++++++++++------------ src/tiny_jpeg.h | 4 ++-- 3 files changed, 39 insertions(+), 33 deletions(-) diff --git a/src/miniz.h b/src/miniz.h index 766940a6..66f97951 100644 --- a/src/miniz.h +++ b/src/miniz.h @@ -2006,22 +2006,26 @@ static void tdefl_optimize_huffman_table(tdefl_compressor *d, int table_num, int } \ } MZ_MACRO_END -#define TDEFL_RLE_PREV_CODE_SIZE() { if (rle_repeat_count) { \ - if (rle_repeat_count < 3) { \ - d->m_huff_count[2][prev_code_size] = (mz_uint16)(d->m_huff_count[2][prev_code_size] + rle_repeat_count); \ - while (rle_repeat_count--) packed_code_sizes[num_packed_code_sizes++] = prev_code_size; \ - } else { \ - d->m_huff_count[2][16] = (mz_uint16)(d->m_huff_count[2][16] + 1); packed_code_sizes[num_packed_code_sizes++] = 16; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_repeat_count - 3); \ -} rle_repeat_count = 0; } } - -#define TDEFL_RLE_ZERO_CODE_SIZE() { if (rle_z_count) { \ - if (rle_z_count < 3) { \ - d->m_huff_count[2][0] = (mz_uint16)(d->m_huff_count[2][0] + rle_z_count); while (rle_z_count--) packed_code_sizes[num_packed_code_sizes++] = 0; \ - } else if (rle_z_count <= 10) { \ - d->m_huff_count[2][17] = (mz_uint16)(d->m_huff_count[2][17] + 1); packed_code_sizes[num_packed_code_sizes++] = 17; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 3); \ - } else { \ - d->m_huff_count[2][18] = (mz_uint16)(d->m_huff_count[2][18] + 1); packed_code_sizes[num_packed_code_sizes++] = 18; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 11); \ -} rle_z_count = 0; } } +#define TDEFL_RLE_PREV_CODE_SIZE() do { \ + if (rle_repeat_count) { \ + if (rle_repeat_count < 3) { \ + d->m_huff_count[2][prev_code_size] = (mz_uint16)(d->m_huff_count[2][prev_code_size] + rle_repeat_count); \ + while (rle_repeat_count--) packed_code_sizes[num_packed_code_sizes++] = prev_code_size; \ + } else { \ + d->m_huff_count[2][16] = (mz_uint16)(d->m_huff_count[2][16] + 1); packed_code_sizes[num_packed_code_sizes++] = 16; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_repeat_count - 3); \ + } rle_repeat_count = 0; } \ +} MZ_MACRO_END + +#define TDEFL_RLE_ZERO_CODE_SIZE() do { \ + if (rle_z_count) { \ + if (rle_z_count < 3) { \ + d->m_huff_count[2][0] = (mz_uint16)(d->m_huff_count[2][0] + rle_z_count); while (rle_z_count--) packed_code_sizes[num_packed_code_sizes++] = 0; \ + } else if (rle_z_count <= 10) { \ + d->m_huff_count[2][17] = (mz_uint16)(d->m_huff_count[2][17] + 1); packed_code_sizes[num_packed_code_sizes++] = 17; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 3); \ + } else { \ + d->m_huff_count[2][18] = (mz_uint16)(d->m_huff_count[2][18] + 1); packed_code_sizes[num_packed_code_sizes++] = 18; packed_code_sizes[num_packed_code_sizes++] = (mz_uint8)(rle_z_count - 11); \ + } rle_z_count = 0; } \ +} MZ_MACRO_END static mz_uint8 s_tdefl_packed_code_size_syms_swizzle[] = { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; @@ -2366,11 +2370,12 @@ static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahe for ( ; ; ) { if (--num_probes_left == 0) return; - #define TDEFL_PROBE \ + #define TDEFL_PROBE do { \ next_probe_pos = d->m_next[probe_pos]; \ if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) return; \ probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \ if (TDEFL_READ_UNALIGNED_WORD(&d->m_dict[probe_pos + match_len - 1]) == c01) break; + } MZ_MACRO_END TDEFL_PROBE; TDEFL_PROBE; TDEFL_PROBE; @@ -2405,11 +2410,12 @@ static MZ_FORCEINLINE void tdefl_find_match(tdefl_compressor *d, mz_uint lookahe for ( ; ; ) { if (--num_probes_left == 0) return; - #define TDEFL_PROBE \ + #define TDEFL_PROBE do { \ next_probe_pos = d->m_next[probe_pos]; \ if ((!next_probe_pos) || ((dist = (mz_uint16)(lookahead_pos - next_probe_pos)) > max_dist)) return; \ probe_pos = next_probe_pos & TDEFL_LZ_DICT_SIZE_MASK; \ - if ((d->m_dict[probe_pos + match_len] == c0) && (d->m_dict[probe_pos + match_len - 1] == c1)) break; + if ((d->m_dict[probe_pos + match_len] == c0) && (d->m_dict[probe_pos + match_len - 1] == c1)) break; \ + } MZ_MACRO_END TDEFL_PROBE; TDEFL_PROBE; TDEFL_PROBE; diff --git a/src/stb_image.h b/src/stb_image.h index 6ba09386..393323fe 100644 --- a/src/stb_image.h +++ b/src/stb_image.h @@ -2723,7 +2723,7 @@ static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64]) b = _mm_unpackhi_epi16(tmp, b) #define dct_pass(bias,shift) \ - { \ + do { \ /* even part */ \ dct_rot(t2e,t3e, row2,row6, rot0_0,rot0_1); \ __m128i sum04 = _mm_add_epi16(row0, row4); \ @@ -2748,7 +2748,7 @@ static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64]) dct_bfly32o(row1,row6, x1,x6,bias,shift); \ dct_bfly32o(row2,row5, x2,x5,bias,shift); \ dct_bfly32o(row3,row4, x3,x4,bias,shift); \ - } + } while ( 0 ) __m128i rot0_0 = dct_const(stbi__f2f(0.5411961f), stbi__f2f(0.5411961f) + stbi__f2f(-1.847759065f)); __m128i rot0_1 = dct_const(stbi__f2f(0.5411961f) + stbi__f2f( 0.765366865f), stbi__f2f(0.5411961f)); @@ -2887,15 +2887,15 @@ static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64]) // butterfly a/b, then shift using "shiftop" by "s" and pack #define dct_bfly32o(out0,out1, a,b,shiftop,s) \ - { \ + do { \ dct_wadd(sum, a, b); \ dct_wsub(dif, a, b); \ out0 = vcombine_s16(shiftop(sum_l, s), shiftop(sum_h, s)); \ out1 = vcombine_s16(shiftop(dif_l, s), shiftop(dif_h, s)); \ - } + } while ( 0 ) #define dct_pass(shiftop, shift) \ - { \ + do { \ /* even part */ \ int16x8_t sum26 = vaddq_s16(row2, row6); \ dct_long_mul(p1e, sum26, rot0_0); \ @@ -2932,7 +2932,7 @@ static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64]) dct_bfly32o(row1,row6, x1,x6,shiftop,shift); \ dct_bfly32o(row2,row5, x2,x5,shiftop,shift); \ dct_bfly32o(row3,row4, x3,x4,shiftop,shift); \ - } + } while ( 0 ) // load row0 = vld1q_s16(data + 0*8); @@ -2954,9 +2954,9 @@ static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64]) { // these three map to a single VTRN.16, VTRN.32, and VSWP, respectively. // whether compilers actually get this is another story, sadly. -#define dct_trn16(x, y) { int16x8x2_t t = vtrnq_s16(x, y); x = t.val[0]; y = t.val[1]; } -#define dct_trn32(x, y) { int32x4x2_t t = vtrnq_s32(vreinterpretq_s32_s16(x), vreinterpretq_s32_s16(y)); x = vreinterpretq_s16_s32(t.val[0]); y = vreinterpretq_s16_s32(t.val[1]); } -#define dct_trn64(x, y) { int16x8_t x0 = x; int16x8_t y0 = y; x = vcombine_s16(vget_low_s16(x0), vget_low_s16(y0)); y = vcombine_s16(vget_high_s16(x0), vget_high_s16(y0)); } +#define dct_trn16(x, y) do { int16x8x2_t t = vtrnq_s16(x, y); x = t.val[0]; y = t.val[1]; } while ( 0 ) +#define dct_trn32(x, y) do { int32x4x2_t t = vtrnq_s32(vreinterpretq_s32_s16(x), vreinterpretq_s32_s16(y)); x = vreinterpretq_s16_s32(t.val[0]); y = vreinterpretq_s16_s32(t.val[1]); } while ( 0 ) +#define dct_trn64(x, y) do { int16x8_t x0 = x; int16x8_t y0 = y; x = vcombine_s16(vget_low_s16(x0), vget_low_s16(y0)); y = vcombine_s16(vget_high_s16(x0), vget_high_s16(y0)); } while ( 0 ) // pass 1 dct_trn16(row0, row1); // a0b0a2b2a4b4a6b6 @@ -2999,9 +2999,9 @@ static void stbi__idct_simd(stbi_uc *out, int out_stride, short data[64]) uint8x8_t p7 = vqrshrun_n_s16(row7, 1); // again, these can translate into one instruction, but often don't. -#define dct_trn8_8(x, y) { uint8x8x2_t t = vtrn_u8(x, y); x = t.val[0]; y = t.val[1]; } -#define dct_trn8_16(x, y) { uint16x4x2_t t = vtrn_u16(vreinterpret_u16_u8(x), vreinterpret_u16_u8(y)); x = vreinterpret_u8_u16(t.val[0]); y = vreinterpret_u8_u16(t.val[1]); } -#define dct_trn8_32(x, y) { uint32x2x2_t t = vtrn_u32(vreinterpret_u32_u8(x), vreinterpret_u32_u8(y)); x = vreinterpret_u8_u32(t.val[0]); y = vreinterpret_u8_u32(t.val[1]); } +#define dct_trn8_8(x, y) do { uint8x8x2_t t = vtrn_u8(x, y); x = t.val[0]; y = t.val[1]; } while ( 0 ) +#define dct_trn8_16(x, y) do { uint16x4x2_t t = vtrn_u16(vreinterpret_u16_u8(x), vreinterpret_u16_u8(y)); x = vreinterpret_u8_u16(t.val[0]); y = vreinterpret_u8_u16(t.val[1]); } while ( 0 ) +#define dct_trn8_32(x, y) do { uint32x2x2_t t = vtrn_u32(vreinterpret_u32_u8(x), vreinterpret_u32_u8(y)); x = vreinterpret_u8_u32(t.val[0]); y = vreinterpret_u8_u32(t.val[1]); } while ( 0 ) // sadly can't use interleaved stores here since we only write // 8 bytes to each scan line! diff --git a/src/tiny_jpeg.h b/src/tiny_jpeg.h index dc859b1c..27f5566b 100644 --- a/src/tiny_jpeg.h +++ b/src/tiny_jpeg.h @@ -168,8 +168,8 @@ int tje_encode_with_func(tje_write_func* func, #ifdef TJE_IMPLEMENTATION -#define tjei_min(a, b) ((a) < b) ? (a) : (b); -#define tjei_max(a, b) ((a) < b) ? (b) : (a); +#define tjei_min(a, b) ((a) < b) ? (a) : (b) +#define tjei_max(a, b) ((a) < b) ? (b) : (a) #if defined(_MSC_VER)