From aae9a4da8f3601b47633e3681f89661e1304d1c5 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Thu, 26 Jun 2008 16:20:07 -0400 Subject: [PATCH] Add api for messing with color palette in text mode This is important so we have more flexibility over what colors show up in the text splash --- TODO | 1 + src/libplybootsplash/ply-window.c | 80 +++++++++++++++++++++++++++++++ src/libplybootsplash/ply-window.h | 7 ++- 3 files changed, 87 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 5f3a0d2..81ee87c 100644 --- a/TODO +++ b/TODO @@ -9,3 +9,4 @@ - rotate boot.log per boot cycle (might be easiest to just fork/exec out to logrotate directly) - fix error handling. In particular, ply_open_module gets it completely wrong (replies on errno instead of dlerror()) - consider moving text code from ply-window to a ply-text-buffer analog of ply-frame-buffer +- restore text color palette on exit diff --git a/src/libplybootsplash/ply-window.c b/src/libplybootsplash/ply-window.c index 1e1f8c0..381d3c1 100644 --- a/src/libplybootsplash/ply-window.c +++ b/src/libplybootsplash/ply-window.c @@ -540,6 +540,86 @@ ply_window_get_foreground_color (ply_window_t *window) return window->foreground_color; } +static uint8_t * +ply_window_get_color_palette (ply_window_t *window) +{ + uint8_t *palette; + + palette = malloc (48); + + if (ioctl (window->tty_fd, GIO_CMAP, palette) < 0) + { + free (palette); + return NULL; + } + + return palette; +} + +static bool +ply_window_set_color_palette (ply_window_t *window, + uint8_t *palette) +{ + if (ioctl (window->tty_fd, PIO_CMAP, palette) < 0) + return false; + + return true; +} + +uint32_t +ply_window_get_color_hex_value (ply_window_t *window, + ply_window_color_t color) +{ + uint8_t *palette; + uint8_t red, green, blue; + uint32_t hex_value; + + assert (window != NULL); + assert (color >= 0 && color <= PLY_WINDOW_COLOR_WHITE); + + palette = ply_window_get_color_palette (window); + + if (palette == NULL) + return 0; + + red = (uint8_t) *(palette + 3 * color); + green = (uint8_t) *(palette + 3 * color + 1); + blue = (uint8_t) *(palette + 3 * color + 2); + free (palette); + + hex_value = red << 16 | green << 8 | blue; + + return hex_value; +} + +void +ply_window_set_color_hex_value (ply_window_t *window, + ply_window_color_t color, + uint32_t hex_value) +{ + uint8_t *palette; + uint8_t red, green, blue; + + assert (window != NULL); + assert (color >= 0 && color <= PLY_WINDOW_COLOR_WHITE); + + palette = ply_window_get_color_palette (window); + + if (palette == NULL) + return; + + red = (uint8_t) ((hex_value >> 16) & 0xff); + green = (uint8_t) ((hex_value >> 8) & 0xff); + blue = (uint8_t) (hex_value & 0xff); + + *(palette + 3 * color) = red; + *(palette + 3 * color + 1) = green; + *(palette + 3 * color + 2) = blue; + + ply_window_set_color_palette (window, palette); + free (palette); +} + void ply_window_hide_text_cursor (ply_window_t *window) { diff --git a/src/libplybootsplash/ply-window.h b/src/libplybootsplash/ply-window.h index 3d2c51f..a79d99b 100644 --- a/src/libplybootsplash/ply-window.h +++ b/src/libplybootsplash/ply-window.h @@ -97,10 +97,15 @@ void ply_window_set_background_color (ply_window_t *window, ply_window_color_t color); void ply_window_set_foreground_color (ply_window_t *window, ply_window_color_t color); - ply_window_color_t ply_window_get_background_color (ply_window_t *window); ply_window_color_t ply_window_get_foreground_color (ply_window_t *window); +uint32_t ply_window_get_color_hex_value (ply_window_t *window, + ply_window_color_t color); +void ply_window_set_color_hex_value (ply_window_t *window, + ply_window_color_t color, + uint32_t hex_value); + void ply_window_attach_to_event_loop (ply_window_t *window, ply_event_loop_t *loop); ply_frame_buffer_t *ply_window_get_frame_buffer (ply_window_t *window);