termiolink: fix _hsl_to_rgb() + update tests

terminology-1.8
Boris Faure 2 years ago
parent 98ee7bdcca
commit 544a4376f7
Signed by: borisfaure
GPG Key ID: 35C0410516166BE8
  1. 38
      src/bin/termiolink.c
  2. 34
      tests/color_link_css_hsl.sh

@ -1035,13 +1035,13 @@ _hsl_to_rgb(double hue, double saturation, double lightness,
uint8_t *rp, uint8_t *gp, uint8_t *bp)
{
double a = saturation * MIN(lightness, 1.0 - lightness);
int n[3] = {0, 8, 4};
double n[3] = {0., 8., 4.};
double res[3] = {};
int i;
for (i = 0; i < 3; i++)
{
double k = fmod(n[i] + hue / 12., 12.);
double k = fmod(n[i] + 12.0 * hue, 12.);
double f = lightness - a * MAX(-1, MIN(MIN(k - 3, 9 - k), 1));
if (f > 1 || f < 0)
return EINA_FALSE;
@ -1917,43 +1917,43 @@ tytest_color_parse_css_hsl(void)
/* These examples all specify the same color: a lavender. */
assert(TY_SB_ADD(&sb, "hsl(270,60%,70%)") == 0);
assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
assert(r == 224 && g == 135 && b == 132 && a == 255);
assert(r == 178 && g == 132 && b == 224 && a == 255);
ty_sb_free(&sb);
r = g = b = a = 0;
assert(TY_SB_ADD(&sb, "hsl(270, 60%, 70%)") == 0);
assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
assert(r == 224 && g == 135 && b == 132 && a == 255);
assert(r == 178 && g == 132 && b == 224 && a == 255);
ty_sb_free(&sb);
r = g = b = a = 0;
assert(TY_SB_ADD(&sb, "hsl(270 60% 70%)") == 0);
assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
assert(r == 224 && g == 135 && b == 132 && a == 255);
assert(r == 178 && g == 132 && b == 224 && a == 255);
ty_sb_free(&sb);
r = g = b = a = 0;
assert(TY_SB_ADD(&sb, "hsl(270deg, 60%, 70%)") == 0);
assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
assert(r == 224 && g == 135 && b == 132 && a == 255);
assert(r == 178 && g == 132 && b == 224 && a == 255);
ty_sb_free(&sb);
r = g = b = a = 0;
assert(TY_SB_ADD(&sb, "hsl(4.71239rad, 60%, 70%)") == 0);
assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
assert(r == 224 && g == 135 && b == 132 && a == 255);
assert(r == 178 && g == 132 && b == 224 && a == 255);
ty_sb_free(&sb);
r = g = b = a = 0;
assert(TY_SB_ADD(&sb, "hsl(300grad, 60%, 70%)") == 0);
assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
assert(r == 224 && g == 135 && b == 132 && a == 255);
assert(r == 178 && g == 132 && b == 224 && a == 255);
ty_sb_free(&sb);
r = g = b = a = 0;
assert(TY_SB_ADD(&sb, "hsl(.75turn, 60%, 70%)") == 0);
assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
assert(r == 224 && g == 135 && b == 132 && a == 255);
assert(r == 178 && g == 132 && b == 224 && a == 255);
ty_sb_free(&sb);
r = g = b = a = 0;
@ -1961,25 +1961,25 @@ tytest_color_parse_css_hsl(void)
/* These examples all specify the same color: a lavender that is 15% opaque. */
assert(TY_SB_ADD(&sb, "hsl(270, 60%, 50%, .15)") == 0);
assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
assert(r == 204 && g == 55 && b == 51 && a == 38);
assert(r == 127 && g == 51 && b == 204 && a == 38);
ty_sb_free(&sb);
r = g = b = a = 0;
assert(TY_SB_ADD(&sb, "hsl(270, 60%, 50%, 15%)") == 0);
assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
assert(r == 204 && g == 55 && b == 51 && a == 38);
assert(r == 127 && g == 51 && b == 204 && a == 38);
ty_sb_free(&sb);
r = g = b = a = 0;
assert(TY_SB_ADD(&sb, "hsl(270 60% 50% / .15)") == 0);
assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
assert(r == 204 && g == 55 && b == 51 && a == 38);
assert(r == 127 && g == 51 && b == 204 && a == 38);
ty_sb_free(&sb);
r = g = b = a = 0;
assert(TY_SB_ADD(&sb, "hsl(270 60% 50% / 15%)") == 0);
assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
assert(r == 204 && g == 55 && b == 51 && a == 38);
assert(r == 127 && g == 51 && b == 204 && a == 38);
ty_sb_free(&sb);
r = g = b = a = 0;
@ -1987,39 +1987,39 @@ tytest_color_parse_css_hsl(void)
/* Different shades */
assert(TY_SB_ADD(&sb, "hsla(240, 100%, 50%, .05)") == 0);
assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
assert(r == 255 && g == 7 && b == 0 && a == 13);
assert(r == 0 && g == 0 && b == 255 && a == 13);
ty_sb_free(&sb);
r = g = b = a = 0;
assert(TY_SB_ADD(&sb, "hsla(240, 100%, 50%, .4)") == 0);
assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
assert(r == 255 && g == 7 && b == 0 && a == 102);
assert(r == 0 && g == 0 && b == 255 && a == 102);
ty_sb_free(&sb);
r = g = b = a = 0;
assert(TY_SB_ADD(&sb, "hsla(240, 100%, 50%, .7)") == 0);
assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
assert(r == 255 && g == 7 && b == 0 && a == 179);
assert(r == 0 && g == 0 && b == 255 && a == 179);
ty_sb_free(&sb);
r = g = b = a = 0;
assert(TY_SB_ADD(&sb, "hsla(240, 100%, 50%, 1)") == 0);
assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
assert(r == 255 && g == 7 && b == 0 && a == 255);
assert(r == 0 && g == 0 && b == 255 && a == 255);
ty_sb_free(&sb);
r = g = b = a = 0;
/* Whitespace syntax */
assert(TY_SB_ADD(&sb, "hsla(240 100% 50% / .05)") == 0);
assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
assert(r == 255 && g == 7 && b == 0 && a == 13);
assert(r == 0 && g == 0 && b == 255 && a == 13);
ty_sb_free(&sb);
r = g = b = a = 0;
/* Percentage value for alpha */
assert(TY_SB_ADD(&sb, "hsla(240 100% 50% / 5%)") == 0);
assert(_parse_css_hsl_color(&sb, &r, &g, &b, &a) == EINA_TRUE);
assert(r == 255 && g == 7 && b == 0 && a == 13);
assert(r == 0 && g == 0 && b == 255 && a == 13);
ty_sb_free(&sb);
r = g = b = a = 0;

@ -39,71 +39,71 @@ printf 'whether there is a color underneath)'
##
## hsl(270,60%,70%)
printf '\033}tm;76;36\0'
printf '\033}tlc;1;2;16;2;224;135;132;255\0'
printf '\033}tlc;1;2;16;2;178;132;224;255\0'
## hsl(270, 60%, 70%)
printf '\033}tm;294;34\0'
printf '\033}tlc;31;2;48;2;224;135;132;255\0'
printf '\033}tlc;31;2;48;2;178;132;224;255\0'
## hsl(270 60% 70%)
printf '\033}tm;32;56\0'
printf '\033}tlc;1;3;16;3;224;135;132;255\0'
printf '\033}tlc;1;3;16;3;178;132;224;255\0'
## hsl(270deg, 60%, 70%)
printf '\033}tm;311;56\0'
printf '\033}tlc;31;3;51;3;224;135;132;255\0'
printf '\033}tlc;31;3;51;3;178;132;224;255\0'
## hsl(4.71239rad, 60%, 70%)
printf '\033}tm;89;67\0'
printf '\033}tlc;1;4;25;4;224;135;132;255\0'
printf '\033}tlc;1;4;25;4;178;132;224;255\0'
## hsl(300grad, 60%, 70%)
printf '\033}tm;328;68\0'
printf '\033}tlc;31;4;52;4;224;135;132;255\0'
printf '\033}tlc;31;4;52;4;178;132;224;255\0'
## hsl(.75turn, 60%, 70%)
printf '\033}tm;14;84\0'
printf '\033}tlc;1;5;22;5;224;135;132;255\0'
printf '\033}tlc;1;5;22;5;178;132;224;255\0'
## hsl(270, 60%, 50%, .15)
printf '\033}tm;226;85\0'
printf '\033}tlc;31;5;53;5;204;55;51;38\0'
printf '\033}tlc;31;5;53;5;127;51;204;38\0'
## hsl(270, 60%, 50%, 15%)
printf '\033}tm;107;99\0'
printf '\033}tlc;1;6;23;6;204;55;51;38\0'
printf '\033}tlc;1;6;23;6;127;51;204;38\0'
## hsl(270 60% 50% / .15)
printf '\033}tm;312;99\0'
printf '\033}tlc;31;6;52;6;204;55;51;38\0'
printf '\033}tlc;31;6;52;6;127;51;204;38\0'
## hsl(270 60% 50% / 15%)
printf '\033}tm;44;111\0'
printf '\033}tlc;1;7;22;7;204;55;51;38\0'
printf '\033}tlc;1;7;22;7;127;51;204;38\0'
## hsla(240, 100%, 50%, .05)
printf '\033}tm;238;114\0'
printf '\033}tlc;31;7;55;7;255;7;0;13\0'
printf '\033}tlc;31;7;55;7;0;0;255;13\0'
## hsla(240, 100%, 50%, .4)
printf '\033}tm;95;129\0'
printf '\033}tlc;1;8;24;8;255;7;0;102\0'
printf '\033}tlc;1;8;24;8;0;0;255;102\0'
## hsla(600, 100%, 50%, .7)
printf '\033}tm;336;127\0'
printf '\033}tlc;31;8;54;8;255;7;0;179\0'
printf '\033}tlc;31;8;54;8;0;0;255;179\0'
## hsla(240, 100%, 50%, 1)
printf '\033}tm;27;142\0'
printf '\033}tlc;1;9;23;9;255;7;0;255\0'
printf '\033}tlc;1;9;23;9;0;0;255;255\0'
## hsla(240 100% 50% / .05)
printf '\033}tm;237;142\0'
printf '\033}tlc;31;9;54;9;255;7;0;13\0'
printf '\033}tlc;31;9;54;9;0;0;255;13\0'
## hsla(240 100% 50% / 5%)
printf '\033}tm;153;158\0'
printf '\033}tlc;1;10;23;10;255;7;0;13\0'
printf '\033}tlc;1;10;23;10;0;0;255;13\0'
##

Loading…
Cancel
Save