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

  1. /*****************************************************************
  2.  * fbmedian.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.  * fbmedian.c: Sharpen an image by using a Laplacian edge enhancement
  11.  *
  12.  * USAGE
  13.  *    % fbmedian [ flags ] arguments
  14.  *
  15.  * EDITLOG
  16.  *    LastEditDate = Mon Jun 25 00:04:40 1990 - Michael Mauldin
  17.  *    LastFileName = /usr2/mlm/src/misc/fbm/fbmedian.c
  18.  *
  19.  * HISTORY
  20.  * 07-Apr-93  Michael Mauldin (mlm) at Carnegie-Mellon University
  21.  *    Added -J switch
  22.  *
  23.  * 04-Feb-93  Michael Mauldin (mlm) at Carnegie-Mellon University
  24.  *    Created.
  25.  *****************************************************************/
  26.  
  27. # include <stdio.h>
  28. # include <math.h>
  29. # include "fbm.h"
  30.  
  31. # define USAGE "fbmedian [ -<type> ] < 8bit > 8bit"
  32.  
  33. #ifndef lint
  34. static char *fbmid =
  35. "$FBM fbmedian.c <1.2> 07-Apr-93 (C) 1989-1993 by Michael Mauldin, source \
  36. code available free from MLM@CS.CMU.EDU and from UUNET archives$";
  37. #endif
  38.  
  39. main (argc, argv)
  40. char *argv[];
  41. { int w, h, k;
  42.   FBM input, output;
  43.   int outtype = DEF_8BIT;
  44.  
  45.   /* Get the options */
  46.   while (--argc > 0 && (*++argv)[0] == '-')
  47.   { while (*++(*argv))
  48.     { switch (**argv)
  49.       { 
  50.     case 'A':    outtype = FMT_ATK; break;
  51.     case 'B':    outtype = FMT_FACE; break;
  52.     case 'F':    outtype = FMT_FBM; break;
  53.     case 'G':    outtype = FMT_GIF; break;
  54.     case 'I':    outtype = FMT_IFF; break;
  55.     case 'J':    outtype = FMT_JPEG; break;
  56.     case 'L':    outtype = FMT_LEAF; break;
  57.     case 'M':    outtype = FMT_MCP; break;
  58.     case 'P':    outtype = FMT_PBM; break;
  59.     case 'R':    outtype = FMT_RLE; 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.   /* Clear the memory pointers so alloc_fbm won't be confused */
  71.   input.cm  = input.bm  = (unsigned char *) NULL;
  72.   output.cm = output.bm = (unsigned char *) NULL;
  73.  
  74.   /* Read the image and sharpen it */
  75.   if (read_bitmap (&input, (char *) NULL))
  76.   {
  77.     if (input.hdr.bits != 8 || input.hdr.physbits != 8)
  78.     { fprintf (stderr,
  79.            "Can't handle images with %d bits and %d physbits per pixel\n",
  80.            input.hdr.bits, input.hdr.physbits);
  81.       exit (1);
  82.     }
  83.  
  84.     /* Determine output height & width (oh*ow <= size) */
  85.     h = input.hdr.rows;
  86.     w = input.hdr.cols;
  87.     k = input.hdr.planes;
  88.  
  89.     fprintf (stderr,
  90.          "Median \"%s\"  [%dx%dx%d]\n",
  91.          input.hdr.title[0] ? input.hdr.title : "(untitled)",
  92.          w, h, k);
  93.  
  94.     /* Sharpen the image using a digitial Laplacian */
  95.     if (median_fbm (&input, &output) &&
  96.         write_bitmap (&output, stdout, outtype))
  97.     { exit (0); }
  98.   }
  99.   
  100.   exit (1);
  101. }
  102.