r4493@vps: verhaegs | 2007-04-19 14:44:00 -0400
[AROS.git] / rom / graphics / freebitmap.c
blob6c8a4a251012f47aa1fa684a0c208001a2aa12ad
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Free the memory occupied by a BitMap.
6 Lang: english
7 */
8 #include <aros/debug.h>
9 #include <exec/memory.h>
10 #include <proto/exec.h>
11 #include "graphics_intern.h"
12 #include "gfxfuncsupport.h"
14 /*****************************************************************************
16 NAME */
17 #include <graphics/gfx.h>
18 #include <proto/graphics.h>
20 AROS_LH1(void, FreeBitMap,
22 /* SYNOPSIS */
23 AROS_LHA(struct BitMap *, bm, A0),
25 /* LOCATION */
26 struct GfxBase *, GfxBase, 154, Graphics)
28 /* FUNCTION
29 Returns the memory occupied by the BitMap to the system.
31 INPUTS
32 bm - The result of AllocBitMap(). Must be non-NULL.
34 RESULT
35 None.
37 NOTES
39 EXAMPLE
41 BUGS
43 SEE ALSO
44 AllocBitMap(), AllocRaster(), FreeRaster()
46 INTERNALS
48 HISTORY
50 *****************************************************************************/
52 AROS_LIBFUNC_INIT
53 AROS_LIBBASE_EXT_DECL(struct GfxBase *,GfxBase)
55 if (!bm) return;
57 ASSERT_VALID_PTR(bm);
59 if (bm->pad != 0 || (bm->Flags & BMF_AROS_HIDD))
61 if (HIDD_BM_FLAGS(bm) & HIDD_BMF_SHARED_PIXTAB)
63 /* NULL colormap otherwise bitmap killing also kills
64 the colormap object of the bitmap object
65 from which we shared it = to which it belongs */
67 HIDD_BM_SetColorMap(HIDD_BM_OBJ(bm), NULL);
69 else if (HIDD_BM_FLAGS(bm) & HIDD_BMF_SCREEN_BITMAP) // (bm->Flags & BMF_DISPLAYABLE)
71 FreeVec(HIDD_BM_PIXTAB(bm));
74 HIDD_Gfx_DisposeBitMap(SDD(GfxBase)->gfxhidd, (OOP_Object *)HIDD_BM_OBJ(bm));
76 FreeMem(bm, sizeof (struct BitMap));
78 else
80 ULONG plane;
81 ULONG width;
83 width = bm->BytesPerRow * 8;
85 for (plane=0; plane < bm->Depth; plane ++)
87 /* Take care of two special cases: plane pointers containing NULL or -1
88 * are supported by BltBitMap() as all 0's and all 1's planes
90 if (bm->Planes[plane] && bm->Planes[plane] != (PLANEPTR)-1)
92 ASSERT_VALID_PTR(bm->Planes[plane]);
93 FreeRaster (bm->Planes[plane], width, bm->Rows);
97 FreeMem (bm, sizeof(struct BitMap) +
98 ((bm->Depth > 8) ? (bm->Depth - 8) * sizeof(PLANEPTR) : 0));
101 AROS_LIBFUNC_EXIT
102 } /* FreeBitMap */