2 * GDI bit-blit operations
4 * Copyright 1993, 1994 Alexandre Julliard
11 #include <X11/Intrinsic.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
)
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;
460 int rop
, i
, res
, src
, dst
, pat
, tmp
, dstUsed
;
463 for (rop
= 0; rop
< 256; rop
++)
466 for (i
= 0; i
< 8; i
++)
471 for (opcode
= BITBLT_Opcodes
[rop
]; *opcode
; opcode
++)
475 case OP_ARGS(DST
,TMP
):
476 tmp
= do_bitop( dst
, tmp
, *opcode
& 0xf );
478 case OP_ARGS(DST
,SRC
):
479 src
= do_bitop( dst
, src
, *opcode
& 0xf );
481 case OP_ARGS(SRC
,TMP
):
482 tmp
= do_bitop( src
, tmp
, *opcode
& 0xf );
484 case OP_ARGS(SRC
,DST
):
485 dst
= do_bitop( src
, dst
, *opcode
& 0xf );
488 case OP_ARGS(PAT
,TMP
):
489 tmp
= do_bitop( pat
, tmp
, *opcode
& 0xf );
491 case OP_ARGS(PAT
,DST
):
492 dst
= do_bitop( pat
, dst
, *opcode
& 0xf );
495 case OP_ARGS(PAT
,SRC
):
496 src
= do_bitop( pat
, src
, *opcode
& 0xf );
498 case OP_ARGS(TMP
,DST
):
499 dst
= do_bitop( tmp
, dst
, *opcode
& 0xf );
502 case OP_ARGS(TMP
,SRC
):
503 src
= do_bitop( tmp
, src
, *opcode
& 0xf );
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 /***********************************************************************
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
;
532 case STRETCH_ANDSCANS
:
533 for(; widthDst
> 0; widthDst
--, xsrc
+= xinc
)
534 *rowDst
++ &= rowSrc
[xsrc
>> 16];
536 case STRETCH_ORSCANS
:
537 for(; widthDst
> 0; widthDst
--, xsrc
+= xinc
)
538 *rowDst
++ |= rowSrc
[xsrc
>> 16];
540 case STRETCH_DELETESCANS
:
541 for(; widthDst
> 0; widthDst
--, xsrc
+= xinc
)
542 *rowDst
++ = rowSrc
[xsrc
>> 16];
548 /***********************************************************************
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
;
561 case STRETCH_ORSCANS
:
562 for(; widthSrc
> 0; widthSrc
--, xdst
+= xinc
)
563 rowDst
[xdst
>> 16] |= *rowSrc
++;
565 case STRETCH_ANDSCANS
:
566 for(; widthSrc
> 0; widthSrc
--, xdst
+= xinc
)
567 rowDst
[xdst
>> 16] &= *rowSrc
++;
569 case STRETCH_DELETESCANS
:
570 for(; widthSrc
> 0; widthSrc
--, xdst
+= xinc
)
571 rowDst
[xdst
>> 16] = *rowSrc
++;
577 /***********************************************************************
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
)
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
)];
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
);
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
;
644 INT32 xinc
, xoff
, yinc
, ysrc
, ydst
;
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
);
672 xinc
= ((int)widthSrc
<< 16) / widthDst
;
673 xoff
= ((widthSrc
<< 16) - (xinc
* widthDst
)) / 2;
677 xinc
= ((int)widthDst
<< 16) / widthSrc
;
678 xoff
= ((widthDst
<< 16) - (xinc
* widthSrc
)) / 2;
683 yinc
= ((int)heightSrc
<< 16) / heightDst
;
684 ydst
= visRectDst
->top
;
687 ysrc
= yinc
* (heightDst
- ydst
- 1);
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
702 visRectSrc
->right
- visRectSrc
->left
,
703 dstImage
->depth
, foreground
, background
, hswap
);
705 /* Stretch or shrink it */
707 BITBLT_StretchRow( rowSrc
, rowDst
, visRectDst
->left
,
708 visRectDst
->right
- visRectDst
->left
,
710 else BITBLT_ShrinkRow( rowSrc
, rowDst
,
711 hswap
? widthSrc
- visRectSrc
->right
713 visRectSrc
->right
- visRectSrc
->left
,
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
;
741 yinc
= ((int)heightDst
<< 16) / heightSrc
;
742 ysrc
= visRectSrc
->top
;
743 ydst
= ((heightDst
<< 16) - (yinc
* heightSrc
)) / 2;
746 ydst
+= yinc
* (heightSrc
- ysrc
- 1);
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
761 visRectSrc
->right
- visRectSrc
->left
,
762 dstImage
->depth
, foreground
, background
, hswap
);
764 /* Stretch or shrink it */
766 BITBLT_StretchRow( rowSrc
, rowDst
, visRectDst
->left
,
767 visRectDst
->right
- visRectDst
->left
,
769 else BITBLT_ShrinkRow( rowSrc
, rowDst
,
770 hswap
? widthSrc
- visRectSrc
->right
772 visRectSrc
->right
- visRectSrc
->left
,
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))
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
;
819 X11DRV_PDEVICE
*physDevSrc
= (X11DRV_PDEVICE
*)dcSrc
->physDev
;
820 X11DRV_PDEVICE
*physDevDst
= (X11DRV_PDEVICE
*)dcDst
->physDev
;
822 RECT32 rectSrc
= *visRectSrc
;
823 RECT32 rectDst
= *visRectDst
;
825 if (widthSrc
< 0) xSrc
+= widthSrc
;
826 if (widthDst
< 0) xDst
+= widthDst
;
827 if (heightSrc
< 0) ySrc
+= heightSrc
;
828 if (heightDst
< 0) yDst
+= heightDst
;
829 OffsetRect32( &rectSrc
, -xSrc
, -ySrc
);
830 OffsetRect32( &rectDst
, -xDst
, -yDst
);
832 /* FIXME: avoid BadMatch errors */
833 imageSrc
= XGetImage( display
, physDevSrc
->drawable
,
834 visRectSrc
->left
, visRectSrc
->top
,
835 visRectSrc
->right
- visRectSrc
->left
,
836 visRectSrc
->bottom
- visRectSrc
->top
,
837 AllPlanes
, ZPixmap
);
838 XCREATEIMAGE( imageDst
, rectDst
.right
- rectDst
.left
,
839 rectDst
.bottom
- rectDst
.top
, dcDst
->w
.bitsPerPixel
);
840 BITBLT_StretchImage( imageSrc
, imageDst
, widthSrc
, heightSrc
,
841 widthDst
, heightDst
, &rectSrc
, &rectDst
,
842 physDevDst
->textPixel
, dcDst
->w
.bitsPerPixel
!= 1 ?
843 physDevDst
->backgroundPixel
:
844 physDevSrc
->backgroundPixel
,
845 dcDst
->w
.stretchBltMode
);
846 XPutImage( display
, pixmap
, gc
, imageDst
, 0, 0, 0, 0,
847 rectDst
.right
- rectDst
.left
, rectDst
.bottom
- rectDst
.top
);
848 XDestroyImage( imageSrc
);
849 XDestroyImage( imageDst
);
853 /***********************************************************************
856 * Retrieve an area from the source DC, mapping all the
857 * pixels to Windows colors.
859 static void BITBLT_GetSrcArea( DC
*dcSrc
, DC
*dcDst
, Pixmap pixmap
, GC gc
,
860 INT32 xSrc
, INT32 ySrc
, RECT32
*visRectSrc
)
862 XImage
*imageSrc
, *imageDst
;
864 INT32 width
= visRectSrc
->right
- visRectSrc
->left
;
865 INT32 height
= visRectSrc
->bottom
- visRectSrc
->top
;
866 X11DRV_PDEVICE
*physDevSrc
= (X11DRV_PDEVICE
*)dcSrc
->physDev
;
867 X11DRV_PDEVICE
*physDevDst
= (X11DRV_PDEVICE
*)dcDst
->physDev
;
869 if (dcSrc
->w
.bitsPerPixel
== dcDst
->w
.bitsPerPixel
)
871 if (!COLOR_PixelToPalette
||
872 (dcDst
->w
.bitsPerPixel
== 1)) /* monochrome -> monochrome */
874 XCopyArea( display
, physDevSrc
->drawable
, pixmap
, gc
,
875 visRectSrc
->left
, visRectSrc
->top
, width
, height
, 0, 0);
877 else /* color -> color */
879 if (dcSrc
->w
.flags
& DC_MEMORY
)
880 imageSrc
= XGetImage( display
, physDevSrc
->drawable
,
881 visRectSrc
->left
, visRectSrc
->top
,
882 width
, height
, AllPlanes
, ZPixmap
);
885 /* Make sure we don't get a BadMatch error */
886 XCopyArea( display
, physDevSrc
->drawable
, pixmap
, gc
,
887 visRectSrc
->left
, visRectSrc
->top
,
888 width
, height
, 0, 0);
889 imageSrc
= XGetImage( display
, pixmap
, 0, 0, width
, height
,
890 AllPlanes
, ZPixmap
);
892 for (y
= 0; y
< height
; y
++)
893 for (x
= 0; x
< width
; x
++)
894 XPutPixel(imageSrc
, x
, y
,
895 COLOR_PixelToPalette
[XGetPixel(imageSrc
, x
, y
)]);
896 XPutImage( display
, pixmap
, gc
, imageSrc
,
897 0, 0, 0, 0, width
, height
);
898 XDestroyImage( imageSrc
);
903 if (dcSrc
->w
.bitsPerPixel
== 1) /* monochrome -> color */
905 if (COLOR_PixelToPalette
)
907 XSetBackground( display
, gc
,
908 COLOR_PixelToPalette
[physDevDst
->textPixel
] );
909 XSetForeground( display
, gc
,
910 COLOR_PixelToPalette
[physDevDst
->backgroundPixel
]);
914 XSetBackground( display
, gc
, physDevDst
->textPixel
);
915 XSetForeground( display
, gc
, physDevDst
->backgroundPixel
);
917 XCopyPlane( display
, physDevSrc
->drawable
, pixmap
, gc
,
918 visRectSrc
->left
, visRectSrc
->top
,
919 width
, height
, 0, 0, 1 );
921 else /* color -> monochrome */
923 /* FIXME: avoid BadMatch error */
924 imageSrc
= XGetImage( display
, physDevSrc
->drawable
,
925 visRectSrc
->left
, visRectSrc
->top
,
926 width
, height
, AllPlanes
, ZPixmap
);
927 XCREATEIMAGE( imageDst
, width
, height
, dcDst
->w
.bitsPerPixel
);
928 for (y
= 0; y
< height
; y
++)
929 for (x
= 0; x
< width
; x
++)
930 XPutPixel(imageDst
, x
, y
, (XGetPixel(imageSrc
,x
,y
) ==
931 physDevSrc
->backgroundPixel
) );
932 XPutImage( display
, pixmap
, gc
, imageDst
,
933 0, 0, 0, 0, width
, height
);
934 XDestroyImage( imageSrc
);
935 XDestroyImage( imageDst
);
941 /***********************************************************************
944 * Retrieve an area from the destination DC, mapping all the
945 * pixels to Windows colors.
947 static void BITBLT_GetDstArea(DC
*dc
, Pixmap pixmap
, GC gc
, RECT32
*visRectDst
)
949 INT32 width
= visRectDst
->right
- visRectDst
->left
;
950 INT32 height
= visRectDst
->bottom
- visRectDst
->top
;
951 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
953 if (!COLOR_PixelToPalette
|| (dc
->w
.bitsPerPixel
== 1) ||
954 (COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL
) )
956 XCopyArea( display
, physDev
->drawable
, pixmap
, gc
,
957 visRectDst
->left
, visRectDst
->top
, width
, height
, 0, 0 );
964 if (dc
->w
.flags
& DC_MEMORY
)
965 image
= XGetImage( display
, physDev
->drawable
,
966 visRectDst
->left
, visRectDst
->top
,
967 width
, height
, AllPlanes
, ZPixmap
);
970 /* Make sure we don't get a BadMatch error */
971 XCopyArea( display
, physDev
->drawable
, pixmap
, gc
,
972 visRectDst
->left
, visRectDst
->top
, width
, height
, 0, 0);
973 image
= XGetImage( display
, pixmap
, 0, 0, width
, height
,
974 AllPlanes
, ZPixmap
);
976 for (y
= 0; y
< height
; y
++)
977 for (x
= 0; x
< width
; x
++)
978 XPutPixel( image
, x
, y
,
979 COLOR_PixelToPalette
[XGetPixel( image
, x
, y
)]);
980 XPutImage( display
, pixmap
, gc
, image
, 0, 0, 0, 0, width
, height
);
981 XDestroyImage( image
);
986 /***********************************************************************
989 * Put an area back into the destination DC, mapping the pixel
990 * colors to X pixels.
992 static void BITBLT_PutDstArea(DC
*dc
, Pixmap pixmap
, GC gc
, RECT32
*visRectDst
)
994 INT32 width
= visRectDst
->right
- visRectDst
->left
;
995 INT32 height
= visRectDst
->bottom
- visRectDst
->top
;
996 X11DRV_PDEVICE
*physDev
= (X11DRV_PDEVICE
*)dc
->physDev
;
998 /* !COLOR_PaletteToPixel is _NOT_ enough */
1000 if (!COLOR_PaletteToPixel
|| (dc
->w
.bitsPerPixel
== 1) ||
1001 (COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL
) )
1003 XCopyArea( display
, pixmap
, physDev
->drawable
, gc
, 0, 0,
1004 width
, height
, visRectDst
->left
, visRectDst
->top
);
1008 register INT32 x
, y
;
1009 XImage
*image
= XGetImage( display
, pixmap
, 0, 0, width
, height
,
1010 AllPlanes
, ZPixmap
);
1011 for (y
= 0; y
< height
; y
++)
1012 for (x
= 0; x
< width
; x
++)
1014 XPutPixel( image
, x
, y
,
1015 COLOR_PaletteToPixel
[XGetPixel( image
, x
, y
)]);
1017 XPutImage( display
, physDev
->drawable
, gc
, image
, 0, 0,
1018 visRectDst
->left
, visRectDst
->top
, width
, height
);
1019 XDestroyImage( image
);
1024 /***********************************************************************
1025 * BITBLT_GetVisRectangles
1027 * Get the source and destination visible rectangles for StretchBlt().
1028 * Return FALSE if one of the rectangles is empty.
1030 static BOOL32
BITBLT_GetVisRectangles( DC
*dcDst
, INT32 xDst
, INT32 yDst
,
1031 INT32 widthDst
, INT32 heightDst
,
1032 DC
*dcSrc
, INT32 xSrc
, INT32 ySrc
,
1033 INT32 widthSrc
, INT32 heightSrc
,
1034 RECT32
*visRectSrc
, RECT32
*visRectDst
)
1036 RECT32 rect
, clipRect
;
1038 /* Get the destination visible rectangle */
1040 SetRect32( &rect
, xDst
, yDst
, xDst
+ widthDst
, yDst
+ heightDst
);
1041 if (widthDst
< 0) SWAP_INT32( &rect
.left
, &rect
.right
);
1042 if (heightDst
< 0) SWAP_INT32( &rect
.top
, &rect
.bottom
);
1043 GetRgnBox32( dcDst
->w
.hGCClipRgn
, &clipRect
);
1044 if (!IntersectRect32( visRectDst
, &rect
, &clipRect
)) return FALSE
;
1046 /* Get the source visible rectangle */
1048 if (!dcSrc
) return TRUE
;
1049 SetRect32( &rect
, xSrc
, ySrc
, xSrc
+ widthSrc
, ySrc
+ heightSrc
);
1050 if (widthSrc
< 0) SWAP_INT32( &rect
.left
, &rect
.right
);
1051 if (heightSrc
< 0) SWAP_INT32( &rect
.top
, &rect
.bottom
);
1052 /* Apparently the clipping and visible regions are only for output,
1053 so just check against totalExtent here to avoid BadMatch errors */
1054 if (!IntersectRect32( visRectSrc
, &rect
, &dcSrc
->w
.totalExtent
))
1057 /* Intersect the rectangles */
1059 if ((widthSrc
== widthDst
) && (heightSrc
== heightDst
)) /* no stretching */
1061 OffsetRect32( visRectSrc
, xDst
- xSrc
, yDst
- ySrc
);
1062 if (!IntersectRect32( &rect
, visRectSrc
, visRectDst
)) return FALSE
;
1063 *visRectSrc
= *visRectDst
= rect
;
1064 OffsetRect32( visRectSrc
, xSrc
- xDst
, ySrc
- yDst
);
1066 else /* stretching */
1068 /* Map source rectangle into destination coordinates */
1069 rect
.left
= xDst
+ (visRectSrc
->left
- xSrc
)*widthDst
/widthSrc
;
1070 rect
.top
= yDst
+ (visRectSrc
->top
- ySrc
)*heightDst
/heightSrc
;
1071 rect
.right
= xDst
+ ((visRectSrc
->right
- xSrc
)*widthDst
)/widthSrc
;
1072 rect
.bottom
= yDst
+ ((visRectSrc
->bottom
- ySrc
)*heightDst
)/heightSrc
;
1073 if (rect
.left
> rect
.right
) SWAP_INT32( &rect
.left
, &rect
.right
);
1074 if (rect
.top
> rect
.bottom
) SWAP_INT32( &rect
.top
, &rect
.bottom
);
1075 InflateRect32( &rect
, 1, 1 ); /* Avoid rounding errors */
1076 if (!IntersectRect32( visRectDst
, &rect
, visRectDst
)) return FALSE
;
1078 /* Map destination rectangle back to source coordinates */
1080 rect
.left
= xSrc
+ (visRectDst
->left
- xDst
)*widthSrc
/widthDst
;
1081 rect
.top
= ySrc
+ (visRectDst
->top
- yDst
)*heightSrc
/heightDst
;
1082 rect
.right
= xSrc
+ ((visRectDst
->right
- xDst
)*widthSrc
)/widthDst
;
1083 rect
.bottom
= ySrc
+ ((visRectDst
->bottom
- yDst
)*heightSrc
)/heightDst
;
1084 if (rect
.left
> rect
.right
) SWAP_INT32( &rect
.left
, &rect
.right
);
1085 if (rect
.top
> rect
.bottom
) SWAP_INT32( &rect
.top
, &rect
.bottom
);
1086 InflateRect32( &rect
, 1, 1 ); /* Avoid rounding errors */
1087 if (!IntersectRect32( visRectSrc
, &rect
, visRectSrc
)) return FALSE
;
1093 /***********************************************************************
1094 * BITBLT_InternalStretchBlt
1096 * Implementation of PatBlt(), BitBlt() and StretchBlt().
1098 static BOOL32
BITBLT_InternalStretchBlt( DC
*dcDst
, INT32 xDst
, INT32 yDst
,
1099 INT32 widthDst
, INT32 heightDst
,
1100 DC
*dcSrc
, INT32 xSrc
, INT32 ySrc
,
1101 INT32 widthSrc
, INT32 heightSrc
,
1104 BOOL32 usePat
, useSrc
, useDst
, destUsed
, fStretch
, fNullBrush
;
1105 RECT32 visRectDst
, visRectSrc
;
1106 INT32 width
, height
;
1108 Pixmap pixmaps
[3] = { 0, 0, 0 }; /* pixmaps for DST, SRC, TMP */
1110 X11DRV_PDEVICE
*physDevSrc
= NULL
;
1111 X11DRV_PDEVICE
*physDevDst
= (X11DRV_PDEVICE
*)dcDst
->physDev
;
1113 if(dcSrc
) physDevSrc
= (X11DRV_PDEVICE
*)dcSrc
->physDev
;
1114 usePat
= (((rop
>> 4) & 0x0f0000) != (rop
& 0x0f0000));
1115 useSrc
= (((rop
>> 2) & 0x330000) != (rop
& 0x330000));
1116 useDst
= (((rop
>> 1) & 0x550000) != (rop
& 0x550000));
1117 if (!dcSrc
&& useSrc
) return FALSE
;
1119 if (dcDst
->w
.flags
& DC_DIRTY
) CLIPPING_UpdateGCRegion( dcDst
);
1120 if (dcSrc
&& (dcSrc
->w
.flags
& DC_DIRTY
)) CLIPPING_UpdateGCRegion( dcSrc
);
1122 /* Map the coordinates to device coords */
1124 xDst
= dcDst
->w
.DCOrgX
+ XLPTODP( dcDst
, xDst
);
1125 yDst
= dcDst
->w
.DCOrgY
+ YLPTODP( dcDst
, yDst
);
1126 widthDst
= widthDst
* dcDst
->vportExtX
/ dcDst
->wndExtX
;
1127 heightDst
= heightDst
* dcDst
->vportExtY
/ dcDst
->wndExtY
;
1129 TRACE(bitblt
, " vportdst=%d,%d-%d,%d wnddst=%d,%d-%d,%d\n",
1130 dcDst
->vportOrgX
, dcDst
->vportOrgY
,
1131 dcDst
->vportExtX
, dcDst
->vportExtY
,
1132 dcDst
->wndOrgX
, dcDst
->wndOrgY
,
1133 dcDst
->wndExtX
, dcDst
->wndExtY
);
1134 TRACE(bitblt
, " rectdst=%d,%d-%d,%d orgdst=%d,%d\n",
1135 xDst
, yDst
, widthDst
, heightDst
,
1136 dcDst
->w
.DCOrgX
, dcDst
->w
.DCOrgY
);
1140 xSrc
= dcSrc
->w
.DCOrgX
+ XLPTODP( dcSrc
, xSrc
);
1141 ySrc
= dcSrc
->w
.DCOrgY
+ YLPTODP( dcSrc
, ySrc
);
1142 widthSrc
= widthSrc
* dcSrc
->vportExtX
/ dcSrc
->wndExtX
;
1143 heightSrc
= heightSrc
* dcSrc
->vportExtY
/ dcSrc
->wndExtY
;
1144 fStretch
= (widthSrc
!= widthDst
) || (heightSrc
!= heightDst
);
1145 TRACE(bitblt
," vportsrc=%d,%d-%d,%d wndsrc=%d,%d-%d,%d\n",
1146 dcSrc
->vportOrgX
, dcSrc
->vportOrgY
,
1147 dcSrc
->vportExtX
, dcSrc
->vportExtY
,
1148 dcSrc
->wndOrgX
, dcSrc
->wndOrgY
,
1149 dcSrc
->wndExtX
, dcSrc
->wndExtY
);
1150 TRACE(bitblt
, " rectsrc=%d,%d-%d,%d orgsrc=%d,%d\n",
1151 xSrc
, ySrc
, widthSrc
, heightSrc
,
1152 dcSrc
->w
.DCOrgX
, dcSrc
->w
.DCOrgY
);
1153 if (!BITBLT_GetVisRectangles( dcDst
, xDst
, yDst
, widthDst
, heightDst
,
1154 dcSrc
, xSrc
, ySrc
, widthSrc
, heightSrc
,
1155 &visRectSrc
, &visRectDst
))
1157 TRACE(bitblt
, " vissrc=%d,%d-%d,%d visdst=%d,%d-%d,%d\n",
1158 visRectSrc
.left
, visRectSrc
.top
,
1159 visRectSrc
.right
, visRectSrc
.bottom
,
1160 visRectDst
.left
, visRectDst
.top
,
1161 visRectDst
.right
, visRectDst
.bottom
);
1166 if (!BITBLT_GetVisRectangles( dcDst
, xDst
, yDst
, widthDst
, heightDst
,
1167 NULL
, 0, 0, 0, 0, NULL
, &visRectDst
))
1169 TRACE(bitblt
, " vissrc=none visdst=%d,%d-%d,%d\n",
1170 visRectDst
.left
, visRectDst
.top
,
1171 visRectDst
.right
, visRectDst
.bottom
);
1174 width
= visRectDst
.right
- visRectDst
.left
;
1175 height
= visRectDst
.bottom
- visRectDst
.top
;
1177 if (!fStretch
) switch(rop
) /* A few optimisations */
1179 case BLACKNESS
: /* 0x00 */
1180 if ((dcDst
->w
.bitsPerPixel
== 1) || !COLOR_PaletteToPixel
)
1181 XSetFunction( display
, physDevDst
->gc
, GXclear
);
1184 XSetFunction( display
, physDevDst
->gc
, GXcopy
);
1185 XSetForeground( display
, physDevDst
->gc
, COLOR_PaletteToPixel
[0] );
1186 XSetFillStyle( display
, physDevDst
->gc
, FillSolid
);
1188 XFillRectangle( display
, physDevDst
->drawable
, physDevDst
->gc
,
1189 visRectDst
.left
, visRectDst
.top
, width
, height
);
1192 case DSTINVERT
: /* 0x55 */
1193 if ((dcDst
->w
.bitsPerPixel
== 1) || !COLOR_PaletteToPixel
||
1194 !Options
.perfectGraphics
)
1196 XSetFunction( display
, physDevDst
->gc
, GXinvert
);
1198 if( COLOR_GetSystemPaletteFlags() & (COLOR_PRIVATE
| COLOR_VIRTUAL
) )
1199 XSetFunction( display
, physDevDst
->gc
, GXinvert
);
1202 /* Xor is much better when we do not have full colormap. */
1203 /* Using white^black ensures that we invert at least black */
1205 Pixel xor_pix
= (WhitePixelOfScreen(screen
) ^
1206 BlackPixelOfScreen(screen
));
1207 XSetFunction( display
, physDevDst
->gc
, GXxor
);
1208 XSetForeground( display
, physDevDst
->gc
, xor_pix
);
1209 XSetFillStyle( display
, physDevDst
->gc
, FillSolid
);
1211 XFillRectangle( display
, physDevDst
->drawable
, physDevDst
->gc
,
1212 visRectDst
.left
, visRectDst
.top
, width
, height
);
1217 case PATINVERT
: /* 0x5a */
1218 if (Options
.perfectGraphics
) break;
1219 if (X11DRV_SetupGCForBrush( dcDst
))
1221 XSetFunction( display
, physDevDst
->gc
, GXxor
);
1222 XFillRectangle( display
, physDevDst
->drawable
, physDevDst
->gc
,
1223 visRectDst
.left
, visRectDst
.top
, width
, height
);
1228 if (Options
.perfectGraphics
) break;
1229 if (X11DRV_SetupGCForBrush( dcDst
))
1231 XSetFunction( display
, physDevDst
->gc
, GXequiv
);
1232 XFillRectangle( display
, physDevDst
->drawable
, physDevDst
->gc
,
1233 visRectDst
.left
, visRectDst
.top
, width
, height
);
1237 case SRCCOPY
: /* 0xcc */
1238 if (dcSrc
->w
.bitsPerPixel
== dcDst
->w
.bitsPerPixel
)
1240 XSetGraphicsExposures( display
, physDevDst
->gc
, True
);
1241 XSetFunction( display
, physDevDst
->gc
, GXcopy
);
1242 XCopyArea( display
, physDevSrc
->drawable
,
1243 physDevDst
->drawable
, physDevDst
->gc
,
1244 visRectSrc
.left
, visRectSrc
.top
,
1245 width
, height
, visRectDst
.left
, visRectDst
.top
);
1246 XSetGraphicsExposures( display
, physDevDst
->gc
, False
);
1249 if (dcSrc
->w
.bitsPerPixel
== 1)
1251 XSetBackground( display
, physDevDst
->gc
, physDevDst
->textPixel
);
1252 XSetForeground( display
, physDevDst
->gc
,
1253 physDevDst
->backgroundPixel
);
1254 XSetFunction( display
, physDevDst
->gc
, GXcopy
);
1255 XSetGraphicsExposures( display
, physDevDst
->gc
, True
);
1256 XCopyPlane( display
, physDevSrc
->drawable
,
1257 physDevDst
->drawable
, physDevDst
->gc
,
1258 visRectSrc
.left
, visRectSrc
.top
,
1259 width
, height
, visRectDst
.left
, visRectDst
.top
, 1 );
1260 XSetGraphicsExposures( display
, physDevDst
->gc
, False
);
1265 case PATCOPY
: /* 0xf0 */
1266 if (!X11DRV_SetupGCForBrush( dcDst
)) return TRUE
;
1267 XSetFunction( display
, physDevDst
->gc
, GXcopy
);
1268 XFillRectangle( display
, physDevDst
->drawable
, physDevDst
->gc
,
1269 visRectDst
.left
, visRectDst
.top
, width
, height
);
1272 case WHITENESS
: /* 0xff */
1273 if ((dcDst
->w
.bitsPerPixel
== 1) || !COLOR_PaletteToPixel
)
1274 XSetFunction( display
, physDevDst
->gc
, GXset
);
1277 XSetFunction( display
, physDevDst
->gc
, GXcopy
);
1278 XSetForeground( display
, physDevDst
->gc
,
1279 COLOR_PaletteToPixel
[COLOR_GetSystemPaletteSize() - 1]);
1280 XSetFillStyle( display
, physDevDst
->gc
, FillSolid
);
1282 XFillRectangle( display
, physDevDst
->drawable
, physDevDst
->gc
,
1283 visRectDst
.left
, visRectDst
.top
, width
, height
);
1287 tmpGC
= XCreateGC( display
, physDevDst
->drawable
, 0, NULL
);
1288 pixmaps
[DST
] = XCreatePixmap( display
, rootWindow
, width
, height
,
1289 dcDst
->w
.bitsPerPixel
);
1292 pixmaps
[SRC
] = XCreatePixmap( display
, rootWindow
, width
, height
,
1293 dcDst
->w
.bitsPerPixel
);
1295 BITBLT_GetSrcAreaStretch( dcSrc
, dcDst
, pixmaps
[SRC
], tmpGC
,
1296 xSrc
, ySrc
, widthSrc
, heightSrc
,
1297 xDst
, yDst
, widthDst
, heightDst
,
1298 &visRectSrc
, &visRectDst
);
1300 BITBLT_GetSrcArea( dcSrc
, dcDst
, pixmaps
[SRC
], tmpGC
,
1301 xSrc
, ySrc
, &visRectSrc
);
1303 if (useDst
) BITBLT_GetDstArea( dcDst
, pixmaps
[DST
], tmpGC
, &visRectDst
);
1304 if (usePat
) fNullBrush
= !X11DRV_SetupGCForPatBlt( dcDst
, tmpGC
, TRUE
);
1305 else fNullBrush
= FALSE
;
1308 for (opcode
= BITBLT_Opcodes
[(rop
>> 16) & 0xff]; *opcode
; opcode
++)
1310 if (OP_DST(*opcode
) == DST
) destUsed
= TRUE
;
1311 XSetFunction( display
, tmpGC
, OP_ROP(*opcode
) );
1312 switch(OP_SRCDST(*opcode
))
1314 case OP_ARGS(DST
,TMP
):
1315 case OP_ARGS(SRC
,TMP
):
1317 pixmaps
[TMP
] = XCreatePixmap( display
, rootWindow
,
1319 dcDst
->w
.bitsPerPixel
);
1321 case OP_ARGS(DST
,SRC
):
1322 case OP_ARGS(SRC
,DST
):
1323 case OP_ARGS(TMP
,SRC
):
1324 case OP_ARGS(TMP
,DST
):
1325 XCopyArea( display
, pixmaps
[OP_SRC(*opcode
)],
1326 pixmaps
[OP_DST(*opcode
)], tmpGC
,
1327 0, 0, width
, height
, 0, 0 );
1330 case OP_ARGS(PAT
,TMP
):
1331 if (!pixmaps
[TMP
] && !fNullBrush
)
1332 pixmaps
[TMP
] = XCreatePixmap( display
, rootWindow
,
1334 dcDst
->w
.bitsPerPixel
);
1336 case OP_ARGS(PAT
,DST
):
1337 case OP_ARGS(PAT
,SRC
):
1339 XFillRectangle( display
, pixmaps
[OP_DST(*opcode
)],
1340 tmpGC
, 0, 0, width
, height
);
1344 XSetFunction( display
, physDevDst
->gc
, GXcopy
);
1345 BITBLT_PutDstArea( dcDst
, pixmaps
[destUsed
? DST
: SRC
],
1346 physDevDst
->gc
, &visRectDst
);
1347 XFreePixmap( display
, pixmaps
[DST
] );
1348 if (pixmaps
[SRC
]) XFreePixmap( display
, pixmaps
[SRC
] );
1349 if (pixmaps
[TMP
]) XFreePixmap( display
, pixmaps
[TMP
] );
1350 XFreeGC( display
, tmpGC
);
1354 struct StretchBlt_params
1369 /***********************************************************************
1370 * BITBLT_DoStretchBlt
1372 * Wrapper function for BITBLT_InternalStretchBlt
1373 * to use with CALL_LARGE_STACK.
1375 static int BITBLT_DoStretchBlt( const struct StretchBlt_params
*p
)
1377 return (int)BITBLT_InternalStretchBlt( p
->dcDst
, p
->xDst
, p
->yDst
,
1378 p
->widthDst
, p
->heightDst
,
1379 p
->dcSrc
, p
->xSrc
, p
->ySrc
,
1380 p
->widthSrc
, p
->heightSrc
, p
->rop
);
1383 /***********************************************************************
1386 BOOL32
X11DRV_PatBlt( DC
*dc
, INT32 left
, INT32 top
,
1387 INT32 width
, INT32 height
, DWORD rop
)
1389 struct StretchBlt_params params
= { dc
, left
, top
, width
, height
,
1390 NULL
, 0, 0, 0, 0, rop
};
1392 DIB_UpdateDIBSection( dc
, FALSE
);
1393 EnterCriticalSection( &X11DRV_CritSection
);
1394 result
= (BOOL32
)CALL_LARGE_STACK( BITBLT_DoStretchBlt
, ¶ms
);
1395 LeaveCriticalSection( &X11DRV_CritSection
);
1396 DIB_UpdateDIBSection( dc
, TRUE
);
1401 /***********************************************************************
1404 BOOL32
X11DRV_BitBlt( DC
*dcDst
, INT32 xDst
, INT32 yDst
,
1405 INT32 width
, INT32 height
, DC
*dcSrc
,
1406 INT32 xSrc
, INT32 ySrc
, DWORD rop
)
1408 struct StretchBlt_params params
= { dcDst
, xDst
, yDst
, width
, height
,
1409 dcSrc
, xSrc
, ySrc
, width
, height
, rop
};
1411 DIB_UpdateDIBSection( dcDst
, FALSE
);
1412 DIB_UpdateDIBSection( dcSrc
, FALSE
);
1413 EnterCriticalSection( &X11DRV_CritSection
);
1414 result
= (BOOL32
)CALL_LARGE_STACK( BITBLT_DoStretchBlt
, ¶ms
);
1415 LeaveCriticalSection( &X11DRV_CritSection
);
1416 DIB_UpdateDIBSection( dcDst
, TRUE
);
1421 /***********************************************************************
1424 BOOL32
X11DRV_StretchBlt( DC
*dcDst
, INT32 xDst
, INT32 yDst
,
1425 INT32 widthDst
, INT32 heightDst
,
1426 DC
*dcSrc
, INT32 xSrc
, INT32 ySrc
,
1427 INT32 widthSrc
, INT32 heightSrc
, DWORD rop
)
1429 struct StretchBlt_params params
= { dcDst
, xDst
, yDst
, widthDst
, heightDst
,
1430 dcSrc
, xSrc
, ySrc
, widthSrc
, heightSrc
,
1433 DIB_UpdateDIBSection( dcDst
, FALSE
);
1434 DIB_UpdateDIBSection( dcSrc
, FALSE
);
1435 EnterCriticalSection( &X11DRV_CritSection
);
1436 result
= (BOOL32
)CALL_LARGE_STACK( BITBLT_DoStretchBlt
, ¶ms
);
1437 LeaveCriticalSection( &X11DRV_CritSection
);
1438 DIB_UpdateDIBSection( dcDst
, TRUE
);