From 9d303c3906c31ac8cc6532268179df2bce4babca Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Fri, 6 Dec 2024 15:01:11 -0800
Subject: [PATCH] Fixed inconsistencies between documentation and
implementation
Fixes https://github.com/libsdl-org/SDL_image/issues/481
---
include/SDL3_image/SDL_image.h | 24 +++++++++++++++---------
src/IMG_avif.c | 2 +-
src/IMG_jpg.c | 2 +-
src/IMG_png.c | 2 +-
4 files changed, 18 insertions(+), 12 deletions(-)
diff --git a/include/SDL3_image/SDL_image.h b/include/SDL3_image/SDL_image.h
index ae1fd347..ae40e751 100644
--- a/include/SDL3_image/SDL_image.h
+++ b/include/SDL3_image/SDL_image.h
@@ -1854,7 +1854,8 @@ 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 true on success or false on failure; call SDL_GetError() for more
+ * information.
*
* \since This function is available since SDL_image 3.0.0.
*
@@ -1876,13 +1877,14 @@ extern SDL_DECLSPEC bool SDLCALL IMG_SaveAVIF(SDL_Surface *surface, const char *
* to leave it open.
* \param quality the desired quality, ranging between 0 (lowest) and 100
* (highest).
- * \returns 0 if successful, -1 on error.
+ * \returns true on success or 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 bool SDLCALL IMG_SaveAVIF_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio, int quality);
+extern SDL_DECLSPEC bool SDLCALL IMG_SaveAVIF_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio, int quality);
/**
* Save an SDL_Surface into a PNG image file.
@@ -1891,7 +1893,8 @@ extern SDL_DECLSPEC bool SDLCALL IMG_SaveAVIF_IO(SDL_Surface *surface, SDL_IOStr
*
* \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 true on success or false on failure; call SDL_GetError() for more
+ * information.
*
* \since This function is available since SDL_image 3.0.0.
*
@@ -1911,13 +1914,14 @@ extern SDL_DECLSPEC bool SDLCALL IMG_SavePNG(SDL_Surface *surface, const char *f
* \param dst the SDL_IOStream to save the image data to.
* \param closeio true to close/free the SDL_IOStream before returning, false
* to leave it open.
- * \returns 0 if successful, -1 on error.
+ * \returns true on success or 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 bool SDLCALL IMG_SavePNG_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio);
+extern SDL_DECLSPEC bool SDLCALL IMG_SavePNG_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio);
/**
* Save an SDL_Surface into a JPEG image file.
@@ -1928,7 +1932,8 @@ extern SDL_DECLSPEC bool SDLCALL IMG_SavePNG_IO(SDL_Surface *surface, SDL_IOStre
* \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 true on success or false on failure; call SDL_GetError() for more
+ * information.
*
* \since This function is available since SDL_image 3.0.0.
*
@@ -1950,13 +1955,14 @@ extern SDL_DECLSPEC bool SDLCALL IMG_SaveJPG(SDL_Surface *surface, const char *f
* 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 true on success or 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 bool SDLCALL IMG_SaveJPG_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio, int quality);
+extern SDL_DECLSPEC bool SDLCALL IMG_SaveJPG_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio, int quality);
/**
* Animated image support Currently only animated GIFs are supported.
diff --git a/src/IMG_avif.c b/src/IMG_avif.c
index ec4035c6..f140a4ac 100644
--- a/src/IMG_avif.c
+++ b/src/IMG_avif.c
@@ -737,7 +737,7 @@ bool IMG_SaveAVIF(SDL_Surface *surface, const char *file, int quality)
}
}
-bool IMG_SaveAVIF_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio, int quality)
+bool IMG_SaveAVIF_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio, int quality)
{
bool result = false;
diff --git a/src/IMG_jpg.c b/src/IMG_jpg.c
index b6f408fd..81bb28a8 100644
--- a/src/IMG_jpg.c
+++ b/src/IMG_jpg.c
@@ -752,7 +752,7 @@ bool IMG_SaveJPG(SDL_Surface *surface, const char *file, int quality)
}
}
-bool IMG_SaveJPG_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio, int quality)
+bool IMG_SaveJPG_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio, int quality)
{
bool result = false;
(void)surface;
diff --git a/src/IMG_png.c b/src/IMG_png.c
index 6e26ba9f..6947be39 100644
--- a/src/IMG_png.c
+++ b/src/IMG_png.c
@@ -785,7 +785,7 @@ bool IMG_SavePNG(SDL_Surface *surface, const char *file)
}
}
-bool IMG_SavePNG_IO(SDL_Surface *surface, SDL_IOStream *dst, int closeio)
+bool IMG_SavePNG_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio)
{
bool result = false;