SDL_LoadPNG_IO(3)

πŸ“¦
version 3.4.18 Β· 5 versions
, in fedora 43, fedora 44

πŸ’– SDL_LoadPNG_IO πŸ’–

okay bestie, so this one lives in the SDL3 FUNCTIONS part of the manual, and it's literally the glow-up you need when you've got a PNG chillin' in an SDL data stream and you want it to become a surface. no cap. πŸ¦‹


✨ NAME ✨

SDL_LoadPNG_IO β€” load a PNG image from a seekable SDL data stream. that's the whole vibe. πŸŽ€


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_surface.h>

SDL_Surface * SDL_LoadPNG_IO(SDL_IOStream *src, bool closeio);

like, that's it. that's the whole function signature. slay. πŸ’…


πŸ’œ DESCRIPTION πŸ’œ

so the tea is: this is a convenience function for loading images from trusted sources. that part matters, bestie. if you're out here wanting to load arbitrary images β€” like, random stuff from the wild internet β€” you should be using libpng or another image loading library that was actually designed with security in mind. this one was not. i'm being so serious rn. 🫢

the new surface it hands you? yeah, you must free it with SDL_DestroySurface(). not doing so will result in a memory leak, which is giving "my laptop fan sounds like a jet engine" energy. don't do that to yourself. 😭


🧚 FUNCTION PARAMETERS 🧚

  • src β€” the data stream for the surface. it's the stream, it's the source, it's the moment. ⭐
  • closeio β€” if this is true, it calls SDL_CloseIO() on src before returning, and it does this even in the case of an error. so like, it's a responsible queen that cleans up after herself no matter how things went. πŸ‘‘

🌈 RETURN VALUE 🌈

returns a pointer to a brand new SDL_Surface structure, or NULL on failure β€” and if you get NULL, go call SDL_GetError() for more info. it will tell you what went wrong, i promise. πŸ”₯


πŸ’€ THREAD SAFETY πŸ’€

it is safe to call this function from any thread. go wild, multitask, live your main character life. ✨


πŸ“ AVAILABILITY πŸ“

this function has been available since SDL 3.4.0. so if you're on something older, it's not you, it's the version. πŸ™ˆ


🌟 SEE ALSO 🌟


real talk though: trusted sources only. libpng exists for a reason and it's not to be ignored. πŸ’–

and that's the page, bestie!! brought to you by Simple Directmedia Layer, running the SDL 3.4.18 era, and stamped with the SDL_LoadPNG_IO(3) energy. go load a PNG, destroy a surface, hydrate, and slay the day away. πŸŽ€πŸ’…πŸ¦‹βœ¨

πŸ“¦ where this page comes from