HUE32: 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 |
||
Line 20: | Line 20: | ||
:* However, this function is not suitable for the HSL (L=Lightness) colorspace, which is widely used in the Web/CSS. | :* However, this function is not suitable for the HSL (L=Lightness) colorspace, which is widely used in the Web/CSS. | ||
;Precision drawbacks | ;Precision drawbacks | ||
:* When converting between colorspaces, rounding errors can occur. While the HSB colorspace has virtually infinite precision | :* When converting between colorspaces, rounding errors can occur. | ||
:* | :* While the HSB colorspace has virtually infinite precision using floating point values, RGB is limited to 8-bit integers (0-255) only, which can lead to quantization errors. | ||
:* In fact, not all colors in HSB can be accurately represented in RGB, but the opposite is possible. | |||
:* It can be guaranteed, that the [[_HUE32]], [[_SATURATION32]] and [[_BRIGHTNESS32]] values retrieved from any arbitrary RGB color will reproduce the exact same RGB color when passed back through [[_HSB32]]. | |||
Line 40: | Line 42: | ||
{{CodeStart}} | {{CodeStart}} | ||
{{Cl|PRINT}} {{Text|<nowiki>"Creating a color using the HSB colorspace..."</nowiki>|#FFB100}} | {{Cl|PRINT}} {{Text|<nowiki>"Creating a color using the HSB colorspace..."</nowiki>|#FFB100}} | ||
c~& = {{Cl|_HSB32}}({{Text|90|#F580B1}}, {{Text|75|#F580B1}}, {{Text|65|#F580B1}}) | c~& = {{Cl|_HSB32}}({{Text|90|#F580B1}}, {{Text|75|#F580B1}}, {{Text|65|#F580B1}}) | ||
{{Cl|PRINT}} {{Text|<nowiki>"_HSB32( 90, 75, 65 ) = _RGB32("</nowiki>|#FFB100}}; {{Cl|_RED32}}(c~&); {{Text|<nowiki>","</nowiki>|#FFB100}}; {{Cl|_GREEN32}}(c~&); {{Text|<nowiki>","</nowiki>|#FFB100}}; {{Cl|_BLUE32}}(c~&); {{Text|<nowiki>")"</nowiki>|#FFB100}} | {{Cl|PRINT}} {{Text|<nowiki>"_HSB32( 90, 75, 65 ) = _RGB32("</nowiki>|#FFB100}}; {{Cl|_RED32}}(c~&); {{Text|<nowiki>","</nowiki>|#FFB100}}; {{Cl|_GREEN32}}(c~&); {{Text|<nowiki>","</nowiki>|#FFB100}}; {{Cl|_BLUE32}}(c~&); {{Text|<nowiki>")"</nowiki>|#FFB100}} | ||
{{Cl|PRINT}} | {{Cl|PRINT}} | ||
{{Cl|PRINT}} {{Text|<nowiki>"back to HSB values (notice the precision loss)..."</nowiki>|#FFB100}} | {{Cl|PRINT}} {{Text|<nowiki>"back to HSB values (notice the precision loss)..."</nowiki>|#FFB100}} | ||
{{Cl|PRINT}} {{Text|<nowiki>"Hue.......:"</nowiki>|#FFB100}}; {{Cl|_HUE32}}(c~&) | {{Cl|PRINT}} {{Text|<nowiki>"Hue.......:"</nowiki>|#FFB100}}; {{Cl|_HUE32}}(c~&) | ||
{{Cl|PRINT}} {{Text|<nowiki>"Saturation:"</nowiki>|#FFB100}}; {{Cl|_SATURATION32}}(c~&) | {{Cl|PRINT}} {{Text|<nowiki>"Saturation:"</nowiki>|#FFB100}}; {{Cl|_SATURATION32}}(c~&) | ||
{{Cl|PRINT}} {{Text|<nowiki>"Brightness:"</nowiki>|#FFB100}}; {{Cl|_BRIGHTNESS32}}(c~&) | {{Cl|PRINT}} {{Text|<nowiki>"Brightness:"</nowiki>|#FFB100}}; {{Cl|_BRIGHTNESS32}}(c~&) | ||
{{Cl|PRINT}} | {{Cl|PRINT}} | ||
{{Cl|PRINT}} {{Text|<nowiki>"but with CINT() we can get back the original values..."</nowiki>|#FFB100}} | {{Cl|PRINT}} {{Text|<nowiki>"but with CINT() we can get back the original values..."</nowiki>|#FFB100}} | ||
{{Cl|PRINT}} {{Text|<nowiki>"Hue.......:"</nowiki>|#FFB100}}; {{Cl|CINT}}({{Cl|_HUE32}}(c~&)) | {{Cl|PRINT}} {{Text|<nowiki>"Hue.......:"</nowiki>|#FFB100}}; {{Cl|CINT}}({{Cl|_HUE32}}(c~&)) | ||
{{Cl|PRINT}} {{Text|<nowiki>"Saturation:"</nowiki>|#FFB100}}; {{Cl|CINT}}({{Cl|_SATURATION32}}(c~&)) | {{Cl|PRINT}} {{Text|<nowiki>"Saturation:"</nowiki>|#FFB100}}; {{Cl|CINT}}({{Cl|_SATURATION32}}(c~&)) | ||
{{Cl|PRINT}} {{Text|<nowiki>"Brightness:"</nowiki>|#FFB100}}; {{Cl|CINT}}({{Cl|_BRIGHTNESS32}}(c~&)) | {{Cl|PRINT}} {{Text|<nowiki>"Brightness:"</nowiki>|#FFB100}}; {{Cl|CINT}}({{Cl|_BRIGHTNESS32}}(c~&)) | ||
{{Cl|END}} | {{Cl|END}} |
Revision as of 18:47, 30 January 2025
The _HUE32 function returns the hue value (HSB colorspace) of a given 32-bit ARGB color.
Syntax
- hue# = _HUE32(argbColor~&)
Parameters
- argbColor~& is the 32-bit ARGB color value to retrieve the hue value from.
Description
- The value returned is of type DOUBLE in the range 0 to 360 degrees, use CINT to work with integers only.
- The color wheel starts with red(0), turns to yellow(60), green(120), cyan(180), blue(240), magenta(300) to red(360) again.
- Mixed colors are represented by values between those 6 base color angles.
- Naming differences
-
- The HSB (B=Brightness) colorspace is also known as HSV (V=Value) and sometimes even called HSI (I=Intensity), but that's all just different names for the same thing.
- However, this function is not suitable for the HSL (L=Lightness) colorspace, which is widely used in the Web/CSS.
- Precision drawbacks
-
- When converting between colorspaces, rounding errors can occur.
- While the HSB colorspace has virtually infinite precision using floating point values, RGB is limited to 8-bit integers (0-255) only, which can lead to quantization errors.
- In fact, not all colors in HSB can be accurately represented in RGB, but the opposite is possible.
- It can be guaranteed, that the _HUE32, _SATURATION32 and _BRIGHTNESS32 values retrieved from any arbitrary RGB color will reproduce the exact same RGB color when passed back through _HSB32.
Availability
Examples
PRINT "Creating a color using the HSB colorspace..." c~& = _HSB32(90, 75, 65) PRINT "_HSB32( 90, 75, 65 ) = _RGB32("; _RED32(c~&); ","; _GREEN32(c~&); ","; _BLUE32(c~&); ")" PRINT PRINT "back to HSB values (notice the precision loss)..." PRINT "Hue.......:"; _HUE32(c~&) PRINT "Saturation:"; _SATURATION32(c~&) PRINT "Brightness:"; _BRIGHTNESS32(c~&) PRINT PRINT "but with CINT() we can get back the original values..." PRINT "Hue.......:"; CINT(_HUE32(c~&)) PRINT "Saturation:"; CINT(_SATURATION32(c~&)) PRINT "Brightness:"; CINT(_BRIGHTNESS32(c~&)) END |
See also