[gnome-photos/wip/rishi/unit-tests-gegl: 1/3] Add photos_gegl_compute_checksum_for_buffer



commit 557acd67527392146486bc5e5bcf5823a915cbe9
Author: Debarshi Ray <debarshir gnome org>
Date:   Sun Nov 18 15:27:57 2018 +0100

    Add photos_gegl_compute_checksum_for_buffer

 src/photos-gegl.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/photos-gegl.h |  4 +++-
 2 files changed, 54 insertions(+), 2 deletions(-)
---
diff --git a/src/photos-gegl.c b/src/photos-gegl.c
index b3b02cff..819309c0 100644
--- a/src/photos-gegl.c
+++ b/src/photos-gegl.c
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2013 – 2017 Red Hat, Inc.
+ * Copyright © 2013 – 2018 Red Hat, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -505,6 +505,56 @@ photos_gegl_buffer_zoom_finish (GeglBuffer *buffer, GAsyncResult *res, GError **
 }
 
 
+gchar *
+photos_gegl_compute_checksum_for_buffer  (GChecksumType checksum_type, GeglBuffer *buffer)
+{
+  const Babl *format;
+  g_autoptr (GChecksum) checksum = NULL;
+  GeglRectangle bbox;
+  GeglRectangle roi;
+  const gchar *str;
+  gchar *ret_val = NULL;
+  gint bpp;
+  gint i;
+  gint stride;
+  g_autofree guchar *buf = NULL;
+
+  checksum = g_checksum_new (checksum_type);
+  if (checksum == NULL)
+    goto out;
+
+  bbox = *gegl_buffer_get_extent (buffer);
+
+  roi.x = bbox.x;
+  roi.y = bbox.y;
+  roi.height = 1;
+  roi.width = bbox.width;
+
+  format = gegl_buffer_get_format (buffer);
+  bpp = babl_format_get_bytes_per_pixel (format);
+
+  buf = g_malloc0_n ((gsize) bbox.width, (gsize) bpp);
+
+  if (bpp > 0 && bbox.width > 0 && bbox.width > G_MAXINT / bpp)
+    goto out;
+
+  stride = bbox.width * bpp;
+
+  for (i = 0; i < bbox.height; i++)
+    {
+      gegl_buffer_get (buffer, &roi, 1.0, format, buf, stride, GEGL_ABYSS_NONE);
+      g_checksum_update (checksum, buf, (gssize) stride);
+      roi.y++;
+    }
+
+  str = g_checksum_get_string (checksum);
+  ret_val = g_strdup (str);
+
+ out:
+  return ret_val;
+}
+
+
 GdkPixbuf *
 photos_gegl_create_pixbuf_from_node (GeglNode *node)
 {
diff --git a/src/photos-gegl.h b/src/photos-gegl.h
index d902300b..716458b3 100644
--- a/src/photos-gegl.h
+++ b/src/photos-gegl.h
@@ -1,6 +1,6 @@
 /*
  * Photos - access, organize and share your photos on GNOME
- * Copyright © 2013 – 2017 Red Hat, Inc.
+ * Copyright © 2013 – 2018 Red Hat, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -39,6 +39,8 @@ void             photos_gegl_buffer_zoom_async            (GeglBuffer *buffer,
 
 GeglBuffer      *photos_gegl_buffer_zoom_finish           (GeglBuffer *buffer, GAsyncResult *res, GError 
**error);
 
+gchar           *photos_gegl_compute_checksum_for_buffer  (GChecksumType checksum_type, GeglBuffer *buffer);
+
 GdkPixbuf       *photos_gegl_create_pixbuf_from_node      (GeglNode *node);
 
 GeglBuffer      *photos_gegl_dup_buffer_from_node         (GeglNode *node, const Babl *format);


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