home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume19 / fbm / part02 / gray2clr.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-08  |  2.4 KB  |  83 lines

  1. /*****************************************************************
  2.  * gray2clr.c: FBM Library 0.9 (Beta test) 07-Mar-89  Michael Mauldin
  3.  *
  4.  * Copyright (C) 1989 by Michael Mauldin.  Permission is granted to
  5.  * use this file in whole or in part provided that you do not sell it
  6.  * for profit and that this copyright notice is retained unchanged.
  7.  *
  8.  * gray2clr.c: 
  9.  *
  10.  * USAGE
  11.  *    % gray2clr [ flags ] arguments
  12.  *
  13.  * EDITLOG
  14.  *    LastEditDate = Thu Apr 20 17:05:31 1989 - Michael Mauldin
  15.  *    LastFileName = /usr2/mlm/src/misc/fbm/gray2clr.c
  16.  *
  17.  * HISTORY
  18.  * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  19.  *    Beta release (version 0.9) mlm@cs.cmu.edu
  20.  *
  21.  *  1-Dec-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  22.  *    Created.
  23.  *****************************************************************/
  24.  
  25. # include <stdio.h>
  26. # include <math.h>
  27. # include "fbm.h"
  28.  
  29. # define USAGE "gray2clr [ -<type> ] [ -u ] < gray > color"
  30.  
  31. #ifndef lint
  32. static char *fbmid =
  33.     "$FBM gray2clr.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  34. #endif
  35.  
  36. main (argc, argv)
  37. char *argv[];
  38. { FBM input, output;
  39.   int outtype = DEF_8BIT;
  40.   int mapped = 1;
  41.  
  42.   /* If invoked as 'unmap', set option to mapped=0 */
  43.   if (strcmp (argv[0] + strlen (argv[0]) - 5, "unmap") == 0)
  44.   { mapped = 0; }
  45.  
  46.   /* Get the options */
  47.   while (--argc > 0 && (*++argv)[0] == '-')
  48.   { while (*++(*argv))
  49.     { switch (**argv)
  50.       { case 'u':    mapped = 0; break;
  51.     case 'A':    outtype = FMT_ATK; break;
  52.     case 'B':    outtype = FMT_FACE; break;
  53.     case 'F':    outtype = FMT_FBM; break;
  54.     case 'G':    outtype = FMT_GIF; break;
  55.     case 'I':    outtype = FMT_IFF; break;
  56.     case 'L':    outtype = FMT_LEAF; break;
  57.     case 'M':    outtype = FMT_MCP; break;
  58.     case 'P':    outtype = FMT_PBM; break;
  59.     case 'S':    outtype = FMT_SUN; break;
  60.     case 'T':    outtype = FMT_TIFF; break;
  61.     case 'X':    outtype = FMT_X11; break;
  62.     case 'Z':    outtype = FMT_PCX; break;
  63.     default:        fprintf (stderr, "%s\n", USAGE);
  64.                         exit (1);
  65.       }
  66.     }
  67.   }
  68.  
  69.   /* Clear the memory pointers so alloc_fbm won't be confused */
  70.   input.cm  = input.bm  = (unsigned char *) NULL;
  71.   output.cm = output.bm = (unsigned char *) NULL;
  72.  
  73.   /* Read the image and convert it */
  74.   if (read_bitmap (&input, (char *) NULL) &&
  75.       (mapped ?
  76.        gray2clr (&input, &output, outtype == FMT_SUN) :
  77.        clr_unmap (&input, &output)) &&
  78.       write_bitmap (&output, stdout, outtype))
  79.   { exit (0); }
  80.  
  81.   exit (1);
  82. }
  83.