2009-04-27 10:48:12 -04:00
|
|
|
/*
|
|
|
|
* Cogl
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* A Low Level GPU Graphics and Utilities API
|
2009-04-27 10:48:12 -04:00
|
|
|
*
|
|
|
|
* Copyright (C) 2008,2009 Intel Corporation.
|
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* Permission is hereby granted, free of charge, to any person
|
|
|
|
* obtaining a copy of this software and associated documentation
|
|
|
|
* files (the "Software"), to deal in the Software without
|
|
|
|
* restriction, including without limitation the rights to use, copy,
|
|
|
|
* modify, merge, publish, distribute, sublicense, and/or sell copies
|
|
|
|
* of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
2009-04-27 10:48:12 -04:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
2009-04-27 10:48:12 -04:00
|
|
|
*
|
2014-02-21 20:28:54 -05:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
|
|
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
|
|
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
2010-03-01 07:56:10 -05:00
|
|
|
*
|
|
|
|
*
|
2009-04-27 10:48:12 -04:00
|
|
|
*/
|
|
|
|
|
2008-10-30 12:50:07 -04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2009-06-05 07:58:31 -04:00
|
|
|
#include <string.h>
|
|
|
|
|
2011-10-13 17:34:30 -04:00
|
|
|
#include "cogl-util.h"
|
2008-10-30 12:50:07 -04:00
|
|
|
#include "cogl-color.h"
|
2008-10-30 13:25:00 -04:00
|
|
|
#include "cogl-fixed.h"
|
2012-03-06 13:21:28 -05:00
|
|
|
#include "cogl-color-private.h"
|
2013-09-02 11:02:42 -04:00
|
|
|
#include "cogl-gtype-private.h"
|
|
|
|
|
|
|
|
COGL_GTYPE_DEFINE_BOXED (Color, color, cogl_color_copy, cogl_color_free);
|
2008-10-30 12:50:07 -04:00
|
|
|
|
2008-11-12 08:57:58 -05:00
|
|
|
CoglColor *
|
|
|
|
cogl_color_new (void)
|
|
|
|
{
|
|
|
|
return g_slice_new (CoglColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
CoglColor *
|
|
|
|
cogl_color_copy (const CoglColor *color)
|
|
|
|
{
|
|
|
|
if (G_LIKELY (color))
|
|
|
|
return g_slice_dup (CoglColor, color);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_color_free (CoglColor *color)
|
|
|
|
{
|
|
|
|
if (G_LIKELY (color))
|
|
|
|
g_slice_free (CoglColor, color);
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:17:42 -04:00
|
|
|
void
|
|
|
|
cogl_color_init_from_4ub (CoglColor *color,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
uint8_t red,
|
|
|
|
uint8_t green,
|
|
|
|
uint8_t blue,
|
|
|
|
uint8_t alpha)
|
2010-06-10 09:17:42 -04:00
|
|
|
{
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (color != NULL);
|
2010-06-10 09:17:42 -04:00
|
|
|
|
|
|
|
color->red = red;
|
|
|
|
color->green = green;
|
|
|
|
color->blue = blue;
|
|
|
|
color->alpha = alpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: deprecated, use cogl_color_init_from_4ub */
|
2008-10-30 12:50:07 -04:00
|
|
|
void
|
|
|
|
cogl_color_set_from_4ub (CoglColor *dest,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
uint8_t red,
|
|
|
|
uint8_t green,
|
|
|
|
uint8_t blue,
|
|
|
|
uint8_t alpha)
|
2008-10-30 12:50:07 -04:00
|
|
|
{
|
2010-06-10 09:17:42 -04:00
|
|
|
cogl_color_init_from_4ub (dest, red, green, blue, alpha);
|
|
|
|
}
|
2008-10-30 12:50:07 -04:00
|
|
|
|
2010-06-10 09:17:42 -04:00
|
|
|
void
|
|
|
|
cogl_color_init_from_4f (CoglColor *color,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
float red,
|
|
|
|
float green,
|
|
|
|
float blue,
|
|
|
|
float alpha)
|
2010-06-10 09:17:42 -04:00
|
|
|
{
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (color != NULL);
|
2010-06-10 09:17:42 -04:00
|
|
|
|
|
|
|
color->red = (red * 255);
|
|
|
|
color->green = (green * 255);
|
|
|
|
color->blue = (blue * 255);
|
|
|
|
color->alpha = (alpha * 255);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX: deprecated, use cogl_color_init_from_4f */
|
|
|
|
void
|
|
|
|
cogl_color_set_from_4f (CoglColor *color,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
float red,
|
|
|
|
float green,
|
|
|
|
float blue,
|
|
|
|
float alpha)
|
2010-06-10 09:17:42 -04:00
|
|
|
{
|
|
|
|
cogl_color_init_from_4f (color, red, green, blue, alpha);
|
2008-10-30 12:50:07 -04:00
|
|
|
}
|
|
|
|
|
2008-11-12 08:57:58 -05:00
|
|
|
void
|
2010-06-10 09:17:42 -04:00
|
|
|
cogl_color_init_from_4fv (CoglColor *color,
|
2012-10-19 12:21:35 -04:00
|
|
|
const float *color_array)
|
2008-11-12 08:57:58 -05:00
|
|
|
{
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_IF_FAIL (color != NULL);
|
2008-11-12 08:57:58 -05:00
|
|
|
|
2010-06-10 09:17:42 -04:00
|
|
|
color->red = (color_array[0] * 255);
|
|
|
|
color->green = (color_array[1] * 255);
|
|
|
|
color->blue = (color_array[2] * 255);
|
|
|
|
color->alpha = (color_array[3] * 255);
|
2008-10-30 12:50:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char
|
|
|
|
cogl_color_get_red_byte (const CoglColor *color)
|
|
|
|
{
|
2008-11-12 08:57:58 -05:00
|
|
|
return color->red;
|
2008-10-30 12:50:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
cogl_color_get_red_float (const CoglColor *color)
|
|
|
|
{
|
2008-11-12 08:57:58 -05:00
|
|
|
return (float) color->red / 255.0;
|
2008-10-30 12:50:07 -04:00
|
|
|
}
|
|
|
|
|
2009-01-20 11:20:54 -05:00
|
|
|
float
|
2008-10-30 12:50:07 -04:00
|
|
|
cogl_color_get_red (const CoglColor *color)
|
|
|
|
{
|
2009-01-20 11:20:54 -05:00
|
|
|
return ((float) color->red / 255.0);
|
2008-10-30 12:50:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char
|
|
|
|
cogl_color_get_green_byte (const CoglColor *color)
|
|
|
|
{
|
2008-11-12 08:57:58 -05:00
|
|
|
return color->green;
|
2008-10-30 12:50:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
cogl_color_get_green_float (const CoglColor *color)
|
|
|
|
{
|
2008-11-12 08:57:58 -05:00
|
|
|
return (float) color->green / 255.0;
|
2008-10-30 12:50:07 -04:00
|
|
|
}
|
|
|
|
|
2009-01-20 11:20:54 -05:00
|
|
|
float
|
2008-10-30 12:50:07 -04:00
|
|
|
cogl_color_get_green (const CoglColor *color)
|
|
|
|
{
|
2009-01-20 11:20:54 -05:00
|
|
|
return ((float) color->green / 255.0);
|
2008-10-30 12:50:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char
|
|
|
|
cogl_color_get_blue_byte (const CoglColor *color)
|
|
|
|
{
|
2008-11-12 08:57:58 -05:00
|
|
|
return color->blue;
|
2008-10-30 12:50:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
cogl_color_get_blue_float (const CoglColor *color)
|
|
|
|
{
|
2008-11-12 08:57:58 -05:00
|
|
|
return (float) color->blue / 255.0;
|
2008-10-30 12:50:07 -04:00
|
|
|
}
|
|
|
|
|
2009-01-20 11:20:54 -05:00
|
|
|
float
|
2008-10-30 12:50:07 -04:00
|
|
|
cogl_color_get_blue (const CoglColor *color)
|
|
|
|
{
|
2009-01-20 11:20:54 -05:00
|
|
|
return ((float) color->blue / 255.0);
|
2008-10-30 12:50:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char
|
|
|
|
cogl_color_get_alpha_byte (const CoglColor *color)
|
|
|
|
{
|
2008-11-12 08:57:58 -05:00
|
|
|
return color->alpha;
|
2008-10-30 12:50:07 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
float
|
|
|
|
cogl_color_get_alpha_float (const CoglColor *color)
|
|
|
|
{
|
2008-11-12 08:57:58 -05:00
|
|
|
return (float) color->alpha / 255.0;
|
2008-10-30 12:50:07 -04:00
|
|
|
}
|
|
|
|
|
2009-01-20 11:20:54 -05:00
|
|
|
float
|
2008-10-30 12:50:07 -04:00
|
|
|
cogl_color_get_alpha (const CoglColor *color)
|
|
|
|
{
|
2009-01-20 11:20:54 -05:00
|
|
|
return ((float) color->alpha / 255.0);
|
2008-11-12 08:57:58 -05:00
|
|
|
}
|
|
|
|
|
2010-06-06 18:03:26 -04:00
|
|
|
void
|
|
|
|
cogl_color_set_red_byte (CoglColor *color,
|
|
|
|
unsigned char red)
|
|
|
|
{
|
|
|
|
color->red = red;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_color_set_red_float (CoglColor *color,
|
|
|
|
float red)
|
|
|
|
{
|
|
|
|
color->red = red * 255.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_color_set_red (CoglColor *color,
|
|
|
|
float red)
|
|
|
|
{
|
|
|
|
color->red = red * 255.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_color_set_green_byte (CoglColor *color,
|
|
|
|
unsigned char green)
|
|
|
|
{
|
|
|
|
color->green = green;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_color_set_green_float (CoglColor *color,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
float green)
|
2010-06-06 18:03:26 -04:00
|
|
|
{
|
|
|
|
color->green = green * 255.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_color_set_green (CoglColor *color,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
float green)
|
2010-06-06 18:03:26 -04:00
|
|
|
{
|
|
|
|
color->green = green * 255.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
cogl_color_set_blue_byte (CoglColor *color,
|
|
|
|
unsigned char blue)
|
2010-06-06 18:03:26 -04:00
|
|
|
{
|
|
|
|
color->blue = blue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_color_set_blue_float (CoglColor *color,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
float blue)
|
2010-06-06 18:03:26 -04:00
|
|
|
{
|
|
|
|
color->blue = blue * 255.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_color_set_blue (CoglColor *color,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
float blue)
|
2010-06-06 18:03:26 -04:00
|
|
|
{
|
|
|
|
color->blue = blue * 255.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
cogl_color_set_alpha_byte (CoglColor *color,
|
2010-06-06 18:03:26 -04:00
|
|
|
unsigned char alpha)
|
|
|
|
{
|
|
|
|
color->alpha = alpha;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_color_set_alpha_float (CoglColor *color,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
float alpha)
|
2010-06-06 18:03:26 -04:00
|
|
|
{
|
|
|
|
color->alpha = alpha * 255.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_color_set_alpha (CoglColor *color,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
float alpha)
|
2010-06-06 18:03:26 -04:00
|
|
|
{
|
|
|
|
color->alpha = alpha * 255.0;
|
|
|
|
}
|
|
|
|
|
2009-05-09 14:39:01 -04:00
|
|
|
void
|
|
|
|
cogl_color_premultiply (CoglColor *color)
|
|
|
|
{
|
|
|
|
color->red = (color->red * color->alpha + 128) / 255;
|
|
|
|
color->green = (color->green * color->alpha + 128) / 255;
|
|
|
|
color->blue = (color->blue * color->alpha + 128) / 255;
|
|
|
|
}
|
|
|
|
|
2010-06-06 17:57:02 -04:00
|
|
|
void
|
|
|
|
cogl_color_unpremultiply (CoglColor *color)
|
|
|
|
{
|
|
|
|
if (color->alpha != 0)
|
|
|
|
{
|
|
|
|
color->red = (color->red * 255) / color->alpha;
|
|
|
|
color->green = (color->green * 255) / color->alpha;
|
|
|
|
color->blue = (color->blue * 255) / color->alpha;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
CoglBool
|
|
|
|
cogl_color_equal (const void *v1, const void *v2)
|
2009-06-05 07:58:31 -04:00
|
|
|
{
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
const uint32_t *c1 = v1, *c2 = v2;
|
2009-06-05 07:58:31 -04:00
|
|
|
|
2011-10-13 17:34:30 -04:00
|
|
|
_COGL_RETURN_VAL_IF_FAIL (v1 != NULL, FALSE);
|
|
|
|
_COGL_RETURN_VAL_IF_FAIL (v2 != NULL, FALSE);
|
2009-06-05 07:58:31 -04:00
|
|
|
|
|
|
|
/* XXX: We don't compare the padding */
|
|
|
|
return *c1 == *c2 ? TRUE : FALSE;
|
|
|
|
}
|
|
|
|
|
2010-06-10 09:07:40 -04:00
|
|
|
void
|
|
|
|
_cogl_color_get_rgba_4ubv (const CoglColor *color,
|
Switch use of primitive glib types to c99 equivalents
The coding style has for a long time said to avoid using redundant glib
data types such as gint or gchar etc because we feel that they make the
code look unnecessarily foreign to developers coming from outside of the
Gnome developer community.
Note: When we tried to find the historical rationale for the types we
just found that they were apparently only added for consistent syntax
highlighting which didn't seem that compelling.
Up until now we have been continuing to use some of the platform
specific type such as gint{8,16,32,64} and gsize but this patch switches
us over to using the standard c99 equivalents instead so we can further
ensure that our code looks familiar to the widest range of C developers
who might potentially contribute to Cogl.
So instead of using the gint{8,16,32,64} and guint{8,16,32,64} types this
switches all Cogl code to instead use the int{8,16,32,64}_t and
uint{8,16,32,64}_t c99 types instead.
Instead of gsize we now use size_t
For now we are not going to use the c99 _Bool type and instead we have
introduced a new CoglBool type to use instead of gboolean.
Reviewed-by: Neil Roberts <neil@linux.intel.com>
(cherry picked from commit 5967dad2400d32ca6319cef6cb572e81bf2c15f0)
2012-04-16 16:56:40 -04:00
|
|
|
uint8_t *dest)
|
2010-06-10 09:07:40 -04:00
|
|
|
{
|
|
|
|
memcpy (dest, color, 4);
|
|
|
|
}
|
|
|
|
|
2013-05-13 08:24:21 -04:00
|
|
|
void
|
|
|
|
cogl_color_to_hsl (const CoglColor *color,
|
|
|
|
float *hue,
|
|
|
|
float *saturation,
|
|
|
|
float *luminance)
|
|
|
|
{
|
|
|
|
float red, green, blue;
|
|
|
|
float min, max, delta;
|
|
|
|
float h, l, s;
|
|
|
|
|
|
|
|
red = color->red / 255.0;
|
|
|
|
green = color->green / 255.0;
|
|
|
|
blue = color->blue / 255.0;
|
|
|
|
|
|
|
|
if (red > green)
|
|
|
|
{
|
|
|
|
if (red > blue)
|
|
|
|
max = red;
|
|
|
|
else
|
|
|
|
max = blue;
|
|
|
|
|
|
|
|
if (green < blue)
|
|
|
|
min = green;
|
|
|
|
else
|
|
|
|
min = blue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (green > blue)
|
|
|
|
max = green;
|
|
|
|
else
|
|
|
|
max = blue;
|
|
|
|
|
|
|
|
if (red < blue)
|
|
|
|
min = red;
|
|
|
|
else
|
|
|
|
min = blue;
|
|
|
|
}
|
|
|
|
|
|
|
|
l = (max + min) / 2;
|
|
|
|
s = 0;
|
|
|
|
h = 0;
|
|
|
|
|
|
|
|
if (max != min)
|
|
|
|
{
|
|
|
|
if (l <= 0.5)
|
|
|
|
s = (max - min) / (max + min);
|
|
|
|
else
|
|
|
|
s = (max - min) / (2.0 - max - min);
|
|
|
|
|
|
|
|
delta = max - min;
|
|
|
|
|
|
|
|
if (red == max)
|
|
|
|
h = (green - blue) / delta;
|
|
|
|
else if (green == max)
|
|
|
|
h = 2.0 + (blue - red) / delta;
|
|
|
|
else if (blue == max)
|
|
|
|
h = 4.0 + (red - green) / delta;
|
|
|
|
|
|
|
|
h *= 60;
|
|
|
|
|
|
|
|
if (h < 0)
|
|
|
|
h += 360.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hue)
|
|
|
|
*hue = h;
|
|
|
|
|
|
|
|
if (luminance)
|
|
|
|
*luminance = l;
|
|
|
|
|
|
|
|
if (saturation)
|
|
|
|
*saturation = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
cogl_color_init_from_hsl (CoglColor *color,
|
|
|
|
float hue,
|
|
|
|
float saturation,
|
|
|
|
float luminance)
|
|
|
|
{
|
|
|
|
float tmp1, tmp2;
|
|
|
|
float tmp3[3];
|
|
|
|
float clr[3];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
hue /= 360.0;
|
|
|
|
|
|
|
|
if (saturation == 0)
|
|
|
|
{
|
|
|
|
cogl_color_init_from_4f (color, luminance, luminance, luminance, 1.0f);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (luminance <= 0.5)
|
|
|
|
tmp2 = luminance * (1.0 + saturation);
|
|
|
|
else
|
|
|
|
tmp2 = luminance + saturation - (luminance * saturation);
|
|
|
|
|
|
|
|
tmp1 = 2.0 * luminance - tmp2;
|
|
|
|
|
|
|
|
tmp3[0] = hue + 1.0 / 3.0;
|
|
|
|
tmp3[1] = hue;
|
|
|
|
tmp3[2] = hue - 1.0 / 3.0;
|
|
|
|
|
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
{
|
|
|
|
if (tmp3[i] < 0)
|
|
|
|
tmp3[i] += 1.0;
|
|
|
|
|
|
|
|
if (tmp3[i] > 1)
|
|
|
|
tmp3[i] -= 1.0;
|
|
|
|
|
|
|
|
if (6.0 * tmp3[i] < 1.0)
|
|
|
|
clr[i] = tmp1 + (tmp2 - tmp1) * tmp3[i] * 6.0;
|
|
|
|
else if (2.0 * tmp3[i] < 1.0)
|
|
|
|
clr[i] = tmp2;
|
|
|
|
else if (3.0 * tmp3[i] < 2.0)
|
|
|
|
clr[i] = (tmp1 + (tmp2 - tmp1) * ((2.0 / 3.0) - tmp3[i]) * 6.0);
|
|
|
|
else
|
|
|
|
clr[i] = tmp1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cogl_color_init_from_4f (color, clr[0], clr[1], clr[2], 1.0f);
|
|
|
|
}
|