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

  1. /*****************************************************************
  2.  * qrt2fbm.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.  * qrt2fbm.c: Convert QRT format (from the QRT ray tracer)
  11.  *
  12.  * USAGE
  13.  *     % qrt2fbm -t'title' -c'credits' < qrtfile > fbm
  14.  *
  15.  * EDITLOG
  16.  *    LastEditDate = Mon Jun 25 00:40:50 1990 - Michael Mauldin
  17.  *    LastFileName = /usr2/mlm/src/misc/fbm/qrt2fbm.c
  18.  *
  19.  * HISTORY
  20.  * 25-Jun-90  Michael Mauldin (mlm@cs.cmu.edu) Carnegie Mellon
  21.  *    Package for Release 1.0
  22.  *
  23.  *  7-Apr-89  Michael Mauldin (mlm) at Carnegie-Mellon University
  24.  *    Installed, code by Butler Hines.
  25.  *
  26.  *****************************************************************/
  27.  
  28. # include <stdio.h>
  29. # include "fbm.h"
  30.  
  31. # define USAGE \
  32. "Usage: qrt2fbm [ -t'title' -c'credits' ] < qrtfile > fbm"
  33.  
  34. #ifndef lint
  35. static char *fbmid =
  36.  
  37. "$FBM qrt2fbm.c <1.0> 25-Jun-90  (C) 1989,1990 by Michael Mauldin, source \
  38. code available free from MLM@CS.CMU.EDU and from UUNET archives$";
  39. #endif
  40.  
  41. main (argc, argv)
  42. char *argv[];
  43. { register int j, k, rowlen;
  44.   double aspect = 0.56;
  45.   int rows, cols, line, len, planes=3;
  46.   FBMHDR hdr;
  47.   unsigned char *buf;
  48.   char title[FBM_MAX_TITLE], credits[FBM_MAX_TITLE];
  49.  
  50.   /* Get the options */
  51.   while (--argc > 0 && (*++argv)[0] == '-')
  52.   { while (*++(*argv))
  53.     { switch (**argv)
  54.       { 
  55.     case 't':    strncpy (title, *argv+1, FBM_MAX_TITLE);
  56.             title[FBM_MAX_TITLE-1] = '\0';
  57.             CLRARG; break;
  58.     case 'c':    strncpy (credits, *argv+1, FBM_MAX_TITLE);
  59.             credits[FBM_MAX_TITLE-1] = '\0';
  60.             CLRARG; break;
  61.     default:    fprintf (stderr, "%s\n", USAGE);
  62.             exit (1);
  63.       }
  64.     }
  65.   }
  66.  
  67.   cols = getchar();
  68.   cols |= (getchar()<<8);
  69.   rows = getchar();
  70.   rows |= (getchar()<<8);
  71.   
  72.   rowlen = 2 * ((cols * 8 + 15) / 16);
  73.  
  74.   /* Build header */
  75.   hdr.rows = rows;
  76.   hdr.cols = cols;
  77.   hdr.planes = planes;
  78.   hdr.bits = 8;
  79.   hdr.physbits = 8;
  80.   hdr.rowlen = rowlen;
  81.   hdr.plnlen = hdr.rowlen * rows;
  82.   hdr.clrlen = 0;
  83.   hdr.aspect = aspect;
  84.   strcpy (hdr.title, title);
  85.   strcpy (hdr.credits, credits);
  86.   
  87.   write_hdr_fbm (&hdr, stdout);
  88.   
  89.   len = planes*cols; 
  90.   buf = (unsigned char *) malloc (rows*len);
  91.  
  92.   for (j=0; j<rows; j++){
  93.     line = getchar();
  94.     line |= (getchar()<<8);
  95.     if (! fread (&buf[j*len], len, 1, stdin))
  96.       { fprintf (stderr, "premature end of file on input at line %d\n", line);
  97.         break;
  98.       }
  99.     }
  100.  
  101.   for(k=0; k<planes; k++){
  102.     for (j=0; j<rows; j++){
  103.       if (! fwrite (&buf[j*len+k*cols], rowlen, 1, stdout))
  104.         { perror ("qrt2fbm"); exit (1); }
  105.       }
  106.     }
  107.   
  108.   exit (0);
  109. }
  110.