[gegl] Added an XML composition driven test system



commit 7d84c22fef081c1bd5958fddfe255cca65a08880
Author: �yvind Kolås <pippin gimp org>
Date:   Sun Jan 17 16:07:53 2010 +0000

    Added an XML composition driven test system

 configure.ac                              |    2 +
 tests/Makefile.am                         |    2 +-
 tests/compositions/.gitignore             |    5 +
 tests/compositions/Makefile.am            |   39 +++++
 tests/compositions/clones.xml             |  223 +++++++++++++++++++++++++++++
 tests/compositions/data/.gitignore        |    2 +
 tests/compositions/data/Makefile.am       |    1 +
 tests/compositions/data/car-stack.jpg     |  Bin 0 -> 69071 bytes
 tests/compositions/data/gegl.png          |  Bin 0 -> 11248 bytes
 tests/compositions/data/grid.png          |  Bin 0 -> 314 bytes
 tests/compositions/reference/clones.png   |  Bin 0 -> 817820 bytes
 tests/compositions/reference/reflect.png  |  Bin 0 -> 930 bytes
 tests/compositions/reference/reflect2.png |  Bin 0 -> 959 bytes
 tests/compositions/reference/rotate.png   |  Bin 0 -> 9424 bytes
 tests/compositions/reflect.xml            |   10 ++
 tests/compositions/reflect2.xml           |   10 ++
 tests/compositions/rotate.xml             |    9 ++
 tests/compositions/verify-results.sh      |   14 ++
 tools/Makefile.am                         |    2 +-
 tools/img_cmp.c                           |  108 ++++++++++++++
 20 files changed, 425 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index ffa6db3..429feef 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1018,6 +1018,8 @@ examples/Makefile
 examples/data/Makefile
 tests/Makefile
 tests/buffer/Makefile
+tests/compositions/Makefile
+tests/compositions/data/Makefile
 gegl.pc
 gegl-uninstalled.pc
 ])
diff --git a/tests/Makefile.am b/tests/Makefile.am
index acc4dce..7165a33 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = buffer
+SUBDIRS = buffer compositions
 
 # Make the tests run against the build and not the installation
 TESTS_ENVIRONMENT = \
