[clutter] image: Add a data setter using GBytes



commit 65c8b11604e299ef2788a69a76df24d8a5ddb870
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Mon Jun 4 10:34:22 2012 +0100

    image: Add a data setter using GBytes
    
    The plain C bytes array, while convenient from a C perspective, is not
    well handled by language bindings: the length of the array is not
    specified, and it's only just implied by the image data size, rowstride,
    and pixel format.
    
    GBytes is a read-only bytes buffer that has an implicit length; we can
    use it as the storage medium so that language bindings can actually
    function correctly.

 clutter/clutter-image.c                    |   65 +++++++++++++++++++++++++++-
 clutter/clutter-image.h                    |    8 +++
 clutter/clutter.symbols                    |    1 +
 doc/reference/clutter/clutter-sections.txt |    1 +
 4 files changed, 74 insertions(+), 1 deletions(-)
---
diff --git a/clutter/clutter-image.c b/clutter/clutter-image.c
index 95d88b2..fb5738e 100644
--- a/clutter/clutter-image.c
+++ b/clutter/clutter-image.c
@@ -183,7 +183,7 @@ clutter_image_new (void)
  * @row_stride: the length of each row inside @data
  * @error: return location for a #GError, or %NULL
  *
- * Sets the image data to be display by @image.
+ * Sets the image data to be displayed by @image.
  *
  * If the image data was successfully loaded, the @image will be invalidated.
  *
@@ -236,6 +236,69 @@ clutter_image_set_data (ClutterImage     *image,
 }
 
 /**
+ * clutter_image_set_bytes:
+ * @image: a #ClutterImage
+ * @data: the image data, as a #GBytes
+ * @pixel_format: the Cogl pixel format of the image data
+ * @width: the width of the image data
+ * @height: the height of the image data
+ * @row_stride: the length of each row inside @data
+ * @error: return location for a #GError, or %NULL
+ *
+ * Sets the image data stored inside a #GBytes to be displayed by @image.
+ *
+ * If the image data was successfully loaded, the @image will be invalidated.
+ *
+ * In case of error, the @error value will be set, and this function will
+ * return %FALSE.
+ *
+ * The image data contained inside the #GBytes is copied in texture memory,
+ * and no additional reference is acquired on the @data.
+ *
+ * Return value: %TRUE if the image data was successfully loaded,
+ *   and %FALSE otherwise.
+ *
+ * Since: 1.12
+ */
+gboolean
+clutter_image_set_bytes (ClutterImage     *image,
+                         GBytes           *data,
+                         CoglPixelFormat   pixel_format,
+                         guint             width,
+                         guint             height,
+                         guint             row_stride,
+                         GError          **error)
+{
+  ClutterImagePrivate *priv;
+
+  g_return_val_if_fail (CLUTTER_IS_IMAGE (image), FALSE);
+  g_return_val_if_fail (data != NULL, FALSE);
+
+  priv = image->priv;
+
+  if (priv->texture != NULL)
+    cogl_object_unref (priv->texture);
+
+  priv->texture = cogl_texture_new_from_data (width, height,
+                                              COGL_TEXTURE_NONE,
+                                              pixel_format,
+                                              COGL_PIXEL_FORMAT_ANY,
+                                              row_stride,
+                                              g_bytes_get_data (data, NULL));
+  if (priv->texture == NULL)
+    {
+      g_set_error_literal (error, CLUTTER_IMAGE_ERROR,
+                           CLUTTER_IMAGE_ERROR_INVALID_DATA,
+                           _("Unable to load image data"));
+      return FALSE;
+    }
+
+  clutter_content_invalidate (CLUTTER_CONTENT (image));
+
+  return TRUE;
+}
+
+/**
  * clutter_image_set_area:
  * @image: a #ClutterImage
  * @data: (array): the image data, as an array of bytes
diff --git a/clutter/clutter-image.h b/clutter/clutter-image.h
index 178a2d3..af8df1e 100644
--- a/clutter/clutter-image.h
+++ b/clutter/clutter-image.h
@@ -122,6 +122,14 @@ gboolean                clutter_image_set_area          (ClutterImage
                                                          const cairo_rectangle_int_t  *rect,
                                                          guint                         row_stride,
                                                          GError                      **error);
+CLUTTER_AVAILABLE_IN_1_12
+gboolean                clutter_image_set_bytes         (ClutterImage                 *image,
+                                                         GBytes                       *data,
+                                                         CoglPixelFormat               pixel_format,
+                                                         guint                         width,
+                                                         guint                         height,
+                                                         guint                         row_stride,
+                                                         GError                      **error);
 
 #if defined(COGL_ENABLE_EXPERIMENTAL_API) && defined(CLUTTER_ENABLE_EXPERIMENTAL_API)
 CLUTTER_AVAILABLE_IN_1_10
diff --git a/clutter/clutter.symbols b/clutter/clutter.symbols
index 0c71a6e..c7c2578 100644
--- a/clutter/clutter.symbols
+++ b/clutter/clutter.symbols
@@ -756,6 +756,7 @@ clutter_image_get_texture
 clutter_image_get_type
 clutter_image_new
 clutter_image_set_area
+clutter_image_set_bytes
 clutter_image_set_data
 clutter_init
 clutter_init_error_get_type
diff --git a/doc/reference/clutter/clutter-sections.txt b/doc/reference/clutter/clutter-sections.txt
index 1a3abae..d10fa56 100644
--- a/doc/reference/clutter/clutter-sections.txt
+++ b/doc/reference/clutter/clutter-sections.txt
@@ -3114,6 +3114,7 @@ CLUTTER_IMAGE_ERROR
 ClutterImageError
 clutter_image_new
 clutter_image_set_data
+clutter_image_set_bytes
 clutter_image_set_area
 clutter_image_get_texture
 <SUBSECTION Standard>



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]