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

  1. /*****************************************************************
  2.  * fbsharp.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.  * fbsharp.c: Sharpen an image by using a Laplacian edge enhancement
  9.  *
  10.  * USAGE
  11.  *    % fbsharp [ flags ] arguments
  12.  *
  13.  * EDITLOG
  14.  *    LastEditDate = Tue Mar  7 19:56:44 1989 - Michael Mauldin
  15.  *    LastFileName = /usr2/mlm/src/misc/fbm/fbsharp.c
  16.  *
  17.  * HISTORY
  18.  * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  19.  *    Beta release (version 0.9) mlm@cs.cmu.edu
  20.  *
  21.  * 10-Sep-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  22.  *    Created.
  23.  *****************************************************************/
  24.  
  25. # include <stdio.h>
  26. # include <math.h>
  27. # include "fbm.h"
  28.  
  29. # define USAGE "fbsharp [ -SF ] beta < 8bit > 8bit"
  30.  
  31. #ifndef lint
  32. static char *fbmid =
  33.     "$FBM fbsharp.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  34. #endif
  35.  
  36. main (argc, argv)
  37. char *argv[];
  38. { int w, h, k;
  39.   double beta = 2.0;
  40.   FBM input, output;
  41.   int outtype = DEF_8BIT;
  42.  
  43.   /* Get the options */
  44.   while (--argc > 0 && (*++argv)[0] == '-')
  45.   { while (*++(*argv))
  46.     { switch (**argv)
  47.       { 
  48.     case 'A':    outtype = FMT_ATK; break;
  49.     case 'B':    outtype = FMT_FACE; break;
  50.     case 'F':    outtype = FMT_FBM; break;
  51.     case 'G':    outtype = FMT_GIF; break;
  52.     case 'I':    outtype = FMT_IFF; break;
  53.     case 'L':    outtype = FMT_LEAF; break;
  54.     case 'M':    outtype = FMT_MCP; break;
  55.     case 'P':    outtype = FMT_PBM; break;
  56.     case 'S':    outtype = FMT_SUN; break;
  57.     case 'T':    outtype = FMT_TIFF; break;
  58.     case 'X':    outtype = FMT_X11; break;
  59.     case 'Z':    outtype = FMT_PCX; break;
  60.     default:        fprintf (stderr, "%s\n", USAGE);
  61.                         exit (1);
  62.       }
  63.     }
  64.   }
  65.  
  66.   /* Clear the memory pointers so alloc_fbm won't be confused */
  67.   input.cm  = input.bm  = (unsigned char *) NULL;
  68.   output.cm = output.bm = (unsigned char *) NULL;
  69.  
  70.   /* Read the image and sharpen it */
  71.   if (read_bitmap (&input, (char *) NULL))
  72.   {
  73.     if (input.hdr.bits != 8 || input.hdr.physbits != 8)
  74.     { fprintf (stderr,
  75.            "Can't handle images with %d bits and %d physbits per pixel\n",
  76.            input.hdr.bits, input.hdr.physbits);
  77.       exit (1);
  78.     }
  79.  
  80.     /* Argument is amount of sharpening */
  81.     if (argc > 0)        { beta = atof (argv[0]); }
  82.  
  83.     /* Determine output height & width (oh*ow <= size) */
  84.     h = input.hdr.rows;
  85.     w = input.hdr.cols;
  86.     k = input.hdr.planes;
  87.  
  88.     fprintf (stderr,
  89.          "Sharpen \"%s\", beta %1.3lf [%dx%dx%d]\n",
  90.          input.hdr.title[0] ? input.hdr.title : "(untitled)",
  91.          beta, w, h, k);
  92.  
  93.     /* Sharpen the image using a digitial Laplacian */
  94.     if (sharpen_fbm (&input, &output, beta) &&
  95.         write_bitmap (&output, stdout, outtype))
  96.     { exit (0); }
  97.   }
  98.   
  99.   exit (1);
  100. }
  101.