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

  1. /*****************************************************************
  2.  * fbedge.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.  * fbedge.c: Take derivative and edge detect image
  10.  *
  11.  * USAGE
  12.  *      % fbedge [ flag ] < image > image2
  13.  *
  14.  * EDITLOG
  15.  *    New Filename = fbedge.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:50:04 1989 - Michael Mauldin
  19.  *      LastFileName = /usr2/mlm/src/misc/fbm/fbedge.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 fbedge.
  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 "Usage: fbedge [ -t<threshhold> ] < bitmap > bitmap"
  37.  
  38. #ifndef lint
  39. static char *fbmid =
  40.     "$FBM fbedge.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  41. #endif
  42.  
  43. main (argc, argv)
  44. char *argv[];
  45. { int w, h, k;
  46.   int blacktrp = 0;
  47.   int outtype = DEF_1BIT;
  48.   FBM input, output;
  49.  
  50.   /* Get the options */
  51.   while (--argc > 0 && (*++argv)[0] == '-')
  52.   { while (*++(*argv))
  53.     { switch (**argv)
  54.       { case 't':    blacktrp = atoi (*argv+1); SKIPARG; break;
  55.     case 'A':    outtype = FMT_ATK; break;
  56.     case 'B':    outtype = FMT_FACE; break;
  57.     case 'F':    outtype = FMT_FBM; break;
  58.     case 'G':    outtype = FMT_GIF; break;
  59.     case 'I':    outtype = FMT_IFF; break;
  60.     case 'L':    outtype = FMT_LEAF; break;
  61.     case 'M':    outtype = FMT_MCP; break;
  62.     case 'P':    outtype = FMT_PBM; 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 clean 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.     /* Determine output height & width (oh*ow <= size) */
  88.     h = input.hdr.rows;
  89.     w = input.hdr.cols;
  90.     k = input.hdr.planes;
  91.  
  92.     fprintf (stderr,
  93.          "Edge detect\"%s\", Black-trip %2d [%dx%dx%d]\n",
  94.          input.hdr.title[0] ? input.hdr.title : "(untitled)",
  95.          blacktrp, w, h, k);
  96.  
  97.     /* Edge detect the image using a digitial Laplacian */
  98.     if (findedge_fbm (&input, &output, blacktrp) &&
  99.         write_bitmap (&output, stdout, outtype))
  100.     { exit (0); }
  101.   }
  102.   
  103.   exit (1);
  104. }
  105.