From: ellson Date: Wed, 13 Jul 2005 11:59:08 +0000 (+0000) Subject: add a program which generates an image which is the visual-diff of two other images X-Git-Tag: LAST_LIBGRAPH~32^2~7465 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5c5885e52a53f5a767962e4c823e7c298def323c;p=graphviz add a program which generates an image which is the visual-diff of two other images (not automatically built or installed) --- diff --git a/contrib/Makefile.am b/contrib/Makefile.am index 0134b1989..c399cebc3 100644 --- a/contrib/Makefile.am +++ b/contrib/Makefile.am @@ -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 index 000000000..33b02dcaf --- /dev/null +++ b/contrib/diffimg/Makefile @@ -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 index 000000000..16a6b93a3 --- /dev/null +++ b/contrib/diffimg/diffimg.c @@ -0,0 +1,80 @@ +#include +#include +#include + +#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; +} +