From f5f1b1b55e5e7ae8352dd4fffc0a4b2a6acc9b38 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
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 <stea@cs.binghamton.edu> */
/* Blame me, not
(Patch may be truncated, please check the link at the top of this post.)