[gegl] tools/gegl-imcmp: assume pass if no reference



commit 0e99d86fa71404244ddd15371f192d39f70fbe14
Author: Øyvind Kolås <pippin gimp org>
Date:   Thu May 28 02:56:20 2015 +0200

    tools/gegl-imcmp: assume pass if no reference
    
    To make the distributed GEGL tarballs smaller, assume the second argument to be the reference image and 
silently succeed if it doesn't exist.

 tools/gegl-imgcmp.c |   48 +++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 47 insertions(+), 1 deletions(-)
---
diff --git a/tools/gegl-imgcmp.c b/tools/gegl-imgcmp.c
index c312815..35483d8 100644
--- a/tools/gegl-imgcmp.c
+++ b/tools/gegl-imgcmp.c
@@ -3,9 +3,13 @@
 #include <errno.h>
 #include <math.h>
 #include <string.h>
+#include <stdio.h>
+#include <unistd.h>
 
-#define DEFAULT_ERROR_DIFFERENCE 1.5
+/* running the gegl-imgcmp should build up the list of checksums..
+ */
 
+#define DEFAULT_ERROR_DIFFERENCE 1.5
 #define SQR(x) ((x) * (x))
 
 typedef enum {
@@ -15,6 +19,43 @@ typedef enum {
     ERROR_PIXELS_DIFFERENT,
 } ExitCode;
 
+const gchar *compute_image_checksum (const char *path);
+const gchar *compute_image_checksum (const char *path)
+{
+  GeglNode *gegl, *img;
+  GeglRectangle  bounds;
+  GChecksum *checksum = g_checksum_new (G_CHECKSUM_MD5);
+  guchar *buf;
+  const gchar *ret;
+
+  gegl = gegl_node_new ();
+  img = gegl_node_new_child (gegl,
+                             "operation", "gegl:load",
+                             "path", path,
+                             NULL);
+  bounds = gegl_node_get_bounding_box (img);
+  fprintf (stderr, "%ix%i\n", bounds.width, bounds.height);
+
+  buf = g_malloc (bounds.width * bounds.height * 4);
+  gegl_node_blit (img, 1.0, &bounds, babl_format("R'G'B'A u8"), buf,
+    GEGL_AUTO_ROWSTRIDE, GEGL_BLIT_DEFAULT);
+  
+  g_checksum_update (checksum, buf, bounds.width * bounds.height * 4);
+  ret = g_checksum_get_string (checksum);
+  ret = g_strdup (ret);
+
+  g_free (buf);
+  g_object_unref (gegl);
+
+  return ret;
+}
+
+const gchar *get_image_checksum (const char *path);
+const gchar *get_image_checksum (const char *path)
+{
+  return compute_image_checksum (path);
+}
+
 gint
 main (gint    argc,
       gchar **argv)
@@ -49,6 +90,11 @@ main (gint    argc,
         error_diff = t;
     }
 
+  if( access( argv[3], F_OK ) != 0 ) {
+    g_print ("missing reference, assuming SUCCESS\n");
+    return SUCCESS;
+  }
+
   gegl = gegl_node_new ();
   imgA = gegl_node_new_child (gegl,
                               "operation", "gegl:load",


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