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