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 - RGBA PNG images are loaded as ABGR
Summary: RGBA PNG images are loaded as ABGR
Status: RESOLVED INVALID
Alias: None
Product: SDL_image
Classification: Unclassified
Component: misc (show other bugs)
Version: unspecified
Hardware: x86_64 Windows 7
: P2 normal
Assignee: Sam Lantinga
QA Contact: Sam Lantinga
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-23 09:34 UTC by Mike Parker
Modified: 2013-10-18 07:55 UTC (History)
0 users

See Also:


Attachments
Tri-colored image that demonstrates the color inversion. (2.06 KB, image/png)
2013-09-23 09:34 UTC, Mike Parker
Details
Another image that demonstrates the color inversion. (1.36 KB, image/png)
2013-09-23 09:35 UTC, Mike Parker
Details

Note You need to log in before you can comment on or make changes to this bug.
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.