mutter/clutter/cogl/common/cogl-color.c
Emmanuele Bassi a547cdbc4d 2008-10-30 Emmanuele Bassi <ebassi@linux.intel.com>
Bug 1210 - Add CoglColor API

	* clutter/cogl/cogl-color.h:
	* clutter/cogl/cogl.h.in:
	* clutter/cogl/common/Makefile.am:
	* clutter/cogl/common/cogl-color.c:
	* clutter/cogl/gl/Makefile.am:
	* clutter/cogl/gl/cogl.c:
	* clutter/cogl/gles/Makefile.am:
	* clutter/cogl/gles/cogl-texture.c:
	* clutter/cogl/gles/cogl.c: Add a new color-type, to be used by
	COGL. CoglColor is optimized to allow the minimum amount of
	conversions possible for both GL and GLES implementations.

	* clutter/clutter-actor.c:
	* clutter/clutter-clone-texture.c:
	* clutter/clutter-entry.c:
	* clutter/clutter-main.c:
	* clutter/clutter-rectangle.c:
	* clutter/clutter-stage.c:
	* clutter/clutter-texture.c: Use CoglColor when needed.

	* clutter/pango/pangoclutter-render.c: Use CoglColor when needed.

	* doc/reference/cogl/cogl-docs.sgml:
	* doc/reference/cogl/cogl-sections.txt: Update the documentation.

	* tests/test-cogl-offscreen.c:
	* tests/test-cogl-primitives.c:
	* tests/test-cogl-tex-convert.c:
	* tests/test-cogl-tex-foreign.c:
	* tests/test-cogl-tex-getset.c:
	* tests/test-cogl-tex-polygon.c:
	* tests/test-cogl-tex-tile.c:
	* tests/test-paint-wrapper.c: Update the tests.

	* README: Update release notes.
2008-10-30 16:50:07 +00:00

108 lines
2.3 KiB
C

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "cogl-color.h"
void
cogl_color_set_from_4ub (CoglColor *dest,
guint8 red,
guint8 green,
guint8 blue,
guint8 alpha)
{
g_return_if_fail (dest != NULL);
dest->red = COGL_FIXED_FROM_FLOAT ((float) red / 0xff * 1.0);
dest->green = COGL_FIXED_FROM_FLOAT ((float) green / 0xff * 1.0);
dest->blue = COGL_FIXED_FROM_FLOAT ((float) blue / 0xff * 1.0);
dest->alpha = COGL_FIXED_FROM_FLOAT ((float) alpha / 0xff * 1.0);
}
void
cogl_color_set_from_4d (CoglColor *dest,
gdouble red,
gdouble green,
gdouble blue,
gdouble alpha)
{
g_return_if_fail (dest != NULL);
dest->red = COGL_FIXED_FROM_FLOAT (CLAMP (red, 0.0, 1.0));
dest->green = COGL_FIXED_FROM_FLOAT (CLAMP (green, 0.0, 1.0));
dest->blue = COGL_FIXED_FROM_FLOAT (CLAMP (blue, 0.0, 1.0));
dest->alpha = COGL_FIXED_FROM_FLOAT (CLAMP (alpha, 0.0, 1.0));
}
unsigned char
cogl_color_get_red_byte (const CoglColor *color)
{
return COGL_FIXED_TO_INT (color->red * 255);
}
float
cogl_color_get_red_float (const CoglColor *color)
{
return COGL_FIXED_TO_FLOAT (color->red);
}
CoglFixed
cogl_color_get_red (const CoglColor *color)
{
return color->red;
}
unsigned char
cogl_color_get_green_byte (const CoglColor *color)
{
return COGL_FIXED_TO_INT (color->green * 255);
}
float
cogl_color_get_green_float (const CoglColor *color)
{
return COGL_FIXED_TO_FLOAT (color->green);
}
CoglFixed
cogl_color_get_green (const CoglColor *color)
{
return color->green;
}
unsigned char
cogl_color_get_blue_byte (const CoglColor *color)
{
return COGL_FIXED_TO_INT (color->blue * 255);
}
float
cogl_color_get_blue_float (const CoglColor *color)
{
return COGL_FIXED_TO_FLOAT (color->blue);
}
CoglFixed
cogl_color_get_blue (const CoglColor *color)
{
return color->blue;
}
unsigned char
cogl_color_get_alpha_byte (const CoglColor *color)
{
return COGL_FIXED_TO_INT (color->alpha * 255);
}
float
cogl_color_get_alpha_float (const CoglColor *color)
{
return COGL_FIXED_TO_FLOAT (color->alpha);
}
CoglFixed
cogl_color_get_alpha (const CoglColor *color)
{
return color->alpha;
}