libfreerdp-codec: add ClearCodec glyph cache

This commit is contained in:
Marc-André Moreau 2014-07-01 09:55:52 -04:00
parent 78e00db45d
commit 8a5591bdef
3 changed files with 46 additions and 7 deletions

View File

@ -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

View File

@ -32,6 +32,7 @@
struct _CLEAR_CONTEXT
{
BOOL Compressor;
BYTE* GlyphCache[4000];
UINT32 VBarStorageCursor;
void* VBarStorage[32768];
UINT32 ShortVBarStorageCursor;

View File

@ -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);
}