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

  1. /*****************************************************************
  2.  * fbrot.c: FBM Library 0.9 (Beta test) 07-Mar-89  Michael Mauldin
  3.  *
  4.  * Copyright (C) 1989 by Michael Mauldin.  Permission is granted to
  5.  * use this file in whole or in part provided that you do not sell it
  6.  * for profit and that this copyright notice is retained unchanged.
  7.  *
  8.  * fbrot.c: Rotate image 90 degrees clockwise
  9.  *
  10.  * USAGE
  11.  *     % fbrot < image1 > image2
  12.  *
  13.  * EDITLOG
  14.  *     LastEditDate = Tue Mar  7 19:56:41 1989 - Michael Mauldin
  15.  *     LastFileName = /usr2/mlm/src/misc/fbm/fbrot.c
  16.  *
  17.  * HISTORY
  18.  * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  19.  *    Beta release (version 0.9) mlm@cs.cmu.edu
  20.  *
  21.  * 22-Aug-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  22.  *     Created.
  23.  *****************************************************************/
  24.  
  25. # include <stdio.h>
  26. # include <math.h>
  27. # include "fbm.h"
  28.  
  29. # define USAGE \
  30.   "Usage: fbrot [ -<type> ] [ -90 | -180 | -270 ] < image > image"
  31.  
  32. #ifndef lint
  33. static char *fbmid =
  34.     "$FBM fbrot.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  35. #endif
  36.  
  37. main (argc, argv)
  38. char *argv[];
  39. { FBM input, output;
  40.   int outtype = -1, rot = 90;
  41.  
  42.   /* Get the options */
  43.   while (--argc > 0 && (*++argv)[0] == '-')
  44.   { while (*++(*argv))
  45.     { switch (**argv)
  46.       {
  47.     case '9':    rot=90; SKIPARG; break;
  48.     case '1':    rot=180; SKIPARG; break;
  49.     case '2':    rot=270; SKIPARG; break;
  50.     case 'A':    outtype = FMT_ATK; break;
  51.     case 'B':    outtype = FMT_FACE; break;
  52.     case 'F':    outtype = FMT_FBM; break;
  53.     case 'G':    outtype = FMT_GIF; break;
  54.     case 'I':    outtype = FMT_IFF; break;
  55.     case 'L':    outtype = FMT_LEAF; break;
  56.     case 'M':    outtype = FMT_MCP; break;
  57.     case 'P':    outtype = FMT_PBM; break;
  58.     case 'S':    outtype = FMT_SUN; break;
  59.     case 'T':    outtype = FMT_TIFF; break;
  60.     case 'X':    outtype = FMT_X11; break;
  61.     case 'Z':    outtype = FMT_PCX; break;
  62.     default:        fprintf (stderr, "%s\n", USAGE);
  63.                         exit (1);
  64.       }
  65.     }
  66.   }
  67.  
  68.   /* Clear the memory pointers so alloc_fbm won't be confused */
  69.   input.cm  = input.bm  = (unsigned char *) NULL;
  70.   output.cm = output.bm = (unsigned char *) NULL;
  71.  
  72.   /* Read the image and rotate it */
  73.   if (read_bitmap (&input, (char *) NULL))
  74.   { if (outtype < 0)
  75.     { if (input.hdr.planes == 1 && input.hdr.bits == 1)
  76.       { outtype = DEF_1BIT; }
  77.       else
  78.       { outtype = DEF_8BIT; }
  79.     }
  80.  
  81.     if (rotate_fbm (&input, &output, rot) &&
  82.         write_bitmap (&output, stdout, outtype))
  83.     { exit (0); }
  84.   }
  85.  
  86.   exit (1);
  87. }
  88.