From df0d1cf7c2bcb6476f8774daa9cb26ecf54cb5c8 Mon Sep 17 00:00:00 2001 From: Andreas Stallinger Date: Wed, 22 Jul 2020 18:50:32 +0200 Subject: colored overlay: config options in man, split rgba split color_rgba into color_rgb and alpha added configuration options to man pages cleanup gitignore: the man pages output is now in the build directory, so there is no to ignore man pages individually --- .gitignore | 3 --- doc/imv.5.txt | 16 ++++++++++++ src/imv.c | 84 ++++++++++++++++++++++++++++++++++++++--------------------- 3 files changed, 70 insertions(+), 33 deletions(-) diff --git a/.gitignore b/.gitignore index 5008593..b022387 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,3 @@ imv *.o test_* build/ -imv.1 -imv.5 -doc/imv-msg.1 diff --git a/doc/imv.5.txt b/doc/imv.5.txt index bf19bf4..1c8c568 100644 --- a/doc/imv.5.txt +++ b/doc/imv.5.txt @@ -60,6 +60,22 @@ The *[options]* section accepts the following settings: expanded, so the output of commands can be used: '$(ls)' as can environment variables, including the ones accessible to imv's 'exec' command. +*overlay_text_color* = :: + Set the color for the text in the overlay. Is a 6-digit hexadecimal color + code. Defaults to 'ffffff'. + +*overlay_text_alpha* = :: + Set the alpha for the text in the overlay. Is a 2-digit hexadecimal color + code. Defaults to 'ff'. + +*overlay_background_color* = :: + Set the color for the background of the overlay. Is a 6-digit hexadecimal color + code. Defaults to '000000'. + +*overlay_background_alpha* = :: + Set the alpha for the background of the overlay. Is a 2-digit hexadecimal color + code. Defaults to 'c3'. + *recursively* = :: Load input paths recursively. Defaults to 'false'. diff --git a/src/imv.c b/src/imv.c index 10936fa..a451839 100644 --- a/src/imv.c +++ b/src/imv.c @@ -52,8 +52,8 @@ enum internal_event_type { COMMAND }; -struct color_rgba { - unsigned char r, g, b, a; +struct color_rgb { + unsigned char r, g, b; }; struct internal_event { @@ -93,8 +93,10 @@ struct imv { bool enabled; /* the user-specified format strings for the overlay*/ char *text; - struct color_rgba text_color; - struct color_rgba background_color; + struct color_rgb text_color; + unsigned char text_alpha; + struct color_rgb background_color; + unsigned char background_alpha; /* overlay position */ bool position_at_bottom; @@ -138,7 +140,7 @@ struct imv { /* show a solid background colour, or chequerboard pattern */ enum background_type type; /* the aforementioned background colour */ - struct { unsigned char r, g, b; } color; + struct color_rgb color; } background; /* slideshow state tracking */ @@ -466,21 +468,36 @@ static void event_handler(void *data, const struct imv_event *e) } -static bool hex_value_to_color_rgba(const char* hex, struct color_rgba* color) +static bool hex_value_to_color_rgb(const char* hex, struct color_rgb* color) { + if (*hex == '#') + hex++; + char *ep; uint32_t n = strtoul(hex, &ep, 16); - if (*ep != '\0' || ep - hex != 8 || n > 0xFFFFFFFF) { + if (*ep != '\0' || ep - hex != 6 || n > 0xFFFFFF) { imv_log(IMV_ERROR, "Invalid hex color: '%s'\n", hex); return false; } - color->a = n & 0xFF; - color->b = (n >> 8) & 0xFF; - color->g = (n >> 16) & 0xFF; - color->r = (n >> 24); + color->b = n & 0xFF; + color->g = (n >> 8) & 0xFF; + color->r = (n >> 16); return true; } +static bool hex_value_to_alpha(const char* hex, unsigned char *alpha) +{ + if (*hex == '#') + hex++; + char *ep; + uint32_t n = strtoul(hex, &ep, 16); + if (*ep != '\0' || ep - hex != 2 || n > 0xFF) { + imv_log(IMV_ERROR, "Invalid hex color: '%s'\n", hex); + return false; + } + *alpha = n & 0xFF; + return true; +} static void log_to_stderr(enum imv_log_level level, const char *text, void *data) { @@ -525,8 +542,11 @@ struct imv *imv_create(void) imv->overlay.text_color.r = 255; imv->overlay.text_color.g = 255; imv->overlay.text_color.b = 255; - imv->overlay.text_color.a = 255; - imv->overlay.background_color.a = 195; + imv->overlay.text_alpha = 255; + imv->overlay.background_color.r = 0; + imv->overlay.background_color.g = 0; + imv->overlay.background_color.b = 0; + imv->overlay.background_alpha = 195; imv->overlay.position_at_bottom = false; imv->startup_commands = list_create(); @@ -647,17 +667,7 @@ static bool parse_bg(struct imv *imv, const char *bg) imv->background.type = BACKGROUND_CHEQUERED; } else { imv->background.type = BACKGROUND_SOLID; - if (*bg == '#') - ++bg; - char *ep; - uint32_t n = strtoul(bg, &ep, 16); - if (*ep != '\0' || ep - bg != 6 || n > 0xFFFFFF) { - imv_log(IMV_ERROR, "Invalid hex color: '%s'\n", bg); - return false; - } - imv->background.color.b = n & 0xFF; - imv->background.color.g = (n >> 8) & 0xFF; - imv->background.color.r = (n >> 16); + return hex_value_to_color_rgb(bg, &imv->background.color); } return true; } @@ -1244,7 +1254,7 @@ static void render_window(struct imv *imv) imv->overlay.background_color.r / 255.f, imv->overlay.background_color.g / 255.f, imv->overlay.background_color.b / 255.f, - imv->overlay.background_color.a / 255.f); + imv->overlay.background_alpha / 255.f); int y = 0 ; const int bottom_offset = 5; if (imv->overlay.position_at_bottom) @@ -1256,7 +1266,7 @@ static void render_window(struct imv *imv) imv->overlay.text_color.r / 255.f, imv->overlay.text_color.g / 255.f, imv->overlay.text_color.b / 255.f, - imv->overlay.text_color.a / 255.f); + imv->overlay.text_alpha / 255.f); char overlay_text[1024]; generate_env_text(imv, overlay_text, sizeof overlay_text, imv->overlay.text); imv_canvas_printf(imv->canvas, 0, y, "%s", overlay_text); @@ -1414,24 +1424,38 @@ static int handle_ini_value(void *user, const char *section, const char *name, } if (!strcmp(name, "overlay_text_color")) { - if (!hex_value_to_color_rgba(value, &imv->overlay.text_color)) { + if (!hex_value_to_color_rgb(value, &imv->overlay.text_color)) { return false; } return 1; } - if (!strcmp(name, "overlay_position_bottom")) { - imv->overlay.position_at_bottom = parse_bool(value); + if (!strcmp(name, "overlay_text_alpha")) { + if (!hex_value_to_alpha(value, &imv->overlay.text_alpha)) { + return false; + } return 1; } if (!strcmp(name, "overlay_background_color")) { - if (!hex_value_to_color_rgba(value, &imv->overlay.background_color)) { + if (!hex_value_to_color_rgb(value, &imv->overlay.background_color)) { return false; } return 1; } + if (!strcmp(name, "overlay_background_alpha")) { + if (!hex_value_to_alpha(value, &imv->overlay.background_alpha)) { + return false; + } + return 1; + } + + if (!strcmp(name, "overlay_position_bottom")) { + imv->overlay.position_at_bottom = parse_bool(value); + return 1; + } + if (!strcmp(name, "overlay_font")) { free(imv->overlay.font.name); imv->overlay.font.name = strdup(value); -- cgit v1.2.3