diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2020-11-15 18:45:33 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2020-11-15 18:45:33 +0000 |
| commit | e0297daa1fcf90a911fd236971e1a2b433f7b134 (patch) | |
| tree | d99cc1c9f9f90166a1e61ca23e9801242ba5609a /sixel.c | |
| parent | render: remove debug output (diff) | |
hsl: add our own implementations of rgb-to-hsl and hsl-to-rgb
* New function: rgb_to_hsl()
* New function: hsl_to_rgb()
* Replace XTerm’s hls_to_rgb() with our own, hsl_to_rgb().
* Ensure hue/lum/sat values are within range before calling
hsl_to_rgb()
Note that sixels’ use the following primary hues:
* blue: 0°
* red: 120
* green: 240°
While “standard” HSL uses:
* red: 0°
* green: 120°
* blue: 240°
Thus, we need to adjust the sixel’s hue value before calling
hsl_to_rgb().
Diffstat (limited to 'sixel.c')
| -rw-r--r-- | sixel.c | 37 |
1 files changed, 28 insertions, 9 deletions
@@ -7,7 +7,7 @@ #define LOG_ENABLE_DBG 0 #include "log.h" #include "render.h" -#include "sixel-hls.h" +#include "hsl.h" #include "util.h" #include "xmalloc.h" @@ -1052,23 +1052,42 @@ decgci(struct terminal *term, uint8_t c) if (nparams > 4) { unsigned format = term->sixel.params[1]; - unsigned c1 = term->sixel.params[2]; - unsigned c2 = term->sixel.params[3]; - unsigned c3 = term->sixel.params[4]; + int c1 = term->sixel.params[2]; + int c2 = term->sixel.params[3]; + int c3 = term->sixel.params[4]; switch (format) { case 1: { /* HLS */ - uint32_t rgb = hls_to_rgb(c1, c2, c3); + int hue = min(c1, 360); + int lum = min(c2, 100); + int sat = min(c3, 100); + + /* + * Sixel’s HLS use the following primary color hues: + * blue: 0° + * red: 120° + * green: 240° + * + * While “standard” HSL uses: + * red: 0° + * green: 120° + * blue: 240° + */ + hue = (hue + 240) % 360; + + uint32_t rgb = hsl_to_rgb(hue, sat, lum); + LOG_DBG("setting palette #%d = HLS %hhu/%hhu/%hhu (0x%06x)", - term->sixel.color_idx, c1, c2, c3, rgb); + term->sixel.color_idx, hue, lum, sat, rgb); + term->sixel.palette[term->sixel.color_idx] = rgb; break; } case 2: { /* RGB */ - uint8_t r = 255 * c1 / 100; - uint8_t g = 255 * c2 / 100; - uint8_t b = 255 * c3 / 100; + uint8_t r = 255 * min(c1, 100) / 100; + uint8_t g = 255 * min(c2, 100) / 100; + uint8_t b = 255 * min(c3, 100) / 100; LOG_DBG("setting palette #%d = RGB %hhu/%hhu/%hhu", term->sixel.color_idx, r, g, b); |
