2 * FreeRDP: A Remote Desktop Protocol Implementation
5 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
6 * Copyright 2016 Armin Novak <armin.novak@thincast.com>
7 * Copyright 2016 Thincast Technologies GmbH
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
28 #include <winpr/wtypes.h>
29 #include <winpr/crt.h>
31 #include <freerdp/api.h>
32 #include <freerdp/log.h>
33 #include <freerdp/graphics.h>
34 #include <freerdp/codec/bitmap.h>
35 #include <freerdp/gdi/gdi.h>
39 #include "../cache/glyph.h"
40 #include "../cache/bitmap.h"
41 #include "../cache/brush.h"
42 #include "../cache/cache.h"
44 #define TAG FREERDP_TAG("core.orders")
46 BYTE get_primary_drawing_order_field_bytes(UINT32 orderType, BOOL* pValid)
53 return DSTBLT_ORDER_FIELD_BYTES;
55 return PATBLT_ORDER_FIELD_BYTES;
57 return SCRBLT_ORDER_FIELD_BYTES;
67 return DRAW_NINE_GRID_ORDER_FIELD_BYTES;
69 return MULTI_DRAW_NINE_GRID_ORDER_FIELD_BYTES;
71 return LINE_TO_ORDER_FIELD_BYTES;
73 return OPAQUE_RECT_ORDER_FIELD_BYTES;
75 return SAVE_BITMAP_ORDER_FIELD_BYTES;
79 return MEMBLT_ORDER_FIELD_BYTES;
81 return MEM3BLT_ORDER_FIELD_BYTES;
83 return MULTI_DSTBLT_ORDER_FIELD_BYTES;
85 return MULTI_PATBLT_ORDER_FIELD_BYTES;
87 return MULTI_SCRBLT_ORDER_FIELD_BYTES;
89 return MULTI_OPAQUE_RECT_ORDER_FIELD_BYTES;
91 return FAST_INDEX_ORDER_FIELD_BYTES;
93 return POLYGON_SC_ORDER_FIELD_BYTES;
95 return POLYGON_CB_ORDER_FIELD_BYTES;
97 return POLYLINE_ORDER_FIELD_BYTES;
101 return FAST_GLYPH_ORDER_FIELD_BYTES;
103 return ELLIPSE_SC_ORDER_FIELD_BYTES;
105 return ELLIPSE_CB_ORDER_FIELD_BYTES;
107 return GLYPH_INDEX_ORDER_FIELD_BYTES;
111 WLog_WARN(TAG, "Invalid orderType 0x%08X received", orderType);
116 static BYTE get_cbr2_bpp(UINT32 bpp, BOOL* pValid)
131 WLog_WARN(TAG, "Invalid bpp %" PRIu32, bpp);
138 static BYTE get_bmf_bpp(UINT32 bmf, BOOL* pValid)
142 /* Mask out highest bit */
143 switch (bmf & (~CACHED_BRUSH))
156 WLog_WARN(TAG, "Invalid bmf %" PRIu32, bmf);
162 static BYTE get_bpp_bmf(UINT32 bpp, BOOL* pValid)
179 WLog_WARN(TAG, "Invalid color depth %" PRIu32, bpp);
186 static BOOL check_order_activated(wLog* log, rdpSettings* settings, const char* orderName,
187 BOOL condition, const char* extendedMessage)
191 if (settings->AllowUnanouncedOrdersFromServer)
193 WLog_Print(log, WLOG_WARN,
194 "%s - SERVER BUG: The support for this feature was not announced!",
197 WLog_Print(log, WLOG_WARN, "%s", extendedMessage);
202 WLog_Print(log, WLOG_ERROR,
203 "%s - SERVER BUG: The support for this feature was not announced! Use "
204 "/relax-order-checks to ignore",
207 WLog_Print(log, WLOG_WARN, "%s", extendedMessage);
215 static BOOL check_alt_order_supported(wLog* log, rdpSettings* settings, BYTE orderType,
216 const char* orderName)
218 const char* extendedMessage = NULL;
219 BOOL condition = FALSE;
223 case ORDER_TYPE_CREATE_OFFSCREEN_BITMAP:
224 case ORDER_TYPE_SWITCH_SURFACE:
225 condition = settings->OffscreenSupportLevel != 0;
226 extendedMessage = "Adding +offscreen-cache might mitigate";
229 case ORDER_TYPE_CREATE_NINE_GRID_BITMAP:
230 condition = settings->DrawNineGridEnabled;
233 case ORDER_TYPE_FRAME_MARKER:
234 condition = settings->FrameMarkerCommandEnabled;
237 case ORDER_TYPE_GDIPLUS_FIRST:
238 case ORDER_TYPE_GDIPLUS_NEXT:
239 case ORDER_TYPE_GDIPLUS_END:
240 case ORDER_TYPE_GDIPLUS_CACHE_FIRST:
241 case ORDER_TYPE_GDIPLUS_CACHE_NEXT:
242 case ORDER_TYPE_GDIPLUS_CACHE_END:
243 condition = settings->DrawGdiPlusCacheEnabled;
246 case ORDER_TYPE_WINDOW:
247 condition = settings->RemoteWndSupportLevel != WINDOW_LEVEL_NOT_SUPPORTED;
250 case ORDER_TYPE_STREAM_BITMAP_FIRST:
251 case ORDER_TYPE_STREAM_BITMAP_NEXT:
252 case ORDER_TYPE_COMPDESK_FIRST:
257 WLog_Print(log, WLOG_WARN, "%s - Alternate Secondary Drawing Order UNKNOWN", orderName);
262 return check_order_activated(log, settings, orderName, condition, extendedMessage);
265 static BOOL check_secondary_order_supported(wLog* log, rdpSettings* settings, BYTE orderType,
266 const char* orderName)
268 const char* extendedMessage = NULL;
269 BOOL condition = FALSE;
273 case ORDER_TYPE_BITMAP_UNCOMPRESSED:
274 case ORDER_TYPE_CACHE_BITMAP_COMPRESSED:
275 condition = settings->BitmapCacheEnabled;
276 extendedMessage = "Adding +bitmap-cache might mitigate";
279 case ORDER_TYPE_BITMAP_UNCOMPRESSED_V2:
280 case ORDER_TYPE_BITMAP_COMPRESSED_V2:
281 condition = settings->BitmapCacheEnabled;
282 extendedMessage = "Adding +bitmap-cache might mitigate";
285 case ORDER_TYPE_BITMAP_COMPRESSED_V3:
286 condition = settings->BitmapCacheV3Enabled;
287 extendedMessage = "Adding +bitmap-cache might mitigate";
290 case ORDER_TYPE_CACHE_COLOR_TABLE:
291 condition = (settings->OrderSupport[NEG_MEMBLT_INDEX] ||
292 settings->OrderSupport[NEG_MEM3BLT_INDEX]);
295 case ORDER_TYPE_CACHE_GLYPH:
297 switch (settings->GlyphSupportLevel)
299 case GLYPH_SUPPORT_PARTIAL:
300 case GLYPH_SUPPORT_FULL:
301 case GLYPH_SUPPORT_ENCODE:
305 case GLYPH_SUPPORT_NONE:
313 case ORDER_TYPE_CACHE_BRUSH:
318 WLog_Print(log, WLOG_WARN, "SECONDARY ORDER %s not supported", orderName);
322 return check_order_activated(log, settings, orderName, condition, extendedMessage);
325 static BOOL check_primary_order_supported(wLog* log, rdpSettings* settings, UINT32 orderType,
326 const char* orderName)
328 const char* extendedMessage = NULL;
329 BOOL condition = FALSE;
333 case ORDER_TYPE_DSTBLT:
334 condition = settings->OrderSupport[NEG_DSTBLT_INDEX];
337 case ORDER_TYPE_SCRBLT:
338 condition = settings->OrderSupport[NEG_SCRBLT_INDEX];
341 case ORDER_TYPE_DRAW_NINE_GRID:
342 condition = settings->OrderSupport[NEG_DRAWNINEGRID_INDEX];
345 case ORDER_TYPE_MULTI_DRAW_NINE_GRID:
346 condition = settings->OrderSupport[NEG_MULTI_DRAWNINEGRID_INDEX];
349 case ORDER_TYPE_LINE_TO:
350 condition = settings->OrderSupport[NEG_LINETO_INDEX];
353 /* [MS-RDPEGDI] 2.2.2.2.1.1.2.5 OpaqueRect (OPAQUERECT_ORDER)
354 * suggests that PatBlt and OpaqueRect imply each other. */
355 case ORDER_TYPE_PATBLT:
356 case ORDER_TYPE_OPAQUE_RECT:
357 condition = settings->OrderSupport[NEG_OPAQUE_RECT_INDEX] ||
358 settings->OrderSupport[NEG_PATBLT_INDEX];
361 case ORDER_TYPE_SAVE_BITMAP:
362 condition = settings->OrderSupport[NEG_SAVEBITMAP_INDEX];
365 case ORDER_TYPE_MEMBLT:
366 condition = settings->OrderSupport[NEG_MEMBLT_INDEX];
369 case ORDER_TYPE_MEM3BLT:
370 condition = settings->OrderSupport[NEG_MEM3BLT_INDEX];
373 case ORDER_TYPE_MULTI_DSTBLT:
374 condition = settings->OrderSupport[NEG_MULTIDSTBLT_INDEX];
377 case ORDER_TYPE_MULTI_PATBLT:
378 condition = settings->OrderSupport[NEG_MULTIPATBLT_INDEX];
381 case ORDER_TYPE_MULTI_SCRBLT:
382 condition = settings->OrderSupport[NEG_MULTIDSTBLT_INDEX];
385 case ORDER_TYPE_MULTI_OPAQUE_RECT:
386 condition = settings->OrderSupport[NEG_MULTIOPAQUERECT_INDEX];
389 case ORDER_TYPE_FAST_INDEX:
390 condition = settings->OrderSupport[NEG_FAST_INDEX_INDEX];
393 case ORDER_TYPE_POLYGON_SC:
394 condition = settings->OrderSupport[NEG_POLYGON_SC_INDEX];
397 case ORDER_TYPE_POLYGON_CB:
398 condition = settings->OrderSupport[NEG_POLYGON_CB_INDEX];
401 case ORDER_TYPE_POLYLINE:
402 condition = settings->OrderSupport[NEG_POLYLINE_INDEX];
405 case ORDER_TYPE_FAST_GLYPH:
406 condition = settings->OrderSupport[NEG_FAST_GLYPH_INDEX];
409 case ORDER_TYPE_ELLIPSE_SC:
410 condition = settings->OrderSupport[NEG_ELLIPSE_SC_INDEX];
413 case ORDER_TYPE_ELLIPSE_CB:
414 condition = settings->OrderSupport[NEG_ELLIPSE_CB_INDEX];
417 case ORDER_TYPE_GLYPH_INDEX:
418 condition = settings->OrderSupport[NEG_GLYPH_INDEX_INDEX];
422 WLog_Print(log, WLOG_WARN, "%s Primary Drawing Order not supported", orderName);
426 return check_order_activated(log, settings, orderName, condition, extendedMessage);
429 static const char* primary_order_string(UINT32 orderType)
431 const char* orders[] = { "[0x%02" PRIx8 "] DstBlt",
432 "[0x%02" PRIx8 "] PatBlt",
433 "[0x%02" PRIx8 "] ScrBlt",
434 "[0x%02" PRIx8 "] UNUSED",
435 "[0x%02" PRIx8 "] UNUSED",
436 "[0x%02" PRIx8 "] UNUSED",
437 "[0x%02" PRIx8 "] UNUSED",
438 "[0x%02" PRIx8 "] DrawNineGrid",
439 "[0x%02" PRIx8 "] MultiDrawNineGrid",
440 "[0x%02" PRIx8 "] LineTo",
441 "[0x%02" PRIx8 "] OpaqueRect",
442 "[0x%02" PRIx8 "] SaveBitmap",
443 "[0x%02" PRIx8 "] UNUSED",
444 "[0x%02" PRIx8 "] MemBlt",
445 "[0x%02" PRIx8 "] Mem3Blt",
446 "[0x%02" PRIx8 "] MultiDstBlt",
447 "[0x%02" PRIx8 "] MultiPatBlt",
448 "[0x%02" PRIx8 "] MultiScrBlt",
449 "[0x%02" PRIx8 "] MultiOpaqueRect",
450 "[0x%02" PRIx8 "] FastIndex",
451 "[0x%02" PRIx8 "] PolygonSC",
452 "[0x%02" PRIx8 "] PolygonCB",
453 "[0x%02" PRIx8 "] Polyline",
454 "[0x%02" PRIx8 "] UNUSED",
455 "[0x%02" PRIx8 "] FastGlyph",
456 "[0x%02" PRIx8 "] EllipseSC",
457 "[0x%02" PRIx8 "] EllipseCB",
458 "[0x%02" PRIx8 "] GlyphIndex" };
459 const char* fmt = "[0x%02" PRIx8 "] UNKNOWN";
460 static char buffer[64] = { 0 };
462 if (orderType < ARRAYSIZE(orders))
463 fmt = orders[orderType];
465 sprintf_s(buffer, ARRAYSIZE(buffer), fmt, orderType);
468 static const char* secondary_order_string(UINT32 orderType)
470 const char* orders[] = { "[0x%02" PRIx8 "] Cache Bitmap",
471 "[0x%02" PRIx8 "] Cache Color Table",
472 "[0x%02" PRIx8 "] Cache Bitmap (Compressed)",
473 "[0x%02" PRIx8 "] Cache Glyph",
474 "[0x%02" PRIx8 "] Cache Bitmap V2",
475 "[0x%02" PRIx8 "] Cache Bitmap V2 (Compressed)",
476 "[0x%02" PRIx8 "] UNUSED",
477 "[0x%02" PRIx8 "] Cache Brush",
478 "[0x%02" PRIx8 "] Cache Bitmap V3" };
479 const char* fmt = "[0x%02" PRIx8 "] UNKNOWN";
480 static char buffer[64] = { 0 };
482 if (orderType < ARRAYSIZE(orders))
483 fmt = orders[orderType];
485 sprintf_s(buffer, ARRAYSIZE(buffer), fmt, orderType);
488 static const char* altsec_order_string(BYTE orderType)
490 const char* orders[] = {
491 "[0x%02" PRIx8 "] Switch Surface", "[0x%02" PRIx8 "] Create Offscreen Bitmap",
492 "[0x%02" PRIx8 "] Stream Bitmap First", "[0x%02" PRIx8 "] Stream Bitmap Next",
493 "[0x%02" PRIx8 "] Create NineGrid Bitmap", "[0x%02" PRIx8 "] Draw GDI+ First",
494 "[0x%02" PRIx8 "] Draw GDI+ Next", "[0x%02" PRIx8 "] Draw GDI+ End",
495 "[0x%02" PRIx8 "] Draw GDI+ Cache First", "[0x%02" PRIx8 "] Draw GDI+ Cache Next",
496 "[0x%02" PRIx8 "] Draw GDI+ Cache End", "[0x%02" PRIx8 "] Windowing",
497 "[0x%02" PRIx8 "] Desktop Composition", "[0x%02" PRIx8 "] Frame Marker"
499 const char* fmt = "[0x%02" PRIx8 "] UNKNOWN";
500 static char buffer[64] = { 0 };
502 if (orderType < ARRAYSIZE(orders))
503 fmt = orders[orderType];
505 sprintf_s(buffer, ARRAYSIZE(buffer), fmt, orderType);
509 static INLINE BOOL update_read_coord(wStream* s, INT32* coord, BOOL delta)
516 if (Stream_GetRemainingLength(s) < 1)
519 Stream_Read_INT8(s, lsi8);
524 if (Stream_GetRemainingLength(s) < 2)
527 Stream_Read_INT16(s, lsi16);
533 static INLINE BOOL update_write_coord(wStream* s, INT32 coord)
535 Stream_Write_UINT16(s, coord);
538 static INLINE BOOL update_read_color(wStream* s, UINT32* color)
542 if (Stream_GetRemainingLength(s) < 3)
546 Stream_Read_UINT8(s, byte);
547 *color = (UINT32)byte;
548 Stream_Read_UINT8(s, byte);
549 *color |= ((UINT32)byte << 8) & 0xFF00;
550 Stream_Read_UINT8(s, byte);
551 *color |= ((UINT32)byte << 16) & 0xFF0000;
554 static INLINE BOOL update_write_color(wStream* s, UINT32 color)
557 byte = (color & 0xFF);
558 Stream_Write_UINT8(s, byte);
559 byte = ((color >> 8) & 0xFF);
560 Stream_Write_UINT8(s, byte);
561 byte = ((color >> 16) & 0xFF);
562 Stream_Write_UINT8(s, byte);
565 static INLINE BOOL update_read_colorref(wStream* s, UINT32* color)
569 if (Stream_GetRemainingLength(s) < 4)
573 Stream_Read_UINT8(s, byte);
575 Stream_Read_UINT8(s, byte);
576 *color |= ((UINT32)byte << 8);
577 Stream_Read_UINT8(s, byte);
578 *color |= ((UINT32)byte << 16);
579 Stream_Seek_UINT8(s);
582 static INLINE BOOL update_read_color_quad(wStream* s, UINT32* color)
584 return update_read_colorref(s, color);
586 static INLINE void update_write_color_quad(wStream* s, UINT32 color)
589 byte = (color >> 16) & 0xFF;
590 Stream_Write_UINT8(s, byte);
591 byte = (color >> 8) & 0xFF;
592 Stream_Write_UINT8(s, byte);
594 Stream_Write_UINT8(s, byte);
596 static INLINE BOOL update_read_2byte_unsigned(wStream* s, UINT32* value)
600 if (Stream_GetRemainingLength(s) < 1)
603 Stream_Read_UINT8(s, byte);
607 if (Stream_GetRemainingLength(s) < 1)
610 *value = (byte & 0x7F) << 8;
611 Stream_Read_UINT8(s, byte);
616 *value = (byte & 0x7F);
621 static INLINE BOOL update_write_2byte_unsigned(wStream* s, UINT32 value)
630 byte = ((value & 0x7F00) >> 8);
631 Stream_Write_UINT8(s, byte | 0x80);
632 byte = (value & 0xFF);
633 Stream_Write_UINT8(s, byte);
637 byte = (value & 0x7F);
638 Stream_Write_UINT8(s, byte);
643 static INLINE BOOL update_read_2byte_signed(wStream* s, INT32* value)
648 if (Stream_GetRemainingLength(s) < 1)
651 Stream_Read_UINT8(s, byte);
652 negative = (byte & 0x40) ? TRUE : FALSE;
653 *value = (byte & 0x3F);
657 if (Stream_GetRemainingLength(s) < 1)
660 Stream_Read_UINT8(s, byte);
661 *value = (*value << 8) | byte;
669 static INLINE BOOL update_write_2byte_signed(wStream* s, INT32 value)
672 BOOL negative = FALSE;
685 byte = ((value & 0x3F00) >> 8);
690 Stream_Write_UINT8(s, byte | 0x80);
691 byte = (value & 0xFF);
692 Stream_Write_UINT8(s, byte);
696 byte = (value & 0x3F);
701 Stream_Write_UINT8(s, byte);
706 static INLINE BOOL update_read_4byte_unsigned(wStream* s, UINT32* value)
711 if (Stream_GetRemainingLength(s) < 1)
714 Stream_Read_UINT8(s, byte);
715 count = (byte & 0xC0) >> 6;
717 if (Stream_GetRemainingLength(s) < count)
723 *value = (byte & 0x3F);
727 *value = (byte & 0x3F) << 8;
728 Stream_Read_UINT8(s, byte);
733 *value = (byte & 0x3F) << 16;
734 Stream_Read_UINT8(s, byte);
735 *value |= (byte << 8);
736 Stream_Read_UINT8(s, byte);
741 *value = (byte & 0x3F) << 24;
742 Stream_Read_UINT8(s, byte);
743 *value |= (byte << 16);
744 Stream_Read_UINT8(s, byte);
745 *value |= (byte << 8);
746 Stream_Read_UINT8(s, byte);
756 static INLINE BOOL update_write_4byte_unsigned(wStream* s, UINT32 value)
762 Stream_Write_UINT8(s, value);
764 else if (value <= 0x3FFF)
766 byte = (value >> 8) & 0x3F;
767 Stream_Write_UINT8(s, byte | 0x40);
768 byte = (value & 0xFF);
769 Stream_Write_UINT8(s, byte);
771 else if (value <= 0x3FFFFF)
773 byte = (value >> 16) & 0x3F;
774 Stream_Write_UINT8(s, byte | 0x80);
775 byte = (value >> 8) & 0xFF;
776 Stream_Write_UINT8(s, byte);
777 byte = (value & 0xFF);
778 Stream_Write_UINT8(s, byte);
780 else if (value <= 0x3FFFFFFF)
782 byte = (value >> 24) & 0x3F;
783 Stream_Write_UINT8(s, byte | 0xC0);
784 byte = (value >> 16) & 0xFF;
785 Stream_Write_UINT8(s, byte);
786 byte = (value >> 8) & 0xFF;
787 Stream_Write_UINT8(s, byte);
788 byte = (value & 0xFF);
789 Stream_Write_UINT8(s, byte);
796 static INLINE BOOL update_read_delta(wStream* s, INT32* value)
800 if (Stream_GetRemainingLength(s) < 1)
802 WLog_ERR(TAG, "Stream_GetRemainingLength(s) < 1");
806 Stream_Read_UINT8(s, byte);
809 *value = (byte | ~0x3F);
811 *value = (byte & 0x3F);
815 if (Stream_GetRemainingLength(s) < 1)
817 WLog_ERR(TAG, "Stream_GetRemainingLength(s) < 1");
821 Stream_Read_UINT8(s, byte);
822 *value = (*value << 8) | byte;
828 static INLINE void update_read_glyph_delta(wStream* s, UINT16* value)
831 Stream_Read_UINT8(s, byte);
834 Stream_Read_UINT16(s, *value);
836 *value = (byte & 0x3F);
838 static INLINE void update_seek_glyph_delta(wStream* s)
841 Stream_Read_UINT8(s, byte);
844 Stream_Seek_UINT8(s);
847 static INLINE BOOL update_read_brush(wStream* s, rdpBrush* brush, BYTE fieldFlags)
849 if (fieldFlags & ORDER_FIELD_01)
851 if (Stream_GetRemainingLength(s) < 1)
854 Stream_Read_UINT8(s, brush->x);
857 if (fieldFlags & ORDER_FIELD_02)
859 if (Stream_GetRemainingLength(s) < 1)
862 Stream_Read_UINT8(s, brush->y);
865 if (fieldFlags & ORDER_FIELD_03)
867 if (Stream_GetRemainingLength(s) < 1)
870 Stream_Read_UINT8(s, brush->style);
873 if (fieldFlags & ORDER_FIELD_04)
875 if (Stream_GetRemainingLength(s) < 1)
878 Stream_Read_UINT8(s, brush->hatch);
881 if (brush->style & CACHED_BRUSH)
884 brush->index = brush->hatch;
885 brush->bpp = get_bmf_bpp(brush->style, &rc);
892 if (fieldFlags & ORDER_FIELD_05)
894 if (Stream_GetRemainingLength(s) < 7)
897 brush->data = (BYTE*)brush->p8x8;
898 Stream_Read_UINT8(s, brush->data[7]);
899 Stream_Read_UINT8(s, brush->data[6]);
900 Stream_Read_UINT8(s, brush->data[5]);
901 Stream_Read_UINT8(s, brush->data[4]);
902 Stream_Read_UINT8(s, brush->data[3]);
903 Stream_Read_UINT8(s, brush->data[2]);
904 Stream_Read_UINT8(s, brush->data[1]);
905 brush->data[0] = brush->hatch;
910 static INLINE BOOL update_write_brush(wStream* s, rdpBrush* brush, BYTE fieldFlags)
912 if (fieldFlags & ORDER_FIELD_01)
914 Stream_Write_UINT8(s, brush->x);
917 if (fieldFlags & ORDER_FIELD_02)
919 Stream_Write_UINT8(s, brush->y);
922 if (fieldFlags & ORDER_FIELD_03)
924 Stream_Write_UINT8(s, brush->style);
927 if (brush->style & CACHED_BRUSH)
930 brush->hatch = brush->index;
931 brush->bpp = get_bmf_bpp(brush->style, &rc);
938 if (fieldFlags & ORDER_FIELD_04)
940 Stream_Write_UINT8(s, brush->hatch);
943 if (fieldFlags & ORDER_FIELD_05)
945 brush->data = (BYTE*)brush->p8x8;
946 Stream_Write_UINT8(s, brush->data[7]);
947 Stream_Write_UINT8(s, brush->data[6]);
948 Stream_Write_UINT8(s, brush->data[5]);
949 Stream_Write_UINT8(s, brush->data[4]);
950 Stream_Write_UINT8(s, brush->data[3]);
951 Stream_Write_UINT8(s, brush->data[2]);
952 Stream_Write_UINT8(s, brush->data[1]);
953 brush->data[0] = brush->hatch;
958 static INLINE BOOL update_read_delta_rects(wStream* s, DELTA_RECT* rectangles, UINT32* nr)
968 WLog_WARN(TAG, "Invalid number of delta rectangles %" PRIu32, number);
972 zeroBitsSize = ((number + 1) / 2);
974 if (Stream_GetRemainingLength(s) < zeroBitsSize)
977 Stream_GetPointer(s, zeroBits);
978 Stream_Seek(s, zeroBitsSize);
979 ZeroMemory(rectangles, sizeof(DELTA_RECT) * number);
981 for (i = 0; i < number; i++)
984 flags = zeroBits[i / 2];
986 if ((~flags & 0x80) && !update_read_delta(s, &rectangles[i].left))
989 if ((~flags & 0x40) && !update_read_delta(s, &rectangles[i].top))
994 if (!update_read_delta(s, &rectangles[i].width))
998 rectangles[i].width = rectangles[i - 1].width;
1000 rectangles[i].width = 0;
1004 if (!update_read_delta(s, &rectangles[i].height))
1008 rectangles[i].height = rectangles[i - 1].height;
1010 rectangles[i].height = 0;
1014 rectangles[i].left += rectangles[i - 1].left;
1015 rectangles[i].top += rectangles[i - 1].top;
1023 static INLINE BOOL update_read_delta_points(wStream* s, DELTA_POINT* points, int number, INT16 x,
1029 UINT32 zeroBitsSize;
1030 zeroBitsSize = ((number + 3) / 4);
1032 if (Stream_GetRemainingLength(s) < zeroBitsSize)
1034 WLog_ERR(TAG, "Stream_GetRemainingLength(s) < %" PRIu32 "", zeroBitsSize);
1038 Stream_GetPointer(s, zeroBits);
1039 Stream_Seek(s, zeroBitsSize);
1040 ZeroMemory(points, sizeof(DELTA_POINT) * number);
1042 for (i = 0; i < number; i++)
1045 flags = zeroBits[i / 4];
1047 if ((~flags & 0x80) && !update_read_delta(s, &points[i].x))
1049 WLog_ERR(TAG, "update_read_delta(x) failed");
1053 if ((~flags & 0x40) && !update_read_delta(s, &points[i].y))
1055 WLog_ERR(TAG, "update_read_delta(y) failed");
1065 static INLINE BOOL read_order_field_byte(const ORDER_INFO* orderInfo, wStream* s, BYTE number,
1066 UINT32* target, BOOL optional)
1068 const BOOL set = orderInfo->fieldFlags & (1 << (number - 1));
1071 if (Stream_GetRemainingLength(s) < 1)
1073 Stream_Read_UINT8(s, *target);
1077 static INLINE BOOL read_order_field_2bytes(const ORDER_INFO* orderInfo, wStream* s, BYTE number,
1078 UINT32* target1, UINT32* target2, BOOL optional)
1080 const BOOL set = orderInfo->fieldFlags & (1 << (number - 1));
1083 if (Stream_GetRemainingLength(s) < 2)
1085 Stream_Read_UINT8(s, *target1);
1086 Stream_Read_UINT8(s, *target2);
1090 static INLINE BOOL read_order_field_uint16(const ORDER_INFO* orderInfo, wStream* s, BYTE number,
1091 UINT32* target, BOOL optional)
1093 const BOOL set = orderInfo->fieldFlags & (1 << (number - 1));
1097 if (Stream_GetRemainingLength(s) < 2)
1100 Stream_Read_UINT16(s, *target);
1104 static INLINE BOOL read_order_field_int16(const ORDER_INFO* orderInfo, wStream* s, BYTE number,
1105 INT32* target, BOOL optional)
1107 const BOOL set = orderInfo->fieldFlags & (1 << (number - 1));
1111 if (Stream_GetRemainingLength(s) < 2)
1114 Stream_Read_INT16(s, *target);
1118 static INLINE BOOL read_order_field_uint32(const ORDER_INFO* orderInfo, wStream* s, BYTE number,
1119 UINT32* target, BOOL optional)
1121 const BOOL set = orderInfo->fieldFlags & (1 << (number - 1));
1124 if (Stream_GetRemainingLength(s) < 4)
1127 Stream_Read_UINT32(s, *target);
1131 static INLINE BOOL read_order_field_coord(const ORDER_INFO* orderInfo, wStream* s, UINT32 NO,
1132 INT32* TARGET, BOOL optional)
1134 const BOOL set = (orderInfo->fieldFlags & (1 << (NO - 1)));
1135 if (!TARGET || !orderInfo)
1140 return update_read_coord(s, TARGET, orderInfo->deltaCoordinates);
1143 static INLINE BOOL read_order_field_color(const ORDER_INFO* orderInfo, wStream* s, UINT32 NO,
1144 UINT32* TARGET, BOOL optional)
1146 const BOOL set = (orderInfo->fieldFlags & (1 << (NO - 1)));
1147 if (!TARGET || !orderInfo)
1152 if (!update_read_color(s, TARGET))
1157 static INLINE BOOL FIELD_SKIP_BUFFER16(wStream* s, UINT32 TARGET_LEN)
1159 if (Stream_GetRemainingLength(s) < 2)
1162 Stream_Read_UINT16(s, TARGET_LEN);
1164 if (!Stream_SafeSeek(s, TARGET_LEN))
1166 WLog_ERR(TAG, "error skipping %" PRIu32 " bytes", TARGET_LEN);
1172 /* Primary Drawing Orders */
1173 static BOOL update_read_dstblt_order(wStream* s, const ORDER_INFO* orderInfo, DSTBLT_ORDER* dstblt)
1175 if (!read_order_field_coord(orderInfo, s, 1, &dstblt->nLeftRect, FALSE) ||
1176 !read_order_field_coord(orderInfo, s, 2, &dstblt->nTopRect, FALSE) ||
1177 !read_order_field_coord(orderInfo, s, 3, &dstblt->nWidth, FALSE) ||
1178 !read_order_field_coord(orderInfo, s, 4, &dstblt->nHeight, FALSE) ||
1179 !read_order_field_byte(orderInfo, s, 5, &dstblt->bRop, TRUE))
1183 int update_approximate_dstblt_order(ORDER_INFO* orderInfo, const DSTBLT_ORDER* dstblt)
1187 BOOL update_write_dstblt_order(wStream* s, ORDER_INFO* orderInfo, const DSTBLT_ORDER* dstblt)
1189 if (!Stream_EnsureRemainingCapacity(s, update_approximate_dstblt_order(orderInfo, dstblt)))
1192 orderInfo->fieldFlags = 0;
1193 orderInfo->fieldFlags |= ORDER_FIELD_01;
1194 update_write_coord(s, dstblt->nLeftRect);
1195 orderInfo->fieldFlags |= ORDER_FIELD_02;
1196 update_write_coord(s, dstblt->nTopRect);
1197 orderInfo->fieldFlags |= ORDER_FIELD_03;
1198 update_write_coord(s, dstblt->nWidth);
1199 orderInfo->fieldFlags |= ORDER_FIELD_04;
1200 update_write_coord(s, dstblt->nHeight);
1201 orderInfo->fieldFlags |= ORDER_FIELD_05;
1202 Stream_Write_UINT8(s, dstblt->bRop);
1205 static BOOL update_read_patblt_order(wStream* s, const ORDER_INFO* orderInfo, PATBLT_ORDER* patblt)
1207 if (!read_order_field_coord(orderInfo, s, 1, &patblt->nLeftRect, FALSE) ||
1208 !read_order_field_coord(orderInfo, s, 2, &patblt->nTopRect, FALSE) ||
1209 !read_order_field_coord(orderInfo, s, 3, &patblt->nWidth, FALSE) ||
1210 !read_order_field_coord(orderInfo, s, 4, &patblt->nHeight, FALSE) ||
1211 !read_order_field_byte(orderInfo, s, 5, &patblt->bRop, TRUE) ||
1212 !read_order_field_color(orderInfo, s, 6, &patblt->backColor, TRUE) ||
1213 !read_order_field_color(orderInfo, s, 7, &patblt->foreColor, TRUE))
1215 return update_read_brush(s, &patblt->brush, orderInfo->fieldFlags >> 7);
1217 int update_approximate_patblt_order(ORDER_INFO* orderInfo, PATBLT_ORDER* patblt)
1221 BOOL update_write_patblt_order(wStream* s, ORDER_INFO* orderInfo, PATBLT_ORDER* patblt)
1223 if (!Stream_EnsureRemainingCapacity(s, update_approximate_patblt_order(orderInfo, patblt)))
1226 orderInfo->fieldFlags = 0;
1227 orderInfo->fieldFlags |= ORDER_FIELD_01;
1228 update_write_coord(s, patblt->nLeftRect);
1229 orderInfo->fieldFlags |= ORDER_FIELD_02;
1230 update_write_coord(s, patblt->nTopRect);
1231 orderInfo->fieldFlags |= ORDER_FIELD_03;
1232 update_write_coord(s, patblt->nWidth);
1233 orderInfo->fieldFlags |= ORDER_FIELD_04;
1234 update_write_coord(s, patblt->nHeight);
1235 orderInfo->fieldFlags |= ORDER_FIELD_05;
1236 Stream_Write_UINT8(s, patblt->bRop);
1237 orderInfo->fieldFlags |= ORDER_FIELD_06;
1238 update_write_color(s, patblt->backColor);
1239 orderInfo->fieldFlags |= ORDER_FIELD_07;
1240 update_write_color(s, patblt->foreColor);
1241 orderInfo->fieldFlags |= ORDER_FIELD_08;
1242 orderInfo->fieldFlags |= ORDER_FIELD_09;
1243 orderInfo->fieldFlags |= ORDER_FIELD_10;
1244 orderInfo->fieldFlags |= ORDER_FIELD_11;
1245 orderInfo->fieldFlags |= ORDER_FIELD_12;
1246 update_write_brush(s, &patblt->brush, orderInfo->fieldFlags >> 7);
1249 static BOOL update_read_scrblt_order(wStream* s, const ORDER_INFO* orderInfo, SCRBLT_ORDER* scrblt)
1251 if (!read_order_field_coord(orderInfo, s, 1, &scrblt->nLeftRect, FALSE) ||
1252 !read_order_field_coord(orderInfo, s, 2, &scrblt->nTopRect, FALSE) ||
1253 !read_order_field_coord(orderInfo, s, 3, &scrblt->nWidth, FALSE) ||
1254 !read_order_field_coord(orderInfo, s, 4, &scrblt->nHeight, FALSE) ||
1255 !read_order_field_byte(orderInfo, s, 5, &scrblt->bRop, TRUE) ||
1256 !read_order_field_coord(orderInfo, s, 6, &scrblt->nXSrc, FALSE) ||
1257 !read_order_field_coord(orderInfo, s, 7, &scrblt->nYSrc, FALSE))
1261 int update_approximate_scrblt_order(ORDER_INFO* orderInfo, const SCRBLT_ORDER* scrblt)
1265 BOOL update_write_scrblt_order(wStream* s, ORDER_INFO* orderInfo, const SCRBLT_ORDER* scrblt)
1267 if (!Stream_EnsureRemainingCapacity(s, update_approximate_scrblt_order(orderInfo, scrblt)))
1270 orderInfo->fieldFlags = 0;
1271 orderInfo->fieldFlags |= ORDER_FIELD_01;
1272 update_write_coord(s, scrblt->nLeftRect);
1273 orderInfo->fieldFlags |= ORDER_FIELD_02;
1274 update_write_coord(s, scrblt->nTopRect);
1275 orderInfo->fieldFlags |= ORDER_FIELD_03;
1276 update_write_coord(s, scrblt->nWidth);
1277 orderInfo->fieldFlags |= ORDER_FIELD_04;
1278 update_write_coord(s, scrblt->nHeight);
1279 orderInfo->fieldFlags |= ORDER_FIELD_05;
1280 Stream_Write_UINT8(s, scrblt->bRop);
1281 orderInfo->fieldFlags |= ORDER_FIELD_06;
1282 update_write_coord(s, scrblt->nXSrc);
1283 orderInfo->fieldFlags |= ORDER_FIELD_07;
1284 update_write_coord(s, scrblt->nYSrc);
1287 static BOOL update_read_opaque_rect_order(wStream* s, const ORDER_INFO* orderInfo,
1288 OPAQUE_RECT_ORDER* opaque_rect)
1291 if (!read_order_field_coord(orderInfo, s, 1, &opaque_rect->nLeftRect, FALSE) ||
1292 !read_order_field_coord(orderInfo, s, 2, &opaque_rect->nTopRect, FALSE) ||
1293 !read_order_field_coord(orderInfo, s, 3, &opaque_rect->nWidth, FALSE) ||
1294 !read_order_field_coord(orderInfo, s, 4, &opaque_rect->nHeight, FALSE))
1297 if ((orderInfo->fieldFlags & ORDER_FIELD_05) != 0)
1299 if (Stream_GetRemainingLength(s) < 1)
1302 Stream_Read_UINT8(s, byte);
1303 opaque_rect->color = (opaque_rect->color & 0x00FFFF00) | ((UINT32)byte);
1306 if ((orderInfo->fieldFlags & ORDER_FIELD_06) != 0)
1308 if (Stream_GetRemainingLength(s) < 1)
1311 Stream_Read_UINT8(s, byte);
1312 opaque_rect->color = (opaque_rect->color & 0x00FF00FF) | ((UINT32)byte << 8);
1315 if ((orderInfo->fieldFlags & ORDER_FIELD_07) != 0)
1317 if (Stream_GetRemainingLength(s) < 1)
1320 Stream_Read_UINT8(s, byte);
1321 opaque_rect->color = (opaque_rect->color & 0x0000FFFF) | ((UINT32)byte << 16);
1326 int update_approximate_opaque_rect_order(ORDER_INFO* orderInfo,
1327 const OPAQUE_RECT_ORDER* opaque_rect)
1331 BOOL update_write_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo,
1332 const OPAQUE_RECT_ORDER* opaque_rect)
1335 int inf = update_approximate_opaque_rect_order(orderInfo, opaque_rect);
1337 if (!Stream_EnsureRemainingCapacity(s, inf))
1340 // TODO: Color format conversion
1341 orderInfo->fieldFlags = 0;
1342 orderInfo->fieldFlags |= ORDER_FIELD_01;
1343 update_write_coord(s, opaque_rect->nLeftRect);
1344 orderInfo->fieldFlags |= ORDER_FIELD_02;
1345 update_write_coord(s, opaque_rect->nTopRect);
1346 orderInfo->fieldFlags |= ORDER_FIELD_03;
1347 update_write_coord(s, opaque_rect->nWidth);
1348 orderInfo->fieldFlags |= ORDER_FIELD_04;
1349 update_write_coord(s, opaque_rect->nHeight);
1350 orderInfo->fieldFlags |= ORDER_FIELD_05;
1351 byte = opaque_rect->color & 0x000000FF;
1352 Stream_Write_UINT8(s, byte);
1353 orderInfo->fieldFlags |= ORDER_FIELD_06;
1354 byte = (opaque_rect->color & 0x0000FF00) >> 8;
1355 Stream_Write_UINT8(s, byte);
1356 orderInfo->fieldFlags |= ORDER_FIELD_07;
1357 byte = (opaque_rect->color & 0x00FF0000) >> 16;
1358 Stream_Write_UINT8(s, byte);
1361 static BOOL update_read_draw_nine_grid_order(wStream* s, const ORDER_INFO* orderInfo,
1362 DRAW_NINE_GRID_ORDER* draw_nine_grid)
1364 if (!read_order_field_coord(orderInfo, s, 1, &draw_nine_grid->srcLeft, FALSE) ||
1365 !read_order_field_coord(orderInfo, s, 2, &draw_nine_grid->srcTop, FALSE) ||
1366 !read_order_field_coord(orderInfo, s, 3, &draw_nine_grid->srcRight, FALSE) ||
1367 !read_order_field_coord(orderInfo, s, 4, &draw_nine_grid->srcBottom, FALSE) ||
1368 !read_order_field_uint16(orderInfo, s, 5, &draw_nine_grid->bitmapId, FALSE))
1372 static BOOL update_read_multi_dstblt_order(wStream* s, const ORDER_INFO* orderInfo,
1373 MULTI_DSTBLT_ORDER* multi_dstblt)
1375 if (!read_order_field_coord(orderInfo, s, 1, &multi_dstblt->nLeftRect, FALSE) ||
1376 !read_order_field_coord(orderInfo, s, 2, &multi_dstblt->nTopRect, FALSE) ||
1377 !read_order_field_coord(orderInfo, s, 3, &multi_dstblt->nWidth, FALSE) ||
1378 !read_order_field_coord(orderInfo, s, 4, &multi_dstblt->nHeight, FALSE) ||
1379 !read_order_field_byte(orderInfo, s, 5, &multi_dstblt->bRop, TRUE) ||
1380 !read_order_field_byte(orderInfo, s, 6, &multi_dstblt->numRectangles, TRUE))
1383 if ((orderInfo->fieldFlags & ORDER_FIELD_07) != 0)
1385 if (Stream_GetRemainingLength(s) < 2)
1388 Stream_Read_UINT16(s, multi_dstblt->cbData);
1389 return update_read_delta_rects(s, multi_dstblt->rectangles, &multi_dstblt->numRectangles);
1394 static BOOL update_read_multi_patblt_order(wStream* s, const ORDER_INFO* orderInfo,
1395 MULTI_PATBLT_ORDER* multi_patblt)
1397 if (!read_order_field_coord(orderInfo, s, 1, &multi_patblt->nLeftRect, FALSE) ||
1398 !read_order_field_coord(orderInfo, s, 2, &multi_patblt->nTopRect, FALSE) ||
1399 !read_order_field_coord(orderInfo, s, 3, &multi_patblt->nWidth, FALSE) ||
1400 !read_order_field_coord(orderInfo, s, 4, &multi_patblt->nHeight, FALSE) ||
1401 !read_order_field_byte(orderInfo, s, 5, &multi_patblt->bRop, TRUE) ||
1402 !read_order_field_color(orderInfo, s, 6, &multi_patblt->backColor, TRUE) ||
1403 !read_order_field_color(orderInfo, s, 7, &multi_patblt->foreColor, TRUE))
1406 if (!update_read_brush(s, &multi_patblt->brush, orderInfo->fieldFlags >> 7))
1409 if (!read_order_field_byte(orderInfo, s, 13, &multi_patblt->numRectangles, TRUE))
1412 if ((orderInfo->fieldFlags & ORDER_FIELD_14) != 0)
1414 if (Stream_GetRemainingLength(s) < 2)
1417 Stream_Read_UINT16(s, multi_patblt->cbData);
1419 if (!update_read_delta_rects(s, multi_patblt->rectangles, &multi_patblt->numRectangles))
1425 static BOOL update_read_multi_scrblt_order(wStream* s, const ORDER_INFO* orderInfo,
1426 MULTI_SCRBLT_ORDER* multi_scrblt)
1428 if (!read_order_field_coord(orderInfo, s, 1, &multi_scrblt->nLeftRect, FALSE) ||
1429 !read_order_field_coord(orderInfo, s, 2, &multi_scrblt->nTopRect, FALSE) ||
1430 !read_order_field_coord(orderInfo, s, 3, &multi_scrblt->nWidth, FALSE) ||
1431 !read_order_field_coord(orderInfo, s, 4, &multi_scrblt->nHeight, FALSE) ||
1432 !read_order_field_byte(orderInfo, s, 5, &multi_scrblt->bRop, TRUE) ||
1433 !read_order_field_coord(orderInfo, s, 6, &multi_scrblt->nXSrc, FALSE) ||
1434 !read_order_field_coord(orderInfo, s, 7, &multi_scrblt->nYSrc, FALSE) ||
1435 !read_order_field_byte(orderInfo, s, 8, &multi_scrblt->numRectangles, TRUE))
1438 if ((orderInfo->fieldFlags & ORDER_FIELD_09) != 0)
1440 if (Stream_GetRemainingLength(s) < 2)
1443 Stream_Read_UINT16(s, multi_scrblt->cbData);
1444 return update_read_delta_rects(s, multi_scrblt->rectangles, &multi_scrblt->numRectangles);
1449 static BOOL update_read_multi_opaque_rect_order(wStream* s, const ORDER_INFO* orderInfo,
1450 MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect)
1453 if (!read_order_field_coord(orderInfo, s, 1, &multi_opaque_rect->nLeftRect, FALSE) ||
1454 !read_order_field_coord(orderInfo, s, 2, &multi_opaque_rect->nTopRect, FALSE) ||
1455 !read_order_field_coord(orderInfo, s, 3, &multi_opaque_rect->nWidth, FALSE) ||
1456 !read_order_field_coord(orderInfo, s, 4, &multi_opaque_rect->nHeight, FALSE))
1459 if ((orderInfo->fieldFlags & ORDER_FIELD_05) != 0)
1461 if (Stream_GetRemainingLength(s) < 1)
1464 Stream_Read_UINT8(s, byte);
1465 multi_opaque_rect->color = (multi_opaque_rect->color & 0x00FFFF00) | ((UINT32)byte);
1468 if ((orderInfo->fieldFlags & ORDER_FIELD_06) != 0)
1470 if (Stream_GetRemainingLength(s) < 1)
1473 Stream_Read_UINT8(s, byte);
1474 multi_opaque_rect->color = (multi_opaque_rect->color & 0x00FF00FF) | ((UINT32)byte << 8);
1477 if ((orderInfo->fieldFlags & ORDER_FIELD_07) != 0)
1479 if (Stream_GetRemainingLength(s) < 1)
1482 Stream_Read_UINT8(s, byte);
1483 multi_opaque_rect->color = (multi_opaque_rect->color & 0x0000FFFF) | ((UINT32)byte << 16);
1486 if (!read_order_field_byte(orderInfo, s, 8, &multi_opaque_rect->numRectangles, TRUE))
1489 if ((orderInfo->fieldFlags & ORDER_FIELD_09) != 0)
1491 if (Stream_GetRemainingLength(s) < 2)
1494 Stream_Read_UINT16(s, multi_opaque_rect->cbData);
1495 return update_read_delta_rects(s, multi_opaque_rect->rectangles,
1496 &multi_opaque_rect->numRectangles);
1501 static BOOL update_read_multi_draw_nine_grid_order(wStream* s, const ORDER_INFO* orderInfo,
1502 MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid)
1504 if (!read_order_field_coord(orderInfo, s, 1, &multi_draw_nine_grid->srcLeft, FALSE) ||
1505 !read_order_field_coord(orderInfo, s, 2, &multi_draw_nine_grid->srcTop, FALSE) ||
1506 !read_order_field_coord(orderInfo, s, 3, &multi_draw_nine_grid->srcRight, FALSE) ||
1507 !read_order_field_coord(orderInfo, s, 4, &multi_draw_nine_grid->srcBottom, FALSE) ||
1508 !read_order_field_uint16(orderInfo, s, 5, &multi_draw_nine_grid->bitmapId, TRUE) ||
1509 !read_order_field_byte(orderInfo, s, 6, &multi_draw_nine_grid->nDeltaEntries, TRUE))
1512 if ((orderInfo->fieldFlags & ORDER_FIELD_07) != 0)
1514 if (Stream_GetRemainingLength(s) < 2)
1517 Stream_Read_UINT16(s, multi_draw_nine_grid->cbData);
1518 return update_read_delta_rects(s, multi_draw_nine_grid->rectangles,
1519 &multi_draw_nine_grid->nDeltaEntries);
1524 static BOOL update_read_line_to_order(wStream* s, const ORDER_INFO* orderInfo,
1525 LINE_TO_ORDER* line_to)
1527 if (!read_order_field_uint16(orderInfo, s, 1, &line_to->backMode, TRUE) ||
1528 !read_order_field_coord(orderInfo, s, 2, &line_to->nXStart, FALSE) ||
1529 !read_order_field_coord(orderInfo, s, 3, &line_to->nYStart, FALSE) ||
1530 !read_order_field_coord(orderInfo, s, 4, &line_to->nXEnd, FALSE) ||
1531 !read_order_field_coord(orderInfo, s, 5, &line_to->nYEnd, FALSE) ||
1532 !read_order_field_color(orderInfo, s, 6, &line_to->backColor, TRUE) ||
1533 !read_order_field_byte(orderInfo, s, 7, &line_to->bRop2, TRUE) ||
1534 !read_order_field_byte(orderInfo, s, 8, &line_to->penStyle, TRUE) ||
1535 !read_order_field_byte(orderInfo, s, 9, &line_to->penWidth, TRUE) ||
1536 !read_order_field_color(orderInfo, s, 10, &line_to->penColor, TRUE))
1540 int update_approximate_line_to_order(ORDER_INFO* orderInfo, const LINE_TO_ORDER* line_to)
1544 BOOL update_write_line_to_order(wStream* s, ORDER_INFO* orderInfo, const LINE_TO_ORDER* line_to)
1546 if (!Stream_EnsureRemainingCapacity(s, update_approximate_line_to_order(orderInfo, line_to)))
1549 orderInfo->fieldFlags = 0;
1550 orderInfo->fieldFlags |= ORDER_FIELD_01;
1551 Stream_Write_UINT16(s, line_to->backMode);
1552 orderInfo->fieldFlags |= ORDER_FIELD_02;
1553 update_write_coord(s, line_to->nXStart);
1554 orderInfo->fieldFlags |= ORDER_FIELD_03;
1555 update_write_coord(s, line_to->nYStart);
1556 orderInfo->fieldFlags |= ORDER_FIELD_04;
1557 update_write_coord(s, line_to->nXEnd);
1558 orderInfo->fieldFlags |= ORDER_FIELD_05;
1559 update_write_coord(s, line_to->nYEnd);
1560 orderInfo->fieldFlags |= ORDER_FIELD_06;
1561 update_write_color(s, line_to->backColor);
1562 orderInfo->fieldFlags |= ORDER_FIELD_07;
1563 Stream_Write_UINT8(s, line_to->bRop2);
1564 orderInfo->fieldFlags |= ORDER_FIELD_08;
1565 Stream_Write_UINT8(s, line_to->penStyle);
1566 orderInfo->fieldFlags |= ORDER_FIELD_09;
1567 Stream_Write_UINT8(s, line_to->penWidth);
1568 orderInfo->fieldFlags |= ORDER_FIELD_10;
1569 update_write_color(s, line_to->penColor);
1572 static BOOL update_read_polyline_order(wStream* s, const ORDER_INFO* orderInfo,
1573 POLYLINE_ORDER* polyline)
1576 UINT32 new_num = polyline->numDeltaEntries;
1577 if (!read_order_field_coord(orderInfo, s, 1, &polyline->xStart, FALSE) ||
1578 !read_order_field_coord(orderInfo, s, 2, &polyline->yStart, FALSE) ||
1579 !read_order_field_byte(orderInfo, s, 3, &polyline->bRop2, TRUE) ||
1580 !read_order_field_uint16(orderInfo, s, 4, &word, TRUE) ||
1581 !read_order_field_color(orderInfo, s, 5, &polyline->penColor, TRUE) ||
1582 !read_order_field_byte(orderInfo, s, 6, &new_num, TRUE))
1585 if ((orderInfo->fieldFlags & ORDER_FIELD_07) != 0)
1587 DELTA_POINT* new_points;
1592 if (Stream_GetRemainingLength(s) < 1)
1594 WLog_ERR(TAG, "Stream_GetRemainingLength(s) < 1");
1598 Stream_Read_UINT8(s, polyline->cbData);
1599 new_points = (DELTA_POINT*)realloc(polyline->points, sizeof(DELTA_POINT) * new_num);
1603 WLog_ERR(TAG, "realloc(%" PRIu32 ") failed", new_num);
1607 polyline->points = new_points;
1608 polyline->numDeltaEntries = new_num;
1609 return update_read_delta_points(s, polyline->points, polyline->numDeltaEntries,
1610 polyline->xStart, polyline->yStart);
1615 static BOOL update_read_memblt_order(wStream* s, const ORDER_INFO* orderInfo, MEMBLT_ORDER* memblt)
1617 if (!s || !orderInfo || !memblt)
1620 if (!read_order_field_uint16(orderInfo, s, 1, &memblt->cacheId, TRUE) ||
1621 !read_order_field_coord(orderInfo, s, 2, &memblt->nLeftRect, FALSE) ||
1622 !read_order_field_coord(orderInfo, s, 3, &memblt->nTopRect, FALSE) ||
1623 !read_order_field_coord(orderInfo, s, 4, &memblt->nWidth, FALSE) ||
1624 !read_order_field_coord(orderInfo, s, 5, &memblt->nHeight, FALSE) ||
1625 !read_order_field_byte(orderInfo, s, 6, &memblt->bRop, TRUE) ||
1626 !read_order_field_coord(orderInfo, s, 7, &memblt->nXSrc, FALSE) ||
1627 !read_order_field_coord(orderInfo, s, 8, &memblt->nYSrc, FALSE) ||
1628 !read_order_field_uint16(orderInfo, s, 9, &memblt->cacheIndex, TRUE))
1630 memblt->colorIndex = (memblt->cacheId >> 8);
1631 memblt->cacheId = (memblt->cacheId & 0xFF);
1632 memblt->bitmap = NULL;
1635 int update_approximate_memblt_order(ORDER_INFO* orderInfo, const MEMBLT_ORDER* memblt)
1639 BOOL update_write_memblt_order(wStream* s, ORDER_INFO* orderInfo, const MEMBLT_ORDER* memblt)
1643 if (!Stream_EnsureRemainingCapacity(s, update_approximate_memblt_order(orderInfo, memblt)))
1646 cacheId = (memblt->cacheId & 0xFF) | ((memblt->colorIndex & 0xFF) << 8);
1647 orderInfo->fieldFlags |= ORDER_FIELD_01;
1648 Stream_Write_UINT16(s, cacheId);
1649 orderInfo->fieldFlags |= ORDER_FIELD_02;
1650 update_write_coord(s, memblt->nLeftRect);
1651 orderInfo->fieldFlags |= ORDER_FIELD_03;
1652 update_write_coord(s, memblt->nTopRect);
1653 orderInfo->fieldFlags |= ORDER_FIELD_04;
1654 update_write_coord(s, memblt->nWidth);
1655 orderInfo->fieldFlags |= ORDER_FIELD_05;
1656 update_write_coord(s, memblt->nHeight);
1657 orderInfo->fieldFlags |= ORDER_FIELD_06;
1658 Stream_Write_UINT8(s, memblt->bRop);
1659 orderInfo->fieldFlags |= ORDER_FIELD_07;
1660 update_write_coord(s, memblt->nXSrc);
1661 orderInfo->fieldFlags |= ORDER_FIELD_08;
1662 update_write_coord(s, memblt->nYSrc);
1663 orderInfo->fieldFlags |= ORDER_FIELD_09;
1664 Stream_Write_UINT16(s, memblt->cacheIndex);
1667 static BOOL update_read_mem3blt_order(wStream* s, const ORDER_INFO* orderInfo,
1668 MEM3BLT_ORDER* mem3blt)
1670 if (!read_order_field_uint16(orderInfo, s, 1, &mem3blt->cacheId, TRUE) ||
1671 !read_order_field_coord(orderInfo, s, 2, &mem3blt->nLeftRect, FALSE) ||
1672 !read_order_field_coord(orderInfo, s, 3, &mem3blt->nTopRect, FALSE) ||
1673 !read_order_field_coord(orderInfo, s, 4, &mem3blt->nWidth, FALSE) ||
1674 !read_order_field_coord(orderInfo, s, 5, &mem3blt->nHeight, FALSE) ||
1675 !read_order_field_byte(orderInfo, s, 6, &mem3blt->bRop, TRUE) ||
1676 !read_order_field_coord(orderInfo, s, 7, &mem3blt->nXSrc, FALSE) ||
1677 !read_order_field_coord(orderInfo, s, 8, &mem3blt->nYSrc, FALSE) ||
1678 !read_order_field_color(orderInfo, s, 9, &mem3blt->backColor, TRUE) ||
1679 !read_order_field_color(orderInfo, s, 10, &mem3blt->foreColor, TRUE))
1682 if (!update_read_brush(s, &mem3blt->brush, orderInfo->fieldFlags >> 10) ||
1683 !read_order_field_uint16(orderInfo, s, 16, &mem3blt->cacheIndex, TRUE))
1685 mem3blt->colorIndex = (mem3blt->cacheId >> 8);
1686 mem3blt->cacheId = (mem3blt->cacheId & 0xFF);
1687 mem3blt->bitmap = NULL;
1690 static BOOL update_read_save_bitmap_order(wStream* s, const ORDER_INFO* orderInfo,
1691 SAVE_BITMAP_ORDER* save_bitmap)
1693 if (!read_order_field_uint32(orderInfo, s, 1, &save_bitmap->savedBitmapPosition, TRUE) ||
1694 !read_order_field_coord(orderInfo, s, 2, &save_bitmap->nLeftRect, FALSE) ||
1695 !read_order_field_coord(orderInfo, s, 3, &save_bitmap->nTopRect, FALSE) ||
1696 !read_order_field_coord(orderInfo, s, 4, &save_bitmap->nRightRect, FALSE) ||
1697 !read_order_field_coord(orderInfo, s, 5, &save_bitmap->nBottomRect, FALSE) ||
1698 !read_order_field_byte(orderInfo, s, 6, &save_bitmap->operation, TRUE))
1702 static BOOL update_read_glyph_index_order(wStream* s, const ORDER_INFO* orderInfo,
1703 GLYPH_INDEX_ORDER* glyph_index)
1705 if (!read_order_field_byte(orderInfo, s, 1, &glyph_index->cacheId, TRUE) ||
1706 !read_order_field_byte(orderInfo, s, 2, &glyph_index->flAccel, TRUE) ||
1707 !read_order_field_byte(orderInfo, s, 3, &glyph_index->ulCharInc, TRUE) ||
1708 !read_order_field_byte(orderInfo, s, 4, &glyph_index->fOpRedundant, TRUE) ||
1709 !read_order_field_color(orderInfo, s, 5, &glyph_index->backColor, TRUE) ||
1710 !read_order_field_color(orderInfo, s, 6, &glyph_index->foreColor, TRUE) ||
1711 !read_order_field_int16(orderInfo, s, 7, &glyph_index->bkLeft, TRUE) ||
1712 !read_order_field_int16(orderInfo, s, 8, &glyph_index->bkTop, TRUE) ||
1713 !read_order_field_int16(orderInfo, s, 9, &glyph_index->bkRight, TRUE) ||
1714 !read_order_field_int16(orderInfo, s, 10, &glyph_index->bkBottom, TRUE) ||
1715 !read_order_field_int16(orderInfo, s, 11, &glyph_index->opLeft, TRUE) ||
1716 !read_order_field_int16(orderInfo, s, 12, &glyph_index->opTop, TRUE) ||
1717 !read_order_field_int16(orderInfo, s, 13, &glyph_index->opRight, TRUE) ||
1718 !read_order_field_int16(orderInfo, s, 14, &glyph_index->opBottom, TRUE) ||
1719 !update_read_brush(s, &glyph_index->brush, orderInfo->fieldFlags >> 14) ||
1720 !read_order_field_int16(orderInfo, s, 20, &glyph_index->x, TRUE) ||
1721 !read_order_field_int16(orderInfo, s, 21, &glyph_index->y, TRUE))
1724 if ((orderInfo->fieldFlags & ORDER_FIELD_22) != 0)
1726 if (Stream_GetRemainingLength(s) < 1)
1729 Stream_Read_UINT8(s, glyph_index->cbData);
1731 if (Stream_GetRemainingLength(s) < glyph_index->cbData)
1734 CopyMemory(glyph_index->data, Stream_Pointer(s), glyph_index->cbData);
1735 Stream_Seek(s, glyph_index->cbData);
1740 int update_approximate_glyph_index_order(ORDER_INFO* orderInfo,
1741 const GLYPH_INDEX_ORDER* glyph_index)
1745 BOOL update_write_glyph_index_order(wStream* s, ORDER_INFO* orderInfo,
1746 GLYPH_INDEX_ORDER* glyph_index)
1748 int inf = update_approximate_glyph_index_order(orderInfo, glyph_index);
1750 if (!Stream_EnsureRemainingCapacity(s, inf))
1753 orderInfo->fieldFlags = 0;
1754 orderInfo->fieldFlags |= ORDER_FIELD_01;
1755 Stream_Write_UINT8(s, glyph_index->cacheId);
1756 orderInfo->fieldFlags |= ORDER_FIELD_02;
1757 Stream_Write_UINT8(s, glyph_index->flAccel);
1758 orderInfo->fieldFlags |= ORDER_FIELD_03;
1759 Stream_Write_UINT8(s, glyph_index->ulCharInc);
1760 orderInfo->fieldFlags |= ORDER_FIELD_04;
1761 Stream_Write_UINT8(s, glyph_index->fOpRedundant);
1762 orderInfo->fieldFlags |= ORDER_FIELD_05;
1763 update_write_color(s, glyph_index->backColor);
1764 orderInfo->fieldFlags |= ORDER_FIELD_06;
1765 update_write_color(s, glyph_index->foreColor);
1766 orderInfo->fieldFlags |= ORDER_FIELD_07;
1767 Stream_Write_UINT16(s, glyph_index->bkLeft);
1768 orderInfo->fieldFlags |= ORDER_FIELD_08;
1769 Stream_Write_UINT16(s, glyph_index->bkTop);
1770 orderInfo->fieldFlags |= ORDER_FIELD_09;
1771 Stream_Write_UINT16(s, glyph_index->bkRight);
1772 orderInfo->fieldFlags |= ORDER_FIELD_10;
1773 Stream_Write_UINT16(s, glyph_index->bkBottom);
1774 orderInfo->fieldFlags |= ORDER_FIELD_11;
1775 Stream_Write_UINT16(s, glyph_index->opLeft);
1776 orderInfo->fieldFlags |= ORDER_FIELD_12;
1777 Stream_Write_UINT16(s, glyph_index->opTop);
1778 orderInfo->fieldFlags |= ORDER_FIELD_13;
1779 Stream_Write_UINT16(s, glyph_index->opRight);
1780 orderInfo->fieldFlags |= ORDER_FIELD_14;
1781 Stream_Write_UINT16(s, glyph_index->opBottom);
1782 orderInfo->fieldFlags |= ORDER_FIELD_15;
1783 orderInfo->fieldFlags |= ORDER_FIELD_16;
1784 orderInfo->fieldFlags |= ORDER_FIELD_17;
1785 orderInfo->fieldFlags |= ORDER_FIELD_18;
1786 orderInfo->fieldFlags |= ORDER_FIELD_19;
1787 update_write_brush(s, &glyph_index->brush, orderInfo->fieldFlags >> 14);
1788 orderInfo->fieldFlags |= ORDER_FIELD_20;
1789 Stream_Write_UINT16(s, glyph_index->x);
1790 orderInfo->fieldFlags |= ORDER_FIELD_21;
1791 Stream_Write_UINT16(s, glyph_index->y);
1792 orderInfo->fieldFlags |= ORDER_FIELD_22;
1793 Stream_Write_UINT8(s, glyph_index->cbData);
1794 Stream_Write(s, glyph_index->data, glyph_index->cbData);
1797 static BOOL update_read_fast_index_order(wStream* s, const ORDER_INFO* orderInfo,
1798 FAST_INDEX_ORDER* fast_index)
1800 if (!read_order_field_byte(orderInfo, s, 1, &fast_index->cacheId, TRUE) ||
1801 !read_order_field_2bytes(orderInfo, s, 2, &fast_index->ulCharInc, &fast_index->flAccel,
1803 !read_order_field_color(orderInfo, s, 3, &fast_index->backColor, TRUE) ||
1804 !read_order_field_color(orderInfo, s, 4, &fast_index->foreColor, TRUE) ||
1805 !read_order_field_coord(orderInfo, s, 5, &fast_index->bkLeft, FALSE) ||
1806 !read_order_field_coord(orderInfo, s, 6, &fast_index->bkTop, FALSE) ||
1807 !read_order_field_coord(orderInfo, s, 7, &fast_index->bkRight, FALSE) ||
1808 !read_order_field_coord(orderInfo, s, 8, &fast_index->bkBottom, FALSE) ||
1809 !read_order_field_coord(orderInfo, s, 9, &fast_index->opLeft, FALSE) ||
1810 !read_order_field_coord(orderInfo, s, 10, &fast_index->opTop, FALSE) ||
1811 !read_order_field_coord(orderInfo, s, 11, &fast_index->opRight, FALSE) ||
1812 !read_order_field_coord(orderInfo, s, 12, &fast_index->opBottom, FALSE) ||
1813 !read_order_field_coord(orderInfo, s, 13, &fast_index->x, FALSE) ||
1814 !read_order_field_coord(orderInfo, s, 14, &fast_index->y, FALSE))
1817 if ((orderInfo->fieldFlags & ORDER_FIELD_15) != 0)
1819 if (Stream_GetRemainingLength(s) < 1)
1822 Stream_Read_UINT8(s, fast_index->cbData);
1824 if (Stream_GetRemainingLength(s) < fast_index->cbData)
1827 CopyMemory(fast_index->data, Stream_Pointer(s), fast_index->cbData);
1828 Stream_Seek(s, fast_index->cbData);
1833 static BOOL update_read_fast_glyph_order(wStream* s, const ORDER_INFO* orderInfo,
1834 FAST_GLYPH_ORDER* fastGlyph)
1836 GLYPH_DATA_V2* glyph = &fastGlyph->glyphData;
1837 if (!read_order_field_byte(orderInfo, s, 1, &fastGlyph->cacheId, TRUE))
1839 if (fastGlyph->cacheId > 9)
1841 if (!read_order_field_2bytes(orderInfo, s, 2, &fastGlyph->ulCharInc, &fastGlyph->flAccel,
1843 !read_order_field_color(orderInfo, s, 3, &fastGlyph->backColor, TRUE) ||
1844 !read_order_field_color(orderInfo, s, 4, &fastGlyph->foreColor, TRUE) ||
1845 !read_order_field_coord(orderInfo, s, 5, &fastGlyph->bkLeft, FALSE) ||
1846 !read_order_field_coord(orderInfo, s, 6, &fastGlyph->bkTop, FALSE) ||
1847 !read_order_field_coord(orderInfo, s, 7, &fastGlyph->bkRight, FALSE) ||
1848 !read_order_field_coord(orderInfo, s, 8, &fastGlyph->bkBottom, FALSE) ||
1849 !read_order_field_coord(orderInfo, s, 9, &fastGlyph->opLeft, FALSE) ||
1850 !read_order_field_coord(orderInfo, s, 10, &fastGlyph->opTop, FALSE) ||
1851 !read_order_field_coord(orderInfo, s, 11, &fastGlyph->opRight, FALSE) ||
1852 !read_order_field_coord(orderInfo, s, 12, &fastGlyph->opBottom, FALSE) ||
1853 !read_order_field_coord(orderInfo, s, 13, &fastGlyph->x, FALSE) ||
1854 !read_order_field_coord(orderInfo, s, 14, &fastGlyph->y, FALSE))
1857 if ((orderInfo->fieldFlags & ORDER_FIELD_15) != 0)
1861 if (Stream_GetRemainingLength(s) < 1)
1864 Stream_Read_UINT8(s, fastGlyph->cbData);
1866 src = Stream_Pointer(s);
1867 if (!Stream_SafeSeek(s, fastGlyph->cbData) || (fastGlyph->cbData == 0))
1870 CopyMemory(fastGlyph->data, src, fastGlyph->cbData);
1871 Stream_StaticInit(&sub, fastGlyph->data, fastGlyph->cbData);
1873 Stream_Read_UINT8(&sub, glyph->cacheIndex);
1875 if (fastGlyph->cbData > 1)
1877 if (!update_read_2byte_signed(&sub, &glyph->x) ||
1878 !update_read_2byte_signed(&sub, &glyph->y) ||
1879 !update_read_2byte_unsigned(&sub, &glyph->cx) ||
1880 !update_read_2byte_unsigned(&sub, &glyph->cy))
1883 glyph->cb = Stream_GetRemainingLength(&sub);
1886 BYTE* new_aj = (BYTE*)realloc(glyph->aj, glyph->cb);
1892 Stream_Read(&sub, glyph->aj, glyph->cb);
1904 static BOOL update_read_polygon_sc_order(wStream* s, const ORDER_INFO* orderInfo,
1905 POLYGON_SC_ORDER* polygon_sc)
1907 UINT32 num = polygon_sc->numPoints;
1908 if (!read_order_field_coord(orderInfo, s, 1, &polygon_sc->xStart, FALSE) ||
1909 !read_order_field_coord(orderInfo, s, 2, &polygon_sc->yStart, FALSE) ||
1910 !read_order_field_byte(orderInfo, s, 3, &polygon_sc->bRop2, TRUE) ||
1911 !read_order_field_byte(orderInfo, s, 4, &polygon_sc->fillMode, TRUE) ||
1912 !read_order_field_color(orderInfo, s, 5, &polygon_sc->brushColor, TRUE) ||
1913 !read_order_field_byte(orderInfo, s, 6, &num, TRUE))
1916 if ((orderInfo->fieldFlags & ORDER_FIELD_07) != 0)
1918 DELTA_POINT* newpoints;
1923 if (Stream_GetRemainingLength(s) < 1)
1926 Stream_Read_UINT8(s, polygon_sc->cbData);
1927 newpoints = (DELTA_POINT*)realloc(polygon_sc->points, sizeof(DELTA_POINT) * num);
1932 polygon_sc->points = newpoints;
1933 polygon_sc->numPoints = num;
1934 return update_read_delta_points(s, polygon_sc->points, polygon_sc->numPoints,
1935 polygon_sc->xStart, polygon_sc->yStart);
1940 static BOOL update_read_polygon_cb_order(wStream* s, const ORDER_INFO* orderInfo,
1941 POLYGON_CB_ORDER* polygon_cb)
1943 UINT32 num = polygon_cb->numPoints;
1944 if (!read_order_field_coord(orderInfo, s, 1, &polygon_cb->xStart, FALSE) ||
1945 !read_order_field_coord(orderInfo, s, 2, &polygon_cb->yStart, FALSE) ||
1946 !read_order_field_byte(orderInfo, s, 3, &polygon_cb->bRop2, TRUE) ||
1947 !read_order_field_byte(orderInfo, s, 4, &polygon_cb->fillMode, TRUE) ||
1948 !read_order_field_color(orderInfo, s, 5, &polygon_cb->backColor, TRUE) ||
1949 !read_order_field_color(orderInfo, s, 6, &polygon_cb->foreColor, TRUE))
1952 if (!update_read_brush(s, &polygon_cb->brush, orderInfo->fieldFlags >> 6))
1955 if (!read_order_field_byte(orderInfo, s, 12, &num, TRUE))
1958 if ((orderInfo->fieldFlags & ORDER_FIELD_13) != 0)
1960 DELTA_POINT* newpoints;
1965 if (Stream_GetRemainingLength(s) < 1)
1968 Stream_Read_UINT8(s, polygon_cb->cbData);
1969 newpoints = (DELTA_POINT*)realloc(polygon_cb->points, sizeof(DELTA_POINT) * num);
1974 polygon_cb->points = newpoints;
1975 polygon_cb->numPoints = num;
1977 if (!update_read_delta_points(s, polygon_cb->points, polygon_cb->numPoints,
1978 polygon_cb->xStart, polygon_cb->yStart))
1982 polygon_cb->backMode = (polygon_cb->bRop2 & 0x80) ? BACKMODE_TRANSPARENT : BACKMODE_OPAQUE;
1983 polygon_cb->bRop2 = (polygon_cb->bRop2 & 0x1F);
1986 static BOOL update_read_ellipse_sc_order(wStream* s, const ORDER_INFO* orderInfo,
1987 ELLIPSE_SC_ORDER* ellipse_sc)
1989 if (!read_order_field_coord(orderInfo, s, 1, &ellipse_sc->leftRect, FALSE) ||
1990 !read_order_field_coord(orderInfo, s, 2, &ellipse_sc->topRect, FALSE) ||
1991 !read_order_field_coord(orderInfo, s, 3, &ellipse_sc->rightRect, FALSE) ||
1992 !read_order_field_coord(orderInfo, s, 4, &ellipse_sc->bottomRect, FALSE) ||
1993 !read_order_field_byte(orderInfo, s, 5, &ellipse_sc->bRop2, TRUE) ||
1994 !read_order_field_byte(orderInfo, s, 6, &ellipse_sc->fillMode, TRUE) ||
1995 !read_order_field_color(orderInfo, s, 7, &ellipse_sc->color, TRUE))
1999 static BOOL update_read_ellipse_cb_order(wStream* s, const ORDER_INFO* orderInfo,
2000 ELLIPSE_CB_ORDER* ellipse_cb)
2002 if (!read_order_field_coord(orderInfo, s, 1, &ellipse_cb->leftRect, FALSE) ||
2003 !read_order_field_coord(orderInfo, s, 2, &ellipse_cb->topRect, FALSE) ||
2004 !read_order_field_coord(orderInfo, s, 3, &ellipse_cb->rightRect, FALSE) ||
2005 !read_order_field_coord(orderInfo, s, 4, &ellipse_cb->bottomRect, FALSE) ||
2006 !read_order_field_byte(orderInfo, s, 5, &ellipse_cb->bRop2, TRUE) ||
2007 !read_order_field_byte(orderInfo, s, 6, &ellipse_cb->fillMode, TRUE) ||
2008 !read_order_field_color(orderInfo, s, 7, &ellipse_cb->backColor, TRUE) ||
2009 !read_order_field_color(orderInfo, s, 8, &ellipse_cb->foreColor, TRUE))
2011 return update_read_brush(s, &ellipse_cb->brush, orderInfo->fieldFlags >> 8);
2013 /* Secondary Drawing Orders */
2014 static CACHE_BITMAP_ORDER* update_read_cache_bitmap_order(rdpUpdate* update, wStream* s,
2015 BOOL compressed, UINT16 flags)
2017 CACHE_BITMAP_ORDER* cache_bitmap;
2022 cache_bitmap = calloc(1, sizeof(CACHE_BITMAP_ORDER));
2027 if (Stream_GetRemainingLength(s) < 9)
2030 Stream_Read_UINT8(s, cache_bitmap->cacheId); /* cacheId (1 byte) */
2031 Stream_Seek_UINT8(s); /* pad1Octet (1 byte) */
2032 Stream_Read_UINT8(s, cache_bitmap->bitmapWidth); /* bitmapWidth (1 byte) */
2033 Stream_Read_UINT8(s, cache_bitmap->bitmapHeight); /* bitmapHeight (1 byte) */
2034 Stream_Read_UINT8(s, cache_bitmap->bitmapBpp); /* bitmapBpp (1 byte) */
2036 if ((cache_bitmap->bitmapBpp < 1) || (cache_bitmap->bitmapBpp > 32))
2038 WLog_Print(update->log, WLOG_ERROR, "invalid bitmap bpp %" PRIu32 "",
2039 cache_bitmap->bitmapBpp);
2043 Stream_Read_UINT16(s, cache_bitmap->bitmapLength); /* bitmapLength (2 bytes) */
2044 Stream_Read_UINT16(s, cache_bitmap->cacheIndex); /* cacheIndex (2 bytes) */
2048 if ((flags & NO_BITMAP_COMPRESSION_HDR) == 0)
2050 BYTE* bitmapComprHdr = (BYTE*)&(cache_bitmap->bitmapComprHdr);
2052 if (Stream_GetRemainingLength(s) < 8)
2055 Stream_Read(s, bitmapComprHdr, 8); /* bitmapComprHdr (8 bytes) */
2056 cache_bitmap->bitmapLength -= 8;
2060 if (cache_bitmap->bitmapLength == 0)
2063 if (Stream_GetRemainingLength(s) < cache_bitmap->bitmapLength)
2066 cache_bitmap->bitmapDataStream = malloc(cache_bitmap->bitmapLength);
2068 if (!cache_bitmap->bitmapDataStream)
2071 Stream_Read(s, cache_bitmap->bitmapDataStream, cache_bitmap->bitmapLength);
2072 cache_bitmap->compressed = compressed;
2073 return cache_bitmap;
2075 free_cache_bitmap_order(update->context, cache_bitmap);
2078 int update_approximate_cache_bitmap_order(const CACHE_BITMAP_ORDER* cache_bitmap, BOOL compressed,
2081 return 64 + cache_bitmap->bitmapLength;
2083 BOOL update_write_cache_bitmap_order(wStream* s, const CACHE_BITMAP_ORDER* cache_bitmap,
2084 BOOL compressed, UINT16* flags)
2086 UINT32 bitmapLength = cache_bitmap->bitmapLength;
2087 int inf = update_approximate_cache_bitmap_order(cache_bitmap, compressed, flags);
2089 if (!Stream_EnsureRemainingCapacity(s, inf))
2092 *flags = NO_BITMAP_COMPRESSION_HDR;
2094 if ((*flags & NO_BITMAP_COMPRESSION_HDR) == 0)
2097 Stream_Write_UINT8(s, cache_bitmap->cacheId); /* cacheId (1 byte) */
2098 Stream_Write_UINT8(s, 0); /* pad1Octet (1 byte) */
2099 Stream_Write_UINT8(s, cache_bitmap->bitmapWidth); /* bitmapWidth (1 byte) */
2100 Stream_Write_UINT8(s, cache_bitmap->bitmapHeight); /* bitmapHeight (1 byte) */
2101 Stream_Write_UINT8(s, cache_bitmap->bitmapBpp); /* bitmapBpp (1 byte) */
2102 Stream_Write_UINT16(s, bitmapLength); /* bitmapLength (2 bytes) */
2103 Stream_Write_UINT16(s, cache_bitmap->cacheIndex); /* cacheIndex (2 bytes) */
2107 if ((*flags & NO_BITMAP_COMPRESSION_HDR) == 0)
2109 BYTE* bitmapComprHdr = (BYTE*)&(cache_bitmap->bitmapComprHdr);
2110 Stream_Write(s, bitmapComprHdr, 8); /* bitmapComprHdr (8 bytes) */
2114 Stream_Write(s, cache_bitmap->bitmapDataStream, bitmapLength);
2118 Stream_Write(s, cache_bitmap->bitmapDataStream, bitmapLength);
2123 static CACHE_BITMAP_V2_ORDER* update_read_cache_bitmap_v2_order(rdpUpdate* update, wStream* s,
2124 BOOL compressed, UINT16 flags)
2127 BYTE bitsPerPixelId;
2128 CACHE_BITMAP_V2_ORDER* cache_bitmap_v2;
2133 cache_bitmap_v2 = calloc(1, sizeof(CACHE_BITMAP_V2_ORDER));
2135 if (!cache_bitmap_v2)
2138 cache_bitmap_v2->cacheId = flags & 0x0003;
2139 cache_bitmap_v2->flags = (flags & 0xFF80) >> 7;
2140 bitsPerPixelId = (flags & 0x0078) >> 3;
2141 cache_bitmap_v2->bitmapBpp = get_cbr2_bpp(bitsPerPixelId, &rc);
2145 if (cache_bitmap_v2->flags & CBR2_PERSISTENT_KEY_PRESENT)
2147 if (Stream_GetRemainingLength(s) < 8)
2150 Stream_Read_UINT32(s, cache_bitmap_v2->key1); /* key1 (4 bytes) */
2151 Stream_Read_UINT32(s, cache_bitmap_v2->key2); /* key2 (4 bytes) */
2154 if (cache_bitmap_v2->flags & CBR2_HEIGHT_SAME_AS_WIDTH)
2156 if (!update_read_2byte_unsigned(s, &cache_bitmap_v2->bitmapWidth)) /* bitmapWidth */
2159 cache_bitmap_v2->bitmapHeight = cache_bitmap_v2->bitmapWidth;
2163 if (!update_read_2byte_unsigned(s, &cache_bitmap_v2->bitmapWidth) || /* bitmapWidth */
2164 !update_read_2byte_unsigned(s, &cache_bitmap_v2->bitmapHeight)) /* bitmapHeight */
2168 if (!update_read_4byte_unsigned(s, &cache_bitmap_v2->bitmapLength) || /* bitmapLength */
2169 !update_read_2byte_unsigned(s, &cache_bitmap_v2->cacheIndex)) /* cacheIndex */
2172 if (cache_bitmap_v2->flags & CBR2_DO_NOT_CACHE)
2173 cache_bitmap_v2->cacheIndex = BITMAP_CACHE_WAITING_LIST_INDEX;
2177 if (!(cache_bitmap_v2->flags & CBR2_NO_BITMAP_COMPRESSION_HDR))
2179 if (Stream_GetRemainingLength(s) < 8)
2183 s, cache_bitmap_v2->cbCompFirstRowSize); /* cbCompFirstRowSize (2 bytes) */
2185 s, cache_bitmap_v2->cbCompMainBodySize); /* cbCompMainBodySize (2 bytes) */
2186 Stream_Read_UINT16(s, cache_bitmap_v2->cbScanWidth); /* cbScanWidth (2 bytes) */
2188 s, cache_bitmap_v2->cbUncompressedSize); /* cbUncompressedSize (2 bytes) */
2189 cache_bitmap_v2->bitmapLength = cache_bitmap_v2->cbCompMainBodySize;
2193 if (cache_bitmap_v2->bitmapLength == 0)
2196 if (Stream_GetRemainingLength(s) < cache_bitmap_v2->bitmapLength)
2199 if (cache_bitmap_v2->bitmapLength == 0)
2202 cache_bitmap_v2->bitmapDataStream = malloc(cache_bitmap_v2->bitmapLength);
2204 if (!cache_bitmap_v2->bitmapDataStream)
2207 Stream_Read(s, cache_bitmap_v2->bitmapDataStream, cache_bitmap_v2->bitmapLength);
2208 cache_bitmap_v2->compressed = compressed;
2209 return cache_bitmap_v2;
2211 free_cache_bitmap_v2_order(update->context, cache_bitmap_v2);
2214 int update_approximate_cache_bitmap_v2_order(CACHE_BITMAP_V2_ORDER* cache_bitmap_v2,
2215 BOOL compressed, UINT16* flags)
2217 return 64 + cache_bitmap_v2->bitmapLength;
2219 BOOL update_write_cache_bitmap_v2_order(wStream* s, CACHE_BITMAP_V2_ORDER* cache_bitmap_v2,
2220 BOOL compressed, UINT16* flags)
2223 BYTE bitsPerPixelId;
2225 if (!Stream_EnsureRemainingCapacity(
2226 s, update_approximate_cache_bitmap_v2_order(cache_bitmap_v2, compressed, flags)))
2229 bitsPerPixelId = get_bpp_bmf(cache_bitmap_v2->bitmapBpp, &rc);
2232 *flags = (cache_bitmap_v2->cacheId & 0x0003) | (bitsPerPixelId << 3) |
2233 ((cache_bitmap_v2->flags << 7) & 0xFF80);
2235 if (cache_bitmap_v2->flags & CBR2_PERSISTENT_KEY_PRESENT)
2237 Stream_Write_UINT32(s, cache_bitmap_v2->key1); /* key1 (4 bytes) */
2238 Stream_Write_UINT32(s, cache_bitmap_v2->key2); /* key2 (4 bytes) */
2241 if (cache_bitmap_v2->flags & CBR2_HEIGHT_SAME_AS_WIDTH)
2243 if (!update_write_2byte_unsigned(s, cache_bitmap_v2->bitmapWidth)) /* bitmapWidth */
2248 if (!update_write_2byte_unsigned(s, cache_bitmap_v2->bitmapWidth) || /* bitmapWidth */
2249 !update_write_2byte_unsigned(s, cache_bitmap_v2->bitmapHeight)) /* bitmapHeight */
2253 if (cache_bitmap_v2->flags & CBR2_DO_NOT_CACHE)
2254 cache_bitmap_v2->cacheIndex = BITMAP_CACHE_WAITING_LIST_INDEX;
2256 if (!update_write_4byte_unsigned(s, cache_bitmap_v2->bitmapLength) || /* bitmapLength */
2257 !update_write_2byte_unsigned(s, cache_bitmap_v2->cacheIndex)) /* cacheIndex */
2262 if (!(cache_bitmap_v2->flags & CBR2_NO_BITMAP_COMPRESSION_HDR))
2264 Stream_Write_UINT16(
2265 s, cache_bitmap_v2->cbCompFirstRowSize); /* cbCompFirstRowSize (2 bytes) */
2266 Stream_Write_UINT16(
2267 s, cache_bitmap_v2->cbCompMainBodySize); /* cbCompMainBodySize (2 bytes) */
2268 Stream_Write_UINT16(s, cache_bitmap_v2->cbScanWidth); /* cbScanWidth (2 bytes) */
2269 Stream_Write_UINT16(
2270 s, cache_bitmap_v2->cbUncompressedSize); /* cbUncompressedSize (2 bytes) */
2271 cache_bitmap_v2->bitmapLength = cache_bitmap_v2->cbCompMainBodySize;
2274 if (!Stream_EnsureRemainingCapacity(s, cache_bitmap_v2->bitmapLength))
2277 Stream_Write(s, cache_bitmap_v2->bitmapDataStream, cache_bitmap_v2->bitmapLength);
2281 if (!Stream_EnsureRemainingCapacity(s, cache_bitmap_v2->bitmapLength))
2284 Stream_Write(s, cache_bitmap_v2->bitmapDataStream, cache_bitmap_v2->bitmapLength);
2287 cache_bitmap_v2->compressed = compressed;
2290 static CACHE_BITMAP_V3_ORDER* update_read_cache_bitmap_v3_order(rdpUpdate* update, wStream* s,
2294 BYTE bitsPerPixelId;
2295 BITMAP_DATA_EX* bitmapData;
2298 CACHE_BITMAP_V3_ORDER* cache_bitmap_v3;
2303 cache_bitmap_v3 = calloc(1, sizeof(CACHE_BITMAP_V3_ORDER));
2305 if (!cache_bitmap_v3)
2308 cache_bitmap_v3->cacheId = flags & 0x00000003;
2309 cache_bitmap_v3->flags = (flags & 0x0000FF80) >> 7;
2310 bitsPerPixelId = (flags & 0x00000078) >> 3;
2311 cache_bitmap_v3->bpp = get_cbr2_bpp(bitsPerPixelId, &rc);
2315 if (Stream_GetRemainingLength(s) < 21)
2318 Stream_Read_UINT16(s, cache_bitmap_v3->cacheIndex); /* cacheIndex (2 bytes) */
2319 Stream_Read_UINT32(s, cache_bitmap_v3->key1); /* key1 (4 bytes) */
2320 Stream_Read_UINT32(s, cache_bitmap_v3->key2); /* key2 (4 bytes) */
2321 bitmapData = &cache_bitmap_v3->bitmapData;
2322 Stream_Read_UINT8(s, bitmapData->bpp);
2324 if ((bitmapData->bpp < 1) || (bitmapData->bpp > 32))
2326 WLog_Print(update->log, WLOG_ERROR, "invalid bpp value %" PRIu32 "", bitmapData->bpp);
2330 Stream_Seek_UINT8(s); /* reserved1 (1 byte) */
2331 Stream_Seek_UINT8(s); /* reserved2 (1 byte) */
2332 Stream_Read_UINT8(s, bitmapData->codecID); /* codecID (1 byte) */
2333 Stream_Read_UINT16(s, bitmapData->width); /* width (2 bytes) */
2334 Stream_Read_UINT16(s, bitmapData->height); /* height (2 bytes) */
2335 Stream_Read_UINT32(s, new_len); /* length (4 bytes) */
2337 if ((new_len == 0) || (Stream_GetRemainingLength(s) < new_len))
2340 new_data = (BYTE*)realloc(bitmapData->data, new_len);
2345 bitmapData->data = new_data;
2346 bitmapData->length = new_len;
2347 Stream_Read(s, bitmapData->data, bitmapData->length);
2348 return cache_bitmap_v3;
2350 free_cache_bitmap_v3_order(update->context, cache_bitmap_v3);
2353 int update_approximate_cache_bitmap_v3_order(CACHE_BITMAP_V3_ORDER* cache_bitmap_v3, UINT16* flags)
2355 BITMAP_DATA_EX* bitmapData = &cache_bitmap_v3->bitmapData;
2356 return 64 + bitmapData->length;
2358 BOOL update_write_cache_bitmap_v3_order(wStream* s, CACHE_BITMAP_V3_ORDER* cache_bitmap_v3,
2362 BYTE bitsPerPixelId;
2363 BITMAP_DATA_EX* bitmapData;
2365 if (!Stream_EnsureRemainingCapacity(
2366 s, update_approximate_cache_bitmap_v3_order(cache_bitmap_v3, flags)))
2369 bitmapData = &cache_bitmap_v3->bitmapData;
2370 bitsPerPixelId = get_bpp_bmf(cache_bitmap_v3->bpp, &rc);
2373 *flags = (cache_bitmap_v3->cacheId & 0x00000003) |
2374 ((cache_bitmap_v3->flags << 7) & 0x0000FF80) | ((bitsPerPixelId << 3) & 0x00000078);
2375 Stream_Write_UINT16(s, cache_bitmap_v3->cacheIndex); /* cacheIndex (2 bytes) */
2376 Stream_Write_UINT32(s, cache_bitmap_v3->key1); /* key1 (4 bytes) */
2377 Stream_Write_UINT32(s, cache_bitmap_v3->key2); /* key2 (4 bytes) */
2378 Stream_Write_UINT8(s, bitmapData->bpp);
2379 Stream_Write_UINT8(s, 0); /* reserved1 (1 byte) */
2380 Stream_Write_UINT8(s, 0); /* reserved2 (1 byte) */
2381 Stream_Write_UINT8(s, bitmapData->codecID); /* codecID (1 byte) */
2382 Stream_Write_UINT16(s, bitmapData->width); /* width (2 bytes) */
2383 Stream_Write_UINT16(s, bitmapData->height); /* height (2 bytes) */
2384 Stream_Write_UINT32(s, bitmapData->length); /* length (4 bytes) */
2385 Stream_Write(s, bitmapData->data, bitmapData->length);
2388 static CACHE_COLOR_TABLE_ORDER* update_read_cache_color_table_order(rdpUpdate* update, wStream* s,
2393 CACHE_COLOR_TABLE_ORDER* cache_color_table = calloc(1, sizeof(CACHE_COLOR_TABLE_ORDER));
2395 if (!cache_color_table)
2398 if (Stream_GetRemainingLength(s) < 3)
2401 Stream_Read_UINT8(s, cache_color_table->cacheIndex); /* cacheIndex (1 byte) */
2402 Stream_Read_UINT16(s, cache_color_table->numberColors); /* numberColors (2 bytes) */
2404 if (cache_color_table->numberColors != 256)
2406 /* This field MUST be set to 256 */
2410 if (Stream_GetRemainingLength(s) < cache_color_table->numberColors * 4)
2413 colorTable = (UINT32*)&cache_color_table->colorTable;
2415 for (i = 0; i < (int)cache_color_table->numberColors; i++)
2416 update_read_color_quad(s, &colorTable[i]);
2418 return cache_color_table;
2420 free_cache_color_table_order(update->context, cache_color_table);
2423 int update_approximate_cache_color_table_order(const CACHE_COLOR_TABLE_ORDER* cache_color_table,
2426 return 16 + (256 * 4);
2428 BOOL update_write_cache_color_table_order(wStream* s,
2429 const CACHE_COLOR_TABLE_ORDER* cache_color_table,
2435 if (cache_color_table->numberColors != 256)
2438 inf = update_approximate_cache_color_table_order(cache_color_table, flags);
2440 if (!Stream_EnsureRemainingCapacity(s, inf))
2443 Stream_Write_UINT8(s, cache_color_table->cacheIndex); /* cacheIndex (1 byte) */
2444 Stream_Write_UINT16(s, cache_color_table->numberColors); /* numberColors (2 bytes) */
2445 colorTable = (UINT32*)&cache_color_table->colorTable;
2447 for (i = 0; i < (int)cache_color_table->numberColors; i++)
2449 update_write_color_quad(s, colorTable[i]);
2454 static CACHE_GLYPH_ORDER* update_read_cache_glyph_order(rdpUpdate* update, wStream* s, UINT16 flags)
2457 CACHE_GLYPH_ORDER* cache_glyph_order = calloc(1, sizeof(CACHE_GLYPH_ORDER));
2459 if (!cache_glyph_order || !update || !s)
2462 if (Stream_GetRemainingLength(s) < 2)
2465 Stream_Read_UINT8(s, cache_glyph_order->cacheId); /* cacheId (1 byte) */
2466 Stream_Read_UINT8(s, cache_glyph_order->cGlyphs); /* cGlyphs (1 byte) */
2468 for (i = 0; i < cache_glyph_order->cGlyphs; i++)
2470 GLYPH_DATA* glyph = &cache_glyph_order->glyphData[i];
2472 if (Stream_GetRemainingLength(s) < 10)
2475 Stream_Read_UINT16(s, glyph->cacheIndex);
2476 Stream_Read_INT16(s, glyph->x);
2477 Stream_Read_INT16(s, glyph->y);
2478 Stream_Read_UINT16(s, glyph->cx);
2479 Stream_Read_UINT16(s, glyph->cy);
2480 glyph->cb = ((glyph->cx + 7) / 8) * glyph->cy;
2481 glyph->cb += ((glyph->cb % 4) > 0) ? 4 - (glyph->cb % 4) : 0;
2483 if (Stream_GetRemainingLength(s) < glyph->cb)
2486 glyph->aj = (BYTE*)malloc(glyph->cb);
2491 Stream_Read(s, glyph->aj, glyph->cb);
2494 if ((flags & CG_GLYPH_UNICODE_PRESENT) && (cache_glyph_order->cGlyphs > 0))
2496 cache_glyph_order->unicodeCharacters = calloc(cache_glyph_order->cGlyphs, sizeof(WCHAR));
2498 if (!cache_glyph_order->unicodeCharacters)
2501 if (Stream_GetRemainingLength(s) < sizeof(WCHAR) * cache_glyph_order->cGlyphs)
2504 Stream_Read_UTF16_String(s, cache_glyph_order->unicodeCharacters,
2505 cache_glyph_order->cGlyphs);
2508 return cache_glyph_order;
2510 free_cache_glyph_order(update->context, cache_glyph_order);
2513 int update_approximate_cache_glyph_order(const CACHE_GLYPH_ORDER* cache_glyph, UINT16* flags)
2515 return 2 + cache_glyph->cGlyphs * 32;
2517 BOOL update_write_cache_glyph_order(wStream* s, const CACHE_GLYPH_ORDER* cache_glyph, UINT16* flags)
2521 const GLYPH_DATA* glyph;
2522 inf = update_approximate_cache_glyph_order(cache_glyph, flags);
2524 if (!Stream_EnsureRemainingCapacity(s, inf))
2527 Stream_Write_UINT8(s, cache_glyph->cacheId); /* cacheId (1 byte) */
2528 Stream_Write_UINT8(s, cache_glyph->cGlyphs); /* cGlyphs (1 byte) */
2530 for (i = 0; i < (int)cache_glyph->cGlyphs; i++)
2533 glyph = &cache_glyph->glyphData[i];
2534 Stream_Write_UINT16(s, glyph->cacheIndex); /* cacheIndex (2 bytes) */
2536 Stream_Write_UINT16(s, lsi16); /* x (2 bytes) */
2538 Stream_Write_UINT16(s, lsi16); /* y (2 bytes) */
2539 Stream_Write_UINT16(s, glyph->cx); /* cx (2 bytes) */
2540 Stream_Write_UINT16(s, glyph->cy); /* cy (2 bytes) */
2541 cb = ((glyph->cx + 7) / 8) * glyph->cy;
2542 cb += ((cb % 4) > 0) ? 4 - (cb % 4) : 0;
2543 Stream_Write(s, glyph->aj, cb);
2546 if (*flags & CG_GLYPH_UNICODE_PRESENT)
2548 Stream_Zero(s, cache_glyph->cGlyphs * 2);
2553 static CACHE_GLYPH_V2_ORDER* update_read_cache_glyph_v2_order(rdpUpdate* update, wStream* s,
2557 CACHE_GLYPH_V2_ORDER* cache_glyph_v2 = calloc(1, sizeof(CACHE_GLYPH_V2_ORDER));
2559 if (!cache_glyph_v2)
2562 cache_glyph_v2->cacheId = (flags & 0x000F);
2563 cache_glyph_v2->flags = (flags & 0x00F0) >> 4;
2564 cache_glyph_v2->cGlyphs = (flags & 0xFF00) >> 8;
2566 for (i = 0; i < cache_glyph_v2->cGlyphs; i++)
2568 GLYPH_DATA_V2* glyph = &cache_glyph_v2->glyphData[i];
2570 if (Stream_GetRemainingLength(s) < 1)
2573 Stream_Read_UINT8(s, glyph->cacheIndex);
2575 if (!update_read_2byte_signed(s, &glyph->x) || !update_read_2byte_signed(s, &glyph->y) ||
2576 !update_read_2byte_unsigned(s, &glyph->cx) ||
2577 !update_read_2byte_unsigned(s, &glyph->cy))
2582 glyph->cb = ((glyph->cx + 7) / 8) * glyph->cy;
2583 glyph->cb += ((glyph->cb % 4) > 0) ? 4 - (glyph->cb % 4) : 0;
2585 if (Stream_GetRemainingLength(s) < glyph->cb)
2588 glyph->aj = (BYTE*)malloc(glyph->cb);
2593 Stream_Read(s, glyph->aj, glyph->cb);
2596 if ((flags & CG_GLYPH_UNICODE_PRESENT) && (cache_glyph_v2->cGlyphs > 0))
2598 cache_glyph_v2->unicodeCharacters = calloc(cache_glyph_v2->cGlyphs, sizeof(WCHAR));
2600 if (!cache_glyph_v2->unicodeCharacters)
2603 if (Stream_GetRemainingLength(s) < sizeof(WCHAR) * cache_glyph_v2->cGlyphs)
2606 Stream_Read_UTF16_String(s, cache_glyph_v2->unicodeCharacters, cache_glyph_v2->cGlyphs);
2609 return cache_glyph_v2;
2611 free_cache_glyph_v2_order(update->context, cache_glyph_v2);
2614 int update_approximate_cache_glyph_v2_order(const CACHE_GLYPH_V2_ORDER* cache_glyph_v2,
2617 return 8 + cache_glyph_v2->cGlyphs * 32;
2619 BOOL update_write_cache_glyph_v2_order(wStream* s, const CACHE_GLYPH_V2_ORDER* cache_glyph_v2,
2623 inf = update_approximate_cache_glyph_v2_order(cache_glyph_v2, flags);
2625 if (!Stream_EnsureRemainingCapacity(s, inf))
2628 *flags = (cache_glyph_v2->cacheId & 0x000F) | ((cache_glyph_v2->flags & 0x000F) << 4) |
2629 ((cache_glyph_v2->cGlyphs & 0x00FF) << 8);
2631 for (i = 0; i < cache_glyph_v2->cGlyphs; i++)
2634 const GLYPH_DATA_V2* glyph = &cache_glyph_v2->glyphData[i];
2635 Stream_Write_UINT8(s, glyph->cacheIndex);
2637 if (!update_write_2byte_signed(s, glyph->x) || !update_write_2byte_signed(s, glyph->y) ||
2638 !update_write_2byte_unsigned(s, glyph->cx) ||
2639 !update_write_2byte_unsigned(s, glyph->cy))
2644 cb = ((glyph->cx + 7) / 8) * glyph->cy;
2645 cb += ((cb % 4) > 0) ? 4 - (cb % 4) : 0;
2646 Stream_Write(s, glyph->aj, cb);
2649 if (*flags & CG_GLYPH_UNICODE_PRESENT)
2651 Stream_Zero(s, cache_glyph_v2->cGlyphs * 2);
2656 static BOOL update_decompress_brush(wStream* s, BYTE* output, size_t outSize, BYTE bpp)
2661 const BYTE* palette = Stream_Pointer(s) + 16;
2662 const size_t bytesPerPixel = ((bpp + 1) / 8);
2664 if (Stream_GetRemainingLength(s) < 16 + bytesPerPixel * 4)
2667 for (y = 7; y >= 0; y--)
2669 for (x = 0; x < 8; x++)
2673 Stream_Read_UINT8(s, byte);
2675 index = ((byte >> ((3 - (x % 4)) * 2)) & 0x03);
2677 for (k = 0; k < bytesPerPixel; k++)
2679 const size_t dstIndex = ((y * 8 + x) * bytesPerPixel) + k;
2680 const size_t srcIndex = (index * bytesPerPixel) + k;
2681 if (dstIndex >= outSize)
2683 output[dstIndex] = palette[srcIndex];
2690 static BOOL update_compress_brush(wStream* s, const BYTE* input, BYTE bpp)
2694 static CACHE_BRUSH_ORDER* update_read_cache_brush_order(rdpUpdate* update, wStream* s, UINT16 flags)
2699 BOOL compressed = FALSE;
2700 CACHE_BRUSH_ORDER* cache_brush = calloc(1, sizeof(CACHE_BRUSH_ORDER));
2705 if (Stream_GetRemainingLength(s) < 6)
2708 Stream_Read_UINT8(s, cache_brush->index); /* cacheEntry (1 byte) */
2709 Stream_Read_UINT8(s, iBitmapFormat); /* iBitmapFormat (1 byte) */
2711 cache_brush->bpp = get_bmf_bpp(iBitmapFormat, &rc);
2715 Stream_Read_UINT8(s, cache_brush->cx); /* cx (1 byte) */
2716 Stream_Read_UINT8(s, cache_brush->cy); /* cy (1 byte) */
2717 /* according to Section 2.2.2.2.1.2.7 errata the windows implementation sets this filed is set
2719 Stream_Read_UINT8(s, cache_brush->style); /* style (1 byte) */
2720 Stream_Read_UINT8(s, cache_brush->length); /* iBytes (1 byte) */
2722 if ((cache_brush->cx == 8) && (cache_brush->cy == 8))
2724 if (cache_brush->bpp == 1)
2726 if (cache_brush->length != 8)
2728 WLog_Print(update->log, WLOG_ERROR, "incompatible 1bpp brush of length:%" PRIu32 "",
2729 cache_brush->length);
2733 if (Stream_GetRemainingLength(s) < 8)
2736 /* rows are encoded in reverse order */
2737 for (i = 7; i >= 0; i--)
2738 Stream_Read_UINT8(s, cache_brush->data[i]);
2742 if ((iBitmapFormat == BMF_8BPP) && (cache_brush->length == 20))
2744 else if ((iBitmapFormat == BMF_16BPP) && (cache_brush->length == 24))
2746 else if ((iBitmapFormat == BMF_24BPP) && (cache_brush->length == 28))
2748 else if ((iBitmapFormat == BMF_32BPP) && (cache_brush->length == 32))
2751 if (compressed != FALSE)
2753 /* compressed brush */
2754 if (!update_decompress_brush(s, cache_brush->data, sizeof(cache_brush->data),
2760 /* uncompressed brush */
2761 UINT32 scanline = (cache_brush->bpp / 8) * 8;
2763 if (Stream_GetRemainingLength(s) < scanline * 8)
2766 for (i = 7; i >= 0; i--)
2768 Stream_Read(s, &cache_brush->data[i * scanline], scanline);
2776 free_cache_brush_order(update->context, cache_brush);
2779 int update_approximate_cache_brush_order(const CACHE_BRUSH_ORDER* cache_brush, UINT16* flags)
2783 BOOL update_write_cache_brush_order(wStream* s, const CACHE_BRUSH_ORDER* cache_brush, UINT16* flags)
2788 BOOL compressed = FALSE;
2790 if (!Stream_EnsureRemainingCapacity(s,
2791 update_approximate_cache_brush_order(cache_brush, flags)))
2794 iBitmapFormat = get_bpp_bmf(cache_brush->bpp, &rc);
2797 Stream_Write_UINT8(s, cache_brush->index); /* cacheEntry (1 byte) */
2798 Stream_Write_UINT8(s, iBitmapFormat); /* iBitmapFormat (1 byte) */
2799 Stream_Write_UINT8(s, cache_brush->cx); /* cx (1 byte) */
2800 Stream_Write_UINT8(s, cache_brush->cy); /* cy (1 byte) */
2801 Stream_Write_UINT8(s, cache_brush->style); /* style (1 byte) */
2802 Stream_Write_UINT8(s, cache_brush->length); /* iBytes (1 byte) */
2804 if ((cache_brush->cx == 8) && (cache_brush->cy == 8))
2806 if (cache_brush->bpp == 1)
2808 if (cache_brush->length != 8)
2810 WLog_ERR(TAG, "incompatible 1bpp brush of length:%" PRIu32 "", cache_brush->length);
2814 for (i = 7; i >= 0; i--)
2816 Stream_Write_UINT8(s, cache_brush->data[i]);
2821 if ((iBitmapFormat == BMF_8BPP) && (cache_brush->length == 20))
2823 else if ((iBitmapFormat == BMF_16BPP) && (cache_brush->length == 24))
2825 else if ((iBitmapFormat == BMF_32BPP) && (cache_brush->length == 32))
2828 if (compressed != FALSE)
2830 /* compressed brush */
2831 if (!update_compress_brush(s, cache_brush->data, cache_brush->bpp))
2836 /* uncompressed brush */
2837 int scanline = (cache_brush->bpp / 8) * 8;
2839 for (i = 7; i >= 0; i--)
2841 Stream_Write(s, &cache_brush->data[i * scanline], scanline);
2849 /* Alternate Secondary Drawing Orders */
2851 update_read_create_offscreen_bitmap_order(wStream* s,
2852 CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap)
2855 BOOL deleteListPresent;
2856 OFFSCREEN_DELETE_LIST* deleteList;
2858 if (Stream_GetRemainingLength(s) < 6)
2861 Stream_Read_UINT16(s, flags); /* flags (2 bytes) */
2862 create_offscreen_bitmap->id = flags & 0x7FFF;
2863 deleteListPresent = (flags & 0x8000) ? TRUE : FALSE;
2864 Stream_Read_UINT16(s, create_offscreen_bitmap->cx); /* cx (2 bytes) */
2865 Stream_Read_UINT16(s, create_offscreen_bitmap->cy); /* cy (2 bytes) */
2866 deleteList = &(create_offscreen_bitmap->deleteList);
2868 if (deleteListPresent)
2872 if (Stream_GetRemainingLength(s) < 2)
2875 Stream_Read_UINT16(s, deleteList->cIndices);
2877 if (deleteList->cIndices > deleteList->sIndices)
2879 UINT16* new_indices;
2880 new_indices = (UINT16*)realloc(deleteList->indices, deleteList->cIndices * 2);
2885 deleteList->sIndices = deleteList->cIndices;
2886 deleteList->indices = new_indices;
2889 if (Stream_GetRemainingLength(s) < 2 * deleteList->cIndices)
2892 for (i = 0; i < deleteList->cIndices; i++)
2894 Stream_Read_UINT16(s, deleteList->indices[i]);
2899 deleteList->cIndices = 0;
2904 int update_approximate_create_offscreen_bitmap_order(
2905 const CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap)
2907 const OFFSCREEN_DELETE_LIST* deleteList = &(create_offscreen_bitmap->deleteList);
2908 return 32 + deleteList->cIndices * 2;
2910 BOOL update_write_create_offscreen_bitmap_order(
2911 wStream* s, const CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap)
2914 BOOL deleteListPresent;
2915 const OFFSCREEN_DELETE_LIST* deleteList;
2917 if (!Stream_EnsureRemainingCapacity(
2918 s, update_approximate_create_offscreen_bitmap_order(create_offscreen_bitmap)))
2921 deleteList = &(create_offscreen_bitmap->deleteList);
2922 flags = create_offscreen_bitmap->id & 0x7FFF;
2923 deleteListPresent = (deleteList->cIndices > 0) ? TRUE : FALSE;
2925 if (deleteListPresent)
2928 Stream_Write_UINT16(s, flags); /* flags (2 bytes) */
2929 Stream_Write_UINT16(s, create_offscreen_bitmap->cx); /* cx (2 bytes) */
2930 Stream_Write_UINT16(s, create_offscreen_bitmap->cy); /* cy (2 bytes) */
2932 if (deleteListPresent)
2935 Stream_Write_UINT16(s, deleteList->cIndices);
2937 for (i = 0; i < (int)deleteList->cIndices; i++)
2939 Stream_Write_UINT16(s, deleteList->indices[i]);
2945 static BOOL update_read_switch_surface_order(wStream* s, SWITCH_SURFACE_ORDER* switch_surface)
2947 if (Stream_GetRemainingLength(s) < 2)
2950 Stream_Read_UINT16(s, switch_surface->bitmapId); /* bitmapId (2 bytes) */
2953 int update_approximate_switch_surface_order(const SWITCH_SURFACE_ORDER* switch_surface)
2957 BOOL update_write_switch_surface_order(wStream* s, const SWITCH_SURFACE_ORDER* switch_surface)
2959 int inf = update_approximate_switch_surface_order(switch_surface);
2961 if (!Stream_EnsureRemainingCapacity(s, inf))
2964 Stream_Write_UINT16(s, switch_surface->bitmapId); /* bitmapId (2 bytes) */
2968 update_read_create_nine_grid_bitmap_order(wStream* s,
2969 CREATE_NINE_GRID_BITMAP_ORDER* create_nine_grid_bitmap)
2971 NINE_GRID_BITMAP_INFO* nineGridInfo;
2973 if (Stream_GetRemainingLength(s) < 19)
2976 Stream_Read_UINT8(s, create_nine_grid_bitmap->bitmapBpp); /* bitmapBpp (1 byte) */
2978 if ((create_nine_grid_bitmap->bitmapBpp < 1) || (create_nine_grid_bitmap->bitmapBpp > 32))
2980 WLog_ERR(TAG, "invalid bpp value %" PRIu32 "", create_nine_grid_bitmap->bitmapBpp);
2984 Stream_Read_UINT16(s, create_nine_grid_bitmap->bitmapId); /* bitmapId (2 bytes) */
2985 nineGridInfo = &(create_nine_grid_bitmap->nineGridInfo);
2986 Stream_Read_UINT32(s, nineGridInfo->flFlags); /* flFlags (4 bytes) */
2987 Stream_Read_UINT16(s, nineGridInfo->ulLeftWidth); /* ulLeftWidth (2 bytes) */
2988 Stream_Read_UINT16(s, nineGridInfo->ulRightWidth); /* ulRightWidth (2 bytes) */
2989 Stream_Read_UINT16(s, nineGridInfo->ulTopHeight); /* ulTopHeight (2 bytes) */
2990 Stream_Read_UINT16(s, nineGridInfo->ulBottomHeight); /* ulBottomHeight (2 bytes) */
2991 update_read_colorref(s, &nineGridInfo->crTransparent); /* crTransparent (4 bytes) */
2994 static BOOL update_read_frame_marker_order(wStream* s, FRAME_MARKER_ORDER* frame_marker)
2996 if (Stream_GetRemainingLength(s) < 4)
2999 Stream_Read_UINT32(s, frame_marker->action); /* action (4 bytes) */
3002 static BOOL update_read_stream_bitmap_first_order(wStream* s,
3003 STREAM_BITMAP_FIRST_ORDER* stream_bitmap_first)
3005 if (Stream_GetRemainingLength(s) < 10) // 8 + 2 at least
3008 Stream_Read_UINT8(s, stream_bitmap_first->bitmapFlags); /* bitmapFlags (1 byte) */
3009 Stream_Read_UINT8(s, stream_bitmap_first->bitmapBpp); /* bitmapBpp (1 byte) */
3011 if ((stream_bitmap_first->bitmapBpp < 1) || (stream_bitmap_first->bitmapBpp > 32))
3013 WLog_ERR(TAG, "invalid bpp value %" PRIu32 "", stream_bitmap_first->bitmapBpp);
3017 Stream_Read_UINT16(s, stream_bitmap_first->bitmapType); /* bitmapType (2 bytes) */
3018 Stream_Read_UINT16(s, stream_bitmap_first->bitmapWidth); /* bitmapWidth (2 bytes) */
3019 Stream_Read_UINT16(s, stream_bitmap_first->bitmapHeight); /* bitmapHeigth (2 bytes) */
3021 if (stream_bitmap_first->bitmapFlags & STREAM_BITMAP_V2)
3023 if (Stream_GetRemainingLength(s) < 4)
3026 Stream_Read_UINT32(s, stream_bitmap_first->bitmapSize); /* bitmapSize (4 bytes) */
3030 if (Stream_GetRemainingLength(s) < 2)
3033 Stream_Read_UINT16(s, stream_bitmap_first->bitmapSize); /* bitmapSize (2 bytes) */
3036 FIELD_SKIP_BUFFER16(
3037 s, stream_bitmap_first->bitmapBlockSize); /* bitmapBlockSize(2 bytes) + bitmapBlock */
3040 static BOOL update_read_stream_bitmap_next_order(wStream* s,
3041 STREAM_BITMAP_NEXT_ORDER* stream_bitmap_next)
3043 if (Stream_GetRemainingLength(s) < 5)
3046 Stream_Read_UINT8(s, stream_bitmap_next->bitmapFlags); /* bitmapFlags (1 byte) */
3047 Stream_Read_UINT16(s, stream_bitmap_next->bitmapType); /* bitmapType (2 bytes) */
3048 FIELD_SKIP_BUFFER16(
3049 s, stream_bitmap_next->bitmapBlockSize); /* bitmapBlockSize(2 bytes) + bitmapBlock */
3052 static BOOL update_read_draw_gdiplus_first_order(wStream* s,
3053 DRAW_GDIPLUS_FIRST_ORDER* draw_gdiplus_first)
3055 if (Stream_GetRemainingLength(s) < 11)
3058 Stream_Seek_UINT8(s); /* pad1Octet (1 byte) */
3059 Stream_Read_UINT16(s, draw_gdiplus_first->cbSize); /* cbSize (2 bytes) */
3060 Stream_Read_UINT32(s, draw_gdiplus_first->cbTotalSize); /* cbTotalSize (4 bytes) */
3061 Stream_Read_UINT32(s, draw_gdiplus_first->cbTotalEmfSize); /* cbTotalEmfSize (4 bytes) */
3062 return Stream_SafeSeek(s, draw_gdiplus_first->cbSize); /* emfRecords */
3064 static BOOL update_read_draw_gdiplus_next_order(wStream* s,
3065 DRAW_GDIPLUS_NEXT_ORDER* draw_gdiplus_next)
3067 if (Stream_GetRemainingLength(s) < 3)
3070 Stream_Seek_UINT8(s); /* pad1Octet (1 byte) */
3071 FIELD_SKIP_BUFFER16(s, draw_gdiplus_next->cbSize); /* cbSize(2 bytes) + emfRecords */
3074 static BOOL update_read_draw_gdiplus_end_order(wStream* s, DRAW_GDIPLUS_END_ORDER* draw_gdiplus_end)
3076 if (Stream_GetRemainingLength(s) < 11)
3079 Stream_Seek_UINT8(s); /* pad1Octet (1 byte) */
3080 Stream_Read_UINT16(s, draw_gdiplus_end->cbSize); /* cbSize (2 bytes) */
3081 Stream_Read_UINT32(s, draw_gdiplus_end->cbTotalSize); /* cbTotalSize (4 bytes) */
3082 Stream_Read_UINT32(s, draw_gdiplus_end->cbTotalEmfSize); /* cbTotalEmfSize (4 bytes) */
3083 return Stream_SafeSeek(s, draw_gdiplus_end->cbSize); /* emfRecords */
3086 update_read_draw_gdiplus_cache_first_order(wStream* s,
3087 DRAW_GDIPLUS_CACHE_FIRST_ORDER* draw_gdiplus_cache_first)
3089 if (Stream_GetRemainingLength(s) < 11)
3092 Stream_Read_UINT8(s, draw_gdiplus_cache_first->flags); /* flags (1 byte) */
3093 Stream_Read_UINT16(s, draw_gdiplus_cache_first->cacheType); /* cacheType (2 bytes) */
3094 Stream_Read_UINT16(s, draw_gdiplus_cache_first->cacheIndex); /* cacheIndex (2 bytes) */
3095 Stream_Read_UINT16(s, draw_gdiplus_cache_first->cbSize); /* cbSize (2 bytes) */
3096 Stream_Read_UINT32(s, draw_gdiplus_cache_first->cbTotalSize); /* cbTotalSize (4 bytes) */
3097 return Stream_SafeSeek(s, draw_gdiplus_cache_first->cbSize); /* emfRecords */
3100 update_read_draw_gdiplus_cache_next_order(wStream* s,
3101 DRAW_GDIPLUS_CACHE_NEXT_ORDER* draw_gdiplus_cache_next)
3103 if (Stream_GetRemainingLength(s) < 7)
3106 Stream_Read_UINT8(s, draw_gdiplus_cache_next->flags); /* flags (1 byte) */
3107 Stream_Read_UINT16(s, draw_gdiplus_cache_next->cacheType); /* cacheType (2 bytes) */
3108 Stream_Read_UINT16(s, draw_gdiplus_cache_next->cacheIndex); /* cacheIndex (2 bytes) */
3109 FIELD_SKIP_BUFFER16(s, draw_gdiplus_cache_next->cbSize); /* cbSize(2 bytes) + emfRecords */
3113 update_read_draw_gdiplus_cache_end_order(wStream* s,
3114 DRAW_GDIPLUS_CACHE_END_ORDER* draw_gdiplus_cache_end)
3116 if (Stream_GetRemainingLength(s) < 11)
3119 Stream_Read_UINT8(s, draw_gdiplus_cache_end->flags); /* flags (1 byte) */
3120 Stream_Read_UINT16(s, draw_gdiplus_cache_end->cacheType); /* cacheType (2 bytes) */
3121 Stream_Read_UINT16(s, draw_gdiplus_cache_end->cacheIndex); /* cacheIndex (2 bytes) */
3122 Stream_Read_UINT16(s, draw_gdiplus_cache_end->cbSize); /* cbSize (2 bytes) */
3123 Stream_Read_UINT32(s, draw_gdiplus_cache_end->cbTotalSize); /* cbTotalSize (4 bytes) */
3124 return Stream_SafeSeek(s, draw_gdiplus_cache_end->cbSize); /* emfRecords */
3126 static BOOL update_read_field_flags(wStream* s, UINT32* fieldFlags, BYTE flags, BYTE fieldBytes)
3131 if (flags & ORDER_ZERO_FIELD_BYTE_BIT0)
3134 if (flags & ORDER_ZERO_FIELD_BYTE_BIT1)
3142 if (Stream_GetRemainingLength(s) < fieldBytes)
3147 for (i = 0; i < fieldBytes; i++)
3149 Stream_Read_UINT8(s, byte);
3150 *fieldFlags |= byte << (i * 8);
3155 BOOL update_write_field_flags(wStream* s, UINT32 fieldFlags, BYTE flags, BYTE fieldBytes)
3159 if (fieldBytes == 1)
3161 byte = fieldFlags & 0xFF;
3162 Stream_Write_UINT8(s, byte);
3164 else if (fieldBytes == 2)
3166 byte = fieldFlags & 0xFF;
3167 Stream_Write_UINT8(s, byte);
3168 byte = (fieldFlags >> 8) & 0xFF;
3169 Stream_Write_UINT8(s, byte);
3171 else if (fieldBytes == 3)
3173 byte = fieldFlags & 0xFF;
3174 Stream_Write_UINT8(s, byte);
3175 byte = (fieldFlags >> 8) & 0xFF;
3176 Stream_Write_UINT8(s, byte);
3177 byte = (fieldFlags >> 16) & 0xFF;
3178 Stream_Write_UINT8(s, byte);
3187 static BOOL update_read_bounds(wStream* s, rdpBounds* bounds)
3191 if (Stream_GetRemainingLength(s) < 1)
3194 Stream_Read_UINT8(s, flags); /* field flags */
3196 if (flags & BOUND_LEFT)
3198 if (!update_read_coord(s, &bounds->left, FALSE))
3201 else if (flags & BOUND_DELTA_LEFT)
3203 if (!update_read_coord(s, &bounds->left, TRUE))
3207 if (flags & BOUND_TOP)
3209 if (!update_read_coord(s, &bounds->top, FALSE))
3212 else if (flags & BOUND_DELTA_TOP)
3214 if (!update_read_coord(s, &bounds->top, TRUE))
3218 if (flags & BOUND_RIGHT)
3220 if (!update_read_coord(s, &bounds->right, FALSE))
3223 else if (flags & BOUND_DELTA_RIGHT)
3225 if (!update_read_coord(s, &bounds->right, TRUE))
3229 if (flags & BOUND_BOTTOM)
3231 if (!update_read_coord(s, &bounds->bottom, FALSE))
3234 else if (flags & BOUND_DELTA_BOTTOM)
3236 if (!update_read_coord(s, &bounds->bottom, TRUE))
3242 BOOL update_write_bounds(wStream* s, ORDER_INFO* orderInfo)
3244 if (!(orderInfo->controlFlags & ORDER_BOUNDS))
3247 if (orderInfo->controlFlags & ORDER_ZERO_BOUNDS_DELTAS)
3250 Stream_Write_UINT8(s, orderInfo->boundsFlags); /* field flags */
3252 if (orderInfo->boundsFlags & BOUND_LEFT)
3254 if (!update_write_coord(s, orderInfo->bounds.left))
3257 else if (orderInfo->boundsFlags & BOUND_DELTA_LEFT)
3261 if (orderInfo->boundsFlags & BOUND_TOP)
3263 if (!update_write_coord(s, orderInfo->bounds.top))
3266 else if (orderInfo->boundsFlags & BOUND_DELTA_TOP)
3270 if (orderInfo->boundsFlags & BOUND_RIGHT)
3272 if (!update_write_coord(s, orderInfo->bounds.right))
3275 else if (orderInfo->boundsFlags & BOUND_DELTA_RIGHT)
3279 if (orderInfo->boundsFlags & BOUND_BOTTOM)
3281 if (!update_write_coord(s, orderInfo->bounds.bottom))
3284 else if (orderInfo->boundsFlags & BOUND_DELTA_BOTTOM)
3291 static BOOL read_primary_order(wLog* log, const char* orderName, wStream* s,
3292 const ORDER_INFO* orderInfo, rdpPrimaryUpdate* primary)
3296 if (!s || !orderInfo || !primary || !orderName)
3299 switch (orderInfo->orderType)
3301 case ORDER_TYPE_DSTBLT:
3302 rc = update_read_dstblt_order(s, orderInfo, &(primary->dstblt));
3305 case ORDER_TYPE_PATBLT:
3306 rc = update_read_patblt_order(s, orderInfo, &(primary->patblt));
3309 case ORDER_TYPE_SCRBLT:
3310 rc = update_read_scrblt_order(s, orderInfo, &(primary->scrblt));
3313 case ORDER_TYPE_OPAQUE_RECT:
3314 rc = update_read_opaque_rect_order(s, orderInfo, &(primary->opaque_rect));
3317 case ORDER_TYPE_DRAW_NINE_GRID:
3318 rc = update_read_draw_nine_grid_order(s, orderInfo, &(primary->draw_nine_grid));
3321 case ORDER_TYPE_MULTI_DSTBLT:
3322 rc = update_read_multi_dstblt_order(s, orderInfo, &(primary->multi_dstblt));
3325 case ORDER_TYPE_MULTI_PATBLT:
3326 rc = update_read_multi_patblt_order(s, orderInfo, &(primary->multi_patblt));
3329 case ORDER_TYPE_MULTI_SCRBLT:
3330 rc = update_read_multi_scrblt_order(s, orderInfo, &(primary->multi_scrblt));
3333 case ORDER_TYPE_MULTI_OPAQUE_RECT:
3334 rc = update_read_multi_opaque_rect_order(s, orderInfo, &(primary->multi_opaque_rect));
3337 case ORDER_TYPE_MULTI_DRAW_NINE_GRID:
3338 rc = update_read_multi_draw_nine_grid_order(s, orderInfo,
3339 &(primary->multi_draw_nine_grid));
3342 case ORDER_TYPE_LINE_TO:
3343 rc = update_read_line_to_order(s, orderInfo, &(primary->line_to));
3346 case ORDER_TYPE_POLYLINE:
3347 rc = update_read_polyline_order(s, orderInfo, &(primary->polyline));
3350 case ORDER_TYPE_MEMBLT:
3351 rc = update_read_memblt_order(s, orderInfo, &(primary->memblt));
3354 case ORDER_TYPE_MEM3BLT:
3355 rc = update_read_mem3blt_order(s, orderInfo, &(primary->mem3blt));
3358 case ORDER_TYPE_SAVE_BITMAP:
3359 rc = update_read_save_bitmap_order(s, orderInfo, &(primary->save_bitmap));
3362 case ORDER_TYPE_GLYPH_INDEX:
3363 rc = update_read_glyph_index_order(s, orderInfo, &(primary->glyph_index));
3366 case ORDER_TYPE_FAST_INDEX:
3367 rc = update_read_fast_index_order(s, orderInfo, &(primary->fast_index));
3370 case ORDER_TYPE_FAST_GLYPH:
3371 rc = update_read_fast_glyph_order(s, orderInfo, &(primary->fast_glyph));
3374 case ORDER_TYPE_POLYGON_SC:
3375 rc = update_read_polygon_sc_order(s, orderInfo, &(primary->polygon_sc));
3378 case ORDER_TYPE_POLYGON_CB:
3379 rc = update_read_polygon_cb_order(s, orderInfo, &(primary->polygon_cb));
3382 case ORDER_TYPE_ELLIPSE_SC:
3383 rc = update_read_ellipse_sc_order(s, orderInfo, &(primary->ellipse_sc));
3386 case ORDER_TYPE_ELLIPSE_CB:
3387 rc = update_read_ellipse_cb_order(s, orderInfo, &(primary->ellipse_cb));
3391 WLog_Print(log, WLOG_WARN, "Primary Drawing Order %s not supported, ignoring",
3399 WLog_Print(log, WLOG_ERROR, "%s - update_read_dstblt_order() failed", orderName);
3406 static BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags)
3410 rdpContext* context = update->context;
3411 rdpPrimaryUpdate* primary = update->primary;
3412 ORDER_INFO* orderInfo = &(primary->order_info);
3413 rdpSettings* settings = context->settings;
3414 const char* orderName;
3416 if (flags & ORDER_TYPE_CHANGE)
3418 if (Stream_GetRemainingLength(s) < 1)
3420 WLog_Print(update->log, WLOG_ERROR, "Stream_GetRemainingLength(s) < 1");
3424 Stream_Read_UINT8(s, orderInfo->orderType); /* orderType (1 byte) */
3427 orderName = primary_order_string(orderInfo->orderType);
3429 if (!check_primary_order_supported(update->log, settings, orderInfo->orderType, orderName))
3432 field = get_primary_drawing_order_field_bytes(orderInfo->orderType, &rc);
3436 if (!update_read_field_flags(s, &(orderInfo->fieldFlags), flags, field))
3438 WLog_Print(update->log, WLOG_ERROR, "update_read_field_flags() failed");
3442 if (flags & ORDER_BOUNDS)
3444 if (!(flags & ORDER_ZERO_BOUNDS_DELTAS))
3446 if (!update_read_bounds(s, &orderInfo->bounds))
3448 WLog_Print(update->log, WLOG_ERROR, "update_read_bounds() failed");
3453 rc = IFCALLRESULT(FALSE, update->SetBounds, context, &orderInfo->bounds);
3459 orderInfo->deltaCoordinates = (flags & ORDER_DELTA_COORDINATES) ? TRUE : FALSE;
3461 if (!read_primary_order(update->log, orderName, s, orderInfo, primary))
3464 switch (orderInfo->orderType)
3466 case ORDER_TYPE_DSTBLT:
3468 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s rop=%s [0x%08" PRIx32 "]",
3469 orderName, gdi_rop3_code_string(primary->dstblt.bRop),
3470 gdi_rop3_code(primary->dstblt.bRop));
3471 rc = IFCALLRESULT(FALSE, primary->DstBlt, context, &primary->dstblt);
3475 case ORDER_TYPE_PATBLT:
3477 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s rop=%s [0x%08" PRIx32 "]",
3478 orderName, gdi_rop3_code_string(primary->patblt.bRop),
3479 gdi_rop3_code(primary->patblt.bRop));
3480 rc = IFCALLRESULT(FALSE, primary->PatBlt, context, &primary->patblt);
3484 case ORDER_TYPE_SCRBLT:
3486 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s rop=%s [0x%08" PRIx32 "]",
3487 orderName, gdi_rop3_code_string(primary->scrblt.bRop),
3488 gdi_rop3_code(primary->scrblt.bRop));
3489 rc = IFCALLRESULT(FALSE, primary->ScrBlt, context, &primary->scrblt);
3493 case ORDER_TYPE_OPAQUE_RECT:
3495 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s", orderName);
3496 rc = IFCALLRESULT(FALSE, primary->OpaqueRect, context, &primary->opaque_rect);
3500 case ORDER_TYPE_DRAW_NINE_GRID:
3502 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s", orderName);
3503 rc = IFCALLRESULT(FALSE, primary->DrawNineGrid, context, &primary->draw_nine_grid);
3507 case ORDER_TYPE_MULTI_DSTBLT:
3509 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s rop=%s [0x%08" PRIx32 "]",
3510 orderName, gdi_rop3_code_string(primary->multi_dstblt.bRop),
3511 gdi_rop3_code(primary->multi_dstblt.bRop));
3512 rc = IFCALLRESULT(FALSE, primary->MultiDstBlt, context, &primary->multi_dstblt);
3516 case ORDER_TYPE_MULTI_PATBLT:
3518 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s rop=%s [0x%08" PRIx32 "]",
3519 orderName, gdi_rop3_code_string(primary->multi_patblt.bRop),
3520 gdi_rop3_code(primary->multi_patblt.bRop));
3521 rc = IFCALLRESULT(FALSE, primary->MultiPatBlt, context, &primary->multi_patblt);
3525 case ORDER_TYPE_MULTI_SCRBLT:
3527 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s rop=%s [0x%08" PRIx32 "]",
3528 orderName, gdi_rop3_code_string(primary->multi_scrblt.bRop),
3529 gdi_rop3_code(primary->multi_scrblt.bRop));
3530 rc = IFCALLRESULT(FALSE, primary->MultiScrBlt, context, &primary->multi_scrblt);
3534 case ORDER_TYPE_MULTI_OPAQUE_RECT:
3536 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s", orderName);
3538 IFCALLRESULT(FALSE, primary->MultiOpaqueRect, context, &primary->multi_opaque_rect);
3542 case ORDER_TYPE_MULTI_DRAW_NINE_GRID:
3544 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s", orderName);
3545 rc = IFCALLRESULT(FALSE, primary->MultiDrawNineGrid, context,
3546 &primary->multi_draw_nine_grid);
3550 case ORDER_TYPE_LINE_TO:
3552 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s", orderName);
3553 rc = IFCALLRESULT(FALSE, primary->LineTo, context, &primary->line_to);
3557 case ORDER_TYPE_POLYLINE:
3559 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s", orderName);
3560 rc = IFCALLRESULT(FALSE, primary->Polyline, context, &primary->polyline);
3564 case ORDER_TYPE_MEMBLT:
3566 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s rop=%s [0x%08" PRIx32 "]",
3567 orderName, gdi_rop3_code_string(primary->memblt.bRop),
3568 gdi_rop3_code(primary->memblt.bRop));
3569 rc = IFCALLRESULT(FALSE, primary->MemBlt, context, &primary->memblt);
3573 case ORDER_TYPE_MEM3BLT:
3575 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s rop=%s [0x%08" PRIx32 "]",
3576 orderName, gdi_rop3_code_string(primary->mem3blt.bRop),
3577 gdi_rop3_code(primary->mem3blt.bRop));
3578 rc = IFCALLRESULT(FALSE, primary->Mem3Blt, context, &primary->mem3blt);
3582 case ORDER_TYPE_SAVE_BITMAP:
3584 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s", orderName);
3585 rc = IFCALLRESULT(FALSE, primary->SaveBitmap, context, &primary->save_bitmap);
3589 case ORDER_TYPE_GLYPH_INDEX:
3591 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s", orderName);
3592 rc = IFCALLRESULT(FALSE, primary->GlyphIndex, context, &primary->glyph_index);
3596 case ORDER_TYPE_FAST_INDEX:
3598 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s", orderName);
3599 rc = IFCALLRESULT(FALSE, primary->FastIndex, context, &primary->fast_index);
3603 case ORDER_TYPE_FAST_GLYPH:
3605 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s", orderName);
3606 rc = IFCALLRESULT(FALSE, primary->FastGlyph, context, &primary->fast_glyph);
3610 case ORDER_TYPE_POLYGON_SC:
3612 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s", orderName);
3613 rc = IFCALLRESULT(FALSE, primary->PolygonSC, context, &primary->polygon_sc);
3617 case ORDER_TYPE_POLYGON_CB:
3619 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s", orderName);
3620 rc = IFCALLRESULT(FALSE, primary->PolygonCB, context, &primary->polygon_cb);
3624 case ORDER_TYPE_ELLIPSE_SC:
3626 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s", orderName);
3627 rc = IFCALLRESULT(FALSE, primary->EllipseSC, context, &primary->ellipse_sc);
3631 case ORDER_TYPE_ELLIPSE_CB:
3633 WLog_Print(update->log, WLOG_DEBUG, "Primary Drawing Order %s", orderName);
3634 rc = IFCALLRESULT(FALSE, primary->EllipseCB, context, &primary->ellipse_cb);
3639 WLog_Print(update->log, WLOG_WARN, "Primary Drawing Order %s not supported", orderName);
3645 WLog_Print(update->log, WLOG_WARN, "Primary Drawing Order %s failed", orderName);
3649 if (flags & ORDER_BOUNDS)
3651 rc = IFCALLRESULT(FALSE, update->SetBounds, context, NULL);
3657 static BOOL update_recv_secondary_order(rdpUpdate* update, wStream* s, BYTE flags)
3660 size_t start, end, pos, diff;
3664 rdpContext* context = update->context;
3665 rdpSettings* settings = context->settings;
3666 rdpSecondaryUpdate* secondary = update->secondary;
3669 if (Stream_GetRemainingLength(s) < 5)
3671 WLog_Print(update->log, WLOG_ERROR, "Stream_GetRemainingLength(s) < 5");
3675 Stream_Read_UINT16(s, orderLength); /* orderLength (2 bytes) */
3676 Stream_Read_UINT16(s, extraFlags); /* extraFlags (2 bytes) */
3677 Stream_Read_UINT8(s, orderType); /* orderType (1 byte) */
3679 * According to [MS-RDPEGDI] 2.2.2.2.1.2.1.1 the order length must be increased by 13 bytes
3680 * including the header. As we already read the header 7 left
3682 if (Stream_GetRemainingLength(s) < orderLength + 7U)
3684 WLog_Print(update->log, WLOG_ERROR, "Stream_GetRemainingLength(s) %" PRIuz " < %" PRIu16,
3685 Stream_GetRemainingLength(s), orderLength + 7);
3689 start = Stream_GetPosition(s);
3690 name = secondary_order_string(orderType);
3691 WLog_Print(update->log, WLOG_DEBUG, "Secondary Drawing Order %s", name);
3693 if (!check_secondary_order_supported(update->log, settings, orderType, name))
3698 case ORDER_TYPE_BITMAP_UNCOMPRESSED:
3699 case ORDER_TYPE_CACHE_BITMAP_COMPRESSED:
3701 const BOOL compressed = (orderType == ORDER_TYPE_CACHE_BITMAP_COMPRESSED);
3702 CACHE_BITMAP_ORDER* order =
3703 update_read_cache_bitmap_order(update, s, compressed, extraFlags);
3707 rc = IFCALLRESULT(FALSE, secondary->CacheBitmap, context, order);
3708 free_cache_bitmap_order(context, order);
3713 case ORDER_TYPE_BITMAP_UNCOMPRESSED_V2:
3714 case ORDER_TYPE_BITMAP_COMPRESSED_V2:
3716 const BOOL compressed = (orderType == ORDER_TYPE_BITMAP_COMPRESSED_V2);
3717 CACHE_BITMAP_V2_ORDER* order =
3718 update_read_cache_bitmap_v2_order(update, s, compressed, extraFlags);
3722 rc = IFCALLRESULT(FALSE, secondary->CacheBitmapV2, context, order);
3723 free_cache_bitmap_v2_order(context, order);
3728 case ORDER_TYPE_BITMAP_COMPRESSED_V3:
3730 CACHE_BITMAP_V3_ORDER* order = update_read_cache_bitmap_v3_order(update, s, extraFlags);
3734 rc = IFCALLRESULT(FALSE, secondary->CacheBitmapV3, context, order);
3735 free_cache_bitmap_v3_order(context, order);
3740 case ORDER_TYPE_CACHE_COLOR_TABLE:
3742 CACHE_COLOR_TABLE_ORDER* order =
3743 update_read_cache_color_table_order(update, s, extraFlags);
3747 rc = IFCALLRESULT(FALSE, secondary->CacheColorTable, context, order);
3748 free_cache_color_table_order(context, order);
3753 case ORDER_TYPE_CACHE_GLYPH:
3755 switch (settings->GlyphSupportLevel)
3757 case GLYPH_SUPPORT_PARTIAL:
3758 case GLYPH_SUPPORT_FULL:
3760 CACHE_GLYPH_ORDER* order = update_read_cache_glyph_order(update, s, extraFlags);
3764 rc = IFCALLRESULT(FALSE, secondary->CacheGlyph, context, order);
3765 free_cache_glyph_order(context, order);
3770 case GLYPH_SUPPORT_ENCODE:
3772 CACHE_GLYPH_V2_ORDER* order =
3773 update_read_cache_glyph_v2_order(update, s, extraFlags);
3777 rc = IFCALLRESULT(FALSE, secondary->CacheGlyphV2, context, order);
3778 free_cache_glyph_v2_order(context, order);
3783 case GLYPH_SUPPORT_NONE:
3790 case ORDER_TYPE_CACHE_BRUSH:
3791 /* [MS-RDPEGDI] 2.2.2.2.1.2.7 Cache Brush (CACHE_BRUSH_ORDER) */
3793 CACHE_BRUSH_ORDER* order = update_read_cache_brush_order(update, s, extraFlags);
3797 rc = IFCALLRESULT(FALSE, secondary->CacheBrush, context, order);
3798 free_cache_brush_order(context, order);
3804 WLog_Print(update->log, WLOG_WARN, "SECONDARY ORDER %s not supported", name);
3810 WLog_Print(update->log, WLOG_ERROR, "SECONDARY ORDER %s failed", name);
3813 end = start + orderLength + 7;
3814 pos = Stream_GetPosition(s);
3817 WLog_Print(update->log, WLOG_WARN, "SECONDARY_ORDER %s: read %" PRIuz "bytes too much",
3824 WLog_Print(update->log, WLOG_DEBUG,
3825 "SECONDARY_ORDER %s: read %" PRIuz "bytes short, skipping", name, diff);
3826 if (!Stream_SafeSeek(s, diff))
3832 static BOOL read_altsec_order(wStream* s, BYTE orderType, rdpAltSecUpdate* altsec)
3838 case ORDER_TYPE_CREATE_OFFSCREEN_BITMAP:
3839 rc = update_read_create_offscreen_bitmap_order(s, &(altsec->create_offscreen_bitmap));
3842 case ORDER_TYPE_SWITCH_SURFACE:
3843 rc = update_read_switch_surface_order(s, &(altsec->switch_surface));
3846 case ORDER_TYPE_CREATE_NINE_GRID_BITMAP:
3847 rc = update_read_create_nine_grid_bitmap_order(s, &(altsec->create_nine_grid_bitmap));
3850 case ORDER_TYPE_FRAME_MARKER:
3851 rc = update_read_frame_marker_order(s, &(altsec->frame_marker));
3854 case ORDER_TYPE_STREAM_BITMAP_FIRST:
3855 rc = update_read_stream_bitmap_first_order(s, &(altsec->stream_bitmap_first));
3858 case ORDER_TYPE_STREAM_BITMAP_NEXT:
3859 rc = update_read_stream_bitmap_next_order(s, &(altsec->stream_bitmap_next));
3862 case ORDER_TYPE_GDIPLUS_FIRST:
3863 rc = update_read_draw_gdiplus_first_order(s, &(altsec->draw_gdiplus_first));
3866 case ORDER_TYPE_GDIPLUS_NEXT:
3867 rc = update_read_draw_gdiplus_next_order(s, &(altsec->draw_gdiplus_next));
3870 case ORDER_TYPE_GDIPLUS_END:
3871 rc = update_read_draw_gdiplus_end_order(s, &(altsec->draw_gdiplus_end));
3874 case ORDER_TYPE_GDIPLUS_CACHE_FIRST:
3875 rc = update_read_draw_gdiplus_cache_first_order(s, &(altsec->draw_gdiplus_cache_first));
3878 case ORDER_TYPE_GDIPLUS_CACHE_NEXT:
3879 rc = update_read_draw_gdiplus_cache_next_order(s, &(altsec->draw_gdiplus_cache_next));
3882 case ORDER_TYPE_GDIPLUS_CACHE_END:
3883 rc = update_read_draw_gdiplus_cache_end_order(s, &(altsec->draw_gdiplus_cache_end));
3886 case ORDER_TYPE_WINDOW:
3887 /* This order is handled elsewhere. */
3891 case ORDER_TYPE_COMPDESK_FIRST:
3902 static BOOL update_recv_altsec_order(rdpUpdate* update, wStream* s, BYTE flags)
3904 BYTE orderType = flags >>= 2; /* orderType is in higher 6 bits of flags field */
3906 rdpContext* context = update->context;
3907 rdpSettings* settings = context->settings;
3908 rdpAltSecUpdate* altsec = update->altsec;
3909 const char* orderName = altsec_order_string(orderType);
3910 WLog_Print(update->log, WLOG_DEBUG, "Alternate Secondary Drawing Order %s", orderName);
3912 if (!check_alt_order_supported(update->log, settings, orderType, orderName))
3915 if (!read_altsec_order(s, orderType, altsec))
3920 case ORDER_TYPE_CREATE_OFFSCREEN_BITMAP:
3921 IFCALLRET(altsec->CreateOffscreenBitmap, rc, context,
3922 &(altsec->create_offscreen_bitmap));
3925 case ORDER_TYPE_SWITCH_SURFACE:
3926 IFCALLRET(altsec->SwitchSurface, rc, context, &(altsec->switch_surface));
3929 case ORDER_TYPE_CREATE_NINE_GRID_BITMAP:
3930 IFCALLRET(altsec->CreateNineGridBitmap, rc, context,
3931 &(altsec->create_nine_grid_bitmap));
3934 case ORDER_TYPE_FRAME_MARKER:
3935 IFCALLRET(altsec->FrameMarker, rc, context, &(altsec->frame_marker));
3938 case ORDER_TYPE_STREAM_BITMAP_FIRST:
3939 IFCALLRET(altsec->StreamBitmapFirst, rc, context, &(altsec->stream_bitmap_first));
3942 case ORDER_TYPE_STREAM_BITMAP_NEXT:
3943 IFCALLRET(altsec->StreamBitmapNext, rc, context, &(altsec->stream_bitmap_next));
3946 case ORDER_TYPE_GDIPLUS_FIRST:
3947 IFCALLRET(altsec->DrawGdiPlusFirst, rc, context, &(altsec->draw_gdiplus_first));
3950 case ORDER_TYPE_GDIPLUS_NEXT:
3951 IFCALLRET(altsec->DrawGdiPlusNext, rc, context, &(altsec->draw_gdiplus_next));
3954 case ORDER_TYPE_GDIPLUS_END:
3955 IFCALLRET(altsec->DrawGdiPlusEnd, rc, context, &(altsec->draw_gdiplus_end));
3958 case ORDER_TYPE_GDIPLUS_CACHE_FIRST:
3959 IFCALLRET(altsec->DrawGdiPlusCacheFirst, rc, context,
3960 &(altsec->draw_gdiplus_cache_first));
3963 case ORDER_TYPE_GDIPLUS_CACHE_NEXT:
3964 IFCALLRET(altsec->DrawGdiPlusCacheNext, rc, context,
3965 &(altsec->draw_gdiplus_cache_next));
3968 case ORDER_TYPE_GDIPLUS_CACHE_END:
3969 IFCALLRET(altsec->DrawGdiPlusCacheEnd, rc, context, &(altsec->draw_gdiplus_cache_end));
3972 case ORDER_TYPE_WINDOW:
3973 rc = update_recv_altsec_window_order(update, s);
3976 case ORDER_TYPE_COMPDESK_FIRST:
3986 WLog_Print(update->log, WLOG_WARN, "Alternate Secondary Drawing Order %s failed",
3992 BOOL update_recv_order(rdpUpdate* update, wStream* s)
3997 if (Stream_GetRemainingLength(s) < 1)
3999 WLog_Print(update->log, WLOG_ERROR, "Stream_GetRemainingLength(s) < 1");
4003 Stream_Read_UINT8(s, controlFlags); /* controlFlags (1 byte) */
4005 if (!(controlFlags & ORDER_STANDARD))
4006 rc = update_recv_altsec_order(update, s, controlFlags);
4007 else if (controlFlags & ORDER_SECONDARY)
4008 rc = update_recv_secondary_order(update, s, controlFlags);
4010 rc = update_recv_primary_order(update, s, controlFlags);
4013 WLog_Print(update->log, WLOG_ERROR, "order flags %02" PRIx8 " failed", controlFlags);