aboutsummaryrefslogtreecommitdiff
path: root/sixel-hls.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-11-15 18:45:33 +0000
committerDaniel Eklöf <daniel@ekloef.se>2020-11-15 18:45:33 +0000
commite0297daa1fcf90a911fd236971e1a2b433f7b134 (patch)
treed99cc1c9f9f90166a1e61ca23e9801242ba5609a /sixel-hls.c
parentrender: 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-hls.c')
-rw-r--r--sixel-hls.c117
1 files changed, 0 insertions, 117 deletions
diff --git a/sixel-hls.c b/sixel-hls.c
deleted file mode 100644
index 8b88b414..00000000
--- a/sixel-hls.c
+++ /dev/null
@@ -1,117 +0,0 @@
-// sixel.c (part of mintty)
-// this function is derived from a part of graphics.c
-// in Xterm pl#310 originally written by Ross Combs.
-//
-// Copyright 2013,2014 by Ross Combs
-//
-// All Rights Reserved
-//
-// Permission is hereby granted, free of charge, to any person obtaining a
-// copy of this software and associated documentation files (the
-// "Software"), to deal in the Software without restriction, including
-// without limitation the rights to use, copy, modify, merge, publish,
-// distribute, sublicense, and/or sell copies of the Software, and to
-// permit persons to whom the Software is furnished to do so, subject to
-// the following conditions:
-//
-// The above copyright notice and this permission notice shall be included
-// in all copies or substantial portions of the Software.
-//
-// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
-// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
-// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
-// IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
-// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
-// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
-// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-//
-// Except as contained in this notice, the name(s) of the above copyright
-// holders shall not be used in advertising or otherwise to promote the
-// sale, use or other dealings in this Software without prior written
-// authorization.
-
-#include "sixel-hls.h"
-
-#define SIXEL_RGB(r, g, b) (((r) << 16) + ((g) << 8) + (b))
-
-int
-hls_to_rgb(int hue, int lum, int sat)
-{
- double hs = (hue + 240) % 360;
- double hv = hs / 360.0;
- double lv = lum / 100.0;
- double sv = sat / 100.0;
- double c, x, m, c2;
- double r1, g1, b1;
- int r, g, b;
- int hpi;
-
- if (sat == 0) {
- r = g = b = lum * 255 / 100;
- return SIXEL_RGB(r, g, b);
- }
-
- if ((c2 = ((2.0 * lv) - 1.0)) < 0.0) {
- c2 = -c2;
- }
- c = (1.0 - c2) * sv;
- hpi = (int) (hv * 6.0);
- x = (hpi & 1) ? c : 0.0;
- m = lv - 0.5 * c;
-
- switch (hpi) {
- case 0:
- r1 = c;
- g1 = x;
- b1 = 0.0;
- break;
- case 1:
- r1 = x;
- g1 = c;
- b1 = 0.0;
- break;
- case 2:
- r1 = 0.0;
- g1 = c;
- b1 = x;
- break;
- case 3:
- r1 = 0.0;
- g1 = x;
- b1 = c;
- break;
- case 4:
- r1 = x;
- g1 = 0.0;
- b1 = c;
- break;
- case 5:
- r1 = c;
- g1 = 0.0;
- b1 = x;
- break;
- default:
- return SIXEL_RGB(255, 255, 255);
- }
-
- r = (int) ((r1 + m) * 100.0 + 0.5);
- g = (int) ((g1 + m) * 100.0 + 0.5);
- b = (int) ((b1 + m) * 100.0 + 0.5);
-
- if (r < 0) {
- r = 0;
- } else if (r > 100) {
- r = 100;
- }
- if (g < 0) {
- g = 0;
- } else if (g > 100) {
- g = 100;
- }
- if (b < 0) {
- b = 0;
- } else if (b > 100) {
- b = 100;
- }
- return SIXEL_RGB(r * 255 / 100, g * 255 / 100, b * 255 / 100);
-}