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

  1. /*****************************************************************
  2.  * flalfb.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.  * flalfb.c: Fuzzy bitmap allocation
  11.  *
  12.  * CONTENTS
  13.  *    alloc_fbm (image)
  14.  *    free_fbm (image)
  15.  *
  16.  * EDITLOG
  17.  *    LastEditDate = Mon Jun 25 00:04:43 1990 - Michael Mauldin
  18.  *    LastFileName = /usr2/mlm/src/misc/fbm/flalfb.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.  * alloc_fbm: Allocate enough bytes for the bitmap and colormap
  38.  *    of an image where the header has already been filled in.
  39.  ****************************************************************/
  40.  
  41. #ifndef lint
  42. static char *fbmid =
  43. "$FBM flalfb.c <1.0> 25-Jun-90  (C) 1989,1990 by Michael Mauldin, source \
  44. code available free from MLM@CS.CMU.EDU and from UUNET archives$";
  45. #endif
  46.  
  47. alloc_fbm (image)
  48. FBM *image;
  49. { unsigned bmsize, cmsize;
  50.  
  51.   if (! free_fbm (image)) return (0);
  52.  
  53.   /* Calculate bytes needed */
  54.   bmsize = (image->hdr.planes * image->hdr.plnlen);
  55.   cmsize = image->hdr.clrlen;
  56.   
  57.   if (! (image->bm = (unsigned char *) malloc (bmsize)) ||
  58.       (cmsize && ! (image->cm = (unsigned char *) malloc (cmsize))))
  59.   { perror ("alloc_fbm"); exit (1); }
  60.  
  61.   return (1);
  62. }
  63.  
  64. /****************************************************************
  65.  * free_fbm: Free the storage allocate by alloc_fbm
  66.  ****************************************************************/
  67.  
  68. free_fbm (image)
  69. FBM *image;
  70. {
  71.   if (image->bm)
  72.   { free ((char *) image->bm); image->bm = (unsigned char *) NULL; }
  73.  
  74.   if (image->cm)
  75.   { free ((char *) image->cm); image->cm = (unsigned char *) NULL; }
  76.  
  77.   return (1);
  78. }
  79.