4 Best viewed with vim5, using ts=4
6 An add-on to wmgeneral to copy XPM areas with transparency and opacity.
8 ------------------------------------------------------------
10 Author: Brad Jorsch (anomie@users.sourceforge.net)
15 16/08/2001 (Brad Jorsch, anomie@users.sourceforge.net)
16 * Wrote these routines.
23 #include "wmgeneral-x11.h"
29 static int get_shift(unsigned mask
){
39 void combineWithTrans(int sx
, int sy
, unsigned w
, unsigned h
, int dx
, int dy
){
41 unsigned int ww
, hh
, bar
;
46 XGetGeometry(display
, wmgen
.pixmap
, &baz
, &foo
, &foo
, &ww
, &hh
, &bar
, &bar
);
47 pix
=XGetImage(display
, wmgen
.pixmap
, 0, 0, ww
, hh
, AllPlanes
, ZPixmap
);
48 XGetGeometry(display
, wmgen
.mask
, &baz
, &foo
, &foo
, &ww
, &hh
, &bar
, &bar
);
49 mask
=XGetImage(display
, wmgen
.mask
, 0, 0, ww
, hh
, AllPlanes
, ZPixmap
);
53 if(!XGetPixel(mask
, sx
+x
, sy
+y
)) continue;
54 XPutPixel(pix
, dx
+x
, dy
+y
, XGetPixel(pix
, sx
+x
, sy
+y
));
57 XPutImage(display
, wmgen
.pixmap
, NormalGC
, pix
, 0, 0, 0, 0, pix
->width
, pix
->height
);
63 void combineWithOpacity(int sx
, int sy
, unsigned w
, unsigned h
, int dx
, int dy
, int o
){
65 unsigned int ww
, hh
, bar
;
68 int rmask
, gmask
, bmask
;
69 int rshift
, gshift
, bshift
;
70 unsigned long spixel
, dpixel
;
76 combineWithTrans(sx
, sy
, w
, h
, dx
, dy
);
80 XGetGeometry(display
, wmgen
.pixmap
, &baz
, &foo
, &foo
, &ww
, &hh
, &bar
, &bar
);
81 pix
=XGetImage(display
, wmgen
.pixmap
, 0, 0, ww
, hh
, AllPlanes
, ZPixmap
);
82 XGetGeometry(display
, wmgen
.mask
, &baz
, &foo
, &foo
, &ww
, &hh
, &bar
, &bar
);
83 mask
=XGetImage(display
, wmgen
.mask
, 0, 0, ww
, hh
, AllPlanes
, ZPixmap
);
85 if (pix
->depth
== DefaultDepth(display
, screen
)) {{
86 Visual
*visual
=DefaultVisual(display
, screen
);
87 rmask
= visual
->red_mask
;
88 gmask
= visual
->green_mask
;
89 bmask
= visual
->blue_mask
;
91 rmask
= pix
->red_mask
;
92 gmask
= pix
->green_mask
;
93 bmask
= pix
->blue_mask
;
97 rshift
=get_shift(rmask
);
98 gshift
=get_shift(gmask
);
99 bshift
=get_shift(bmask
);
100 /* NOTE: >>s then <<s to prevent overflow when multiplying opacity */
101 #define AVG(m, s) ((((((spixel&m)>>s)*o+((dpixel&m)>>s)*c_o)>>8)<<s)&m)
104 if(!XGetPixel(mask
, sx
+x
, sy
+y
)) continue;
105 spixel
=XGetPixel(pix
, sx
+x
, sy
+y
);
106 if(!XGetPixel(mask
, dx
+x
, dy
+y
)){
107 XPutPixel(pix
, dx
+x
, dy
+y
, spixel
);
109 dpixel
=XGetPixel(pix
, dx
+x
, dy
+y
);
110 XPutPixel(pix
, dx
+x
, dy
+y
,
118 XPutImage(display
, wmgen
.pixmap
, NormalGC
, pix
, 0, 0, 0, 0, pix
->width
, pix
->height
);