show more relevant debug
[AROS.git] / rom / graphics / freebitmap.c
blob5183a6f9f1d0a17cbe1c3798e6e8e1f432f6071e
1 /*
2 Copyright © 1995-2015, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Free the memory occupied by a BitMap.
6 Lang: english
7 */
9 #include <aros/debug.h>
10 #include <exec/memory.h>
11 #include <proto/exec.h>
13 #include "graphics_intern.h"
14 #include "gfxfuncsupport.h"
16 /*****************************************************************************
18 NAME */
19 #include <graphics/gfx.h>
20 #include <proto/graphics.h>
22 AROS_LH1(void, FreeBitMap,
24 /* SYNOPSIS */
25 AROS_LHA(struct BitMap *, bm, A0),
27 /* LOCATION */
28 struct GfxBase *, GfxBase, 154, Graphics)
30 /* FUNCTION
31 Returns the memory occupied by the BitMap to the system.
33 INPUTS
34 bm - The result of AllocBitMap(). Must be non-NULL.
36 RESULT
37 None.
39 NOTES
41 EXAMPLE
43 BUGS
45 SEE ALSO
46 AllocBitMap(), AllocRaster(), FreeRaster()
48 INTERNALS
50 HISTORY
52 *****************************************************************************/
54 AROS_LIBFUNC_INIT
56 if (!bm) return;
58 ASSERT_VALID_PTR(bm);
60 if (IS_HIDD_BM(bm))
62 OOP_Object *bmobj = HIDD_BM_OBJ(bm);
64 D(bug("%s: Free HIDD bitmap %p (obj %p)\n", __func__, bm, bmobj));
66 if (HIDD_BM_FLAGS(bm) & HIDD_BMF_SHARED_PIXTAB)
68 /* NULL colormap otherwise bitmap killing also kills
69 the colormap object of the bitmap object
70 from which we shared it = to which it belongs */
71 if (bmobj)
72 HIDD_BM_SetColorMap(bmobj, NULL);
74 else if (HIDD_BM_FLAGS(bm) & HIDD_BMF_SCREEN_BITMAP) // (bm->Flags & BMF_DISPLAYABLE)
76 FreeVec(HIDD_BM_PIXTAB(bm));
79 if (bmobj)
80 OOP_DisposeObject(bmobj);
82 FreeMem(bm, sizeof (struct BitMap) + sizeof(PLANEPTR) * HIDD_BM_EXTRAPLANES);
84 else
86 ULONG plane;
87 ULONG width;
89 D(bug("%s: Free plain bitmap %p\n", __func__, bm));
91 width = bm->BytesPerRow * 8;
93 for (plane=0; plane < bm->Depth; plane ++)
95 /* Take care of two special cases: plane pointers containing NULL or -1
96 * are supported by BltBitMap() as all 0's and all 1's planes
98 if (bm->Planes[plane] && bm->Planes[plane] != (PLANEPTR)-1)
100 ASSERT_VALID_PTR(bm->Planes[plane]);
101 FreeRaster (bm->Planes[plane], width, bm->Rows);
105 FreeMem (bm, sizeof(struct BitMap) +
106 ((bm->Depth > 8) ? (bm->Depth - 8) * sizeof(PLANEPTR) : 0));
109 AROS_LIBFUNC_EXIT
110 } /* FreeBitMap */