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

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