freerdp_image_copy fixes, 8bit color improvements.
authorArmin Novak <armin.novak@gmail.com>
Sat, 23 Apr 2016 09:25:55 +0000 (11:25 +0200)
committerArmin Novak <armin.novak@thincast.com>
Thu, 6 Oct 2016 11:42:59 +0000 (13:42 +0200)
include/freerdp/gdi/bitmap.h
libfreerdp/cache/glyph.c
libfreerdp/codec/color.c
libfreerdp/codec/planar.c
libfreerdp/codec/progressive.c
libfreerdp/gdi/bitmap.c
libfreerdp/gdi/brush.c
libfreerdp/gdi/brush.h
libfreerdp/gdi/gdi.c
libfreerdp/gdi/gfx.c
libfreerdp/gdi/graphics.c

index 8309ff7..bf38324 100644 (file)
@@ -31,24 +31,25 @@ extern "C" {
 
 FREERDP_API UINT32 gdi_GetPixel(HGDI_DC hdc, UINT32 nXPos, UINT32 nYPos);
 FREERDP_API UINT32 gdi_SetPixel(HGDI_DC hdc, UINT32 X, UINT32 Y,
-                               UINT32 crColor);
+                                UINT32 crColor);
 FREERDP_API BYTE* gdi_GetPointer(HGDI_BITMAP hBmp, UINT32 X, UINT32 Y);
 
 FREERDP_API HGDI_BITMAP gdi_CreateBitmap(UINT32 nWidth, UINT32 nHeight,
-               UINT32 format,  BYTE* data);
+        UINT32 format, BYTE* data);
 FREERDP_API HGDI_BITMAP gdi_CreateBitmapEx(UINT32 nWidth, UINT32 nHeight,
-               UINT32 format, UINT32 stride,
-               BYTE* data, void (*fkt_free)(void*));
+        UINT32 format, UINT32 stride,
+        BYTE* data, void (*fkt_free)(void*));
 FREERDP_API HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc,
-               UINT32 nWidth, UINT32 nHeight);
+        UINT32 nWidth, UINT32 nHeight);
 
 FREERDP_API BOOL gdi_BitBlt(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                                                       UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
-                                                       UINT32 nXSrc, UINT32 nYSrc, DWORD rop);
+                            UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
+                            UINT32 nXSrc, UINT32 nYSrc, DWORD rop,
+                            const gdiPalette* palette);
 
 typedef BOOL (*p_BitBlt)(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                                                UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
-                                                UINT32 nXSrc, UINT32 nYSrc, DWORD rop);
+                         UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
+                         UINT32 nXSrc, UINT32 nYSrc, DWORD rop);
 
 #ifdef __cplusplus
 }
index 5478468..bbe0fd7 100644 (file)
 
 #define TAG FREERDP_TAG("cache.glyph")
 
+static rdpGlyph* glyph_cache_get(rdpGlyphCache* glyph_cache, UINT32 id,
+                                 UINT32 index);
+static void glyph_cache_put(rdpGlyphCache* glyph_cache, UINT32 id, UINT32 index,
+                            rdpGlyph* entry);
 
-static rdpGlyph* glyph_cache_get(rdpGlyphCache* glyph_cache, UINT32 id, UINT32 index);
-static void glyph_cache_put(rdpGlyphCache* glyph_cache, UINT32 id, UINT32 index, rdpGlyph* entry);
-
-static void* glyph_cache_fragment_get(rdpGlyphCache* glyph, UINT32 index, UINT32* count);
-static void glyph_cache_fragment_put(rdpGlyphCache* glyph, UINT32 index, UINT32 count, void* entry);
+static void* glyph_cache_fragment_get(rdpGlyphCache* glyph, UINT32 index,
+                                      UINT32* count);
+static void glyph_cache_fragment_put(rdpGlyphCache* glyph, UINT32 index,
+                                     UINT32 count, void* entry);
 
 static void update_process_glyph(rdpContext* context, const BYTE* data,
-                                UINT32* index, UINT32* x, UINT32* y,
-                                UINT32 cacheId, UINT32 ulCharInc, UINT32 flAccel)
+                                 UINT32* index,        UINT32* x, UINT32* y,
+                                 UINT32 cacheId, UINT32 ulCharInc, UINT32 flAccel)
 {
        UINT32 offset;
        rdpGlyph* glyph;
        UINT32 cacheIndex;
        rdpGraphics* graphics;
        rdpGlyphCache* glyph_cache;
-
        graphics = context->graphics;
        glyph_cache = context->cache->glyph;
-
        cacheIndex = data[*index];
-
        glyph = glyph_cache_get(glyph_cache, cacheId, cacheIndex);
 
        if ((ulCharInc == 0) && (!(flAccel & SO_CHAR_INC_EQUAL_BM_BASE)))
@@ -85,16 +85,17 @@ static void update_process_glyph(rdpContext* context, const BYTE* data,
        }
 }
 
