home *** CD-ROM | disk | FTP | other *** search
- #include "bitmap.h"
- #include "screen.h"
-
- #include<exec/memory.h>
-
- #include<stdio.h>
-
- #include<clib/exec_protos.h>
- #include<clib/graphics_protos.h>
-
- /* Global handle for our bitmap */
- static struct BitMap* bitmap = NULL;
- /* Global record of requested depth, width and height */
- static int depth, width, height;
-
- /* Create a bitmap */
- int createBitmap()
- {
- struct Screen* scr = getScreen();
- /* The MEMF_CLEAR flag is vital, since it zeroes the allocated memory. */
- /* Thus the pointers in the bitmap will be NULL, if we don't manage to */
- /* allocate them properly. */
- if(bitmap = AllocMem(sizeof(struct BitMap), MEMF_PUBLIC | MEMF_CLEAR))
- {
- int plane;
- /* Our new BitMap has sizes based on the screen BitMap */
- depth = scr->BitMap.Depth;
- width = scr->Width;
- height = scr->Height;
- InitBitMap(bitmap, depth, width, height);
- for(plane = 0; plane < depth; plane++)
- {
- bitmap->Planes[plane] = AllocRaster(width, height);
- if(bitmap->Planes[plane] == NULL)
- {
- printf("Error: could not create planes for bitmap\n");
- return FALSE;
- }
- }
- /* If we get here, we succeeded. */
- return TRUE;
- }
- else
- printf("Error: could not create bitmap\n");
- return FALSE;
- }
-
- /* Free any allocated bitmap */
- void freeBitmap()
- {
- if(bitmap)
- {
- int plane;
- for(plane = 0; plane < depth; plane++)
- {
- if(bitmap->Planes[plane])
- FreeRaster(bitmap->Planes[plane], width, height);
- }
- FreeMem(bitmap, sizeof(struct BitMap));
- /* Set to NULL to indicate that it's been freed */
- bitmap = NULL;
- }
- }
-
- struct BitMap* getBitmap()
- {
- return bitmap;
- }
-