Release 980614
[wine/multimedia.git] / graphics / x11drv / bitblt.c
blob699d67c10151c023e4772a083f5db95f108d3681
1 /*
2 * GDI bit-blit operations
4 * Copyright 1993, 1994 Alexandre Julliard
5 */
7 #include <assert.h>
8 #include <stdio.h>
9 #include <stdlib.h>
10 #include <X11/Xlib.h>
11 #include <X11/Intrinsic.h>
12 #include "bitmap.h"
13 #include "callback.h"
14 #include "color.h"
15 #include "dc.h"
16 #include "metafile.h"
17 #include "options.h"
18 #include "x11drv.h"
19 #include "debug.h"
20 #include "xmalloc.h"
23 #define DST 0 /* Destination drawable */
24 #define SRC 1 /* Source drawable */
25 #define TMP 2 /* Temporary drawable */
26 #define PAT 3 /* Pattern (brush) in destination DC */
28 #define OP(src,dst,rop) (OP_ARGS(src,dst) << 4 | (rop))
29 #define OP_ARGS(src,dst) (((src) << 2) | (dst))
31 #define OP_SRC(opcode) ((opcode) >> 6)
32 #define OP_DST(opcode) (((opcode) >> 4) & 3)
33 #define OP_SRCDST(opcode) ((opcode) >> 4)
34 #define OP_ROP(opcode) ((opcode) & 0x0f)
36 #define MAX_OP_LEN 6 /* Longest opcode + 1 for the terminating 0 */
38 #define SWAP_INT32(i1,i2) \
39 do { INT32 __t = *(i1); *(i1) = *(i2); *(i2) = __t; } while(0)
41 static const unsigned char BITBLT_Opcodes[256][MAX_OP_LEN] =
43 { OP(PAT,DST,GXclear) }, /* 0x00 0 */
44 { OP(PAT,SRC,GXor), OP(SRC,DST,GXnor) }, /* 0x01 ~(D|(P|S)) */
45 { OP(PAT,SRC,GXnor), OP(SRC,DST,GXand) }, /* 0x02 D&~(P|S) */
46 { OP(PAT,SRC,GXnor) }, /* 0x03 ~(P|S) */
47 { OP(PAT,DST,GXnor), OP(SRC,DST,GXand) }, /* 0x04 S&~(D|P) */
48 { OP(PAT,DST,GXnor) }, /* 0x05 ~(D|P) */
49 { OP(SRC,DST,GXequiv), OP(PAT,DST,GXnor), }, /* 0x06 ~(P|~(D^S)) */
50 { OP(SRC,DST,GXand), OP(PAT,DST,GXnor) }, /* 0x07 ~(P|(D&S)) */
51 { OP(PAT,DST,GXandInverted), OP(SRC,DST,GXand) },/* 0x08 S&D&~P */
52 { OP(SRC,DST,GXxor), OP(PAT,DST,GXnor) }, /* 0x09 ~(P|(D^S)) */
53 { OP(PAT,DST,GXandInverted) }, /* 0x0a D&~P */
54 { OP(SRC,DST,GXandReverse), OP(PAT,DST,GXnor) }, /* 0x0b ~(P|(S&~D)) */
55 { OP(PAT,SRC,GXandInverted) }, /* 0x0c S&~P */
56 { OP(SRC,DST,GXandInverted), OP(PAT,DST,GXnor) },/* 0x0d ~(P|(D&~S)) */
57 { OP(SRC,DST,GXnor), OP(PAT,DST,GXnor) }, /* 0x0e ~(P|~(D|S)) */
58 { OP(PAT,DST,GXcopyInverted) }, /* 0x0f ~P */
59 { OP(SRC,DST,GXnor), OP(PAT,DST,GXand) }, /* 0x10 P&~(S|D) */
60 { OP(SRC,DST,GXnor) }, /* 0x11 ~(D|S) */
61 { OP(PAT,DST,GXequiv), OP(SRC,DST,GXnor) }, /* 0x12 ~(S|~(D^P)) */
62 { OP(PAT,DST,GXand), OP(SRC,DST,GXnor) }, /* 0x13 ~(S|(D&P)) */
63 { OP(PAT,SRC,GXequiv), OP(SRC,DST,GXnor) }, /* 0x14 ~(D|~(P^S)) */
64 { OP(PAT,SRC,GXand), OP(SRC,DST,GXnor) }, /* 0x15 ~(D|(P&S)) */
65 { OP(SRC,TMP,GXcopy), OP(PAT,TMP,GXnand),
66 OP(TMP,DST,GXand), OP(SRC,DST,GXxor),
67 OP(PAT,DST,GXxor) }, /* 0x16 P^S^(D&~(P&S) */
68 { OP(SRC,TMP,GXcopy), OP(SRC,DST,GXxor),
69 OP(PAT,SRC,GXxor), OP(SRC,DST,GXand),
70 OP(TMP,DST,GXequiv) }, /* 0x17 ~S^((S^P)&(S^D))*/
71 { OP(PAT,SRC,GXxor), OP(PAT,DST,GXxor),
72 OP(SRC,DST,GXand) }, /* 0x18 (S^P)&(D^P) */
73 { OP(SRC,TMP,GXcopy), OP(PAT,TMP,GXnand),
74 OP(TMP,DST,GXand), OP(SRC,DST,GXequiv) }, /* 0x19 ~S^(D&~(P&S)) */
75 { OP(PAT,SRC,GXand), OP(SRC,DST,GXor),
76 OP(PAT,DST,GXxor) }, /* 0x1a P^(D|(S&P)) */
77 { OP(SRC,TMP,GXcopy), OP(PAT,TMP,GXxor),
78 OP(TMP,DST,GXand), OP(SRC,DST,GXequiv) }, /* 0x1b ~S^(D&(P^S)) */
79 { OP(PAT,DST,GXand), OP(SRC,DST,GXor),
80 OP(PAT,DST,GXxor) }, /* 0x1c P^(S|(D&P)) */
81 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXxor),
82 OP(SRC,DST,GXand), OP(TMP,DST,GXequiv) }, /* 0x1d ~D^(S&(D^P)) */
83 { OP(SRC,DST,GXor), OP(PAT,DST,GXxor) }, /* 0x1e P^(D|S) */
84 { OP(SRC,DST,GXor), OP(PAT,DST,GXnand) }, /* 0x1f ~(P&(D|S)) */
85 { OP(PAT,SRC,GXandReverse), OP(SRC,DST,GXand) }, /* 0x20 D&(P&~S) */
86 { OP(PAT,DST,GXxor), OP(SRC,DST,GXnor) }, /* 0x21 ~(S|(D^P)) */
87 { OP(SRC,DST,GXandInverted) }, /* 0x22 ~S&D */
88 { OP(PAT,DST,GXandReverse), OP(SRC,DST,GXnor) }, /* 0x23 ~(S|(P&~D)) */
89 { OP(SRC,DST,GXxor), OP(PAT,SRC,GXxor),
90 OP(SRC,DST,GXand) }, /* 0x24 (S^P)&(S^D) */
91 { OP(PAT,SRC,GXnand), OP(SRC,DST,GXand),
92 OP(PAT,DST,GXequiv) }, /* 0x25 ~P^(D&~(S&P)) */
93 { OP(SRC,TMP,GXcopy), OP(PAT,TMP,GXand),
94 OP(TMP,DST,GXor), OP(SRC,DST,GXxor) }, /* 0x26 S^(D|(S&P)) */
95 { OP(SRC,TMP,GXcopy), OP(PAT,TMP,GXequiv),
96 OP(TMP,DST,GXor), OP(SRC,DST,GXxor) }, /* 0x27 S^(D|~(P^S)) */
97 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXand) }, /* 0x28 D&(P^S) */
98 { OP(SRC,TMP,GXcopy), OP(PAT,TMP,GXand),
99 OP(TMP,DST,GXor), OP(SRC,DST,GXxor),
100 OP(PAT,DST,GXequiv) }, /* 0x29 ~P^S^(D|(P&S)) */
101 { OP(PAT,SRC,GXnand), OP(SRC,DST,GXand) }, /* 0x2a D&~(P&S) */
102 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXxor),
103 OP(PAT,DST,GXxor), OP(SRC,DST,GXand),
104 OP(TMP,DST,GXequiv) }, /* 0x2b ~S^((P^S)&(P^D))*/
105 { OP(SRC,DST,GXor), OP(PAT,DST,GXand),
106 OP(SRC,DST,GXxor) }, /* 0x2c S^(P&(S|D)) */
107 { OP(SRC,DST,GXorReverse), OP(PAT,DST,GXxor) }, /* 0x2d P^(S|~D) */
108 { OP(PAT,DST,GXxor), OP(SRC,DST,GXor),
109 OP(PAT,DST,GXxor) }, /* 0x2e P^(S|(D^P)) */
110 { OP(SRC,DST,GXorReverse), OP(PAT,DST,GXnand) }, /* 0x2f ~(P&(S|~D)) */
111 { OP(PAT,SRC,GXandReverse) }, /* 0x30 P&~S */
112 { OP(PAT,DST,GXandInverted), OP(SRC,DST,GXnor) },/* 0x31 ~(S|(D&~P)) */
113 { OP(SRC,DST,GXor), OP(PAT,DST,GXor),
114 OP(SRC,DST,GXxor) }, /* 0x32 S^(D|P|S) */
115 { OP(SRC,DST,GXcopyInverted) }, /* 0x33 ~S */
116 { OP(SRC,DST,GXand), OP(PAT,DST,GXor),
117 OP(SRC,DST,GXxor) }, /* 0x34 S^(P|(D&S)) */
118 { OP(SRC,DST,GXequiv), OP(PAT,DST,GXor),
119 OP(SRC,DST,GXxor) }, /* 0x35 S^(P|~(D^S)) */
120 { OP(PAT,DST,GXor), OP(SRC,DST,GXxor) }, /* 0x36 S^(D|P) */
121 { OP(PAT,DST,GXor), OP(SRC,DST,GXnand) }, /* 0x37 ~(S&(D|P)) */
122 { OP(PAT,DST,GXor), OP(SRC,DST,GXand),
123 OP(PAT,DST,GXxor) }, /* 0x38 P^(S&(D|P)) */
124 { OP(PAT,DST,GXorReverse), OP(SRC,DST,GXxor) }, /* 0x39 S^(P|~D) */
125 { OP(SRC,DST,GXxor), OP(PAT,DST,GXor),
126 OP(SRC,DST,GXxor) }, /* 0x3a S^(P|(D^S)) */
127 { OP(PAT,DST,GXorReverse), OP(SRC,DST,GXnand) }, /* 0x3b ~(S&(P|~D)) */
128 { OP(PAT,SRC,GXxor) }, /* 0x3c P^S */
129 { OP(SRC,DST,GXnor), OP(PAT,DST,GXor),
130 OP(SRC,DST,GXxor) }, /* 0x3d S^(P|~(D|S)) */
131 { OP(SRC,DST,GXandInverted), OP(PAT,DST,GXor),
132 OP(SRC,DST,GXxor) }, /* 0x3e S^(P|(D&~S)) */
133 { OP(PAT,SRC,GXnand) }, /* 0x3f ~(P&S) */
134 { OP(SRC,DST,GXandReverse), OP(PAT,DST,GXand) }, /* 0x40 P&S&~D */
135 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXnor) }, /* 0x41 ~(D|(P^S)) */
136 { OP(DST,SRC,GXxor), OP(PAT,DST,GXxor),
137 OP(SRC,DST,GXand) }, /* 0x42 (S^D)&(P^D) */
138 { OP(SRC,DST,GXnand), OP(PAT,DST,GXand),
139 OP(SRC,DST,GXequiv) }, /* 0x43 ~S^(P&~(D&S)) */
140 { OP(SRC,DST,GXandReverse) }, /* 0x44 S&~D */
141 { OP(PAT,SRC,GXandReverse), OP(SRC,DST,GXnor) }, /* 0x45 ~(D|(P&~S)) */
142 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXand),
143 OP(SRC,DST,GXor), OP(TMP,DST,GXxor) }, /* 0x46 D^(S|(P&D)) */
144 { OP(PAT,DST,GXxor), OP(SRC,DST,GXand),
145 OP(PAT,DST,GXequiv) }, /* 0x47 ~P^(S&(D^P)) */
146 { OP(PAT,DST,GXxor), OP(SRC,DST,GXand) }, /* 0x48 S&(P^D) */
147 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXand),
148 OP(SRC,DST,GXor), OP(TMP,DST,GXxor),
149 OP(PAT,DST,GXequiv) }, /* 0x49 ~P^D^(S|(P&D)) */
150 { OP(DST,SRC,GXor), OP(PAT,SRC,GXand),
151 OP(SRC,DST,GXxor) }, /* 0x4a D^(P&(S|D)) */
152 { OP(SRC,DST,GXorInverted), OP(PAT,DST,GXxor) }, /* 0x4b P^(D|~S) */
153 { OP(PAT,DST,GXnand), OP(SRC,DST,GXand) }, /* 0x4c S&~(D&P) */
154 { OP(SRC,TMP,GXcopy), OP(SRC,DST,GXxor),
155 OP(PAT,SRC,GXxor), OP(SRC,DST,GXor),
156 OP(TMP,DST,GXequiv) }, /* 0x4d ~S^((S^P)|(S^D))*/
157 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXor),
158 OP(PAT,DST,GXxor) }, /* 0x4e P^(D|(S^P)) */
159 { OP(SRC,DST,GXorInverted), OP(PAT,DST,GXnand) },/* 0x4f ~(P&(D|~S)) */
160 { OP(PAT,DST,GXandReverse) }, /* 0x50 P&~D */
161 { OP(PAT,SRC,GXandInverted), OP(SRC,DST,GXnor) },/* 0x51 ~(D|(S&~P)) */
162 { OP(DST,SRC,GXand), OP(PAT,SRC,GXor),
163 OP(SRC,DST,GXxor) }, /* 0x52 D^(P|(S&D)) */
164 { OP(SRC,DST,GXxor), OP(PAT,DST,GXand),
165 OP(SRC,DST,GXequiv) }, /* 0x53 ~S^(P&(D^S)) */
166 { OP(PAT,SRC,GXnor), OP(SRC,DST,GXnor) }, /* 0x54 ~(D|~(P|S)) */
167 { OP(PAT,DST,GXinvert) }, /* 0x55 ~D */
168 { OP(PAT,SRC,GXor), OP(SRC,DST,GXxor) }, /* 0x56 D^(P|S) */
169 { OP(PAT,SRC,GXor), OP(SRC,DST,GXnand) }, /* 0x57 ~(D&(P|S)) */
170 { OP(PAT,SRC,GXor), OP(SRC,DST,GXand),
171 OP(PAT,DST,GXxor) }, /* 0x58 P^(D&(P|S)) */
172 { OP(PAT,SRC,GXorReverse), OP(SRC,DST,GXxor) }, /* 0x59 D^(P|~S) */
173 { OP(PAT,DST,GXxor) }, /* 0x5a D^P */
174 { OP(DST,SRC,GXnor), OP(PAT,SRC,GXor),
175 OP(SRC,DST,GXxor) }, /* 0x5b D^(P|~(S|D)) */
176 { OP(DST,SRC,GXxor), OP(PAT,SRC,GXor),
177 OP(SRC,DST,GXxor) }, /* 0x5c D^(P|(S^D)) */
178 { OP(PAT,SRC,GXorReverse), OP(SRC,DST,GXnand) }, /* 0x5d ~(D&(P|~S)) */
179 { OP(DST,SRC,GXandInverted), OP(PAT,SRC,GXor),
180 OP(SRC,DST,GXxor) }, /* 0x5e D^(P|(S&~D)) */
181 { OP(PAT,DST,GXnand) }, /* 0x5f ~(D&P) */
182 { OP(SRC,DST,GXxor), OP(PAT,DST,GXand) }, /* 0x60 P&(D^S) */
183 { OP(DST,TMP,GXcopy), OP(SRC,DST,GXand),
184 OP(PAT,DST,GXor), OP(SRC,DST,GXxor),
185 OP(TMP,DST,GXequiv) }, /* 0x61 ~D^S^(P|(D&S)) */
186 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXor),
187 OP(SRC,DST,GXand), OP(TMP,DST,GXxor) }, /* 0x62 D^(S&(P|D)) */
188 { OP(PAT,DST,GXorInverted), OP(SRC,DST,GXxor) }, /* 0x63 S^(D|~P) */
189 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXor),
190 OP(SRC,DST,GXand), OP(TMP,DST,GXxor) }, /* 0x64 S^(D&(P|S)) */
191 { OP(PAT,SRC,GXorInverted), OP(SRC,DST,GXxor) }, /* 0x65 D^(S|~P) */
192 { OP(SRC,DST,GXxor) }, /* 0x66 S^D */
193 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXnor),
194 OP(SRC,DST,GXor), OP(TMP,DST,GXxor) }, /* 0x67 S^(D|~(S|P) */
195 { OP(DST,TMP,GXcopy), OP(SRC,DST,GXnor),
196 OP(PAT,DST,GXor), OP(SRC,DST,GXxor),
197 OP(TMP,DST,GXequiv) }, /* 0x68 ~D^S^(P|~(D|S))*/
198 { OP(SRC,DST,GXxor), OP(PAT,DST,GXequiv) }, /* 0x69 ~P^(D^S) */
199 { OP(PAT,SRC,GXand), OP(SRC,DST,GXxor) }, /* 0x6a D^(P&S) */
200 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXor),
201 OP(SRC,DST,GXand), OP(TMP,DST,GXxor),
202 OP(PAT,DST,GXequiv) }, /* 0x6b ~P^S^(D&(P|S)) */
203 { OP(PAT,DST,GXand), OP(SRC,DST,GXxor) }, /* 0x6c S^(D&P) */
204 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXor),
205 OP(SRC,DST,GXand), OP(TMP,DST,GXxor),
206 OP(PAT,DST,GXequiv) }, /* 0x6d ~P^D^(S&(P|D)) */
207 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXorReverse),
208 OP(SRC,DST,GXand), OP(TMP,DST,GXxor) }, /* 0x6e S^(D&(P|~S)) */
209 { OP(SRC,DST,GXequiv), OP(PAT,DST,GXnand) }, /* 0x6f ~(P&~(S^D)) */
210 { OP(SRC,DST,GXnand), OP(PAT,DST,GXand) }, /* 0x70 P&~(D&S) */
211 { OP(SRC,TMP,GXcopy), OP(DST,SRC,GXxor),
212 OP(PAT,DST,GXxor), OP(SRC,DST,GXand),
213 OP(TMP,DST,GXequiv) }, /* 0x71 ~S^((S^D)&(P^D))*/
214 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXxor),
215 OP(SRC,DST,GXor), OP(TMP,DST,GXxor) }, /* 0x72 S^(D|(P^S)) */
216 { OP(PAT,DST,GXorInverted), OP(SRC,DST,GXnand) },/* 0x73 ~(S&(D|~P)) */
217 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXxor),
218 OP(SRC,DST,GXor), OP(TMP,DST,GXxor) }, /* 0x74 D^(S|(P^D)) */
219 { OP(PAT,SRC,GXorInverted), OP(SRC,DST,GXnand) },/* 0x75 ~(D&(S|~P)) */
220 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXandReverse),
221 OP(SRC,DST,GXor), OP(TMP,DST,GXxor) }, /* 0x76 S^(D|(P&~S)) */
222 { OP(SRC,DST,GXnand) }, /* 0x77 ~(S&D) */
223 { OP(SRC,DST,GXand), OP(PAT,DST,GXxor) }, /* 0x78 P^(D&S) */
224 { OP(DST,TMP,GXcopy), OP(SRC,DST,GXor),
225 OP(PAT,DST,GXand), OP(SRC,DST,GXxor),
226 OP(TMP,DST,GXequiv) }, /* 0x79 ~D^S^(P&(D|S)) */
227 { OP(DST,SRC,GXorInverted), OP(PAT,SRC,GXand),
228 OP(SRC,DST,GXxor) }, /* 0x7a D^(P&(S|~D)) */
229 { OP(PAT,DST,GXequiv), OP(SRC,DST,GXnand) }, /* 0x7b ~(S&~(D^P)) */
230 { OP(SRC,DST,GXorInverted), OP(PAT,DST,GXand),
231 OP(SRC,DST,GXxor) }, /* 0x7c S^(P&(D|~S)) */
232 { OP(PAT,SRC,GXequiv), OP(SRC,DST,GXnand) }, /* 0x7d ~(D&~(P^S)) */
233 { OP(SRC,DST,GXxor), OP(PAT,SRC,GXxor),
234 OP(SRC,DST,GXor) }, /* 0x7e (S^P)|(S^D) */
235 { OP(PAT,SRC,GXand), OP(SRC,DST,GXnand) }, /* 0x7f ~(D&P&S) */
236 { OP(PAT,SRC,GXand), OP(SRC,DST,GXand) }, /* 0x80 D&P&S */
237 { OP(SRC,DST,GXxor), OP(PAT,SRC,GXxor),
238 OP(SRC,DST,GXnor) }, /* 0x81 ~((S^P)|(S^D)) */
239 { OP(PAT,SRC,GXequiv), OP(SRC,DST,GXand) }, /* 0x82 D&~(P^S) */
240 { OP(SRC,DST,GXorInverted), OP(PAT,DST,GXand),
241 OP(SRC,DST,GXequiv) }, /* 0x83 ~S^(P&(D|~S)) */
242 { OP(PAT,DST,GXequiv), OP(SRC,DST,GXand) }, /* 0x84 S&~(D^P) */
243 { OP(PAT,SRC,GXorInverted), OP(SRC,DST,GXand),
244 OP(PAT,DST,GXequiv) }, /* 0x85 ~P^(D&(S|~P)) */
245 { OP(DST,TMP,GXcopy), OP(SRC,DST,GXor),
246 OP(PAT,DST,GXand), OP(SRC,DST,GXxor),
247 OP(TMP,DST,GXxor) }, /* 0x86 D^S^(P&(D|S)) */
248 { OP(SRC,DST,GXand), OP(PAT,DST,GXequiv) }, /* 0x87 ~P^(D&S) */
249 { OP(SRC,DST,GXand) }, /* 0x88 S&D */
250 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXandReverse),
251 OP(SRC,DST,GXor), OP(TMP,DST,GXequiv) }, /* 0x89 ~S^(D|(P&~S)) */
252 { OP(PAT,SRC,GXorInverted), OP(SRC,DST,GXand) }, /* 0x8a D&(S|~P) */
253 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXxor),
254 OP(SRC,DST,GXor), OP(TMP,DST,GXequiv) }, /* 0x8b ~D^(S|(P^D)) */
255 { OP(PAT,DST,GXorInverted), OP(SRC,DST,GXand) }, /* 0x8c S&(D|~P) */
256 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXxor),
257 OP(SRC,DST,GXor), OP(TMP,DST,GXequiv) }, /* 0x8d ~S^(D|(P^S)) */
258 { OP(SRC,TMP,GXcopy), OP(DST,SRC,GXxor),
259 OP(PAT,DST,GXxor), OP(SRC,DST,GXand),
260 OP(TMP,DST,GXxor) }, /* 0x8e S^((S^D)&(P^D))*/
261 { OP(SRC,DST,GXnand), OP(PAT,DST,GXnand) }, /* 0x8f ~(P&~(D&S)) */
262 { OP(SRC,DST,GXequiv), OP(PAT,DST,GXand) }, /* 0x90 P&~(D^S) */
263 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXorReverse),
264 OP(SRC,DST,GXand), OP(TMP,DST,GXequiv) }, /* 0x91 ~S^(D&(P|~S)) */
265 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXor),
266 OP(SRC,DST,GXand), OP(PAT,DST,GXxor),
267 OP(TMP,DST,GXxor) }, /* 0x92 D^P^(S&(D|P)) */
268 { OP(PAT,DST,GXand), OP(SRC,DST,GXequiv) }, /* 0x93 ~S^(P&D) */
269 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXor),
270 OP(SRC,DST,GXand), OP(PAT,DST,GXxor),
271 OP(TMP,DST,GXxor) }, /* 0x94 S^P^(D&(P|S)) */
272 { OP(PAT,SRC,GXand), OP(SRC,DST,GXequiv) }, /* 0x95 ~D^(P&S) */
273 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXxor) }, /* 0x96 D^P^S */
274 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXnor),
275 OP(SRC,DST,GXor), OP(PAT,DST,GXxor),
276 OP(TMP,DST,GXxor) }, /* 0x97 S^P^(D|~(P|S)) */
277 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXnor),
278 OP(SRC,DST,GXor), OP(TMP,DST,GXequiv) }, /* 0x98 ~S^(D|~(P|S)) */
279 { OP(SRC,DST,GXequiv) }, /* 0x99 ~S^D */
280 { OP(PAT,SRC,GXandReverse), OP(SRC,DST,GXxor) }, /* 0x9a D^(P&~S) */
281 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXor),
282 OP(SRC,DST,GXand), OP(TMP,DST,GXequiv) }, /* 0x9b ~S^(D&(P|S)) */
283 { OP(PAT,DST,GXandReverse), OP(SRC,DST,GXxor) }, /* 0x9c S^(P&~D) */
284 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXor),
285 OP(SRC,DST,GXand), OP(TMP,DST,GXequiv) }, /* 0x9d ~D^(S&(P|D)) */
286 { OP(DST,TMP,GXcopy), OP(SRC,DST,GXand),
287 OP(PAT,DST,GXor), OP(SRC,DST,GXxor),
288 OP(TMP,DST,GXxor) }, /* 0x9e D^S^(P|(D&S)) */
289 { OP(SRC,DST,GXxor), OP(PAT,DST,GXnand) }, /* 0x9f ~(P&(D^S)) */
290 { OP(PAT,DST,GXand) }, /* 0xa0 D&P */
291 { OP(PAT,SRC,GXandInverted), OP(SRC,DST,GXor),
292 OP(PAT,DST,GXequiv) }, /* 0xa1 ~P^(D|(S&~P)) */
293 { OP(PAT,SRC,GXorReverse), OP(SRC,DST,GXand) }, /* 0xa2 D&(P|~S) */
294 { OP(DST,SRC,GXxor), OP(PAT,SRC,GXor),
295 OP(SRC,DST,GXequiv) }, /* 0xa3 ~D^(P|(S^D)) */
296 { OP(PAT,SRC,GXnor), OP(SRC,DST,GXor),
297 OP(PAT,DST,GXequiv) }, /* 0xa4 ~P^(D|~(S|P)) */
298 { OP(PAT,DST,GXequiv) }, /* 0xa5 ~P^D */
299 { OP(PAT,SRC,GXandInverted), OP(SRC,DST,GXxor) },/* 0xa6 D^(S&~P) */
300 { OP(PAT,SRC,GXor), OP(SRC,DST,GXand),
301 OP(PAT,DST,GXequiv) }, /* 0xa7 ~P^(D&(S|P)) */
302 { OP(PAT,SRC,GXor), OP(SRC,DST,GXand) }, /* 0xa8 D&(P|S) */
303 { OP(PAT,SRC,GXor), OP(SRC,DST,GXequiv) }, /* 0xa9 ~D^(P|S) */
304 { OP(SRC,DST,GXnoop) }, /* 0xaa D */
305 { OP(PAT,SRC,GXnor), OP(SRC,DST,GXor) }, /* 0xab D|~(P|S) */
306 { OP(SRC,DST,GXxor), OP(PAT,DST,GXand),
307 OP(SRC,DST,GXxor) }, /* 0xac S^(P&(D^S)) */
308 { OP(DST,SRC,GXand), OP(PAT,SRC,GXor),
309 OP(SRC,DST,GXequiv) }, /* 0xad ~D^(P|(S&D)) */
310 { OP(PAT,SRC,GXandInverted), OP(SRC,DST,GXor) }, /* 0xae D|(S&~P) */
311 { OP(PAT,DST,GXorInverted) }, /* 0xaf D|~P */
312 { OP(SRC,DST,GXorInverted), OP(PAT,DST,GXand) }, /* 0xb0 P&(D|~S) */
313 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXor),
314 OP(PAT,DST,GXequiv) }, /* 0xb1 ~P^(D|(S^P)) */
315 { OP(SRC,TMP,GXcopy), OP(SRC,DST,GXxor),
316 OP(PAT,SRC,GXxor), OP(SRC,DST,GXor),
317 OP(TMP,DST,GXxor) }, /* 0xb2 S^((S^P)|(S^D))*/
318 { OP(PAT,DST,GXnand), OP(SRC,DST,GXnand) }, /* 0xb3 ~(S&~(D&P)) */
319 { OP(SRC,DST,GXandReverse), OP(PAT,DST,GXxor) }, /* 0xb4 P^(S&~D) */
320 { OP(DST,SRC,GXor), OP(PAT,SRC,GXand),
321 OP(SRC,DST,GXequiv) }, /* 0xb5 ~D^(P&(S|D)) */
322 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXand),
323 OP(SRC,DST,GXor), OP(PAT,DST,GXxor),
324 OP(TMP,DST,GXxor) }, /* 0xb6 D^P^(S|(D&P)) */
325 { OP(PAT,DST,GXxor), OP(SRC,DST,GXnand) }, /* 0xb7 ~(S&(D^P)) */
326 { OP(PAT,DST,GXxor), OP(SRC,DST,GXand),
327 OP(PAT,DST,GXxor) }, /* 0xb8 P^(S&(D^P)) */
328 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXand),
329 OP(SRC,DST,GXor), OP(TMP,DST,GXequiv) }, /* 0xb9 ~D^(S|(P&D)) */
330 { OP(PAT,SRC,GXandReverse), OP(SRC,DST,GXor) }, /* 0xba D|(P&~S) */
331 { OP(SRC,DST,GXorInverted) }, /* 0xbb ~S|D */
332 { OP(SRC,DST,GXnand), OP(PAT,DST,GXand),
333 OP(SRC,DST,GXxor) }, /* 0xbc S^(P&~(D&S)) */
334 { OP(DST,SRC,GXxor), OP(PAT,DST,GXxor),
335 OP(SRC,DST,GXnand) }, /* 0xbd ~((S^D)&(P^D)) */
336 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXor) }, /* 0xbe D|(P^S) */
337 { OP(PAT,SRC,GXnand), OP(SRC,DST,GXor) }, /* 0xbf D|~(P&S) */
338 { OP(PAT,SRC,GXand) }, /* 0xc0 P&S */
339 { OP(SRC,DST,GXandInverted), OP(PAT,DST,GXor),
340 OP(SRC,DST,GXequiv) }, /* 0xc1 ~S^(P|(D&~S)) */
341 { OP(SRC,DST,GXnor), OP(PAT,DST,GXor),
342 OP(SRC,DST,GXequiv) }, /* 0xc2 ~S^(P|~(D|S)) */
343 { OP(PAT,SRC,GXequiv) }, /* 0xc3 ~P^S */
344 { OP(PAT,DST,GXorReverse), OP(SRC,DST,GXand) }, /* 0xc4 S&(P|~D) */
345 { OP(SRC,DST,GXxor), OP(PAT,DST,GXor),
346 OP(SRC,DST,GXequiv) }, /* 0xc5 ~S^(P|(D^S)) */
347 { OP(PAT,DST,GXandInverted), OP(SRC,DST,GXxor) },/* 0xc6 S^(D&~P) */
348 { OP(PAT,DST,GXor), OP(SRC,DST,GXand),
349 OP(PAT,DST,GXequiv) }, /* 0xc7 ~P^(S&(D|P)) */
350 { OP(PAT,DST,GXor), OP(SRC,DST,GXand) }, /* 0xc8 S&(D|P) */
351 { OP(PAT,DST,GXor), OP(SRC,DST,GXequiv) }, /* 0xc9 ~S^(P|D) */
352 { OP(DST,SRC,GXxor), OP(PAT,SRC,GXand),
353 OP(SRC,DST,GXxor) }, /* 0xca D^(P&(S^D)) */
354 { OP(SRC,DST,GXand), OP(PAT,DST,GXor),
355 OP(SRC,DST,GXequiv) }, /* 0xcb ~S^(P|(D&S)) */
356 { OP(SRC,DST,GXcopy) }, /* 0xcc S */
357 { OP(PAT,DST,GXnor), OP(SRC,DST,GXor) }, /* 0xcd S|~(D|P) */
358 { OP(PAT,DST,GXandInverted), OP(SRC,DST,GXor) }, /* 0xce S|(D&~P) */
359 { OP(PAT,SRC,GXorInverted) }, /* 0xcf S|~P */
360 { OP(SRC,DST,GXorReverse), OP(PAT,DST,GXand) }, /* 0xd0 P&(S|~D) */
361 { OP(PAT,DST,GXxor), OP(SRC,DST,GXor),
362 OP(PAT,DST,GXequiv) }, /* 0xd1 ~P^(S|(D^P)) */
363 { OP(SRC,DST,GXandInverted), OP(PAT,DST,GXxor) },/* 0xd2 P^(D&~S) */
364 { OP(SRC,DST,GXor), OP(PAT,DST,GXand),
365 OP(SRC,DST,GXequiv) }, /* 0xd3 ~S^(P&(D|S)) */
366 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXxor),
367 OP(PAT,DST,GXxor), OP(SRC,DST,GXand),
368 OP(TMP,DST,GXxor) }, /* 0xd4 S^((S^P)&(D^P))*/
369 { OP(PAT,SRC,GXnand), OP(SRC,DST,GXnand) }, /* 0xd5 ~(D&~(P&S)) */
370 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXand),
371 OP(SRC,DST,GXor), OP(PAT,DST,GXxor),
372 OP(TMP,DST,GXxor) }, /* 0xd6 S^P^(D|(P&S)) */
373 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXnand) }, /* 0xd7 ~(D&(P^S)) */
374 { OP(PAT,SRC,GXxor), OP(SRC,DST,GXand),
375 OP(PAT,DST,GXxor) }, /* 0xd8 P^(D&(S^P)) */
376 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXand),
377 OP(SRC,DST,GXor), OP(TMP,DST,GXequiv) }, /* 0xd9 ~S^(D|(P&S)) */
378 { OP(DST,SRC,GXnand), OP(PAT,SRC,GXand),
379 OP(SRC,DST,GXxor) }, /* 0xda D^(P&~(S&D)) */
380 { OP(SRC,DST,GXxor), OP(PAT,SRC,GXxor),
381 OP(SRC,DST,GXnand) }, /* 0xdb ~((S^P)&(S^D)) */
382 { OP(PAT,DST,GXandReverse), OP(SRC,DST,GXor) }, /* 0xdc S|(P&~D) */
383 { OP(SRC,DST,GXorReverse) }, /* 0xdd S|~D */
384 { OP(PAT,DST,GXxor), OP(SRC,DST,GXor) }, /* 0xde S|(D^P) */
385 { OP(PAT,DST,GXnand), OP(SRC,DST,GXor) }, /* 0xdf S|~(D&P) */
386 { OP(SRC,DST,GXor), OP(PAT,DST,GXand) }, /* 0xe0 P&(D|S) */
387 { OP(SRC,DST,GXor), OP(PAT,DST,GXequiv) }, /* 0xe1 ~P^(D|S) */
388 { OP(DST,TMP,GXcopy), OP(PAT,DST,GXxor),
389 OP(SRC,DST,GXand), OP(TMP,DST,GXxor) }, /* 0xe2 D^(S&(P^D)) */
390 { OP(PAT,DST,GXand), OP(SRC,DST,GXor),
391 OP(PAT,DST,GXequiv) }, /* 0xe3 ~P^(S|(D&P)) */
392 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXxor),
393 OP(SRC,DST,GXand), OP(TMP,DST,GXxor) }, /* 0xe4 S^(D&(P^S)) */
394 { OP(PAT,SRC,GXand), OP(SRC,DST,GXor),
395 OP(PAT,DST,GXequiv) }, /* 0xe5 ~P^(D|(S&P)) */
396 { OP(SRC,TMP,GXcopy), OP(PAT,SRC,GXnand),
397 OP(SRC,DST,GXand), OP(TMP,DST,GXxor) }, /* 0xe6 S^(D&~(P&S)) */
398 { OP(PAT,SRC,GXxor), OP(PAT,DST,GXxor),
399 OP(SRC,DST,GXnand) }, /* 0xe7 ~((S^P)&(D^P)) */
400 { OP(SRC,TMP,GXcopy), OP(SRC,DST,GXxor),
401 OP(PAT,SRC,GXxor), OP(SRC,DST,GXand),
402 OP(TMP,DST,GXxor) }, /* 0xe8 S^((S^P)&(S^D))*/
403 { OP(DST,TMP,GXcopy), OP(SRC,DST,GXnand),
404 OP(PAT,DST,GXand), OP(SRC,DST,GXxor),
405 OP(TMP,DST,GXequiv) }, /* 0xe9 ~D^S^(P&~(S&D))*/
406 { OP(PAT,SRC,GXand), OP(SRC,DST,GXor) }, /* 0xea D|(P&S) */
407 { OP(PAT,SRC,GXequiv), OP(SRC,DST,GXor) }, /* 0xeb D|~(P^S) */
408 { OP(PAT,DST,GXand), OP(SRC,DST,GXor) }, /* 0xec S|(D&P) */
409 { OP(PAT,DST,GXequiv), OP(SRC,DST,GXor) }, /* 0xed S|~(D^P) */
410 { OP(SRC,DST,GXor) }, /* 0xee S|D */
411 { OP(PAT,DST,GXorInverted), OP(SRC,DST,GXor) }, /* 0xef S|D|~P */
412 { OP(PAT,DST,GXcopy) }, /* 0xf0 P */
413 { OP(SRC,DST,GXnor), OP(PAT,DST,GXor) }, /* 0xf1 P|~(D|S) */
414 { OP(SRC,DST,GXandInverted), OP(PAT,DST,GXor) }, /* 0xf2 P|(D&~S) */
415 { OP(PAT,SRC,GXorReverse) }, /* 0xf3 P|~S */
416 { OP(SRC,DST,GXandReverse), OP(PAT,DST,GXor) }, /* 0xf4 P|(S&~D) */
417 { OP(PAT,DST,GXorReverse) }, /* 0xf5 P|~D */
418 { OP(SRC,DST,GXxor), OP(PAT,DST,GXor) }, /* 0xf6 P|(D^S) */
419 { OP(SRC,DST,GXnand), OP(PAT,DST,GXor) }, /* 0xf7 P|~(S&D) */
420 { OP(SRC,DST,GXand), OP(PAT,DST,GXor) }, /* 0xf8 P|(D&S) */
421 { OP(SRC,DST,GXequiv), OP(PAT,DST,GXor) }, /* 0xf9 P|~(D^S) */
422 { OP(PAT,DST,GXor) }, /* 0xfa D|P */
423 { OP(PAT,SRC,GXorReverse), OP(SRC,DST,GXor) }, /* 0xfb D|P|~S */
424 { OP(PAT,SRC,GXor) }, /* 0xfc P|S */
425 { OP(SRC,DST,GXorReverse), OP(PAT,DST,GXor) }, /* 0xfd P|S|~D */
426 { OP(SRC,DST,GXor), OP(PAT,DST,GXor) }, /* 0xfe P|D|S */
427 { OP(PAT,DST,GXset) } /* 0xff 1 */
431 #ifdef BITBLT_TEST /* Opcodes test */
433 static int do_bitop( int s, int d, int rop )
435 int res;
436 switch(rop)
438 case GXclear: res = 0; break;
439 case GXand: res = s & d; break;
440 case GXandReverse: res = s & ~d; break;
441 case GXcopy: res = s; break;
442 case GXandInverted: res = ~s & d; break;
443 case GXnoop: res = d; break;
444 case GXxor: res = s ^ d; break;
445 case GXor: res = s | d; break;
446 case GXnor: res = ~(s | d); break;
447 case GXequiv: res = ~s ^ d; break;
448 case GXinvert: res = ~d; break;
449 case GXorReverse: res = s | ~d; break;
450 case GXcopyInverted: res = ~s; break;
451 case GXorInverted: res = ~s | d; break;
452 case GXnand: res = ~(s & d); break;
453 case GXset: res = 1; break;
455 return res & 1;
458 main()
460 int rop, i, res, src, dst, pat, tmp, dstUsed;
461 const BYTE *opcode;
463 for (rop = 0; rop < 256; rop++)
465 res = dstUsed = 0;
466 for (i = 0; i < 8; i++)
468 pat = (i >> 2) & 1;
469 src = (i >> 1) & 1;
470 dst = i & 1;
471 for (opcode = BITBLT_Opcodes[rop]; *opcode; opcode++)
473 switch(*opcode >> 4)
475 case OP_ARGS(DST,TMP):
476 tmp = do_bitop( dst, tmp, *opcode & 0xf );
477 break;
478 case OP_ARGS(DST,SRC):
479 src = do_bitop( dst, src, *opcode & 0xf );
480 break;
481 case OP_ARGS(SRC,TMP):
482 tmp = do_bitop( src, tmp, *opcode & 0xf );
483 break;
484 case OP_ARGS(SRC,DST):
485 dst = do_bitop( src, dst, *opcode & 0xf );
486 dstUsed = 1;
487 break;
488 case OP_ARGS(PAT,TMP):
489 tmp = do_bitop( pat, tmp, *opcode & 0xf );
490 break;
491 case OP_ARGS(PAT,DST):
492 dst = do_bitop( pat, dst, *opcode & 0xf );
493 dstUsed = 1;
494 break;
495 case OP_ARGS(PAT,SRC):
496 src = do_bitop( pat, src, *opcode & 0xf );
497 break;
498 case OP_ARGS(TMP,DST):
499 dst = do_bitop( tmp, dst, *opcode & 0xf );
500 dstUsed = 1;
501 break;
502 case OP_ARGS(TMP,SRC):
503 src = do_bitop( tmp, src, *opcode & 0xf );
504 break;
505 default:
506 printf( "Invalid opcode %x\n", *opcode );
509 if (!dstUsed) dst = src;
510 if (dst) res |= 1 << i;
512 if (res != rop) printf( "%02x: ERROR, res=%02x\n", rop, res );
516 #endif /* BITBLT_TEST */
519 /***********************************************************************
520 * BITBLT_StretchRow
522 * Stretch a row of pixels. Helper function for BITBLT_StretchImage.
524 static void BITBLT_StretchRow( int *rowSrc, int *rowDst,
525 INT32 startDst, INT32 widthDst,
526 INT32 xinc, INT32 xoff, WORD mode )
528 register INT32 xsrc = xinc * startDst + xoff;
529 rowDst += startDst;
530 switch(mode)
532 case STRETCH_ANDSCANS:
533 for(; widthDst > 0; widthDst--, xsrc += xinc)
534 *rowDst++ &= rowSrc[xsrc >> 16];
535 break;
536 case STRETCH_ORSCANS:
537 for(; widthDst > 0; widthDst--, xsrc += xinc)
538 *rowDst++ |= rowSrc[xsrc >> 16];
539 break;
540 case STRETCH_DELETESCANS:
541 for(; widthDst > 0; widthDst--, xsrc += xinc)
542 *rowDst++ = rowSrc[xsrc >> 16];
543 break;
548 /***********************************************************************
549 * BITBLT_ShrinkRow
551 * Shrink a row of pixels. Helper function for BITBLT_StretchImage.
553 static void BITBLT_ShrinkRow( int *rowSrc, int *rowDst,
554 INT32 startSrc, INT32 widthSrc,
555 INT32 xinc, INT32 xoff, WORD mode )
557 register INT32 xdst = xinc * startSrc + xoff;
558 rowSrc += startSrc;
559 switch(mode)
561 case STRETCH_ORSCANS:
562 for(; widthSrc > 0; widthSrc--, xdst += xinc)
563 rowDst[xdst >> 16] |= *rowSrc++;
564 break;
565 case STRETCH_ANDSCANS:
566 for(; widthSrc > 0; widthSrc--, xdst += xinc)
567 rowDst[xdst >> 16] &= *rowSrc++;
568 break;
569 case STRETCH_DELETESCANS:
570 for(; widthSrc > 0; widthSrc--, xdst += xinc)
571 rowDst[xdst >> 16] = *rowSrc++;
572 break;
577 /***********************************************************************
578 * BITBLT_GetRow
580 * Retrieve a row from an image. Helper function for BITBLT_StretchImage.
582 static void BITBLT_GetRow( XImage *image, int *pdata, INT32 row,
583 INT32 start, INT32 width, INT32 depthDst,
584 int fg, int bg, BOOL32 swap)
586 register INT32 i;
588 assert( (row >= 0) && (row < image->height) );
589 assert( (start >= 0) && (width <= image->width) );
591 pdata += swap ? start+width-1 : start;
592 if (image->depth == depthDst) /* color -> color */
594 if (COLOR_PixelToPalette && (depthDst != 1))
595 if (swap) for (i = 0; i < width; i++)
596 *pdata-- = COLOR_PixelToPalette[XGetPixel( image, i, row )];
597 else for (i = 0; i < width; i++)
598 *pdata++ = COLOR_PixelToPalette[XGetPixel( image, i, row )];
599 else
600 if (swap) for (i = 0; i < width; i++)
601 *pdata-- = XGetPixel( image, i, row );
602 else for (i = 0; i < width; i++)
603 *pdata++ = XGetPixel( image, i, row );
605 else
607 if (image->depth == 1) /* monochrome -> color */
609 if (COLOR_PixelToPalette)
611 fg = COLOR_PixelToPalette[fg];
612 bg = COLOR_PixelToPalette[bg];
614 if (swap) for (i = 0; i < width; i++)
615 *pdata-- = XGetPixel( image, i, row ) ? bg : fg;
616 else for (i = 0; i < width; i++)
617 *pdata++ = XGetPixel( image, i, row ) ? bg : fg;
619 else /* color -> monochrome */
621 if (swap) for (i = 0; i < width; i++)
622 *pdata-- = (XGetPixel( image, i, row ) == bg) ? 1 : 0;
623 else for (i = 0; i < width; i++)
624 *pdata++ = (XGetPixel( image, i, row ) == bg) ? 1 : 0;
630 /***********************************************************************
631 * BITBLT_StretchImage
633 * Stretch an X image.
634 * FIXME: does not work for full 32-bit coordinates.
636 static void BITBLT_StretchImage( XImage *srcImage, XImage *dstImage,
637 INT32 widthSrc, INT32 heightSrc,
638 INT32 widthDst, INT32 heightDst,
639 RECT32 *visRectSrc, RECT32 *visRectDst,
640 int foreground, int background, WORD mode )
642 int *rowSrc, *rowDst, *pixel;
643 char *pdata;
644 INT32 xinc, xoff, yinc, ysrc, ydst;
645 register INT32 x, y;
646 BOOL32 hstretch, vstretch, hswap, vswap;
648 hswap = ((int)widthSrc * widthDst) < 0;
649 vswap = ((int)heightSrc * heightDst) < 0;
650 widthSrc = abs(widthSrc);
651 heightSrc = abs(heightSrc);
652 widthDst = abs(widthDst);
653 heightDst = abs(heightDst);
655 if (!(rowSrc = (int *)HeapAlloc( GetProcessHeap(), 0,
656 (widthSrc+widthDst)*sizeof(int) ))) return;
657 rowDst = rowSrc + widthSrc;
659 /* When stretching, all modes are the same, and DELETESCANS is faster */
660 if ((widthSrc < widthDst) && (heightSrc < heightDst))
661 mode = STRETCH_DELETESCANS;
663 if (mode != STRETCH_DELETESCANS)
664 memset( rowDst, (mode == STRETCH_ANDSCANS) ? 0xff : 0x00,
665 widthDst*sizeof(int) );
667 hstretch = (widthSrc < widthDst);
668 vstretch = (heightSrc < heightDst);
670 if (hstretch)
672 xinc = ((int)widthSrc << 16) / widthDst;
673 xoff = ((widthSrc << 16) - (xinc * widthDst)) / 2;
675 else
677 xinc = ((int)widthDst << 16) / widthSrc;
678 xoff = ((widthDst << 16) - (xinc * widthSrc)) / 2;
681 if (vstretch)
683 yinc = ((int)heightSrc << 16) / heightDst;
684 ydst = visRectDst->top;
685 if (vswap)
687 ysrc = yinc * (heightDst - ydst - 1);
688 yinc = -yinc;
690 else
691 ysrc = yinc * ydst;
693 for ( ; (ydst < visRectDst->bottom); ysrc += yinc, ydst++)
695 if (((ysrc >> 16) < visRectSrc->top) ||
696 ((ysrc >> 16) >= visRectSrc->bottom)) continue;
698 /* Retrieve a source row */
699 BITBLT_GetRow( srcImage, rowSrc, (ysrc >> 16) - visRectSrc->top,
700 hswap ? widthSrc - visRectSrc->right
701 : visRectSrc->left,
702 visRectSrc->right - visRectSrc->left,
703 dstImage->depth, foreground, background, hswap );
705 /* Stretch or shrink it */
706 if (hstretch)
707 BITBLT_StretchRow( rowSrc, rowDst, visRectDst->left,
708 visRectDst->right - visRectDst->left,
709 xinc, xoff, mode );
710 else BITBLT_ShrinkRow( rowSrc, rowDst,
711 hswap ? widthSrc - visRectSrc->right
712 : visRectSrc->left,
713 visRectSrc->right - visRectSrc->left,
714 xinc, xoff, mode );
716 /* Store the destination row */
717 pixel = rowDst + visRectDst->right - 1;
718 y = ydst - visRectDst->top;
719 for (x = visRectDst->right-visRectDst->left-1; x >= 0; x--)
720 XPutPixel( dstImage, x, y, *pixel-- );
721 if (mode != STRETCH_DELETESCANS)
722 memset( rowDst, (mode == STRETCH_ANDSCANS) ? 0xff : 0x00,
723 widthDst*sizeof(int) );
725 /* Make copies of the destination row */
727 pdata = dstImage->data + dstImage->bytes_per_line * y;
728 while (((ysrc + yinc) >> 16 == ysrc >> 16) &&
729 (ydst < visRectDst->bottom-1))
731 memcpy( pdata + dstImage->bytes_per_line, pdata,
732 dstImage->bytes_per_line );
733 pdata += dstImage->bytes_per_line;
734 ysrc += yinc;
735 ydst++;
739 else /* Shrinking */
741 yinc = ((int)heightDst << 16) / heightSrc;
742 ysrc = visRectSrc->top;
743 ydst = ((heightDst << 16) - (yinc * heightSrc)) / 2;
744 if (vswap)
746 ydst += yinc * (heightSrc - ysrc - 1);
747 yinc = -yinc;
749 else
750 ydst += yinc * ysrc;
752 for( ; (ysrc < visRectSrc->bottom); ydst += yinc, ysrc++)
754 if (((ydst >> 16) < visRectDst->top) ||
755 ((ydst >> 16) >= visRectDst->bottom)) continue;
757 /* Retrieve a source row */
758 BITBLT_GetRow( srcImage, rowSrc, ysrc - visRectSrc->top,
759 hswap ? widthSrc - visRectSrc->right
760 : visRectSrc->left,
761 visRectSrc->right - visRectSrc->left,
762 dstImage->depth, foreground, background, hswap );
764 /* Stretch or shrink it */
765 if (hstretch)
766 BITBLT_StretchRow( rowSrc, rowDst, visRectDst->left,
767 visRectDst->right - visRectDst->left,
768 xinc, xoff, mode );
769 else BITBLT_ShrinkRow( rowSrc, rowDst,
770 hswap ? widthSrc - visRectSrc->right
771 : visRectSrc->left,
772 visRectSrc->right - visRectSrc->left,
773 xinc, xoff, mode );
775 /* Merge several source rows into the destination */
776 if (mode == STRETCH_DELETESCANS)
778 /* Simply skip the overlapping rows */
779 while (((ydst + yinc) >> 16 == ydst >> 16) &&
780 (ysrc < visRectSrc->bottom-1))
782 ydst += yinc;
783 ysrc++;
786 else if (((ydst + yinc) >> 16 == ydst >> 16) &&
787 (ysrc < visRectSrc->bottom-1))
788 continue; /* Restart loop for next overlapping row */
790 /* Store the destination row */
791 pixel = rowDst + visRectDst->right - 1;
792 y = (ydst >> 16) - visRectDst->top;
793 for (x = visRectDst->right-visRectDst->left-1; x >= 0; x--)
794 XPutPixel( dstImage, x, y, *pixel-- );
795 if (mode != STRETCH_DELETESCANS)
796 memset( rowDst, (mode == STRETCH_ANDSCANS) ? 0xff : 0x00,
797 widthDst*sizeof(int) );
800 HeapFree( GetProcessHeap(), 0, rowSrc );
804 /***********************************************************************
805 * BITBLT_GetSrcAreaStretch
807 * Retrieve an area from the source DC, stretching and mapping all the
808 * pixels to Windows colors.
810 static void BITBLT_GetSrcAreaStretch( DC *dcSrc, DC *dcDst,
811 Pixmap pixmap, GC gc,
812 INT32 xSrc, INT32 ySrc,
813 INT32 widthSrc, INT32 heightSrc,
814 INT32 xDst, INT32 yDst,
815 INT32 widthDst, INT32 heightDst,
816 RECT32 *visRectSrc, RECT32 *visRectDst )
818 XImage *imageSrc, *imageDst;
820 RECT32 rectSrc = *visRectSrc;
821 RECT32 rectDst = *visRectDst;
823 if (widthSrc < 0) xSrc += widthSrc;
824 if (widthDst < 0) xDst += widthDst;
825 if (heightSrc < 0) ySrc += heightSrc;
826 if (heightDst < 0) yDst += heightDst;
827 OffsetRect32( &rectSrc, -xSrc, -ySrc );
828 OffsetRect32( &rectDst, -xDst, -yDst );
830 /* FIXME: avoid BadMatch errors */
831 imageSrc = XGetImage( display, dcSrc->u.x.drawable,
832 visRectSrc->left, visRectSrc->top,
833 visRectSrc->right - visRectSrc->left,
834 visRectSrc->bottom - visRectSrc->top,
835 AllPlanes, ZPixmap );
836 XCREATEIMAGE( imageDst, rectDst.right - rectDst.left,
837 rectDst.bottom - rectDst.top, dcDst->w.bitsPerPixel );
838 BITBLT_StretchImage( imageSrc, imageDst, widthSrc, heightSrc,
839 widthDst, heightDst, &rectSrc, &rectDst,
840 dcDst->w.textPixel, dcDst->w.bitsPerPixel != 1 ?
841 dcDst->w.backgroundPixel : dcSrc->w.backgroundPixel,
842 dcDst->w.stretchBltMode );
843 XPutImage( display, pixmap, gc, imageDst, 0, 0, 0, 0,
844 rectDst.right - rectDst.left, rectDst.bottom - rectDst.top );
845 XDestroyImage( imageSrc );
846 XDestroyImage( imageDst );
850 /***********************************************************************
851 * BITBLT_GetSrcArea
853 * Retrieve an area from the source DC, mapping all the
854 * pixels to Windows colors.
856 static void BITBLT_GetSrcArea( DC *dcSrc, DC *dcDst, Pixmap pixmap, GC gc,
857 INT32 xSrc, INT32 ySrc, RECT32 *visRectSrc )
859 XImage *imageSrc, *imageDst;
860 register INT32 x, y;
861 INT32 width = visRectSrc->right - visRectSrc->left;
862 INT32 height = visRectSrc->bottom - visRectSrc->top;
864 if (dcSrc->w.bitsPerPixel == dcDst->w.bitsPerPixel)
866 if (!COLOR_PixelToPalette ||
867 (dcDst->w.bitsPerPixel == 1)) /* monochrome -> monochrome */
869 XCopyArea( display, dcSrc->u.x.drawable, pixmap, gc,
870 visRectSrc->left, visRectSrc->top, width, height, 0, 0);
872 else /* color -> color */
874 if (dcSrc->w.flags & DC_MEMORY)
875 imageSrc = XGetImage( display, dcSrc->u.x.drawable,
876 visRectSrc->left, visRectSrc->top,
877 width, height, AllPlanes, ZPixmap );
878 else
880 /* Make sure we don't get a BadMatch error */
881 XCopyArea( display, dcSrc->u.x.drawable, pixmap, gc,
882 visRectSrc->left, visRectSrc->top,
883 width, height, 0, 0);
884 imageSrc = XGetImage( display, pixmap, 0, 0, width, height,
885 AllPlanes, ZPixmap );
887 for (y = 0; y < height; y++)
888 for (x = 0; x < width; x++)
889 XPutPixel(imageSrc, x, y,
890 COLOR_PixelToPalette[XGetPixel(imageSrc, x, y)]);
891 XPutImage( display, pixmap, gc, imageSrc,
892 0, 0, 0, 0, width, height );
893 XDestroyImage( imageSrc );
896 else
898 if (dcSrc->w.bitsPerPixel == 1) /* monochrome -> color */
900 if (COLOR_PixelToPalette)
902 XSetBackground( display, gc,
903 COLOR_PixelToPalette[dcDst->w.textPixel] );
904 XSetForeground( display, gc,
905 COLOR_PixelToPalette[dcDst->w.backgroundPixel]);
907 else
909 XSetBackground( display, gc, dcDst->w.textPixel );
910 XSetForeground( display, gc, dcDst->w.backgroundPixel );
912 XCopyPlane( display, dcSrc->u.x.drawable, pixmap, gc,
913 visRectSrc->left, visRectSrc->top,
914 width, height, 0, 0, 1 );
916 else /* color -> monochrome */
918 /* FIXME: avoid BadMatch error */
919 imageSrc = XGetImage( display, dcSrc->u.x.drawable,
920 visRectSrc->left, visRectSrc->top,
921 width, height, AllPlanes, ZPixmap );
922 XCREATEIMAGE( imageDst, width, height, dcDst->w.bitsPerPixel );
923 for (y = 0; y < height; y++)
924 for (x = 0; x < width; x++)
925 XPutPixel(imageDst, x, y, (XGetPixel(imageSrc,x,y) ==
926 dcSrc->w.backgroundPixel) );
927 XPutImage( display, pixmap, gc, imageDst,
928 0, 0, 0, 0, width, height );
929 XDestroyImage( imageSrc );
930 XDestroyImage( imageDst );
936 /***********************************************************************
937 * BITBLT_GetDstArea
939 * Retrieve an area from the destination DC, mapping all the
940 * pixels to Windows colors.
942 static void BITBLT_GetDstArea(DC *dc, Pixmap pixmap, GC gc, RECT32 *visRectDst)
944 INT32 width = visRectDst->right - visRectDst->left;
945 INT32 height = visRectDst->bottom - visRectDst->top;
947 if (!COLOR_PixelToPalette || (dc->w.bitsPerPixel == 1) ||
948 (COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL) )
950 XCopyArea( display, dc->u.x.drawable, pixmap, gc,
951 visRectDst->left, visRectDst->top, width, height, 0, 0 );
953 else
955 register INT32 x, y;
956 XImage *image;
958 if (dc->w.flags & DC_MEMORY)
959 image = XGetImage( display, dc->u.x.drawable,
960 visRectDst->left, visRectDst->top,
961 width, height, AllPlanes, ZPixmap );
962 else
964 /* Make sure we don't get a BadMatch error */
965 XCopyArea( display, dc->u.x.drawable, pixmap, gc,
966 visRectDst->left, visRectDst->top, width, height, 0, 0);
967 image = XGetImage( display, pixmap, 0, 0, width, height,
968 AllPlanes, ZPixmap );
970 for (y = 0; y < height; y++)
971 for (x = 0; x < width; x++)
972 XPutPixel( image, x, y,
973 COLOR_PixelToPalette[XGetPixel( image, x, y )]);
974 XPutImage( display, pixmap, gc, image, 0, 0, 0, 0, width, height );
975 XDestroyImage( image );
980 /***********************************************************************
981 * BITBLT_PutDstArea
983 * Put an area back into the destination DC, mapping the pixel
984 * colors to X pixels.
986 static void BITBLT_PutDstArea(DC *dc, Pixmap pixmap, GC gc, RECT32 *visRectDst)
988 INT32 width = visRectDst->right - visRectDst->left;
989 INT32 height = visRectDst->bottom - visRectDst->top;
991 /* !COLOR_PaletteToPixel is _NOT_ enough */
993 if (!COLOR_PaletteToPixel || (dc->w.bitsPerPixel == 1) ||
994 (COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL) )
996 XCopyArea( display, pixmap, dc->u.x.drawable, gc, 0, 0,
997 width, height, visRectDst->left, visRectDst->top );
999 else
1001 register INT32 x, y;
1002 XImage *image = XGetImage( display, pixmap, 0, 0, width, height,
1003 AllPlanes, ZPixmap );
1004 for (y = 0; y < height; y++)
1005 for (x = 0; x < width; x++)
1007 XPutPixel( image, x, y,
1008 COLOR_PaletteToPixel[XGetPixel( image, x, y )]);
1010 XPutImage( display, dc->u.x.drawable, gc, image, 0, 0,
1011 visRectDst->left, visRectDst->top, width, height );
1012 XDestroyImage( image );
1017 /***********************************************************************
1018 * BITBLT_GetVisRectangles
1020 * Get the source and destination visible rectangles for StretchBlt().
1021 * Return FALSE if one of the rectangles is empty.
1023 static BOOL32 BITBLT_GetVisRectangles( DC *dcDst, INT32 xDst, INT32 yDst,
1024 INT32 widthDst, INT32 heightDst,
1025 DC *dcSrc, INT32 xSrc, INT32 ySrc,
1026 INT32 widthSrc, INT32 heightSrc,
1027 RECT32 *visRectSrc, RECT32 *visRectDst )
1029 RECT32 rect, clipRect;
1031 /* Get the destination visible rectangle */
1033 SetRect32( &rect, xDst, yDst, xDst + widthDst, yDst + heightDst );
1034 if (widthDst < 0) SWAP_INT32( &rect.left, &rect.right );
1035 if (heightDst < 0) SWAP_INT32( &rect.top, &rect.bottom );
1036 GetRgnBox32( dcDst->w.hGCClipRgn, &clipRect );
1037 OffsetRect32( &clipRect, dcDst->w.DCOrgX, dcDst->w.DCOrgY );
1038 if (!IntersectRect32( visRectDst, &rect, &clipRect )) return FALSE;
1040 /* Get the source visible rectangle */
1042 if (!dcSrc) return TRUE;
1043 SetRect32( &rect, xSrc, ySrc, xSrc + widthSrc, ySrc + heightSrc );
1044 if (widthSrc < 0) SWAP_INT32( &rect.left, &rect.right );
1045 if (heightSrc < 0) SWAP_INT32( &rect.top, &rect.bottom );
1046 /* Apparently the clip region is only for output, so use hVisRgn here */
1047 GetRgnBox32( dcSrc->w.hVisRgn, &clipRect );
1048 OffsetRect32( &clipRect, dcSrc->w.DCOrgX, dcSrc->w.DCOrgY );
1049 if (!IntersectRect32( visRectSrc, &rect, &clipRect )) return FALSE;
1051 /* Intersect the rectangles */
1053 if ((widthSrc == widthDst) && (heightSrc == heightDst)) /* no stretching */
1055 OffsetRect32( visRectSrc, xDst - xSrc, yDst - ySrc );
1056 if (!IntersectRect32( &rect, visRectSrc, visRectDst )) return FALSE;
1057 *visRectSrc = *visRectDst = rect;
1058 OffsetRect32( visRectSrc, xSrc - xDst, ySrc - yDst );
1060 else /* stretching */
1062 /* Map source rectangle into destination coordinates */
1063 rect.left = xDst + (visRectSrc->left - xSrc)*widthDst/widthSrc;
1064 rect.top = yDst + (visRectSrc->top - ySrc)*heightDst/heightSrc;
1065 rect.right = xDst + ((visRectSrc->right - xSrc)*widthDst)/widthSrc;
1066 rect.bottom = yDst + ((visRectSrc->bottom - ySrc)*heightDst)/heightSrc;
1067 if (rect.left > rect.right) SWAP_INT32( &rect.left, &rect.right );
1068 if (rect.top > rect.bottom) SWAP_INT32( &rect.top, &rect.bottom );
1069 InflateRect32( &rect, 1, 1 ); /* Avoid rounding errors */
1070 if (!IntersectRect32( visRectDst, &rect, visRectDst )) return FALSE;
1072 /* Map destination rectangle back to source coordinates */
1073 rect = *visRectDst;
1074 rect.left = xSrc + (visRectDst->left - xDst)*widthSrc/widthDst;
1075 rect.top = ySrc + (visRectDst->top - yDst)*heightSrc/heightDst;
1076 rect.right = xSrc + ((visRectDst->right - xDst)*widthSrc)/widthDst;
1077 rect.bottom = ySrc + ((visRectDst->bottom - yDst)*heightSrc)/heightDst;
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 InflateRect32( &rect, 1, 1 ); /* Avoid rounding errors */
1081 if (!IntersectRect32( visRectSrc, &rect, visRectSrc )) return FALSE;
1083 return TRUE;
1087 /***********************************************************************
1088 * BITBLT_InternalStretchBlt
1090 * Implementation of PatBlt(), BitBlt() and StretchBlt().
1092 static BOOL32 BITBLT_InternalStretchBlt( DC *dcDst, INT32 xDst, INT32 yDst,
1093 INT32 widthDst, INT32 heightDst,
1094 DC *dcSrc, INT32 xSrc, INT32 ySrc,
1095 INT32 widthSrc, INT32 heightSrc,
1096 DWORD rop )
1098 BOOL32 usePat, useSrc, useDst, destUsed, fStretch, fNullBrush;
1099 RECT32 visRectDst, visRectSrc;
1100 INT32 width, height;
1101 const BYTE *opcode;
1102 Pixmap pixmaps[3] = { 0, 0, 0 }; /* pixmaps for DST, SRC, TMP */
1103 GC tmpGC = 0;
1105 usePat = (((rop >> 4) & 0x0f0000) != (rop & 0x0f0000));
1106 useSrc = (((rop >> 2) & 0x330000) != (rop & 0x330000));
1107 useDst = (((rop >> 1) & 0x550000) != (rop & 0x550000));
1108 if (!dcSrc && useSrc) return FALSE;
1110 if (dcDst->w.flags & DC_DIRTY) CLIPPING_UpdateGCRegion( dcDst );
1111 if (dcSrc && (dcSrc->w.flags & DC_DIRTY)) CLIPPING_UpdateGCRegion( dcSrc );
1113 /* Map the coordinates to device coords */
1115 xDst = dcDst->w.DCOrgX + XLPTODP( dcDst, xDst );
1116 yDst = dcDst->w.DCOrgY + YLPTODP( dcDst, yDst );
1117 widthDst = widthDst * dcDst->vportExtX / dcDst->wndExtX;
1118 heightDst = heightDst * dcDst->vportExtY / dcDst->wndExtY;
1120 TRACE(bitblt, " vportdst=%d,%d-%d,%d wnddst=%d,%d-%d,%d\n",
1121 dcDst->vportOrgX, dcDst->vportOrgY,
1122 dcDst->vportExtX, dcDst->vportExtY,
1123 dcDst->wndOrgX, dcDst->wndOrgY,
1124 dcDst->wndExtX, dcDst->wndExtY );
1125 TRACE(bitblt, " rectdst=%d,%d-%d,%d orgdst=%d,%d\n",
1126 xDst, yDst, widthDst, heightDst,
1127 dcDst->w.DCOrgX, dcDst->w.DCOrgY );
1129 if (useSrc)
1131 xSrc = dcSrc->w.DCOrgX + XLPTODP( dcSrc, xSrc );
1132 ySrc = dcSrc->w.DCOrgY + YLPTODP( dcSrc, ySrc );
1133 widthSrc = widthSrc * dcSrc->vportExtX / dcSrc->wndExtX;
1134 heightSrc = heightSrc * dcSrc->vportExtY / dcSrc->wndExtY;
1135 fStretch = (widthSrc != widthDst) || (heightSrc != heightDst);
1136 TRACE(bitblt," vportsrc=%d,%d-%d,%d wndsrc=%d,%d-%d,%d\n",
1137 dcSrc->vportOrgX, dcSrc->vportOrgY,
1138 dcSrc->vportExtX, dcSrc->vportExtY,
1139 dcSrc->wndOrgX, dcSrc->wndOrgY,
1140 dcSrc->wndExtX, dcSrc->wndExtY );
1141 TRACE(bitblt, " rectsrc=%d,%d-%d,%d orgsrc=%d,%d\n",
1142 xSrc, ySrc, widthSrc, heightSrc,
1143 dcSrc->w.DCOrgX, dcSrc->w.DCOrgY );
1144 if (!BITBLT_GetVisRectangles( dcDst, xDst, yDst, widthDst, heightDst,
1145 dcSrc, xSrc, ySrc, widthSrc, heightSrc,
1146 &visRectSrc, &visRectDst ))
1147 return TRUE;
1148 TRACE(bitblt, " vissrc=%d,%d-%d,%d visdst=%d,%d-%d,%d\n",
1149 visRectSrc.left, visRectSrc.top,
1150 visRectSrc.right, visRectSrc.bottom,
1151 visRectDst.left, visRectDst.top,
1152 visRectDst.right, visRectDst.bottom );
1154 else
1156 fStretch = FALSE;
1157 if (!BITBLT_GetVisRectangles( dcDst, xDst, yDst, widthDst, heightDst,
1158 NULL, 0, 0, 0, 0, NULL, &visRectDst ))
1159 return TRUE;
1160 TRACE(bitblt, " vissrc=none visdst=%d,%d-%d,%d\n",
1161 visRectDst.left, visRectDst.top,
1162 visRectDst.right, visRectDst.bottom );
1165 width = visRectDst.right - visRectDst.left;
1166 height = visRectDst.bottom - visRectDst.top;
1168 if (!fStretch) switch(rop) /* A few optimisations */
1170 case BLACKNESS: /* 0x00 */
1171 if ((dcDst->w.bitsPerPixel == 1) || !COLOR_PaletteToPixel)
1172 XSetFunction( display, dcDst->u.x.gc, GXclear );
1173 else
1175 XSetFunction( display, dcDst->u.x.gc, GXcopy );
1176 XSetForeground( display, dcDst->u.x.gc, COLOR_PaletteToPixel[0] );
1177 XSetFillStyle( display, dcDst->u.x.gc, FillSolid );
1179 XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
1180 visRectDst.left, visRectDst.top, width, height );
1181 return TRUE;
1183 case DSTINVERT: /* 0x55 */
1184 if ((dcDst->w.bitsPerPixel == 1) || !COLOR_PaletteToPixel ||
1185 !Options.perfectGraphics)
1187 XSetFunction( display, dcDst->u.x.gc, GXinvert );
1189 if( COLOR_GetSystemPaletteFlags() & (COLOR_PRIVATE | COLOR_VIRTUAL) )
1190 XSetFunction( display, dcDst->u.x.gc, GXinvert);
1191 else
1193 /* Xor is much better when we do not have full colormap. */
1194 /* Using white^black ensures that we invert at least black */
1195 /* and white. */
1196 Pixel xor_pix = (WhitePixelOfScreen(screen) ^
1197 BlackPixelOfScreen(screen));
1198 XSetFunction( display, dcDst->u.x.gc, GXxor );
1199 XSetForeground( display, dcDst->u.x.gc, xor_pix);
1200 XSetFillStyle( display, dcDst->u.x.gc, FillSolid );
1202 XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
1203 visRectDst.left, visRectDst.top, width, height );
1204 return TRUE;
1206 break;
1208 case PATINVERT: /* 0x5a */
1209 if (Options.perfectGraphics) break;
1210 if (DC_SetupGCForBrush( dcDst ))
1212 XSetFunction( display, dcDst->u.x.gc, GXxor );
1213 XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
1214 visRectDst.left, visRectDst.top, width, height );
1216 return TRUE;
1218 case 0xa50065:
1219 if (Options.perfectGraphics) break;
1220 if (DC_SetupGCForBrush( dcDst ))
1222 XSetFunction( display, dcDst->u.x.gc, GXequiv );
1223 XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
1224 visRectDst.left, visRectDst.top, width, height );
1226 return TRUE;
1228 case SRCCOPY: /* 0xcc */
1229 if (dcSrc->w.bitsPerPixel == dcDst->w.bitsPerPixel)
1231 XSetGraphicsExposures( display, dcDst->u.x.gc, True );
1232 XSetFunction( display, dcDst->u.x.gc, GXcopy );
1233 XCopyArea( display, dcSrc->u.x.drawable,
1234 dcDst->u.x.drawable, dcDst->u.x.gc,
1235 visRectSrc.left, visRectSrc.top,
1236 width, height, visRectDst.left, visRectDst.top );
1237 XSetGraphicsExposures( display, dcDst->u.x.gc, False );
1238 return TRUE;
1240 if (dcSrc->w.bitsPerPixel == 1)
1242 XSetBackground( display, dcDst->u.x.gc, dcDst->w.textPixel );
1243 XSetForeground( display, dcDst->u.x.gc, dcDst->w.backgroundPixel );
1244 XSetFunction( display, dcDst->u.x.gc, GXcopy );
1245 XSetGraphicsExposures( display, dcDst->u.x.gc, True );
1246 XCopyPlane( display, dcSrc->u.x.drawable,
1247 dcDst->u.x.drawable, dcDst->u.x.gc,
1248 visRectSrc.left, visRectSrc.top,
1249 width, height, visRectDst.left, visRectDst.top, 1 );
1250 XSetGraphicsExposures( display, dcDst->u.x.gc, False );
1251 return TRUE;
1253 break;
1255 case PATCOPY: /* 0xf0 */
1256 if (!DC_SetupGCForBrush( dcDst )) return TRUE;
1257 XSetFunction( display, dcDst->u.x.gc, GXcopy );
1258 XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
1259 visRectDst.left, visRectDst.top, width, height );
1260 return TRUE;
1262 case WHITENESS: /* 0xff */
1263 if ((dcDst->w.bitsPerPixel == 1) || !COLOR_PaletteToPixel)
1264 XSetFunction( display, dcDst->u.x.gc, GXset );
1265 else
1267 XSetFunction( display, dcDst->u.x.gc, GXcopy );
1268 XSetForeground( display, dcDst->u.x.gc,
1269 COLOR_PaletteToPixel[COLOR_GetSystemPaletteSize() - 1]);
1270 XSetFillStyle( display, dcDst->u.x.gc, FillSolid );
1272 XFillRectangle( display, dcDst->u.x.drawable, dcDst->u.x.gc,
1273 visRectDst.left, visRectDst.top, width, height );
1274 return TRUE;
1277 tmpGC = XCreateGC( display, dcDst->u.x.drawable, 0, NULL );
1278 pixmaps[DST] = XCreatePixmap( display, rootWindow, width, height,
1279 dcDst->w.bitsPerPixel );
1280 if (useSrc)
1282 pixmaps[SRC] = XCreatePixmap( display, rootWindow, width, height,
1283 dcDst->w.bitsPerPixel );
1284 if (fStretch)
1285 BITBLT_GetSrcAreaStretch( dcSrc, dcDst, pixmaps[SRC], tmpGC,
1286 xSrc, ySrc, widthSrc, heightSrc,
1287 xDst, yDst, widthDst, heightDst,
1288 &visRectSrc, &visRectDst );
1289 else
1290 BITBLT_GetSrcArea( dcSrc, dcDst, pixmaps[SRC], tmpGC,
1291 xSrc, ySrc, &visRectSrc );
1293 if (useDst) BITBLT_GetDstArea( dcDst, pixmaps[DST], tmpGC, &visRectDst );
1294 if (usePat) fNullBrush = !DC_SetupGCForPatBlt( dcDst, tmpGC, TRUE );
1295 else fNullBrush = FALSE;
1296 destUsed = FALSE;
1298 for (opcode = BITBLT_Opcodes[(rop >> 16) & 0xff]; *opcode; opcode++)
1300 if (OP_DST(*opcode) == DST) destUsed = TRUE;
1301 XSetFunction( display, tmpGC, OP_ROP(*opcode) );
1302 switch(OP_SRCDST(*opcode))
1304 case OP_ARGS(DST,TMP):
1305 case OP_ARGS(SRC,TMP):
1306 if (!pixmaps[TMP])
1307 pixmaps[TMP] = XCreatePixmap( display, rootWindow,
1308 width, height,
1309 dcDst->w.bitsPerPixel );
1310 /* fall through */
1311 case OP_ARGS(DST,SRC):
1312 case OP_ARGS(SRC,DST):
1313 case OP_ARGS(TMP,SRC):
1314 case OP_ARGS(TMP,DST):
1315 XCopyArea( display, pixmaps[OP_SRC(*opcode)],
1316 pixmaps[OP_DST(*opcode)], tmpGC,
1317 0, 0, width, height, 0, 0 );
1318 break;
1320 case OP_ARGS(PAT,TMP):
1321 if (!pixmaps[TMP] && !fNullBrush)
1322 pixmaps[TMP] = XCreatePixmap( display, rootWindow,
1323 width, height,
1324 dcDst->w.bitsPerPixel );
1325 /* fall through */
1326 case OP_ARGS(PAT,DST):
1327 case OP_ARGS(PAT,SRC):
1328 if (!fNullBrush)
1329 XFillRectangle( display, pixmaps[OP_DST(*opcode)],
1330 tmpGC, 0, 0, width, height );
1331 break;
1334 XSetFunction( display, dcDst->u.x.gc, GXcopy );
1335 BITBLT_PutDstArea( dcDst, pixmaps[destUsed ? DST : SRC],
1336 dcDst->u.x.gc, &visRectDst );
1337 XFreePixmap( display, pixmaps[DST] );
1338 if (pixmaps[SRC]) XFreePixmap( display, pixmaps[SRC] );
1339 if (pixmaps[TMP]) XFreePixmap( display, pixmaps[TMP] );
1340 XFreeGC( display, tmpGC );
1341 return TRUE;
1344 struct StretchBlt_params
1346 DC *dcDst;
1347 INT32 xDst;
1348 INT32 yDst;
1349 INT32 widthDst;
1350 INT32 heightDst;
1351 DC *dcSrc;
1352 INT32 xSrc;
1353 INT32 ySrc;
1354 INT32 widthSrc;
1355 INT32 heightSrc;
1356 DWORD rop;
1359 /***********************************************************************
1360 * BITBLT_DoStretchBlt
1362 * Wrapper function for BITBLT_InternalStretchBlt
1363 * to use with CALL_LARGE_STACK.
1365 static int BITBLT_DoStretchBlt( const struct StretchBlt_params *p )
1367 return (int)BITBLT_InternalStretchBlt( p->dcDst, p->xDst, p->yDst,
1368 p->widthDst, p->heightDst,
1369 p->dcSrc, p->xSrc, p->ySrc,
1370 p->widthSrc, p->heightSrc, p->rop );
1373 /***********************************************************************
1374 * X11DRV_PatBlt
1376 BOOL32 X11DRV_PatBlt( DC *dc, INT32 left, INT32 top,
1377 INT32 width, INT32 height, DWORD rop )
1379 struct StretchBlt_params params = { dc, left, top, width, height,
1380 NULL, 0, 0, 0, 0, rop };
1381 BOOL32 result;
1382 DIB_UpdateDIBSection( dc, FALSE );
1383 EnterCriticalSection( &X11DRV_CritSection );
1384 result = (BOOL32)CALL_LARGE_STACK( BITBLT_DoStretchBlt, &params );
1385 LeaveCriticalSection( &X11DRV_CritSection );
1386 DIB_UpdateDIBSection( dc, TRUE );
1387 return result;
1391 /***********************************************************************
1392 * X11DRV_BitBlt
1394 BOOL32 X11DRV_BitBlt( DC *dcDst, INT32 xDst, INT32 yDst,
1395 INT32 width, INT32 height, DC *dcSrc,
1396 INT32 xSrc, INT32 ySrc, DWORD rop )
1398 struct StretchBlt_params params = { dcDst, xDst, yDst, width, height,
1399 dcSrc, xSrc, ySrc, width, height, rop};
1400 BOOL32 result;
1401 DIB_UpdateDIBSection( dcDst, FALSE );
1402 DIB_UpdateDIBSection( dcSrc, FALSE );
1403 EnterCriticalSection( &X11DRV_CritSection );
1404 result = (BOOL32)CALL_LARGE_STACK( BITBLT_DoStretchBlt, &params );
1405 LeaveCriticalSection( &X11DRV_CritSection );
1406 DIB_UpdateDIBSection( dcDst, TRUE );
1407 DIB_UpdateDIBSection( dcSrc, TRUE );
1408 return result;
1412 /***********************************************************************
1413 * X11DRV_StretchBlt
1415 BOOL32 X11DRV_StretchBlt( DC *dcDst, INT32 xDst, INT32 yDst,
1416 INT32 widthDst, INT32 heightDst,
1417 DC *dcSrc, INT32 xSrc, INT32 ySrc,
1418 INT32 widthSrc, INT32 heightSrc, DWORD rop )
1420 struct StretchBlt_params params = { dcDst, xDst, yDst, widthDst, heightDst,
1421 dcSrc, xSrc, ySrc, widthSrc, heightSrc,
1422 rop };
1423 BOOL32 result;
1424 DIB_UpdateDIBSection( dcDst, FALSE );
1425 DIB_UpdateDIBSection( dcSrc, FALSE );
1426 EnterCriticalSection( &X11DRV_CritSection );
1427 result = (BOOL32)CALL_LARGE_STACK( BITBLT_DoStretchBlt, &params );
1428 LeaveCriticalSection( &X11DRV_CritSection );
1429 DIB_UpdateDIBSection( dcDst, TRUE );
1430 DIB_UpdateDIBSection( dcSrc, TRUE );
1431 return result;