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

  1. /*****************************************************************
  2.  * fbclean.c: FBM Library 0.9 (Beta test) 07-Mar-89  Michael Mauldin
  3.  *
  4.  * Copyright (C) 1989 by Michael Mauldin & Gary Sherwin.
  5.  * Permission is granted to use this file in whole or in part provided
  6.  * that you do not sell it for profit and that this copyright notice
  7.  * is retained unchanged.
  8.  *
  9.  * fbclean.c: Normalize contrast and brightness of image
  10.  *
  11.  * USAGE
  12.  *      % fbclean [ flag ] < image > image2
  13.  *
  14.  * EDITLOG
  15.  *    New Filename = fbclean.c  Mon Nov 7 09:24:00 1988 - Gary Sherwin
  16.  *    LastEditDate = Mon Oct 31 08:34:55 1988 - Michael Mauldin
  17.  *    LastFileName = /usr2/mlm/src/misc/images/bsharp.c
  18.  *      LastEditDate = Tue Mar  7 17:46:17 1989 - Michael Mauldin
  19.  *      LastFileName = /usr2/mlm/src/misc/fbm/fbclean.c
  20.  *
  21.  * HISTORY
  22.  * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  23.  *    Beta release (version 0.9) mlm@cs.cmu.edu
  24.  *
  25.  * 07-Nov-88  Gary W. Sherwin (sherwin) at Westinghouse R&D
  26.  *    Changed to fbclean.
  27.  *
  28.  * 10-Sep-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  29.  *    Created.
  30.  *****************************************************************/
  31.  
  32. # include <stdio.h>
  33. # include <math.h>
  34. # include "fbm.h"
  35.  
  36. # define USAGE \
  37.   "Usage: fbclean [ -b<cleaner> -t<threshhold> -n<nbr> ]\n\
  38.            [ -<type> ] < bitmap > bitmap"
  39.  
  40. #ifndef lint
  41. static char *fbmid =
  42.     "$FBM fbclean.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  43. #endif
  44.  
  45. main (argc, argv)
  46. char *argv[];
  47. { int w, h, k;
  48.   int cleaner = 5;
  49.   int blacktrp = 0;
  50.   int nbr = 5;
  51.   int outtype = DEF_1BIT;
  52.   FBM input, output;
  53.  
  54.   /* Get the options */
  55.   while (--argc > 0 && (*++argv)[0] == '-')
  56.   { while (*++(*argv))
  57.     { switch (**argv)
  58.       { case 'b':       cleaner = atoi (*argv+1); SKIPARG; break;
  59.         case 't':    blacktrp = atoi (*argv+1); SKIPARG; break;
  60.         case 'n':    nbr = 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 'L':    outtype = FMT_LEAF; break;
  67.     case 'M':    outtype = FMT_MCP; break;
  68.     case 'P':    outtype = FMT_PBM; break;
  69.     case 'S':    outtype = FMT_SUN; break;
  70.     case 'T':    outtype = FMT_TIFF; break;
  71.     case 'X':    outtype = FMT_X11; break;
  72.     case 'Z':    outtype = FMT_PCX; break;
  73.         default:        fprintf (stderr, "%s\n", USAGE);
  74.                         exit (1);
  75.       }
  76.     }
  77.   }
  78.   
  79.   /* Clear the memory pointers so alloc_fbm won't be confused */
  80.   input.cm  = input.bm  = (unsigned char *) NULL;
  81.   output.cm = output.bm = (unsigned char *) NULL;
  82.  
  83.   /* Read the image and clean it */
  84.   if (read_bitmap (&input, (char *) NULL))
  85.   {
  86.     if (input.hdr.bits != 8 || input.hdr.physbits != 8)
  87.     { fprintf (stderr,
  88.            "Can't handle images with %d bits and %d physbits per pixel\n",
  89.            input.hdr.bits, input.hdr.physbits);
  90.       exit (1);
  91.     }
  92.  
  93.     /* Determine output height & width (oh*ow <= size) */
  94.     h = input.hdr.rows;
  95.     w = input.hdr.cols;
  96.     k = input.hdr.planes;
  97.  
  98.     fprintf (stderr,
  99.          "Cleaning \"%s\", # of Neighbors %2d, nbr %d [%dx%dx%d]\n",
  100.          input.hdr.title[0] ? input.hdr.title : "(untitled)",
  101.          cleaner, nbr, w, h, k);
  102.  
  103.     /* Clean the image using a digitial Laplacian */
  104.     if (clean_fbm (&input, &output, cleaner, blacktrp, nbr) &&
  105.         write_bitmap (&output, stdout, outtype))
  106.     { exit (0); }
  107.   }
  108.   
  109.   exit (1);
  110. }
  111.