-static BOOL update_process_glyph_fragments(rdpContext* context, const BYTE* data,
-                                       UINT32 length, UINT32 cacheId,
-                                       UINT32 ulCharInc, UINT32 flAccel,
-                                       UINT32 bgcolor, UINT32 fgcolor,
-                                       UINT32 x, UINT32 y,
-                                       UINT32 bkX, UINT32 bkY,
-                                       UINT32 bkWidth, UINT32 bkHeight,
-                                       UINT32 opX, UINT32 opY,
-                                          UINT32 opWidth, UINT32 opHeight,
-                                       BOOL fOpRedundant)
+static BOOL update_process_glyph_fragments(rdpContext* context,
+        const BYTE* data,
+        UINT32 length, UINT32 cacheId,
+        UINT32 ulCharInc, UINT32 flAccel,
+        UINT32 bgcolor, UINT32 fgcolor,
+        UINT32 x, UINT32 y,
+        UINT32 bkX, UINT32 bkY,
+        UINT32 bkWidth, UINT32 bkHeight,
+        UINT32 opX, UINT32 opY,
+        UINT32 opWidth, UINT32 opHeight,
+        BOOL fOpRedundant)
 {
        UINT32 n;
        UINT32 id;
@@ -103,7 +104,6 @@ static BOOL update_process_glyph_fragments(rdpContext* context, const BYTE* data
        BYTE* fragments;
        rdpGraphics* graphics;
        rdpGlyphCache* glyph_cache;
-
        graphics = context->graphics;
        glyph_cache = context->cache->glyph;
 
@@ -123,14 +123,16 @@ static BOOL update_process_glyph_fragments(rdpContext* context, const BYTE* data
 
        if (opWidth > 0 && opHeight > 0)
        {
-               if (!Glyph_BeginDraw(context, opX, opY, opWidth, opHeight, bgcolor, fgcolor, fOpRedundant))
+               if (!Glyph_BeginDraw(context, opX, opY, opWidth, opHeight, bgcolor, fgcolor,
+                                    fOpRedundant))
                        return FALSE;
        }
        else
        {
                if (fOpRedundant)
                {
-                       if (!Glyph_BeginDraw(context, bkX, bkY, bkWidth, bkHeight, bgcolor, fgcolor, fOpRedundant))
+                       if (!Glyph_BeginDraw(context, bkX, bkY, bkWidth, bkHeight, bgcolor, fgcolor,
+                                            fOpRedundant))
                                return FALSE;
                }
                else
@@ -145,7 +147,6 @@ static BOOL update_process_glyph_fragments(rdpContext* context, const BYTE* data
                switch (data[index])
                {
                        case GLYPH_FRAGMENT_USE:
-
                                if (index + 2 > (int) length)
                                {
                                        /* at least one byte need to follow */
@@ -160,7 +161,8 @@ static BOOL update_process_glyph_fragments(rdpContext* context, const BYTE* data
                                {
                                        for (n = 0; n < (int) size; n++)
                                        {
-                                               update_process_glyph(context, fragments, &n, &x, &y, cacheId, ulCharInc, flAccel);
+                                               update_process_glyph(context, fragments, &n, &x, &y, cacheId, ulCharInc,
+                                                                    flAccel);
                                        }
 
                                        /* Contrary to glyphs, the offset is added after the fragment. */
@@ -177,11 +179,9 @@ static BOOL update_process_glyph_fragments(rdpContext* context, const BYTE* data
                                length -= index;
                                data = &(data[index]);
                                index = 0;
-
                                break;
 
                        case GLYPH_FRAGMENT_ADD:
-
                                if (index + 3 > (int) length)
                                {
                                        /* at least two bytes need to follow */
@@ -191,23 +191,22 @@ static BOOL update_process_glyph_fragments(rdpContext* context, const BYTE* data
 
                                id = data[index + 1];
                                size = data[index + 2];
-
                                fragments = (BYTE*) malloc(size);
+
                                if (!fragments)
                                        return FALSE;
-                               CopyMemory(fragments, data, size);
 
+                               CopyMemory(fragments, data, size);
                                glyph_cache_fragment_put(glyph_cache, id, size, fragments);
-
                                index += 3;
                                length -= index;
                                data = &(data[index]);
                                index = 0;
-
                                break;
 
                        default:
-                               update_process_glyph(context, data, &index, &x, &y, cacheId, ulCharInc, flAccel);
+                               update_process_glyph(context, data, &index, &x, &y, cacheId, ulCharInc,
+                                                    flAccel);
                                index++;
                                break;
                }
@@ -220,36 +219,32 @@ static BOOL update_process_glyph_fragments(rdpContext* context, const BYTE* data
 }
 
 static BOOL update_gdi_glyph_index(rdpContext* context,
-                                  GLYPH_INDEX_ORDER* glyphIndex)
+                                   GLYPH_INDEX_ORDER* glyphIndex)
 {
        rdpGlyphCache* glyph_cache;
        int bkWidth, bkHeight, opWidth, opHeight;
-
        glyph_cache = context->cache->glyph;
-
        bkWidth = glyphIndex->bkRight - glyphIndex->bkLeft;
        opWidth = glyphIndex->opRight - glyphIndex->opLeft;
        bkHeight = glyphIndex->bkBottom - glyphIndex->bkTop;
        opHeight = glyphIndex->opBottom - glyphIndex->opTop;
-
-       return update_process_glyph_fragments(context, glyphIndex->data, glyphIndex->cbData,
-                       glyphIndex->cacheId, glyphIndex->ulCharInc, glyphIndex->flAccel,
-                       glyphIndex->backColor, glyphIndex->foreColor, glyphIndex->x, glyphIndex->y,
-                       glyphIndex->bkLeft, glyphIndex->bkTop, bkWidth, bkHeight,
-                       glyphIndex->opLeft, glyphIndex->opTop, opWidth, opHeight,
-                       glyphIndex->fOpRedundant);
+       return update_process_glyph_fragments(context, glyphIndex->data,
+                                             glyphIndex->cbData,
+                                             glyphIndex->cacheId, glyphIndex->ulCharInc, glyphIndex->flAccel,
+                                             glyphIndex->backColor, glyphIndex->foreColor, glyphIndex->x, glyphIndex->y,
+                                             glyphIndex->bkLeft, glyphIndex->bkTop, bkWidth, bkHeight,
+                                             glyphIndex->opLeft, glyphIndex->opTop, opWidth, opHeight,
+                                             glyphIndex->fOpRedundant);
 }
 
 static BOOL update_gdi_fast_index(rdpContext* context,
-                                 const FAST_INDEX_ORDER* fastIndex)
+                                  const FAST_INDEX_ORDER* fastIndex)
 {
        INT32 x, y;
        INT32 opLeft, opTop;
        INT32 opRight, opBottom;
        rdpGlyphCache* glyph_cache;
-
        glyph_cache = context->cache->glyph;
-
        opLeft = fastIndex->opLeft;
        opTop = fastIndex->opTop;
        opRight = fastIndex->opRight;
@@ -259,14 +254,17 @@ static BOOL update_gdi_fast_index(rdpContext* context,
 
        if (opBottom == -32768)
        {
-               BYTE flags = (BYTE) (opTop & 0x0F);
+               BYTE flags = (BYTE)(opTop & 0x0F);
 
                if (flags & 0x01)
                        opBottom = fastIndex->bkBottom;
+
                if (flags & 0x02)
                        opRight = fastIndex->bkRight;
+
                if (flags & 0x04)
                        opTop = fastIndex->bkTop;
+
                if (flags & 0x08)
                        opLeft = fastIndex->bkLeft;
        }
@@ -289,18 +287,19 @@ static BOOL update_gdi_fast_index(rdpContext* context,
        if (y == -32768)
                y = fastIndex->bkTop;
 
-       return update_process_glyph_fragments(context, fastIndex->data, fastIndex->cbData,
-                       fastIndex->cacheId, fastIndex->ulCharInc, fastIndex->flAccel,
-                       fastIndex->backColor, fastIndex->foreColor, x, y,
-                       fastIndex->bkLeft, fastIndex->bkTop,
-                       fastIndex->bkRight - fastIndex->bkLeft, fastIndex->bkBottom - fastIndex->bkTop,
-                       opLeft, opTop,
-                       opRight - opLeft, opBottom - opTop,
-                       FALSE);
+       return update_process_glyph_fragments(context, fastIndex->data,
+                                             fastIndex->cbData,
+                                             fastIndex->cacheId, fastIndex->ulCharInc, fastIndex->flAccel,
+                                             fastIndex->backColor, fastIndex->foreColor, x, y,
+                                             fastIndex->bkLeft, fastIndex->bkTop,
+                                             fastIndex->bkRight - fastIndex->bkLeft, fastIndex->bkBottom - fastIndex->bkTop,
+                                             opLeft, opTop,
+                                             opRight - opLeft, opBottom - opTop,
+                                             FALSE);
 }
 
 static BOOL update_gdi_fast_glyph(rdpContext* context,
-                                 const FAST_GLYPH_ORDER* fastGlyph)
+                                  const FAST_GLYPH_ORDER* fastGlyph)
 {
        INT32 x, y;
        rdpGlyph* glyph;
@@ -309,7 +308,6 @@ static BOOL update_gdi_fast_glyph(rdpContext* context,
        INT32 opRight, opBottom;
        const GLYPH_DATA_V2* glyphData;
        rdpCache* cache = context->cache;
-
        opLeft = fastGlyph->opLeft;
        opTop = fastGlyph->opTop;
        opRight = fastGlyph->opRight;
@@ -319,14 +317,17 @@ static BOOL update_gdi_fast_glyph(rdpContext* context,
 
        if (opBottom == -32768)
        {
-               BYTE flags = (BYTE) (opTop & 0x0F);
+               BYTE flags = (BYTE)(opTop & 0x0F);
 
                if (flags & 0x01)
                        opBottom = fastGlyph->bkBottom;
+
                if (flags & 0x02)
                        opRight = fastGlyph->bkRight;
+
                if (flags & 0x04)
                        opTop = fastGlyph->bkTop;
+
                if (flags & 0x08)
                        opLeft = fastGlyph->bkLeft;
        }
@@ -351,18 +352,21 @@ static BOOL update_gdi_fast_glyph(rdpContext* context,
        {
                /* got option font that needs to go into cache */
                glyphData = &fastGlyph->glyphData;
-
                glyph = Glyph_Alloc(context);
+
                if (!glyph)
                        return FALSE;
+
                glyph->x = glyphData->x;
                glyph->y = glyphData->y;
                glyph->cx = glyphData->cx;
                glyph->cy = glyphData->cy;
                glyph->cb = glyphData->cb;
                glyph->aj = malloc(glyphData->cb);
+
                if (!glyph->aj)
                        goto error_aj;
+
                CopyMemory(glyph->aj, glyphData->aj, glyph->cb);
 
                if (!Glyph_New(context, glyph))
@@ -373,16 +377,14 @@ static BOOL update_gdi_fast_glyph(rdpContext* context,
 
        text_data[0] = fastGlyph->data[0];
        text_data[1] = 0;
-
        return update_process_glyph_fragments(context, text_data, 1,
-                       fastGlyph->cacheId, fastGlyph->ulCharInc, fastGlyph->flAccel,
-                       fastGlyph->backColor, fastGlyph->foreColor, x, y,
-                       fastGlyph->bkLeft, fastGlyph->bkTop,
-                       fastGlyph->bkRight - fastGlyph->bkLeft, fastGlyph->bkBottom - fastGlyph->bkTop,
-                       opLeft, opTop,
-                       opRight - opLeft, opBottom - opTop,
-                       FALSE);
-
+                                             fastGlyph->cacheId, fastGlyph->ulCharInc, fastGlyph->flAccel,
+                                             fastGlyph->backColor, fastGlyph->foreColor, x, y,
+                                             fastGlyph->bkLeft, fastGlyph->bkTop,
+                                             fastGlyph->bkRight - fastGlyph->bkLeft, fastGlyph->bkBottom - fastGlyph->bkTop,
+                                             opLeft, opTop,
+                                             opRight - opLeft, opBottom - opTop,
+                                             FALSE);
 error_glyph_new:
        free(glyph->aj);
        glyph->aj = NULL;
@@ -392,7 +394,7 @@ error_aj:
 }
 
 static BOOL update_gdi_cache_glyph(rdpContext* context,
-                                  const CACHE_GLYPH_ORDER* cacheGlyph)
+                                   const CACHE_GLYPH_ORDER* cacheGlyph)
 {
        UINT32 i;
        rdpGlyph* glyph;
@@ -402,8 +404,8 @@ static BOOL update_gdi_cache_glyph(rdpContext* context,
        for (i = 0; i < cacheGlyph->cGlyphs; i++)
        {
                glyph_data = &cacheGlyph->glyphData[i];
-
                glyph = Glyph_Alloc(context);
+
                if (!glyph)
                        return FALSE;
 
@@ -413,19 +415,22 @@ static BOOL update_gdi_cache_glyph(rdpContext* context,
                glyph->cy = glyph_data->cy;
                glyph->cb = glyph_data->cb;
                glyph->aj = glyph_data->aj;
+
                if (!Glyph_New(context, glyph))
                {
                        Glyph_Free(context, glyph);
                        return FALSE;
                }
 
-               glyph_cache_put(cache->glyph, cacheGlyph->cacheId, glyph_data->cacheIndex, glyph);
+               glyph_cache_put(cache->glyph, cacheGlyph->cacheId, glyph_data->cacheIndex,
+                               glyph);
        }
+
        return TRUE;
 }
 
 static BOOL update_gdi_cache_glyph_v2(rdpContext* context,
-                                         const CACHE_GLYPH_V2_ORDER* cacheGlyphV2)
+                                      const CACHE_GLYPH_V2_ORDER* cacheGlyphV2)
 {
        UINT32 i;
        rdpGlyph* glyph;
@@ -435,8 +440,8 @@ static BOOL update_gdi_cache_glyph_v2(rdpContext* context,
        for (i = 0; i < cacheGlyphV2->cGlyphs; i++)
        {
                glyphData = &cacheGlyphV2->glyphData[i];
-
                glyph = Glyph_Alloc(context);
+
                if (!glyph)
                {
                        /* TODO: cleanup perviosly allocated glyph memory in error case */
@@ -450,16 +455,16 @@ static BOOL update_gdi_cache_glyph_v2(rdpContext* context,
                glyph->cb = glyphData->cb;
                glyph->aj = glyphData->aj;
                Glyph_New(context, glyph);
-
-               glyph_cache_put(cache->glyph, cacheGlyphV2->cacheId, glyphData->cacheIndex, glyph);
+               glyph_cache_put(cache->glyph, cacheGlyphV2->cacheId, glyphData->cacheIndex,
+                               glyph);
        }
+
        return TRUE;
 }
 
 rdpGlyph* glyph_cache_get(rdpGlyphCache* glyphCache, UINT32 id, UINT32 index)
 {
        rdpGlyph* glyph;
-
        WLog_DBG(TAG, "GlyphCacheGet: id: %d index: %d", id, index);
 
        if (id > 9)
@@ -482,7 +487,8 @@ rdpGlyph* glyph_cache_get(rdpGlyphCache* glyphCache, UINT32 id, UINT32 index)
        return glyph;
 }
 
-void glyph_cache_put(rdpGlyphCache* glyphCache, UINT32 id, UINT32 index, rdpGlyph* glyph)
+void glyph_cache_put(rdpGlyphCache* glyphCache, UINT32 id, UINT32 index,
+                     rdpGlyph* glyph)
 {
        rdpGlyph* prevGlyph;
 
@@ -499,7 +505,6 @@ void glyph_cache_put(rdpGlyphCache* glyphCache, UINT32 id, UINT32 index, rdpGlyp
        }
 
        WLog_DBG(TAG, "GlyphCachePut: id: %d index: %d", id, index);
-
        prevGlyph = glyphCache->glyphCache[id].entries[index];
 
        if (prevGlyph)
@@ -512,7 +517,8 @@ void glyph_cache_put(rdpGlyphCache* glyphCache, UINT32 id, UINT32 index, rdpGlyp
        glyphCache->glyphCache[id].entries[index] = glyph;
 }
 
-void* glyph_cache_fragment_get(rdpGlyphCache* glyphCache, UINT32 index, UINT32* size)
+void* glyph_cache_fragment_get(rdpGlyphCache* glyphCache, UINT32 index,
+                               UINT32* size)
 {
        void* fragment;
 
@@ -524,7 +530,6 @@ void* glyph_cache_fragment_get(rdpGlyphCache* glyphCache, UINT32 index, UINT32*
 
        fragment = glyphCache->fragCache.entries[index].fragment;
        *size = (BYTE) glyphCache->fragCache.entries[index].size;
-
        WLog_DBG(TAG, "GlyphCacheFragmentGet: index: %d size: %d", index, *size);
 
        if (!fragment)
@@ -533,7 +538,8 @@ void* glyph_cache_fragment_get(rdpGlyphCache* glyphCache, UINT32 index, UINT32*
        return fragment;
 }
 
-void glyph_cache_fragment_put(rdpGlyphCache* glyphCache, UINT32 index, UINT32 size, void* fragment)
+void glyph_cache_fragment_put(rdpGlyphCache* glyphCache, UINT32 index,
+                              UINT32 size, void* fragment)
 {
        void* prevFragment;
 
@@ -544,12 +550,9 @@ void glyph_cache_fragment_put(rdpGlyphCache* glyphCache, UINT32 index, UINT32 si
        }
 
        WLog_DBG(TAG, "GlyphCacheFragmentPut: index: %d size: %d", index, size);
-
        prevFragment = glyphCache->fragCache.entries[index].fragment;
-
        glyphCache->fragCache.entries[index].fragment = fragment;
        glyphCache->fragCache.entries[index].size = size;
-
        free(prevFragment);
 }
 
@@ -565,24 +568,23 @@ void glyph_cache_register_callbacks(rdpUpdate* update)
 rdpGlyphCache* glyph_cache_new(rdpSettings* settings)
 {
        rdpGlyphCache* glyphCache;
-
        glyphCache = (rdpGlyphCache*) calloc(1, sizeof(rdpGlyphCache));
 
        if (glyphCache)
        {
                int i;
-
                WLog_Init();
                glyphCache->log = WLog_Get("com.freerdp.cache.glyph");
-
                glyphCache->settings = settings;
                glyphCache->context = ((freerdp*) settings->instance)->update->context;
 
                for (i = 0; i < 10; i++)
                {
                        glyphCache->glyphCache[i].number = settings->GlyphCache[i].cacheEntries;
-                       glyphCache->glyphCache[i].maxCellSize = settings->GlyphCache[i].cacheMaximumCellSize;
-                       glyphCache->glyphCache[i].entries = (rdpGlyph**) calloc(glyphCache->glyphCache[i].number, sizeof(rdpGlyph*));
+                       glyphCache->glyphCache[i].maxCellSize =
+                           settings->GlyphCache[i].cacheMaximumCellSize;
+                       glyphCache->glyphCache[i].entries = (rdpGlyph**) calloc(
+                                                               glyphCache->glyphCache[i].number, sizeof(rdpGlyph*));
                }
 
                glyphCache->fragCache.entries = calloc(256, sizeof(FRAGMENT_CACHE_ENTRY));
@@ -604,7 +606,6 @@ void glyph_cache_free(rdpGlyphCache* glyphCache)
                        for (j = 0; j < (int) glyphCache->glyphCache[i].number; j++)
                        {
                                rdpGlyph* glyph;
-
                                glyph = glyphCache->glyphCache[i].entries[j];
 
                                if (glyph)
@@ -615,6 +616,7 @@ void glyph_cache_free(rdpGlyphCache* glyphCache)
                                        glyphCache->glyphCache[i].entries[j] = NULL;
                                }
                        }
+
                        free(glyphCache->glyphCache[i].entries);
                        glyphCache->glyphCache[i].entries = NULL;
                }
index e9efbe0..584f9c3 100644 (file)
@@ -76,11 +76,11 @@ BYTE* freerdp_glyph_convert(UINT32 width, UINT32 height, const BYTE* data)
 }
 
 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 nDstStep, UINT32 nXDst, UINT32 nYDst,
+                                        UINT32 nWidth, UINT32 nHeight,
+                                        const BYTE* pSrcData,
+                                        UINT32 backColor, UINT32 foreColor,
+                                        const gdiPalette* palette)
 {
        UINT32 x, y;
        BOOL vFlip;
@@ -161,11 +161,11 @@ static INLINE UINT32 freerdp_image_inverted_pointer_color(UINT32 x, UINT32 y)
  */
 
 BOOL freerdp_image_copy_from_pointer_data(
-       BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep,
-       UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight,
-       const BYTE* xorMask, UINT32 xorMaskLength,
-       const BYTE* andMask, UINT32 andMaskLength,
-       UINT32 xorBpp, const gdiPalette* palette)
+    BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep,
+    UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight,
+    const BYTE* xorMask, UINT32 xorMaskLength,
+    const BYTE* andMask, UINT32 andMaskLength,
+    UINT32 xorBpp, const gdiPalette* palette)
 {
        UINT32 x, y;
        BOOL vFlip;
@@ -220,7 +220,7 @@ BOOL freerdp_image_copy_from_pointer_data(
                for (y = 0; y < nHeight; y++)
                {
                        BYTE* pDstPixel = &pDstData[((nYDst + y) * nDstStep) +
-                                                       (nXDst * GetBytesPerPixel(DstFormat))];
+                                                   (nXDst * GetBytesPerPixel(DstFormat))];
                        xorBit = andBit = 0x80;
 
                        if (!vFlip)
@@ -263,7 +263,7 @@ BOOL freerdp_image_copy_from_pointer_data(
                                        color = freerdp_image_inverted_pointer_color(x, y); /* inverted */
 
                                color = ConvertColor(color, PIXEL_FORMAT_ABGR32,
-                                                        DstFormat, palette);
+                                                    DstFormat, palette);
                                WriteColor(pDstPixel, DstFormat, color);
                                pDstPixel += GetBytesPerPixel(DstFormat);
                        }
@@ -279,7 +279,7 @@ BOOL freerdp_image_copy_from_pointer_data(
                if (xorBpp == 8 && !palette)
                {
                        WLog_ERR(TAG, "null palette in convertion from %d bpp to %d bpp",
-                                xorBpp, dstBitsPerPixel);
+                                xorBpp, dstBitsPerPixel);
                        return -1;
                }
 
@@ -295,7 +295,7 @@ BOOL freerdp_image_copy_from_pointer_data(
                for (y = 0; y < nHeight; y++)
                {
                        BYTE* pDstPixel = &pDstData[((nYDst + y) * nDstStep) +
-                                                       (nXDst * GetBytesPerPixel(DstFormat))];
+                                                   (nXDst * GetBytesPerPixel(DstFormat))];
                        andBit = 0x80;
 
                        if (!vFlip)
@@ -328,9 +328,9 @@ BOOL freerdp_image_copy_from_pointer_data(
                                else if (xorBpp == 16)
                                {
                                        xorPixel = ConvertColor(*(UINT16*)xorBits,
-                                                               PIXEL_FORMAT_RGB16,
-                                                               PIXEL_FORMAT_ARGB32,
-                                                               palette);
+                                                               PIXEL_FORMAT_RGB16,
+                                                               PIXEL_FORMAT_ARGB32,
+                                                               palette);
                                }
                                else if (xorBpp == 8)
                                {
@@ -368,12 +368,12 @@ BOOL freerdp_image_copy_from_pointer_data(
                                                color = xorPixel;
 
                                        color = ConvertColor(color, PIXEL_FORMAT_ARGB32, DstFormat,
-                                                                                palette);
+                                                            palette);
                                }
                                else
                                {
                                        color = ConvertColor(xorPixel, PIXEL_FORMAT_ARGB32,
-                                                                DstFormat, palette);
+                                                            DstFormat, palette);
                                }
 
                                WriteColor(pDstPixel, DstFormat, color);
@@ -385,17 +385,36 @@ BOOL freerdp_image_copy_from_pointer_data(
        }
 
        WLog_ERR(TAG, "failed to convert from %d bpp to %d bpp",
-                xorBpp, dstBitsPerPixel);
+                xorBpp, dstBitsPerPixel);
        return -1;
 }
 
+static BOOL overlapping(const BYTE* pDstData, UINT32 nXDst, UINT32 nYDst,
+                        UINT32 nDstStep, UINT32 dstBytesPerPixel,
+                        const BYTE* pSrcData, UINT32 nXSrc, UINT32 nYSrc,
+                        UINT32 nSrcStep, UINT32 srcBytesPerPixel,
+                        UINT32 nWidth, UINT32 nHeight)
+{
+       const BYTE* pDstStart = &pDstData[nXDst * dstBytesPerPixel + nYDst * nDstStep];
+       const BYTE* pDstEnd = pDstStart + nHeight * nDstStep;
+       const BYTE* pSrcStart = &pSrcData[nXSrc * srcBytesPerPixel + nYSrc * nSrcStep];
+       const BYTE* pSrcEnd = pSrcStart + nHeight * nSrcStep;
+
+       if ((pDstStart >= pSrcStart) && (pDstStart <= pSrcEnd))
+               return TRUE;
+
+       if ((pDstEnd >= pSrcStart) && (pDstEnd <= pSrcEnd))
+               return TRUE;
+
+       return FALSE;
+}
 
 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)
 {
        const UINT32 dstByte = GetBytesPerPixel(DstFormat);
        const UINT32 srcByte = GetBytesPerPixel(SrcFormat);
@@ -465,45 +484,45 @@ BOOL freerdp_image_copy(BYTE* pDstData, DWORD DstFormat,
        if (vSrcHFlip || vDstHFlip)
        {
                WLog_ERR(TAG, "Horizontal flipping not supported! %s %s",
-                        GetColorFormatName(SrcFormat), GetColorFormatName(DstFormat));
+                        GetColorFormatName(SrcFormat), GetColorFormatName(DstFormat));
                return FALSE;
        }
 
        if (FREERDP_PIXEL_FORMAT_FLIP_MASKED(SrcFormat) ==
-               FREERDP_PIXEL_FORMAT_FLIP_MASKED(DstFormat))
+           FREERDP_PIXEL_FORMAT_FLIP_MASKED(DstFormat))
        {
                INT32 y;
 
-               if (pDstData == pSrcData)
+               if (overlapping(pDstData, nXDst, nYDst, nDstStep, dstByte,
+                               pSrcData, nXSrc, nYSrc, nSrcStep, srcByte,
+                               nWidth, nHeight))
                {
                        /* Copy down */
-                       if (nYDst > nYSrc)
+                       if (nYDst < nYSrc)
                        {
                                for (y = 0; y < nHeight; y++)
                                {
                                        const BYTE* srcLine = &pSrcData[(y + nYSrc) *
-                                                             nSrcStep * srcVMultiplier +
-                                                             srcVOffset];
+                                                                       nSrcStep * srcVMultiplier +
+                                                                       srcVOffset];
                                        BYTE* dstLine = &pDstData[(y + nYDst) *
-                                                       nDstStep * dstVMultiplier +
-                                                       dstVOffset];
-
+                                                                 nDstStep * dstVMultiplier +
+                                                                 dstVOffset];
                                        memcpy(&dstLine[xDstOffset],
                                               &srcLine[xSrcOffset], copyDstWidth);
                                }
                        }
                        /* Copy up */
-                       else if (nYDst < nYSrc)
+                       else if (nYDst > nYSrc)
                        {
                                for (y = nHeight - 1; y >= 0; y--)
                                {
                                        const BYTE* srcLine = &pSrcData[(y + nYSrc) *
-                                                             nSrcStep * srcVMultiplier +
-                                                             srcVOffset];
+                                                                       nSrcStep * srcVMultiplier +
+                                                                       srcVOffset];
                                        BYTE* dstLine = &pDstData[(y + nYDst) *
-                                                       nDstStep * dstVMultiplier +
-                                                       dstVOffset];
-
+                                                                 nDstStep * dstVMultiplier +
+                                                                 dstVOffset];
                                        memcpy(&dstLine[xDstOffset],
                                               &srcLine[xSrcOffset], copyDstWidth);
                                }
@@ -514,14 +533,13 @@ BOOL freerdp_image_copy(BYTE* pDstData, DWORD DstFormat,
                                for (y = 0; y < nHeight; y++)
                                {
                                        const BYTE* srcLine = &pSrcData[(y + nYSrc) *
-                                                             nSrcStep * srcVMultiplier +
-                                                             srcVOffset];
+                                                                       nSrcStep * srcVMultiplier +
+                                                                       srcVOffset];
                                        BYTE* dstLine = &pDstData[(y + nYDst) *
-                                                       nDstStep * dstVMultiplier +
-                                                       dstVOffset];
-
+                                                                 nDstStep * dstVMultiplier +
+                                                                 dstVOffset];
                                        memmove(&dstLine[xDstOffset],
-                                              &srcLine[xSrcOffset], copyDstWidth);
+                                               &srcLine[xSrcOffset], copyDstWidth);
                                }
                        }
                        /* Copy right */
@@ -530,33 +548,30 @@ BOOL freerdp_image_copy(BYTE* pDstData, DWORD DstFormat,
                                for (y = nHeight - 1; y >= 0; y--)
                                {
                                        const BYTE* srcLine = &pSrcData[(y + nYSrc) *
-                                                             nSrcStep * srcVMultiplier +
-                                                             srcVOffset];
+                                                                       nSrcStep * srcVMultiplier +
+                                                                       srcVOffset];
                                        BYTE* dstLine = &pDstData[(y + nYDst) *
-                                                       nDstStep * dstVMultiplier +
-                                                       dstVOffset];
-
-                                       memove(&dstLine[xDstOffset],
-                                              &srcLine[xSrcOffset], copyDstWidth);
+                                                                 nDstStep * dstVMultiplier +
+                                                                 dstVOffset];
+                                       memmove(&dstLine[xDstOffset],
+                                               &srcLine[xSrcOffset], copyDstWidth);
                                }
                        }
                        /* Source and destination are equal... */
                        else
                        {
-
                        }
                }
-               else if (nYDst < nYSrc)
+               else
                {
                        for (y = 0; y < nHeight; y++)
                        {
                                const BYTE* srcLine = &pSrcData[(y + nYSrc) *
-                                                     nSrcStep * srcVMultiplier +
-                                                     srcVOffset];
+                                                               nSrcStep * srcVMultiplier +
+                                                               srcVOffset];
                                BYTE* dstLine = &pDstData[(y + nYDst) *
-                                               nDstStep * dstVMultiplier +
-                                               dstVOffset];
-
+                                                         nDstStep * dstVMultiplier +
+                                                         dstVOffset];
                                memcpy(&dstLine[xDstOffset],
                                       &srcLine[xSrcOffset], copyDstWidth);
                        }
@@ -569,16 +584,16 @@ BOOL freerdp_image_copy(BYTE* pDstData, DWORD DstFormat,
                for (y = 0; y < nHeight; y++)
                {
                        const BYTE* srcLine = &pSrcData[(y + nYSrc) *
-                                             nSrcStep * srcVMultiplier +
-                                             srcVOffset];
+                                                       nSrcStep * srcVMultiplier +
+                                                       srcVOffset];
                        BYTE* dstLine = &pDstData[(y + nYDst) *
-                                       nDstStep * dstVMultiplier + dstVOffset];
+                                                 nDstStep * dstVMultiplier + dstVOffset];
 
                        for (x = 0; x < nWidth; x++)
                        {
                                UINT32 dstColor;
                                UINT32 color = ReadColor(&srcLine[(x + nXSrc) * srcByte],
-                                                        SrcFormat);
+                                                        SrcFormat);
                                dstColor = ConvertColor(color, SrcFormat, DstFormat, palette);
                                WriteColor(&dstLine[(x + nXDst) * dstByte], DstFormat, dstColor);
                        }
@@ -589,8 +604,8 @@ BOOL freerdp_image_copy(BYTE* pDstData, DWORD DstFormat,
 }
 
 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)
 {
        UINT32 x, y;
 
index 7c491ad..cdff589 100644 (file)
@@ -34,7 +34,7 @@
 #define TAG FREERDP_TAG("codec")
 
 static int planar_skip_plane_rle(const BYTE* pSrcData, UINT32 SrcSize,
-                                int nWidth, int nHeight)
+                                 int nWidth, int nHeight)
 {
        int x, y;
        int cRawBytes;
@@ -83,10 +83,10 @@ static int planar_skip_plane_rle(const BYTE* pSrcData, UINT32 SrcSize,
 }
 
 static int planar_decompress_plane_rle(const BYTE* pSrcData, UINT32 SrcSize,
-                                          BYTE* pDstData, INT32 nDstStep,
-                                          UINT32 nXDst, UINT32 nYDst,
-                                          UINT32 nWidth, UINT32 nHeight,
-                                          UINT32 nChannel, BOOL vFlip)
+                                       BYTE* pDstData, INT32 nDstStep,
+                                       UINT32 nXDst, UINT32 nYDst,
+                                       UINT32 nWidth, UINT32 nHeight,
+                                       UINT32 nChannel, BOOL vFlip)
 {
        UINT32 x, y;
        BYTE* dstp;
@@ -218,9 +218,9 @@ static int planar_decompress_plane_rle(const BYTE* pSrcData, UINT32 SrcSize,
 }
 
 static BOOL planar_decompress_planes_raw(const BYTE* pSrcData[4],
-       BYTE* pDstData, UINT32 DstFormat,
-       UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight,
-       BOOL alpha, BOOL vFlip)
+        BYTE* pDstData, UINT32 DstFormat,
+        UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight,
+        BOOL alpha, BOOL vFlip)
 {
        INT32 x, y;
        INT32 beg, end, inc;
@@ -247,7 +247,7 @@ static BOOL planar_decompress_planes_raw(const BYTE* pSrcData[4],
                for (y = beg; y != end; y += inc)
                {
                        BYTE* pRGB = &pDstData[((nYDst + y) * nDstStep) + (nXDst * GetBytesPerPixel(
-                                                  DstFormat))];
+                                                  DstFormat))];
 
                        for (x = 0; x < nWidth; x++)
                        {
@@ -262,7 +262,7 @@ static BOOL planar_decompress_planes_raw(const BYTE* pSrcData[4],
                for (y = beg; y != end; y += inc)
                {
                        BYTE* pRGB = &pDstData[((nYDst + y) * nDstStep) + (nXDst * GetBytesPerPixel(
-                                                  DstFormat))];
+                                                  DstFormat))];
 
                        for (x = 0; x < nWidth; x++)
                        {
@@ -277,10 +277,10 @@ static BOOL planar_decompress_planes_raw(const BYTE* pSrcData[4],
 }
 
 INT32 planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
-                       const BYTE* pSrcData, UINT32 SrcSize,
-                       BYTE* pDstData, UINT32 DstFormat,
-                       UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
-                       UINT32 nWidth, UINT32 nHeight, BOOL vFlip)
+                        const BYTE* pSrcData, UINT32 SrcSize,
+                        BYTE* pDstData, UINT32 DstFormat,
+                        UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
+                        UINT32 nWidth, UINT32 nHeight, BOOL vFlip)
 {
        BOOL cs;
        BOOL rle;
@@ -399,28 +399,28 @@ INT32 planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
                {
                        planes[3] = srcp;
                        rleSizes[3] = planar_skip_plane_rle(planes[3], SrcSize - (planes[3] - pSrcData),
-                                                               rawWidths[3], rawHeights[3]); /* AlphaPlane */
+                                                           rawWidths[3], rawHeights[3]); /* AlphaPlane */
 
                        if (rleSizes[3] < 0)
                                return -1;
 
                        planes[0] = planes[3] + rleSizes[3];
                        rleSizes[0] = planar_skip_plane_rle(planes[0], SrcSize - (planes[0] - pSrcData),
-                                                               rawWidths[0], rawHeights[0]); /* RedPlane */
+                                                           rawWidths[0], rawHeights[0]); /* RedPlane */
 
                        if (rleSizes[0] < 0)
                                return -1;
 
                        planes[1] = planes[0] + rleSizes[0];
                        rleSizes[1] = planar_skip_plane_rle(planes[1], SrcSize - (planes[1] - pSrcData),
-                                                               rawWidths[1], rawHeights[1]); /* GreenPlane */
+                                                           rawWidths[1], rawHeights[1]); /* GreenPlane */
 
                        if (rleSizes[1] < 1)
                                return -1;
 
                        planes[2] = planes[1] + rleSizes[1];
                        rleSizes[2] = planar_skip_plane_rle(planes[2], SrcSize - (planes[2] - pSrcData),
-                                                               rawWidths[2], rawHeights[2]); /* BluePlane */
+                                                           rawWidths[2], rawHeights[2]); /* BluePlane */
 
                        if (rleSizes[2] < 1)
                                return -1;
@@ -429,21 +429,21 @@ INT32 planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
                {
                        planes[0] = srcp;
                        rleSizes[0] = planar_skip_plane_rle(planes[0], SrcSize - (planes[0] - pSrcData),
-                                                               rawWidths[0], rawHeights[0]); /* RedPlane */
+                                                           rawWidths[0], rawHeights[0]); /* RedPlane */
 
                        if (rleSizes[0] < 0)
                                return -1;
 
                        planes[1] = planes[0] + rleSizes[0];
                        rleSizes[1] = planar_skip_plane_rle(planes[1], SrcSize - (planes[1] - pSrcData),
-                                                               rawWidths[1], rawHeights[1]); /* GreenPlane */
+                                                           rawWidths[1], rawHeights[1]); /* GreenPlane */
 
                        if (rleSizes[1] < 1)
                                return -1;
 
                        planes[2] = planes[1] + rleSizes[1];
                        rleSizes[2] = planar_skip_plane_rle(planes[2], SrcSize - (planes[2] - pSrcData),
-                                                               rawWidths[2], rawHeights[2]); /* BluePlane */
+                                                           rawWidths[2], rawHeights[2]); /* BluePlane */
 
                        if (rleSizes[2] < 1)
                                return -1;
@@ -457,13 +457,13 @@ INT32 planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
                        if (alpha)
                        {
                                planar_decompress_planes_raw(planes, pDstData, DstFormat, nDstStep,
-                                                                nXDst, nYDst, nWidth, nHeight, alpha, vFlip);
+                                                            nXDst, nYDst, nWidth, nHeight, alpha, vFlip);
                                srcp += rawSizes[0] + rawSizes[1] + rawSizes[2] + rawSizes[3];
                        }
                        else /* NoAlpha */
                        {
                                planar_decompress_planes_raw(planes, pDstData, DstFormat, nDstStep,
-                                                                nXDst, nYDst, nWidth, nHeight, alpha, vFlip);
+                                                            nXDst, nYDst, nWidth, nHeight, alpha, vFlip);
                                srcp += rawSizes[0] + rawSizes[1] + rawSizes[2];
                        }
 
