RGB: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
No edit summary |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:_RGB}} | {{DISPLAYTITLE:_RGB}} | ||
The [[_RGB]] function returns the closest palette attribute index (legacy SCREEN modes) OR the [[LONG]] 32-bit color value (32-bit screens). | The [[_RGB]] function returns the closest palette attribute index (legacy SCREEN modes) OR the [[LONG]] 32-bit color value (32-bit screens). | ||
Line 8: | Line 8: | ||
{{PageDescription}} | {{PageDescription}} | ||
* The value returned is either the closest color attribute number or a 32-bit [[_UNSIGNED]] [[LONG]] color value. | * The value returned is either the closest color attribute number or a 32-bit [[_UNSIGNED]] [[LONG]] color value. | ||
* '''Return variable types must be [[LONG]] or resulting color may lose the [[_BLUE]] value.''' | * '''Return variable types must be [[LONG]] or resulting color may lose the [[_BLUE]] value.''' | ||
* {{Parameter|red&}} specifies the red component intensity from 0 to 255. | * {{Parameter|red&}} specifies the red component intensity from 0 to 255. | ||
Line 14: | Line 14: | ||
* {{Parameter|blue&}} specifies the blue component intensity from 0 to 255. | * {{Parameter|blue&}} specifies the blue component intensity from 0 to 255. | ||
* Intensity values outside the valid range are clipped. | * Intensity values outside the valid range are clipped. | ||
* Returns [[LONG]] 32-bit hexadecimal values from '''&HFF{{ | * Returns [[LONG]] 32-bit hexadecimal values from '''&HFF{{Text|00|red}}{{Text|00|green}}{{Text|00|blue}}''' to '''&HFF{{Text|FF|red}}{{Text|FF|green}}{{Text|FF|blue}}''', always with full [[_ALPHA]]. | ||
* When [[LONG]] values are [[PUT]] to file, the ARGB values become BGRA. Use [[LEFT$]]([[MKL$]]({{Parameter|colorIndex~&}}), 3) to place 3 colors. | * When [[LONG]] values are [[PUT]] to file, the ARGB values become BGRA. Use [[LEFT$]]([[MKL$]]({{Parameter|colorIndex~&}}), 3) to place 3 colors. | ||
* If the {{Parameter|imageHandle&}} is omitted the image is assumed to be the current [[_DEST|destination]] or [[SCREEN]] page. | * If the {{Parameter|imageHandle&}} is omitted the image is assumed to be the current [[_DEST|destination]] or [[SCREEN]] page. | ||
Line 22: | Line 22: | ||
{{PageExamples}} | {{PageExamples}} | ||
''Example:'' Converting the color port RGB intensity palette values 0 to 63 to 32 bit hexadecimal values. | ''Example:'' Converting the color port RGB intensity palette values 0 to 63 to 32 bit hexadecimal values. | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|SCREEN}} 12 | {{Cl|SCREEN}} 12 | ||
Line 34: | Line 34: | ||
{{Cl|COLOR}} attribute | {{Cl|COLOR}} attribute | ||
{{Cl|PRINT}} "{{Cl|COLOR}}" + {{Cl|STR$}}({{Cl|_RGB}}(red, grn, blu)) + " = " + hex32$(attribute) 'closest attribute | {{Cl|PRINT}} "{{Cl|COLOR}}" + {{Cl|STR$}}({{Cl|_RGB}}(red, grn, blu)) + " = " + hex32$(attribute) 'closest attribute | ||
{{Cl|NEXT}} | {{Cl|NEXT}} | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{OutputStart}}{{ | {{OutputStart}}{{Text|COLOR 1 <nowiki>=</nowiki> &HFF0000A8|#0000A8}} | ||
{{ | {{Text|COLOR 2 <nowiki>=</nowiki> &HFF00A800|#00A800}} | ||
{{ | {{Text|COLOR 3 <nowiki>=</nowiki> &HFF00A8A8|#00A8A8}} | ||
{{ | {{Text|COLOR 4 <nowiki>=</nowiki> &HFFA80000|#A80000}} | ||
{{ | {{Text|COLOR 5 <nowiki>=</nowiki> &HFFA800A8|#A800A8}} | ||
{{ | {{Text|COLOR 6 <nowiki>=</nowiki> &HFFA85400|#A85400}} | ||
{{ | {{Text|COLOR 7 <nowiki>=</nowiki> &HFFA8A8A8|#A8A8A8}} | ||
{{ | {{Text|COLOR 8 <nowiki>=</nowiki> &HFF545454|#545454}} | ||
{{ | {{Text|COLOR 9 <nowiki>=</nowiki> &HFF5454FC|#5454FC}} | ||
{{ | {{Text|COLOR 10 <nowiki>=</nowiki> &HFF54FC54|#54FC54}} | ||
{{ | {{Text|COLOR 11 <nowiki>=</nowiki> &HFF54FCFC|#54FCFC}} | ||
{{ | {{Text|COLOR 12 <nowiki>=</nowiki> &HFFFC5454|#FC5454}} | ||
{{ | {{Text|COLOR 13 <nowiki>=</nowiki> &HFFFC54FC|#FC54FC}} | ||
{{ | {{Text|COLOR 14 <nowiki>=</nowiki> &HFFFCFC54|#FCFC54}} | ||
{{ | {{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 60: | Line 60: | ||
* [[_LOADIMAGE]], [[_NEWIMAGE]] | * [[_LOADIMAGE]], [[_NEWIMAGE]] | ||
* [[HEX$ 32 Bit Values]], [[POINT]] | * [[HEX$ 32 Bit Values]], [[POINT]] | ||
* [[ | * [[SaveImage SUB]] | ||
* [http://www.w3schools.com/html/html_colornames.asp Hexadecimal Color Values] | * [http://www.w3schools.com/html/html_colornames.asp Hexadecimal Color Values] | ||
{{PageNavigation}} | {{PageNavigation}} |
Latest revision as of 20:04, 5 January 2024
The _RGB function returns the closest palette attribute index (legacy SCREEN modes) OR the LONG 32-bit color value (32-bit screens).
Syntax
- colorIndex~& = _RGB(red&, green&, blue&[, imageHandle&])
Description
- The value returned is either the closest color attribute number or a 32-bit _UNSIGNED LONG color value.
- Return variable types must be LONG or resulting color may lose the _BLUE value.
- red& specifies the red component intensity from 0 to 255.
- green& specifies the green component intensity from 0 to 255.
- blue& specifies the blue component intensity from 0 to 255.
- Intensity values outside the valid range are clipped.
- Returns LONG 32-bit hexadecimal values from &HFF000000 to &HFFFFFFFF, always with full _ALPHA.
- When LONG values are PUT to file, the ARGB values become BGRA. Use LEFT$(MKL$(colorIndex~&), 3) to place 3 colors.
- If the imageHandle& is omitted the image is assumed to be the current destination or SCREEN page.
- Colors returned are always opaque as the transparency value is always 255. Use _ALPHA or _CLEARCOLOR to change it.
- NOTE: Default 32-bit backgrounds are clear black or _RGBA(0, 0, 0, 0). Use CLS to make the black opaque.
Examples
Example: 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.
See also
- _RGBA, _RGB32, _RGBA32
- _RED, _GREEN, _BLUE
- _LOADIMAGE, _NEWIMAGE
- HEX$ 32 Bit Values, POINT
- SaveImage SUB
- Hexadecimal Color Values