/[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 49 - (hide annotations)
Fri Apr 19 12:06:08 2002 UTC (22 years, 1 month ago) by mmihalik
File MIME type: text/plain
File size: 19722 byte(s)
This fixes TEXT2(cache) procesing with corrupted screen with long lines and vertical text.

1 matty 10 /*
2     rdesktop: A Remote Desktop Protocol client.
3     RDP order processing
4 matty 30 Copyright (C) Matthew Chapman 1999-2001
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 matty 28 extern uint8 *next_packet;
25 matty 10 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 37 *coord += (signed 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 matty 30 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 matty 10
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 matty 30 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 matty 10
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 matty 30 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 matty 10
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 matty 30 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 matty 10
272     if (os->opcode < 0x01 || os->opcode > 0x10)
273     {
274 matty 30 error("bad ROP2 0x%x\n", os->opcode);
275 matty 10 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 matty 30 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 matty 10
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 matty 30 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 matty 10
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 matty 30 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 matty 10
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 30 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",
441     os->opcode, os->x, os->y, os->cx, os->cy, os->cache_id,
442     os->cache_idx, os->brush.style, os->bgcolour, os->fgcolour));
443 matty 10
444     bitmap = cache_get_bitmap(os->cache_id, os->cache_idx);
445     if (bitmap == NULL)
446     return;
447    
448     ui_triblt(os->opcode, os->x, os->y, os->cx, os->cy,
449 matty 24 bitmap, os->srcx, os->srcy,
450     &os->brush, os->bgcolour, os->fgcolour);
451 matty 10 }
452    
453 matty 15 /* Parse a delta co-ordinate in polyline order form */
454 matty 25 static int
455     parse_delta(uint8 *buffer, int *offset)
456 matty 15 {
457     int value = buffer[(*offset)++];
458     int two_byte = value & 0x80;
459    
460 matty 24 if (value & 0x40) /* sign bit */
461 matty 15 value |= ~0x3f;
462     else
463     value &= 0x3f;
464    
465     if (two_byte)
466     value = (value << 8) | buffer[(*offset)++];
467    
468     return value;
469     }
470    
471     /* Process a polyline order */
472 matty 25 static void
473     process_polyline(STREAM s, POLYLINE_ORDER *os, uint32 present, BOOL delta)
474 matty 15 {
475     int index, line, data;
476     int x, y, xfrom, yfrom;
477     uint8 flags = 0;
478     PEN pen;
479    
480     if (present & 0x01)
481     rdp_in_coord(s, &os->x, delta);
482    
483     if (present & 0x02)
484     rdp_in_coord(s, &os->y, delta);
485    
486     if (present & 0x04)
487     in_uint8(s, os->flags);
488    
489     if (present & 0x10)
490     rdp_in_colour(s, &os->fgcolour);
491    
492     if (present & 0x20)
493     in_uint8(s, os->lines);
494    
495     if (present & 0x40)
496     {
497     in_uint8(s, os->datasize);
498     in_uint8a(s, os->data, os->datasize);
499     }
500    
501 matty 30 DEBUG(("POLYLINE(x=%d,y=%d,fl=0x%x,fg=0x%x,n=%d,sz=%d)\n",
502     os->x, os->y, os->flags, os->fgcolour, os->lines, os->datasize));
503 matty 15
504 matty 30 DEBUG(("Data: "));
505 matty 15
506     for (index = 0; index < os->datasize; index++)
507 matty 30 DEBUG(("%02x ", os->data[index]));
508 matty 15
509 matty 30 DEBUG(("\n"));
510 matty 15
511     x = os->x;
512     y = os->y;
513     pen.style = pen.width = 0;
514     pen.colour = os->fgcolour;
515    
516     index = 0;
517     data = ((os->lines - 1) / 4) + 1;
518     for (line = 0; (line < os->lines) && (data < os->datasize); line++)
519     {
520     xfrom = x;
521     yfrom = y;
522    
523     if (line % 4 == 0)
524     flags = os->data[index++];
525    
526     if ((flags & 0xc0) == 0)
527 matty 24 flags |= 0xc0; /* none = both */
528 matty 15
529     if (flags & 0x40)
530     x += parse_delta(os->data, &data);
531    
532     if (flags & 0x80)
533     y += parse_delta(os->data, &data);
534    
535 matty 28 ui_line(ROP2_NXOR, xfrom, yfrom, x, y, &pen);
536 matty 15
537     flags <<= 2;
538     }
539     }
540    
541 matty 10 /* Process a text order */
542 matty 25 static void
543     process_text2(STREAM s, TEXT2_ORDER *os, uint32 present, BOOL delta)
544 matty 10 {
545     int i;
546    
547     if (present & 0x000001)
548     in_uint8(s, os->font);
549    
550     if (present & 0x000002)
551     in_uint8(s, os->flags);
552    
553     if (present & 0x000004)
554     in_uint8(s, os->unknown);
555    
556     if (present & 0x000008)
557     in_uint8(s, os->mixmode);
558    
559     if (present & 0x000010)
560     rdp_in_colour(s, &os->fgcolour);
561    
562     if (present & 0x000020)
563     rdp_in_colour(s, &os->bgcolour);
564    
565     if (present & 0x000040)
566     in_uint16_le(s, os->clipleft);
567    
568     if (present & 0x000080)
569     in_uint16_le(s, os->cliptop);
570    
571     if (present & 0x000100)
572     in_uint16_le(s, os->clipright);
573    
574     if (present & 0x000200)
575     in_uint16_le(s, os->clipbottom);
576    
577     if (present & 0x000400)
578     in_uint16_le(s, os->boxleft);
579    
580     if (present & 0x000800)
581     in_uint16_le(s, os->boxtop);
582    
583     if (present & 0x001000)
584     in_uint16_le(s, os->boxright);
585    
586     if (present & 0x002000)
587     in_uint16_le(s, os->boxbottom);
588    
589     if (present & 0x080000)
590     in_uint16_le(s, os->x);
591    
592     if (present & 0x100000)
593     in_uint16_le(s, os->y);
594    
595     if (present & 0x200000)
596     {
597     in_uint8(s, os->length);
598     in_uint8a(s, os->text, os->length);
599     }
600    
601 matty 30 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",
602     os->x, os->y, os->clipleft, os->cliptop, os->clipright,
603     os->clipbottom, os->boxleft, os->boxtop, os->boxright,
604     os->boxbottom, os->fgcolour, os->bgcolour, os->font,
605     os->flags, os->mixmode, os->unknown, os->length));
606 matty 10
607 matty 30 DEBUG(("Text: "));
608 matty 10
609     for (i = 0; i < os->length; i++)
610 matty 30 DEBUG(("%02x ", os->text[i]));
611 matty 10
612 matty 30 DEBUG(("\n"));
613 matty 10
614 matty 17 ui_draw_text(os->font, os->flags, os->mixmode, os->x, os->y,
615 matty 24 os->clipleft, os->cliptop,
616     os->clipright - os->clipleft,
617     os->clipbottom - os->cliptop,
618     os->boxleft, os->boxtop,
619     os->boxright - os->boxleft,
620     os->boxbottom - os->boxtop,
621     os->bgcolour, os->fgcolour, os->text, os->length);
622 matty 10 }
623    
624     /* Process a raw bitmap cache order */
625 matty 25 static void
626     process_raw_bmpcache(STREAM s)
627 matty 10 {
628     HBITMAP bitmap;
629     uint16 cache_idx, bufsize;
630     uint8 cache_id, width, height, bpp;
631 matty 28 uint8 *data, *inverted;
632     int y;
633 matty 10
634     in_uint8(s, cache_id);
635 matty 24 in_uint8s(s, 1); /* pad */
636 matty 10 in_uint8(s, width);
637     in_uint8(s, height);
638     in_uint8(s, bpp);
639     in_uint16_le(s, bufsize);
640     in_uint16_le(s, cache_idx);
641     in_uint8p(s, data, bufsize);
642    
643 matty 30 DEBUG(("RAW_BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n",
644     width, height, cache_id, cache_idx));
645 matty 28 inverted = xmalloc(width * height);
646     for (y = 0; y < height; y++)
647     {
648     memcpy(&inverted[(height - y - 1) * width], &data[y * width],
649     width);
650     }
651 matty 10
652 matty 28 bitmap = ui_create_bitmap(width, height, inverted);
653     xfree(inverted);
654 matty 10 cache_put_bitmap(cache_id, cache_idx, bitmap);
655     }
656    
657     /* Process a bitmap cache order */
658 matty 25 static void
659     process_bmpcache(STREAM s)
660 matty 10 {
661     HBITMAP bitmap;
662     uint16 cache_idx, size;
663     uint8 cache_id, width, height, bpp;
664     uint8 *data, *bmpdata;
665    
666     in_uint8(s, cache_id);
667 matty 24 in_uint8s(s, 1); /* pad */
668 matty 10 in_uint8(s, width);
669     in_uint8(s, height);
670     in_uint8(s, bpp);
671 matty 24 in_uint8s(s, 2); /* bufsize */
672 matty 10 in_uint16_le(s, cache_idx);
673 matty 24 in_uint8s(s, 2); /* pad */
674 matty 10 in_uint16_le(s, size);
675 matty 24 in_uint8s(s, 4); /* row_size, final_size */
676 matty 10 in_uint8p(s, data, size);
677    
678 matty 30 DEBUG(("BMPCACHE(cx=%d,cy=%d,id=%d,idx=%d)\n",
679     width, height, cache_id, cache_idx));
680 matty 10
681     bmpdata = xmalloc(width * height);
682    
683     if (bitmap_decompress(bmpdata, width, height, data, size))
684     {
685     bitmap = ui_create_bitmap(width, height, bmpdata);
686     cache_put_bitmap(cache_id, cache_idx, bitmap);
687     }
688    
689     xfree(bmpdata);
690     }
691    
692     /* Process a colourmap cache order */
693 matty 25 static void
694     process_colcache(STREAM s)
695 matty 10 {
696     COLOURENTRY *entry;
697     COLOURMAP map;
698     HCOLOURMAP hmap;
699     uint8 cache_id;
700     int i;
701    
702     in_uint8(s, cache_id);
703     in_uint16_le(s, map.ncolours);
704    
705     map.colours = xmalloc(3 * map.ncolours);
706    
707     for (i = 0; i < map.ncolours; i++)
708     {
709     entry = &map.colours[i];
710     in_uint8(s, entry->blue);
711     in_uint8(s, entry->green);
712     in_uint8(s, entry->red);
713 matty 24 in_uint8s(s, 1); /* pad */
714 matty 10 }
715    
716 matty 30 DEBUG(("COLCACHE(id=%d,n=%d)\n", cache_id, map.ncolours));
717 matty 10
718     hmap = ui_create_colourmap(&map);
719     ui_set_colourmap(hmap);
720    
721     xfree(map.colours);
722     }
723    
724     /* Process a font cache order */
725 matty 25 static void
726     process_fontcache(STREAM s)
727 matty 10 {
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 matty 30 DEBUG(("FONTCACHE(font=%d,n=%d)\n", font, nglyphs));
738 matty 10
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 matty 25 static void
758     process_secondary_order(STREAM s)
759 matty 10 {
760     uint16 length;
761     uint8 type;
762     uint8 *next_order;
763    
764     in_uint16_le(s, length);
765 matty 24 in_uint8s(s, 2); /* flags */
766 matty 10 in_uint8(s, type);
767    
768     next_order = s->p + length + 7;
769    
770     switch (type)
771     {
772     case RDP_ORDER_RAW_BMPCACHE:
773     process_raw_bmpcache(s);
774     break;
775    
776     case RDP_ORDER_COLCACHE:
777     process_colcache(s);
778     break;
779    
780     case RDP_ORDER_BMPCACHE:
781     process_bmpcache(s);
782     break;
783    
784     case RDP_ORDER_FONTCACHE:
785     process_fontcache(s);
786     break;
787    
788     default:
789 matty 30 unimpl("secondary order %d\n", type);
790 matty 10 }
791    
792     s->p = next_order;
793     }
794    
795     /* Process an order PDU */
796 matty 25 void
797     process_orders(STREAM s)
798 matty 10 {
799     RDP_ORDER_STATE *os = &order_state;
800     uint32 present;
801     uint16 num_orders;
802     uint8 order_flags;
803     int size, processed = 0;
804     BOOL delta;
805    
806 matty 24 in_uint8s(s, 2); /* pad */
807 matty 10 in_uint16_le(s, num_orders);
808 matty 24 in_uint8s(s, 2); /* pad */
809 matty 10
810     while (processed < num_orders)
811     {
812     in_uint8(s, order_flags);
813    
814     if (!(order_flags & RDP_ORDER_STANDARD))
815     {
816 matty 30 error("order parsing failed\n");
817 matty 10 break;
818     }
819    
820     if (order_flags & RDP_ORDER_SECONDARY)
821     {
822     process_secondary_order(s);
823     }
824     else
825     {
826     if (order_flags & RDP_ORDER_CHANGE)
827     {
828     in_uint8(s, os->order_type);
829     }
830    
831     switch (os->order_type)
832     {
833     case RDP_ORDER_TRIBLT:
834     case RDP_ORDER_TEXT2:
835     size = 3;
836     break;
837    
838     case RDP_ORDER_PATBLT:
839     case RDP_ORDER_MEMBLT:
840     case RDP_ORDER_LINE:
841     size = 2;
842     break;
843    
844     default:
845     size = 1;
846     }
847    
848     rdp_in_present(s, &present, order_flags, size);
849    
850     if (order_flags & RDP_ORDER_BOUNDS)
851     {
852     if (!(order_flags & RDP_ORDER_LASTBOUNDS))
853     rdp_parse_bounds(s, &os->bounds);
854    
855     ui_set_clip(os->bounds.left,
856 matty 24 os->bounds.top,
857     os->bounds.right -
858     os->bounds.left + 1,
859     os->bounds.bottom -
860     os->bounds.top + 1);
861 matty 10 }
862    
863     delta = order_flags & RDP_ORDER_DELTA;
864    
865     switch (os->order_type)
866     {
867     case RDP_ORDER_DESTBLT:
868     process_destblt(s, &os->destblt,
869     present, delta);
870     break;
871    
872     case RDP_ORDER_PATBLT:
873     process_patblt(s, &os->patblt,
874     present, delta);
875     break;
876    
877     case RDP_ORDER_SCREENBLT:
878     process_screenblt(s, &os->screenblt,
879     present, delta);
880     break;
881    
882     case RDP_ORDER_LINE:
883     process_line(s, &os->line,
884 matty 24 present, delta);
885 matty 10 break;
886    
887     case RDP_ORDER_RECT:
888     process_rect(s, &os->rect,
889     present, delta);
890     break;
891    
892     case RDP_ORDER_DESKSAVE:
893     process_desksave(s, &os->desksave,
894     present, delta);
895     break;
896    
897     case RDP_ORDER_MEMBLT:
898     process_memblt(s, &os->memblt,
899     present, delta);
900     break;
901    
902     case RDP_ORDER_TRIBLT:
903     process_triblt(s, &os->triblt,
904     present, delta);
905     break;
906    
907 matty 15 case RDP_ORDER_POLYLINE:
908     process_polyline(s, &os->polyline,
909     present, delta);
910     break;
911    
912 matty 10 case RDP_ORDER_TEXT2:
913     process_text2(s, &os->text2,
914     present, delta);
915     break;
916    
917     default:
918 matty 30 unimpl("order %d\n", os->order_type);
919 matty 10 return;
920     }
921    
922     if (order_flags & RDP_ORDER_BOUNDS)
923     ui_reset_clip();
924     }
925    
926     processed++;
927     }
928    
929     if (s->p != next_packet)
930 matty 30 error("%d bytes remaining\n", (int) (next_packet - s->p));
931 matty 10 }
932    
933     /* Reset order state */
934 matty 25 void
935     reset_order_state()
936 matty 10 {
937     memset(&order_state, 0, sizeof(order_state));
938 matty 28 order_state.order_type = RDP_ORDER_PATBLT;
939 matty 10 }

  ViewVC Help
Powered by ViewVC 1.1.26