Page 1 of 1

Once again: Color Byte Order on different OS

Posted: Wed Nov 19, 2025 2:20 pm
by SMaag
I do direct Color x Matrix multiplication.
For that the correct Color Byte Order is important.

Windows RGBA : no doubt!

My opinion was MAC and Linux BGRA!
But seems not correct. It's RGBA too!
We tested a time ago here: viewtopic.php?p=634650&hilit=color+byte+order#p634650

To be sure, I made a better ColorByteOrder Test.
Can anyone Check on Linux and Mac

Code: Select all

EnableExplicit

Procedure.s GetSystemColorOrderString()
  Protected ret$, OS$
  Protected I, col.l, cc.c
   
  col = RGBA('R','G','B','A')

  For I = 0 To 3
    ; read color order from memory
    cc = PeekA(@col+I)
    ret$ = ret$+Chr(cc)
  Next
  ProcedureReturn ret$
EndProcedure

Define OS$, ColorOrder$ = GetSystemColorOrderString()

CompilerSelect #PB_Compiler_OS
  CompilerCase #PB_OS_Windows
    OS$="Windows"
  CompilerCase #PB_OS_Linux
    OS$="Linux"    
  CompilerCase #PB_OS_MacOS
    OS$="MacOS"  
CompilerEndSelect

Debug "System Color Order on " + OS$ + " = "  + ColorOrder$

Re: Once again: Color Byte Order on different OS

Posted: Wed Nov 19, 2025 2:29 pm
by moulder61
The debugger output on my Linux box says "System Color Order on Linux = RGBA". :)

Moulder.

Re: Once again: Color Byte Order on different OS

Posted: Wed Nov 19, 2025 2:39 pm
by kenmo
Can't test right now, but I expect it to output "RGBA" on all systems... all this is really confirming is Little Endian vs Big Endian, and I believe Fred has confirmed all systems PB supports are Little Endian. (Meaning the lowest byte of col, red byte, is first in memory, *address + 0)

Where you might find many RGBA order differences are in drawing buffer memory! Try DrawingBufferPixelFormat().

Re: Once again: Color Byte Order on different OS

Posted: Wed Nov 19, 2025 6:31 pm
by Mindphazer

Code: Select all

System Color Order on MacOS = RGBA

Re: Once again: Color Byte Order on different OS

Posted: Wed Nov 19, 2025 7:22 pm
by mk-soft
PureBasic uses the same byte sequence in all OS
Only when you want to access the graphics memory directly, you must query the bytes to follow beforehand. DrawingBufferPixelFormat()

Update

Code: Select all

;-TOP

Structure udtColorComponents
  Red.a
  Green.a
  Blue.a
  Alpha.a
EndStructure

Structure udtColor
  StructureUnion
    Color.l
    Componente.udtColorComponents
    Byte.a[4]
  EndStructureUnion
EndStructure

Define Color.l, *MyColor.udtColor
Color = RGBA(1,2,3, 255)
*MyColor = @Color
Debug Hex(*MyColor\Color, #PB_Long)
Debug "Red = " + *MyColor\Componente\Red
Debug "Green = " + *MyColor\Componente\Green
Debug "Blue = " + *MyColor\Componente\Blue
Debug "Alpha = " + *MyColor\Componente\Alpha

Debug "Little Endian Notation"
Debug "Byte 0 = " + *MyColor\Byte[0]
Debug "Byte 1 = " + *MyColor\Byte[1]
Debug "Byte 2 = " + *MyColor\Byte[2]
Debug "Byte 3 = " + *MyColor\Byte[3]