@@ -489,38 +489,40 @@ INT32 planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
                        if (alpha)
                        {
                                status = planar_decompress_plane_rle(planes[3], rleSizes[3],
-                                                                        pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 3,
-                                                                        vFlip); /* AlphaPlane */
+                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 3,
+                                                                    vFlip); /* AlphaPlane */
                                status = planar_decompress_plane_rle(planes[0], rleSizes[0],
-                                                                        pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2,
-                                                                        vFlip); /* RedPlane */
+                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2,
+                                                                    vFlip); /* RedPlane */
                                status = planar_decompress_plane_rle(planes[1], rleSizes[1],
-                                                                        pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1,
-                                                                        vFlip); /* GreenPlane */
+                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1,
+                                                                    vFlip); /* GreenPlane */
                                status = planar_decompress_plane_rle(planes[2], rleSizes[2],
-                                                                        pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0,
-                                                                        vFlip); /* BluePlane */
+                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0,
+                                                                    vFlip); /* BluePlane */
                                srcp += rleSizes[0] + rleSizes[1] + rleSizes[2] + rleSizes[3];
                        }
                        else /* NoAlpha */
                        {
                                status = planar_decompress_plane_rle(planes[0], rleSizes[0],
-                                                                        pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2,
-                                                                        vFlip); /* RedPlane */
+                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2,
+                                                                    vFlip); /* RedPlane */
                                status = planar_decompress_plane_rle(planes[1], rleSizes[1],
-                                                                        pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1,
-                                                                        vFlip); /* GreenPlane */
+                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1,
+                                                                    vFlip); /* GreenPlane */
                                status = planar_decompress_plane_rle(planes[2], rleSizes[2],
-                                                                        pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0,
-                                                                        vFlip); /* BluePlane */
+                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0,
+                                                                    vFlip); /* BluePlane */
                                srcp += rleSizes[0] + rleSizes[1] + rleSizes[2];
                        }
 
                        if (pTempData != pDstData)
                        {
-                               freerdp_image_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth, nHeight,
-                                                  pTempData,
-                                                  TempFormat, nTempStep, nXDst, nYDst, NULL);
+                               if (!freerdp_image_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth,
+                                                       nHeight,
+                                                       pTempData,
+                                                       TempFormat, nTempStep, nXDst, nYDst, NULL))
+                                       return -1;
                        }
                }
        }
