use dmb/dsb from asm/cpu.h file.
[AROS.git] / workbench / libs / muimaster / classes / chunkyimage.c
blobe2de02f17c5dba6edba9af818c5e9e41bf471967
1 /*
2 Copyright © 2002-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <graphics/gfx.h>
7 #include <graphics/view.h>
8 #include <clib/alib_protos.h>
9 #include <proto/exec.h>
10 #include <proto/graphics.h>
11 #include <proto/utility.h>
12 #include <proto/intuition.h>
13 #include <proto/muimaster.h>
15 #include "mui.h"
16 #include "muimaster_intern.h"
17 #include "support.h"
19 extern struct Library *MUIMasterBase;
21 struct MUI_ChunkyImageData
23 struct BitMap *bm;
24 UBYTE *pixels;
25 UBYTE *palette;
26 ULONG *palette32;
27 UWORD width, height, numcolors, modulo;
30 static BOOL make_bitmap(struct IClass *cl, Object *obj)
32 struct MUI_ChunkyImageData *data = INST_DATA(cl, obj);
33 struct RastPort temprp;
34 WORD depth;
36 if (!data->pixels ||
37 (data->width < 1) ||
38 (data->height < 1) ||
39 (data->numcolors < 1) || (data->numcolors > 256))
41 return FALSE;
44 if (data->palette)
46 data->palette32 =
47 AllocVec(data->numcolors * 3 * sizeof(ULONG), MEMF_ANY);
48 if (!data->palette32)
49 return FALSE;
51 if (data->palette32)
53 UBYTE *src = data->palette;
54 ULONG *dest = data->palette32;
55 WORD i;
57 for (i = 0; i < data->numcolors; i++)
59 *dest++ = ((ULONG) (*src++)) * 0x01010101;
60 *dest++ = ((ULONG) (*src++)) * 0x01010101;
61 *dest++ = ((ULONG) (*src++)) * 0x01010101;
66 for (depth = 1; (1L << depth) < data->numcolors; depth++)
70 data->bm =
71 AllocBitMap(data->width, data->height, depth, BMF_CLEAR, NULL);
72 if (!data->bm)
74 if (data->palette32)
76 FreeVec(data->palette32);
77 data->palette32 = NULL;
79 return FALSE;
82 InitRastPort(&temprp);
83 temprp.BitMap = data->bm;
85 WriteChunkyPixels(&temprp,
87 0, data->width - 1, data->height - 1, data->pixels, data->modulo);
89 return TRUE;
92 /**************************************************************************
93 OM_NEW
94 **************************************************************************/
95 IPTR ChunkyImage__OM_NEW(struct IClass *cl, Object *obj,
96 struct opSet *msg)
98 struct MUI_ChunkyImageData *data;
99 struct TagItem *tag, *tags;
101 obj = (Object *) DoSuperMethodA(cl, obj, (Msg) msg);
102 if (!obj)
103 return FALSE;
105 data = INST_DATA(cl, obj);
107 /* parse initial taglist */
109 data->modulo = 0xFFFF;
111 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags));)
113 switch (tag->ti_Tag)
115 case MUIA_ChunkyImage_Pixels:
116 data->pixels = (UBYTE *) tag->ti_Data;
117 break;
119 case MUIA_ChunkyImage_Palette:
120 data->palette = (UBYTE *) tag->ti_Data;
121 break;
123 case MUIA_ChunkyImage_NumColors:
124 data->numcolors = (LONG) tag->ti_Data;
125 break;
127 case MUIA_ChunkyImage_Modulo:
128 data->modulo = (LONG) tag->ti_Data;
129 break;
131 case MUIA_Bitmap_Width:
132 data->width = (LONG) tag->ti_Data;
133 break;
135 case MUIA_Bitmap_Height:
136 data->height = (LONG) tag->ti_Data;
137 break;
142 if (data->modulo == 0xFFFF)
143 data->modulo = data->width;
145 return (IPTR) obj;
148 /**************************************************************************
149 OM_DISPOSE
150 **************************************************************************/
151 IPTR ChunkyImage__OM_DISPOSE(struct IClass *cl, Object *obj, Msg msg)
153 struct MUI_ChunkyImageData *data = INST_DATA(cl, obj);
155 if (data->bm)
157 WaitBlit();
158 FreeBitMap(data->bm);
161 return DoSuperMethodA(cl, obj, msg);
164 /**************************************************************************
165 OM_SET
166 **************************************************************************/
167 IPTR ChunkyImage__OM_SET(struct IClass *cl, Object *obj,
168 struct opSet *msg)
170 struct MUI_ChunkyImageData *data = INST_DATA(cl, obj);
171 struct TagItem *tags = msg->ops_AttrList;
172 struct TagItem *tag;
174 while ((tag = NextTagItem(&tags)) != NULL)
176 switch (tag->ti_Tag)
178 case MUIA_ChunkyImage_Pixels:
179 data->pixels = (UBYTE *) tag->ti_Data;
180 break;
182 case MUIA_ChunkyImage_Palette:
183 data->palette = (UBYTE *) tag->ti_Data;
184 break;
186 case MUIA_ChunkyImage_NumColors:
187 data->numcolors = (LONG) tag->ti_Data;
188 break;
190 case MUIA_ChunkyImage_Modulo:
191 data->modulo = (LONG) tag->ti_Data;
192 break;
194 case MUIA_Bitmap_Width:
195 data->width = (LONG) tag->ti_Data;
196 break;
198 case MUIA_Bitmap_Height:
199 data->height = (LONG) tag->ti_Data;
200 break;
205 return DoSuperMethodA(cl, obj, (Msg) msg);
208 /**************************************************************************
209 OM_GET
210 **************************************************************************/
211 IPTR ChunkyImage__OM_GET(struct IClass *cl, Object *obj,
212 struct opGet *msg)
214 #define STORE *(msg->opg_Storage)
216 struct MUI_ChunkyImageData *data = INST_DATA(cl, obj);
218 switch (msg->opg_AttrID)
220 case MUIA_ChunkyImage_Pixels:
221 STORE = (IPTR) data->pixels;
222 return TRUE;
224 case MUIA_ChunkyImage_Palette:
225 STORE = (IPTR) data->palette;
226 return TRUE;
228 case MUIA_ChunkyImage_NumColors:
229 STORE = (IPTR) data->numcolors;
230 return TRUE;
232 case MUIA_ChunkyImage_Modulo:
233 STORE = (IPTR) data->modulo;
234 return TRUE;
238 return DoSuperMethodA(cl, obj, (Msg) msg);
239 #undef STORE
242 /**************************************************************************
243 MUIM_Setup
244 **************************************************************************/
245 IPTR ChunkyImage__MUIM_Setup(struct IClass *cl, Object *obj,
246 struct MUIP_Setup *msg)
248 struct MUI_ChunkyImageData *data = INST_DATA(cl, obj);
250 if (!make_bitmap(cl, obj))
251 return FALSE;
253 set(obj, MUIA_Bitmap_Bitmap, (IPTR) data->bm);
255 if (data->palette32)
257 set(obj, MUIA_Bitmap_SourceColors, (IPTR) data->palette32);
260 if (!DoSuperMethodA(cl, obj, (Msg) msg))
262 set(obj, MUIA_Bitmap_Bitmap, NULL);
263 WaitBlit();
264 FreeBitMap(data->bm);
265 data->bm = NULL;
266 if (data->palette32)
268 set(obj, MUIA_Bitmap_SourceColors, NULL);
270 FreeVec(data->palette32);
271 data->palette32 = NULL;
273 return FALSE;
276 return TRUE;
279 /**************************************************************************
280 MUIM_Cleanup
281 **************************************************************************/
282 IPTR ChunkyImage__MUIM_Cleanup(struct IClass *cl, Object *obj,
283 struct MUIP_Cleanup *msg)
285 struct MUI_ChunkyImageData *data = INST_DATA(cl, obj);
286 IPTR retval;
288 retval = DoSuperMethodA(cl, obj, (Msg) msg);
289 if (data->bm)
291 set(obj, MUIA_Bitmap_Bitmap, NULL);
293 WaitBlit();
295 FreeBitMap(data->bm);
296 data->bm = NULL;
298 if (data->palette32)
300 set(obj, MUIA_Bitmap_SourceColors, NULL);
301 FreeVec(data->palette32);
302 data->palette32 = NULL;
306 return retval;
310 BOOPSI_DISPATCHER(IPTR, ChunkyImage_Dispatcher, cl, obj, msg)
312 switch (msg->MethodID)
314 case OM_NEW:
315 return ChunkyImage__OM_NEW(cl, obj, (struct opSet *)msg);
316 case OM_DISPOSE:
317 return ChunkyImage__OM_DISPOSE(cl, obj, msg);
318 case OM_SET:
319 return ChunkyImage__OM_SET(cl, obj, (struct opSet *)msg);
320 case OM_GET:
321 return ChunkyImage__OM_GET(cl, obj, (struct opGet *)msg);
322 case MUIM_Setup:
323 return ChunkyImage__MUIM_Setup(cl, obj, (struct MUIP_Setup *)msg);
324 case MUIM_Cleanup:
325 return ChunkyImage__MUIM_Cleanup(cl, obj,
326 (struct MUIP_Cleanup *)msg);
329 return DoSuperMethodA(cl, obj, msg);
331 BOOPSI_DISPATCHER_END
334 * Class descriptor.
336 const struct __MUIBuiltinClass _MUI_ChunkyImage_desc =
338 MUIC_ChunkyImage,
339 MUIC_Bitmap,
340 sizeof(struct MUI_ChunkyImageData),
341 (void *) ChunkyImage_Dispatcher