| Summary: | Add SDL_PIXELFORMAT_RGBA32 for byte-wise 32bit RGBA data | ||
|---|---|---|---|
| Product: | SDL | Reporter: | Daniel Gibson <metalcaedes> |
| Component: | video | Assignee: | Sam Lantinga <slouken> |
| Status: | RESOLVED FIXED | QA Contact: | Sam Lantinga <slouken> |
| Severity: | enhancement | ||
| Priority: | P2 | CC: | metalcaedes |
| Version: | HG 2.0 | ||
| Hardware: | All | ||
| OS: | All | ||
| Attachments: |
patch that adds SDL_PIXELFORMAT_RGBA32
patch that adds SDL_PIXELFORMAT_RGBA32, also ARGB, BGRA, ABGR add SDL_PIXELFORMAT_RGBA32, also ARGB, BGRA, ABGR as aliases test program (for latest SDL2 hg + my patch), needs stb_image.h one of the test images I used |
||
|
Description
Daniel Gibson
2015-03-26 03:47:21 UTC
This is totally useful with https://bugzilla.libsdl.org/show_bug.cgi?id=2924 This seems reasonable, however wouldn't you need the common variations... RGBA, ARGB, BGRA, ABGR, etc? Also you'd probably need to update the various other code that handles the appropriate packed formats to treat these as equivalent. Hmm yeah, adding other common variations sounds useful, are there any more than the ones you listed? I'm not sure what other code you mean, I thought this was all that's needed? Note that I intentionally didn't touch any code that maps masks back to pixelformats, to make sure masks still map to the same formats as before (RGBA8888/ABGR8888 depending on endianess) for backwards compatibility. Created attachment 2577 [details]
patch that adds SDL_PIXELFORMAT_RGBA32, also ARGB, BGRA, ABGR
ok, I updated the patch, now there's SDL_PIXELFORMAT_RGBA32, SDL_PIXELFORMAT_ARGB32, SDL_PIXELFORMAT_BGRA32, SDL_PIXELFORMAT_ABGR32
That's all the available 4 channel SDL_ARRAYORDERs.
/Maybe/ SDL_ARRAYORDER_RGBX etc would be useful, but currently they don't exist so I didn't create SDL_PIXELFORMAT_RGBX32 etc.
Anyway, if I should have modified more places in the code to support the new formats (without breaking backwards compatibility), please tell me and I'll update the patch accordingly.
Look for any code that references the packed pixel formats like SDL_PIXELFORMAT_RGBA8888 - they might also need to handle the new formats. Ok, I looked SDL_PIXELFORMAT_RGB24 (which doesn't have a packed equivalent), so it looked like there wasn't that much to do. There's things like the blitting table which could be done by mapping SDL_PIXELFORMAT_*32 to the corresponding (depending on endianess) SDL_PIXELFORMAT_*8888 in SDL_ChooseBlitFunc().. But then there's RendererInfo::texture_formats and everything related like the format passed to SDL_CreateTexture(), (and possibly other places that need to decide whether a format of a surface or supplied by the user is valid).. that needs some more thought to get right. So.. well.. damn, doing this properly doesn't seem trivial :-/ *grin* You've got a good start! :) Of course, there's also the easy way:
in SDL_pixels.h
enum {
...
#if SDL_BYTEORDER == SDL_BIG_ENDIAN
SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_RGBA8888,
SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_ARGB8888,
SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_BGRA8888,
SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_ABGR8888,
#else
SDL_PIXELFORMAT_RGBA32 = SDL_PIXELFORMAT_ABGR8888,
SDL_PIXELFORMAT_ARGB32 = SDL_PIXELFORMAT_BGRA8888,
SDL_PIXELFORMAT_BGRA32 = SDL_PIXELFORMAT_ARGB8888,
SDL_PIXELFORMAT_ABGR32 = SDL_PIXELFORMAT_RGBA8888,
#endif
...
};
This might be a bit surprising when setting one format and printing it yields the string of the other, but sooner or later the user will stumble upon the equivalence anyway
That might actually be a better approach. Can you try it out and create a patch if that works? Created attachment 2578 [details]
add SDL_PIXELFORMAT_RGBA32, also ARGB, BGRA, ABGR as aliases
Ok, I followed the simple approach of just making SDL_PIXELFORMAT_RGBA32 an alias of SDL_PIXELFORMAT_RGBA8888/SDL_PIXELFORMAT_ABGR8888, depending on endianess. And I did the same for SDL_PIXELFORMAT_ARGB32, .._BGRA, .._ABGR.
Seems to work fine with my little test program.
SDL_GetPixelFormatName() will of course return SDL_PIXELFORMAT_RGBA8888 (or SDL_PIXELFORMAT_ABGR8888) instead of SDL_PIXELFORMAT_RGBA32, but as long as that's mentioned in the docs it shouldn't be a problem.
I documented them in the header like
/**< endianess-specific alias for byte-wise 32bit RGBA data */
I hope the wording is clear enough, otherwise I'm open for suggestions of course :)
Created attachment 2579 [details]
test program (for latest SDL2 hg + my patch), needs stb_image.h
Created attachment 2580 [details]
one of the test images I used
Okay, this is in! https://hg.libsdl.org/SDL/rev/c6d79a1bec47 It also cleaned up a few places where arrays of color bytes is exactly what we wanted. :) Cool, thanks for getting this into 2.0.5! :-) You're welcome, thanks for contributing! :) |