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

  1. /*****************************************************************
  2.  * uunet2fbm.c: FBM Release 1.0 25-Feb-90 Michael Mauldin
  3.  *
  4.  * uunet2fbm.c: convert a bitmap to Targa format
  5.  *
  6.  * USAGE
  7.  *      % uunet2fbm [ image ] > image.fbm
  8.  *
  9.  * EDITLOG
  10.  *    LastEditDate = Mon Jun 25 00:09:49 1990 - Michael Mauldin
  11.  *    LastFileName = /usr2/mlm/src/misc/fbm/flgifc.c
  12.  *
  13.  * HISTORY
  14.  * 25-Jun-90  Michael Mauldin (mlm@cs.cmu.edu) Carnegie Mellon
  15.  *    Package for Release 1.0
  16.  *
  17.  * 16-Aug-89  Anders (klemets@sics.se)
  18.  *    Bug fix (width not mult of 8) by 
  19.  *
  20.  * 05-Jul-89 Dan Sahlin (dan@sics.se) at SICS
  21.  *    Created from a copy of pic2fbm
  22.  *****************************************************************/
  23.  
  24. # include <stdio.h>
  25. # include "fbm.h"
  26.  
  27. #ifndef lint
  28. static char *fbmid =
  29. "$FBM fluun.c <1.0> written by Dan Sahlin, source code available \
  30. free from MLM@CS.CMU.EDU and from UUNET archives$";
  31. #endif
  32.  
  33. /*
  34.  * read_uunet(image, rfile, mstr, mlen)
  35.  */
  36.  
  37. #define FROMHEX(x) ((x>='a')?(x-'a'+10):((x>='A')?(x-'A'+10):(x-'0')))
  38.  
  39. read_uunet(image, rfile, mstr, mlen)
  40. FBM *image;
  41. FILE *rfile;
  42. char *mstr;
  43. int mlen;
  44. {
  45. unsigned int        Width, Height, Bits;
  46. unsigned int        Imwidth, Imheight, Imbits;
  47. int            i,j;
  48. unsigned char           *Red;
  49. int                     ch,ch2;
  50. char            buf[80],credits[80],title[160];
  51.  
  52.  
  53.     /* parse the header lines */
  54.     buf[0] = credits[0] = title[0] = '\0';
  55.     do {
  56.         fgets(buf, 80, rfile);
  57.         if (!strncmp("PicData:", buf, 8))
  58.             sscanf(&buf[8],"%d%d%d", &Width, &Height, &Bits);
  59.         if (!strncmp("Image:", buf, 6))
  60.             sscanf(&buf[6], "%d%d%d", &Imwidth, &Imheight, &Imbits);
  61.         if (!strncmp("FirstName:", buf, 10)) {
  62.             sscanf(&buf[10],"%s", title);
  63.             strcat(title," ");
  64.         }
  65.         if (!strncmp("LastName:", buf, 9))
  66.             sscanf(&buf[9],"%s", &title[strlen(title)]);
  67.         if (!strncmp("E-Mail:", buf, 7))
  68.             sscanf(&buf[7],"%s", credits);
  69.         
  70.     } while(strlen(buf) && buf[0] != '\n');
  71.  
  72. /* Create output image header */
  73.     image->hdr.rows = Height;
  74.     image->hdr.cols = Width;
  75.     /* If this is odd number of bytes, add one */
  76.     if ((image->hdr.cols & 1) != 0) image->hdr.cols++;
  77.     image->hdr.planes = 1;
  78.     image->hdr.bits = Bits;
  79.     image->hdr.physbits = Bits;
  80.     image->hdr.rowlen = image->hdr.cols;
  81.     image->hdr.plnlen = (image->hdr.rows/8+1)*8 * image->hdr.cols;
  82.     image->hdr.clrlen = 0;
  83.     image->hdr.aspect = Width / Imwidth;
  84.     strcpy(image->hdr.title,title);
  85.     strcpy(image->hdr.credits,credits);
  86.  
  87. /* Get the Image */
  88.     alloc_fbm(image);
  89.  
  90.     Red = image->bm;
  91.     for (i=Height-1; i>=0; i--)
  92.     {
  93.         for (j=0; j< Width; j++)
  94.         {
  95.             while((ch = getc(rfile))=='\n')
  96.                 ;
  97.             ch2 = getc(rfile);
  98.             *(Red+j+Width*i) = (FROMHEX(ch)*16)+FROMHEX(ch2);
  99.         }
  100.     }
  101.     return 1;
  102. }
  103.