SFML community forums

Help => Graphics => Topic started by: Phanoo on May 29, 2018, 09:55:48 pm

Title: sf::Color toInteger() returns ARGB instead of RGBA ?
Post by: Phanoo on May 29, 2018, 09:55:48 pm
Hello

I found that the toInteger() function from sf::Color returns components in ARGB instead of RGBA format, which is not very compatible with the rest of the API which uses RGBA format. Is it a bug or it's meant to work like that ?
Title: Re: sf::Color toInteger() returns ARGB instead of RGBA ?
Post by: eXpl0it3r on May 29, 2018, 10:05:45 pm
How did you find that out?

What system/OS/etc.?
Title: Re: sf::Color toInteger() returns ARGB instead of RGBA ?
Post by: Phanoo on May 29, 2018, 10:37:49 pm
Well sorry I did a mistake somewhere, it's totally my bad. I was expecting that:
buffer[4*(i+j*width)+0]=R;
buffer[4*(i+j*width)+1]=G;
buffer[4*(i+j*width)+2]=B;
buffer[4*(i+j*width)+3]=A;
(for a pixel buffer to load with image.create())

Was the same as
uintbuffer[i+j*width]=RGBA; // RGBA = 0xff0000ff for a red color for example
 

But for some reason it's reversed (some endianness thing ?), I need to write the int in ABGR format to get the correct color once loaded with image.create()
Title: Re: sf::Color toInteger() returns ARGB instead of RGBA ?
Post by: FRex on May 30, 2018, 03:44:48 am
Because the endian is little (x86) on your machine the order of doing that is actually ABGR. The code in sf::Color is correct and endian independent because it only uses bit ops, not casts or unions.

See this example: https://ideone.com/iLgpoz