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

  1. /*
  2.  *  FILE: bitplane.c
  3.  *  Support routines for dynamic (de)allocation of bitplanes for bitmaps
  4.  *  and/or image data.
  5.  *
  6.  *  Public Domain, but keep my name in it as the original author.
  7.  *  31-Aug-88    Jan Sven Trabandt   first release version
  8.  */
  9.  
  10.  
  11. #define I_AM_BITPLANE
  12. #include "gimmelib/gimmefuncs.h"
  13. #include "gimmelib/bitplane.h"
  14.  
  15.  
  16. ULONG gimmeBitPlanes( bm, myflags )
  17.     struct BitMap   *bm;
  18.     ULONG        myflags;
  19. {
  20.     SHORT   i;
  21.     SHORT   width, height, depth;
  22.     ULONG   planesize;
  23.  
  24. #ifdef GIMME_WIMPY
  25.     if( !bm ) {
  26.     return( GBP_ERROR );
  27.     }
  28. #endif
  29.     width = bm->BytesPerRow << 3;
  30.     height = bm->Rows;
  31.     depth = bm->Depth;
  32.     planesize = RASSIZE((ULONG)width, (ULONG)height);
  33.     bm->Planes[0] = NULL;
  34.     if( myflags & GBP_CONTIGUOUS ) {
  35.     if( bm->Planes[0] = AllocMem( (ULONG)(depth) * planesize,
  36.                     MEMF_CHIP | MEMF_CLEAR) ) {
  37.         for( i = 1; i < depth; ++i ) {
  38.         bm->Planes[i] = (UBYTE *)(bm->Planes[i-1]) + planesize;
  39.         } /* for */
  40.         return( GBP_CONTIGUOUS );
  41.     }
  42.     }
  43.     if( (myflags & GBP_SEPARATE) || !myflags ) {
  44.     for( i = 0; i < depth; ++i ) {
  45.         if( !(bm->Planes[i] = (PLANEPTR)
  46.                     AllocRaster((ULONG)width,(ULONG)height)) ) {
  47.         while( --i >= 0 ) {
  48.             FreeRaster( bm->Planes[i], (ULONG) bm->BytesPerRow << 3,
  49.                     (ULONG) bm->Rows );
  50.         } /* while */
  51.         return( GBP_ERROR );
  52.         }
  53.         BltClear( bm->Planes[i], planesize, 0L );
  54.     } /* for */
  55.     return( GBP_SEPARATE );
  56.     }
  57.     return( GBP_ERROR );
  58. } /* gimmeBitPlanes */
  59.  
  60.  
  61. short getRidOfBitPlanes( bm, myflags )
  62.     struct BitMap   *bm;
  63.     ULONG        myflags;
  64. {
  65.     SHORT   i;
  66.     SHORT   width, height, depth;
  67.  
  68. #ifdef GIMME_WIMPY
  69.     if( !bm ) {
  70.     return( -1 );
  71.     }
  72. #endif
  73.     width = bm->BytesPerRow << 3;
  74.     height = bm->Rows;
  75.     depth = bm->Depth;
  76.     if( myflags & GBP_CONTIGUOUS ) {
  77.     FreeMem( bm->Planes[0],
  78.             (ULONG)(depth) * RASSIZE((ULONG)width,(ULONG)height) );
  79.     } else {
  80.     for( i = 0; i < depth && bm->Planes[i]; ++i ) {
  81.         FreeRaster( bm->Planes[i], (ULONG) width, (ULONG) height );
  82.     } /* for */
  83.     }
  84.     return( 0 );
  85. } /* getRidOfBitPlanes */
  86.