2 Copyright © 2002-2006, The AROS Development Team. All rights reserved.
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>
16 #include "muimaster_intern.h"
19 extern struct Library
*MUIMasterBase
;
21 struct MUI_ChunkyImageData
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
;
39 (data
->numcolors
< 1) ||
40 (data
->numcolors
> 256))
47 data
->palette32
= AllocVec(data
->numcolors
* 3 * sizeof(ULONG
), MEMF_ANY
);
48 if (!data
->palette32
) return FALSE
;
52 UBYTE
*src
= data
->palette
;
53 ULONG
*dest
= data
->palette32
;
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
);
74 FreeVec(data
->palette32
);
75 data
->palette32
= NULL
;
80 InitRastPort(&temprp
);
81 temprp
.BitMap
= data
->bm
;
83 WriteChunkyPixels(&temprp
,
91 DeinitRastPort(&temprp
);
96 /**************************************************************************
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
)); )
117 case MUIA_ChunkyImage_Pixels
:
118 data
->pixels
= (UBYTE
*)tag
->ti_Data
;
121 case MUIA_ChunkyImage_Palette
:
122 data
->palette
= (UBYTE
*)tag
->ti_Data
;
125 case MUIA_ChunkyImage_NumColors
:
126 data
->numcolors
= (LONG
)tag
->ti_Data
;
129 case MUIA_ChunkyImage_Modulo
:
130 data
->modulo
= (LONG
)tag
->ti_Data
;
133 case MUIA_Bitmap_Width
:
134 data
->width
= (LONG
)tag
->ti_Data
;
137 case MUIA_Bitmap_Height
:
138 data
->height
= (LONG
)tag
->ti_Data
;
144 if (data
->modulo
== 0xFFFF) data
->modulo
= data
->width
;
149 /**************************************************************************
151 **************************************************************************/
152 IPTR
ChunkyImage__OM_DISPOSE(struct IClass
*cl
, Object
*obj
, Msg msg
)
154 struct MUI_ChunkyImageData
*data
= INST_DATA(cl
, obj
);
159 FreeBitMap(data
->bm
);
162 return DoSuperMethodA(cl
, obj
, msg
);
165 /**************************************************************************
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
;
174 while ((tag
= NextTagItem((const struct TagItem
**)&tags
)) != NULL
)
178 case MUIA_ChunkyImage_Pixels
:
179 data
->pixels
= (UBYTE
*)tag
->ti_Data
;
182 case MUIA_ChunkyImage_Palette
:
183 data
->palette
= (UBYTE
*)tag
->ti_Data
;
186 case MUIA_ChunkyImage_NumColors
:
187 data
->numcolors
= (LONG
)tag
->ti_Data
;
190 case MUIA_ChunkyImage_Modulo
:
191 data
->modulo
= (LONG
)tag
->ti_Data
;
194 case MUIA_Bitmap_Width
:
195 data
->width
= (LONG
)tag
->ti_Data
;
198 case MUIA_Bitmap_Height
:
199 data
->height
= (LONG
)tag
->ti_Data
;
205 return DoSuperMethodA(cl
, obj
, (Msg
)msg
);
208 /**************************************************************************
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
;
223 case MUIA_ChunkyImage_Palette
:
224 STORE
= (IPTR
)data
->palette
;
227 case MUIA_ChunkyImage_NumColors
:
228 STORE
= (IPTR
)data
->numcolors
;
231 case MUIA_ChunkyImage_Modulo
:
232 STORE
= (IPTR
)data
->modulo
;
237 return DoSuperMethodA(cl
, obj
, (Msg
)msg
);
241 /**************************************************************************
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
);
254 set(obj
, MUIA_Bitmap_SourceColors
, (IPTR
)data
->palette32
);
257 if (!DoSuperMethodA(cl
, obj
, (Msg
)msg
))
259 set(obj
, MUIA_Bitmap_Bitmap
, NULL
);
261 FreeBitMap(data
->bm
);
265 set(obj
, MUIA_Bitmap_SourceColors
, NULL
);
267 FreeVec(data
->palette32
);
268 data
->palette32
= NULL
;
276 /**************************************************************************
278 **************************************************************************/
279 IPTR
ChunkyImage__MUIM_Cleanup(struct IClass
*cl
, Object
*obj
, struct MUIP_Cleanup
*msg
)
281 struct MUI_ChunkyImageData
*data
= INST_DATA(cl
, obj
);
284 retval
= DoSuperMethodA(cl
, obj
, (Msg
)msg
);
287 set(obj
, MUIA_Bitmap_Bitmap
, NULL
);
291 FreeBitMap(data
->bm
);
296 set(obj
, MUIA_Bitmap_SourceColors
, NULL
);
297 FreeVec(data
->palette32
);
298 data
->palette32
= NULL
;
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
325 const struct __MUIBuiltinClass _MUI_ChunkyImage_desc
= {
328 sizeof(struct MUI_ChunkyImageData
),
329 (void*)ChunkyImage_Dispatcher