home *** CD-ROM | disk | FTP | other *** search
-
-
- '' Routines to Allocate & Free BitMaps that can be used safely under
- '' all versions of the operating system.
- ''
- '' (c) Copyright HiSoft 1994
-
-
- 'Pre-V39 raster size computation
- FUNCTION RASSIZE&(BYVAL w, BYVAL h)
- RASSIZE& = CLNG(h) * ((CLNG(w) + 15) >> 3 AND &h0000FFFE&)
- END FUNCTION
-
- '
- 'Free a BitMap allocated via SafeAllocBitMap
- '
- SUB SafeFreeBitMap(BYVAL bm&)
- STATIC i, sizex, sizey, depth, pp&
-
- IF bm& <> NULL& THEN
- WaitBlit ' make sure no blitter op can be happening in our bitplanes
- IF PEEKW(LIBRARY("graphics.library") + lib_Version) >= 39 THEN
- FreeBitMap bm&
- ELSE
- sizex = 8 * PEEKW(bm& + BytesPerRow)
- sizey = PEEKW(bm& + Rows)
- depth = PEEKB(bm& + BitMapDepth)
- FOR i = 0 TO depth - 1
- pp& = PEEKL(bm& + Planes + i * 4)
- IF pp& <> NULL& THEN
- FreeRaster pp&, sizex, sizey
- END IF
- NEXT i
- FreeMem bm&, BitMap_sizeof
- END IF
- END IF
- END SUB
-
- '
- 'Allocate a BitMap in a >V39 friendly manner, with fallbacks for pre-V39
- '
- FUNCTION SafeAllocBitMap&(BYVAL sizex, BYVAL sizey, BYVAL depth, _
- BYVAL flags&, BYVAL friend&)
- STATIC bm&, i, pp&, plsize&
-
- IF PEEKW(LIBRARY("graphics.library") + lib_Version) >= 39 THEN
- SafeAllocBitmap& = AllocBitMap&(sizex, sizey, depth, flags&, friend&)
- ELSE
- bm& = AllocMem&(BitMap_sizeof, MEMF_PUBLIC& OR MEMF_CLEAR&)
- IF bm& <> NULL& THEN
- InitBitMap bm&, depth, sizex, sizey
- plsize& = RASSIZE&(sizex, sizey)
- DO WHILE i < depth
- pp& = AllocRaster&(sizex, sizey)
- IF pp& = NULL& THEN
- SafeFreeBitMap bm&
- bm& = NULL&
- EXIT DO
- ELSEIF flags& AND BMF_CLEAR& THEN
- BltClear pp&, plsize&, 0
- END IF
- POKEL bm& + Planes + i * 4, pp&
- i = i + 1
- LOOP
- END IF
- SafeAllocBitmap& = bm&
- WaitBlit ' make sure the blitter is done clearing our bitplanes
- END IF
- END FUNCTION
-
-