SDL icon indicating copy to clipboard operation
SDL copied to clipboard

New API request: `SDL_ConvertSurfaceToPixels`

Open ankith26 opened this issue 1 year ago • 0 comments

Here is my usecase:

Given an SDL_Surface instance, I want to

  1. Convert the pixelformat.
  2. Specify a custom pitch.
  3. Copy the resulting pixel data into an already available buffer.

My current approach is to use SDL_ConvertSurface to get a new surface in the desired format, and then manually copy the data into the pixel buffer. This works but the minor issues here are:

  1. I have to handle the custom pitch myself
  2. SDL does extra work setting up the dest surface and allocing an intermediate buffer.

Then I found out that SDL_ConvertPixels exists, which at a first glance seems to be exactly what I want, but now the problem is this function cannot handle any cases where my input surface has extra data apart from the raw pixel data (e.g indexed surfaces, surfaces with colorkey or surface-alpha, etc)

It would be very appreciated if I can use a variant of SDL_ConvertPixels that takes the src as a SDL_Surface, basically. The function signature could be something like

int SDL_ConvertSurfaceToPixels(SDL_Surface *src, void *dst, Uint32 dst_format, int dst_pitch);

It would also be nice if there was an additional boolean argument called dst_flip which controls if the resulting pixel data is vertically flipped or not, but now I realize at this point I may be asking for too much :)

The reason this argument would be useful is that some libraries (like PyOpenGL) apparently prefer their image data in a flipped format. Atleast this is what a comment in the pygame(-ce) codebase tells me, I've not verified this information myself.

ankith26 avatar Jun 30 '24 10:06 ankith26