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 * converttogray.c 00018 * 00019 */ 00020 00021 #include "allheaders.h" 00022 00023 main(int argc, 00024 char **argv) 00025 { 00026 char *filein, *fileout; 00027 l_int32 d, same; 00028 PIX *pixs, *pixd, *pixt0, *pixt1, *pixt2, *pixt3, *pixt4, *pixt5; 00029 static char mainName[] = "converttogray"; 00030 00031 if (argc != 2 && argc != 3) 00032 exit(ERROR_INT(" Syntax: converttogray filein [fileout]", 00033 mainName, 1)); 00034 00035 filein = argv[1]; 00036 fileout = argv[2]; 00037 00038 if ((pixs = pixRead(filein)) == NULL) 00039 exit(ERROR_INT("pixs not made", mainName, 1)); 00040 00041 #if 0 00042 pixd = pixConvertRGBToGray(pixs, 0.33, 0.34, 0.33); 00043 pixWrite(fileout, pixd, IFF_PNG); 00044 pixDestroy(&pixd); 00045 #endif 00046 00047 #if 1 00048 d = pixGetDepth(pixs); 00049 if (d == 2) { 00050 pixt1 = pixConvert2To8(pixs, 0x00, 0x55, 0xaa, 0xff, TRUE); 00051 pixt2 = pixConvert2To8(pixs, 0x00, 0x55, 0xaa, 0xff, FALSE); 00052 pixEqual(pixt1, pixt2, &same); 00053 if (same) 00054 fprintf(stderr, "images are the same\n"); 00055 else 00056 fprintf(stderr, "images are different!\n"); 00057 pixWrite("/tmp/junkpixt1", pixt1, IFF_PNG); 00058 pixWrite("/tmp/junkpixt2", pixt2, IFF_PNG); 00059 pixDestroy(&pixt1); 00060 pixDestroy(&pixt2); 00061 pixSetColormap(pixs, NULL); 00062 pixt3 = pixConvert2To8(pixs, 0x00, 0x55, 0xaa, 0xff, TRUE); 00063 pixt4 = pixConvert2To8(pixs, 0x00, 0x55, 0xaa, 0xff, FALSE); 00064 pixEqual(pixt3, pixt4, &same); 00065 if (same) 00066 fprintf(stderr, "images are the same\n"); 00067 else 00068 fprintf(stderr, "images are different!\n"); 00069 pixWrite("/tmp/junkpixt3", pixt3, IFF_PNG); 00070 pixWrite("/tmp/junkpixt4", pixt4, IFF_PNG); 00071 pixDestroy(&pixt3); 00072 pixDestroy(&pixt4); 00073 } 00074 else if (d == 4) { 00075 pixt1 = pixConvert4To8(pixs, TRUE); 00076 pixt2 = pixConvert4To8(pixs, FALSE); 00077 pixEqual(pixt1, pixt2, &same); 00078 if (same) 00079 fprintf(stderr, "images are the same\n"); 00080 else 00081 fprintf(stderr, "images are different!\n"); 00082 pixWrite("/tmp/junkpixt1", pixt1, IFF_PNG); 00083 pixWrite("/tmp/junkpixt2", pixt2, IFF_PNG); 00084 pixDestroy(&pixt1); 00085 pixDestroy(&pixt2); 00086 pixSetColormap(pixs, NULL); 00087 pixt3 = pixConvert4To8(pixs, TRUE); 00088 pixt4 = pixConvert4To8(pixs, FALSE); 00089 pixEqual(pixt3, pixt4, &same); 00090 if (same) 00091 fprintf(stderr, "images are the same\n"); 00092 else 00093 fprintf(stderr, "images are different!\n"); 00094 pixWrite("/tmp/junkpixt3", pixt3, IFF_PNG); 00095 pixWrite("/tmp/junkpixt4", pixt4, IFF_PNG); 00096 pixDestroy(&pixt3); 00097 pixDestroy(&pixt4); 00098 } 00099 #endif 00100 00101 pixDestroy(&pixs); 00102 00103 return 0; 00104 } 00105