Minor fixes to comments.
[AROS.git] / rom / graphics / freebitmap.c
blobeafea890c2a27569c64ffceeee4880dbe0b0533c
1 /*
2 Copyright © 1995-2010, 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 (bm->pad != 0 || (bm->Flags & BMF_SPECIALFMT))
62 OOP_Object *bmobj = HIDD_BM_OBJ(bm);
64 if (HIDD_BM_FLAGS(bm) & HIDD_BMF_SHARED_PIXTAB)
66 /* NULL colormap otherwise bitmap killing also kills
67 the colormap object of the bitmap object
68 from which we shared it = to which it belongs */
69 if (bmobj)
70 HIDD_BM_SetColorMap(bmobj, NULL);
72 else if (HIDD_BM_FLAGS(bm) & HIDD_BMF_SCREEN_BITMAP) // (bm->Flags & BMF_DISPLAYABLE)
74 FreeVec(HIDD_BM_PIXTAB(bm));
77 if (bmobj)
78 HIDD_Gfx_DisposeBitMap(HIDD_BM_DRVDATA(bm)->gfxhidd, bmobj);
80 FreeMem(bm, sizeof (struct BitMap));
82 else
84 ULONG plane;
85 ULONG width;
87 width = bm->BytesPerRow * 8;
89 for (plane=0; plane < bm->Depth; plane ++)
91 /* Take care of two special cases: plane pointers containing NULL or -1
92 * are supported by BltBitMap() as all 0's and all 1's planes
94 if (bm->Planes[plane] && bm->Planes[plane] != (PLANEPTR)-1)
96 ASSERT_VALID_PTR(bm->Planes[plane]);
97 FreeRaster (bm->Planes[plane], width, bm->Rows);
101 FreeMem (bm, sizeof(struct BitMap) +
102 ((bm->Depth > 8) ? (bm->Depth - 8) * sizeof(PLANEPTR) : 0));
105 AROS_LIBFUNC_EXIT
106 } /* FreeBitMap */