home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / fbm / src / gray2clr.c < prev    next >
C/C++ Source or Header  |  1990-06-24  |  3KB  |  90 lines

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