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

  1. /*****************************************************************
  2.  * clr2gray.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.  * USAGE
  9.  *    % clr2gray [ -r<red> -g<grn> -b<blu> ] [ -<type> ] < color > gray
  10.  *
  11.  * EDITLOG
  12.  *    LastEditDate = Tue Mar  7 19:56:03 1989 - Michael Mauldin
  13.  *    LastFileName = /usr2/mlm/src/misc/fbm/clr2gray.c
  14.  *
  15.  * HISTORY
  16.  * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  17.  *    Beta release (version 0.9) mlm@cs.cmu.edu
  18.  *
  19.  * 06-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  20.  *    Added options for RGB weights
  21.  *
  22.  *  1-Dec-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  23.  *    Created.
  24.  *****************************************************************/
  25.  
  26. # include <stdio.h>
  27. # include <math.h>
  28. # include "fbm.h"
  29.  
  30. # define USAGE \
  31. "Usage: clr2gray [ -r<red> -g<grn> -b<blu> ] [ -<type> ] < color > gray"
  32.  
  33. #ifndef lint
  34. static char *fbmid =
  35.     "$FBM clr2gray.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  36. #endif
  37.  
  38. main (argc, argv)
  39. char *argv[];
  40. { FBM input, output;
  41.   int outtype = DEF_8BIT;
  42.   int rw=0, gw=0, bw=0;
  43.  
  44.   /* Get the options */
  45.   while (--argc > 0 && (*++argv)[0] == '-')
  46.   { while (*++(*argv))
  47.     { switch (**argv)
  48.       { 
  49.     case 'r':    rw = atoi (*argv+1); SKIPARG; break;
  50.     case 'g':    gw = atoi (*argv+1); SKIPARG; break;
  51.     case 'b':    bw = atoi (*argv+1); SKIPARG; break;
  52.     case 'A':    outtype = FMT_ATK; break;
  53.     case 'B':    outtype = FMT_FACE; break;
  54.     case 'F':    outtype = FMT_FBM; break;
  55.     case 'G':    outtype = FMT_GIF; break;
  56.     case 'I':    outtype = FMT_IFF; break;
  57.     case 'L':    outtype = FMT_LEAF; break;
  58.     case 'M':    outtype = FMT_MCP; break;
  59.     case 'P':    outtype = FMT_PBM; break;
  60.     case 'S':    outtype = FMT_SUN; break;
  61.     case 'T':    outtype = FMT_TIFF; break;
  62.     case 'X':    outtype = FMT_X11; break;
  63.     case 'Z':    outtype = FMT_PCX; break;
  64.     default:        fprintf (stderr, "%s\n", USAGE);
  65.                         exit (1);
  66.       }
  67.     }
  68.   }
  69.  
  70.   /* Use NTSC weights for defaults */
  71.   if (rw + gw + bw <= 0)
  72.   { rw = 299; gw = 587; bw = 114; }
  73.  
  74.   /* Clear the memory pointers so alloc_fbm won't be confused */
  75.   input.cm  = input.bm  = (unsigned char *) NULL;
  76.   output.cm = output.bm = (unsigned char *) NULL;
  77.  
  78.   /* Read the image and convert it, use NTSC weights */
  79.   if (read_bitmap (&input, (char *) NULL) &&
  80.       clr2gray (&input, &output, rw, gw, bw) &&
  81.       write_bitmap (&output, stdout, outtype))
  82.   { exit (0); }
  83.  
  84.   exit (1);
  85. }
  86.