From f9a89ae6b4cc0c5ea50d750d29ced7f75f405875 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Fri, 15 Jul 2016 16:23:00 +0200 Subject: [PATCH] Bug fixes, refactoring. --- include/freerdp/cache/cache.h | 4 - include/freerdp/codec/color.h | 68 +-- libfreerdp/cache/cache.c | 47 +- libfreerdp/cache/offscreen.c | 26 +- libfreerdp/core/orders.c | 946 ++++++++++++++++++---------------- libfreerdp/gdi/CMakeLists.txt | 2 +- libfreerdp/gdi/bitmap.c | 7 +- libfreerdp/gdi/gdi.c | 44 +- libfreerdp/gdi/graphics.c | 33 +- 9 files changed, 612 insertions(+), 565 deletions(-) diff --git a/include/freerdp/cache/cache.h b/include/freerdp/cache/cache.h index a25812ba5..30721f566 100644 --- a/include/freerdp/cache/cache.h +++ b/include/freerdp/cache/cache.h @@ -43,10 +43,6 @@ struct rdp_cache rdpOffscreenCache* offscreen; /* 4 */ rdpPaletteCache* palette; /* 5 */ rdpNineGridCache* nine_grid; /* 6 */ - - /* internal */ - - rdpSettings* settings; }; #ifdef __cplusplus diff --git a/include/freerdp/codec/color.h b/include/freerdp/codec/color.h index 546c7c410..86f2272dd 100644 --- a/include/freerdp/codec/color.h +++ b/include/freerdp/codec/color.h @@ -129,8 +129,8 @@ struct gdi_palette { - UINT32 format; - UINT32 palette[256]; + UINT32 format; + UINT32 palette[256]; }; typedef struct gdi_palette gdiPalette; @@ -269,7 +269,7 @@ static const char* GetColorFormatName(UINT32 format) } static INLINE void SplitColor(UINT32 color, UINT32 format, BYTE* _r, BYTE* _g, - BYTE* _b, BYTE* _a, const gdiPalette* palette) + BYTE* _b, BYTE* _a, const gdiPalette* palette) { UINT32 tmp; @@ -521,28 +521,32 @@ static INLINE void SplitColor(UINT32 color, UINT32 format, BYTE* _r, BYTE* _g, /* 8bpp formats */ case PIXEL_FORMAT_RGB8: - if (color <= 0xFF) - { - tmp = palette->palette[color]; - SplitColor(tmp, palette->format, _r, _g, _b, _a, NULL); - } + if (color <= 0xFF) + { + tmp = palette->palette[color]; + SplitColor(tmp, palette->format, _r, _g, _b, _a, NULL); + } + break; /* 1bpp formats */ case PIXEL_FORMAT_MONO: if (_r) *_r = (color) ? 0xFF : 0x00; + if (_g) *_g = (color) ? 0xFF : 0x00; + if (_b) *_b = (color) ? 0xFF : 0x00; + if (_a) *_a = (color) ? 0xFF : 0x00; + break; + /* 4 bpp formats */ case PIXEL_FORMAT_A4: - - default: WLog_ERR("xxxxx", "Unsupported format %s", GetColorFormatName(format)); break; @@ -593,28 +597,28 @@ static INLINE UINT32 GetColor(UINT32 format, BYTE r, BYTE g, BYTE b, BYTE a) /* 16bpp formats */ case PIXEL_FORMAT_RGB16: return (((_r >> 3) & 0x1F) << 11) | (((_g >> 2) & 0x3F) << 5) | (( - _b >> 3) & 0x1F); + _b >> 3) & 0x1F); case PIXEL_FORMAT_BGR16: return (((_b >> 3) & 0x1F) << 11) | (((_g >> 2) & 0x3F) << 5) | (( - _r >> 3) & 0x1F); + _r >> 3) & 0x1F); case PIXEL_FORMAT_ARGB15: return (((_r >> 3) & 0x1F) << 10) | (((_g >> 3) & 0x1F) << 5) | (( - _b >> 3) & 0x1F); + _b >> 3) & 0x1F); case PIXEL_FORMAT_ABGR15: return (((_b >> 3) & 0x1F) << 10) | (((_g >> 3) & 0x1F) << 5) | (( - _r >> 3) & 0x1F); + _r >> 3) & 0x1F); /* 15bpp formats */ case PIXEL_FORMAT_RGB15: return (((_r >> 3) & 0x1F) << 10) | (((_g >> 3) & 0x1F) << 5) | (( - _b >> 3) & 0x1F); + _b >> 3) & 0x1F); case PIXEL_FORMAT_BGR15: return (((_b >> 3) & 0x1F) << 10) | (((_g >> 3) & 0x1F) << 5) | (( - _r >> 3) & 0x1F);; + _r >> 3) & 0x1F);; /* 8bpp formats */ case PIXEL_FORMAT_RGB8: @@ -653,7 +657,7 @@ static INLINE UINT32 ReadColor(const BYTE* src, UINT32 format) { case 32: color = ((UINT32)src[0] << 24) | ((UINT32)src[1] << 16) | - ((UINT32)src[2] << 8) | src[3]; + ((UINT32)src[2] << 8) | src[3]; break; case 24: @@ -718,7 +722,7 @@ static INLINE BOOL WriteColor(BYTE* dst, UINT32 format, UINT32 color) } static INLINE UINT32 ConvertColor(UINT32 color, UINT32 srcFormat, - UINT32 dstFormat, const gdiPalette* palette) + UINT32 dstFormat, const gdiPalette* palette) { BYTE r = 0; BYTE g = 0; @@ -734,15 +738,15 @@ static INLINE UINT32 GetBytesPerPixel(UINT32 format) } FREERDP_API BYTE* freerdp_glyph_convert(UINT32 width, UINT32 height, - const BYTE* data); + const BYTE* data); FREERDP_API BOOL freerdp_image_copy_from_monochrome(BYTE* pDstData, - UINT32 DstFormat, - UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, - UINT32 nWidth, UINT32 nHeight, - const BYTE* pSrcData, - UINT32 backColor, UINT32 foreColor, - const gdiPalette* palette); + UINT32 DstFormat, + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, + const BYTE* pSrcData, + UINT32 backColor, UINT32 foreColor, + const gdiPalette* palette); FREERDP_API BOOL freerdp_image_copy_from_pointer_data( BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep, @@ -752,15 +756,15 @@ FREERDP_API BOOL freerdp_image_copy_from_pointer_data( UINT32 xorBpp, const gdiPalette* palette); FREERDP_API BOOL freerdp_image_copy(BYTE* pDstData, DWORD DstFormat, - INT32 nDstStep, UINT32 nXDst, UINT32 nYDst, - UINT32 nWidth, UINT32 nHeight, - const BYTE* pSrcData, DWORD SrcFormat, - INT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, - const gdiPalette* palette); + INT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, + const BYTE* pSrcData, DWORD SrcFormat, + INT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, + const gdiPalette* palette); FREERDP_API BOOL freerdp_image_fill(BYTE* pDstData, DWORD DstFormat, - UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, - UINT32 nWidth, UINT32 nHeight, UINT32 color); + UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, + UINT32 nWidth, UINT32 nHeight, UINT32 color); #ifdef __cplusplus } diff --git a/libfreerdp/cache/cache.c b/libfreerdp/cache/cache.c index 0e42f6b6c..a0da79e8c 100644 --- a/libfreerdp/cache/cache.c +++ b/libfreerdp/cache/cache.c @@ -30,50 +30,49 @@ rdpCache* cache_new(rdpSettings* settings) { rdpCache* cache; - cache = (rdpCache*) calloc(1, sizeof(rdpCache)); + if (!cache) return NULL; - cache->settings = settings; cache->glyph = glyph_cache_new(settings); + if (!cache->glyph) - goto error_glyph; + goto error; + cache->brush = brush_cache_new(settings); + if (!cache->brush) - goto error_brush; + goto error; + cache->pointer = pointer_cache_new(settings); + if (!cache->pointer) - goto error_pointer; + goto error; + cache->bitmap = bitmap_cache_new(settings); + if (!cache->bitmap) - goto error_bitmap; + goto error; + cache->offscreen = offscreen_cache_new(settings); + if (!cache->offscreen) - goto error_offscreen; + goto error; + cache->palette = palette_cache_new(settings); + if (!cache->palette) - goto error_palette; + goto error; + cache->nine_grid = nine_grid_cache_new(settings); + if (!cache->nine_grid) - goto error_ninegrid; + goto error; return cache; - -error_ninegrid: - palette_cache_free(cache->palette); -error_palette: - offscreen_cache_free(cache->offscreen); -error_offscreen: - bitmap_cache_free(cache->bitmap); -error_bitmap: - pointer_cache_free(cache->pointer); -error_pointer: - brush_cache_free(cache->brush); -error_brush: - glyph_cache_free(cache->glyph); -error_glyph: - free(cache); +error: + cache_free(cache); return NULL; } diff --git a/libfreerdp/cache/offscreen.c b/libfreerdp/cache/offscreen.c index 59cff9bae..ace0cc0f7 100644 --- a/libfreerdp/cache/offscreen.c +++ b/libfreerdp/cache/offscreen.c @@ -32,18 +32,19 @@ #define TAG FREERDP_TAG("cache.offscreen") -static void offscreen_cache_put(rdpOffscreenCache* offscreen_cache, UINT32 index, rdpBitmap* bitmap); +static void offscreen_cache_put(rdpOffscreenCache* offscreen_cache, + UINT32 index, rdpBitmap* bitmap); static void offscreen_cache_delete(rdpOffscreenCache* offscreen, UINT32 index); static BOOL update_gdi_create_offscreen_bitmap(rdpContext* context, - const CREATE_OFFSCREEN_BITMAP_ORDER* createOffscreenBitmap) + const CREATE_OFFSCREEN_BITMAP_ORDER* createOffscreenBitmap) { - int i; + UINT32 i; UINT16 index; rdpBitmap* bitmap; rdpCache* cache = context->cache; - bitmap = Bitmap_Alloc(context); + if (!bitmap) return FALSE; @@ -59,19 +60,20 @@ static BOOL update_gdi_create_offscreen_bitmap(rdpContext* context, offscreen_cache_delete(cache->offscreen, createOffscreenBitmap->id); offscreen_cache_put(cache->offscreen, createOffscreenBitmap->id, bitmap); - if(cache->offscreen->currentSurface == createOffscreenBitmap->id) + if (cache->offscreen->currentSurface == createOffscreenBitmap->id) Bitmap_SetSurface(context, bitmap, FALSE); - for (i = 0; i < (int) createOffscreenBitmap->deleteList.cIndices; i++) + for (i = 0; i < createOffscreenBitmap->deleteList.cIndices; i++) { index = createOffscreenBitmap->deleteList.indices[i]; offscreen_cache_delete(cache->offscreen, index); } + return TRUE; } static BOOL update_gdi_switch_surface(rdpContext* context, - const SWITCH_SURFACE_ORDER* switchSurface) + const SWITCH_SURFACE_ORDER* switchSurface) { rdpCache* cache = context->cache; @@ -111,7 +113,8 @@ rdpBitmap* offscreen_cache_get(rdpOffscreenCache* offscreenCache, UINT32 index) return bitmap; } -void offscreen_cache_put(rdpOffscreenCache* offscreenCache, UINT32 index, rdpBitmap* bitmap) +void offscreen_cache_put(rdpOffscreenCache* offscreenCache, UINT32 index, + rdpBitmap* bitmap) { if (index >= offscreenCache->maxEntries) { @@ -150,7 +153,6 @@ void offscreen_cache_register_callbacks(rdpUpdate* update) rdpOffscreenCache* offscreen_cache_new(rdpSettings* settings) { rdpOffscreenCache* offscreenCache; - offscreenCache = (rdpOffscreenCache*) calloc(1, sizeof(rdpOffscreenCache)); if (!offscreenCache) @@ -158,20 +160,20 @@ rdpOffscreenCache* offscreen_cache_new(rdpSettings* settings) offscreenCache->settings = settings; offscreenCache->update = ((freerdp*) settings->instance)->update; - offscreenCache->currentSurface = SCREEN_BITMAP_SURFACE; offscreenCache->maxSize = 7680; offscreenCache->maxEntries = 2000; - settings->OffscreenCacheSize = offscreenCache->maxSize; settings->OffscreenCacheEntries = offscreenCache->maxEntries; + offscreenCache->entries = (rdpBitmap**) calloc(offscreenCache->maxEntries, + sizeof(rdpBitmap*)); - offscreenCache->entries = (rdpBitmap**) calloc(offscreenCache->maxEntries, sizeof(rdpBitmap*)); if (!offscreenCache->entries) { free(offscreenCache); return NULL; } + return offscreenCache; } diff --git a/libfreerdp/core/orders.c b/libfreerdp/core/orders.c index f41e83a23..4325347cc 100644 --- a/libfreerdp/core/orders.c +++ b/libfreerdp/core/orders.c @@ -137,44 +137,44 @@ const BYTE PRIMARY_DRAWING_ORDER_FIELD_BYTES[] = static const BYTE CBR2_BPP[] = { - 0, 0, 0, 8, 16, 24, 32 + 0, 0, 0, 8, 16, 24, 32 }; static const BYTE BPP_CBR2[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 0, 0, 0, 0, - 4, 0, 0, 0, 0, 0, 0, 0, - 5, 0, 0, 0, 0, 0, 0, 0, - 6, 0, 0, 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, 0, 0, + 5, 0, 0, 0, 0, 0, 0, 0, + 6, 0, 0, 0, 0, 0, 0, 0 }; static const BYTE CBR23_BPP[] = { - 0, 0, 0, 8, 16, 24, 32 + 0, 0, 0, 8, 16, 24, 32 }; static const BYTE BPP_CBR23[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 0, 0, 0, 0, - 4, 0, 0, 0, 0, 0, 0, 0, - 5, 0, 0, 0, 0, 0, 0, 0, - 6, 0, 0, 0, 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, 0, 0, + 5, 0, 0, 0, 0, 0, 0, 0, + 6, 0, 0, 0, 0, 0, 0, 0 }; static const BYTE BMF_BPP[] = { - 0, 1, 0, 8, 16, 24, 32 + 0, 1, 0, 8, 16, 24, 32 }; static const BYTE BPP_BMF[] = { - 0, 1, 0, 0, 0, 0, 0, 0, - 3, 0, 0, 0, 0, 0, 0, 0, - 4, 0, 0, 0, 0, 0, 0, 0, - 5, 0, 0, 0, 0, 0, 0, 0, - 6, 0, 0, 0, 0, 0, 0, 0 + 0, 1, 0, 0, 0, 0, 0, 0, + 3, 0, 0, 0, 0, 0, 0, 0, + 4, 0, 0, 0, 0, 0, 0, 0, + 5, 0, 0, 0, 0, 0, 0, 0, + 6, 0, 0, 0, 0, 0, 0, 0 }; static INLINE BOOL update_read_coord(wStream* s, INT32* coord, BOOL delta) @@ -208,18 +208,6 @@ static INLINE BOOL update_write_coord(wStream* s, INT32 coord) return TRUE; } -#if 0 -static INLINE BOOL update_write_coord_delta(wStream* s, INT32 prevCoord, INT32 nextCoord) -{ - INT8 lsi8; - - lsi8 = nextCoord - prevCoord; - Stream_Write_UINT8(s, lsi8); - - return TRUE; -} -#endif - static INLINE BOOL update_read_color(wStream* s, UINT32* color) { BYTE byte; @@ -233,28 +221,24 @@ static INLINE BOOL update_read_color(wStream* s, UINT32* color) *color |= ((UINT32) byte << 8); Stream_Read_UINT8(s, byte); *color |= (UINT32) byte; - return TRUE; } static INLINE BOOL update_write_color(wStream* s, UINT32 color) { BYTE byte; - byte = (color & 0xFF); Stream_Write_UINT8(s, byte); byte = ((color >> 8) & 0xFF); Stream_Write_UINT8(s, byte); byte = ((color >> 16) & 0xFF); Stream_Write_UINT8(s, byte); - return TRUE; } static INLINE void update_read_colorref(wStream* s, UINT32* color) { BYTE byte; - Stream_Read_UINT8(s, byte); *color = byte; Stream_Read_UINT8(s, byte); @@ -267,7 +251,6 @@ static INLINE void update_read_colorref(wStream* s, UINT32* color) static INLINE void update_read_color_quad(wStream* s, UINT32* color) { BYTE byte; - Stream_Read_UINT8(s, byte); *color = (byte << 16); Stream_Read_UINT8(s, byte); @@ -280,7 +263,6 @@ static INLINE void update_read_color_quad(wStream* s, UINT32* color) static INLINE void update_write_color_quad(wStream* s, UINT32 color) { BYTE byte; - byte = (color << 16) & 0xFF; Stream_Write_UINT8(s, byte); byte = (color << 8) & 0xFF; @@ -295,6 +277,7 @@ static INLINE BOOL update_read_2byte_unsigned(wStream* s, UINT32* value) if (Stream_GetRemainingLength(s) < 1) return FALSE; + Stream_Read_UINT8(s, byte); if (byte & 0x80) @@ -346,9 +329,7 @@ static INLINE BOOL update_read_2byte_signed(wStream* s, INT32* value) return FALSE; Stream_Read_UINT8(s, byte); - negative = (byte & 0x40) ? TRUE : FALSE; - *value = (byte & 0x3F); if (byte & 0x80) @@ -413,7 +394,6 @@ static INLINE BOOL update_read_4byte_unsigned(wStream* s, UINT32* value) return FALSE; Stream_Read_UINT8(s, byte); - count = (byte & 0xC0) >> 6; if (Stream_GetRemainingLength(s) < count) @@ -506,6 +486,7 @@ static INLINE BOOL update_read_delta(wStream* s, INT32* value) WLog_ERR(TAG, "Stream_GetRemainingLength(s) < 1"); return FALSE; } + Stream_Read_UINT8(s, byte); if (byte & 0x40) @@ -520,9 +501,11 @@ static INLINE BOOL update_read_delta(wStream* s, INT32* value) WLog_ERR(TAG, "Stream_GetRemainingLength(s) < 1"); return FALSE; } + Stream_Read_UINT8(s, byte); *value = (*value << 8) | byte; } + return TRUE; } @@ -530,7 +513,6 @@ static INLINE BOOL update_read_delta(wStream* s, INT32* value) static INLINE void update_read_glyph_delta(wStream* s, UINT16* value) { BYTE byte; - Stream_Read_UINT8(s, byte); if (byte == 0x80) @@ -542,7 +524,6 @@ static INLINE void update_read_glyph_delta(wStream* s, UINT16* value) static INLINE void update_seek_glyph_delta(wStream* s) { BYTE byte; - Stream_Read_UINT8(s, byte); if (byte & 0x80) @@ -550,7 +531,8 @@ static INLINE void update_seek_glyph_delta(wStream* s) } #endif -static INLINE BOOL update_read_brush(wStream* s, rdpBrush* brush, BYTE fieldFlags) +static INLINE BOOL update_read_brush(wStream* s, rdpBrush* brush, + BYTE fieldFlags) { if (fieldFlags & ORDER_FIELD_01) { @@ -587,7 +569,6 @@ static INLINE BOOL update_read_brush(wStream* s, rdpBrush* brush, BYTE fieldFlag if (brush->style & CACHED_BRUSH) { brush->index = brush->hatch; - brush->bpp = BMF_BPP[brush->style & 0x0F]; if (brush->bpp == 0) @@ -614,7 +595,7 @@ static INLINE BOOL update_read_brush(wStream* s, rdpBrush* brush, BYTE fieldFlag } static INLINE BOOL update_write_brush(wStream* s, rdpBrush* brush, - BYTE fieldFlags) + BYTE fieldFlags) { if (fieldFlags & ORDER_FIELD_01) { @@ -634,7 +615,6 @@ static INLINE BOOL update_write_brush(wStream* s, rdpBrush* brush, if (brush->style & CACHED_BRUSH) { brush->hatch = brush->index; - brush->bpp = BMF_BPP[brush->style & 0x0F]; if (brush->bpp == 0) @@ -662,7 +642,8 @@ static INLINE BOOL update_write_brush(wStream* s, rdpBrush* brush, return TRUE; } -static INLINE BOOL update_read_delta_rects(wStream* s, DELTA_RECT* rectangles, int number) +static INLINE BOOL update_read_delta_rects(wStream* s, DELTA_RECT* rectangles, + int number) { int i; BYTE flags = 0; @@ -679,7 +660,6 @@ static INLINE BOOL update_read_delta_rects(wStream* s, DELTA_RECT* rectangles, i Stream_GetPointer(s, zeroBits); Stream_Seek(s, zeroBitsSize); - ZeroMemory(rectangles, sizeof(DELTA_RECT) * (number + 1)); for (i = 1; i < number + 1; i++) @@ -715,20 +695,19 @@ static INLINE BOOL update_read_delta_rects(wStream* s, DELTA_RECT* rectangles, i rectangles[i].left = rectangles[i].left + rectangles[i - 1].left; rectangles[i].top = rectangles[i].top + rectangles[i - 1].top; - flags <<= 4; } return TRUE; } -static INLINE BOOL update_read_delta_points(wStream* s, DELTA_POINT* points, int number, INT16 x, INT16 y) +static INLINE BOOL update_read_delta_points(wStream* s, DELTA_POINT* points, + int number, INT16 x, INT16 y) { int i; BYTE flags = 0; BYTE* zeroBits; UINT32 zeroBitsSize; - zeroBitsSize = ((number + 3) / 4); if (Stream_GetRemainingLength(s) < zeroBitsSize) @@ -739,7 +718,6 @@ static INLINE BOOL update_read_delta_points(wStream* s, DELTA_POINT* points, int Stream_GetPointer(s, zeroBits); Stream_Seek(s, zeroBitsSize); - ZeroMemory(points, sizeof(DELTA_POINT) * number); for (i = 0; i < number; i++) @@ -761,6 +739,7 @@ static INLINE BOOL update_read_delta_points(wStream* s, DELTA_POINT* points, int flags <<= 2; } + return TRUE; } @@ -843,7 +822,8 @@ static INLINE BOOL update_read_delta_points(wStream* s, DELTA_POINT* points, int } while(0) /* Primary Drawing Orders */ -static BOOL update_read_dstblt_order(wStream* s, ORDER_INFO* orderInfo, DSTBLT_ORDER* dstblt) +static BOOL update_read_dstblt_order(wStream* s, ORDER_INFO* orderInfo, + DSTBLT_ORDER* dstblt) { ORDER_FIELD_COORD(1, dstblt->nLeftRect); ORDER_FIELD_COORD(2, dstblt->nTopRect); @@ -854,39 +834,34 @@ static BOOL update_read_dstblt_order(wStream* s, ORDER_INFO* orderInfo, DSTBLT_O } int update_approximate_dstblt_order(ORDER_INFO* orderInfo, - const DSTBLT_ORDER* dstblt) + const DSTBLT_ORDER* dstblt) { return 32; } BOOL update_write_dstblt_order(wStream* s, ORDER_INFO* orderInfo, - const DSTBLT_ORDER* dstblt) + const DSTBLT_ORDER* dstblt) { - - if (!Stream_EnsureRemainingCapacity(s, update_approximate_dstblt_order(orderInfo, dstblt))) + if (!Stream_EnsureRemainingCapacity(s, + update_approximate_dstblt_order(orderInfo, dstblt))) return FALSE; orderInfo->fieldFlags = 0; - orderInfo->fieldFlags |= ORDER_FIELD_01; update_write_coord(s, dstblt->nLeftRect); - orderInfo->fieldFlags |= ORDER_FIELD_02; update_write_coord(s, dstblt->nTopRect); - orderInfo->fieldFlags |= ORDER_FIELD_03; update_write_coord(s, dstblt->nWidth); - orderInfo->fieldFlags |= ORDER_FIELD_04; update_write_coord(s, dstblt->nHeight); - orderInfo->fieldFlags |= ORDER_FIELD_05; Stream_Write_UINT8(s, dstblt->bRop); - return TRUE; } -static BOOL update_read_patblt_order(wStream* s, ORDER_INFO* orderInfo, PATBLT_ORDER* patblt) +static BOOL update_read_patblt_order(wStream* s, ORDER_INFO* orderInfo, + PATBLT_ORDER* patblt) { ORDER_FIELD_COORD(1, patblt->nLeftRect); ORDER_FIELD_COORD(2, patblt->nTopRect); @@ -903,47 +878,39 @@ int update_approximate_patblt_order(ORDER_INFO* orderInfo, PATBLT_ORDER* patblt) return 32; } -BOOL update_write_patblt_order(wStream* s, ORDER_INFO* orderInfo, PATBLT_ORDER* patblt) +BOOL update_write_patblt_order(wStream* s, ORDER_INFO* orderInfo, + PATBLT_ORDER* patblt) { - - if (!Stream_EnsureRemainingCapacity(s, update_approximate_patblt_order(orderInfo, patblt))) + if (!Stream_EnsureRemainingCapacity(s, + update_approximate_patblt_order(orderInfo, patblt))) return FALSE; orderInfo->fieldFlags = 0; - orderInfo->fieldFlags |= ORDER_FIELD_01; update_write_coord(s, patblt->nLeftRect); - orderInfo->fieldFlags |= ORDER_FIELD_02; update_write_coord(s, patblt->nTopRect); - orderInfo->fieldFlags |= ORDER_FIELD_03; update_write_coord(s, patblt->nWidth); - orderInfo->fieldFlags |= ORDER_FIELD_04; update_write_coord(s, patblt->nHeight); - orderInfo->fieldFlags |= ORDER_FIELD_05; Stream_Write_UINT8(s, patblt->bRop); - orderInfo->fieldFlags |= ORDER_FIELD_06; update_write_color(s, patblt->backColor); - orderInfo->fieldFlags |= ORDER_FIELD_07; update_write_color(s, patblt->foreColor); - orderInfo->fieldFlags |= ORDER_FIELD_08; orderInfo->fieldFlags |= ORDER_FIELD_09; orderInfo->fieldFlags |= ORDER_FIELD_10; orderInfo->fieldFlags |= ORDER_FIELD_11; orderInfo->fieldFlags |= ORDER_FIELD_12; update_write_brush(s, &patblt->brush, orderInfo->fieldFlags >> 7); - return TRUE; } static BOOL update_read_scrblt_order(wStream* s, ORDER_INFO* orderInfo, - SCRBLT_ORDER* scrblt) + SCRBLT_ORDER* scrblt) { ORDER_FIELD_COORD(1, scrblt->nLeftRect); ORDER_FIELD_COORD(2, scrblt->nTopRect); @@ -952,54 +919,44 @@ static BOOL update_read_scrblt_order(wStream* s, ORDER_INFO* orderInfo, ORDER_FIELD_BYTE(5, scrblt->bRop); ORDER_FIELD_COORD(6, scrblt->nXSrc); ORDER_FIELD_COORD(7, scrblt->nYSrc); - return TRUE; } int update_approximate_scrblt_order(ORDER_INFO* orderInfo, - const SCRBLT_ORDER* scrblt) + const SCRBLT_ORDER* scrblt) { return 32; } BOOL update_write_scrblt_order(wStream* s, ORDER_INFO* orderInfo, - const SCRBLT_ORDER* scrblt) + const SCRBLT_ORDER* scrblt) { - - if (!Stream_EnsureRemainingCapacity(s, update_approximate_scrblt_order(orderInfo, scrblt))) + if (!Stream_EnsureRemainingCapacity(s, + update_approximate_scrblt_order(orderInfo, scrblt))) return FALSE; orderInfo->fieldFlags = 0; - orderInfo->fieldFlags |= ORDER_FIELD_01; update_write_coord(s, scrblt->nLeftRect); - orderInfo->fieldFlags |= ORDER_FIELD_02; update_write_coord(s, scrblt->nTopRect); - orderInfo->fieldFlags |= ORDER_FIELD_03; update_write_coord(s, scrblt->nWidth); - orderInfo->fieldFlags |= ORDER_FIELD_04; update_write_coord(s, scrblt->nHeight); - orderInfo->fieldFlags |= ORDER_FIELD_05; Stream_Write_UINT8(s, scrblt->bRop); - orderInfo->fieldFlags |= ORDER_FIELD_06; update_write_coord(s, scrblt->nXSrc); - orderInfo->fieldFlags |= ORDER_FIELD_07; update_write_coord(s, scrblt->nYSrc); - return TRUE; } static BOOL update_read_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, - OPAQUE_RECT_ORDER* opaque_rect) + OPAQUE_RECT_ORDER* opaque_rect) { BYTE byte; - ORDER_FIELD_COORD(1, opaque_rect->nLeftRect); ORDER_FIELD_COORD(2, opaque_rect->nTopRect); ORDER_FIELD_COORD(3, opaque_rect->nWidth); @@ -1036,13 +993,13 @@ static BOOL update_read_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, } int update_approximate_opaque_rect_order(ORDER_INFO* orderInfo, - const OPAQUE_RECT_ORDER* opaque_rect) + const OPAQUE_RECT_ORDER* opaque_rect) { return 32; } BOOL update_write_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, - const OPAQUE_RECT_ORDER* opaque_rect) + const OPAQUE_RECT_ORDER* opaque_rect) { BYTE byte; int inf = update_approximate_opaque_rect_order(orderInfo, opaque_rect); @@ -1051,7 +1008,6 @@ BOOL update_write_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, return FALSE; orderInfo->fieldFlags = 0; - orderInfo->fieldFlags |= ORDER_FIELD_01; update_write_coord(s, opaque_rect->nLeftRect); orderInfo->fieldFlags |= ORDER_FIELD_02; @@ -1060,36 +1016,31 @@ BOOL update_write_opaque_rect_order(wStream* s, ORDER_INFO* orderInfo, update_write_coord(s, opaque_rect->nWidth); orderInfo->fieldFlags |= ORDER_FIELD_04; update_write_coord(s, opaque_rect->nHeight); - orderInfo->fieldFlags |= ORDER_FIELD_05; byte = opaque_rect->color & 0x000000FF; Stream_Write_UINT8(s, byte); - orderInfo->fieldFlags |= ORDER_FIELD_06; byte = (opaque_rect->color & 0x0000FF00) >> 8; Stream_Write_UINT8(s, byte); - orderInfo->fieldFlags |= ORDER_FIELD_07; byte = (opaque_rect->color & 0x00FF0000) >> 16; Stream_Write_UINT8(s, byte); - return TRUE; } static BOOL update_read_draw_nine_grid_order(wStream* s, ORDER_INFO* orderInfo, - DRAW_NINE_GRID_ORDER* draw_nine_grid) + DRAW_NINE_GRID_ORDER* draw_nine_grid) { ORDER_FIELD_COORD(1, draw_nine_grid->srcLeft); ORDER_FIELD_COORD(2, draw_nine_grid->srcTop); ORDER_FIELD_COORD(3, draw_nine_grid->srcRight); ORDER_FIELD_COORD(4, draw_nine_grid->srcBottom); ORDER_FIELD_UINT16(5, draw_nine_grid->bitmapId); - return TRUE; } static BOOL update_read_multi_dstblt_order(wStream* s, ORDER_INFO* orderInfo, - MULTI_DSTBLT_ORDER* multi_dstblt) + MULTI_DSTBLT_ORDER* multi_dstblt) { ORDER_FIELD_COORD(1, multi_dstblt->nLeftRect); ORDER_FIELD_COORD(2, multi_dstblt->nTopRect); @@ -1104,15 +1055,15 @@ static BOOL update_read_multi_dstblt_order(wStream* s, ORDER_INFO* orderInfo, return FALSE; Stream_Read_UINT16(s, multi_dstblt->cbData); - - return update_read_delta_rects(s, multi_dstblt->rectangles, multi_dstblt->numRectangles); + return update_read_delta_rects(s, multi_dstblt->rectangles, + multi_dstblt->numRectangles); } return TRUE; } static BOOL update_read_multi_patblt_order(wStream* s, ORDER_INFO* orderInfo, - MULTI_PATBLT_ORDER* multi_patblt) + MULTI_PATBLT_ORDER* multi_patblt) { ORDER_FIELD_COORD(1, multi_patblt->nLeftRect); ORDER_FIELD_COORD(2, multi_patblt->nTopRect); @@ -1134,14 +1085,16 @@ static BOOL update_read_multi_patblt_order(wStream* s, ORDER_INFO* orderInfo, Stream_Read_UINT16(s, multi_patblt->cbData); - if (!update_read_delta_rects(s, multi_patblt->rectangles, multi_patblt->numRectangles)) + if (!update_read_delta_rects(s, multi_patblt->rectangles, + multi_patblt->numRectangles)) return FALSE; } + return TRUE; } static BOOL update_read_multi_scrblt_order(wStream* s, ORDER_INFO* orderInfo, - MULTI_SCRBLT_ORDER* multi_scrblt) + MULTI_SCRBLT_ORDER* multi_scrblt) { ORDER_FIELD_COORD(1, multi_scrblt->nLeftRect); ORDER_FIELD_COORD(2, multi_scrblt->nTopRect); @@ -1158,17 +1111,18 @@ static BOOL update_read_multi_scrblt_order(wStream* s, ORDER_INFO* orderInfo, return FALSE; Stream_Read_UINT16(s, multi_scrblt->cbData); - return update_read_delta_rects(s, multi_scrblt->rectangles, multi_scrblt->numRectangles); + return update_read_delta_rects(s, multi_scrblt->rectangles, + multi_scrblt->numRectangles); } + return TRUE; } static BOOL update_read_multi_opaque_rect_order(wStream* s, - ORDER_INFO* orderInfo, - MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect) + ORDER_INFO* orderInfo, + MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect) { BYTE byte; - ORDER_FIELD_COORD(1, multi_opaque_rect->nLeftRect); ORDER_FIELD_COORD(2, multi_opaque_rect->nTopRect); ORDER_FIELD_COORD(3, multi_opaque_rect->nWidth); @@ -1180,7 +1134,8 @@ static BOOL update_read_multi_opaque_rect_order(wStream* s, return FALSE; Stream_Read_UINT8(s, byte); - multi_opaque_rect->color = (multi_opaque_rect->color & 0xFF00FFFF) | ((UINT32) byte << 16); + multi_opaque_rect->color = (multi_opaque_rect->color & 0xFF00FFFF) | (( + UINT32) byte << 16); } if (orderInfo->fieldFlags & ORDER_FIELD_06) @@ -1189,7 +1144,8 @@ static BOOL update_read_multi_opaque_rect_order(wStream* s, return FALSE; Stream_Read_UINT8(s, byte); - multi_opaque_rect->color = (multi_opaque_rect->color & 0xFFFF00FF) | ((UINT32) byte << 8); + multi_opaque_rect->color = (multi_opaque_rect->color & 0xFFFF00FF) | (( + UINT32) byte << 8); } if (orderInfo->fieldFlags & ORDER_FIELD_07) @@ -1198,7 +1154,8 @@ static BOOL update_read_multi_opaque_rect_order(wStream* s, return FALSE; Stream_Read_UINT8(s, byte); - multi_opaque_rect->color = (multi_opaque_rect->color & 0xFFFFFF00) | (UINT32) byte; + multi_opaque_rect->color = (multi_opaque_rect->color & 0xFFFFFF00) | + (UINT32) byte; } ORDER_FIELD_BYTE(8, multi_opaque_rect->numRectangles); @@ -1207,16 +1164,18 @@ static BOOL update_read_multi_opaque_rect_order(wStream* s, { if (Stream_GetRemainingLength(s) < 2) return FALSE; + Stream_Read_UINT16(s, multi_opaque_rect->cbData); - return update_read_delta_rects(s, multi_opaque_rect->rectangles, multi_opaque_rect->numRectangles); + return update_read_delta_rects(s, multi_opaque_rect->rectangles, + multi_opaque_rect->numRectangles); } return TRUE; } static BOOL update_read_multi_draw_nine_grid_order(wStream* s, - ORDER_INFO* orderInfo, - MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid) + ORDER_INFO* orderInfo, + MULTI_DRAW_NINE_GRID_ORDER* multi_draw_nine_grid) { ORDER_FIELD_COORD(1, multi_draw_nine_grid->srcLeft); ORDER_FIELD_COORD(2, multi_draw_nine_grid->srcTop); @@ -1234,7 +1193,7 @@ static BOOL update_read_multi_draw_nine_grid_order(wStream* s, } static BOOL update_read_line_to_order(wStream* s, ORDER_INFO* orderInfo, - LINE_TO_ORDER* line_to) + LINE_TO_ORDER* line_to) { ORDER_FIELD_UINT16(1, line_to->backMode); ORDER_FIELD_COORD(2, line_to->nXStart); @@ -1250,58 +1209,47 @@ static BOOL update_read_line_to_order(wStream* s, ORDER_INFO* orderInfo, } int update_approximate_line_to_order(ORDER_INFO* orderInfo, - const LINE_TO_ORDER* line_to) + const LINE_TO_ORDER* line_to) { return 32; } BOOL update_write_line_to_order(wStream* s, ORDER_INFO* orderInfo, - const LINE_TO_ORDER* line_to) + const LINE_TO_ORDER* line_to) { - if (!Stream_EnsureRemainingCapacity(s, update_approximate_line_to_order(orderInfo, line_to))) + if (!Stream_EnsureRemainingCapacity(s, + update_approximate_line_to_order(orderInfo, line_to))) return FALSE; orderInfo->fieldFlags = 0; - orderInfo->fieldFlags |= ORDER_FIELD_01; Stream_Write_UINT16(s, line_to->backMode); - orderInfo->fieldFlags |= ORDER_FIELD_02; update_write_coord(s, line_to->nXStart); - orderInfo->fieldFlags |= ORDER_FIELD_03; update_write_coord(s, line_to->nYStart); - orderInfo->fieldFlags |= ORDER_FIELD_04; update_write_coord(s, line_to->nXEnd); - orderInfo->fieldFlags |= ORDER_FIELD_05; update_write_coord(s, line_to->nYEnd); - orderInfo->fieldFlags |= ORDER_FIELD_06; update_write_color(s, line_to->backColor); - orderInfo->fieldFlags |= ORDER_FIELD_07; Stream_Write_UINT8(s, line_to->bRop2); - orderInfo->fieldFlags |= ORDER_FIELD_08; Stream_Write_UINT8(s, line_to->penStyle); - orderInfo->fieldFlags |= ORDER_FIELD_09; Stream_Write_UINT8(s, line_to->penWidth); - orderInfo->fieldFlags |= ORDER_FIELD_10; update_write_color(s, line_to->penColor); - return TRUE; } static BOOL update_read_polyline_order(wStream* s, ORDER_INFO* orderInfo, - POLYLINE_ORDER* polyline) + POLYLINE_ORDER* polyline) { UINT16 word; UINT32 new_num = polyline->numDeltaEntries; - ORDER_FIELD_COORD(1, polyline->xStart); ORDER_FIELD_COORD(2, polyline->yStart); ORDER_FIELD_BYTE(3, polyline->bRop2); @@ -1311,32 +1259,35 @@ static BOOL update_read_polyline_order(wStream* s, ORDER_INFO* orderInfo, if (orderInfo->fieldFlags & ORDER_FIELD_07) { - DELTA_POINT *new_points; + DELTA_POINT* new_points; if (Stream_GetRemainingLength(s) < 1) { WLog_ERR(TAG, "Stream_GetRemainingLength(s) < 1"); return FALSE; } - Stream_Read_UINT8(s, polyline->cbData); - new_points = (DELTA_POINT*) realloc(polyline->points, sizeof(DELTA_POINT) * new_num); + Stream_Read_UINT8(s, polyline->cbData); + new_points = (DELTA_POINT*) realloc(polyline->points, + sizeof(DELTA_POINT) * new_num); + if (!new_points) { WLog_ERR(TAG, "realloc(%i) failed", new_num); return FALSE; } + polyline->points = new_points; polyline->numDeltaEntries = new_num; - - return update_read_delta_points(s, polyline->points, polyline->numDeltaEntries, polyline->xStart, polyline->yStart); + return update_read_delta_points(s, polyline->points, polyline->numDeltaEntries, + polyline->xStart, polyline->yStart); } return TRUE; } static BOOL update_read_memblt_order(wStream* s, ORDER_INFO* orderInfo, - MEMBLT_ORDER* memblt) + MEMBLT_ORDER* memblt) { ORDER_FIELD_UINT16(1, memblt->cacheId); ORDER_FIELD_COORD(2, memblt->nLeftRect); @@ -1347,62 +1298,51 @@ static BOOL update_read_memblt_order(wStream* s, ORDER_INFO* orderInfo, ORDER_FIELD_COORD(7, memblt->nXSrc); ORDER_FIELD_COORD(8, memblt->nYSrc); ORDER_FIELD_UINT16(9, memblt->cacheIndex); - memblt->colorIndex = (memblt->cacheId >> 8); memblt->cacheId = (memblt->cacheId & 0xFF); memblt->bitmap = NULL; - return TRUE; } int update_approximate_memblt_order(ORDER_INFO* orderInfo, - const MEMBLT_ORDER* memblt) + const MEMBLT_ORDER* memblt) { return 64; } BOOL update_write_memblt_order(wStream* s, ORDER_INFO* orderInfo, - const MEMBLT_ORDER* memblt) + const MEMBLT_ORDER* memblt) { UINT16 cacheId; - if (!Stream_EnsureRemainingCapacity(s, update_approximate_memblt_order(orderInfo, memblt))) + if (!Stream_EnsureRemainingCapacity(s, + update_approximate_memblt_order(orderInfo, memblt))) return FALSE; cacheId = (memblt->cacheId & 0xFF) | ((memblt->colorIndex & 0xFF) << 8); - orderInfo->fieldFlags |= ORDER_FIELD_01; Stream_Write_UINT16(s, cacheId); - orderInfo->fieldFlags |= ORDER_FIELD_02; update_write_coord(s, memblt->nLeftRect); - orderInfo->fieldFlags |= ORDER_FIELD_03; update_write_coord(s, memblt->nTopRect); - orderInfo->fieldFlags |= ORDER_FIELD_04; update_write_coord(s, memblt->nWidth); - orderInfo->fieldFlags |= ORDER_FIELD_05; update_write_coord(s, memblt->nHeight); - orderInfo->fieldFlags |= ORDER_FIELD_06; Stream_Write_UINT8(s, memblt->bRop); - orderInfo->fieldFlags |= ORDER_FIELD_07; update_write_coord(s, memblt->nXSrc); - orderInfo->fieldFlags |= ORDER_FIELD_08; update_write_coord(s, memblt->nYSrc); - orderInfo->fieldFlags |= ORDER_FIELD_09; Stream_Write_UINT16(s, memblt->cacheIndex); - return TRUE; } static BOOL update_read_mem3blt_order(wStream* s, ORDER_INFO* orderInfo, - MEM3BLT_ORDER* mem3blt) + MEM3BLT_ORDER* mem3blt) { ORDER_FIELD_UINT16(1, mem3blt->cacheId); ORDER_FIELD_COORD(2, mem3blt->nLeftRect); @@ -1422,12 +1362,11 @@ static BOOL update_read_mem3blt_order(wStream* s, ORDER_INFO* orderInfo, mem3blt->colorIndex = (mem3blt->cacheId >> 8); mem3blt->cacheId = (mem3blt->cacheId & 0xFF); mem3blt->bitmap = NULL; - return TRUE; } static BOOL update_read_save_bitmap_order(wStream* s, ORDER_INFO* orderInfo, - SAVE_BITMAP_ORDER* save_bitmap) + SAVE_BITMAP_ORDER* save_bitmap) { ORDER_FIELD_UINT32(1, save_bitmap->savedBitmapPosition); ORDER_FIELD_COORD(2, save_bitmap->nLeftRect); @@ -1439,7 +1378,7 @@ static BOOL update_read_save_bitmap_order(wStream* s, ORDER_INFO* orderInfo, } static BOOL update_read_glyph_index_order(wStream* s, ORDER_INFO* orderInfo, - GLYPH_INDEX_ORDER* glyph_index) + GLYPH_INDEX_ORDER* glyph_index) { ORDER_FIELD_BYTE(1, glyph_index->cacheId); ORDER_FIELD_BYTE(2, glyph_index->flAccel); @@ -1480,13 +1419,13 @@ static BOOL update_read_glyph_index_order(wStream* s, ORDER_INFO* orderInfo, } int update_approximate_glyph_index_order(ORDER_INFO* orderInfo, - const GLYPH_INDEX_ORDER* glyph_index) + const GLYPH_INDEX_ORDER* glyph_index) { return 64; } BOOL update_write_glyph_index_order(wStream* s, ORDER_INFO* orderInfo, - GLYPH_INDEX_ORDER* glyph_index) + GLYPH_INDEX_ORDER* glyph_index) { int inf = update_approximate_glyph_index_order(orderInfo, glyph_index); @@ -1494,71 +1433,52 @@ BOOL update_write_glyph_index_order(wStream* s, ORDER_INFO* orderInfo, return FALSE; orderInfo->fieldFlags = 0; - orderInfo->fieldFlags |= ORDER_FIELD_01; Stream_Write_UINT8(s, glyph_index->cacheId); - orderInfo->fieldFlags |= ORDER_FIELD_02; Stream_Write_UINT8(s, glyph_index->flAccel); - orderInfo->fieldFlags |= ORDER_FIELD_03; Stream_Write_UINT8(s, glyph_index->ulCharInc); - orderInfo->fieldFlags |= ORDER_FIELD_04; Stream_Write_UINT8(s, glyph_index->fOpRedundant); - orderInfo->fieldFlags |= ORDER_FIELD_05; update_write_color(s, glyph_index->backColor); - orderInfo->fieldFlags |= ORDER_FIELD_06; update_write_color(s, glyph_index->foreColor); - orderInfo->fieldFlags |= ORDER_FIELD_07; Stream_Write_UINT16(s, glyph_index->bkLeft); - orderInfo->fieldFlags |= ORDER_FIELD_08; Stream_Write_UINT16(s, glyph_index->bkTop); - orderInfo->fieldFlags |= ORDER_FIELD_09; Stream_Write_UINT16(s, glyph_index->bkRight); - orderInfo->fieldFlags |= ORDER_FIELD_10; Stream_Write_UINT16(s, glyph_index->bkBottom); - orderInfo->fieldFlags |= ORDER_FIELD_11; Stream_Write_UINT16(s, glyph_index->opLeft); - orderInfo->fieldFlags |= ORDER_FIELD_12; Stream_Write_UINT16(s, glyph_index->opTop); - orderInfo->fieldFlags |= ORDER_FIELD_13; Stream_Write_UINT16(s, glyph_index->opRight); - orderInfo->fieldFlags |= ORDER_FIELD_14; Stream_Write_UINT16(s, glyph_index->opBottom); - orderInfo->fieldFlags |= ORDER_FIELD_15; orderInfo->fieldFlags |= ORDER_FIELD_16; orderInfo->fieldFlags |= ORDER_FIELD_17; orderInfo->fieldFlags |= ORDER_FIELD_18; orderInfo->fieldFlags |= ORDER_FIELD_19; update_write_brush(s, &glyph_index->brush, orderInfo->fieldFlags >> 14); - orderInfo->fieldFlags |= ORDER_FIELD_20; Stream_Write_UINT16(s, glyph_index->x); - orderInfo->fieldFlags |= ORDER_FIELD_21; Stream_Write_UINT16(s, glyph_index->y); - orderInfo->fieldFlags |= ORDER_FIELD_22; Stream_Write_UINT8(s, glyph_index->cbData); Stream_Write(s, glyph_index->data, glyph_index->cbData); - return TRUE; } static BOOL update_read_fast_index_order(wStream* s, ORDER_INFO* orderInfo, - FAST_INDEX_ORDER* fast_index) + FAST_INDEX_ORDER* fast_index) { ORDER_FIELD_BYTE(1, fast_index->cacheId); ORDER_FIELD_2BYTE(2, fast_index->ulCharInc, fast_index->flAccel); @@ -1593,11 +1513,10 @@ static BOOL update_read_fast_index_order(wStream* s, ORDER_INFO* orderInfo, } static BOOL update_read_fast_glyph_order(wStream* s, ORDER_INFO* orderInfo, - FAST_GLYPH_ORDER* fastGlyph) + FAST_GLYPH_ORDER* fastGlyph) { BYTE* phold; GLYPH_DATA_V2* glyph = &fastGlyph->glyphData; - ORDER_FIELD_BYTE(1, fastGlyph->cacheId); ORDER_FIELD_2BYTE(2, fastGlyph->ulCharInc, fastGlyph->flAccel); ORDER_FIELD_COLOR(3, fastGlyph->backColor); @@ -1636,23 +1555,24 @@ static BOOL update_read_fast_glyph_order(wStream* s, ORDER_INFO* orderInfo, glyph->cacheIndex = fastGlyph->data[0]; if (!update_read_2byte_signed(s, &glyph->x) || - !update_read_2byte_signed(s, &glyph->y) || - !update_read_2byte_unsigned(s, &glyph->cx) || - !update_read_2byte_unsigned(s, &glyph->cy)) + !update_read_2byte_signed(s, &glyph->y) || + !update_read_2byte_unsigned(s, &glyph->cx) || + !update_read_2byte_unsigned(s, &glyph->cy)) return FALSE; glyph->cb = ((glyph->cx + 7) / 8) * glyph->cy; glyph->cb += ((glyph->cb % 4) > 0) ? 4 - (glyph->cb % 4) : 0; - new_cb = ((glyph->cx + 7) / 8) * glyph->cy; new_cb += ((new_cb % 4) > 0) ? 4 - (new_cb % 4) : 0; + if (Stream_GetRemainingLength(s) < new_cb) return FALSE; if (new_cb) { - BYTE *new_aj; + BYTE* new_aj; new_aj = (BYTE*) realloc(glyph->aj, new_cb); + if (!new_aj) return FALSE; @@ -1669,10 +1589,9 @@ static BOOL update_read_fast_glyph_order(wStream* s, ORDER_INFO* orderInfo, } static BOOL update_read_polygon_sc_order(wStream* s, ORDER_INFO* orderInfo, - POLYGON_SC_ORDER* polygon_sc) + POLYGON_SC_ORDER* polygon_sc) { UINT32 num = polygon_sc->numPoints; - ORDER_FIELD_COORD(1, polygon_sc->xStart); ORDER_FIELD_COORD(2, polygon_sc->yStart); ORDER_FIELD_BYTE(3, polygon_sc->bRop2); @@ -1682,31 +1601,31 @@ static BOOL update_read_polygon_sc_order(wStream* s, ORDER_INFO* orderInfo, if (orderInfo->fieldFlags & ORDER_FIELD_07) { - DELTA_POINT *newpoints; + DELTA_POINT* newpoints; if (Stream_GetRemainingLength(s) < 1) return FALSE; Stream_Read_UINT8(s, polygon_sc->cbData); + newpoints = (DELTA_POINT*) realloc(polygon_sc->points, + sizeof(DELTA_POINT) * num); - newpoints = (DELTA_POINT*) realloc(polygon_sc->points, sizeof(DELTA_POINT) * num); if (!newpoints) return FALSE; polygon_sc->points = newpoints; polygon_sc->numPoints = num; - - return update_read_delta_points(s, polygon_sc->points, polygon_sc->numPoints, polygon_sc->xStart, polygon_sc->yStart); + return update_read_delta_points(s, polygon_sc->points, polygon_sc->numPoints, + polygon_sc->xStart, polygon_sc->yStart); } return TRUE; } static BOOL update_read_polygon_cb_order(wStream* s, ORDER_INFO* orderInfo, - POLYGON_CB_ORDER* polygon_cb) + POLYGON_CB_ORDER* polygon_cb) { UINT32 num = polygon_cb->numPoints; - ORDER_FIELD_COORD(1, polygon_cb->xStart); ORDER_FIELD_COORD(2, polygon_cb->yStart); ORDER_FIELD_BYTE(3, polygon_cb->bRop2); @@ -1721,31 +1640,34 @@ static BOOL update_read_polygon_cb_order(wStream* s, ORDER_INFO* orderInfo, if (orderInfo->fieldFlags & ORDER_FIELD_13) { - DELTA_POINT *newpoints; + DELTA_POINT* newpoints; if (Stream_GetRemainingLength(s) < 1) return FALSE; Stream_Read_UINT8(s, polygon_cb->cbData); + newpoints = (DELTA_POINT*) realloc(polygon_cb->points, + sizeof(DELTA_POINT) * num); - newpoints = (DELTA_POINT*) realloc(polygon_cb->points, sizeof(DELTA_POINT) * num); if (!newpoints) return FALSE; polygon_cb->points = newpoints; polygon_cb->numPoints = num; - if (!update_read_delta_points(s, polygon_cb->points, polygon_cb->numPoints, polygon_cb->xStart, polygon_cb->yStart)) + + if (!update_read_delta_points(s, polygon_cb->points, polygon_cb->numPoints, + polygon_cb->xStart, polygon_cb->yStart)) return FALSE; } - polygon_cb->backMode = (polygon_cb->bRop2 & 0x80) ? BACKMODE_TRANSPARENT : BACKMODE_OPAQUE; + polygon_cb->backMode = (polygon_cb->bRop2 & 0x80) ? BACKMODE_TRANSPARENT : + BACKMODE_OPAQUE; polygon_cb->bRop2 = (polygon_cb->bRop2 & 0x1F); - return TRUE; } static BOOL update_read_ellipse_sc_order(wStream* s, ORDER_INFO* orderInfo, - ELLIPSE_SC_ORDER* ellipse_sc) + ELLIPSE_SC_ORDER* ellipse_sc) { ORDER_FIELD_COORD(1, ellipse_sc->leftRect); ORDER_FIELD_COORD(2, ellipse_sc->topRect); @@ -1758,7 +1680,7 @@ static BOOL update_read_ellipse_sc_order(wStream* s, ORDER_INFO* orderInfo, } static BOOL update_read_ellipse_cb_order(wStream* s, ORDER_INFO* orderInfo, - ELLIPSE_CB_ORDER* ellipse_cb) + ELLIPSE_CB_ORDER* ellipse_cb) { ORDER_FIELD_COORD(1, ellipse_cb->leftRect); ORDER_FIELD_COORD(2, ellipse_cb->topRect); @@ -1772,8 +1694,9 @@ static BOOL update_read_ellipse_cb_order(wStream* s, ORDER_INFO* orderInfo, } /* Secondary Drawing Orders */ -static BOOL update_read_cache_bitmap_order(wStream* s, CACHE_BITMAP_ORDER* cache_bitmap, - BOOL compressed, UINT16 flags) +static BOOL update_read_cache_bitmap_order(wStream* s, + CACHE_BITMAP_ORDER* cache_bitmap, + BOOL compressed, UINT16 flags) { if (Stream_GetRemainingLength(s) < 9) return FALSE; @@ -1783,11 +1706,13 @@ static BOOL update_read_cache_bitmap_order(wStream* s, CACHE_BITMAP_ORDER* cache Stream_Read_UINT8(s, cache_bitmap->bitmapWidth); /* bitmapWidth (1 byte) */ Stream_Read_UINT8(s, cache_bitmap->bitmapHeight); /* bitmapHeight (1 byte) */ Stream_Read_UINT8(s, cache_bitmap->bitmapBpp); /* bitmapBpp (1 byte) */ + if ((cache_bitmap->bitmapBpp < 1) || (cache_bitmap->bitmapBpp > 32)) { WLog_ERR(TAG, "invalid bitmap bpp %d", cache_bitmap->bitmapBpp); return FALSE; } + Stream_Read_UINT16(s, cache_bitmap->bitmapLength); /* bitmapLength (2 bytes) */ Stream_Read_UINT16(s, cache_bitmap->cacheIndex); /* cacheIndex (2 bytes) */ @@ -1795,7 +1720,7 @@ static BOOL update_read_cache_bitmap_order(wStream* s, CACHE_BITMAP_ORDER* cache { if ((flags & NO_BITMAP_COMPRESSION_HDR) == 0) { - BYTE* bitmapComprHdr = (BYTE*) &(cache_bitmap->bitmapComprHdr); + BYTE* bitmapComprHdr = (BYTE*) & (cache_bitmap->bitmapComprHdr); if (Stream_GetRemainingLength(s) < 8) return FALSE; @@ -1820,22 +1745,24 @@ static BOOL update_read_cache_bitmap_order(wStream* s, CACHE_BITMAP_ORDER* cache } cache_bitmap->compressed = compressed; - return TRUE; } -int update_approximate_cache_bitmap_order(const CACHE_BITMAP_ORDER* cache_bitmap, - BOOL compressed, UINT16* flags) +int update_approximate_cache_bitmap_order(const CACHE_BITMAP_ORDER* + cache_bitmap, + BOOL compressed, UINT16* flags) { return 64 + cache_bitmap->bitmapLength; } BOOL update_write_cache_bitmap_order(wStream* s, - const CACHE_BITMAP_ORDER* cache_bitmap, - BOOL compressed, UINT16* flags) + const CACHE_BITMAP_ORDER* cache_bitmap, + BOOL compressed, UINT16* flags) { UINT32 bitmapLength = cache_bitmap->bitmapLength; - int inf = update_approximate_cache_bitmap_order(cache_bitmap, compressed, flags); + int inf = update_approximate_cache_bitmap_order(cache_bitmap, compressed, + flags); + if (!Stream_EnsureRemainingCapacity(s, inf)) return FALSE; @@ -1856,7 +1783,7 @@ BOOL update_write_cache_bitmap_order(wStream* s, { if ((*flags & NO_BITMAP_COMPRESSION_HDR) == 0) { - BYTE* bitmapComprHdr = (BYTE*) &(cache_bitmap->bitmapComprHdr); + BYTE* bitmapComprHdr = (BYTE*) & (cache_bitmap->bitmapComprHdr); Stream_Write(s, bitmapComprHdr, 8); /* bitmapComprHdr (8 bytes) */ bitmapLength -= 8; } @@ -1872,14 +1799,12 @@ BOOL update_write_cache_bitmap_order(wStream* s, } static BOOL update_read_cache_bitmap_v2_order(wStream* s, - CACHE_BITMAP_V2_ORDER* cache_bitmap_v2, - BOOL compressed, UINT16 flags) + CACHE_BITMAP_V2_ORDER* cache_bitmap_v2, + BOOL compressed, UINT16 flags) { BYTE bitsPerPixelId; - cache_bitmap_v2->cacheId = flags & 0x0003; cache_bitmap_v2->flags = (flags & 0xFF80) >> 7; - bitsPerPixelId = (flags & 0x0078) >> 3; cache_bitmap_v2->bitmapBpp = CBR2_BPP[bitsPerPixelId]; @@ -1894,20 +1819,24 @@ static BOOL update_read_cache_bitmap_v2_order(wStream* s, if (cache_bitmap_v2->flags & CBR2_HEIGHT_SAME_AS_WIDTH) { - if (!update_read_2byte_unsigned(s, &cache_bitmap_v2->bitmapWidth)) /* bitmapWidth */ + if (!update_read_2byte_unsigned(s, + &cache_bitmap_v2->bitmapWidth)) /* bitmapWidth */ return FALSE; cache_bitmap_v2->bitmapHeight = cache_bitmap_v2->bitmapWidth; } else { - if (!update_read_2byte_unsigned(s, &cache_bitmap_v2->bitmapWidth) || /* bitmapWidth */ - !update_read_2byte_unsigned(s, &cache_bitmap_v2->bitmapHeight)) /* bitmapHeight */ + if (!update_read_2byte_unsigned(s, &cache_bitmap_v2->bitmapWidth) + || /* bitmapWidth */ + !update_read_2byte_unsigned(s, + &cache_bitmap_v2->bitmapHeight)) /* bitmapHeight */ return FALSE; } - if (!update_read_4byte_unsigned(s, &cache_bitmap_v2->bitmapLength) || /* bitmapLength */ - !update_read_2byte_unsigned(s, &cache_bitmap_v2->cacheIndex)) /* cacheIndex */ + if (!update_read_4byte_unsigned(s, &cache_bitmap_v2->bitmapLength) + || /* bitmapLength */ + !update_read_2byte_unsigned(s, &cache_bitmap_v2->cacheIndex)) /* cacheIndex */ return FALSE; if (cache_bitmap_v2->flags & CBR2_DO_NOT_CACHE) @@ -1920,10 +1849,13 @@ static BOOL update_read_cache_bitmap_v2_order(wStream* s, if (Stream_GetRemainingLength(s) < 8) return FALSE; - Stream_Read_UINT16(s, cache_bitmap_v2->cbCompFirstRowSize); /* cbCompFirstRowSize (2 bytes) */ - Stream_Read_UINT16(s, cache_bitmap_v2->cbCompMainBodySize); /* cbCompMainBodySize (2 bytes) */ + Stream_Read_UINT16(s, + cache_bitmap_v2->cbCompFirstRowSize); /* cbCompFirstRowSize (2 bytes) */ + Stream_Read_UINT16(s, + cache_bitmap_v2->cbCompMainBodySize); /* cbCompMainBodySize (2 bytes) */ Stream_Read_UINT16(s, cache_bitmap_v2->cbScanWidth); /* cbScanWidth (2 bytes) */ - Stream_Read_UINT16(s, cache_bitmap_v2->cbUncompressedSize); /* cbUncompressedSize (2 bytes) */ + Stream_Read_UINT16(s, + cache_bitmap_v2->cbUncompressedSize); /* cbUncompressedSize (2 bytes) */ cache_bitmap_v2->bitmapLength = cache_bitmap_v2->cbCompMainBodySize; } @@ -1943,26 +1875,27 @@ static BOOL update_read_cache_bitmap_v2_order(wStream* s, } cache_bitmap_v2->compressed = compressed; - return TRUE; } -int update_approximate_cache_bitmap_v2_order(CACHE_BITMAP_V2_ORDER* cache_bitmap_v2, BOOL compressed, UINT16* flags) +int update_approximate_cache_bitmap_v2_order(CACHE_BITMAP_V2_ORDER* + cache_bitmap_v2, BOOL compressed, UINT16* flags) { return 64 + cache_bitmap_v2->bitmapLength; } -BOOL update_write_cache_bitmap_v2_order(wStream* s, CACHE_BITMAP_V2_ORDER* cache_bitmap_v2, BOOL compressed, UINT16* flags) +BOOL update_write_cache_bitmap_v2_order(wStream* s, + CACHE_BITMAP_V2_ORDER* cache_bitmap_v2, BOOL compressed, UINT16* flags) { BYTE bitsPerPixelId; - if (!Stream_EnsureRemainingCapacity(s, update_approximate_cache_bitmap_v2_order(cache_bitmap_v2, compressed, flags))) + if (!Stream_EnsureRemainingCapacity(s, + update_approximate_cache_bitmap_v2_order(cache_bitmap_v2, compressed, flags))) return FALSE; bitsPerPixelId = BPP_CBR2[cache_bitmap_v2->bitmapBpp]; - *flags = (cache_bitmap_v2->cacheId & 0x0003) | - (bitsPerPixelId << 3) | ((cache_bitmap_v2->flags << 7) & 0xFF80); + (bitsPerPixelId << 3) | ((cache_bitmap_v2->flags << 7) & 0xFF80); if (cache_bitmap_v2->flags & CBR2_PERSISTENT_KEY_PRESENT) { @@ -1972,62 +1905,71 @@ BOOL update_write_cache_bitmap_v2_order(wStream* s, CACHE_BITMAP_V2_ORDER* cache if (cache_bitmap_v2->flags & CBR2_HEIGHT_SAME_AS_WIDTH) { - if (!update_write_2byte_unsigned(s, cache_bitmap_v2->bitmapWidth)) /* bitmapWidth */ + if (!update_write_2byte_unsigned(s, + cache_bitmap_v2->bitmapWidth)) /* bitmapWidth */ return FALSE; } else { - if (!update_write_2byte_unsigned(s, cache_bitmap_v2->bitmapWidth) || /* bitmapWidth */ - !update_write_2byte_unsigned(s, cache_bitmap_v2->bitmapHeight)) /* bitmapHeight */ + if (!update_write_2byte_unsigned(s, cache_bitmap_v2->bitmapWidth) + || /* bitmapWidth */ + !update_write_2byte_unsigned(s, + cache_bitmap_v2->bitmapHeight)) /* bitmapHeight */ return FALSE; } if (cache_bitmap_v2->flags & CBR2_DO_NOT_CACHE) cache_bitmap_v2->cacheIndex = BITMAP_CACHE_WAITING_LIST_INDEX; - if (!update_write_4byte_unsigned(s, cache_bitmap_v2->bitmapLength) || /* bitmapLength */ - !update_write_2byte_unsigned(s, cache_bitmap_v2->cacheIndex)) /* cacheIndex */ + if (!update_write_4byte_unsigned(s, cache_bitmap_v2->bitmapLength) + || /* bitmapLength */ + !update_write_2byte_unsigned(s, cache_bitmap_v2->cacheIndex)) /* cacheIndex */ return FALSE; if (compressed) { if (!(cache_bitmap_v2->flags & CBR2_NO_BITMAP_COMPRESSION_HDR)) { - Stream_Write_UINT16(s, cache_bitmap_v2->cbCompFirstRowSize); /* cbCompFirstRowSize (2 bytes) */ - Stream_Write_UINT16(s, cache_bitmap_v2->cbCompMainBodySize); /* cbCompMainBodySize (2 bytes) */ - Stream_Write_UINT16(s, cache_bitmap_v2->cbScanWidth); /* cbScanWidth (2 bytes) */ - Stream_Write_UINT16(s, cache_bitmap_v2->cbUncompressedSize); /* cbUncompressedSize (2 bytes) */ + Stream_Write_UINT16(s, + cache_bitmap_v2->cbCompFirstRowSize); /* cbCompFirstRowSize (2 bytes) */ + Stream_Write_UINT16(s, + cache_bitmap_v2->cbCompMainBodySize); /* cbCompMainBodySize (2 bytes) */ + Stream_Write_UINT16(s, + cache_bitmap_v2->cbScanWidth); /* cbScanWidth (2 bytes) */ + Stream_Write_UINT16(s, + cache_bitmap_v2->cbUncompressedSize); /* cbUncompressedSize (2 bytes) */ cache_bitmap_v2->bitmapLength = cache_bitmap_v2->cbCompMainBodySize; } if (!Stream_EnsureRemainingCapacity(s, cache_bitmap_v2->bitmapLength)) return FALSE; - Stream_Write(s, cache_bitmap_v2->bitmapDataStream, cache_bitmap_v2->bitmapLength); + + Stream_Write(s, cache_bitmap_v2->bitmapDataStream, + cache_bitmap_v2->bitmapLength); } else { if (!Stream_EnsureRemainingCapacity(s, cache_bitmap_v2->bitmapLength)) return FALSE; - Stream_Write(s, cache_bitmap_v2->bitmapDataStream, cache_bitmap_v2->bitmapLength); + + Stream_Write(s, cache_bitmap_v2->bitmapDataStream, + cache_bitmap_v2->bitmapLength); } cache_bitmap_v2->compressed = compressed; - return TRUE; } static BOOL update_read_cache_bitmap_v3_order(wStream* s, - CACHE_BITMAP_V3_ORDER* cache_bitmap_v3, - UINT16 flags) + CACHE_BITMAP_V3_ORDER* cache_bitmap_v3, + UINT16 flags) { BYTE bitsPerPixelId; BITMAP_DATA_EX* bitmapData; UINT32 new_len; - BYTE *new_data; - + BYTE* new_data; cache_bitmap_v3->cacheId = flags & 0x00000003; cache_bitmap_v3->flags = (flags & 0x0000FF80) >> 7; - bitsPerPixelId = (flags & 0x00000078) >> 3; cache_bitmap_v3->bpp = CBR23_BPP[bitsPerPixelId]; @@ -2037,15 +1979,15 @@ static BOOL update_read_cache_bitmap_v3_order(wStream* s, Stream_Read_UINT16(s, cache_bitmap_v3->cacheIndex); /* cacheIndex (2 bytes) */ Stream_Read_UINT32(s, cache_bitmap_v3->key1); /* key1 (4 bytes) */ Stream_Read_UINT32(s, cache_bitmap_v3->key2); /* key2 (4 bytes) */ - bitmapData = &cache_bitmap_v3->bitmapData; - Stream_Read_UINT8(s, bitmapData->bpp); + if ((bitmapData->bpp < 1) || (bitmapData->bpp > 32)) { WLog_ERR(TAG, "invalid bpp value %d", bitmapData->bpp); return FALSE; } + Stream_Seek_UINT8(s); /* reserved1 (1 byte) */ Stream_Seek_UINT8(s); /* reserved2 (1 byte) */ Stream_Read_UINT8(s, bitmapData->codecID); /* codecID (1 byte) */ @@ -2057,40 +1999,41 @@ static BOOL update_read_cache_bitmap_v3_order(wStream* s, return FALSE; new_data = (BYTE*) realloc(bitmapData->data, new_len); + if (!new_data) return FALSE; + bitmapData->data = new_data; bitmapData->length = new_len; Stream_Read(s, bitmapData->data, bitmapData->length); - return TRUE; } -int update_approximate_cache_bitmap_v3_order(CACHE_BITMAP_V3_ORDER* cache_bitmap_v3, UINT16* flags) +int update_approximate_cache_bitmap_v3_order(CACHE_BITMAP_V3_ORDER* + cache_bitmap_v3, UINT16* flags) { BITMAP_DATA_EX* bitmapData = &cache_bitmap_v3->bitmapData; return 64 + bitmapData->length; } -BOOL update_write_cache_bitmap_v3_order(wStream* s, CACHE_BITMAP_V3_ORDER* cache_bitmap_v3, UINT16* flags) +BOOL update_write_cache_bitmap_v3_order(wStream* s, + CACHE_BITMAP_V3_ORDER* cache_bitmap_v3, UINT16* flags) { BYTE bitsPerPixelId; BITMAP_DATA_EX* bitmapData; - if (!Stream_EnsureRemainingCapacity(s, update_approximate_cache_bitmap_v3_order(cache_bitmap_v3, flags))) + if (!Stream_EnsureRemainingCapacity(s, + update_approximate_cache_bitmap_v3_order(cache_bitmap_v3, flags))) return FALSE; bitmapData = &cache_bitmap_v3->bitmapData; bitsPerPixelId = BPP_CBR23[cache_bitmap_v3->bpp]; - *flags = (cache_bitmap_v3->cacheId & 0x00000003) | - ((cache_bitmap_v3->flags << 7) & 0x0000FF80) | - ((bitsPerPixelId << 3) & 0x00000078); - + ((cache_bitmap_v3->flags << 7) & 0x0000FF80) | + ((bitsPerPixelId << 3) & 0x00000078); Stream_Write_UINT16(s, cache_bitmap_v3->cacheIndex); /* cacheIndex (2 bytes) */ Stream_Write_UINT32(s, cache_bitmap_v3->key1); /* key1 (4 bytes) */ Stream_Write_UINT32(s, cache_bitmap_v3->key2); /* key2 (4 bytes) */ - Stream_Write_UINT8(s, bitmapData->bpp); Stream_Write_UINT8(s, 0); /* reserved1 (1 byte) */ Stream_Write_UINT8(s, 0); /* reserved2 (1 byte) */ @@ -2098,15 +2041,13 @@ BOOL update_write_cache_bitmap_v3_order(wStream* s, CACHE_BITMAP_V3_ORDER* cache Stream_Write_UINT16(s, bitmapData->width); /* width (2 bytes) */ Stream_Write_UINT16(s, bitmapData->height); /* height (2 bytes) */ Stream_Write_UINT32(s, bitmapData->length); /* length (4 bytes) */ - Stream_Write(s, bitmapData->data, bitmapData->length); - return TRUE; } static BOOL update_read_cache_color_table_order(wStream* s, - CACHE_COLOR_TABLE_ORDER* cache_color_table, - UINT16 flags) + CACHE_COLOR_TABLE_ORDER* cache_color_table, + UINT16 flags) { int i; UINT32* colorTable; @@ -2115,7 +2056,8 @@ static BOOL update_read_cache_color_table_order(wStream* s, return FALSE; Stream_Read_UINT8(s, cache_color_table->cacheIndex); /* cacheIndex (1 byte) */ - Stream_Read_UINT16(s, cache_color_table->numberColors); /* numberColors (2 bytes) */ + Stream_Read_UINT16(s, + cache_color_table->numberColors); /* numberColors (2 bytes) */ if (cache_color_table->numberColors != 256) { @@ -2137,14 +2079,14 @@ static BOOL update_read_cache_color_table_order(wStream* s, } int update_approximate_cache_color_table_order( - const CACHE_COLOR_TABLE_ORDER* cache_color_table, UINT16* flags) + const CACHE_COLOR_TABLE_ORDER* cache_color_table, UINT16* flags) { return 16 + (256 * 4); } BOOL update_write_cache_color_table_order(wStream* s, - const CACHE_COLOR_TABLE_ORDER* cache_color_table, - UINT16* flags) + const CACHE_COLOR_TABLE_ORDER* cache_color_table, + UINT16* flags) { int i, inf; UINT32* colorTable; @@ -2153,12 +2095,13 @@ BOOL update_write_cache_color_table_order(wStream* s, return FALSE; inf = update_approximate_cache_color_table_order(cache_color_table, flags); + if (!Stream_EnsureRemainingCapacity(s, inf)) return FALSE; Stream_Write_UINT8(s, cache_color_table->cacheIndex); /* cacheIndex (1 byte) */ - Stream_Write_UINT16(s, cache_color_table->numberColors); /* numberColors (2 bytes) */ - + Stream_Write_UINT16(s, + cache_color_table->numberColors); /* numberColors (2 bytes) */ colorTable = (UINT32*) &cache_color_table->colorTable; for (i = 0; i < (int) cache_color_table->numberColors; i++) @@ -2170,8 +2113,8 @@ BOOL update_write_cache_color_table_order(wStream* s, } static BOOL update_read_cache_glyph_order(wStream* s, - CACHE_GLYPH_ORDER* cache_glyph_order, - UINT16 flags) + CACHE_GLYPH_ORDER* cache_glyph_order, + UINT16 flags) { int i; INT16 lsi16; @@ -2197,7 +2140,6 @@ static BOOL update_read_cache_glyph_order(wStream* s, glyph->y = lsi16; Stream_Read_UINT16(s, glyph->cx); Stream_Read_UINT16(s, glyph->cy); - glyph->cb = ((glyph->cx + 7) / 8) * glyph->cy; glyph->cb += ((glyph->cb % 4) > 0) ? 4 - (glyph->cb % 4) : 0; @@ -2205,8 +2147,10 @@ static BOOL update_read_cache_glyph_order(wStream* s, return FALSE; glyph->aj = (BYTE*) malloc(glyph->cb); + if (!glyph->aj) return FALSE; + Stream_Read(s, glyph->aj, glyph->cb); } @@ -2219,20 +2163,20 @@ static BOOL update_read_cache_glyph_order(wStream* s, } int update_approximate_cache_glyph_order( - const CACHE_GLYPH_ORDER* cache_glyph, UINT16* flags) + const CACHE_GLYPH_ORDER* cache_glyph, UINT16* flags) { return 2 + cache_glyph->cGlyphs * 32; } BOOL update_write_cache_glyph_order(wStream* s, - const CACHE_GLYPH_ORDER* cache_glyph, - UINT16* flags) + const CACHE_GLYPH_ORDER* cache_glyph, + UINT16* flags) { int i, inf; INT16 lsi16; const GLYPH_DATA* glyph; - inf = update_approximate_cache_glyph_order(cache_glyph, flags); + if (!Stream_EnsureRemainingCapacity(s, inf)) return FALSE; @@ -2242,23 +2186,16 @@ BOOL update_write_cache_glyph_order(wStream* s, for (i = 0; i < (int) cache_glyph->cGlyphs; i++) { UINT32 cb; - glyph = &cache_glyph->glyphData[i]; - Stream_Write_UINT16(s, glyph->cacheIndex); /* cacheIndex (2 bytes) */ - lsi16 = glyph->x; Stream_Write_UINT16(s, lsi16); /* x (2 bytes) */ - lsi16 = glyph->y; Stream_Write_UINT16(s, lsi16); /* y (2 bytes) */ - Stream_Write_UINT16(s, glyph->cx); /* cx (2 bytes) */ Stream_Write_UINT16(s, glyph->cy); /* cy (2 bytes) */ - cb = ((glyph->cx + 7) / 8) * glyph->cy; cb += ((cb % 4) > 0) ? 4 - (cb % 4) : 0; - Stream_Write(s, glyph->aj, cb); } @@ -2271,12 +2208,11 @@ BOOL update_write_cache_glyph_order(wStream* s, } static BOOL update_read_cache_glyph_v2_order(wStream* s, - CACHE_GLYPH_V2_ORDER* cache_glyph_v2, - UINT16 flags) + CACHE_GLYPH_V2_ORDER* cache_glyph_v2, + UINT16 flags) { int i; GLYPH_DATA_V2* glyph; - cache_glyph_v2->cacheId = (flags & 0x000F); cache_glyph_v2->flags = (flags & 0x00F0) >> 4; cache_glyph_v2->cGlyphs = (flags & 0xFF00) >> 8; @@ -2291,9 +2227,9 @@ static BOOL update_read_cache_glyph_v2_order(wStream* s, Stream_Read_UINT8(s, glyph->cacheIndex); if (!update_read_2byte_signed(s, &glyph->x) || - !update_read_2byte_signed(s, &glyph->y) || - !update_read_2byte_unsigned(s, &glyph->cx) || - !update_read_2byte_unsigned(s, &glyph->cy)) + !update_read_2byte_signed(s, &glyph->y) || + !update_read_2byte_unsigned(s, &glyph->cx) || + !update_read_2byte_unsigned(s, &glyph->cy)) { return FALSE; } @@ -2305,8 +2241,10 @@ static BOOL update_read_cache_glyph_v2_order(wStream* s, return FALSE; glyph->aj = (BYTE*) malloc(glyph->cb); + if (!glyph->aj) return FALSE; + Stream_Read(s, glyph->aj, glyph->cb); } @@ -2319,36 +2257,35 @@ static BOOL update_read_cache_glyph_v2_order(wStream* s, } int update_approximate_cache_glyph_v2_order( - const CACHE_GLYPH_V2_ORDER* cache_glyph_v2, UINT16* flags) + const CACHE_GLYPH_V2_ORDER* cache_glyph_v2, UINT16* flags) { return 8 + cache_glyph_v2->cGlyphs * 32; } BOOL update_write_cache_glyph_v2_order(wStream* s, - const CACHE_GLYPH_V2_ORDER* cache_glyph_v2, - UINT16* flags) + const CACHE_GLYPH_V2_ORDER* cache_glyph_v2, + UINT16* flags) { int i, inf; - inf = update_approximate_cache_glyph_v2_order(cache_glyph_v2, flags); + if (!Stream_EnsureRemainingCapacity(s, inf)) return FALSE; *flags = (cache_glyph_v2->cacheId & 0x000F) | - ((cache_glyph_v2->flags & 0x000F) << 4) | - ((cache_glyph_v2->cGlyphs & 0x00FF) << 8); + ((cache_glyph_v2->flags & 0x000F) << 4) | + ((cache_glyph_v2->cGlyphs & 0x00FF) << 8); for (i = 0; i < (int) cache_glyph_v2->cGlyphs; i++) { UINT32 cb; const GLYPH_DATA_V2* glyph = &cache_glyph_v2->glyphData[i]; - Stream_Write_UINT8(s, glyph->cacheIndex); if (!update_write_2byte_signed(s, glyph->x) || - !update_write_2byte_signed(s, glyph->y) || - !update_write_2byte_unsigned(s, glyph->cx) || - !update_write_2byte_unsigned(s, glyph->cy)) + !update_write_2byte_signed(s, glyph->y) || + !update_write_2byte_unsigned(s, glyph->cx) || + !update_write_2byte_unsigned(s, glyph->cy)) { return FALSE; } @@ -2373,7 +2310,6 @@ static BOOL update_decompress_brush(wStream* s, BYTE* output, BYTE bpp) BYTE byte = 0; BYTE* palette; int bytesPerPixel; - palette = Stream_Pointer(s) + 16; bytesPerPixel = ((bpp + 1) / 8); @@ -2391,7 +2327,8 @@ static BOOL update_decompress_brush(wStream* s, BYTE* output, BYTE bpp) for (k = 0; k < bytesPerPixel; k++) { - output[((y * 8 + x) * bytesPerPixel) + k] = palette[(index * bytesPerPixel) + k]; + output[((y * 8 + x) * bytesPerPixel) + k] = palette[(index * bytesPerPixel) + + k]; } } } @@ -2405,8 +2342,8 @@ static BOOL update_compress_brush(wStream* s, const BYTE* input, BYTE bpp) } static BOOL update_read_cache_brush_order(wStream* s, - CACHE_BRUSH_ORDER* cache_brush, - UINT16 flags) + CACHE_BRUSH_ORDER* cache_brush, + UINT16 flags) { int i; int size; @@ -2417,10 +2354,8 @@ static BOOL update_read_cache_brush_order(wStream* s, return FALSE; Stream_Read_UINT8(s, cache_brush->index); /* cacheEntry (1 byte) */ - Stream_Read_UINT8(s, iBitmapFormat); /* iBitmapFormat (1 byte) */ cache_brush->bpp = BMF_BPP[iBitmapFormat]; - Stream_Read_UINT8(s, cache_brush->cx); /* cx (1 byte) */ Stream_Read_UINT8(s, cache_brush->cy); /* cy (1 byte) */ Stream_Read_UINT8(s, cache_brush->style); /* style (1 byte) */ @@ -2482,28 +2417,27 @@ static BOOL update_read_cache_brush_order(wStream* s, } int update_approximate_cache_brush_order( - const CACHE_BRUSH_ORDER* cache_brush, UINT16* flags) + const CACHE_BRUSH_ORDER* cache_brush, UINT16* flags) { return 64; } BOOL update_write_cache_brush_order(wStream* s, - const CACHE_BRUSH_ORDER* cache_brush, - UINT16* flags) + const CACHE_BRUSH_ORDER* cache_brush, + UINT16* flags) { int i; int size; BYTE iBitmapFormat; BOOL compressed = FALSE; - if (!Stream_EnsureRemainingCapacity(s, update_approximate_cache_brush_order(cache_brush, flags))) + if (!Stream_EnsureRemainingCapacity(s, + update_approximate_cache_brush_order(cache_brush, flags))) return FALSE; iBitmapFormat = BPP_BMF[cache_brush->bpp]; - Stream_Write_UINT8(s, cache_brush->index); /* cacheEntry (1 byte) */ Stream_Write_UINT8(s, iBitmapFormat); /* iBitmapFormat (1 byte) */ - Stream_Write_UINT8(s, cache_brush->cx); /* cx (1 byte) */ Stream_Write_UINT8(s, cache_brush->cy); /* cy (1 byte) */ Stream_Write_UINT8(s, cache_brush->style); /* style (1 byte) */ @@ -2559,7 +2493,7 @@ BOOL update_write_cache_brush_order(wStream* s, /* Alternate Secondary Drawing Orders */ static BOOL update_read_create_offscreen_bitmap_order(wStream* s, - CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap) + CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap) { UINT16 flags; BOOL deleteListPresent; @@ -2571,10 +2505,8 @@ static BOOL update_read_create_offscreen_bitmap_order(wStream* s, Stream_Read_UINT16(s, flags); /* flags (2 bytes) */ create_offscreen_bitmap->id = flags & 0x7FFF; deleteListPresent = (flags & 0x8000) ? TRUE : FALSE; - Stream_Read_UINT16(s, create_offscreen_bitmap->cx); /* cx (2 bytes) */ Stream_Read_UINT16(s, create_offscreen_bitmap->cy); /* cy (2 bytes) */ - deleteList = &(create_offscreen_bitmap->deleteList); if (deleteListPresent) @@ -2588,9 +2520,9 @@ static BOOL update_read_create_offscreen_bitmap_order(wStream* s, if (deleteList->cIndices > deleteList->sIndices) { - UINT16 *new_indices; + UINT16* new_indices; + new_indices = (UINT16*)realloc(deleteList->indices, deleteList->sIndices * 2); - new_indices = (UINT16 *)realloc(deleteList->indices, deleteList->sIndices * 2); if (!new_indices) return FALSE; @@ -2615,41 +2547,39 @@ static BOOL update_read_create_offscreen_bitmap_order(wStream* s, } int update_approximate_create_offscreen_bitmap_order( - const CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap) + const CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap) { - const OFFSCREEN_DELETE_LIST* deleteList = &(create_offscreen_bitmap->deleteList); + const OFFSCREEN_DELETE_LIST* deleteList = & + (create_offscreen_bitmap->deleteList); return 32 + deleteList->cIndices * 2; } BOOL update_write_create_offscreen_bitmap_order( - wStream* s, - const CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap) + wStream* s, + const CREATE_OFFSCREEN_BITMAP_ORDER* create_offscreen_bitmap) { UINT16 flags; BOOL deleteListPresent; const OFFSCREEN_DELETE_LIST* deleteList; - if (!Stream_EnsureRemainingCapacity(s, update_approximate_create_offscreen_bitmap_order(create_offscreen_bitmap))) + if (!Stream_EnsureRemainingCapacity(s, + update_approximate_create_offscreen_bitmap_order(create_offscreen_bitmap))) return FALSE; deleteList = &(create_offscreen_bitmap->deleteList); - flags = create_offscreen_bitmap->id & 0x7FFF; - deleteListPresent = (deleteList->cIndices > 0) ? TRUE : FALSE; if (deleteListPresent) flags |= 0x8000; Stream_Write_UINT16(s, flags); /* flags (2 bytes) */ - Stream_Write_UINT16(s, create_offscreen_bitmap->cx); /* cx (2 bytes) */ Stream_Write_UINT16(s, create_offscreen_bitmap->cy); /* cy (2 bytes) */ if (deleteListPresent) { int i; - Stream_Write_UINT16(s, deleteList->cIndices); for (i = 0; i < (int) deleteList->cIndices; i++) @@ -2662,209 +2592,231 @@ BOOL update_write_create_offscreen_bitmap_order( } static BOOL update_read_switch_surface_order(wStream* s, - SWITCH_SURFACE_ORDER* switch_surface) + SWITCH_SURFACE_ORDER* switch_surface) { if (Stream_GetRemainingLength(s) < 2) return FALSE; Stream_Read_UINT16(s, switch_surface->bitmapId); /* bitmapId (2 bytes) */ - return TRUE; } int update_approximate_switch_surface_order( - const SWITCH_SURFACE_ORDER* switch_surface) + const SWITCH_SURFACE_ORDER* switch_surface) { return 2; } BOOL update_write_switch_surface_order( - wStream* s, const SWITCH_SURFACE_ORDER* switch_surface) + wStream* s, const SWITCH_SURFACE_ORDER* switch_surface) { int inf = update_approximate_switch_surface_order(switch_surface); + if (!Stream_EnsureRemainingCapacity(s, inf)) return FALSE; Stream_Write_UINT16(s, switch_surface->bitmapId); /* bitmapId (2 bytes) */ - return TRUE; } static BOOL update_read_create_nine_grid_bitmap_order( - wStream* s, - CREATE_NINE_GRID_BITMAP_ORDER* create_nine_grid_bitmap) + wStream* s, + CREATE_NINE_GRID_BITMAP_ORDER* create_nine_grid_bitmap) { NINE_GRID_BITMAP_INFO* nineGridInfo; if (Stream_GetRemainingLength(s) < 19) return FALSE; - Stream_Read_UINT8(s, create_nine_grid_bitmap->bitmapBpp); /* bitmapBpp (1 byte) */ - if ((create_nine_grid_bitmap->bitmapBpp < 1) || (create_nine_grid_bitmap->bitmapBpp > 32)) + Stream_Read_UINT8(s, + create_nine_grid_bitmap->bitmapBpp); /* bitmapBpp (1 byte) */ + + if ((create_nine_grid_bitmap->bitmapBpp < 1) + || (create_nine_grid_bitmap->bitmapBpp > 32)) { WLog_ERR(TAG, "invalid bpp value %d", create_nine_grid_bitmap->bitmapBpp); return FALSE; } - Stream_Read_UINT16(s, create_nine_grid_bitmap->bitmapId); /* bitmapId (2 bytes) */ + Stream_Read_UINT16(s, + create_nine_grid_bitmap->bitmapId); /* bitmapId (2 bytes) */ nineGridInfo = &(create_nine_grid_bitmap->nineGridInfo); Stream_Read_UINT32(s, nineGridInfo->flFlags); /* flFlags (4 bytes) */ Stream_Read_UINT16(s, nineGridInfo->ulLeftWidth); /* ulLeftWidth (2 bytes) */ Stream_Read_UINT16(s, nineGridInfo->ulRightWidth); /* ulRightWidth (2 bytes) */ Stream_Read_UINT16(s, nineGridInfo->ulTopHeight); /* ulTopHeight (2 bytes) */ - Stream_Read_UINT16(s, nineGridInfo->ulBottomHeight); /* ulBottomHeight (2 bytes) */ - update_read_colorref(s, &nineGridInfo->crTransparent); /* crTransparent (4 bytes) */ - + Stream_Read_UINT16(s, + nineGridInfo->ulBottomHeight); /* ulBottomHeight (2 bytes) */ + update_read_colorref(s, + &nineGridInfo->crTransparent); /* crTransparent (4 bytes) */ return TRUE; } static BOOL update_read_frame_marker_order(wStream* s, - FRAME_MARKER_ORDER* frame_marker) + FRAME_MARKER_ORDER* frame_marker) { if (Stream_GetRemainingLength(s) < 4) return FALSE; Stream_Read_UINT32(s, frame_marker->action); /* action (4 bytes) */ - return TRUE; } static BOOL update_read_stream_bitmap_first_order( - wStream* s, STREAM_BITMAP_FIRST_ORDER* stream_bitmap_first) + wStream* s, STREAM_BITMAP_FIRST_ORDER* stream_bitmap_first) { if (Stream_GetRemainingLength(s) < 10) // 8 + 2 at least return FALSE; - Stream_Read_UINT8(s, stream_bitmap_first->bitmapFlags); /* bitmapFlags (1 byte) */ + Stream_Read_UINT8(s, + stream_bitmap_first->bitmapFlags); /* bitmapFlags (1 byte) */ Stream_Read_UINT8(s, stream_bitmap_first->bitmapBpp); /* bitmapBpp (1 byte) */ - if ((stream_bitmap_first->bitmapBpp < 1) || (stream_bitmap_first->bitmapBpp > 32)) + + if ((stream_bitmap_first->bitmapBpp < 1) + || (stream_bitmap_first->bitmapBpp > 32)) { WLog_ERR(TAG, "invalid bpp value %d", stream_bitmap_first->bitmapBpp); return FALSE; } - Stream_Read_UINT16(s, stream_bitmap_first->bitmapType); /* bitmapType (2 bytes) */ - Stream_Read_UINT16(s, stream_bitmap_first->bitmapWidth); /* bitmapWidth (2 bytes) */ - Stream_Read_UINT16(s, stream_bitmap_first->bitmapHeight); /* bitmapHeigth (2 bytes) */ + Stream_Read_UINT16(s, + stream_bitmap_first->bitmapType); /* bitmapType (2 bytes) */ + Stream_Read_UINT16(s, + stream_bitmap_first->bitmapWidth); /* bitmapWidth (2 bytes) */ + Stream_Read_UINT16(s, + stream_bitmap_first->bitmapHeight); /* bitmapHeigth (2 bytes) */ if (stream_bitmap_first->bitmapFlags & STREAM_BITMAP_V2) { if (Stream_GetRemainingLength(s) < 4) return FALSE; - Stream_Read_UINT32(s, stream_bitmap_first->bitmapSize); /* bitmapSize (4 bytes) */ + Stream_Read_UINT32(s, + stream_bitmap_first->bitmapSize); /* bitmapSize (4 bytes) */ } else { if (Stream_GetRemainingLength(s) < 2) return FALSE; - Stream_Read_UINT16(s, stream_bitmap_first->bitmapSize); /* bitmapSize (2 bytes) */ + Stream_Read_UINT16(s, + stream_bitmap_first->bitmapSize); /* bitmapSize (2 bytes) */ } - FIELD_SKIP_BUFFER16(s, stream_bitmap_first->bitmapBlockSize); /* bitmapBlockSize(2 bytes) + bitmapBlock */ - + FIELD_SKIP_BUFFER16(s, + stream_bitmap_first->bitmapBlockSize); /* bitmapBlockSize(2 bytes) + bitmapBlock */ return TRUE; } static BOOL update_read_stream_bitmap_next_order( - wStream* s, STREAM_BITMAP_NEXT_ORDER* stream_bitmap_next) + wStream* s, STREAM_BITMAP_NEXT_ORDER* stream_bitmap_next) { if (Stream_GetRemainingLength(s) < 5) return FALSE; - Stream_Read_UINT8(s, stream_bitmap_next->bitmapFlags); /* bitmapFlags (1 byte) */ - Stream_Read_UINT16(s, stream_bitmap_next->bitmapType); /* bitmapType (2 bytes) */ - FIELD_SKIP_BUFFER16(s, stream_bitmap_next->bitmapBlockSize); /* bitmapBlockSize(2 bytes) + bitmapBlock */ - + Stream_Read_UINT8(s, + stream_bitmap_next->bitmapFlags); /* bitmapFlags (1 byte) */ + Stream_Read_UINT16(s, + stream_bitmap_next->bitmapType); /* bitmapType (2 bytes) */ + FIELD_SKIP_BUFFER16(s, + stream_bitmap_next->bitmapBlockSize); /* bitmapBlockSize(2 bytes) + bitmapBlock */ return TRUE; } static BOOL update_read_draw_gdiplus_first_order( - wStream* s, DRAW_GDIPLUS_FIRST_ORDER* draw_gdiplus_first) + wStream* s, DRAW_GDIPLUS_FIRST_ORDER* draw_gdiplus_first) { if (Stream_GetRemainingLength(s) < 11) return FALSE; Stream_Seek_UINT8(s); /* pad1Octet (1 byte) */ Stream_Read_UINT16(s, draw_gdiplus_first->cbSize); /* cbSize (2 bytes) */ - Stream_Read_UINT32(s, draw_gdiplus_first->cbTotalSize); /* cbTotalSize (4 bytes) */ - Stream_Read_UINT32(s, draw_gdiplus_first->cbTotalEmfSize); /* cbTotalEmfSize (4 bytes) */ - + Stream_Read_UINT32(s, + draw_gdiplus_first->cbTotalSize); /* cbTotalSize (4 bytes) */ + Stream_Read_UINT32(s, + draw_gdiplus_first->cbTotalEmfSize); /* cbTotalEmfSize (4 bytes) */ return Stream_SafeSeek(s, draw_gdiplus_first->cbSize); /* emfRecords */ } static BOOL update_read_draw_gdiplus_next_order( - wStream* s, DRAW_GDIPLUS_NEXT_ORDER* draw_gdiplus_next) + wStream* s, DRAW_GDIPLUS_NEXT_ORDER* draw_gdiplus_next) { if (Stream_GetRemainingLength(s) < 3) return FALSE; Stream_Seek_UINT8(s); /* pad1Octet (1 byte) */ - FIELD_SKIP_BUFFER16(s, draw_gdiplus_next->cbSize); /* cbSize(2 bytes) + emfRecords */ - + FIELD_SKIP_BUFFER16(s, + draw_gdiplus_next->cbSize); /* cbSize(2 bytes) + emfRecords */ return TRUE; } static BOOL update_read_draw_gdiplus_end_order( - wStream* s, DRAW_GDIPLUS_END_ORDER* draw_gdiplus_end) + wStream* s, DRAW_GDIPLUS_END_ORDER* draw_gdiplus_end) { if (Stream_GetRemainingLength(s) < 11) return FALSE; Stream_Seek_UINT8(s); /* pad1Octet (1 byte) */ Stream_Read_UINT16(s, draw_gdiplus_end->cbSize); /* cbSize (2 bytes) */ - Stream_Read_UINT32(s, draw_gdiplus_end->cbTotalSize); /* cbTotalSize (4 bytes) */ - Stream_Read_UINT32(s, draw_gdiplus_end->cbTotalEmfSize); /* cbTotalEmfSize (4 bytes) */ - + Stream_Read_UINT32(s, + draw_gdiplus_end->cbTotalSize); /* cbTotalSize (4 bytes) */ + Stream_Read_UINT32(s, + draw_gdiplus_end->cbTotalEmfSize); /* cbTotalEmfSize (4 bytes) */ return Stream_SafeSeek(s, draw_gdiplus_end->cbSize); /* emfRecords */ } static BOOL update_read_draw_gdiplus_cache_first_order( - wStream* s, DRAW_GDIPLUS_CACHE_FIRST_ORDER* draw_gdiplus_cache_first) + wStream* s, DRAW_GDIPLUS_CACHE_FIRST_ORDER* draw_gdiplus_cache_first) { if (Stream_GetRemainingLength(s) < 11) return FALSE; Stream_Read_UINT8(s, draw_gdiplus_cache_first->flags); /* flags (1 byte) */ - Stream_Read_UINT16(s, draw_gdiplus_cache_first->cacheType); /* cacheType (2 bytes) */ - Stream_Read_UINT16(s, draw_gdiplus_cache_first->cacheIndex); /* cacheIndex (2 bytes) */ + Stream_Read_UINT16(s, + draw_gdiplus_cache_first->cacheType); /* cacheType (2 bytes) */ + Stream_Read_UINT16(s, + draw_gdiplus_cache_first->cacheIndex); /* cacheIndex (2 bytes) */ Stream_Read_UINT16(s, draw_gdiplus_cache_first->cbSize); /* cbSize (2 bytes) */ - Stream_Read_UINT32(s, draw_gdiplus_cache_first->cbTotalSize); /* cbTotalSize (4 bytes) */ - + Stream_Read_UINT32(s, + draw_gdiplus_cache_first->cbTotalSize); /* cbTotalSize (4 bytes) */ return Stream_SafeSeek(s, draw_gdiplus_cache_first->cbSize); /* emfRecords */ } static BOOL update_read_draw_gdiplus_cache_next_order( - wStream* s, DRAW_GDIPLUS_CACHE_NEXT_ORDER* draw_gdiplus_cache_next) + wStream* s, DRAW_GDIPLUS_CACHE_NEXT_ORDER* draw_gdiplus_cache_next) { if (Stream_GetRemainingLength(s) < 7) return FALSE; Stream_Read_UINT8(s, draw_gdiplus_cache_next->flags); /* flags (1 byte) */ - Stream_Read_UINT16(s, draw_gdiplus_cache_next->cacheType); /* cacheType (2 bytes) */ - Stream_Read_UINT16(s, draw_gdiplus_cache_next->cacheIndex); /* cacheIndex (2 bytes) */ - FIELD_SKIP_BUFFER16(s, draw_gdiplus_cache_next->cbSize); /* cbSize(2 bytes) + emfRecords */ - + Stream_Read_UINT16(s, + draw_gdiplus_cache_next->cacheType); /* cacheType (2 bytes) */ + Stream_Read_UINT16(s, + draw_gdiplus_cache_next->cacheIndex); /* cacheIndex (2 bytes) */ + FIELD_SKIP_BUFFER16(s, + draw_gdiplus_cache_next->cbSize); /* cbSize(2 bytes) + emfRecords */ return TRUE; } static BOOL update_read_draw_gdiplus_cache_end_order( - wStream* s, DRAW_GDIPLUS_CACHE_END_ORDER* draw_gdiplus_cache_end) + wStream* s, DRAW_GDIPLUS_CACHE_END_ORDER* draw_gdiplus_cache_end) { if (Stream_GetRemainingLength(s) < 11) return FALSE; Stream_Read_UINT8(s, draw_gdiplus_cache_end->flags); /* flags (1 byte) */ - Stream_Read_UINT16(s, draw_gdiplus_cache_end->cacheType); /* cacheType (2 bytes) */ - Stream_Read_UINT16(s, draw_gdiplus_cache_end->cacheIndex); /* cacheIndex (2 bytes) */ + Stream_Read_UINT16(s, + draw_gdiplus_cache_end->cacheType); /* cacheType (2 bytes) */ + Stream_Read_UINT16(s, + draw_gdiplus_cache_end->cacheIndex); /* cacheIndex (2 bytes) */ Stream_Read_UINT16(s, draw_gdiplus_cache_end->cbSize); /* cbSize (2 bytes) */ - Stream_Read_UINT32(s, draw_gdiplus_cache_end->cbTotalSize); /* cbTotalSize (4 bytes) */ - + Stream_Read_UINT32(s, + draw_gdiplus_cache_end->cbTotalSize); /* cbTotalSize (4 bytes) */ return Stream_SafeSeek(s, draw_gdiplus_cache_end->cbSize); /* emfRecords */ } -static BOOL update_read_field_flags(wStream* s, UINT32* fieldFlags, BYTE flags, BYTE fieldBytes) +static BOOL update_read_field_flags(wStream* s, UINT32* fieldFlags, BYTE flags, + BYTE fieldBytes) { int i; BYTE byte; @@ -2884,6 +2836,7 @@ static BOOL update_read_field_flags(wStream* s, UINT32* fieldFlags, BYTE flags, return FALSE; *fieldFlags = 0; + for (i = 0; i < fieldBytes; i++) { Stream_Read_UINT8(s, byte); @@ -2893,7 +2846,8 @@ static BOOL update_read_field_flags(wStream* s, UINT32* fieldFlags, BYTE flags, return TRUE; } -BOOL update_write_field_flags(wStream* s, UINT32 fieldFlags, BYTE flags, BYTE fieldBytes) +BOOL update_write_field_flags(wStream* s, UINT32 fieldFlags, BYTE flags, + BYTE fieldBytes) { BYTE byte; @@ -2999,7 +2953,6 @@ BOOL update_write_bounds(wStream* s, ORDER_INFO* orderInfo) } else if (orderInfo->boundsFlags & BOUND_DELTA_LEFT) { - } if (orderInfo->boundsFlags & BOUND_TOP) @@ -3009,7 +2962,6 @@ BOOL update_write_bounds(wStream* s, ORDER_INFO* orderInfo) } else if (orderInfo->boundsFlags & BOUND_DELTA_TOP) { - } if (orderInfo->boundsFlags & BOUND_RIGHT) @@ -3019,7 +2971,6 @@ BOOL update_write_bounds(wStream* s, ORDER_INFO* orderInfo) } else if (orderInfo->boundsFlags & BOUND_DELTA_RIGHT) { - } if (orderInfo->boundsFlags & BOUND_BOTTOM) @@ -3029,7 +2980,6 @@ BOOL update_write_bounds(wStream* s, ORDER_INFO* orderInfo) } else if (orderInfo->boundsFlags & BOUND_DELTA_BOTTOM) { - } return TRUE; @@ -3040,7 +2990,6 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) ORDER_INFO* orderInfo; rdpContext* context = update->context; rdpPrimaryUpdate* primary = update->primary; - orderInfo = &(primary->order_info); if (flags & ORDER_TYPE_CHANGE) @@ -3053,7 +3002,7 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) } if (!update_read_field_flags(s, &(orderInfo->fieldFlags), flags, - PRIMARY_DRAWING_ORDER_FIELD_BYTES[orderInfo->orderType])) + PRIMARY_DRAWING_ORDER_FIELD_BYTES[orderInfo->orderType])) { WLog_ERR(TAG, "update_read_field_flags() failed"); return FALSE; @@ -3074,9 +3023,9 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) } orderInfo->deltaCoordinates = (flags & ORDER_DELTA_COORDINATES) ? TRUE : FALSE; - #ifdef WITH_DEBUG_ORDERS - WLog_DBG(TAG, "%s Primary Drawing Order (0x%02X)", PRIMARY_DRAWING_ORDER_STRINGS[orderInfo->orderType], orderInfo->orderType); + WLog_DBG(TAG, "%s Primary Drawing Order (0x%02X)", + PRIMARY_DRAWING_ORDER_STRINGS[orderInfo->orderType], orderInfo->orderType); #endif switch (orderInfo->orderType) @@ -3087,6 +3036,7 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) WLog_ERR(TAG, "ORDER_TYPE_DSTBLT - update_read_dstblt_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "DstBlt"); IFCALL(primary->DstBlt, context, &primary->dstblt); break; @@ -3097,6 +3047,7 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) WLog_ERR(TAG, "ORDER_TYPE_PATBLT - update_read_patblt_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "PatBlt"); IFCALL(primary->PatBlt, context, &primary->patblt); break; @@ -3107,6 +3058,7 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) WLog_ERR(TAG, "ORDER_TYPE_SCRBLT - update_read_scrblt_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "ScrBlt"); IFCALL(primary->ScrBlt, context, &primary->scrblt); break; @@ -3114,9 +3066,11 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) case ORDER_TYPE_OPAQUE_RECT: if (!update_read_opaque_rect_order(s, orderInfo, &(primary->opaque_rect))) { - WLog_ERR(TAG, "ORDER_TYPE_OPAQUE_RECT - update_read_opaque_rect_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_OPAQUE_RECT - update_read_opaque_rect_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "OpaqueRect"); IFCALL(primary->OpaqueRect, context, &primary->opaque_rect); break; @@ -3124,9 +3078,11 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) case ORDER_TYPE_DRAW_NINE_GRID: if (!update_read_draw_nine_grid_order(s, orderInfo, &(primary->draw_nine_grid))) { - WLog_ERR(TAG, "ORDER_TYPE_DRAW_NINE_GRID - update_read_draw_nine_grid_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_DRAW_NINE_GRID - update_read_draw_nine_grid_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "DrawNineGrid"); IFCALL(primary->DrawNineGrid, context, &primary->draw_nine_grid); break; @@ -3134,9 +3090,11 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) case ORDER_TYPE_MULTI_DSTBLT: if (!update_read_multi_dstblt_order(s, orderInfo, &(primary->multi_dstblt))) { - WLog_ERR(TAG, "ORDER_TYPE_MULTI_DSTBLT - update_read_multi_dstblt_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_MULTI_DSTBLT - update_read_multi_dstblt_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "MultiDstBlt"); IFCALL(primary->MultiDstBlt, context, &primary->multi_dstblt); break; @@ -3144,9 +3102,11 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) case ORDER_TYPE_MULTI_PATBLT: if (!update_read_multi_patblt_order(s, orderInfo, &(primary->multi_patblt))) { - WLog_ERR(TAG, "ORDER_TYPE_MULTI_PATBLT - update_read_multi_patblt_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_MULTI_PATBLT - update_read_multi_patblt_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "MultiPatBlt"); IFCALL(primary->MultiPatBlt, context, &primary->multi_patblt); break; @@ -3154,29 +3114,37 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) case ORDER_TYPE_MULTI_SCRBLT: if (!update_read_multi_scrblt_order(s, orderInfo, &(primary->multi_scrblt))) { - WLog_ERR(TAG, "ORDER_TYPE_MULTI_SCRBLT - update_read_multi_scrblt_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_MULTI_SCRBLT - update_read_multi_scrblt_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "MultiScrBlt"); IFCALL(primary->MultiScrBlt, context, &primary->multi_scrblt); break; case ORDER_TYPE_MULTI_OPAQUE_RECT: - if (!update_read_multi_opaque_rect_order(s, orderInfo, &(primary->multi_opaque_rect))) + if (!update_read_multi_opaque_rect_order(s, orderInfo, + &(primary->multi_opaque_rect))) { - WLog_ERR(TAG, "ORDER_TYPE_MULTI_OPAQUE_RECT - update_read_multi_opaque_rect_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_MULTI_OPAQUE_RECT - update_read_multi_opaque_rect_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "MultiOpaqueRect"); IFCALL(primary->MultiOpaqueRect, context, &primary->multi_opaque_rect); break; case ORDER_TYPE_MULTI_DRAW_NINE_GRID: - if (!update_read_multi_draw_nine_grid_order(s, orderInfo, &(primary->multi_draw_nine_grid))) + if (!update_read_multi_draw_nine_grid_order(s, orderInfo, + &(primary->multi_draw_nine_grid))) { - WLog_ERR(TAG, "ORDER_TYPE_MULTI_DRAW_NINE_GRID - update_read_multi_draw_nine_grid_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_MULTI_DRAW_NINE_GRID - update_read_multi_draw_nine_grid_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "MultiDrawNineGrid"); IFCALL(primary->MultiDrawNineGrid, context, &primary->multi_draw_nine_grid); break; @@ -3187,6 +3155,7 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) WLog_ERR(TAG, "ORDER_TYPE_LINE_TO - update_read_line_to_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "LineTo"); IFCALL(primary->LineTo, context, &primary->line_to); break; @@ -3197,6 +3166,7 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) WLog_ERR(TAG, "ORDER_TYPE_POLYLINE - update_read_polyline_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "Polyline"); IFCALL(primary->Polyline, context, &primary->polyline); break; @@ -3207,6 +3177,7 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) WLog_ERR(TAG, "ORDER_TYPE_MEMBLT - update_read_memblt_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "MemBlt"); IFCALL(primary->MemBlt, context, &primary->memblt); break; @@ -3217,6 +3188,7 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) WLog_ERR(TAG, "ORDER_TYPE_MEM3BLT - update_read_mem3blt_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "Mem3Blt"); IFCALL(primary->Mem3Blt, context, &primary->mem3blt); break; @@ -3224,9 +3196,11 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) case ORDER_TYPE_SAVE_BITMAP: if (!update_read_save_bitmap_order(s, orderInfo, &(primary->save_bitmap))) { - WLog_ERR(TAG, "ORDER_TYPE_SAVE_BITMAP - update_read_save_bitmap_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_SAVE_BITMAP - update_read_save_bitmap_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "SaveBitmap"); IFCALL(primary->SaveBitmap, context, &primary->save_bitmap); break; @@ -3234,9 +3208,11 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) case ORDER_TYPE_GLYPH_INDEX: if (!update_read_glyph_index_order(s, orderInfo, &(primary->glyph_index))) { - WLog_ERR(TAG, "ORDER_TYPE_GLYPH_INDEX - update_read_glyph_index_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_GLYPH_INDEX - update_read_glyph_index_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "GlyphIndex"); IFCALL(primary->GlyphIndex, context, &primary->glyph_index); break; @@ -3247,6 +3223,7 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) WLog_ERR(TAG, "ORDER_TYPE_FAST_INDEX - update_read_fast_index_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "FastIndex"); IFCALL(primary->FastIndex, context, &primary->fast_index); break; @@ -3257,6 +3234,7 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) WLog_ERR(TAG, "ORDER_TYPE_FAST_GLYPH - update_read_fast_glyph_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "FastGlyph"); IFCALL(primary->FastGlyph, context, &primary->fast_glyph); break; @@ -3267,6 +3245,7 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) WLog_ERR(TAG, "ORDER_TYPE_POLYGON_SC - update_read_polygon_sc_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "PolygonSC"); IFCALL(primary->PolygonSC, context, &primary->polygon_sc); break; @@ -3277,6 +3256,7 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) WLog_ERR(TAG, "ORDER_TYPE_POLYGON_CB - update_read_polygon_cb_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "PolygonCB"); IFCALL(primary->PolygonCB, context, &primary->polygon_cb); break; @@ -3287,6 +3267,7 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) WLog_ERR(TAG, "ORDER_TYPE_ELLIPSE_SC - update_read_ellipse_sc_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "EllipseSC"); IFCALL(primary->EllipseSC, context, &primary->ellipse_sc); break; @@ -3297,6 +3278,7 @@ BOOL update_recv_primary_order(rdpUpdate* update, wStream* s, BYTE flags) WLog_ERR(TAG, "ORDER_TYPE_ELLIPSE_CB - update_read_ellipse_cb_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "EllipseCB"); IFCALL(primary->EllipseCB, context, &primary->ellipse_cb); break; @@ -3331,107 +3313,137 @@ BOOL update_recv_secondary_order(rdpUpdate* update, wStream* s, BYTE flags) Stream_Read_UINT16(s, orderLength); /* orderLength (2 bytes) */ Stream_Read_UINT16(s, extraFlags); /* extraFlags (2 bytes) */ Stream_Read_UINT8(s, orderType); /* orderType (1 byte) */ - next = Stream_Pointer(s) + ((INT16) orderLength) + 7; - #ifdef WITH_DEBUG_ORDERS + if (orderType < SECONDARY_DRAWING_ORDER_COUNT) - WLog_DBG(TAG, "%s Secondary Drawing Order (0x%02X)", SECONDARY_DRAWING_ORDER_STRINGS[orderType], orderType); + WLog_DBG(TAG, "%s Secondary Drawing Order (0x%02X)", + SECONDARY_DRAWING_ORDER_STRINGS[orderType], orderType); else WLog_DBG(TAG, "Unknown Secondary Drawing Order (0x%02X)", orderType); + #endif switch (orderType) { case ORDER_TYPE_BITMAP_UNCOMPRESSED: - if (!update_read_cache_bitmap_order(s, &(secondary->cache_bitmap_order), FALSE, extraFlags)) + if (!update_read_cache_bitmap_order(s, &(secondary->cache_bitmap_order), FALSE, + extraFlags)) { - WLog_ERR(TAG, "ORDER_TYPE_BITMAP_UNCOMPRESSED - update_read_cache_bitmap_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_BITMAP_UNCOMPRESSED - update_read_cache_bitmap_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "CacheBitmapUncompressed"); IFCALL(secondary->CacheBitmap, context, &(secondary->cache_bitmap_order)); break; case ORDER_TYPE_CACHE_BITMAP_COMPRESSED: - if (!update_read_cache_bitmap_order(s, &(secondary->cache_bitmap_order), TRUE, extraFlags)) + if (!update_read_cache_bitmap_order(s, &(secondary->cache_bitmap_order), TRUE, + extraFlags)) { - WLog_ERR(TAG, "ORDER_TYPE_CACHE_BITMAP_COMPRESSED - update_read_cache_bitmap_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_CACHE_BITMAP_COMPRESSED - update_read_cache_bitmap_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "CacheBitmapCompressed"); IFCALL(secondary->CacheBitmap, context, &(secondary->cache_bitmap_order)); break; case ORDER_TYPE_BITMAP_UNCOMPRESSED_V2: - if (!update_read_cache_bitmap_v2_order(s, &(secondary->cache_bitmap_v2_order), FALSE, extraFlags)) + if (!update_read_cache_bitmap_v2_order(s, &(secondary->cache_bitmap_v2_order), + FALSE, extraFlags)) { - WLog_ERR(TAG, "ORDER_TYPE_BITMAP_UNCOMPRESSED_V2 - update_read_cache_bitmap_v2_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_BITMAP_UNCOMPRESSED_V2 - update_read_cache_bitmap_v2_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "CacheBitmapUncompressedV2"); IFCALL(secondary->CacheBitmapV2, context, &(secondary->cache_bitmap_v2_order)); break; case ORDER_TYPE_BITMAP_COMPRESSED_V2: - if (!update_read_cache_bitmap_v2_order(s, &(secondary->cache_bitmap_v2_order), TRUE, extraFlags)) + if (!update_read_cache_bitmap_v2_order(s, &(secondary->cache_bitmap_v2_order), + TRUE, extraFlags)) { - WLog_ERR(TAG, "ORDER_TYPE_BITMAP_COMPRESSED_V2 - update_read_cache_bitmap_v2_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_BITMAP_COMPRESSED_V2 - update_read_cache_bitmap_v2_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "CacheBitmapCompressedV2"); IFCALL(secondary->CacheBitmapV2, context, &(secondary->cache_bitmap_v2_order)); break; case ORDER_TYPE_BITMAP_COMPRESSED_V3: - if (!update_read_cache_bitmap_v3_order(s, &(secondary->cache_bitmap_v3_order), extraFlags)) + if (!update_read_cache_bitmap_v3_order(s, &(secondary->cache_bitmap_v3_order), + extraFlags)) { - WLog_ERR(TAG, "ORDER_TYPE_BITMAP_COMPRESSED_V3 - update_read_cache_bitmap_v3_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_BITMAP_COMPRESSED_V3 - update_read_cache_bitmap_v3_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "CacheBitmapCompressedV3"); IFCALL(secondary->CacheBitmapV3, context, &(secondary->cache_bitmap_v3_order)); break; case ORDER_TYPE_CACHE_COLOR_TABLE: - if (!update_read_cache_color_table_order(s, &(secondary->cache_color_table_order), extraFlags)) + if (!update_read_cache_color_table_order(s, + &(secondary->cache_color_table_order), extraFlags)) { - WLog_ERR(TAG, "ORDER_TYPE_CACHE_COLOR_TABLE - update_read_cache_color_table_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_CACHE_COLOR_TABLE - update_read_cache_color_table_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "CacheColorTable"); - IFCALL(secondary->CacheColorTable, context, &(secondary->cache_color_table_order)); + IFCALL(secondary->CacheColorTable, context, + &(secondary->cache_color_table_order)); break; case ORDER_TYPE_CACHE_GLYPH: if (secondary->glyph_v2) { - if (!update_read_cache_glyph_v2_order(s, &(secondary->cache_glyph_v2_order), extraFlags)) + if (!update_read_cache_glyph_v2_order(s, &(secondary->cache_glyph_v2_order), + extraFlags)) { - WLog_ERR(TAG, "ORDER_TYPE_CACHE_GLYPH - update_read_cache_glyph_v2_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_CACHE_GLYPH - update_read_cache_glyph_v2_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "CacheGlyphV2"); IFCALL(secondary->CacheGlyphV2, context, &(secondary->cache_glyph_v2_order)); } else { - if (!update_read_cache_glyph_order(s, &(secondary->cache_glyph_order), extraFlags)) + if (!update_read_cache_glyph_order(s, &(secondary->cache_glyph_order), + extraFlags)) { - WLog_ERR(TAG, "ORDER_TYPE_CACHE_GLYPH - update_read_cache_glyph_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_CACHE_GLYPH - update_read_cache_glyph_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "CacheGlyph"); IFCALL(secondary->CacheGlyph, context, &(secondary->cache_glyph_order)); } + break; case ORDER_TYPE_CACHE_BRUSH: - if (!update_read_cache_brush_order(s, &(secondary->cache_brush_order), extraFlags)) + if (!update_read_cache_brush_order(s, &(secondary->cache_brush_order), + extraFlags)) { - WLog_ERR(TAG, "ORDER_TYPE_CACHE_BRUSH - update_read_cache_brush_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_CACHE_BRUSH - update_read_cache_brush_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "CacheBrush"); IFCALL(secondary->CacheBrush, context, &(secondary->cache_brush_order)); break; @@ -3441,74 +3453,88 @@ BOOL update_recv_secondary_order(rdpUpdate* update, wStream* s, BYTE flags) } Stream_SetPointer(s, next); - return TRUE; } -BOOL update_recv_altsec_order(rdpUpdate* update, wStream* s, BYTE flags) +static BOOL update_recv_altsec_order(rdpUpdate* update, wStream* s, BYTE flags) { BYTE orderType; rdpContext* context = update->context; rdpAltSecUpdate* altsec = update->altsec; - orderType = flags >>= 2; /* orderType is in higher 6 bits of flags field */ - #ifdef WITH_DEBUG_ORDERS + if (orderType < ALTSEC_DRAWING_ORDER_COUNT) - WLog_DBG(TAG, "%s Alternate Secondary Drawing Order (0x%02X)", ALTSEC_DRAWING_ORDER_STRINGS[orderType], orderType); + WLog_DBG(TAG, "%s Alternate Secondary Drawing Order (0x%02X)", + ALTSEC_DRAWING_ORDER_STRINGS[orderType], orderType); else WLog_DBG(TAG, "Unknown Alternate Secondary Drawing Order: 0x%02X", orderType); + #endif switch (orderType) { case ORDER_TYPE_CREATE_OFFSCREEN_BITMAP: - if (!update_read_create_offscreen_bitmap_order(s, &(altsec->create_offscreen_bitmap))) + if (!update_read_create_offscreen_bitmap_order(s, + &(altsec->create_offscreen_bitmap))) { - WLog_ERR(TAG, "ORDER_TYPE_CREATE_OFFSCREEN_BITMAP - update_read_create_offscreen_bitmap_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_CREATE_OFFSCREEN_BITMAP - update_read_create_offscreen_bitmap_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "CreateOffscreenBitmap"); - IFCALL(altsec->CreateOffscreenBitmap, context, &(altsec->create_offscreen_bitmap)); + IFCALL(altsec->CreateOffscreenBitmap, context, + &(altsec->create_offscreen_bitmap)); break; case ORDER_TYPE_SWITCH_SURFACE: if (!update_read_switch_surface_order(s, &(altsec->switch_surface))) { - WLog_ERR(TAG, "ORDER_TYPE_SWITCH_SURFACE - update_read_switch_surface_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_SWITCH_SURFACE - update_read_switch_surface_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "SwitchSurface"); IFCALL(altsec->SwitchSurface, context, &(altsec->switch_surface)); break; case ORDER_TYPE_CREATE_NINE_GRID_BITMAP: - if (!update_read_create_nine_grid_bitmap_order(s, &(altsec->create_nine_grid_bitmap))) + if (!update_read_create_nine_grid_bitmap_order(s, + &(altsec->create_nine_grid_bitmap))) { - WLog_ERR(TAG, "ORDER_TYPE_CREATE_NINE_GRID_BITMAP - update_read_create_nine_grid_bitmap_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_CREATE_NINE_GRID_BITMAP - update_read_create_nine_grid_bitmap_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "CreateNineGridBitmap"); - IFCALL(altsec->CreateNineGridBitmap, context, &(altsec->create_nine_grid_bitmap)); + IFCALL(altsec->CreateNineGridBitmap, context, + &(altsec->create_nine_grid_bitmap)); break; case ORDER_TYPE_FRAME_MARKER: if (!update_read_frame_marker_order(s, &(altsec->frame_marker))) { - WLog_ERR(TAG, "ORDER_TYPE_FRAME_MARKER - update_read_frame_marker_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_FRAME_MARKER - update_read_frame_marker_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "AltSecFrameMarker: action: %s (%d)", - (!altsec->frame_marker.action) ? "Begin" : "End", altsec->frame_marker.action); + (!altsec->frame_marker.action) ? "Begin" : "End", altsec->frame_marker.action); IFCALL(altsec->FrameMarker, context, &(altsec->frame_marker)); break; case ORDER_TYPE_STREAM_BITMAP_FIRST: if (!update_read_stream_bitmap_first_order(s, &(altsec->stream_bitmap_first))) { - WLog_ERR(TAG, "ORDER_TYPE_STREAM_BITMAP_FIRST - update_read_stream_bitmap_first_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_STREAM_BITMAP_FIRST - update_read_stream_bitmap_first_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "StreamBitmapFirst"); IFCALL(altsec->StreamBitmapFirst, context, &(altsec->stream_bitmap_first)); break; @@ -3516,9 +3542,11 @@ BOOL update_recv_altsec_order(rdpUpdate* update, wStream* s, BYTE flags) case ORDER_TYPE_STREAM_BITMAP_NEXT: if (!update_read_stream_bitmap_next_order(s, &(altsec->stream_bitmap_next))) { - WLog_ERR(TAG, "ORDER_TYPE_STREAM_BITMAP_NEXT - update_read_stream_bitmap_next_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_STREAM_BITMAP_NEXT - update_read_stream_bitmap_next_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "StreamBitmapNext"); IFCALL(altsec->StreamBitmapNext, context, &(altsec->stream_bitmap_next)); break; @@ -3526,9 +3554,11 @@ BOOL update_recv_altsec_order(rdpUpdate* update, wStream* s, BYTE flags) case ORDER_TYPE_GDIPLUS_FIRST: if (!update_read_draw_gdiplus_first_order(s, &(altsec->draw_gdiplus_first))) { - WLog_ERR(TAG, "ORDER_TYPE_GDIPLUS_FIRST - update_read_draw_gdiplus_first_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_GDIPLUS_FIRST - update_read_draw_gdiplus_first_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "DrawGdiPlusFirst"); IFCALL(altsec->DrawGdiPlusFirst, context, &(altsec->draw_gdiplus_first)); break; @@ -3536,9 +3566,11 @@ BOOL update_recv_altsec_order(rdpUpdate* update, wStream* s, BYTE flags) case ORDER_TYPE_GDIPLUS_NEXT: if (!update_read_draw_gdiplus_next_order(s, &(altsec->draw_gdiplus_next))) { - WLog_ERR(TAG, "ORDER_TYPE_GDIPLUS_NEXT - update_read_draw_gdiplus_next_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_GDIPLUS_NEXT - update_read_draw_gdiplus_next_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "DrawGdiPlusNext"); IFCALL(altsec->DrawGdiPlusNext, context, &(altsec->draw_gdiplus_next)); break; @@ -3546,39 +3578,52 @@ BOOL update_recv_altsec_order(rdpUpdate* update, wStream* s, BYTE flags) case ORDER_TYPE_GDIPLUS_END: if (update_read_draw_gdiplus_end_order(s, &(altsec->draw_gdiplus_end))) { - WLog_ERR(TAG, "ORDER_TYPE_GDIPLUS_END - update_read_draw_gdiplus_end_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_GDIPLUS_END - update_read_draw_gdiplus_end_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "DrawGdiPlusEnd"); IFCALL(altsec->DrawGdiPlusEnd, context, &(altsec->draw_gdiplus_end)); break; case ORDER_TYPE_GDIPLUS_CACHE_FIRST: - if (!update_read_draw_gdiplus_cache_first_order(s, &(altsec->draw_gdiplus_cache_first))) + if (!update_read_draw_gdiplus_cache_first_order(s, + &(altsec->draw_gdiplus_cache_first))) { - WLog_ERR(TAG, "ORDER_TYPE_GDIPLUS_CACHE_FIRST - update_read_draw_gdiplus_cache_first_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_GDIPLUS_CACHE_FIRST - update_read_draw_gdiplus_cache_first_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "DrawGdiPlusCacheFirst"); - IFCALL(altsec->DrawGdiPlusCacheFirst, context, &(altsec->draw_gdiplus_cache_first)); + IFCALL(altsec->DrawGdiPlusCacheFirst, context, + &(altsec->draw_gdiplus_cache_first)); break; case ORDER_TYPE_GDIPLUS_CACHE_NEXT: - if (!update_read_draw_gdiplus_cache_next_order(s, &(altsec->draw_gdiplus_cache_next))) + if (!update_read_draw_gdiplus_cache_next_order(s, + &(altsec->draw_gdiplus_cache_next))) { - WLog_ERR(TAG, "ORDER_TYPE_GDIPLUS_CACHE_NEXT - update_read_draw_gdiplus_cache_next_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_GDIPLUS_CACHE_NEXT - update_read_draw_gdiplus_cache_next_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "DrawGdiPlusCacheNext"); - IFCALL(altsec->DrawGdiPlusCacheNext, context, &(altsec->draw_gdiplus_cache_next)); + IFCALL(altsec->DrawGdiPlusCacheNext, context, + &(altsec->draw_gdiplus_cache_next)); break; case ORDER_TYPE_GDIPLUS_CACHE_END: - if (!update_read_draw_gdiplus_cache_end_order(s, &(altsec->draw_gdiplus_cache_end))) + if (!update_read_draw_gdiplus_cache_end_order(s, + &(altsec->draw_gdiplus_cache_end))) { - WLog_ERR(TAG, "ORDER_TYPE_GDIPLUS_CACHE_END - update_read_draw_gdiplus_cache_end_order() failed"); + WLog_ERR(TAG, + "ORDER_TYPE_GDIPLUS_CACHE_END - update_read_draw_gdiplus_cache_end_order() failed"); return FALSE; } + WLog_Print(update->log, WLOG_DEBUG, "DrawGdiPlusCacheEnd"); IFCALL(altsec->DrawGdiPlusCacheEnd, context, &(altsec->draw_gdiplus_cache_end)); break; @@ -3593,6 +3638,7 @@ BOOL update_recv_altsec_order(rdpUpdate* update, wStream* s, BYTE flags) default: break; } + return TRUE; } diff --git a/libfreerdp/gdi/CMakeLists.txt b/libfreerdp/gdi/CMakeLists.txt index 0bdc3423c..d3f91a1e6 100644 --- a/libfreerdp/gdi/CMakeLists.txt +++ b/libfreerdp/gdi/CMakeLists.txt @@ -39,6 +39,6 @@ set(${MODULE_PREFIX}_SRCS freerdp_module_add(${${MODULE_PREFIX}_SRCS}) if(BUILD_TESTING) -# add_subdirectory(test) + add_subdirectory(test) endif() diff --git a/libfreerdp/gdi/bitmap.c b/libfreerdp/gdi/bitmap.c index 521bda0bc..151e439a4 100644 --- a/libfreerdp/gdi/bitmap.c +++ b/libfreerdp/gdi/bitmap.c @@ -585,9 +585,10 @@ static BOOL BitBlt_SPna(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, UINT32 color; UINT32 colorA = ReadColor(srcp, hdcSrc->format); UINT32 colorB = ReadColor(patp, hdcDest->format); - colorA = ConvertColor(colorA, hdcSrc->format, - hdcDest->format, palette); + colorB = ConvertColor(colorB, hdcDest->format, + hdcSrc->format, palette); color = colorA & ~colorB; + color = ConvertColor(color, hdcSrc->format, hdcDest->format, palette); WriteColor(dstp, hdcDest->format, color); } } @@ -740,6 +741,8 @@ BOOL gdi_BitBlt(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest, if (!gdi_InvalidateRegion(hdcDest, nXDest, nYDest, nWidth, nHeight)) return FALSE; + WLog_DBG(TAG, "%s [%s]", __FUNCTION__, gdi_rop_to_string(rop)); + switch (rop) { case GDI_SRCCOPY: diff --git a/libfreerdp/gdi/gdi.c b/libfreerdp/gdi/gdi.c index af9b307c7..dd56edf4c 100644 --- a/libfreerdp/gdi/gdi.c +++ b/libfreerdp/gdi/gdi.c @@ -584,9 +584,9 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) UINT32 nXSrc = 0; UINT32 nYSrc = 0; foreColor = ConvertColor(patblt->foreColor, SrcFormat, - gdi->dstFormat, &gdi->palette); + gdi->drawing->hdc->format, &gdi->palette); backColor = ConvertColor(patblt->backColor, SrcFormat, - gdi->dstFormat, &gdi->palette); + gdi->drawing->hdc->format, &gdi->palette); originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor); switch (brush->style) @@ -616,7 +616,8 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) { const BYTE* hatched; HGDI_BITMAP hBmp; - BYTE* data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(gdi->dstFormat), + BYTE* data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel( + gdi->drawing->hdc->format), 16); if (!data) @@ -626,7 +627,8 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) } hatched = GDI_BS_HATCHED_PATTERNS + (8 * brush->hatch); - freerdp_image_copy_from_monochrome(data, gdi->dstFormat, 0, 0, 0, 8, 8, + freerdp_image_copy_from_monochrome(data, gdi->drawing->hdc->format, 0, 0, 0, 8, + 8, hatched, backColor, foreColor, &gdi->palette); hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->format, data); @@ -665,7 +667,8 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) { HGDI_BITMAP hBmp; UINT32 brushFormat; - BYTE* data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(gdi->dstFormat), + BYTE* data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel( + gdi->drawing->hdc->format), 16); if (!data) @@ -678,7 +681,7 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) { brushFormat = gdi_get_pixel_format(brush->bpp, FALSE); - if (!freerdp_image_copy(data, gdi->dstFormat, 0, 0, 0, + if (!freerdp_image_copy(data, gdi->drawing->hdc->format, 0, 0, 0, 8, 8, brush->data, brushFormat, 0, 0, 0, &gdi->palette)) { @@ -689,7 +692,8 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt) } else { - if (!freerdp_image_copy_from_monochrome(data, gdi->dstFormat, 0, 0, 0, 8, 8, + if (!freerdp_image_copy_from_monochrome(data, gdi->drawing->hdc->format, 0, 0, + 0, 8, 8, brush->data, backColor, foreColor, &gdi->palette)) { _aligned_free(data); @@ -762,8 +766,8 @@ static BOOL gdi_opaque_rect(rdpContext* context, UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth, FALSE); gdi_CRgnToRect(opaque_rect->nLeftRect, opaque_rect->nTopRect, opaque_rect->nWidth, opaque_rect->nHeight, &rect); - brush_color = ConvertColor(opaque_rect->color, SrcFormat, - gdi->dstFormat, &gdi->palette); + brush_color = ConvertColor(opaque_rect->color, PIXEL_FORMAT_RGB16, + gdi->drawing->hdc->format, &gdi->palette); if (!(hBrush = gdi_CreateSolidBrush(brush_color))) return FALSE; @@ -791,7 +795,7 @@ static BOOL gdi_multi_opaque_rect(rdpContext* context, gdi_CRgnToRect(rectangle->left, rectangle->top, rectangle->width, rectangle->height, &rect); brush_color = ConvertColor(multi_opaque_rect->color, SrcFormat, - gdi->dstFormat, &gdi->palette); + gdi->drawing->hdc->format, &gdi->palette); hBrush = gdi_CreateSolidBrush(brush_color); if (!hBrush) @@ -881,9 +885,9 @@ static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt) const rdpBrush* brush = &mem3blt->brush; gdiBitmap* bitmap = (gdiBitmap*) mem3blt->bitmap; const UINT32 foreColor = ConvertColor(mem3blt->foreColor, SrcFormat, - gdi->dstFormat, &gdi->palette); + gdi->drawing->hdc->format, &gdi->palette); const UINT32 backColor = ConvertColor(mem3blt->backColor, SrcFormat, - gdi->dstFormat, &gdi->palette); + gdi->drawing->hdc->format, &gdi->palette); const UINT32 originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor); switch (brush->style) @@ -1263,11 +1267,8 @@ BOOL gdi_init_ex(freerdp* instance, UINT32 format, UINT32 stride, BYTE* buffer, if (!gdi_init_primary(gdi, stride, buffer, pfree)) goto fail; - if (!context->cache) - { - if (!(context->cache = cache_new(instance->settings))) - goto fail; - } + if (!(context->cache = cache_new(instance->settings))) + goto fail; if (!freerdp_client_codecs_prepare(context->codecs, FREERDP_CODEC_ALL, gdi->width, gdi->height)) @@ -1309,13 +1310,8 @@ void gdi_free(freerdp* instance) } context = instance->context; - - if (context->cache) - { - cache_free(context->cache); - context->cache = NULL; - } - + cache_free(context->cache); + context->cache = NULL; instance->context->gdi = (rdpGdi*) NULL; } diff --git a/libfreerdp/gdi/graphics.c b/libfreerdp/gdi/graphics.c index 0e85d22e6..d1cf9303d 100644 --- a/libfreerdp/gdi/graphics.c +++ b/libfreerdp/gdi/graphics.c @@ -124,24 +124,26 @@ static BOOL gdi_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap) } static BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, - const BYTE* data, UINT32 width, UINT32 height, + const BYTE* pSrcData, UINT32 width, UINT32 height, UINT32 bpp, UINT32 length, BOOL compressed, UINT32 codecId) { int status; UINT16 size; - const BYTE* pSrcData; - BYTE* pDstData; - UINT32 SrcSize; + UINT32 SrcSize = length; UINT32 SrcFormat; UINT32 bytesPerPixel; rdpGdi* gdi = context->gdi; bytesPerPixel = (bpp + 7) / 8; size = width * height * 4; bitmap->data = (BYTE*) _aligned_malloc(size, 16); - pSrcData = data; - SrcSize = (UINT32) length; - pDstData = bitmap->data; + + if (!bitmap->data) + return FALSE; + + bitmap->compressed = FALSE; + bitmap->length = size; + bitmap->format = gdi->dstFormat; if (compressed) { @@ -150,14 +152,14 @@ static BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, status = interleaved_decompress(context->codecs->interleaved, pSrcData, SrcSize, bpp, - pDstData, gdi->dstFormat, + bitmap->data, bitmap->format, 0, 0, 0, width, height, &gdi->palette); } else { status = planar_decompress(context->codecs->planar, pSrcData, SrcSize, - pDstData, gdi->dstFormat, 0, 0, 0, + bitmap->data, bitmap->format, 0, 0, 0, width, height, TRUE); } @@ -170,14 +172,11 @@ static BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap, else { SrcFormat = gdi_get_pixel_format(bpp, FALSE); - status = freerdp_image_copy(pDstData, gdi->dstFormat, 0, 0, 0, + status = freerdp_image_copy(bitmap->data, bitmap->format, 0, 0, 0, width, height, pSrcData, SrcFormat, 0, 0, 0, &gdi->palette); } - bitmap->compressed = FALSE; - bitmap->length = size; - bitmap->format = gdi->dstFormat; return TRUE; } @@ -264,8 +263,10 @@ static BOOL gdi_Glyph_BeginDraw(rdpContext* context, UINT32 x, UINT32 y, BOOL ret = FALSE; UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth, FALSE); /* TODO: handle fOpRedundant! See xf_Glyph_BeginDraw() */ - bgcolor = ConvertColor(bgcolor, SrcFormat, gdi->dstFormat, &gdi->palette); - fgcolor = ConvertColor(fgcolor, SrcFormat, gdi->dstFormat, &gdi->palette); + bgcolor = ConvertColor(bgcolor, SrcFormat, gdi->drawing->hdc->format, + &gdi->palette); + fgcolor = ConvertColor(fgcolor, SrcFormat, gdi->drawing->hdc->format, + &gdi->palette); if (!(brush = gdi_CreateSolidBrush(fgcolor))) goto out; @@ -284,7 +285,7 @@ static BOOL gdi_Glyph_EndDraw(rdpContext* context, UINT32 x, UINT32 y, rdpGdi* gdi = context->gdi; UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth, FALSE); bgcolor = ConvertColor(bgcolor, SrcFormat, - gdi->dstFormat, &gdi->palette); + gdi->drawing->hdc->format, &gdi->palette); gdi->textColor = gdi_SetTextColor(gdi->drawing->hdc, bgcolor); return TRUE; }