We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 2924

Summary: SDL_CreateRGBSurface[From] versions that take SDL_PIXELFORMAT enum
Product: SDL Reporter: Daniel Gibson <metalcaedes>
Component: videoAssignee: Sam Lantinga <slouken>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: enhancement    
Priority: P2    
Version: HG 2.0   
Hardware: All   
OS: All   
Attachments: add SDL_CreateRGBSurfaceWithFormat[From]()

Description Daniel Gibson 2015-03-26 03:57:58 UTC
Created attachment 2089 [details]
add SDL_CreateRGBSurfaceWithFormat[From]()

Currently, SDL_CreateRGBSurface() and SDL_CreateRGBSurfaceFrom() take Uint32 masks for RGBA to "describe" the Pixelformat of the surface.
Internally those value are only used to map to one of the SDL_PIXELFORMAT_* enum values that are used for further processing.

I think it would be both handy and more efficient to be able to specify SDL_PIXELFORMAT_* yourself without using SDL_PixelFormatEnumToMasks() to create masks first, so I implemented functions that do that:
SDL_CreateRGBSurfaceWithFormat() and SDL_CreateRGBSurfaceWithFormatFrom() which are like the versions without "WithFormat" but instead of taking 4 Uint32s for R/G/B/A masks, they take one for a SDL_PIXELFORMAT_* enum value.

Together with https://bugzilla.libsdl.org/show_bug.cgi?id=2923 creating a SDL_Surface* from RGBA data (e.g. from stb_image)  is as easy as
  surf = SDL_SDL_CreateRGBSurfaceWithFormat(0, w, h, bppToUse*8, SDL_PIXELFORMAT_RGBA32);
Comment 1 Daniel Gibson 2015-03-26 04:00:21 UTC
Oh by the way, some discussion about this: https://forums.libsdl.org/viewtopic.php?t=11123
Comment 2 Sam Lantinga 2016-10-08 00:05:25 UTC
API added, thanks!
https://hg.libsdl.org/SDL/rev/f99f58ef8363
Comment 3 Daniel Gibson 2016-10-08 00:27:02 UTC
Thank you! :-)