Workaround for includes conflict that stopped compilation with GCC 3.
[tangerine.git] / rom / graphics / attachpalextra.c
blobd3e7ac5be328a030ed72e4c738c0cfceb9908284
1 /*
2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Graphics function AttachPalExtra()
6 Lang: english
7 */
9 #include <proto/exec.h>
10 #include <graphics/view.h>
11 #include "graphics_intern.h"
13 /*****************************************************************************
15 NAME */
16 #include <proto/graphics.h>
18 AROS_LH2(LONG, AttachPalExtra,
20 /* SYNOPSIS */
21 AROS_LHA(struct ColorMap *, cm, A0),
22 AROS_LHA(struct ViewPort *, vp, A1),
24 /* LOCATION */
25 struct GfxBase *, GfxBase, 139, Graphics)
27 /* FUNCTION
28 Allocates a PalExtra structure and attaches it to the
29 given ColorMap. This function must be called prior to palette
30 sharing. The PalExtra structure will be freed by FreeColorMap().
32 INPUTS
33 cm - Pointer to a color map structure
34 vp - Pointer to the viewport associated with the ColorMap
36 RESULT
37 0 - success
38 1 - out of memory
40 NOTES
42 EXAMPLE
44 BUGS
46 SEE ALSO
48 INTERNALS
50 HISTORY
52 *****************************************************************************/
54 AROS_LIBFUNC_INIT
56 struct PaletteExtra * pe;
58 if (NULL != cm->PalExtra)
59 return 0;
61 pe = AllocMem(sizeof(struct PaletteExtra), MEMF_CLEAR|MEMF_PUBLIC);
62 if (NULL != pe)
64 /*
65 ** if you change the number of byte allocated here then you
66 ** must also make chnages to FreeColorMap()!
68 pe->pe_RefCnt = AllocMem(cm->Count * sizeof(PalExtra_RefCnt_Type), MEMF_CLEAR);
69 pe->pe_AllocList = AllocMem(cm->Count * sizeof(PalExtra_AllocList_Type), MEMF_ANY);
71 if (NULL != pe->pe_RefCnt && NULL != pe->pe_AllocList)
73 UWORD sharablecolors, bmdepth;
75 sharablecolors = cm->Count;
77 /* cm->Count may contain more entries than 2 ^ bitmapdepth,
78 for pointer sprite colors, etc. Sharablecolors OTOH is
79 limited to 2 ^ bitmapdepth */
81 bmdepth = GetBitMapAttr(vp->RasInfo->BitMap, BMA_DEPTH);
82 if (bmdepth < 8)
84 if ((1L << bmdepth) < sharablecolors)
86 sharablecolors = 1L << bmdepth;
90 /* initialize the AllocList BYTE-array */
91 ULONG i = 0;
93 /* CHECKME: Should probably say "i < sharablecolors", but might
94 not actually cause anything bad either, even if it doesn't. */
95 while (i < cm->Count)
97 PALEXTRA_ALLOCLIST(pe, i) = (PalExtra_AllocList_Type)i-1;
98 i++;
101 /* connect the PaletteExtra structure to the ColorMap */
102 cm ->PalExtra = pe;
104 /* initialize the Palette Extra structure */
105 InitSemaphore(&pe->pe_Semaphore);
106 pe->pe_ViewPort = vp;
108 pe->pe_FirstFree = sharablecolors-1;
109 pe->pe_NFree = sharablecolors;
110 pe->pe_FirstShared = (UWORD)-1;
111 pe->pe_NShared = 0;
113 /* set all entries in the color table to be shareable
114 pe_SharableColors is not the number of colors but the last color index! */
116 pe->pe_SharableColors = sharablecolors;
118 } /* if (NULL != pe->pe_RefCnt && NULL != pe->pe_AllocList) */
119 else
121 /* some memory allocation failed */
122 if (pe->pe_RefCnt)
123 FreeMem(pe->pe_RefCnt, cm->Count * sizeof(PalExtra_RefCnt_Type));
124 if (pe->pe_AllocList)
125 FreeMem(pe->pe_AllocList, cm->Count* sizeof(PalExtra_AllocList_Type));
126 FreeMem(pe, sizeof(struct PaletteExtra));
127 return 1;
130 } /* if (NULL != pe) */
131 else
132 return 1;
134 return 0;
136 AROS_LIBFUNC_EXIT
138 } /* AttachPalExtra */