#include "pz.h" /* Various bitmap/blitter routines for IFF2PCS ** Ali Ozer, Nov 1987 ** Fixed memory lossage problem with half-allocated bitmaps Dec '87 */ /* InitBM will try to allocate d (depth) bitplanes of w x h bits each. It'll ** actually round w upto a multiple of 8 bits. If unsuccessful, InitBM will ** return false and set bm->Depth to the actual number of bit planes allocated. ** If successful, bm->Depth will be set to d and InitBM will return true. ** To deallocate the bitmap correctly, simply call FreeBM. */ int InitBM (bm, h, w, d) struct BitMap *bm; int h, w, d; /* Height, width, depth, in bits, bits, and bitplanes */ { int cnt; w = ((w+7) >> 3) << 3; /* We allocate upto 7 extra bits... */ bm->BytesPerRow = w >> 3; /* In bytes */ bm->Rows = h; bm->Depth = d; for (cnt = 0; cnt < d; cnt++) if ((bm->Planes[cnt] = (PLANEPTR) AllocRaster((long)w, (long)h)) == NULL) { bm->Depth = cnt; return (false); } return (true); } void FreeBM (bm) struct BitMap *bm; { int cnt; long w = (bm->BytesPerRow) << 3; long h = (bm->Rows); for (cnt = 0; cnt < bm->Depth; cnt++) if (bm->Planes[cnt] != NULL) FreeRaster (bm->Planes[cnt], w, h); } CopyFromBMToBM (srcbm, srcx, srcy, destbm, destx, desty, sizex, sizey) struct BitMap *srcbm, *destbm; int srcx, srcy, destx, desty, sizex, sizey; { /* The "c0" indicates copy; the "ff" indicates include all planes */ BltBitMap (srcbm, (long)srcx, (long)srcy, destbm, (long)destx, (long)desty, (long)sizex, (long)sizey, 0x00c0L, 0x00ffL, NULL); } XORFromBMToBM (srcbm, srcx, srcy, destbm, destx, desty, sizex, sizey) struct BitMap *srcbm, *destbm; int srcx, srcy, destx, desty, sizex, sizey; { BltBitMap (srcbm, (long)srcx, (long)srcy, destbm, (long)destx, (long)desty, (long)sizex, (long)sizey, 0x0060L, 0x00ffL, NULL); }