2 Copyright © 1995-2013, 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 by FreeColorMap().
33 cm - Pointer to a color map structure
34 vp - Pointer to the viewport associated with the ColorMap
52 *****************************************************************************/
56 struct PaletteExtra
* pe
;
58 if (NULL
!= cm
->PalExtra
)
61 pe
= AllocMem(sizeof(struct PaletteExtra
), MEMF_CLEAR
|MEMF_PUBLIC
);
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
);
84 if ((1L << bmdepth
) < sharablecolors
)
86 sharablecolors
= 1L << bmdepth
;
90 /* initialize the AllocList BYTE-array */
93 /* CHECKME: Should probably say "i < sharablecolors", but might
94 not actually cause anything bad either, even if it doesn't. */
97 PALEXTRA_ALLOCLIST(pe
, i
) = (PalExtra_AllocList_Type
)i
-1;
101 /* connect the PaletteExtra structure to the ColorMap */
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;
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
- 1;
118 } /* if (NULL != pe->pe_RefCnt && NULL != pe->pe_AllocList) */
121 /* some memory allocation failed */
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
));
130 } /* if (NULL != pe) */
138 } /* AttachPalExtra */