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

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