Functions | |
| void | hsv_to_rgb (float h, float s, float v, uint8_t *r, uint8_t *g, uint8_t *b) |
| HSV → RGB conversion helper. | |
| void | qualitative_colormap (uint8_t value, uint8_t *r, uint8_t *g, uint8_t *b) |
| Maps a given value to a qualitative colormap. | |
| void | rainbow_colormap (uint8_t value, uint8_t *r, uint8_t *g, uint8_t *b) |
| Maps a given value to a rainbow colormap with smooth interpolation. | |
| void hsv_to_rgb | ( | float | h, |
| float | s, | ||
| float | v, | ||
| uint8_t * | r, | ||
| uint8_t * | g, | ||
| uint8_t * | b ) |
HSV → RGB conversion helper.
This routine converts a colour expressed in HSV (Hue, Saturation, Value) space to its equivalent RGB (Red, Green, Blue) representation with 8-bit integer channels (0 – 255).
The implementation follows the classical algorithm described in Foley & van Dam Computer Graphics: Principles and Practice
(section “Converting HSV to RGB”), using the “hexcone” model:
h) is interpreted as an angle around the colour wheel, measured in degrees in [0 … 360). s) and Value (v) are floating-point fractions in [0.0 … 1.0], where 0 is fully desaturated (grey / black) and 1 is maximum chroma / brightness. Internally, the algorithm:
The six hue sectors [0°,60°), [60°,120°), …, [300°,360°) are handled explicitly to avoid expensive divisions at run-time (important on the robot’s MCU). The resulting floating-point RGB components are finally scaled to integers in 0 … 255 and written back through the output pointers.
| [in] | h | Hue angle in degrees (wraps outside [0,360) without UB) |
| [in] | s | Saturation fraction in the closed interval [0.0, 1.0] |
| [in] | v | Value / brightness fraction in [0.0, 1.0] |
| [out] | r | Pointer to destination for the red component (0 – 255) |
| [out] | g | Pointer to destination for the green component (0 – 255) |
| [out] | b | Pointer to destination for the blue component (0 – 255) |
| void qualitative_colormap | ( | uint8_t const | value, |
| uint8_t * | r, | ||
| uint8_t * | g, | ||
| uint8_t * | b ) |
Maps a given value to a qualitative colormap.
This function assigns a fixed color from a predefined qualitative colormap based on the provided value. The colormap is defined as an array of 10 distinct colors. The input value is mapped to a color index using modulo arithmetic, ensuring that it wraps around if the value exceeds the number of available colors.
| value | The input value used to select a color from the colormap. |
| r | Pointer to a uint8_t variable where the red component of the selected color will be stored. |
| g | Pointer to a uint8_t variable where the green component of the selected color will be stored. |
| b | Pointer to a uint8_t variable where the blue component of the selected color will be stored. |
| void rainbow_colormap | ( | uint8_t const | value, |
| uint8_t * | r, | ||
| uint8_t * | g, | ||
| uint8_t * | b ) |
Maps a given value to a rainbow colormap with smooth interpolation.
This function computes a rainbow color based on the input value. The value, expected in the range [0, 255], is normalized to a range [0, 6] to determine the color segment and the interpolation factor. Depending on the segment, the function interpolates between two adjacent colors in the rainbow spectrum.
The segments are as follows:
| value | The input value (0-255) that determines the color. |
| r | Pointer to a uint8_t variable where the red component of the computed color will be stored. |
| g | Pointer to a uint8_t variable where the green component of the computed color will be stored. |
| b | Pointer to a uint8_t variable where the blue component of the computed color will be stored. |