summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2020-07-17 12:58:22 +0200
committerBoris Faure <billiob@gmail.com>2020-07-17 12:58:22 +0200
commit544a4376f7984be0419d034f3e4f0db5a43aa151 (patch)
tree423805842e660a65dcae60af97de25887f00d601
parent98ee7bdccabe5c33b3ef968629b258d81fbee4ec (diff)
termiolink: fix _hsl_to_rgb() + update tests
-rw-r--r--src/bin/termiolink.c38
-rwxr-xr-xtests/color_link_css_hsl.sh34
2 files changed, 36 insertions, 36 deletions
diff --git a/src/bin/termiolink.c b/src/bin/termiolink.c
index 8d4a63f..6bd0e2e 100644
--- a/src/bin/termiolink.c
+++ b/src/bin/termiolink.c
@@ -1035,13 +1035,13 @@ _hsl_to_rgb(double hue, double saturation, double lightness,
1035 uint8_t *rp, uint8_t *gp, uint8_t *bp) 1035 uint8_t *rp, uint8_t *gp, uint8_t *bp)
1036{ 1036{
1037 double a = saturation * MIN(lightness, 1.0 - lightness); 1037 double a = saturation * MIN(lightness, 1.0 - lightness);
1038 int n[3] = {0, 8, 4}; 1038 double n[3] = {0., 8., 4.};
1039 double res[3] = {}; 1039 double res[3] = {};
1040 int i; 1040 int i;
1041 1041
1042 for (i = 0; i < 3; i++) 1042 for (i = 0; i < 3; i++)
1043 { 1043 {
1044 double k = fmod(n[i] + hue / 12., 12.); 1044 double k = fmod(n[i] + 12.0 * hue, 12.);
1045 double f = lightness - a * MAX(-1, MIN(MIN(k - 3, 9 - k), 1)); 1045 double f = lightness - a * MAX(-1, MIN(MIN(k - 3, 9 - k), 1));
1046 if (f > 1 || f < 0) 1046 if (f > 1 || f < 0)
1047 return EINA_FALSE; 1047 return EINA_FALSE;
@@ -1917,43 +1917,43 @@ tytest_color_parse_css_hsl(void)
1917 /* These examples all specify the same color: a lavender. */ 1917 /* These examples all specify the same color: a lavender. */
1918 assert(TY_SB_ADD(&sb, "hsl(270,60%,70%)") == 0); 1918 assert(TY_SB_ADD(&sb, "hsl(270,60%,70%)") == 0);
1919 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE); 1919 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
1920 assert(r == 224 && g == 135 && b == 132 && a == 255); 1920 assert(r == 178 && g == 132 && b == 224 && a == 255);
1921 ty_sb_free(&sb); 1921 ty_sb_free(&sb);
1922 r = g = b = a = 0; 1922 r = g = b = a = 0;
1923 1923
1924 assert(TY_SB_ADD(&sb, "hsl(270, 60%, 70%)") == 0); 1924 assert(TY_SB_ADD(&sb, "hsl(270, 60%, 70%)") == 0);
1925 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE); 1925 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
1926 assert(r == 224 && g == 135 && b == 132 && a == 255); 1926 assert(r == 178 && g == 132 && b == 224 && a == 255);
1927 ty_sb_free(&sb); 1927 ty_sb_free(&sb);
1928 r = g = b = a = 0; 1928 r = g = b = a = 0;
1929 1929
1930 assert(TY_SB_ADD(&sb, "hsl(270 60% 70%)") == 0); 1930 assert(TY_SB_ADD(&sb, "hsl(270 60% 70%)") == 0);
1931 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE); 1931 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
1932 assert(r == 224 && g == 135 && b == 132 && a == 255); 1932 assert(r == 178 && g == 132 && b == 224 && a == 255);
1933 ty_sb_free(&sb); 1933 ty_sb_free(&sb);
1934 r = g = b = a = 0; 1934 r = g = b = a = 0;
1935 1935
1936 assert(TY_SB_ADD(&sb, "hsl(270deg, 60%, 70%)") == 0); 1936 assert(TY_SB_ADD(&sb, "hsl(270deg, 60%, 70%)") == 0);
1937 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE); 1937 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
1938 assert(r == 224 && g == 135 && b == 132 && a == 255); 1938 assert(r == 178 && g == 132 && b == 224 && a == 255);
1939 ty_sb_free(&sb); 1939 ty_sb_free(&sb);
1940 r = g = b = a = 0; 1940 r = g = b = a = 0;
1941 1941
1942 assert(TY_SB_ADD(&sb, "hsl(4.71239rad, 60%, 70%)") == 0); 1942 assert(TY_SB_ADD(&sb, "hsl(4.71239rad, 60%, 70%)") == 0);
1943 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE); 1943 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
1944 assert(r == 224 && g == 135 && b == 132 && a == 255); 1944 assert(r == 178 && g == 132 && b == 224 && a == 255);
1945 ty_sb_free(&sb); 1945 ty_sb_free(&sb);
1946 r = g = b = a = 0; 1946 r = g = b = a = 0;
1947 1947
1948 assert(TY_SB_ADD(&sb, "hsl(300grad, 60%, 70%)") == 0); 1948 assert(TY_SB_ADD(&sb, "hsl(300grad, 60%, 70%)") == 0);
1949 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE); 1949 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
1950 assert(r == 224 && g == 135 && b == 132 && a == 255); 1950 assert(r == 178 && g == 132 && b == 224 && a == 255);
1951 ty_sb_free(&sb); 1951 ty_sb_free(&sb);
1952 r = g = b = a = 0; 1952 r = g = b = a = 0;
1953 1953
1954 assert(TY_SB_ADD(&sb, "hsl(.75turn, 60%, 70%)") == 0); 1954 assert(TY_SB_ADD(&sb, "hsl(.75turn, 60%, 70%)") == 0);
1955 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE); 1955 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
1956 assert(r == 224 && g == 135 && b == 132 && a == 255); 1956 assert(r == 178 && g == 132 && b == 224 && a == 255);
1957 ty_sb_free(&sb); 1957 ty_sb_free(&sb);
1958 r = g = b = a = 0; 1958 r = g = b = a = 0;
1959 1959
@@ -1961,25 +1961,25 @@ tytest_color_parse_css_hsl(void)
1961 /* These examples all specify the same color: a lavender that is 15% opaque. */ 1961 /* These examples all specify the same color: a lavender that is 15% opaque. */
1962 assert(TY_SB_ADD(&sb, "hsl(270, 60%, 50%, .15)") == 0); 1962 assert(TY_SB_ADD(&sb, "hsl(270, 60%, 50%, .15)") == 0);
1963 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE); 1963 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
1964 assert(r == 204 && g == 55 && b == 51 && a == 38); 1964 assert(r == 127 && g == 51 && b == 204 && a == 38);
1965 ty_sb_free(&sb); 1965 ty_sb_free(&sb);
1966 r = g = b = a = 0; 1966 r = g = b = a = 0;
1967 1967
1968 assert(TY_SB_ADD(&sb, "hsl(270, 60%, 50%, 15%)") == 0); 1968 assert(TY_SB_ADD(&sb, "hsl(270, 60%, 50%, 15%)") == 0);
1969 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE); 1969 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
1970 assert(r == 204 && g == 55 && b == 51 && a == 38); 1970 assert(r == 127 && g == 51 && b == 204 && a == 38);
1971 ty_sb_free(&sb); 1971 ty_sb_free(&sb);
1972 r = g = b = a = 0; 1972 r = g = b = a = 0;
1973 1973
1974 assert(TY_SB_ADD(&sb, "hsl(270 60% 50% / .15)") == 0); 1974 assert(TY_SB_ADD(&sb, "hsl(270 60% 50% / .15)") == 0);
1975 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE); 1975 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
1976 assert(r == 204 && g == 55 && b == 51 && a == 38); 1976 assert(r == 127 && g == 51 && b == 204 && a == 38);
1977 ty_sb_free(&sb); 1977 ty_sb_free(&sb);
1978 r = g = b = a = 0; 1978 r = g = b = a = 0;
1979 1979
1980 assert(TY_SB_ADD(&sb, "hsl(270 60% 50% / 15%)") == 0); 1980 assert(TY_SB_ADD(&sb, "hsl(270 60% 50% / 15%)") == 0);
1981 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE); 1981 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
1982 assert(r == 204 && g == 55 && b == 51 && a == 38); 1982 assert(r == 127 && g == 51 && b == 204 && a == 38);
1983 ty_sb_free(&sb); 1983 ty_sb_free(&sb);
1984 r = g = b = a = 0; 1984 r = g = b = a = 0;
1985 1985
@@ -1987,39 +1987,39 @@ tytest_color_parse_css_hsl(void)
1987 /* Different shades */ 1987 /* Different shades */
1988 assert(TY_SB_ADD(&sb, "hsla(240, 100%, 50%, .05)") == 0); 1988 assert(TY_SB_ADD(&sb, "hsla(240, 100%, 50%, .05)") == 0);
1989 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE); 1989 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
1990 assert(r == 255 && g == 7 && b == 0 && a == 13); 1990 assert(r == 0 && g == 0 && b == 255 && a == 13);
1991 ty_sb_free(&sb); 1991 ty_sb_free(&sb);
1992 r = g = b = a = 0; 1992 r = g = b = a = 0;
1993 1993
1994 assert(TY_SB_ADD(&sb, "hsla(240, 100%, 50%, .4)") == 0); 1994 assert(TY_SB_ADD(&sb, "hsla(240, 100%, 50%, .4)") == 0);
1995 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE); 1995 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
1996 assert(r == 255 && g == 7 && b == 0 && a == 102); 1996 assert(r == 0 && g == 0 && b == 255 && a == 102);
1997 ty_sb_free(&sb); 1997 ty_sb_free(&sb);
1998 r = g = b = a = 0; 1998 r = g = b = a = 0;
1999 1999
2000 assert(TY_SB_ADD(&sb, "hsla(240, 100%, 50%, .7)") == 0); 2000 assert(TY_SB_ADD(&sb, "hsla(240, 100%, 50%, .7)") == 0);
2001 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE); 2001 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
2002 assert(r == 255 && g == 7 && b == 0 && a == 179); 2002 assert(r == 0 && g == 0 && b == 255 && a == 179);
2003 ty_sb_free(&sb); 2003 ty_sb_free(&sb);
2004 r = g = b = a = 0; 2004 r = g = b = a = 0;
2005 2005
2006 assert(TY_SB_ADD(&sb, "hsla(240, 100%, 50%, 1)") == 0); 2006 assert(TY_SB_ADD(&sb, "hsla(240, 100%, 50%, 1)") == 0);
2007 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE); 2007 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
2008 assert(r == 255 && g == 7 && b == 0 && a == 255); 2008 assert(r == 0 && g == 0 && b == 255 && a == 255);
2009 ty_sb_free(&sb); 2009 ty_sb_free(&sb);
2010 r = g = b = a = 0; 2010 r = g = b = a = 0;
2011 2011
2012 /* Whitespace syntax */ 2012 /* Whitespace syntax */
2013 assert(TY_SB_ADD(&sb, "hsla(240 100% 50% / .05)") == 0); 2013 assert(TY_SB_ADD(&sb, "hsla(240 100% 50% / .05)") == 0);
2014 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE); 2014 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
2015 assert(r == 255 && g == 7 && b == 0 && a == 13); 2015 assert(r == 0 && g == 0 && b == 255 && a == 13);
2016 ty_sb_free(&sb); 2016 ty_sb_free(&sb);
2017 r = g = b = a = 0; 2017 r = g = b = a = 0;
2018 2018
2019 /* Percentage value for alpha */ 2019 /* Percentage value for alpha */
2020 assert(TY_SB_ADD(&sb, "hsla(240 100% 50% / 5%)") == 0); 2020 assert(TY_SB_ADD(&sb, "hsla(240 100% 50% / 5%)") == 0);
2021 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE); 2021 assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
2022 assert(r == 255 && g == 7 && b == 0 && a == 13); 2022 assert(r == 0 && g == 0 && b == 255 && a == 13);
2023 ty_sb_free(&sb); 2023 ty_sb_free(&sb);
2024 r = g = b = a = 0; 2024 r = g = b = a = 0;
2025 2025
diff --git a/tests/color_link_css_hsl.sh b/tests/color_link_css_hsl.sh
index da0dd7f..067c390 100755
--- a/tests/color_link_css_hsl.sh
+++ b/tests/color_link_css_hsl.sh
@@ -39,71 +39,71 @@ printf 'whether there is a color underneath)'
39## 39##
40## hsl(270,60%,70%) 40## hsl(270,60%,70%)
41printf '\033}tm;76;36\0' 41printf '\033}tm;76;36\0'
42printf '\033}tlc;1;2;16;2;224;135;132;255\0' 42printf '\033}tlc;1;2;16;2;178;132;224;255\0'
43 43
44## hsl(270, 60%, 70%) 44## hsl(270, 60%, 70%)
45printf '\033}tm;294;34\0' 45printf '\033}tm;294;34\0'
46printf '\033}tlc;31;2;48;2;224;135;132;255\0' 46printf '\033}tlc;31;2;48;2;178;132;224;255\0'
47 47
48## hsl(270 60% 70%) 48## hsl(270 60% 70%)
49printf '\033}tm;32;56\0' 49printf '\033}tm;32;56\0'
50printf '\033}tlc;1;3;16;3;224;135;132;255\0' 50printf '\033}tlc;1;3;16;3;178;132;224;255\0'
51 51
52## hsl(270deg, 60%, 70%) 52## hsl(270deg, 60%, 70%)
53printf '\033}tm;311;56\0' 53printf '\033}tm;311;56\0'
54printf '\033}tlc;31;3;51;3;224;135;132;255\0' 54printf '\033}tlc;31;3;51;3;178;132;224;255\0'
55 55
56## hsl(4.71239rad, 60%, 70%) 56## hsl(4.71239rad, 60%, 70%)
57printf '\033}tm;89;67\0' 57printf '\033}tm;89;67\0'
58printf '\033}tlc;1;4;25;4;224;135;132;255\0' 58printf '\033}tlc;1;4;25;4;178;132;224;255\0'
59 59
60## hsl(300grad, 60%, 70%) 60## hsl(300grad, 60%, 70%)
61printf '\033}tm;328;68\0' 61printf '\033}tm;328;68\0'
62printf '\033}tlc;31;4;52;4;224;135;132;255\0' 62printf '\033}tlc;31;4;52;4;178;132;224;255\0'
63 63
64## hsl(.75turn, 60%, 70%) 64## hsl(.75turn, 60%, 70%)
65printf '\033}tm;14;84\0' 65printf '\033}tm;14;84\0'
66printf '\033}tlc;1;5;22;5;224;135;132;255\0' 66printf '\033}tlc;1;5;22;5;178;132;224;255\0'
67 67
68## hsl(270, 60%, 50%, .15) 68## hsl(270, 60%, 50%, .15)
69printf '\033}tm;226;85\0' 69printf '\033}tm;226;85\0'
70printf '\033}tlc;31;5;53;5;204;55;51;38\0' 70printf '\033}tlc;31;5;53;5;127;51;204;38\0'
71 71
72## hsl(270, 60%, 50%, 15%) 72## hsl(270, 60%, 50%, 15%)
73printf '\033}tm;107;99\0' 73printf '\033}tm;107;99\0'
74printf '\033}tlc;1;6;23;6;204;55;51;38\0' 74printf '\033}tlc;1;6;23;6;127;51;204;38\0'
75 75
76## hsl(270 60% 50% / .15) 76## hsl(270 60% 50% / .15)
77printf '\033}tm;312;99\0' 77printf '\033}tm;312;99\0'
78printf '\033}tlc;31;6;52;6;204;55;51;38\0' 78printf '\033}tlc;31;6;52;6;127;51;204;38\0'
79 79
80## hsl(270 60% 50% / 15%) 80## hsl(270 60% 50% / 15%)
81printf '\033}tm;44;111\0' 81printf '\033}tm;44;111\0'
82printf '\033}tlc;1;7;22;7;204;55;51;38\0' 82printf '\033}tlc;1;7;22;7;127;51;204;38\0'
83 83
84## hsla(240, 100%, 50%, .05) 84## hsla(240, 100%, 50%, .05)
85printf '\033}tm;238;114\0' 85printf '\033}tm;238;114\0'
86printf '\033}tlc;31;7;55;7;255;7;0;13\0' 86printf '\033}tlc;31;7;55;7;0;0;255;13\0'
87 87
88## hsla(240, 100%, 50%, .4) 88## hsla(240, 100%, 50%, .4)
89printf '\033}tm;95;129\0' 89printf '\033}tm;95;129\0'
90printf '\033}tlc;1;8;24;8;255;7;0;102\0' 90printf '\033}tlc;1;8;24;8;0;0;255;102\0'
91 91
92## hsla(600, 100%, 50%, .7) 92## hsla(600, 100%, 50%, .7)
93printf '\033}tm;336;127\0' 93printf '\033}tm;336;127\0'
94printf '\033}tlc;31;8;54;8;255;7;0;179\0' 94printf '\033}tlc;31;8;54;8;0;0;255;179\0'
95 95
96## hsla(240, 100%, 50%, 1) 96## hsla(240, 100%, 50%, 1)
97printf '\033}tm;27;142\0' 97printf '\033}tm;27;142\0'
98printf '\033}tlc;1;9;23;9;255;7;0;255\0' 98printf '\033}tlc;1;9;23;9;0;0;255;255\0'
99 99
100## hsla(240 100% 50% / .05) 100## hsla(240 100% 50% / .05)
101printf '\033}tm;237;142\0' 101printf '\033}tm;237;142\0'
102printf '\033}tlc;31;9;54;9;255;7;0;13\0' 102printf '\033}tlc;31;9;54;9;0;0;255;13\0'
103 103
104## hsla(240 100% 50% / 5%) 104## hsla(240 100% 50% / 5%)
105printf '\033}tm;153;158\0' 105printf '\033}tm;153;158\0'
106printf '\033}tlc;1;10;23;10;255;7;0;13\0' 106printf '\033}tlc;1;10;23;10;0;0;255;13\0'
107 107
108 108
109## 109##