2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Graphics chunky bitmap class implementation.
9 /****************************************************************************************/
11 #include <proto/exec.h>
12 #include <proto/utility.h>
13 #include <proto/oop.h>
15 #include <exec/memory.h>
16 #include <utility/tagitem.h>
19 #include <hidd/graphics.h>
21 #include "graphics_intern.h"
26 #include <aros/debug.h>
28 /****************************************************************************************/
30 OOP_Object
*CBM__Root__New(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
)
32 struct chunkybm_data
*data
;
37 UBYTE alignoffset
= 15;
46 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
50 /* Initialize the instance data to 0 */
51 data
= OOP_INST_DATA(cl
, o
);
52 memset(data
, 0, sizeof (*data
));
54 OOP_GetAttr(o
, aHidd_BitMap_PixFmt
, (IPTR
*)p_pf
);
55 OOP_GetAttr(o
, aHidd_BitMap_Width
, &width
);
56 OOP_GetAttr(o
, aHidd_BitMap_Height
, &height
);
57 /* Get some dimensions of the bitmap */
58 OOP_GetAttr(pf
, aHidd_PixFmt_BytesPerPixel
, &bytesperpixel
);
60 width
= (width
+ 15) & ~15;
62 data
->bytesperpixel
= bytesperpixel
;
63 data
->bytesperrow
= data
->bytesperpixel
* width
;
65 data
->buffer
= AllocVec(height
* data
->bytesperrow
, MEMF_ANY
|MEMF_CLEAR
);
66 if (NULL
== data
->buffer
)
69 /* free all on error */
73 OOP_MethodID dispose_mid
= OOP_GetMethodID(IID_Root
, moRoot_Dispose
);
74 if(o
) OOP_CoerceMethod(cl
, o
, (OOP_Msg
)&dispose_mid
);
82 /****************************************************************************************/
84 void CBM__Root__Dispose(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
)
86 struct chunkybm_data
*data
;
88 data
= OOP_INST_DATA(cl
, o
);
90 if (NULL
!= data
->buffer
)
91 FreeVec(data
->buffer
);
93 OOP_DoSuperMethod(cl
, o
, msg
);
98 /****************************************************************************************/
100 VOID
CBM__Hidd_BitMap__PutPixel(OOP_Class
*cl
, OOP_Object
*o
,
101 struct pHidd_BitMap_PutPixel
*msg
)
105 struct chunkybm_data
*data
;
107 data
= OOP_INST_DATA(cl
, o
);
109 /* bitmap in chunky-mode */
110 dest
= data
->buffer
+ msg
->x
* data
->bytesperpixel
+ msg
->y
* data
->bytesperrow
;
112 switch(data
->bytesperpixel
)
115 *((UBYTE
*) dest
) = (UBYTE
) msg
->pixel
;
119 *((UWORD
*) dest
) = (UWORD
) msg
->pixel
;
124 dest
[0] = (UBYTE
)(msg
->pixel
>> 16) & 0x000000FF;
125 dest
[1] = (UBYTE
)(msg
->pixel
>> 8) & 0x000000FF;
126 dest
[2] = (UBYTE
)msg
->pixel
& 0x000000FF;
128 dest
[0] = (UBYTE
)msg
->pixel
& 0x000000FF;
129 dest
[1] = (UBYTE
)(msg
->pixel
>> 8) & 0x000000FF;
130 dest
[2] = (UBYTE
)(msg
->pixel
>> 16) & 0x000000FF;
134 /* if (1 == ( ((IPTR)dest) & 1) )
136 *((UBYTE *) dest++) = (UBYTE) msg->pixel >> 16;
137 *((UWORD *) dest ) = (UWORD) msg->pixel;
141 *((UWORD *) dest++) = (UWORD) msg->pixel >> 8;
142 *((UBYTE *) dest ) = (UBYTE) msg->pixel;
147 *((ULONG
*) dest
) = (ULONG
) msg
->pixel
;
153 /****************************************************************************************/
155 ULONG
CBM__Hidd_BitMap__GetPixel(OOP_Class
*cl
, OOP_Object
*o
,
156 struct pHidd_BitMap_GetPixel
*msg
)
158 HIDDT_Pixel retval
= 0;
160 struct chunkybm_data
*data
;
162 data
= OOP_INST_DATA(cl
, o
);
164 src
= data
->buffer
+ msg
->x
* data
->bytesperpixel
+ msg
->y
* data
->bytesperrow
;
166 switch(data
->bytesperpixel
)
169 retval
= (HIDDT_Pixel
) *((UBYTE
*) src
);
173 retval
= (HIDDT_Pixel
) *((UWORD
*) src
);
178 retval
= (HIDDT_Pixel
) (src
[0] << 16) + (src
[1] << 8) + src
[2];
180 retval
= (HIDDT_Pixel
) (src
[2] << 16) + (src
[1] << 8) + src
[0];
184 //(*((UBYTE *) src++) << 16) | *((UWORD *) src));
188 retval
= ((ULONG
) *((ULONG
*) src
));
195 /****************************************************************************************/
197 VOID
CBM__Hidd_BitMap__FillRect(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_DrawRect
*msg
)
199 struct chunkybm_data
*data
=OOP_INST_DATA(cl
, o
);
200 HIDDT_Pixel fg
= GC_FG(msg
->gc
);
201 HIDDT_DrawMode mode
= GC_DRMD(msg
->gc
);
204 mod
= data
->bytesperrow
;
208 case vHidd_GC_DrawMode_Copy
:
209 switch(data
->bytesperpixel
)
212 HIDD_BM_FillMemRect8(o
,
223 HIDD_BM_FillMemRect16(o
,
234 HIDD_BM_FillMemRect24(o
,
245 HIDD_BM_FillMemRect32(o
,
258 case vHidd_GC_DrawMode_Invert
:
259 HIDD_BM_InvertMemRect(o
,
261 msg
->minX
* data
->bytesperpixel
,
263 msg
->maxX
* data
->bytesperpixel
+ data
->bytesperpixel
- 1,
269 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
276 /****************************************************************************************/
278 VOID
CBM__Hidd_BitMap__PutImage(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutImage
*msg
)
280 struct chunkybm_data
*data
= OOP_INST_DATA(cl
, o
);
284 case vHidd_StdPixFmt_Native
:
285 switch(data
->bytesperpixel
)
288 HIDD_BM_CopyMemBox8(o
,
302 HIDD_BM_CopyMemBox16(o
,
316 HIDD_BM_CopyMemBox24(o
,
330 HIDD_BM_CopyMemBox32(o
,
343 } /* switch(data->bytesperpixel) */
346 case vHidd_StdPixFmt_Native32
:
347 switch(data
->bytesperpixel
)
350 HIDD_BM_PutMem32Image8(o
,
362 HIDD_BM_PutMem32Image16(o
,
374 HIDD_BM_PutMem32Image24(o
,
386 HIDD_BM_CopyMemBox32(o
,
399 } /* switch(data->bytesperpixel) */
403 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
406 } /* switch(msg->pixFmt) */
410 /****************************************************************************************/
412 VOID
CBM__Hidd_BitMap__GetImage(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_GetImage
*msg
)
414 struct chunkybm_data
*data
= OOP_INST_DATA(cl
, o
);
418 case vHidd_StdPixFmt_Native
:
419 switch(data
->bytesperpixel
)
422 HIDD_BM_CopyMemBox8(o
,
436 HIDD_BM_CopyMemBox16(o
,
450 HIDD_BM_CopyMemBox24(o
,
464 HIDD_BM_CopyMemBox32(o
,
477 } /* switch(data->bytesperpix) */
480 case vHidd_StdPixFmt_Native32
:
481 switch(data
->bytesperpixel
)
484 HIDD_BM_GetMem32Image8(o
,
496 HIDD_BM_GetMem32Image16(o
,
508 HIDD_BM_GetMem32Image24(o
,
520 HIDD_BM_CopyMemBox32(o
,
533 } /* switch(data->bytesperpixel) */
537 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
540 } /* switch(msg->pixFmt) */
544 /****************************************************************************************/
546 VOID
CBM__Hidd_BitMap__PutImageLUT(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutImageLUT
*msg
)
548 struct chunkybm_data
*data
= OOP_INST_DATA(cl
, o
);
550 switch(data
->bytesperpixel
)
553 HIDD_BM_CopyLUTMemBox16(o
,
568 HIDD_BM_CopyLUTMemBox24(o
,
583 HIDD_BM_CopyLUTMemBox32(o
,
598 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
600 } /* switch(data->bytesperpixel) */
604 /****************************************************************************************/
606 VOID
CBM__Hidd_BitMap__BlitColorExpansion(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_BlitColorExpansion
*msg
)
608 struct chunkybm_data
*data
= OOP_INST_DATA(cl
, o
);
609 HIDDT_Pixel fg
, bg
, pix
;
618 cemd
= GC_COLEXP(msg
->gc
);
620 bpp
= data
->bytesperpixel
;
622 mem
= data
->buffer
+ msg
->destY
* data
->bytesperrow
+ msg
->destX
* bpp
;
623 mod
= data
->bytesperrow
- msg
->width
* bpp
;
625 opaque
= (cemd
& vHidd_GC_ColExp_Opaque
) ? TRUE
: FALSE
;
627 for (y
= 0; y
< msg
->height
; y
++)
629 for (x
= 0; x
< msg
->width
; x
++)
633 is_set
= HIDD_BM_GetPixel(msg
->srcBitMap
, x
+ msg
->srcX
, y
+ msg
->srcY
);
655 *((UWORD
*)mem
) = pix
;
673 *((ULONG
*)mem
) = pix
;
687 /****************************************************************************************/
689 VOID
CBM__Hidd_BitMap__PutTemplate(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutTemplate
*msg
)
691 struct chunkybm_data
*data
= OOP_INST_DATA(cl
, o
);
693 switch(data
->bytesperpixel
)
696 HIDD_BM_PutMemTemplate8(o
,
707 msg
->inverttemplate
);
711 HIDD_BM_PutMemTemplate16(o
,
722 msg
->inverttemplate
);
726 HIDD_BM_PutMemTemplate24(o
,
737 msg
->inverttemplate
);
741 HIDD_BM_PutMemTemplate32(o
,
752 msg
->inverttemplate
);
756 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
759 } /* switch(data->bytesperpixel) */
763 /****************************************************************************************/
765 VOID
CBM__Hidd_BitMap__PutPattern(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutPattern
*msg
)
767 struct chunkybm_data
*data
= OOP_INST_DATA(cl
, o
);
769 switch(data
->bytesperpixel
)
772 HIDD_BM_PutMemPattern8(o
,
793 HIDD_BM_PutMemPattern16(o
,
814 HIDD_BM_PutMemPattern24(o
,
835 HIDD_BM_PutMemPattern32(o
,
856 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
859 } /* switch(data->bytesperpixel) */
863 /****************************************************************************************/