1 |
forsberg |
355 |
/* -*- c-basic-offset: 8 -*- |
2 |
matty |
10 |
rdesktop: A Remote Desktop Protocol client. |
3 |
|
|
RDP order processing |
4 |
stargo |
828 |
Copyright (C) Matthew Chapman 1999-2005 |
5 |
matty |
10 |
|
6 |
|
|
This program is free software; you can redistribute it and/or modify |
7 |
|
|
it under the terms of the GNU General Public License as published by |
8 |
|
|
the Free Software Foundation; either version 2 of the License, or |
9 |
|
|
(at your option) any later version. |
10 |
|
|
|
11 |
|
|
This program is distributed in the hope that it will be useful, |
12 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
GNU General Public License for more details. |
15 |
|
|
|
16 |
|
|
You should have received a copy of the GNU General Public License |
17 |
|
|
along with this program; if not, write to the Free Software |
18 |
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#include "rdesktop.h" |
22 |
|
|
#include "orders.h" |
23 |
|
|
|
24 |
jsorg71 |
438 |
extern uint8 *g_next_packet; |
25 |
jsorg71 |
382 |
static RDP_ORDER_STATE g_order_state; |
26 |
jsorg71 |
438 |
extern BOOL g_use_rdp5; |
27 |
matty |
10 |
|
28 |
|
|
/* Read field indicating which parameters are present */ |
29 |
matty |
25 |
static void |
30 |
astrand |
64 |
rdp_in_present(STREAM s, uint32 * present, uint8 flags, int size) |
31 |
matty |
10 |
{ |
32 |
|
|
uint8 bits; |
33 |
|
|
int i; |
34 |
|
|
|
35 |
|
|
if (flags & RDP_ORDER_SMALL) |
36 |
|
|
{ |
37 |
|
|
size--; |
38 |
|
|
} |
39 |
|
|
|
40 |
|
|
if (flags & RDP_ORDER_TINY) |
41 |
|
|
{ |
42 |
|
|
if (size < 2) |
43 |
|
|
size = 0; |
44 |
|
|
else |
45 |
|
|
size -= 2; |
46 |
|
|
} |
47 |
|
|
|
48 |
|
|
*present = 0; |
49 |
|
|
for (i = 0; i < size; i++) |
50 |
|
|
{ |
51 |
|
|
in_uint8(s, bits); |
52 |
|
|
*present |= bits << (i * 8); |
53 |
|
|
} |
54 |
|
|
} |
55 |
|
|
|
56 |
|
|
/* Read a co-ordinate (16-bit, or 8-bit delta) */ |
57 |
matty |
25 |
static void |
58 |
jsorg71 |
375 |
rdp_in_coord(STREAM s, sint16 * coord, BOOL delta) |
59 |
matty |
10 |
{ |
60 |
matthewc |
299 |
sint8 change; |
61 |
matty |
10 |
|
62 |
|
|
if (delta) |
63 |
|
|
{ |
64 |
|
|
in_uint8(s, change); |
65 |
matthewc |
299 |
*coord += change; |
66 |
matty |
10 |
} |
67 |
|
|
else |
68 |
|
|
{ |
69 |
|
|
in_uint16_le(s, *coord); |
70 |
|
|
} |
71 |
|
|
} |
72 |
|
|
|
73 |
jdmeijer |
831 |
/* Parse a delta co-ordinate in polyline/polygon order form */ |
74 |
|
|
static int |
75 |
|
|
parse_delta(uint8 * buffer, int *offset) |
76 |
|
|
{ |
77 |
|
|
int value = buffer[(*offset)++]; |
78 |
|
|
int two_byte = value & 0x80; |
79 |
|
|
|
80 |
|
|
if (value & 0x40) /* sign bit */ |
81 |
|
|
value |= ~0x3f; |
82 |
|
|
else |
83 |
|
|
value &= 0x3f; |
84 |
|
|
|
85 |
|
|
if (two_byte) |
86 |
|
|
value = (value << 8) | buffer[(*offset)++]; |
87 |
|
|
|
88 |
|
|
return value; |
89 |
|
|
} |
90 |
|
|
|
91 |
matty |
10 |
/* Read a colour entry */ |
92 |
matty |
25 |
static void |
93 |
jsorg71 |
309 |
rdp_in_colour(STREAM s, uint32 * colour) |
94 |
matty |
10 |
{ |
95 |
jsorg71 |
309 |
uint32 i; |
96 |
|
|
in_uint8(s, i); |
97 |
|
|
*colour = i; |
98 |
|
|
in_uint8(s, i); |
99 |
|
|
*colour |= i << 8; |
100 |
|
|
in_uint8(s, i); |
101 |
|
|
*colour |= i << 16; |
102 |
matty |
10 |
} |
103 |
|
|
|
104 |
|
|
/* Parse bounds information */ |
105 |
matty |
25 |
static BOOL |
106 |
astrand |
64 |
rdp_parse_bounds(STREAM s, BOUNDS * bounds) |
107 |
matty |
10 |
{ |
108 |
|
|
uint8 present; |
109 |
|
|
|
110 |
|
|
in_uint8(s, present); |
111 |
|
|
|
112 |
|
|
if (present & 1) |
113 |
|
|
rdp_in_coord(s, &bounds->left, False); |
114 |
|
|
else if (present & 16) |
115 |
|
|
rdp_in_coord(s, &bounds->left, True); |
116 |
|
|
|
117 |
|
|
if (present & 2) |
118 |
|
|
rdp_in_coord(s, &bounds->top, False); |
119 |
|
|
else if (present & 32) |
120 |
|
|
rdp_in_coord(s, &bounds->top, True); |
121 |
|
|
|
122 |
|
|
if (present & 4) |
123 |
|
|
rdp_in_coord(s, &bounds->right, False); |
124 |
|
|
else if (present & 64) |
125 |
|
|
rdp_in_coord(s, &bounds->right, True); |
126 |
|
|
|
127 |
|
|
if (present & 8) |
128 |
|
|
rdp_in_coord(s, &bounds->bottom, False); |
129 |
|
|
else if (present & 128) |
130 |
|
|
rdp_in_coord(s, &bounds->bottom, True); |
131 |
|
|
|
132 |
|
|
return s_check(s); |
133 |
|
|
} |
134 |
|
|
|
135 |
|
|
/* Parse a pen */ |
136 |
matty |
25 |
static BOOL |
137 |
astrand |
64 |
rdp_parse_pen(STREAM s, PEN * pen, uint32 present) |
138 |
matty |
10 |
{ |
139 |
|
|
if (present & 1) |
140 |
|
|
in_uint8(s, pen->style); |
141 |
|
|
|
142 |
|
|
if (present & 2) |
143 |
|
|
in_uint8(s, pen->width); |
144 |
|
|
|
145 |
|
|
if (present & 4) |
146 |
|
|
rdp_in_colour(s, &pen->colour); |
147 |
|
|
|
148 |
|
|
return s_check(s); |
149 |
|
|
} |
150 |
|
|
|
151 |
|
|
/* Parse a brush */ |
152 |
matty |
25 |
static BOOL |
153 |
astrand |
64 |
rdp_parse_brush(STREAM s, BRUSH * brush, uint32 present) |
154 |
matty |
10 |
{ |
155 |
|
|
if (present & 1) |
156 |
|
|
in_uint8(s, brush->xorigin); |
157 |
|
|
|
158 |
|
|
if (present & 2) |
159 |
|
|
in_uint8(s, brush->yorigin); |
160 |
|
|
|
161 |
|
|
if (present & 4) |
162 |
|
|
in_uint8(s, brush->style); |
163 |
|
|
|
164 |
|
|
if (present & 8) |
165 |
|
|
in_uint8(s, brush->pattern[0]); |
166 |
|
|
|
167 |
|
|
if (present & 16) |
168 |
|
|
in_uint8a(s, &brush->pattern[1], 7); |
169 |
|
|
|
170 |
|
|
return s_check(s); |
171 |
|
|
} |
172 |
|
|
|
173 |
|
|
/* Process a destination blt order */ |
174 |
matty |
25 |
static void |
175 |
astrand |
64 |
process_destblt(STREAM s, DESTBLT_ORDER * os, uint32 present, BOOL delta) |
176 |
matty |
10 |
{ |
177 |
|
|
if (present & 0x01) |
178 |
|
|
rdp_in_coord(s, &os->x, delta); |
179 |
|
|
|
180 |
|
|
if (present & 0x02) |
181 |
|
|
rdp_in_coord(s, &os->y, delta); |
182 |
|
|
|
183 |
|
|
if (present & 0x04) |
184 |
|
|
rdp_in_coord(s, &os->cx, delta); |
185 |
|
|
|
186 |
|
|
if (present & 0x08) |
187 |
|
|
rdp_in_coord(s, &os->cy, delta); |
188 |
|
|
|
189 |
|
|
if (present & 0x10) |
190 |
|
|
in_uint8(s, os->opcode); |
191 |
|
|
|
192 |
matty |
30 |
DEBUG(("DESTBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d)\n", |
193 |
|
|
os->opcode, os->x, os->y, os->cx, os->cy)); |
194 |
matty |
10 |
|
195 |
|
|
ui_destblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy); |
196 |
|
|
} |
197 |
|
|
|
198 |
|
|
/* Process a pattern blt order */ |
199 |
matty |
25 |
static void |
200 |
astrand |
64 |
process_patblt(STREAM s, PATBLT_ORDER * os, uint32 present, BOOL delta) |
201 |
matty |
10 |
{ |
202 |
|
|
if (present & 0x0001) |
203 |
|
|
rdp_in_coord(s, &os->x, delta); |
204 |
|
|
|
205 |
|
|
if (present & 0x0002) |
206 |
|
|
rdp_in_coord(s, &os->y, delta); |
207 |
|
|
|
208 |
|
|
if (present & 0x0004) |
209 |
|
|
rdp_in_coord(s, &os->cx, delta); |
210 |
|
|
|
211 |
|
|
if (present & 0x0008) |
212 |
|
|
rdp_in_coord(s, &os->cy, delta); |
213 |
|
|
|
214 |
|
|
if (present & 0x0010) |
215 |
|
|
in_uint8(s, os->opcode); |
216 |
|
|
|
217 |
|
|
if (present & 0x0020) |
218 |
|
|
rdp_in_colour(s, &os->bgcolour); |
219 |
|
|
|
220 |
|
|
if (present & 0x0040) |
221 |
|
|
rdp_in_colour(s, &os->fgcolour); |
222 |
|
|
|
223 |
|
|
rdp_parse_brush(s, &os->brush, present >> 7); |
224 |
|
|
|
225 |
astrand |
82 |
DEBUG(("PATBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,bs=%d,bg=0x%x,fg=0x%x)\n", os->opcode, os->x, |
226 |
|
|
os->y, os->cx, os->cy, os->brush.style, os->bgcolour, os->fgcolour)); |
227 |
matty |
10 |
|
228 |
|
|
ui_patblt(ROP2_P(os->opcode), os->x, os->y, os->cx, os->cy, |
229 |
matty |
24 |
&os->brush, os->bgcolour, os->fgcolour); |
230 |
matty |
10 |
} |
231 |
|
|
|
232 |
|
|
/* Process a screen blt order */ |
233 |
matty |
25 |
static void |
234 |
astrand |
64 |
process_screenblt(STREAM s, SCREENBLT_ORDER * os, uint32 present, BOOL delta) |
235 |
matty |
10 |
{ |
236 |
|
|
if (present & 0x0001) |
237 |
|
|
rdp_in_coord(s, &os->x, delta); |
238 |
|
|
|
239 |
|
|
if (present & 0x0002) |
240 |
|
|
rdp_in_coord(s, &os->y, delta); |
241 |
|
|
|
242 |
|
|
if (present & 0x0004) |
243 |
|
|
rdp_in_coord(s, &os->cx, delta); |
244 |
|
|
|
245 |
|
|
if (present & 0x0008) |
246 |
|
|
rdp_in_coord(s, &os->cy, delta); |
247 |
|
|
|
248 |
|
|
if (present & 0x0010) |
249 |
|
|
in_uint8(s, os->opcode); |
250 |
|
|
|
251 |
|
|
if (present & 0x0020) |
252 |
|
|
rdp_in_coord(s, &os->srcx, delta); |
253 |
|
|
|
254 |
|
|
if (present & 0x0040) |
255 |
|
|
rdp_in_coord(s, &os->srcy, delta); |
256 |
|
|
|
257 |
matty |
30 |
DEBUG(("SCREENBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,srcx=%d,srcy=%d)\n", |
258 |
|
|
os->opcode, os->x, os->y, os->cx, os->cy, os->srcx, os->srcy)); |
259 |
matty |
10 |
|
260 |
astrand |
82 |
ui_screenblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy, os->srcx, os->srcy); |
261 |
matty |
10 |
} |
262 |
|
|
|
263 |
|
|
/* Process a line order */ |
264 |
matty |
25 |
static void |
265 |
astrand |
64 |
process_line(STREAM s, LINE_ORDER * os, uint32 present, BOOL delta) |
266 |
matty |
10 |
{ |
267 |
|
|
if (present & 0x0001) |
268 |
|
|
in_uint16_le(s, os->mixmode); |
269 |
|
|
|
270 |
|
|
if (present & 0x0002) |
271 |
|
|
rdp_in_coord(s, &os->startx, delta); |
272 |
|
|
|
273 |
|
|
if (present & 0x0004) |
274 |
|
|
rdp_in_coord(s, &os->starty, delta); |
275 |
|
|
|
276 |
|
|
if (present & 0x0008) |
277 |
|
|
rdp_in_coord(s, &os->endx, delta); |
278 |
|
|
|
279 |
|
|
if (present & 0x0010) |
280 |
|
|
rdp_in_coord(s, &os->endy, delta); |
281 |
|
|
|
282 |
|
|
if (present & 0x0020) |
283 |
|
|
rdp_in_colour(s, &os->bgcolour); |
284 |
|
|
|
285 |
|
|
if (present & 0x0040) |
286 |
|
|
in_uint8(s, os->opcode); |
287 |
|
|
|
288 |
|
|
rdp_parse_pen(s, &os->pen, present >> 7); |
289 |
|
|
|
290 |
jsorg71 |
732 |
DEBUG(("LINE(op=0x%x,sx=%d,sy=%d,dx=%d,dy=%d,fg=0x%x)\n", |
291 |
astrand |
82 |
os->opcode, os->startx, os->starty, os->endx, os->endy, os->pen.colour)); |
292 |
matty |
10 |
|
293 |
|
|
if (os->opcode < 0x01 || os->opcode > 0x10) |
294 |
|
|
{ |
295 |
matty |
30 |
error("bad ROP2 0x%x\n", os->opcode); |
296 |
matty |
10 |
return; |
297 |
|
|
} |
298 |
|
|
|
299 |
astrand |
82 |
ui_line(os->opcode - 1, os->startx, os->starty, os->endx, os->endy, &os->pen); |
300 |
matty |
10 |
} |
301 |
|
|
|
302 |
|
|
/* Process an opaque rectangle order */ |
303 |
matty |
25 |
static void |
304 |
astrand |
64 |
process_rect(STREAM s, RECT_ORDER * os, uint32 present, BOOL delta) |
305 |
matty |
10 |
{ |
306 |
jsorg71 |
309 |
uint32 i; |
307 |
matty |
10 |
if (present & 0x01) |
308 |
|
|
rdp_in_coord(s, &os->x, delta); |
309 |
|
|
|
310 |
|
|
if (present & 0x02) |
311 |
|
|
rdp_in_coord(s, &os->y, delta); |
312 |
|
|
|
313 |
|
|
if (present & 0x04) |
314 |
|
|
rdp_in_coord(s, &os->cx, delta); |
315 |
|
|
|
316 |
|
|
if (present & 0x08) |
317 |
|
|
rdp_in_coord(s, &os->cy, delta); |
318 |
|
|
|
319 |
|
|
if (present & 0x10) |
320 |
jsorg71 |
309 |
{ |
321 |
|
|
in_uint8(s, i); |
322 |
|
|
os->colour = (os->colour & 0xffffff00) | i; |
323 |
|
|
} |
324 |
matty |
10 |
|
325 |
jsorg71 |
309 |
if (present & 0x20) |
326 |
|
|
{ |
327 |
|
|
in_uint8(s, i); |
328 |
|
|
os->colour = (os->colour & 0xffff00ff) | (i << 8); |
329 |
|
|
} |
330 |
|
|
|
331 |
|
|
if (present & 0x40) |
332 |
|
|
{ |
333 |
|
|
in_uint8(s, i); |
334 |
|
|
os->colour = (os->colour & 0xff00ffff) | (i << 16); |
335 |
|
|
} |
336 |
|
|
|
337 |
astrand |
82 |
DEBUG(("RECT(x=%d,y=%d,cx=%d,cy=%d,fg=0x%x)\n", os->x, os->y, os->cx, os->cy, os->colour)); |
338 |
matty |
10 |
|
339 |
|
|
ui_rect(os->x, os->y, os->cx, os->cy, os->colour); |
340 |
|
|
} |
341 |
|
|
|
342 |
|
|
/* Process a desktop save order */ |
343 |
matty |
25 |
static void |
344 |
astrand |
64 |
process_desksave(STREAM s, DESKSAVE_ORDER * os, uint32 present, BOOL delta) |
345 |
matty |
10 |
{ |
346 |
|
|
int width, height; |
347 |
|
|
|
348 |
|
|
if (present & 0x01) |
349 |
|
|
in_uint32_le(s, os->offset); |
350 |
|
|
|
351 |
|
|
if (present & 0x02) |
352 |
|
|
rdp_in_coord(s, &os->left, delta); |
353 |
|
|
|
354 |
|
|
if (present & 0x04) |
355 |
|
|
rdp_in_coord(s, &os->top, delta); |
356 |
|
|
|
357 |
|
|
if (present & 0x08) |
358 |
|
|
rdp_in_coord(s, &os->right, delta); |
359 |
|
|
|
360 |
|
|
if (present & 0x10) |
361 |
|
|
rdp_in_coord(s, &os->bottom, delta); |
362 |
|
|
|
363 |
|
|
if (present & 0x20) |
364 |
|
|
in_uint8(s, os->action); |
365 |
|
|
|
366 |
matty |
30 |
DEBUG(("DESKSAVE(l=%d,t=%d,r=%d,b=%d,off=%d,op=%d)\n", |
367 |
astrand |
82 |
os->left, os->top, os->right, os->bottom, os->offset, os->action)); |
368 |
matty |
10 |
|
369 |
|
|
width = os->right - os->left + 1; |
370 |
|
|
height = os->bottom - os->top + 1; |
371 |
|
|
|
372 |
|
|
if (os->action == 0) |
373 |
|
|
ui_desktop_save(os->offset, os->left, os->top, width, height); |
374 |
|
|
else |
375 |
astrand |
82 |
ui_desktop_restore(os->offset, os->left, os->top, width, height); |
376 |
matty |
10 |
} |
377 |
|
|
|
378 |
|
|
/* Process a memory blt order */ |
379 |
matty |
25 |
static void |
380 |
astrand |
64 |
process_memblt(STREAM s, MEMBLT_ORDER * os, uint32 present, BOOL delta) |
381 |
matty |
10 |
{ |
382 |
|
|
HBITMAP bitmap; |
383 |
|
|
|
384 |
|
|
if (present & 0x0001) |
385 |
|
|
{ |
386 |
|
|
in_uint8(s, os->cache_id); |
387 |
|
|
in_uint8(s, os->colour_table); |
388 |
|
|
} |
389 |
|
|
|
390 |
|
|
if (present & 0x0002) |
391 |
|
|
rdp_in_coord(s, &os->x, delta); |
392 |
|
|
|
393 |
|
|
if (present & 0x0004) |
394 |
|
|
rdp_in_coord(s, &os->y, delta); |
395 |
|
|
|
396 |
|
|
if (present & 0x0008) |
397 |
|
|
rdp_in_coord(s, &os->cx, delta); |
398 |
|
|
|
399 |
|
|
if (present & 0x0010) |
400 |
|
|
rdp_in_coord(s, &os->cy, delta); |
401 |
|
|
|
402 |
|
|
if (present & 0x0020) |
403 |
|
|
in_uint8(s, os->opcode); |
404 |
|
|
|
405 |
|
|
if (present & 0x0040) |
406 |
|
|
rdp_in_coord(s, &os->srcx, delta); |
407 |
|
|
|
408 |
|
|
if (present & 0x0080) |
409 |
|
|
rdp_in_coord(s, &os->srcy, delta); |
410 |
|
|
|
411 |
|
|
if (present & 0x0100) |
412 |
|
|
in_uint16_le(s, os->cache_idx); |
413 |
|
|
|
414 |
matty |
30 |
DEBUG(("MEMBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,id=%d,idx=%d)\n", |
415 |
astrand |
82 |
os->opcode, os->x, os->y, os->cx, os->cy, os->cache_id, os->cache_idx)); |
416 |
matty |
10 |
|
417 |
|
|
bitmap = cache_get_bitmap(os->cache_id, os->cache_idx); |
418 |
|
|
if (bitmap == NULL) |
419 |
|
|
return; |
420 |
|
|
|
421 |
astrand |
82 |
ui_memblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy, bitmap, os->srcx, os->srcy); |
422 |
matty |
10 |
} |
423 |
|
|
|
424 |
|
|
/* Process a 3-way blt order */ |
425 |
matty |
25 |
static void |
426 |
astrand |
64 |
process_triblt(STREAM s, TRIBLT_ORDER * os, uint32 present, BOOL delta) |
427 |
matty |
10 |
{ |
428 |
|
|
HBITMAP bitmap; |
429 |
|
|
|
430 |
|
|
if (present & 0x000001) |
431 |
|
|
{ |
432 |
|
|
in_uint8(s, os->cache_id); |
433 |
|
|
in_uint8(s, os->colour_table); |
434 |
|
|
} |
435 |
|
|
|
436 |
|
|
if (present & 0x000002) |
437 |
|
|
rdp_in_coord(s, &os->x, delta); |
438 |
|
|
|
439 |
|
|
if (present & 0x000004) |
440 |
|
|
rdp_in_coord(s, &os->y, delta); |
441 |
|
|
|
442 |
|
|
if (present & 0x000008) |
443 |
|
|
rdp_in_coord(s, &os->cx, delta); |
444 |
|
|
|
445 |
|
|
if (present & 0x000010) |
446 |
|
|
rdp_in_coord(s, &os->cy, delta); |
447 |
|
|
|
448 |
|
|
if (present & 0x000020) |
449 |
|
|
in_uint8(s, os->opcode); |
450 |
|
|
|
451 |
|
|
if (present & 0x000040) |
452 |
|
|
rdp_in_coord(s, &os->srcx, delta); |
453 |
|
|
|
454 |
|
|
if (present & 0x000080) |
455 |
|
|
rdp_in_coord(s, &os->srcy, delta); |
456 |
|
|
|
457 |
|
|
if (present & 0x000100) |
458 |
|
|
rdp_in_colour(s, &os->bgcolour); |
459 |
|
|
|
460 |
|
|
if (present & 0x000200) |
461 |
|
|
rdp_in_colour(s, &os->fgcolour); |
462 |
|
|
|
463 |
|
|
rdp_parse_brush(s, &os->brush, present >> 10); |
464 |
|
|
|
465 |
|
|
if (present & 0x008000) |
466 |
|
|
in_uint16_le(s, os->cache_idx); |
467 |
|
|
|
468 |
|
|
if (present & 0x010000) |
469 |
|
|
in_uint16_le(s, os->unknown); |
470 |
|
|
|
471 |
astrand |
82 |
DEBUG(("TRIBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,id=%d,idx=%d,bs=%d,bg=0x%x,fg=0x%x)\n", |
472 |
|
|
os->opcode, os->x, os->y, os->cx, os->cy, os->cache_id, os->cache_idx, |
473 |
|
|
os->brush.style, os->bgcolour, os->fgcolour)); |
474 |
matty |
10 |
|
475 |
|
|
bitmap = cache_get_bitmap(os->cache_id, os->cache_idx); |
476 |
|
|
if (bitmap == NULL) |
477 |
|
|
return; |
478 |
|
|
|
479 |
|
|
ui_triblt(os->opcode, os->x, os->y, os->cx, os->cy, |
480 |
astrand |
82 |
bitmap, os->srcx, os->srcy, &os->brush, os->bgcolour, os->fgcolour); |
481 |
matty |
10 |
} |
482 |
|
|
|
483 |
jdmeijer |
831 |
/* Process a polygon order */ |
484 |
|
|
static void |
485 |
|
|
process_polygon(STREAM s, POLYGON_ORDER * os, uint32 present, BOOL delta) |
486 |
matty |
15 |
{ |
487 |
jdmeijer |
831 |
int index, data, next; |
488 |
|
|
uint8 flags = 0; |
489 |
|
|
POINT *points; |
490 |
matty |
15 |
|
491 |
jdmeijer |
831 |
if (present & 0x01) |
492 |
|
|
rdp_in_coord(s, &os->x, delta); |
493 |
|
|
|
494 |
|
|
if (present & 0x02) |
495 |
|
|
rdp_in_coord(s, &os->y, delta); |
496 |
|
|
|
497 |
|
|
if (present & 0x04) |
498 |
|
|
in_uint8(s, os->opcode); |
499 |
|
|
|
500 |
|
|
if (present & 0x08) |
501 |
|
|
in_uint8(s, os->fillmode); |
502 |
|
|
|
503 |
|
|
if (present & 0x10) |
504 |
|
|
rdp_in_colour(s, &os->fgcolour); |
505 |
|
|
|
506 |
|
|
if (present & 0x20) |
507 |
|
|
in_uint8(s, os->npoints); |
508 |
|
|
|
509 |
|
|
if (present & 0x40) |
510 |
|
|
{ |
511 |
|
|
in_uint8(s, os->datasize); |
512 |
|
|
in_uint8a(s, os->data, os->datasize); |
513 |
|
|
} |
514 |
|
|
|
515 |
|
|
DEBUG(("POLYGON(x=%d,y=%d,op=0x%x,fm=%d,fg=0x%x,n=%d,sz=%d)\n", |
516 |
|
|
os->x, os->y, os->opcode, os->fillmode, os->fgcolour, os->npoints, os->datasize)); |
517 |
|
|
|
518 |
|
|
DEBUG(("Data: ")); |
519 |
|
|
|
520 |
|
|
for (index = 0; index < os->datasize; index++) |
521 |
|
|
DEBUG(("%02x ", os->data[index])); |
522 |
|
|
|
523 |
|
|
DEBUG(("\n")); |
524 |
|
|
|
525 |
|
|
if (os->opcode < 0x01 || os->opcode > 0x10) |
526 |
|
|
{ |
527 |
|
|
error("bad ROP2 0x%x\n", os->opcode); |
528 |
|
|
return; |
529 |
|
|
} |
530 |
|
|
|
531 |
|
|
points = (POINT *) xmalloc((os->npoints + 1) * sizeof(POINT)); |
532 |
|
|
memset(points, 0, (os->npoints + 1) * sizeof(POINT)); |
533 |
|
|
|
534 |
|
|
points[0].x = os->x; |
535 |
|
|
points[0].y = os->y; |
536 |
|
|
|
537 |
|
|
index = 0; |
538 |
|
|
data = ((os->npoints - 1) / 4) + 1; |
539 |
|
|
for (next = 1; (next <= os->npoints) && (next < 256) && (data < os->datasize); next++) |
540 |
|
|
{ |
541 |
|
|
if ((next - 1) % 4 == 0) |
542 |
|
|
flags = os->data[index++]; |
543 |
|
|
|
544 |
|
|
if (~flags & 0x80) |
545 |
|
|
points[next].x = parse_delta(os->data, &data); |
546 |
|
|
|
547 |
|
|
if (~flags & 0x40) |
548 |
|
|
points[next].y = parse_delta(os->data, &data); |
549 |
|
|
|
550 |
|
|
flags <<= 2; |
551 |
|
|
} |
552 |
|
|
|
553 |
|
|
if (next - 1 == os->npoints) |
554 |
|
|
ui_polygon(os->opcode - 1, os->fillmode, points, os->npoints + 1, NULL, 0, |
555 |
|
|
os->fgcolour); |
556 |
matty |
15 |
else |
557 |
jdmeijer |
831 |
error("polygon parse error\n"); |
558 |
matty |
15 |
|
559 |
jdmeijer |
831 |
xfree(points); |
560 |
|
|
} |
561 |
matty |
15 |
|
562 |
jdmeijer |
831 |
/* Process a polygon2 order */ |
563 |
|
|
static void |
564 |
|
|
process_polygon2(STREAM s, POLYGON2_ORDER * os, uint32 present, BOOL delta) |
565 |
|
|
{ |
566 |
|
|
int index, data, next; |
567 |
|
|
uint8 flags = 0; |
568 |
|
|
POINT *points; |
569 |
|
|
|
570 |
|
|
if (present & 0x0001) |
571 |
|
|
rdp_in_coord(s, &os->x, delta); |
572 |
|
|
|
573 |
|
|
if (present & 0x0002) |
574 |
|
|
rdp_in_coord(s, &os->y, delta); |
575 |
|
|
|
576 |
|
|
if (present & 0x0004) |
577 |
|
|
in_uint8(s, os->opcode); |
578 |
|
|
|
579 |
|
|
if (present & 0x0008) |
580 |
|
|
in_uint8(s, os->fillmode); |
581 |
|
|
|
582 |
|
|
if (present & 0x0010) |
583 |
|
|
rdp_in_colour(s, &os->bgcolour); |
584 |
|
|
|
585 |
|
|
if (present & 0x0020) |
586 |
|
|
rdp_in_colour(s, &os->fgcolour); |
587 |
|
|
|
588 |
|
|
rdp_parse_brush(s, &os->brush, present >> 6); |
589 |
|
|
|
590 |
|
|
if (present & 0x0800) |
591 |
|
|
in_uint8(s, os->npoints); |
592 |
|
|
|
593 |
|
|
if (present & 0x1000) |
594 |
|
|
{ |
595 |
|
|
in_uint8(s, os->datasize); |
596 |
|
|
in_uint8a(s, os->data, os->datasize); |
597 |
|
|
} |
598 |
|
|
|
599 |
|
|
DEBUG(("POLYGON2(x=%d,y=%d,op=0x%x,fm=%d,bs=%d,bg=0x%x,fg=0x%x,n=%d,sz=%d)\n", |
600 |
|
|
os->x, os->y, os->opcode, os->fillmode, os->brush.style, os->bgcolour, os->fgcolour, |
601 |
|
|
os->npoints, os->datasize)); |
602 |
|
|
|
603 |
|
|
DEBUG(("Data: ")); |
604 |
|
|
|
605 |
|
|
for (index = 0; index < os->datasize; index++) |
606 |
|
|
DEBUG(("%02x ", os->data[index])); |
607 |
|
|
|
608 |
|
|
DEBUG(("\n")); |
609 |
|
|
|
610 |
|
|
if (os->opcode < 0x01 || os->opcode > 0x10) |
611 |
|
|
{ |
612 |
|
|
error("bad ROP2 0x%x\n", os->opcode); |
613 |
|
|
return; |
614 |
|
|
} |
615 |
|
|
|
616 |
|
|
points = (POINT *) xmalloc((os->npoints + 1) * sizeof(POINT)); |
617 |
|
|
memset(points, 0, (os->npoints + 1) * sizeof(POINT)); |
618 |
|
|
|
619 |
|
|
points[0].x = os->x; |
620 |
|
|
points[0].y = os->y; |
621 |
|
|
|
622 |
|
|
index = 0; |
623 |
|
|
data = ((os->npoints - 1) / 4) + 1; |
624 |
|
|
for (next = 1; (next <= os->npoints) && (next < 256) && (data < os->datasize); next++) |
625 |
|
|
{ |
626 |
|
|
if ((next - 1) % 4 == 0) |
627 |
|
|
flags = os->data[index++]; |
628 |
|
|
|
629 |
|
|
if (~flags & 0x80) |
630 |
|
|
points[next].x = parse_delta(os->data, &data); |
631 |
|
|
|
632 |
|
|
if (~flags & 0x40) |
633 |
|
|
points[next].y = parse_delta(os->data, &data); |
634 |
|
|
|
635 |
|
|
flags <<= 2; |
636 |
|
|
} |
637 |
|
|
|
638 |
|
|
if (next - 1 == os->npoints) |
639 |
|
|
ui_polygon(os->opcode - 1, os->fillmode, points, os->npoints + 1, |
640 |
|
|
&os->brush, os->bgcolour, os->fgcolour); |
641 |
|
|
else |
642 |
|
|
error("polygon2 parse error\n"); |
643 |
|
|
|
644 |
|
|
xfree(points); |
645 |
matty |
15 |
} |
646 |
|
|
|
647 |
|
|
/* Process a polyline order */ |
648 |
matty |
25 |
static void |
649 |
astrand |
64 |
process_polyline(STREAM s, POLYLINE_ORDER * os, uint32 present, BOOL delta) |
650 |
matty |
15 |
{ |
651 |
|
|
int index, line, data; |
652 |
|
|
int x, y, xfrom, yfrom; |
653 |
|
|
uint8 flags = 0; |
654 |
|
|
PEN pen; |
655 |
jsorg71 |
55 |
uint8 opcode; |
656 |
matty |
15 |
|
657 |
|
|
if (present & 0x01) |
658 |
|
|
rdp_in_coord(s, &os->x, delta); |
659 |
|
|
|
660 |
|
|
if (present & 0x02) |
661 |
|
|
rdp_in_coord(s, &os->y, delta); |
662 |
|
|
|
663 |
|
|
if (present & 0x04) |
664 |
matthewc |
168 |
in_uint8(s, os->opcode); |
665 |
matty |
15 |
|
666 |
|
|
if (present & 0x10) |
667 |
|
|
rdp_in_colour(s, &os->fgcolour); |
668 |
|
|
|
669 |
|
|
if (present & 0x20) |
670 |
|
|
in_uint8(s, os->lines); |
671 |
|
|
|
672 |
|
|
if (present & 0x40) |
673 |
|
|
{ |
674 |
|
|
in_uint8(s, os->datasize); |
675 |
|
|
in_uint8a(s, os->data, os->datasize); |
676 |
|
|
} |
677 |
|
|
|
678 |
matthewc |
168 |
DEBUG(("POLYLINE(x=%d,y=%d,op=0x%x,fg=0x%x,n=%d,sz=%d)\n", |
679 |
|
|
os->x, os->y, os->opcode, os->fgcolour, os->lines, os->datasize)); |
680 |
matty |
15 |
|
681 |
matty |
30 |
DEBUG(("Data: ")); |
682 |
matty |
15 |
|
683 |
|
|
for (index = 0; index < os->datasize; index++) |
684 |
matty |
30 |
DEBUG(("%02x ", os->data[index])); |
685 |
matty |
15 |
|
686 |
matty |
30 |
DEBUG(("\n")); |
687 |
matty |
15 |
|
688 |
matthewc |
168 |
if (os->opcode < 0x01 || os->opcode > 0x10) |
689 |
|
|
{ |
690 |
|
|
error("bad ROP2 0x%x\n", os->opcode); |
691 |
|
|
return; |
692 |
|
|
} |
693 |
|
|
|
694 |
|
|
opcode = os->opcode - 1; |
695 |
matty |
15 |
x = os->x; |
696 |
|
|
y = os->y; |
697 |
|
|
pen.style = pen.width = 0; |
698 |
|
|
pen.colour = os->fgcolour; |
699 |
|
|
|
700 |
|
|
index = 0; |
701 |
|
|
data = ((os->lines - 1) / 4) + 1; |
702 |
|
|
for (line = 0; (line < os->lines) && (data < os->datasize); line++) |
703 |
|
|
{ |
704 |
|
|
xfrom = x; |
705 |
|
|
yfrom = y; |
706 |
|
|
|
707 |
|
|
if (line % 4 == 0) |
708 |
|
|
flags = os->data[index++]; |
709 |
|
|
|
710 |
|
|
if ((flags & 0xc0) == 0) |
711 |
matty |
24 |
flags |= 0xc0; /* none = both */ |
712 |
matty |
15 |
|
713 |
|
|
if (flags & 0x40) |
714 |
|
|
x += parse_delta(os->data, &data); |
715 |
|
|
|
716 |
|
|
if (flags & 0x80) |
717 |
|
|
y += parse_delta(os->data, &data); |
718 |
|
|
|
719 |
jsorg71 |
55 |
ui_line(opcode, xfrom, yfrom, x, y, &pen); |
720 |
matty |
15 |
|
721 |
|
|
flags <<= 2; |
722 |
|
|
} |
723 |
|
|
} |
724 |
|
|
|
725 |
jdmeijer |
831 |
/* Process an ellipse order */ |
726 |
|
|
static void |
727 |
|
|
process_ellipse(STREAM s, ELLIPSE_ORDER * os, uint32 present, BOOL delta) |
728 |
|
|
{ |
729 |
|
|
if (present & 0x01) |
730 |
|
|
rdp_in_coord(s, &os->left, delta); |
731 |
|
|
|
732 |
|
|
if (present & 0x02) |
733 |
|
|
rdp_in_coord(s, &os->top, delta); |
734 |
|
|
|
735 |
|
|
if (present & 0x04) |
736 |
|
|
rdp_in_coord(s, &os->right, delta); |
737 |
|
|
|
738 |
|
|
if (present & 0x08) |
739 |
|
|
rdp_in_coord(s, &os->bottom, delta); |
740 |
|
|
|
741 |
|
|
if (present & 0x10) |
742 |
|
|
in_uint8(s, os->opcode); |
743 |
|
|
|
744 |
|
|
if (present & 0x20) |
745 |
|
|
in_uint8(s, os->fillmode); |
746 |
|
|
|
747 |
|
|
if (present & 0x40) |
748 |
|
|
rdp_in_colour(s, &os->fgcolour); |
749 |
|
|
|
750 |
|
|
DEBUG(("ELLIPSE(l=%d,t=%d,r=%d,b=%d,op=0x%x,fm=%d,fg=0x%x)\n", os->left, os->top, |
751 |
|
|
os->right, os->bottom, os->opcode, os->fillmode, os->fgcolour)); |
752 |
|
|
|
753 |
|
|
ui_ellipse(os->opcode - 1, os->fillmode, os->left, os->top, os->right - os->left, |
754 |
|
|
os->bottom - os->top, NULL, 0, os->fgcolour); |
755 |
|
|
} |
756 |
|
|
|
757 |
|
|
/* Process an ellipse2 order */ |
758 |
|
|
static void |
759 |
|
|
process_ellipse2(STREAM s, ELLIPSE2_ORDER * os, uint32 present, BOOL delta) |
760 |
|
|
{ |
761 |
|
|
if (present & 0x0001) |
762 |
|
|
rdp_in_coord(s, &os->left, delta); |
763 |
|
|
|
764 |
|
|
if (present & 0x0002) |
765 |
|
|
rdp_in_coord(s, &os->top, delta); |
766 |
|
|
|
767 |
|
|
if (present & 0x0004) |
768 |
|
|
rdp_in_coord(s, &os->right, delta); |
769 |
|
|
|
770 |
|
|
if (present & 0x0008) |
771 |
|
|
rdp_in_coord(s, &os->bottom, delta); |
772 |
|
|
|
773 |
|
|
if (present & 0x0010) |
774 |
|
|
in_uint8(s, os->opcode); |
775 |
|
|
|
776 |
|
|
if (present & 0x0020) |
777 |
|
|
in_uint8(s, os->fillmode); |
778 |
|
|
|
779 |
|
|
if (present & 0x0040) |
780 |
|
|
rdp_in_colour(s, &os->bgcolour); |
781 |
|
|
|
782 |
|
|
if (present & 0x0080) |
783 |
|
|
rdp_in_colour(s, &os->fgcolour); |
784 |
|
|
|
785 |
|
|
rdp_parse_brush(s, &os->brush, present >> 8); |
786 |
|
|
|
787 |
|
|
DEBUG(("ELLIPSE2(l=%d,t=%d,r=%d,b=%d,op=0x%x,fm=%d,bs=%d,bg=0x%x,fg=0x%x)\n", |
788 |
|
|
os->left, os->top, os->right, os->bottom, os->opcode, os->fillmode, os->brush.style, |
789 |
|
|
os->bgcolour, os->fgcolour)); |
790 |
|
|
|
791 |
|
|
ui_ellipse(os->opcode - 1, os->fillmode, os->left, os->top, os->right - os->left, |
792 |
|
|
os->bottom - os->top, &os->brush, os->bgcolour, os->fgcolour); |
793 |
|
|
} |
794 |
|
|
|
795 |
matty |
10 |
/* Process a text order */ |
796 |
matty |
25 |
static void |
797 |
astrand |
64 |
process_text2(STREAM s, TEXT2_ORDER * os, uint32 present, BOOL delta) |
798 |
matty |
10 |
{ |
799 |
|
|
int i; |
800 |
|
|
|
801 |
|
|
if (present & 0x000001) |
802 |
|
|
in_uint8(s, os->font); |
803 |
|
|
|
804 |
|
|
if (present & 0x000002) |
805 |
|
|
in_uint8(s, os->flags); |
806 |
|
|
|
807 |
|
|
if (present & 0x000004) |
808 |
|
|
in_uint8(s, os->unknown); |
809 |
|
|
|
810 |
|
|
if (present & 0x000008) |
811 |
|
|
in_uint8(s, os->mixmode); |
812 |
|
|
|
813 |
|
|
if (present & 0x000010) |
814 |
|
|
rdp_in_colour(s, &os->fgcolour); |
815 |
|
|
|
816 |
|
|
if (present & 0x000020) |
817 |
|
|
rdp_in_colour(s, &os->bgcolour); |
818 |
|
|
|
819 |
|
|
if (present & 0x000040) |
820 |
|
|
in_uint16_le(s, os->clipleft); |
821 |
|
|
|
822 |
|
|
if (present & 0x000080) |
823 |
|
|
in_uint16_le(s, os->cliptop); |
824 |
|
|
|
825 |
|
|
if (present & 0x000100) |
826 |
|
|
in_uint16_le(s, os->clipright); |
827 |
|
|
|
828 |
|
|
if (present & 0x000200) |
829 |
|
|
in_uint16_le(s, os->clipbottom); |
830 |
|
|
|
831 |
|
|
if (present & 0x000400) |
832 |
|
|
in_uint16_le(s, os->boxleft); |
833 |
|
|
|
834 |
|
|
if (present & 0x000800) |
835 |
|
|
in_uint16_le(s, os->boxtop); |
836 |
|
|
|
837 |
|
|
if (present & 0x001000) |
838 |
|
|
in_uint16_le(s, os->boxright); |
839 |
|
|
|
840 |
|
|
if (present & 0x002000) |
841 |
|
|
in_uint16_le(s, os->boxbottom); |
842 |
|
|
|
843 |
jdmeijer |
813 |
/* |
844 |
|
|
* Unknown members, seen when connecting to a session that was disconnected with |
845 |
|
|
* mstsc and with wintach's spreadsheet test. |
846 |
|
|
*/ |
847 |
|
|
if (present & 0x004000) |
848 |
|
|
in_uint8s(s, 1); |
849 |
jsorg71 |
336 |
|
850 |
jdmeijer |
813 |
if (present & 0x008000) |
851 |
|
|
in_uint8s(s, 1); |
852 |
|
|
|
853 |
|
|
if (present & 0x010000) |
854 |
|
|
{ |
855 |
|
|
in_uint8s(s, 1); /* guessing the length here */ |
856 |
|
|
warning("Unknown order state member (0x010000) in text2 order.\n"); |
857 |
|
|
} |
858 |
|
|
|
859 |
|
|
if (present & 0x020000) |
860 |
|
|
in_uint8s(s, 4); |
861 |
|
|
|
862 |
|
|
if (present & 0x040000) |
863 |
|
|
in_uint8s(s, 4); |
864 |
|
|
|
865 |
matty |
10 |
if (present & 0x080000) |
866 |
|
|
in_uint16_le(s, os->x); |
867 |
|
|
|
868 |
|
|
if (present & 0x100000) |
869 |
|
|
in_uint16_le(s, os->y); |
870 |
|
|
|
871 |
|
|
if (present & 0x200000) |
872 |
|
|
{ |
873 |
|
|
in_uint8(s, os->length); |
874 |
|
|
in_uint8a(s, os->text, os->length); |
875 |
|
|
} |
876 |
|
|
|
877 |
astrand |
64 |
DEBUG(("TEXT2(x=%d,y=%d,cl=%d,ct=%d,cr=%d,cb=%d,bl=%d,bt=%d,bb=%d,br=%d,fg=0x%x,bg=0x%x,font=%d,fl=0x%x,mix=%d,unk=0x%x,n=%d)\n", os->x, os->y, os->clipleft, os->cliptop, os->clipright, os->clipbottom, os->boxleft, os->boxtop, os->boxright, os->boxbottom, os->fgcolour, os->bgcolour, os->font, os->flags, os->mixmode, os->unknown, os->length)); |
878 |
matty |
10 |
|
879 |
matty |
30 |
DEBUG(("Text: ")); |
880 |
matty |
10 |
|
881 |
|
|
for (i = 0; i < os->length; i++) |
882 |
matty |
30 |
DEBUG(("%02x ", os->text[i])); |
883 |
matty |
10 |
|
884 |
matty |
30 |
DEBUG(("\n")); |
885 |
matty |
10 |
|
886 |
matty |
17 |
ui_draw_text(os->font, os->flags, os->mixmode, os->x, os->y, |
887 |
matty |
24 |
os->clipleft, os->cliptop, |
888 |
|
|
os->clipright - os->clipleft, |
889 |
|
|
os->clipbottom - os->cliptop, |
890 |
|
|
os->boxleft, os->boxtop, |
891 |
|
|
os->boxright - os->boxleft, |
892 |
astrand |
82 |
os->boxbottom - os->boxtop, os->bgcolour, os->fgcolour, os->text, os->length); |
893 |
matty |
10 |
} |
894 |
|
|
|
895 |
|
|
/* Process a raw bitmap cache order */ |
896 |
matty |
25 |
static void |
897 |
|
|
process_raw_bmpcache(STREAM s) |
898 |
matty |
10 |
{ |
899 |
|
|
HBITMAP bitmap; |
900 |
|
|
uint16 cache_idx, bufsize; |
901 |
jsorg71 |
314 |
uint8 cache_id, width, height, bpp, Bpp; |
902 |
matty |
28 |
uint8 *data, *inverted; |
903 |
|
|
int y; |
904 |
matty |
10 |
|
905 |
|
|
in_uint8(s, cache_id); |
906 |
matty |
24 |
in_uint8s(s, 1); /* pad */ |
907 |
matty |
10 |
in_uint8(s, width); |
908 |
|
|
in_uint8(s, height); |
909 |
|
|
in_uint8(s, bpp); |
910 |
jsorg71 |
314 |
Bpp = (bpp + 7) / 8; |
911 |
matty |
10 |
in_uint16_le(s, bufsize); |
912 |
|
|
in_uint16_le(s, cache_idx); |
913 |
|
|
in_uint8p(s, data, bufsize); |
914 |
|
|
|
915 |
astrand |
82 |
DEBUG(("RAW_BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n", width, height, cache_id, cache_idx)); |
916 |
forsberg |
414 |
inverted = (uint8 *) xmalloc(width * height * Bpp); |
917 |
matty |
28 |
for (y = 0; y < height; y++) |
918 |
|
|
{ |
919 |
astrand |
318 |
memcpy(&inverted[(height - y - 1) * (width * Bpp)], &data[y * (width * Bpp)], |
920 |
|
|
width * Bpp); |
921 |
matty |
28 |
} |
922 |
matty |
10 |
|
923 |
matty |
28 |
bitmap = ui_create_bitmap(width, height, inverted); |
924 |
|
|
xfree(inverted); |
925 |
jdmeijer |
830 |
cache_put_bitmap(cache_id, cache_idx, bitmap); |
926 |
matty |
10 |
} |
927 |
|
|
|
928 |
|
|
/* Process a bitmap cache order */ |
929 |
matty |
25 |
static void |
930 |
|
|
process_bmpcache(STREAM s) |
931 |
matty |
10 |
{ |
932 |
|
|
HBITMAP bitmap; |
933 |
|
|
uint16 cache_idx, size; |
934 |
jsorg71 |
314 |
uint8 cache_id, width, height, bpp, Bpp; |
935 |
matty |
10 |
uint8 *data, *bmpdata; |
936 |
forsberg |
355 |
uint16 bufsize, pad2, row_size, final_size; |
937 |
|
|
uint8 pad1; |
938 |
matty |
10 |
|
939 |
forsberg |
414 |
pad2 = row_size = final_size = 0xffff; /* Shut the compiler up */ |
940 |
forsberg |
356 |
|
941 |
matty |
10 |
in_uint8(s, cache_id); |
942 |
forsberg |
355 |
in_uint8(s, pad1); /* pad */ |
943 |
matty |
10 |
in_uint8(s, width); |
944 |
|
|
in_uint8(s, height); |
945 |
|
|
in_uint8(s, bpp); |
946 |
jsorg71 |
314 |
Bpp = (bpp + 7) / 8; |
947 |
forsberg |
355 |
in_uint16_le(s, bufsize); /* bufsize */ |
948 |
matty |
10 |
in_uint16_le(s, cache_idx); |
949 |
forsberg |
355 |
|
950 |
jsorg71 |
725 |
if (g_use_rdp5) |
951 |
forsberg |
414 |
{ |
952 |
jsorg71 |
725 |
size = bufsize; |
953 |
|
|
} |
954 |
|
|
else |
955 |
|
|
{ |
956 |
forsberg |
355 |
|
957 |
|
|
/* Begin compressedBitmapData */ |
958 |
|
|
in_uint16_le(s, pad2); /* pad */ |
959 |
|
|
in_uint16_le(s, size); |
960 |
astrand |
542 |
/* in_uint8s(s, 4); *//* row_size, final_size */ |
961 |
forsberg |
355 |
in_uint16_le(s, row_size); |
962 |
|
|
in_uint16_le(s, final_size); |
963 |
|
|
|
964 |
forsberg |
414 |
} |
965 |
matty |
10 |
in_uint8p(s, data, size); |
966 |
|
|
|
967 |
forsberg |
414 |
DEBUG(("BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d,bpp=%d,size=%d,pad1=%d,bufsize=%d,pad2=%d,rs=%d,fs=%d)\n", width, height, cache_id, cache_idx, bpp, size, pad1, bufsize, pad2, row_size, final_size)); |
968 |
matty |
10 |
|
969 |
forsberg |
414 |
bmpdata = (uint8 *) xmalloc(width * height * Bpp); |
970 |
matty |
10 |
|
971 |
jsorg71 |
314 |
if (bitmap_decompress(bmpdata, width, height, data, size, Bpp)) |
972 |
matty |
10 |
{ |
973 |
|
|
bitmap = ui_create_bitmap(width, height, bmpdata); |
974 |
jdmeijer |
830 |
cache_put_bitmap(cache_id, cache_idx, bitmap); |
975 |
matty |
10 |
} |
976 |
forsberg |
349 |
else |
977 |
|
|
{ |
978 |
|
|
DEBUG(("Failed to decompress bitmap data\n")); |
979 |
|
|
} |
980 |
matty |
10 |
|
981 |
|
|
xfree(bmpdata); |
982 |
|
|
} |
983 |
|
|
|
984 |
jsorg71 |
725 |
/* Process a bitmap cache v2 order */ |
985 |
|
|
static void |
986 |
|
|
process_bmpcache2(STREAM s, uint16 flags, BOOL compressed) |
987 |
|
|
{ |
988 |
|
|
HBITMAP bitmap; |
989 |
|
|
int y; |
990 |
|
|
uint8 cache_id, cache_idx_low, width, height, Bpp; |
991 |
|
|
uint16 cache_idx, bufsize; |
992 |
|
|
uint8 *data, *bmpdata, *bitmap_id; |
993 |
|
|
|
994 |
|
|
bitmap_id = NULL; /* prevent compiler warning */ |
995 |
|
|
cache_id = flags & ID_MASK; |
996 |
|
|
Bpp = ((flags & MODE_MASK) >> MODE_SHIFT) - 2; |
997 |
|
|
|
998 |
|
|
if (flags & PERSIST) |
999 |
|
|
{ |
1000 |
|
|
in_uint8p(s, bitmap_id, 8); |
1001 |
|
|
} |
1002 |
|
|
|
1003 |
|
|
if (flags & SQUARE) |
1004 |
|
|
{ |
1005 |
|
|
in_uint8(s, width); |
1006 |
|
|
height = width; |
1007 |
|
|
} |
1008 |
|
|
else |
1009 |
|
|
{ |
1010 |
|
|
in_uint8(s, width); |
1011 |
|
|
in_uint8(s, height); |
1012 |
|
|
} |
1013 |
|
|
|
1014 |
|
|
in_uint16_be(s, bufsize); |
1015 |
|
|
bufsize &= BUFSIZE_MASK; |
1016 |
|
|
in_uint8(s, cache_idx); |
1017 |
|
|
|
1018 |
|
|
if (cache_idx & LONG_FORMAT) |
1019 |
|
|
{ |
1020 |
|
|
in_uint8(s, cache_idx_low); |
1021 |
|
|
cache_idx = ((cache_idx ^ LONG_FORMAT) << 8) + cache_idx_low; |
1022 |
|
|
} |
1023 |
|
|
|
1024 |
|
|
in_uint8p(s, data, bufsize); |
1025 |
|
|
|
1026 |
|
|
DEBUG(("BMPCACHE2(compr=%d,flags=%x,cx=%d,cy=%d,id=%d,idx=%d,Bpp=%d,bs=%d)\n", |
1027 |
astrand |
738 |
compressed, flags, width, height, cache_id, cache_idx, Bpp, bufsize)); |
1028 |
jsorg71 |
725 |
|
1029 |
|
|
bmpdata = (uint8 *) xmalloc(width * height * Bpp); |
1030 |
|
|
|
1031 |
|
|
if (compressed) |
1032 |
|
|
{ |
1033 |
|
|
if (!bitmap_decompress(bmpdata, width, height, data, bufsize, Bpp)) |
1034 |
|
|
{ |
1035 |
|
|
DEBUG(("Failed to decompress bitmap data\n")); |
1036 |
|
|
xfree(bmpdata); |
1037 |
|
|
return; |
1038 |
|
|
} |
1039 |
|
|
} |
1040 |
|
|
else |
1041 |
|
|
{ |
1042 |
|
|
for (y = 0; y < height; y++) |
1043 |
|
|
memcpy(&bmpdata[(height - y - 1) * (width * Bpp)], |
1044 |
astrand |
738 |
&data[y * (width * Bpp)], width * Bpp); |
1045 |
jsorg71 |
725 |
} |
1046 |
|
|
|
1047 |
|
|
bitmap = ui_create_bitmap(width, height, bmpdata); |
1048 |
|
|
|
1049 |
|
|
if (bitmap) |
1050 |
|
|
{ |
1051 |
jdmeijer |
830 |
cache_put_bitmap(cache_id, cache_idx, bitmap); |
1052 |
jsorg71 |
725 |
if (flags & PERSIST) |
1053 |
jdmeijer |
830 |
pstcache_save_bitmap(cache_id, cache_idx, bitmap_id, width, height, |
1054 |
|
|
width * height * Bpp, bmpdata); |
1055 |
jsorg71 |
725 |
} |
1056 |
|
|
else |
1057 |
|
|
{ |
1058 |
|
|
DEBUG(("process_bmpcache2: ui_create_bitmap failed\n")); |
1059 |
|
|
} |
1060 |
|
|
|
1061 |
|
|
xfree(bmpdata); |
1062 |
|
|
} |
1063 |
|
|
|
1064 |
matty |
10 |
/* Process a colourmap cache order */ |
1065 |
matty |
25 |
static void |
1066 |
|
|
process_colcache(STREAM s) |
1067 |
matty |
10 |
{ |
1068 |
|
|
COLOURENTRY *entry; |
1069 |
|
|
COLOURMAP map; |
1070 |
|
|
HCOLOURMAP hmap; |
1071 |
|
|
uint8 cache_id; |
1072 |
|
|
int i; |
1073 |
|
|
|
1074 |
|
|
in_uint8(s, cache_id); |
1075 |
|
|
in_uint16_le(s, map.ncolours); |
1076 |
|
|
|
1077 |
jsorg71 |
436 |
map.colours = (COLOURENTRY *) xmalloc(sizeof(COLOURENTRY) * map.ncolours); |
1078 |
matty |
10 |
|
1079 |
|
|
for (i = 0; i < map.ncolours; i++) |
1080 |
|
|
{ |
1081 |
|
|
entry = &map.colours[i]; |
1082 |
|
|
in_uint8(s, entry->blue); |
1083 |
|
|
in_uint8(s, entry->green); |
1084 |
|
|
in_uint8(s, entry->red); |
1085 |
matty |
24 |
in_uint8s(s, 1); /* pad */ |
1086 |
matty |
10 |
} |
1087 |
|
|
|
1088 |
matty |
30 |
DEBUG(("COLCACHE(id=%d,n=%d)\n", cache_id, map.ncolours)); |
1089 |
matty |
10 |
|
1090 |
|
|
hmap = ui_create_colourmap(&map); |
1091 |
|
|
ui_set_colourmap(hmap); |
1092 |
|
|
|
1093 |
|
|
xfree(map.colours); |
1094 |
|
|
} |
1095 |
|
|
|
1096 |
|
|
/* Process a font cache order */ |
1097 |
matty |
25 |
static void |
1098 |
|
|
process_fontcache(STREAM s) |
1099 |
matty |
10 |
{ |
1100 |
|
|
HGLYPH bitmap; |
1101 |
|
|
uint8 font, nglyphs; |
1102 |
matty |
20 |
uint16 character, offset, baseline, width, height; |
1103 |
matty |
24 |
int i, datasize; |
1104 |
|
|
uint8 *data; |
1105 |
matty |
10 |
|
1106 |
|
|
in_uint8(s, font); |
1107 |
|
|
in_uint8(s, nglyphs); |
1108 |
|
|
|
1109 |
matty |
30 |
DEBUG(("FONTCACHE(font=%d,n=%d)\n", font, nglyphs)); |
1110 |
matty |
10 |
|
1111 |
|
|
for (i = 0; i < nglyphs; i++) |
1112 |
|
|
{ |
1113 |
|
|
in_uint16_le(s, character); |
1114 |
matty |
20 |
in_uint16_le(s, offset); |
1115 |
matty |
10 |
in_uint16_le(s, baseline); |
1116 |
|
|
in_uint16_le(s, width); |
1117 |
|
|
in_uint16_le(s, height); |
1118 |
|
|
|
1119 |
|
|
datasize = (height * ((width + 7) / 8) + 3) & ~3; |
1120 |
|
|
in_uint8p(s, data, datasize); |
1121 |
|
|
|
1122 |
matty |
23 |
bitmap = ui_create_glyph(width, height, data); |
1123 |
astrand |
82 |
cache_put_font(font, character, offset, baseline, width, height, bitmap); |
1124 |
matty |
10 |
} |
1125 |
|
|
} |
1126 |
|
|
|
1127 |
|
|
/* Process a secondary order */ |
1128 |
matty |
25 |
static void |
1129 |
|
|
process_secondary_order(STREAM s) |
1130 |
matty |
10 |
{ |
1131 |
jsorg71 |
725 |
/* The length isn't calculated correctly by the server. |
1132 |
|
|
* For very compact orders the length becomes negative |
1133 |
|
|
* so a signed integer must be used. */ |
1134 |
stargo |
726 |
uint16 length; |
1135 |
jsorg71 |
725 |
uint16 flags; |
1136 |
matty |
10 |
uint8 type; |
1137 |
|
|
uint8 *next_order; |
1138 |
|
|
|
1139 |
stargo |
726 |
in_uint16_le(s, length); |
1140 |
astrand |
738 |
in_uint16_le(s, flags); /* used by bmpcache2 */ |
1141 |
matty |
10 |
in_uint8(s, type); |
1142 |
|
|
|
1143 |
astrand |
738 |
next_order = s->p + (sint16) length + 7; |
1144 |
matty |
10 |
|
1145 |
|
|
switch (type) |
1146 |
|
|
{ |
1147 |
|
|
case RDP_ORDER_RAW_BMPCACHE: |
1148 |
|
|
process_raw_bmpcache(s); |
1149 |
|
|
break; |
1150 |
|
|
|
1151 |
|
|
case RDP_ORDER_COLCACHE: |
1152 |
|
|
process_colcache(s); |
1153 |
|
|
break; |
1154 |
|
|
|
1155 |
|
|
case RDP_ORDER_BMPCACHE: |
1156 |
|
|
process_bmpcache(s); |
1157 |
|
|
break; |
1158 |
|
|
|
1159 |
|
|
case RDP_ORDER_FONTCACHE: |
1160 |
|
|
process_fontcache(s); |
1161 |
|
|
break; |
1162 |
|
|
|
1163 |
jsorg71 |
725 |
case RDP_ORDER_RAW_BMPCACHE2: |
1164 |
|
|
process_bmpcache2(s, flags, False); /* uncompressed */ |
1165 |
|
|
break; |
1166 |
|
|
|
1167 |
|
|
case RDP_ORDER_BMPCACHE2: |
1168 |
|
|
process_bmpcache2(s, flags, True); /* compressed */ |
1169 |
|
|
break; |
1170 |
|
|
|
1171 |
matty |
10 |
default: |
1172 |
matty |
30 |
unimpl("secondary order %d\n", type); |
1173 |
matty |
10 |
} |
1174 |
|
|
|
1175 |
|
|
s->p = next_order; |
1176 |
|
|
} |
1177 |
|
|
|
1178 |
|
|
/* Process an order PDU */ |
1179 |
matty |
25 |
void |
1180 |
forsberg |
349 |
process_orders(STREAM s, uint16 num_orders) |
1181 |
matty |
10 |
{ |
1182 |
jsorg71 |
382 |
RDP_ORDER_STATE *os = &g_order_state; |
1183 |
matty |
10 |
uint32 present; |
1184 |
|
|
uint8 order_flags; |
1185 |
|
|
int size, processed = 0; |
1186 |
|
|
BOOL delta; |
1187 |
|
|
|
1188 |
|
|
while (processed < num_orders) |
1189 |
|
|
{ |
1190 |
|
|
in_uint8(s, order_flags); |
1191 |
|
|
|
1192 |
|
|
if (!(order_flags & RDP_ORDER_STANDARD)) |
1193 |
|
|
{ |
1194 |
matty |
30 |
error("order parsing failed\n"); |
1195 |
matty |
10 |
break; |
1196 |
|
|
} |
1197 |
|
|
|
1198 |
|
|
if (order_flags & RDP_ORDER_SECONDARY) |
1199 |
|
|
{ |
1200 |
|
|
process_secondary_order(s); |
1201 |
|
|
} |
1202 |
|
|
else |
1203 |
|
|
{ |
1204 |
|
|
if (order_flags & RDP_ORDER_CHANGE) |
1205 |
|
|
{ |
1206 |
|
|
in_uint8(s, os->order_type); |
1207 |
|
|
} |
1208 |
|
|
|
1209 |
|
|
switch (os->order_type) |
1210 |
|
|
{ |
1211 |
|
|
case RDP_ORDER_TRIBLT: |
1212 |
|
|
case RDP_ORDER_TEXT2: |
1213 |
|
|
size = 3; |
1214 |
|
|
break; |
1215 |
|
|
|
1216 |
|
|
case RDP_ORDER_PATBLT: |
1217 |
|
|
case RDP_ORDER_MEMBLT: |
1218 |
|
|
case RDP_ORDER_LINE: |
1219 |
jdmeijer |
831 |
case RDP_ORDER_POLYGON2: |
1220 |
|
|
case RDP_ORDER_ELLIPSE2: |
1221 |
matty |
10 |
size = 2; |
1222 |
|
|
break; |
1223 |
|
|
|
1224 |
|
|
default: |
1225 |
|
|
size = 1; |
1226 |
|
|
} |
1227 |
|
|
|
1228 |
|
|
rdp_in_present(s, &present, order_flags, size); |
1229 |
|
|
|
1230 |
|
|
if (order_flags & RDP_ORDER_BOUNDS) |
1231 |
|
|
{ |
1232 |
|
|
if (!(order_flags & RDP_ORDER_LASTBOUNDS)) |
1233 |
|
|
rdp_parse_bounds(s, &os->bounds); |
1234 |
|
|
|
1235 |
|
|
ui_set_clip(os->bounds.left, |
1236 |
matty |
24 |
os->bounds.top, |
1237 |
|
|
os->bounds.right - |
1238 |
|
|
os->bounds.left + 1, |
1239 |
astrand |
82 |
os->bounds.bottom - os->bounds.top + 1); |
1240 |
matty |
10 |
} |
1241 |
|
|
|
1242 |
|
|
delta = order_flags & RDP_ORDER_DELTA; |
1243 |
|
|
|
1244 |
|
|
switch (os->order_type) |
1245 |
|
|
{ |
1246 |
|
|
case RDP_ORDER_DESTBLT: |
1247 |
astrand |
82 |
process_destblt(s, &os->destblt, present, delta); |
1248 |
matty |
10 |
break; |
1249 |
|
|
|
1250 |
|
|
case RDP_ORDER_PATBLT: |
1251 |
astrand |
82 |
process_patblt(s, &os->patblt, present, delta); |
1252 |
matty |
10 |
break; |
1253 |
|
|
|
1254 |
|
|
case RDP_ORDER_SCREENBLT: |
1255 |
astrand |
82 |
process_screenblt(s, &os->screenblt, present, delta); |
1256 |
matty |
10 |
break; |
1257 |
|
|
|
1258 |
|
|
case RDP_ORDER_LINE: |
1259 |
astrand |
82 |
process_line(s, &os->line, present, delta); |
1260 |
matty |
10 |
break; |
1261 |
|
|
|
1262 |
|
|
case RDP_ORDER_RECT: |
1263 |
astrand |
82 |
process_rect(s, &os->rect, present, delta); |
1264 |
matty |
10 |
break; |
1265 |
|
|
|
1266 |
|
|
case RDP_ORDER_DESKSAVE: |
1267 |
astrand |
82 |
process_desksave(s, &os->desksave, present, delta); |
1268 |
matty |
10 |
break; |
1269 |
|
|
|
1270 |
|
|
case RDP_ORDER_MEMBLT: |
1271 |
astrand |
82 |
process_memblt(s, &os->memblt, present, delta); |
1272 |
matty |
10 |
break; |
1273 |
|
|
|
1274 |
|
|
case RDP_ORDER_TRIBLT: |
1275 |
astrand |
82 |
process_triblt(s, &os->triblt, present, delta); |
1276 |
matty |
10 |
break; |
1277 |
|
|
|
1278 |
jdmeijer |
831 |
case RDP_ORDER_POLYGON: |
1279 |
|
|
process_polygon(s, &os->polygon, present, delta); |
1280 |
|
|
break; |
1281 |
|
|
|
1282 |
|
|
case RDP_ORDER_POLYGON2: |
1283 |
|
|
process_polygon2(s, &os->polygon2, present, delta); |
1284 |
|
|
break; |
1285 |
|
|
|
1286 |
matty |
15 |
case RDP_ORDER_POLYLINE: |
1287 |
astrand |
82 |
process_polyline(s, &os->polyline, present, delta); |
1288 |
matty |
15 |
break; |
1289 |
|
|
|
1290 |
jdmeijer |
831 |
case RDP_ORDER_ELLIPSE: |
1291 |
|
|
process_ellipse(s, &os->ellipse, present, delta); |
1292 |
|
|
break; |
1293 |
|
|
|
1294 |
|
|
case RDP_ORDER_ELLIPSE2: |
1295 |
|
|
process_ellipse2(s, &os->ellipse2, present, delta); |
1296 |
|
|
break; |
1297 |
|
|
|
1298 |
matty |
10 |
case RDP_ORDER_TEXT2: |
1299 |
astrand |
82 |
process_text2(s, &os->text2, present, delta); |
1300 |
matty |
10 |
break; |
1301 |
|
|
|
1302 |
|
|
default: |
1303 |
matty |
30 |
unimpl("order %d\n", os->order_type); |
1304 |
matty |
10 |
return; |
1305 |
|
|
} |
1306 |
|
|
|
1307 |
|
|
if (order_flags & RDP_ORDER_BOUNDS) |
1308 |
|
|
ui_reset_clip(); |
1309 |
|
|
} |
1310 |
|
|
|
1311 |
|
|
processed++; |
1312 |
|
|
} |
1313 |
n-ki |
683 |
#if 0 |
1314 |
|
|
/* not true when RDP_COMPRESSION is set */ |
1315 |
jsorg71 |
438 |
if (s->p != g_next_packet) |
1316 |
|
|
error("%d bytes remaining\n", (int) (g_next_packet - s->p)); |
1317 |
n-ki |
683 |
#endif |
1318 |
|
|
|
1319 |
matty |
10 |
} |
1320 |
|
|
|
1321 |
|
|
/* Reset order state */ |
1322 |
matty |
25 |
void |
1323 |
matthewc |
192 |
reset_order_state(void) |
1324 |
matty |
10 |
{ |
1325 |
jsorg71 |
382 |
memset(&g_order_state, 0, sizeof(g_order_state)); |
1326 |
|
|
g_order_state.order_type = RDP_ORDER_PATBLT; |
1327 |
matty |
10 |
} |