BSB Developer Docs
Loading...
Searching...
No Matches
color.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <stdint.h>
9#include <stddef.h>
10#include <stdbool.h>
11
12#ifdef __cplusplus
13extern "C" {
14#endif
15
19#define COLOR_MAKE_RGB(rv, gv, bv) {.b = (bv), .g = (gv), .r = (rv), .a = 255}
20
24#define COLOR_MAKE_RGBA(rv, gv, bv, av) {.b = (bv), .g = (gv), .r = (rv), .a = (av)}
25
29#define COLOR_MAKE_HEX(hex) \
30 {.b = (hex) & 0xFF, .g = ((hex) >> 8) & 0xFF, .r = ((hex) >> 16) & 0xFF, .a = 255}
31
35#define COLOR_MAKE_HEXA(hexa) \
36 {.a = (hexa) & 0xFF, \
37 .b = ((hexa) >> 8) & 0xFF, \
38 .g = ((hexa) >> 16) & 0xFF, \
39 .r = ((hexa) >> 24) & 0xFF}
40
42typedef struct {
43 uint8_t b;
44 uint8_t g;
45 uint8_t r;
46 uint8_t a;
47} Color;
48
50typedef struct {
51 uint8_t h;
52 uint8_t s;
53 uint8_t v;
54 uint8_t a;
55} ColorHsv;
56
65
73Color color_hex_to_rgb(uint32_t hex);
74
82Color color_hexa_to_rgb(uint32_t hexa);
83
92bool color_parse_hex_string(const char* hex, Color* color_out);
93
102bool color_parse_hexa_string(const char* hexa, Color* color_out);
103
111uint8_t color_rgb_to_l8(Color color);
112
120void color_buf_l8_to_l4(void* dst, const void* src, size_t size);
121
122#ifdef __cplusplus
123}
124#endif
Color color_hexa_to_rgb(uint32_t hexa)
Convert a HEX 0xRRGGBBAA representation to an RGB color.
Definition color.c:83
Color color_hex_to_rgb(uint32_t hex)
Convert a HEX 0xRRGGBB representation to an RGB color.
Definition color.c:70
bool color_parse_hex_string(const char *hex, Color *color_out)
Convert a HEX "#RRGGBB" representation to an RGB color.
Definition color.c:94
bool color_parse_hexa_string(const char *hexa, Color *color_out)
Convert a HEX "#RRGGBBAA" representation to an RGB color.
Definition color.c:104
void color_buf_l8_to_l4(void *dst, const void *src, size_t size)
Convert an L8-encoded color data into L4.
Definition color.c:122
uint8_t color_rgb_to_l8(Color color)
Convert an RGB color to an L8 luminance value.
Definition color.c:114
Color color_hsv_to_rgb(ColorHsv hsv)
Convert HSV color to RGB color.
Definition color.c:9
HSV color structure.
Definition color.h:50
uint8_t a
Alpha component.
Definition color.h:54
uint8_t s
Saturation component.
Definition color.h:52
uint8_t v
Value component.
Definition color.h:53
uint8_t h
Hue component.
Definition color.h:51
RGB color structure.
Definition color.h:42
uint8_t a
Alpha component.
Definition color.h:46
uint8_t g
Green component.
Definition color.h:44
uint8_t b
Blue component.
Definition color.h:43
uint8_t r
Red component.
Definition color.h:45