/[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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 24 - (hide annotations)
Sat Jan 6 03:12:10 2001 UTC (23 years, 4 months ago) by matty
File MIME type: text/plain
File size: 19886 byte(s)
ran indent (-bli0 -i8 -cli8 -npcs -npsl)

1 matty 10 /*
2     rdesktop: A Remote Desktop Protocol client.
3     RDP order processing
4     Copyright (C) Matthew Chapman 1999-2000
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 unsigned char *next_packet;
25     static RDP_ORDER_STATE order_state;
26    
27     /* Read field indicating which parameters are present */
28     static void rdp_in_present(STREAM s, uint32 *present, uint8 flags, int size)
29     {
30     uint8 bits;
31     int i;
32    
33     if (flags & RDP_ORDER_SMALL)
34     {
35     size--;
36     }
37    
38     if (flags & RDP_ORDER_TINY)
39     {
40     if (size < 2)
41     size = 0;
42     else
43     size -= 2;
44     }
45    
46     *present = 0;
47     for (i = 0; i < size; i++)
48     {
49     in_uint8(s, bits);
50     *present |= bits << (i * 8);
51     }
52     }
53    
54     /* Read a co-ordinate (16-bit, or 8-bit delta) */
55     static void rdp_in_coord(STREAM s, uint16 *coord, BOOL delta)
56     {
57     uint8 change;
58    
59     if (delta)
60     {
61     in_uint8(s, change);
62 matty 24 *coord += (char) change;
63 matty 10 }
64     else
65     {
66     in_uint16_le(s, *coord);
67     }
68     }
69    
70     /* Read a colour entry */
71     static void rdp_in_colour(STREAM s, uint8 *colour)
72     {
73     in_uint8(s, *colour);
74     s->p += 2;
75     }
76    
77     /* Parse bounds information */
78     static BOOL rdp_parse_bounds(STREAM s, BOUNDS *bounds)
79     {
80     uint8 present;
81    
82     in_uint8(s, present);
83    
84     if (present & 1)
85     rdp_in_coord(s, &bounds->left, False);
86     else if (present & 16)
87     rdp_in_coord(s, &bounds->left, True);
88    
89     if (present & 2)
90     rdp_in_coord(s, &bounds->top, False);
91     else if (present & 32)
92     rdp_in_coord(s, &bounds->top, True);
93    
94     if (present & 4)
95     rdp_in_coord(s, &bounds->right, False);
96     else if (present & 64)
97     rdp_in_coord(s, &bounds->right, True);
98    
99     if (present & 8)
100     rdp_in_coord(s, &bounds->bottom, False);
101     else if (present & 128)
102     rdp_in_coord(s, &bounds->bottom, True);
103    
104     return s_check(s);
105     }
106    
107     /* Parse a pen */
108     static BOOL rdp_parse_pen(STREAM s, PEN *pen, uint32 present)
109     {
110     if (present & 1)
111     in_uint8(s, pen->style);
112    
113     if (present & 2)
114     in_uint8(s, pen->width);
115    
116     if (present & 4)
117     rdp_in_colour(s, &pen->colour);
118    
119     return s_check(s);
120     }
121    
122     /* Parse a brush */
123     static BOOL rdp_parse_brush(STREAM s, BRUSH *brush, uint32 present)
124     {
125     if (present & 1)
126     in_uint8(s, brush->xorigin);
127    
128     if (present & 2)
129     in_uint8(s, brush->yorigin);
130    
131     if (present & 4)
132     in_uint8(s, brush->style);
133    
134     if (present & 8)
135     in_uint8(s, brush->pattern[0]);
136    
137     if (present & 16)
138     in_uint8a(s, &brush->pattern[1], 7);
139    
140     return s_check(s);
141     }
142    
143     /* Process a destination blt order */
144     static void process_destblt(STREAM s, DESTBLT_ORDER *os,
145 matty 24 uint32 present, BOOL delta)
146 matty 10 {
147     if (present & 0x01)
148     rdp_in_coord(s, &os->x, delta);
149    
150     if (present & 0x02)
151     rdp_in_coord(s, &os->y, delta);
152    
153     if (present & 0x04)
154     rdp_in_coord(s, &os->cx, delta);
155    
156     if (present & 0x08)
157     rdp_in_coord(s, &os->cy, delta);
158    
159     if (present & 0x10)
160     in_uint8(s, os->opcode);
161    
162     DEBUG("DESTBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d)\n",
163     os->opcode, os->x, os->y, os->cx, os->cy);
164    
165     ui_destblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy);
166     }
167    
168     /* Process a pattern blt order */
169     static void process_patblt(STREAM s, PATBLT_ORDER *os,
170 matty 24 uint32 present, BOOL delta)
171 matty 10 {
172     if (present & 0x0001)
173     rdp_in_coord(s, &os->x, delta);
174    
175     if (present & 0x0002)
176     rdp_in_coord(s, &os->y, delta);
177    
178     if (present & 0x0004)
179     rdp_in_coord(s, &os->cx, delta);
180    
181     if (present & 0x0008)
182     rdp_in_coord(s, &os->cy, delta);
183    
184     if (present & 0x0010)
185     in_uint8(s, os->opcode);
186    
187     if (present & 0x0020)
188     rdp_in_colour(s, &os->bgcolour);
189    
190     if (present & 0x0040)
191     rdp_in_colour(s, &os->fgcolour);
192    
193     rdp_parse_brush(s, &os->brush, present >> 7);
194    
195     DEBUG("PATBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,bs=%d,bg=0x%x,fg=0x%x)\n",
196     os->opcode, os->x, os->y, os->cx, os->cy,
197     os->brush.style, os->bgcolour, os->fgcolour);
198    
199     ui_patblt(ROP2_P(os->opcode), os->x, os->y, os->cx, os->cy,
200 matty 24 &os->brush, os->bgcolour, os->fgcolour);
201 matty 10 }
202    
203     /* Process a screen blt order */
204     static void process_screenblt(STREAM s, SCREENBLT_ORDER *os,
205 matty 24 uint32 present, BOOL delta)
206 matty 10 {
207     if (present & 0x0001)
208     rdp_in_coord(s, &os->x, delta);
209    
210     if (present & 0x0002)
211     rdp_in_coord(s, &os->y, delta);
212    
213     if (present & 0x0004)
214     rdp_in_coord(s, &os->cx, delta);
215    
216     if (present & 0x0008)
217     rdp_in_coord(s, &os->cy, delta);
218    
219     if (present & 0x0010)
220     in_uint8(s, os->opcode);
221    
222     if (present & 0x0020)
223     rdp_in_coord(s, &os->srcx, delta);
224    
225     if (present & 0x0040)
226     rdp_in_coord(s, &os->srcy, delta);
227    
228     DEBUG("SCREENBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,srcx=%d,srcy=%d)\n",
229     os->opcode, os->x, os->y, os->cx, os->cy, os->srcx, os->srcy);
230    
231     ui_screenblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy,
232 matty 24 os->srcx, os->srcy);
233 matty 10 }
234    
235     /* Process a line order */
236     static void process_line(STREAM s, LINE_ORDER *os, uint32 present, BOOL delta)
237     {
238     if (present & 0x0001)
239     in_uint16_le(s, os->mixmode);
240    
241     if (present & 0x0002)
242     rdp_in_coord(s, &os->startx, delta);
243    
244     if (present & 0x0004)
245     rdp_in_coord(s, &os->starty, delta);
246    
247     if (present & 0x0008)
248     rdp_in_coord(s, &os->endx, delta);
249    
250     if (present & 0x0010)
251     rdp_in_coord(s, &os->endy, delta);
252    
253     if (present & 0x0020)
254     rdp_in_colour(s, &os->bgcolour);
255    
256     if (present & 0x0040)
257     in_uint8(s, os->opcode);
258    
259     rdp_parse_pen(s, &os->pen, present >> 7);
260    
261     DEBUG("LINE(op=0x%x,sx=%d,sy=%d,dx=%d,dx=%d,fg=0x%x)\n",
262     os->opcode, os->startx, os->starty, os->endx, os->endy,
263     os->pen.colour);
264    
265     if (os->opcode < 0x01 || os->opcode > 0x10)
266     {
267     ERROR("bad ROP2 0x%x\n", os->opcode);
268     return;
269     }
270    
271 matty 24 ui_line(os->opcode - 1, os->startx, os->starty,
272     os->endx, os->endy, &os->pen);
273 matty 10 }
274    
275     /* Process an opaque rectangle order */
276     static void process_rect(STREAM s, RECT_ORDER *os, uint32 present, BOOL delta)
277     {
278     if (present & 0x01)
279     rdp_in_coord(s, &os->x, delta);
280    
281     if (present & 0x02)
282     rdp_in_coord(s, &os->y, delta);
283    
284     if (present & 0x04)
285     rdp_in_coord(s, &os->cx, delta);
286    
287     if (present & 0x08)
288     rdp_in_coord(s, &os->cy, delta);
289    
290     if (present & 0x10)
291     in_uint8(s, os->colour);
292    
293     DEBUG("RECT(x=%d,y=%d,cx=%d,cy=%d,fg=0x%x)\n",
294     os->x, os->y, os->cx, os->cy, os->colour);
295    
296     ui_rect(os->x, os->y, os->cx, os->cy, os->colour);
297     }
298    
299     /* Process a desktop save order */
300     static void process_desksave(STREAM s, DESKSAVE_ORDER *os,
301 matty 24 uint32 present, BOOL delta)
302 matty 10 {
303     int width, height;
304    
305     if (present & 0x01)
306     in_uint32_le(s, os->offset);
307    
308     if (present & 0x02)
309     rdp_in_coord(s, &os->left, delta);
310    
311     if (present & 0x04)
312     rdp_in_coord(s, &os->top, delta);
313    
314     if (present & 0x08)
315     rdp_in_coord(s, &os->right, delta);
316    
317     if (present & 0x10)
318     rdp_in_coord(s, &os->bottom, delta);
319    
320     if (present & 0x20)
321     in_uint8(s, os->action);
322    
323     DEBUG("DESKSAVE(l=%d,t=%d,r=%d,b=%d,off=%d,op=%d)\n",
324     os->left, os->top, os->right, os->bottom, os->offset,
325     os->action);
326    
327     width = os->right - os->left + 1;
328     height = os->bottom - os->top + 1;
329    
330     if (os->action == 0)
331     ui_desktop_save(os->offset, os->left, os->top, width, height);
332     else
333 matty 24 ui_desktop_restore(os->offset, os->left, os->top, width,
334     height);
335 matty 10 }
336    
337     /* Process a memory blt order */
338     static void process_memblt(STREAM s, MEMBLT_ORDER *os,
339 matty 24 uint32 present, BOOL delta)
340 matty 10 {
341     HBITMAP bitmap;
342    
343     if (present & 0x0001)
344     {
345     in_uint8(s, os->cache_id);
346     in_uint8(s, os->colour_table);
347     }
348    
349     if (present & 0x0002)
350     rdp_in_coord(s, &os->x, delta);
351    
352     if (present & 0x0004)
353     rdp_in_coord(s, &os->y, delta);
354    
355     if (present & 0x0008)
356     rdp_in_coord(s, &os->cx, delta);
357    
358     if (present & 0x0010)
359     rdp_in_coord(s, &os->cy, delta);
360    
361     if (present & 0x0020)
362     in_uint8(s, os->opcode);
363    
364     if (present & 0x0040)
365     rdp_in_coord(s, &os->srcx, delta);
366    
367     if (present & 0x0080)
368     rdp_in_coord(s, &os->srcy, delta);
369    
370     if (present & 0x0100)
371     in_uint16_le(s, os->cache_idx);
372    
373     DEBUG("MEMBLT(op=0x%x,x=%d,y=%d,cx=%d,cy=%d,id=%d,idx=%d)\n",
374     os->opcode, os->x, os->y, os->cx, os->cy, os->cache_id,
375     os->cache_idx);
376    
377     bitmap = cache_get_bitmap(os->cache_id, os->cache_idx);
378     if (bitmap == NULL)
379     return;
380    
381     ui_memblt(ROP2_S(os->opcode), os->x, os->y, os->cx, os->cy,
382 matty 24 bitmap, os->srcx, os->srcy);
383 matty 10 }
384    
385     /* Process a 3-way blt order */
386     static void process_triblt(STREAM s, TRIBLT_ORDER *os,
387 matty 24 uint32 present, BOOL delta)
388 matty 10 {
389     HBITMAP bitmap;
390    
391     if (present & 0x000001)
392     {
393     in_uint8(s, os->cache_id);
394     in_uint8(s, os->colour_table);
395     }
396    
397     if (present & 0x000002)
398     rdp_in_coord(s, &os->x, delta);
399    
400     if (present & 0x000004)
401     rdp_in_coord(s, &os->y, delta);
402    
403     if (present & 0x000008)
404     rdp_in_coord(s, &os->cx, delta);
405    
406     if (present & 0x000010)
407     rdp_in_coord(s, &os->cy, delta);
408    
409     if (present & 0x000020)
410     in_uint8(s, os->opcode);
411    
412     if (present & 0x000040)
413     rdp_in_coord(s, &os->srcx, delta);
414    
415     if (present & 0x000080)
416     rdp_in_coord(s, &os->srcy, delta);
417    
418     if (present & 0x000100)
419     rdp_in_colour(s, &os->bgcolour);
420    
421     if (present & 0x000200)
422     rdp_in_colour(s, &os->fgcolour);
423    
424     rdp_parse_brush(s, &os->brush, present >> 10);
425    
426     if (present & 0x008000)
427     in_uint16_le(s, os->cache_idx);
428    
429     if (present & 0x010000)
430     in_uint16_le(s, os->unknown);
431    
432 matty 24 DEBUG
433     ("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",
434     os->opcode, os->x, os->y, os->cx, os->cy, os->cache_id,
435     os->cache_idx, os->brush.style, os->bgcolour, os->fgcolour);
436 matty 10
437     bitmap = cache_get_bitmap(os->cache_id, os->cache_idx);
438     if (bitmap == NULL)
439     return;
440    
441     ui_triblt(os->opcode, os->x, os->y, os->cx, os->cy,
442 matty 24 bitmap, os->srcx, os->srcy,
443     &os->brush, os->bgcolour, os->fgcolour);
444 matty 10 }
445    
446 matty 15 /* Parse a delta co-ordinate in polyline order form */
447     static int parse_delta(uint8 *buffer, int *offset)
448     {
449     int value = buffer[(*offset)++];
450     int two_byte = value & 0x80;
451    
452 matty 24 if (value & 0x40) /* sign bit */
453 matty 15 value |= ~0x3f;
454     else
455     value &= 0x3f;
456    
457     if (two_byte)
458     value = (value << 8) | buffer[(*offset)++];
459    
460     return value;
461     }
462    
463     /* Process a polyline order */
464     static void process_polyline(STREAM s, POLYLINE_ORDER *os,
465 matty 24 uint32 present, BOOL delta)
466 matty 15 {
467     int index, line, data;
468     int x, y, xfrom, yfrom;
469     uint8 flags = 0;
470     PEN pen;
471    
472     if (present & 0x01)
473     rdp_in_coord(s, &os->x, delta);
474    
475     if (present & 0x02)
476     rdp_in_coord(s, &os->y, delta);
477    
478     if (present & 0x04)
479     in_uint8(s, os->flags);
480    
481     if (present & 0x10)
482     rdp_in_colour(s, &os->fgcolour);
483    
484     if (present & 0x20)
485     in_uint8(s, os->lines);
486    
487     if (present & 0x40)
488     {
489     in_uint8(s, os->datasize);
490     in_uint8a(s, os->data, os->datasize);
491     }
492    
493     DEBUG("POLYLINE(x=%d,y=%d,fl=0x%x,fg=0x%x,n=%d,sz=%d)\n",
494 matty 24 os->x, os->y, os->flags, os->fgcolour, os->lines, os->datasize);
495 matty 15
496     DEBUG("Data: ");
497    
498     for (index = 0; index < os->datasize; index++)
499     DEBUG("%02x ", os->data[index]);
500    
501     DEBUG("\n");
502    
503     x = os->x;
504     y = os->y;
505     pen.style = pen.width = 0;
506     pen.colour = os->fgcolour;
507    
508     index = 0;
509     data = ((os->lines - 1) / 4) + 1;
510     for (line = 0; (line < os->lines) && (data < os->datasize); line++)
511     {
512     xfrom = x;
513     yfrom = y;
514    
515     if (line % 4 == 0)
516     flags = os->data[index++];
517    
518     if ((flags & 0xc0) == 0)
519 matty 24 flags |= 0xc0; /* none = both */
520 matty 15
521     if (flags & 0x40)
522     x += parse_delta(os->data, &data);
523    
524     if (flags & 0x80)
525     y += parse_delta(os->data, &data);
526    
527     ui_line(ROP2_COPY, xfrom, yfrom, x, y, &pen);
528    
529     flags <<= 2;
530     }
531     }
532    
533 matty 10 /* Process a text order */
534 matty 24 static void process_text2(STREAM s, TEXT2_ORDER *os, uint32 present,
535     BOOL delta)
536 matty 10 {
537     DATABLOB *entry;
538     int i;
539    
540     if (present & 0x000001)
541     in_uint8(s, os->font);
542    
543     if (present & 0x000002)
544     in_uint8(s, os->flags);
545    
546     if (present & 0x000004)
547     in_uint8(s, os->unknown);
548    
549     if (present & 0x000008)
550     in_uint8(s, os->mixmode);
551    
552     if (present & 0x000010)
553     rdp_in_colour(s, &os->fgcolour);
554    
555     if (present & 0x000020)
556     rdp_in_colour(s, &os->bgcolour);
557    
558     if (present & 0x000040)
559     in_uint16_le(s, os->clipleft);
560    
561     if (present & 0x000080)
562     in_uint16_le(s, os->cliptop);
563    
564     if (present & 0x000100)
565     in_uint16_le(s, os->clipright);
566    
567     if (present & 0x000200)
568     in_uint16_le(s, os->clipbottom);
569    
570     if (present & 0x000400)
571     in_uint16_le(s, os->boxleft);
572    
573     if (present & 0x000800)
574     in_uint16_le(s, os->boxtop);
575    
576     if (present & 0x001000)
577     in_uint16_le(s, os->boxright);
578    
579     if (present & 0x002000)
580     in_uint16_le(s, os->boxbottom);
581    
582     if (present & 0x080000)
583     in_uint16_le(s, os->x);
584    
585     if (present & 0x100000)
586     in_uint16_le(s, os->y);
587    
588     if (present & 0x200000)
589     {
590     in_uint8(s, os->length);
591     in_uint8a(s, os->text, os->length);
592     }
593    
594 matty 24 DEBUG
595     ("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",
596     os->x, os->y, os->clipleft, os->cliptop, os->clipright,
597     os->clipbottom, os->boxleft, os->boxtop, os->boxright,
598     os->boxbottom, os->fgcolour, os->bgcolour, os->font,
599     os->flags, os->mixmode, os->unknown, os->length);
600 matty 10
601     DEBUG("Text: ");
602    
603     for (i = 0; i < os->length; i++)
604     DEBUG("%02x ", os->text[i]);
605    
606     DEBUG("\n");
607    
608     /* Process special cache strings */
609 matty 15 if ((os->length >= 2) && (os->text[0] == 0xfe))
610 matty 10 {
611     entry = cache_get_text(os->text[1]);
612    
613     if (entry == NULL)
614     return;
615 matty 24
616 matty 10 memcpy(os->text, entry->data, entry->size);
617     os->length = entry->size;
618     }
619 matty 24 else if ((os->length >= 3) && (os->text[os->length - 3] == 0xff))
620 matty 10 {
621     os->length -= 3;
622 matty 24 cache_put_text(os->text[os->length + 1], os->text,
623     os->length);
624 matty 10 }
625    
626 matty 17 ui_draw_text(os->font, os->flags, os->mixmode, os->x, os->y,
627 matty 24 os->clipleft, os->cliptop,
628     os->clipright - os->clipleft,
629     os->clipbottom - os->cliptop,
630     os->boxleft, os->boxtop,
631     os->boxright - os->boxleft,
632     os->boxbottom - os->boxtop,
633     os->bgcolour, os->fgcolour, os->text, os->length);
634 matty 10 }
635    
636     /* Process a raw bitmap cache order */
637     static void process_raw_bmpcache(STREAM s)
638     {
639     HBITMAP bitmap;
640     uint16 cache_idx, bufsize;
641     uint8 cache_id, width, height, bpp;
642     uint8 *data;
643    
644     in_uint8(s, cache_id);
645 matty 24 in_uint8s(s, 1); /* pad */
646 matty 10 in_uint8(s, width);
647     in_uint8(s, height);
648     in_uint8(s, bpp);
649     in_uint16_le(s, bufsize);
650     in_uint16_le(s, cache_idx);
651     in_uint8p(s, data, bufsize);
652    
653     DEBUG("RAW_BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n",
654     width, height, cache_id, cache_idx);
655    
656     bitmap = ui_create_bitmap(width, height, data);
657     cache_put_bitmap(cache_id, cache_idx, bitmap);
658     }
659    
660     /* Process a bitmap cache order */
661     static void process_bmpcache(STREAM s)
662     {
663     HBITMAP bitmap;
664     uint16 cache_idx, size;
665     uint8 cache_id, width, height, bpp;
666     uint8 *data, *bmpdata;
667    
668     in_uint8(s, cache_id);
669 matty 24 in_uint8s(s, 1); /* pad */
670 matty 10 in_uint8(s, width);
671     in_uint8(s, height);
672     in_uint8(s, bpp);
673 matty 24 in_uint8s(s, 2); /* bufsize */
674 matty 10 in_uint16_le(s, cache_idx);
675 matty 24 in_uint8s(s, 2); /* pad */
676 matty 10 in_uint16_le(s, size);
677 matty 24 in_uint8s(s, 4); /* row_size, final_size */
678 matty 10 in_uint8p(s, data, size);
679    
680     DEBUG("BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n",
681     width, height, cache_id, cache_idx);
682    
683     bmpdata = xmalloc(width * height);
684    
685     if (bitmap_decompress(bmpdata, width, height, data, size))
686     {
687     bitmap = ui_create_bitmap(width, height, bmpdata);
688     cache_put_bitmap(cache_id, cache_idx, bitmap);
689     }
690    
691     xfree(bmpdata);
692     }
693    
694     /* Process a colourmap cache order */
695     static void process_colcache(STREAM s)
696     {
697     COLOURENTRY *entry;
698     COLOURMAP map;
699     HCOLOURMAP hmap;
700     uint8 cache_id;
701     int i;
702    
703     in_uint8(s, cache_id);
704     in_uint16_le(s, map.ncolours);
705    
706     map.colours = xmalloc(3 * map.ncolours);
707    
708     for (i = 0; i < map.ncolours; i++)
709     {
710     entry = &map.colours[i];
711     in_uint8(s, entry->blue);
712     in_uint8(s, entry->green);
713     in_uint8(s, entry->red);
714 matty 24 in_uint8s(s, 1); /* pad */
715 matty 10 }
716    
717     DEBUG("COLCACHE(id=%d,n=%d)\n", cache_id, map.ncolours);
718    
719     hmap = ui_create_colourmap(&map);
720     ui_set_colourmap(hmap);
721    
722     xfree(map.colours);
723     }
724    
725     /* Process a font cache order */
726     static void process_fontcache(STREAM s)
727     {
728     HGLYPH bitmap;
729     uint8 font, nglyphs;
730 matty 20 uint16 character, offset, baseline, width, height;
731 matty 24 int i, datasize;
732     uint8 *data;
733 matty 10
734     in_uint8(s, font);
735     in_uint8(s, nglyphs);
736    
737     DEBUG("FONTCACHE(font=%d,n=%d)\n", font, nglyphs);
738    
739     for (i = 0; i < nglyphs; i++)
740     {
741     in_uint16_le(s, character);
742 matty 20 in_uint16_le(s, offset);
743 matty 10 in_uint16_le(s, baseline);
744     in_uint16_le(s, width);
745     in_uint16_le(s, height);
746    
747     datasize = (height * ((width + 7) / 8) + 3) & ~3;
748     in_uint8p(s, data, datasize);
749    
750 matty 23 bitmap = ui_create_glyph(width, height, data);
751 matty 20 cache_put_font(font, character, offset, baseline,
752 matty 24 width, height, bitmap);
753 matty 10 }
754     }
755    
756     /* Process a secondary order */
757     static void process_secondary_order(STREAM s)
758     {
759     uint16 length;
760     uint8 type;
761     uint8 *next_order;
762    
763     in_uint16_le(s, length);
764 matty 24 in_uint8s(s, 2); /* flags */
765 matty 10 in_uint8(s, type);
766    
767     next_order = s->p + length + 7;
768    
769     switch (type)
770     {
771     case RDP_ORDER_RAW_BMPCACHE:
772     process_raw_bmpcache(s);
773     break;
774    
775     case RDP_ORDER_COLCACHE:
776     process_colcache(s);
777     break;
778    
779     case RDP_ORDER_BMPCACHE:
780     process_bmpcache(s);
781     break;
782    
783     case RDP_ORDER_FONTCACHE:
784     process_fontcache(s);
785     break;
786    
787     default:
788     NOTIMP("secondary order %d\n", type);
789     }
790    
791     s->p = next_order;
792     }
793    
794     /* Process an order PDU */
795     void process_orders(STREAM s)
796     {
797     RDP_ORDER_STATE *os = &order_state;
798     uint32 present;
799     uint16 num_orders;
800     uint8 order_flags;
801     int size, processed = 0;
802     BOOL delta;
803    
804 matty 24 in_uint8s(s, 2); /* pad */
805 matty 10 in_uint16_le(s, num_orders);
806 matty 24 in_uint8s(s, 2); /* pad */
807 matty 10
808     while (processed < num_orders)
809     {
810     in_uint8(s, order_flags);
811    
812     if (!(order_flags & RDP_ORDER_STANDARD))
813     {
814     ERROR("order parsing failed\n");
815     break;
816     }
817    
818     if (order_flags & RDP_ORDER_SECONDARY)
819     {
820     process_secondary_order(s);
821     }
822     else
823     {
824     if (order_flags & RDP_ORDER_CHANGE)
825     {
826     in_uint8(s, os->order_type);
827     }
828    
829     switch (os->order_type)
830     {
831     case RDP_ORDER_TRIBLT:
832     case RDP_ORDER_TEXT2:
833     size = 3;
834     break;
835    
836     case RDP_ORDER_PATBLT:
837     case RDP_ORDER_MEMBLT:
838     case RDP_ORDER_LINE:
839     size = 2;
840     break;
841    
842     default:
843     size = 1;
844     }
845    
846     rdp_in_present(s, &present, order_flags, size);
847    
848     if (order_flags & RDP_ORDER_BOUNDS)
849     {
850     if (!(order_flags & RDP_ORDER_LASTBOUNDS))
851     rdp_parse_bounds(s, &os->bounds);
852    
853     ui_set_clip(os->bounds.left,
854 matty 24 os->bounds.top,
855     os->bounds.right -
856     os->bounds.left + 1,
857     os->bounds.bottom -
858     os->bounds.top + 1);
859 matty 10 }
860    
861     delta = order_flags & RDP_ORDER_DELTA;
862    
863     switch (os->order_type)
864     {
865     case RDP_ORDER_DESTBLT:
866     process_destblt(s, &os->destblt,
867     present, delta);
868     break;
869    
870     case RDP_ORDER_PATBLT:
871     process_patblt(s, &os->patblt,
872     present, delta);
873     break;
874    
875     case RDP_ORDER_SCREENBLT:
876     process_screenblt(s, &os->screenblt,
877     present, delta);
878     break;
879    
880     case RDP_ORDER_LINE:
881     process_line(s, &os->line,
882 matty 24 present, delta);
883 matty 10 break;
884    
885     case RDP_ORDER_RECT:
886     process_rect(s, &os->rect,
887     present, delta);
888     break;
889    
890     case RDP_ORDER_DESKSAVE:
891     process_desksave(s, &os->desksave,
892     present, delta);
893     break;
894    
895     case RDP_ORDER_MEMBLT:
896     process_memblt(s, &os->memblt,
897     present, delta);
898     break;
899    
900     case RDP_ORDER_TRIBLT:
901     process_triblt(s, &os->triblt,
902     present, delta);
903     break;
904    
905 matty 15 case RDP_ORDER_POLYLINE:
906     process_polyline(s, &os->polyline,
907     present, delta);
908     break;
909    
910 matty 10 case RDP_ORDER_TEXT2:
911     process_text2(s, &os->text2,
912     present, delta);
913     break;
914    
915     default:
916     NOTIMP("order %d\n", os->order_type);
917     return;
918     }
919    
920     if (order_flags & RDP_ORDER_BOUNDS)
921     ui_reset_clip();
922     }
923    
924     processed++;
925     }
926    
927     if (s->p != next_packet)
928 matty 24 WARN("%d bytes remaining\n", (int) (next_packet - s->p));
929 matty 10 }
930    
931     /* Reset order state */
932     void reset_order_state()
933     {
934     memset(&order_state, 0, sizeof(order_state));
935     }

  ViewVC Help
Powered by ViewVC 1.1.26