[Cogl] [PATCH 1/2] Add cogl_color_init_from_color()

Damien Lespiau damien.lespiau at gmail.com
Thu May 31 03:41:18 PDT 2012


From: Damien Lespiau <damien.lespiau at intel.com>

Handy to copy a CoglColor into an already allocated one.
---
 cogl/cogl-color.c                      |   11 +++++++++++
 cogl/cogl-color.h                      |   11 +++++++++++
 doc/reference/cogl2/cogl2-sections.txt |    1 +
 3 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/cogl/cogl-color.c b/cogl/cogl-color.c
index ed4dd46..de6a0a5 100644
--- a/cogl/cogl-color.c
+++ b/cogl/cogl-color.c
@@ -95,6 +95,17 @@ cogl_color_init_from_4fv (CoglColor *color,
   color->alpha =  (color_array[3] * 255);
 }
 
+void
+cogl_color_init_from_color (CoglColor *color,
+                            CoglColor *src)
+{
+  _COGL_RETURN_IF_FAIL (color != NULL);
+  _COGL_RETURN_IF_FAIL (src != NULL);
+
+  /* don't copy the padding bytes */
+  memcpy (color, src, 4);
+}
+
 unsigned char
 cogl_color_get_red_byte (const CoglColor *color)
 {
diff --git a/cogl/cogl-color.h b/cogl/cogl-color.h
index 964482a..83aa223 100644
--- a/cogl/cogl-color.h
+++ b/cogl/cogl-color.h
@@ -132,6 +132,17 @@ cogl_color_init_from_4fv (CoglColor *color,
                           float *color_array);
 
 /**
+ * cogl_color_init_from_color:
+ * @color: A pointer to a #CoglColor to initialize
+ * @src: A #CoglColor with which to initialize @color
+ *
+ * Since: 2.0
+ */
+void
+cogl_color_init_from_color (CoglColor *color,
+                            CoglColor *src);
+
+/**
  * cogl_color_get_red_byte:
  * @color: a #CoglColor
  *
diff --git a/doc/reference/cogl2/cogl2-sections.txt b/doc/reference/cogl2/cogl2-sections.txt
index 856d9cb..b006f7f 100644
--- a/doc/reference/cogl2/cogl2-sections.txt
+++ b/doc/reference/cogl2/cogl2-sections.txt
@@ -451,6 +451,7 @@ cogl_color_free
 cogl_color_init_from_4ub
 cogl_color_init_from_4f
 cogl_color_init_from_4fv
+cogl_color_init_color
 
 <SUBSECTION>
 cogl_color_get_red
-- 
1.7.7.5



More information about the Cogl mailing list