SDL_SaveBMP_IO(3)

πŸŽ€ SDL_SaveBMP_IO πŸŽ€

okay bestie, so this is a page from the SDL3 FUNCTIONS manual, and today's main character is SDL_SaveBMP_IO β€” the girl who takes your surface and yeets it into a BMP. let's get into it πŸ’…


✨ NAME ✨

SDL_SaveBMP_IO β€” save a surface to a seekable SDL data stream, in BMP format. that's it, that's the whole vibe πŸŽ€


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_surface.h>

bool SDL_SaveBMP_IO(SDL_Surface *surface, SDL_IOStream *dst, bool closeio);

πŸ’– DESCRIPTION πŸ’–

okay so here's the tea on how the saving actually goes down πŸ«–

Surfaces with a 24-bit, 32-bit, and paletted 8-bit format get saved into the BMP directly. no conversion, no detour, straight through. slay ✨

Other RGB formats with 8-bit or higher get converted first:

  • to a 24-bit surface, or
  • if they have an alpha mask or a colorkey, to a 32-bit surface

...and then they get saved. it's giving "we'll fix your outfit before the photo, don't worry" πŸ’…

and now the part nobody wants to hear 😭

YUV formats, and paletted 1-bit and 4-bit formats, are not supported. periodt. they do not pass the vibe check and they do not get saved.

πŸ¦‹ FUNCTION PARAMETERS πŸ¦‹

  • surface β€” the SDL_Surface structure holding the image you want to save. this is your girl, your canvas, your moment πŸ‘‘
  • dst β€” a data stream to save to. the destination, the place where the BMP is gonna live 🏑
  • closeio β€” if true, it calls SDL_CloseIO() on dst before returning, even in the case of an error. so like, yes, it will still close it even if everything went sideways. no cap, that's the deal πŸ™ˆ

🌈 RETURN VALUE 🌈

Returns true on success or false on failure β€” and bestie, if it fails, please call SDL_GetError() for more information. the function will not tell you what went wrong, you gotta go ask 😀


⭐ THREAD SAFETY ⭐

This function can be called on different threads with different surfaces. so as long as each thread has its own surface, you're good β€” go be multithreaded, you icon 🧚


πŸ‘‘ AVAILABILITY πŸ‘‘

This function is available since SDL 3.2.0. if you're on something older, this is not for you, sorry not sorry πŸ’œ


πŸ’€ SEE ALSO πŸ’€

iykyk β€” load it back, or save it the non-IO way 🌸


and that's the whole page, bestie!! 🫢 this little manual moment came to you from Simple Directmedia Layer, running SDL 3.4.18, and yeah the page header said SDL_SaveBMP_IO(3) the whole time, we just folded that in up top like a cute little hair clip πŸŽ€βœ¨ go save some BMPs, you're doing amazing πŸ’–

πŸ“¦ where this page comes from