home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 199.lha / GimmeLib / bitmap.c next >
C/C++ Source or Header  |  1988-12-27  |  1KB  |  59 lines

  1. /*
  2.  *  FILE: bitmap.c
  3.  *  Support routines for dynamic (de)allocation of bitmaps.
  4.  *
  5.  *  Public Domain, but keep my name in it as the original author.
  6.  *  31-Aug-88    Jan Sven Trabandt   first release version
  7.  */
  8.  
  9.  
  10. #include "gimmelib/gimmefuncs.h"
  11.  
  12.  
  13. struct BitMap *gimmeBitMap( depth, width, height )
  14.     SHORT   depth, width, height;
  15. {
  16.     register struct BitMap  *bm;
  17.     SHORT            i;
  18.  
  19.     bm = (struct BitMap *) AllocMem( (ULONG)sizeof(struct BitMap),
  20.                     MEMF_PUBLIC | MEMF_CLEAR );
  21.     if( !bm ) {
  22.     return( NULL );
  23.     }
  24.     if( depth > 0 && width > 0 && height > 0 ) {
  25.     InitBitMap( bm, (ULONG) depth, (ULONG) width, (ULONG) height );
  26.     for( i = 0; i < depth; ++i ) {
  27.         if( !(bm->Planes[i] = (PLANEPTR)
  28.                     AllocRaster((ULONG)width,(ULONG)height)) ) {
  29.         bm->Depth = i;
  30.         getRidOfBitMap( bm );
  31.         return( NULL );
  32.         }
  33.         BltClear( bm->Planes[i],
  34.             (ULONG)RASSIZE((ULONG)width,(ULONG)height), 0L );
  35.     } /* for */
  36.     }
  37.     return( bm );
  38. } /* gimmeBitMap */
  39.  
  40.  
  41. short getRidOfBitMap( bitmap )
  42.     register struct BitMap  *bitmap;
  43. {
  44.     SHORT   i;
  45.     SHORT   width;
  46.  
  47. #ifdef GIMME_WIMPY
  48.     if( !bitmap ) {
  49.     return( -1 );
  50.     }
  51. #endif
  52.     width = bitmap->BytesPerRow << 3;
  53.     for( i = 0; i < bitmap->Depth && bitmap->Planes[i]; ++i ) {
  54.     FreeRaster( bitmap->Planes[i], (ULONG) width, (ULONG) bitmap->Rows );
  55.     } /* for */
  56.     FreeMem( bitmap, (ULONG)sizeof(struct BitMap) );
  57.     return( 0 );
  58. } /* getRidOfBitMap */
  59.