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 * iotest.c 00018 * 00019 * Tests all I/O except multipage/custom tiff and PostScript, which 00020 * are separately tested in mtifftest and psiotest, respectively. 00021 */ 00022 00023 #include "allheaders.h" 00024 00025 LEPT_DLL extern const char *ImageFileFormatExtensions[]; 00026 00027 main(int argc, 00028 char **argv) 00029 { 00030 l_int32 w, h, d, wpl, count, i, format, xres, yres; 00031 FILE *fp; 00032 PIX *pix, *pixt1, *pixt2; 00033 PIXCMAP *cmap; 00034 char *filein; 00035 char *fileout = NULL; 00036 static char mainName[] = "iotest"; 00037 00038 if (argc != 2 && argc != 3) 00039 exit(ERROR_INT(" Syntax: iotest filein [fileout]", mainName, 1)); 00040 00041 filein = argv[1]; 00042 if (argc == 3) 00043 fileout = argv[2]; 00044 00045 #if 1 00046 if ((pix = pixRead(filein)) == NULL) 00047 exit(ERROR_INT("pix not made", mainName, 1)); 00048 #else 00049 if ((pix = pixReadJpeg(filein, 0, 4, NULL)) == NULL) 00050 exit(ERROR_INT("pix not made", mainName, 1)); 00051 #endif 00052 00053 pixGetDimensions(pix, &w, &h, &d); 00054 wpl = pixGetWpl(pix); 00055 fprintf(stderr, "w = %d, h = %d, d = %d, wpl = %d\n", w, h, d, wpl); 00056 xres = pixGetXRes(pix); 00057 yres = pixGetXRes(pix); 00058 if (xres != 0 && yres != 0) 00059 fprintf(stderr, "xres = %d, yres = %d\n", xres, yres); 00060 if (pixGetColormap(pix)) { 00061 /* Write and read back the colormap */ 00062 pixcmapWriteStream(stderr, pixGetColormap(pix)); 00063 fp = lept_fopen("/tmp/junkcmap1", "wb"); 00064 pixcmapWriteStream(fp, pixGetColormap(pix)); 00065 lept_fclose(fp); 00066 fp = lept_fopen("/tmp/junkcmap1", "rb"); 00067 cmap = pixcmapReadStream(fp); 00068 lept_fclose(fp); 00069 fp = lept_fopen("/tmp/junkcmap2", "wb"); 00070 pixcmapWriteStream(fp, cmap); 00071 lept_fclose(fp); 00072 pixcmapDestroy(&cmap); 00073 00074 /* Remove and regenerate colormap */ 00075 pixt1 = pixRemoveColormap(pix, REMOVE_CMAP_BASED_ON_SRC); 00076 if (pixGetDepth(pixt1) == 8) { 00077 fprintf(stderr, "Colormap: represents grayscale image\n"); 00078 pixt2 = pixConvertGrayToColormap(pixt1); 00079 } 00080 else { /* 32 bpp */ 00081 fprintf(stderr, "Colormap: represents RGB image\n"); 00082 pixt2 = pixConvertRGBToColormap(pixt1, 1); 00083 } 00084 pixWrite("/tmp/junkpixt2.png", pixt2, IFF_PNG); 00085 pixDestroy(&pixt1); 00086 pixDestroy(&pixt2); 00087 } 00088 else { 00089 fprintf(stderr, "no colormap\n"); 00090 } 00091 format = pixGetInputFormat(pix); 00092 fprintf(stderr, "Input format extension: %s\n", 00093 ImageFileFormatExtensions[format]); 00094 if (format == IFF_JFIF_JPEG) 00095 fprintf(stderr, "Jpeg comment: %s\n", pixGetText(pix)); 00096 00097 if (d == 1) { 00098 pixCountPixels(pix, &count, NULL); 00099 fprintf(stderr, "pixel ratio ON/OFF = %6.3f\n", 00100 (l_float32)count / (l_float32)(pixGetWidth(pix) * pixGetHeight(pix))); 00101 } 00102 00103 if (argc == 3) { 00104 #if 1 00105 d = pixGetDepth(pix); 00106 if (d == 16 || d < 8 || pixGetColormap(pix)) 00107 pixWrite(fileout, pix, IFF_PNG); 00108 else 00109 pixWriteJpeg(fileout, pix, 75, 0); 00110 #elif 0 00111 pixWrite(fileout, pix, IFF_BMP); 00112 #elif 0 00113 pixWrite(fileout, pix, IFF_PNG); 00114 #elif 0 00115 pixWrite(fileout, pix, IFF_TIFF); 00116 fprintTiffInfo(stderr, fileout); 00117 #elif 0 00118 pixWrite(fileout, pix, IFF_TIFF_PACKBITS); 00119 fprintTiffInfo(stderr, fileout); 00120 #elif 0 00121 pixWrite(fileout, pix, IFF_TIFF_G3); 00122 fprintTiffInfo(stderr, fileout); 00123 #elif 0 00124 pixWrite(fileout, pix, IFF_TIFF_G4); 00125 fprintTiffInfo(stderr, fileout); 00126 #elif 0 00127 pixWrite(fileout, pix, IFF_JFIF_JPEG); 00128 #elif 0 00129 pixWriteJpeg(fileout, pix, 75, 0); 00130 #elif 0 00131 pixWrite(fileout, pix, IFF_PNM); 00132 #elif 0 00133 pixWrite(fileout, pix, IFF_PS); 00134 #endif 00135 } 00136 00137 pixDestroy(&pix); 00138 00139 #if 0 /* test tiff header reader */ 00140 { l_int32 w, h, bps, spp, res, cmap; 00141 if (readHeaderTiff(filein, 0, &w, &h, &bps, &spp, &res, &cmap) == 0) 00142 fprintf(stderr, 00143 "w = %d, h = %d, bps = %d, spp = %d, res = %d, cmap = %d\n", 00144 w, h, bps, spp, res, cmap); 00145 } 00146 #endif 00147 00148 return 0; 00149 } 00150