@@ -544,13 +546,13 @@ INT32 planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
                        if (alpha)
                        {
                                planar_decompress_planes_raw(planes, pTempData, TempFormat, nTempStep,
-                                                                nXDst, nYDst, nWidth, nHeight, alpha, vFlip);
+                                                            nXDst, nYDst, nWidth, nHeight, alpha, vFlip);
                                srcp += rawSizes[0] + rawSizes[1] + rawSizes[2] + rawSizes[3];
                        }
                        else /* NoAlpha */
                        {
                                planar_decompress_planes_raw(planes, pTempData, TempFormat, nTempStep,
-                                                                nXDst, nYDst, nWidth, nHeight, alpha, vFlip);
+                                                            nXDst, nYDst, nWidth, nHeight, alpha, vFlip);
                                srcp += rawSizes[0] + rawSizes[1] + rawSizes[2];
                        }
 
@@ -562,36 +564,36 @@ INT32 planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
                        if (alpha)
                        {
                                status = planar_decompress_plane_rle(planes[3], rleSizes[3],
-                                                                        pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 3,
-                                                                        vFlip); /* AlphaPlane */
+                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 3,
+                                                                    vFlip); /* AlphaPlane */
                                status = planar_decompress_plane_rle(planes[0], rleSizes[0],
-                                                                        pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2,
-                                                                        vFlip); /* LumaPlane */
+                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2,
+                                                                    vFlip); /* LumaPlane */
                                status = planar_decompress_plane_rle(planes[1], rleSizes[1],
-                                                                        pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1,
-                                                                        vFlip); /* OrangeChromaPlane */
+                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1,
+                                                                    vFlip); /* OrangeChromaPlane */
                                status = planar_decompress_plane_rle(planes[2], rleSizes[2],
-                                                                        pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0,
-                                                                        vFlip); /* GreenChromaPlane */
+                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0,
+                                                                    vFlip); /* GreenChromaPlane */
                                srcp += rleSizes[0] + rleSizes[1] + rleSizes[2] + rleSizes[3];
                        }
                        else /* NoAlpha */
                        {
                                status = planar_decompress_plane_rle(planes[0], rleSizes[0],
-                                                                        pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2,
-                                                                        vFlip); /* LumaPlane */
+                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 2,
+                                                                    vFlip); /* LumaPlane */
                                status = planar_decompress_plane_rle(planes[1], rleSizes[1],
-                                                                        pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1,
-                                                                        vFlip); /* OrangeChromaPlane */
+                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 1,
+                                                                    vFlip); /* OrangeChromaPlane */
                                status = planar_decompress_plane_rle(planes[2], rleSizes[2],
-                                                                        pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0,
-                                                                        vFlip); /* GreenChromaPlane */
+                                                                    pTempData, nTempStep, nXDst, nYDst, nWidth, nHeight, 0,
+                                                                    vFlip); /* GreenChromaPlane */
                                srcp += rleSizes[0] + rleSizes[1] + rleSizes[2];
                        }
                }
 
                prims->YCoCgToRGB_8u_AC4R(pTempData, nTempStep, pDstData, DstFormat, nDstStep,
-                                         nWidth, nHeight, cll, alpha);
+                                         nWidth, nHeight, cll, alpha);
        }
 
        status = (SrcSize == (srcp - pSrcData)) ? 1 : -1;
@@ -599,8 +601,8 @@ INT32 planar_decompress(BITMAP_PLANAR_CONTEXT* planar,
 }
 
 static BOOL freerdp_split_color_planes(const BYTE* data, UINT32 format,
-                                          UINT32 width, UINT32 height,
-                                          UINT32 scanline, BYTE** planes)
+                                       UINT32 width, UINT32 height,
+                                       UINT32 scanline, BYTE** planes)
 {
        INT32 i, j, k;
        UINT32* pixel;
@@ -613,7 +615,7 @@ static BOOL freerdp_split_color_planes(const BYTE* data, UINT32 format,
                for (j = 0; j < width; j++)
                {
                        *pixel = GetColor(format, planes[1][k], planes[2][k],
-                                         planes[3][k], planes[0][k]);
+                                         planes[3][k], planes[0][k]);
                        pixel++;
                        k++;
                }
@@ -623,8 +625,8 @@ static BOOL freerdp_split_color_planes(const BYTE* data, UINT32 format,
 }
 
 static UINT32 freerdp_bitmap_planar_write_rle_bytes(
-       const BYTE* pInBuffer, UINT32 cRawBytes, UINT32 nRunLength,
-       BYTE* pOutBuffer, UINT32 outBufferSize)
+    const BYTE* pInBuffer, UINT32 cRawBytes, UINT32 nRunLength,
+    BYTE* pOutBuffer, UINT32 outBufferSize)
 {
        const BYTE* pInput;
        BYTE* pOutput;
@@ -737,9 +739,9 @@ static UINT32 freerdp_bitmap_planar_write_rle_bytes(
 }
 
 static UINT32 freerdp_bitmap_planar_encode_rle_bytes(const BYTE* pInBuffer,
-       UINT32 inBufferSize,
-       BYTE* pOutBuffer,
-       UINT32 outBufferSize)
+        UINT32 inBufferSize,
+        BYTE* pOutBuffer,
+        UINT32 outBufferSize)
 {
        BYTE symbol;
        const BYTE* pInput;
@@ -781,9 +783,9 @@ static UINT32 freerdp_bitmap_planar_encode_rle_bytes(const BYTE* pInBuffer,
                        {
                                pBytes = pInput - (cRawBytes + nRunLength + 1);
                                nBytesWritten = freerdp_bitmap_planar_write_rle_bytes(
-                                                       pBytes, cRawBytes,
-                                                       nRunLength, pOutput,
-                                                       outBufferSize);
+                                                   pBytes, cRawBytes,
+                                                   nRunLength, pOutput,
+                                                   outBufferSize);
                                nRunLength = 0;
 
                                if (!nBytesWritten || (nBytesWritten > outBufferSize))
@@ -805,7 +807,7 @@ static UINT32 freerdp_bitmap_planar_encode_rle_bytes(const BYTE* pInBuffer,
        {
                pBytes = pInput - (cRawBytes + nRunLength);
                nBytesWritten = freerdp_bitmap_planar_write_rle_bytes(pBytes,
-                               cRawBytes, nRunLength, pOutput, outBufferSize);
+                               cRawBytes, nRunLength, pOutput, outBufferSize);
 
                if (!nBytesWritten)
                        return 0;
@@ -820,8 +822,8 @@ static UINT32 freerdp_bitmap_planar_encode_rle_bytes(const BYTE* pInBuffer,
 }
 
 BYTE* freerdp_bitmap_planar_compress_plane_rle(const BYTE* inPlane,
-       UINT32 width, UINT32 height,
-       BYTE* outPlane, UINT32* dstSize)
+        UINT32 width, UINT32 height,
+        BYTE* outPlane, UINT32* dstSize)
 {
        UINT32 index;
        const BYTE* pInput;
@@ -851,7 +853,7 @@ BYTE* freerdp_bitmap_planar_compress_plane_rle(const BYTE* inPlane,
        while (outBufferSize)
        {
                nBytesWritten = freerdp_bitmap_planar_encode_rle_bytes(
-                                       pInput, width, pOutput, outBufferSize);
+                                   pInput, width, pOutput, outBufferSize);
 
                if ((!nBytesWritten) || (nBytesWritten > outBufferSize))
                        return NULL;
@@ -871,8 +873,8 @@ BYTE* freerdp_bitmap_planar_compress_plane_rle(const BYTE* inPlane,
 }
 
 static UINT32 freerdp_bitmap_planar_compress_planes_rle(
-       const BYTE** inPlanes, UINT32 width, UINT32 height,
-       BYTE* outPlanes, UINT32* dstSizes, BOOL skipAlpha)
+    const BYTE** inPlanes, UINT32 width, UINT32 height,
+    BYTE* outPlanes, UINT32* dstSizes, BOOL skipAlpha)
 {
        UINT32 outPlanesSize = width * height * 4;
 
@@ -886,7 +888,7 @@ static UINT32 freerdp_bitmap_planar_compress_planes_rle(
                dstSizes[0] = outPlanesSize;
 
                if (!freerdp_bitmap_planar_compress_plane_rle(
-                       inPlanes[0], width, height, outPlanes, &dstSizes[0]))
+                       inPlanes[0], width, height, outPlanes, &dstSizes[0]))
                        return 0;
 
                outPlanes += dstSizes[0];
@@ -897,7 +899,7 @@ static UINT32 freerdp_bitmap_planar_compress_planes_rle(
        dstSizes[1] = outPlanesSize;
 
        if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[1], width, height,
-               outPlanes, &dstSizes[1]))
+               outPlanes, &dstSizes[1]))
                return 0;
 
        outPlanes += dstSizes[1];