diff --git a/tests/compositions/.gitignore b/tests/compositions/.gitignore
new file mode 100644
index 0000000..5784a6d
--- /dev/null
+++ b/tests/compositions/.gitignore
@@ -0,0 +1,5 @@
+Makefile
+Makefile.in
+images.stamp
+tests-report
+*~
diff --git a/tests/compositions/Makefile.am b/tests/compositions/Makefile.am
new file mode 100644
index 0000000..af646d1
--- /dev/null
+++ b/tests/compositions/Makefile.am
@@ -0,0 +1,39 @@
+SUBDIRS=data
+
+EXTRA_DIST=$(wildcard *.xml) $(wildcard reference/*.png) verify-results.sh
+
+$(builddir)/output/%.png: %.xml
+	@echo $@ > /tmp/a ;\
+	GEGL_SWAP=RAM GEGL_PATH=$(top_builddir)/operations \
+	$(top_builddir)/bin/gegl$(EXEEXT) $< -o $@ 
+
+images.stamp: $(wildcard $(builddir)/*.xml) \
+              $(wildcard $(top_builddir)/operations/*/*$(SHREXT)) \
+	      $(top_builddir)/gegl/libgegl-$(GEGL_API_VERSION).la \
+	      $(top_builddir)/bin/gegl$(EXEEXT)
+	@echo "--[updating test renders]--"; \
+	mkdir output;
+	ln -s $(srcdir)/reference $(builddir)/reference;
+	for XML in $(srcdir)/*.xml; do \
+	    export BASE=`echo $$XML | sed s?$(srcdir)/?? | sed s/\.xml//`;\
+            PNG=$$BASE".png";\
+	    echo $${XML}; \
+	   $(MAKE) $(builddir)"/output/$$PNG" >/dev/null; \
+	done
+	@touch images.stamp
+
+
+TESTS = verify-results.sh
+verify-results.sh: tests-report
+
+tests-report: images.stamp $(top_srcdir)/tools/img_cmp
+	@echo "" > tests-report ;
+	@for XML in $(srcdir)/*.xml; do\
+	    export BASE=`echo $$XML | sed s?$(srcdir)/?? | sed s/\.xml//`;\
+	    PNG=$$BASE".png";\
+            GEGL_SWAP=RAM GEGL_PATH=$(top_builddir)/operations \
+	    $(top_builddir)/tools/img_cmp $(srcdir)/reference/$$PNG $(builddir)/output/$$PNG >> tests-report; true ;\
+	   done;
+
+clean-local:
+	rm -f images.stamp *.png output/*.png *.txt tests-report
diff --git a/tests/compositions/clones.xml b/tests/compositions/clones.xml
new file mode 100644
index 0000000..0c72e80
--- /dev/null
+++ b/tests/compositions/clones.xml
@@ -0,0 +1,223 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<gegl>
+  <node operation='gegl:over'>
+      <node operation='gegl:translate'>
+          <params>
+            <param name='x'>10.000000</param>
+            <param name='y'>280.000000</param>
+          </params>
+      </node>
+      <node operation='gegl:scale'>
+          <params>
+            <param name='origin-x'>0.000000</param>
+            <param name='origin-y'>0.000000</param>
+            <param name='filter'>linear</param>
+            <param name='hard-edges'>false</param>
+            <param name='lanczos-width'>3</param>
+            <param name='x'>0.200000</param>
+            <param name='y'>0.200000</param>
+          </params>
+      </node>
+      <node operation='gegl:box-blur'>
+          <params>
+            <param name='radius'>5.000000</param>
+          </params>
+      </node>
+      <node operation='gegl:load' id='clone0'>
+          <params>
+            <param name='path'>data/car-stack.jpg</param>
+          </params>
+      </node>
+  </node>
+  <node operation='gegl:over'>
+      <node operation='gegl:translate'>
+          <params>
+            <param name='x'>10.000000</param>
+            <param name='y'>190.000000</param>
+          </params>
+      </node>
+      <node operation='gegl:gamma'>
+          <params>
+            <param name='value'>2.500000</param>
+          </params>
+      </node>
+      <node operation='gegl:scale'>
+          <params>
+            <param name='origin-x'>0.000000</param>
+            <param name='origin-y'>0.000000</param>
+            <param name='filter'>linear</param>
+            <param name='hard-edges'>false</param>
+            <param name='lanczos-width'>3</param>
+            <param name='x'>0.200000</param>
+            <param name='y'>0.200000</param>
+          </params>
+      </node>
+      <clone ref='clone0'/>
+  </node>
+  <node operation='gegl:over'>
+      <node operation='gegl:translate'>
+          <params>
+            <param name='x'>10.000000</param>
+            <param name='y'>100.000000</param>
+          </params>
+      </node>
+      <node operation='gegl:invert'>
+      </node>
+      <node operation='gegl:scale'>
+          <params>
+            <param name='origin-x'>0.000000</param>
+            <param name='origin-y'>0.000000</param>
+            <param name='filter'>linear</param>
+            <param name='hard-edges'>false</param>
+            <param name='lanczos-width'>3</param>
+            <param name='x'>0.200000</param>
+            <param name='y'>0.200000</param>
+          </params>
+      </node>
+      <clone ref='clone0'/>
+  </node>
+  <node operation='gegl:over'>
+      <node operation='gegl:translate'>
+          <params>
+            <param name='x'>10.000000</param>
+            <param name='y'>10.000000</param>
+          </params>
+      </node>
+      <node operation='gegl:threshold'>
+          <params>
+            <param name='value'>0.500000</param>
+          </params>
+      </node>
+      <node operation='gegl:scale'>
+          <params>
+            <param name='origin-x'>0.000000</param>
+            <param name='origin-y'>0.000000</param>
+            <param name='filter'>linear</param>
+            <param name='hard-edges'>false</param>
+            <param name='lanczos-width'>3</param>
+            <param name='x'>0.200000</param>
+            <param name='y'>0.200000</param>
+          </params>
+      </node>
+      <clone ref='clone0'/>
+  </node>
+  <node operation='gegl:over'>
+      <node operation='gegl:translate'>
+          <params>
+            <param name='x'>335.000000</param>
+            <param name='y'>210.000000</param>
+          </params>
+      </node>
+      <node operation='gegl:over'>
+          <node operation='gegl:translate'>
+              <params>
+                <param name='x'>-10.000000</param>
+                <param name='y'>120.000000</param>
+              </params>
+          </node>
+          <node operation='gegl:opacity'>
+              <params>
+                <param name='value'>0.600000</param>
+              </params>
+          </node>
+          <node operation='gegl:dst-over'>
+              <node operation='gegl:opacity'>
+                  <params>
+                    <param name='value'>2.000000</param>
+                  </params>
+              </node>
+              <node operation='gegl:translate'>
+                  <params>
+                    <param name='x'>0.000000</param>
+                    <param name='y'>0.000000</param>
+                  </params>
+              </node>
+              <node operation='gegl:box-blur'>
+                  <params>
+                    <param name='radius'>4.000000</param>
+                  </params>
+              </node>
+              <node operation='gegl:brightness-contrast'>
+                  <params>
+                    <param name='contrast'>1.000000</param>
+                    <param name='brightness'>-1.000000</param>
+                  </params>
+              </node>
+              <node operation='gegl:text' id='clone1'>
+                  <params>
+                    <param name='string'>warming up</param>
+                    <param name='font'>Sans</param>
+                    <param name='size'>30.000000</param>
+                    <param name='color'>rgb(1.0000, 1.0000, 1.0000)</param>
+                    <param name='wrap'>-1</param>
+                    <param name='alignment'>0</param>
+                    <param name='width'>177</param>
+                    <param name='height'>36</param>
+                  </params>
+              </node>
+          </node>
+          <clone ref='clone1'/>
+      </node>
+      <node operation='gegl:scale'>
+          <params>
+            <param name='origin-x'>0.000000</param>
+            <param name='origin-y'>0.000000</param>
+            <param name='filter'>linear</param>
+            <param name='hard-edges'>false</param>
+            <param name='lanczos-width'>3</param>
+            <param name='x'>0.500000</param>
+            <param name='y'>0.500000</param>
+          </params>
+      </node>
+      <node operation='gegl:dst-over' id='clone2'>
+          <node operation='gegl:opacity'>
+              <params>
+                <param name='value'>0.800000</param>
+              </params>
+          </node>
+          <node operation='gegl:translate'>
+              <params>
+                <param name='x'>5.000000</param>
+                <param name='y'>-2.000000</param>
+              </params>
+          </node>
+          <node operation='gegl:add'>
+              <params>
+                <param name='value'>0.500000</param>
+              </params>
+          </node>
+          <node operation='gegl:gaussian-blur'>
+              <params>
+                <param name='std-dev-x'>5.000000</param>
+                <param name='std-dev-y'>5.000000</param>
+              </params>
+          </node>
+          <node operation='gegl:load' id='clone3'>
+              <params>
+                <param name='path'>data/gegl.png</param>
+              </params>
+          </node>
+      </node>
+      <clone ref='clone3'/>
+  </node>
+  <node operation='gegl:over'>
+      <node operation='gegl:translate'>
+          <params>
+            <param name='x'>90.000000</param>
+            <param name='y'>90.000000</param>
+          </params>
+      </node>
+      <node operation='gegl:opacity'>
+          <params>
+            <param name='value'>-0.500000</param>
+          </params>
+      </node>
+      <node operation='gegl:box-blur'>
+          <params>
+            <param name='radius'>15.000000</param>
+          </params>
+      </node>
+      <clone ref='clone2'/>
+  </node>
+  <clone ref='clone0'/>
+</gegl>
diff --git a/tests/compositions/data/.gitignore b/tests/compositions/data/.gitignore
new file mode 100644
index 0000000..b336cc7
--- /dev/null
+++ b/tests/compositions/data/.gitignore
@@ -0,0 +1,2 @@
+/Makefile
+/Makefile.in
diff --git a/tests/compositions/data/Makefile.am b/tests/compositions/data/Makefile.am
new file mode 100644
index 0000000..0f68210
--- /dev/null
+++ b/tests/compositions/data/Makefile.am
@@ -0,0 +1 @@
+EXTRA_DIST=$(wildcard *.png) $(wildcard *.jpg)
diff --git a/tests/compositions/data/car-stack.jpg b/tests/compositions/data/car-stack.jpg
new file mode 100644
index 0000000..df558fe
Binary files /dev/null and b/tests/compositions/data/car-stack.jpg differ
diff --git a/tests/compositions/data/gegl.png b/tests/compositions/data/gegl.png
new file mode 100644
index 0000000..3bf4580
Binary files /dev/null and b/tests/compositions/data/gegl.png differ
diff --git a/tests/compositions/data/grid.png b/tests/compositions/data/grid.png
new file mode 100644
index 0000000..aa11a90
Binary files /dev/null and b/tests/compositions/data/grid.png differ
diff --git a/tests/compositions/reference/clones.png b/tests/compositions/reference/clones.png
new file mode 100644
index 0000000..37eab34
Binary files /dev/null and b/tests/compositions/reference/clones.png differ
diff --git a/tests/compositions/reference/reflect.png b/tests/compositions/reference/reflect.png
new file mode 100644
index 0000000..9d38d38
Binary files /dev/null and b/tests/compositions/reference/reflect.png differ
diff --git a/tests/compositions/reference/reflect2.png b/tests/compositions/reference/reflect2.png
new file mode 100644
index 0000000..6752189
Binary files /dev/null and b/tests/compositions/reference/reflect2.png differ
diff --git a/tests/compositions/reference/rotate.png b/tests/compositions/reference/rotate.png
new file mode 100644
index 0000000..52e2b09
Binary files /dev/null and b/tests/compositions/reference/rotate.png differ
diff --git a/tests/compositions/reflect.xml b/tests/compositions/reflect.xml
new file mode 100644
index 0000000..6f770bb
--- /dev/null
+++ b/tests/compositions/reflect.xml
@@ -0,0 +1,10 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<gegl>
+    <node operation='gegl:reflect' x='1.0' y='0.0'> </node>
+    <node operation='gegl:translate' x='0.0' y='1.0'> </node>
+      <node operation='gegl:load' id='clone0'>
+          <params>
+            <param name='path'>data/grid.png</param>
+          </params>
+      </node>
+</gegl>
diff --git a/tests/compositions/reflect2.xml b/tests/compositions/reflect2.xml
new file mode 100644
index 0000000..501889a
--- /dev/null
+++ b/tests/compositions/reflect2.xml
@@ -0,0 +1,10 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<gegl>
+    <node operation='gegl:reflect' x='1.0' y='0.0'> </node>
+    <node operation='gegl:translate' x='0.0' y='0.5'> </node>
+      <node operation='gegl:load' id='clone0'>
+          <params>
+            <param name='path'>data/grid.png</param>
+          </params>
+      </node>
+</gegl>
diff --git a/tests/compositions/rotate.xml b/tests/compositions/rotate.xml
new file mode 100644
index 0000000..22f1791
--- /dev/null
+++ b/tests/compositions/rotate.xml
@@ -0,0 +1,9 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<gegl>
+    <node operation='gegl:rotate' degrees='42.0'> </node>
+      <node operation='gegl:load'>
+          <params>
+            <param name='path'>data/grid.png</param>
+          </params>
+      </node>
+</gegl>
diff --git a/tests/compositions/verify-results.sh b/tests/compositions/verify-results.sh
new file mode 100755
index 0000000..b30a58a
--- /dev/null
+++ b/tests/compositions/verify-results.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+total_tests=`ls -1 reference | wc -l`
+successful_tests=`cat tests-report | grep identical | wc -l`
+
+if [ $total_tests -eq $successful_tests ]
+then
+echo $successful_tests of $total_tests tests succesful.
+exit 0;
+else
+cat tests-report
+echo -------------------------
+echo $successful_tests of $total_tests tests succesful.
+exit 1;
+fi
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 21322a2..db91e92 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -22,4 +22,4 @@ AM_LDFLAGS = \
 	$(top_builddir)/gegl/libgegl-$(GEGL_API_VERSION).la \
 	$(DEP_LIBS) $(BABL_LIBS)
 
-noinst_PROGRAMS = introspect operation_reference
+noinst_PROGRAMS = introspect operation_reference img_cmp
diff --git a/tools/img_cmp.c b/tools/img_cmp.c
new file mode 100644
index 0000000..e9a4396
--- /dev/null
+++ b/tools/img_cmp.c
@@ -0,0 +1,108 @@
+#include <gegl.h> 
+#include <math.h>
+
+gint
+main (gint    argc,
+      gchar **argv)
+{
+  GeglBuffer *bufferA = NULL;
+  GeglBuffer *bufferB = NULL;
+
+  gegl_init (&argc, &argv);
+
+  if (argc != 3)
+    {
+      g_print ("This is simple image difference detection tool for use in regression testing"
+               "return message is non zero if images are different, if they are equal"
+               "the output will contain the string identical.");
+      g_print ("Usage: %s <imageA> <imageB>\n", argv[0]);
+      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_print ("Failed top 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_print ("Failed top 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))
+    {
+      g_print ("%s and %s differ in size\n", argv[1], argv[2]);
+      g_print ("  %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));
+      return 1;
+    }
+
+  {
+     guchar *bufA, *bufB;
+     guchar *a, *b;
+     gint   rowstrideA, rowstrideB;
+     gint   pixels;
+     gint   wrong_pixels=0;
+     gint   i;
+     gdouble diffsum = 0.0;
+
+     pixels = gegl_buffer_get_pixel_count (bufferA);
+
+     bufA = (void*)gegl_buffer_linear_open (bufferA, NULL, &rowstrideA, babl_format ("R'G'B'A u8"));
+     bufB = (void*)gegl_buffer_linear_open (bufferB, NULL, &rowstrideB, babl_format ("R'G'B'A u8"));
+
+     a = bufA;
+     b = bufB;
+
+     for (i=0;i<pixels;i++)
+       {
+#define P2(o) (((o))*((o)))
+         gdouble diff = sqrt ( P2(a[0]-b[0])+P2(a[1]-b[1])+P2(a[2]-b[2])+P2(a[3]-b[3]));
+#undef P2
+         a+=4;
+         b+=4;
+         if (diff>=0.0001)
+           {
+             wrong_pixels++;
+             diffsum += diff;
+           }
+       }
+
+     if (diffsum >= 0.001)
+       {
+         g_print ("%s and %s differ\n"
+                  "  wrong pixels     : %i (%f%%)\n"
+                  "  avg diff (wrong) : %f\n"
+                  "  avg diff (total) : %f\n",
+                  argv[1], argv[2],
+                  wrong_pixels, (wrong_pixels*1.0/pixels), 
+                  diffsum/wrong_pixels,
+                  diffsum/pixels);
+         return 1;
+       }
+
+     gegl_buffer_linear_close (bufferA, bufA);
+     gegl_buffer_linear_close (bufferB, bufB);
+  }
+
+  g_print ("%s and %s are identical\n", argv[1], argv[2]);
+  g_object_unref (bufferA); 
+  g_object_unref (bufferB); 
+  gegl_exit ();
+  return 0;
+}



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