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 * rotateorth_reg.c 00018 * 00019 * Regression test for all rotateorth functions 00020 */ 00021 00022 #include "allheaders.h" 00023 00024 #define BINARY_IMAGE "test1.png" 00025 #define GRAYSCALE_IMAGE "test8.jpg" 00026 #define FOUR_BPP_IMAGE "weasel4.8g.png" 00027 #define COLORMAP_IMAGE "dreyfus8.png" 00028 #define RGB_IMAGE "marge.jpg" 00029 00030 void RotateOrthTest(PIX *pix, L_REGPARAMS *rp); 00031 00032 00033 main(int argc, 00034 char **argv) 00035 { 00036 PIX *pixs; 00037 L_REGPARAMS *rp; 00038 00039 if (regTestSetup(argc, argv, &rp)) 00040 return 1; 00041 00042 fprintf(stderr, "\nTest binary image:\n"); 00043 pixs = pixRead(BINARY_IMAGE); 00044 RotateOrthTest(pixs, rp); 00045 pixDestroy(&pixs); 00046 fprintf(stderr, "\nTest 4 bpp colormapped image:\n"); 00047 pixs = pixRead(FOUR_BPP_IMAGE); 00048 RotateOrthTest(pixs, rp); 00049 pixDestroy(&pixs); 00050 fprintf(stderr, "\nTest grayscale image:\n"); 00051 pixs = pixRead(GRAYSCALE_IMAGE); 00052 RotateOrthTest(pixs, rp); 00053 pixDestroy(&pixs); 00054 fprintf(stderr, "\nTest colormap image:\n"); 00055 pixs = pixRead(COLORMAP_IMAGE); 00056 RotateOrthTest(pixs, rp); 00057 pixDestroy(&pixs); 00058 fprintf(stderr, "\nTest rgb image:\n"); 00059 pixs = pixRead(RGB_IMAGE); 00060 RotateOrthTest(pixs, rp); 00061 pixDestroy(&pixs); 00062 00063 regTestCleanup(rp); 00064 return 0; 00065 } 00066 00067 00068 void 00069 RotateOrthTest(PIX *pixs, 00070 L_REGPARAMS *rp) 00071 { 00072 l_int32 zero, count; 00073 PIX *pixt, *pixd; 00074 PIXCMAP *cmap; 00075 00076 cmap = pixGetColormap(pixs); 00077 00078 /* Test 4 successive 90 degree rotations */ 00079 pixt = pixRotate90(pixs, 1); 00080 pixd = pixRotate90(pixt, 1); 00081 pixDestroy(&pixt); 00082 pixt = pixRotate90(pixd, 1); 00083 pixDestroy(&pixd); 00084 pixd = pixRotate90(pixt, 1); 00085 pixDestroy(&pixt); 00086 regTestComparePix(rp, pixs, pixd); 00087 if (!cmap) { 00088 pixXor(pixd, pixd, pixs); 00089 pixZero(pixd, &zero); 00090 if (zero) 00091 fprintf(stderr, "OK. Four 90-degree rotations gives I\n"); 00092 else { 00093 pixCountPixels(pixd, &count, NULL); 00094 fprintf(stderr, "Failure for four 90-degree rots; count = %d\n", 00095 count); 00096 } 00097 } 00098 pixDestroy(&pixd); 00099 00100 /* Test 2 successive 180 degree rotations */ 00101 pixt = pixRotate180(NULL, pixs); 00102 pixRotate180(pixt, pixt); 00103 regTestComparePix(rp, pixs, pixt); 00104 if (!cmap) { 00105 pixXor(pixt, pixt, pixs); 00106 pixZero(pixt, &zero); 00107 if (zero) 00108 fprintf(stderr, "OK. Two 180-degree rotations gives I\n"); 00109 else { 00110 pixCountPixels(pixt, &count, NULL); 00111 fprintf(stderr, "Failure for two 180-degree rots; count = %d\n", 00112 count); 00113 } 00114 } 00115 pixDestroy(&pixt); 00116 00117 /* Test 2 successive LR flips */ 00118 pixt = pixFlipLR(NULL, pixs); 00119 pixFlipLR(pixt, pixt); 00120 regTestComparePix(rp, pixs, pixt); 00121 if (!cmap) { 00122 pixXor(pixt, pixt, pixs); 00123 pixZero(pixt, &zero); 00124 if (zero) 00125 fprintf(stderr, "OK. Two LR flips gives I\n"); 00126 else { 00127 pixCountPixels(pixt, &count, NULL); 00128 fprintf(stderr, "Failure for two LR flips; count = %d\n", count); 00129 } 00130 } 00131 pixDestroy(&pixt); 00132 00133 /* Test 2 successive TB flips */ 00134 pixt = pixFlipTB(NULL, pixs); 00135 pixFlipTB(pixt, pixt); 00136 regTestComparePix(rp, pixs, pixt); 00137 if (!cmap) { 00138 pixXor(pixt, pixt, pixs); 00139 pixZero(pixt, &zero); 00140 if (zero) 00141 fprintf(stderr, "OK. Two TB flips gives I\n"); 00142 else { 00143 pixCountPixels(pixt, &count, NULL); 00144 fprintf(stderr, "Failure for two TB flips; count = %d\n", count); 00145 } 00146 } 00147 pixDestroy(&pixt); 00148 return; 00149 } 00150