Large-scale renaming of all Win32 functions and types to use the
[wine/multimedia.git] / graphics / x11drv / bitblt.c
blob4b1be45a5647b3ae8cdc9bdbb25b5a8698a0540d
1 /*
2 * GDI bit-blit operations
4 * Copyright 1993, 1994 Alexandre Julliard
5 */
7 #include "config.h"
9 #ifndef X_DISPLAY_MISSING
11 #include <X11/Intrinsic.h>
12 #include "ts_xlib.h"
14 #include <assert.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include "bitmap.h"
18 #include "callback.h"
19 #include "color.h"
20 #include "dc.h"
21 #include "metafile.h"
22 #include "options.h"
23 #include "x11drv.h"
24 #include "debug.h"
25 #include "xmalloc.h" /* for XCREATEIMAGE macro */
28 #define DST 0 /* Destination drawable */
29 #define SRC 1 /* Source drawable */
30 #define TMP 2 /* Temporary drawable */
31 #define PAT 3 /* Pattern (brush) in destination DC */
33 #define OP(src,dst,rop) (OP_ARGS(src,dst) << 4 | (rop))
34 #define OP_ARGS(src,dst) (((src) << 2) | (dst))
36 #define OP_SRC(opcode) ((opcode) >> 6)
37 #define OP_DST(opcode) (((opcode) >> 4) & 3)
38 #define OP_SRCDST(opcode) ((opcode) >> 4)
39 #define OP_ROP(opcode) ((opcode) & 0x0f)
41 #define MAX_OP_LEN 6 /* Longest opcode + 1 for the terminating 0 */
43 #define SWAP_INT32(i1,i2) \
44 do { INT __t = *(i1); *(i1) = *(i2); *(i2) = __t; } while(0)
46 static const unsigned char BITBLT_Opcodes[256][MAX_OP_LEN] =
48 { OP(PAT,DST,GXclear) }, /* 0x00 0 */
49 { OP(PAT,SRC,GXor), OP(SRC,DST,GXnor) }, /* 0x01 ~(D|(P|S)) */
50 { OP(PAT,SRC,GXnor), OP(SRC,DST,GXand) }, /* 0x02 D&~(P|S) */
51 { OP(PAT,SRC,GXnor) }, /* 0x03 ~(P|S) */
52 { OP(PAT,DST,GXnor), OP(SRC,DST,GXand) }, /* 0x04 S&~(D|P) */
53 { OP(PAT,DST,GXnor) }, /* 0x05 ~(D|P) */
54 { OP(SRC,DST,GXequiv), OP(PAT,DST,GXnor), }, /* 0x06 ~(P|~(D^S)) */
55 { OP(SRC,DST,GXand), OP(PAT,DST,GXnor) }, /* 0x07 ~(P|(D&S)) */
56 { OP(PAT,DST,GXandInverted), OP(SRC,DST,GXand) },/* 0x08 S&D&~P */
57 { OP(SRC,DST,GXxor), OP(PAT,DST,GXnor) }, /* 0x09 ~(P|(D^S)) */
58 { OP(PAT,DST,GXandInverted) }, /* 0x0a D&~P */
59 { OP(SRC,DST,GXandReverse), OP(PAT,DST,GXnor) }, /* 0x0b ~(P|(S&~D)) */
60 { OP(PAT,SRC,GXandInverted) }, /* 0x0c S&~P */
61 { OP(SRC,DST,GXandInverted), OP(PAT,DST,GXnor) },/* 0x0d ~(P|(D&~S)) */
62 { OP(SRC,DST,GXnor), OP(PAT,DST,GXnor) }, /* 0x0e ~(P|~(D|S)) */
63 { OP(PAT,DST,GXcopyInverted) }, /* 0x0f ~P */
64 { OP(SRC,DST,GXnor), OP(PAT,DST,GXand) }, /* 0x10 P&~(S|D) */
65 { OP(SRC,DST,GXnor) }, /* 0x11 ~(D|S) */
66 { OP(PAT,DST,GXequiv), OP(SRC,DST,GXnor) }, /* 0x12 ~(S|~(D^P)) */
67 { OP(PAT,DST,GXand), OP(SRC,DST,GXnor) }, /* 0x13 ~(S|(D&P)) */
68 { OP(PAT,SRC,GXequiv), OP(SRC,DST,GXnor) }, /* 0x14 ~(D|~(P^S)) */
69 { OP(PAT,SRC,GXand), OP(SRC,DST,GXnor) }, /* 0x15 ~(D|(P&S)) */
70 { OP(SRC,TMP,GXcopy), OP(PAT,TMP,GXnand),
71 OP(TMP,DST,GXand), OP(SRC,DST,GXxor),
72 OP(PAT,DST,GXxor) }, /* 0x16 P^S^(D&~(P&S) */
73 { OP(SRC,TMP,GXcopy), OP(SRC,DST,GXxor),
74 OP(PAT,SRC,GXxor), OP(SRC,DST,GXand),
75 OP(TMP,DST,GXequiv) }, /* 0x17 ~S^((S^P)&(S^D))*/
76 { OP(PAT,SRC,GXxor), OP(PAT,DST,GXxor),
77 OP(SRC,DST,GXand) }, /* 0x18 (S^P)&(D^P) */
78 { OP(SRC,TMP,GXcopy), OP(PAT,TMP,GXnand),
79 OP(TMP,DST,GXand), OP(SRC,DST,GXequiv) }, /* 0x19 ~S^(D&~(P&S)) */
80 { OP(PAT,SRC,GXand), OP(SRC,DST,GXor),
81 OP(PAT,DST,GXxor) }, /* 0x1a P^(D|(S&P)) */
82 { OP(SRC,TMP,GXcopy), OP(PAT,TMP,GXxor),
83 OP(TMP,DST,GXand), OP(SRC,DST,GXequiv) }, /* 0x1b ~S^(D&(P^S)) */
84 { OP(PAT,DST,GXand), OP(SRC,DST,GXor),
85 OP(PAT,DST,GXxor) }, /* 0x1c P^(S|(D&P)) */
86 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXxor),
87 OP(SRC,DST,GXand), OP(TMP,DST,GXequiv) }, /* 0x1d ~D^(S&(D^P)) */
88 { OP(SRC,DST,GXor), OP(PAT,DST,GXxor) }, /* 0x1e P^(D|S) */
89 { OP(SRC,DST,GXor), OP(PAT,DST,GXnand) }, /* 0x1f ~(P&(D|S)) */
90 { OP(PAT,SRC,GXandReverse), OP(SRC,DST,GXand) }, /* 0x20 D&(P&~S) */
91 { OP(PAT,DST,GXxor), OP(SRC,DST,GXnor) }, /* 0x21 ~(S|(D^P)) */
92 { OP(SRC,DST,GXandInverted) }, /* 0x22 ~S&D */
93 { OP(PAT,DST,GXandReverse), OP(SRC,DST,GXnor) }, /* 0x23 ~(S|(P&~D)) */
94 { OP(SRC,DST,GXxor), OP(PAT,SRC,GXxor),
95 OP(SRC,DST,GXand) }, /* 0x24 (S^P)&(S^D) */
96 { OP(PAT,SRC,GXnand), OP(SRC,DST,GXand),
97 OP(PAT,DST,GXequiv) }, /* 0x25 ~P^(D&~(S&P)) */
98 { OP(SRC,TMP,GXcopy), OP(PAT,TMP,GXand),
99 OP(TMP,DST,GXor), OP(SRC,DST,GXxor) }, /* 0x26 S^(D|(S&P)) */
100 { OP(SRC,TMP,GXcopy), OP(PAT,TMP,GXequiv),
101 OP(TMP,DST,GXor), OP(SRC,DST,GXxor) }, /* 0x27 S^(D|~(P^S)) */
102 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXand) }, /* 0x28 D&(P^S) */
103 { OP(SRC,TMP,GXcopy), OP(PAT,TMP,GXand),
104 OP(TMP,DST,GXor), OP(SRC,DST,GXxor),
105 OP(PAT,DST,GXequiv) }, /* 0x29 ~P^S^(D|(P&S)) */
106 { OP(PAT,SRC,GXnand), OP(SRC,DST,GXand) }, /* 0x2a D&~(P&S) */
107 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXxor),
108 OP(PAT,DST,GXxor), OP(SRC,DST,GXand),
109 OP(TMP,DST,GXequiv) }, /* 0x2b ~S^((P^S)&(P^D))*/
110 { OP(SRC,DST,GXor), OP(PAT,DST,GXand),
111 OP(SRC,DST,GXxor) }, /* 0x2c S^(P&(S|D)) */
112 { OP(SRC,DST,GXorReverse), OP(PAT,DST,GXxor) }, /* 0x2d P^(S|~D) */
113 { OP(PAT,DST,GXxor), OP(SRC,DST,GXor),
114 OP(PAT,DST,GXxor) }, /* 0x2e P^(S|(D^P)) */
115 { OP(SRC,DST,GXorReverse), OP(PAT,DST,GXnand) }, /* 0x2f ~(P&(S|~D)) */
116 { OP(PAT,SRC,GXandReverse) }, /* 0x30 P&~S */
117 { OP(PAT,DST,GXandInverted), OP(SRC,DST,GXnor) },/* 0x31 ~(S|(D&~P)) */
118 { OP(SRC,DST,GXor), OP(PAT,DST,GXor),
119 OP(SRC,DST,GXxor) }, /* 0x32 S^(D|P|S) */
120 { OP(SRC,DST,GXcopyInverted) }, /* 0x33 ~S */
121 { OP(SRC,DST,GXand), OP(PAT,DST,GXor),
122 OP(SRC,DST,GXxor) }, /* 0x34 S^(P|(D&S)) */
123 { OP(SRC,DST,GXequiv), OP(PAT,DST,GXor),
124 OP(SRC,DST,GXxor) }, /* 0x35 S^(P|~(D^S)) */
125 { OP(PAT,DST,GXor), OP(SRC,DST,GXxor) }, /* 0x36 S^(D|P) */
126 { OP(PAT,DST,GXor), OP(SRC,DST,GXnand) }, /* 0x37 ~(S&(D|P)) */
127 { OP(PAT,DST,GXor), OP(SRC,DST,GXand),
128 OP(PAT,DST,GXxor) }, /* 0x38 P^(S&(D|P)) */
129 { OP(PAT,DST,GXorReverse), OP(SRC,DST,GXxor) }, /* 0x39 S^(P|~D) */
130 { OP(SRC,DST,GXxor), OP(PAT,DST,GXor),
131 OP(SRC,DST,GXxor) }, /* 0x3a S^(P|(D^S)) */
132 { OP(PAT,DST,GXorReverse), OP(SRC,DST,GXnand) }, /* 0x3b ~(S&(P|~D)) */
133 { OP(PAT,SRC,GXxor) }, /* 0x3c P^S */
134 { OP(SRC,DST,GXnor), OP(PAT,DST,GXor),
135 OP(SRC,DST,GXxor) }, /* 0x3d S^(P|~(D|S)) */
136 { OP(SRC,DST,GXandInverted), OP(PAT,DST,GXor),
137 OP(SRC,DST,GXxor) }, /* 0x3e S^(P|(D&~S)) */
138 { OP(PAT,SRC,GXnand) }, /* 0x3f ~(P&S) */
139 { OP(SRC,DST,GXandReverse), OP(PAT,DST,GXand) }, /* 0x40 P&S&~D */
140 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXnor) }, /* 0x41 ~(D|(P^S)) */
141 { OP(DST,SRC,GXxor), OP(PAT,DST,GXxor),
142 OP(SRC,DST,GXand) }, /* 0x42 (S^D)&(P^D) */
143 { OP(SRC,DST,GXnand), OP(PAT,DST,GXand),
144 OP(SRC,DST,GXequiv) }, /* 0x43 ~S^(P&~(D&S)) */
145 { OP(SRC,DST,GXandReverse) }, /* 0x44 S&~D */
146 { OP(PAT,SRC,GXandReverse), OP(SRC,DST,GXnor) }, /* 0x45 ~(D|(P&~S)) */
147 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXand),
148 OP(SRC,DST,GXor), OP(TMP,DST,GXxor) }, /* 0x46 D^(S|(P&D)) */
149 { OP(PAT,DST,GXxor), OP(SRC,DST,GXand),
150 OP(PAT,DST,GXequiv) }, /* 0x47 ~P^(S&(D^P)) */
151 { OP(PAT,DST,GXxor), OP(SRC,DST,GXand) }, /* 0x48 S&(P^D) */
152 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXand),
153 OP(SRC,DST,GXor), OP(TMP,DST,GXxor),
154 OP(PAT,DST,GXequiv) }, /* 0x49 ~P^D^(S|(P&D)) */
155 { OP(DST,SRC,GXor), OP(PAT,SRC,GXand),
156 OP(SRC,DST,GXxor) }, /* 0x4a D^(P&(S|D)) */
157 { OP(SRC,DST,GXorInverted), OP(PAT,DST,GXxor) }, /* 0x4b P^(D|~S) */
158 { OP(PAT,DST,GXnand), OP(SRC,DST,GXand) }, /* 0x4c S&~(D&P) */
159 { OP(SRC,TMP,GXcopy), OP(SRC,DST,GXxor),
160 OP(PAT,SRC,GXxor), OP(SRC,DST,GXor),
161 OP(TMP,DST,GXequiv) }, /* 0x4d ~S^((S^P)|(S^D))*/
162 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXor),
163 OP(PAT,DST,GXxor) }, /* 0x4e P^(D|(S^P)) */
164 { OP(SRC,DST,GXorInverted), OP(PAT,DST,GXnand) },/* 0x4f ~(P&(D|~S)) */
165 { OP(PAT,DST,GXandReverse) }, /* 0x50 P&~D */
166 { OP(PAT,SRC,GXandInverted), OP(SRC,DST,GXnor) },/* 0x51 ~(D|(S&~P)) */
167 { OP(DST,SRC,GXand), OP(PAT,SRC,GXor),
168 OP(SRC,DST,GXxor) }, /* 0x52 D^(P|(S&D)) */
169 { OP(SRC,DST,GXxor), OP(PAT,DST,GXand),
170 OP(SRC,DST,GXequiv) }, /* 0x53 ~S^(P&(D^S)) */
171 { OP(PAT,SRC,GXnor), OP(SRC,DST,GXnor) }, /* 0x54 ~(D|~(P|S)) */
172 { OP(PAT,DST,GXinvert) }, /* 0x55 ~D */
173 { OP(PAT,SRC,GXor), OP(SRC,DST,GXxor) }, /* 0x56 D^(P|S) */
174 { OP(PAT,SRC,GXor), OP(SRC,DST,GXnand) }, /* 0x57 ~(D&(P|S)) */
175 { OP(PAT,SRC,GXor), OP(SRC,DST,GXand),
176 OP(PAT,DST,GXxor) }, /* 0x58 P^(D&(P|S)) */
177 { OP(PAT,SRC,GXorReverse), OP(SRC,DST,GXxor) }, /* 0x59 D^(P|~S) */
178 { OP(PAT,DST,GXxor) }, /* 0x5a D^P */
179 { OP(DST,SRC,GXnor), OP(PAT,SRC,GXor),
180 OP(SRC,DST,GXxor) }, /* 0x5b D^(P|~(S|D)) */
181 { OP(DST,SRC,GXxor), OP(PAT,SRC,GXor),
182 OP(SRC,DST,GXxor) }, /* 0x5c D^(P|(S^D)) */
183 { OP(PAT,SRC,GXorReverse), OP(SRC,DST,GXnand) }, /* 0x5d ~(D&(P|~S)) */
184 { OP(DST,SRC,GXandInverted), OP(PAT,SRC,GXor),
185 OP(SRC,DST,GXxor) }, /* 0x5e D^(P|(S&~D)) */
186 { OP(PAT,DST,GXnand) }, /* 0x5f ~(D&P) */
187 { OP(SRC,DST,GXxor), OP(PAT,DST,GXand) }, /* 0x60 P&(D^S) */
188 { OP(DST,TMP,GXcopy), OP(SRC,DST,GXand),
189 OP(PAT,DST,GXor), OP(SRC,DST,GXxor),
190 OP(TMP,DST,GXequiv) }, /* 0x61 ~D^S^(P|(D&S)) */
191 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXor),
192 OP(SRC,DST,GXand), OP(TMP,DST,GXxor) }, /* 0x62 D^(S&(P|D)) */
193 { OP(PAT,DST,GXorInverted), OP(SRC,DST,GXxor) }, /* 0x63 S^(D|~P) */
194 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXor),
195 OP(SRC,DST,GXand), OP(TMP,DST,GXxor) }, /* 0x64 S^(D&(P|S)) */
196 { OP(PAT,SRC,GXorInverted), OP(SRC,DST,GXxor) }, /* 0x65 D^(S|~P) */
197 { OP(SRC,DST,GXxor) }, /* 0x66 S^D */
198 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXnor),
199 OP(SRC,DST,GXor), OP(TMP,DST,GXxor) }, /* 0x67 S^(D|~(S|P) */
200 { OP(DST,TMP,GXcopy), OP(SRC,DST,GXnor),
201 OP(PAT,DST,GXor), OP(SRC,DST,GXxor),
202 OP(TMP,DST,GXequiv) }, /* 0x68 ~D^S^(P|~(D|S))*/
203 { OP(SRC,DST,GXxor), OP(PAT,DST,GXequiv) }, /* 0x69 ~P^(D^S) */
204 { OP(PAT,SRC,GXand), OP(SRC,DST,GXxor) }, /* 0x6a D^(P&S) */
205 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXor),
206 OP(SRC,DST,GXand), OP(TMP,DST,GXxor),
207 OP(PAT,DST,GXequiv) }, /* 0x6b ~P^S^(D&(P|S)) */
208 { OP(PAT,DST,GXand), OP(SRC,DST,GXxor) }, /* 0x6c S^(D&P) */
209 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXor),
210 OP(SRC,DST,GXand), OP(TMP,DST,GXxor),
211 OP(PAT,DST,GXequiv) }, /* 0x6d ~P^D^(S&(P|D)) */
212 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXorReverse),
213 OP(SRC,DST,GXand), OP(TMP,DST,GXxor) }, /* 0x6e S^(D&(P|~S)) */
214 { OP(SRC,DST,GXequiv), OP(PAT,DST,GXnand) }, /* 0x6f ~(P&~(S^D)) */
215 { OP(SRC,DST,GXnand), OP(PAT,DST,GXand) }, /* 0x70 P&~(D&S) */
216 { OP(SRC,TMP,GXcopy), OP(DST,SRC,GXxor),
217 OP(PAT,DST,GXxor), OP(SRC,DST,GXand),
218 OP(TMP,DST,GXequiv) }, /* 0x71 ~S^((S^D)&(P^D))*/
219 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXxor),
220 OP(SRC,DST,GXor), OP(TMP,DST,GXxor) }, /* 0x72 S^(D|(P^S)) */
221 { OP(PAT,DST,GXorInverted), OP(SRC,DST,GXnand) },/* 0x73 ~(S&(D|~P)) */
222 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXxor),
223 OP(SRC,DST,GXor), OP(TMP,DST,GXxor) }, /* 0x74 D^(S|(P^D)) */
224 { OP(PAT,SRC,GXorInverted), OP(SRC,DST,GXnand) },/* 0x75 ~(D&(S|~P)) */
225 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXandReverse),
226 OP(SRC,DST,GXor), OP(TMP,DST,GXxor) }, /* 0x76 S^(D|(P&~S)) */
227 { OP(SRC,DST,GXnand) }, /* 0x77 ~(S&D) */
228 { OP(SRC,DST,GXand), OP(PAT,DST,GXxor) }, /* 0x78 P^(D&S) */
229 { OP(DST,TMP,GXcopy), OP(SRC,DST,GXor),
230 OP(PAT,DST,GXand), OP(SRC,DST,GXxor),
231 OP(TMP,DST,GXequiv) }, /* 0x79 ~D^S^(P&(D|S)) */
232 { OP(DST,SRC,GXorInverted), OP(PAT,SRC,GXand),
233 OP(SRC,DST,GXxor) }, /* 0x7a D^(P&(S|~D)) */
234 { OP(PAT,DST,GXequiv), OP(SRC,DST,GXnand) }, /* 0x7b ~(S&~(D^P)) */
235 { OP(SRC,DST,GXorInverted), OP(PAT,DST,GXand),
236 OP(SRC,DST,GXxor) }, /* 0x7c S^(P&(D|~S)) */
237 { OP(PAT,SRC,GXequiv), OP(SRC,DST,GXnand) }, /* 0x7d ~(D&~(P^S)) */
238 { OP(SRC,DST,GXxor), OP(PAT,SRC,GXxor),
239 OP(SRC,DST,GXor) }, /* 0x7e (S^P)|(S^D) */
240 { OP(PAT,SRC,GXand), OP(SRC,DST,GXnand) }, /* 0x7f ~(D&P&S) */
241 { OP(PAT,SRC,GXand), OP(SRC,DST,GXand) }, /* 0x80 D&P&S */
242 { OP(SRC,DST,GXxor), OP(PAT,SRC,GXxor),
243 OP(SRC,DST,GXnor) }, /* 0x81 ~((S^P)|(S^D)) */
244 { OP(PAT,SRC,GXequiv), OP(SRC,DST,GXand) }, /* 0x82 D&~(P^S) */
245 { OP(SRC,DST,GXorInverted), OP(PAT,DST,GXand),
246 OP(SRC,DST,GXequiv) }, /* 0x83 ~S^(P&(D|~S)) */
247 { OP(PAT,DST,GXequiv), OP(SRC,DST,GXand) }, /* 0x84 S&~(D^P) */
248 { OP(PAT,SRC,GXorInverted), OP(SRC,DST,GXand),
249 OP(PAT,DST,GXequiv) }, /* 0x85 ~P^(D&(S|~P)) */
250 { OP(DST,TMP,GXcopy), OP(SRC,DST,GXor),
251 OP(PAT,DST,GXand), OP(SRC,DST,GXxor),
252 OP(TMP,DST,GXxor) }, /* 0x86 D^S^(P&(D|S)) */
253 { OP(SRC,DST,GXand), OP(PAT,DST,GXequiv) }, /* 0x87 ~P^(D&S) */
254 { OP(SRC,DST,GXand) }, /* 0x88 S&D */
255 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXandReverse),
256 OP(SRC,DST,GXor), OP(TMP,DST,GXequiv) }, /* 0x89 ~S^(D|(P&~S)) */
257 { OP(PAT,SRC,GXorInverted), OP(SRC,DST,GXand) }, /* 0x8a D&(S|~P) */
258 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXxor),
259 OP(SRC,DST,GXor), OP(TMP,DST,GXequiv) }, /* 0x8b ~D^(S|(P^D)) */
260 { OP(PAT,DST,GXorInverted), OP(SRC,DST,GXand) }, /* 0x8c S&(D|~P) */
261 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXxor),
262 OP(SRC,DST,GXor), OP(TMP,DST,GXequiv) }, /* 0x8d ~S^(D|(P^S)) */
263 { OP(SRC,TMP,GXcopy), OP(DST,SRC,GXxor),
264 OP(PAT,DST,GXxor), OP(SRC,DST,GXand),
265 OP(TMP,DST,GXxor) }, /* 0x8e S^((S^D)&(P^D))*/
266 { OP(SRC,DST,GXnand), OP(PAT,DST,GXnand) }, /* 0x8f ~(P&~(D&S)) */
267 { OP(SRC,DST,GXequiv), OP(PAT,DST,GXand) }, /* 0x90 P&~(D^S) */
268 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXorReverse),
269 OP(SRC,DST,GXand), OP(TMP,DST,GXequiv) }, /* 0x91 ~S^(D&(P|~S)) */
270 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXor),
271 OP(SRC,DST,GXand), OP(PAT,DST,GXxor),
272 OP(TMP,DST,GXxor) }, /* 0x92 D^P^(S&(D|P)) */
273 { OP(PAT,DST,GXand), OP(SRC,DST,GXequiv) }, /* 0x93 ~S^(P&D) */
274 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXor),
275 OP(SRC,DST,GXand), OP(PAT,DST,GXxor),
276 OP(TMP,DST,GXxor) }, /* 0x94 S^P^(D&(P|S)) */
277 { OP(PAT,SRC,GXand), OP(SRC,DST,GXequiv) }, /* 0x95 ~D^(P&S) */
278 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXxor) }, /* 0x96 D^P^S */
279 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXnor),
280 OP(SRC,DST,GXor), OP(PAT,DST,GXxor),
281 OP(TMP,DST,GXxor) }, /* 0x97 S^P^(D|~(P|S)) */
282 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXnor),
283 OP(SRC,DST,GXor), OP(TMP,DST,GXequiv) }, /* 0x98 ~S^(D|~(P|S)) */
284 { OP(SRC,DST,GXequiv) }, /* 0x99 ~S^D */
285 { OP(PAT,SRC,GXandReverse), OP(SRC,DST,GXxor) }, /* 0x9a D^(P&~S) */
286 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXor),
287 OP(SRC,DST,GXand), OP(TMP,DST,GXequiv) }, /* 0x9b ~S^(D&(P|S)) */
288 { OP(PAT,DST,GXandReverse), OP(SRC,DST,GXxor) }, /* 0x9c S^(P&~D) */
289 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXor),
290 OP(SRC,DST,GXand), OP(TMP,DST,GXequiv) }, /* 0x9d ~D^(S&(P|D)) */
291 { OP(DST,TMP,GXcopy), OP(SRC,DST,GXand),
292 OP(PAT,DST,GXor), OP(SRC,DST,GXxor),
293 OP(TMP,DST,GXxor) }, /* 0x9e D^S^(P|(D&S)) */
294 { OP(SRC,DST,GXxor), OP(PAT,DST,GXnand) }, /* 0x9f ~(P&(D^S)) */
295 { OP(PAT,DST,GXand) }, /* 0xa0 D&P */
296 { OP(PAT,SRC,GXandInverted), OP(SRC,DST,GXor),
297 OP(PAT,DST,GXequiv) }, /* 0xa1 ~P^(D|(S&~P)) */
298 { OP(PAT,SRC,GXorReverse), OP(SRC,DST,GXand) }, /* 0xa2 D&(P|~S) */
299 { OP(DST,SRC,GXxor), OP(PAT,SRC,GXor),
300 OP(SRC,DST,GXequiv) }, /* 0xa3 ~D^(P|(S^D)) */
301 { OP(PAT,SRC,GXnor), OP(SRC,DST,GXor),
302 OP(PAT,DST,GXequiv) }, /* 0xa4 ~P^(D|~(S|P)) */
303 { OP(PAT,DST,GXequiv) }, /* 0xa5 ~P^D */
304 { OP(PAT,SRC,GXandInverted), OP(SRC,DST,GXxor) },/* 0xa6 D^(S&~P) */
305 { OP(PAT,SRC,GXor), OP(SRC,DST,GXand),
306 OP(PAT,DST,GXequiv) }, /* 0xa7 ~P^(D&(S|P)) */
307 { OP(PAT,SRC,GXor), OP(SRC,DST,GXand) }, /* 0xa8 D&(P|S) */
308 { OP(PAT,SRC,GXor), OP(SRC,DST,GXequiv) }, /* 0xa9 ~D^(P|S) */
309 { OP(SRC,DST,GXnoop) }, /* 0xaa D */
310 { OP(PAT,SRC,GXnor), OP(SRC,DST,GXor) }, /* 0xab D|~(P|S) */
311 { OP(SRC,DST,GXxor), OP(PAT,DST,GXand),
312 OP(SRC,DST,GXxor) }, /* 0xac S^(P&(D^S)) */
313 { OP(DST,SRC,GXand), OP(PAT,SRC,GXor),
314 OP(SRC,DST,GXequiv) }, /* 0xad ~D^(P|(S&D)) */
315 { OP(PAT,SRC,GXandInverted), OP(SRC,DST,GXor) }, /* 0xae D|(S&~P) */
316 { OP(PAT,DST,GXorInverted) }, /* 0xaf D|~P */
317 { OP(SRC,DST,GXorInverted), OP(PAT,DST,GXand) }, /* 0xb0 P&(D|~S) */
318 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXor),
319 OP(PAT,DST,GXequiv) }, /* 0xb1 ~P^(D|(S^P)) */
320 { OP(SRC,TMP,GXcopy), OP(SRC,DST,GXxor),
321 OP(PAT,SRC,GXxor), OP(SRC,DST,GXor),
322 OP(TMP,DST,GXxor) }, /* 0xb2 S^((S^P)|(S^D))*/
323 { OP(PAT,DST,GXnand), OP(SRC,DST,GXnand) }, /* 0xb3 ~(S&~(D&P)) */
324 { OP(SRC,DST,GXandReverse), OP(PAT,DST,GXxor) }, /* 0xb4 P^(S&~D) */
325 { OP(DST,SRC,GXor), OP(PAT,SRC,GXand),
326 OP(SRC,DST,GXequiv) }, /* 0xb5 ~D^(P&(S|D)) */
327 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXand),
328 OP(SRC,DST,GXor), OP(PAT,DST,GXxor),
329 OP(TMP,DST,GXxor) }, /* 0xb6 D^P^(S|(D&P)) */
330 { OP(PAT,DST,GXxor), OP(SRC,DST,GXnand) }, /* 0xb7 ~(S&(D^P)) */
331 { OP(PAT,DST,GXxor), OP(SRC,DST,GXand),
332 OP(PAT,DST,GXxor) }, /* 0xb8 P^(S&(D^P)) */
333 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXand),
334 OP(SRC,DST,GXor), OP(TMP,DST,GXequiv) }, /* 0xb9 ~D^(S|(P&D)) */
335 { OP(PAT,SRC,GXandReverse), OP(SRC,DST,GXor) }, /* 0xba D|(P&~S) */
336 { OP(SRC,DST,GXorInverted) }, /* 0xbb ~S|D */
337 { OP(SRC,DST,GXnand), OP(PAT,DST,GXand),
338 OP(SRC,DST,GXxor) }, /* 0xbc S^(P&~(D&S)) */
339 { OP(DST,SRC,GXxor), OP(PAT,DST,GXxor),
340 OP(SRC,DST,GXnand) }, /* 0xbd ~((S^D)&(P^D)) */
341 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXor) }, /* 0xbe D|(P^S) */
342 { OP(PAT,SRC,GXnand), OP(SRC,DST,GXor) }, /* 0xbf D|~(P&S) */
343 { OP(PAT,SRC,GXand) }, /* 0xc0 P&S */
344 { OP(SRC,DST,GXandInverted), OP(PAT,DST,GXor),
345 OP(SRC,DST,GXequiv) }, /* 0xc1 ~S^(P|(D&~S)) */
346 { OP(SRC,DST,GXnor), OP(PAT,DST,GXor),
347 OP(SRC,DST,GXequiv) }, /* 0xc2 ~S^(P|~(D|S)) */
348 { OP(PAT,SRC,GXequiv) }, /* 0xc3 ~P^S */
349 { OP(PAT,DST,GXorReverse), OP(SRC,DST,GXand) }, /* 0xc4 S&(P|~D) */
350 { OP(SRC,DST,GXxor), OP(PAT,DST,GXor),
351 OP(SRC,DST,GXequiv) }, /* 0xc5 ~S^(P|(D^S)) */
352 { OP(PAT,DST,GXandInverted), OP(SRC,DST,GXxor) },/* 0xc6 S^(D&~P) */
353 { OP(PAT,DST,GXor), OP(SRC,DST,GXand),
354 OP(PAT,DST,GXequiv) }, /* 0xc7 ~P^(S&(D|P)) */
355 { OP(PAT,DST,GXor), OP(SRC,DST,GXand) }, /* 0xc8 S&(D|P) */
356 { OP(PAT,DST,GXor), OP(SRC,DST,GXequiv) }, /* 0xc9 ~S^(P|D) */
357 { OP(DST,SRC,GXxor), OP(PAT,SRC,GXand),
358 OP(SRC,DST,GXxor) }, /* 0xca D^(P&(S^D)) */
359 { OP(SRC,DST,GXand), OP(PAT,DST,GXor),
360 OP(SRC,DST,GXequiv) }, /* 0xcb ~S^(P|(D&S)) */
361 { OP(SRC,DST,GXcopy) }, /* 0xcc S */
362 { OP(PAT,DST,GXnor), OP(SRC,DST,GXor) }, /* 0xcd S|~(D|P) */
363 { OP(PAT,DST,GXandInverted), OP(SRC,DST,GXor) }, /* 0xce S|(D&~P) */
364 { OP(PAT,SRC,GXorInverted) }, /* 0xcf S|~P */
365 { OP(SRC,DST,GXorReverse), OP(PAT,DST,GXand) }, /* 0xd0 P&(S|~D) */
366 { OP(PAT,DST,GXxor), OP(SRC,DST,GXor),
367 OP(PAT,DST,GXequiv) }, /* 0xd1 ~P^(S|(D^P)) */
368 { OP(SRC,DST,GXandInverted), OP(PAT,DST,GXxor) },/* 0xd2 P^(D&~S) */
369 { OP(SRC,DST,GXor), OP(PAT,DST,GXand),
370 OP(SRC,DST,GXequiv) }, /* 0xd3 ~S^(P&(D|S)) */
371 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXxor),
372 OP(PAT,DST,GXxor), OP(SRC,DST,GXand),
373 OP(TMP,DST,GXxor) }, /* 0xd4 S^((S^P)&(D^P))*/
374 { OP(PAT,SRC,GXnand), OP(SRC,DST,GXnand) }, /* 0xd5 ~(D&~(P&S)) */
375 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXand),
376 OP(SRC,DST,GXor), OP(PAT,DST,GXxor),
377 OP(TMP,DST,GXxor) }, /* 0xd6 S^P^(D|(P&S)) */
378 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXnand) }, /* 0xd7 ~(D&(P^S)) */
379 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXand),
380 OP(PAT,DST,GXxor) }, /* 0xd8 P^(D&(S^P)) */
381 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXand),
382 OP(SRC,DST,GXor), OP(TMP,DST,GXequiv) }, /* 0xd9 ~S^(D|(P&S)) */
383 { OP(DST,SRC,GXnand), OP(PAT,SRC,GXand),
384 OP(SRC,DST,GXxor) }, /* 0xda D^(P&~(S&D)) */
385 { OP(SRC,DST,GXxor), OP(PAT,SRC,GXxor),
386 OP(SRC,DST,GXnand) }, /* 0xdb ~((S^P)&(S^D)) */
387 { OP(PAT,DST,GXandReverse), OP(SRC,DST,GXor) }, /* 0xdc S|(P&~D) */
388 { OP(SRC,DST,GXorReverse) }, /* 0xdd S|~D */
389 { OP(PAT,DST,GXxor), OP(SRC,DST,GXor) }, /* 0xde S|(D^P) */
390 { OP(PAT,DST,GXnand), OP(SRC,DST,GXor) }, /* 0xdf S|~(D&P) */
391 { OP(SRC,DST,GXor), OP(PAT,DST,GXand) }, /* 0xe0 P&(D|S) */
392 { OP(SRC,DST,GXor), OP(PAT,DST,GXequiv) }, /* 0xe1 ~P^(D|S) */
393 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXxor),
394 OP(SRC,DST,GXand), OP(TMP,DST,GXxor) }, /* 0xe2 D^(S&(P^D)) */
395 { OP(PAT,DST,GXand), OP(SRC,DST,GXor),
396 OP(PAT,DST,GXequiv) }, /* 0xe3 ~P^(S|(D&P)) */
397 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXxor),
398 OP(SRC,DST,GXand), OP(TMP,DST,GXxor) }, /* 0xe4 S^(D&(P^S)) */
399 { OP(PAT,SRC,GXand), OP(SRC,DST,GXor),
400 OP(PAT,DST,GXequiv) }, /* 0xe5 ~P^(D|(S&P)) */
401 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXnand),
402 OP(SRC,DST,GXand), OP(TMP,DST,GXxor) }, /* 0xe6 S^(D&~(P&S)) */
403 { OP(PAT,SRC,GXxor), OP(PAT,DST,GXxor),
404 OP(SRC,DST,GXnand) }, /* 0xe7 ~((S^P)&(D^P)) */
405 { OP(SRC,TMP,GXcopy), OP(SRC,DST,GXxor),
406 OP(PAT,SRC,GXxor), OP(SRC,DST,GXand),
407 OP(TMP,DST,GXxor) }, /* 0xe8 S^((S^P)&(S^D))*/
408 { OP(DST,TMP,GXcopy), OP(SRC,DST,GXnand),
409 OP(PAT,DST,GXand), OP(SRC,DST,GXxor),
410 OP(TMP,DST,GXequiv) }, /* 0xe9 ~D^S^(P&~(S&D))*/
411 { OP(PAT,SRC,GXand), OP(SRC,DST,GXor) }, /* 0xea D|(P&S) */
412 { OP(PAT,SRC,GXequiv), OP(SRC,DST,GXor) }, /* 0xeb D|~(P^S) */
413 { OP(PAT,DST,GXand), OP(SRC,DST,GXor) }, /* 0xec S|(D&P) */
414 { OP(PAT,DST,GXequiv), OP(SRC,DST,GXor) }, /* 0xed S|~(D^P) */
415 { OP(SRC,DST,GXor) }, /* 0xee S|D */
416 { OP(PAT,DST,GXorInverted), OP(SRC,DST,GXor) }, /* 0xef S|D|~P */
417 { OP(PAT,DST,GXcopy) }, /* 0xf0 P */
418 { OP(SRC,DST,GXnor), OP(PAT,DST,GXor) }, /* 0xf1 P|~(D|S) */
419 { OP(SRC,DST,GXandInverted), OP(PAT,DST,GXor) }, /* 0xf2 P|(D&~S) */
420 { OP(PAT,SRC,GXorReverse) }, /* 0xf3 P|~S */
421 { OP(SRC,DST,GXandReverse), OP(PAT,DST,GXor) }, /* 0xf4 P|(S&~D) */
422 { OP(PAT,DST,GXorReverse) }, /* 0xf5 P|~D */
423 { OP(SRC,DST,GXxor), OP(PAT,DST,GXor) }, /* 0xf6 P|(D^S) */
424 { OP(SRC,DST,GXnand), OP(PAT,DST,GXor) }, /* 0xf7 P|~(S&D) */
425 { OP(SRC,DST,GXand), OP(PAT,DST,GXor) }, /* 0xf8 P|(D&S) */
426 { OP(SRC,DST,GXequiv), OP(PAT,DST,GXor) }, /* 0xf9 P|~(D^S) */
427 { OP(PAT,DST,GXor) }, /* 0xfa D|P */
428 { OP(PAT,SRC,GXorReverse), OP(SRC,DST,GXor) }, /* 0xfb D|P|~S */
429 { OP(PAT,SRC,GXor) }, /* 0xfc P|S */
430 { OP(SRC,DST,GXorReverse), OP(PAT,DST,GXor) }, /* 0xfd P|S|~D */
431 { OP(SRC,DST,GXor), OP(PAT,DST,GXor) }, /* 0xfe P|D|S */
432 { OP(PAT,DST,GXset) } /* 0xff 1 */
436 #ifdef BITBLT_TEST /* Opcodes test */
438 static int do_bitop( int s, int d, int rop )
440 int res;
441 switch(rop)
443 case GXclear: res = 0; break;
444 case GXand: res = s & d; break;
445 case GXandReverse: res = s & ~d; break;
446 case GXcopy: res = s; break;
447 case GXandInverted: res = ~s & d; break;
448 case GXnoop: res = d; break;
449 case GXxor: res = s ^ d; break;
450 case GXor: res = s | d; break;
451 case GXnor: res = ~(s | d); break;
452 case GXequiv: res = ~s ^ d; break;
453 case GXinvert: res = ~d; break;
454 case GXorReverse: res = s | ~d; break;
455 case GXcopyInverted: res = ~s; break;
456 case GXorInverted: res = ~s | d; break;
457 case GXnand: res = ~(s & d); break;
458 case GXset: res = 1; break;
460 return res & 1;
463 main()
465 int rop, i, res, src, dst, pat, tmp, dstUsed;
466 const BYTE *opcode;
468 for (rop = 0; rop < 256; rop++)
470 res = dstUsed = 0;
471 for (i = 0; i < 8; i++)
473 pat = (i >> 2) & 1;
474 src = (i >> 1) & 1;
475 dst = i & 1;
476 for (opcode = BITBLT_Opcodes[rop]; *opcode; opcode++)
478 switch(*opcode >> 4)
480 case OP_ARGS(DST,TMP):
481 tmp = do_bitop( dst, tmp, *opcode & 0xf );
482 break;
483 case OP_ARGS(DST,SRC):
484 src = do_bitop( dst, src, *opcode & 0xf );
485 break;
486 case OP_ARGS(SRC,TMP):
487 tmp = do_bitop( src, tmp, *opcode & 0xf );
488 break;
489 case OP_ARGS(SRC,DST):
490 dst = do_bitop( src, dst, *opcode & 0xf );
491 dstUsed = 1;
492 break;
493 case OP_ARGS(PAT,TMP):
494 tmp = do_bitop( pat, tmp, *opcode & 0xf );
495 break;
496 case OP_ARGS(PAT,DST):
497 dst = do_bitop( pat, dst, *opcode & 0xf );
498 dstUsed = 1;
499 break;
500 case OP_ARGS(PAT,SRC):
501 src = do_bitop( pat, src, *opcode & 0xf );
502 break;
503 case OP_ARGS(TMP,DST):
504 dst = do_bitop( tmp, dst, *opcode & 0xf );
505 dstUsed = 1;
506 break;
507 case OP_ARGS(TMP,SRC):
508 src = do_bitop( tmp, src, *opcode & 0xf );
509 break;
510 default:
511 printf( "Invalid opcode %x\n", *opcode );
514 if (!dstUsed) dst = src;
515 if (dst) res |= 1 << i;
517 if (res != rop) printf( "%02x: ERROR, res=%02x\n", rop, res );
521 #endif /* BITBLT_TEST */
524 /***********************************************************************
525 * BITBLT_StretchRow
527 * Stretch a row of pixels. Helper function for BITBLT_StretchImage.
529 static void BITBLT_StretchRow( int *rowSrc, int *rowDst,
530 INT startDst, INT widthDst,
531 INT xinc, INT xoff, WORD mode )
533 register INT xsrc = xinc * startDst + xoff;
534 rowDst += startDst;
535 switch(mode)
537 case STRETCH_ANDSCANS:
538 for(; widthDst > 0; widthDst--, xsrc += xinc)
539 *rowDst++ &= rowSrc[xsrc >> 16];
540 break;
541 case STRETCH_ORSCANS:
542 for(; widthDst > 0; widthDst--, xsrc += xinc)
543 *rowDst++ |= rowSrc[xsrc >> 16];
544 break;
545 case STRETCH_DELETESCANS:
546 for(; widthDst > 0; widthDst--, xsrc += xinc)
547 *rowDst++ = rowSrc[xsrc >> 16];
548 break;
553 /***********************************************************************
554 * BITBLT_ShrinkRow
556 * Shrink a row of pixels. Helper function for BITBLT_StretchImage.
558 static void BITBLT_ShrinkRow( int *rowSrc, int *rowDst,
559 INT startSrc, INT widthSrc,
560 INT xinc, INT xoff, WORD mode )
562 register INT xdst = xinc * startSrc + xoff;
563 rowSrc += startSrc;
564 switch(mode)
566 case STRETCH_ORSCANS:
567 for(; widthSrc > 0; widthSrc--, xdst += xinc)
568 rowDst[xdst >> 16] |= *rowSrc++;
569 break;
570 case STRETCH_ANDSCANS:
571 for(; widthSrc > 0; widthSrc--, xdst += xinc)
572 rowDst[xdst >> 16] &= *rowSrc++;
573 break;
574 case STRETCH_DELETESCANS:
575 for(; widthSrc > 0; widthSrc--, xdst += xinc)
576 rowDst[xdst >> 16] = *rowSrc++;
577 break;
582 /***********************************************************************
583 * BITBLT_GetRow
585 * Retrieve a row from an image. Helper function for BITBLT_StretchImage.
587 static void BITBLT_GetRow( XImage *image, int *pdata, INT row,
588 INT start, INT width, INT depthDst,
589 int fg, int bg, BOOL swap)
591 register INT i;
593 assert( (row >= 0) && (row < image->height) );
594 assert( (start >= 0) && (width <= image->width) );
596 pdata += swap ? start+width-1 : start;
597 if (image->depth == depthDst) /* color -> color */
599 if (COLOR_PixelToPalette && (depthDst != 1))
600 if (swap) for (i = 0; i < width; i++)
601 *pdata-- = COLOR_PixelToPalette[XGetPixel( image, i, row )];
602 else for (i = 0; i < width; i++)
603 *pdata++ = COLOR_PixelToPalette[XGetPixel( image, i, row )];
604 else
605 if (swap) for (i = 0; i < width; i++)
606 *pdata-- = XGetPixel( image, i, row );
607 else for (i = 0; i < width; i++)
608 *pdata++ = XGetPixel( image, i, row );
610 else
612 if (image->depth == 1) /* monochrome -> color */
614 if (COLOR_PixelToPalette)
616 fg = COLOR_PixelToPalette[fg];
617 bg = COLOR_PixelToPalette[bg];
619 if (swap) for (i = 0; i < width; i++)
620 *pdata-- = XGetPixel( image, i, row ) ? bg : fg;
621 else for (i = 0; i < width; i++)
622 *pdata++ = XGetPixel( image, i, row ) ? bg : fg;
624 else /* color -> monochrome */
626 if (swap) for (i = 0; i < width; i++)
627 *pdata-- = (XGetPixel( image, i, row ) == bg) ? 1 : 0;
628 else for (i = 0; i < width; i++)
629 *pdata++ = (XGetPixel( image, i, row ) == bg) ? 1 : 0;
635 /***********************************************************************
636 * BITBLT_StretchImage
638 * Stretch an X image.
639 * FIXME: does not work for full 32-bit coordinates.
641 static void BITBLT_StretchImage( XImage *srcImage, XImage *dstImage,
642 INT widthSrc, INT heightSrc,
643 INT widthDst, INT heightDst,
644 RECT *visRectSrc, RECT *visRectDst,
645 int foreground, int background, WORD mode )
647 int *rowSrc, *rowDst, *pixel;
648 char *pdata;
649 INT xinc, xoff, yinc, ysrc, ydst;
650 register INT x, y;
651 BOOL hstretch, vstretch, hswap, vswap;
653 hswap = ((int)widthSrc * widthDst) < 0;
654 vswap = ((int)heightSrc * heightDst) < 0;
655 widthSrc = abs(widthSrc);
656 heightSrc = abs(heightSrc);
657 widthDst = abs(widthDst);
658 heightDst = abs(heightDst);
660 if (!(rowSrc = (int *)HeapAlloc( GetProcessHeap(), 0,
661 (widthSrc+widthDst)*sizeof(int) ))) return;
662 rowDst = rowSrc + widthSrc;
664 /* When stretching, all modes are the same, and DELETESCANS is faster */
665 if ((widthSrc < widthDst) && (heightSrc < heightDst))
666 mode = STRETCH_DELETESCANS;
668 if (mode != STRETCH_DELETESCANS)
669 memset( rowDst, (mode == STRETCH_ANDSCANS) ? 0xff : 0x00,
670 widthDst*sizeof(int) );
672 hstretch = (widthSrc < widthDst);
673 vstretch = (heightSrc < heightDst);
675 if (hstretch)
677 xinc = ((int)widthSrc << 16) / widthDst;
678 xoff = ((widthSrc << 16) - (xinc * widthDst)) / 2;
680 else
682 xinc = ((int)widthDst << 16) / widthSrc;
683 xoff = ((widthDst << 16) - (xinc * widthSrc)) / 2;
686 if (vstretch)
688 yinc = ((int)heightSrc << 16) / heightDst;
689 ydst = visRectDst->top;
690 if (vswap)
692 ysrc = yinc * (heightDst - ydst - 1);
693 yinc = -yinc;
695 else
696 ysrc = yinc * ydst;
698 for ( ; (ydst < visRectDst->bottom); ysrc += yinc, ydst++)
700 if (((ysrc >> 16) < visRectSrc->top) ||
701 ((ysrc >> 16) >= visRectSrc->bottom)) continue;
703 /* Retrieve a source row */
704 BITBLT_GetRow( srcImage, rowSrc, (ysrc >> 16) - visRectSrc->top,
705 hswap ? widthSrc - visRectSrc->right
706 : visRectSrc->left,
707 visRectSrc->right - visRectSrc->left,
708 dstImage->depth, foreground, background, hswap );
710 /* Stretch or shrink it */
711 if (hstretch)
712 BITBLT_StretchRow( rowSrc, rowDst, visRectDst->left,
713 visRectDst->right - visRectDst->left,
714 xinc, xoff, mode );
715 else BITBLT_ShrinkRow( rowSrc, rowDst,
716 hswap ? widthSrc - visRectSrc->right
717 : visRectSrc->left,
718 visRectSrc->right - visRectSrc->left,
719 xinc, xoff, mode );
721 /* Store the destination row */
722 pixel = rowDst + visRectDst->right - 1;
723 y = ydst - visRectDst->top;
724 for (x = visRectDst->right-visRectDst->left-1; x >= 0; x--)
725 XPutPixel( dstImage, x, y, *pixel-- );
726 if (mode != STRETCH_DELETESCANS)
727 memset( rowDst, (mode == STRETCH_ANDSCANS) ? 0xff : 0x00,
728 widthDst*sizeof(int) );
730 /* Make copies of the destination row */
732 pdata = dstImage->data + dstImage->bytes_per_line * y;
733 while (((ysrc + yinc) >> 16 == ysrc >> 16) &&
734 (ydst < visRectDst->bottom-1))
736 memcpy( pdata + dstImage->bytes_per_line, pdata,
737 dstImage->bytes_per_line );
738 pdata += dstImage->bytes_per_line;
739 ysrc += yinc;
740 ydst++;
744 else /* Shrinking */
746 yinc = ((int)heightDst << 16) / heightSrc;
747 ysrc = visRectSrc->top;
748 ydst = ((heightDst << 16) - (yinc * heightSrc)) / 2;
749 if (vswap)
751 ydst += yinc * (heightSrc - ysrc - 1);
752 yinc = -yinc;
754 else
755 ydst += yinc * ysrc;
757 for( ; (ysrc < visRectSrc->bottom); ydst += yinc, ysrc++)
759 if (((ydst >> 16) < visRectDst->top) ||
760 ((ydst >> 16) >= visRectDst->bottom)) continue;
762 /* Retrieve a source row */
763 BITBLT_GetRow( srcImage, rowSrc, ysrc - visRectSrc->top,
764 hswap ? widthSrc - visRectSrc->right
765 : visRectSrc->left,
766 visRectSrc->right - visRectSrc->left,
767 dstImage->depth, foreground, background, hswap );
769 /* Stretch or shrink it */
770 if (hstretch)
771 BITBLT_StretchRow( rowSrc, rowDst, visRectDst->left,
772 visRectDst->right - visRectDst->left,
773 xinc, xoff, mode );
774 else BITBLT_ShrinkRow( rowSrc, rowDst,
775 hswap ? widthSrc - visRectSrc->right
776 : visRectSrc->left,
777 visRectSrc->right - visRectSrc->left,
778 xinc, xoff, mode );
780 /* Merge several source rows into the destination */
781 if (mode == STRETCH_DELETESCANS)
783 /* Simply skip the overlapping rows */
784 while (((ydst + yinc) >> 16 == ydst >> 16) &&
785 (ysrc < visRectSrc->bottom-1))
787 ydst += yinc;
788 ysrc++;
791 else if (((ydst + yinc) >> 16 == ydst >> 16) &&
792 (ysrc < visRectSrc->bottom-1))
793 continue; /* Restart loop for next overlapping row */
795 /* Store the destination row */
796 pixel = rowDst + visRectDst->right - 1;
797 y = (ydst >> 16) - visRectDst->top;
798 for (x = visRectDst->right-visRectDst->left-1; x >= 0; x--)
799 XPutPixel( dstImage, x, y, *pixel-- );
800 if (mode != STRETCH_DELETESCANS)
801 memset( rowDst, (mode == STRETCH_ANDSCANS) ? 0xff : 0x00,
802 widthDst*sizeof(int) );
805 HeapFree( GetProcessHeap(), 0, rowSrc );
809 /***********************************************************************
810 * BITBLT_GetSrcAreaStretch
812 * Retrieve an area from the source DC, stretching and mapping all the
813 * pixels to Windows colors.
815 static void BITBLT_GetSrcAreaStretch( DC *dcSrc, DC *dcDst,
816 Pixmap pixmap, GC gc,
817 INT xSrc, INT ySrc,
818 INT widthSrc, INT heightSrc,
819 INT xDst, INT yDst,
820 INT widthDst, INT heightDst,
821 RECT *visRectSrc, RECT *visRectDst )
823 XImage *imageSrc, *imageDst;
824 X11DRV_PDEVICE *physDevSrc = (X11DRV_PDEVICE *)dcSrc->physDev;
825 X11DRV_PDEVICE *physDevDst = (X11DRV_PDEVICE *)dcDst->physDev;
827 RECT rectSrc = *visRectSrc;
828 RECT rectDst = *visRectDst;
830 if (widthSrc < 0) xSrc += widthSrc;
831 if (widthDst < 0) xDst += widthDst;
832 if (heightSrc < 0) ySrc += heightSrc;
833 if (heightDst < 0) yDst += heightDst;
834 OffsetRect( &rectSrc, -xSrc, -ySrc );
835 OffsetRect( &rectDst, -xDst, -yDst );
837 /* FIXME: avoid BadMatch errors */
838 imageSrc = XGetImage( display, physDevSrc->drawable,
839 visRectSrc->left, visRectSrc->top,
840 visRectSrc->right - visRectSrc->left,
841 visRectSrc->bottom - visRectSrc->top,
842 AllPlanes, ZPixmap );
843 XCREATEIMAGE( imageDst, rectDst.right - rectDst.left,
844 rectDst.bottom - rectDst.top, dcDst->w.bitsPerPixel );
845 BITBLT_StretchImage( imageSrc, imageDst, widthSrc, heightSrc,
846 widthDst, heightDst, &rectSrc, &rectDst,
847 physDevDst->textPixel, dcDst->w.bitsPerPixel != 1 ?
848 physDevDst->backgroundPixel :
849 physDevSrc->backgroundPixel,
850 dcDst->w.stretchBltMode );
851 XPutImage( display, pixmap, gc, imageDst, 0, 0, 0, 0,
852 rectDst.right - rectDst.left, rectDst.bottom - rectDst.top );
853 XDestroyImage( imageSrc );
854 XDestroyImage( imageDst );
858 /***********************************************************************
859 * BITBLT_GetSrcArea
861 * Retrieve an area from the source DC, mapping all the
862 * pixels to Windows colors.
864 static void BITBLT_GetSrcArea( DC *dcSrc, DC *dcDst, Pixmap pixmap, GC gc,
865 INT xSrc, INT ySrc, RECT *visRectSrc )
867 XImage *imageSrc, *imageDst;
868 register INT x, y;
869 INT width = visRectSrc->right - visRectSrc->left;
870 INT height = visRectSrc->bottom - visRectSrc->top;
871 X11DRV_PDEVICE *physDevSrc = (X11DRV_PDEVICE *)dcSrc->physDev;
872 X11DRV_PDEVICE *physDevDst = (X11DRV_PDEVICE *)dcDst->physDev;
874 if (dcSrc->w.bitsPerPixel == dcDst->w.bitsPerPixel)
876 if (!COLOR_PixelToPalette ||
877 (dcDst->w.bitsPerPixel == 1)) /* monochrome -> monochrome */
879 XCopyArea( display, physDevSrc->drawable, pixmap, gc,
880 visRectSrc->left, visRectSrc->top, width, height, 0, 0);
882 else /* color -> color */
884 if (dcSrc->w.flags & DC_MEMORY)
885 imageSrc = XGetImage( display, physDevSrc->drawable,
886 visRectSrc->left, visRectSrc->top,
887 width, height, AllPlanes, ZPixmap );
888 else
890 /* Make sure we don't get a BadMatch error */
891 XCopyArea( display, physDevSrc->drawable, pixmap, gc,
892 visRectSrc->left, visRectSrc->top,
893 width, height, 0, 0);
894 imageSrc = XGetImage( display, pixmap, 0, 0, width, height,
895 AllPlanes, ZPixmap );
897 for (y = 0; y < height; y++)
898 for (x = 0; x < width; x++)
899 XPutPixel(imageSrc, x, y,
900 COLOR_PixelToPalette[XGetPixel(imageSrc, x, y)]);
901 XPutImage( display, pixmap, gc, imageSrc,
902 0, 0, 0, 0, width, height );
903 XDestroyImage( imageSrc );
906 else
908 if (dcSrc->w.bitsPerPixel == 1) /* monochrome -> color */
910 if (COLOR_PixelToPalette)
912 XSetBackground( display, gc,
913 COLOR_PixelToPalette[physDevDst->textPixel] );
914 XSetForeground( display, gc,
915 COLOR_PixelToPalette[physDevDst->backgroundPixel]);
917 else
919 XSetBackground( display, gc, physDevDst->textPixel );
920 XSetForeground( display, gc, physDevDst->backgroundPixel );
922 XCopyPlane( display, physDevSrc->drawable, pixmap, gc,
923 visRectSrc->left, visRectSrc->top,
924 width, height, 0, 0, 1 );
926 else /* color -> monochrome */
928 /* FIXME: avoid BadMatch error */
929 imageSrc = XGetImage( display, physDevSrc->drawable,
930 visRectSrc->left, visRectSrc->top,
931 width, height, AllPlanes, ZPixmap );
932 XCREATEIMAGE( imageDst, width, height, dcDst->w.bitsPerPixel );
933 for (y = 0; y < height; y++)
934 for (x = 0; x < width; x++)
935 XPutPixel(imageDst, x, y, (XGetPixel(imageSrc,x,y) ==
936 physDevSrc->backgroundPixel) );
937 XPutImage( display, pixmap, gc, imageDst,
938 0, 0, 0, 0, width, height );
939 XDestroyImage( imageSrc );
940 XDestroyImage( imageDst );
946 /***********************************************************************
947 * BITBLT_GetDstArea
949 * Retrieve an area from the destination DC, mapping all the
950 * pixels to Windows colors.
952 static void BITBLT_GetDstArea(DC *dc, Pixmap pixmap, GC gc, RECT *visRectDst)
954 INT width = visRectDst->right - visRectDst->left;
955 INT height = visRectDst->bottom - visRectDst->top;
956 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
958 if (!COLOR_PixelToPalette || (dc->w.bitsPerPixel == 1) ||
959 (COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL) )
961 XCopyArea( display, physDev->drawable, pixmap, gc,
962 visRectDst->left, visRectDst->top, width, height, 0, 0 );
964 else
966 register INT x, y;
967 XImage *image;
969 if (dc->w.flags & DC_MEMORY)
970 image = XGetImage( display, physDev->drawable,
971 visRectDst->left, visRectDst->top,
972 width, height, AllPlanes, ZPixmap );
973 else
975 /* Make sure we don't get a BadMatch error */
976 XCopyArea( display, physDev->drawable, pixmap, gc,
977 visRectDst->left, visRectDst->top, width, height, 0, 0);
978 image = XGetImage( display, pixmap, 0, 0, width, height,
979 AllPlanes, ZPixmap );
981 for (y = 0; y < height; y++)
982 for (x = 0; x < width; x++)
983 XPutPixel( image, x, y,
984 COLOR_PixelToPalette[XGetPixel( image, x, y )]);
985 XPutImage( display, pixmap, gc, image, 0, 0, 0, 0, width, height );
986 XDestroyImage( image );
991 /***********************************************************************
992 * BITBLT_PutDstArea
994 * Put an area back into the destination DC, mapping the pixel
995 * colors to X pixels.
997 static void BITBLT_PutDstArea(DC *dc, Pixmap pixmap, GC gc, RECT *visRectDst)
999 INT width = visRectDst->right - visRectDst->left;
1000 INT height = visRectDst->bottom - visRectDst->top;
1001 X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
1003 /* !COLOR_PaletteToPixel is _NOT_ enough */
1005 if (!COLOR_PaletteToPixel || (dc->w.bitsPerPixel == 1) ||
1006 (COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL) )
1008 XCopyArea( display, pixmap, physDev->drawable, gc, 0, 0,
1009 width, height, visRectDst->left, visRectDst->top );
1011 else
1013 register INT x, y;
1014 XImage *image = XGetImage( display, pixmap, 0, 0, width, height,
1015 AllPlanes, ZPixmap );
1016 for (y = 0; y < height; y++)
1017 for (x = 0; x < width; x++)
1019 XPutPixel( image, x, y,
1020 COLOR_PaletteToPixel[XGetPixel( image, x, y )]);
1022 XPutImage( display, physDev->drawable, gc, image, 0, 0,
1023 visRectDst->left, visRectDst->top, width, height );
1024 XDestroyImage( image );
1029 /***********************************************************************
1030 * BITBLT_GetVisRectangles
1032 * Get the source and destination visible rectangles for StretchBlt().
1033 * Return FALSE if one of the rectangles is empty.
1035 static BOOL BITBLT_GetVisRectangles( DC *dcDst, INT xDst, INT yDst,
1036 INT widthDst, INT heightDst,
1037 DC *dcSrc, INT xSrc, INT ySrc,
1038 INT widthSrc, INT heightSrc,
1039 RECT *visRectSrc, RECT *visRectDst )
1041 RECT rect, clipRect;
1043 /* Get the destination visible rectangle */
1045 SetRect( &rect, xDst, yDst, xDst + widthDst, yDst + heightDst );
1046 if (widthDst < 0) SWAP_INT32( &rect.left, &rect.right );
1047 if (heightDst < 0) SWAP_INT32( &rect.top, &rect.bottom );
1048 GetRgnBox( dcDst->w.hGCClipRgn, &clipRect );
1049 if (!IntersectRect( visRectDst, &rect, &clipRect )) return FALSE;
1051 /* Get the source visible rectangle */
1053 if (!dcSrc) return TRUE;
1054 SetRect( &rect, xSrc, ySrc, xSrc + widthSrc, ySrc + heightSrc );
1055 if (widthSrc < 0) SWAP_INT32( &rect.left, &rect.right );
1056 if (heightSrc < 0) SWAP_INT32( &rect.top, &rect.bottom );
1057 /* Apparently the clipping and visible regions are only for output,
1058 so just check against totalExtent here to avoid BadMatch errors */
1059 if (!IntersectRect( visRectSrc, &rect, &dcSrc->w.totalExtent ))
1060 return FALSE;
1062 /* Intersect the rectangles */
1064 if ((widthSrc == widthDst) && (heightSrc == heightDst)) /* no stretching */
1066 OffsetRect( visRectSrc, xDst - xSrc, yDst - ySrc );
1067 if (!IntersectRect( &rect, visRectSrc, visRectDst )) return FALSE;
1068 *visRectSrc = *visRectDst = rect;
1069 OffsetRect( visRectSrc, xSrc - xDst, ySrc - yDst );
1071 else /* stretching */
1073 /* Map source rectangle into destination coordinates */
1074 rect.left = xDst + (visRectSrc->left - xSrc)*widthDst/widthSrc;
1075 rect.top = yDst + (visRectSrc->top - ySrc)*heightDst/heightSrc;
1076 rect.right = xDst + ((visRectSrc->right - xSrc)*widthDst)/widthSrc;
1077 rect.bottom = yDst + ((visRectSrc->bottom - ySrc)*heightDst)/heightSrc;
1078 if (rect.left > rect.right) SWAP_INT32( &rect.left, &rect.right );
1079 if (rect.top > rect.bottom) SWAP_INT32( &rect.top, &rect.bottom );
1080 InflateRect( &rect, 1, 1 ); /* Avoid rounding errors */
1081 if (!IntersectRect( visRectDst, &rect, visRectDst )) return FALSE;
1083 /* Map destination rectangle back to source coordinates */
1084 rect = *visRectDst;
1085 rect.left = xSrc + (visRectDst->left - xDst)*widthSrc/widthDst;
1086 rect.top = ySrc + (visRectDst->top - yDst)*heightSrc/heightDst;
1087 rect.right = xSrc + ((visRectDst->right - xDst)*widthSrc)/widthDst;
1088 rect.bottom = ySrc + ((visRectDst->bottom - yDst)*heightSrc)/heightDst;
1089 if (rect.left > rect.right) SWAP_INT32( &rect.left, &rect.right );
1090 if (rect.top > rect.bottom) SWAP_INT32( &rect.top, &rect.bottom );
1091 InflateRect( &rect, 1, 1 ); /* Avoid rounding errors */
1092 if (!IntersectRect( visRectSrc, &rect, visRectSrc )) return FALSE;
1094 return TRUE;
1098 /***********************************************************************
1099 * BITBLT_InternalStretchBlt
1101 * Implementation of PatBlt(), BitBlt() and StretchBlt().
1103 static BOOL BITBLT_InternalStretchBlt( DC *dcDst, INT xDst, INT yDst,
1104 INT widthDst, INT heightDst,
1105 DC *dcSrc, INT xSrc, INT ySrc,
1106 INT widthSrc, INT heightSrc,
1107 DWORD rop )
1109 BOOL usePat, useSrc, useDst, destUsed, fStretch, fNullBrush;
1110 RECT visRectDst, visRectSrc;
1111 INT width, height;
1112 const BYTE *opcode;
1113 Pixmap pixmaps[3] = { 0, 0, 0 }; /* pixmaps for DST, SRC, TMP */
1114 GC tmpGC = 0;
1115 X11DRV_PDEVICE *physDevSrc = NULL;
1116 X11DRV_PDEVICE *physDevDst = (X11DRV_PDEVICE *)dcDst->physDev;
1118 if(dcSrc) physDevSrc = (X11DRV_PDEVICE *)dcSrc->physDev;
1119 usePat = (((rop >> 4) & 0x0f0000) != (rop & 0x0f0000));
1120 useSrc = (((rop >> 2) & 0x330000) != (rop & 0x330000));
1121 useDst = (((rop >> 1) & 0x550000) != (rop & 0x550000));
1122 if (!dcSrc && useSrc) return FALSE;
1124 if (dcDst->w.flags & DC_DIRTY) CLIPPING_UpdateGCRegion( dcDst );
1125 if (dcSrc && (dcSrc->w.flags & DC_DIRTY)) CLIPPING_UpdateGCRegion( dcSrc );
1127 /* Map the coordinates to device coords */
1129 xDst = dcDst->w.DCOrgX + XLPTODP( dcDst, xDst );
1130 yDst = dcDst->w.DCOrgY + YLPTODP( dcDst, yDst );
1131 widthDst = widthDst * dcDst->vportExtX / dcDst->wndExtX;
1132 heightDst = heightDst * dcDst->vportExtY / dcDst->wndExtY;
1134 TRACE(bitblt, " vportdst=%d,%d-%d,%d wnddst=%d,%d-%d,%d\n",
1135 dcDst->vportOrgX, dcDst->vportOrgY,
1136 dcDst->vportExtX, dcDst->vportExtY,
1137 dcDst->wndOrgX, dcDst->wndOrgY,
1138 dcDst->wndExtX, dcDst->wndExtY );
1139 TRACE(bitblt, " rectdst=%d,%d-%d,%d orgdst=%d,%d\n",
1140 xDst, yDst, widthDst, heightDst,
1141 dcDst->w.DCOrgX, dcDst->w.DCOrgY );
1143 if (useSrc)
1145 xSrc = dcSrc->w.DCOrgX + XLPTODP( dcSrc, xSrc );
1146 ySrc = dcSrc->w.DCOrgY + YLPTODP( dcSrc, ySrc );
1147 widthSrc = widthSrc * dcSrc->vportExtX / dcSrc->wndExtX;
1148 heightSrc = heightSrc * dcSrc->vportExtY / dcSrc->wndExtY;
1149 fStretch = (widthSrc != widthDst) || (heightSrc != heightDst);
1150 TRACE(bitblt," vportsrc=%d,%d-%d,%d wndsrc=%d,%d-%d,%d\n",
1151 dcSrc->vportOrgX, dcSrc->vportOrgY,
1152 dcSrc->vportExtX, dcSrc->vportExtY,
1153 dcSrc->wndOrgX, dcSrc->wndOrgY,
1154 dcSrc->wndExtX, dcSrc->wndExtY );
1155 TRACE(bitblt, " rectsrc=%d,%d-%d,%d orgsrc=%d,%d\n",
1156 xSrc, ySrc, widthSrc, heightSrc,
1157 dcSrc->w.DCOrgX, dcSrc->w.DCOrgY );
1158 if (!BITBLT_GetVisRectangles( dcDst, xDst, yDst, widthDst, heightDst,
1159 dcSrc, xSrc, ySrc, widthSrc, heightSrc,
1160 &visRectSrc, &visRectDst ))
1161 return TRUE;
1162 TRACE(bitblt, " vissrc=%d,%d-%d,%d visdst=%d,%d-%d,%d\n",
1163 visRectSrc.left, visRectSrc.top,
1164 visRectSrc.right, visRectSrc.bottom,
1165 visRectDst.left, visRectDst.top,
1166 visRectDst.right, visRectDst.bottom );
1168 else
1170 fStretch = FALSE;
1171 if (!BITBLT_GetVisRectangles( dcDst, xDst, yDst, widthDst, heightDst,
1172 NULL, 0, 0, 0, 0, NULL, &visRectDst ))
1173 return TRUE;
1174 TRACE(bitblt, " vissrc=none visdst=%d,%d-%d,%d\n",
1175 visRectDst.left, visRectDst.top,
1176 visRectDst.right, visRectDst.bottom );
1179 width = visRectDst.right - visRectDst.left;
1180 height = visRectDst.bottom - visRectDst.top;
1182 if (!fStretch) switch(rop) /* A few optimisations */
1184 case BLACKNESS: /* 0x00 */
1185 if ((dcDst->w.bitsPerPixel == 1) || !COLOR_PaletteToPixel)
1186 XSetFunction( display, physDevDst->gc, GXclear );
1187 else
1189 XSetFunction( display, physDevDst->gc, GXcopy );
1190 XSetForeground( display, physDevDst->gc, COLOR_PaletteToPixel[0] );
1191 XSetFillStyle( display, physDevDst->gc, FillSolid );
1193 XFillRectangle( display, physDevDst->drawable, physDevDst->gc,
1194 visRectDst.left, visRectDst.top, width, height );
1195 return TRUE;
1197 case DSTINVERT: /* 0x55 */
1198 if ((dcDst->w.bitsPerPixel == 1) || !COLOR_PaletteToPixel ||
1199 !Options.perfectGraphics)
1201 XSetFunction( display, physDevDst->gc, GXinvert );
1203 if( COLOR_GetSystemPaletteFlags() & (COLOR_PRIVATE | COLOR_VIRTUAL) )
1204 XSetFunction( display, physDevDst->gc, GXinvert);
1205 else
1207 /* Xor is much better when we do not have full colormap. */
1208 /* Using white^black ensures that we invert at least black */
1209 /* and white. */
1210 Pixel xor_pix = (WhitePixelOfScreen(X11DRV_GetXScreen()) ^
1211 BlackPixelOfScreen(X11DRV_GetXScreen()));
1212 XSetFunction( display, physDevDst->gc, GXxor );
1213 XSetForeground( display, physDevDst->gc, xor_pix);
1214 XSetFillStyle( display, physDevDst->gc, FillSolid );
1216 XFillRectangle( display, physDevDst->drawable, physDevDst->gc,
1217 visRectDst.left, visRectDst.top, width, height );
1218 return TRUE;
1220 break;
1222 case PATINVERT: /* 0x5a */
1223 if (Options.perfectGraphics) break;
1224 if (X11DRV_SetupGCForBrush( dcDst ))
1226 XSetFunction( display, physDevDst->gc, GXxor );
1227 XFillRectangle( display, physDevDst->drawable, physDevDst->gc,
1228 visRectDst.left, visRectDst.top, width, height );
1230 return TRUE;
1232 case 0xa50065:
1233 if (Options.perfectGraphics) break;
1234 if (X11DRV_SetupGCForBrush( dcDst ))
1236 XSetFunction( display, physDevDst->gc, GXequiv );
1237 XFillRectangle( display, physDevDst->drawable, physDevDst->gc,
1238 visRectDst.left, visRectDst.top, width, height );
1240 return TRUE;
1242 case SRCCOPY: /* 0xcc */
1243 if (dcSrc->w.bitsPerPixel == dcDst->w.bitsPerPixel)
1245 XSetGraphicsExposures( display, physDevDst->gc, True );
1246 XSetFunction( display, physDevDst->gc, GXcopy );
1247 XCopyArea( display, physDevSrc->drawable,
1248 physDevDst->drawable, physDevDst->gc,
1249 visRectSrc.left, visRectSrc.top,
1250 width, height, visRectDst.left, visRectDst.top );
1251 XSetGraphicsExposures( display, physDevDst->gc, False );
1252 return TRUE;
1254 if (dcSrc->w.bitsPerPixel == 1)
1256 XSetBackground( display, physDevDst->gc, physDevDst->textPixel );
1257 XSetForeground( display, physDevDst->gc,
1258 physDevDst->backgroundPixel );
1259 XSetFunction( display, physDevDst->gc, GXcopy );
1260 XSetGraphicsExposures( display, physDevDst->gc, True );
1261 XCopyPlane( display, physDevSrc->drawable,
1262 physDevDst->drawable, physDevDst->gc,
1263 visRectSrc.left, visRectSrc.top,
1264 width, height, visRectDst.left, visRectDst.top, 1 );
1265 XSetGraphicsExposures( display, physDevDst->gc, False );
1266 return TRUE;
1268 break;
1270 case PATCOPY: /* 0xf0 */
1271 if (!X11DRV_SetupGCForBrush( dcDst )) return TRUE;
1272 XSetFunction( display, physDevDst->gc, GXcopy );
1273 XFillRectangle( display, physDevDst->drawable, physDevDst->gc,
1274 visRectDst.left, visRectDst.top, width, height );
1275 return TRUE;
1277 case WHITENESS: /* 0xff */
1278 if ((dcDst->w.bitsPerPixel == 1) || !COLOR_PaletteToPixel)
1279 XSetFunction( display, physDevDst->gc, GXset );
1280 else
1282 XSetFunction( display, physDevDst->gc, GXcopy );
1283 XSetForeground( display, physDevDst->gc,
1284 COLOR_PaletteToPixel[COLOR_GetSystemPaletteSize() - 1]);
1285 XSetFillStyle( display, physDevDst->gc, FillSolid );
1287 XFillRectangle( display, physDevDst->drawable, physDevDst->gc,
1288 visRectDst.left, visRectDst.top, width, height );
1289 return TRUE;
1292 tmpGC = XCreateGC( display, physDevDst->drawable, 0, NULL );
1293 pixmaps[DST] = XCreatePixmap( display, X11DRV_GetXRootWindow(), width, height,
1294 dcDst->w.bitsPerPixel );
1295 if (useSrc)
1297 pixmaps[SRC] = XCreatePixmap( display, X11DRV_GetXRootWindow(), width, height,
1298 dcDst->w.bitsPerPixel );
1299 if (fStretch)
1300 BITBLT_GetSrcAreaStretch( dcSrc, dcDst, pixmaps[SRC], tmpGC,
1301 xSrc, ySrc, widthSrc, heightSrc,
1302 xDst, yDst, widthDst, heightDst,
1303 &visRectSrc, &visRectDst );
1304 else
1305 BITBLT_GetSrcArea( dcSrc, dcDst, pixmaps[SRC], tmpGC,
1306 xSrc, ySrc, &visRectSrc );
1308 if (useDst) BITBLT_GetDstArea( dcDst, pixmaps[DST], tmpGC, &visRectDst );
1309 if (usePat) fNullBrush = !X11DRV_SetupGCForPatBlt( dcDst, tmpGC, TRUE );
1310 else fNullBrush = FALSE;
1311 destUsed = FALSE;
1313 for (opcode = BITBLT_Opcodes[(rop >> 16) & 0xff]; *opcode; opcode++)
1315 if (OP_DST(*opcode) == DST) destUsed = TRUE;
1316 XSetFunction( display, tmpGC, OP_ROP(*opcode) );
1317 switch(OP_SRCDST(*opcode))
1319 case OP_ARGS(DST,TMP):
1320 case OP_ARGS(SRC,TMP):
1321 if (!pixmaps[TMP])
1322 pixmaps[TMP] = XCreatePixmap( display, X11DRV_GetXRootWindow(),
1323 width, height,
1324 dcDst->w.bitsPerPixel );
1325 /* fall through */
1326 case OP_ARGS(DST,SRC):
1327 case OP_ARGS(SRC,DST):
1328 case OP_ARGS(TMP,SRC):
1329 case OP_ARGS(TMP,DST):
1330 XCopyArea( display, pixmaps[OP_SRC(*opcode)],
1331 pixmaps[OP_DST(*opcode)], tmpGC,
1332 0, 0, width, height, 0, 0 );
1333 break;
1335 case OP_ARGS(PAT,TMP):
1336 if (!pixmaps[TMP] && !fNullBrush)
1337 pixmaps[TMP] = XCreatePixmap( display, X11DRV_GetXRootWindow(),
1338 width, height,
1339 dcDst->w.bitsPerPixel );
1340 /* fall through */
1341 case OP_ARGS(PAT,DST):
1342 case OP_ARGS(PAT,SRC):
1343 if (!fNullBrush)
1344 XFillRectangle( display, pixmaps[OP_DST(*opcode)],
1345 tmpGC, 0, 0, width, height );
1346 break;
1349 XSetFunction( display, physDevDst->gc, GXcopy );
1350 BITBLT_PutDstArea( dcDst, pixmaps[destUsed ? DST : SRC],
1351 physDevDst->gc, &visRectDst );
1352 XFreePixmap( display, pixmaps[DST] );
1353 if (pixmaps[SRC]) XFreePixmap( display, pixmaps[SRC] );
1354 if (pixmaps[TMP]) XFreePixmap( display, pixmaps[TMP] );
1355 XFreeGC( display, tmpGC );
1356 return TRUE;
1359 struct StretchBlt_params
1361 DC *dcDst;
1362 INT xDst;
1363 INT yDst;
1364 INT widthDst;
1365 INT heightDst;
1366 DC *dcSrc;
1367 INT xSrc;
1368 INT ySrc;
1369 INT widthSrc;
1370 INT heightSrc;
1371 DWORD rop;
1374 /***********************************************************************
1375 * BITBLT_DoStretchBlt
1377 * Wrapper function for BITBLT_InternalStretchBlt
1378 * to use with CALL_LARGE_STACK.
1380 static int BITBLT_DoStretchBlt( const struct StretchBlt_params *p )
1382 return (int)BITBLT_InternalStretchBlt( p->dcDst, p->xDst, p->yDst,
1383 p->widthDst, p->heightDst,
1384 p->dcSrc, p->xSrc, p->ySrc,
1385 p->widthSrc, p->heightSrc, p->rop );
1388 /***********************************************************************
1389 * X11DRV_PatBlt
1391 BOOL X11DRV_PatBlt( DC *dc, INT left, INT top,
1392 INT width, INT height, DWORD rop )
1394 struct StretchBlt_params params = { dc, left, top, width, height,
1395 NULL, 0, 0, 0, 0, rop };
1396 BOOL result;
1397 DIB_UpdateDIBSection( dc, FALSE );
1398 EnterCriticalSection( &X11DRV_CritSection );
1399 result = (BOOL)CALL_LARGE_STACK( BITBLT_DoStretchBlt, &params );
1400 LeaveCriticalSection( &X11DRV_CritSection );
1401 DIB_UpdateDIBSection( dc, TRUE );
1402 return result;
1406 /***********************************************************************
1407 * X11DRV_BitBlt
1409 BOOL X11DRV_BitBlt( DC *dcDst, INT xDst, INT yDst,
1410 INT width, INT height, DC *dcSrc,
1411 INT xSrc, INT ySrc, DWORD rop )
1413 struct StretchBlt_params params = { dcDst, xDst, yDst, width, height,
1414 dcSrc, xSrc, ySrc, width, height, rop};
1415 BOOL result;
1416 DIB_UpdateDIBSection( dcDst, FALSE );
1417 DIB_UpdateDIBSection( dcSrc, FALSE );
1418 EnterCriticalSection( &X11DRV_CritSection );
1419 result = (BOOL)CALL_LARGE_STACK( BITBLT_DoStretchBlt, &params );
1420 LeaveCriticalSection( &X11DRV_CritSection );
1421 DIB_UpdateDIBSection( dcDst, TRUE );
1422 return result;
1426 /***********************************************************************
1427 * X11DRV_StretchBlt
1429 BOOL X11DRV_StretchBlt( DC *dcDst, INT xDst, INT yDst,
1430 INT widthDst, INT heightDst,
1431 DC *dcSrc, INT xSrc, INT ySrc,
1432 INT widthSrc, INT heightSrc, DWORD rop )
1434 struct StretchBlt_params params = { dcDst, xDst, yDst, widthDst, heightDst,
1435 dcSrc, xSrc, ySrc, widthSrc, heightSrc,
1436 rop };
1437 BOOL result;
1438 DIB_UpdateDIBSection( dcDst, FALSE );
1439 DIB_UpdateDIBSection( dcSrc, FALSE );
1440 EnterCriticalSection( &X11DRV_CritSection );
1441 result = (BOOL)CALL_LARGE_STACK( BITBLT_DoStretchBlt, &params );
1442 LeaveCriticalSection( &X11DRV_CritSection );
1443 DIB_UpdateDIBSection( dcDst, TRUE );
1444 return result;
1447 #endif /* !defined(X_DISPLAY_MISSING) */