2 // pmdrawshadow.c - Renders shadows, uses CyberGfx if available.
4 // Copyright (C) 1996 - 2002 Henrik Isaksson
5 // All Rights Reserved.
8 #include <cybergraphx/cybergraphics.h>
9 #include <proto/cybergraphics.h>
12 // Macros that extract colour information
14 #define PC16BIT1(x) ((x&0x1f00)>>8)
15 #define PC16BIT2(x) ((x&0x00F8)>>3)
16 #define PC16BIT3(x) (((x&0xE000)>>13)|((x&0x0007)<<3))
18 #define PC15BIT1(x) ((x&0x1f00)>>8)
19 #define PC15BIT2(x) ((x&0x007C)>>2)
20 #define PC15BIT3(x) (((x&0xE000)>>13)|((x&0x0003)<<3))
22 #define M16RED(x) ((x&0xF800)>>11)
23 #define M16GREEN(x) ((x&0x07E0)>>5)
24 #define M16BLUE(x) (x&0x001F)
26 #define M15RED(x) ((x&0x7C00)>>10)
27 #define M15GREEN(x) ((x&0x03E0)>>5)
28 #define M15BLUE(x) (x&0x001F)
30 // Clamping macro, make sure that x stays within l <= x <= u
32 #define CLAMP(x, l, u) x=x>u?x=u:x;x=x<l?x=l:x;
38 UWORD bytesperrow
, bytesperpix
;
48 // shadefunc - CGFX hook that processes a ShRect structure passed in
50 ULONG
shadefunc(struct Hook
*hook
, struct RastPort
*rp
, struct CGFXHookMsg
*m
)
52 UBYTE
*ptr
=(UBYTE
*)m
->memptr
;
54 struct ShRect
*rect
= (struct ShRect
*)hook
->h_Data
;
55 register WORD tr
, tg
, tb
;
59 int y
, z
= m
->bytesperrow
;
66 switch(m
->colormodel
) {
68 for(y
=rect
->ya
;y
<rect
->yb
;y
++) {
70 for(x
=rect
->xa
*4;x
<4*rect
->xb
;x
+=4) {
89 for(y
=rect
->ya
;y
<rect
->yb
;y
++) {
91 for(x
=rect
->xa
*4;x
<4*rect
->xb
;x
+=4) {
110 for(y
=rect
->ya
;y
<rect
->yb
;y
++) {
112 for(x
=rect
->xa
*4;x
<4*rect
->xb
;x
+=4) {
132 for(y
=rect
->ya
;y
<rect
->yb
;y
++) {
134 for(x
=rect
->xa
*3;x
<3*rect
->xb
;x
+=3) {
153 //kprintf("bgr24\n");
154 for(y
=rect
->ya
;y
<rect
->yb
;y
++) {
156 for(x
=rect
->xa
*3;x
<3*rect
->xb
;x
+=3) {
179 for(y
=rect
->ya
;y
<rect
->yb
;y
++) {
180 wrow
=(UWORD
*)&ptr
[y
*z
];
181 for(x
=rect
->xa
;x
<rect
->xb
;x
++) {
192 wrow
[x
]=(tr
<<11)|(tb
)|(tg
<<5);
200 for(y
=rect
->ya
;y
<rect
->yb
;y
++) {
201 wrow
=(UWORD
*)&ptr
[y
*z
];
202 for(x
=rect
->xa
;x
<rect
->xb
;x
++) {
213 wrow
[x
]=(tr
<<11)|(tb
)|(tg
<<5);
221 for(y
=rect
->ya
;y
<rect
->yb
;y
++) {
222 wrow
=(UWORD
*)&ptr
[y
*z
];
223 for(x
=rect
->xa
;x
<rect
->xb
;x
++) {
234 wrow
[x
]=(tr
<<8)|(tb
<<3)|((tg
&0x38)>>3)|((tg
&0x7)<<13);
242 for(y
=rect
->ya
;y
<rect
->yb
;y
++) {
243 wrow
=(UWORD
*)&ptr
[y
*z
];
244 for(x
=rect
->xa
;x
<rect
->xb
;x
++) {
255 wrow
[x
]=(tb
<<8)|(tr
<<3)|((tg
&0x38)>>3)|((tg
&0x7)<<13);
263 for(y
=rect
->ya
;y
<rect
->yb
;y
++) {
264 wrow
=(UWORD
*)&ptr
[y
*z
];
265 for(x
=rect
->xa
;x
<rect
->xb
;x
++) {
276 wrow
[x
]=(tr
<<10)|(tb
)|(tg
<<5);
284 for(y
=rect
->ya
;y
<rect
->yb
;y
++) {
285 wrow
=(UWORD
*)&ptr
[y
*z
];
286 for(x
=rect
->xa
;x
<rect
->xb
;x
++) {
297 wrow
[x
]=(tr
<<10)|(tb
)|(tg
<<5);
305 for(y
=rect
->ya
;y
<rect
->yb
;y
++) {
306 wrow
=(UWORD
*)&ptr
[y
*z
];
307 for(x
=rect
->xa
;x
<rect
->xb
;x
++) {
318 wrow
[x
]=(tr
<<8)|(tb
<<2)|((tg
)>>3)|((tg
&0x7)<<13);
326 for(y
=rect
->ya
;y
<rect
->yb
;y
++) {
327 wrow
=(UWORD
*)&ptr
[y
*z
];
328 for(x
=rect
->xa
;x
<rect
->xb
;x
++) {
339 wrow
[x
]=(tb
<<8)|(tr
<<2)|((tg
)>>3)|((tg
&0x7)<<13);
348 // PM_DrawShadow - This function draws a shadow in a PM_Window. The shadow
349 // will be a rectangle defined by x, y - xb, yb (left, top - right, bottom)
351 void PM_DrawShadow(struct PM_Window
*w
, int x
, int y
, int xb
, int yb
)
353 static UWORD pat
[] = { 0xaaaa, 0x5555 };
355 struct Hook shadehook
;
357 ULONG depth
= 0, iscgfx
= FALSE
;
358 // BOOL realshadow = PM_Prefs->RealShadows;
359 BOOL realshadow
= TRUE
;
361 // Shall we draw a real CGFX shadow?
362 if(CyberGfx
&& realshadow
) {
363 iscgfx
=GetCyberMapAttr(w
->RPort
->BitMap
, CYBRMATTR_ISCYBERGFX
);
364 if(iscgfx
) depth
=GetCyberMapAttr(w
->RPort
->BitMap
, CYBRMATTR_DEPTH
);
365 if(iscgfx
&& depth
>8) {
366 rect
.xa
= x
+ w
->Wnd
->LeftEdge
;
367 rect
.xb
= xb
+ 1 + w
->Wnd
->LeftEdge
;
368 rect
.ya
= y
+ w
->Wnd
->TopEdge
;
369 rect
.yb
= yb
+ 1 + w
->Wnd
->TopEdge
;
371 rect
.r
= PM_Prefs
->pmp_ShadowR
;
372 rect
.g
= PM_Prefs
->pmp_ShadowG
;
373 rect
.b
= PM_Prefs
->pmp_ShadowB
;
375 shadehook
.h_Data
= &rect
;
376 shadehook
.h_Entry
= HookEntry
;
377 shadehook
.h_SubEntry
= (HOOKFUNC
)shadefunc
;
379 DoCDrawMethodTagList(&shadehook
, w
->RPort
, NULL
);
381 } else realshadow
= FALSE
;
382 } else realshadow
= FALSE
;
388 // A "real" shadow could not be drawn, or it was not desired.
390 SetAPen(w
->RPort
, 1); // Should use DRIPen
391 SetAfPt(w
->RPort
, pat
, 1);
392 PM_RectFill(w
, x
, y
, xb
, yb
);
393 SetAfPt(w
->RPort
, NULL
, 0);