2 Copyright © 2002-2011, 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) || (data
->numcolors
> 256))
47 AllocVec(data
->numcolors
* 3 * sizeof(ULONG
), MEMF_ANY
);
53 UBYTE
*src
= data
->palette
;
54 ULONG
*dest
= data
->palette32
;
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
++)
71 AllocBitMap(data
->width
, data
->height
, depth
, BMF_CLEAR
, NULL
);
76 FreeVec(data
->palette32
);
77 data
->palette32
= NULL
;
82 InitRastPort(&temprp
);
83 temprp
.BitMap
= data
->bm
;
85 WriteChunkyPixels(&temprp
,
87 0, data
->width
- 1, data
->height
- 1, data
->pixels
, data
->modulo
);
92 /**************************************************************************
94 **************************************************************************/
95 IPTR
ChunkyImage__OM_NEW(struct IClass
*cl
, Object
*obj
,
98 struct MUI_ChunkyImageData
*data
;
99 struct TagItem
*tag
, *tags
;
101 obj
= (Object
*) DoSuperMethodA(cl
, obj
, (Msg
) msg
);
105 data
= INST_DATA(cl
, obj
);
107 /* parse initial taglist */
109 data
->modulo
= 0xFFFF;
111 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
));)
115 case MUIA_ChunkyImage_Pixels
:
116 data
->pixels
= (UBYTE
*) tag
->ti_Data
;
119 case MUIA_ChunkyImage_Palette
:
120 data
->palette
= (UBYTE
*) tag
->ti_Data
;
123 case MUIA_ChunkyImage_NumColors
:
124 data
->numcolors
= (LONG
) tag
->ti_Data
;
127 case MUIA_ChunkyImage_Modulo
:
128 data
->modulo
= (LONG
) tag
->ti_Data
;
131 case MUIA_Bitmap_Width
:
132 data
->width
= (LONG
) tag
->ti_Data
;
135 case MUIA_Bitmap_Height
:
136 data
->height
= (LONG
) tag
->ti_Data
;
142 if (data
->modulo
== 0xFFFF)
143 data
->modulo
= data
->width
;
148 /**************************************************************************
150 **************************************************************************/
151 IPTR
ChunkyImage__OM_DISPOSE(struct IClass
*cl
, Object
*obj
, Msg msg
)
153 struct MUI_ChunkyImageData
*data
= INST_DATA(cl
, obj
);
158 FreeBitMap(data
->bm
);
161 return DoSuperMethodA(cl
, obj
, msg
);
164 /**************************************************************************
166 **************************************************************************/
167 IPTR
ChunkyImage__OM_SET(struct IClass
*cl
, Object
*obj
,
170 struct MUI_ChunkyImageData
*data
= INST_DATA(cl
, obj
);
171 struct TagItem
*tags
= msg
->ops_AttrList
;
174 while ((tag
= NextTagItem(&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
,
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
;
224 case MUIA_ChunkyImage_Palette
:
225 STORE
= (IPTR
) data
->palette
;
228 case MUIA_ChunkyImage_NumColors
:
229 STORE
= (IPTR
) data
->numcolors
;
232 case MUIA_ChunkyImage_Modulo
:
233 STORE
= (IPTR
) data
->modulo
;
238 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
242 /**************************************************************************
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
))
253 set(obj
, MUIA_Bitmap_Bitmap
, (IPTR
) data
->bm
);
257 set(obj
, MUIA_Bitmap_SourceColors
, (IPTR
) data
->palette32
);
260 if (!DoSuperMethodA(cl
, obj
, (Msg
) msg
))
262 set(obj
, MUIA_Bitmap_Bitmap
, NULL
);
264 FreeBitMap(data
->bm
);
268 set(obj
, MUIA_Bitmap_SourceColors
, NULL
);
270 FreeVec(data
->palette32
);
271 data
->palette32
= NULL
;
279 /**************************************************************************
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
);
288 retval
= DoSuperMethodA(cl
, obj
, (Msg
) msg
);
291 set(obj
, MUIA_Bitmap_Bitmap
, NULL
);
295 FreeBitMap(data
->bm
);
300 set(obj
, MUIA_Bitmap_SourceColors
, NULL
);
301 FreeVec(data
->palette32
);
302 data
->palette32
= NULL
;
310 BOOPSI_DISPATCHER(IPTR
, ChunkyImage_Dispatcher
, cl
, obj
, msg
)
312 switch (msg
->MethodID
)
315 return ChunkyImage__OM_NEW(cl
, obj
, (struct opSet
*)msg
);
317 return ChunkyImage__OM_DISPOSE(cl
, obj
, msg
);
319 return ChunkyImage__OM_SET(cl
, obj
, (struct opSet
*)msg
);
321 return ChunkyImage__OM_GET(cl
, obj
, (struct opGet
*)msg
);
323 return ChunkyImage__MUIM_Setup(cl
, obj
, (struct MUIP_Setup
*)msg
);
325 return ChunkyImage__MUIM_Cleanup(cl
, obj
,
326 (struct MUIP_Cleanup
*)msg
);
329 return DoSuperMethodA(cl
, obj
, msg
);
331 BOOPSI_DISPATCHER_END
336 const struct __MUIBuiltinClass _MUI_ChunkyImage_desc
=
340 sizeof(struct MUI_ChunkyImageData
),
341 (void *) ChunkyImage_Dispatcher