From f5f1b1b55e5e7ae8352dd4fffc0a4b2a6acc9b38 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Tue, 27 Aug 2024 16:23:57 -0700 Subject: [PATCH] Use SDL_bool instead an int return code in the SDL API Most SDL functions used to indicate success or failure using an int return code. These functions have been changed to return SDL_bool. Here is a coccinelle patch to change code that previously compared the return value to 0 and changes it to a boolean test: @ bool_return_type @ identifier func =~ "^(IMG_SaveAVIF|IMG_SaveAVIF_IO|IMG_SaveJPG|IMG_SaveJPG_IO|IMG_SavePNG|IMG_SavePNG_IO)$" @@ ( func( ... ) - == 0 | - func( + !func( ... ) - < 0 | - func( + !func( ... ) - != 0 | - func( + !func( ... ) - == -1 ) --- examples/showimage.c | 12 +-- include/SDL3_image/SDL_image.h | 129 +++++++++++-------------- src/IMG.c | 45 ++++----- src/IMG_ImageIO.m | 29 +++--- src/IMG_WIC.c | 111 +++++++++++----------- src/IMG_avif.c | 64 ++++++------- src/IMG_bmp.c | 69 +++++++------- src/IMG_gif.c | 24 ++--- src/IMG_jpg.c | 167 +++++++++++++++++---------------- src/IMG_jxl.c | 47 +++++----- src/IMG_lbm.c | 26 ++--- src/IMG_pcx.c | 26 ++--- src/IMG_png.c | 98 ++++++++++--------- src/IMG_pnm.c | 30 +++--- src/IMG_qoi.c | 28 +++--- src/IMG_stb.c | 4 +- src/IMG_svg.c | 26 ++--- src/IMG_tga.c | 2 +- src/IMG_tif.c | 26 ++--- src/IMG_webp.c | 30 +++--- src/IMG_xcf.c | 22 ++--- src/IMG_xpm.c | 36 +++---- src/IMG_xv.c | 24 ++--- src/IMG_xxx.c | 14 +-- src/stb_image.h | 2 +- test/main.c | 2 +- 26 files changed, 544 insertions(+), 549 deletions(-) diff --git a/examples/showimage.c b/examples/showimage.c index 671cb2b5..caf339d5 100644 --- a/examples/showimage.c +++ b/examples/showimage.c @@ -173,19 +173,19 @@ int main(int argc, char *argv[]) SDL_Surface *surface = IMG_Load(argv[i]); if (surface) { const char *ext = SDL_strrchr(saveFile, '.'); + SDL_bool saved = SDL_FALSE; if (ext && SDL_strcasecmp(ext, ".avif") == 0) { - result = IMG_SaveAVIF(surface, saveFile, 90); + saved = IMG_SaveAVIF(surface, saveFile, 90); } else if (ext && SDL_strcasecmp(ext, ".bmp") == 0) { - result = SDL_SaveBMP(surface, saveFile); + saved = SDL_SaveBMP(surface, saveFile); } else if (ext && SDL_strcasecmp(ext, ".jpg") == 0) { - result = IMG_SaveJPG(surface, saveFile, 90); + saved = IMG_SaveJPG(surface, saveFile, 90); } else if (ext && SDL_strcasecmp(ext, ".png") == 0) { - result = IMG_SavePNG(surface, saveFile); + saved = IMG_SavePNG(surface, saveFile); } else { SDL_SetError("Unknown save file type"); - result = -1; } - if (result < 0) { + if (!saved) { SDL_Log("Couldn't save %s: %s\n", saveFile, SDL_GetError()); result = 3; } diff --git a/include/SDL3_image/SDL_image.h b/include/SDL3_image/SDL_image.h index 75a2b15b..4e803c6a 100644 --- a/include/SDL3_image/SDL_image.h +++ b/include/SDL3_image/SDL_image.h @@ -70,15 +70,14 @@ extern SDL_DECLSPEC int SDLCALL IMG_Version(void); /** * Initialization flags */ -typedef enum IMG_InitFlags -{ - IMG_INIT_JPG = 0x00000001, - IMG_INIT_PNG = 0x00000002, - IMG_INIT_TIF = 0x00000004, - IMG_INIT_WEBP = 0x00000008, - IMG_INIT_JXL = 0x00000010, - IMG_INIT_AVIF = 0x00000020 -} IMG_InitFlags; +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. @@ -142,7 +141,7 @@ typedef enum IMG_InitFlags * * \sa IMG_Quit */ -extern SDL_DECLSPEC int SDLCALL IMG_Init(int flags); +extern SDL_DECLSPEC IMG_InitFlags SDLCALL IMG_Init(IMG_InitFlags flags); /** * Deinitialize SDL_image. @@ -489,7 +488,7 @@ extern SDL_DECLSPEC SDL_Texture * SDLCALL IMG_LoadTextureTyped_IO(SDL_Renderer * * determine file type in many cases in its standard load functions. * * \param src a seekable/readable SDL_IOStream to provide image data. - * \returns non-zero if this is AVIF data, zero otherwise. + * \returns SDL_TRUE if this is AVIF data, SDL_FALSE otherwise. * * \since This function is available since SDL_image 3.0.0. * @@ -512,7 +511,7 @@ extern SDL_DECLSPEC SDL_Texture * SDLCALL IMG_LoadTextureTyped_IO(SDL_Renderer * * \sa IMG_isXV * \sa IMG_isWEBP */ -extern SDL_DECLSPEC int SDLCALL IMG_isAVIF(SDL_IOStream *src); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_isAVIF(SDL_IOStream *src); /** * Detect ICO image data on a readable/seekable SDL_IOStream. @@ -533,7 +532,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isAVIF(SDL_IOStream *src); * determine file type in many cases in its standard load functions. * * \param src a seekable/readable SDL_IOStream to provide image data. - * \returns non-zero if this is ICO data, zero otherwise. + * \returns SDL_TRUE if this is ICO data, SDL_FALSE otherwise. * * \since This function is available since SDL_image 3.0.0. * @@ -555,7 +554,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isAVIF(SDL_IOStream *src); * \sa IMG_isXV * \sa IMG_isWEBP */ -extern SDL_DECLSPEC int SDLCALL IMG_isICO(SDL_IOStream *src); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_isICO(SDL_IOStream *src); /** * Detect CUR image data on a readable/seekable SDL_IOStream. @@ -576,7 +575,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isICO(SDL_IOStream *src); * determine file type in many cases in its standard load functions. * * \param src a seekable/readable SDL_IOStream to provide image data. - * \returns non-zero if this is CUR data, zero otherwise. + * \returns SDL_TRUE if this is CUR data, SDL_FALSE otherwise. * * \since This function is available since SDL_image 3.0.0. * @@ -598,7 +597,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isICO(SDL_IOStream *src); * \sa IMG_isXV * \sa IMG_isWEBP */ -extern SDL_DECLSPEC int SDLCALL IMG_isCUR(SDL_IOStream *src); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_isCUR(SDL_IOStream *src); /** * Detect BMP image data on a readable/seekable SDL_IOStream. @@ -619,7 +618,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isCUR(SDL_IOStream *src); * determine file type in many cases in its standard load functions. * * \param src a seekable/readable SDL_IOStream to provide image data. - * \returns non-zero if this is BMP data, zero otherwise. + * \returns SDL_TRUE if this is BMP data, SDL_FALSE otherwise. * * \since This function is available since SDL_image 3.0.0. * @@ -641,7 +640,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isCUR(SDL_IOStream *src); * \sa IMG_isXV * \sa IMG_isWEBP */ -extern SDL_DECLSPEC int SDLCALL IMG_isBMP(SDL_IOStream *src); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_isBMP(SDL_IOStream *src); /** * Detect GIF image data on a readable/seekable SDL_IOStream. @@ -662,7 +661,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isBMP(SDL_IOStream *src); * determine file type in many cases in its standard load functions. * * \param src a seekable/readable SDL_IOStream to provide image data. - * \returns non-zero if this is GIF data, zero otherwise. + * \returns SDL_TRUE if this is GIF data, SDL_FALSE otherwise. * * \since This function is available since SDL_image 3.0.0. * @@ -684,7 +683,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isBMP(SDL_IOStream *src); * \sa IMG_isXV * \sa IMG_isWEBP */ -extern SDL_DECLSPEC int SDLCALL IMG_isGIF(SDL_IOStream *src); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_isGIF(SDL_IOStream *src); /** * Detect JPG image data on a readable/seekable SDL_IOStream. @@ -705,7 +704,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isGIF(SDL_IOStream *src); * determine file type in many cases in its standard load functions. * * \param src a seekable/readable SDL_IOStream to provide image data. - * \returns non-zero if this is JPG data, zero otherwise. + * \returns SDL_TRUE if this is JPG data, SDL_FALSE otherwise. * * \since This function is available since SDL_image 3.0.0. * @@ -727,7 +726,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isGIF(SDL_IOStream *src); * \sa IMG_isXV * \sa IMG_isWEBP */ -extern SDL_DECLSPEC int SDLCALL IMG_isJPG(SDL_IOStream *src); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_isJPG(SDL_IOStream *src); /** * Detect JXL image data on a readable/seekable SDL_IOStream. @@ -748,7 +747,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isJPG(SDL_IOStream *src); * determine file type in many cases in its standard load functions. * * \param src a seekable/readable SDL_IOStream to provide image data. - * \returns non-zero if this is JXL data, zero otherwise. + * \returns SDL_TRUE if this is JXL data, SDL_FALSE otherwise. * * \since This function is available since SDL_image 3.0.0. * @@ -770,7 +769,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isJPG(SDL_IOStream *src); * \sa IMG_isXV * \sa IMG_isWEBP */ -extern SDL_DECLSPEC int SDLCALL IMG_isJXL(SDL_IOStream *src); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_isJXL(SDL_IOStream *src); /** * Detect LBM image data on a readable/seekable SDL_IOStream. @@ -791,7 +790,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isJXL(SDL_IOStream *src); * determine file type in many cases in its standard load functions. * * \param src a seekable/readable SDL_IOStream to provide image data. - * \returns non-zero if this is LBM data, zero otherwise. + * \returns SDL_TRUE if this is LBM data, SDL_FALSE otherwise. * * \since This function is available since SDL_image 3.0.0. * @@ -813,7 +812,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isJXL(SDL_IOStream *src); * \sa IMG_isXV * \sa IMG_isWEBP */ -extern SDL_DECLSPEC int SDLCALL IMG_isLBM(SDL_IOStream *src); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_isLBM(SDL_IOStream *src); /** * Detect PCX image data on a readable/seekable SDL_IOStream. @@ -834,7 +833,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isLBM(SDL_IOStream *src); * determine file type in many cases in its standard load functions. * * \param src a seekable/readable SDL_IOStream to provide image data. - * \returns non-zero if this is PCX data, zero otherwise. + * \returns SDL_TRUE if this is PCX data, SDL_FALSE otherwise. * * \since This function is available since SDL_image 3.0.0. * @@ -856,7 +855,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isLBM(SDL_IOStream *src); * \sa IMG_isXV * \sa IMG_isWEBP */ -extern SDL_DECLSPEC int SDLCALL IMG_isPCX(SDL_IOStream *src); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_isPCX(SDL_IOStream *src); /** * Detect PNG image data on a readable/seekable SDL_IOStream. @@ -877,7 +876,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isPCX(SDL_IOStream *src); * determine file type in many cases in its standard load functions. * * \param src a seekable/readable SDL_IOStream to provide image data. - * \returns non-zero if this is PNG data, zero otherwise. + * \returns SDL_TRUE if this is PNG data, SDL_FALSE otherwise. * * \since This function is available since SDL_image 3.0.0. * @@ -899,7 +898,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isPCX(SDL_IOStream *src); * \sa IMG_isXV * \sa IMG_isWEBP */ -extern SDL_DECLSPEC int SDLCALL IMG_isPNG(SDL_IOStream *src); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_isPNG(SDL_IOStream *src); /** * Detect PNM image data on a readable/seekable SDL_IOStream. @@ -920,7 +919,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isPNG(SDL_IOStream *src); * determine file type in many cases in its standard load functions. * * \param src a seekable/readable SDL_IOStream to provide image data. - * \returns non-zero if this is PNM data, zero otherwise. + * \returns SDL_TRUE if this is PNM data, SDL_FALSE otherwise. * * \since This function is available since SDL_image 3.0.0. * @@ -942,7 +941,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isPNG(SDL_IOStream *src); * \sa IMG_isXV * \sa IMG_isWEBP */ -extern SDL_DECLSPEC int SDLCALL IMG_isPNM(SDL_IOStream *src); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_isPNM(SDL_IOStream *src); /** * Detect SVG image data on a readable/seekable SDL_IOStream. @@ -963,7 +962,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isPNM(SDL_IOStream *src); * determine file type in many cases in its standard load functions. * * \param src a seekable/readable SDL_IOStream to provide image data. - * \returns non-zero if this is SVG data, zero otherwise. + * \returns SDL_TRUE if this is SVG data, SDL_FALSE otherwise. * * \since This function is available since SDL_image 3.0.0. * @@ -985,7 +984,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isPNM(SDL_IOStream *src); * \sa IMG_isXV * \sa IMG_isWEBP */ -extern SDL_DECLSPEC int SDLCALL IMG_isSVG(SDL_IOStream *src); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_isSVG(SDL_IOStream *src); /** * Detect QOI image data on a readable/seekable SDL_IOStream. @@ -1006,7 +1005,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isSVG(SDL_IOStream *src); * determine file type in many cases in its standard load functions. * * \param src a seekable/readable SDL_IOStream to provide image data. - * \returns non-zero if this is QOI data, zero otherwise. + * \returns SDL_TRUE if this is QOI data, SDL_FALSE otherwise. * * \since This function is available since SDL_image 3.0.0. * @@ -1028,7 +1027,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isSVG(SDL_IOStream *src); * \sa IMG_isXV * \sa IMG_isWEBP */ -extern SDL_DECLSPEC int SDLCALL IMG_isQOI(SDL_IOStream *src); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_isQOI(SDL_IOStream *src); /** * Detect TIFF image data on a readable/seekable SDL_IOStream. @@ -1049,7 +1048,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isQOI(SDL_IOStream *src); * determine file type in many cases in its standard load functions. * * \param src a seekable/readable SDL_IOStream to provide image data. - * \returns non-zero if this is TIFF data, zero otherwise. + * \returns SDL_TRUE if this is TIFF data, SDL_FALSE otherwise. * * \since This function is available since SDL_image 3.0.0. * @@ -1071,7 +1070,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isQOI(SDL_IOStream *src); * \sa IMG_isXV * \sa IMG_isWEBP */ -extern SDL_DECLSPEC int SDLCALL IMG_isTIF(SDL_IOStream *src); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_isTIF(SDL_IOStream *src); /** * Detect XCF image data on a readable/seekable SDL_IOStream. @@ -1092,7 +1091,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isTIF(SDL_IOStream *src); * determine file type in many cases in its standard load functions. * * \param src a seekable/readable SDL_IOStream to provide image data. - * \returns non-zero if this is XCF data, zero otherwise. + * \returns SDL_TRUE if this is XCF data, SDL_FALSE otherwise. * * \since This function is available since SDL_image 3.0.0. * @@ -1114,7 +1113,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isTIF(SDL_IOStream *src); * \sa IMG_isXV * \sa IMG_isWEBP */ -extern SDL_DECLSPEC int SDLCALL IMG_isXCF(SDL_IOStream *src); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_isXCF(SDL_IOStream *src); /** * Detect XPM image data on a readable/seekable SDL_IOStream. @@ -1135,7 +1134,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isXCF(SDL_IOStream *src); * determine file type in many cases in its standard load functions. * * \param src a seekable/readable SDL_IOStream to provide image data. - * \returns non-zero if this is XPM data, zero otherwise. + * \returns SDL_TRUE if this is XPM data, SDL_FALSE otherwise. * * \since This function is available since SDL_image 3.0.0. * @@ -1157,7 +1156,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isXCF(SDL_IOStream *src); * \sa IMG_isXV * \sa IMG_isWEBP */ -extern SDL_DECLSPEC int SDLCALL IMG_isXPM(SDL_IOStream *src); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_isXPM(SDL_IOStream *src); /** * Detect XV image data on a readable/seekable SDL_IOStream. @@ -1178,7 +1177,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isXPM(SDL_IOStream *src); * determine file type in many cases in its standard load functions. * * \param src a seekable/readable SDL_IOStream to provide image data. - * \returns non-zero if this is XV data, zero otherwise. + * \returns SDL_TRUE if this is XV data, SDL_FALSE otherwise. * * \since This function is available since SDL_image 3.0.0. * @@ -1200,7 +1199,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isXPM(SDL_IOStream *src); * \sa IMG_isXPM * \sa IMG_isWEBP */ -extern SDL_DECLSPEC int SDLCALL IMG_isXV(SDL_IOStream *src); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_isXV(SDL_IOStream *src); /** * Detect WEBP image data on a readable/seekable SDL_IOStream. @@ -1221,7 +1220,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isXV(SDL_IOStream *src); * determine file type in many cases in its standard load functions. * * \param src a seekable/readable SDL_IOStream to provide image data. - * \returns non-zero if this is WEBP data, zero otherwise. + * \returns SDL_TRUE if this is WEBP data, SDL_FALSE otherwise. * * \since This function is available since SDL_image 3.0.0. * @@ -1243,7 +1242,7 @@ extern SDL_DECLSPEC int SDLCALL IMG_isXV(SDL_IOStream *src); * \sa IMG_isXPM * \sa IMG_isXV */ -extern SDL_DECLSPEC int SDLCALL IMG_isWEBP(SDL_IOStream *src); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_isWEBP(SDL_IOStream *src); /** * Load a AVIF image directly. @@ -1959,13 +1958,13 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL IMG_ReadXPMFromArrayToRGB888(char **xp * \param file path on the filesystem to write new file to. * \param quality the desired quality, ranging between 0 (lowest) and 100 * (highest). - * \returns 0 if successful, -1 on error. + * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError() for more information. * * \since This function is available since SDL_image 3.0.0. * * \sa IMG_SaveAVIF_IO */ -extern SDL_DECLSPEC int SDLCALL IMG_SaveAVIF(SDL_Surface *surface, const char *file, int quality); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_SaveAVIF(SDL_Surface *surface, const char *file, int quality); /** * Save an SDL_Surface into AVIF image data, via an SDL_IOStream. @@ -1981,13 +1980,13 @@ extern SDL_DECLSPEC int SDLCALL IMG_SaveAVIF(SDL_Surface *surface, const char *f * SDL_FALSE to leave it open. * \param quality the desired quality, ranging between 0 (lowest) and 100 * (highest). - * \returns 0 if successful, -1 on error. + * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError() for more information. * * \since This function is available since SDL_image 3.0.0. * * \sa IMG_SaveAVIF */ -extern SDL_DECLSPEC int SDLCALL IMG_SaveAVIF_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio, int quality); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_SaveAVIF_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio, int quality); /** * Save an SDL_Surface into a PNG image file. @@ -1996,13 +1995,13 @@ extern SDL_DECLSPEC int SDLCALL IMG_SaveAVIF_IO(SDL_Surface *surface, SDL_IOStre * * \param surface the SDL surface to save. * \param file path on the filesystem to write new file to. - * \returns 0 if successful, -1 on error. + * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError() for more information. * * \since This function is available since SDL_image 3.0.0. * * \sa IMG_SavePNG_IO */ -extern SDL_DECLSPEC int SDLCALL IMG_SavePNG(SDL_Surface *surface, const char *file); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_SavePNG(SDL_Surface *surface, const char *file); /** * Save an SDL_Surface into PNG image data, via an SDL_IOStream. @@ -2016,13 +2015,13 @@ extern SDL_DECLSPEC int SDLCALL IMG_SavePNG(SDL_Surface *surface, const char *fi * \param dst the SDL_IOStream to save the image data to. * \param closeio SDL_TRUE to close/free the SDL_IOStream before returning, * SDL_FALSE to leave it open. - * \returns 0 if successful, -1 on error. + * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError() for more information. * * \since This function is available since SDL_image 3.0.0. * * \sa IMG_SavePNG */ -extern SDL_DECLSPEC int SDLCALL IMG_SavePNG_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_SavePNG_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio); /** * Save an SDL_Surface into a JPEG image file. @@ -2033,13 +2032,13 @@ extern SDL_DECLSPEC int SDLCALL IMG_SavePNG_IO(SDL_Surface *surface, SDL_IOStrea * \param file path on the filesystem to write new file to. * \param quality [0; 33] is Lowest quality, [34; 66] is Middle quality, [67; * 100] is Highest quality. - * \returns 0 if successful, -1 on error. + * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError() for more information. * * \since This function is available since SDL_image 3.0.0. * * \sa IMG_SaveJPG_IO */ -extern SDL_DECLSPEC int SDLCALL IMG_SaveJPG(SDL_Surface *surface, const char *file, int quality); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_SaveJPG(SDL_Surface *surface, const char *file, int quality); /** * Save an SDL_Surface into JPEG image data, via an SDL_IOStream. @@ -2055,13 +2054,13 @@ extern SDL_DECLSPEC int SDLCALL IMG_SaveJPG(SDL_Surface *surface, const char *fi * SDL_FALSE to leave it open. * \param quality [0; 33] is Lowest quality, [34; 66] is Middle quality, [67; * 100] is Highest quality. - * \returns 0 if successful, -1 on error. + * \returns SDL_TRUE on success or SDL_FALSE on failure; call SDL_GetError() for more information. * * \since This function is available since SDL_image 3.0.0. * * \sa IMG_SaveJPG */ -extern SDL_DECLSPEC int SDLCALL IMG_SaveJPG_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio, int quality); +extern SDL_DECLSPEC SDL_bool SDLCALL IMG_SaveJPG_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio, int quality); /** * Animated image support Currently only animated GIFs are supported. @@ -2195,20 +2194,6 @@ extern SDL_DECLSPEC IMG_Animation * SDLCALL IMG_LoadGIFAnimation_IO(SDL_IOStream */ extern SDL_DECLSPEC IMG_Animation * SDLCALL IMG_LoadWEBPAnimation_IO(SDL_IOStream *src); -/** - * Report SDL_image errors - * - * \sa IMG_GetError - */ -#define IMG_SetError SDL_SetError - -/** - * Get last SDL_image error - * - * \sa IMG_SetError - */ -#define IMG_GetError SDL_GetError - /* Ends C function definitions when using C++ */ #ifdef __cplusplus } diff --git a/src/IMG.c b/src/IMG.c index 1be365e8..45793fda 100644 --- a/src/IMG.c +++ b/src/IMG.c @@ -48,7 +48,7 @@ SDL_COMPILE_TIME_ASSERT(SDL_IMAGE_MICRO_VERSION_max, SDL_IMAGE_MICRO_VERSION <= /* Table of image detection and loading functions */ static struct { const char *type; - int (SDLCALL *is)(SDL_IOStream *src); + SDL_bool (SDLCALL *is)(SDL_IOStream *src); SDL_Surface *(SDLCALL *load)(SDL_IOStream *src); } supported[] = { /* keep magicless formats first */ @@ -76,7 +76,7 @@ static struct { /* Table of animation detection and loading functions */ static struct { const char *type; - int (SDLCALL *is)(SDL_IOStream *src); + SDL_bool (SDLCALL *is)(SDL_IOStream *src); IMG_Animation *(SDLCALL *load)(SDL_IOStream *src); } supported_anims[] = { /* keep magicless formats first */ @@ -89,11 +89,11 @@ int IMG_Version(void) return SDL_IMAGE_VERSION; } -static int initialized = 0; +static IMG_InitFlags initialized = 0; -int IMG_Init(int flags) +IMG_InitFlags IMG_Init(IMG_InitFlags flags) { - int result = 0; + IMG_InitFlags result = 0; if (flags & IMG_INIT_AVIF) { if ((initialized & IMG_INIT_AVIF) || IMG_InitAVIF() == 0) { @@ -192,19 +192,6 @@ SDL_Surface *IMG_Load_IO(SDL_IOStream *src, SDL_bool closeio) return IMG_LoadTyped_IO(src, closeio, NULL); } -/* Portable case-insensitive string compare function */ -static int IMG_string_equals(const char *str1, const char *str2) -{ - while ( *str1 && *str2 ) { - if ( SDL_toupper((unsigned char)*str1) != - SDL_toupper((unsigned char)*str2) ) - break; - ++str1; - ++str2; - } - return (!*str1 && !*str2); -} - /* Load an image from an SDL datasource, optionally specifying the type */ SDL_Surface *IMG_LoadTyped_IO(SDL_IOStream *src, SDL_bool closeio, const char *type) { @@ -213,16 +200,16 @@ SDL_Surface *IMG_LoadTyped_IO(SDL_IOStream *src, SDL_bool closeio, const char *t /* Make sure there is something to do.. */ if ( src == NULL ) { - IMG_SetError("Passed a NULL data source"); - return(NULL); + SDL_SetError("Passed a NULL data source"); + return NULL; } /* See whether or not this data source can handle seeking */ if (SDL_SeekIO(src, 0, SDL_IO_SEEK_CUR) < 0 ) { - IMG_SetError("Can't seek in this data source"); + SDL_SetError("Can't seek in this data source"); if (closeio) SDL_CloseIO(src); - return(NULL); + return NULL; } #ifdef __EMSCRIPTEN__ @@ -257,7 +244,7 @@ SDL_Surface *IMG_LoadTyped_IO(SDL_IOStream *src, SDL_bool closeio, const char *t continue; } else { /* magicless format */ - if (!type || !IMG_string_equals(type, supported[i].type)) + if (!type || !SDL_strcasecmp(type, supported[i].type)) continue; } #ifdef DEBUG_IMGLIB @@ -273,7 +260,7 @@ SDL_Surface *IMG_LoadTyped_IO(SDL_IOStream *src, SDL_bool closeio, const char *t if ( closeio ) { SDL_CloseIO(src); } - IMG_SetError("Unsupported image format"); + SDL_SetError("Unsupported image format"); return NULL; } @@ -342,16 +329,16 @@ IMG_Animation *IMG_LoadAnimationTyped_IO(SDL_IOStream *src, SDL_bool closeio, co /* Make sure there is something to do.. */ if ( src == NULL ) { - IMG_SetError("Passed a NULL data source"); - return(NULL); + SDL_SetError("Passed a NULL data source"); + return NULL; } /* See whether or not this data source can handle seeking */ if (SDL_SeekIO(src, 0, SDL_IO_SEEK_CUR) < 0 ) { - IMG_SetError("Can't seek in this data source"); + SDL_SetError("Can't seek in this data source"); if (closeio) SDL_CloseIO(src); - return(NULL); + return NULL; } /* Detect the type of image being loaded */ @@ -361,7 +348,7 @@ IMG_Animation *IMG_LoadAnimationTyped_IO(SDL_IOStream *src, SDL_bool closeio, co continue; } else { /* magicless format */ - if (!type || !IMG_string_equals(type, supported_anims[i].type)) + if (!type || !SDL_strcasecmp(type, supported_anims[i].type)) continue; } #ifdef DEBUG_IMGLIB diff --git a/src/IMG_ImageIO.m b/src/IMG_ImageIO.m index e071d5dd..8c4bd0bc 100644 --- a/src/IMG_ImageIO.m +++ b/src/IMG_ImageIO.m @@ -161,7 +161,7 @@ static CGImageRef CreateCGImageFromCGImageSource(CGImageSourceRef image_source) image_ref = CGImageSourceCreateImageAtIndex(image_source, 0, NULL); if(NULL == image_ref) { - IMG_SetError("CGImageSourceCreateImageAtIndex() failed"); + SDL_SetError("CGImageSourceCreateImageAtIndex() failed"); } return image_ref; } @@ -391,12 +391,13 @@ void IMG_QuitTIF(void) { } -static int Internal_isType (SDL_IOStream *rw_ops, CFStringRef uti_string_to_test) +static SDL_bool Internal_isType (SDL_IOStream *rw_ops, CFStringRef uti_string_to_test) { - int is_type = 0; + SDL_bool is_type = SDL_FALSE; - if (rw_ops == NULL) - return 0; + if (rw_ops == NULL) { + return SDL_FALSE; + } Sint64 start = SDL_TellIO(rw_ops); CFDictionaryRef hint_dictionary = CreateHintDictionary(uti_string_to_test); @@ -421,7 +422,7 @@ static int Internal_isType (SDL_IOStream *rw_ops, CFStringRef uti_string_to_test // CFShow(uti_type); // Unsure if we really want conformance or equality - is_type = (int)UTTypeConformsTo(uti_string_to_test, uti_type); + is_type = UTTypeConformsTo(uti_string_to_test, uti_type); CFRelease(image_source); @@ -432,25 +433,25 @@ static int Internal_isType (SDL_IOStream *rw_ops, CFStringRef uti_string_to_test #ifdef BMP_USES_IMAGEIO -int IMG_isCUR(SDL_IOStream *src) +SDL_bool IMG_isCUR(SDL_IOStream *src) { /* FIXME: Is this a supported type? */ return Internal_isType(src, CFSTR("com.microsoft.cur")); } -int IMG_isICO(SDL_IOStream *src) +SDL_bool IMG_isICO(SDL_IOStream *src) { return Internal_isType(src, kUTTypeICO); } -int IMG_isBMP(SDL_IOStream *src) +SDL_bool IMG_isBMP(SDL_IOStream *src) { return Internal_isType(src, kUTTypeBMP); } #endif /* BMP_USES_IMAGEIO */ -int IMG_isGIF(SDL_IOStream *src) +SDL_bool IMG_isGIF(SDL_IOStream *src) { return Internal_isType(src, kUTTypeGIF); } @@ -458,7 +459,7 @@ int IMG_isGIF(SDL_IOStream *src) #ifdef JPG_USES_IMAGEIO // Note: JPEG 2000 is kUTTypeJPEG2000 -int IMG_isJPG(SDL_IOStream *src) +SDL_bool IMG_isJPG(SDL_IOStream *src) { return Internal_isType(src, kUTTypeJPEG); } @@ -467,7 +468,7 @@ int IMG_isJPG(SDL_IOStream *src) #ifdef PNG_USES_IMAGEIO -int IMG_isPNG(SDL_IOStream *src) +SDL_bool IMG_isPNG(SDL_IOStream *src) { return Internal_isType(src, kUTTypePNG); } @@ -475,12 +476,12 @@ int IMG_isPNG(SDL_IOStream *src) #endif /* PNG_USES_IMAGEIO */ // This isn't a public API function. Apple seems to be able to identify tga's. -int IMG_isTGA(SDL_IOStream *src) +SDL_bool IMG_isTGA(SDL_IOStream *src) { return Internal_isType(src, CFSTR("com.truevision.tga-image")); } -int IMG_isTIF(SDL_IOStream *src) +SDL_bool IMG_isTIF(SDL_IOStream *src) { return Internal_isType(src, kUTTypeTIFF); } diff --git a/src/IMG_WIC.c b/src/IMG_WIC.c index a94bc76a..d00fddcd 100644 --- a/src/IMG_WIC.c +++ b/src/IMG_WIC.c @@ -84,91 +84,88 @@ void IMG_QuitTIF(void) WIC_Quit(); } -int IMG_isPNG(SDL_IOStream *src) +SDL_bool IMG_isPNG(SDL_IOStream *src) { Sint64 start; - int is_PNG; + SDL_bool is_PNG; Uint8 magic[4]; - if ( !src ) { - return 0; + if (!src) { + return SDL_FALSE; } start = SDL_TellIO(src); - is_PNG = 0; + is_PNG = SDL_FALSE; if (SDL_ReadIO(src, magic, sizeof(magic)) == sizeof(magic) ) { if ( magic[0] == 0x89 && magic[1] == 'P' && magic[2] == 'N' && magic[3] == 'G' ) { - is_PNG = 1; + is_PNG = SDL_TRUE; } } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return(is_PNG); + return is_PNG; } -int IMG_isJPG(SDL_IOStream *src) +SDL_bool IMG_isJPG(SDL_IOStream *src) { Sint64 start; - int is_JPG; - int in_scan; + SDL_bool is_JPG; + SDL_bool in_scan; Uint8 magic[4]; /* This detection code is by Steaphan Greene */ /* Blame me, not Sam, if this doesn't work right. */ /* And don't forget to report the problem to the the sdl list too! */ - if (!src) - return 0; + if (!src) { + return SDL_FALSE; + } + start = SDL_TellIO(src); - is_JPG = 0; - in_scan = 0; + is_JPG = SDL_FALSE; + in_scan = SDL_FALSE; if (SDL_ReadIO(src, magic, 2) == 2) { - if ((magic[0] == 0xFF) && (magic[1] == 0xD8)) { - is_JPG = 1; - while (is_JPG == 1) { + if ( (magic[0] == 0xFF) && (magic[1] == 0xD8) ) { + is_JPG = SDL_TRUE; + while (is_JPG) { if (SDL_ReadIO(src, magic, 2) != 2) { - is_JPG = 0; - } - else if ((magic[0] != 0xFF) && (in_scan == 0)) { - is_JPG = 0; - } - else if ((magic[0] != 0xFF) || (magic[1] == 0xFF)) { + is_JPG = SDL_FALSE; + } else if ( (magic[0] != 0xFF) && !in_scan ) { + is_JPG = SDL_FALSE; + } else if ( (magic[0] != 0xFF) || (magic[1] == 0xFF) ) { /* Extra padding in JPEG (legal) */ /* or this is data and we are scanning */ SDL_SeekIO(src, -1, SDL_IO_SEEK_CUR); - } - else if (magic[1] == 0xD9) { + } else if (magic[1] == 0xD9) { /* Got to end of good JPEG */ break; - } - else if ((in_scan == 1) && (magic[1] == 0x00)) { + } else if ( in_scan && (magic[1] == 0x00) ) { /* This is an encoded 0xFF within the data */ - } - else if ((magic[1] >= 0xD0) && (magic[1] < 0xD9)) { + } else if ( (magic[1] >= 0xD0) && (magic[1] < 0xD9) ) { /* These have nothing else */ - } - else if (SDL_ReadIO(src, magic + 2, 2) != 2) { - is_JPG = 0; - } - else { + } else if (SDL_ReadIO(src, magic+2, 2) != 2) { + is_JPG = SDL_FALSE; + } else { /* Yes, it's big-endian */ Sint64 innerStart; Uint32 size; Sint64 end; innerStart = SDL_TellIO(src); size = (magic[2] << 8) + magic[3]; - end = SDL_SeekIO(src, size - 2, SDL_IO_SEEK_CUR); - if (end != innerStart + size - 2) is_JPG = 0; - if (magic[1] == 0xDA) { + end = SDL_SeekIO(src, size-2, SDL_IO_SEEK_CUR); + if ( end != innerStart + size - 2 ) { + is_JPG = SDL_FALSE; + } + if ( magic[1] == 0xDA ) { /* Now comes the actual JPEG meat */ #ifdef FAST_IS_JPEG /* Ok, I'm convinced. It is a JPEG. */ break; #else /* I'm not convinced. Prove it! */ - in_scan = 1; + in_scan = SDL_TRUE; #endif } } @@ -176,33 +173,35 @@ int IMG_isJPG(SDL_IOStream *src) } } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return(is_JPG); + return is_JPG; } -int IMG_isTIF(SDL_IOStream * src) +SDL_bool IMG_isTIF(SDL_IOStream * src) { Sint64 start; - int is_TIF; + SDL_bool is_TIF; Uint8 magic[4]; - if (!src) - return 0; + if (!src) { + return SDL_FALSE; + } + start = SDL_TellIO(src); - is_TIF = 0; - if (SDL_ReadIO(src, magic, sizeof(magic)) == sizeof(magic)) { - if ((magic[0] == 'I' && - magic[1] == 'I' && - magic[2] == 0x2a && - magic[3] == 0x00) || - (magic[0] == 'M' && - magic[1] == 'M' && - magic[2] == 0x00 && - magic[3] == 0x2a)) { - is_TIF = 1; + is_TIF = SDL_FALSE; + if (SDL_ReadIO(src, magic, sizeof(magic)) == sizeof(magic) ) { + if ( (magic[0] == 'I' && + magic[1] == 'I' && + magic[2] == 0x2a && + magic[3] == 0x00) || + (magic[0] == 'M' && + magic[1] == 'M' && + magic[2] == 0x00 && + magic[3] == 0x2a) ) { + is_TIF = SDL_TRUE; } } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return(is_TIF); + return is_TIF; } static SDL_Surface* WIC_LoadImage(SDL_IOStream *src) @@ -216,7 +215,7 @@ static SDL_Surface* WIC_LoadImage(SDL_IOStream *src) UINT width, height; if (wicFactory == NULL && (WIC_Init() < 0)) { - IMG_SetError("WIC failed to initialize!"); + SDL_SetError("WIC failed to initialize!"); return NULL; } diff --git a/src/IMG_avif.c b/src/IMG_avif.c index c61cdd3d..2adb3adb 100644 --- a/src/IMG_avif.c +++ b/src/IMG_avif.c @@ -81,7 +81,7 @@ static struct { #else #define FUNCTION_LOADER(FUNC, SIG) \ lib.FUNC = FUNC; \ - if (lib.FUNC == NULL) { IMG_SetError("Missing avif.framework"); return -1; } + if (lib.FUNC == NULL) { SDL_SetError("Missing avif.framework"); return -1; } #endif #ifdef __APPLE__ @@ -196,15 +196,15 @@ static SDL_bool ReadAVIFHeader(SDL_IOStream *src, Uint8 **header_data, size_t *h } /* See if an image is contained in a data source */ -int IMG_isAVIF(SDL_IOStream *src) +SDL_bool IMG_isAVIF(SDL_IOStream *src) { Sint64 start; - int is_AVIF; + SDL_bool is_AVIF; Uint8 *data; size_t size; if (!src) { - return 0; + return SDL_FALSE; } start = SDL_TellIO(src); @@ -221,7 +221,7 @@ int IMG_isAVIF(SDL_IOStream *src) SDL_free(data); } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return(is_AVIF); + return is_AVIF; } /* Context for AFIF I/O operations */ @@ -374,7 +374,7 @@ SDL_Surface *IMG_LoadAVIF_IO(SDL_IOStream *src) decoder = lib.avifDecoderCreate(); if (!decoder) { - IMG_SetError("Couldn't create AVIF decoder"); + SDL_SetError("Couldn't create AVIF decoder"); goto done; } @@ -390,13 +390,13 @@ SDL_Surface *IMG_LoadAVIF_IO(SDL_IOStream *src) result = lib.avifDecoderParse(decoder); if (result != AVIF_RESULT_OK) { - IMG_SetError("Couldn't parse AVIF image: %s", lib.avifResultToString(result)); + SDL_SetError("Couldn't parse AVIF image: %s", lib.avifResultToString(result)); goto done; } result = lib.avifDecoderNextImage(decoder); if (result != AVIF_RESULT_OK) { - IMG_SetError("Couldn't get AVIF image: %s", lib.avifResultToString(result)); + SDL_SetError("Couldn't get AVIF image: %s", lib.avifResultToString(result)); goto done; } @@ -435,7 +435,7 @@ SDL_Surface *IMG_LoadAVIF_IO(SDL_IOStream *src) } result = lib.avifImageYUVToRGB(image, &rgb); if (result != AVIF_RESULT_OK) { - IMG_SetError("Couldn't convert AVIF image to RGB: %s", lib.avifResultToString(result)); + SDL_SetError("Couldn't convert AVIF image to RGB: %s", lib.avifResultToString(result)); SDL_free(rgb.pixels); goto done; } @@ -503,7 +503,7 @@ SDL_Surface *IMG_LoadAVIF_IO(SDL_IOStream *src) rgb.rowBytes = (uint32_t)surface->pitch; result = lib.avifImageYUVToRGB(image, &rgb); if (result != AVIF_RESULT_OK) { - IMG_SetError("Couldn't convert AVIF image to RGB: %s", lib.avifResultToString(result)); + SDL_SetError("Couldn't convert AVIF image to RGB: %s", lib.avifResultToString(result)); SDL_DestroySurface(surface); surface = NULL; goto done; @@ -520,7 +520,7 @@ SDL_Surface *IMG_LoadAVIF_IO(SDL_IOStream *src) return surface; } -static int IMG_SaveAVIF_IO_libavif(SDL_Surface *surface, SDL_IOStream *dst, int quality) +static SDL_bool IMG_SaveAVIF_IO_libavif(SDL_Surface *surface, SDL_IOStream *dst, int quality) { avifImage *image = NULL; avifRGBImage rgb; @@ -530,10 +530,10 @@ static int IMG_SaveAVIF_IO_libavif(SDL_Surface *surface, SDL_IOStream *dst, int SDL_Colorspace colorspace; Uint16 maxCLL, maxFALL; SDL_PropertiesID props; - int result = -1; + SDL_bool result = SDL_FALSE; if (!IMG_Init(IMG_INIT_AVIF)) { - return -1; + return SDL_FALSE; } /* Get the colorspace and light level properties, if any */ @@ -544,7 +544,7 @@ static int IMG_SaveAVIF_IO_libavif(SDL_Surface *surface, SDL_IOStream *dst, int image = lib.avifImageCreate(surface->w, surface->h, 10, AVIF_PIXEL_FORMAT_YUV444); if (!image) { - IMG_SetError("Couldn't create AVIF YUV image"); + SDL_SetError("Couldn't create AVIF YUV image"); goto done; } image->yuvRange = AVIF_RANGE_FULL; @@ -603,7 +603,7 @@ static int IMG_SaveAVIF_IO_libavif(SDL_Surface *surface, SDL_IOStream *dst, int rc = lib.avifImageRGBToYUV(image, &rgb); if (rc != AVIF_RESULT_OK) { - IMG_SetError("Couldn't convert to YUV: %s", lib.avifResultToString(rc)); + SDL_SetError("Couldn't convert to YUV: %s", lib.avifResultToString(rc)); goto done; } @@ -660,7 +660,7 @@ static int IMG_SaveAVIF_IO_libavif(SDL_Surface *surface, SDL_IOStream *dst, int /* Check the result of the conversion */ if (rc != AVIF_RESULT_OK) { - IMG_SetError("Couldn't convert to YUV: %s", lib.avifResultToString(rc)); + SDL_SetError("Couldn't convert to YUV: %s", lib.avifResultToString(rc)); goto done; } } @@ -672,18 +672,18 @@ static int IMG_SaveAVIF_IO_libavif(SDL_Surface *surface, SDL_IOStream *dst, int rc = lib.avifEncoderAddImage(encoder, image, 1, AVIF_ADD_IMAGE_FLAG_SINGLE); if (rc != AVIF_RESULT_OK) { - IMG_SetError("Failed to add image to avif encoder: %s", lib.avifResultToString(rc)); + SDL_SetError("Failed to add image to avif encoder: %s", lib.avifResultToString(rc)); goto done; } rc = lib.avifEncoderFinish(encoder, &avifOutput); if (rc != AVIF_RESULT_OK) { - IMG_SetError("Failed to finish encoder: %s", lib.avifResultToString(rc)); + SDL_SetError("Failed to finish encoder: %s", lib.avifResultToString(rc)); goto done; } if (SDL_WriteIO(dst, avifOutput.data, avifOutput.size) == avifOutput.size) { - result = 0; + result = SDL_TRUE; } done: @@ -712,8 +712,8 @@ static int IMG_SaveAVIF_IO_libavif(SDL_Surface *surface, SDL_IOStream *dst, int int IMG_InitAVIF(void) { - IMG_SetError("AVIF images are not supported"); - return(-1); + SDL_SetError("AVIF images are not supported"); + return -1; } void IMG_QuitAVIF(void) @@ -721,49 +721,47 @@ void IMG_QuitAVIF(void) } /* See if an image is contained in a data source */ -int IMG_isAVIF(SDL_IOStream *src) +SDL_bool IMG_isAVIF(SDL_IOStream *src) { (void)src; - return(0); + return SDL_FALSE; } /* Load a AVIF type image from an SDL datasource */ SDL_Surface *IMG_LoadAVIF_IO(SDL_IOStream *src) { (void)src; - return(NULL); + return NULL; } #endif /* LOAD_AVIF */ -int IMG_SaveAVIF(SDL_Surface *surface, const char *file, int quality) +SDL_bool IMG_SaveAVIF(SDL_Surface *surface, const char *file, int quality) { SDL_IOStream *dst = SDL_IOFromFile(file, "wb"); if (dst) { return IMG_SaveAVIF_IO(surface, dst, 1, quality); } else { - return -1; + return SDL_FALSE; } } -int IMG_SaveAVIF_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio, int quality) +SDL_bool IMG_SaveAVIF_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio, int quality) { - int result = -1; + SDL_bool result = SDL_FALSE; if (!dst) { - IMG_SetError("Passed NULL dst"); - return -1; + return SDL_SetError("Passed NULL dst"); } #ifdef SDL_IMAGE_SAVE_AVIF - if (result < 0) { + if (!result) { result = IMG_SaveAVIF_IO_libavif(surface, dst, quality); } #else (void) surface; (void) quality; - IMG_SetError("SDL_image built without AVIF save support"); - result = -1; + result = SDL_SetError("SDL_image built without AVIF save support"); #endif if (closeio) { diff --git a/src/IMG_bmp.c b/src/IMG_bmp.c index dbd563c0..2dbb55c0 100644 --- a/src/IMG_bmp.c +++ b/src/IMG_bmp.c @@ -36,29 +36,31 @@ #ifdef LOAD_BMP /* See if an image is contained in a data source */ -int IMG_isBMP(SDL_IOStream *src) +SDL_bool IMG_isBMP(SDL_IOStream *src) { Sint64 start; - int is_BMP; + SDL_bool is_BMP; char magic[2]; - if ( !src ) - return 0; + if (!src) { + return SDL_FALSE; + } + start = SDL_TellIO(src); - is_BMP = 0; + is_BMP = SDL_FALSE; if (SDL_ReadIO(src, magic, sizeof(magic)) == sizeof(magic)) { if (SDL_strncmp(magic, "BM", 2) == 0) { - is_BMP = 1; + is_BMP = SDL_TRUE; } } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return(is_BMP); + return is_BMP; } -static int IMG_isICOCUR(SDL_IOStream *src, int type) +static SDL_bool IMG_isICOCUR(SDL_IOStream *src, int type) { Sint64 start; - int is_ICOCUR; + SDL_bool is_ICOCUR; /* The Win32 ICO file header (14 bytes) */ Uint16 bfReserved; @@ -66,27 +68,28 @@ static int IMG_isICOCUR(SDL_IOStream *src, int type) Uint16 bfCount; if (!src) { - return 0; + return SDL_FALSE; } + start = SDL_TellIO(src); - is_ICOCUR = 0; + is_ICOCUR = SDL_FALSE; if (SDL_ReadU16LE(src, &bfReserved) && SDL_ReadU16LE(src, &bfType) && SDL_ReadU16LE(src, &bfCount) && (bfReserved == 0) && (bfType == type) && (bfCount != 0)) { - is_ICOCUR = 1; + is_ICOCUR = SDL_TRUE; } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return (is_ICOCUR); + return is_ICOCUR; } -int IMG_isICO(SDL_IOStream *src) +SDL_bool IMG_isICO(SDL_IOStream *src) { return IMG_isICOCUR(src, 1); } -int IMG_isCUR(SDL_IOStream *src) +SDL_bool IMG_isCUR(SDL_IOStream *src) { return IMG_isICOCUR(src, 2); } @@ -159,7 +162,7 @@ LoadICOCUR_IO(SDL_IOStream * src, int type, SDL_bool closeio) !SDL_ReadU16LE(src, &bfType) || !SDL_ReadU16LE(src, &bfCount) || (bfReserved != 0) || (bfType != type) || (bfCount == 0)) { - IMG_SetError("File is not a Windows %s file", type == 1 ? "ICO" : "CUR"); + SDL_SetError("File is not a Windows %s file", type == 1 ? "ICO" : "CUR"); goto done; } @@ -238,7 +241,7 @@ LoadICOCUR_IO(SDL_IOStream * src, int type, SDL_bool closeio) goto done; } } else { - IMG_SetError("Unsupported ICO bitmap format"); + SDL_SetError("Unsupported ICO bitmap format"); goto done; } @@ -266,19 +269,19 @@ LoadICOCUR_IO(SDL_IOStream * src, int type, SDL_bool closeio) ExpandBMP = 0; break; default: - IMG_SetError("ICO file with unsupported bit count"); + SDL_SetError("ICO file with unsupported bit count"); goto done; } break; default: - IMG_SetError("Compressed ICO files not supported"); + SDL_SetError("Compressed ICO files not supported"); goto done; } /* sanity check image size, so we don't overflow integers, etc. */ if ((biWidth < 0) || (biWidth > 0xFFFFFF) || (biHeight < 0) || (biHeight > 0xFFFFFF)) { - IMG_SetError("Unsupported or invalid ICO dimensions"); + SDL_SetError("Unsupported or invalid ICO dimensions"); goto done; } @@ -297,7 +300,7 @@ LoadICOCUR_IO(SDL_IOStream * src, int type, SDL_bool closeio) biClrUsed = 1 << biBitCount; } if (biClrUsed > SDL_arraysize(palette)) { - IMG_SetError("Unsupported or incorrect biClrUsed field"); + SDL_SetError("Unsupported or incorrect biClrUsed field"); goto done; } for (i = 0; i < (int) biClrUsed; ++i) { @@ -436,19 +439,19 @@ LoadICOCUR_IO(SDL_IOStream * src, int type, SDL_bool closeio) /* Load a BMP type image from an SDL datasource */ SDL_Surface *IMG_LoadBMP_IO(SDL_IOStream *src) { - return(LoadBMP_IO(src, SDL_FALSE)); + return LoadBMP_IO(src, SDL_FALSE); } /* Load a ICO type image from an SDL datasource */ SDL_Surface *IMG_LoadICO_IO(SDL_IOStream *src) { - return(LoadICOCUR_IO(src, 1, SDL_FALSE)); + return LoadICOCUR_IO(src, 1, SDL_FALSE); } /* Load a CUR type image from an SDL datasource */ SDL_Surface *IMG_LoadCUR_IO(SDL_IOStream *src) { - return(LoadICOCUR_IO(src, 2, SDL_FALSE)); + return LoadICOCUR_IO(src, 2, SDL_FALSE); } #else @@ -458,37 +461,37 @@ SDL_Surface *IMG_LoadCUR_IO(SDL_IOStream *src) #endif /* See if an image is contained in a data source */ -int IMG_isBMP(SDL_IOStream *src) +SDL_bool IMG_isBMP(SDL_IOStream *src) { - return(0); + return SDL_FALSE; } -int IMG_isICO(SDL_IOStream *src) +SDL_bool IMG_isICO(SDL_IOStream *src) { - return(0); + return SDL_FALSE; } -int IMG_isCUR(SDL_IOStream *src) +SDL_bool IMG_isCUR(SDL_IOStream *src) { - return(0); + return SDL_FALSE; } /* Load a BMP type image from an SDL datasource */ SDL_Surface *IMG_LoadBMP_IO(SDL_IOStream *src) { - return(NULL); + return NULL; } /* Load a BMP type image from an SDL datasource */ SDL_Surface *IMG_LoadCUR_IO(SDL_IOStream *src) { - return(NULL); + return NULL; } /* Load a BMP type image from an SDL datasource */ SDL_Surface *IMG_LoadICO_IO(SDL_IOStream *src) { - return(NULL); + return NULL; } #endif /* LOAD_BMP */ diff --git a/src/IMG_gif.c b/src/IMG_gif.c index 45aa69b1..e16bf521 100644 --- a/src/IMG_gif.c +++ b/src/IMG_gif.c @@ -48,7 +48,7 @@ #include #define Image SDL_Surface -#define RWSetMsg IMG_SetError +#define RWSetMsg SDL_SetError #define ImageNewCmap(w, h, s) SDL_CreateSurface(w, h, SDL_PIXELFORMAT_INDEX8) #define ImageSetCmap(s, i, R, G, B) do { \ palette->colors[i].r = R; \ @@ -753,25 +753,27 @@ IMG_Animation *IMG_LoadGIFAnimation_IO(SDL_IOStream *src) #ifdef LOAD_GIF /* See if an image is contained in a data source */ -int IMG_isGIF(SDL_IOStream *src) +SDL_bool IMG_isGIF(SDL_IOStream *src) { Sint64 start; - int is_GIF; + SDL_bool is_GIF; char magic[6]; - if ( !src ) - return 0; + if (!src) { + return SDL_FALSE; + } + start = SDL_TellIO(src); - is_GIF = 0; + is_GIF = SDL_FALSE; if (SDL_ReadIO(src, magic, sizeof(magic)) == sizeof(magic) ) { if ( (SDL_strncmp(magic, "GIF", 3) == 0) && ((SDL_memcmp(magic + 3, "87a", 3) == 0) || (SDL_memcmp(magic + 3, "89a", 3) == 0)) ) { - is_GIF = 1; + is_GIF = SDL_TRUE; } } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return(is_GIF); + return is_GIF; } /* Load a GIF type image from an SDL datasource */ @@ -793,15 +795,15 @@ SDL_Surface *IMG_LoadGIF_IO(SDL_IOStream *src) #endif /* See if an image is contained in a data source */ -int IMG_isGIF(SDL_IOStream *src) +SDL_bool IMG_isGIF(SDL_IOStream *src) { - return(0); + return SDL_FALSE; } /* Load a GIF type image from an SDL datasource */ SDL_Surface *IMG_LoadGIF_IO(SDL_IOStream *src) { - return(NULL); + return NULL; } #endif /* LOAD_GIF */ diff --git a/src/IMG_jpg.c b/src/IMG_jpg.c index 2bda404e..ebca1a29 100644 --- a/src/IMG_jpg.c +++ b/src/IMG_jpg.c @@ -139,43 +139,45 @@ void IMG_QuitJPG(void) } /* See if an image is contained in a data source */ -int IMG_isJPG(SDL_IOStream *src) +SDL_bool IMG_isJPG(SDL_IOStream *src) { Sint64 start; - int is_JPG; - int in_scan; + SDL_bool is_JPG; + SDL_bool in_scan; Uint8 magic[4]; /* This detection code is by Steaphan Greene */ /* Blame me, not Sam, if this doesn't work right. */ /* And don't forget to report the problem to the the sdl list too! */ - if ( !src ) - return 0; + if (!src) { + return SDL_FALSE; + } + start = SDL_TellIO(src); - is_JPG = 0; - in_scan = 0; + is_JPG = SDL_FALSE; + in_scan = SDL_FALSE; if (SDL_ReadIO(src, magic, 2) == 2) { if ( (magic[0] == 0xFF) && (magic[1] == 0xD8) ) { - is_JPG = 1; - while (is_JPG == 1) { - if(SDL_ReadIO(src, magic, 2) != 2) { - is_JPG = 0; - } else if( (magic[0] != 0xFF) && (in_scan == 0) ) { - is_JPG = 0; - } else if( (magic[0] != 0xFF) || (magic[1] == 0xFF) ) { + is_JPG = SDL_TRUE; + while (is_JPG) { + if (SDL_ReadIO(src, magic, 2) != 2) { + is_JPG = SDL_FALSE; + } else if ( (magic[0] != 0xFF) && !in_scan ) { + is_JPG = SDL_FALSE; + } else if ( (magic[0] != 0xFF) || (magic[1] == 0xFF) ) { /* Extra padding in JPEG (legal) */ /* or this is data and we are scanning */ SDL_SeekIO(src, -1, SDL_IO_SEEK_CUR); - } else if(magic[1] == 0xD9) { + } else if (magic[1] == 0xD9) { /* Got to end of good JPEG */ break; - } else if( (in_scan == 1) && (magic[1] == 0x00) ) { + } else if ( in_scan && (magic[1] == 0x00) ) { /* This is an encoded 0xFF within the data */ - } else if( (magic[1] >= 0xD0) && (magic[1] < 0xD9) ) { + } else if ( (magic[1] >= 0xD0) && (magic[1] < 0xD9) ) { /* These have nothing else */ - } else if(SDL_ReadIO(src, magic+2, 2) != 2) { - is_JPG = 0; + } else if (SDL_ReadIO(src, magic+2, 2) != 2) { + is_JPG = SDL_FALSE; } else { /* Yes, it's big-endian */ Sint64 innerStart; @@ -184,7 +186,9 @@ int IMG_isJPG(SDL_IOStream *src) innerStart = SDL_TellIO(src); size = (magic[2] << 8) + magic[3]; end = SDL_SeekIO(src, size-2, SDL_IO_SEEK_CUR); - if ( end != innerStart + size - 2 ) is_JPG = 0; + if ( end != innerStart + size - 2 ) { + is_JPG = SDL_FALSE; + } if ( magic[1] == 0xDA ) { /* Now comes the actual JPEG meat */ #ifdef FAST_IS_JPEG @@ -192,7 +196,7 @@ int IMG_isJPG(SDL_IOStream *src) break; #else /* I'm not convinced. Prove it! */ - in_scan = 1; + in_scan = SDL_TRUE; #endif } } @@ -200,7 +204,7 @@ int IMG_isJPG(SDL_IOStream *src) } } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return(is_JPG); + return is_JPG; } #define INPUT_BUFFER_SIZE 4096 @@ -364,14 +368,14 @@ SDL_Surface *IMG_LoadJPG_IO(SDL_IOStream *src) #ifdef _MSC_VER #pragma warning(disable:4611) /* warning C4611: interaction between '_setjmp' and C++ object destruction is non-portable */ #endif - if(setjmp(jerr.escape)) { + if (setjmp(jerr.escape)) { /* If we get here, libjpeg found an error */ lib.jpeg_destroy_decompress(&cinfo); if ( surface != NULL ) { SDL_DestroySurface(surface); } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - IMG_SetError("JPEG loading error"); + SDL_SetError("JPEG loading error"); return NULL; } @@ -379,7 +383,7 @@ SDL_Surface *IMG_LoadJPG_IO(SDL_IOStream *src) jpeg_SDL_IO_src(&cinfo, src); lib.jpeg_read_header(&cinfo, TRUE); - if(cinfo.num_components == 4) { + if (cinfo.num_components == 4) { /* Set 32-bit Raw output */ cinfo.out_color_space = JCS_CMYK; cinfo.quantize_colors = FALSE; @@ -406,7 +410,7 @@ SDL_Surface *IMG_LoadJPG_IO(SDL_IOStream *src) if ( surface == NULL ) { lib.jpeg_destroy_decompress(&cinfo); SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - IMG_SetError("Out of memory"); + SDL_SetError("Out of memory"); return NULL; } @@ -420,7 +424,7 @@ SDL_Surface *IMG_LoadJPG_IO(SDL_IOStream *src) lib.jpeg_finish_decompress(&cinfo); lib.jpeg_destroy_decompress(&cinfo); - return(surface); + return surface; } #define OUTPUT_BUFFER_SIZE 4096 @@ -485,7 +489,7 @@ struct savejpeg_vars Sint64 original_offset; }; -static int JPEG_SaveJPEG_IO(struct savejpeg_vars *vars, SDL_Surface *jpeg_surface, SDL_IOStream *dst, int quality) +static SDL_bool JPEG_SaveJPEG_IO(struct savejpeg_vars *vars, SDL_Surface *jpeg_surface, SDL_IOStream *dst, int quality) { /* Create a compression structure and load the JPEG header */ vars->cinfo.err = lib.jpeg_std_error(&vars->jerr.errmgr); @@ -493,12 +497,11 @@ static int JPEG_SaveJPEG_IO(struct savejpeg_vars *vars, SDL_Surface *jpeg_surfac vars->jerr.errmgr.output_message = output_no_message; vars->original_offset = SDL_TellIO(dst); - if(setjmp(vars->jerr.escape)) { + if (setjmp(vars->jerr.escape)) { /* If we get here, libjpeg found an error */ lib.jpeg_destroy_compress(&vars->cinfo); SDL_SeekIO(dst, vars->original_offset, SDL_IO_SEEK_SET); - IMG_SetError("Error saving JPEG with libjpeg"); - return -1; + return SDL_SetError("Error saving JPEG with libjpeg"); } lib.jpeg_create_compress(&vars->cinfo); @@ -523,37 +526,37 @@ static int JPEG_SaveJPEG_IO(struct savejpeg_vars *vars, SDL_Surface *jpeg_surfac lib.jpeg_finish_compress(&vars->cinfo); lib.jpeg_destroy_compress(&vars->cinfo); - return 0; + return SDL_TRUE; } -static int IMG_SaveJPG_IO_jpeglib(SDL_Surface *surface, SDL_IOStream *dst, int quality) +static SDL_bool IMG_SaveJPG_IO_jpeglib(SDL_Surface *surface, SDL_IOStream *dst, int quality) { /* The JPEG library reads bytes in R,G,B order, so this is the right * encoding for either endianness */ struct savejpeg_vars vars; static const Uint32 jpg_format = SDL_PIXELFORMAT_RGB24; SDL_Surface* jpeg_surface = surface; - int ret; + SDL_bool result; if (!IMG_Init(IMG_INIT_JPG)) { - return -1; + return SDL_FALSE; } /* Convert surface to format we can save */ if (surface->format != jpg_format) { jpeg_surface = SDL_ConvertSurface(surface, jpg_format); if (!jpeg_surface) { - return -1; + return SDL_FALSE; } } SDL_zero(vars); - ret = JPEG_SaveJPEG_IO(&vars, jpeg_surface, dst, quality); + result = JPEG_SaveJPEG_IO(&vars, jpeg_surface, dst, quality); if (jpeg_surface != surface) { SDL_DestroySurface(jpeg_surface); } - return ret; + return result; } #elif defined(USE_STBIMAGE) @@ -575,43 +578,45 @@ void IMG_QuitJPG(void) /* Define this for quicker (but less perfect) JPEG identification */ #define FAST_IS_JPEG /* See if an image is contained in a data source */ -int IMG_isJPG(SDL_IOStream *src) +SDL_bool IMG_isJPG(SDL_IOStream *src) { Sint64 start; - int is_JPG; - int in_scan; + SDL_bool is_JPG; + SDL_bool in_scan; Uint8 magic[4]; /* This detection code is by Steaphan Greene */ /* Blame me, not Sam, if this doesn't work right. */ /* And don't forget to report the problem to the the sdl list too! */ - if ( !src ) - return 0; + if (!src) { + return SDL_FALSE; + } + start = SDL_TellIO(src); - is_JPG = 0; - in_scan = 0; - if (SDL_ReadIO(src, magic, 2) == 2 ) { + is_JPG = SDL_FALSE; + in_scan = SDL_FALSE; + if (SDL_ReadIO(src, magic, 2) == 2) { if ( (magic[0] == 0xFF) && (magic[1] == 0xD8) ) { - is_JPG = 1; - while (is_JPG == 1) { - if(SDL_ReadIO(src, magic, 2) != 2) { - is_JPG = 0; - } else if( (magic[0] != 0xFF) && (in_scan == 0) ) { - is_JPG = 0; - } else if( (magic[0] != 0xFF) || (magic[1] == 0xFF) ) { + is_JPG = SDL_TRUE; + while (is_JPG) { + if (SDL_ReadIO(src, magic, 2) != 2) { + is_JPG = SDL_FALSE; + } else if ( (magic[0] != 0xFF) && !in_scan ) { + is_JPG = SDL_FALSE; + } else if ( (magic[0] != 0xFF) || (magic[1] == 0xFF) ) { /* Extra padding in JPEG (legal) */ /* or this is data and we are scanning */ SDL_SeekIO(src, -1, SDL_IO_SEEK_CUR); - } else if(magic[1] == 0xD9) { + } else if (magic[1] == 0xD9) { /* Got to end of good JPEG */ break; - } else if( (in_scan == 1) && (magic[1] == 0x00) ) { + } else if ( in_scan && (magic[1] == 0x00) ) { /* This is an encoded 0xFF within the data */ - } else if( (magic[1] >= 0xD0) && (magic[1] < 0xD9) ) { + } else if ( (magic[1] >= 0xD0) && (magic[1] < 0xD9) ) { /* These have nothing else */ - } else if(SDL_ReadIO(src, magic+2, 2) != 2) { - is_JPG = 0; + } else if (SDL_ReadIO(src, magic+2, 2) != 2) { + is_JPG = SDL_FALSE; } else { /* Yes, it's big-endian */ Sint64 innerStart; @@ -620,7 +625,9 @@ int IMG_isJPG(SDL_IOStream *src) innerStart = SDL_TellIO(src); size = (magic[2] << 8) + magic[3]; end = SDL_SeekIO(src, size-2, SDL_IO_SEEK_CUR); - if ( end != innerStart + size - 2 ) is_JPG = 0; + if ( end != innerStart + size - 2 ) { + is_JPG = SDL_FALSE; + } if ( magic[1] == 0xDA ) { /* Now comes the actual JPEG meat */ #ifdef FAST_IS_JPEG @@ -628,7 +635,7 @@ int IMG_isJPG(SDL_IOStream *src) break; #else /* I'm not convinced. Prove it! */ - in_scan = 1; + in_scan = SDL_TRUE; #endif } } @@ -636,7 +643,7 @@ int IMG_isJPG(SDL_IOStream *src) } } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return(is_JPG); + return is_JPG; } /* Load a JPEG type image from an SDL datasource */ @@ -654,8 +661,8 @@ SDL_Surface *IMG_LoadJPG_IO(SDL_IOStream *src) int IMG_InitJPG(void) { - IMG_SetError("JPEG images are not supported"); - return(-1); + SDL_SetError("JPEG images are not supported"); + return -1; } void IMG_QuitJPG(void) @@ -663,17 +670,17 @@ void IMG_QuitJPG(void) } /* See if an image is contained in a data source */ -int IMG_isJPG(SDL_IOStream *src) +SDL_bool IMG_isJPG(SDL_IOStream *src) { (void)src; - return(0); + return SDL_FALSE; } /* Load a JPEG type image from an SDL datasource */ SDL_Surface *IMG_LoadJPG_IO(SDL_IOStream *src) { (void)src; - return(NULL); + return NULL; } #endif /* LOAD_JPG */ @@ -707,19 +714,19 @@ static void IMG_SaveJPG_IO_tinyjpeg_callback(void* context, void* data, int size SDL_WriteIO((SDL_IOStream*) context, data, size); } -static int IMG_SaveJPG_IO_tinyjpeg(SDL_Surface *surface, SDL_IOStream *dst, int quality) +static SDL_bool IMG_SaveJPG_IO_tinyjpeg(SDL_Surface *surface, SDL_IOStream *dst, int quality) { /* The JPEG library reads bytes in R,G,B order, so this is the right * encoding for either endianness */ static const Uint32 jpg_format = SDL_PIXELFORMAT_RGB24; SDL_Surface* jpeg_surface = surface; - int result = -1; + SDL_bool result = SDL_FALSE; /* Convert surface to format we can save */ if (surface->format != jpg_format) { jpeg_surface = SDL_ConvertSurface(surface, jpg_format); if (!jpeg_surface) { - return -1; + return SDL_FALSE; } } @@ -741,13 +748,13 @@ static int IMG_SaveJPG_IO_tinyjpeg(SDL_Surface *surface, SDL_IOStream *dst, int 3, jpeg_surface->pixels, jpeg_surface->pitch - ) - 1; /* tinyjpeg returns 0 on error, 1 on success */ + ); if (jpeg_surface != surface) { SDL_DestroySurface(jpeg_surface); } - if (result < 0) { + if (!result) { SDL_SetError("tinyjpeg error"); } return result; @@ -755,43 +762,41 @@ static int IMG_SaveJPG_IO_tinyjpeg(SDL_Surface *surface, SDL_IOStream *dst, int #endif /* SDL_IMAGE_SAVE_JPG && (defined(LOAD_JPG_DYNAMIC) || !defined(WANT_JPEGLIB)) */ -int IMG_SaveJPG(SDL_Surface *surface, const char *file, int quality) +SDL_bool IMG_SaveJPG(SDL_Surface *surface, const char *file, int quality) { SDL_IOStream *dst = SDL_IOFromFile(file, "wb"); if (dst) { return IMG_SaveJPG_IO(surface, dst, 1, quality); } else { - return -1; + return SDL_FALSE; } } -int IMG_SaveJPG_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio, int quality) +SDL_bool IMG_SaveJPG_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio, int quality) { - int result = -1; + SDL_bool result = SDL_FALSE; (void)surface; (void)quality; if (!dst) { - IMG_SetError("Passed NULL dst"); - return -1; + return SDL_SetError("Passed NULL dst"); } #if SDL_IMAGE_SAVE_JPG #ifdef USE_JPEGLIB - if (result < 0) { + if (!result) { result = IMG_SaveJPG_IO_jpeglib(surface, dst, quality); } #endif #if defined(LOAD_JPG_DYNAMIC) || !defined(WANT_JPEGLIB) - if (result < 0) { + if (!result) { result = IMG_SaveJPG_IO_tinyjpeg(surface, dst, quality); } #endif #else - IMG_SetError("SDL_image built without JPEG save support"); - result = -1; + result = SDL_SetError("SDL_image built without JPEG save support"); #endif if (closeio) { diff --git a/src/IMG_jxl.c b/src/IMG_jxl.c index b9ef7170..fb9425ad 100644 --- a/src/IMG_jxl.c +++ b/src/IMG_jxl.c @@ -49,7 +49,7 @@ static struct { #else #define FUNCTION_LOADER(FUNC, SIG) \ lib.FUNC = FUNC; \ - if (lib.FUNC == NULL) { IMG_SetError("Missing jxl.framework"); return -1; } + if (lib.FUNC == NULL) { SDL_SetError("Missing jxl.framework"); return -1; } #endif #ifdef __APPLE__ @@ -92,21 +92,22 @@ void IMG_QuitJXL(void) } /* See if an image is contained in a data source */ -int IMG_isJXL(SDL_IOStream *src) +SDL_bool IMG_isJXL(SDL_IOStream *src) { Sint64 start; - int is_JXL; + SDL_bool is_JXL; Uint8 magic[12]; if (!src) { - return 0; + return SDL_FALSE; } + start = SDL_TellIO(src); - is_JXL = 0; + is_JXL = SDL_FALSE; if (SDL_ReadIO(src, magic, 2) == 2 ) { if ( magic[0] == 0xFF && magic[1] == 0x0A ) { /* This is a JXL codestream */ - is_JXL = 1; + is_JXL = SDL_TRUE; } else { if (SDL_ReadIO(src, &magic[2], sizeof(magic) - 2) == (sizeof(magic) - 2) ) { if ( magic[0] == 0x00 && magic[1] == 0x00 && @@ -116,13 +117,13 @@ int IMG_isJXL(SDL_IOStream *src) magic[8] == 0x0D && magic[9] == 0x0A && magic[10] == 0x87 && magic[11] == 0x0A ) { /* This is a JXL container */ - is_JXL = 1; + is_JXL = SDL_TRUE; } } } } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return(is_JXL); + return is_JXL; } /* Load a JXL type image from an SDL datasource */ @@ -156,17 +157,17 @@ SDL_Surface *IMG_LoadJXL_IO(SDL_IOStream *src) decoder = lib.JxlDecoderCreate(NULL); if (!decoder) { - IMG_SetError("Couldn't create JXL decoder"); + SDL_SetError("Couldn't create JXL decoder"); goto done; } if (lib.JxlDecoderSubscribeEvents(decoder, JXL_DEC_BASIC_INFO | JXL_DEC_FULL_IMAGE) != JXL_DEC_SUCCESS) { - IMG_SetError("Couldn't subscribe to JXL events"); + SDL_SetError("Couldn't subscribe to JXL events"); goto done; } if (lib.JxlDecoderSetInput(decoder, data, datasize) != JXL_DEC_SUCCESS) { - IMG_SetError("Couldn't set JXL input"); + SDL_SetError("Couldn't set JXL input"); goto done; } @@ -177,24 +178,24 @@ SDL_Surface *IMG_LoadJXL_IO(SDL_IOStream *src) switch (status) { case JXL_DEC_ERROR: - IMG_SetError("JXL decoder error"); + SDL_SetError("JXL decoder error"); goto done; case JXL_DEC_NEED_MORE_INPUT: - IMG_SetError("Incomplete JXL image"); + SDL_SetError("Incomplete JXL image"); goto done; case JXL_DEC_BASIC_INFO: if (lib.JxlDecoderGetBasicInfo(decoder, &info) != JXL_DEC_SUCCESS) { - IMG_SetError("Couldn't get JXL image info"); + SDL_SetError("Couldn't get JXL image info"); goto done; } break; case JXL_DEC_NEED_IMAGE_OUT_BUFFER: if (lib.JxlDecoderImageOutBufferSize(decoder, &format, &outputsize) != JXL_DEC_SUCCESS) { - IMG_SetError("Couldn't get JXL image size"); + SDL_SetError("Couldn't get JXL image size"); goto done; } if (info.xsize == 0 || info.ysize == 0) { - IMG_SetError("Couldn't get pixels for %dx%d JXL image", info.xsize, info.ysize); + SDL_SetError("Couldn't get pixels for %dx%d JXL image", info.xsize, info.ysize); goto done; } if (pixels) { @@ -210,7 +211,7 @@ SDL_Surface *IMG_LoadJXL_IO(SDL_IOStream *src) } pitch = (int)(outputsize / info.ysize); if (lib.JxlDecoderSetImageOutBuffer(decoder, &format, pixels, outputsize) != JXL_DEC_SUCCESS) { - IMG_SetError("Couldn't set JXL output buffer"); + SDL_SetError("Couldn't set JXL output buffer"); goto done; } break; @@ -227,7 +228,7 @@ SDL_Surface *IMG_LoadJXL_IO(SDL_IOStream *src) } goto done; default: - IMG_SetError("Unknown JXL decoding status: %d", status); + SDL_SetError("Unknown JXL decoding status: %d", status); goto done; } } @@ -255,8 +256,8 @@ SDL_Surface *IMG_LoadJXL_IO(SDL_IOStream *src) int IMG_InitJXL(void) { - IMG_SetError("JXL images are not supported"); - return(-1); + SDL_SetError("JXL images are not supported"); + return -1; } void IMG_QuitJXL(void) @@ -264,17 +265,17 @@ void IMG_QuitJXL(void) } /* See if an image is contained in a data source */ -int IMG_isJXL(SDL_IOStream *src) +SDL_bool IMG_isJXL(SDL_IOStream *src) { (void)src; - return(0); + return SDL_FALSE; } /* Load a JXL type image from an SDL datasource */ SDL_Surface *IMG_LoadJXL_IO(SDL_IOStream *src) { (void)src; - return(NULL); + return NULL; } #endif /* LOAD_JXL */ diff --git a/src/IMG_lbm.c b/src/IMG_lbm.c index 14269c82..44418201 100644 --- a/src/IMG_lbm.c +++ b/src/IMG_lbm.c @@ -56,27 +56,29 @@ typedef struct Sint16 Hpage; /* height of the screen in pixels */ } BMHD; -int IMG_isLBM(SDL_IOStream *src ) +SDL_bool IMG_isLBM(SDL_IOStream *src ) { Sint64 start; - int is_LBM; + SDL_bool is_LBM; Uint8 magic[4+4+4]; - if ( !src ) - return 0; + if (!src) { + return SDL_FALSE; + } + start = SDL_TellIO(src); - is_LBM = 0; + is_LBM = SDL_FALSE; if (SDL_ReadIO( src, magic, sizeof(magic) ) == sizeof(magic) ) { if ( !SDL_memcmp( magic, "FORM", 4 ) && ( !SDL_memcmp( magic + 8, "PBM ", 4 ) || !SDL_memcmp( magic + 8, "ILBM", 4 ) ) ) { - is_LBM = 1; + is_LBM = SDL_TRUE; } } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return( is_LBM ); + return is_LBM; } SDL_Surface *IMG_LoadLBM_IO(SDL_IOStream *src ) @@ -495,10 +497,10 @@ SDL_Surface *IMG_LoadLBM_IO(SDL_IOStream *src ) SDL_DestroySurface( Image ); Image = NULL; } - IMG_SetError( "%s", error ); + SDL_SetError( "%s", error ); } - return( Image ); + return Image; } #else /* LOAD_LBM */ @@ -507,15 +509,15 @@ SDL_Surface *IMG_LoadLBM_IO(SDL_IOStream *src ) #endif /* See if an image is contained in a data source */ -int IMG_isLBM(SDL_IOStream *src) +SDL_bool IMG_isLBM(SDL_IOStream *src) { - return(0); + return SDL_FALSE; } /* Load an IFF type image from an SDL datasource */ SDL_Surface *IMG_LoadLBM_IO(SDL_IOStream *src) { - return(NULL); + return NULL; } #endif /* LOAD_LBM */ diff --git a/src/IMG_pcx.c b/src/IMG_pcx.c index b262042b..21d69220 100644 --- a/src/IMG_pcx.c +++ b/src/IMG_pcx.c @@ -58,30 +58,32 @@ struct PCXheader { }; /* See if an image is contained in a data source */ -int IMG_isPCX(SDL_IOStream *src) +SDL_bool IMG_isPCX(SDL_IOStream *src) { Sint64 start; - int is_PCX; + SDL_bool is_PCX; const int ZSoft_Manufacturer = 10; const int PC_Paintbrush_Version = 5; const int PCX_Uncompressed_Encoding = 0; const int PCX_RunLength_Encoding = 1; struct PCXheader pcxh; - if ( !src ) - return 0; + if (!src) { + return SDL_FALSE; + } + start = SDL_TellIO(src); - is_PCX = 0; + is_PCX = SDL_FALSE; if (SDL_ReadIO(src, &pcxh, sizeof(pcxh)) == sizeof(pcxh) ) { if ( (pcxh.Manufacturer == ZSoft_Manufacturer) && (pcxh.Version == PC_Paintbrush_Version) && (pcxh.Encoding == PCX_RunLength_Encoding || pcxh.Encoding == PCX_Uncompressed_Encoding) ) { - is_PCX = 1; + is_PCX = SDL_TRUE; } } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return(is_PCX); + return is_PCX; } /* Load a PCX type image from an SDL datasource */ @@ -286,9 +288,9 @@ SDL_Surface *IMG_LoadPCX_IO(SDL_IOStream *src) SDL_DestroySurface(surface); surface = NULL; } - IMG_SetError("%s", error); + SDL_SetError("%s", error); } - return(surface); + return surface; } #else @@ -297,15 +299,15 @@ SDL_Surface *IMG_LoadPCX_IO(SDL_IOStream *src) #endif /* See if an image is contained in a data source */ -int IMG_isPCX(SDL_IOStream *src) +SDL_bool IMG_isPCX(SDL_IOStream *src) { - return(0); + return SDL_FALSE; } /* Load a PCX type image from an SDL datasource */ SDL_Surface *IMG_LoadPCX_IO(SDL_IOStream *src) { - return(NULL); + return NULL; } #endif /* LOAD_PCX */ diff --git a/src/IMG_png.c b/src/IMG_png.c index a291a4ba..37545d2d 100644 --- a/src/IMG_png.c +++ b/src/IMG_png.c @@ -201,28 +201,28 @@ void IMG_QuitPNG(void) } /* See if an image is contained in a data source */ -int IMG_isPNG(SDL_IOStream *src) +SDL_bool IMG_isPNG(SDL_IOStream *src) { Sint64 start; - int is_PNG; + SDL_bool is_PNG; Uint8 magic[4]; - if ( !src ) { - return 0; + if (!src) { + return SDL_FALSE; } start = SDL_TellIO(src); - is_PNG = 0; + is_PNG = SDL_FALSE; if (SDL_ReadIO(src, magic, sizeof(magic)) == sizeof(magic) ) { if ( magic[0] == 0x89 && magic[1] == 'P' && magic[2] == 'N' && magic[3] == 'G' ) { - is_PNG = 1; + is_PNG = SDL_TRUE; } } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return(is_PNG); + return is_PNG; } /* Load a PNG type image from an SDL datasource */ @@ -493,7 +493,7 @@ SDL_Surface *IMG_LoadPNG_IO(SDL_IOStream *src) SDL_DestroySurface(vars.surface); vars.surface = NULL; } - IMG_SetError("%s", vars.error); + SDL_SetError("%s", vars.error); } return vars.surface; @@ -516,28 +516,28 @@ void IMG_QuitPNG(void) /* FIXME: This is a copypaste from LIBPNG! Pull that out of the ifdefs */ /* See if an image is contained in a data source */ -int IMG_isPNG(SDL_IOStream *src) +SDL_bool IMG_isPNG(SDL_IOStream *src) { Sint64 start; - int is_PNG; + SDL_bool is_PNG; Uint8 magic[4]; - if ( !src ) { - return 0; + if (!src) { + return SDL_FALSE; } start = SDL_TellIO(src); - is_PNG = 0; + is_PNG = SDL_FALSE; if (SDL_ReadIO(src, magic, sizeof(magic)) == sizeof(magic) ) { if ( magic[0] == 0x89 && magic[1] == 'P' && magic[2] == 'N' && magic[3] == 'G' ) { - is_PNG = 1; + is_PNG = SDL_TRUE; } } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return(is_PNG); + return is_PNG; } /* Load a PNG type image from an SDL datasource */ @@ -555,8 +555,8 @@ SDL_Surface *IMG_LoadPNG_IO(SDL_IOStream *src) int IMG_InitPNG(void) { - IMG_SetError("PNG images are not supported"); - return(-1); + SDL_SetError("PNG images are not supported"); + return -1; } void IMG_QuitPNG(void) @@ -564,15 +564,15 @@ void IMG_QuitPNG(void) } /* See if an image is contained in a data source */ -int IMG_isPNG(SDL_IOStream *src) +SDL_bool IMG_isPNG(SDL_IOStream *src) { - return(0); + return SDL_FALSE; } /* Load a PNG type image from an SDL datasource */ SDL_Surface *IMG_LoadPNG_IO(SDL_IOStream *src) { - return(NULL); + return NULL; } #endif /* LOAD_PNG */ @@ -603,7 +603,7 @@ struct savepng_vars { SDL_Surface *source; }; -static int LIBPNG_SavePNG_IO(struct savepng_vars *vars, SDL_Surface *surface, SDL_IOStream *dst) +static SDL_bool LIBPNG_SavePNG_IO(struct savepng_vars *vars, SDL_Surface *surface, SDL_IOStream *dst) { Uint8 transparent_table[256]; SDL_Palette *palette; @@ -613,14 +613,14 @@ static int LIBPNG_SavePNG_IO(struct savepng_vars *vars, SDL_Surface *surface, SD vars->png_ptr = lib.png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); if (vars->png_ptr == NULL) { - IMG_SetError("Couldn't allocate memory for PNG file or incompatible PNG dll"); - return -1; + vars->error = "Couldn't allocate memory for PNG file or incompatible PNG dll"; + return SDL_FALSE; } vars->info_ptr = lib.png_create_info_struct(vars->png_ptr); if (vars->info_ptr == NULL) { vars->error = "Couldn't create image information for PNG file"; - return -1; + return SDL_FALSE; } #ifdef PNG_SETJMP_SUPPORTED #ifndef LIBPNG_VERSION_12 @@ -631,7 +631,7 @@ static int LIBPNG_SavePNG_IO(struct savepng_vars *vars, SDL_Surface *surface, SD #endif { vars->error = "Error writing the PNG file."; - return -1; + return SDL_FALSE; } palette = SDL_GetSurfacePalette(surface); @@ -643,7 +643,7 @@ static int LIBPNG_SavePNG_IO(struct savepng_vars *vars, SDL_Surface *surface, SD vars->color_ptr = (png_colorp)SDL_malloc(sizeof(png_color) * ncolors); if (vars->color_ptr == NULL) { vars->error = "Couldn't create palette for PNG file"; - return -1; + return SDL_FALSE; } for (i = 0; i < ncolors; i++) { vars->color_ptr[i].red = palette->colors[i].r; @@ -693,7 +693,7 @@ static int LIBPNG_SavePNG_IO(struct savepng_vars *vars, SDL_Surface *surface, SD vars->row_pointers = (png_bytep *) SDL_malloc(sizeof(png_bytep) * vars->source->h); if (!vars->row_pointers) { vars->error = "Out of memory"; - return -1; + return SDL_FALSE; } for (row = 0; row < (int)vars->source->h; row++) { vars->row_pointers[row] = (png_bytep) (Uint8 *) vars->source->pixels + row * vars->source->pitch; @@ -703,20 +703,20 @@ static int LIBPNG_SavePNG_IO(struct savepng_vars *vars, SDL_Surface *surface, SD lib.png_write_png(vars->png_ptr, vars->info_ptr, PNG_TRANSFORM_IDENTITY, NULL); } - return 0; + return SDL_TRUE; } -static int IMG_SavePNG_IO_libpng(SDL_Surface *surface, SDL_IOStream *dst) +static SDL_bool IMG_SavePNG_IO_libpng(SDL_Surface *surface, SDL_IOStream *dst) { struct savepng_vars vars; - int ret; + SDL_bool result; if (!IMG_Init(IMG_INIT_PNG)) { - return -1; + return SDL_FALSE; } SDL_zero(vars); - ret = LIBPNG_SavePNG_IO(&vars, surface, dst); + result = LIBPNG_SavePNG_IO(&vars, surface, dst); if (vars.png_ptr) { lib.png_destroy_write_struct(&vars.png_ptr, &vars.info_ptr); @@ -735,10 +735,10 @@ static int IMG_SavePNG_IO_libpng(SDL_Surface *surface, SDL_IOStream *dst) } if (vars.error) { - IMG_SetError("%s", vars.error); + SDL_SetError("%s", vars.error); } - return ret; + return result; } #endif /* USE_LIBPNG */ @@ -762,15 +762,14 @@ static int IMG_SavePNG_IO_libpng(SDL_Surface *surface, SDL_IOStream *dst) #define MINIZ_SDL_NOUNUSED #include "miniz.h" -static int IMG_SavePNG_IO_miniz(SDL_Surface *surface, SDL_IOStream *dst) +static SDL_bool IMG_SavePNG_IO_miniz(SDL_Surface *surface, SDL_IOStream *dst) { size_t size = 0; void *png = NULL; - int result = -1; + SDL_bool result = SDL_FALSE; if (!dst) { - IMG_SetError("Passed NULL dst"); - return -1; + return SDL_SetError("Passed NULL dst"); } if (surface->format == png_format) { @@ -784,12 +783,11 @@ static int IMG_SavePNG_IO_miniz(SDL_Surface *surface, SDL_IOStream *dst) } if (png) { if (SDL_WriteIO(dst, png, size)) { - result = 0; + result = SDL_TRUE; } mz_free(png); /* calls SDL_free() */ } else { - IMG_SetError("Failed to convert and save image"); - return -1; + return SDL_SetError("Failed to convert and save image"); } return result; } @@ -797,41 +795,39 @@ static int IMG_SavePNG_IO_miniz(SDL_Surface *surface, SDL_IOStream *dst) #endif /* SDL_IMAGE_SAVE_PNG */ -int IMG_SavePNG(SDL_Surface *surface, const char *file) +SDL_bool IMG_SavePNG(SDL_Surface *surface, const char *file) { SDL_IOStream *dst = SDL_IOFromFile(file, "wb"); if (dst) { return IMG_SavePNG_IO(surface, dst, 1); } else { - return -1; + return SDL_FALSE; } } -int IMG_SavePNG_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio) +SDL_bool IMG_SavePNG_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio) { - int result = -1; + SDL_bool result = SDL_FALSE; if (!dst) { - IMG_SetError("Passed NULL dst"); - return -1; + return SDL_SetError("Passed NULL dst"); } #if SDL_IMAGE_SAVE_PNG #ifdef USE_LIBPNG - if (result < 0) { + if (!result) { result = IMG_SavePNG_IO_libpng(surface, dst); } #endif #if defined(LOAD_PNG_DYNAMIC) || !defined(WANT_LIBPNG) - if (result < 0) { + if (!result) { result = IMG_SavePNG_IO_miniz(surface, dst); } #endif #else - IMG_SetError("SDL_image built without PNG save support"); - result = -1; + result = SDL_SetError("SDL_image built without PNG save support"); #endif if (closeio) { diff --git a/src/IMG_pnm.c b/src/IMG_pnm.c index 48d17515..d40076e2 100644 --- a/src/IMG_pnm.c +++ b/src/IMG_pnm.c @@ -33,16 +33,18 @@ #ifdef LOAD_PNM /* See if an image is contained in a data source */ -int IMG_isPNM(SDL_IOStream *src) +SDL_bool IMG_isPNM(SDL_IOStream *src) { Sint64 start; - int is_PNM; + SDL_bool is_PNM; char magic[2]; - if ( !src ) - return 0; + if (!src) { + return SDL_FALSE; + } + start = SDL_TellIO(src); - is_PNM = 0; + is_PNM = SDL_FALSE; if (SDL_ReadIO(src, magic, sizeof(magic)) == sizeof(magic) ) { /* * PNM magic signatures: @@ -55,11 +57,11 @@ int IMG_isPNM(SDL_IOStream *src) * P7 PAM, a general wrapper for PNM data */ if ( magic[0] == 'P' && magic[1] >= '1' && magic[1] <= '6' ) { - is_PNM = 1; + is_PNM = SDL_TRUE; } } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return(is_PNM); + return is_PNM; } /* read a non-negative integer from the source. return -1 upon error */ @@ -74,7 +76,7 @@ static int ReadNumber(SDL_IOStream *src) /* Skip leading whitespace */ do { if (SDL_ReadIO(src, &ch, 1) != 1 ) { - return(-1); + return -1; } /* Eat comments as whitespace */ if ( ch == '#' ) { /* Comment is '#' to end of line */ @@ -103,7 +105,7 @@ static int ReadNumber(SDL_IOStream *src) } } while ( SDL_isdigit(ch) ); - return(number); + return number; } SDL_Surface *IMG_LoadPNM_IO(SDL_IOStream *src) @@ -246,9 +248,9 @@ SDL_Surface *IMG_LoadPNM_IO(SDL_IOStream *src) SDL_DestroySurface(surface); surface = NULL; } - IMG_SetError("%s", error); + SDL_SetError("%s", error); } - return(surface); + return surface; } #else @@ -257,15 +259,15 @@ SDL_Surface *IMG_LoadPNM_IO(SDL_IOStream *src) #endif /* See if an image is contained in a data source */ -int IMG_isPNM(SDL_IOStream *src) +SDL_bool IMG_isPNM(SDL_IOStream *src) { - return(0); + return SDL_FALSE; } /* Load a PNM type image from an SDL datasource */ SDL_Surface *IMG_LoadPNM_IO(SDL_IOStream *src) { - return(NULL); + return NULL; } #endif /* LOAD_PNM */ diff --git a/src/IMG_qoi.c b/src/IMG_qoi.c index ef1c07d1..8fa9e06a 100644 --- a/src/IMG_qoi.c +++ b/src/IMG_qoi.c @@ -43,23 +43,25 @@ #include "qoi.h" /* See if an image is contained in a data source */ -int IMG_isQOI(SDL_IOStream *src) +SDL_bool IMG_isQOI(SDL_IOStream *src) { Sint64 start; - int is_QOI; + SDL_bool is_QOI; char magic[4]; - if ( !src ) - return 0; + if (!src) { + return SDL_FALSE; + } + start = SDL_TellIO(src); - is_QOI = 0; + is_QOI = SDL_FALSE; if (SDL_ReadIO(src, magic, sizeof(magic)) == sizeof(magic) ) { if ( SDL_strncmp(magic, "qoif", 4) == 0 ) { - is_QOI = 1; + is_QOI = SDL_TRUE; } } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return(is_QOI); + return is_QOI; } /* Load a QOI type image from an SDL datasource */ @@ -77,7 +79,7 @@ SDL_Surface *IMG_LoadQOI_IO(SDL_IOStream *src) } if ( size > INT_MAX ) { SDL_free(data); - IMG_SetError("QOI image is too big."); + SDL_SetError("QOI image is too big."); return NULL; } @@ -85,7 +87,7 @@ SDL_Surface *IMG_LoadQOI_IO(SDL_IOStream *src) /* pixel_data is in R,G,B,A order regardless of endianness */ SDL_free(data); if ( !pixel_data ) { - IMG_SetError("Couldn't parse QOI image"); + SDL_SetError("Couldn't parse QOI image"); return NULL; } @@ -96,7 +98,7 @@ SDL_Surface *IMG_LoadQOI_IO(SDL_IOStream *src) (image_info.width * 4)); if ( !surface ) { QOI_FREE(pixel_data); - IMG_SetError("Couldn't create SDL_Surface"); + SDL_SetError("Couldn't create SDL_Surface"); return NULL; } @@ -112,15 +114,15 @@ SDL_Surface *IMG_LoadQOI_IO(SDL_IOStream *src) #endif /* See if an image is contained in a data source */ -int IMG_isQOI(SDL_IOStream *src) +SDL_bool IMG_isQOI(SDL_IOStream *src) { - return(0); + return SDL_FALSE; } /* Load a QOI type image from an SDL datasource */ SDL_Surface *IMG_LoadQOI_IO(SDL_IOStream *src) { - return(NULL); + return NULL; } #endif /* LOAD_QOI */ diff --git a/src/IMG_stb.c b/src/IMG_stb.c index 34231527..8a1ea45a 100644 --- a/src/IMG_stb.c +++ b/src/IMG_stb.c @@ -71,7 +71,7 @@ static void IMG_LoadSTB_IO_skip(void *user, int n) static int IMG_LoadSTB_IO_eof(void *user) { SDL_IOStream *src = (SDL_IOStream*)user; - return (SDL_GetIOStatus(src) == SDL_IO_STATUS_EOF); + return SDL_GetIOStatus(src) == SDL_IO_STATUS_EOF; } SDL_Surface *IMG_LoadSTB_IO(SDL_IOStream *src) @@ -241,7 +241,7 @@ SDL_Surface *IMG_LoadSTB_IO(SDL_IOStream *src) stbi_image_free(pixels); } } else { - IMG_SetError("Unknown image format: %d", format); + SDL_SetError("Unknown image format: %d", format); } if (!surface) { diff --git a/src/IMG_svg.c b/src/IMG_svg.c index 535bb47e..0fb08e93 100644 --- a/src/IMG_svg.c +++ b/src/IMG_svg.c @@ -85,26 +85,28 @@ static float SDLCALL SDL_roundf(float x) #include "nanosvgrast.h" /* See if an image is contained in a data source */ -int IMG_isSVG(SDL_IOStream *src) +SDL_bool IMG_isSVG(SDL_IOStream *src) { Sint64 start; - int is_SVG; + SDL_bool is_SVG; char magic[4096]; size_t magic_len; - if (!src) - return 0; + if (!src) { + return SDL_FALSE; + } + start = SDL_TellIO(src); - is_SVG = 0; + is_SVG = SDL_FALSE; magic_len = SDL_ReadIO(src, magic, sizeof(magic) - 1); if (magic_len > 0) { magic[magic_len] = '\0'; if (SDL_strstr(magic, "width <= 0.0f || image->height <= 0.0f) { - IMG_SetError("Couldn't parse SVG image"); + SDL_SetError("Couldn't parse SVG image"); return NULL; } rasterizer = nsvgCreateRasterizer(); if (!rasterizer) { - IMG_SetError("Couldn't create SVG rasterizer"); + SDL_SetError("Couldn't create SVG rasterizer"); nsvgDelete(image); return NULL; } @@ -172,15 +174,15 @@ SDL_Surface *IMG_LoadSizedSVG_IO(SDL_IOStream *src, int width, int height) #endif /* See if an image is contained in a data source */ -int IMG_isSVG(SDL_IOStream *src) +SDL_bool IMG_isSVG(SDL_IOStream *src) { - return(0); + return SDL_FALSE; } /* Load a SVG type image from an SDL datasource */ SDL_Surface *IMG_LoadSizedSVG_IO(SDL_IOStream *src, int width, int height) { - return(NULL); + return NULL; } #endif /* LOAD_SVG */ diff --git a/src/IMG_tga.c b/src/IMG_tga.c index cf37e6ca..9eeba224 100644 --- a/src/IMG_tga.c +++ b/src/IMG_tga.c @@ -332,7 +332,7 @@ SDL_Surface *IMG_LoadTGA_IO(SDL_IOStream *src) if ( img ) { SDL_DestroySurface(img); } - IMG_SetError("%s", error); + SDL_SetError("%s", error); return NULL; } diff --git a/src/IMG_tif.c b/src/IMG_tif.c index ccd6a525..4b6dbed9 100644 --- a/src/IMG_tif.c +++ b/src/IMG_tif.c @@ -139,16 +139,18 @@ static toff_t tiff_size(thandle_t fd) return size; } -int IMG_isTIF(SDL_IOStream * src) +SDL_bool IMG_isTIF(SDL_IOStream * src) { Sint64 start; - int is_TIF; + SDL_bool is_TIF; Uint8 magic[4]; - if ( !src ) - return 0; + if (!src) { + return SDL_FALSE; + } + start = SDL_TellIO(src); - is_TIF = 0; + is_TIF = SDL_FALSE; if (SDL_ReadIO(src, magic, sizeof(magic)) == sizeof(magic) ) { if ( (magic[0] == 'I' && magic[1] == 'I' && @@ -158,11 +160,11 @@ int IMG_isTIF(SDL_IOStream * src) magic[1] == 'M' && magic[2] == 0x00 && magic[3] == 0x2a) ) { - is_TIF = 1; + is_TIF = SDL_TRUE; } } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return(is_TIF); + return is_TIF; } SDL_Surface* IMG_LoadTIF_IO(SDL_IOStream * src) @@ -221,8 +223,8 @@ SDL_Surface* IMG_LoadTIF_IO(SDL_IOStream * src) int IMG_InitTIF(void) { - IMG_SetError("TIFF images are not supported"); - return(-1); + SDL_SetError("TIFF images are not supported"); + return -1; } void IMG_QuitTIF(void) @@ -230,11 +232,11 @@ void IMG_QuitTIF(void) } /* See if an image is contained in a data source */ -int IMG_isTIF(SDL_IOStream *src) +SDL_bool IMG_isTIF(SDL_IOStream *src) { (void)src; - return(0); + return SDL_FALSE; } /* Load a TIFF type image from an SDL datasource */ @@ -242,7 +244,7 @@ SDL_Surface *IMG_LoadTIF_IO(SDL_IOStream *src) { (void)src; - return(NULL); + return NULL; } #endif /* LOAD_TIF */ diff --git a/src/IMG_webp.c b/src/IMG_webp.c index 77d8de31..13768bf3 100644 --- a/src/IMG_webp.c +++ b/src/IMG_webp.c @@ -66,10 +66,10 @@ static struct { #else #define FUNCTION_LOADER_LIBWEBP(FUNC, SIG) \ lib.FUNC = FUNC; \ - if (lib.FUNC == NULL) { IMG_SetError("Missing webp.framework"); return -1; } + if (lib.FUNC == NULL) { SDL_SetError("Missing webp.framework"); return -1; } #define FUNCTION_LOADER_LIBWEBPDEMUX(FUNC, SIG) \ lib.FUNC = FUNC; \ - if (lib.FUNC == NULL) { IMG_SetError("Missing webpdemux.framework"); return -1; } + if (lib.FUNC == NULL) { SDL_SetError("Missing webpdemux.framework"); return -1; } #endif #ifdef __APPLE__ @@ -115,16 +115,18 @@ void IMG_QuitWEBP(void) --lib.loaded; } -static int webp_getinfo(SDL_IOStream *src, size_t *datasize) { +static SDL_bool webp_getinfo(SDL_IOStream *src, size_t *datasize) +{ Sint64 start, size; - int is_WEBP; + SDL_bool is_WEBP; Uint8 magic[20]; if (!src) { - return 0; + return SDL_FALSE; } + start = SDL_TellIO(src); - is_WEBP = 0; + is_WEBP = SDL_FALSE; if (SDL_ReadIO(src, magic, sizeof(magic)) == sizeof(magic)) { if (magic[ 0] == 'R' && magic[ 1] == 'I' && @@ -138,7 +140,7 @@ static int webp_getinfo(SDL_IOStream *src, size_t *datasize) { magic[13] == 'P' && magic[14] == '8' && (magic[15] == ' ' || magic[15] == 'X' || magic[15] == 'L')) { - is_WEBP = 1; + is_WEBP = SDL_TRUE; if (datasize) { size = SDL_GetIOSize(src); if (size > 0) { @@ -150,11 +152,11 @@ static int webp_getinfo(SDL_IOStream *src, size_t *datasize) { } } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return(is_WEBP); + return is_WEBP; } /* See if an image is contained in a data source */ -int IMG_isWEBP(SDL_IOStream *src) +SDL_bool IMG_isWEBP(SDL_IOStream *src) { return webp_getinfo(src, NULL); } @@ -252,7 +254,7 @@ SDL_Surface *IMG_LoadWEBP_IO(SDL_IOStream *src) } if (error) { - IMG_SetError("%s", error); + SDL_SetError("%s", error); } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); @@ -372,7 +374,7 @@ IMG_Animation *IMG_LoadWEBPAnimation_IO(SDL_IOStream *src) } if (error) { - IMG_SetError("%s", error); + SDL_SetError("%s", error); } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); return NULL; @@ -385,7 +387,7 @@ IMG_Animation *IMG_LoadWEBPAnimation_IO(SDL_IOStream *src) int IMG_InitWEBP(void) { - IMG_SetError("WEBP images are not supported"); + SDL_SetError("WEBP images are not supported"); return -1; } @@ -394,11 +396,11 @@ void IMG_QuitWEBP(void) } /* See if an image is contained in a data source */ -int IMG_isWEBP(SDL_IOStream *src) +SDL_bool IMG_isWEBP(SDL_IOStream *src) { (void)src; - return 0; + return SDL_FALSE; } /* Load a WEBP type image from an SDL datasource */ diff --git a/src/IMG_xcf.c b/src/IMG_xcf.c index c8cdbac0..233fa21f 100644 --- a/src/IMG_xcf.c +++ b/src/IMG_xcf.c @@ -213,17 +213,17 @@ typedef unsigned char *(*load_tile_type)(SDL_IOStream *, size_t, int, int, int); /* See if an image is contained in a data source */ -int IMG_isXCF(SDL_IOStream *src) +SDL_bool IMG_isXCF(SDL_IOStream *src) { Sint64 start; - int is_XCF = 0; + SDL_bool is_XCF = SDL_FALSE; char magic[14]; if (src) { start = SDL_TellIO(src); if (SDL_ReadIO(src, magic, sizeof(magic)) == sizeof(magic)) { if (SDL_strncmp(magic, "gimp xcf ", 9) == 0) { - is_XCF = 1; + is_XCF = SDL_TRUE; } } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); @@ -738,13 +738,13 @@ do_layer_surface(SDL_Surface *surface, SDL_IOStream *src, xcf_header *head, xcf_ hierarchy = read_xcf_hierarchy(src, head); if (hierarchy->bpp > 4) { /* unsupported. */ - IMG_SetError("Unknown Gimp image bpp (%u)", (unsigned int) hierarchy->bpp); + SDL_SetError("Unknown Gimp image bpp (%u)", (unsigned int) hierarchy->bpp); free_xcf_hierarchy(hierarchy); return 1; } if ((hierarchy->width > 20000) || (hierarchy->height > 20000)) { /* arbitrary limit to avoid integer overflow. */ - IMG_SetError("Gimp image too large (%ux%u)", (unsigned int) hierarchy->width, (unsigned int) hierarchy->height); + SDL_SetError("Gimp image too large (%ux%u)", (unsigned int) hierarchy->width, (unsigned int) hierarchy->height); free_xcf_hierarchy(hierarchy); return 1; } @@ -770,7 +770,7 @@ do_layer_surface(SDL_Surface *surface, SDL_IOStream *src, xcf_header *head, xcf_ if (length <= SDL_SIZE_MAX) { tile = load_tile(src, (size_t)length, hierarchy->bpp, ox, oy); } else { - IMG_SetError("Gimp image invalid tile offsets"); + SDL_SetError("Gimp image invalid tile offsets"); tile = NULL; } if (!tile) { @@ -826,7 +826,7 @@ do_layer_surface(SDL_Surface *surface, SDL_IOStream *src, xcf_header *head, xcf_ } break; default: - IMG_SetError("Unknown Gimp image type (%" SDL_PRIu32 ")", head->image_type); + SDL_SetError("Unknown Gimp image type (%" SDL_PRIu32 ")", head->image_type); if (hierarchy) { free_xcf_hierarchy(hierarchy); } @@ -857,7 +857,7 @@ do_layer_surface(SDL_Surface *surface, SDL_IOStream *src, xcf_header *head, xcf_ } break; default: - IMG_SetError("Unknown Gimp image type (%" SDL_PRIu32 ")\n", head->image_type); + SDL_SetError("Unknown Gimp image type (%" SDL_PRIu32 ")\n", head->image_type); if (tile) free_xcf_tile(tile); if (level) @@ -1024,7 +1024,7 @@ SDL_Surface *IMG_LoadXCF_IO(SDL_IOStream *src) SDL_DestroySurface(surface); surface = NULL; } - IMG_SetError("%s", error); + SDL_SetError("%s", error); } return surface; } @@ -1035,9 +1035,9 @@ SDL_Surface *IMG_LoadXCF_IO(SDL_IOStream *src) #endif /* See if an image is contained in a data source */ -int IMG_isXCF(SDL_IOStream *src) +SDL_bool IMG_isXCF(SDL_IOStream *src) { - return 0; + return SDL_FALSE; } /* Load a XCF type image from an SDL datasource */ diff --git a/src/IMG_xpm.c b/src/IMG_xpm.c index e5aa4fe1..1752f0bd 100644 --- a/src/IMG_xpm.c +++ b/src/IMG_xpm.c @@ -51,23 +51,25 @@ #ifdef LOAD_XPM /* See if an image is contained in a data source */ -int IMG_isXPM(SDL_IOStream *src) +SDL_bool IMG_isXPM(SDL_IOStream *src) { Sint64 start; - int is_XPM; + SDL_bool is_XPM; char magic[9]; - if ( !src ) - return 0; + if (!src) { + return SDL_FALSE; + } + start = SDL_TellIO(src); - is_XPM = 0; + is_XPM = SDL_FALSE; if (SDL_ReadIO(src, magic, sizeof(magic)) == sizeof(magic) ) { if ( SDL_memcmp(magic, "/* XPM */", sizeof(magic)) == 0 ) { - is_XPM = 1; + is_XPM = SDL_TRUE; } } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return(is_XPM); + return is_XPM; } /* Hash table to look up colors from pixel strings */ @@ -118,7 +120,7 @@ static struct color_hash *create_colorhash(int maxnum) bytes = hash->size * sizeof(struct hash_entry **); /* Check for overflow */ if ((bytes / sizeof(struct hash_entry **)) != (Uint32)hash->size) { - IMG_SetError("memory allocation overflow"); + SDL_SetError("memory allocation overflow"); SDL_free(hash); return NULL; } @@ -131,7 +133,7 @@ static struct color_hash *create_colorhash(int maxnum) bytes = maxnum * sizeof(struct hash_entry); /* Check for overflow */ if ((bytes / sizeof(struct hash_entry)) != (Uint32)maxnum) { - IMG_SetError("memory allocation overflow"); + SDL_SetError("memory allocation overflow"); SDL_free(hash->table); SDL_free(hash); return NULL; @@ -1168,14 +1170,14 @@ static SDL_Surface *load_xpm(char **xpm, SDL_IOStream *src, SDL_bool force_32bit SDL_DestroySurface(image); image = NULL; } - IMG_SetError("%s", error); + SDL_SetError("%s", error); } if (keystrings) SDL_free(keystrings); free_colorhash(colors); if (linebuf) SDL_free(linebuf); - return(image); + return image; } /* Load a XPM type image from an IOStream datasource */ @@ -1191,7 +1193,7 @@ SDL_Surface *IMG_LoadXPM_IO(SDL_IOStream *src) SDL_Surface *IMG_ReadXPMFromArray(char **xpm) { if (!xpm) { - IMG_SetError("array is NULL"); + SDL_SetError("array is NULL"); return NULL; } return load_xpm(xpm, NULL, SDL_FALSE); @@ -1200,10 +1202,10 @@ SDL_Surface *IMG_ReadXPMFromArray(char **xpm) SDL_Surface *IMG_ReadXPMFromArrayToRGB888(char **xpm) { if (!xpm) { - IMG_SetError("array is NULL"); + SDL_SetError("array is NULL"); return NULL; } - return load_xpm(xpm, NULL, SDL_TRUE /* force_32bit */); + return load_xpm(xpm, NULL, SDL_TRUE); } #else /* not LOAD_XPM */ @@ -1212,16 +1214,16 @@ SDL_Surface *IMG_ReadXPMFromArrayToRGB888(char **xpm) #endif /* See if an image is contained in a data source */ -int IMG_isXPM(SDL_IOStream *src) +SDL_bool IMG_isXPM(SDL_IOStream *src) { - return(0); + return SDL_FALSE; } /* Load a XPM type image from an SDL datasource */ SDL_Surface *IMG_LoadXPM_IO(SDL_IOStream *src) { - return(NULL); + return NULL; } SDL_Surface *IMG_ReadXPMFromArray(char **xpm) diff --git a/src/IMG_xv.c b/src/IMG_xv.c index 31e742c8..adba9b11 100644 --- a/src/IMG_xv.c +++ b/src/IMG_xv.c @@ -80,21 +80,23 @@ static int get_header(SDL_IOStream *src, int *w, int *h) } /* See if an image is contained in a data source */ -int IMG_isXV(SDL_IOStream *src) +SDL_bool IMG_isXV(SDL_IOStream *src) { Sint64 start; - int is_XV; + SDL_bool is_XV; int w, h; - if ( !src ) - return 0; + if (!src) { + return SDL_FALSE; + } + start = SDL_TellIO(src); - is_XV = 0; + is_XV = SDL_FALSE; if ( get_header(src, &w, &h) == 0 ) { - is_XV = 1; + is_XV = SDL_TRUE; } SDL_SeekIO(src, start, SDL_IO_SEEK_SET); - return(is_XV); + return is_XV; } /* Load a XV thumbnail image from an SDL datasource */ @@ -141,7 +143,7 @@ SDL_Surface *IMG_LoadXV_IO(SDL_IOStream *src) SDL_DestroySurface(surface); surface = NULL; } - IMG_SetError("%s", error); + SDL_SetError("%s", error); } return surface; } @@ -152,15 +154,15 @@ SDL_Surface *IMG_LoadXV_IO(SDL_IOStream *src) #endif /* See if an image is contained in a data source */ -int IMG_isXV(SDL_IOStream *src) +SDL_bool IMG_isXV(SDL_IOStream *src) { - return(0); + return SDL_FALSE; } /* Load a XXX type image from an SDL datasource */ SDL_Surface *IMG_LoadXV_IO(SDL_IOStream *src) { - return(NULL); + return NULL; } #endif /* LOAD_XV */ diff --git a/src/IMG_xxx.c b/src/IMG_xxx.c index b3c1d4c4..e5d1fceb 100644 --- a/src/IMG_xxx.c +++ b/src/IMG_xxx.c @@ -28,17 +28,17 @@ /* See if an image is contained in a data source */ /* Remember to declare this procedure in IMG.h . */ -int IMG_isXXX(SDL_IOStream *src) +SDL_bool IMG_isXXX(SDL_IOStream *src) { int start; - int is_XXX; + SDL_bool is_XXX; if (!src) { - return 0; + return SDL_FALSE; } start = SDL_TellIO(src); - is_XXX = 0; + is_XXX = SDL_FALSE; /* Detect the image here */ @@ -69,7 +69,7 @@ SDL_Surface *IMG_LoadXXX_IO(SDL_IOStream *src) SDL_DestroySurface(surface); surface = NULL; } - IMG_SetError("%s", error); + SDL_SetError("%s", error); } return surface; @@ -81,10 +81,10 @@ SDL_Surface *IMG_LoadXXX_IO(SDL_IOStream *src) #pragma warning(disable : 4100) /* warning C4100: 'op' : unreferenced formal parameter */ #endif -int IMG_isXXX(SDL_IOStream *src) +SDL_bool IMG_isXXX(SDL_IOStream *src) { (void) src; - return 0; + return SDL_FALSE; } SDL_Surface *IMG_LoadXXX_IO(SDL_IOStream *src) diff --git a/src/stb_image.h b/src/stb_image.h index 7ba9d30c..6ba09386 100644 --- a/src/stb_image.h +++ b/src/stb_image.h @@ -1034,7 +1034,7 @@ static int stbi__pnm_is16(stbi__context *s); #if 1 /* SDL_image change: */ static int stbi__err(const char *str) { - IMG_SetError("%s", str); + SDL_SetError("%s", str); return 0; } #else /* SDL_image change. */ diff --git a/test/main.c b/test/main.c index 057870d9..69cab49d 100644 --- a/test/main.c +++ b/test/main.c @@ -117,7 +117,7 @@ typedef struct int initFlag; SDL_bool canLoad; SDL_bool canSave; - int (SDLCALL * checkFunction)(SDL_IOStream *src); + SDL_bool (SDLCALL * checkFunction)(SDL_IOStream *src); SDL_Surface *(SDLCALL * loadFunction)(SDL_IOStream *src); } Format;