2 Copyright � 1995-2013, The AROS Development Team. All rights reserved.
5 Desc: Graphics planar 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>
17 #include <graphics/gfx.h>
20 #include <hidd/graphics.h>
29 #include <aros/debug.h>
31 /****************************************************************************************/
33 #define _sd (&((struct atibase *)cl->UserData)->sd)
35 #undef HiddPCIDeviceAttrBase
36 #undef HiddGfxAttrBase
37 #undef HiddPixFmtAttrBase
38 #undef HiddSyncAttrBase
39 #undef HiddBitMapAttrBase
40 #define HiddPCIDeviceAttrBase (_sd->pciAttrBase)
41 #define HiddATIBitMapAttrBase (_sd->atiBitMapAttrBase)
42 #define HiddBitMapAttrBase (_sd->bitMapAttrBase)
43 #define HiddPixFmtAttrBase (_sd->pixFmtAttrBase)
44 #define HiddGfxAttrBase (_sd->gfxAttrBase)
45 #define HiddSyncAttrBase (_sd->syncAttrBase)
46 #define __IHidd_PlanarBM (_sd->planarAttrBase)
48 /****************************************************************************************/
50 OOP_Object
*ATIPlanBM__Root__New(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
)
52 IPTR width
, height
, depth
;
57 /* Set the bitmaps' pixelformat */
58 struct TagItem pf_tags
[] =
60 { aHidd_PixFmt_ColorModel
, vHidd_ColorModel_Palette
}, /* 0 */
61 { aHidd_PixFmt_Depth
, 0 }, /* 1 */
62 { aHidd_PixFmt_BytesPerPixel
, 0 }, /* 2 */
63 { aHidd_PixFmt_BitsPerPixel
, 0 }, /* 3 */
64 { aHidd_PixFmt_StdPixFmt
, 0 }, /* 4 */
65 { aHidd_PixFmt_CLUTShift
, 0 }, /* 5 */
66 { aHidd_PixFmt_CLUTMask
, 0x000000FF }, /* 6 */
67 { aHidd_PixFmt_RedMask
, 0x00FF0000 }, /* 7 */
68 { aHidd_PixFmt_GreenMask
, 0x0000FF00 }, /* 8 */
69 { aHidd_PixFmt_BlueMask
, 0x000000FF }, /* 9 */
70 { aHidd_PixFmt_BitMapType
, vHidd_BitMapType_Planar
},
75 struct planarbm_data
*data
;
79 o
=(OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
83 data
= OOP_INST_DATA(cl
, o
);
84 memset(data
, 0, sizeof (*data
));
87 /* Get some data about the dimensions of the bitmap */
89 data
->planes_alloced
= (BOOL
)GetTagData(aHidd_PlanarBM_AllocPlanes
, TRUE
, msg
->attrList
);
91 /* FIXME: Fix this hack */
92 /* Because this class is used to emulate Amiga bitmaps, we
93 have to see if it should have late initalisation
95 if (!data
->planes_alloced
)
96 return o
; /* Late initialization */
99 /* Not late initalization. Get some info on the bitmap */
100 OOP_GetAttr(o
, aHidd_BitMap_Width
, &width
);
101 OOP_GetAttr(o
, aHidd_BitMap_Height
, &height
);
102 OOP_GetAttr(o
, aHidd_BitMap_PixFmt
, (IPTR
*)p_pf
);
103 OOP_GetAttr(pf
, aHidd_PixFmt_Depth
, (IPTR
*)&depth
);
105 /* We cache some info */
106 data
->bytesperrow
= ((width
+ 31) & ~31) / 8;
112 /* Allocate memory for plane array */
113 data
->planes
= AllocVec(sizeof (UBYTE
*) * depth
, MEMF_ANY
|MEMF_CLEAR
);
114 if (NULL
== data
->planes
)
120 data
->planebuf_size
= depth
;
122 /* Allocate all the planes */
123 for ( i
= 0; i
< depth
&& ok
; i
++)
125 data
->planes
[i
] = AllocVec(height
* data
->bytesperrow
, MEMF_ANY
|MEMF_CLEAR
);
126 if (NULL
== data
->planes
[i
])
134 OOP_MethodID dispose_mid
;
136 dispose_mid
= OOP_GetMethodID(IID_Root
, moRoot_Dispose
);
137 OOP_CoerceMethod(cl
, o
, (OOP_Msg
)&dispose_mid
);
145 /****************************************************************************************/
147 VOID
ATIPlanBM__Root__Dispose(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
)
149 struct planarbm_data
*data
;
152 data
= OOP_INST_DATA(cl
, o
);
154 if (data
->planes_alloced
)
156 if (NULL
!= data
->planes
)
158 for (i
= 0; i
< data
->depth
; i
++)
160 FreeVec(data
->planes
[i
]);
162 FreeVec(data
->planes
);
166 OOP_DoSuperMethod(cl
, o
, msg
);
171 /****************************************************************************************/
173 VOID
ATIPlanBM__Hidd_BitMap__PutPixel(OOP_Class
*cl
, OOP_Object
*o
,
174 struct pHidd_BitMap_PutPixel
*msg
)
177 struct planarbm_data
*data
;
180 UBYTE pixel
, notpixel
;
183 data
= OOP_INST_DATA(cl
, o
);
185 /* bitmap in plane-mode */
186 plane
= data
->planes
;
187 offset
= msg
->x
/ 8 + msg
->y
* data
->bytesperrow
;
188 pixel
= 128 >> (msg
->x
% 8);
192 for(i
= 0; i
< data
->depth
; i
++, mask
<<=1, plane
++)
194 if ((*plane
!= NULL
) && (*plane
!= (UBYTE
*)-1))
196 if(msg
->pixel
& mask
)
198 *(*plane
+ offset
) = *(*plane
+ offset
) | pixel
;
202 *(*plane
+ offset
) = *(*plane
+ offset
) & notpixel
;
208 /****************************************************************************************/
210 ULONG
ATIPlanBM__Hidd_BitMap__GetPixel(OOP_Class
*cl
, OOP_Object
*o
,
211 struct pHidd_BitMap_GetPixel
*msg
)
213 struct planarbm_data
*data
;
220 data
= OOP_INST_DATA(cl
, o
);
222 plane
= data
->planes
;
223 offset
= msg
->x
/ 8 + msg
->y
* data
->bytesperrow
;
224 pixel
= 128 >> (msg
->x
% 8);
227 for(i
= 0; i
< data
->depth
; i
++, plane
++)
230 if (*plane
== (UBYTE
*)-1)
232 retval
= retval
| (1 << i
);
234 else if (*plane
!= NULL
)
236 if(*(*plane
+ offset
) & pixel
)
238 retval
= retval
| (1 << i
);
246 /****************************************************************************************/
248 VOID
ATIPlanBM__Hidd_BitMap__PutImage(OOP_Class
*cl
, OOP_Object
*o
,
249 struct pHidd_BitMap_PutImage
*msg
)
252 UBYTE
*pixarray
= (UBYTE
*)msg
->pixels
;
255 struct planarbm_data
*data
;
257 if ((msg
->pixFmt
!= vHidd_StdPixFmt_Native
) &&
258 (msg
->pixFmt
!= vHidd_StdPixFmt_Native32
))
260 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
264 data
= OOP_INST_DATA(cl
, o
);
266 planeoffset
= msg
->y
* data
->bytesperrow
+ msg
->x
/ 8;
268 for(y
= 0; y
< msg
->height
; y
++)
272 case vHidd_StdPixFmt_Native
:
274 UBYTE
*src
= pixarray
;
276 plane
= data
->planes
;
278 for(d
= 0; d
< data
->depth
; d
++)
280 ULONG dmask
= 1L << d
;
281 ULONG pmask
= 0x80 >> (msg
->x
& 7);
284 if (pl
== (UBYTE
*)-1) continue;
285 if (pl
== NULL
) continue;
289 for(x
= 0; x
< msg
->width
; x
++)
310 } /* for(x = 0; x < msg->width; x++) */
314 } /* for(d = 0; d < data->depth; d++) */
316 pixarray
+= msg
->modulo
;
317 planeoffset
+= data
->bytesperrow
;
321 case vHidd_StdPixFmt_Native32
:
323 HIDDT_Pixel
*src
= (HIDDT_Pixel
*)pixarray
;
325 plane
= data
->planes
;
327 for(d
= 0; d
< data
->depth
; d
++)
329 ULONG dmask
= 1L << d
;
330 ULONG pmask
= 0x80 >> (msg
->x
& 7);
333 if (pl
== (UBYTE
*)-1) continue;
334 if (pl
== NULL
) continue;
338 for(x
= 0; x
< msg
->width
; x
++)
359 } /* for(x = 0; x < msg->width; x++) */
363 } /* for(d = 0; d < data->depth; d++) */
365 pixarray
+= msg
->modulo
;
366 planeoffset
+= data
->bytesperrow
;
371 } /* switch(msg->pixFmt) */
373 } /* for(y = 0; y < msg->height; y++) */
376 /****************************************************************************************/
378 VOID
ATIPlanBM__Hidd_BitMap__PutImageLUT(OOP_Class
*cl
, OOP_Object
*o
,
379 struct pHidd_BitMap_PutImageLUT
*msg
)
382 UBYTE
*pixarray
= (UBYTE
*)msg
->pixels
;
385 struct planarbm_data
*data
;
387 data
= OOP_INST_DATA(cl
, o
);
389 planeoffset
= msg
->y
* data
->bytesperrow
+ msg
->x
/ 8;
391 for(y
= 0; y
< msg
->height
; y
++)
393 UBYTE
*src
= pixarray
;
395 plane
= data
->planes
;
397 for(d
= 0; d
< data
->depth
; d
++)
399 ULONG dmask
= 1L << d
;
400 ULONG pmask
= 0x80 >> (msg
->x
& 7);
403 if (pl
== (UBYTE
*)-1) continue;
404 if (pl
== NULL
) continue;
408 for(x
= 0; x
< msg
->width
; x
++)
429 } /* for(x = 0; x < msg->width; x++) */
433 } /* for(d = 0; d < data->depth; d++) */
435 pixarray
+= msg
->modulo
;
436 planeoffset
+= data
->bytesperrow
;
438 } /* for(y = 0; y < msg->height; y++) */
441 /****************************************************************************************/
443 VOID
ATIPlanBM__Hidd_BitMap__GetImageLUT(OOP_Class
*cl
, OOP_Object
*o
,
444 struct pHidd_BitMap_GetImageLUT
*msg
)
447 UBYTE
*pixarray
= (UBYTE
*)msg
->pixels
;
450 struct planarbm_data
*data
;
453 data
= OOP_INST_DATA(cl
, o
);
455 planeoffset
= msg
->y
* data
->bytesperrow
+ msg
->x
/ 8;
458 for(d
= 0; d
< data
->depth
; d
++)
460 if (data
->planes
[d
] == (UBYTE
*)-1)
462 prefill
|= (1L << d
);
466 for(y
= 0; y
< msg
->height
; y
++)
468 UBYTE
*dest
= pixarray
;
470 plane
= data
->planes
;
472 for(x
= 0; x
< msg
->width
; x
++)
477 for(d
= 0; d
< data
->depth
; d
++)
479 ULONG dmask
= 1L << d
;
480 ULONG pmask
= 0x80 >> (msg
->x
& 7);
483 if (pl
== (UBYTE
*)-1) continue;
484 if (pl
== NULL
) continue;
488 for(x
= 0; x
< msg
->width
; x
++)
509 } /* for(x = 0; x < msg->width; x++) */
513 } /* for(d = 0; d < data->depth; d++) */
515 pixarray
+= msg
->modulo
;
516 planeoffset
+= data
->bytesperrow
;
518 } /* for(y = 0; y < msg->height; y++) */
522 /****************************************************************************************/
524 VOID
ATIPlanBM__Hidd_BitMap__BlitColorExpansion(OOP_Class
*cl
, OOP_Object
*o
,
525 struct pHidd_BitMap_BlitColorExpansion
*msg
)
530 ULONG planeoffset
/*, maskoffset*/;
533 OOP_Object
*gc
= msg
->gc
;
534 struct planarbm_data
*data
, *maskdata
;
536 data
= OOP_INST_DATA(cl
, o
);
538 cemd
= GC_COLEXP(gc
);
542 opaque
= (cemd
& vHidd_GC_ColExp_Opaque
) ? TRUE
: FALSE
;
544 planeoffset
= msg
->destY
* data
->bytesperrow
+ msg
->destX
/ 8;
546 if (OOP_OCLASS(msg
->srcBitMap
) == cl
)
548 /* srcBitMap is a planarbm class object */
550 maskdata
= OOP_INST_DATA(cl
, msg
->srcBitMap
);
551 mask
= maskdata
->planes
[0];
552 mask
+= msg
->srcY
* maskdata
->bytesperrow
+ msg
->srcX
/ 8;
554 for(y
= 0; y
< msg
->height
; y
++)
556 plane
= data
->planes
;
558 for(d
= 0; d
< data
->depth
; d
++)
560 ULONG dmask
= 1L << d
;
561 ULONG pmask
= 0x80 >> (msg
->destX
& 7);
562 ULONG mmask
= 0x80 >> (msg
->srcX
& 7);
563 BOOL fgset
= (fg
& dmask
) ? TRUE
: FALSE
;
564 BOOL bgset
= (bg
& dmask
) ? TRUE
: FALSE
;
569 if (pl
== (UBYTE
*)-1) continue;
570 if (pl
== NULL
) continue;
574 for(x
= 0; x
< msg
->width
; x
++)
611 } /* for(x = 0; x < msg->width; x++) */
615 } /* for(d = 0; d < data->depth; d++) */
617 mask
+= maskdata
->bytesperrow
;
618 planeoffset
+= data
->bytesperrow
;
620 } /* for(y = 0; y < msg->height; y++) */
622 } /* if (OOP_OCLASS(msg->srcBitMap) == cl) */
625 HIDDT_Pixel
*maskline
;
627 maskline
= AllocVec(msg
->width
* sizeof(HIDDT_Pixel
), MEMF_PUBLIC
);
630 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
634 for(y
= 0; y
< msg
->height
; y
++)
636 plane
= data
->planes
;
638 struct pHidd_BitMap_GetImage __m
= {
646 vHidd_StdPixFmt_Native32
649 OOP_DoMethod(msg
->srcBitMap
, (OOP_Msg
)m
);
651 for(d
= 0; d
< data
->depth
; d
++)
653 ULONG dmask
= 1L << d
;
654 ULONG pmask
= 0x80 >> (msg
->destX
& 7);
655 BOOL fgset
= (fg
& dmask
) ? TRUE
: FALSE
;
656 BOOL bgset
= (bg
& dmask
) ? TRUE
: FALSE
;
660 if (pl
== (UBYTE
*)-1) continue;
661 if (pl
== NULL
) continue;
665 for(x
= 0; x
< msg
->width
; x
++)
692 } /* for(x = 0; x < msg->width; x++) */
696 } /* for(d = 0; d < data->depth; d++) */
698 planeoffset
+= data
->bytesperrow
;
700 } /* for(y = 0; y < msg->height; y++) */
704 } /* if (OOP_OCLASS(msg->srcBitMap) == cl) else ... */
708 /****************************************************************************************/
710 BOOL
ATIPlanBM__Hidd_PlanarBM__SetBitMap(OOP_Class
*cl
, OOP_Object
*o
,
711 struct pHidd_PlanarBM_SetBitMap
*msg
)
713 struct planarbm_data
*data
;
716 struct TagItem pftags
[] =
718 { aHidd_PixFmt_Depth
, 0UL }, /* 0 */
719 { aHidd_PixFmt_BitsPerPixel
, 0UL }, /* 1 */
720 { aHidd_PixFmt_BytesPerPixel
, 1UL }, /* 2 */
721 { aHidd_PixFmt_ColorModel
, vHidd_ColorModel_Palette
}, /* 3 */
722 { aHidd_PixFmt_BitMapType
, vHidd_BitMapType_Planar
}, /* 4 */
723 { aHidd_PixFmt_CLUTShift
, 0UL }, /* 5 */
724 { aHidd_PixFmt_CLUTMask
, 0x000000FF }, /* 6 */
725 { aHidd_PixFmt_RedMask
, 0x00FF0000 }, /* 7 */
726 { aHidd_PixFmt_GreenMask
, 0x0000FF00 }, /* 8 */
727 { aHidd_PixFmt_BlueMask
, 0x000000FF }, /* 9 */
728 { TAG_DONE
, 0UL } /* 7 */
730 struct TagItem bmtags
[] =
732 { aHidd_BitMap_Width
, 0UL },
733 { aHidd_BitMap_Height
, 0UL },
739 data
= OOP_INST_DATA(cl
, o
);
742 if (data
->planes_alloced
)
744 D(bug(" !!!!! PlanarBM: Trying to set bitmap in one that allready has planes allocated\n"));
748 /* Check if plane array allready allocated */
749 if (NULL
!= data
->planes
)
751 if (bm
->Depth
> data
->planebuf_size
)
753 FreeVec(data
->planes
);
758 if (NULL
== data
->planes
)
760 data
->planes
= AllocVec(sizeof (UBYTE
*) * bm
->Depth
, MEMF_CLEAR
);
762 if (NULL
== data
->planes
)
765 data
->planebuf_size
= bm
->Depth
;
769 /* Update the planes */
770 for (i
= 0; i
< data
->planebuf_size
; i
++)
773 data
->planes
[i
] = bm
->Planes
[i
];
775 data
->planes
[i
] = NULL
;
778 data
->depth
= bm
->Depth
;
779 data
->bytesperrow
= bm
->BytesPerRow
;
780 data
->rows
= bm
->Rows
;
782 pftags
[0].ti_Data
= bm
->Depth
; /* PixFmt_Depth */
783 pftags
[1].ti_Data
= bm
->Depth
; /* PixFmt_BitsPerPixel */
785 bmtags
[0].ti_Data
= bm
->BytesPerRow
* 8;
786 bmtags
[1].ti_Data
= bm
->Rows
;
787 bmtags
[2].ti_Data
= (IPTR
)pftags
;
789 struct pHidd_BitMap_SetBitMapTags
{
791 struct TagItem
*tags
;
793 OOP_GetMethodID(IID_Hidd_BitMap
, num_Hidd_BitMap_Methods
),
797 /* Call private bitmap method to update superclass */
798 if (!OOP_DoMethod(o
, (OOP_Msg
)m
))
802 for (i
= 0; i
< data
->planebuf_size
; i
++)
804 data
->planes
[i
] = NULL
;
811 /****************************************************************************************/