home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Basic / MAXONB32.DMS / in.adf / Includes.lha / BH / BLib / BitMapSupport.bas next >
Encoding:
BASIC Source File  |  1994-04-29  |  1.8 KB  |  71 lines

  1.  
  2.  
  3. '' Routines to Allocate & Free BitMaps that can be used safely under
  4. '' all versions of the operating system.
  5. ''
  6. ''    (c) Copyright HiSoft 1994
  7.  
  8.  
  9. 'Pre-V39 raster size computation
  10. FUNCTION RASSIZE&(BYVAL w, BYVAL h)
  11.     RASSIZE& = CLNG(h) * ((CLNG(w) + 15) >> 3 AND &h0000FFFE&)
  12. END FUNCTION
  13.  
  14. '
  15. 'Free a BitMap allocated via SafeAllocBitMap
  16. '
  17. SUB SafeFreeBitMap(BYVAL bm&)
  18.     STATIC i, sizex, sizey, depth, pp&
  19.  
  20.     IF bm& <> NULL& THEN
  21.         WaitBlit    ' make sure no blitter op can be happening in our bitplanes
  22.         IF PEEKW(LIBRARY("graphics.library") + lib_Version) >= 39 THEN
  23.             FreeBitMap bm&
  24.         ELSE
  25.             sizex = 8 * PEEKW(bm& + BytesPerRow)
  26.             sizey = PEEKW(bm& + Rows)
  27.             depth = PEEKB(bm& + BitMapDepth)
  28.             FOR i = 0 TO depth - 1
  29.                 pp& = PEEKL(bm& + Planes + i * 4)
  30.                 IF pp& <> NULL& THEN
  31.                     FreeRaster pp&, sizex, sizey
  32.                 END IF
  33.             NEXT i
  34.             FreeMem bm&, BitMap_sizeof
  35.         END IF
  36.     END IF
  37. END SUB
  38.  
  39. '
  40. 'Allocate a BitMap in a >V39 friendly manner, with fallbacks for pre-V39
  41. '
  42. FUNCTION SafeAllocBitMap&(BYVAL sizex, BYVAL sizey, BYVAL depth, _
  43.   BYVAL flags&, BYVAL friend&)
  44.     STATIC bm&, i, pp&, plsize&
  45.  
  46.     IF PEEKW(LIBRARY("graphics.library") + lib_Version) >= 39 THEN
  47.         SafeAllocBitmap& = AllocBitMap&(sizex, sizey, depth, flags&, friend&)
  48.     ELSE
  49.         bm& = AllocMem&(BitMap_sizeof, MEMF_PUBLIC& OR MEMF_CLEAR&)
  50.         IF bm& <> NULL& THEN
  51.             InitBitMap bm&, depth, sizex, sizey
  52.             plsize& = RASSIZE&(sizex, sizey)
  53.             DO WHILE i < depth
  54.                 pp& = AllocRaster&(sizex, sizey)
  55.                 IF pp& = NULL& THEN
  56.                     SafeFreeBitMap bm&
  57.                     bm& = NULL&
  58.                     EXIT DO
  59.                 ELSEIF flags& AND BMF_CLEAR& THEN
  60.                     BltClear pp&, plsize&, 0
  61.                 END IF
  62.                 POKEL bm& + Planes + i * 4, pp&
  63.                 i = i + 1
  64.             LOOP
  65.         END IF
  66.         SafeAllocBitmap& = bm&
  67.         WaitBlit    ' make sure the blitter is done clearing our bitplanes
  68.     END IF
  69. END FUNCTION
  70.  
  71.