Leptonica 1.68
C Image Processing Library
|
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 * pixtile_reg.c 00018 */ 00019 00020 #include <stdio.h> 00021 #include <stdlib.h> 00022 #include "allheaders.h" 00023 00024 static l_int32 TestTiling(PIX *pixd, PIX *pixs, l_int32 nx, l_int32 ny, 00025 l_int32 w, l_int32 h, l_int32 xoverlap, 00026 l_int32 yoverlap); 00027 00028 00029 main(int argc, 00030 char **argv) 00031 { 00032 PIX *pixs, *pixd; 00033 00034 pixs = pixRead("test24.jpg"); 00035 pixd = pixCreateTemplateNoInit(pixs); 00036 00037 TestTiling(pixd, pixs, 1, 1, 0, 0, 183, 83); 00038 TestTiling(pixd, pixs, 0, 1, 60, 0, 30, 20); 00039 TestTiling(pixd, pixs, 1, 0, 0, 60, 40, 40); 00040 TestTiling(pixd, pixs, 0, 0, 27, 31, 27, 31); 00041 TestTiling(pixd, pixs, 0, 0, 400, 400, 40, 20); 00042 TestTiling(pixd, pixs, 7, 9, 0, 0, 35, 35); 00043 TestTiling(pixd, pixs, 0, 0, 27, 31, 0, 0); 00044 TestTiling(pixd, pixs, 7, 9, 0, 0, 0, 0); 00045 00046 pixDestroy(&pixs); 00047 pixDestroy(&pixd); 00048 return 0; 00049 } 00050 00051 00052 l_int32 00053 TestTiling(PIX *pixd, 00054 PIX *pixs, 00055 l_int32 nx, 00056 l_int32 ny, 00057 l_int32 w, 00058 l_int32 h, 00059 l_int32 xoverlap, 00060 l_int32 yoverlap) 00061 { 00062 l_int32 i, j, same; 00063 PIX *pixt; 00064 PIXTILING *pt; 00065 00066 pixClearAll(pixd); 00067 pt = pixTilingCreate(pixs, nx, ny, w, h, xoverlap, yoverlap); 00068 pixTilingGetCount(pt, &nx, &ny); 00069 pixTilingGetSize(pt, &w, &h); 00070 if (pt) 00071 fprintf(stderr, "nx,ny = %d,%d; w,h = %d,%d; overlap = %d,%d\n", 00072 nx, ny, w, h, pt->xoverlap, pt->yoverlap); 00073 else 00074 return 1; 00075 00076 for (i = 0; i < ny; i++) { 00077 for (j = 0; j < nx; j++) { 00078 pixt = pixTilingGetTile(pt, i, j); 00079 pixTilingPaintTile(pixd, i, j, pixt, pt); 00080 pixDestroy(&pixt); 00081 } 00082 } 00083 pixEqual(pixs, pixd, &same); 00084 if (same) 00085 fprintf(stderr, "Tiling OK\n"); 00086 else 00087 fprintf(stderr, "Tiling ERROR !\n"); 00088 00089 pixTilingDestroy(&pt); 00090 return 0; 00091 } 00092 00093