Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: sf::Color toInteger() returns ARGB instead of RGBA ?  (Read 2276 times)

0 Members and 1 Guest are viewing this topic.

Phanoo

  • Full Member
  • ***
  • Posts: 136
    • View Profile
sf::Color toInteger() returns ARGB instead of RGBA ?
« 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 ?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: sf::Color toInteger() returns ARGB instead of RGBA ?
« Reply #1 on: May 29, 2018, 10:05:45 pm »
How did you find that out?

What system/OS/etc.?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Phanoo

  • Full Member
  • ***
  • Posts: 136
    • View Profile
Re: sf::Color toInteger() returns ARGB instead of RGBA ?
« Reply #2 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()
« Last Edit: May 29, 2018, 10:40:34 pm by Phanoo »

FRex

  • Hero Member
  • *****
  • Posts: 1845
  • Back to C++ gamedev with SFML in May 2023
    • View Profile
    • Email
Re: sf::Color toInteger() returns ARGB instead of RGBA ?
« Reply #3 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
« Last Edit: May 30, 2018, 03:48:59 am by FRex »
Back to C++ gamedev with SFML in May 2023

 

anything