2009-06-01 17:43:47 +00:00
|
|
|
#include <clutter/clutter.h>
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
static void
|
|
|
|
color_hls_roundtrip (void)
|
2009-07-27 10:46:26 +00:00
|
|
|
{
|
|
|
|
ClutterColor color;
|
|
|
|
gfloat hue, luminance, saturation;
|
|
|
|
|
|
|
|
/* test luminance only */
|
|
|
|
clutter_color_from_string (&color, "#7f7f7f");
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (color.red, ==, 0x7f);
|
|
|
|
g_assert_cmpuint (color.green, ==, 0x7f);
|
|
|
|
g_assert_cmpuint (color.blue, ==, 0x7f);
|
2009-07-27 10:46:26 +00:00
|
|
|
|
|
|
|
clutter_color_to_hls (&color, &hue, &luminance, &saturation);
|
|
|
|
g_assert_cmpfloat (hue, ==, 0.0);
|
|
|
|
g_assert (luminance >= 0.0 && luminance <= 1.0);
|
|
|
|
g_assert_cmpfloat (saturation, ==, 0.0);
|
|
|
|
if (g_test_verbose ())
|
|
|
|
{
|
|
|
|
g_print ("RGB = { %x, %x, %x }, HLS = { %.2f, %.2f, %.2f }\n",
|
|
|
|
color.red,
|
|
|
|
color.green,
|
|
|
|
color.blue,
|
|
|
|
hue,
|
|
|
|
luminance,
|
|
|
|
saturation);
|
|
|
|
}
|
|
|
|
|
|
|
|
color.red = color.green = color.blue = 0;
|
|
|
|
clutter_color_from_hls (&color, hue, luminance, saturation);
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (color.red, ==, 0x7f);
|
|
|
|
g_assert_cmpuint (color.green, ==, 0x7f);
|
|
|
|
g_assert_cmpuint (color.blue, ==, 0x7f);
|
2009-07-27 10:46:26 +00:00
|
|
|
|
|
|
|
/* full conversion */
|
|
|
|
clutter_color_from_string (&color, "#7f8f7f");
|
|
|
|
color.alpha = 255;
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (color.red, ==, 0x7f);
|
|
|
|
g_assert_cmpuint (color.green, ==, 0x8f);
|
|
|
|
g_assert_cmpuint (color.blue, ==, 0x7f);
|
2009-07-27 10:46:26 +00:00
|
|
|
|
|
|
|
clutter_color_to_hls (&color, &hue, &luminance, &saturation);
|
|
|
|
g_assert (hue >= 0.0 && hue < 360.0);
|
|
|
|
g_assert (luminance >= 0.0 && luminance <= 1.0);
|
|
|
|
g_assert (saturation >= 0.0 && saturation <= 1.0);
|
|
|
|
if (g_test_verbose ())
|
|
|
|
{
|
|
|
|
g_print ("RGB = { %x, %x, %x }, HLS = { %.2f, %.2f, %.2f }\n",
|
|
|
|
color.red,
|
|
|
|
color.green,
|
|
|
|
color.blue,
|
|
|
|
hue,
|
|
|
|
luminance,
|
|
|
|
saturation);
|
|
|
|
}
|
|
|
|
|
|
|
|
color.red = color.green = color.blue = 0;
|
|
|
|
clutter_color_from_hls (&color, hue, luminance, saturation);
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (color.red, ==, 0x7f);
|
|
|
|
g_assert_cmpuint (color.green, ==, 0x8f);
|
|
|
|
g_assert_cmpuint (color.blue, ==, 0x7f);
|
2009-07-27 10:46:26 +00:00
|
|
|
|
|
|
|
/* the alpha channel should be untouched */
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (color.alpha, ==, 255);
|
2009-07-27 10:46:26 +00:00
|
|
|
}
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
static void
|
|
|
|
color_from_string_invalid (void)
|
2011-11-10 14:15:32 +00:00
|
|
|
{
|
|
|
|
ClutterColor color;
|
|
|
|
|
|
|
|
g_assert (!clutter_color_from_string (&color, "ff0000ff"));
|
|
|
|
g_assert (!clutter_color_from_string (&color, "#decaffbad"));
|
|
|
|
g_assert (!clutter_color_from_string (&color, "ponies"));
|
|
|
|
g_assert (!clutter_color_from_string (&color, "rgb(255, 0, 0, 0)"));
|
|
|
|
g_assert (!clutter_color_from_string (&color, "rgba(1.0, 0, 0)"));
|
|
|
|
g_assert (!clutter_color_from_string (&color, "hsl(100, 0, 0)"));
|
|
|
|
g_assert (!clutter_color_from_string (&color, "hsla(10%, 0%, 50%)"));
|
|
|
|
g_assert (!clutter_color_from_string (&color, "hsla(100%, 0%, 50%, 20%)"));
|
|
|
|
}
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
static void
|
|
|
|
color_from_string_valid (void)
|
2009-06-01 17:43:47 +00:00
|
|
|
{
|
|
|
|
ClutterColor color;
|
|
|
|
|
color: Support CSS color definitions
The CSS Color Module 3, available at:
http://www.w3.org/TR/css3-color/
allows defining colors as:
rgb ( r, g, b )
rgba ( r, g, b, a)
along with the usual hexadecimal and named notations.
The r, g, and b channels can be:
• integers between 0 and 255
• percentages, between 0% and 100%
The alpha channel, if included using the rgba() modifier, can be a
floating point value between 0.0 and 1.0.
The ClutterColor parser should support this notation.
2010-11-22 14:22:56 +00:00
|
|
|
g_assert (clutter_color_from_string (&color, "#ff0000ff"));
|
2009-06-01 17:43:47 +00:00
|
|
|
if (g_test_verbose ())
|
|
|
|
{
|
|
|
|
g_print ("color = { %x, %x, %x, %x }, expected = { 0xff, 0, 0, 0xff }\n",
|
|
|
|
color.red,
|
|
|
|
color.green,
|
|
|
|
color.blue,
|
|
|
|
color.alpha);
|
|
|
|
}
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (color.red, ==, 0xff);
|
|
|
|
g_assert_cmpuint (color.green, ==, 0);
|
|
|
|
g_assert_cmpuint (color.blue, ==, 0);
|
|
|
|
g_assert_cmpuint (color.alpha, ==, 0xff);
|
2009-06-01 17:43:47 +00:00
|
|
|
|
color: Support CSS color definitions
The CSS Color Module 3, available at:
http://www.w3.org/TR/css3-color/
allows defining colors as:
rgb ( r, g, b )
rgba ( r, g, b, a)
along with the usual hexadecimal and named notations.
The r, g, and b channels can be:
• integers between 0 and 255
• percentages, between 0% and 100%
The alpha channel, if included using the rgba() modifier, can be a
floating point value between 0.0 and 1.0.
The ClutterColor parser should support this notation.
2010-11-22 14:22:56 +00:00
|
|
|
g_assert (clutter_color_from_string (&color, "#0f0f"));
|
2009-06-01 17:43:47 +00:00
|
|
|
if (g_test_verbose ())
|
|
|
|
{
|
|
|
|
g_print ("color = { %x, %x, %x, %x }, expected = { 0, 0xff, 0, 0xff }\n",
|
|
|
|
color.red,
|
|
|
|
color.green,
|
|
|
|
color.blue,
|
|
|
|
color.alpha);
|
|
|
|
}
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (color.red, ==, 0);
|
|
|
|
g_assert_cmpuint (color.green, ==, 0xff);
|
|
|
|
g_assert_cmpuint (color.blue, ==, 0);
|
|
|
|
g_assert_cmpuint (color.alpha, ==, 0xff);
|
2009-06-01 17:43:47 +00:00
|
|
|
|
color: Support CSS color definitions
The CSS Color Module 3, available at:
http://www.w3.org/TR/css3-color/
allows defining colors as:
rgb ( r, g, b )
rgba ( r, g, b, a)
along with the usual hexadecimal and named notations.
The r, g, and b channels can be:
• integers between 0 and 255
• percentages, between 0% and 100%
The alpha channel, if included using the rgba() modifier, can be a
floating point value between 0.0 and 1.0.
The ClutterColor parser should support this notation.
2010-11-22 14:22:56 +00:00
|
|
|
g_assert (clutter_color_from_string (&color, "#0000ff"));
|
2009-06-01 17:43:47 +00:00
|
|
|
if (g_test_verbose ())
|
|
|
|
{
|
|
|
|
g_print ("color = { %x, %x, %x, %x }, expected = { 0, 0, 0xff, 0xff }\n",
|
|
|
|
color.red,
|
|
|
|
color.green,
|
|
|
|
color.blue,
|
|
|
|
color.alpha);
|
|
|
|
}
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (color.red, ==, 0);
|
|
|
|
g_assert_cmpuint (color.green, ==, 0);
|
|
|
|
g_assert_cmpuint (color.blue, ==, 0xff);
|
|
|
|
g_assert_cmpuint (color.alpha, ==, 0xff);
|
2009-10-07 11:27:38 +00:00
|
|
|
|
color: Support CSS color definitions
The CSS Color Module 3, available at:
http://www.w3.org/TR/css3-color/
allows defining colors as:
rgb ( r, g, b )
rgba ( r, g, b, a)
along with the usual hexadecimal and named notations.
The r, g, and b channels can be:
• integers between 0 and 255
• percentages, between 0% and 100%
The alpha channel, if included using the rgba() modifier, can be a
floating point value between 0.0 and 1.0.
The ClutterColor parser should support this notation.
2010-11-22 14:22:56 +00:00
|
|
|
g_assert (clutter_color_from_string (&color, "#abc"));
|
2009-10-07 11:27:38 +00:00
|
|
|
if (g_test_verbose ())
|
|
|
|
{
|
|
|
|
g_print ("color = { %x, %x, %x, %x }, expected = { 0xaa, 0xbb, 0xcc, 0xff }\n",
|
|
|
|
color.red,
|
|
|
|
color.green,
|
|
|
|
color.blue,
|
|
|
|
color.alpha);
|
|
|
|
}
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (color.red, ==, 0xaa);
|
|
|
|
g_assert_cmpuint (color.green, ==, 0xbb);
|
|
|
|
g_assert_cmpuint (color.blue, ==, 0xcc);
|
|
|
|
g_assert_cmpuint (color.alpha, ==, 0xff);
|
2009-10-07 11:27:38 +00:00
|
|
|
|
color: Support CSS color definitions
The CSS Color Module 3, available at:
http://www.w3.org/TR/css3-color/
allows defining colors as:
rgb ( r, g, b )
rgba ( r, g, b, a)
along with the usual hexadecimal and named notations.
The r, g, and b channels can be:
• integers between 0 and 255
• percentages, between 0% and 100%
The alpha channel, if included using the rgba() modifier, can be a
floating point value between 0.0 and 1.0.
The ClutterColor parser should support this notation.
2010-11-22 14:22:56 +00:00
|
|
|
g_assert (clutter_color_from_string (&color, "#123abc"));
|
2009-10-07 11:27:38 +00:00
|
|
|
if (g_test_verbose ())
|
|
|
|
{
|
|
|
|
g_print ("color = { %x, %x, %x, %x }, expected = { 0x12, 0x3a, 0xbc, 0xff }\n",
|
|
|
|
color.red,
|
|
|
|
color.green,
|
|
|
|
color.blue,
|
|
|
|
color.alpha);
|
|
|
|
}
|
|
|
|
g_assert (color.red == 0x12);
|
|
|
|
g_assert (color.green == 0x3a);
|
|
|
|
g_assert (color.blue == 0xbc);
|
|
|
|
g_assert (color.alpha == 0xff);
|
color: Support CSS color definitions
The CSS Color Module 3, available at:
http://www.w3.org/TR/css3-color/
allows defining colors as:
rgb ( r, g, b )
rgba ( r, g, b, a)
along with the usual hexadecimal and named notations.
The r, g, and b channels can be:
• integers between 0 and 255
• percentages, between 0% and 100%
The alpha channel, if included using the rgba() modifier, can be a
floating point value between 0.0 and 1.0.
The ClutterColor parser should support this notation.
2010-11-22 14:22:56 +00:00
|
|
|
|
|
|
|
g_assert (clutter_color_from_string (&color, "rgb(255, 128, 64)"));
|
|
|
|
if (g_test_verbose ())
|
|
|
|
{
|
|
|
|
g_print ("color = { %x, %x, %x, %x }, expected = { 255, 128, 64, 255 }\n",
|
|
|
|
color.red,
|
|
|
|
color.green,
|
|
|
|
color.blue,
|
|
|
|
color.alpha);
|
|
|
|
}
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (color.red, ==, 255);
|
|
|
|
g_assert_cmpuint (color.green, ==, 128);
|
|
|
|
g_assert_cmpuint (color.blue, ==, 64);
|
|
|
|
g_assert_cmpuint (color.alpha, ==, 255);
|
color: Support CSS color definitions
The CSS Color Module 3, available at:
http://www.w3.org/TR/css3-color/
allows defining colors as:
rgb ( r, g, b )
rgba ( r, g, b, a)
along with the usual hexadecimal and named notations.
The r, g, and b channels can be:
• integers between 0 and 255
• percentages, between 0% and 100%
The alpha channel, if included using the rgba() modifier, can be a
floating point value between 0.0 and 1.0.
The ClutterColor parser should support this notation.
2010-11-22 14:22:56 +00:00
|
|
|
|
|
|
|
g_assert (clutter_color_from_string (&color, "rgba ( 30%, 0, 25%, 0.5 ) "));
|
|
|
|
if (g_test_verbose ())
|
|
|
|
{
|
|
|
|
g_print ("color = { %x, %x, %x, %x }, expected = { %.1f, 0, %.1f, 128 }\n",
|
|
|
|
color.red,
|
|
|
|
color.green,
|
|
|
|
color.blue,
|
|
|
|
color.alpha,
|
|
|
|
CLAMP (255.0 / 100.0 * 30.0, 0, 255),
|
|
|
|
CLAMP (255.0 / 100.0 * 25.0, 0, 255));
|
|
|
|
}
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (color.red, ==, (255.0 / 100.0 * 30.0));
|
|
|
|
g_assert_cmpuint (color.green, ==, 0);
|
|
|
|
g_assert_cmpuint (color.blue, ==, (255.0 / 100.0 * 25.0));
|
|
|
|
g_assert_cmpuint (color.alpha, ==, 127);
|
color: Support CSS color definitions
The CSS Color Module 3, available at:
http://www.w3.org/TR/css3-color/
allows defining colors as:
rgb ( r, g, b )
rgba ( r, g, b, a)
along with the usual hexadecimal and named notations.
The r, g, and b channels can be:
• integers between 0 and 255
• percentages, between 0% and 100%
The alpha channel, if included using the rgba() modifier, can be a
floating point value between 0.0 and 1.0.
The ClutterColor parser should support this notation.
2010-11-22 14:22:56 +00:00
|
|
|
|
|
|
|
g_assert (clutter_color_from_string (&color, "rgb( 50%, -50%, 150% )"));
|
|
|
|
if (g_test_verbose ())
|
|
|
|
{
|
|
|
|
g_print ("color = { %x, %x, %x, %x }, expected = { 127, 0, 255, 255 }\n",
|
|
|
|
color.red,
|
|
|
|
color.green,
|
|
|
|
color.blue,
|
|
|
|
color.alpha);
|
|
|
|
}
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (color.red, ==, 127);
|
|
|
|
g_assert_cmpuint (color.green, ==, 0);
|
|
|
|
g_assert_cmpuint (color.blue, ==, 255);
|
|
|
|
g_assert_cmpuint (color.alpha, ==, 255);
|
2010-11-22 15:02:47 +00:00
|
|
|
|
|
|
|
g_assert (clutter_color_from_string (&color, "hsl( 0, 100%, 50% )"));
|
|
|
|
if (g_test_verbose ())
|
|
|
|
{
|
|
|
|
g_print ("color = { %x, %x, %x, %x }, expected = { 255, 0, 0, 255 }\n",
|
|
|
|
color.red,
|
|
|
|
color.green,
|
|
|
|
color.blue,
|
|
|
|
color.alpha);
|
|
|
|
}
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (color.red, ==, 255);
|
|
|
|
g_assert_cmpuint (color.green, ==, 0);
|
|
|
|
g_assert_cmpuint (color.blue, ==, 0);
|
|
|
|
g_assert_cmpuint (color.alpha, ==, 255);
|
2011-11-10 12:56:47 +00:00
|
|
|
|
|
|
|
g_assert (clutter_color_from_string (&color, "hsla( 0, 100%, 50%, 0.5 )"));
|
|
|
|
if (g_test_verbose ())
|
|
|
|
{
|
|
|
|
g_print ("color = { %x, %x, %x, %x }, expected = { 255, 0, 0, 127 }\n",
|
|
|
|
color.red,
|
|
|
|
color.green,
|
|
|
|
color.blue,
|
|
|
|
color.alpha);
|
|
|
|
}
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (color.red, ==, 255);
|
|
|
|
g_assert_cmpuint (color.green, ==, 0);
|
|
|
|
g_assert_cmpuint (color.blue, ==, 0);
|
|
|
|
g_assert_cmpuint (color.alpha, ==, 127);
|
2009-06-01 17:43:47 +00:00
|
|
|
}
|
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
static void
|
|
|
|
color_to_string (void)
|
2009-06-01 17:43:47 +00:00
|
|
|
{
|
|
|
|
ClutterColor color;
|
|
|
|
gchar *str;
|
|
|
|
|
|
|
|
color.red = 0xcc;
|
|
|
|
color.green = 0xcc;
|
|
|
|
color.blue = 0xcc;
|
|
|
|
color.alpha = 0x22;
|
|
|
|
|
|
|
|
str = clutter_color_to_string (&color);
|
|
|
|
g_assert_cmpstr (str, ==, "#cccccc22");
|
|
|
|
|
|
|
|
g_free (str);
|
|
|
|
}
|
2010-01-14 14:07:04 +00:00
|
|
|
|
2013-12-12 15:05:16 +00:00
|
|
|
static void
|
|
|
|
color_operators (void)
|
2010-01-14 14:07:04 +00:00
|
|
|
{
|
|
|
|
ClutterColor op1, op2;
|
|
|
|
ClutterColor res;
|
|
|
|
|
|
|
|
clutter_color_from_pixel (&op1, 0xff0000ff);
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (op1.red, ==, 0xff);
|
|
|
|
g_assert_cmpuint (op1.green, ==, 0);
|
|
|
|
g_assert_cmpuint (op1.blue, ==, 0);
|
|
|
|
g_assert_cmpuint (op1.alpha, ==, 0xff);
|
2010-01-14 14:07:04 +00:00
|
|
|
|
|
|
|
clutter_color_from_pixel (&op2, 0x00ff00ff);
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (op2.red, ==, 0);
|
|
|
|
g_assert_cmpuint (op2.green, ==, 0xff);
|
|
|
|
g_assert_cmpuint (op2.blue, ==, 0);
|
|
|
|
g_assert_cmpuint (op2.alpha, ==, 0xff);
|
2010-01-14 14:07:04 +00:00
|
|
|
|
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("Adding %x, %x; expected result: %x\n",
|
|
|
|
clutter_color_to_pixel (&op1),
|
|
|
|
clutter_color_to_pixel (&op2),
|
|
|
|
0xffff00ff);
|
|
|
|
|
|
|
|
clutter_color_add (&op1, &op2, &res);
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (clutter_color_to_pixel (&res), ==, 0xffff00ff);
|
2010-01-14 14:07:04 +00:00
|
|
|
|
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("Checking alpha channel on color add\n");
|
|
|
|
|
|
|
|
op1.alpha = 0xdd;
|
|
|
|
op2.alpha = 0xcc;
|
|
|
|
clutter_color_add (&op1, &op2, &res);
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (clutter_color_to_pixel (&res), ==, 0xffff00dd);
|
2010-01-14 14:07:04 +00:00
|
|
|
|
|
|
|
clutter_color_from_pixel (&op1, 0xffffffff);
|
|
|
|
clutter_color_from_pixel (&op2, 0xff00ffff);
|
|
|
|
|
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("Subtracting %x, %x; expected result: %x\n",
|
|
|
|
clutter_color_to_pixel (&op1),
|
|
|
|
clutter_color_to_pixel (&op2),
|
|
|
|
0x00ff00ff);
|
|
|
|
|
|
|
|
clutter_color_subtract (&op1, &op2, &res);
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (clutter_color_to_pixel (&res), ==, 0x00ff00ff);
|
2010-01-14 14:07:04 +00:00
|
|
|
|
|
|
|
if (g_test_verbose ())
|
|
|
|
g_print ("Checking alpha channel on color subtract\n");
|
|
|
|
|
|
|
|
op1.alpha = 0xdd;
|
|
|
|
op2.alpha = 0xcc;
|
|
|
|
clutter_color_subtract (&op1, &op2, &res);
|
2013-12-12 15:05:16 +00:00
|
|
|
g_assert_cmpuint (clutter_color_to_pixel (&res), ==, 0x00ff00cc);
|
2010-01-14 14:07:04 +00:00
|
|
|
}
|
2013-12-12 15:05:16 +00:00
|
|
|
|
|
|
|
CLUTTER_TEST_SUITE (
|
|
|
|
CLUTTER_TEST_UNIT ("/color/hls-roundtrip", color_hls_roundtrip)
|
|
|
|
CLUTTER_TEST_UNIT ("/color/from-string/invalid", color_from_string_invalid)
|
|
|
|
CLUTTER_TEST_UNIT ("/color/from-string/valid", color_from_string_valid)
|
|
|
|
CLUTTER_TEST_UNIT ("/color/to-string", color_to_string)
|
|
|
|
CLUTTER_TEST_UNIT ("/color/operators", color_operators)
|
|
|
|
)
|