Seperate colour into Red, Green and Blue

Previous topic - Next topic

MrTAToad

Whilst there is sample code for separating a 32-bit value into its corresponding red, green and blue variants, the code is rather more complicated than it needs to be.

Thus, I present the simpler version :

Code (glbasic) Select
FUNCTION RGBR%:colour%
INLINE
return (DGNat) colour & 255;
ENDINLINE
ENDFUNCTION

FUNCTION RGBG%:colour%
INLINE
return (DGNat) ((colour>>8) & 255);
ENDINLINE
ENDFUNCTION


FUNCTION RGBB%:colour%
INLINE
return (DGNat) ((colour>>16) & 255);
ENDINLINE
ENDFUNCTION

Schranz0r

Try to use:


Code (glbasic) Select
FUNCTION Get_R_G_B: color, BYREF R, BYREF G, BYREF B
   INLINE
       R = (DGNat) colour & 255;
       G = (DGNat) ((colour>>8) & 255);
       B = (DGNat) ((colour>>16) & 255);
   ENDINLINE
ENDFUNCTION
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

MrTAToad

Thats useful if you want to get the three components in one go, or you don't want to use the return value as a parameter for a function :)

Ian Price

What is DGNat? - it's not documented in GLBasic or on the online helpfile.

GLB knows what it is, but it's not in uppercase...
I came. I saw. I played.

Quentin

DGInt = Float variable
DGNat = Integer variable

in INLINE blocks

Schranz0r

Quote from: Quentin on 2009-Sep-26
DGInt = Float variable
DGNat = Integer variable

in INLINE blocks

@ Quentin:

Thats right!


@ MrTAToad:

Thats true, but you need normaly all 3 values :)
But nice work!
Thanks for sharing this!
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

MrTAToad


Ian Price

Quote from: Quentin on 2009-Sep-26
DGInt = Float variable
DGNat = Integer variable

in INLINE blocks

OK. Cheers :)
I came. I saw. I played.

Kitty Hello


MrTAToad

Mine is/should be a bit more efficient  =D