[Cogl] [PATCH 3/3] color: Add a function to shade colors
Damien Lespiau
damien.lespiau at intel.com
Sat May 18 22:04:40 PDT 2013
---
cogl/cogl-color.c | 17 +++++++++++++++++
cogl/cogl-color.h | 15 +++++++++++++++
doc/reference/cogl2/cogl2-sections.txt | 1 +
3 files changed, 33 insertions(+)
diff --git a/cogl/cogl-color.c b/cogl/cogl-color.c
index 0dba9da..123851a 100644
--- a/cogl/cogl-color.c
+++ b/cogl/cogl-color.c
@@ -395,6 +395,23 @@ cogl_color_init_from_hsl (CoglColor *color,
}
void
+cogl_color_shade (const CoglColor *color,
+ float factor,
+ CoglColor *result)
+{
+ float h, l, s;
+
+ cogl_color_to_hsl (color, &h, &l, &s);
+
+ l = CLAMP (l * factor, 0.0, 1.0);
+ s = CLAMP (s * factor, 0.0, 1.0);
+
+ cogl_color_init_from_hsl (result, h, l, s);
+
+ result->alpha = color->alpha;
+}
+
+void
_cogl_color_get_rgba_4fv (const CoglColor *color,
float *dest)
{
diff --git a/cogl/cogl-color.h b/cogl/cogl-color.h
index 7e520a9..5df29b2 100644
--- a/cogl/cogl-color.h
+++ b/cogl/cogl-color.h
@@ -523,6 +523,21 @@ cogl_color_init_from_hsl (CoglColor *color,
float luminance,
float saturation);
+/**
+ * cogl_color_shade:
+ * @color: a #CoglColor
+ * @factor: the shade factor to apply
+ * @result: (out caller-allocates): return location for the shaded color
+ *
+ * Shades @color by @factor and saves the modified color into @result. This
+ * involves converting the color to HLS, applying the factor to the luminance
+ * and saturation before converting it back to RBGA.
+ */
+void
+cogl_color_shade (const CoglColor *color,
+ float factor,
+ CoglColor *result);
+
COGL_END_DECLS
#endif /* __COGL_COLOR_H__ */
diff --git a/doc/reference/cogl2/cogl2-sections.txt b/doc/reference/cogl2/cogl2-sections.txt
index 4ac1148..6b76c4d 100644
--- a/doc/reference/cogl2/cogl2-sections.txt
+++ b/doc/reference/cogl2/cogl2-sections.txt
@@ -632,6 +632,7 @@ cogl_color_equal
<SUBSECTION>
cogl_color_init_from_hls
cogl_color_to_hls
+cogl_color_shade
</SECTION>
<SECTION>
--
1.8.1.4
More information about the Cogl
mailing list