2014-06-04 04:51:28 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* ClearCodec Bitmap Compression
|
|
|
|
*
|
|
|
|
* Copyright 2014 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <winpr/crt.h>
|
|
|
|
#include <winpr/print.h>
|
|
|
|
#include <winpr/bitstream.h>
|
|
|
|
|
2014-06-26 02:39:28 +04:00
|
|
|
#include <freerdp/codec/color.h>
|
2014-06-04 04:51:28 +04:00
|
|
|
#include <freerdp/codec/clear.h>
|
|
|
|
|
2014-06-27 01:08:51 +04:00
|
|
|
static UINT32 CLEAR_LOG2_FLOOR[256] =
|
|
|
|
{
|
|
|
|
0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3,
|
|
|
|
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
|
|
|
|
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
|
|
|
5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
|
|
|
|
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
|
|
|
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
|
|
|
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
|
|
|
6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
|
|
|
|
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
|
|
|
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
|
|
|
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
|
|
|
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
|
|
|
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
|
|
|
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
|
|
|
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
|
|
|
|
7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7
|
|
|
|
};
|
|
|
|
|
|
|
|
static BYTE CLEAR_8BIT_MASKS[9] =
|
|
|
|
{
|
|
|
|
0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF
|
|
|
|
};
|
|
|
|
|
2014-06-26 02:39:28 +04:00
|
|
|
int clear_decompress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize,
|
|
|
|
BYTE** ppDstData, DWORD DstFormat, int nDstStep, int nXDst, int nYDst, int nWidth, int nHeight)
|
2014-06-04 04:51:28 +04:00
|
|
|
{
|
2014-07-01 22:38:54 +04:00
|
|
|
UINT32 i;
|
2014-09-17 00:55:47 +04:00
|
|
|
BOOL invert;
|
2014-07-02 00:32:36 +04:00
|
|
|
UINT32 x, y;
|
2014-11-17 02:37:29 +03:00
|
|
|
UINT32 count = 0;
|
2014-06-27 01:08:51 +04:00
|
|
|
UINT32 color;
|
2014-07-02 21:45:19 +04:00
|
|
|
int nXDstRel;
|
|
|
|
int nYDstRel;
|
|
|
|
int nSrcStep;
|
2014-06-13 20:17:16 +04:00
|
|
|
BYTE seqNumber;
|
2014-07-01 17:55:52 +04:00
|
|
|
BYTE glyphFlags;
|
|
|
|
BYTE* glyphData;
|
2014-06-13 20:17:16 +04:00
|
|
|
UINT32 offset = 0;
|
2014-07-08 23:07:19 +04:00
|
|
|
UINT16 glyphIndex = 0;
|
2014-06-27 01:08:51 +04:00
|
|
|
BYTE* pDstData = NULL;
|
2014-06-13 20:17:16 +04:00
|
|
|
UINT32 residualByteCount;
|
|
|
|
UINT32 bandsByteCount;
|
|
|
|
UINT32 subcodecByteCount;
|
2014-06-27 01:08:51 +04:00
|
|
|
UINT32 runLengthFactor;
|
2014-07-02 02:21:51 +04:00
|
|
|
UINT32 pixelIndex = 0;
|
|
|
|
UINT32 pixelCount = 0;
|
2014-07-02 22:51:46 +04:00
|
|
|
BYTE* pSrcPixel8 = NULL;
|
|
|
|
BYTE* pDstPixel8 = NULL;
|
|
|
|
UINT32* pSrcPixel32 = NULL;
|
|
|
|
UINT32* pDstPixel32 = NULL;
|
2014-07-08 19:37:27 +04:00
|
|
|
CLEAR_GLYPH_ENTRY* glyphEntry;
|
2014-06-27 01:08:51 +04:00
|
|
|
|
|
|
|
if (!ppDstData)
|
2014-07-02 00:32:36 +04:00
|
|
|
return -1001;
|
2014-06-27 01:08:51 +04:00
|
|
|
|
|
|
|
pDstData = *ppDstData;
|
|
|
|
|
|
|
|
if (!pDstData)
|
2014-07-02 00:32:36 +04:00
|
|
|
return -1002;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
|
|
|
if (SrcSize < 2)
|
2014-07-02 00:32:36 +04:00
|
|
|
return -1003;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2014-07-07 23:48:56 +04:00
|
|
|
if ((nWidth > 0xFFFF) || (nHeight > 0xFFFF))
|
|
|
|
return -1004;
|
|
|
|
|
2014-09-17 00:55:47 +04:00
|
|
|
invert = FREERDP_PIXEL_FORMAT_IS_ABGR(DstFormat) ? TRUE : FALSE;
|
|
|
|
|
2014-06-13 20:17:16 +04:00
|
|
|
glyphFlags = pSrcData[0];
|
|
|
|
seqNumber = pSrcData[1];
|
|
|
|
offset += 2;
|
|
|
|
|
2014-09-26 06:08:10 +04:00
|
|
|
if (!clear->seqNumber && seqNumber)
|
|
|
|
clear->seqNumber = seqNumber;
|
|
|
|
|
2014-07-06 00:29:28 +04:00
|
|
|
if (seqNumber != clear->seqNumber)
|
2014-07-07 23:48:56 +04:00
|
|
|
return -1005;
|
2014-07-06 00:29:28 +04:00
|
|
|
|
|
|
|
clear->seqNumber = (seqNumber + 1) % 256;
|
|
|
|
|
2014-07-01 22:38:54 +04:00
|
|
|
if (glyphFlags & CLEARCODEC_FLAG_CACHE_RESET)
|
|
|
|
{
|
|
|
|
clear->VBarStorageCursor = 0;
|
|
|
|
clear->ShortVBarStorageCursor = 0;
|
|
|
|
}
|
|
|
|
|
2014-07-02 02:21:51 +04:00
|
|
|
if ((glyphFlags & CLEARCODEC_FLAG_GLYPH_HIT) && !(glyphFlags & CLEARCODEC_FLAG_GLYPH_INDEX))
|
2014-07-07 23:48:56 +04:00
|
|
|
return -1006;
|
2014-07-02 02:21:51 +04:00
|
|
|
|
2014-06-13 20:17:16 +04:00
|
|
|
if (glyphFlags & CLEARCODEC_FLAG_GLYPH_INDEX)
|
|
|
|
{
|
2014-07-01 17:55:52 +04:00
|
|
|
if ((nWidth * nHeight) > (1024 * 1024))
|
2014-07-07 23:48:56 +04:00
|
|
|
return -1007;
|
2014-07-01 17:55:52 +04:00
|
|
|
|
2014-06-13 20:17:16 +04:00
|
|
|
if (SrcSize < 4)
|
2014-07-07 23:48:56 +04:00
|
|
|
return -1008;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
|
|
|
glyphIndex = *((UINT16*) &pSrcData[2]);
|
|
|
|
offset += 2;
|
|
|
|
|
2014-07-01 22:38:54 +04:00
|
|
|
if (glyphIndex >= 4000)
|
2014-07-07 23:48:56 +04:00
|
|
|
return -1009;
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2014-06-13 20:17:16 +04:00
|
|
|
if (glyphFlags & CLEARCODEC_FLAG_GLYPH_HIT)
|
|
|
|
{
|
2014-07-08 19:37:27 +04:00
|
|
|
glyphEntry = &(clear->GlyphCache[glyphIndex]);
|
|
|
|
glyphData = (BYTE*) glyphEntry->pixels;
|
2014-07-01 17:55:52 +04:00
|
|
|
|
|
|
|
if (!glyphData)
|
2014-07-07 23:48:56 +04:00
|
|
|
return -1010;
|
2014-07-01 17:55:52 +04:00
|
|
|
|
2014-08-12 02:48:42 +04:00
|
|
|
if ((nWidth * nHeight) > (int) glyphEntry->count)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1011;
|
|
|
|
|
2014-07-02 21:45:19 +04:00
|
|
|
nSrcStep = nWidth * 4;
|
2014-07-02 22:51:46 +04:00
|
|
|
pSrcPixel8 = glyphData;
|
|
|
|
pDstPixel8 = &pDstData[(nYDst * nDstStep) + (nXDst * 4)];
|
2014-07-02 21:45:19 +04:00
|
|
|
|
2014-08-12 02:48:42 +04:00
|
|
|
for (y = 0; y < (UINT32) nHeight; y++)
|
2014-07-01 17:55:52 +04:00
|
|
|
{
|
2014-07-02 22:51:46 +04:00
|
|
|
CopyMemory(pDstPixel8, pSrcPixel8, nSrcStep);
|
|
|
|
pSrcPixel8 += nSrcStep;
|
|
|
|
pDstPixel8 += nDstStep;
|
2014-07-01 17:55:52 +04:00
|
|
|
}
|
|
|
|
|
2014-06-13 20:17:16 +04:00
|
|
|
return 1; /* Finish */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read composition payload header parameters */
|
|
|
|
|
|
|
|
if ((SrcSize - offset) < 12)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1012;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
|
|
|
residualByteCount = *((UINT32*) &pSrcData[offset]);
|
|
|
|
bandsByteCount = *((UINT32*) &pSrcData[offset + 4]);
|
|
|
|
subcodecByteCount = *((UINT32*) &pSrcData[offset + 8]);
|
|
|
|
offset += 12;
|
|
|
|
|
2015-01-20 13:10:16 +03:00
|
|
|
//WLog_DBG(TAG, "residualByteCount: %d bandsByteCount: %d subcodecByteCount: %d",
|
2014-07-08 00:50:19 +04:00
|
|
|
// residualByteCount, bandsByteCount, subcodecByteCount);
|
2014-06-13 20:17:16 +04:00
|
|
|
|
|
|
|
if (residualByteCount > 0)
|
|
|
|
{
|
|
|
|
UINT32 suboffset;
|
|
|
|
BYTE* residualData;
|
|
|
|
|
|
|
|
if ((SrcSize - offset) < residualByteCount)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1013;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
|
|
|
suboffset = 0;
|
|
|
|
residualData = &pSrcData[offset];
|
|
|
|
|
2014-08-12 02:48:42 +04:00
|
|
|
if ((nWidth * nHeight * 4) > (int) clear->TempSize)
|
2014-07-07 23:48:56 +04:00
|
|
|
{
|
|
|
|
clear->TempSize = (nWidth * nHeight * 4);
|
|
|
|
clear->TempBuffer = (BYTE*) realloc(clear->TempBuffer, clear->TempSize);
|
|
|
|
|
|
|
|
if (!clear->TempBuffer)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1014;
|
2014-07-07 23:48:56 +04:00
|
|
|
}
|
|
|
|
|
2014-07-04 00:09:53 +04:00
|
|
|
pixelIndex = 0;
|
2014-07-07 23:48:56 +04:00
|
|
|
pixelCount = nWidth * nHeight;
|
|
|
|
pDstPixel32 = (UINT32*) clear->TempBuffer;
|
2014-07-02 02:21:51 +04:00
|
|
|
|
2014-06-13 20:17:16 +04:00
|
|
|
while (suboffset < residualByteCount)
|
|
|
|
{
|
|
|
|
if ((residualByteCount - suboffset) < 4)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1015;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2014-09-17 00:55:47 +04:00
|
|
|
if (!invert)
|
|
|
|
color = RGB32(residualData[suboffset + 2], residualData[suboffset + 1], residualData[suboffset + 0]);
|
|
|
|
else
|
|
|
|
color = BGR32(residualData[suboffset + 2], residualData[suboffset + 1], residualData[suboffset + 0]);
|
|
|
|
|
2014-06-13 20:17:16 +04:00
|
|
|
suboffset += 3;
|
|
|
|
|
2014-07-02 22:51:46 +04:00
|
|
|
runLengthFactor = (UINT32) residualData[suboffset];
|
|
|
|
suboffset++;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2014-07-02 22:51:46 +04:00
|
|
|
if (runLengthFactor >= 0xFF)
|
2014-06-13 20:17:16 +04:00
|
|
|
{
|
|
|
|
if ((residualByteCount - suboffset) < 2)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1016;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2014-07-02 22:51:46 +04:00
|
|
|
runLengthFactor = (UINT32) *((UINT16*) &residualData[suboffset]);
|
2014-06-13 20:17:16 +04:00
|
|
|
suboffset += 2;
|
|
|
|
|
2014-07-02 22:51:46 +04:00
|
|
|
if (runLengthFactor >= 0xFFFF)
|
2014-06-13 20:17:16 +04:00
|
|
|
{
|
|
|
|
if ((residualByteCount - suboffset) < 4)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1017;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2014-07-02 22:51:46 +04:00
|
|
|
runLengthFactor = *((UINT32*) &residualData[suboffset]);
|
2014-06-13 20:17:16 +04:00
|
|
|
suboffset += 4;
|
|
|
|
}
|
|
|
|
}
|
2014-06-26 02:39:28 +04:00
|
|
|
|
2014-07-07 23:48:56 +04:00
|
|
|
if ((pixelIndex + runLengthFactor) > pixelCount)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1018;
|
2014-06-27 01:08:51 +04:00
|
|
|
|
2014-07-07 23:48:56 +04:00
|
|
|
for (i = 0; i < runLengthFactor; i++)
|
2014-06-27 01:08:51 +04:00
|
|
|
{
|
2014-07-07 23:48:56 +04:00
|
|
|
*pDstPixel32 = color;
|
|
|
|
pDstPixel32++;
|
2014-06-27 01:08:51 +04:00
|
|
|
}
|
2014-06-26 02:39:28 +04:00
|
|
|
|
|
|
|
pixelIndex += runLengthFactor;
|
|
|
|
}
|
|
|
|
|
2014-07-07 23:48:56 +04:00
|
|
|
nSrcStep = nWidth * 4;
|
|
|
|
pSrcPixel8 = clear->TempBuffer;
|
|
|
|
pDstPixel8 = &pDstData[(nYDst * nDstStep) + (nXDst * 4)];
|
|
|
|
|
|
|
|
if (pixelIndex != pixelCount)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1019;
|
2014-07-07 23:48:56 +04:00
|
|
|
|
2014-08-12 02:48:42 +04:00
|
|
|
for (y = 0; y < (UINT32) nHeight; y++)
|
2014-07-07 23:48:56 +04:00
|
|
|
{
|
|
|
|
CopyMemory(pDstPixel8, pSrcPixel8, nSrcStep);
|
|
|
|
pSrcPixel8 += nSrcStep;
|
|
|
|
pDstPixel8 += nDstStep;
|
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
|
|
|
|
offset += residualByteCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bandsByteCount > 0)
|
|
|
|
{
|
|
|
|
BYTE* bandsData;
|
|
|
|
UINT32 suboffset;
|
|
|
|
|
|
|
|
if ((SrcSize - offset) < bandsByteCount)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1020;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
|
|
|
suboffset = 0;
|
|
|
|
bandsData = &pSrcData[offset];
|
|
|
|
|
|
|
|
while (suboffset < bandsByteCount)
|
|
|
|
{
|
|
|
|
UINT16 xStart;
|
|
|
|
UINT16 xEnd;
|
|
|
|
UINT16 yStart;
|
|
|
|
UINT16 yEnd;
|
2014-07-01 22:38:54 +04:00
|
|
|
BYTE* vBar;
|
|
|
|
BOOL vBarUpdate;
|
2014-07-02 21:45:19 +04:00
|
|
|
UINT32 colorBkg;
|
2014-06-13 20:17:16 +04:00
|
|
|
UINT16 vBarHeader;
|
2014-06-14 01:30:13 +04:00
|
|
|
UINT16 vBarIndex;
|
|
|
|
UINT16 vBarYOn;
|
|
|
|
UINT16 vBarYOff;
|
2014-07-01 22:38:54 +04:00
|
|
|
UINT32 vBarCount;
|
2014-07-04 00:09:53 +04:00
|
|
|
UINT32 vBarHeight;
|
2014-07-01 22:38:54 +04:00
|
|
|
UINT32 vBarPixelCount;
|
|
|
|
UINT32 vBarShortPixelCount;
|
|
|
|
CLEAR_VBAR_ENTRY* vBarEntry;
|
|
|
|
CLEAR_VBAR_ENTRY* vBarShortEntry;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
|
|
|
if ((bandsByteCount - suboffset) < 11)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1021;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
|
|
|
xStart = *((UINT16*) &bandsData[suboffset]);
|
|
|
|
xEnd = *((UINT16*) &bandsData[suboffset + 2]);
|
|
|
|
yStart = *((UINT16*) &bandsData[suboffset + 4]);
|
|
|
|
yEnd = *((UINT16*) &bandsData[suboffset + 6]);
|
2014-07-02 21:45:19 +04:00
|
|
|
suboffset += 8;
|
|
|
|
|
2014-09-17 00:55:47 +04:00
|
|
|
if (!invert)
|
|
|
|
colorBkg = RGB32(bandsData[suboffset + 2], bandsData[suboffset + 1], bandsData[suboffset + 0]);
|
|
|
|
else
|
|
|
|
colorBkg = BGR32(bandsData[suboffset + 2], bandsData[suboffset + 1], bandsData[suboffset + 0]);
|
|
|
|
|
2014-07-02 21:45:19 +04:00
|
|
|
suboffset += 3;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2014-07-02 02:21:51 +04:00
|
|
|
if (xEnd < xStart)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1022;
|
2014-07-02 02:21:51 +04:00
|
|
|
|
|
|
|
if (yEnd < yStart)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1023;
|
2014-07-02 02:21:51 +04:00
|
|
|
|
2014-06-14 01:30:13 +04:00
|
|
|
vBarCount = (xEnd - xStart) + 1;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2014-06-27 01:08:51 +04:00
|
|
|
for (i = 0; i < vBarCount; i++)
|
2014-06-13 20:17:16 +04:00
|
|
|
{
|
2014-07-01 22:38:54 +04:00
|
|
|
vBarUpdate = FALSE;
|
|
|
|
vBar = &bandsData[suboffset];
|
2014-06-14 01:30:13 +04:00
|
|
|
|
|
|
|
if ((bandsByteCount - suboffset) < 2)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1024;
|
2014-06-14 01:30:13 +04:00
|
|
|
|
2014-07-01 22:38:54 +04:00
|
|
|
vBarHeader = *((UINT16*) &vBar[0]);
|
2014-06-13 20:17:16 +04:00
|
|
|
suboffset += 2;
|
|
|
|
|
2014-07-04 00:09:53 +04:00
|
|
|
vBarHeight = (yEnd - yStart + 1);
|
2014-07-02 00:32:36 +04:00
|
|
|
|
2014-07-04 00:09:53 +04:00
|
|
|
if (vBarHeight > 52)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1025;
|
2014-07-02 21:45:19 +04:00
|
|
|
|
2014-07-06 00:29:28 +04:00
|
|
|
if ((vBarHeader & 0xC000) == 0x4000) /* SHORT_VBAR_CACHE_HIT */
|
2014-06-14 01:30:13 +04:00
|
|
|
{
|
|
|
|
vBarIndex = (vBarHeader & 0x3FFF);
|
|
|
|
|
2014-07-01 22:38:54 +04:00
|
|
|
if (vBarIndex >= 16384)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1026;
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2014-06-14 01:30:13 +04:00
|
|
|
if ((bandsByteCount - suboffset) < 1)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1027;
|
2014-06-14 01:30:13 +04:00
|
|
|
|
2014-07-01 22:38:54 +04:00
|
|
|
vBarYOn = vBar[2];
|
2014-06-14 01:30:13 +04:00
|
|
|
suboffset += 1;
|
|
|
|
|
2014-07-08 00:50:19 +04:00
|
|
|
vBarShortEntry = &(clear->ShortVBarStorage[vBarIndex]);
|
2014-07-01 22:38:54 +04:00
|
|
|
|
|
|
|
if (!vBarShortEntry)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1028;
|
2014-07-02 00:32:36 +04:00
|
|
|
|
|
|
|
vBarShortPixelCount = vBarShortEntry->count;
|
2014-07-01 22:38:54 +04:00
|
|
|
|
|
|
|
vBarUpdate = TRUE;
|
2014-06-14 01:30:13 +04:00
|
|
|
}
|
|
|
|
else if ((vBarHeader & 0xC000) == 0x0000) /* SHORT_VBAR_CACHE_MISS */
|
|
|
|
{
|
|
|
|
vBarYOn = (vBarHeader & 0xFF);
|
|
|
|
vBarYOff = ((vBarHeader >> 8) & 0x3F);
|
|
|
|
|
2014-07-02 00:32:36 +04:00
|
|
|
if (vBarYOff < vBarYOn)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1029;
|
2014-06-14 01:30:13 +04:00
|
|
|
|
2014-07-03 19:49:06 +04:00
|
|
|
pSrcPixel8 = &vBar[2];
|
2014-07-01 22:38:54 +04:00
|
|
|
vBarShortPixelCount = (vBarYOff - vBarYOn);
|
2014-06-14 01:30:13 +04:00
|
|
|
|
2014-07-02 21:45:19 +04:00
|
|
|
if (vBarShortPixelCount > 52)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1030;
|
2014-06-14 01:30:13 +04:00
|
|
|
|
2014-07-01 22:38:54 +04:00
|
|
|
if ((bandsByteCount - suboffset) < (vBarShortPixelCount * 3))
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1031;
|
2014-06-14 01:30:13 +04:00
|
|
|
|
2014-07-06 00:29:28 +04:00
|
|
|
if (clear->ShortVBarStorageCursor >= 16384)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1032;
|
2014-07-06 00:29:28 +04:00
|
|
|
|
2014-07-01 22:38:54 +04:00
|
|
|
vBarShortEntry = &(clear->ShortVBarStorage[clear->ShortVBarStorageCursor]);
|
|
|
|
|
2014-07-08 19:37:27 +04:00
|
|
|
vBarShortEntry->count = vBarShortPixelCount;
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2014-07-08 19:37:27 +04:00
|
|
|
if (vBarShortEntry->count > vBarShortEntry->size)
|
|
|
|
{
|
2015-06-16 16:42:07 +03:00
|
|
|
UINT32 *tmp;
|
2014-07-08 19:37:27 +04:00
|
|
|
vBarShortEntry->size = vBarShortEntry->count;
|
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
tmp = (UINT32*) realloc(vBarShortEntry->pixels, vBarShortEntry->count * 4);
|
|
|
|
if (!tmp)
|
|
|
|
return -1;
|
|
|
|
vBarShortEntry->pixels = tmp;
|
2014-07-08 19:37:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!vBarShortEntry->pixels && vBarShortEntry->size)
|
|
|
|
return -1033;
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2014-07-02 22:51:46 +04:00
|
|
|
pDstPixel32 = vBarShortEntry->pixels;
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2014-09-17 00:55:47 +04:00
|
|
|
if (!invert)
|
2014-07-01 22:38:54 +04:00
|
|
|
{
|
2014-09-17 00:55:47 +04:00
|
|
|
for (y = 0; y < vBarShortPixelCount; y++)
|
|
|
|
{
|
|
|
|
*pDstPixel32 = RGB32(pSrcPixel8[2], pSrcPixel8[1], pSrcPixel8[0]);
|
|
|
|
pSrcPixel8 += 3;
|
|
|
|
pDstPixel32++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (y = 0; y < vBarShortPixelCount; y++)
|
|
|
|
{
|
|
|
|
*pDstPixel32 = BGR32(pSrcPixel8[2], pSrcPixel8[1], pSrcPixel8[0]);
|
|
|
|
pSrcPixel8 += 3;
|
|
|
|
pDstPixel32++;
|
|
|
|
}
|
2014-07-01 22:38:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
suboffset += (vBarShortPixelCount * 3);
|
|
|
|
|
|
|
|
vBarShortEntry->count = vBarShortPixelCount;
|
2014-07-07 20:17:37 +04:00
|
|
|
clear->ShortVBarStorageCursor = (clear->ShortVBarStorageCursor + 1) % 16384;
|
2014-07-01 22:38:54 +04:00
|
|
|
|
|
|
|
vBarUpdate = TRUE;
|
2014-06-14 01:30:13 +04:00
|
|
|
}
|
2014-07-06 00:29:28 +04:00
|
|
|
else if ((vBarHeader & 0x8000) == 0x8000) /* VBAR_CACHE_HIT */
|
|
|
|
{
|
|
|
|
vBarIndex = (vBarHeader & 0x7FFF);
|
|
|
|
|
|
|
|
if (vBarIndex >= 32768)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1034;
|
2014-07-06 00:29:28 +04:00
|
|
|
|
|
|
|
vBarEntry = &(clear->VBarStorage[vBarIndex]);
|
|
|
|
}
|
2014-06-14 01:30:13 +04:00
|
|
|
else
|
|
|
|
{
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1035; /* invalid vBarHeader */
|
2014-06-14 01:30:13 +04:00
|
|
|
}
|
2014-07-01 22:38:54 +04:00
|
|
|
|
|
|
|
if (vBarUpdate)
|
|
|
|
{
|
2014-07-06 00:29:28 +04:00
|
|
|
if (clear->VBarStorageCursor >= 32768)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1036;
|
2014-07-06 00:29:28 +04:00
|
|
|
|
2014-07-01 22:38:54 +04:00
|
|
|
vBarEntry = &(clear->VBarStorage[clear->VBarStorageCursor]);
|
|
|
|
|
2014-07-08 19:37:27 +04:00
|
|
|
vBarPixelCount = vBarHeight;
|
|
|
|
vBarEntry->count = vBarPixelCount;
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2014-07-08 19:37:27 +04:00
|
|
|
if (vBarEntry->count > vBarEntry->size)
|
|
|
|
{
|
2015-06-16 16:42:07 +03:00
|
|
|
UINT32 *tmp;
|
2014-07-08 19:37:27 +04:00
|
|
|
vBarEntry->size = vBarEntry->count;
|
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
tmp = (UINT32*) realloc(vBarEntry->pixels, vBarEntry->count * 4);
|
|
|
|
if (!tmp)
|
|
|
|
return -1;
|
|
|
|
vBarEntry->pixels = tmp;
|
2014-07-08 19:37:27 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!vBarEntry->pixels && vBarEntry->size)
|
|
|
|
return -1037;
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2014-07-02 22:51:46 +04:00
|
|
|
pDstPixel32 = vBarEntry->pixels;
|
2014-07-01 22:38:54 +04:00
|
|
|
|
|
|
|
/* if (y < vBarYOn), use colorBkg */
|
|
|
|
|
|
|
|
y = 0;
|
|
|
|
count = vBarYOn;
|
|
|
|
|
|
|
|
if ((y + count) > vBarPixelCount)
|
|
|
|
count = (vBarPixelCount > y) ? (vBarPixelCount - y) : 0;
|
|
|
|
|
2014-07-02 02:21:51 +04:00
|
|
|
while (count--)
|
2014-07-01 22:38:54 +04:00
|
|
|
{
|
2014-07-02 22:51:46 +04:00
|
|
|
*pDstPixel32 = colorBkg;
|
|
|
|
pDstPixel32++;
|
2014-07-01 22:38:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if ((y >= vBarYOn) && (y < (vBarYOn + vBarShortPixelCount))),
|
|
|
|
* use vBarShortPixels at index (y - shortVBarYOn)
|
|
|
|
*/
|
|
|
|
|
|
|
|
y = vBarYOn;
|
|
|
|
count = vBarShortPixelCount;
|
|
|
|
|
|
|
|
if ((y + count) > vBarPixelCount)
|
|
|
|
count = (vBarPixelCount > y) ? (vBarPixelCount - y) : 0;
|
|
|
|
|
2014-07-02 22:51:46 +04:00
|
|
|
pSrcPixel32 = &(vBarShortEntry->pixels[y - vBarYOn]);
|
|
|
|
CopyMemory(pDstPixel32, pSrcPixel32, count * 4);
|
|
|
|
pDstPixel32 += count;
|
2014-07-01 22:38:54 +04:00
|
|
|
|
|
|
|
/* if (y >= (vBarYOn + vBarShortPixelCount)), use colorBkg */
|
|
|
|
|
|
|
|
y = vBarYOn + vBarShortPixelCount;
|
|
|
|
count = (vBarPixelCount > y) ? (vBarPixelCount - y) : 0;
|
|
|
|
|
2014-07-02 02:21:51 +04:00
|
|
|
while (count--)
|
2014-07-01 22:38:54 +04:00
|
|
|
{
|
2014-07-02 22:51:46 +04:00
|
|
|
*pDstPixel32 = colorBkg;
|
|
|
|
pDstPixel32++;
|
2014-07-01 22:38:54 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
vBarEntry->count = vBarPixelCount;
|
2014-07-07 20:17:37 +04:00
|
|
|
clear->VBarStorageCursor = (clear->VBarStorageCursor + 1) % 32768;
|
2014-07-01 22:38:54 +04:00
|
|
|
}
|
2014-07-02 00:32:36 +04:00
|
|
|
|
2014-07-02 21:45:19 +04:00
|
|
|
nXDstRel = nXDst + xStart;
|
|
|
|
nYDstRel = nYDst + yStart;
|
|
|
|
|
2014-07-04 00:09:53 +04:00
|
|
|
pSrcPixel32 = vBarEntry->pixels;
|
2014-07-02 22:51:46 +04:00
|
|
|
pDstPixel8 = &pDstData[(nYDstRel * nDstStep) + ((nXDstRel + i) * 4)];
|
2014-07-02 00:32:36 +04:00
|
|
|
|
2014-07-04 00:09:53 +04:00
|
|
|
count = yEnd - yStart + 1;
|
|
|
|
|
2014-07-08 00:50:19 +04:00
|
|
|
if (vBarEntry->count != count)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1038;
|
2014-07-04 00:09:53 +04:00
|
|
|
|
2014-07-08 00:50:19 +04:00
|
|
|
for (y = 0; y < count; y++)
|
2014-07-02 00:32:36 +04:00
|
|
|
{
|
2014-07-08 00:50:19 +04:00
|
|
|
*((UINT32*) pDstPixel8) = *pSrcPixel32;
|
|
|
|
pDstPixel8 += nDstStep;
|
|
|
|
pSrcPixel32++;
|
2014-07-02 00:32:36 +04:00
|
|
|
}
|
2014-06-14 01:30:13 +04:00
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
offset += bandsByteCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (subcodecByteCount > 0)
|
|
|
|
{
|
|
|
|
UINT16 xStart;
|
|
|
|
UINT16 yStart;
|
|
|
|
UINT16 width;
|
|
|
|
UINT16 height;
|
|
|
|
BYTE* bitmapData;
|
2014-06-27 01:08:51 +04:00
|
|
|
UINT32 bitmapDataOffset;
|
2014-06-13 20:17:16 +04:00
|
|
|
UINT32 bitmapDataByteCount;
|
|
|
|
BYTE subcodecId;
|
|
|
|
BYTE* subcodecs;
|
|
|
|
UINT32 suboffset;
|
|
|
|
|
|
|
|
if ((SrcSize - offset) < subcodecByteCount)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1039;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
|
|
|
suboffset = 0;
|
|
|
|
subcodecs = &pSrcData[offset];
|
|
|
|
|
|
|
|
while (suboffset < subcodecByteCount)
|
|
|
|
{
|
|
|
|
if ((subcodecByteCount - suboffset) < 13)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1040;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
|
|
|
xStart = *((UINT16*) &subcodecs[suboffset]);
|
|
|
|
yStart = *((UINT16*) &subcodecs[suboffset + 2]);
|
|
|
|
width = *((UINT16*) &subcodecs[suboffset + 4]);
|
|
|
|
height = *((UINT16*) &subcodecs[suboffset + 6]);
|
|
|
|
bitmapDataByteCount = *((UINT32*) &subcodecs[suboffset + 8]);
|
|
|
|
subcodecId = subcodecs[suboffset + 12];
|
|
|
|
suboffset += 13;
|
|
|
|
|
2015-01-20 13:10:16 +03:00
|
|
|
//WLog_DBG(TAG, "bitmapDataByteCount: %d subcodecByteCount: %d suboffset: %d subCodecId: %d",
|
2014-07-02 02:21:51 +04:00
|
|
|
// bitmapDataByteCount, subcodecByteCount, suboffset, subcodecId);
|
2014-06-13 20:17:16 +04:00
|
|
|
|
|
|
|
if ((subcodecByteCount - suboffset) < bitmapDataByteCount)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1041;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2014-07-02 21:45:19 +04:00
|
|
|
nXDstRel = nXDst + xStart;
|
|
|
|
nYDstRel = nYDst + yStart;
|
|
|
|
|
2014-07-07 23:48:56 +04:00
|
|
|
if (width > nWidth)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1042;
|
2014-07-07 23:48:56 +04:00
|
|
|
|
|
|
|
if (height > nHeight)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1043;
|
2014-07-07 23:48:56 +04:00
|
|
|
|
2014-08-12 02:48:42 +04:00
|
|
|
if (((UINT32) (width * height * 4)) > clear->TempSize)
|
2014-07-07 22:16:05 +04:00
|
|
|
{
|
|
|
|
clear->TempSize = (width * height * 4);
|
|
|
|
clear->TempBuffer = (BYTE*) realloc(clear->TempBuffer, clear->TempSize);
|
|
|
|
|
|
|
|
if (!clear->TempBuffer)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1044;
|
2014-07-07 22:16:05 +04:00
|
|
|
}
|
|
|
|
|
2014-06-13 20:17:16 +04:00
|
|
|
bitmapData = &subcodecs[suboffset];
|
|
|
|
|
2014-06-27 01:08:51 +04:00
|
|
|
if (subcodecId == 0) /* Uncompressed */
|
|
|
|
{
|
2014-07-02 00:32:36 +04:00
|
|
|
if (bitmapDataByteCount != (width * height * 3))
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1045;
|
2014-06-27 01:08:51 +04:00
|
|
|
|
2014-07-02 22:51:46 +04:00
|
|
|
pSrcPixel8 = bitmapData;
|
2014-07-02 00:32:36 +04:00
|
|
|
|
2014-09-17 00:55:47 +04:00
|
|
|
if (!invert)
|
2014-07-02 00:32:36 +04:00
|
|
|
{
|
2014-09-17 00:55:47 +04:00
|
|
|
for (y = 0; y < height; y++)
|
2014-07-02 00:32:36 +04:00
|
|
|
{
|
2014-09-17 00:55:47 +04:00
|
|
|
pDstPixel32 = (UINT32*) &pDstData[((nYDstRel + y) * nDstStep) + (nXDstRel * 4)];
|
|
|
|
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
*pDstPixel32 = RGB32(pSrcPixel8[2], pSrcPixel8[1], pSrcPixel8[0]);
|
|
|
|
pSrcPixel8 += 3;
|
|
|
|
pDstPixel32++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
pDstPixel32 = (UINT32*) &pDstData[((nYDstRel + y) * nDstStep) + (nXDstRel * 4)];
|
|
|
|
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
*pDstPixel32 = BGR32(pSrcPixel8[2], pSrcPixel8[1], pSrcPixel8[0]);
|
|
|
|
pSrcPixel8 += 3;
|
|
|
|
pDstPixel32++;
|
|
|
|
}
|
2014-07-02 00:32:36 +04:00
|
|
|
}
|
|
|
|
}
|
2014-06-27 01:08:51 +04:00
|
|
|
}
|
|
|
|
else if (subcodecId == 1) /* NSCodec */
|
|
|
|
{
|
2014-07-02 22:51:46 +04:00
|
|
|
if (nsc_process_message(clear->nsc, 32, width, height, bitmapData, bitmapDataByteCount) < 0)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1046;
|
2014-07-02 00:32:36 +04:00
|
|
|
|
2014-07-02 21:45:19 +04:00
|
|
|
nSrcStep = width * 4;
|
2014-07-02 22:51:46 +04:00
|
|
|
pSrcPixel8 = clear->nsc->BitmapData;
|
|
|
|
pDstPixel8 = &pDstData[(nYDstRel * nDstStep) + (nXDstRel * 4)];
|
2014-06-27 01:08:51 +04:00
|
|
|
|
2014-09-17 00:55:47 +04:00
|
|
|
if (!invert)
|
2014-07-02 00:32:36 +04:00
|
|
|
{
|
2014-09-17 00:55:47 +04:00
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
CopyMemory(pDstPixel8, pSrcPixel8, nSrcStep);
|
|
|
|
pSrcPixel8 += nSrcStep;
|
|
|
|
pDstPixel8 += nDstStep;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
for (x = 0; x < width; x++)
|
|
|
|
{
|
|
|
|
pDstPixel8[0] = pSrcPixel8[2];
|
|
|
|
pDstPixel8[1] = pSrcPixel8[1];
|
|
|
|
pDstPixel8[2] = pSrcPixel8[0];
|
|
|
|
pDstPixel8[3] = 0xFF;
|
|
|
|
|
|
|
|
pSrcPixel8 += 4;
|
|
|
|
pDstPixel8 += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
pSrcPixel8 += (nSrcStep - (width * 4));
|
|
|
|
pDstPixel8 += (nDstStep - (width * 4));
|
|
|
|
}
|
2014-07-02 00:32:36 +04:00
|
|
|
}
|
2014-06-27 01:08:51 +04:00
|
|
|
}
|
|
|
|
else if (subcodecId == 2) /* CLEARCODEC_SUBCODEC_RLEX */
|
|
|
|
{
|
2014-07-02 02:21:51 +04:00
|
|
|
UINT32 numBits;
|
|
|
|
BYTE startIndex;
|
|
|
|
BYTE stopIndex;
|
|
|
|
BYTE suiteIndex;
|
|
|
|
BYTE suiteDepth;
|
|
|
|
BYTE paletteCount;
|
2014-07-07 22:16:05 +04:00
|
|
|
UINT32 palette[128];
|
2014-07-02 02:21:51 +04:00
|
|
|
|
2014-06-27 01:08:51 +04:00
|
|
|
paletteCount = bitmapData[0];
|
2014-07-07 22:16:05 +04:00
|
|
|
pSrcPixel8 = &bitmapData[1];
|
2014-06-27 01:08:51 +04:00
|
|
|
bitmapDataOffset = 1 + (paletteCount * 3);
|
|
|
|
|
2014-07-07 22:16:05 +04:00
|
|
|
if (paletteCount > 127)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1047;
|
2014-07-02 02:21:51 +04:00
|
|
|
|
2014-09-17 00:55:47 +04:00
|
|
|
if (!invert)
|
|
|
|
{
|
|
|
|
for (i = 0; i < paletteCount; i++)
|
|
|
|
{
|
|
|
|
palette[i] = RGB32(pSrcPixel8[2], pSrcPixel8[1], pSrcPixel8[0]);
|
|
|
|
pSrcPixel8 += 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2014-06-27 01:08:51 +04:00
|
|
|
{
|
2014-09-17 00:55:47 +04:00
|
|
|
for (i = 0; i < paletteCount; i++)
|
|
|
|
{
|
|
|
|
palette[i] = BGR32(pSrcPixel8[2], pSrcPixel8[1], pSrcPixel8[0]);
|
|
|
|
pSrcPixel8 += 3;
|
|
|
|
}
|
2014-06-27 01:08:51 +04:00
|
|
|
}
|
|
|
|
|
2014-07-07 23:48:56 +04:00
|
|
|
pixelIndex = 0;
|
|
|
|
pixelCount = width * height;
|
2014-07-07 22:16:05 +04:00
|
|
|
pDstPixel32 = (UINT32*) clear->TempBuffer;
|
|
|
|
|
2014-06-27 01:08:51 +04:00
|
|
|
numBits = CLEAR_LOG2_FLOOR[paletteCount - 1] + 1;
|
|
|
|
|
|
|
|
while (bitmapDataOffset < bitmapDataByteCount)
|
|
|
|
{
|
2014-07-02 22:51:46 +04:00
|
|
|
if ((bitmapDataByteCount - bitmapDataOffset) < 2)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1048;
|
2014-07-02 22:51:46 +04:00
|
|
|
|
2014-06-27 01:08:51 +04:00
|
|
|
stopIndex = bitmapData[bitmapDataOffset] & CLEAR_8BIT_MASKS[numBits];
|
2014-07-07 22:16:05 +04:00
|
|
|
suiteDepth = (bitmapData[bitmapDataOffset] >> numBits) & CLEAR_8BIT_MASKS[(8 - numBits)];
|
2014-07-02 02:21:51 +04:00
|
|
|
startIndex = stopIndex - suiteDepth;
|
2014-06-27 01:08:51 +04:00
|
|
|
bitmapDataOffset++;
|
|
|
|
|
2014-07-02 22:51:46 +04:00
|
|
|
runLengthFactor = (UINT32) bitmapData[bitmapDataOffset];
|
|
|
|
bitmapDataOffset++;
|
2014-06-27 01:08:51 +04:00
|
|
|
|
2014-07-02 22:51:46 +04:00
|
|
|
if (runLengthFactor >= 0xFF)
|
2014-06-27 01:08:51 +04:00
|
|
|
{
|
|
|
|
if ((bitmapDataByteCount - bitmapDataOffset) < 2)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1049;
|
2014-06-27 01:08:51 +04:00
|
|
|
|
2014-07-02 22:51:46 +04:00
|
|
|
runLengthFactor = (UINT32) *((UINT16*) &bitmapData[bitmapDataOffset]);
|
2014-06-27 01:08:51 +04:00
|
|
|
bitmapDataOffset += 2;
|
|
|
|
|
2014-07-02 22:51:46 +04:00
|
|
|
if (runLengthFactor >= 0xFFFF)
|
2014-06-27 01:08:51 +04:00
|
|
|
{
|
|
|
|
if ((bitmapDataByteCount - bitmapDataOffset) < 4)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1050;
|
2014-06-27 01:08:51 +04:00
|
|
|
|
2014-07-02 22:51:46 +04:00
|
|
|
runLengthFactor = *((UINT32*) &bitmapData[bitmapDataOffset]);
|
2014-06-27 01:08:51 +04:00
|
|
|
bitmapDataOffset += 4;
|
|
|
|
}
|
|
|
|
}
|
2014-07-02 02:21:51 +04:00
|
|
|
|
2014-07-07 22:16:05 +04:00
|
|
|
if (startIndex >= paletteCount)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1051;
|
2014-07-02 02:21:51 +04:00
|
|
|
|
2014-07-07 22:16:05 +04:00
|
|
|
if (stopIndex >= paletteCount)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1052;
|
2014-07-02 02:21:51 +04:00
|
|
|
|
|
|
|
suiteIndex = startIndex;
|
2014-07-07 22:16:05 +04:00
|
|
|
color = palette[suiteIndex];
|
2014-07-02 02:21:51 +04:00
|
|
|
|
2014-07-07 23:48:56 +04:00
|
|
|
if ((pixelIndex + runLengthFactor) > pixelCount)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1053;
|
2014-07-07 23:48:56 +04:00
|
|
|
|
2014-07-07 22:16:05 +04:00
|
|
|
for (i = 0; i < runLengthFactor; i++)
|
2014-07-02 02:21:51 +04:00
|
|
|
{
|
2014-07-07 22:16:05 +04:00
|
|
|
*pDstPixel32 = color;
|
|
|
|
pDstPixel32++;
|
|
|
|
}
|
2014-07-02 02:21:51 +04:00
|
|
|
|
2014-07-07 23:48:56 +04:00
|
|
|
pixelIndex += runLengthFactor;
|
|
|
|
|
|
|
|
if ((pixelIndex + (suiteDepth + 1)) > pixelCount)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1054;
|
2014-07-07 23:48:56 +04:00
|
|
|
|
2014-07-07 22:16:05 +04:00
|
|
|
for (i = 0; i <= suiteDepth; i++)
|
|
|
|
{
|
|
|
|
*pDstPixel32 = palette[suiteIndex++];
|
|
|
|
pDstPixel32++;
|
2014-07-02 02:21:51 +04:00
|
|
|
}
|
2014-07-07 22:16:05 +04:00
|
|
|
|
2014-07-07 23:48:56 +04:00
|
|
|
pixelIndex += (suiteDepth + 1);
|
2014-07-07 22:16:05 +04:00
|
|
|
}
|
|
|
|
|
2014-07-07 23:48:56 +04:00
|
|
|
nSrcStep = width * 4;
|
2014-07-07 22:16:05 +04:00
|
|
|
pSrcPixel8 = clear->TempBuffer;
|
|
|
|
pDstPixel8 = &pDstData[(nYDstRel * nDstStep) + (nXDstRel * 4)];
|
|
|
|
|
2014-07-07 23:48:56 +04:00
|
|
|
if (pixelIndex != pixelCount)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1055;
|
2014-07-07 22:16:05 +04:00
|
|
|
|
2014-07-07 23:48:56 +04:00
|
|
|
for (y = 0; y < height; y++)
|
2014-07-07 22:16:05 +04:00
|
|
|
{
|
|
|
|
CopyMemory(pDstPixel8, pSrcPixel8, nSrcStep);
|
|
|
|
pSrcPixel8 += nSrcStep;
|
|
|
|
pDstPixel8 += nDstStep;
|
|
|
|
pixelCount -= count;
|
2014-06-27 01:08:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1056;
|
2014-06-27 01:08:51 +04:00
|
|
|
}
|
|
|
|
|
2014-06-13 20:17:16 +04:00
|
|
|
suboffset += bitmapDataByteCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
offset += subcodecByteCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (glyphFlags & CLEARCODEC_FLAG_GLYPH_INDEX)
|
|
|
|
{
|
2014-07-08 19:37:27 +04:00
|
|
|
glyphEntry = &(clear->GlyphCache[glyphIndex]);
|
|
|
|
|
|
|
|
glyphEntry->count = nWidth * nHeight;
|
2014-07-01 17:55:52 +04:00
|
|
|
|
2014-07-08 19:37:27 +04:00
|
|
|
if (glyphEntry->count > glyphEntry->size)
|
|
|
|
{
|
2015-06-16 16:42:07 +03:00
|
|
|
UINT32 *tmp;
|
2014-07-08 19:37:27 +04:00
|
|
|
glyphEntry->size = glyphEntry->count;
|
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
tmp = (UINT32*) realloc(glyphEntry->pixels, glyphEntry->size * 4);
|
|
|
|
if (!tmp)
|
|
|
|
return -1;
|
|
|
|
glyphEntry->pixels = tmp;
|
2014-07-08 19:37:27 +04:00
|
|
|
}
|
2014-07-01 17:55:52 +04:00
|
|
|
|
2014-07-08 19:37:27 +04:00
|
|
|
if (!glyphEntry->pixels)
|
|
|
|
return -1057;
|
2014-07-01 17:55:52 +04:00
|
|
|
|
2014-07-08 19:37:27 +04:00
|
|
|
glyphData = (BYTE*) glyphEntry->pixels;
|
2014-07-01 17:55:52 +04:00
|
|
|
|
2014-07-02 21:45:19 +04:00
|
|
|
nSrcStep = nWidth * 4;
|
2014-07-02 22:51:46 +04:00
|
|
|
pDstPixel8 = glyphData;
|
|
|
|
pSrcPixel8 = &pDstData[(nYDst * nDstStep) + (nXDst * 4)];
|
|
|
|
|
2014-08-12 02:48:42 +04:00
|
|
|
for (y = 0; y < (UINT32) nHeight; y++)
|
2014-07-01 17:55:52 +04:00
|
|
|
{
|
2014-07-02 22:51:46 +04:00
|
|
|
CopyMemory(pDstPixel8, pSrcPixel8, nSrcStep);
|
|
|
|
pDstPixel8 += nSrcStep;
|
|
|
|
pSrcPixel8 += nDstStep;
|
2014-07-01 17:55:52 +04:00
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (offset != SrcSize)
|
2014-07-08 19:37:27 +04:00
|
|
|
return -1058;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2014-06-04 04:51:28 +04:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int clear_compress(CLEAR_CONTEXT* clear, BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData, UINT32* pDstSize)
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-03-01 18:17:28 +03:00
|
|
|
BOOL clear_context_reset(CLEAR_CONTEXT* clear)
|
2014-06-04 04:51:28 +04:00
|
|
|
{
|
2016-03-01 18:17:28 +03:00
|
|
|
if (!clear)
|
|
|
|
return FALSE;
|
|
|
|
|
2014-07-06 00:29:28 +04:00
|
|
|
clear->seqNumber = 0;
|
|
|
|
clear->VBarStorageCursor = 0;
|
|
|
|
clear->ShortVBarStorageCursor = 0;
|
2016-03-01 18:17:28 +03:00
|
|
|
|
|
|
|
return TRUE;
|
2014-06-04 04:51:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
CLEAR_CONTEXT* clear_context_new(BOOL Compressor)
|
|
|
|
{
|
|
|
|
CLEAR_CONTEXT* clear;
|
|
|
|
|
|
|
|
clear = (CLEAR_CONTEXT*) calloc(1, sizeof(CLEAR_CONTEXT));
|
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!clear)
|
|
|
|
return NULL;
|
2014-06-04 04:51:28 +04:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
clear->Compressor = Compressor;
|
2014-07-02 00:32:36 +04:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
clear->nsc = nsc_context_new();
|
|
|
|
if (!clear->nsc)
|
|
|
|
goto error_nsc;
|
2014-07-02 00:32:36 +04:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
nsc_context_set_pixel_format(clear->nsc, RDP_PIXEL_FORMAT_R8G8B8);
|
2014-07-02 00:32:36 +04:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
clear->TempSize = 512 * 512 * 4;
|
|
|
|
clear->TempBuffer = (BYTE*) malloc(clear->TempSize);
|
|
|
|
if (!clear->TempBuffer)
|
|
|
|
goto error_temp_buffer;
|
2014-07-07 22:16:05 +04:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
clear_context_reset(clear);
|
2014-06-04 04:51:28 +04:00
|
|
|
|
|
|
|
return clear;
|
2015-06-16 16:42:07 +03:00
|
|
|
|
|
|
|
error_temp_buffer:
|
|
|
|
nsc_context_free(clear->nsc);
|
|
|
|
error_nsc:
|
|
|
|
free(clear);
|
|
|
|
return NULL;
|
2014-06-04 04:51:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void clear_context_free(CLEAR_CONTEXT* clear)
|
|
|
|
{
|
2014-07-01 17:55:52 +04:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!clear)
|
|
|
|
return;
|
|
|
|
|
2014-07-02 00:32:36 +04:00
|
|
|
nsc_context_free(clear->nsc);
|
|
|
|
|
2014-07-07 22:16:05 +04:00
|
|
|
free(clear->TempBuffer);
|
|
|
|
|
2014-07-01 17:55:52 +04:00
|
|
|
for (i = 0; i < 4000; i++)
|
2014-07-08 19:37:27 +04:00
|
|
|
free(clear->GlyphCache[i].pixels);
|
2014-07-01 17:55:52 +04:00
|
|
|
|
2014-07-01 22:38:54 +04:00
|
|
|
for (i = 0; i < 32768; i++)
|
|
|
|
free(clear->VBarStorage[i].pixels);
|
|
|
|
|
|
|
|
for (i = 0; i < 16384; i++)
|
|
|
|
free(clear->ShortVBarStorage[i].pixels);
|
|
|
|
|
2014-07-01 17:55:52 +04:00
|
|
|
free(clear);
|
2014-06-04 04:51:28 +04:00
|
|
|
}
|
|
|
|
|