Back to index

lightning-sunbird  0.9+nobinonly
imagediff.c
Go to the documentation of this file.
00001 /* imagediff - Compare two images
00002  *
00003  * Copyright © 2004 Richard D. Worth
00004  *
00005  * Permission to use, copy, modify, distribute, and sell this software
00006  * and its documentation for any purpose is hereby granted without
00007  * fee, provided that the above copyright notice appear in all copies
00008  * and that both that copyright notice and this permission notice
00009  * appear in supporting documentation, and that the name of Richard Worth
00010  * not be used in advertising or publicity pertaining to distribution
00011  * of the software without specific, written prior permission.
00012  * Richard Worth makes no representations about the suitability of this
00013  * software for any purpose.  It is provided "as is" without express
00014  * or implied warranty.
00015  * 
00016  * RICHARD WORTH DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
00017  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
00018  * NO EVENT SHALL RICHARD WORTH BE LIABLE FOR ANY SPECIAL, INDIRECT OR
00019  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
00020  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
00021  * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
00022  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
00023  *
00024  * Author: Richard D. Worth <richard@theworths.org> */
00025 
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 
00029 #include "buffer_diff.h"
00030 #include "read_png.h"
00031 #include "write_png.h"
00032 #include "xmalloc.h"
00033 
00034 int 
00035 main (int argc, char *argv[])
00036 {
00037     unsigned char *buffer_a;
00038     unsigned int width_a, height_a, stride_a;
00039     unsigned char *buffer_b;
00040     unsigned int width_b, height_b, stride_b;
00041 
00042     unsigned char *buffer;
00043     unsigned int width, height, stride;
00044     int buffer_size, total_pixels_changed;
00045 
00046     if (argc < 2) {
00047        fprintf (stderr, "Usage: %s image1.png image2.png\n", argv[0]);
00048        fprintf (stderr, "Computes an output image designed to present a \"visual diff\" such that even\n");
00049        fprintf (stderr, "small errors in single pixels are readily apparent in the output.\n");
00050        fprintf (stderr, "The output image is written on stdout.\n");
00051        exit (1);
00052     }
00053 
00054     read_png_argb32 (argv[1], &buffer_a, &width_a, &height_a, &stride_a);
00055     read_png_argb32 (argv[2], &buffer_b, &width_b, &height_b, &stride_b);
00056 
00057     if ((width_a == width_b) && (height_a == height_b) && (stride_a == stride_b))
00058     {
00059        width = width_a;
00060        height = height_a;
00061        stride = stride_a;
00062     } else {
00063        fprintf (stderr, "Error. Both images must be the same size\n");
00064        return 1;
00065     }
00066 
00067     buffer_size = stride * height;
00068     buffer = xmalloc (buffer_size);
00069     
00070     total_pixels_changed = buffer_diff (buffer_a, buffer_b, buffer,
00071                                    width_a, height_a, stride_a);
00072 
00073 
00074     if (total_pixels_changed)
00075        fprintf (stderr, "Total pixels changed: %d\n", total_pixels_changed);
00076     write_png_argb32 (buffer, stdout, width, height, stride);
00077 
00078     free (buffer);
00079 
00080     return 0;
00081 }
00082 
00083 
00084