Don't call ReadArgs() if started from WB.
[tangerine.git] / compiler / coolimages / imageclass.c
blob841a14e90b4125201cd3940e2da651ab4a570cdd
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 /****************************************************************************************/
8 #define USE_BOOPSI_STUBS
10 #include <exec/execbase.h>
11 #include <exec/memory.h>
12 #include <intuition/intuition.h>
13 #include <intuition/classes.h>
14 #include <intuition/classusr.h>
15 #include <intuition/imageclass.h>
16 #include <graphics/gfx.h>
17 #include <cybergraphx/cybergraphics.h>
18 #include <proto/exec.h>
19 #include <proto/intuition.h>
20 #include <proto/graphics.h>
21 #include <proto/cybergraphics.h>
22 #include <proto/utility.h>
23 #include <aros/asmcall.h>
24 #include <clib/boopsistubs.h>
26 #include "coolimages.h"
28 /****************************************************************************************/
30 struct CoolImageData
32 struct CoolImage *image;
33 ULONG *pal;
34 ULONG bgcol;
37 /****************************************************************************************/
39 extern struct IntuitionBase *IntuitionBase;
40 extern struct GfxBase *GfxBase;
41 extern struct UtilityBase *UtilityBase;
43 struct IClass *cool_imageclass;
45 /****************************************************************************************/
47 #define CyberGfxBase cool_cybergfxbase
48 #define IM(x) ((struct Image *)(x))
50 /****************************************************************************************/
52 static struct Library *cool_cybergfxbase;
54 /****************************************************************************************/
56 static IPTR coolimage_new(Class * cl, Object * o, struct opSet * msg)
58 AROS_GET_SYSBASE_OK
59 struct CoolImageData *data;
61 o = (Object *)DoSuperMethodA(cl, o, (Msg)msg);
63 if (o)
65 data = INST_DATA(cl, o);
67 data->image = (struct CoolImage *)GetTagData(COOLIM_CoolImage, 0, msg->ops_AttrList);
69 if (!data->image)
71 CoerceMethod(cl, o, OM_DISPOSE);
72 o = NULL;
73 } else {
74 data->bgcol = GetTagData(COOLIM_BgColor,
75 (data->image->pal[0] << 16) | (data->image->pal[1] << 8) | data->image->pal[2],
76 msg->ops_AttrList);
77 if (CyberGfxBase)
79 if ((data->pal = AllocVec(data->image->numcolors * sizeof(ULONG), MEMF_PUBLIC)))
81 ULONG *p = data->pal;
82 WORD i;
84 for(i = 0; i < data->image->numcolors; i++)
86 *p++ = (data->image->pal[i * 3] << 16) |
87 (data->image->pal[i * 3 + 1] << 8) |
88 (data->image->pal[i * 3 + 2]);
91 } else {
92 data->image = NULL;
97 } /* if (o) */
99 return (IPTR)o;
102 /****************************************************************************************/
104 static IPTR coolimage_dispose(Class * cl, Object * o, Msg msg)
106 AROS_GET_SYSBASE_OK
107 struct CoolImageData *data;
109 data = INST_DATA(cl, o);
111 if (data->pal) FreeVec(data->pal);
113 return DoSuperMethodA(cl, o, msg);
116 /****************************************************************************************/
118 static IPTR coolimage_draw(Class *cl, Object *o, struct impDraw *msg)
120 struct CoolImageData *data;
121 WORD x, y;
123 data = INST_DATA(cl, o);
125 x = IM(o)->LeftEdge + msg->imp_Offset.X;
126 y = IM(o)->TopEdge + msg->imp_Offset.Y;
128 if (CyberGfxBase && (GetBitMapAttr(msg->imp_RPort->BitMap, BMA_DEPTH) >= 15))
130 data->pal[0] = data->bgcol;
132 WriteLUTPixelArray((APTR)data->image->data,
135 data->image->width,
136 msg->imp_RPort,
137 data->pal,
140 data->image->width,
141 data->image->height,
142 CTABFMT_XRGB8);
146 return 0;
149 /****************************************************************************************/
150 /****************************************************************************************/
151 /****************************************************************************************/
153 AROS_UFH3S(IPTR, cool_imageclass_dispatcher,
154 AROS_UFHA(Class *, cl, A0),
155 AROS_UFHA(Object *, obj, A2),
156 AROS_UFHA(Msg, msg, A1))
158 AROS_USERFUNC_INIT
160 IPTR retval;
162 switch (msg->MethodID)
164 case OM_NEW:
165 retval = coolimage_new(cl, obj, (struct opSet *)msg);
166 break;
168 case OM_DISPOSE:
169 retval = coolimage_dispose(cl, obj, msg);
170 break;
172 case IM_DRAW:
173 retval = coolimage_draw(cl, obj, (struct impDraw *)msg);
174 break;
176 default:
177 retval = DoSuperMethodA(cl, obj, msg);
178 break;
180 } /* switch (msg->MethodID) */
182 return retval;
184 AROS_USERFUNC_EXIT
187 /****************************************************************************************/
189 #undef CyberGfxBase
191 /****************************************************************************************/
193 BOOL InitCoolImageClass(struct Library *CyberGfxBase)
195 AROS_GET_SYSBASE_OK
196 BOOL retval = FALSE;
198 cool_cybergfxbase = CyberGfxBase;
200 if (IntuitionBase && GfxBase && UtilityBase && SysBase)
202 if (!cool_imageclass)
204 cool_imageclass = MakeClass(NULL, IMAGECLASS, NULL, sizeof(struct CoolImageData), 0UL);
207 if (cool_imageclass)
209 cool_imageclass->cl_Dispatcher.h_Entry = (HOOKFUNC)cool_imageclass_dispatcher;
210 retval = TRUE;
214 return retval;
217 /****************************************************************************************/
219 void CleanupCoolImageClass(void)
221 if (cool_imageclass)
223 FreeClass(cool_imageclass);
224 cool_imageclass = NULL;
228 /****************************************************************************************/