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_BodychunkData
25 LONG width
, height
, depth
;
30 static void planar2chunky(UBYTE
*src
, UBYTE
*dest
, WORD width
, WORD depth
, LONG bpr
)
33 UBYTE pmask
, dmask
= 1, notdmask
= ~1;
36 for(pl
= 0; pl
< depth
; pl
++)
44 for(x
= 0; x
< width
; x
++)
66 dmask
<<= 1; notdmask
= ~dmask
;
72 static UBYTE
*unpack_byterun1(UBYTE
*src
, UBYTE
*dest
, LONG unpackedsize
)
85 if (--unpackedsize
<= 0) return src
;
96 if (--unpackedsize
<= 0) return src
;
103 static BOOL
make_bitmap(struct IClass
*cl
, Object
*obj
)
105 struct MUI_BodychunkData
*data
= INST_DATA(cl
, obj
);
106 struct RastPort bmrp
, temprp
;
108 UBYTE
*bodyptr
, *unpackptr
;
114 (data
->height
< 1) ||
117 (data
->compression
> 1) )
122 chunkyline
= AllocVec(2 * (data
->width
+ 16), MEMF_PUBLIC
| MEMF_CLEAR
);
123 if (!chunkyline
) return FALSE
;
125 unpackptr
= chunkyline
+ data
->width
+ 16;
127 data
->bm
= AllocBitMap(data
->width
, data
->height
, data
->depth
, BMF_CLEAR
, NULL
);
134 InitRastPort(&temprp
);
135 temprp
.BitMap
= AllocBitMap(data
->width
, 1, 1, 0, NULL
);
138 bmrp
.BitMap
= data
->bm
;
140 bodyptr
= data
->body
;
141 w16
= (data
->width
+ 15) & ~15;
144 totdepth
= data
->depth
+ ((data
->masking
== 1) ? 1 : 0);
145 bpl
= bpr
* totdepth
;
147 for(y
= 0; y
< data
->height
; y
++)
149 if (data
->compression
)
151 bodyptr
= unpack_byterun1(bodyptr
, unpackptr
, bpl
);
152 planar2chunky(unpackptr
, chunkyline
, data
->width
, data
->depth
, bpr
);
156 planar2chunky(bodyptr
, chunkyline
, data
->width
, data
->depth
, bpr
);
162 WritePixelLine8(&bmrp
, 0, y
, data
->width
, chunkyline
, &temprp
);
166 for(x
= 0; x
< data
->width
; x
++)
168 SetAPen(&bmrp
, chunkyline
[x
]);
169 WritePixel(&bmrp
, x
, y
);
174 DeinitRastPort(&temprp
);
175 DeinitRastPort(&bmrp
);
180 FreeBitMap(temprp
.BitMap
);
188 /**************************************************************************
190 **************************************************************************/
191 IPTR
Bodychunk__OM_NEW(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
193 struct MUI_BodychunkData
*data
;
194 struct TagItem
*tag
, *tags
;
196 obj
= (Object
*)DoSuperMethodA(cl
, obj
, (Msg
)msg
);
197 if (!obj
) return FALSE
;
199 data
= INST_DATA(cl
, obj
);
201 /* parse initial taglist */
203 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem((const struct TagItem
**)&tags
)); )
207 case MUIA_Bodychunk_Body
:
208 data
->body
= (UBYTE
*)tag
->ti_Data
;
211 case MUIA_Bodychunk_Compression
:
212 data
->compression
= (UBYTE
)tag
->ti_Data
;
215 case MUIA_Bodychunk_Depth
:
216 data
->depth
= (LONG
)tag
->ti_Data
;
219 case MUIA_Bodychunk_Masking
:
220 data
->masking
= (UBYTE
)tag
->ti_Data
;
223 case MUIA_Bitmap_Width
:
224 data
->width
= (LONG
)tag
->ti_Data
;
227 case MUIA_Bitmap_Height
:
228 data
->height
= (LONG
)tag
->ti_Data
;
237 /**************************************************************************
239 **************************************************************************/
240 IPTR
Bodychunk__OM_DISPOSE(struct IClass
*cl
, Object
*obj
, Msg msg
)
242 struct MUI_BodychunkData
*data
= INST_DATA(cl
, obj
);
247 FreeBitMap(data
->bm
);
250 return DoSuperMethodA(cl
, obj
, msg
);
253 /**************************************************************************
255 **************************************************************************/
256 IPTR
Bodychunk__OM_SET(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
258 struct MUI_BodychunkData
*data
= INST_DATA(cl
, obj
);
259 struct TagItem
*tags
= msg
->ops_AttrList
;
262 while ((tag
= NextTagItem((const struct TagItem
**)&tags
)) != NULL
)
266 case MUIA_Bodychunk_Body
:
267 data
->body
= (UBYTE
*)tag
->ti_Data
;
270 case MUIA_Bodychunk_Compression
:
271 data
->compression
= (UBYTE
)tag
->ti_Data
;
274 case MUIA_Bodychunk_Depth
:
275 data
->depth
= (LONG
)tag
->ti_Data
;
278 case MUIA_Bodychunk_Masking
:
279 data
->masking
= (UBYTE
)tag
->ti_Data
;
282 case MUIA_Bitmap_Width
:
283 data
->width
= (LONG
)tag
->ti_Data
;
286 case MUIA_Bitmap_Height
:
287 data
->height
= (LONG
)tag
->ti_Data
;
293 return DoSuperMethodA(cl
, obj
, (Msg
)msg
);
296 /**************************************************************************
298 **************************************************************************/
299 IPTR
Bodychunk__OM_GET(struct IClass
*cl
, Object
*obj
, struct opGet
*msg
)
301 #define STORE *(msg->opg_Storage)
303 struct MUI_BodychunkData
*data
= INST_DATA(cl
, obj
);
305 switch(msg
->opg_AttrID
)
307 case MUIA_Bodychunk_Body
:
308 STORE
= (IPTR
)data
->body
;
311 case MUIA_Bodychunk_Compression
:
312 STORE
= (IPTR
)data
->compression
;
315 case MUIA_Bodychunk_Depth
:
316 STORE
= (IPTR
)data
->depth
;
319 case MUIA_Bodychunk_Masking
:
320 STORE
= (IPTR
)data
->masking
;
325 return DoSuperMethodA(cl
, obj
, (Msg
)msg
);
329 /**************************************************************************
331 **************************************************************************/
332 IPTR
Bodychunk__MUIM_Setup(struct IClass
*cl
, Object
*obj
, struct MUIP_Setup
*msg
)
334 struct MUI_BodychunkData
*data
= INST_DATA(cl
, obj
);
336 if (!make_bitmap(cl
, obj
)) return FALSE
;
338 set(obj
, MUIA_Bitmap_Bitmap
, (IPTR
)data
->bm
);
340 if (!DoSuperMethodA(cl
, obj
, (Msg
)msg
))
342 set(obj
, MUIA_Bitmap_Bitmap
, NULL
);
344 FreeBitMap(data
->bm
);
353 /**************************************************************************
355 **************************************************************************/
356 IPTR
Bodychunk__MUIM_Cleanup(struct IClass
*cl
, Object
*obj
, struct MUIP_Cleanup
*msg
)
358 struct MUI_BodychunkData
*data
= INST_DATA(cl
, obj
);
361 retval
= DoSuperMethodA(cl
, obj
, (Msg
)msg
);
364 set(obj
, MUIA_Bitmap_Bitmap
, NULL
);
368 FreeBitMap(data
->bm
);
376 BOOPSI_DISPATCHER(IPTR
, Bodychunk_Dispatcher
, cl
, obj
, msg
)
378 switch (msg
->MethodID
)
380 case OM_NEW
: return Bodychunk__OM_NEW(cl
, obj
, (struct opSet
*)msg
);
381 case OM_DISPOSE
: return Bodychunk__OM_DISPOSE(cl
, obj
, msg
);
382 case OM_SET
: return Bodychunk__OM_SET(cl
, obj
, (struct opSet
*)msg
);
383 case OM_GET
: return Bodychunk__OM_GET(cl
, obj
, (struct opGet
*)msg
);
384 case MUIM_Setup
: return Bodychunk__MUIM_Setup(cl
, obj
, (struct MUIP_Setup
*)msg
);
385 case MUIM_Cleanup
: return Bodychunk__MUIM_Cleanup(cl
, obj
, (struct MUIP_Cleanup
*)msg
);
388 return DoSuperMethodA(cl
, obj
, msg
);
390 BOOPSI_DISPATCHER_END
395 const struct __MUIBuiltinClass _MUI_Bodychunk_desc
= {
398 sizeof(struct MUI_BodychunkData
),
399 (void*)Bodychunk_Dispatcher