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

  1. /*****************************************************************
  2.  * fbclean.c: FBM Release 1.0 25-Feb-90 Michael Mauldin
  3.  *
  4.  * Copyright (C) 1989,1990 by Gary Sherwin & Michael Mauldin.
  5.  * Permission is granted to use this file in whole or in part for
  6.  * any purpose, educational, recreational or commercial, provided
  7.  * that this copyright notice is retained unchanged.  This software
  8.  * is available to all free of charge by anonymous FTP and in the
  9.  * UUNET archives.
  10.  *
  11.  *
  12.  * fbclean.c: Normalize contrast and brightness of image
  13.  *
  14.  * USAGE
  15.  *      % fbclean [ flag ] < image > image2
  16.  *
  17.  * EDITLOG
  18.  *    LastEditDate = Mon Jun 25 00:04:47 1990 - Michael Mauldin
  19.  *    LastFileName = /usr2/mlm/src/misc/fbm/flblue.c
  20.  *
  21.  * HISTORY
  22.  * 25-Jun-90  Michael Mauldin (mlm@cs.cmu.edu) Carnegie Mellon
  23.  *    Package for Release 1.0
  24.  *
  25.  * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  26.  *    Beta release (version 0.9) mlm@cs.cmu.edu
  27.  *
  28.  * 07-Nov-88  Gary W. Sherwin (sherwin) at Westinghouse R&D
  29.  *    Changed to fbclean.
  30.  *
  31.  * 10-Sep-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  32.  *    Created.
  33.  *****************************************************************/
  34.  
  35. # include <stdio.h>
  36. # include <math.h>
  37. # include "fbm.h"
  38.  
  39. # define USAGE \
  40.   "Usage: fbclean [ -b<cleaner> -t<threshhold> -n<nbr> ]\n\
  41.            [ -<type> ] < bitmap > bitmap"
  42.  
  43. #ifndef lint
  44. static char *fbmid =
  45. "$FBM fbclean.c <1.0> 25-Jun-90  (C) 1989,1990 by Gary Sherwin & \
  46. Michael Mauldin, source code available free from MLM@CS.CMU.EDU \
  47. and from UUNET archives$";
  48. #endif
  49.  
  50. main (argc, argv)
  51. char *argv[];
  52. { int w, h, k;
  53.   int cleaner = 5;
  54.   int blacktrp = 0;
  55.   int nbr = 5;
  56.   int outtype = DEF_1BIT;
  57.   FBM input, output;
  58.  
  59.   /* Get the options */
  60.   while (--argc > 0 && (*++argv)[0] == '-')
  61.   { while (*++(*argv))
  62.     { switch (**argv)
  63.       { case 'b':       cleaner = atoi (*argv+1); SKIPARG; break;
  64.         case 't':    blacktrp = atoi (*argv+1); SKIPARG; break;
  65.         case 'n':    nbr = atoi (*argv+1); SKIPARG; break;
  66.     case 'A':    outtype = FMT_ATK; break;
  67.     case 'B':    outtype = FMT_FACE; break;
  68.     case 'F':    outtype = FMT_FBM; break;
  69.     case 'G':    outtype = FMT_GIF; break;
  70.     case 'I':    outtype = FMT_IFF; break;
  71.     case 'L':    outtype = FMT_LEAF; break;
  72.     case 'M':    outtype = FMT_MCP; break;
  73.     case 'P':    outtype = FMT_PBM; break;
  74.     case 'R':    outtype = FMT_RLE; break;
  75.     case 'S':    outtype = FMT_SUN; break;
  76.     case 'T':    outtype = FMT_TIFF; break;
  77.     case 'X':    outtype = FMT_X11; break;
  78.     case 'Z':    outtype = FMT_PCX; break;
  79.         default:        fprintf (stderr, "%s\n", USAGE);
  80.                         exit (1);
  81.       }
  82.     }
  83.   }
  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 clean it */
  90.   if (read_bitmap (&input, (char *) NULL))
  91.   {
  92.     if (input.hdr.bits != 8 || input.hdr.physbits != 8)
  93.     { fprintf (stderr,
  94.            "Can't handle images with %d bits and %d physbits per pixel\n",
  95.            input.hdr.bits, input.hdr.physbits);
  96.       exit (1);
  97.     }
  98.  
  99.     /* Determine output height & width (oh*ow <= size) */
  100.     h = input.hdr.rows;
  101.     w = input.hdr.cols;
  102.     k = input.hdr.planes;
  103.  
  104.     fprintf (stderr,
  105.          "Cleaning \"%s\", # of Neighbors %2d, nbr %d [%dx%dx%d]\n",
  106.          input.hdr.title[0] ? input.hdr.title : "(untitled)",
  107.          cleaner, nbr, w, h, k);
  108.  
  109.     /* Clean the image using a digitial Laplacian */
  110.     if (clean_fbm (&input, &output, cleaner, blacktrp, nbr) &&
  111.         write_bitmap (&output, stdout, outtype))
  112.     { exit (0); }
  113.   }
  114.   
  115.   exit (1);
  116. }
  117.