Backport
[AROS.git] / compiler / coolimages / imageclass.c
blobd69cccba50a2bb2d57d43c8a7bdcca2cb44f3581
1 /*
2 Copyright © 1995-2013, 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 struct CoolImageData *data;
60 o = (Object *)DoSuperMethodA(cl, o, (Msg)msg);
62 if (o)
64 data = INST_DATA(cl, o);
66 data->image = (struct CoolImage *)GetTagData(COOLIM_CoolImage, 0, msg->ops_AttrList);
68 if (!data->image)
70 CoerceMethod(cl, o, OM_DISPOSE);
71 o = NULL;
72 } else {
73 data->bgcol = GetTagData(COOLIM_BgColor,
74 (data->image->pal[0] << 16) | (data->image->pal[1] << 8) | data->image->pal[2],
75 msg->ops_AttrList);
76 if (CyberGfxBase)
78 if ((data->pal = AllocVec(data->image->numcolors * sizeof(ULONG), MEMF_PUBLIC)))
80 ULONG *p = data->pal;
81 WORD i;
83 for(i = 0; i < data->image->numcolors; i++)
85 *p++ = (data->image->pal[i * 3] << 16) |
86 (data->image->pal[i * 3 + 1] << 8) |
87 (data->image->pal[i * 3 + 2]);
90 } else {
91 data->image = NULL;
96 } /* if (o) */
98 return (IPTR)o;
101 /****************************************************************************************/
103 static IPTR coolimage_dispose(Class * cl, Object * o, Msg msg)
105 struct CoolImageData *data;
107 data = INST_DATA(cl, o);
109 FreeVec(data->pal);
111 return DoSuperMethodA(cl, o, msg);
114 /****************************************************************************************/
116 static IPTR coolimage_draw(Class *cl, Object *o, struct impDraw *msg)
118 struct CoolImageData *data;
119 WORD x, y;
121 data = INST_DATA(cl, o);
123 x = IM(o)->LeftEdge + msg->imp_Offset.X;
124 y = IM(o)->TopEdge + msg->imp_Offset.Y;
126 if (CyberGfxBase && (GetBitMapAttr(msg->imp_RPort->BitMap, BMA_DEPTH) >= 15))
128 data->pal[0] = data->bgcol;
130 WriteLUTPixelArray((APTR)data->image->data,
133 data->image->width,
134 msg->imp_RPort,
135 data->pal,
138 data->image->width,
139 data->image->height,
140 CTABFMT_XRGB8);
144 return 0;
147 /****************************************************************************************/
148 /****************************************************************************************/
149 /****************************************************************************************/
151 AROS_UFH3S(IPTR, cool_imageclass_dispatcher,
152 AROS_UFHA(Class *, cl, A0),
153 AROS_UFHA(Object *, obj, A2),
154 AROS_UFHA(Msg, msg, A1))
156 AROS_USERFUNC_INIT
158 IPTR retval;
160 switch (msg->MethodID)
162 case OM_NEW:
163 retval = coolimage_new(cl, obj, (struct opSet *)msg);
164 break;
166 case OM_DISPOSE:
167 retval = coolimage_dispose(cl, obj, msg);
168 break;
170 case IM_DRAW:
171 retval = coolimage_draw(cl, obj, (struct impDraw *)msg);
172 break;
174 default:
175 retval = DoSuperMethodA(cl, obj, msg);
176 break;
178 } /* switch (msg->MethodID) */
180 return retval;
182 AROS_USERFUNC_EXIT
185 /****************************************************************************************/
187 #undef CyberGfxBase
189 /****************************************************************************************/
191 BOOL InitCoolImageClass(struct Library *CyberGfxBase)
193 BOOL retval = FALSE;
195 cool_cybergfxbase = CyberGfxBase;
197 if (IntuitionBase && GfxBase && UtilityBase) // && SysBase)
199 if (!cool_imageclass)
201 cool_imageclass = MakeClass(NULL, IMAGECLASS, NULL, sizeof(struct CoolImageData), 0UL);
204 if (cool_imageclass)
206 cool_imageclass->cl_Dispatcher.h_Entry = (HOOKFUNC)cool_imageclass_dispatcher;
207 retval = TRUE;
211 return retval;
214 /****************************************************************************************/
216 void CleanupCoolImageClass(void)
218 if (cool_imageclass)
220 FreeClass(cool_imageclass);
221 cool_imageclass = NULL;
225 /****************************************************************************************/