New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / rom / graphics / releasepen.c
blob2e174034e5303d61fb956f5e1606609ba13dd881
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Release a pen previously allocated.
6 Lang: english
7 */
8 #include "graphics_intern.h"
9 #include <graphics/view.h>
10 #ifdef DEBUG
11 #undef DEBUG
12 #endif
13 #define DEBUG 0
14 #include <aros/debug.h>
16 /*****************************************************************************
18 NAME */
19 #include <clib/graphics_protos.h>
21 AROS_LH2(void, ReleasePen,
23 /* SYNOPSIS */
24 AROS_LHA(struct ColorMap *, cm, A0),
25 AROS_LHA(ULONG , n , D0),
27 /* LOCATION */
28 struct GfxBase *, GfxBase, 158, Graphics)
30 /* FUNCTION
31 Release a pen that was previously allocated as an exclusive
32 or shared pen by the application. Any other application can
33 then obtain this pen and make changes to the color register
34 entries.
37 INPUTS
38 cm - ColorMap structure where the pen was allocated
39 n - The number of the pen
41 RESULT
42 An exclusive pen is deallocated for other applications to use.
43 A shared pen is only completely deallocated if no other
44 application is using it anymore.
46 NOTES
48 EXAMPLE
50 BUGS
52 SEE ALSO
54 INTERNALS
56 HISTORY
58 *****************************************************************************/
60 AROS_LIBFUNC_INIT
61 AROS_LIBBASE_EXT_DECL(struct GfxBase *,GfxBase)
63 if (NULL != cm && n < cm->Count)
65 struct PaletteExtra * pe = cm->PalExtra;
66 PalExtra_AllocList_Type index;
68 ObtainSemaphore(&pe->pe_Semaphore);
69 /* First I check whether this pen is somewhere in the
70 free list already...
73 index = pe->pe_FirstFree;
74 while ((PalExtra_AllocList_Type)-1 != index)
76 if (index == (PalExtra_AllocList_Type)n)
77 goto exit;
79 index = PALEXTRA_ALLOCLIST(pe, index);
83 ** It is not in the free list.
84 ** If it is a shared pen, then I can recognize this
85 ** by its value in the RefCnt
88 if (0 != PALEXTRA_REFCNT(pe,n))
90 /*
91 ** A SHARED pen
93 PALEXTRA_REFCNT(pe, n)--;
94 if (0 == PALEXTRA_REFCNT(pe, n))
96 BOOL found = FALSE;
97 /*
98 ** I can take this out if the list of shared pens
99 ** since this was the last application that used
100 ** this pen.
102 index = pe->pe_FirstShared;
103 if ((PalExtra_AllocList_Type)n == index)
105 found = TRUE;
107 ** it's the very first one.
110 ** Take it out of the list of entries in
111 ** the shared list...
113 if ((PalExtra_AllocList_Type)-1 == PALEXTRA_ALLOCLIST(pe,n))
114 pe->pe_FirstShared = (WORD)-1;
115 else
116 pe->pe_FirstShared = (WORD)PALEXTRA_ALLOCLIST(pe,n);
118 pe->pe_NShared--;
121 ** ... and make it available in the list of free
122 ** entries.
124 PALEXTRA_ALLOCLIST(pe,n) = (PalExtra_AllocList_Type)pe->pe_FirstFree;
125 pe->pe_FirstFree = n;
126 pe->pe_NFree++;
128 else
132 if ((PalExtra_AllocList_Type)n == PALEXTRA_ALLOCLIST(pe, index))
134 found = TRUE;
137 ** Take it out of the list of shared entries
139 PALEXTRA_ALLOCLIST(pe, index) = PALEXTRA_ALLOCLIST(pe, n);
140 pe->pe_NShared--;
143 ** ... and make it available in the list of free
144 ** entries.
146 PALEXTRA_ALLOCLIST(pe, n) = (PalExtra_AllocList_Type)pe->pe_FirstFree;
147 pe->pe_FirstFree = n;
148 pe->pe_NFree++;
149 break;
151 else
152 index = PALEXTRA_ALLOCLIST(pe, index);
154 while ((PalExtra_AllocList_Type)-1 != index);
157 #if DEBUG
158 if (FALSE==found)
159 D(bug("Error in RealsePen() pen = %d!\n",n));
160 #endif
162 } /* if (no further app needs this pen) */
164 } /* if (0 != PALEXTRA_REFCNT(pe,n)) */
165 else
167 /* releasing an EXCLUSIVE pen */
168 D(bug("Releasing (exclusive) pen %d\n"));
170 PALEXTRA_ALLOCLIST(pe, n) = pe->pe_FirstFree;
171 pe->pe_FirstFree = n;
172 pe->pe_NFree++;
174 exit:
175 ReleaseSemaphore(&pe->pe_Semaphore);
177 } /* if (NULL != cm && n < cm->Count) */
179 AROS_LIBFUNC_EXIT
181 } /* ReleasePen */