@@ -906,7 +908,7 @@ static UINT32 freerdp_bitmap_planar_compress_planes_rle(
        dstSizes[2] = outPlanesSize;
 
        if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[2], width, height,
-               outPlanes, &dstSizes[2]))
+               outPlanes, &dstSizes[2]))
                return 0;
 
        outPlanes += dstSizes[2];
@@ -915,7 +917,7 @@ static UINT32 freerdp_bitmap_planar_compress_planes_rle(
        dstSizes[3] = outPlanesSize;
 
        if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[3], width, height,
-               outPlanes, &dstSizes[3]))
+               outPlanes, &dstSizes[3]))
                return 0;
 
        outPlanes += dstSizes[3];
@@ -924,8 +926,8 @@ static UINT32 freerdp_bitmap_planar_compress_planes_rle(
 }
 
 BYTE* freerdp_bitmap_planar_delta_encode_plane(const BYTE* inPlane,
-       UINT32 width, UINT32 height,
-       BYTE* outPlane)
+        UINT32 width, UINT32 height,
+        BYTE* outPlane)
 {
        char s2c;
        INT32 delta;
@@ -960,15 +962,15 @@ BYTE* freerdp_bitmap_planar_delta_encode_plane(const BYTE* inPlane,
 }
 
 BOOL freerdp_bitmap_planar_delta_encode_planes(const BYTE** inPlanes,
-       UINT32 width, UINT32 height,
-       BYTE* outPlanes[4])
+        UINT32 width, UINT32 height,
+        BYTE* outPlanes[4])
 {
        UINT32 i;
 
        for (i = 0; i < 4; i++)
        {
                outPlanes[i] = freerdp_bitmap_planar_delta_encode_plane(
-                                  inPlanes[i], width, height, outPlanes[i]);
+                                  inPlanes[i], width, height, outPlanes[i]);
 
                if (!outPlanes[i])
                        return FALSE;
@@ -978,9 +980,9 @@ BOOL freerdp_bitmap_planar_delta_encode_planes(const BYTE** inPlanes,
 }
 
 BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* context,
-                                        const BYTE* data, UINT32 format,
-                                        UINT32 width, UINT32 height, UINT32 scanline,
-                                        BYTE* dstData, UINT32* pDstSize)
+                                     const BYTE* data, UINT32 format,
+                                     UINT32 width, UINT32 height, UINT32 scanline,
+                                     BYTE* dstData, UINT32* pDstSize)
 {
        UINT32 size;
        BYTE* dstp;
@@ -994,20 +996,20 @@ BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* context,
        planeSize = width * height;
 
        if (!freerdp_split_color_planes(data, format, width, height, scanline,
-                                       context->planes))
+                                       context->planes))
                return NULL;
 
        if (context->AllowRunLengthEncoding)
        {
                if (!freerdp_bitmap_planar_delta_encode_planes(
-                       (const BYTE**)context->planes, width, height,
-                       context->deltaPlanes))
+                       (const BYTE**)context->planes, width, height,
+                       context->deltaPlanes))
                        return NULL;;
 
                if (freerdp_bitmap_planar_compress_planes_rle(
-                       (const BYTE**)context->deltaPlanes, width, height,
-                       context->rlePlanesBuffer, dstSizes,
-                       context->AllowSkipAlpha) > 0)
+                       (const BYTE**)context->deltaPlanes, width, height,
+                       context->rlePlanesBuffer, dstSizes,
+                       context->AllowSkipAlpha) > 0)
                {
                        int offset = 0;
                        FormatHeader |= PLANAR_FORMAT_HEADER_RLE;
@@ -1125,7 +1127,7 @@ BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* context,
 }
 
 BOOL freerdp_bitmap_planar_context_reset(
-               BITMAP_PLANAR_CONTEXT* context, UINT32 width, UINT32 height)
+    BITMAP_PLANAR_CONTEXT* context, UINT32 width, UINT32 height)
 {
        if (!context)
                return FALSE;
@@ -1134,36 +1136,32 @@ BOOL freerdp_bitmap_planar_context_reset(
        context->maxHeight = height;
        context->maxPlaneSize = context->maxWidth * context->maxHeight;
        context->nTempStep = context->maxWidth * 4;
-
        context->planesBuffer = malloc(context->maxPlaneSize * 4);
        context->pTempData = malloc(context->maxPlaneSize * 4);
        context->deltaPlanesBuffer = malloc(context->maxPlaneSize * 4);
        context->rlePlanesBuffer = malloc(context->maxPlaneSize * 4);
 
        if (!context->planesBuffer || !context->pTempData ||
-                       !context->deltaPlanesBuffer || !context->rlePlanesBuffer)
+           !context->deltaPlanesBuffer || !context->rlePlanesBuffer)
                return FALSE;
 
        context->planes[0] = &context->planesBuffer[context->maxPlaneSize * 0];
        context->planes[1] = &context->planesBuffer[context->maxPlaneSize * 1];
        context->planes[2] = &context->planesBuffer[context->maxPlaneSize * 2];
        context->planes[3] = &context->planesBuffer[context->maxPlaneSize * 3];
-
-
        context->deltaPlanes[0] = &context->deltaPlanesBuffer[context->maxPlaneSize *
-                                 0];
+                                 0];
        context->deltaPlanes[1] = &context->deltaPlanesBuffer[context->maxPlaneSize *
-                                 1];
+                                 1];
        context->deltaPlanes[2] = &context->deltaPlanesBuffer[context->maxPlaneSize *
-                                 2];
+                                 2];
        context->deltaPlanes[3] = &context->deltaPlanesBuffer[context->maxPlaneSize *
-                                 3];
-
+                                 3];
        return TRUE;
 }
 
 BITMAP_PLANAR_CONTEXT* freerdp_bitmap_planar_context_new(
-       DWORD flags, UINT32 maxWidth, UINT32 maxHeight)
+    DWORD flags, UINT32 maxWidth, UINT32 maxHeight)
 {
        BITMAP_PLANAR_CONTEXT* context;
        context = (BITMAP_PLANAR_CONTEXT*) calloc(1, sizeof(BITMAP_PLANAR_CONTEXT));
index efab10d..809aaa5 100644 (file)
@@ -1555,6 +1555,7 @@ INT32 progressive_decompress(PROGRESSIVE_CONTEXT* progressive,
                              UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
                              UINT32 nWidth, UINT32 nHeight, UINT16 surfaceId)
 {
+       INT32 rc = 1;
        UINT status;
        const BYTE* block;
        const BYTE* blocks;
@@ -1925,16 +1926,21 @@ INT32 progressive_decompress(PROGRESSIVE_CONTEXT* progressive,
                        nHeight = updateRects[j].bottom - updateRects[j].top;
                        nXSrc = updateRects[j].left - (nXDst + tile->x);
                        nYSrc = updateRects[j].top - (nYDst + tile->y);
-                       freerdp_image_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst,
-                                          nWidth, nHeight,     tile->data, PIXEL_FORMAT_XRGB32,
-                                          64 * 4, nXSrc, nYSrc, NULL);
+
+                       if (!freerdp_image_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst,
+                                               nWidth, nHeight,        tile->data, PIXEL_FORMAT_XRGB32,
+                                               64 * 4, nXSrc, nYSrc, NULL))
+                       {
+                               rc = -42;
+                               break;
+                       }
                }
 
                region16_uninit(&updateRegion);
        }
 
        region16_uninit(&clippingRects);
-       return 1;
+       return rc;
 }
 
 int progressive_compress(PROGRESSIVE_CONTEXT* progressive, BYTE* pSrcData,
index 5ec1dab..30afaec 100644 (file)
@@ -54,7 +54,7 @@ INLINE UINT32 gdi_GetPixel(HGDI_DC hdc, UINT32 nXPos, UINT32 nYPos)
 {
        HGDI_BITMAP hBmp = (HGDI_BITMAP) hdc->selectedObject;
        BYTE* data = &(hBmp->data[(nYPos * hBmp->scanline) + nXPos * GetBytesPerPixel(
-                                                                 hBmp->format)]);
+                                     hBmp->format)]);
        return ReadColor(data, hBmp->format);
 }
 
@@ -75,10 +75,10 @@ INLINE BYTE* gdi_GetPointer(HGDI_BITMAP hBmp, UINT32 X, UINT32 Y)
  */
 
 static INLINE UINT32 gdi_SetPixelBmp(HGDI_BITMAP hBmp, UINT32 X, UINT32 Y,
-                                                                        UINT32 crColor)
+                                     UINT32 crColor)
 {
        BYTE* p = &hBmp->data[(Y * hBmp->scanline) + X * GetBytesPerPixel(
-                                                         hBmp->format)];
+                                 hBmp->format)];
        WriteColor(p, hBmp->format, crColor);
        return crColor;
 }
@@ -101,13 +101,13 @@ INLINE UINT32 gdi_SetPixel(HGDI_DC hdc, UINT32 X, UINT32 Y, UINT32 crColor)
  */
 
 HGDI_BITMAP gdi_CreateBitmap(UINT32 nWidth, UINT32 nHeight, UINT32 format,
-                                                        BYTE* data)
+                             BYTE* data)
 {
        return gdi_CreateBitmapEx(nWidth, nHeight, format, 0, data, _aligned_free);
 }
 
 HGDI_BITMAP gdi_CreateBitmapEx(UINT32 nWidth, UINT32 nHeight, UINT32 format,
-                                                          UINT32 stride, BYTE* data, void (*fkt_free)(void*))
+                               UINT32 stride, BYTE* data, void (*fkt_free)(void*))
 {
        HGDI_BITMAP hBitmap = (HGDI_BITMAP) calloc(1, sizeof(GDI_BITMAP));
 
@@ -139,7 +139,7 @@ HGDI_BITMAP gdi_CreateBitmapEx(UINT32 nWidth, UINT32 nHeight, UINT32 format,
  */
 
 HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, UINT32 nWidth,
-                                                                          UINT32 nHeight)
+                                       UINT32 nHeight)
 {
        HGDI_BITMAP hBitmap = (HGDI_BITMAP) calloc(1, sizeof(GDI_BITMAP));
 
@@ -151,7 +151,7 @@ HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, UINT32 nWidth,
        hBitmap->width = nWidth;
        hBitmap->height = nHeight;
        hBitmap->data = _aligned_malloc(nWidth * nHeight * GetBytesPerPixel(
-                                                                               hBitmap->format), 16);
+                                           hBitmap->format), 16);
        hBitmap->free = _aligned_free;
 
        if (!hBitmap->data)
