Leptonica 1.68
C Image Processing Library

fileinfo.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  * fileinfo.c
00018  *
00019  *   Returns information about the image data file
00020  */
00021 
00022 #include "allheaders.h"
00023 
00024 LEPT_DLL extern const char *ImageFileFormatExtensions[];
00025 
00026 main(int    argc,
00027      char **argv)
00028 {
00029 char        *text;
00030 l_int32      w, h, d, wpl, count, npages, color, format, bps, spp, iscmap;
00031 FILE        *fp;
00032 PIX         *pix;
00033 PIXCMAP     *cmap;
00034 char        *filein;
00035 static char  mainName[] = "fileinfo";
00036 
00037     if (argc != 2)
00038         exit(ERROR_INT(" Syntax:  fileinfo filein", mainName, 1));
00039     filein = argv[1];
00040 
00041     l_pngSetStrip16To8(0);  /* to preserve 16 bpp if format is png */
00042 
00043         /* Read the full image */
00044     if ((pix = pixRead(filein)) == NULL)
00045         exit(ERROR_INT("image not returned from file", mainName, 1));
00046 
00047     format = pixGetInputFormat(pix);
00048     pixGetDimensions(pix, &w, &h, &d);
00049     wpl = pixGetWpl(pix);
00050     fprintf(stderr, "Reading the full image:\n");
00051     fprintf(stderr, "  Input image format type: %s\n",
00052             ImageFileFormatExtensions[format]);
00053     fprintf(stderr, "  w = %d, h = %d, d = %d, wpl = %d\n", w, h, d, wpl);
00054     fprintf(stderr, "  xres = %d, yres = %d\n",
00055             pixGetXRes(pix), pixGetYRes(pix));
00056 
00057     text = pixGetText(pix);
00058     if (text)  /*  not null */
00059         fprintf(stderr, "  Text: %s\n", text);
00060 
00061     cmap = pixGetColormap(pix);
00062     if (cmap) {
00063         pixcmapHasColor(cmap, &color);
00064         if (color)
00065             fprintf(stderr, "  Colormap exists and has color values:");
00066         else
00067             fprintf(stderr, "  Colormap exists and has only gray values:");
00068         pixcmapWriteStream(stderr, pixGetColormap(pix));
00069     }
00070     else
00071         fprintf(stderr, "  Colormap does not exist.\n");
00072 
00073     if (format == IFF_TIFF || format == IFF_TIFF_G4 ||
00074         format == IFF_TIFF_G3 || format == IFF_TIFF_PACKBITS) {
00075         fprintf(stderr, "  Tiff header information:\n");
00076         fp = lept_fopen(filein, "rb");
00077         tiffGetCount(fp, &npages);
00078         lept_fclose(fp);
00079         if (npages == 1)
00080             fprintf(stderr, "    One page in file\n", npages);
00081         else
00082             fprintf(stderr, "    %d pages in file\n", npages);
00083         fprintTiffInfo(stderr, filein);
00084     }
00085 
00086     if (d == 1) {
00087         pixCountPixels(pix, &count, NULL);
00088         fprintf(stderr, "  1 bpp: pixel ratio ON/OFF = %6.3f\n",
00089           (l_float32)count / (l_float32)(pixGetWidth(pix) * pixGetHeight(pix)));
00090     }
00091 
00092     pixDestroy(&pix);
00093 
00094         /* Test pixReadHeader() */
00095     if (pixReadHeader(filein, &format, &w, &h, &bps, &spp, &iscmap)) {
00096         fprintf(stderr, "Failure to read header!\n");
00097         return 1;
00098     }
00099     fprintf(stderr, "Reading just the header:\n");
00100     fprintf(stderr, "  Input image format type: %s\n",
00101             ImageFileFormatExtensions[format]);
00102     fprintf(stderr,
00103             "  w = %d, h = %d, d = %d, bps = %d, spp = %d, iscmap = %d\n",
00104             w, h, d, bps, spp, iscmap);
00105     return 0;
00106 }
00107 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines