[Parser] Fix HWB parser alpha channel and add test.

This commit is contained in:
Dave Davenport 2017-05-13 22:51:10 +02:00
parent c54a817555
commit 94ee637102
2 changed files with 24 additions and 1 deletions

View File

@ -444,7 +444,6 @@ t_property_color
}
/** hwb ( 0-360 , 0-100 %, 0 - 100 %) */
| T_COL_HWB T_PARENT_LEFT T_INT T_COMMA t_property_color_value T_PERCENT T_COMMA t_property_color_value T_PERCENT T_PARENT_RIGHT {
$$.alpha = 1.0;
if ( ! check_in_range($3,0,360, &(@$)) ) { YYABORT; }
if ( ! check_in_range($5,0,100, &(@$)) ) { YYABORT; }
if ( ! check_in_range($8,0,100, &(@$)) ) { YYABORT; }
@ -452,6 +451,7 @@ t_property_color
double w = $5/100.0;
double b = $8/100.0;
$$ = hsl_to_rgb ( h, 1.0, 0.5);
$$.alpha = 1.0;
$$.red *= ( 1. - w - b );
$$.red += w;
$$.green *= ( 1. - w - b );

View File

@ -610,6 +610,28 @@ START_TEST ( test_properties_color_hsl )
ck_assert_double_eq_tol ( p->value.color.blue , 0 , 0.004);
}
END_TEST
START_TEST ( test_properties_color_hwb )
{
widget wid;
wid.name = "blaat";
wid.state = NULL;
rofi_theme_parse_string ( "* { test1: hwb(190,65%,0%); test2: hwb(265, 31%, 29%); }");
ThemeWidget *twid = rofi_theme_find_widget ( wid.name, wid.state, FALSE );
Property *p = rofi_theme_find_property ( twid, P_COLOR, "test2", FALSE );
ck_assert_ptr_nonnull ( p );
ck_assert_double_eq ( p->value.color.alpha , 1.0 );
ck_assert_double_eq_tol ( p->value.color.red , 0x7a/255.0 , 0.004);
ck_assert_double_eq_tol ( p->value.color.green , 0x4f/255.0, 0.004 );
ck_assert_double_eq_tol ( p->value.color.blue , 0xb5/255.0 , 0.004);
p = rofi_theme_find_property ( twid, P_COLOR, "test1", FALSE );
ck_assert_ptr_nonnull ( p );
ck_assert_double_eq ( p->value.color.alpha , 1.0 );
ck_assert_double_eq_tol ( p->value.color.red , 166/255.0, 0.004);
ck_assert_double_eq_tol ( p->value.color.green ,240/255.0, 0.004 );
ck_assert_double_eq_tol ( p->value.color.blue , 255/255.0 , 0.004);
}
END_TEST
START_TEST ( test_properties_color_cmyk )
{
widget wid;
@ -841,6 +863,7 @@ static Suite * theme_parser_suite (void)
tcase_add_test ( tc_prop_color, test_properties_color_rgba_percent);
tcase_add_test ( tc_prop_color, test_properties_color_argb);
tcase_add_test ( tc_prop_color, test_properties_color_hsl);
tcase_add_test ( tc_prop_color, test_properties_color_hwb);
tcase_add_test ( tc_prop_color, test_properties_color_cmyk);
suite_add_tcase(s, tc_prop_color );
}