tools/adflib: build only host variant which is used by Sam440 target
[AROS.git] / workbench / devs / diskimage / png_image / init.c
blob4c4830124c47a688aac3de971b1eb824ca851a8c
1 /* Copyright 2007-2012 Fredrik Wikstrom. All rights reserved.
2 **
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
5 ** are met:
6 **
7 ** 1. Redistributions of source code must retain the above copyright
8 ** notice, this list of conditions and the following disclaimer.
9 **
10 ** 2. Redistributions in binary form must reproduce the above copyright
11 ** notice, this list of conditions and the following disclaimer in the
12 ** documentation and/or other materials provided with the distribution.
14 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
15 ** AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 ** ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
18 ** LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 ** CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
20 ** SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
21 ** INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
22 ** CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 ** ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
24 ** POSSIBILITY OF SUCH DAMAGE.
27 #include "class.h"
28 #include <proto/exec.h>
29 #include <proto/dos.h>
30 #include <proto/utility.h>
31 #include <proto/intuition.h>
32 #include <proto/graphics.h>
33 #include <proto/z.h>
34 #include "support.h"
35 #include "png.image_rev.h"
37 #define LIBNAME "png.image"
38 const char USED verstag[] = VERSTAG;
40 struct ExecBase *SysBase;
41 struct DosLibrary *DOSBase;
42 struct UtilityBase *UtilityBase;
43 struct IntuitionBase *IntuitionBase;
44 struct GfxBase *GfxBase;
45 struct Library *LayersBase;
46 struct Library *P96Base;
47 struct Library *CyberGfxBase;
48 struct Library *ZBase;
50 struct ClassBase *libInit (REG(d0, struct ClassBase *libBase), REG(a0, BPTR seglist),
51 REG(a6, struct ExecBase *exec_base));
52 struct ClassBase *libOpen (REG(a6, struct ClassBase *libBase), REG(d0, ULONG version));
53 BPTR libClose (REG(a6, struct ClassBase *libBase));
54 BPTR libExpunge (REG(a6, struct ClassBase *libBase));
55 APTR libReserved (REG(a6, struct ClassBase *libBase));
56 BOOL OpenLibs (void);
57 void CloseLibs (void);
58 Class *GetClass (REG(a6, struct ClassBase *libBase));
60 struct InitTable {
61 ULONG it_Size;
62 APTR it_FunctionTable;
63 APTR it_DataTable;
64 APTR it_InitRoutine;
67 CONST_APTR function_table[] = {
68 (APTR)libOpen,
69 (APTR)libClose,
70 (APTR)libExpunge,
71 (APTR)libReserved,
72 (APTR)GetClass,
73 (APTR)-1
76 CONST struct InitTable init_table = {
77 sizeof(struct ClassBase),
78 (APTR)function_table,
79 NULL,
80 (APTR)libInit
83 CONST struct Resident USED lib_res = {
84 RTC_MATCHWORD,
85 (struct Resident *)&lib_res,
86 (APTR)(&lib_res + 1),
87 RTF_AUTOINIT,
88 VERSION,
89 NT_LIBRARY,
91 LIBNAME,
92 VSTRING,
93 (APTR)&init_table
96 struct ClassBase *libInit (REG(d0, struct ClassBase *libBase), REG(a0, BPTR seglist),
97 REG(a6, struct ExecBase *exec_base))
99 libBase->libNode.lib_Node.ln_Type = NT_LIBRARY;
100 libBase->libNode.lib_Node.ln_Pri = 0;
101 libBase->libNode.lib_Node.ln_Name = LIBNAME;
102 libBase->libNode.lib_Flags = LIBF_SUMUSED|LIBF_CHANGED;
103 libBase->libNode.lib_Version = VERSION;
104 libBase->libNode.lib_Revision = REVISION;
105 libBase->libNode.lib_IdString = VSTRING;
107 SysBase = exec_base;
108 libBase->seglist = seglist;
110 if (OpenLibs()) {
111 libBase->class = MakeClass(LIBNAME, "imageclass", NULL, sizeof(struct ClassData), 0);
112 if (libBase->class) {
113 libBase->class->cl_Dispatcher.h_Entry = (HOOKFUNC)ClassDispatch;
114 AddClass(libBase->class);
115 return libBase;
118 CloseLibs();
119 DeleteLibrary((struct Library *)libBase);
121 return NULL;
124 struct ClassBase *libOpen (REG(a6, struct ClassBase *libBase), REG(d0, ULONG version)) {
125 libBase->libNode.lib_OpenCnt++;
126 libBase->libNode.lib_Flags &= ~LIBF_DELEXP;
127 return libBase;
130 BPTR libClose (REG(a6, struct ClassBase *libBase)) {
131 libBase->libNode.lib_OpenCnt--;
132 return 0;
135 BPTR libExpunge (REG(a6, struct ClassBase *libBase)) {
136 BPTR result = 0;
138 if (libBase->libNode.lib_OpenCnt > 0) {
139 libBase->libNode.lib_Flags |= LIBF_DELEXP;
140 return 0;
143 Remove(&libBase->libNode.lib_Node);
145 FreeClass(libBase->class);
146 CloseLibs();
148 result = libBase->seglist;
150 DeleteLibrary((struct Library *)libBase);
152 return result;
155 APTR libReserved (REG(a6, struct ClassBase *libBase)) {
156 return NULL;
159 BOOL OpenLibs (void) {
160 return (DOSBase = (struct DosLibrary *)OpenLibrary("dos.library", 39)) &&
161 (UtilityBase = (struct UtilityBase *)OpenLibrary("utility.library", 39)) &&
162 (IntuitionBase = (struct IntuitionBase *)OpenLibrary("intuition.library", 39)) &&
163 (GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 39)) &&
164 (LayersBase = OpenLibrary("layers.library", 39)) &&
165 ((P96Base = OpenLibrary("Picasso96API.library", 0)) ||
166 (CyberGfxBase = OpenLibrary("cybergraphics.library", 0)) || 1) &&
167 (ZBase = OpenLibrary("z.library", 1));
170 void CloseLibs (void) {
171 if (ZBase) CloseLibrary(ZBase);
172 if (CyberGfxBase) CloseLibrary(CyberGfxBase);
173 if (P96Base) CloseLibrary(P96Base);
174 if (LayersBase) CloseLibrary(LayersBase);
175 if (GfxBase) CloseLibrary((struct Library *)GfxBase);
176 if (IntuitionBase) CloseLibrary((struct Library *)IntuitionBase);
177 if (UtilityBase) CloseLibrary((struct Library *)UtilityBase);
178 if (DOSBase) CloseLibrary((struct Library *)DOSBase);
181 Class *GetClass (REG(a6, struct ClassBase *libBase)) {
182 return libBase->class;