/[rdesktop]/sourceforge.net/trunk/rdesktop/orders.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /sourceforge.net/trunk/rdesktop/orders.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 844 - (show annotations)
Thu Mar 10 22:48:15 2005 UTC (19 years, 3 months ago) by jdmeijer
File MIME type: text/plain
File size: 28693 byte(s)
do polyline in a single ui operation: ui_polyline

1 /* -*- c-basic-offset: 8 -*-
2 rdesktop: A Remote Desktop Protocol client.
3 RDP order processing
4 Copyright (C) Matthew Chapman 1999-2005
5
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 extern uint8 *g_next_packet;
25 static RDP_ORDER_STATE g_order_state;
26 extern BOOL g_use_rdp5;
27
28 /* Read field indicating which parameters are present */
29 static void
30 rdp_in_present(STREAM s, uint32 * present, uint8 flags, int size)
31 {
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 static void
58 rdp_in_coord(STREAM s, sint16 * coord, BOOL delta)
59 {
60 sint8 change;
61
62 if (delta)
63 {
64 in_uint8(s, change);
65 *coord += change;
66 }
67 else
68 {
69 in_uint16_le(s, *coord);
70 }
71 }
72
73 /* 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 /* Read a colour entry */
92 static void
93 rdp_in_colour(STREAM s, uint32 * colour)
94 {
95 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 }
103
104 /* Parse bounds information */
105 static BOOL
106 rdp_parse_bounds(STREAM s, BOUNDS * bounds)
107 {
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 static BOOL
137 rdp_parse_pen(STREAM s, PEN * pen, uint32 present)
138 {
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 static BOOL
153 rdp_parse_brush(STREAM s, BRUSH * brush, uint32 present)
154 {
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 static void
175 process_destblt(STREAM s, DESTBLT_ORDER * os, uint32 present, BOOL delta)
176 {
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 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
195 ui_destblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy);
196 }
197
198 /* Process a pattern blt order */
199 static void
200 process_patblt(STREAM s, PATBLT_ORDER * os, uint32 present, BOOL delta)
201 {
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 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
228 ui_patblt(ROP2_P(os->opcode), os->x, os->y, os->cx, os->cy,
229 &os->brush, os->bgcolour, os->fgcolour);
230 }
231
232 /* Process a screen blt order */
233 static void
234 process_screenblt(STREAM s, SCREENBLT_ORDER * os, uint32 present, BOOL delta)
235 {
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 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
260 ui_screenblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy, os->srcx, os->srcy);
261 }
262
263 /* Process a line order */
264 static void
265 process_line(STREAM s, LINE_ORDER * os, uint32 present, BOOL delta)
266 {
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 DEBUG(("LINE(op=0x%x,sx=%d,sy=%d,dx=%d,dy=%d,fg=0x%x)\n",
291 os->opcode, os->startx, os->starty, os->endx, os->endy, os->pen.colour));
292
293 if (os->opcode < 0x01 || os->opcode > 0x10)
294 {
295 error("bad ROP2 0x%x\n", os->opcode);
296 return;
297 }
298
299 ui_line(os->opcode - 1, os->startx, os->starty, os->endx, os->endy, &os->pen);
300 }
301
302 /* Process an opaque rectangle order */
303 static void
304 process_rect(STREAM s, RECT_ORDER * os, uint32 present, BOOL delta)
305 {
306 uint32 i;
307 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 {
321 in_uint8(s, i);
322 os->colour = (os->colour & 0xffffff00) | i;
323 }
324
325 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 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
339 ui_rect(os->x, os->y, os->cx, os->cy, os->colour);
340 }
341
342 /* Process a desktop save order */
343 static void
344 process_desksave(STREAM s, DESKSAVE_ORDER * os, uint32 present, BOOL delta)
345 {
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 DEBUG(("DESKSAVE(l=%d,t=%d,r=%d,b=%d,off=%d,op=%d)\n",
367 os->left, os->top, os->right, os->bottom, os->offset, os->action));
368
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 ui_desktop_restore(os->offset, os->left, os->top, width, height);
376 }
377
378 /* Process a memory blt order */
379 static void
380 process_memblt(STREAM s, MEMBLT_ORDER * os, uint32 present, BOOL delta)
381 {
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 DEBUG(("MEMBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,id=%d,idx=%d)\n",
415 os->opcode, os->x, os->y, os->cx, os->cy, os->cache_id, os->cache_idx));
416
417 bitmap = cache_get_bitmap(os->cache_id, os->cache_idx);
418 if (bitmap == NULL)
419 return;
420
421 ui_memblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy, bitmap, os->srcx, os->srcy);
422 }
423
424 /* Process a 3-way blt order */
425 static void
426 process_triblt(STREAM s, TRIBLT_ORDER * os, uint32 present, BOOL delta)
427 {
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 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
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 bitmap, os->srcx, os->srcy, &os->brush, os->bgcolour, os->fgcolour);
481 }
482
483 /* Process a polygon order */
484 static void
485 process_polygon(STREAM s, POLYGON_ORDER * os, uint32 present, BOOL delta)
486 {
487 int index, data, next;
488 uint8 flags = 0;
489 POINT *points;
490
491 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 else
557 error("polygon parse error\n");
558
559 xfree(points);
560 }
561
562 /* 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 }
646
647 /* Process a polyline order */
648 static void
649 process_polyline(STREAM s, POLYLINE_ORDER * os, uint32 present, BOOL delta)
650 {
651 int index, next, data;
652 uint8 flags = 0;
653 PEN pen;
654 POINT *points;
655
656 if (present & 0x01)
657 rdp_in_coord(s, &os->x, delta);
658
659 if (present & 0x02)
660 rdp_in_coord(s, &os->y, delta);
661
662 if (present & 0x04)
663 in_uint8(s, os->opcode);
664
665 if (present & 0x10)
666 rdp_in_colour(s, &os->fgcolour);
667
668 if (present & 0x20)
669 in_uint8(s, os->lines);
670
671 if (present & 0x40)
672 {
673 in_uint8(s, os->datasize);
674 in_uint8a(s, os->data, os->datasize);
675 }
676
677 DEBUG(("POLYLINE(x=%d,y=%d,op=0x%x,fg=0x%x,n=%d,sz=%d)\n",
678 os->x, os->y, os->opcode, os->fgcolour, os->lines, os->datasize));
679
680 DEBUG(("Data: "));
681
682 for (index = 0; index < os->datasize; index++)
683 DEBUG(("%02x ", os->data[index]));
684
685 DEBUG(("\n"));
686
687 if (os->opcode < 0x01 || os->opcode > 0x10)
688 {
689 error("bad ROP2 0x%x\n", os->opcode);
690 return;
691 }
692
693 points = (POINT *) xmalloc((os->lines + 1) * sizeof(POINT));
694 memset(points, 0, (os->lines + 1) * sizeof(POINT));
695
696 points[0].x = os->x;
697 points[0].y = os->y;
698
699 index = 0;
700 data = ((os->lines - 1) / 4) + 1;
701 for (next = 1; (next < os->lines) && (data < os->datasize); next++)
702 {
703 if ((next - 1) % 4 == 0)
704 flags = os->data[index++];
705
706 if (~flags & 0x80)
707 points[next].x = parse_delta(os->data, &data);
708
709 if (~flags & 0x40)
710 points[next].y = parse_delta(os->data, &data);
711
712 flags <<= 2;
713 }
714
715 if (next - 1 == os->lines)
716 ui_polyline(os->opcode - 1, points, os->lines + 1, &pen);
717 else
718 error("polyline parse error\n");
719 }
720
721 /* Process an ellipse order */
722 static void
723 process_ellipse(STREAM s, ELLIPSE_ORDER * os, uint32 present, BOOL delta)
724 {
725 if (present & 0x01)
726 rdp_in_coord(s, &os->left, delta);
727
728 if (present & 0x02)
729 rdp_in_coord(s, &os->top, delta);
730
731 if (present & 0x04)
732 rdp_in_coord(s, &os->right, delta);
733
734 if (present & 0x08)
735 rdp_in_coord(s, &os->bottom, delta);
736
737 if (present & 0x10)
738 in_uint8(s, os->opcode);
739
740 if (present & 0x20)
741 in_uint8(s, os->fillmode);
742
743 if (present & 0x40)
744 rdp_in_colour(s, &os->fgcolour);
745
746 DEBUG(("ELLIPSE(l=%d,t=%d,r=%d,b=%d,op=0x%x,fm=%d,fg=0x%x)\n", os->left, os->top,
747 os->right, os->bottom, os->opcode, os->fillmode, os->fgcolour));
748
749 ui_ellipse(os->opcode - 1, os->fillmode, os->left, os->top, os->right - os->left,
750 os->bottom - os->top, NULL, 0, os->fgcolour);
751 }
752
753 /* Process an ellipse2 order */
754 static void
755 process_ellipse2(STREAM s, ELLIPSE2_ORDER * os, uint32 present, BOOL delta)
756 {
757 if (present & 0x0001)
758 rdp_in_coord(s, &os->left, delta);
759
760 if (present & 0x0002)
761 rdp_in_coord(s, &os->top, delta);
762
763 if (present & 0x0004)
764 rdp_in_coord(s, &os->right, delta);
765
766 if (present & 0x0008)
767 rdp_in_coord(s, &os->bottom, delta);
768
769 if (present & 0x0010)
770 in_uint8(s, os->opcode);
771
772 if (present & 0x0020)
773 in_uint8(s, os->fillmode);
774
775 if (present & 0x0040)
776 rdp_in_colour(s, &os->bgcolour);
777
778 if (present & 0x0080)
779 rdp_in_colour(s, &os->fgcolour);
780
781 rdp_parse_brush(s, &os->brush, present >> 8);
782
783 DEBUG(("ELLIPSE2(l=%d,t=%d,r=%d,b=%d,op=0x%x,fm=%d,bs=%d,bg=0x%x,fg=0x%x)\n",
784 os->left, os->top, os->right, os->bottom, os->opcode, os->fillmode, os->brush.style,
785 os->bgcolour, os->fgcolour));
786
787 ui_ellipse(os->opcode - 1, os->fillmode, os->left, os->top, os->right - os->left,
788 os->bottom - os->top, &os->brush, os->bgcolour, os->fgcolour);
789 }
790
791 /* Process a text order */
792 static void
793 process_text2(STREAM s, TEXT2_ORDER * os, uint32 present, BOOL delta)
794 {
795 int i;
796
797 if (present & 0x000001)
798 in_uint8(s, os->font);
799
800 if (present & 0x000002)
801 in_uint8(s, os->flags);
802
803 if (present & 0x000004)
804 in_uint8(s, os->opcode);
805
806 if (present & 0x000008)
807 in_uint8(s, os->mixmode);
808
809 if (present & 0x000010)
810 rdp_in_colour(s, &os->fgcolour);
811
812 if (present & 0x000020)
813 rdp_in_colour(s, &os->bgcolour);
814
815 if (present & 0x000040)
816 in_uint16_le(s, os->clipleft);
817
818 if (present & 0x000080)
819 in_uint16_le(s, os->cliptop);
820
821 if (present & 0x000100)
822 in_uint16_le(s, os->clipright);
823
824 if (present & 0x000200)
825 in_uint16_le(s, os->clipbottom);
826
827 if (present & 0x000400)
828 in_uint16_le(s, os->boxleft);
829
830 if (present & 0x000800)
831 in_uint16_le(s, os->boxtop);
832
833 if (present & 0x001000)
834 in_uint16_le(s, os->boxright);
835
836 if (present & 0x002000)
837 in_uint16_le(s, os->boxbottom);
838
839 rdp_parse_brush(s, &os->brush, present >> 14);
840
841 if (present & 0x080000)
842 in_uint16_le(s, os->x);
843
844 if (present & 0x100000)
845 in_uint16_le(s, os->y);
846
847 if (present & 0x200000)
848 {
849 in_uint8(s, os->length);
850 in_uint8a(s, os->text, os->length);
851 }
852
853 DEBUG(("TEXT2(x=%d,y=%d,cl=%d,ct=%d,cr=%d,cb=%d,bl=%d,bt=%d,br=%d,bb=%d,bs=%d,bg=0x%x,fg=0x%x,font=%d,fl=0x%x,op=0x%x,mix=%d,n=%d)\n", os->x, os->y, os->clipleft, os->cliptop, os->clipright, os->clipbottom, os->boxleft, os->boxtop, os->boxright, os->boxbottom, os->brush.style, os->bgcolour, os->fgcolour, os->font, os->flags, os->opcode, os->mixmode, os->length));
854
855 DEBUG(("Text: "));
856
857 for (i = 0; i < os->length; i++)
858 DEBUG(("%02x ", os->text[i]));
859
860 DEBUG(("\n"));
861
862 ui_draw_text(os->font, os->flags, os->opcode - 1, os->mixmode, os->x, os->y,
863 os->clipleft, os->cliptop, os->clipright - os->clipleft,
864 os->clipbottom - os->cliptop, os->boxleft, os->boxtop,
865 os->boxright - os->boxleft, os->boxbottom - os->boxtop,
866 &os->brush, os->bgcolour, os->fgcolour, os->text, os->length);
867 }
868
869 /* Process a raw bitmap cache order */
870 static void
871 process_raw_bmpcache(STREAM s)
872 {
873 HBITMAP bitmap;
874 uint16 cache_idx, bufsize;
875 uint8 cache_id, width, height, bpp, Bpp;
876 uint8 *data, *inverted;
877 int y;
878
879 in_uint8(s, cache_id);
880 in_uint8s(s, 1); /* pad */
881 in_uint8(s, width);
882 in_uint8(s, height);
883 in_uint8(s, bpp);
884 Bpp = (bpp + 7) / 8;
885 in_uint16_le(s, bufsize);
886 in_uint16_le(s, cache_idx);
887 in_uint8p(s, data, bufsize);
888
889 DEBUG(("RAW_BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n", width, height, cache_id, cache_idx));
890 inverted = (uint8 *) xmalloc(width * height * Bpp);
891 for (y = 0; y < height; y++)
892 {
893 memcpy(&inverted[(height - y - 1) * (width * Bpp)], &data[y * (width * Bpp)],
894 width * Bpp);
895 }
896
897 bitmap = ui_create_bitmap(width, height, inverted);
898 xfree(inverted);
899 cache_put_bitmap(cache_id, cache_idx, bitmap);
900 }
901
902 /* Process a bitmap cache order */
903 static void
904 process_bmpcache(STREAM s)
905 {
906 HBITMAP bitmap;
907 uint16 cache_idx, size;
908 uint8 cache_id, width, height, bpp, Bpp;
909 uint8 *data, *bmpdata;
910 uint16 bufsize, pad2, row_size, final_size;
911 uint8 pad1;
912
913 pad2 = row_size = final_size = 0xffff; /* Shut the compiler up */
914
915 in_uint8(s, cache_id);
916 in_uint8(s, pad1); /* pad */
917 in_uint8(s, width);
918 in_uint8(s, height);
919 in_uint8(s, bpp);
920 Bpp = (bpp + 7) / 8;
921 in_uint16_le(s, bufsize); /* bufsize */
922 in_uint16_le(s, cache_idx);
923
924 if (g_use_rdp5)
925 {
926 size = bufsize;
927 }
928 else
929 {
930
931 /* Begin compressedBitmapData */
932 in_uint16_le(s, pad2); /* pad */
933 in_uint16_le(s, size);
934 /* in_uint8s(s, 4); *//* row_size, final_size */
935 in_uint16_le(s, row_size);
936 in_uint16_le(s, final_size);
937
938 }
939 in_uint8p(s, data, size);
940
941 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));
942
943 bmpdata = (uint8 *) xmalloc(width * height * Bpp);
944
945 if (bitmap_decompress(bmpdata, width, height, data, size, Bpp))
946 {
947 bitmap = ui_create_bitmap(width, height, bmpdata);
948 cache_put_bitmap(cache_id, cache_idx, bitmap);
949 }
950 else
951 {
952 DEBUG(("Failed to decompress bitmap data\n"));
953 }
954
955 xfree(bmpdata);
956 }
957
958 /* Process a bitmap cache v2 order */
959 static void
960 process_bmpcache2(STREAM s, uint16 flags, BOOL compressed)
961 {
962 HBITMAP bitmap;
963 int y;
964 uint8 cache_id, cache_idx_low, width, height, Bpp;
965 uint16 cache_idx, bufsize;
966 uint8 *data, *bmpdata, *bitmap_id;
967
968 bitmap_id = NULL; /* prevent compiler warning */
969 cache_id = flags & ID_MASK;
970 Bpp = ((flags & MODE_MASK) >> MODE_SHIFT) - 2;
971
972 if (flags & PERSIST)
973 {
974 in_uint8p(s, bitmap_id, 8);
975 }
976
977 if (flags & SQUARE)
978 {
979 in_uint8(s, width);
980 height = width;
981 }
982 else
983 {
984 in_uint8(s, width);
985 in_uint8(s, height);
986 }
987
988 in_uint16_be(s, bufsize);
989 bufsize &= BUFSIZE_MASK;
990 in_uint8(s, cache_idx);
991
992 if (cache_idx & LONG_FORMAT)
993 {
994 in_uint8(s, cache_idx_low);
995 cache_idx = ((cache_idx ^ LONG_FORMAT) << 8) + cache_idx_low;
996 }
997
998 in_uint8p(s, data, bufsize);
999
1000 DEBUG(("BMPCACHE2(compr=%d,flags=%x,cx=%d,cy=%d,id=%d,idx=%d,Bpp=%d,bs=%d)\n",
1001 compressed, flags, width, height, cache_id, cache_idx, Bpp, bufsize));
1002
1003 bmpdata = (uint8 *) xmalloc(width * height * Bpp);
1004
1005 if (compressed)
1006 {
1007 if (!bitmap_decompress(bmpdata, width, height, data, bufsize, Bpp))
1008 {
1009 DEBUG(("Failed to decompress bitmap data\n"));
1010 xfree(bmpdata);
1011 return;
1012 }
1013 }
1014 else
1015 {
1016 for (y = 0; y < height; y++)
1017 memcpy(&bmpdata[(height - y - 1) * (width * Bpp)],
1018 &data[y * (width * Bpp)], width * Bpp);
1019 }
1020
1021 bitmap = ui_create_bitmap(width, height, bmpdata);
1022
1023 if (bitmap)
1024 {
1025 cache_put_bitmap(cache_id, cache_idx, bitmap);
1026 if (flags & PERSIST)
1027 pstcache_save_bitmap(cache_id, cache_idx, bitmap_id, width, height,
1028 width * height * Bpp, bmpdata);
1029 }
1030 else
1031 {
1032 DEBUG(("process_bmpcache2: ui_create_bitmap failed\n"));
1033 }
1034
1035 xfree(bmpdata);
1036 }
1037
1038 /* Process a colourmap cache order */
1039 static void
1040 process_colcache(STREAM s)
1041 {
1042 COLOURENTRY *entry;
1043 COLOURMAP map;
1044 HCOLOURMAP hmap;
1045 uint8 cache_id;
1046 int i;
1047
1048 in_uint8(s, cache_id);
1049 in_uint16_le(s, map.ncolours);
1050
1051 map.colours = (COLOURENTRY *) xmalloc(sizeof(COLOURENTRY) * map.ncolours);
1052
1053 for (i = 0; i < map.ncolours; i++)
1054 {
1055 entry = &map.colours[i];
1056 in_uint8(s, entry->blue);
1057 in_uint8(s, entry->green);
1058 in_uint8(s, entry->red);
1059 in_uint8s(s, 1); /* pad */
1060 }
1061
1062 DEBUG(("COLCACHE(id=%d,n=%d)\n", cache_id, map.ncolours));
1063
1064 hmap = ui_create_colourmap(&map);
1065 ui_set_colourmap(hmap);
1066
1067 xfree(map.colours);
1068 }
1069
1070 /* Process a font cache order */
1071 static void
1072 process_fontcache(STREAM s)
1073 {
1074 HGLYPH bitmap;
1075 uint8 font, nglyphs;
1076 uint16 character, offset, baseline, width, height;
1077 int i, datasize;
1078 uint8 *data;
1079
1080 in_uint8(s, font);
1081 in_uint8(s, nglyphs);
1082
1083 DEBUG(("FONTCACHE(font=%d,n=%d)\n", font, nglyphs));
1084
1085 for (i = 0; i < nglyphs; i++)
1086 {
1087 in_uint16_le(s, character);
1088 in_uint16_le(s, offset);
1089 in_uint16_le(s, baseline);
1090 in_uint16_le(s, width);
1091 in_uint16_le(s, height);
1092
1093 datasize = (height * ((width + 7) / 8) + 3) & ~3;
1094 in_uint8p(s, data, datasize);
1095
1096 bitmap = ui_create_glyph(width, height, data);
1097 cache_put_font(font, character, offset, baseline, width, height, bitmap);
1098 }
1099 }
1100
1101 /* Process a secondary order */
1102 static void
1103 process_secondary_order(STREAM s)
1104 {
1105 /* The length isn't calculated correctly by the server.
1106 * For very compact orders the length becomes negative
1107 * so a signed integer must be used. */
1108 uint16 length;
1109 uint16 flags;
1110 uint8 type;
1111 uint8 *next_order;
1112
1113 in_uint16_le(s, length);
1114 in_uint16_le(s, flags); /* used by bmpcache2 */
1115 in_uint8(s, type);
1116
1117 next_order = s->p + (sint16) length + 7;
1118
1119 switch (type)
1120 {
1121 case RDP_ORDER_RAW_BMPCACHE:
1122 process_raw_bmpcache(s);
1123 break;
1124
1125 case RDP_ORDER_COLCACHE:
1126 process_colcache(s);
1127 break;
1128
1129 case RDP_ORDER_BMPCACHE:
1130 process_bmpcache(s);
1131 break;
1132
1133 case RDP_ORDER_FONTCACHE:
1134 process_fontcache(s);
1135 break;
1136
1137 case RDP_ORDER_RAW_BMPCACHE2:
1138 process_bmpcache2(s, flags, False); /* uncompressed */
1139 break;
1140
1141 case RDP_ORDER_BMPCACHE2:
1142 process_bmpcache2(s, flags, True); /* compressed */
1143 break;
1144
1145 default:
1146 unimpl("secondary order %d\n", type);
1147 }
1148
1149 s->p = next_order;
1150 }
1151
1152 /* Process an order PDU */
1153 void
1154 process_orders(STREAM s, uint16 num_orders)
1155 {
1156 RDP_ORDER_STATE *os = &g_order_state;
1157 uint32 present;
1158 uint8 order_flags;
1159 int size, processed = 0;
1160 BOOL delta;
1161
1162 while (processed < num_orders)
1163 {
1164 in_uint8(s, order_flags);
1165
1166 if (!(order_flags & RDP_ORDER_STANDARD))
1167 {
1168 error("order parsing failed\n");
1169 break;
1170 }
1171
1172 if (order_flags & RDP_ORDER_SECONDARY)
1173 {
1174 process_secondary_order(s);
1175 }
1176 else
1177 {
1178 if (order_flags & RDP_ORDER_CHANGE)
1179 {
1180 in_uint8(s, os->order_type);
1181 }
1182
1183 switch (os->order_type)
1184 {
1185 case RDP_ORDER_TRIBLT:
1186 case RDP_ORDER_TEXT2:
1187 size = 3;
1188 break;
1189
1190 case RDP_ORDER_PATBLT:
1191 case RDP_ORDER_MEMBLT:
1192 case RDP_ORDER_LINE:
1193 case RDP_ORDER_POLYGON2:
1194 case RDP_ORDER_ELLIPSE2:
1195 size = 2;
1196 break;
1197
1198 default:
1199 size = 1;
1200 }
1201
1202 rdp_in_present(s, &present, order_flags, size);
1203
1204 if (order_flags & RDP_ORDER_BOUNDS)
1205 {
1206 if (!(order_flags & RDP_ORDER_LASTBOUNDS))
1207 rdp_parse_bounds(s, &os->bounds);
1208
1209 ui_set_clip(os->bounds.left,
1210 os->bounds.top,
1211 os->bounds.right -
1212 os->bounds.left + 1,
1213 os->bounds.bottom - os->bounds.top + 1);
1214 }
1215
1216 delta = order_flags & RDP_ORDER_DELTA;
1217
1218 switch (os->order_type)
1219 {
1220 case RDP_ORDER_DESTBLT:
1221 process_destblt(s, &os->destblt, present, delta);
1222 break;
1223
1224 case RDP_ORDER_PATBLT:
1225 process_patblt(s, &os->patblt, present, delta);
1226 break;
1227
1228 case RDP_ORDER_SCREENBLT:
1229 process_screenblt(s, &os->screenblt, present, delta);
1230 break;
1231
1232 case RDP_ORDER_LINE:
1233 process_line(s, &os->line, present, delta);
1234 break;
1235
1236 case RDP_ORDER_RECT:
1237 process_rect(s, &os->rect, present, delta);
1238 break;
1239
1240 case RDP_ORDER_DESKSAVE:
1241 process_desksave(s, &os->desksave, present, delta);
1242 break;
1243
1244 case RDP_ORDER_MEMBLT:
1245 process_memblt(s, &os->memblt, present, delta);
1246 break;
1247
1248 case RDP_ORDER_TRIBLT:
1249 process_triblt(s, &os->triblt, present, delta);
1250 break;
1251
1252 case RDP_ORDER_POLYGON:
1253 process_polygon(s, &os->polygon, present, delta);
1254 break;
1255
1256 case RDP_ORDER_POLYGON2:
1257 process_polygon2(s, &os->polygon2, present, delta);
1258 break;
1259
1260 case RDP_ORDER_POLYLINE:
1261 process_polyline(s, &os->polyline, present, delta);
1262 break;
1263
1264 case RDP_ORDER_ELLIPSE:
1265 process_ellipse(s, &os->ellipse, present, delta);
1266 break;
1267
1268 case RDP_ORDER_ELLIPSE2:
1269 process_ellipse2(s, &os->ellipse2, present, delta);
1270 break;
1271
1272 case RDP_ORDER_TEXT2:
1273 process_text2(s, &os->text2, present, delta);
1274 break;
1275
1276 default:
1277 unimpl("order %d\n", os->order_type);
1278 return;
1279 }
1280
1281 if (order_flags & RDP_ORDER_BOUNDS)
1282 ui_reset_clip();
1283 }
1284
1285 processed++;
1286 }
1287 #if 0
1288 /* not true when RDP_COMPRESSION is set */
1289 if (s->p != g_next_packet)
1290 error("%d bytes remaining\n", (int) (g_next_packet - s->p));
1291 #endif
1292
1293 }
1294
1295 /* Reset order state */
1296 void
1297 reset_order_state(void)
1298 {
1299 memset(&g_order_state, 0, sizeof(g_order_state));
1300 g_order_state.order_type = RDP_ORDER_PATBLT;
1301 }

  ViewVC Help
Powered by ViewVC 1.1.26