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



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

    Add photos_gegl_compute_checksum_for_buffer
    
    https://gitlab.gnome.org/GNOME/gnome-photos/merge_requests/84

 src/photos-gegl.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 src/photos-gegl.h |  4 +++-
 2 files changed, 53 insertions(+), 2 deletions(-)
---
diff --git a/src/photos-gegl.c b/src/photos-gegl.c
index 6a09fe97..186f1613 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
@@ -507,6 +507,55 @@ 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);
+
+  if (bpp > 0 && bbox.width > 0 && bbox.width > G_MAXINT / bpp)
+    goto out;
+
+  stride = bpp * bbox.width;
+  buf = (guchar *) g_malloc0_n ((gsize) bbox.width, (gsize) 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 27bf3062..550a1dd8 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]