@@ -165,71 +165,33 @@ HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, UINT32 nWidth,
 }
 
 static BOOL BitBlt_SRCCOPY(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                          UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
-                          UINT32 nXSrc, UINT32 nYSrc)
+                           UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
+                           UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette)
 {
-       INT32 y;
-       BYTE* srcp;
-       BYTE* dstp;
+       HGDI_BITMAP hSrcBmp;
+       HGDI_BITMAP hDstBmp;
 
        if (!hdcDest || !hdcSrc)
                return FALSE;
 
-       if (hdcDest->format != hdcSrc->format)
-       {
-               WLog_ERR(TAG, "Function does not support color conversion!");
-               return FALSE;
-       }
-
        if ((nHeight == 0) || (nWidth == 0))
                return TRUE;
 
-       if ((hdcDest->selectedObject != hdcSrc->selectedObject) ||
-               !gdi_CopyOverlap(nXDest, nYDest, nWidth, nHeight, nXSrc, nYSrc))
-       {
-               for (y = 0; y < nHeight; y++)
-               {
-                       srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
-                       dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
-
-                       if (srcp != 0 && dstp != 0)
-                               memmove(dstp, srcp, nWidth * GetBytesPerPixel(hdcDest->format));
-               }
-
-               return TRUE;
-       }
-
-       if (nYSrc < nYDest)
-       {
-               /* copy down (bottom to top) */
-               for (y = nHeight - 1; y >= 0; y--)
-               {
-                       srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
-                       dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
+       hSrcBmp = (HGDI_BITMAP) hdcSrc->selectedObject;
+       hDstBmp = (HGDI_BITMAP) hdcDest->selectedObject;
 
-                       if (srcp != 0 && dstp != 0)
-                               memmove(dstp, srcp, nWidth * GetBytesPerPixel(hdcDest->format));
-               }
-       }
-       else
-       {
-               /* copy straight right */
-               for (y = 0; y < nHeight; y++)
-               {
-                       srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc, nYSrc + y);
-                       dstp = gdi_get_bitmap_pointer(hdcDest, nXDest, nYDest + y);
-
-                       if (srcp != 0 && dstp != 0)
-                               memmove(dstp, srcp, nWidth * GetBytesPerPixel(hdcDest->format));
-               }
-       }
+       if (!freerdp_image_copy(hDstBmp->data, hDstBmp->format, hDstBmp->scanline,
+                               nXDest, nYDest, nWidth, nHeight,
+                               hSrcBmp->data, hSrcBmp->format, hSrcBmp->scanline,
+                               nXSrc, nYSrc, palette))
+               return FALSE;
 
        return TRUE;
 }
 
 static BOOL BitBlt_NOTSRCCOPY(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                                 UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
-                                 UINT32 nXSrc, UINT32 nYSrc)
+                              UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
+                              UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette)
 {
        UINT32 x, y;
 
@@ -241,14 +203,15 @@ static BOOL BitBlt_NOTSRCCOPY(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
                for (x = 0; x < nWidth; x++)
                {
                        const BYTE* srcp = gdi_get_bitmap_pointer(
-                                                  hdcSrc, nXSrc + x, nYSrc + y);
+                                              hdcSrc, nXSrc + x, nYSrc + y);
                        BYTE* dstp = gdi_get_bitmap_pointer(
-                                                hdcDest, nXDest + x, nYDest + y);
+                                        hdcDest, nXDest + x, nYDest + y);
 
                        if (srcp && dstp)
                        {
                                UINT32 color = ReadColor(srcp, hdcSrc->format);
-                               color = ConvertColor(color, hdcSrc->format, hdcDest->format, NULL);
+                               color = ConvertColor(color, hdcSrc->format, hdcDest->format,
+                                                    palette);
                                color = ~color;
                                WriteColor(dstp, hdcDest->format, color);
                        }
@@ -259,8 +222,8 @@ static BOOL BitBlt_NOTSRCCOPY(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
 }
 
 static BOOL BitBlt_SRCERASE(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                               UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
-                               UINT32 nXSrc, UINT32 nYSrc)
+                            UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
+                            UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette)
 {
        UINT32 x, y;
 
@@ -272,17 +235,17 @@ static BOOL BitBlt_SRCERASE(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
                for (x = 0; x < nWidth; x++)
                {
                        const BYTE* srcp = gdi_get_bitmap_pointer(
-                                                  hdcSrc, nXSrc + x, nYSrc + y);
+                                              hdcSrc, nXSrc + x, nYSrc + y);
                        BYTE* dstp = gdi_get_bitmap_pointer(
-                                                hdcDest, nXDest + x, nYDest + y);
+                                        hdcDest, nXDest + x, nYDest + y);
 
                        if (srcp && dstp)
                        {
                                UINT32 colorA = ReadColor(srcp, hdcSrc->format);
                                UINT32 colorB = ReadColor(dstp, hdcDest->format);
                                UINT32 color;
-
-                               colorA = ConvertColor(colorA, hdcSrc->format, hdcDest->format, NULL);
+                               colorA = ConvertColor(colorA, hdcSrc->format, hdcDest->format,
+                                                     palette);
                                color = colorA & ~colorB;
                                WriteColor(dstp, hdcDest->format, color);
                        }
@@ -293,8 +256,8 @@ static BOOL BitBlt_SRCERASE(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
 }
 
 static BOOL BitBlt_NOTSRCERASE(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                                  UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
-                                  UINT32 nXSrc, UINT32 nYSrc)
+                               UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
+                               UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette)
 {
        UINT32 x, y;
 
@@ -306,19 +269,17 @@ static BOOL BitBlt_NOTSRCERASE(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
                for (x = 0; x < nWidth; x++)
                {
                        const BYTE* srcp = gdi_get_bitmap_pointer(
-                                                  hdcSrc, nXSrc + x, nYSrc + y);
+                                              hdcSrc, nXSrc + x, nYSrc + y);
                        BYTE* dstp = gdi_get_bitmap_pointer(
-                                                hdcDest, nXDest + x, nYDest + y);
+                                        hdcDest, nXDest + x, nYDest + y);
 
                        if (srcp && dstp)
                        {
                                UINT32 color;
                                UINT32 colorA = ReadColor(srcp, hdcSrc->format);
                                UINT32 colorB = ReadColor(dstp, hdcDest->format);
-
                                colorA = ConvertColor(colorA, hdcSrc->format,
-                                                         hdcDest->format, NULL);
-
+                                                     hdcDest->format, palette);
                                color = ~colorA & ~colorB;
                                WriteColor(dstp, hdcDest->format, color);
                        }
@@ -329,8 +290,8 @@ static BOOL BitBlt_NOTSRCERASE(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
 }
 
 static BOOL BitBlt_SRCINVERT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                                UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
-                                UINT32 nXSrc, UINT32 nYSrc)
+                             UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
+                             UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette)
 {
        UINT32 x, y;
 
@@ -342,19 +303,17 @@ static BOOL BitBlt_SRCINVERT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
                for (x = 0; x < nWidth; x++)
                {
                        const BYTE* srcp = gdi_get_bitmap_pointer(
-                                                  hdcSrc, nXSrc + x, nYSrc + y);
+                                              hdcSrc, nXSrc + x, nYSrc + y);
                        BYTE* dstp = gdi_get_bitmap_pointer(
-                                                hdcDest, nXDest + x, nYDest + y);
+                                        hdcDest, nXDest + x, nYDest + y);
 
                        if (srcp && dstp)
                        {
                                UINT32 color;
                                UINT32 colorA = ReadColor(srcp, hdcSrc->format);
                                UINT32 colorB = ReadColor(dstp, hdcDest->format);
-
                                colorA = ConvertColor(colorA, hdcSrc->format,
-                                                         hdcDest->format, NULL);
-
+                                                     hdcDest->format, palette);
                                color = colorA ^ colorB;
                                WriteColor(dstp, hdcDest->format, color);
                        }
@@ -365,8 +324,8 @@ static BOOL BitBlt_SRCINVERT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
 }
 
 static BOOL BitBlt_SRCAND(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                         UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
-                         UINT32 nXSrc, UINT32 nYSrc)
+                          UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
+                          UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette)
 {
        UINT32 x, y;
 
@@ -378,19 +337,17 @@ static BOOL BitBlt_SRCAND(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
                for (x = 0; x < nWidth; x++)
                {
                        const BYTE* srcp = gdi_get_bitmap_pointer(
-                                                  hdcSrc, nXSrc + x, nYSrc + y);
+                                              hdcSrc, nXSrc + x, nYSrc + y);
                        BYTE* dstp = gdi_get_bitmap_pointer(
-                                                hdcDest, nXDest + x, nYDest + y);
+                                        hdcDest, nXDest + x, nYDest + y);
 
                        if (srcp && dstp)
                        {
                                UINT32 color;
                                UINT32 colorA = ReadColor(srcp, hdcSrc->format);
                                UINT32 colorB = ReadColor(dstp, hdcDest->format);
-
                                colorA = ConvertColor(colorA, hdcSrc->format,
-                                                         hdcDest->format, NULL);
-
+                                                     hdcDest->format, palette);
                                color = colorA & colorB;
                                WriteColor(dstp, hdcDest->format, color);
                        }
@@ -401,8 +358,8 @@ static BOOL BitBlt_SRCAND(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
 }
 
 static BOOL BitBlt_SRCPAINT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                               UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
-                               UINT32 nXSrc, UINT32 nYSrc)
+                            UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
+                            UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette)
 {
        UINT32 x, y;
 
@@ -414,19 +371,17 @@ static BOOL BitBlt_SRCPAINT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
                for (x = 0; x < nWidth; x++)
                {
                        const BYTE* srcp = gdi_get_bitmap_pointer(
-                                                  hdcSrc, nXSrc + x, nYSrc + y);
+                                              hdcSrc, nXSrc + x, nYSrc + y);
                        BYTE* dstp = gdi_get_bitmap_pointer(
-                                                hdcDest, nXDest + x, nYDest + y);
+                                        hdcDest, nXDest + x, nYDest + y);
 
                        if (srcp && dstp)
                        {
                                UINT32 color;
                                UINT32 colorA = ReadColor(srcp, hdcSrc->format);
                                UINT32 colorB = ReadColor(dstp, hdcDest->format);
-
                                colorA = ConvertColor(colorA, hdcSrc->format,
-                                                         hdcDest->format, NULL);
-
+                                                     hdcDest->format, palette);
                                color = colorA | colorB;
                                WriteColor(dstp, hdcDest->format, color);
                        }
@@ -437,8 +392,8 @@ static BOOL BitBlt_SRCPAINT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
 }
 
 static BOOL BitBlt_DSPDxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                          UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
-                          UINT32 nXSrc, UINT32 nYSrc)
+                           UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
+                           UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette)
 {
        UINT32 x, y;
        UINT32 color;
@@ -451,22 +406,20 @@ static BOOL BitBlt_DSPDxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
 
        for (y = 0; y < nHeight; y++)
        {
-               for (x = 0; x<nWidth; x++)
+               for (x = 0; x < nWidth; x++)
                {
                        const BYTE* srcp = gdi_get_bitmap_pointer(
-                                                  hdcSrc, nXSrc + x, nYSrc + y);
+                                              hdcSrc, nXSrc + x, nYSrc + y);
                        BYTE* dstp = gdi_get_bitmap_pointer(
-                                                hdcDest, nXDest + x, nYDest + y);
+                                        hdcDest, nXDest + x, nYDest + y);
 
                        if (srcp && dstp)
                        {
                                UINT32 color;
                                UINT32 colorA = ReadColor(srcp, hdcSrc->format);
                                UINT32 colorB = ReadColor(dstp, hdcDest->format);
-
                                colorA = ConvertColor(colorA, hdcSrc->format,
-                                                         hdcDest->format, NULL);
-
+                                                     hdcDest->format, palette);
                                color = (colorA & color) | (~colorA & colorB);
                                WriteColor(dstp, hdcDest->format, color);
                        }
@@ -477,8 +430,8 @@ static BOOL BitBlt_DSPDxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
 }
 
 static BOOL BitBlt_PSDPxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                          UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
-                          UINT32 nXSrc, UINT32 nYSrc)
+                           UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
+                           UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette)
 {
        UINT32 x, y;
 
@@ -492,22 +445,20 @@ static BOOL BitBlt_PSDPxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
 
                for (y = 0; y < nHeight; y++)
                {
-                       for (x = 0; x<nWidth; x++)
+                       for (x = 0; x < nWidth; x++)
                        {
                                const BYTE* srcp = gdi_get_bitmap_pointer(
-                                                          hdcSrc, nXSrc + x, nYSrc + y);
+                                                      hdcSrc, nXSrc + x, nYSrc + y);
                                BYTE* dstp = gdi_get_bitmap_pointer(
-                                                        hdcDest, nXDest + x, nYDest + y);
+                                                hdcDest, nXDest + x, nYDest + y);
 
                                if (srcp && dstp)
                                {
                                        UINT32 color;
                                        UINT32 colorA = ReadColor(srcp, hdcSrc->format);
                                        UINT32 colorB = ReadColor(dstp, hdcDest->format);
-
                                        colorA = ConvertColor(colorA, hdcSrc->format,
-                                                                 hdcDest->format, NULL);
-
+                                                             hdcDest->format, palette);
                                        color = (colorA & colorB) | (~colorA & colorC);
                                        WriteColor(dstp, hdcDest->format, color);
                                }
@@ -518,14 +469,14 @@ static BOOL BitBlt_PSDPxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
        {
                for (y = 0; y < nHeight; y++)
                {
-                       for (x = 0; x<nWidth; x++)
+                       for (x = 0; x < nWidth; x++)
                        {
                                const BYTE* srcp = gdi_get_bitmap_pointer(
-                                                          hdcSrc, nXSrc + x, nYSrc + y);
+                                                      hdcSrc, nXSrc + x, nYSrc + y);
                                const BYTE* patp = gdi_get_brush_pointer(
-                                                          hdcDest, nXDest + x, nYDest + y);
+                                                      hdcDest, nXDest + x, nYDest + y);
                                BYTE* dstp = gdi_get_bitmap_pointer(
-                                                        hdcDest, nXDest + x, nYDest + y);
+                                                hdcDest, nXDest + x, nYDest + y);
 
                                if (srcp && dstp)
                                {
@@ -533,10 +484,8 @@ static BOOL BitBlt_PSDPxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
                                        UINT32 colorA = ReadColor(srcp, hdcSrc->format);
                                        UINT32 colorB = ReadColor(dstp, hdcDest->format);
                                        UINT32 colorC = ReadColor(patp, hdcDest->format);
-
                                        colorA = ConvertColor(colorA, hdcSrc->format,
-                                                                 hdcDest->format, NULL);
-
+                                                             hdcDest->format, palette);
                                        color = (colorA & colorB) | (~colorA & colorC);
                                        WriteColor(dstp, hdcDest->format, color);
                                }
@@ -548,8 +497,8 @@ static BOOL BitBlt_PSDPxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
 }
 
 static BOOL BitBlt_SPDSxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                          UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
