2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Graphics function AttachPalExtra()
9 #include <proto/exec.h>
10 #include <graphics/view.h>
11 #include "graphics_intern.h"
13 /*****************************************************************************
16 #include <proto/graphics.h>
18 AROS_LH2(LONG
, AttachPalExtra
,
21 AROS_LHA(struct ColorMap
*, cm
, A0
),
22 AROS_LHA(struct ViewPort
*, vp
, A1
),
25 struct GfxBase
*, GfxBase
, 139, Graphics
)
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 bt FreeColorMap().
33 cm - Pointer to a color map structure
34 vp - Pointer to the viewport associated with the ColorMap
52 *****************************************************************************/
55 AROS_LIBBASE_EXT_DECL(struct GfxBase
*,GfxBase
)
57 struct PaletteExtra
* pe
;
59 if (NULL
!= cm
->PalExtra
)
62 pe
= AllocMem(sizeof(struct PaletteExtra
), MEMF_CLEAR
|MEMF_PUBLIC
);
66 ** if you change the number of byte allocated here then you
67 ** must also make chnages to FreeColorMap()!
69 pe
->pe_RefCnt
= AllocMem(cm
->Count
* sizeof(PalExtra_RefCnt_Type
), MEMF_CLEAR
);
70 pe
->pe_AllocList
= AllocMem(cm
->Count
* sizeof(PalExtra_AllocList_Type
), MEMF_ANY
);
72 if (NULL
!= pe
->pe_RefCnt
&& NULL
!= pe
->pe_AllocList
)
74 UWORD sharablecolors
, bmdepth
;
76 sharablecolors
= cm
->Count
;
78 /* cm->Count may contain more entries than 2 ^ bitmapdepth,
79 for pointer sprite colors, etc. Sharablecolors OTOH is
80 limited to 2 ^ bitmapdepth */
82 bmdepth
= GetBitMapAttr(vp
->RasInfo
->BitMap
, BMA_DEPTH
);
85 if ((1L << bmdepth
) < sharablecolors
)
87 sharablecolors
= 1L << bmdepth
;
91 /* initialize the AllocList BYTE-array */
94 /* CHECKME: Should probably say "i < sharablecolors", but might
95 not actually cause anything bad either, even if it doesn't. */
98 PALEXTRA_ALLOCLIST(pe
, i
) = (PalExtra_AllocList_Type
)i
-1;
102 /* connect the PaletteExtra structure to the ColorMap */
105 /* initialize the Palette Extra structure */
106 InitSemaphore(&pe
->pe_Semaphore
);
107 pe
->pe_ViewPort
= vp
;
109 pe
->pe_FirstFree
= sharablecolors
-1;
110 pe
->pe_NFree
= sharablecolors
;
111 pe
->pe_FirstShared
= (UWORD
)-1;
114 /* set all entries in the color table to be shareable
115 pe_SharableColors is not the number of colors but the last color index! */
117 pe
->pe_SharableColors
= sharablecolors
;
119 } /* if (NULL != pe->pe_RefCnt && NULL != pe->pe_AllocList) */
122 /* some memory allocation failed */
124 FreeMem(pe
->pe_RefCnt
, cm
->Count
* sizeof(PalExtra_RefCnt_Type
));
125 if (pe
->pe_AllocList
)
126 FreeMem(pe
->pe_AllocList
, cm
->Count
* sizeof(PalExtra_AllocList_Type
));
127 FreeMem(pe
, sizeof(struct PaletteExtra
));
131 } /* if (NULL != pe) */
139 } /* AttachPalExtra */