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

  1. /*****************************************************************
  2.  * fbsharp.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.  * fbsharp.c: Sharpen an image by using a Laplacian edge enhancement
  11.  *
  12.  * USAGE
  13.  *    % fbsharp [ flags ] arguments
  14.  *
  15.  * EDITLOG
  16.  *    LastEditDate = Mon Jun 25 00:04:40 1990 - Michael Mauldin
  17.  *    LastFileName = /usr2/mlm/src/misc/fbm/fbsharp.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.  * 10-Sep-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 "fbsharp [ -SF ] beta < 8bit > 8bit"
  35.  
  36. #ifndef lint
  37. static char *fbmid =
  38. "$FBM fbsharp.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. { int w, h, k;
  45.   double beta = 2.0;
  46.   FBM input, output;
  47.   int outtype = DEF_8BIT;
  48.  
  49.   /* Get the options */
  50.   while (--argc > 0 && (*++argv)[0] == '-')
  51.   { while (*++(*argv))
  52.     { switch (**argv)
  53.       { 
  54.     case 'A':    outtype = FMT_ATK; break;
  55.     case 'B':    outtype = FMT_FACE; break;
  56.     case 'F':    outtype = FMT_FBM; break;
  57.     case 'G':    outtype = FMT_GIF; break;
  58.     case 'I':    outtype = FMT_IFF; break;
  59.     case 'L':    outtype = FMT_LEAF; break;
  60.     case 'M':    outtype = FMT_MCP; break;
  61.     case 'P':    outtype = FMT_PBM; break;
  62.     case 'R':    outtype = FMT_RLE; break;
  63.     case 'S':    outtype = FMT_SUN; break;
  64.     case 'T':    outtype = FMT_TIFF; break;
  65.     case 'X':    outtype = FMT_X11; break;
  66.     case 'Z':    outtype = FMT_PCX; break;
  67.     default:        fprintf (stderr, "%s\n", USAGE);
  68.                         exit (1);
  69.       }
  70.     }
  71.   }
  72.  
  73.   /* Clear the memory pointers so alloc_fbm won't be confused */
  74.   input.cm  = input.bm  = (unsigned char *) NULL;
  75.   output.cm = output.bm = (unsigned char *) NULL;
  76.  
  77.   /* Read the image and sharpen it */
  78.   if (read_bitmap (&input, (char *) NULL))
  79.   {
  80.     if (input.hdr.bits != 8 || input.hdr.physbits != 8)
  81.     { fprintf (stderr,
  82.            "Can't handle images with %d bits and %d physbits per pixel\n",
  83.            input.hdr.bits, input.hdr.physbits);
  84.       exit (1);
  85.     }
  86.  
  87.     /* Argument is amount of sharpening */
  88.     if (argc > 0)        { beta = atof (argv[0]); }
  89.  
  90.     /* Determine output height & width (oh*ow <= size) */
  91.     h = input.hdr.rows;
  92.     w = input.hdr.cols;
  93.     k = input.hdr.planes;
  94.  
  95.     fprintf (stderr,
  96.          "Sharpen \"%s\", beta %1.3lf [%dx%dx%d]\n",
  97.          input.hdr.title[0] ? input.hdr.title : "(untitled)",
  98.          beta, w, h, k);
  99.  
  100.     /* Sharpen the image using a digitial Laplacian */
  101.     if (sharpen_fbm (&input, &output, beta) &&
  102.         write_bitmap (&output, stdout, outtype))
  103.     { exit (0); }
  104.   }
  105.   
  106.   exit (1);
  107. }
  108.