Some fix for scrolling with lasso.
[tangerine.git] / workbench / libs / muimaster / classes / chunkyimage.c
blobdc39e1ee499c466db5e9f1b569bdf524655e27c3
1 /*
2 Copyright © 2002-2006, 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) ||
40 (data->numcolors > 256))
42 return FALSE;
45 if (data->palette)
47 data->palette32 = AllocVec(data->numcolors * 3 * sizeof(ULONG), MEMF_ANY);
48 if (!data->palette32) return FALSE;
50 if (data->palette32)
52 UBYTE *src = data->palette;
53 ULONG *dest = data->palette32;
54 WORD i;
56 for(i = 0; i < data->numcolors; i++)
58 *dest++ = ((ULONG)(*src++)) * 0x01010101;
59 *dest++ = ((ULONG)(*src++)) * 0x01010101;
60 *dest++ = ((ULONG)(*src++)) * 0x01010101;
65 for(depth = 1; (1L << depth) < data->numcolors; depth++)
69 data->bm = AllocBitMap(data->width, data->height, depth, BMF_CLEAR, NULL);
70 if (!data->bm)
72 if (data->palette32)
74 FreeVec(data->palette32);
75 data->palette32 = NULL;
77 return FALSE;
80 InitRastPort(&temprp);
81 temprp.BitMap = data->bm;
83 WriteChunkyPixels(&temprp,
86 data->width - 1,
87 data->height - 1,
88 data->pixels,
89 data->modulo);
91 DeinitRastPort(&temprp);
93 return TRUE;
96 /**************************************************************************
97 OM_NEW
98 **************************************************************************/
99 IPTR ChunkyImage__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
101 struct MUI_ChunkyImageData *data;
102 struct TagItem *tag, *tags;
104 obj = (Object *)DoSuperMethodA(cl, obj, (Msg)msg);
105 if (!obj) return FALSE;
107 data = INST_DATA(cl, obj);
109 /* parse initial taglist */
111 data->modulo = 0xFFFF;
113 for (tags = msg->ops_AttrList; (tag = NextTagItem((const struct TagItem**)&tags)); )
115 switch (tag->ti_Tag)
117 case MUIA_ChunkyImage_Pixels:
118 data->pixels = (UBYTE *)tag->ti_Data;
119 break;
121 case MUIA_ChunkyImage_Palette:
122 data->palette = (UBYTE *)tag->ti_Data;
123 break;
125 case MUIA_ChunkyImage_NumColors:
126 data->numcolors = (LONG)tag->ti_Data;
127 break;
129 case MUIA_ChunkyImage_Modulo:
130 data->modulo = (LONG)tag->ti_Data;
131 break;
133 case MUIA_Bitmap_Width:
134 data->width = (LONG)tag->ti_Data;
135 break;
137 case MUIA_Bitmap_Height:
138 data->height = (LONG)tag->ti_Data;
139 break;
144 if (data->modulo == 0xFFFF) data->modulo = data->width;
146 return (IPTR)obj;
149 /**************************************************************************
150 OM_DISPOSE
151 **************************************************************************/
152 IPTR ChunkyImage__OM_DISPOSE(struct IClass *cl, Object *obj, Msg msg)
154 struct MUI_ChunkyImageData *data = INST_DATA(cl, obj);
156 if (data->bm)
158 WaitBlit();
159 FreeBitMap(data->bm);
162 return DoSuperMethodA(cl, obj, msg);
165 /**************************************************************************
166 OM_SET
167 **************************************************************************/
168 IPTR ChunkyImage__OM_SET(struct IClass *cl, Object *obj, 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((const struct TagItem**)&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, struct opGet *msg)
213 #define STORE *(msg->opg_Storage)
215 struct MUI_ChunkyImageData *data = INST_DATA(cl, obj);
217 switch(msg->opg_AttrID)
219 case MUIA_ChunkyImage_Pixels:
220 STORE = (IPTR)data->pixels;
221 return TRUE;
223 case MUIA_ChunkyImage_Palette:
224 STORE = (IPTR)data->palette;
225 return TRUE;
227 case MUIA_ChunkyImage_NumColors:
228 STORE = (IPTR)data->numcolors;
229 return TRUE;
231 case MUIA_ChunkyImage_Modulo:
232 STORE = (IPTR)data->modulo;
233 return TRUE;
237 return DoSuperMethodA(cl, obj, (Msg)msg);
238 #undef STORE
241 /**************************************************************************
242 MUIM_Setup
243 **************************************************************************/
244 IPTR ChunkyImage__MUIM_Setup(struct IClass *cl, Object *obj, struct MUIP_Setup *msg)
246 struct MUI_ChunkyImageData *data = INST_DATA(cl, obj);
248 if (!make_bitmap(cl, obj)) return FALSE;
250 set(obj, MUIA_Bitmap_Bitmap, (IPTR)data->bm);
252 if (data->palette32)
254 set(obj, MUIA_Bitmap_SourceColors, (IPTR)data->palette32);
257 if (!DoSuperMethodA(cl, obj, (Msg)msg))
259 set(obj, MUIA_Bitmap_Bitmap, NULL);
260 WaitBlit();
261 FreeBitMap(data->bm);
262 data->bm = NULL;
263 if (data->palette32)
265 set(obj, MUIA_Bitmap_SourceColors, NULL);
267 FreeVec(data->palette32);
268 data->palette32 = NULL;
270 return FALSE;
273 return TRUE;
276 /**************************************************************************
277 MUIM_Cleanup
278 **************************************************************************/
279 IPTR ChunkyImage__MUIM_Cleanup(struct IClass *cl, Object *obj, struct MUIP_Cleanup *msg)
281 struct MUI_ChunkyImageData *data = INST_DATA(cl, obj);
282 IPTR retval;
284 retval = DoSuperMethodA(cl, obj, (Msg)msg);
285 if (data->bm)
287 set(obj, MUIA_Bitmap_Bitmap, NULL);
289 WaitBlit();
291 FreeBitMap(data->bm);
292 data->bm = NULL;
294 if (data->palette32)
296 set(obj, MUIA_Bitmap_SourceColors, NULL);
297 FreeVec(data->palette32);
298 data->palette32 = NULL;
302 return retval;
306 BOOPSI_DISPATCHER(IPTR, ChunkyImage_Dispatcher, cl, obj, msg)
308 switch (msg->MethodID)
310 case OM_NEW: return ChunkyImage__OM_NEW(cl, obj, (struct opSet *)msg);
311 case OM_DISPOSE: return ChunkyImage__OM_DISPOSE(cl, obj, msg);
312 case OM_SET: return ChunkyImage__OM_SET(cl, obj, (struct opSet *)msg);
313 case OM_GET: return ChunkyImage__OM_GET(cl, obj, (struct opGet *)msg);
314 case MUIM_Setup: return ChunkyImage__MUIM_Setup(cl, obj, (struct MUIP_Setup *)msg);
315 case MUIM_Cleanup: return ChunkyImage__MUIM_Cleanup(cl, obj, (struct MUIP_Cleanup *)msg);
318 return DoSuperMethodA(cl, obj, msg);
320 BOOPSI_DISPATCHER_END
323 * Class descriptor.
325 const struct __MUIBuiltinClass _MUI_ChunkyImage_desc = {
326 MUIC_ChunkyImage,
327 MUIC_Bitmap,
328 sizeof(struct MUI_ChunkyImageData),
329 (void*)ChunkyImage_Dispatcher