home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume19 / fbm / part01 / flalfb.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-08  |  2.0 KB  |  73 lines

  1. /*****************************************************************
  2.  * flalfb.c: FBM Library 0.9 (Beta test) 07-Mar-89  Michael Mauldin
  3.  *
  4.  * Copyright (C) 1989 by Michael Mauldin.  Permission is granted to
  5.  * use this file in whole or in part provided that you do not sell it
  6.  * for profit and that this copyright notice is retained unchanged.
  7.  *
  8.  * flalfb.c: Fuzzy bitmap allocation
  9.  *
  10.  * CONTENTS
  11.  *    alloc_fbm (image)
  12.  *    free_fbm (image)
  13.  *
  14.  * EDITLOG
  15.  *    LastEditDate = Tue Mar  7 19:56:45 1989 - Michael Mauldin
  16.  *    LastFileName = /usr2/mlm/src/misc/fbm/flalfb.c
  17.  *
  18.  * HISTORY
  19.  * 07-Mar-89  Michael Mauldin (mlm) at Carnegie Mellon University
  20.  *    Beta release (version 0.9) mlm@cs.cmu.edu
  21.  *
  22.  * 12-Nov-88  Michael Mauldin (mlm) at Carnegie-Mellon University
  23.  *    Created.
  24.  *****************************************************************/
  25.  
  26. # include <stdio.h>
  27. # include <math.h>
  28. # include <ctype.h>
  29. # include "fbm.h"
  30.  
  31. /****************************************************************
  32.  * alloc_fbm: Allocate enough bytes for the bitmap and colormap
  33.  *    of an image where the header has already been filled in.
  34.  ****************************************************************/
  35.  
  36. #ifndef lint
  37. static char *fbmid =
  38.     "$FBM flalfb.c <0.9> 07-Mar-89  (C) 1989 by Michael Mauldin$";
  39. #endif
  40.  
  41. alloc_fbm (image)
  42. FBM *image;
  43. { unsigned bmsize, cmsize;
  44.  
  45.   if (! free_fbm (image)) return (0);
  46.  
  47.   /* Calculate bytes needed */
  48.   bmsize = (image->hdr.planes * image->hdr.plnlen);
  49.   cmsize = image->hdr.clrlen;
  50.   
  51.   if (! (image->bm = (unsigned char *) malloc (bmsize)) ||
  52.       (cmsize && ! (image->cm = (unsigned char *) malloc (cmsize))))
  53.   { perror ("alloc_fbm"); exit (1); }
  54.  
  55.   return (1);
  56. }
  57.  
  58. /****************************************************************
  59.  * free_fbm: Free the storage allocate by alloc_fbm
  60.  ****************************************************************/
  61.  
  62. free_fbm (image)
  63. FBM *image;
  64. {
  65.   if (image->bm)
  66.   { free ((char *) image->bm); image->bm = (unsigned char *) NULL; }
  67.  
  68.   if (image->cm)
  69.   { free ((char *) image->cm); image->cm = (unsigned char *) NULL; }
  70.  
  71.   return (1);
  72. }
  73.