Leptonica 1.68
C Image Processing Library

equal_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  * equal_reg.c
00018  *
00019  *    Tests the pixEqual() function in many situations.
00020  *
00021  *    This also tests the quantization of grayscale and color
00022  *    images (to generate a colormapped image), and removal of
00023  *    the colormap to either RGB or grayscale.
00024  */
00025 
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include "allheaders.h"
00029 
00030     /* use this set */
00031 #define   FEYN1            "feyn.tif"      /* 1 bpp */
00032 #define   DREYFUS2         "dreyfus2.png"  /* 2 bpp cmapped */
00033 #define   DREYFUS4         "dreyfus4.png"  /* 4 bpp cmapped */
00034 #define   DREYFUS8         "dreyfus8.png"  /* 8 bpp cmapped */
00035 #define   KAREN8           "karen8.jpg"    /* 8 bpp, not cmapped */
00036 #define   MARGE32          "marge.jpg"     /* rgb */
00037 
00038 main(int    argc,
00039      char **argv)
00040 {
00041 l_int32      errorfound, same;
00042 PIX         *pixs, *pixt1, *pixt2, *pixt3, *pixt4;
00043 static char  mainName[] = "equal_reg";
00044 
00045     if (argc != 1)
00046         exit(ERROR_INT(" Syntax:  equal_reg", mainName, 1));
00047 
00048     errorfound = FALSE;
00049     pixs = pixRead(FEYN1);
00050     pixWrite("/tmp/junkfeyn.png", pixs, IFF_PNG);
00051     pixt1 = pixRead("/tmp/junkfeyn.png");
00052     pixEqual(pixs, pixt1, &same);
00053     if (same)
00054         L_INFO("equal for feyn1", mainName);
00055     else {
00056         L_INFO("FAILURE for equal for feyn1", mainName);
00057         errorfound = TRUE;
00058     }
00059     pixDestroy(&pixs);
00060     pixDestroy(&pixt1);
00061 
00062     pixs = pixRead(DREYFUS2);
00063     pixt1 = pixRemoveColormap(pixs, REMOVE_CMAP_BASED_ON_SRC);
00064     pixWrite("/tmp/junkdrey2-1.png", pixt1, IFF_PNG);
00065     pixt2 = pixRemoveColormap(pixs, REMOVE_CMAP_TO_FULL_COLOR);
00066     pixWrite("/tmp/junkdrey2-2.png", pixt2, IFF_PNG);
00067     pixt3 = pixOctreeQuantNumColors(pixt2, 64, 1);
00068     pixWrite("/tmp/junkdrey2-3.png", pixt3, IFF_PNG);
00069     pixt4 = pixConvertRGBToColormap(pixt2, 1);
00070     pixWrite("/tmp/junkdrey2-4.png", pixt4, IFF_PNG);
00071     pixEqual(pixs, pixt1, &same);
00072     if (same)
00073         L_INFO("equal for pixt1 of dreyfus2", mainName);
00074     else {
00075         L_INFO("FAILURE for pixt1 of dreyfus2", mainName);
00076         errorfound = TRUE;
00077     }
00078     pixEqual(pixs, pixt2, &same);
00079     if (same)
00080         L_INFO("equal for pixt2 of dreyfus2", mainName);
00081     else {
00082         L_INFO("FAILURE for pixt2 of dreyfus2", mainName);
00083         errorfound = TRUE;
00084     }
00085     pixEqual(pixs, pixt3, &same);
00086     if (same)
00087         L_INFO("equal for pixt3 of dreyfus2", mainName);
00088     else {
00089         L_INFO("FAILURE for pixt3 of dreyfus2", mainName);
00090         errorfound = TRUE;
00091     }
00092     pixEqual(pixs, pixt4, &same);
00093     if (same)
00094         L_INFO("equal for pixt4 of dreyfus2", mainName);
00095     else {
00096         L_INFO("FAILURE for pixt4 of dreyfus2", mainName);
00097         errorfound = TRUE;
00098     }
00099     pixDestroy(&pixs);
00100     pixDestroy(&pixt1);
00101     pixDestroy(&pixt2);
00102     pixDestroy(&pixt3);
00103     pixDestroy(&pixt4);
00104 
00105     pixs = pixRead(DREYFUS4);
00106     pixt1 = pixRemoveColormap(pixs, REMOVE_CMAP_BASED_ON_SRC);
00107     pixWrite("/tmp/junkdrey4-1.png", pixt1, IFF_PNG);
00108     pixt2 = pixRemoveColormap(pixs, REMOVE_CMAP_TO_FULL_COLOR);
00109     pixWrite("/tmp/junkdrey4-2.png", pixt2, IFF_PNG);
00110     pixt3 = pixOctreeQuantNumColors(pixt2, 256, 1);
00111     pixWrite("/tmp/junkdrey4-3.png", pixt3, IFF_PNG);
00112     pixt4 = pixConvertRGBToColormap(pixt2, 1);
00113     pixWrite("/tmp/junkdrey4-4.png", pixt4, IFF_PNG);
00114     pixEqual(pixs, pixt1, &same);
00115     if (same)
00116         L_INFO("equal for pixt1 of dreyfus4", mainName);
00117     else {
00118         L_INFO("FAILURE for pixt1 of dreyfus4", mainName);
00119         errorfound = TRUE;
00120     }
00121     pixEqual(pixs, pixt2, &same);
00122     if (same)
00123         L_INFO("equal for pixt2 of dreyfus4", mainName);
00124     else {
00125         L_INFO("FAILURE for pixt2 of dreyfus4", mainName);
00126         errorfound = TRUE;
00127     }
00128     pixEqual(pixs, pixt3, &same);
00129     if (same)
00130         L_INFO("equal for pixt3 of dreyfus4", mainName);
00131     else {
00132         L_INFO("FAILURE for pixt3 of dreyfus4", mainName);
00133         errorfound = TRUE;
00134     }
00135     pixEqual(pixs, pixt4, &same);
00136     if (same)
00137         L_INFO("equal for pixt4 of dreyfus4", mainName);
00138     else {
00139         L_INFO("FAILURE for pixt4 of dreyfus4", mainName);
00140         errorfound = TRUE;
00141     }
00142     pixDestroy(&pixs);
00143     pixDestroy(&pixt1);
00144     pixDestroy(&pixt2);
00145     pixDestroy(&pixt3);
00146     pixDestroy(&pixt4);
00147 
00148     pixs = pixRead(DREYFUS8);
00149     pixt1 = pixRemoveColormap(pixs, REMOVE_CMAP_BASED_ON_SRC);
00150     pixWrite("/tmp/junkdrey8-1.png", pixt1, IFF_PNG);
00151     pixt2 = pixRemoveColormap(pixs, REMOVE_CMAP_TO_FULL_COLOR);
00152     pixWrite("/tmp/junkdrey8-2.png", pixt2, IFF_PNG);
00153     pixt3 = pixConvertRGBToColormap(pixt2, 1);
00154     pixWrite("/tmp/junkdrey8-3.png", pixt3, IFF_PNG);
00155     pixEqual(pixs, pixt1, &same);
00156     if (same)
00157         L_INFO("equal for pixt1 of dreyfus8", mainName);
00158     else {
00159         L_INFO("FAILURE for pixt1 of dreyfus8", mainName);
00160         errorfound = TRUE;
00161     }
00162     pixEqual(pixs, pixt2, &same);
00163     if (same)
00164         L_INFO("equal for pixt2 of dreyfus8", mainName);
00165     else {
00166         L_INFO("FAILURE for pixt2 of dreyfus8", mainName);
00167         errorfound = TRUE;
00168     }
00169     pixDestroy(&pixs);
00170     pixDestroy(&pixt1);
00171     pixDestroy(&pixt2);
00172     pixDestroy(&pixt3);
00173 
00174     pixs = pixRead(KAREN8);
00175     pixt1 = pixThresholdTo4bpp(pixs, 16, 1);
00176     pixWrite("/tmp/junkkar8-1.png", pixt1, IFF_PNG);
00177     pixt2 = pixRemoveColormap(pixt1, REMOVE_CMAP_BASED_ON_SRC);
00178     pixWrite("/tmp/junkkar8-2.png", pixt2, IFF_PNG);
00179     pixt3 = pixRemoveColormap(pixt1, REMOVE_CMAP_TO_FULL_COLOR);
00180     pixWrite("/tmp/junkkar8-3.png", pixt3, IFF_PNG);
00181     pixt4 = pixConvertRGBToColormap(pixt3, 1);
00182     pixEqual(pixt1, pixt2, &same);
00183     if (same)
00184         L_INFO("equal for pixt2 of karen8", mainName);
00185     else {
00186         L_INFO("FAILURE for pixt2 of karen8", mainName);
00187         errorfound = TRUE;
00188     }
00189     pixEqual(pixt1, pixt3, &same);
00190     if (same)
00191         L_INFO("equal for pixt3 of karen8", mainName);
00192     else {
00193         L_INFO("FAILURE for pixt3 of karen8", mainName);
00194         errorfound = TRUE;
00195     }
00196     pixEqual(pixt1, pixt4, &same);
00197     if (same)
00198         L_INFO("equal for pixt4 of karen8", mainName);
00199     else {
00200         L_INFO("FAILURE for pixt4 of karen8", mainName);
00201         errorfound = TRUE;
00202     }
00203     pixDestroy(&pixs);
00204     pixDestroy(&pixt1);
00205     pixDestroy(&pixt2);
00206     pixDestroy(&pixt3);
00207     pixDestroy(&pixt4);
00208 
00209     pixs = pixRead(MARGE32);
00210     pixt1 = pixOctreeQuantNumColors(pixs, 32, 0);
00211     pixWrite("/tmp/junkmarge8-1.png", pixt1, IFF_PNG);
00212     pixt2 = pixRemoveColormap(pixt1, REMOVE_CMAP_TO_FULL_COLOR);
00213     pixWrite("/tmp/junkmarge8-2.png", pixt2, IFF_PNG);
00214     pixt3 = pixConvertRGBToColormap(pixt2, 1);
00215     pixWrite("/tmp/junkmarge8-3.png", pixt3, IFF_PNG);
00216     pixt4 = pixOctreeQuantNumColors(pixt2, 64, 0);
00217     pixWrite("/tmp/junkmarge8-4.png", pixt4, IFF_PNG);
00218     pixEqual(pixt1, pixt2, &same);
00219     if (same)
00220         L_INFO("equal for pixt2 of marge32", mainName);
00221     else {
00222         L_INFO("FAILURE for pixt2 of marge32", mainName);
00223         errorfound = TRUE;
00224     }
00225     pixEqual(pixt1, pixt3, &same);
00226     if (same)
00227         L_INFO("equal for pixt3 of marge32", mainName);
00228     else {
00229         L_INFO("FAILURE for pixt3 of marge32", mainName);
00230         errorfound = TRUE;
00231     }
00232     pixEqual(pixt1, pixt4, &same);
00233     if (same)
00234         L_INFO("equal for pixt4 of marge32", mainName);
00235     else {
00236         L_INFO("FAILURE for pixt4 of marge32", mainName);
00237         errorfound = TRUE;
00238     }
00239     pixDestroy(&pixs);
00240     pixDestroy(&pixt1);
00241     pixDestroy(&pixt2);
00242     pixDestroy(&pixt3);
00243     pixDestroy(&pixt4);
00244 
00245     if (errorfound)
00246         L_INFO("FAILURE in processing this test", mainName);
00247     else
00248         L_INFO("SUCCESS in processing this test", mainName);
00249 
00250     exit(0);
00251 }
00252 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines