]> granicus.if.org Git - graphviz/commitdiff
add a program which generates an image which is the visual-diff of two other images
authorellson <devnull@localhost>
Wed, 13 Jul 2005 11:59:08 +0000 (11:59 +0000)
committerellson <devnull@localhost>
Wed, 13 Jul 2005 11:59:08 +0000 (11:59 +0000)
(not automatically built or installed)

contrib/Makefile.am
contrib/diffimg/Makefile [new file with mode: 0644]
contrib/diffimg/diffimg.c [new file with mode: 0644]

index 0134b1989e162a7ff4e0f652fe99a053f3c2c272..c399cebc3abb5cb5ffa6a8343c8de86b58940c46 100644 (file)
@@ -3,4 +3,4 @@
 SUBDIRS = prune
 
 EXTRA_DIST = INDEX dotmcl.pl gprof2dot.awk webdot.cgi Makefile.old \
-       lefty-grace dirgraph
+       lefty-grace dirgraph diffimg
diff --git a/contrib/diffimg/Makefile b/contrib/diffimg/Makefile
new file mode 100644 (file)
index 0000000..33b02dc
--- /dev/null
@@ -0,0 +1,15 @@
+LDFLAGS = -lgd
+
+diffimg: diffimg.o
+
+GRAPH = "digraph G { hello -> world }"
+
+test: diffimg
+       echo $(GRAPH) | dot -Tpng:cg >hello1.png
+       echo $(GRAPH) | dot -Tpng:cg >hello2.png
+       ./diffimg hello1.png hello2.png >test1.png
+       echo $(GRAPH) | dot -Grankdir=LR -Tpng:cg >hello2.png
+       ./diffimg hello1.png hello2.png >test2.png
+
+clean:
+       rm -f diffimg *.o *.png
diff --git a/contrib/diffimg/diffimg.c b/contrib/diffimg/diffimg.c
new file mode 100644 (file)
index 0000000..16a6b93
--- /dev/null
@@ -0,0 +1,80 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <gd.h>
+
+#define ABS(x) (((x) < 0) ? -(x) : (x))
+
+void imageDiff (gdImagePtr dst, gdImagePtr src, int dstX, int dstY, int srcX,
+             int srcY, int w, int h)
+{
+  int s, d;
+  int x, y;
+/*  assert (dst->trueColor); */
+  for (y = 0; (y < h); y++)
+    {
+      for (x = 0; (x < w); x++)
+        {
+         s = gdImageGetTrueColorPixel (src, srcX + x, srcY + y);
+         d = gdImageGetTrueColorPixel (dst, dstX + x, dstY + y);
+
+         d = gdTrueColorAlpha(
+               ABS(gdTrueColorGetRed(s) - gdTrueColorGetRed(d)),
+               ABS(gdTrueColorGetGreen(s) - gdTrueColorGetGreen(d)),
+               ABS(gdTrueColorGetBlue(s) - gdTrueColorGetBlue(d)),
+               ABS(gdTrueColorGetAlpha(s) - gdTrueColorGetAlpha(d)));
+
+          gdImageSetPixel (dst, dstX + x, dstY + y, d);
+        }
+    }
+}
+
+int main(int argc, char **argv)
+{
+    gdImagePtr im1, im2, im3;
+    FILE *in;
+
+    if (argc != 3) {
+        fprintf(stderr, "Usage: diffimg file1.png file2.png \n");
+        exit(1);
+    }
+    in = fopen(argv[1], "rb");
+    if (!in) {
+        fprintf(stderr, "Input file1 does not exist!\n");
+        exit(1);
+    }
+    im1 = gdImageCreateFromPng(in);
+    fclose(in);
+    if (!im1) {
+        fprintf(stderr, "Input file1 is not in PNG format!\n");
+        exit(1);
+    }
+
+    in = fopen(argv[2], "rb");
+    if (!in) {
+        fprintf(stderr, "Input file2 does not exist!\n");
+        exit(1);
+    }
+    im2 = gdImageCreateFromPng(in);
+    fclose(in);
+    if (!im2) {
+        fprintf(stderr, "Input file2 is not in PNG format!\n");
+        exit(1);
+    }
+
+    im3 = gdImageCreateTrueColor (
+       (gdImageSX(im1) > gdImageSX(im2)) ? gdImageSX(im1) : gdImageSX(im2),
+       (gdImageSY(im1) > gdImageSY(im2)) ? gdImageSY(im1) : gdImageSY(im2));
+
+    gdImageCopy (im3, im1, 0, 0, 0, 0, gdImageSX(im1), gdImageSY(im1));
+
+    imageDiff (im3, im2, 0, 0, 0, 0, gdImageSX(im2), gdImageSY(im2));
+
+    gdImagePng (im3, stdout);
+
+    gdImageDestroy(im1);
+    gdImageDestroy(im2);
+    gdImageDestroy(im3);
+
+    return 0;
+}
+