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

  1. /*****************************************************************
  2.  * flwrfb.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.  * flwrfb.c: 
  11.  *
  12.  * CONTENTS
  13.  *    write_fbm (image, wfile)
  14.  *    write_hdr_fbm (image, wfile)
  15.  *
  16.  * EDITLOG
  17.  *    LastEditDate = Mon Jun 25 00:18:12 1990 - Michael Mauldin
  18.  *    LastFileName = /usr2/mlm/src/misc/fbm/flwrfb.c
  19.  *
  20.  * HISTORY
  21.  * 25-Jun-90  Michael Mauldin (mlm@cs.cmu.edu) Carnegie Mellon
  22.  *    Package for Release 1.0
  23.  *
  24.  * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  25.  *    Beta release (version 0.9) mlm@cs.cmu.edu
  26.  *
  27.  * 12-Nov-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  28.  *    Created.
  29.  *****************************************************************/
  30.  
  31. # include <stdio.h>
  32. # include <math.h>
  33. # include <ctype.h>
  34. # include "fbm.h"
  35.  
  36. /****************************************************************
  37.  * write_fbm: Write an image to a stream
  38.  ****************************************************************/
  39.  
  40. #ifndef lint
  41. static char *fbmid =
  42. "$FBM flwrfb.c <1.0> 25-Jun-90  (C) 1989,1990 by Michael Mauldin, source \
  43. code available free from MLM@CS.CMU.EDU and from UUNET archives$";
  44. #endif
  45.  
  46. write_fbm (image, wfile)
  47. register FBM *image;
  48. register FILE *wfile;
  49. { register int k, j, rowlen, plnlen;
  50.   register unsigned char *bmptr;
  51.  
  52.   if (! write_hdr_fbm (image, wfile)) return (0);
  53.  
  54.   rowlen = image->hdr.rowlen;
  55.   plnlen = image->hdr.plnlen;
  56.   
  57.   if (image->hdr.clrlen > 0)
  58.   { if (!fwrite (image->cm, image->hdr.clrlen, 1, wfile))
  59.     { perror ("write_fbm (colormap)"); return (0); }
  60.   }
  61.  
  62.   for (k=0; k<image->hdr.planes; k++)
  63.   { bmptr = &(image->bm[k*plnlen]);
  64.     
  65.     for (j=0; j<image->hdr.rows; j++, bmptr += rowlen)
  66.     { if (! fwrite (bmptr, 1, rowlen, wfile))
  67.       { perror ("write_fbm"); return (0); }
  68.     }
  69.   }
  70.     
  71.   return (1);
  72. }
  73.  
  74. /****************************************************************
  75.  * write_hdr_fbm: Write an image header to a stream
  76.  ****************************************************************/
  77.  
  78. write_hdr_fbm (image, wfile)
  79. register FBM *image;
  80. register FILE *wfile;
  81. { FBMFILEHDR file_hdr;
  82.  
  83.   strncpy (file_hdr.magic, FBM_MAGIC, 8);
  84.   sprintf (file_hdr.cols, "%7d", image->hdr.cols);
  85.   sprintf (file_hdr.rows, "%7d", image->hdr.rows);
  86.   sprintf (file_hdr.planes, "%7d", image->hdr.planes);
  87.   sprintf (file_hdr.bits, "%7d", image->hdr.bits);
  88.   sprintf (file_hdr.physbits, "%7d", image->hdr.physbits);
  89.   sprintf (file_hdr.rowlen, "%11d", image->hdr.rowlen);
  90.   sprintf (file_hdr.plnlen, "%11d", image->hdr.plnlen);
  91.   sprintf (file_hdr.clrlen, "%11d", image->hdr.clrlen);
  92.   sprintf (file_hdr.aspect, "%11.6lf", image->hdr.aspect);
  93.   strncpy (file_hdr.title, image->hdr.title, FBM_MAX_TITLE);
  94.   strncpy (file_hdr.credits, image->hdr.credits, FBM_MAX_TITLE);
  95.  
  96.   if (! fwrite (&file_hdr, sizeof (file_hdr), 1, wfile))
  97.   { perror ("write_fbm (header)"); return (0); }
  98.     
  99.   return (1);
  100. }
  101.