[gegl] Add gegl_color_get/set_components for introspection
- From: Daniel Sabo <daniels src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] Add gegl_color_get/set_components for introspection
- Date: Sun, 13 Oct 2013 20:54:16 +0000 (UTC)
commit bee6407a898a7d5ee4c2e2fc3d31c531104521ed
Author: Daniel Sabo <DanielSabo gmail com>
Date: Wed Oct 9 05:49:15 2013 -0700
Add gegl_color_get/set_components for introspection
gegl/gegl-introspection-support.c | 144 +++++++++++++++++++++++++++++++++++++
gegl/gegl-introspection-support.h | 25 +++++++
2 files changed, 169 insertions(+), 0 deletions(-)
---
diff --git a/gegl/gegl-introspection-support.c b/gegl/gegl-introspection-support.c
index 2176a0d..a9a57ab 100644
--- a/gegl/gegl-introspection-support.c
+++ b/gegl/gegl-introspection-support.c
@@ -60,6 +60,150 @@ gegl_format_get_name (GValue *value)
return babl_get_name (format);
}
+gdouble *
+gegl_color_get_components (GeglColor *color, GValue *value, gint *components_length)
+{
+ Babl *format;
+
+ if (G_TYPE_POINTER == G_VALUE_TYPE(value))
+ format = g_value_get_pointer (value);
+ else
+ {
+ *components_length = 0;
+ return NULL;
+ }
+
+ if (!color || !format)
+ {
+ *components_length = 0;
+ return NULL;
+ }
+ else
+ {
+ gint components = babl_format_get_n_components (format);
+ gint bpp = babl_format_get_bytes_per_pixel (format);
+ const Babl *comp_type = babl_format_get_type (format, 0);
+
+ gdouble *result = g_new (gdouble, components);
+ *components_length = components;
+
+ if (comp_type == babl_type ("u8"))
+ {
+ int i;
+ guint8 *pixel_buf = alloca (bpp * components);
+
+ gegl_color_get_pixel (color, format, pixel_buf);
+
+ for (i = 0; i < components; ++i)
+ result[i] = pixel_buf[i];
+ }
+ else if (comp_type == babl_type ("u16"))
+ {
+ int i;
+ guint16 *pixel_buf = alloca (bpp * components);
+
+ gegl_color_get_pixel (color, format, pixel_buf);
+
+ for (i = 0; i < components; ++i)
+ result[i] = pixel_buf[i];
+ }
+ else if (comp_type == babl_type ("u32"))
+ {
+ int i;
+ guint32 *pixel_buf = alloca (bpp * components);
+
+ gegl_color_get_pixel (color, format, pixel_buf);
+
+ for (i = 0; i < components; ++i)
+ result[i] = pixel_buf[i];
+ }
+ else if (comp_type == babl_type ("float"))
+ {
+ int i;
+ float *pixel_buf = alloca (bpp * components);
+
+ gegl_color_get_pixel (color, format, pixel_buf);
+
+ for (i = 0; i < components; ++i)
+ result[i] = pixel_buf[i];
+ }
+ else if (comp_type == babl_type ("double"))
+ {
+ gegl_color_get_pixel (color, format, result);
+ }
+ else
+ {
+ g_free (result);
+ *components_length = 0;
+ }
+
+ return result;
+ }
+}
+
+void
+gegl_color_set_components (GeglColor *color, GValue *value, gdouble *components, gint components_length)
+{
+ Babl *format;
+
+ if (!(G_TYPE_POINTER == G_VALUE_TYPE(value)))
+ return;
+ format = g_value_get_pointer (value);
+
+ if (!color || !format || components_length != babl_format_get_n_components (format))
+ return;
+ else
+ {
+ gint bpp = babl_format_get_bytes_per_pixel (format);
+ const Babl *comp_type = babl_format_get_type (format, 0);
+
+ if (comp_type == babl_type ("u8"))
+ {
+ int i;
+ guint8 *pixel_buf = alloca (bpp * components_length);
+
+ for (i = 0; i < components_length; ++i)
+ pixel_buf[i] = components[i];
+
+ gegl_color_set_pixel (color, format, pixel_buf);
+ }
+ else if (comp_type == babl_type ("u16"))
+ {
+ int i;
+ guint16 *pixel_buf = alloca (bpp * components_length);
+
+ for (i = 0; i < components_length; ++i)
+ pixel_buf[i] = components[i];
+
+ gegl_color_set_pixel (color, format, pixel_buf);
+ }
+ else if (comp_type == babl_type ("u32"))
+ {
+ int i;
+ guint32 *pixel_buf = alloca (bpp * components_length);
+
+ for (i = 0; i < components_length; ++i)
+ pixel_buf[i] = components[i];
+
+ gegl_color_set_pixel (color, format, pixel_buf);
+ }
+ else if (comp_type == babl_type ("float"))
+ {
+ int i;
+ float *pixel_buf = alloca (bpp * components_length);
+
+ for (i = 0; i < components_length; ++i)
+ pixel_buf[i] = components[i];
+
+ gegl_color_set_pixel (color, format, pixel_buf);
+ }
+ else if (comp_type == babl_type ("double"))
+ {
+ gegl_color_set_pixel (color, format, components);
+ }
+ }
+}
+
GeglRectangle *
gegl_node_introspectable_get_bounding_box (GeglNode *node)
{
diff --git a/gegl/gegl-introspection-support.h b/gegl/gegl-introspection-support.h
index e26ed38..18a5369 100644
--- a/gegl/gegl-introspection-support.h
+++ b/gegl/gegl-introspection-support.h
@@ -53,6 +53,31 @@ const gchar *
gegl_format_get_name (GValue *format);
/**
+ * gegl_color_get_components:
+ * @color: (transfer none): a #GeglColor
+ * @format: A Babl pointer
+ * @components_length: (out): The length of the returned buffer
+ *
+ * Get the component values of the color in @format.
+ *
+ * Return value: (transfer full) (array length=components_length): The color components
+ */
+gdouble *
+gegl_color_get_components (GeglColor *color, GValue *format, gint *components_length);
+
+ /**
+ * gegl_color_set_components:
+ * @color: (transfer none): a #GeglColor
+ * @format: A Babl pointer
+ * @components: (transfer none) (array length=components_length): The color components.
+ * @components_length: The length of the components array
+ *
+ * Set the color using the component values as @format.
+ */
+void
+gegl_color_set_components (GeglColor *color, GValue *format, gdouble *components, gint components_length);
+
+ /**
* gegl_node_introspectable_get_bounding_box:
* @node: a #GeglNode
*
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]