Leptonica 1.68
C Image Processing Library

removecmap.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  * removecmap.c
00018  *
00019  *      removecmap filein type fileout
00020  *
00021  *          type:  1 for conversion to 8 bpp gray
00022  *                 2 for conversion to 24 bpp full color
00023  *                 3 for conversion depending on src
00024  *
00025  *      Removes the colormap and does the conversion
00026  *      Works on palette images of 2, 4 and 8 bpp
00027  */
00028 
00029 #include "allheaders.h"
00030 
00031 main(int    argc,
00032      char **argv)
00033 {
00034 char        *filein, *fileout;
00035 l_int32      d, type, numcolors;
00036 PIX         *pixs, *pixd;
00037 PIXCMAP     *cmap;
00038 static char  mainName[] = "removecmap";
00039 
00040     if (argc != 4)
00041         exit(ERROR_INT("Syntax:  removecmap filein type fileout", mainName, 1));
00042 
00043     filein = argv[1];
00044     type = atoi(argv[2]);
00045     fileout = argv[3];
00046 
00047     if ((pixs = pixRead(filein)) == NULL)
00048         exit(ERROR_INT("pixs not made", mainName, 1));
00049             
00050     fprintf(stderr, " depth = %d\n", pixGetDepth(pixs));
00051     if ((cmap = pixGetColormap(pixs)) != NULL) {
00052         numcolors = pixcmapGetCount(cmap);
00053         pixcmapWriteStream(stderr, cmap);
00054         fprintf(stderr, " colormap found; num colors = %d\n", numcolors);
00055     }
00056     else
00057         fprintf(stderr, " no colormap\n");
00058 
00059     pixd = pixRemoveColormap(pixs, type);
00060     pixWrite(fileout, pixd, IFF_PNG);
00061     pixDestroy(&pixs);
00062     pixDestroy(&pixd);
00063     return 0;
00064 }
00065 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines