home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / fbm12s.lha / clr2gray.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-18  |  3.0 KB  |  97 lines

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