RGB32: Difference between revisions

From QB64 Phoenix Edition Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 29: Line 29:
* '''Return variable types must be [[_UNSIGNED]] [[LONG]] or [[LONG]], otherwise resulting color may lose the [[_BLUE]] value.'''
* '''Return variable types must be [[_UNSIGNED]] [[LONG]] or [[LONG]], otherwise resulting color may lose the [[_BLUE]] value.'''
* Parameter values outside of the 0 to 255 range are clipped.
* Parameter values outside of the 0 to 255 range are clipped.
* Returns [[LONG]] 32 bit hexadecimal values from '''&H00{{text|00|red}}{{text|00|green}}{{text|00|blue}}''' to '''&HFF{{text|FF|red}}{{text|FF|green}}{{text|FF|blue}}'''.
* Returns [[LONG]] 32 bit hexadecimal values from '''&H00{{Text|00|red}}{{Text|00|green}}{{Text|00|blue}}''' to '''&HFF{{Text|FF|red}}{{Text|FF|green}}{{Text|FF|blue}}'''.
* When [[LONG]] values are [[PUT]] to file, the ARGB values become BGRA. Use [[LEFT$]]([[MKL$]]({{Parameter|color32value~&}}), 3) to place 3 colors.
* When [[LONG]] values are [[PUT]] to file, the ARGB values become BGRA. Use [[LEFT$]]([[MKL$]]({{Parameter|color32value~&}}), 3) to place 3 colors.
* '''NOTE: Default 32-bit backgrounds are clear black or [[_RGB32]](0, 0). Use [[CLS]] to make the black opaque.'''
* '''NOTE: Default 32-bit backgrounds are clear black or [[_RGB32]](0, 0). Use [[CLS]] to make the black opaque.'''
Line 53: Line 53:
{{Cl|NEXT}}
{{Cl|NEXT}}
{{CodeEnd}}
{{CodeEnd}}
{{OutputStart}}{{text|COLOR 1 <nowiki>=</nowiki> &HFF0000A8|#0000A8}}
{{OutputStart}}{{Text|COLOR 1 <nowiki>=</nowiki> &HFF0000A8|#0000A8}}
{{text|COLOR 2 <nowiki>=</nowiki> &HFF00A800|#00A800}}
{{Text|COLOR 2 <nowiki>=</nowiki> &HFF00A800|#00A800}}
{{text|COLOR 3 <nowiki>=</nowiki> &HFF00A8A8|#00A8A8}}
{{Text|COLOR 3 <nowiki>=</nowiki> &HFF00A8A8|#00A8A8}}
{{text|COLOR 4 <nowiki>=</nowiki> &HFFA80000|#A80000}}
{{Text|COLOR 4 <nowiki>=</nowiki> &HFFA80000|#A80000}}
{{text|COLOR 5 <nowiki>=</nowiki> &HFFA800A8|#A800A8}}
{{Text|COLOR 5 <nowiki>=</nowiki> &HFFA800A8|#A800A8}}
{{text|COLOR 6 <nowiki>=</nowiki> &HFFA85400|#A85400}}
{{Text|COLOR 6 <nowiki>=</nowiki> &HFFA85400|#A85400}}
{{text|COLOR 7 <nowiki>=</nowiki> &HFFA8A8A8|#A8A8A8}}
{{Text|COLOR 7 <nowiki>=</nowiki> &HFFA8A8A8|#A8A8A8}}
{{text|COLOR 8 <nowiki>=</nowiki> &HFF545454|#545454}}
{{Text|COLOR 8 <nowiki>=</nowiki> &HFF545454|#545454}}
{{text|COLOR 9 <nowiki>=</nowiki> &HFF5454FC|#5454FC}}
{{Text|COLOR 9 <nowiki>=</nowiki> &HFF5454FC|#5454FC}}
{{text|COLOR 10 <nowiki>=</nowiki> &HFF54FC54|#54FC54}}
{{Text|COLOR 10 <nowiki>=</nowiki> &HFF54FC54|#54FC54}}
{{text|COLOR 11 <nowiki>=</nowiki> &HFF54FCFC|#54FCFC}}
{{Text|COLOR 11 <nowiki>=</nowiki> &HFF54FCFC|#54FCFC}}
{{text|COLOR 12 <nowiki>=</nowiki> &HFFFC5454|#FC5454}}
{{Text|COLOR 12 <nowiki>=</nowiki> &HFFFC5454|#FC5454}}
{{text|COLOR 13 <nowiki>=</nowiki> &HFFFC54FC|#FC54FC}}
{{Text|COLOR 13 <nowiki>=</nowiki> &HFFFC54FC|#FC54FC}}
{{text|COLOR 14 <nowiki>=</nowiki> &HFFFCFC54|#FCFC54}}
{{Text|COLOR 14 <nowiki>=</nowiki> &HFFFCFC54|#FCFC54}}
{{text|COLOR 15 <nowiki>=</nowiki> &HFFFCFCFC|#FCFCFC}}
{{Text|COLOR 15 <nowiki>=</nowiki> &HFFFCFCFC|#FCFCFC}}
{{OutputEnd}}
{{OutputEnd}}
:''Note:'' This procedure also shows how the returns from [[_RGB]] and [[_RGB32]] differ in a non-32 bit screen mode.
:''Note:'' This procedure also shows how the returns from [[_RGB]] and [[_RGB32]] differ in a non-32 bit screen mode.
Line 100: Line 100:
{{Cl|SLEEP}}
{{Cl|SLEEP}}
SYSTEM
SYSTEM
{{CodeEnd}}{{small|Code by Steve McNeill}}
{{CodeEnd}}
{{Small|Code by Steve McNeill}}





Revision as of 22:46, 11 February 2023

The _RGB32 function returns the 32-bit RGBA color value with specified red, green and blue component intensities and optional alpha.


Syntax

Original syntax:

color32value~& = _RGB32(red&, green&, blue&)

Alternative Syntax 2:

color32value~& = _RGB32(red&, green&, blue&, alpha&)

Alternative Syntax 3:

color32value~& = _RGB32(intensity&, alpha&)

Alternative Syntax 4:

color32value~& = _RGB32(intensity&)


Parameters

  • red& specifies the red LONG component intensity from 0 to 255.
  • green& specifies the green LONG component intensity from 0 to 255.
  • blue& specifies the blue LONG component intensity from 0 to 255.
  • alpha& specifies the alpha LONG component from 0 to 255.
  • intensity& specifies the red, green and blue LONG components intensity from 0 to 255 simultaneously, to generate a shade of gray.


Description

  • The value returned is always a 32-bit _UNSIGNED LONG color value, as is the POINT value.
  • Return variable types must be _UNSIGNED LONG or LONG, otherwise resulting color may lose the _BLUE value.
  • Parameter values outside of the 0 to 255 range are clipped.
  • Returns LONG 32 bit hexadecimal values from &H00000000 to &HFFFFFFFF.
  • When LONG values are PUT to file, the ARGB values become BGRA. Use LEFT$(MKL$(color32value~&), 3) to place 3 colors.
  • NOTE: Default 32-bit backgrounds are clear black or _RGB32(0, 0). Use CLS to make the black opaque.


Availability

  • Alternative syntaxes available with version 1.3 and up.


Examples

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

SCREEN 12
DIM hex32$(15)
FOR attribute = 1 TO 15
  OUT &H3C7, attribute      'set color attribute to read
  red = INP(&H3C9) * 4      'multiply by 4 to convert intensity to 0 to 255 RGB values
  grn = INP(&H3C9) * 4
  blu = INP(&H3C9) * 4
  hex32$(attribute) = "&H" + HEX$(_RGB32(red, grn, blu))   'always returns the 32 bit value
  COLOR attribute
  PRINT "COLOR" + STR$(_RGB(red, grn, blu)) + " = " + hex32$(attribute)  'closest attribute
NEXT
COLOR 1 = &HFF0000A8
COLOR 2 = &HFF00A800
COLOR 3 = &HFF00A8A8
COLOR 4 = &HFFA80000
COLOR 5 = &HFFA800A8
COLOR 6 = &HFFA85400
COLOR 7 = &HFFA8A8A8
COLOR 8 = &HFF545454
COLOR 9 = &HFF5454FC
COLOR 10 = &HFF54FC54
COLOR 11 = &HFF54FCFC
COLOR 12 = &HFFFC5454
COLOR 13 = &HFFFC54FC
COLOR 14 = &HFFFCFC54
COLOR 15 = &HFFFCFCFC
Note: This procedure also shows how the returns from _RGB and _RGB32 differ in a non-32 bit screen mode.


Example 2: Working with 32 bit colors.

SCREEN _NEWIMAGE(640, 480, 32)

CLS , _RGB32(0, 0, 128) 'deep blue background

LINE (100, 100)-(540, 380), _RGB(255, 0, 0), BF ' a red box
LINE (200, 200)-(440, 280), _RGB(0, 255, 0), BF ' a green box


SLEEP 'Just so we can see our pretty background before we print anything on it.


COLOR _RGB32(255, 255, 255), 0 'White on NO BACKGROUND

FOR i = 1 TO 10
    PRINT "This is just a whole bunch of happy nothing!  Happy World!!"
NEXT
PRINT: PRINT: PRINT:

COLOR 0, _RGB32(0, 0, 0) 'And here, we're going with NO COLOR text, with a BLACK background.
'Notice how this doesn't change the color on the screen at all, where the text is, but does toss a black background to it.

LOCATE , 15: PRINT "NOTICE HOW OUR 0 COLOR WORKS?"
PRINT
LOCATE , 15: PRINT "NEAT, HUH?"
SLEEP
SYSTEM
Code by Steve McNeill


Example 3: Comparing the output of the new _RGB32 syntaxes (starting with version 1.3) and their equivalents in previous versions.

SCREEN _NEWIMAGE(400, 400, 32)

COLOR _RGB32(255, 255, 255)
PRINT "White"
COLOR _RGB32(255)
PRINT "White, too, but with less typing"
PRINT

COLOR _RGB32(80, 80, 80)
PRINT "Dark gray"
COLOR _RGB32(80)
PRINT "Same gray, but with less typing"
PRINT

COLOR _RGBA32(255, 255, 255, 120)
PRINT "White with alpha of 120 (out of 255)"
COLOR _RGB32(255, 120)
PRINT "White with alpha of 120 - but with less typing"
PRINT

COLOR _RGBA32(255, 0, 255, 110)
PRINT "Magenta, 110 alpha"
COLOR _RGB32(255, 0, 255, 110)
PRINT "Magenta too, 110 alpha - but with less typing"


See also



Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage