imgLoadIo function

Pointer<SdlSurface> imgLoadIo(
  1. Pointer<SdlIoStream> src,
  2. bool closeio
)

Load an image from an SDL data source into a software surface.

An SDL_Surface is a buffer of pixels in memory accessible by the CPU. Use this if you plan to hand the data to something else or manipulate it further in code.

There are no guarantees about what format the new SDL_Surface data will be; in many cases, SDL_image will attempt to supply a surface that exactly matches the provided image, but in others it might have to convert (either because the image is in a format that SDL doesn't directly support or because it's compressed data that could reasonably uncompress to various formats and SDL_image had to pick one). You can inspect an SDL_Surface for its specifics, and use SDL_ConvertSurface to then migrate to any supported format.

If the image format supports a transparent pixel, SDL will set the colorkey for the surface. You can enable RLE acceleration on the surface afterwards by calling: SDL_SetSurfaceColorKey(image, SDL_RLEACCEL, image->format->colorkey);

If closeio is true, src will be closed before returning, whether this function succeeds or not. SDL_image reads everything it needs from src during this call in any case.

There is a separate function to read files from disk without having to deal with SDL_IOStream: IMG_Load("filename.jpg") will call this function and manage those details for you, determining the file type from the filename's extension.

There is also IMG_LoadTyped_IO(), which is equivalent to this function except a file extension (like "BMP", "JPG", etc) can be specified, in case SDL_image cannot autodetect the file format.

If you are using SDL's 2D rendering API, there is an equivalent call to load images directly into an SDL_Texture for use by the GPU without using a software surface: call IMG_LoadTexture_IO() instead.

When done with the returned surface, the app should dispose of it with a call to SDL_DestroySurface().

\param src an SDL_IOStream that data will be read from. \param closeio true to close/free the SDL_IOStream before returning, false to leave it open. \returns a new SDL surface, or NULL on error.

\since This function is available since SDL_image 3.0.0.

\sa IMG_Load \sa IMG_LoadTyped_IO \sa SDL_DestroySurface

extern SDL_DECLSPEC SDL_Surface * SDLCALL IMG_Load_IO(SDL_IOStream *src, bool closeio)

Implementation

Pointer<SdlSurface> imgLoadIo(Pointer<SdlIoStream> src, bool closeio) {
  final imgLoadIoLookupFunction = libSdl3Image.lookupFunction<
      Pointer<SdlSurface> Function(Pointer<SdlIoStream> src, Uint8 closeio),
      Pointer<SdlSurface> Function(
          Pointer<SdlIoStream> src, int closeio)>('IMG_Load_IO');
  return imgLoadIoLookupFunction(src, closeio ? 1 : 0);
}