diff options
Diffstat (limited to 'src/user/highway/line.c')
-rw-r--r-- | src/user/highway/line.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/src/user/highway/line.c b/src/user/highway/line.c index 5d1e543..3bc3bf2 100644 --- a/src/user/highway/line.c +++ b/src/user/highway/line.c @@ -12,18 +12,33 @@ #define LINE_SIZE 4096 static char line[LINE_SIZE]; -static inline uint8_t hex_to_int(char ch) { +static inline uint8_t hex_digit_to_int(char ch) { return ch - (ch <= '9' ? '0' : 'a' - 10); } +static inline uint8_t hex_byte_to_int(const char *ch) { + return (hex_digit_to_int(ch[0]) << 4) | hex_digit_to_int(ch[1]); +} + +static inline _pixel_t hex_to_pixel(const char *ch) { + return (_pixel_t){ + .r = hex_byte_to_int(ch), + .g = hex_byte_to_int(ch + 2), + .b = hex_byte_to_int(ch + 4) + }; +} + void ensure_color() { - const struct no_null_sn *color = get_var((struct no_null_sn){.data = "_color", .length = 6}); - //fgbg - if (color) - term_set_color( - (hex_to_int(color->data[0]) << 4) | hex_to_int(color->data[1]), - (hex_to_int(color->data[2]) << 4) | hex_to_int(color->data[3]) - ); + const struct no_null_sn *color; +get_color: + color = get_var((struct no_null_sn){.data = "_color", .length = 6}); + if (color && (color->length == 12)) + //rgb, fgbg + term_set_color(hex_to_pixel(color->data), hex_to_pixel(color->data + 6)); + else { + new_color(); + goto get_color; + } } static void line_replace(const char *from) { |