[gegl] tools: changed img_cmp to use gegl:image-compare
- From: Ville Sokk <villesokk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gegl] tools: changed img_cmp to use gegl:image-compare
- Date: Wed, 15 Aug 2012 18:04:48 +0000 (UTC)
commit 130d2ad9d399358bd9bcb6a1cbcea69d9b624b67
Author: Ville Sokk <ville sokk gmail com>
Date: Wed Aug 15 20:57:29 2012 +0300
tools: changed img_cmp to use gegl:image-compare
operations/common/image-compare.c | 22 +++--
tools/img_cmp.c | 227 ++++++++++++-------------------------
2 files changed, 89 insertions(+), 160 deletions(-)
---
diff --git a/operations/common/image-compare.c b/operations/common/image-compare.c
index a331811..67a6c13 100644
--- a/operations/common/image-compare.c
+++ b/operations/common/image-compare.c
@@ -69,16 +69,20 @@ process (GeglOperation *operation,
gdouble diffsum = 0.0;
gint wrong_pixels = 0;
const Babl* cielab = babl_format ("CIE Lab float");
- gint rowstride_in, rowstride_aux, rowstride_out, pixels, i;
+ const Babl* srgb = babl_format ("R'G'B' u8");
+ gint pixels, i;
gfloat *in_buf, *aux_buf, *a, *b;
guchar *out_buf, *out;
if (aux == NULL)
return TRUE;
- in_buf = (void *) gegl_buffer_linear_open (input, result, &rowstride_in, cielab);
- aux_buf = (void *) gegl_buffer_linear_open (aux, result, &rowstride_aux, cielab);
- out_buf = (void *) gegl_buffer_linear_open (output, result, &rowstride_out, babl_format ("R'G'B' u8"));
+ in_buf = g_malloc (result->height * result->width * babl_format_get_bytes_per_pixel (cielab));
+ aux_buf = g_malloc (result->height * result->width * babl_format_get_bytes_per_pixel (cielab));
+ out_buf = g_malloc (result->height * result->width * babl_format_get_bytes_per_pixel (srgb));
+
+ gegl_buffer_get (input, result, 1.0, cielab, in_buf, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
+ gegl_buffer_get (aux, result, 1.0, cielab, aux_buf, GEGL_AUTO_ROWSTRIDE, GEGL_ABYSS_NONE);
a = in_buf;
b = aux_buf;
@@ -140,9 +144,11 @@ process (GeglOperation *operation,
out += 3;
}
- gegl_buffer_linear_close (input, in_buf);
- gegl_buffer_linear_close (aux, aux_buf);
- gegl_buffer_linear_close (output, out_buf);
+ gegl_buffer_set (output, result, 1.0, srgb, out_buf, GEGL_AUTO_ROWSTRIDE);
+
+ g_free (in_buf);
+ g_free (aux_buf);
+ g_free (out_buf);
props->wrong_pixels = wrong_pixels;
props->max_diff = max_diff;
@@ -167,7 +173,7 @@ gegl_chant_class_init (GeglChantClass *klass)
gegl_operation_class_set_keys (operation_class,
"name" , "gegl:image-compare",
- "categories" , "misc",
+ "categories" , "programming",
"description", _("Compares if input and aux buffers are "
"different. Results are saved in the "
"properties."),
diff --git a/tools/img_cmp.c b/tools/img_cmp.c
index d59ece0..705a1ad 100644
--- a/tools/img_cmp.c
+++ b/tools/img_cmp.c
@@ -1,4 +1,4 @@
-#include <gegl.h>
+#include <gegl.h>
#include <math.h>
#include <string.h>
@@ -8,9 +8,10 @@ gint
main (gint argc,
gchar **argv)
{
- GeglBuffer *bufferA = NULL;
- GeglBuffer *bufferB = NULL;
- GeglBuffer *debug_buf = NULL;
+ GeglNode *gegl, *imgA, *imgB, *comparison;
+ GeglRectangle boundsA, boundsB;
+ gdouble max_diff, avg_diff_wrong, avg_diff_total;
+ gint wrong_pixels, total_pixels;
g_thread_init (NULL);
gegl_init (&argc, &argv);
@@ -24,162 +25,84 @@ main (gint argc,
return 1;
}
- {
- GeglNode *graph, *sink;
- graph = gegl_graph (sink=gegl_node ("gegl:buffer-sink", "buffer", &bufferA, NULL,
- gegl_node ("gegl:load", "path", argv[1], NULL)));
- gegl_node_process (sink);
- g_object_unref (graph);
- if (!bufferA)
- {
- g_printerr ("Failed to open %s\n", argv[1]);
- return 1;
- }
-
- graph = gegl_graph (sink=gegl_node ("gegl:buffer-sink", "buffer", &bufferB, NULL,
- gegl_node ("gegl:load", "path", argv[2], NULL)));
- gegl_node_process (sink);
- g_object_unref (graph);
- if (!bufferB)
- {
- g_printerr ("Failed to open %s\n", argv[2]);
- return 1;
- }
- }
-
- if (gegl_buffer_get_width (bufferA) != gegl_buffer_get_width (bufferB) ||
- gegl_buffer_get_height (bufferA) != gegl_buffer_get_height (bufferB))
+ gegl = gegl_node_new ();
+ imgA = gegl_node_new_child (gegl,
+ "operation", "gegl:load",
+ "path", argv[1],
+ NULL);
+ imgB = gegl_node_new_child (gegl,
+ "operation", "gegl:load",
+ "path", argv[2],
+ NULL);
+
+ boundsA = gegl_node_get_bounding_box (imgA);
+ boundsB = gegl_node_get_bounding_box (imgB);
+ total_pixels = boundsA.width * boundsA.height;
+
+ if (boundsA.width != boundsB.width || boundsA.height != boundsB.height)
{
g_printerr ("%s and %s differ in size\n", argv[1], argv[2]);
g_printerr (" %ix%i vs %ix%i\n",
- gegl_buffer_get_width (bufferA), gegl_buffer_get_height (bufferA),
- gegl_buffer_get_width (bufferB), gegl_buffer_get_height (bufferB));
+ boundsA.width, boundsA.height, boundsB.width, boundsB.height);
return 1;
}
- debug_buf = gegl_buffer_new (gegl_buffer_get_extent (bufferA), babl_format ("R'G'B' u8"));
-
-
-
- {
- gfloat *bufA, *bufB;
- gfloat *a, *b;
- guchar *debug, *d;
- gint rowstrideA, rowstrideB, dRowstride;
- gint pixels;
- gint wrong_pixels=0;
- gint i;
- gdouble diffsum = 0.0;
- gdouble max_diff = 0.0;
-
- pixels = gegl_buffer_get_pixel_count (bufferA);
-
- bufA = (void*)gegl_buffer_linear_open (bufferA, NULL, &rowstrideA,
- babl_format ("CIE Lab float"));
- bufB = (void*)gegl_buffer_linear_open (bufferB, NULL, &rowstrideB,
- babl_format ("CIE Lab float"));
- debug = (void*)gegl_buffer_linear_open (debug_buf, NULL, &dRowstride, babl_format ("R'G'B' u8"));
-
- a = bufA;
- b = bufB;
- d = debug;
-
- for (i=0;i<pixels;i++)
- {
- gdouble diff = sqrt ( SQR(a[0]-b[0])+
- SQR(a[1]-b[1])+
- SQR(a[2]-b[2])
- /*+SQR(a[3]-b[3])*/);
- if (diff>=0.01)
- {
- wrong_pixels++;
- diffsum += diff;
- if (diff > max_diff)
- max_diff = diff;
- d[0]=(diff/100.0 * 255);
- d[1]=0;
- d[2]=a[0]/100.0*255;
- }
- else
- {
- d[0]=a[0]/100.0*255;
- d[1]=a[0]/100.0*255;
- d[2]=a[0]/100.0*255;
- }
- a+=3;
- b+=3;
- d+=3;
- }
-
- a = bufA;
- b = bufB;
- d = debug;
-
- if (wrong_pixels)
- for (i=0;i<pixels;i++)
- {
- gdouble diff = sqrt ( SQR(a[0]-b[0])+
- SQR(a[1]-b[1])+
- SQR(a[2]-b[2])
- /*+SQR(a[3]-b[3])*/);
- if (diff>=0.01)
- {
- d[0]=(100-a[0])/100.0*64+32;
- d[1]=(diff/max_diff * 255);
- d[2]=0;
- }
- else
- {
- d[0]=a[0]/100.0*255;
- d[1]=a[0]/100.0*255;
- d[2]=a[0]/100.0*255;
- }
- a+=3;
- b+=3;
- d+=3;
- }
-
- gegl_buffer_linear_close (bufferA, bufA);
- gegl_buffer_linear_close (bufferB, bufB);
- gegl_buffer_linear_close (debug_buf, debug);
-
- if (max_diff >= 0.1)
- {
- g_printerr ("%s and %s differ\n"
- " wrong pixels : %i/%i (%2.2f%%)\n"
- " max Îe : %2.3f\n"
- " avg Îe (wrong) : %2.3f(wrong) %2.3f(total)\n",
- argv[1], argv[2],
- wrong_pixels, pixels, (wrong_pixels*100.0/pixels),
- max_diff,
- diffsum/wrong_pixels,
- diffsum/pixels);
- if (max_diff > 1.5 &&
- !strstr (argv[2], "broken"))
- {
- GeglNode *sink;
- gchar *debug_path = g_malloc (strlen (argv[2])+16);
- memcpy (debug_path, argv[2], strlen (argv[2])+1);
- memcpy (debug_path + strlen(argv[2])-4, "-diff.png", 11);
- gegl_graph (sink=gegl_node ("gegl:png-save",
- "path", debug_path, NULL,
- gegl_node ("gegl:buffer-source", "buffer", debug_buf, NULL)));
- gegl_node_process (sink);
- return 1;
- }
- if (strstr (argv[2], "broken"))
- g_print ("because the test is expected to fail ");
- else
- g_print ("because the error is small ");
- g_print ("we'll say ");
- }
-
- }
+ comparison = gegl_node_create_child (gegl, "gegl:image-compare");
+ gegl_node_link (imgA, comparison);
+ gegl_node_connect_to (imgB, "output", comparison, "aux");
+ gegl_node_process (comparison);
+ gegl_node_get (comparison,
+ "max diff", &max_diff,
+ "avg-diff-wrong", &avg_diff_wrong,
+ "avg-diff-total", &avg_diff_total,
+ "wrong-pixels", &wrong_pixels,
+ NULL);
+
+ if (max_diff >= 0.1)
+ {
+ g_printerr ("%s and %s differ\n"
+ " wrong pixels : %i/%i (%2.2f%%)\n"
+ " max Îe : %2.3f\n"
+ " avg Îe (wrong) : %2.3f(wrong) %2.3f(total)\n",
+ argv[1], argv[2],
+ wrong_pixels, total_pixels,
+ (wrong_pixels*100.0/total_pixels), max_diff,
+ avg_diff_wrong, avg_diff_total);
+
+ if (max_diff > 1.5 &&
+ !strstr (argv[2], "broken"))
+ {
+ GeglNode *save;
+ gchar *debug_path = g_malloc (strlen (argv[2])+16);
+
+ memcpy (debug_path, argv[2], strlen (argv[2])+1);
+ memcpy (debug_path + strlen(argv[2])-4, "-diff.png", 11);
+
+ save = gegl_node_new_child (gegl,
+ "operation", "gegl:png-save",
+ "path", debug_path,
+ NULL);
+ gegl_node_link (comparison, save);
+ gegl_node_process (save);
+
+
+ /*gegl_graph (sink=gegl_node ("gegl:png-save",
+ "path", debug_path, NULL,
+ gegl_node ("gegl:buffer-source", "buffer", debug_buf, NULL)));*/
+
+ return 1;
+ }
+ if (strstr (argv[2], "broken"))
+ g_print ("because the test is expected to fail ");
+ else
+ g_print ("because the error is small ");
+ g_print ("we'll say ");
+ }
g_print ("%s and %s are identical\n", argv[1], argv[2]);
- g_object_unref (debug_buf);
- g_object_unref (bufferA);
- g_object_unref (bufferB);
+
+ g_object_unref (gegl);
+
gegl_exit ();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]