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

  1. /*****************************************************************
  2.  * fbrot.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.  * fbrot.c: Rotate image 90 degrees clockwise
  11.  *
  12.  * USAGE
  13.  *     % fbrot < image1 > image2
  14.  *
  15.  * EDITLOG
  16.  *     LastEditDate = Mon Jun 25 00:04:32 1990 - Michael Mauldin
  17.  *     LastFileName = /usr2/mlm/src/misc/fbm/fbrot.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.  * 22-Aug-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  27.  *     Created.
  28.  *****************************************************************/
  29.  
  30. # include <stdio.h>
  31. # include <math.h>
  32. # include "fbm.h"
  33.  
  34. # define USAGE \
  35.   "Usage: fbrot [ -<type> ] [ -90 | -180 | -270 ] < image > image"
  36.  
  37. #ifndef lint
  38. static char *fbmid =
  39. "$FBM fbrot.c <1.0> 25-Jun-90  (C) 1989,1990 by Michael Mauldin, source \
  40. code available free from MLM@CS.CMU.EDU and from UUNET archives$";
  41. #endif
  42.  
  43. main (argc, argv)
  44. char *argv[];
  45. { FBM input, output;
  46.   int outtype = -1, rot = 90;
  47.  
  48.   /* Get the options */
  49.   while (--argc > 0 && (*++argv)[0] == '-')
  50.   { while (*++(*argv))
  51.     { switch (**argv)
  52.       {
  53.     case '9':    rot=90; SKIPARG; break;
  54.     case '1':    rot=180; SKIPARG; break;
  55.     case '2':    rot=270; SKIPARG; break;
  56.     case 'A':    outtype = FMT_ATK; break;
  57.     case 'B':    outtype = FMT_FACE; break;
  58.     case 'F':    outtype = FMT_FBM; break;
  59.     case 'G':    outtype = FMT_GIF; break;
  60.     case 'I':    outtype = FMT_IFF; break;
  61.     case 'L':    outtype = FMT_LEAF; break;
  62.     case 'M':    outtype = FMT_MCP; break;
  63.     case 'P':    outtype = FMT_PBM; break;
  64.     case 'R':    outtype = FMT_RLE; break;
  65.     case 'S':    outtype = FMT_SUN; break;
  66.     case 'T':    outtype = FMT_TIFF; break;
  67.     case 'X':    outtype = FMT_X11; break;
  68.     case 'Z':    outtype = FMT_PCX; break;
  69.     default:        fprintf (stderr, "%s\n", USAGE);
  70.                         exit (1);
  71.       }
  72.     }
  73.   }
  74.  
  75.   /* Clear the memory pointers so alloc_fbm won't be confused */
  76.   input.cm  = input.bm  = (unsigned char *) NULL;
  77.   output.cm = output.bm = (unsigned char *) NULL;
  78.  
  79.   /* Read the image and rotate it */
  80.   if (read_bitmap (&input, (char *) NULL))
  81.   { if (outtype < 0)
  82.     { if (input.hdr.planes == 1 && input.hdr.bits == 1)
  83.       { outtype = DEF_1BIT; }
  84.       else
  85.       { outtype = DEF_8BIT; }
  86.     }
  87.  
  88.     if (rotate_fbm (&input, &output, rot) &&
  89.         write_bitmap (&output, stdout, outtype))
  90.     { exit (0); }
  91.   }
  92.  
  93.   exit (1);
  94. }
  95.