summaryrefslogtreecommitdiff
path: root/libappstream-glib/as-image.c
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2014-05-13 17:14:07 +0100
committerRichard Hughes <richard@hughsie.com>2014-05-13 17:14:07 +0100
commit13f1b126a3ec00c7f199aeee9ee37f412a7337c9 (patch)
treeea1cedef0a24e3ec9ccfb28d06ac20b031cb5d02 /libappstream-glib/as-image.c
parentd57a0ac8bc9d814ab29a7cbcfddd77b4e33f64f3 (diff)
downloadappstream-glib-13f1b126a3ec00c7f199aeee9ee37f412a7337c9.tar.gz
Add as_image_get_md5()
This is not supposed to be a secure hash.
Diffstat (limited to 'libappstream-glib/as-image.c')
-rw-r--r--libappstream-glib/as-image.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/libappstream-glib/as-image.c b/libappstream-glib/as-image.c
index 4ddcdbd..9df7616 100644
--- a/libappstream-glib/as-image.c
+++ b/libappstream-glib/as-image.c
@@ -43,6 +43,7 @@ struct _AsImagePrivate
{
AsImageKind kind;
gchar *url;
+ gchar *md5;
guint width;
guint height;
GdkPixbuf *pixbuf;
@@ -64,6 +65,7 @@ as_image_finalize (GObject *object)
if (priv->pixbuf != NULL)
g_object_unref (priv->pixbuf);
g_free (priv->url);
+ g_free (priv->md5);
G_OBJECT_CLASS (as_image_parent_class)->finalize (object);
}
@@ -145,6 +147,23 @@ as_image_get_url (AsImage *image)
}
/**
+ * as_image_get_md5:
+ * @image: a #AsImage instance.
+ *
+ * Gets the string representation of the pixbuf hash value.
+ *
+ * Returns: string representing the MD5 sum, or %NULL if unset
+ *
+ * Since: 0.1.6
+ **/
+const gchar *
+as_image_get_md5 (AsImage *image)
+{
+ AsImagePrivate *priv = GET_PRIVATE (image);
+ return priv->md5;
+}
+
+/**
* as_image_get_width:
* @image: a #AsImage instance.
*
@@ -291,8 +310,16 @@ void
as_image_set_pixbuf (AsImage *image, GdkPixbuf *pixbuf)
{
AsImagePrivate *priv = GET_PRIVATE (image);
+ guchar *data;
+ guint len;
+
if (priv->pixbuf != NULL)
g_object_unref (priv->pixbuf);
+ if (priv->md5 == NULL) {
+ data = gdk_pixbuf_get_pixels_with_length (pixbuf, &len);
+ priv->md5 = g_compute_checksum_for_data (G_CHECKSUM_MD5,
+ data, len);
+ }
priv->pixbuf = g_object_ref (pixbuf);
}