From 396d7d303d3bf0e796d0c817883ec1dec928352a Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Wed, 29 Apr 2020 15:26:21 +0200 Subject: Some work on the libgui --- src/userspace/libgui/util.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/userspace/libgui/util.c (limited to 'src/userspace/libgui/util.c') diff --git a/src/userspace/libgui/util.c b/src/userspace/libgui/util.c new file mode 100644 index 0000000..5019175 --- /dev/null +++ b/src/userspace/libgui/util.c @@ -0,0 +1,33 @@ +#include +#include + +void gui_convert_color(u32 *color_array, u32 color) +{ + u8 red = (u8)((color >> 16) & 255); + u8 green = (u8)((color >> 8) & 255); + u8 blue = (u8)(color & 255); + + if ((vbe_bpl << 3) == 8) { + u32 new_color = + ((red * 7 / 255) << 5) + ((green * 7 / 255) << 2) + (blue * 3 / 255); + color_array[0] = (new_color >> 16) & 255; + color_array[1] = (new_color >> 8) & 255; + color_array[2] = new_color & 255; + } else if ((vbe_bpl << 3) == 16) { + u32 new_color = + (((red & 0b11111000) << 8) + ((green & 0b11111100) << 3) + (blue >> 3)); + color_array[0] = (new_color >> 16) & 255; + color_array[1] = (new_color >> 8) & 255; + color_array[2] = new_color & 255; + } else if ((vbe_bpl << 3) == 24 || (vbe_bpl << 3) == 32) { + color_array[0] = red; + color_array[1] = green; + color_array[2] = blue; + } +} + +void gui_set_color(u32 color) +{ + gui_convert_color(terminal_color, color); + gui_convert_color(terminal_background, gui_black); +} \ No newline at end of file -- cgit v1.2.3