home *** CD-ROM | disk | FTP | other *** search
/ BCI NET / BCI NET Dec 94.iso / archives / programming / source / fbm12s.lha / fbrev.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-18  |  3.5 KB  |  124 lines

  1. /*****************************************************************
  2.  * fbrev.c: FBM Release 1.2 07-Apr-93 Michael Mauldin
  3.  *
  4.  * Copyright (C) 1989-1993 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.  * fbrev.c: Reverse intensity of image.
  11.  *
  12.  * USAGE
  13.  *      % fbrev < image > image2
  14.  *
  15.  * EDITLOG
  16.  *      LastEditDate = Thu Dec 27 14:47:54 1990 - Michael Mauldin
  17.  *      LastFileName = /usr2/mlm/src/misc/fbm/fbrev.c
  18.  *
  19.  * HISTORY
  20.  * 07-Apr-93  Michael Mauldin (mlm) at Carnegie-Mellon University
  21.  *    Added -J switch
  22.  *
  23.  * 25-Jun-90  Michael Mauldin (mlm@cs.cmu.edu) Carnegie Mellon
  24.  *    Package for Release 1.0
  25.  *
  26.  * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  27.  *    Beta release (version 0.9) mlm@cs.cmu.edu
  28.  *
  29.  * 21-Aug-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  30.  *      Created.
  31.  *****************************************************************/
  32.  
  33. # include <stdio.h>
  34. # include <math.h>
  35. # include <ctype.h>
  36. # include "fbm.h"
  37.  
  38. # define USAGE \
  39.     "Usage: fbrev [ -<type> ] < image > image"
  40.  
  41. #ifndef lint
  42. static char *fbmid =
  43. "$FBM fbrev.c <1.2> 07-Apr-93 (C) 1989-1993 by Michael Mauldin, source \
  44. code available free from MLM@CS.CMU.EDU and from UUNET archives$";
  45. #endif
  46.  
  47. main (argc, argv)
  48. char *argv[];
  49. { FBM image;
  50.   register unsigned char *bmptr, *tail;
  51.   register int i;
  52.   int outtype = FMT_FBM;
  53.  
  54.   /* Get the options */
  55.   while (--argc > 0 && (*++argv)[0] == '-')
  56.   { while (*++(*argv))
  57.     { switch (**argv)
  58.       { case 'A':    outtype = FMT_ATK; break;
  59.     case 'B':    outtype = FMT_FACE; break;
  60.     case 'F':    outtype = FMT_FBM; break;
  61.     case 'G':    outtype = FMT_GIF; break;
  62.     case 'I':    outtype = FMT_IFF; break;
  63.     case 'J':    outtype = FMT_JPEG; break;
  64.     case 'L':    outtype = FMT_LEAF; break;
  65.     case 'M':    outtype = FMT_MCP; break;
  66.     case 'P':    outtype = FMT_PBM; break;
  67.     case 'R':    outtype = FMT_RLE; break;
  68.     case 'S':    outtype = FMT_SUN; break;
  69.     case 'T':    outtype = FMT_TIFF; break;
  70.     case 'X':    outtype = FMT_X11; break;
  71.     case 'Z':    outtype = FMT_PCX; break;
  72.         default:        fprintf (stderr, "%s\n", USAGE);
  73.                         exit (1);
  74.       }
  75.     }
  76.   }
  77.   
  78.   /* Clear the memory pointer so alloc_fbm won't be confused */
  79.   image.cm  = image.bm  = (unsigned char *) NULL;
  80.  
  81.   /* Now read in the image */
  82.   if (read_bitmap (&image, (char *) NULL))
  83.   { if (image.hdr.clrlen > 0)
  84.     { fprintf (stderr, "Reversing map: \"%s\" [%dx%d], %d colors\n",
  85.                image.hdr.title[0] ? image.hdr.title : "(untitled)",
  86.            image.hdr.cols, image.hdr.rows, image.hdr.clrlen / 3);
  87.  
  88.       for (i=0; i<image.hdr.clrlen; i++)
  89.       { image.cm[i] = WHITE - image.cm[i]; }
  90.     }
  91.     
  92.     else if (image.hdr.physbits != 8)
  93.     { fprintf (stderr,
  94.            "fbrev: can't handle files with %d physical bytes per pixel.\n",
  95.            image.hdr.physbits);
  96.       exit (1);
  97.     }
  98.     
  99.     else
  100.     { fprintf (stderr, "Reversing: \"%s\" [%dx%d]",
  101.                image.hdr.title[0] ? image.hdr.title : "(untitled)",
  102.            image.hdr.cols, image.hdr.rows);
  103.       if (image.hdr.planes > 1)
  104.       { fprintf (stderr, ", %d planes", image.hdr.planes); }
  105.       fprintf (stderr, "\n");
  106.  
  107.       bmptr = image.bm;
  108.       tail = bmptr + image.hdr.plnlen * image.hdr.planes;
  109.  
  110.       while (bmptr < tail)
  111.       { *bmptr = WHITE - *bmptr;
  112.         bmptr++;
  113.       }
  114.     }
  115.     
  116.     /* Write it out */
  117.     write_bitmap (&image, stdout, outtype);
  118.   }
  119.   else
  120.   { exit (1); }
  121.   
  122.   exit (0);
  123. }
  124.