api
color_utils.ch
Declarations in color_utils.ch
3 declarationscss_parser
Declarations
Public only
hex_digit_to_int#
function
func hex_digit_to_int(c : char) : int
parse_css_hex_color#
function
func parse_css_hex_color(str : *char, len : size_t, outColor : *uint32_t) : bool
Parses a CSS hex color string into a 32-bit unsigned integer.
REQUIREMENT: str must not contain '#' symbol at the zero index
REQUIREMENT: str must of 3, 4, 6 or 8 in length
Acceptable formats: 3-digit (#RGB), 4-digit (#RGBA), 6-digit (#RRGGBB) or 8-digit (#RRGGBBAA).
The resulting 32-bit color is stored in 0xRRGGBBAA format, where the
alpha channel defaults to 0xFF if not provided.
Returns true on success, or false if the input is invalid.
print_color_hex#
function
func print_color_hex(color : uint32_t) : void
TOOO use snprintf to return a string instead
Prints the given color (stored as 0xRRGGBBAA) in the smallest valid CSS hex
representation.
For opaque colors (alpha == 0xFF):
- If each color channel can be expressed as a single hex digit (i.e. both
nibbles are identical), prints in 3-digit shorthand (#RGB).
- Otherwise, prints the full 6-digit form (#RRGGBB).
For colors with transparency:
- If each channel (including alpha) qualifies for shorthand, prints #RGBA.
- Otherwise, prints the full 8-digit form (#RRGGBBAA).