2 Copyright � 1995-2001, The AROS Development Team. All rights reserved.
3 $Id: planarbm.c 30792 2009-03-07 22:40:04Z neil $
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 HiddNVidiaBitMapAttrBase (_sd->nvBitMapAttrBase)
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 #warning 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 if (NULL
!= data
->planes
[i
])
162 FreeVec(data
->planes
[i
]);
165 FreeVec(data
->planes
);
169 OOP_DoSuperMethod(cl
, o
, msg
);
174 /****************************************************************************************/
176 VOID
ATIPlanBM__Hidd_BitMap__PutPixel(OOP_Class
*cl
, OOP_Object
*o
,
177 struct pHidd_BitMap_PutPixel
*msg
)
180 struct planarbm_data
*data
;
183 UBYTE pixel
, notpixel
;
186 data
= OOP_INST_DATA(cl
, o
);
188 /* bitmap in plane-mode */
189 plane
= data
->planes
;
190 offset
= msg
->x
/ 8 + msg
->y
* data
->bytesperrow
;
191 pixel
= 128 >> (msg
->x
% 8);
195 for(i
= 0; i
< data
->depth
; i
++, mask
<<=1, plane
++)
197 if ((*plane
!= NULL
) && (*plane
!= (UBYTE
*)-1))
199 if(msg
->pixel
& mask
)
201 *(*plane
+ offset
) = *(*plane
+ offset
) | pixel
;
205 *(*plane
+ offset
) = *(*plane
+ offset
) & notpixel
;
211 /****************************************************************************************/
213 ULONG
ATIPlanBM__Hidd_BitMap__GetPixel(OOP_Class
*cl
, OOP_Object
*o
,
214 struct pHidd_BitMap_GetPixel
*msg
)
216 struct planarbm_data
*data
;
223 data
= OOP_INST_DATA(cl
, o
);
225 plane
= data
->planes
;
226 offset
= msg
->x
/ 8 + msg
->y
* data
->bytesperrow
;
227 pixel
= 128 >> (msg
->x
% 8);
230 for(i
= 0; i
< data
->depth
; i
++, plane
++)
233 if (*plane
== (UBYTE
*)-1)
235 retval
= retval
| (1 << i
);
237 else if (*plane
!= NULL
)
239 if(*(*plane
+ offset
) & pixel
)
241 retval
= retval
| (1 << i
);
249 /****************************************************************************************/
251 VOID
ATIPlanBM__Hidd_BitMap__PutImage(OOP_Class
*cl
, OOP_Object
*o
,
252 struct pHidd_BitMap_PutImage
*msg
)
255 UBYTE
*pixarray
= (UBYTE
*)msg
->pixels
;
258 struct planarbm_data
*data
;
260 if ((msg
->pixFmt
!= vHidd_StdPixFmt_Native
) &&
261 (msg
->pixFmt
!= vHidd_StdPixFmt_Native32
))
263 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
267 data
= OOP_INST_DATA(cl
, o
);
269 planeoffset
= msg
->y
* data
->bytesperrow
+ msg
->x
/ 8;
271 for(y
= 0; y
< msg
->height
; y
++)
275 case vHidd_StdPixFmt_Native
:
277 UBYTE
*src
= pixarray
;
279 plane
= data
->planes
;
281 for(d
= 0; d
< data
->depth
; d
++)
283 ULONG dmask
= 1L << d
;
284 ULONG pmask
= 0x80 >> (msg
->x
& 7);
287 if (pl
== (UBYTE
*)-1) continue;
288 if (pl
== NULL
) continue;
292 for(x
= 0; x
< msg
->width
; x
++)
313 } /* for(x = 0; x < msg->width; x++) */
317 } /* for(d = 0; d < data->depth; d++) */
319 pixarray
+= msg
->modulo
;
320 planeoffset
+= data
->bytesperrow
;
324 case vHidd_StdPixFmt_Native32
:
326 HIDDT_Pixel
*src
= (HIDDT_Pixel
*)pixarray
;
328 plane
= data
->planes
;
330 for(d
= 0; d
< data
->depth
; d
++)
332 ULONG dmask
= 1L << d
;
333 ULONG pmask
= 0x80 >> (msg
->x
& 7);
336 if (pl
== (UBYTE
*)-1) continue;
337 if (pl
== NULL
) continue;
341 for(x
= 0; x
< msg
->width
; x
++)
362 } /* for(x = 0; x < msg->width; x++) */
366 } /* for(d = 0; d < data->depth; d++) */
368 pixarray
+= msg
->modulo
;
369 planeoffset
+= data
->bytesperrow
;
374 } /* switch(msg->pixFmt) */
376 } /* for(y = 0; y < msg->height; y++) */
379 /****************************************************************************************/
381 VOID
ATIPlanBM__Hidd_BitMap__PutImageLUT(OOP_Class
*cl
, OOP_Object
*o
,
382 struct pHidd_BitMap_PutImageLUT
*msg
)
385 UBYTE
*pixarray
= (UBYTE
*)msg
->pixels
;
388 struct planarbm_data
*data
;
390 data
= OOP_INST_DATA(cl
, o
);
392 planeoffset
= msg
->y
* data
->bytesperrow
+ msg
->x
/ 8;
394 for(y
= 0; y
< msg
->height
; y
++)
396 UBYTE
*src
= pixarray
;
398 plane
= data
->planes
;
400 for(d
= 0; d
< data
->depth
; d
++)
402 ULONG dmask
= 1L << d
;
403 ULONG pmask
= 0x80 >> (msg
->x
& 7);
406 if (pl
== (UBYTE
*)-1) continue;
407 if (pl
== NULL
) continue;
411 for(x
= 0; x
< msg
->width
; x
++)
432 } /* for(x = 0; x < msg->width; x++) */
436 } /* for(d = 0; d < data->depth; d++) */
438 pixarray
+= msg
->modulo
;
439 planeoffset
+= data
->bytesperrow
;
441 } /* for(y = 0; y < msg->height; y++) */
444 /****************************************************************************************/
446 VOID
ATIPlanBM__Hidd_BitMap__GetImageLUT(OOP_Class
*cl
, OOP_Object
*o
,
447 struct pHidd_BitMap_GetImageLUT
*msg
)
450 UBYTE
*pixarray
= (UBYTE
*)msg
->pixels
;
453 struct planarbm_data
*data
;
456 data
= OOP_INST_DATA(cl
, o
);
458 planeoffset
= msg
->y
* data
->bytesperrow
+ msg
->x
/ 8;
461 for(d
= 0; d
< data
->depth
; d
++)
463 if (data
->planes
[d
] == (UBYTE
*)-1)
465 prefill
|= (1L << d
);
469 for(y
= 0; y
< msg
->height
; y
++)
471 UBYTE
*dest
= pixarray
;
473 plane
= data
->planes
;
475 for(x
= 0; x
< msg
->width
; x
++)
480 for(d
= 0; d
< data
->depth
; d
++)
482 ULONG dmask
= 1L << d
;
483 ULONG pmask
= 0x80 >> (msg
->x
& 7);
486 if (pl
== (UBYTE
*)-1) continue;
487 if (pl
== NULL
) continue;
491 for(x
= 0; x
< msg
->width
; x
++)
512 } /* for(x = 0; x < msg->width; x++) */
516 } /* for(d = 0; d < data->depth; d++) */
518 pixarray
+= msg
->modulo
;
519 planeoffset
+= data
->bytesperrow
;
521 } /* for(y = 0; y < msg->height; y++) */
525 /****************************************************************************************/
527 VOID
ATIPlanBM__Hidd_BitMap__BlitColorExpansion(OOP_Class
*cl
, OOP_Object
*o
,
528 struct pHidd_BitMap_BlitColorExpansion
*msg
)
533 ULONG planeoffset
/*, maskoffset*/;
536 OOP_Object
*gc
= msg
->gc
;
537 struct planarbm_data
*data
, *maskdata
;
539 data
= OOP_INST_DATA(cl
, o
);
541 cemd
= GC_COLEXP(gc
);
545 opaque
= (cemd
& vHidd_GC_ColExp_Opaque
) ? TRUE
: FALSE
;
547 planeoffset
= msg
->destY
* data
->bytesperrow
+ msg
->destX
/ 8;
549 if (OOP_OCLASS(msg
->srcBitMap
) == cl
)
551 /* srcBitMap is a planarbm class object */
553 maskdata
= OOP_INST_DATA(cl
, msg
->srcBitMap
);
554 mask
= maskdata
->planes
[0];
555 mask
+= msg
->srcY
* maskdata
->bytesperrow
+ msg
->srcX
/ 8;
557 for(y
= 0; y
< msg
->height
; y
++)
559 plane
= data
->planes
;
561 for(d
= 0; d
< data
->depth
; d
++)
563 ULONG dmask
= 1L << d
;
564 ULONG pmask
= 0x80 >> (msg
->destX
& 7);
565 ULONG mmask
= 0x80 >> (msg
->srcX
& 7);
566 BOOL fgset
= (fg
& dmask
) ? TRUE
: FALSE
;
567 BOOL bgset
= (bg
& dmask
) ? TRUE
: FALSE
;
572 if (pl
== (UBYTE
*)-1) continue;
573 if (pl
== NULL
) continue;
577 for(x
= 0; x
< msg
->width
; x
++)
614 } /* for(x = 0; x < msg->width; x++) */
618 } /* for(d = 0; d < data->depth; d++) */
620 mask
+= maskdata
->bytesperrow
;
621 planeoffset
+= data
->bytesperrow
;
623 } /* for(y = 0; y < msg->height; y++) */
625 } /* if (OOP_OCLASS(msg->srcBitMap) == cl) */
628 HIDDT_Pixel
*maskline
;
630 maskline
= AllocVec(msg
->width
* sizeof(HIDDT_Pixel
), MEMF_PUBLIC
);
633 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
637 for(y
= 0; y
< msg
->height
; y
++)
639 plane
= data
->planes
;
641 struct pHidd_BitMap_GetImage __m
= {
649 vHidd_StdPixFmt_Native32
652 OOP_DoMethod(msg
->srcBitMap
, (OOP_Msg
)m
);
654 for(d
= 0; d
< data
->depth
; d
++)
656 ULONG dmask
= 1L << d
;
657 ULONG pmask
= 0x80 >> (msg
->destX
& 7);
658 BOOL fgset
= (fg
& dmask
) ? TRUE
: FALSE
;
659 BOOL bgset
= (bg
& dmask
) ? TRUE
: FALSE
;
663 if (pl
== (UBYTE
*)-1) continue;
664 if (pl
== NULL
) continue;
668 for(x
= 0; x
< msg
->width
; x
++)
695 } /* for(x = 0; x < msg->width; x++) */
699 } /* for(d = 0; d < data->depth; d++) */
701 planeoffset
+= data
->bytesperrow
;
703 } /* for(y = 0; y < msg->height; y++) */
707 } /* if (OOP_OCLASS(msg->srcBitMap) == cl) else ... */
711 /****************************************************************************************/
713 BOOL
ATIPlanBM__Hidd_PlanarBM__SetBitMap(OOP_Class
*cl
, OOP_Object
*o
,
714 struct pHidd_PlanarBM_SetBitMap
*msg
)
716 struct planarbm_data
*data
;
719 struct TagItem pftags
[] =
721 { aHidd_PixFmt_Depth
, 0UL }, /* 0 */
722 { aHidd_PixFmt_BitsPerPixel
, 0UL }, /* 1 */
723 { aHidd_PixFmt_BytesPerPixel
, 1UL }, /* 2 */
724 { aHidd_PixFmt_ColorModel
, vHidd_ColorModel_Palette
}, /* 3 */
725 { aHidd_PixFmt_BitMapType
, vHidd_BitMapType_Planar
}, /* 4 */
726 { aHidd_PixFmt_CLUTShift
, 0UL }, /* 5 */
727 { aHidd_PixFmt_CLUTMask
, 0x000000FF }, /* 6 */
728 { aHidd_PixFmt_RedMask
, 0x00FF0000 }, /* 7 */
729 { aHidd_PixFmt_GreenMask
, 0x0000FF00 }, /* 8 */
730 { aHidd_PixFmt_BlueMask
, 0x000000FF }, /* 9 */
731 { TAG_DONE
, 0UL } /* 7 */
733 struct TagItem bmtags
[] =
735 { aHidd_BitMap_Width
, 0UL },
736 { aHidd_BitMap_Height
, 0UL },
737 { aHidd_BitMap_PixFmtTags
, 0UL },
743 data
= OOP_INST_DATA(cl
, o
);
746 if (data
->planes_alloced
)
748 D(bug(" !!!!! PlanarBM: Trying to set bitmap in one that allready has planes allocated\n"));
752 /* Check if plane array allready allocated */
753 if (NULL
!= data
->planes
)
755 if (bm
->Depth
> data
->planebuf_size
)
757 FreeVec(data
->planes
);
762 if (NULL
== data
->planes
)
764 data
->planes
= AllocVec(sizeof (UBYTE
*) * bm
->Depth
, MEMF_CLEAR
);
766 if (NULL
== data
->planes
)
769 data
->planebuf_size
= bm
->Depth
;
773 /* Update the planes */
774 for (i
= 0; i
< data
->planebuf_size
; i
++)
777 data
->planes
[i
] = bm
->Planes
[i
];
779 data
->planes
[i
] = NULL
;
782 data
->depth
= bm
->Depth
;
783 data
->bytesperrow
= bm
->BytesPerRow
;
784 data
->rows
= bm
->Rows
;
786 pftags
[0].ti_Data
= bm
->Depth
; /* PixFmt_Depth */
787 pftags
[1].ti_Data
= bm
->Depth
; /* PixFmt_BitsPerPixel */
789 bmtags
[0].ti_Data
= bm
->BytesPerRow
* 8;
790 bmtags
[1].ti_Data
= bm
->Rows
;
791 bmtags
[2].ti_Data
= (IPTR
)pftags
;
793 struct pHidd_BitMap_SetBitMapTags
{
795 struct TagItem
*tags
;
797 OOP_GetMethodID(IID_Hidd_BitMap
, num_Hidd_BitMap_Methods
),
801 /* Call private bitmap method to update superclass */
802 if (!OOP_DoMethod(o
, (OOP_Msg
)m
))
806 for (i
= 0; i
< data
->planebuf_size
; i
++)
808 data
->planes
[i
] = NULL
;
815 /****************************************************************************************/