From 8a5591bdef99e83e94a765bb804520c7b4c2f2d9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marc-Andr=C3=A9=20Moreau?= Date: Tue, 1 Jul 2014 09:55:52 -0400 Subject: [PATCH] libfreerdp-codec: add ClearCodec glyph cache --- client/X11/xf_gfx.c | 2 +- include/freerdp/codec/clear.h | 1 + libfreerdp/codec/clear.c | 50 +++++++++++++++++++++++++++++++++++++------ 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/client/X11/xf_gfx.c b/client/X11/xf_gfx.c index 01ec060..66f032e 100644 --- a/client/X11/xf_gfx.c +++ b/client/X11/xf_gfx.c @@ -267,7 +267,7 @@ int xf_SurfaceCommand_ClearCodec(xfContext* xfc, RdpgfxClientContext* context, R DstData = surface->data; - status = clear_decompress(NULL, cmd->data, cmd->length, &DstData, + status = clear_decompress(xfc->clear, cmd->data, cmd->length, &DstData, PIXEL_FORMAT_XRGB32, surface->scanline, cmd->left, cmd->top, cmd->width, cmd->height); #if 0 diff --git a/include/freerdp/codec/clear.h b/include/freerdp/codec/clear.h index 03aed70..b3c17c5 100644 --- a/include/freerdp/codec/clear.h +++ b/include/freerdp/codec/clear.h @@ -32,6 +32,7 @@ struct _CLEAR_CONTEXT { BOOL Compressor; + BYTE* GlyphCache[4000]; UINT32 VBarStorageCursor; void* VBarStorage[32768]; UINT32 ShortVBarStorageCursor; diff --git a/libfreerdp/codec/clear.c b/libfreerdp/codec/clear.c index 40dcfc2..000c257 100644 --- a/libfreerdp/codec/clear.c +++ b/libfreerdp/codec/clear.c @@ -56,12 +56,13 @@ static BYTE CLEAR_8BIT_MASKS[9] = int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight) { - UINT32 i; + UINT32 i, y; UINT32 count; BYTE r, g, b; UINT32 color; - BYTE glyphFlags; BYTE seqNumber; + BYTE glyphFlags; + BYTE* glyphData; UINT16 glyphIndex; UINT32 offset = 0; BYTE* pDstData = NULL; @@ -72,6 +73,8 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, UINT16 runLengthFactor2; UINT32 runLengthFactor3; UINT32 runLengthFactor; + UINT32* pSrcPixel = NULL; + UINT32* pDstPixel = NULL; if (!ppDstData) return -1; @@ -92,6 +95,9 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, if (glyphFlags & CLEARCODEC_FLAG_GLYPH_INDEX) { + if ((nWidth * nHeight) > (1024 * 1024)) + return -1; + if (SrcSize < 4) return -1002; @@ -105,6 +111,18 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, * specified by the glyphIndex field to the output bitmap */ + glyphData = clear->GlyphCache[glyphIndex]; + + if (!glyphData) + return -1; + + for (y = 0; y < nHeight; y++) + { + pDstPixel = (UINT32*) &pSrcData[y * (nWidth * 4)]; + pSrcPixel = (UINT32*) &pDstData[((nYDst + y) * nDstStep) + (nXDst * 4)]; + CopyMemory(pDstPixel, pSrcPixel, nWidth * 4); + } + return 1; /* Finish */ } } @@ -430,6 +448,21 @@ int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, * Copy decompressed bitmap to the Decompressor Glyph * Storage position specified by the glyphIndex field */ + + if (!clear->GlyphCache[glyphIndex]) + clear->GlyphCache[glyphIndex] = (BYTE*) malloc(1024 * 1024 * 4); + + glyphData = clear->GlyphCache[glyphIndex]; + + if (!glyphData) + return -1; + + for (y = 0; y < nHeight; y++) + { + pSrcPixel = (UINT32*) &pDstData[((nYDst + y) * nDstStep) + (nXDst * 4)]; + pDstPixel = (UINT32*) &pSrcData[y * (nWidth * 4)]; + CopyMemory(pDstPixel, pSrcPixel, nWidth * 4); + } } if (offset != SrcSize) @@ -468,9 +501,14 @@ CLEAR_CONTEXT* clear_context_new(BOOL Compressor) void clear_context_free(CLEAR_CONTEXT* clear) { - if (clear) - { - free(clear); - } + int i; + + if (!clear) + return; + + for (i = 0; i < 4000; i++) + free(clear->GlyphCache[i]); + + free(clear); } -- 2.7.4