Added support for loading and saving PNG images using stb_image

This commit is contained in:
Sam Lantinga
2025-10-06 10:18:28 -07:00
parent 8d81ee3f5d
commit 73334b6bb4
8 changed files with 368 additions and 27 deletions

View File

@@ -559,7 +559,7 @@ extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadBMP(const char *file);
extern SDL_DECLSPEC bool SDLCALL SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio);
/**
* Save a surface to a file.
* Save a surface to a file in BMP format.
*
* Surfaces with a 24-bit, 32-bit and paletted 8-bit format get saved in the
* BMP directly. Other RGB formats with 8-bit or higher get converted to a
@@ -581,6 +581,84 @@ extern SDL_DECLSPEC bool SDLCALL SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStre
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SaveBMP(SDL_Surface *surface, const char *file);
/**
* Load a PNG image from a seekable SDL data stream.
*
* The new surface should be freed with SDL_DestroySurface(). Not doing so
* will result in a memory leak.
*
* \param src the data stream for the surface.
* \param closeio if true, calls SDL_CloseIO() on `src` before returning, even
* in the case of an error.
* \returns a pointer to a new SDL_Surface structure or NULL on failure; call
* SDL_GetError() for more information.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DestroySurface
* \sa SDL_LoadPNG
* \sa SDL_SavePNG_IO
*/
extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadPNG_IO(SDL_IOStream *src, bool closeio);
/**
* Load a PNG image from a file.
*
* The new surface should be freed with SDL_DestroySurface(). Not doing so
* will result in a memory leak.
*
* \param file the PNG file to load.
* \returns a pointer to a new SDL_Surface structure or NULL on failure; call
* SDL_GetError() for more information.
*
* \threadsafety It is safe to call this function from any thread.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_DestroySurface
* \sa SDL_LoadPNG_IO
* \sa SDL_SavePNG
*/
extern SDL_DECLSPEC SDL_Surface * SDLCALL SDL_LoadPNG(const char *file);
/**
* Save a surface to a seekable SDL data stream in PNG format.
*
* \param surface the SDL_Surface structure containing the image to be saved.
* \param dst a data stream to save to.
* \param closeio if true, calls SDL_CloseIO() on `dst` before returning, even
* in the case of an error.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \threadsafety This function is not thread safe.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LoadPNG_IO
* \sa SDL_SavePNG
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SavePNG_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio);
/**
* Save a surface to a file in PNG format.
*
* \param surface the SDL_Surface structure containing the image to be saved.
* \param file a file to save to.
* \returns true on success or false on failure; call SDL_GetError() for more
* information.
*
* \threadsafety This function is not thread safe.
*
* \since This function is available since SDL 3.2.0.
*
* \sa SDL_LoadPNG
* \sa SDL_SavePNG_IO
*/
extern SDL_DECLSPEC bool SDLCALL SDL_SavePNG(SDL_Surface *surface, const char *file);
/**
* Set the RLE acceleration hint for a surface.
*