1 #include <math.h>
2 #include <string.h>
3
4 #include <cogl/cogl.h>
5
6 #include "test-utils.h"
7
8 #define cogl_assert_float(a, b) \
9 do { \
10 if (fabsf ((a) - (b)) >= 0.0001f) \
11 g_assert_cmpfloat ((a), ==, (b)); \
12 } while (0)
13
14 void
test_color_hsl(void)15 test_color_hsl (void)
16 {
17 CoglColor color;
18 float hue, saturation, luminance;
19
20 cogl_color_init_from_4ub(&color, 108, 198, 78, 255);
21 cogl_color_to_hsl(&color, &hue, &saturation, &luminance);
22
23 cogl_assert_float(hue, 105.f);
24 cogl_assert_float(saturation, 0.512821);
25 cogl_assert_float(luminance, 0.541176);
26
27 memset(&color, 0, sizeof (CoglColor));
28 cogl_color_init_from_hsl(&color, hue, saturation, luminance);
29
30 g_assert_cmpint (cogl_color_get_red_byte (&color), ==, 108);
31 g_assert_cmpint (cogl_color_get_green_byte (&color), ==, 198);
32 g_assert_cmpint (cogl_color_get_blue_byte (&color), ==, 78);
33 g_assert_cmpint (cogl_color_get_alpha_byte (&color), ==, 255);
34
35 memset(&color, 0, sizeof (CoglColor));
36 cogl_color_init_from_hsl(&color, hue, 0, luminance);
37
38 cogl_assert_float (cogl_color_get_red_float (&color), luminance);
39 cogl_assert_float (cogl_color_get_green_float (&color), luminance);
40 cogl_assert_float (cogl_color_get_blue_float (&color), luminance);
41 cogl_assert_float (cogl_color_get_alpha_float (&color), 1.0f);
42
43 if (cogl_test_verbose ())
44 g_print ("OK\n");
45 }
46