Difference between revisions of "RGB"

From QB64 Wiki
Jump to navigation Jump to search
imported>Clippy
m
imported>Clippy
m
Line 11: Line 11:
 
* Valid component intensity values range from 0 (no intensity; color not present) to 255 (full intensity).
 
* Valid component intensity values range from 0 (no intensity; color not present) to 255 (full intensity).
 
* Values outside the valid range are clipped.
 
* Values outside the valid range are clipped.
 +
 +
 +
''Example:'' Converting the color port RGB intensity palette values 0 to 63 to 32 bit hexadecimal values.
 +
{{CodeStart}}
 +
{{Cl|SCREEN}} 12
 +
 +
{{Cl|FOR...NEXT|FOR}} attribute = 1 {{Cl|TO}} 15
 +
  {{Cl|OUT}} {{Cl|&H}}3C7, attribute      'set color attribute to read
 +
  red = {{Cl|INP}}({{Cl|&H}}3C9) * 4      'convert port setting to 32 bit values
 +
  grn = {{Cl|INP}}({{Cl|&H}}3C9) * 4
 +
  blu = {{Cl|INP}}({{Cl|&H}}3C9) * 4
 +
  hex32$ = {{Cl|HEX$}}({{Cl|_RGB32}}(red, grn, blu))                      'always returns the 32 bit value
 +
  {{Cl|PRINT}} "{{Cl|COLOR}}" + {{Cl|STR$}}({{Cl|_RGB}}(red, grn, blu)) + " = {{Cl|&H}}" + hex32$  'returns closest attribute
 +
{{Cl|NEXT}} '' ''
 +
{{CodeEnd}}
 +
:''Note:'' This procedure also shows how the returns from [[_RGB]] and [[_RGB32]] differ in a non-32 bit screen mode.
  
  

Revision as of 16:48, 25 May 2011

The _RGB function returns the closest palette index OR the 32 bit color value in 32 bit screens only.


colorindex& = _RGB(red, green, blue[, image_handle])


  • The value returned is either the closest color attribute number or a 32 bit LONG color value.
  • red& specifies the red component intensity.
  • green& specifies the green component intensity.
  • blue& specifies the blue component intensity.
  • Valid component intensity values range from 0 (no intensity; color not present) to 255 (full intensity).
  • Values outside the valid range are clipped.


Example: Converting the color port RGB intensity palette values 0 to 63 to 32 bit hexadecimal values.

SCREEN 12 FOR attribute = 1 TO 15 OUT &H3C7, attribute 'set color attribute to read red = INP(&H3C9) * 4 'convert port setting to 32 bit values grn = INP(&H3C9) * 4 blu = INP(&H3C9) * 4 hex32$ = HEX$(_RGB32(red, grn, blu)) 'always returns the 32 bit value PRINT "COLOR" + STR$(_RGB(red, grn, blu)) + " = &H" + hex32$ 'returns closest attribute NEXT

Note: This procedure also shows how the returns from _RGB and _RGB32 differ in a non-32 bit screen mode.


See also



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page