-                          UINT32 nXSrc, UINT32 nYSrc)
+                           UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
+                           UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette)
 {
        UINT32 x, y;
 
@@ -563,22 +512,20 @@ static BOOL BitBlt_SPDSxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
 
                for (y = 0; y < nHeight; y++)
                {
-                       for (x = 0; x<nWidth; x++)
+                       for (x = 0; x < nWidth; x++)
                        {
                                const BYTE* srcp = gdi_get_bitmap_pointer(
-                                                          hdcSrc, nXSrc + x, nYSrc + y);
+                                                      hdcSrc, nXSrc + x, nYSrc + y);
                                BYTE* dstp = gdi_get_bitmap_pointer(
-                                                        hdcDest, nXDest + x, nYDest + y);
+                                                hdcDest, nXDest + x, nYDest + y);
 
                                if (srcp && dstp)
                                {
                                        UINT32 colorD;
                                        UINT32 colorA = ReadColor(srcp, hdcSrc->format);
                                        UINT32 colorB = ReadColor(dstp, hdcDest->format);
-
                                        colorA = ConvertColor(colorA, hdcSrc->format,
-                                                                 hdcDest->format, NULL);
-
+                                                             hdcDest->format, palette);
                                        colorD = colorA ^ (color & (colorB ^ colorA));
                                        WriteColor(dstp, hdcDest->format, color);
                                }
@@ -589,14 +536,14 @@ static BOOL BitBlt_SPDSxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
        {
                for (y = 0; y < nHeight; y++)
                {
-                       for (x = 0; x<nWidth; x++)
+                       for (x = 0; x < nWidth; x++)
                        {
                                const BYTE* srcp = gdi_get_bitmap_pointer(
-                                                          hdcSrc, nXSrc + x, nYSrc + y);
+                                                      hdcSrc, nXSrc + x, nYSrc + y);
                                const BYTE* patp = gdi_get_brush_pointer(
-                                                          hdcDest, nXDest + x, nYDest + y);
+                                                      hdcDest, nXDest + x, nYDest + y);
                                BYTE* dstp = gdi_get_bitmap_pointer(
-                                                        hdcDest, nXDest + x, nYDest + y);
+                                                hdcDest, nXDest + x, nYDest + y);
 
                                if (srcp && dstp)
                                {
@@ -604,10 +551,8 @@ static BOOL BitBlt_SPDSxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
                                        UINT32 colorA = ReadColor(srcp, hdcSrc->format);
                                        UINT32 colorB = ReadColor(dstp, hdcDest->format);
                                        UINT32 color = ReadColor(patp, hdcDest->format);
-
                                        colorA = ConvertColor(colorA, hdcSrc->format,
-                                                                 hdcDest->format, NULL);
-
+                                                             hdcDest->format, palette);
                                        colorD = colorA ^ (color & (colorB ^ colorA));
                                        WriteColor(dstp, hdcDest->format, color);
                                }
@@ -619,8 +564,8 @@ static BOOL BitBlt_SPDSxax(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
 }
 
 static BOOL BitBlt_SPna(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                       UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
-                       UINT32 nXSrc, UINT32 nYSrc)
+                        UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
+                        UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette)
 {
        UINT32 x, y;
 
@@ -640,9 +585,8 @@ 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, NULL);
+                                                     hdcDest->format, palette);
                                color = colorA & ~colorB;
                                WriteColor(dstp, hdcDest->format, color);
                        }
@@ -653,8 +597,8 @@ static BOOL BitBlt_SPna(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
 }
 
 static BOOL BitBlt_DSna(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                       UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
-                       UINT32 nXSrc, UINT32 nYSrc)
+                        UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
+                        UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette)
 {
        UINT32 x, y;
 
@@ -666,18 +610,17 @@ static BOOL BitBlt_DSna(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
                for (x = 0; x < nWidth; x++)
                {
                        const BYTE* srcp = gdi_get_bitmap_pointer(
-                                          hdcSrc, nXSrc + x, nYSrc + y);
+                                              hdcSrc, nXSrc + x, nYSrc + y);
                        BYTE* dstp = gdi_get_bitmap_pointer(
-                                          hdcDest, nXDest + x, nYDest + y);
+                                        hdcDest, nXDest + x, nYDest + y);
+
                        if (srcp && dstp)
                        {
                                UINT32 color;
                                UINT32 colorA = ReadColor(srcp, hdcSrc->format);
                                UINT32 colorB = ReadColor(dstp, hdcDest->format);
-
                                colorA = ConvertColor(colorA, hdcSrc->format,
-                                                         hdcDest->format, NULL);
-
+                                                     hdcDest->format, palette);
                                color = ~colorA & colorB;
                                WriteColor(dstp, hdcDest->format, color);
                        }
@@ -690,8 +633,8 @@ static BOOL BitBlt_DSna(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
 
 
 static BOOL BitBlt_MERGECOPY(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                                UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
-                                UINT32 nXSrc, UINT32 nYSrc)
+                             UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
+                             UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette)
 {
        UINT32 x, y;
 
@@ -703,20 +646,19 @@ static BOOL BitBlt_MERGECOPY(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
                for (x = 0; x < nWidth; x++)
                {
                        const BYTE* srcp = gdi_get_bitmap_pointer(
-                                                  hdcSrc, nXSrc + x, nYSrc + y);
+                                              hdcSrc, nXSrc + x, nYSrc + y);
                        const BYTE* patp = gdi_get_brush_pointer(
-                                                  hdcDest, nXDest + x, nYDest + y);
+                                              hdcDest, nXDest + x, nYDest + y);
                        BYTE* dstp = gdi_get_bitmap_pointer(
-                                                hdcDest, nXDest + x, nYDest + y);
+                                        hdcDest, nXDest + x, nYDest + y);
 
                        if (srcp && patp && dstp)
                        {
                                UINT32 color;
                                UINT32 colorA = ReadColor(srcp, hdcSrc->format);
                                UINT32 colorB = ReadColor(patp, hdcDest->format);
-
                                colorA = ConvertColor(colorA, hdcSrc->format,
-                                                         hdcDest->format, NULL);
+                                                     hdcDest->format, palette);
                                color = colorA & colorB;
                                WriteColor(dstp, hdcDest->format, color);
                        }
@@ -727,8 +669,8 @@ static BOOL BitBlt_MERGECOPY(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
 }
 
 static BOOL BitBlt_MERGEPAINT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                                 UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
-                                 UINT32 nXSrc, UINT32 nYSrc)
+                              UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
+                              UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette)
 {
        UINT32 x, y;
 
@@ -747,8 +689,8 @@ static BOOL BitBlt_MERGEPAINT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
                                UINT32 colorA = ReadColor(srcp, hdcSrc->format);
                                UINT32 colorB = ReadColor(dstp, hdcDest->format);
                                UINT32 color;
-
-                               colorA = ConvertColor(colorA, hdcSrc->format, hdcDest->format, NULL);
+                               colorA = ConvertColor(colorA, hdcSrc->format, hdcDest->format,
+                                                     palette);
                                color = ~colorA | colorB;
                                WriteColor(dstp, hdcDest->format, color);
                        }
