/[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 25 - (hide annotations)
Sat Jan 6 03:47:04 2001 UTC (23 years, 4 months ago) by matty
File MIME type: text/plain
File size: 19831 byte(s)
Changed indentation style (-psl).

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

  ViewVC Help
Powered by ViewVC 1.1.26