Color: Difference between revisions
| (One intermediate revision by the same user not shown) | |||
| Line 22: | Line 22: | ||
or obtained with bitshift operations: | or obtained with bitshift operations: | ||
{{code|1= | {{code|1= | ||
R = | R = rgb >> 16 & 0xff; | ||
G = | G = rgb >> 8 & 0xff; | ||
B = | B = rgb >> 0 & 0xff; | ||
}} | |||
===Alpha value=== | ===Alpha value=== | ||
Latest revision as of 12:33, 18 September 2026
Color is usually expressed as a combination of values that define a specific color. An example of such a format is RGB, in which three values represent the amount of red, blue, and green displayed respectively.
Many spatial components with attributes automatically have a "COLOR" attribute added to them, indicating the color used when the components are displayed. The value is the same as the color property of that component. When that color property is changed, the attribute is changed, and vice versa.
Color values can be configured in a couple of ways.
Single value format
For optimal compatibility between formats which only allow the reading and setting of a single value, the color can be read and stored as a single value as well. The numeric value corresponds to an RGB color value, calculated by combining the red, green and blue values of the desired color together, multiplied by powers of 256. The amount of red, green, and blue are values between 0 and 255, inclusive. These are added to a base value of -16777216.
An RGB color value for the Tygron Platform can be calculated as follows:
rgb = -16777216 + red * 65536 + green * 256 + blue
RGB values (with ranges of 0-255) can be calculated as follows:
R = (( rgb + 16777216 ) / 65536 ) % 256 G = (( rgb + 16777216 ) / 256 ) % 256 B = ( rgb + 16777216 ) % 256
or obtained with bitshift operations:
R = rgb >> 16 & 0xff; G = rgb >> 8 & 0xff; B = rgb >> 0 & 0xff;
Alpha value
The opacity of a color is controlled using the alpha channel.
An ARGB integer color value for the Tygron Platform can be calculated as follows, with the amount of red, green, blue and alpha values in the range 0 to 255:
if alpha >= 128: argb = alpha * 16777216 + red * 65536 + green * 256 + blue - 4294967296
otherwise: argb = alpha * 16777216 + red * 65536 + green * 256 + blue
Individual A R G B values, each ranging from 0 to 255, can be calculated as follows using the integer color value:
A = ((( (argb + 2147483648) % 4294967296 ) / 16777216 ) + 128) % 256 R = (( argb % 4294967296 ) / 65536 ) % 256 G = (( argb % 4294967296 ) / 256 ) % 256 B = ( argb % 4294967296 ) % 256
or obtained with bitshift operations:
A = argb >> 24 & 0xff; R = argb >> 16 & 0xff; G = argb >> 8 & 0xff; B = argb >> 0 & 0xff;
RGB(A) Attribute arrays
Using Attribute arrays, a color can also be written as a list of 3 separate values in a single attribute, representing red, green, and blue respectively. Any of these color values can range from 0 to 255. Optionally, a 4th value can be added representing the "alpha" of the color, which indicates the opacity. This value too can range from 0 (fully transparent) to 255 (fully opaque).
Red examples:
| name | attribute array values |
|---|---|
| red | 255 0 0 |
| semi transparent red | 255 0 0 128 |
| full transparent red | 255 0 0 0 |
| opaque red | 255 0 0 255 |
HEX format
When requesting an items Color by executing a Select color (TQL) query, the result is returned in a HEX format, such that it can be used directly in HTML. A hexadecimal color is specified with: #RRGGBB, where the RR (red), GG (green) and BB (blue) hexadecimal integers specify the components of the color. A hexadecimal number is represented by a number from 0 to 9 or by a letter A to F, where A represents the number 10 and F the number 15. Two hexadecimal numbers support 256 unique decimal numbers.
See also: HTML HEX Colors
Combo Overlay Functions
The Combo Overlay provides the following functions to convert between RGBA values and a Tygron Color value:
- COLOR: Create a color given a red, green and blue value. A fourth alpha value is optional.
- RED: Get a red channel value (0-255) for a legend color or pixel value.
- GREEN: Get a green channel value (0-255) for a legend color or pixel value.
- BLUE: Get a blue channel value (0-255) for a legend color or pixel value.
- ALPHA: Get an alpha channel value (0-255) for a legend color or pixel value.
Always use these functions for conversions instead of writing your own.
Notes
- For single value notation, including a transparency (alpha) value involves adding an additional value based on a base value of 16777216 (=256³). However, in this situation an integer roll-over may occur while calculating the required value, which leads to the slightly more complex formula.
See also
- Basement color (Function Value)
- Ground color (Function Value)
- Extra color (Function Value)
- Top color (Function Value)
- Roof color (Function Value)
- Color (Terrain Attribute)
- Color (Panel Attribute)
- Color (Area Attribute)