@@ -773,15 +715,19 @@ static BOOL BitBlt_MERGEPAINT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
  * @return 0 on failure, non-zero otherwise
  */
 BOOL gdi_BitBlt(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                 UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
-                 UINT32 nXSrc, UINT32 nYSrc, DWORD rop)
+                UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
+                UINT32 nXSrc, UINT32 nYSrc, DWORD rop, const gdiPalette* palette)
 {
        if (!hdcDest)
                return FALSE;
 
+       if (gdi_PatBlt(hdcDest, nXDest, nYDest, nWidth, nHeight, rop))
+               return TRUE;
+
        if (hdcSrc != NULL)
        {
-               if (!gdi_ClipCoords(hdcDest, &nXDest, &nYDest, &nWidth, &nHeight, &nXSrc, &nYSrc))
+               if (!gdi_ClipCoords(hdcDest, &nXDest, &nYDest, &nWidth, &nHeight, &nXSrc,
+                                   &nYSrc))
                        return TRUE;
        }
        else
@@ -795,65 +741,64 @@ BOOL gdi_BitBlt(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
 
        switch (rop)
        {
-               case GDI_BLACKNESS:
-                       return BitBlt_BLACKNESS(hdcDest, nXDest, nYDest, nWidth, nHeight);
-
-               case GDI_WHITENESS:
-                       return BitBlt_WHITENESS(hdcDest, nXDest, nYDest, nWidth, nHeight);
-
                case GDI_SRCCOPY:
-                       return BitBlt_SRCCOPY(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
+                       return BitBlt_SRCCOPY(hdcDest, nXDest, nYDest, nWidth, nHeight,
+                                             hdcSrc, nXSrc, nYSrc, palette);
 
                case GDI_SPna:
-                       return BitBlt_SPna(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
+                       return BitBlt_SPna(hdcDest, nXDest, nYDest, nWidth, nHeight,
+                                          hdcSrc, nXSrc, nYSrc, palette);
 
                case GDI_DSna:
-                       return BitBlt_DSna(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
+                       return BitBlt_DSna(hdcDest, nXDest, nYDest, nWidth, nHeight,
+                                          hdcSrc, nXSrc, nYSrc, palette);
 
                case GDI_DSPDxax:
-                       return BitBlt_DSPDxax(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
+                       return BitBlt_DSPDxax(hdcDest, nXDest, nYDest, nWidth, nHeight,
+                                             hdcSrc, nXSrc, nYSrc, palette);
 
                case GDI_PSDPxax:
-                       return BitBlt_PSDPxax(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
+                       return BitBlt_PSDPxax(hdcDest, nXDest, nYDest, nWidth, nHeight,
+                                             hdcSrc, nXSrc, nYSrc, palette);
 
                case GDI_SPDSxax:
-                       return BitBlt_SPDSxax(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
+                       return BitBlt_SPDSxax(hdcDest, nXDest, nYDest, nWidth, nHeight,
+                                             hdcSrc, nXSrc, nYSrc, palette);
 
                case GDI_NOTSRCCOPY:
-                       return BitBlt_NOTSRCCOPY(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
-
-               case GDI_DSTINVERT:
-                       return BitBlt_DSTINVERT(hdcDest, nXDest, nYDest, nWidth, nHeight);
+                       return BitBlt_NOTSRCCOPY(hdcDest, nXDest, nYDest, nWidth, nHeight,
+                                                hdcSrc, nXSrc, nYSrc, palette);
 
                case GDI_SRCERASE:
-                       return BitBlt_SRCERASE(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
+                       return BitBlt_SRCERASE(hdcDest, nXDest, nYDest, nWidth, nHeight,
+                                              hdcSrc, nXSrc, nYSrc, palette);
 
                case GDI_NOTSRCERASE:
-                       return BitBlt_NOTSRCERASE(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
+                       return BitBlt_NOTSRCERASE(hdcDest, nXDest, nYDest, nWidth, nHeight,
+                                                 hdcSrc, nXSrc, nYSrc, palette);
 
                case GDI_SRCINVERT:
-                       return BitBlt_SRCINVERT(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
+                       return BitBlt_SRCINVERT(hdcDest, nXDest, nYDest, nWidth, nHeight,
+                                               hdcSrc, nXSrc, nYSrc, palette);
 
                case GDI_SRCAND:
-                       return BitBlt_SRCAND(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
+                       return BitBlt_SRCAND(hdcDest, nXDest, nYDest, nWidth, nHeight,
+                                            hdcSrc, nXSrc, nYSrc, palette);
 
                case GDI_SRCPAINT:
-                       return BitBlt_SRCPAINT(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
+                       return BitBlt_SRCPAINT(hdcDest, nXDest, nYDest, nWidth, nHeight,
+                                              hdcSrc, nXSrc, nYSrc, palette);
 
                case GDI_MERGECOPY:
-                       return BitBlt_MERGECOPY(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
+                       return BitBlt_MERGECOPY(hdcDest, nXDest, nYDest, nWidth, nHeight,
+                                               hdcSrc, nXSrc, nYSrc, palette);
 
                case GDI_MERGEPAINT:
-                       return BitBlt_MERGEPAINT(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
-
-               case GDI_PATCOPY:
-                       return BitBlt_PATCOPY(hdcDest, nXDest, nYDest, nWidth, nHeight);
-
-               case GDI_PATINVERT:
-                       return BitBlt_PATINVERT(hdcDest, nXDest, nYDest, nWidth, nHeight);
+                       return BitBlt_MERGEPAINT(hdcDest, nXDest, nYDest, nWidth, nHeight,
+                                                hdcSrc, nXSrc, nYSrc, palette);
 
-               case GDI_PATPAINT:
-                       return BitBlt_PATPAINT(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc);
+               default:
+                       break;
        }
 
        WLog_ERR(TAG,  "BitBlt: unknown rop: 0x%08X", rop);
index b1e5814..b6eba4d 100644 (file)
@@ -149,8 +149,8 @@ static BOOL BitBlt_PDxn(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
        return TRUE;
 }
 
-BOOL BitBlt_PATINVERT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                      UINT32 nWidth, UINT32 nHeight)
+static BOOL BitBlt_PATINVERT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
+                             UINT32 nWidth, UINT32 nHeight)
 {
        UINT32 x, y;
 
@@ -195,9 +195,9 @@ BOOL BitBlt_PATINVERT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
        return TRUE;
 }
 
-BOOL BitBlt_PATPAINT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                     UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
-                     UINT32 nXSrc, UINT32 nYSrc)
+static BOOL BitBlt_PATPAINT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
+                            UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
+                            UINT32 nXSrc, UINT32 nYSrc)
 {
        UINT32 x, y;
 
@@ -226,8 +226,8 @@ BOOL BitBlt_PATPAINT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
        return TRUE;
 }
 
-BOOL BitBlt_PATCOPY(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                    UINT32 nWidth, UINT32 nHeight)
+static BOOL BitBlt_PATCOPY(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
+                           UINT32 nWidth, UINT32 nHeight)
 {
        UINT32 x, y, xOffset, yOffset;
 
@@ -283,8 +283,8 @@ BOOL BitBlt_PATCOPY(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
        return TRUE;
 }
 
-BOOL BitBlt_DSTINVERT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                      UINT32 nWidth, UINT32 nHeight)
+static BOOL BitBlt_DSTINVERT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
+                             UINT32 nWidth, UINT32 nHeight)
 {
        UINT32 x, y;
 
@@ -307,8 +307,8 @@ BOOL BitBlt_DSTINVERT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
        return TRUE;
 }
 
-BOOL BitBlt_BLACKNESS(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                      UINT32 nWidth, UINT32 nHeight)
+static BOOL BitBlt_BLACKNESS(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
+                             UINT32 nWidth, UINT32 nHeight)
 {
        UINT32 x, y;
        UINT32 color = GetColor(hdcDest->format, 0, 0, 0, 0xFF);
@@ -327,8 +327,8 @@ BOOL BitBlt_BLACKNESS(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
        return TRUE;
 }
 
-BOOL BitBlt_WHITENESS(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                      UINT32 nWidth, UINT32 nHeight)
+static BOOL BitBlt_WHITENESS(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
+                             UINT32 nWidth, UINT32 nHeight)
 {
        UINT32 x, y;
        UINT32 color = GetColor(hdcDest->format, 0, 0, 0, 0);
@@ -383,6 +383,5 @@ BOOL gdi_PatBlt(HGDI_DC hdc, UINT32 nXLeft, UINT32 nYLeft,
                        break;
        }
 
-       WLog_ERR(TAG,  "PatBlt: unknown rop: 0x%08X", rop);
        return FALSE;
 }
index df1d33f..d9c0a12 100644 (file)
@@ -33,27 +33,13 @@ HGDI_BRUSH gdi_CreateSolidBrush(UINT32 crColor);
 HGDI_BRUSH gdi_CreatePatternBrush(HGDI_BITMAP hbmp);
 HGDI_BRUSH gdi_CreateHatchBrush(HGDI_BITMAP hbmp);
 BOOL gdi_PatBlt(HGDI_DC hdc, UINT32 nXLeft, UINT32 nYLeft,
-                               UINT32 nWidth, UINT32 nHeight, DWORD rop);
-
-BOOL BitBlt_PATPAINT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                           UINT32 nWidth, UINT32 nHeight, HGDI_DC hdcSrc,
-                           UINT32 nXSrc, UINT32 nYSrc);
-BOOL BitBlt_PATINVERT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                            UINT32 nWidth, UINT32 nHeight);
-BOOL BitBlt_BLACKNESS(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                            UINT32 nWidth, UINT32 nHeight);
-BOOL BitBlt_WHITENESS(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                            UINT32 nWidth, UINT32 nHeight);
-BOOL BitBlt_PATCOPY(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                          UINT32 nWidth, UINT32 nHeight);
-BOOL BitBlt_DSTINVERT(HGDI_DC hdcDest, UINT32 nXDest, UINT32 nYDest,
-                            UINT32 nWidth, UINT32 nHeight);
+                UINT32 nWidth, UINT32 nHeight, DWORD rop);
 
 #ifdef __cplusplus
 }
 #endif
 
 typedef BOOL (*p_PatBlt)(HGDI_DC hdc, UINT32 nXLeft, UINT32 nYLeft,
-                                                UINT32 nWidth, UINT32 nHeight, DWORD rop);
+                         UINT32 nWidth, UINT32 nHeight, DWORD rop);
 
 #endif /* FREERDP_GDI_BRUSH_H */
index 4482283..1e0f7f9 100644 (file)
@@ -484,13 +484,13 @@ static BOOL gdi_bitmap_update(rdpContext* context,
                        if (bitsPerPixel < 32)
                        {
                                status = interleaved_decompress(codecs->interleaved,
-                                                               pSrcData, SrcSize,
-                                                               bitsPerPixel,
-                                                               gdi->primary_buffer,
-                                                               gdi->dstFormat,
-                                                               gdi->stride, nXDst, nYDst,
-                                                               nWidth, nHeight,
-                                                               gdi->palette);
+                                                               pSrcData, SrcSize,
+                                                               bitsPerPixel,
+                                                               gdi->primary_buffer,
+                                                               gdi->dstFormat,
+                                                               gdi->stride, nXDst, nYDst,
+                                                               nWidth, nHeight,
+                                                               &gdi->palette);
                        }
                        else
                        {
@@ -518,10 +518,10 @@ static BOOL gdi_bitmap_update(rdpContext* context,
                                          gdi->height - 1) - bitmap->destTop + 1; /* clip height */
 
                        if (!freerdp_image_copy(gdi->primary_buffer, gdi->dstFormat, gdi->stride,
-                                                                       nXDst, nYDst, nWidth, nHeight,
-                                                                       pSrcData, SrcFormat, nSrcStep,
-                                                                       nXSrc, nYSrc, gdi->palette))
-                                       return FALSE;
+                                               nXDst, nYDst, nWidth, nHeight,
+                                               pSrcData, SrcFormat, nSrcStep,
+                                               nXSrc, nYSrc, &gdi->palette))
+                               return FALSE;
                }
 
                if (!gdi_InvalidateRegion(gdi->primary->hdc, nXDst, nYDst,
@@ -537,10 +537,10 @@ static BOOL gdi_palette_update(rdpContext* context,
 {
        int index;
        const PALETTE_ENTRY* pe;
-       UINT32* palette32;
        rdpGdi* gdi = context->gdi;
-       palette32 = (UINT32*) gdi->palette;
+       gdi->palette.format = gdi->dstFormat;
 
+       gdi->palette.format = gdi->dstFormat;
        for (index = 0; index < (int) palette->number; index++)
        {
                pe = &(palette->entries[index]);
@@ -589,9 +589,9 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
        UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth, FALSE);
        brush = &patblt->brush;
        foreColor = ConvertColor(patblt->foreColor, SrcFormat,
-                                gdi->dstFormat, gdi->palette);
+                                gdi->dstFormat, &gdi->palette);
        backColor = ConvertColor(patblt->backColor, SrcFormat,
-                                gdi->dstFormat, gdi->palette);
+                                gdi->dstFormat, &gdi->palette);
        originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor);
 
        if (brush->style == GDI_BS_SOLID)
@@ -628,7 +628,7 @@ 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,
-                                                  hatched, backColor, foreColor, gdi->palette);
+                                                  hatched, backColor, foreColor, &gdi->palette);
                hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->format, data);
 
                if (!hBmp)
@@ -676,8 +676,13 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
                                goto out_error;
                        }
 
-                       freerdp_image_copy(data, gdi->dstFormat, -1, 0, 0,
-                                          8, 8, brush->data, brushFormat, -1, 0, 0, gdi->palette);
+                       if (!freerdp_image_copy(data, gdi->dstFormat, 0, 0, 0,
+                                               8, 8, brush->data, brushFormat, 0, 0, 0,
+                                               &gdi->palette))
+                       {
+                               ret = FALSE;
+                               goto out_error;
+                       }
                }
                else
                {
@@ -690,7 +695,7 @@ static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
                        }
 
                        freerdp_image_copy_from_monochrome(data, gdi->dstFormat, 0, 0, 0, 8, 8,
-                                                          brush->data, backColor, foreColor, gdi->palette);
+                                                          brush->data, backColor, foreColor, &gdi->palette);
                }
 
                hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->format, data);
@@ -754,7 +759,7 @@ static BOOL gdi_opaque_rect(rdpContext* context,
        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);
+                                  gdi->dstFormat, &gdi->palette);
 
        if (!(hBrush = gdi_CreateSolidBrush(brush_color)))
                return FALSE;
@@ -782,7 +787,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->dstFormat, &gdi->palette);
                hBrush = gdi_CreateSolidBrush(brush_color);
 
                if (!hBrush)
@@ -807,7 +812,7 @@ static BOOL gdi_line_to(rdpContext* context, const LINE_TO_ORDER* lineTo)
        UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth, FALSE);
 
        if (!(hPen = gdi_CreatePen(lineTo->penStyle, lineTo->penWidth, color,
-                                  SrcFormat)))
+                                  SrcFormat, &gdi->palette)))
                return FALSE;
 
        gdi_SelectObject(gdi->drawing->hdc, (HGDIOBJECT) hPen);
@@ -830,7 +835,7 @@ static BOOL gdi_polyline(rdpContext* context, const POLYLINE_ORDER* polyline)
        UINT32 SrcFormat = gdi_get_pixel_format(context->settings->ColorDepth, FALSE);
        color =  polyline->penColor;
 
-       if (!(hPen = gdi_CreatePen(GDI_PS_SOLID, 1, color, SrcFormat)))
+       if (!(hPen = gdi_CreatePen(GDI_PS_SOLID, 1, color, SrcFormat, &gdi->palette)))
                return FALSE;
 
        gdi_SelectObject(gdi->drawing->hdc, (HGDIOBJECT) hPen);
@@ -877,9 +882,9 @@ static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
        brush = &mem3blt->brush;
        bitmap = (gdiBitmap*) mem3blt->bitmap;
        foreColor = ConvertColor(mem3blt->foreColor, SrcFormat,
-                                gdi->dstFormat, gdi->palette);
+                                gdi->dstFormat, &gdi->palette);
        backColor = ConvertColor(mem3blt->backColor, SrcFormat,
-                                gdi->dstFormat, gdi->palette);
+                                gdi->dstFormat, &gdi->palette);
        originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor);
 
        if (brush->style == GDI_BS_SOLID)
@@ -929,7 +934,7 @@ static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
                        }
 
                        freerdp_image_copy_from_monochrome(data, gdi->dstFormat, 0, 0, 0, 8, 8,
-                                                          brush->data, backColor, foreColor, gdi->palette);
+                                                          brush->data, backColor, foreColor, &gdi->palette);
                }
 
                hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->format, data);
index 2c8f2e6..4727933 100644 (file)
@@ -758,7 +758,8 @@ static UINT gdi_SolidFill(RdpgfxClientContext* context,
        r = solidFill->fillPixel.R;
        a = solidFill->fillPixel.XA;
        color = GetColor(PIXEL_FORMAT_ARGB32, r, g, b, a);
-       color = ConvertColor(color, PIXEL_FORMAT_ARGB32, surface->format, NULL);
+       color = ConvertColor(color, PIXEL_FORMAT_ARGB32, surface->format,
+                            &gdi->palette);
 
        for (index = 0; index < solidFill->fillRectCount; index++)
        {
index 63ff64e..c2ad7de 100644 (file)
@@ -54,8 +54,15 @@ HGDI_BITMAP gdi_create_bitmap(rdpGdi* gdi, UINT32 nWidth, UINT32 nHeight,
 
        pSrcData = data;
        nSrcStep = nWidth * GetBytesPerPixel(SrcFormat);
-       freerdp_image_copy(pDstData, gdi->dstFormat, nDstStep, 0, 0,
-                                          nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, 0, 0, gdi->palette);
+
+       if (!freerdp_image_copy(pDstData, gdi->dstFormat, nDstStep, 0, 0,
+                               nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, 0, 0,
+                               &gdi->palette))
+       {
+               _aligned_free(pDstData);
+               return NULL;
+       }
+
        bitmap = gdi_CreateBitmap(nWidth, nHeight, gdi->dstFormat, pDstData);
        return bitmap;
 }
@@ -141,11 +148,11 @@ static BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
                if (bpp < 32)
                {
                        status = interleaved_decompress(gdi->codecs->interleaved,
-                                                                                       pSrcData, SrcSize,
-                                                                                       bpp,
-                                                                                       pDstData, gdi->dstFormat,
-                                                                                       0, 0, 0, width, height,
-                                                                                       gdi->palette);
+                                                       pSrcData, SrcSize,
+                                                       bpp,
+                                                       pDstData, gdi->dstFormat,
+                                                       0, 0, 0, width, height,
+                                                       &gdi->palette);
                }
                else
                {
@@ -164,8 +171,8 @@ static BOOL gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
        {
                SrcFormat = gdi_get_pixel_format(bpp, FALSE);
                status = freerdp_image_copy(pDstData, gdi->dstFormat, 0, 0, 0,
-                                                                       width, height, pSrcData, SrcFormat,
-                                                                       0, 0, 0, gdi->palette);
+                                           width, height, pSrcData, SrcFormat,
+                                           0, 0, 0, &gdi->palette);
        }
 
        bitmap->compressed = FALSE;
@@ -256,8 +263,8 @@ 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->dstFormat, &gdi->palette);
+       fgcolor = ConvertColor(fgcolor, SrcFormat, gdi->dstFormat, &gdi->palette);
 
        if (!(brush = gdi_CreateSolidBrush(fgcolor)))
                goto out;
@@ -276,7 +283,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->dstFormat, &gdi->palette);
        gdi->textColor = gdi_SetTextColor(gdi->drawing->hdc, bgcolor);
        return TRUE;
 }