From be9c38a77d31ceaaba1647c05ee1ee16940a8875 Mon Sep 17 00:00:00 2001 From: Ludwig Nussel Date: Mon, 19 Feb 2024 18:19:48 +0100 Subject: [PATCH] pcrlock: exclude red and green color ranges Using red and green in the output is rather confusing as that is normally associated with good or bad like in the checkmark columns. So let's exclude those colors from the display. Co-authored-by: Akarithos <277667353+Akarithos@users.noreply.github.com> --- src/pcrlock/pcrlock.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/pcrlock/pcrlock.c b/src/pcrlock/pcrlock.c index 33b35ac414..bdee629bc0 100644 --- a/src/pcrlock/pcrlock.c +++ b/src/pcrlock/pcrlock.c @@ -2098,6 +2098,18 @@ static const char *ansi_true_color(uint8_t r, uint8_t g, uint8_t b, char ret[sta return ret; } +/* red and green colors usually have good/bad meaning. So exclude color ranges that look too red- or + * greenish. See https://en.wikipedia.org/wiki/Hue */ +static double map_pcr_to_hue(uint32_t pcr) { + double exclude_red_range = 60.0; + double exclude_green_range = 60.0; + double h = (360.0 - exclude_red_range - exclude_green_range) / (TPM2_PCRS_MAX - 1) * pcr; + h += exclude_red_range / 2; + if (h > 120 - exclude_green_range / 2) + h += exclude_green_range; + return MIN(h, 360 - exclude_red_range / 2); +} + static char *color_for_pcr(EventLog *el, uint32_t pcr) { char color[ANSI_TRUE_COLOR_MAX]; uint8_t r, g, b; @@ -2108,7 +2120,7 @@ static char *color_for_pcr(EventLog *el, uint32_t pcr) { if (el->registers[pcr].color) return el->registers[pcr].color; - hsv_to_rgb(360.0 / (TPM2_PCRS_MAX - 1) * pcr, 100, 90, &r, &g, &b); + hsv_to_rgb(map_pcr_to_hue(pcr), 100, 90, &r, &g, &b); ansi_true_color(r, g, b, color); el->registers[pcr].color = strdup(color);