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_BodychunkData
25 LONG width
, height
, depth
;
30 static void planar2chunky(UBYTE
*src
, UBYTE
*dest
, WORD width
, WORD depth
,
34 UBYTE pmask
, dmask
= 1, notdmask
= ~1;
37 for (pl
= 0; pl
< depth
; pl
++)
45 for (x
= 0; x
< width
; x
++)
74 static UBYTE
*unpack_byterun1(UBYTE
*src
, UBYTE
*dest
, LONG unpackedsize
)
87 if (--unpackedsize
<= 0)
99 if (--unpackedsize
<= 0)
107 static BOOL
make_bitmap(struct IClass
*cl
, Object
*obj
)
109 struct MUI_BodychunkData
*data
= INST_DATA(cl
, obj
);
110 struct RastPort bmrp
, temprp
;
112 UBYTE
*bodyptr
, *unpackptr
;
118 (data
->height
< 1) ||
119 (data
->depth
< 1) || (data
->depth
> 8) || (data
->compression
> 1))
124 chunkyline
= AllocVec(2 * (data
->width
+ 16), MEMF_PUBLIC
| MEMF_CLEAR
);
128 unpackptr
= chunkyline
+ data
->width
+ 16;
131 AllocBitMap(data
->width
, data
->height
, data
->depth
, BMF_CLEAR
,
139 InitRastPort(&temprp
);
140 temprp
.BitMap
= AllocBitMap(data
->width
, 1, 1, 0, NULL
);
143 bmrp
.BitMap
= data
->bm
;
145 bodyptr
= data
->body
;
146 w16
= (data
->width
+ 15) & ~15;
149 totdepth
= data
->depth
+ ((data
->masking
== 1) ? 1 : 0);
150 bpl
= bpr
* totdepth
;
152 for (y
= 0; y
< data
->height
; y
++)
154 if (data
->compression
)
156 bodyptr
= unpack_byterun1(bodyptr
, unpackptr
, bpl
);
157 planar2chunky(unpackptr
, chunkyline
, data
->width
, data
->depth
,
162 planar2chunky(bodyptr
, chunkyline
, data
->width
, data
->depth
,
169 WritePixelLine8(&bmrp
, 0, y
, data
->width
, chunkyline
, &temprp
);
173 for (x
= 0; x
< data
->width
; x
++)
175 SetAPen(&bmrp
, chunkyline
[x
]);
176 WritePixel(&bmrp
, x
, y
);
184 FreeBitMap(temprp
.BitMap
);
192 /**************************************************************************
194 **************************************************************************/
195 IPTR
Bodychunk__OM_NEW(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
197 struct MUI_BodychunkData
*data
;
198 struct TagItem
*tag
, *tags
;
200 obj
= (Object
*) DoSuperMethodA(cl
, obj
, (Msg
) msg
);
204 data
= INST_DATA(cl
, obj
);
206 /* parse initial taglist */
208 for (tags
= msg
->ops_AttrList
; (tag
= NextTagItem(&tags
));)
212 case MUIA_Bodychunk_Body
:
213 data
->body
= (UBYTE
*) tag
->ti_Data
;
216 case MUIA_Bodychunk_Compression
:
217 data
->compression
= (UBYTE
) tag
->ti_Data
;
220 case MUIA_Bodychunk_Depth
:
221 data
->depth
= (LONG
) tag
->ti_Data
;
224 case MUIA_Bodychunk_Masking
:
225 data
->masking
= (UBYTE
) tag
->ti_Data
;
228 case MUIA_Bitmap_Width
:
229 data
->width
= (LONG
) tag
->ti_Data
;
232 case MUIA_Bitmap_Height
:
233 data
->height
= (LONG
) tag
->ti_Data
;
242 /**************************************************************************
244 **************************************************************************/
245 IPTR
Bodychunk__OM_DISPOSE(struct IClass
*cl
, Object
*obj
, Msg msg
)
247 struct MUI_BodychunkData
*data
= INST_DATA(cl
, obj
);
252 FreeBitMap(data
->bm
);
255 return DoSuperMethodA(cl
, obj
, msg
);
258 /**************************************************************************
260 **************************************************************************/
261 IPTR
Bodychunk__OM_SET(struct IClass
*cl
, Object
*obj
, struct opSet
*msg
)
263 struct MUI_BodychunkData
*data
= INST_DATA(cl
, obj
);
264 struct TagItem
*tags
= msg
->ops_AttrList
;
267 while ((tag
= NextTagItem(&tags
)) != NULL
)
271 case MUIA_Bodychunk_Body
:
272 data
->body
= (UBYTE
*) tag
->ti_Data
;
275 case MUIA_Bodychunk_Compression
:
276 data
->compression
= (UBYTE
) tag
->ti_Data
;
279 case MUIA_Bodychunk_Depth
:
280 data
->depth
= (LONG
) tag
->ti_Data
;
283 case MUIA_Bodychunk_Masking
:
284 data
->masking
= (UBYTE
) tag
->ti_Data
;
287 case MUIA_Bitmap_Width
:
288 data
->width
= (LONG
) tag
->ti_Data
;
291 case MUIA_Bitmap_Height
:
292 data
->height
= (LONG
) tag
->ti_Data
;
298 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
301 /**************************************************************************
303 **************************************************************************/
304 IPTR
Bodychunk__OM_GET(struct IClass
*cl
, Object
*obj
, struct opGet
*msg
)
306 #define STORE *(msg->opg_Storage)
308 struct MUI_BodychunkData
*data
= INST_DATA(cl
, obj
);
310 switch (msg
->opg_AttrID
)
312 case MUIA_Bodychunk_Body
:
313 STORE
= (IPTR
) data
->body
;
316 case MUIA_Bodychunk_Compression
:
317 STORE
= (IPTR
) data
->compression
;
320 case MUIA_Bodychunk_Depth
:
321 STORE
= (IPTR
) data
->depth
;
324 case MUIA_Bodychunk_Masking
:
325 STORE
= (IPTR
) data
->masking
;
330 return DoSuperMethodA(cl
, obj
, (Msg
) msg
);
334 /**************************************************************************
336 **************************************************************************/
337 IPTR
Bodychunk__MUIM_Setup(struct IClass
*cl
, Object
*obj
,
338 struct MUIP_Setup
*msg
)
340 struct MUI_BodychunkData
*data
= INST_DATA(cl
, obj
);
342 if (!make_bitmap(cl
, obj
))
345 set(obj
, MUIA_Bitmap_Bitmap
, (IPTR
) data
->bm
);
347 if (!DoSuperMethodA(cl
, obj
, (Msg
) msg
))
349 set(obj
, MUIA_Bitmap_Bitmap
, NULL
);
351 FreeBitMap(data
->bm
);
360 /**************************************************************************
362 **************************************************************************/
363 IPTR
Bodychunk__MUIM_Cleanup(struct IClass
*cl
, Object
*obj
,
364 struct MUIP_Cleanup
*msg
)
366 struct MUI_BodychunkData
*data
= INST_DATA(cl
, obj
);
369 retval
= DoSuperMethodA(cl
, obj
, (Msg
) msg
);
372 set(obj
, MUIA_Bitmap_Bitmap
, NULL
);
376 FreeBitMap(data
->bm
);
384 BOOPSI_DISPATCHER(IPTR
, Bodychunk_Dispatcher
, cl
, obj
, msg
)
386 switch (msg
->MethodID
)
389 return Bodychunk__OM_NEW(cl
, obj
, (struct opSet
*)msg
);
391 return Bodychunk__OM_DISPOSE(cl
, obj
, msg
);
393 return Bodychunk__OM_SET(cl
, obj
, (struct opSet
*)msg
);
395 return Bodychunk__OM_GET(cl
, obj
, (struct opGet
*)msg
);
397 return Bodychunk__MUIM_Setup(cl
, obj
, (struct MUIP_Setup
*)msg
);
399 return Bodychunk__MUIM_Cleanup(cl
, obj
, (struct MUIP_Cleanup
*)msg
);
402 return DoSuperMethodA(cl
, obj
, msg
);
405 BOOPSI_DISPATCHER_END
409 const struct __MUIBuiltinClass _MUI_Bodychunk_desc
=
413 sizeof(struct MUI_BodychunkData
),
414 (void *) Bodychunk_Dispatcher