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

  1. /*****************************************************************
  2.  * fbcat.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.  * fbcat.c: 
  9.  *    Convert an image from one format to another.  Input image type
  10.  *    is determined by magic number.  Output is specified by argument.
  11.  *    Note that the ascpect ratio, size and number of colors is not
  12.  *    changed, and that some conversions (such as grayscale to bitmap
  13.  *    or color to gray require more processing than fbcat can do.
  14.  *    For these transformations you must use other programs like
  15.  *    clr2gray, gray2clr, fbhalf, and fbsample.
  16.  *
  17.  * USAGE
  18.  *    % fbcat [ -t'title' -c'credits' ] [ -<type> ] [ image ] > image
  19.  *
  20.  * EDITLOG
  21.  *    LastEditDate = Wed May  3 22:03:33 1989 - Michael Mauldin
  22.  *    LastFileName = /usr2/mlm/src/misc/fbm/fbcat.c
  23.  *
  24.  * HISTORY
  25.  * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  26.  *    Beta release (version 0.9) mlm@cs.cmu.edu
  27.  *
  28.  * 29-Nov-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  29.  *    Created.
  30.  *****************************************************************/
  31.  
  32.  
  33. # include <stdio.h>
  34. # include "fbm.h"
  35.  
  36. # define USAGE \
  37. "Usage: fbcat [ -a<aspect> -t'title' -c'credits' ]\n\
  38.          [ -<type> ] [ image ] > image"
  39.  
  40. /****************************************************************
  41.  * main
  42.  ****************************************************************/
  43.  
  44. #ifndef lint
  45. static char *fbmid =
  46.     "$FBM fbcat.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  47. #endif
  48.  
  49. main (argc, argv)
  50. char *argv[];
  51. { FBM image;
  52.   int outtype = FMT_FBM;
  53.   double aspect = 0.0;
  54.   char *title = NULL, *credits = NULL;
  55.  
  56.   /* Get the options */
  57.   while (--argc > 0 && (*++argv)[0] == '-')
  58.   { while (*++(*argv))
  59.     { switch (**argv)
  60.       {
  61.     case 'a':    aspect = atof (*argv+1); SKIPARG; break;
  62.     case 't':    title = *argv+1; SKIPARG; break;
  63.     case 'c':    credits = *argv+1; SKIPARG; break;
  64.     case 'A':    outtype = FMT_ATK; break;
  65.     case 'B':    outtype = FMT_FACE; break;
  66.     case 'F':    outtype = FMT_FBM; break;
  67.     case 'G':    outtype = FMT_GIF; break;
  68.     case 'I':    outtype = FMT_IFF; break;
  69.     case 'M':    outtype = FMT_MCP; break;
  70.     case 'P':    outtype = FMT_PBM; break;
  71.     case 'S':    outtype = FMT_SUN; break;
  72.     case 'T':    outtype = FMT_TIFF; break;
  73.     case 'X':    outtype = FMT_X11; break;
  74.     case 'Z':    outtype = FMT_PCX; break;
  75.     default:        fprintf (stderr, "%s\n", USAGE);
  76.                         exit (1);
  77.       }
  78.     }
  79.   }
  80.  
  81.   /* Clear the memory pointers so alloc_fbm won't be confused */
  82.   image.cm  = image.bm  = (unsigned char *) NULL;
  83.  
  84.   /* Now read in the Sun format image and write an FBM format file */
  85.   if (read_bitmap (&image, (argc > 0) ? *argv : (char *) NULL))
  86.   {
  87.     if (aspect != 0.0)
  88.     { fprintf (stderr,
  89.            "Overiding aspect ratio read (%1.3lf) with (%1.3lf)\n",
  90.            image.hdr.aspect, aspect);
  91.       image.hdr.aspect = aspect;
  92.     }
  93.  
  94.     if (title)
  95.     { strncpy (image.hdr.title, title, FBM_MAX_TITLE); }
  96.  
  97.     if (credits)
  98.     { strncpy (image.hdr.credits, credits, FBM_MAX_TITLE); }
  99.  
  100.     if (write_bitmap (&image, stdout, outtype))
  101.     { exit (0);
  102.     }
  103.   }
  104.  
  105.   exit (1);
  106. }
  107.