1 /* Copyright 2007-2012 Fredrik Wikstrom. All rights reserved.
3 ** Redistribution and use in source and binary forms, with or without
4 ** modification, are permitted provided that the following conditions
7 ** 1. Redistributions of source code must retain the above copyright
8 ** notice, this list of conditions and the following disclaimer.
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.
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>
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
));
57 void CloseLibs (void);
58 Class
*GetClass (REG(a6
, struct ClassBase
*libBase
));
62 APTR it_FunctionTable
;
67 CONST_APTR function_table
[] = {
76 CONST
struct InitTable init_table
= {
77 sizeof(struct ClassBase
),
83 CONST
struct Resident USED lib_res
= {
85 (struct Resident
*)&lib_res
,
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
;
108 libBase
->seglist
= seglist
;
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);
119 DeleteLibrary((struct Library
*)libBase
);
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
;
130 BPTR
libClose (REG(a6
, struct ClassBase
*libBase
)) {
131 libBase
->libNode
.lib_OpenCnt
--;
135 BPTR
libExpunge (REG(a6
, struct ClassBase
*libBase
)) {
138 if (libBase
->libNode
.lib_OpenCnt
> 0) {
139 libBase
->libNode
.lib_Flags
|= LIBF_DELEXP
;
143 Remove(&libBase
->libNode
.lib_Node
);
145 FreeClass(libBase
->class);
148 result
= libBase
->seglist
;
150 DeleteLibrary((struct Library
*)libBase
);
155 APTR
libReserved (REG(a6
, struct ClassBase
*libBase
)) {
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;