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 2111

Summary: RGBA PNG images are loaded as ABGR
Product: SDL_image Reporter: Mike Parker <aldacron>
Component: miscAssignee: Sam Lantinga <slouken>
Status: RESOLVED INVALID QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: unspecified   
Hardware: x86_64   
OS: Windows 7   
Attachments: Tri-colored image that demonstrates the color inversion.
Another image that demonstrates the color inversion.

Description Mike Parker 2013-09-23 09:34:52 UTC
Created attachment 1336 [details]
Tri-colored image that demonstrates the color inversion.

When loading 32-bit RGBA images, the pixel format is set to SDL_PIXELFORMAT_ABGR8888. Converting the image to SDL_PIXELFORMAT_RGBA8888 and then passing it to OpenGL with both the internal storage and texture format set to GL_RGBA results in the texture being displayed with the colors inverted. However, if the ABGR8888 image is passed as is with no conversion, again with both internal storage and texture format set to GL_RGBA, then the colors display correctly.

In short, SDL_PIXELFORMAT_RGBA8888 is backwards compared to GL_RGBA, but SDL_PIXELFORMAT_ABGR8888 is not.

Compiling as 32-bit on 64-bit Windows 7.
Comment 1 Mike Parker 2013-09-23 09:35:15 UTC
Created attachment 1337 [details]
Another image that demonstrates the color inversion.
Comment 2 Sam Lantinga 2013-10-18 07:55:13 UTC
SDL's pixel formats are packed pixels which are endian dependent, while OpenGL's pixel formats are (usually) byte arrays, which are not endian dependent.

The SDL 2D renderer uses SDL_PIXELFORMAT_ARGB8888 with this code:
    case SDL_PIXELFORMAT_ARGB8888:
        *internalFormat = GL_RGBA8;
        *format = GL_BGRA;
        *type = GL_UNSIGNED_INT_8_8_8_8_REV;
        break;

You just need to account for the OpenGL formats you plan to use when you're loading your data.