home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 4 / CDPD_IV.bin / networking / dnet / dnet2.3.2 / amiga / suplib / bitmap.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-29  |  1.6 KB  |  99 lines

  1.  
  2. /*
  3.  *  BITMAP.C
  4.  */
  5.  
  6. #include <local/typedefs.h>
  7.  
  8. extern struct GfxBase *GfxBase;
  9.  
  10. int
  11. MakeRastPortBitMap(rp, bm, depth, width, height, tmprassize, numai)
  12. RP *rp;
  13. BM *bm;
  14. short depth, width, height, numai;
  15. long tmprassize;
  16. {
  17.     if (MakeBitMap(bm, depth, width, height, MEMF_PUBLIC|MEMF_CHIP|MEMF_CLEAR)) {
  18.     if (MakeRastPort(rp, bm, tmprassize, numai))
  19.         return(1);
  20.     FreeBitMap(bm);
  21.     }
  22.     return(0);
  23. }
  24.  
  25. void
  26. FreeRastPortBitMap(rp)
  27. RP *rp;
  28. {
  29.     if (rp) {
  30.     BM *bm = rp->BitMap;
  31.     FreeRastPort(rp);
  32.     if (bm)
  33.         FreeBitMap(bm);
  34.     }
  35. }
  36.  
  37. int
  38. MakeBitMap(bm, depth, width, height, memflags)
  39. register BM *bm;
  40. short depth;
  41. short width;
  42. short height;
  43. ulong memflags;
  44. {
  45.     register short i;
  46.     register ulong rassize;
  47.     register PLANEPTR *ptr;
  48.  
  49.     if (!bm)
  50.     return(0);
  51.     if (!GfxBase)
  52.     OpenGfxLibrary();
  53.     InitBitMap(bm, depth, width, height);
  54.     rassize = bm->Rows * bm->BytesPerRow;
  55.     for (i = 0, ptr = bm->Planes; i < bm->Depth; ++i, ++ptr) {
  56.     if ((*ptr = AllocMem(rassize, memflags)) == NULL)
  57.         break;
  58.     }
  59.     if (i != bm->Depth) {
  60.     while (--i >= 0) {
  61.         --ptr;
  62.         FreeMem(*ptr, rassize);
  63.         *ptr = NULL;
  64.     }
  65.     return(0);
  66.     }
  67.     return(1);
  68. }
  69.  
  70. void
  71. FreeBitMap(bm)
  72. register BM *bm;
  73. {
  74.     PLANEPTR lastptr = NULL;
  75.  
  76.     WaitBlit();
  77.     if (bm) {
  78.     register short i;
  79.     register PLANEPTR *ptr;
  80.     register ulong rassize = bm->Rows * bm->BytesPerRow;
  81.  
  82.     for (i = 0, ptr = bm->Planes; i < bm->Depth; ++i, ++ptr) {
  83.         if (*ptr && *ptr != lastptr) {
  84.         lastptr = *ptr;
  85.         FreeMem(*ptr, rassize);
  86.         *ptr = NULL;
  87.         }
  88.         *ptr = NULL;
  89.     }
  90.     }
  91. }
  92.  
  93. void
  94. OpenGfxLibrary()
  95. {
  96.     GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0);
  97. }
  98.  
  99.