GLBasic forum

Codesnippets => Code Snippets => Topic started by: MrTAToad on 2009-Sep-26

Title: Seperate colour into Red, Green and Blue
Post by: MrTAToad on 2009-Sep-26
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
Title: Re: Seperate colour into Red, Green and Blue
Post by: Schranz0r on 2009-Sep-26
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
Title: Re: Seperate colour into Red, Green and Blue
Post by: MrTAToad on 2009-Sep-26
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 :)
Title: Re: Seperate colour into Red, Green and Blue
Post by: Ian Price on 2009-Sep-26
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...
Title: Re: Seperate colour into Red, Green and Blue
Post by: Quentin on 2009-Sep-26
DGInt = Float variable
DGNat = Integer variable

in INLINE blocks
Title: Re: Seperate colour into Red, Green and Blue
Post by: Schranz0r on 2009-Sep-26
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!
Title: Re: Seperate colour into Red, Green and Blue
Post by: MrTAToad on 2009-Sep-26
No problem  :good:
Title: Re: Seperate colour into Red, Green and Blue
Post by: Ian Price on 2009-Sep-27
Quote from: Quentin on 2009-Sep-26
DGInt = Float variable
DGNat = Integer variable

in INLINE blocks

OK. Cheers :)
Title: Re: Seperate colour into Red, Green and Blue
Post by: Kitty Hello on 2009-Sep-28
there is GLBasic code for that.
http://www.glbasic.com/forum/index.php?topic=1637.0 (http://www.glbasic.com/forum/index.php?topic=1637.0)
Title: Re: Seperate colour into Red, Green and Blue
Post by: MrTAToad on 2009-Sep-28
Mine is/should be a bit more efficient  =D