Once again: Color Byte Order on different OS

Just starting out? Need help? Post your questions and find answers here.
SMaag
Enthusiast
Enthusiast
Posts: 339
Joined: Sat Jan 14, 2023 6:55 pm
Location: Bavaria/Germany

Once again: Color Byte Order on different OS

Post 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$
User avatar
moulder61
Enthusiast
Enthusiast
Posts: 211
Joined: Sun Sep 19, 2021 6:16 pm
Location: U.K.

Re: Once again: Color Byte Order on different OS

Post by moulder61 »

The debugger output on my Linux box says "System Color Order on Linux = RGBA". :)

Moulder.
"If it ain't broke, fix it until it is!

This message is brought to you thanks to SenselessComments.com

My PB stuff for Linux: "https://u.pcloud.link/publink/show?code ... z3MR0T3jyV
User avatar
kenmo
Addict
Addict
Posts: 2064
Joined: Tue Dec 23, 2003 3:54 am

Re: Once again: Color Byte Order on different OS

Post 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().
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 505
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: Once again: Color Byte Order on different OS

Post by Mindphazer »

Code: Select all

System Color Order on MacOS = RGBA
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 26.1 - Iphone 17 Pro Max - iPad at home
...and unfortunately... Windows at work...
User avatar
mk-soft
Always Here
Always Here
Posts: 6374
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Once again: Color Byte Order on different OS

Post 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]
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply