Leptonica 1.68
C Image Processing Library

rasterop_reg.c

Go to the documentation of this file.
00001 /*====================================================================*
00002  -  Copyright (C) 2001 Leptonica.  All rights reserved.
00003  -  This software is distributed in the hope that it will be
00004  -  useful, but with NO WARRANTY OF ANY KIND.
00005  -  No author or distributor accepts responsibility to anyone for the
00006  -  consequences of using this software, or for whether it serves any
00007  -  particular purpose or works at all, unless he or she says so in
00008  -  writing.  Everyone is granted permission to copy, modify and
00009  -  redistribute this source code, for commercial or non-commercial
00010  -  purposes, with the following restrictions: (1) the origin of this
00011  -  source code must not be misrepresented; (2) modified versions must
00012  -  be plainly marked as such; and (3) this notice may not be removed
00013  -  or altered from any source or modified source distribution.
00014  *====================================================================*/
00015 
00016 /*
00017  * rasterop_reg.c
00018  *
00019  *     This is a fairly rigorous test of rasterop.
00020  *     It demonstrates both that the results are correct
00021  *     with many different rop configurations, and,
00022  *     if done under valgrind, that no memory violations occur.
00023  *
00024  *     Use it on images with a significant amount of FG
00025  *     that extends to the edges.
00026  */
00027 
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030 #include "allheaders.h"
00031 
00032     /* choose these variably to explore range of widths and heights */
00033 #define    MINW            1
00034 #define    MAXW            35
00035 #define    MINH            1
00036 #define    MAXH            1
00037 
00038 
00039 main(int    argc,
00040      char **argv)
00041 {
00042 l_int32      i, j, w, h, same, width, height, cx, cy;
00043 l_uint32     val;
00044 PIX         *pixs, *pixse, *pixd1, *pixd2;
00045 SEL         *sel;
00046 static char  mainName[] = "rasterop_reg";
00047 
00048     if (argc != 1)
00049         exit(ERROR_INT(" Syntax:  rasterop_reg", mainName, 1));
00050 
00051     if ((pixs = pixRead("feyn.tif")) == NULL)
00052         exit(ERROR_INT("pix not made", mainName, 1));
00053 
00054     for (width = MINW; width <= MAXW; width++) {
00055         for (height = MINH; height <= MAXH; height++) {
00056 
00057             cx = width / 2;
00058             cy = height / 2;
00059 
00060                 /* dilate using an actual sel */
00061             sel = selCreateBrick(height, width, cy, cx, SEL_HIT);
00062             pixd1 = pixDilate(NULL, pixs, sel);
00063 
00064                 /* dilate using a pix as a sel */
00065             pixse = pixCreate(width, height, 1);
00066             pixSetAll(pixse);
00067             pixd2 = pixCopy(NULL, pixs);
00068             w = pixGetWidth(pixs);
00069             h = pixGetHeight(pixs);
00070             for (i = 0; i < h; i++) {
00071                 for (j = 0; j < w; j++) {
00072                     pixGetPixel(pixs, j, i, &val);
00073                     if (val)
00074                         pixRasterop(pixd2, j - cx, i - cy, width, height,
00075                                     PIX_SRC | PIX_DST, pixse, 0, 0);
00076                 }
00077             }
00078             
00079             pixEqual(pixd1, pixd2, &same);
00080             if (same == 1)
00081                 fprintf(stderr, "Correct: results for (%d,%d) are identical!\n",
00082                                  width, height);
00083             else {
00084                 fprintf(stderr, "Error: results are different!\n");
00085                 fprintf(stderr, "SE: width = %d, height = %d\n", width, height);
00086                 pixWrite("/tmp/junkout1.png", pixd1, IFF_PNG);
00087                 pixWrite("/tmp/junkout2.png", pixd2, IFF_PNG);
00088                 exit(1);
00089             }
00090 
00091             pixDestroy(&pixse);
00092             pixDestroy(&pixd1);
00093             pixDestroy(&pixd2);
00094             selDestroy(&sel);
00095         }
00096     }
00097     pixDestroy(&pixs);
00098 
00099     exit(0);
00100 }
00101 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines