Check for SYS/GL during library init. Reason is that
[AROS.git] / workbench / libs / icon / icon_intern.h
blob51e9352f2d65b94c7e29b61b2577047acb3aae3b
1 #ifndef ICON_INTERN_H
2 #define ICON_INTERN_H
4 /*
5 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
6 $Id$
7 */
9 #include <exec/memory.h>
10 #include <exec/libraries.h>
11 #include <aros/asmcall.h>
12 #include <dos/dos.h>
13 #include <libraries/iffparse.h>
14 #include <cybergraphx/cybergraphics.h>
15 #include <workbench/workbench.h>
16 #include <workbench/icon.h>
17 #include <graphics/view.h>
19 #include <proto/alib.h>
20 #include <proto/exec.h>
21 #include <proto/intuition.h>
22 #include <proto/graphics.h>
23 #include <proto/icon.h>
24 #include <proto/iffparse.h>
25 #include <proto/utility.h>
26 #include <proto/cybergraphics.h>
27 #include <proto/dos.h>
29 #include <stddef.h>
31 #include <string.h>
32 #include <aros/libcall.h>
33 #include <aros/asmcall.h>
35 /****************************************************************************************/
37 /* Constants */
38 #define MAX_DEFICON_FILEPATH 256
40 /* Number of entries in the mementrys in the freelists */
41 #define FREELIST_MEMLISTENTRIES 10
43 /* This must be a power of 2 */
44 #ifdef __mc68000
45 #define ICONLIST_HASHSIZE 32 /* Save space on small memory m68k machines */
46 #else
47 #define ICONLIST_HASHSIZE 256
48 #endif
50 /****************************************************************************************/
52 /*
53 To get right alignment we make our very own memlist structure.
54 Look at the original struct MemList in <exec/memory.h> to see why.
57 struct IconInternalMemList
59 struct Node iiml_Node;
60 UWORD iiml_NumEntries;
61 struct MemEntry iiml_ME[FREELIST_MEMLISTENTRIES];
64 #define IMAGE35F_HASTRANSPARENTCOLOR 1
65 #define IMAGE35F_HASPALETTE 2
67 #define ICON35F_FRAMELESS 1
69 struct NativeIcon
71 struct MinNode ni_Node;
72 struct DiskObject ni_DiskObject;
73 struct FreeList ni_FreeList;
74 ULONG ni_ReadStruct_State;
76 /* Source icon data */
77 struct {
78 APTR Data; /* Raw IFF or PNG stream */
79 ULONG Size;
80 struct {
81 LONG Offset;
82 LONG Size;
83 } PNG[2];
84 } ni_Extra;
86 /* Parameters */
87 BOOL ni_IsDefault;
88 BOOL ni_Frameless;
89 ULONG ni_ScaleBox;
91 /* The 'laid out' icon. The laid out data will
92 * also be resized for the screen's aspect ratio,
93 * so the nil_Width and nil_Height will probably
94 * be different than the original image on some
95 * screens.
97 struct Screen *ni_Screen; /* Screen for the layout */
98 ULONG ni_Width; /* Dimension of the aspect */
99 ULONG ni_Height; /* ratio corrected icon */
101 /* Pens for drawing the border and frame */
102 UWORD ni_Pens[NUMDRIPENS]; /* Copied from DrawInfo for the screen */
104 struct NativeIconFace {
105 UBYTE Aspect; /* Source aspect ratio */
106 ULONG Width;
107 ULONG Height;
108 } ni_Face;
110 struct NativeIconImage {
111 /* This data was either allocated during icon load
112 * (and is in the ni_FreeList), or was provided by
113 * the user via IconControlA().
115 LONG TransparentColor;
116 ULONG Pens; /* Pens allocated for the layout */
117 const struct ColorRegister *Palette; /* one entry per pen */
118 const UBYTE *ImageData; /* 'ChunkyPixels' image */
119 const ULONG *ARGB; /* RGB+Alpha (A 0=transparent) */
121 /* Dynamically allocated by LayoutIconA(), and are
122 * _not_ in the ni_FreeList.
124 * You must call LayoutIconA(icon, NULL, NULL) or
125 * FreeDiskObject() to free this memory.
127 ULONG *Pen; /* Palette n to Pen m mapping */
128 struct BitMap *BitMap; /* 'friend' of the Screen */
129 PLANEPTR BitMask; /* TransparentColor >= 0 bitmask */
130 APTR ARGBMap; /* ARGB, rescaled version */
132 /* For m68k legacy support, the struct Image render
133 * is stored here.
135 struct Image Render;
136 } ni_Image[2];
139 #define RSS_OLDDRAWERDATA_READ (1 << 0)
140 #define RSS_GADGETIMAGE_READ (1 << 1)
141 #define RSS_SELECTIMAGE_READ (1 << 2)
142 #define RSS_DEFAULTTOOL_READ (1 << 3)
143 #define RSS_TOOLWINDOW_READ (1 << 4)
144 #define RSS_TOOLTYPES_READ (1 << 5)
146 #define NATIVEICON(icon) ((struct NativeIcon *)((UBYTE *)(icon) - offsetof(struct NativeIcon, ni_DiskObject)))
148 struct IconBase
150 struct Library ib_Lib;
152 struct Hook dsh;
153 struct SignalSemaphore iconlistlock;
154 struct MinList iconlists[ICONLIST_HASHSIZE];
156 ULONG *ib_CRCTable;
158 /* Global settings -----------------------------------------------------*/
159 struct Screen *ib_Screen;
160 LONG ib_Precision;
161 struct Rectangle ib_EmbossRectangle;
162 BOOL ib_Frameless;
163 ULONG ib_ScaleBox;
164 struct Hook *ib_IdentifyHook;
165 LONG ib_MaxNameLength;
166 BOOL ib_NewIconsSupport;
167 BOOL ib_ColorIconSupport;
168 BPTR ib_SegList;
170 /* Required External libraries */
171 APTR ib_DOSBase;
172 APTR ib_GfxBase;
173 APTR ib_IntuitionBase;
174 APTR ib_UtilityBase;
176 /* Optional external libraries */
177 APTR ib_CyberGfxBase;
178 APTR ib_IFFParseBase;
179 APTR ib_DataTypesBase;
180 APTR ib_WorkbenchBase;
183 typedef struct IconBase IconBase_T;
185 /* FIXME: Remove these #define xxxBase hacks
186 Do not use this in new code !
188 #define DOSBase (IconBase->ib_DOSBase)
189 #define GfxBase (IconBase->ib_GfxBase)
190 #define IntuitionBase (IconBase->ib_IntuitionBase)
191 #define UtilityBase (IconBase->ib_UtilityBase)
193 /****************************************************************************************/
195 extern struct ExecBase *SysBase;
197 /****************************************************************************************/
198 /* On-demand open of optional libraries. Just that is
199 * non-NULL before you use it!
201 extern const LONG IFFParseBase_version,
202 GfxBase_version,
203 CyberGfxBase_version,
204 DataTypesBase_version;
206 static inline APTR DemandOpenLibrary(struct Library **libp, CONST_STRPTR libname, ULONG version)
208 if (*libp == NULL)
209 *libp = OpenLibrary(libname, version);
211 return *libp;
214 #define IFFParseBase DemandOpenLibrary((struct Library **)&IconBase->ib_IFFParseBase, "iffparse.library", IFFParseBase_version)
215 #define CyberGfxBase DemandOpenLibrary((struct Library **)&IconBase->ib_CyberGfxBase, "cybergraphics.library", CyberGfxBase_version)
216 #define DataTypesBase DemandOpenLibrary((struct Library **)&IconBase->ib_DataTypesBase, "datatypes.library", DataTypesBase_version)
217 #define WorkbenchBase DemandOpenLibrary((struct Library **)&IconBase->ib_WorkbenchBase, "workbench.library", 0)
219 /****************************************************************************************/
221 /* Internal prototypes */
222 AROS_UFP3(LONG, dosstreamhook,
223 AROS_UFPA(struct Hook *, hook, A0),
224 AROS_UFPA(BPTR, file, A2),
225 AROS_UFPA(ULONG *, msg, A1)
228 #include "support.h"
230 UBYTE * WriteValue (LONG, UBYTE *);
232 BOOL ReadIcon35(struct NativeIcon *icon, struct Hook *streamhook, void *stream, struct IconBase *IconBase);
233 BOOL WriteIcon35(struct NativeIcon *icon, struct Hook *streamhook, void *stream, struct IconBase *IconBase);
234 VOID FreeIcon35(struct NativeIcon *icon, struct IconBase *IconBase);
235 VOID MakeMask35(UBYTE *imgdata, UBYTE *imgmask, UBYTE transpcolor, LONG imagew, LONG imageh);
237 BOOL ReadIconNI(struct NativeIcon *icon, struct Hook *streamhook, void *stream, struct IconBase *IconBase);
238 BOOL WriteIconNI(struct NativeIcon *icon, struct Hook *streamhook, void *stream, struct IconBase *IconBase);
239 VOID FreeIconNI(struct NativeIcon *icon, struct IconBase *IconBase);
241 /* Returns an ARGB image.
242 * Set &width == ~0 and &height == ~0 to get the size.
243 * Otherwise, sets the image size of width & height
245 ULONG *ReadMemPNG(struct DiskObject *icon, APTR stream, LONG *width, LONG *height, const CONST_STRPTR *chunknames, APTR *chunkpointer, struct IconBase *IconBase);
247 BOOL ReadIconPNG(struct DiskObject *dobj, BPTR file, struct IconBase *IconBase);
248 BOOL WriteIconPNG(BPTR file, struct DiskObject *dobj, struct IconBase *IconBase);
249 VOID FreeIconPNG(struct DiskObject *dobj, struct IconBase *IconBase);
252 #define LB(ib) ((struct IconBase *) (ib))
254 #endif /* ICON_INTERN_H */