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>
|
2016-04-05 18:07:45 +03:00
|
|
|
* Copyright 2016 Armin Novak <armin.novak@thincast.com>
|
|
|
|
* Copyright 2016 Thincast Technologies GmbH
|
2014-06-04 04:51:28 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2022-02-16 13:20:38 +03:00
|
|
|
#include <freerdp/config.h>
|
2014-06-04 04:51:28 +04:00
|
|
|
|
|
|
|
#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>
|
2016-07-14 17:08:06 +03:00
|
|
|
#include <freerdp/log.h>
|
2014-06-04 04:51:28 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
#define TAG FREERDP_TAG("codec.clear")
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
#define CLEARCODEC_FLAG_GLYPH_INDEX 0x01
|
|
|
|
#define CLEARCODEC_FLAG_GLYPH_HIT 0x02
|
|
|
|
#define CLEARCODEC_FLAG_CACHE_RESET 0x04
|
2017-01-10 16:15:53 +03:00
|
|
|
|
|
|
|
#define CLEARCODEC_VBAR_SIZE 32768
|
|
|
|
#define CLEARCODEC_VBAR_SHORT_SIZE 16384
|
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2017-01-10 16:15:53 +03:00
|
|
|
{
|
|
|
|
UINT32 size;
|
|
|
|
UINT32 count;
|
|
|
|
UINT32* pixels;
|
2022-02-14 16:59:22 +03:00
|
|
|
} CLEAR_GLYPH_ENTRY;
|
2017-01-10 16:15:53 +03:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
typedef struct
|
2017-01-10 16:15:53 +03:00
|
|
|
{
|
|
|
|
UINT32 size;
|
|
|
|
UINT32 count;
|
|
|
|
BYTE* pixels;
|
2022-02-14 16:59:22 +03:00
|
|
|
} CLEAR_VBAR_ENTRY;
|
2017-01-10 16:15:53 +03:00
|
|
|
|
2022-02-14 16:59:22 +03:00
|
|
|
struct S_CLEAR_CONTEXT
|
2017-01-10 16:15:53 +03:00
|
|
|
{
|
|
|
|
BOOL Compressor;
|
|
|
|
NSC_CONTEXT* nsc;
|
|
|
|
UINT32 seqNumber;
|
|
|
|
BYTE* TempBuffer;
|
|
|
|
UINT32 TempSize;
|
|
|
|
UINT32 nTempStep;
|
|
|
|
UINT32 TempFormat;
|
|
|
|
UINT32 format;
|
|
|
|
CLEAR_GLYPH_ENTRY GlyphCache[4000];
|
|
|
|
UINT32 VBarStorageCursor;
|
|
|
|
CLEAR_VBAR_ENTRY VBarStorage[CLEARCODEC_VBAR_SIZE];
|
|
|
|
UINT32 ShortVBarStorageCursor;
|
|
|
|
CLEAR_VBAR_ENTRY ShortVBarStorage[CLEARCODEC_VBAR_SHORT_SIZE];
|
|
|
|
};
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static const 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
|
2014-06-27 01:08:51 +04:00
|
|
|
};
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static const BYTE CLEAR_8BIT_MASKS[9] = { 0x00, 0x01, 0x03, 0x07, 0x0F, 0x1F, 0x3F, 0x7F, 0xFF };
|
2014-06-27 01:08:51 +04:00
|
|
|
|
2022-06-20 16:54:46 +03:00
|
|
|
static void clear_reset_vbar_storage(CLEAR_CONTEXT* clear, BOOL zero)
|
2022-05-26 16:07:21 +03:00
|
|
|
{
|
2022-06-23 08:57:38 +03:00
|
|
|
if (zero)
|
|
|
|
{
|
2022-12-05 10:58:38 +03:00
|
|
|
for (size_t i = 0; i < ARRAYSIZE(clear->VBarStorage); i++)
|
2023-03-24 14:14:08 +03:00
|
|
|
winpr_aligned_free(clear->VBarStorage[i].pixels);
|
2022-05-26 16:07:21 +03:00
|
|
|
|
|
|
|
ZeroMemory(clear->VBarStorage, sizeof(clear->VBarStorage));
|
|
|
|
}
|
|
|
|
|
|
|
|
clear->VBarStorageCursor = 0;
|
|
|
|
|
2022-06-23 08:57:38 +03:00
|
|
|
if (zero)
|
|
|
|
{
|
2022-12-05 10:58:38 +03:00
|
|
|
for (size_t i = 0; i < ARRAYSIZE(clear->ShortVBarStorage); i++)
|
2023-03-24 14:14:08 +03:00
|
|
|
winpr_aligned_free(clear->ShortVBarStorage[i].pixels);
|
2022-05-26 16:07:21 +03:00
|
|
|
|
|
|
|
ZeroMemory(clear->ShortVBarStorage, sizeof(clear->ShortVBarStorage));
|
|
|
|
}
|
|
|
|
|
|
|
|
clear->ShortVBarStorageCursor = 0;
|
|
|
|
}
|
|
|
|
|
2022-06-20 16:54:46 +03:00
|
|
|
static void clear_reset_glyph_cache(CLEAR_CONTEXT* clear)
|
2022-05-26 16:07:21 +03:00
|
|
|
{
|
2022-12-05 10:58:38 +03:00
|
|
|
for (size_t i = 0; i < ARRAYSIZE(clear->GlyphCache); i++)
|
2023-03-24 14:14:08 +03:00
|
|
|
winpr_aligned_free(clear->GlyphCache[i].pixels);
|
2022-05-26 16:07:21 +03:00
|
|
|
|
|
|
|
ZeroMemory(clear->GlyphCache, sizeof(clear->GlyphCache));
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL convert_color(BYTE* dst, UINT32 nDstStep, UINT32 DstFormat, UINT32 nXDst, UINT32 nYDst,
|
|
|
|
UINT32 nWidth, UINT32 nHeight, const BYTE* src, UINT32 nSrcStep,
|
|
|
|
UINT32 SrcFormat, UINT32 nDstWidth, UINT32 nDstHeight,
|
|
|
|
const gdiPalette* palette)
|
2014-06-04 04:51:28 +04:00
|
|
|
{
|
2016-04-14 00:06:33 +03:00
|
|
|
if (nWidth + nXDst > nDstWidth)
|
|
|
|
nWidth = nDstWidth - nXDst;
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2016-04-14 00:06:33 +03:00
|
|
|
if (nHeight + nYDst > nDstHeight)
|
|
|
|
nHeight = nDstHeight - nYDst;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
return freerdp_image_copy(dst, DstFormat, nDstStep, nXDst, nYDst, nWidth, nHeight, src,
|
2023-01-09 10:07:43 +03:00
|
|
|
SrcFormat, nSrcStep, 0, 0, palette, FREERDP_KEEP_DST_ALPHA);
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL clear_decompress_nscodec(NSC_CONTEXT* nsc, UINT32 width, UINT32 height, wStream* s,
|
|
|
|
UINT32 bitmapDataByteCount, BYTE* pDstData, UINT32 DstFormat,
|
|
|
|
UINT32 nDstStep, UINT32 nXDstRel, UINT32 nYDstRel)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BOOL rc = 0;
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, bitmapDataByteCount))
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
rc = nsc_process_message(nsc, 32, width, height, Stream_Pointer(s), bitmapDataByteCount,
|
|
|
|
pDstData, DstFormat, nDstStep, nXDstRel, nYDstRel, width, height,
|
|
|
|
FREERDP_FLIP_NONE);
|
2016-07-14 17:08:06 +03:00
|
|
|
Stream_Seek(s, bitmapDataByteCount);
|
|
|
|
return rc;
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2014-07-06 00:29:28 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL clear_decompress_subcode_rlex(wStream* s, UINT32 bitmapDataByteCount, UINT32 width,
|
|
|
|
UINT32 height, BYTE* pDstData, UINT32 DstFormat,
|
|
|
|
UINT32 nDstStep, UINT32 nXDstRel, UINT32 nYDstRel,
|
|
|
|
UINT32 nDstWidth, UINT32 nDstHeight)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 x = 0;
|
|
|
|
UINT32 y = 0;
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 pixelCount = 0;
|
|
|
|
UINT32 bitmapDataOffset = 0;
|
|
|
|
size_t pixelIndex = 0;
|
|
|
|
UINT32 numBits = 0;
|
|
|
|
BYTE startIndex = 0;
|
|
|
|
BYTE stopIndex = 0;
|
|
|
|
BYTE suiteIndex = 0;
|
|
|
|
BYTE suiteDepth = 0;
|
|
|
|
BYTE paletteCount = 0;
|
2016-08-10 11:29:59 +03:00
|
|
|
UINT32 palette[128] = { 0 };
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, bitmapDataByteCount))
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
|
2020-04-21 11:35:17 +03:00
|
|
|
return FALSE;
|
2016-07-14 17:08:06 +03:00
|
|
|
Stream_Read_UINT8(s, paletteCount);
|
2016-04-05 18:07:45 +03:00
|
|
|
bitmapDataOffset = 1 + (paletteCount * 3);
|
|
|
|
|
2019-01-28 12:55:56 +03:00
|
|
|
if ((paletteCount > 127) || (paletteCount < 1))
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "paletteCount %" PRIu8 "", paletteCount);
|
2016-04-14 00:06:33 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2023-01-24 16:53:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, paletteCount, 3ull))
|
2020-04-21 11:35:17 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 i = 0; i < paletteCount; i++)
|
2014-07-01 22:38:54 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE r = 0;
|
|
|
|
BYTE g = 0;
|
|
|
|
BYTE b = 0;
|
2016-07-14 17:08:06 +03:00
|
|
|
Stream_Read_UINT8(s, b);
|
|
|
|
Stream_Read_UINT8(s, g);
|
|
|
|
Stream_Read_UINT8(s, r);
|
2017-11-24 15:19:48 +03:00
|
|
|
palette[i] = FreeRDPGetColor(DstFormat, r, g, b, 0xFF);
|
2014-07-01 22:38:54 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
pixelIndex = 0;
|
|
|
|
pixelCount = width * height;
|
|
|
|
numBits = CLEAR_LOG2_FLOOR[paletteCount - 1] + 1;
|
2014-07-02 02:21:51 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
while (bitmapDataOffset < bitmapDataByteCount)
|
2014-06-13 20:17:16 +04:00
|
|
|
{
|
2023-06-05 13:16:57 +03:00
|
|
|
UINT32 tmp = 0;
|
|
|
|
UINT32 color = 0;
|
|
|
|
UINT32 runLengthFactor = 0;
|
2014-07-01 17:55:52 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
|
2016-04-05 18:07:45 +03:00
|
|
|
return FALSE;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
Stream_Read_UINT8(s, tmp);
|
|
|
|
Stream_Read_UINT8(s, runLengthFactor);
|
|
|
|
bitmapDataOffset += 2;
|
|
|
|
suiteDepth = (tmp >> numBits) & CLEAR_8BIT_MASKS[(8 - numBits)];
|
|
|
|
stopIndex = tmp & CLEAR_8BIT_MASKS[numBits];
|
2016-04-05 18:07:45 +03:00
|
|
|
startIndex = stopIndex - suiteDepth;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (runLengthFactor >= 0xFF)
|
2014-06-13 20:17:16 +04:00
|
|
|
{
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
|
2016-04-05 18:07:45 +03:00
|
|
|
return FALSE;
|
2014-07-01 17:55:52 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
Stream_Read_UINT16(s, runLengthFactor);
|
2016-04-05 18:07:45 +03:00
|
|
|
bitmapDataOffset += 2;
|
2014-07-01 17:55:52 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (runLengthFactor >= 0xFFFF)
|
2014-07-01 17:55:52 +04:00
|
|
|
{
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
2016-04-05 18:07:45 +03:00
|
|
|
return FALSE;
|
2014-07-01 17:55:52 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
Stream_Read_UINT32(s, runLengthFactor);
|
2016-04-05 18:07:45 +03:00
|
|
|
bitmapDataOffset += 4;
|
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (startIndex >= paletteCount)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "startIndex %" PRIu8 " > paletteCount %" PRIu8 "]", startIndex,
|
|
|
|
paletteCount);
|
2016-04-05 18:07:45 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (stopIndex >= paletteCount)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "stopIndex %" PRIu8 " > paletteCount %" PRIu8 "]", stopIndex,
|
|
|
|
paletteCount);
|
2016-04-05 18:07:45 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
suiteIndex = startIndex;
|
2016-08-10 11:29:59 +03:00
|
|
|
|
|
|
|
if (suiteIndex > 127)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "suiteIndex %" PRIu8 " > 127]", suiteIndex);
|
2016-08-10 11:29:59 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2016-08-10 11:29:59 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
color = palette[suiteIndex];
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if ((pixelIndex + runLengthFactor) > pixelCount)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG,
|
|
|
|
"pixelIndex %" PRIu32 " + runLengthFactor %" PRIu32 " > pixelCount %" PRIu32
|
|
|
|
"",
|
|
|
|
pixelIndex, runLengthFactor, pixelCount);
|
2016-04-05 18:07:45 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 i = 0; i < runLengthFactor; i++)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2022-04-28 06:43:31 +03:00
|
|
|
BYTE* pTmpData = &pDstData[(nXDstRel + x) * FreeRDPGetBytesPerPixel(DstFormat) +
|
|
|
|
(nYDstRel + y) * nDstStep];
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2016-04-14 00:06:33 +03:00
|
|
|
if ((nXDstRel + x < nDstWidth) && (nYDstRel + y < nDstHeight))
|
2022-04-28 06:43:31 +03:00
|
|
|
FreeRDPWriteColor(pTmpData, DstFormat, color);
|
2016-04-14 00:06:33 +03:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if (++x >= width)
|
|
|
|
{
|
2016-04-14 00:06:33 +03:00
|
|
|
y++;
|
|
|
|
x = 0;
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
pixelIndex += runLengthFactor;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if ((pixelIndex + (suiteDepth + 1)) > pixelCount)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG,
|
|
|
|
"pixelIndex %" PRIu32 " + suiteDepth %" PRIu8 " + 1 > pixelCount %" PRIu32 "",
|
|
|
|
pixelIndex, suiteDepth, pixelCount);
|
2016-04-05 18:07:45 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 i = 0; i <= suiteDepth; i++)
|
2014-07-07 23:48:56 +04:00
|
|
|
{
|
2022-04-28 06:43:31 +03:00
|
|
|
BYTE* pTmpData = &pDstData[(nXDstRel + x) * FreeRDPGetBytesPerPixel(DstFormat) +
|
|
|
|
(nYDstRel + y) * nDstStep];
|
2021-07-29 11:07:04 +03:00
|
|
|
UINT32 ccolor = palette[suiteIndex];
|
2016-08-10 11:29:59 +03:00
|
|
|
|
|
|
|
if (suiteIndex > 127)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "suiteIndex %" PRIu8 " > 127", suiteIndex);
|
2016-08-10 11:29:59 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2016-08-10 11:29:59 +03:00
|
|
|
|
|
|
|
suiteIndex++;
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2016-04-14 00:06:33 +03:00
|
|
|
if ((nXDstRel + x < nDstWidth) && (nYDstRel + y < nDstHeight))
|
2022-04-28 06:43:31 +03:00
|
|
|
FreeRDPWriteColor(pTmpData, DstFormat, ccolor);
|
2016-04-14 00:06:33 +03:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if (++x >= width)
|
|
|
|
{
|
2016-04-14 00:06:33 +03:00
|
|
|
y++;
|
|
|
|
x = 0;
|
|
|
|
}
|
2014-07-07 23:48:56 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
pixelIndex += (suiteDepth + 1);
|
|
|
|
}
|
2014-07-02 02:21:51 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (pixelIndex != pixelCount)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2020-04-21 11:35:17 +03:00
|
|
|
WLog_ERR(TAG, "pixelIndex %" PRIdz " != pixelCount %" PRIu32 "", pixelIndex, pixelCount);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2014-09-17 00:55:47 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2017-01-10 16:15:53 +03:00
|
|
|
static BOOL clear_resize_buffer(CLEAR_CONTEXT* clear, UINT32 width, UINT32 height)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 size = 0;
|
2017-01-10 16:15:53 +03:00
|
|
|
|
|
|
|
if (!clear)
|
|
|
|
return FALSE;
|
|
|
|
|
2022-04-28 06:43:31 +03:00
|
|
|
size = ((width + 16) * (height + 16) * FreeRDPGetBytesPerPixel(clear->format));
|
2017-01-10 16:15:53 +03:00
|
|
|
|
|
|
|
if (size > clear->TempSize)
|
|
|
|
{
|
2023-03-24 14:14:08 +03:00
|
|
|
BYTE* tmp = (BYTE*)winpr_aligned_recalloc(clear->TempBuffer, size, sizeof(BYTE), 32);
|
2017-01-10 16:15:53 +03:00
|
|
|
|
|
|
|
if (!tmp)
|
|
|
|
{
|
2023-03-24 14:14:08 +03:00
|
|
|
WLog_ERR(TAG, "clear->TempBuffer winpr_aligned_recalloc failed for %" PRIu32 " bytes",
|
|
|
|
size);
|
2017-01-10 16:15:53 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
clear->TempSize = size;
|
|
|
|
clear->TempBuffer = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL clear_decompress_residual_data(CLEAR_CONTEXT* clear, wStream* s,
|
|
|
|
UINT32 residualByteCount, UINT32 nWidth, UINT32 nHeight,
|
|
|
|
BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep,
|
|
|
|
UINT32 nXDst, UINT32 nYDst, UINT32 nDstWidth,
|
|
|
|
UINT32 nDstHeight, const gdiPalette* palette)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 nSrcStep = 0;
|
|
|
|
UINT32 suboffset = 0;
|
|
|
|
BYTE* dstBuffer = NULL;
|
|
|
|
UINT32 pixelIndex = 0;
|
|
|
|
UINT32 pixelCount = 0;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, residualByteCount))
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
suboffset = 0;
|
|
|
|
pixelIndex = 0;
|
|
|
|
pixelCount = nWidth * nHeight;
|
2017-01-10 16:15:53 +03:00
|
|
|
|
|
|
|
if (!clear_resize_buffer(clear, nWidth, nHeight))
|
|
|
|
return FALSE;
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
dstBuffer = clear->TempBuffer;
|
|
|
|
|
|
|
|
while (suboffset < residualByteCount)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE r = 0;
|
|
|
|
BYTE g = 0;
|
|
|
|
BYTE b = 0;
|
|
|
|
UINT32 runLengthFactor = 0;
|
|
|
|
UINT32 color = 0;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
Stream_Read_UINT8(s, b);
|
|
|
|
Stream_Read_UINT8(s, g);
|
|
|
|
Stream_Read_UINT8(s, r);
|
|
|
|
Stream_Read_UINT8(s, runLengthFactor);
|
|
|
|
suboffset += 4;
|
2017-11-24 15:19:48 +03:00
|
|
|
color = FreeRDPGetColor(clear->format, r, g, b, 0xFF);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
|
|
|
if (runLengthFactor >= 0xFF)
|
|
|
|
{
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2014-06-26 02:39:28 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
Stream_Read_UINT16(s, runLengthFactor);
|
2016-04-05 18:07:45 +03:00
|
|
|
suboffset += 2;
|
2014-06-27 01:08:51 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (runLengthFactor >= 0xFFFF)
|
2014-06-27 01:08:51 +04:00
|
|
|
{
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 4))
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2014-06-26 02:39:28 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
Stream_Read_UINT32(s, runLengthFactor);
|
2016-04-05 18:07:45 +03:00
|
|
|
suboffset += 4;
|
|
|
|
}
|
2014-06-26 02:39:28 +04:00
|
|
|
}
|
|
|
|
|
2024-04-16 09:35:05 +03:00
|
|
|
if ((pixelIndex >= pixelCount) || (runLengthFactor > (pixelCount - pixelIndex)))
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG,
|
|
|
|
"pixelIndex %" PRIu32 " + runLengthFactor %" PRIu32 " > pixelCount %" PRIu32
|
|
|
|
"",
|
|
|
|
pixelIndex, runLengthFactor, pixelCount);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2014-07-07 23:48:56 +04:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 i = 0; i < runLengthFactor; i++)
|
2014-07-07 23:48:56 +04:00
|
|
|
{
|
2022-04-28 06:43:31 +03:00
|
|
|
FreeRDPWriteColor(dstBuffer, clear->format, color);
|
|
|
|
dstBuffer += FreeRDPGetBytesPerPixel(clear->format);
|
2014-07-07 23:48:56 +04:00
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
pixelIndex += runLengthFactor;
|
2014-06-13 20:17:16 +04:00
|
|
|
}
|
|
|
|
|
2022-04-28 06:43:31 +03:00
|
|
|
nSrcStep = nWidth * FreeRDPGetBytesPerPixel(clear->format);
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (pixelIndex != pixelCount)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "pixelIndex %" PRIu32 " != pixelCount %" PRIu32 "", pixelIndex, pixelCount);
|
2016-10-20 12:09:37 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
return convert_color(pDstData, nDstStep, DstFormat, nXDst, nYDst, nWidth, nHeight,
|
|
|
|
clear->TempBuffer, nSrcStep, clear->format, nDstWidth, nDstHeight,
|
|
|
|
palette);
|
2016-07-14 17:08:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL clear_decompress_subcodecs_data(CLEAR_CONTEXT* clear, wStream* s,
|
2019-11-06 17:24:51 +03:00
|
|
|
UINT32 subcodecByteCount, UINT32 nWidth, UINT32 nHeight,
|
|
|
|
BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep,
|
|
|
|
UINT32 nXDst, UINT32 nYDst, UINT32 nDstWidth,
|
|
|
|
UINT32 nDstHeight, const gdiPalette* palette)
|
2016-07-14 17:08:06 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT16 xStart = 0;
|
|
|
|
UINT16 yStart = 0;
|
|
|
|
UINT16 width = 0;
|
|
|
|
UINT16 height = 0;
|
|
|
|
UINT32 bitmapDataByteCount = 0;
|
|
|
|
BYTE subcodecId = 0;
|
|
|
|
UINT32 suboffset = 0;
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, subcodecByteCount))
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
suboffset = 0;
|
|
|
|
|
|
|
|
while (suboffset < subcodecByteCount)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 nXDstRel = 0;
|
|
|
|
UINT32 nYDstRel = 0;
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 13))
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
Stream_Read_UINT16(s, xStart);
|
|
|
|
Stream_Read_UINT16(s, yStart);
|
|
|
|
Stream_Read_UINT16(s, width);
|
|
|
|
Stream_Read_UINT16(s, height);
|
|
|
|
Stream_Read_UINT32(s, bitmapDataByteCount);
|
|
|
|
Stream_Read_UINT8(s, subcodecId);
|
|
|
|
suboffset += 13;
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, bitmapDataByteCount))
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
nXDstRel = nXDst + xStart;
|
|
|
|
nYDstRel = nYDst + yStart;
|
|
|
|
|
2024-04-24 14:56:28 +03:00
|
|
|
if (1ull * xStart + width > nWidth)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2024-04-24 14:56:28 +03:00
|
|
|
WLog_ERR(TAG, "xStart %" PRIu16 " + width %" PRIu16 " > nWidth %" PRIu32 "", xStart,
|
|
|
|
width, nWidth);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2024-04-24 14:56:28 +03:00
|
|
|
if (1ull * yStart + height > nHeight)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2024-04-24 14:56:28 +03:00
|
|
|
WLog_ERR(TAG, "yStart %" PRIu16 " + height %" PRIu16 " > nHeight %" PRIu32 "", yStart,
|
|
|
|
height, nHeight);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2017-01-10 16:15:53 +03:00
|
|
|
if (!clear_resize_buffer(clear, width, height))
|
|
|
|
return FALSE;
|
2016-07-14 17:08:06 +03:00
|
|
|
|
|
|
|
switch (subcodecId)
|
|
|
|
{
|
|
|
|
case 0: /* Uncompressed */
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2024-04-20 18:40:33 +03:00
|
|
|
const UINT32 nSrcStep = width * FreeRDPGetBytesPerPixel(PIXEL_FORMAT_BGR24);
|
|
|
|
const size_t nSrcSize = 1ull * nSrcStep * height;
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (bitmapDataByteCount != nSrcSize)
|
|
|
|
{
|
2024-04-20 18:40:33 +03:00
|
|
|
WLog_ERR(TAG, "bitmapDataByteCount %" PRIu32 " != nSrcSize %" PRIuz "",
|
2019-11-06 17:24:51 +03:00
|
|
|
bitmapDataByteCount, nSrcSize);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-10-20 12:09:37 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!convert_color(pDstData, nDstStep, DstFormat, nXDstRel, nYDstRel, width, height,
|
|
|
|
Stream_Pointer(s), nSrcStep, PIXEL_FORMAT_BGR24, nDstWidth,
|
|
|
|
nDstHeight, palette))
|
|
|
|
return FALSE;
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
Stream_Seek(s, bitmapDataByteCount);
|
|
|
|
}
|
|
|
|
break;
|
2016-07-14 17:08:06 +03:00
|
|
|
|
|
|
|
case 1: /* NSCodec */
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!clear_decompress_nscodec(clear->nsc, width, height, s, bitmapDataByteCount,
|
|
|
|
pDstData, DstFormat, nDstStep, nXDstRel, nYDstRel))
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2: /* CLEARCODEC_SUBCODEC_RLEX */
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!clear_decompress_subcode_rlex(s, bitmapDataByteCount, width, height, pDstData,
|
|
|
|
DstFormat, nDstStep, nXDstRel, nYDstRel,
|
2016-07-14 17:08:06 +03:00
|
|
|
nDstWidth, nDstHeight))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Unknown subcodec ID %" PRIu8 "", subcodecId);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
suboffset += bitmapDataByteCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL resize_vbar_entry(CLEAR_CONTEXT* clear, CLEAR_VBAR_ENTRY* vBarEntry)
|
|
|
|
{
|
|
|
|
if (vBarEntry->count > vBarEntry->size)
|
|
|
|
{
|
2022-04-28 06:43:31 +03:00
|
|
|
const UINT32 bpp = FreeRDPGetBytesPerPixel(clear->format);
|
2016-07-14 18:39:39 +03:00
|
|
|
const UINT32 oldPos = vBarEntry->size * bpp;
|
|
|
|
const UINT32 diffSize = (vBarEntry->count - vBarEntry->size) * bpp;
|
2023-06-05 13:16:57 +03:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
vBarEntry->size = vBarEntry->count;
|
2023-06-05 13:16:57 +03:00
|
|
|
BYTE* tmp =
|
2023-08-22 10:41:28 +03:00
|
|
|
(BYTE*)winpr_aligned_recalloc(vBarEntry->pixels, vBarEntry->count, 1ull * bpp, 32);
|
2016-07-14 17:08:06 +03:00
|
|
|
|
|
|
|
if (!tmp)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2023-03-24 14:14:08 +03:00
|
|
|
WLog_ERR(TAG, "vBarEntry->pixels winpr_aligned_recalloc %" PRIu32 " failed",
|
|
|
|
vBarEntry->count * bpp);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2016-07-14 18:39:39 +03:00
|
|
|
memset(&tmp[oldPos], 0, diffSize);
|
2016-07-14 17:08:06 +03:00
|
|
|
vBarEntry->pixels = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!vBarEntry->pixels && vBarEntry->size)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "vBarEntry->pixels is NULL but vBarEntry->size is %" PRIu32 "",
|
2016-12-14 00:47:08 +03:00
|
|
|
vBarEntry->size);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL clear_decompress_bands_data(CLEAR_CONTEXT* clear, wStream* s, UINT32 bandsByteCount,
|
|
|
|
UINT32 nWidth, UINT32 nHeight, BYTE* pDstData,
|
|
|
|
UINT32 DstFormat, UINT32 nDstStep, UINT32 nXDst,
|
2023-08-22 15:44:57 +03:00
|
|
|
UINT32 nYDst, UINT32 nDstWidth, UINT32 nDstHeight)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2023-08-22 15:44:57 +03:00
|
|
|
UINT32 suboffset = 0;
|
2014-09-17 00:55:47 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, bandsByteCount))
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
|
|
|
while (suboffset < bandsByteCount)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE cr = 0;
|
|
|
|
BYTE cg = 0;
|
|
|
|
BYTE cb = 0;
|
|
|
|
UINT16 xStart = 0;
|
|
|
|
UINT16 xEnd = 0;
|
|
|
|
UINT16 yStart = 0;
|
|
|
|
UINT16 yEnd = 0;
|
|
|
|
UINT32 colorBkg = 0;
|
|
|
|
UINT16 vBarHeader = 0;
|
2021-09-08 16:47:03 +03:00
|
|
|
UINT16 vBarYOn = 0;
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT16 vBarYOff = 0;
|
|
|
|
UINT32 vBarCount = 0;
|
|
|
|
UINT32 vBarPixelCount = 0;
|
2021-09-08 16:47:03 +03:00
|
|
|
UINT32 vBarShortPixelCount = 0;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 11))
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
Stream_Read_UINT16(s, xStart);
|
|
|
|
Stream_Read_UINT16(s, xEnd);
|
|
|
|
Stream_Read_UINT16(s, yStart);
|
|
|
|
Stream_Read_UINT16(s, yEnd);
|
2021-07-29 11:07:04 +03:00
|
|
|
Stream_Read_UINT8(s, cb);
|
|
|
|
Stream_Read_UINT8(s, cg);
|
|
|
|
Stream_Read_UINT8(s, cr);
|
2016-07-14 17:08:06 +03:00
|
|
|
suboffset += 11;
|
2021-07-29 11:07:04 +03:00
|
|
|
colorBkg = FreeRDPGetColor(clear->format, cr, cg, cb, 0xFF);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
|
|
|
if (xEnd < xStart)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "xEnd %" PRIu16 " < xStart %" PRIu16 "", xEnd, xStart);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
|
|
|
if (yEnd < yStart)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "yEnd %" PRIu16 " < yStart %" PRIu16 "", yEnd, yStart);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
|
|
|
vBarCount = (xEnd - xStart) + 1;
|
|
|
|
|
2023-08-22 15:44:57 +03:00
|
|
|
for (UINT32 i = 0; i < vBarCount; i++)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 vBarHeight = 0;
|
2016-07-14 18:39:39 +03:00
|
|
|
CLEAR_VBAR_ENTRY* vBarEntry = NULL;
|
2021-09-08 16:47:03 +03:00
|
|
|
CLEAR_VBAR_ENTRY* vBarShortEntry = NULL;
|
2016-07-14 17:08:06 +03:00
|
|
|
BOOL vBarUpdate = FALSE;
|
2024-01-23 18:49:54 +03:00
|
|
|
const BYTE* cpSrcPixel = NULL;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2014-07-02 02:21:51 +04:00
|
|
|
|
2016-12-05 15:43:45 +03:00
|
|
|
Stream_Read_UINT16(s, vBarHeader);
|
2016-04-05 18:07:45 +03:00
|
|
|
suboffset += 2;
|
|
|
|
vBarHeight = (yEnd - yStart + 1);
|
2014-07-02 02:21:51 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (vBarHeight > 52)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "vBarHeight (%" PRIu32 ") > 52", vBarHeight);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if ((vBarHeader & 0xC000) == 0x4000) /* SHORT_VBAR_CACHE_HIT */
|
2014-06-13 20:17:16 +04:00
|
|
|
{
|
2018-09-19 13:03:07 +03:00
|
|
|
const UINT16 vBarIndex = (vBarHeader & 0x3FFF);
|
2016-07-14 18:39:39 +03:00
|
|
|
vBarShortEntry = &(clear->ShortVBarStorage[vBarIndex]);
|
2014-06-14 01:30:13 +04:00
|
|
|
|
2016-07-14 18:39:39 +03:00
|
|
|
if (!vBarShortEntry)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "missing vBarShortEntry %" PRIu16 "", vBarIndex);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2014-06-14 01:30:13 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 1))
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
Stream_Read_UINT8(s, vBarYOn);
|
2016-04-05 18:07:45 +03:00
|
|
|
suboffset += 1;
|
|
|
|
vBarShortPixelCount = vBarShortEntry->count;
|
|
|
|
vBarUpdate = TRUE;
|
|
|
|
}
|
|
|
|
else if ((vBarHeader & 0xC000) == 0x0000) /* SHORT_VBAR_CACHE_MISS */
|
|
|
|
{
|
|
|
|
vBarYOn = (vBarHeader & 0xFF);
|
|
|
|
vBarYOff = ((vBarHeader >> 8) & 0x3F);
|
2014-06-14 01:30:13 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (vBarYOff < vBarYOn)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "vBarYOff %" PRIu16 " < vBarYOn %" PRIu16 "", vBarYOff, vBarYOn);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
vBarShortPixelCount = (vBarYOff - vBarYOn);
|
2014-06-14 01:30:13 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (vBarShortPixelCount > 52)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "vBarShortPixelCount %" PRIu32 " > 52", vBarShortPixelCount);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2014-06-14 01:30:13 +04:00
|
|
|
|
2023-01-24 16:53:36 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLengthOfSize(TAG, s, vBarShortPixelCount, 3ull))
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2016-07-14 18:39:39 +03:00
|
|
|
if (clear->ShortVBarStorageCursor >= CLEARCODEC_VBAR_SHORT_SIZE)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG,
|
2019-11-06 17:24:51 +03:00
|
|
|
"clear->ShortVBarStorageCursor %" PRIu32
|
|
|
|
" >= CLEARCODEC_VBAR_SHORT_SIZE (%" PRIu32 ")",
|
2016-10-20 12:09:37 +03:00
|
|
|
clear->ShortVBarStorageCursor, CLEARCODEC_VBAR_SHORT_SIZE);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2014-07-02 00:32:36 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
vBarShortEntry = &(clear->ShortVBarStorage[clear->ShortVBarStorageCursor]);
|
|
|
|
vBarShortEntry->count = vBarShortPixelCount;
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if (!resize_vbar_entry(clear, vBarShortEntry))
|
|
|
|
return FALSE;
|
2014-06-14 01:30:13 +04:00
|
|
|
|
2023-08-22 15:44:57 +03:00
|
|
|
for (UINT32 y = 0; y < vBarShortPixelCount; y++)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE r = 0;
|
|
|
|
BYTE g = 0;
|
|
|
|
BYTE b = 0;
|
2022-04-28 06:43:31 +03:00
|
|
|
BYTE* dstBuffer =
|
|
|
|
&vBarShortEntry->pixels[y * FreeRDPGetBytesPerPixel(clear->format)];
|
2023-08-22 15:44:57 +03:00
|
|
|
UINT32 color = 0;
|
2016-07-14 17:08:06 +03:00
|
|
|
Stream_Read_UINT8(s, b);
|
|
|
|
Stream_Read_UINT8(s, g);
|
|
|
|
Stream_Read_UINT8(s, r);
|
2017-11-24 15:19:48 +03:00
|
|
|
color = FreeRDPGetColor(clear->format, r, g, b, 0xFF);
|
2016-10-20 12:09:37 +03:00
|
|
|
|
2022-04-28 06:43:31 +03:00
|
|
|
if (!FreeRDPWriteColor(dstBuffer, clear->format, color))
|
2016-10-20 12:09:37 +03:00
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2014-06-14 01:30:13 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
suboffset += (vBarShortPixelCount * 3);
|
2016-07-14 18:39:39 +03:00
|
|
|
clear->ShortVBarStorageCursor =
|
|
|
|
(clear->ShortVBarStorageCursor + 1) % CLEARCODEC_VBAR_SHORT_SIZE;
|
2016-04-05 18:07:45 +03:00
|
|
|
vBarUpdate = TRUE;
|
|
|
|
}
|
|
|
|
else if ((vBarHeader & 0x8000) == 0x8000) /* VBAR_CACHE_HIT */
|
|
|
|
{
|
2018-09-19 13:03:07 +03:00
|
|
|
const UINT16 vBarIndex = (vBarHeader & 0x7FFF);
|
2016-04-05 18:07:45 +03:00
|
|
|
vBarEntry = &(clear->VBarStorage[vBarIndex]);
|
2018-09-19 13:03:07 +03:00
|
|
|
|
|
|
|
/* If the cache was reset we need to fill in some dummy data. */
|
|
|
|
if (vBarEntry->size == 0)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_WARN(TAG, "Empty cache index %" PRIu16 ", filling dummy data", vBarIndex);
|
2018-09-19 13:03:07 +03:00
|
|
|
vBarEntry->count = vBarHeight;
|
|
|
|
|
|
|
|
if (!resize_vbar_entry(clear, vBarEntry))
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "invalid vBarHeader 0x%04" PRIX16 "", vBarHeader);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE; /* invalid vBarHeader */
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2014-07-06 00:29:28 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (vBarUpdate)
|
|
|
|
{
|
2020-05-18 18:40:28 +03:00
|
|
|
BYTE* pSrcPixel = NULL;
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE* dstBuffer = NULL;
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2016-07-14 18:39:39 +03:00
|
|
|
if (clear->VBarStorageCursor >= CLEARCODEC_VBAR_SIZE)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG,
|
|
|
|
"clear->VBarStorageCursor %" PRIu32 " >= CLEARCODEC_VBAR_SIZE %" PRIu32
|
|
|
|
"",
|
|
|
|
clear->VBarStorageCursor, CLEARCODEC_VBAR_SIZE);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
vBarEntry = &(clear->VBarStorage[clear->VBarStorageCursor]);
|
|
|
|
vBarPixelCount = vBarHeight;
|
|
|
|
vBarEntry->count = vBarPixelCount;
|
2014-07-08 19:37:27 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if (!resize_vbar_entry(clear, vBarEntry))
|
|
|
|
return FALSE;
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
dstBuffer = vBarEntry->pixels;
|
|
|
|
/* if (y < vBarYOn), use colorBkg */
|
2023-08-22 15:44:57 +03:00
|
|
|
UINT32 y = 0;
|
|
|
|
UINT32 count = vBarYOn;
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if ((y + count) > vBarPixelCount)
|
|
|
|
count = (vBarPixelCount > y) ? (vBarPixelCount - y) : 0;
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
while (count--)
|
2014-07-06 00:29:28 +04:00
|
|
|
{
|
2022-04-28 06:43:31 +03:00
|
|
|
FreeRDPWriteColor(dstBuffer, clear->format, colorBkg);
|
|
|
|
dstBuffer += FreeRDPGetBytesPerPixel(clear->format);
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2014-07-06 00:29:28 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
/*
|
|
|
|
* if ((y >= vBarYOn) && (y < (vBarYOn + vBarShortPixelCount))),
|
|
|
|
* use vBarShortPixels at index (y - shortVBarYOn)
|
|
|
|
*/
|
|
|
|
y = vBarYOn;
|
|
|
|
count = vBarShortPixelCount;
|
2014-07-06 00:29:28 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if ((y + count) > vBarPixelCount)
|
|
|
|
count = (vBarPixelCount > y) ? (vBarPixelCount - y) : 0;
|
|
|
|
|
2020-05-18 18:40:28 +03:00
|
|
|
if (count > 0)
|
2024-04-20 18:16:35 +03:00
|
|
|
{
|
2024-04-20 18:40:33 +03:00
|
|
|
const size_t offset =
|
|
|
|
(1ull * y - vBarYOn) * FreeRDPGetBytesPerPixel(clear->format);
|
2024-04-20 18:16:35 +03:00
|
|
|
pSrcPixel = &vBarShortEntry->pixels[offset];
|
|
|
|
if (offset + count > vBarShortEntry->count)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "offset + count > vBarShortEntry->count");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 x = 0; x < count; x++)
|
2014-06-14 01:30:13 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 color = 0;
|
2022-04-28 06:43:31 +03:00
|
|
|
color = FreeRDPReadColor(&pSrcPixel[x * FreeRDPGetBytesPerPixel(clear->format)],
|
|
|
|
clear->format);
|
2016-10-20 12:09:37 +03:00
|
|
|
|
2022-04-28 06:43:31 +03:00
|
|
|
if (!FreeRDPWriteColor(dstBuffer, clear->format, color))
|
2016-10-20 12:09:37 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2022-04-28 06:43:31 +03:00
|
|
|
dstBuffer += FreeRDPGetBytesPerPixel(clear->format);
|
2014-06-14 01:30:13 +04:00
|
|
|
}
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
/* if (y >= (vBarYOn + vBarShortPixelCount)), use colorBkg */
|
|
|
|
y = vBarYOn + vBarShortPixelCount;
|
|
|
|
count = (vBarPixelCount > y) ? (vBarPixelCount - y) : 0;
|
|
|
|
|
|
|
|
while (count--)
|
2014-07-01 22:38:54 +04:00
|
|
|
{
|
2022-04-28 06:43:31 +03:00
|
|
|
if (!FreeRDPWriteColor(dstBuffer, clear->format, colorBkg))
|
2016-10-20 12:09:37 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2022-04-28 06:43:31 +03:00
|
|
|
dstBuffer += FreeRDPGetBytesPerPixel(clear->format);
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2014-07-06 00:29:28 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
vBarEntry->count = vBarPixelCount;
|
2019-11-06 17:24:51 +03:00
|
|
|
clear->VBarStorageCursor = (clear->VBarStorageCursor + 1) % CLEARCODEC_VBAR_SIZE;
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2016-07-14 18:39:39 +03:00
|
|
|
if (vBarEntry->count != vBarHeight)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "vBarEntry->count %" PRIu32 " != vBarHeight %" PRIu32 "",
|
|
|
|
vBarEntry->count, vBarHeight);
|
2018-09-19 15:10:50 +03:00
|
|
|
vBarEntry->count = vBarHeight;
|
|
|
|
|
|
|
|
if (!resize_vbar_entry(clear, vBarEntry))
|
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2023-08-22 15:44:57 +03:00
|
|
|
const UINT32 nXDstRel = nXDst + xStart;
|
|
|
|
const UINT32 nYDstRel = nYDst + yStart;
|
2021-07-29 11:07:04 +03:00
|
|
|
cpSrcPixel = vBarEntry->pixels;
|
2014-07-08 19:37:27 +04:00
|
|
|
|
2016-07-14 18:39:39 +03:00
|
|
|
if (i < nWidth)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2023-08-22 15:44:57 +03:00
|
|
|
UINT32 count = vBarEntry->count;
|
2016-07-14 18:39:39 +03:00
|
|
|
|
|
|
|
if (count > nHeight)
|
|
|
|
count = nHeight;
|
|
|
|
|
2023-08-22 15:44:57 +03:00
|
|
|
if (nXDstRel + i > nDstWidth)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
for (UINT32 y = 0; y < count; y++)
|
2016-07-14 18:39:39 +03:00
|
|
|
{
|
2023-08-22 15:44:57 +03:00
|
|
|
if (nYDstRel + y > nDstHeight)
|
|
|
|
return FALSE;
|
|
|
|
|
2022-04-28 06:43:31 +03:00
|
|
|
BYTE* pDstPixel8 =
|
|
|
|
&pDstData[((nYDstRel + y) * nDstStep) +
|
|
|
|
((nXDstRel + i) * FreeRDPGetBytesPerPixel(DstFormat))];
|
|
|
|
UINT32 color = FreeRDPReadColor(cpSrcPixel, clear->format);
|
2019-11-06 17:24:51 +03:00
|
|
|
color = FreeRDPConvertColor(color, clear->format, DstFormat, NULL);
|
2016-10-20 12:09:37 +03:00
|
|
|
|
2022-04-28 06:43:31 +03:00
|
|
|
if (!FreeRDPWriteColor(pDstPixel8, DstFormat, color))
|
2016-10-20 12:09:37 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2022-04-28 06:43:31 +03:00
|
|
|
cpSrcPixel += FreeRDPGetBytesPerPixel(clear->format);
|
2016-07-14 18:39:39 +03:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-08 19:37:27 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static BOOL clear_decompress_glyph_data(CLEAR_CONTEXT* clear, wStream* s, UINT32 glyphFlags,
|
|
|
|
UINT32 nWidth, UINT32 nHeight, BYTE* pDstData,
|
|
|
|
UINT32 DstFormat, UINT32 nDstStep, UINT32 nXDst,
|
|
|
|
UINT32 nYDst, UINT32 nDstWidth, UINT32 nDstHeight,
|
2016-12-07 14:49:04 +03:00
|
|
|
const gdiPalette* palette, BYTE** ppGlyphData)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
|
|
|
UINT16 glyphIndex = 0;
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2016-12-07 14:49:04 +03:00
|
|
|
if (ppGlyphData)
|
|
|
|
*ppGlyphData = NULL;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if ((glyphFlags & CLEARCODEC_FLAG_GLYPH_HIT) && !(glyphFlags & CLEARCODEC_FLAG_GLYPH_INDEX))
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Invalid glyph flags %08" PRIX32 "", glyphFlags);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if ((glyphFlags & CLEARCODEC_FLAG_GLYPH_INDEX) == 0)
|
|
|
|
return TRUE;
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if ((nWidth * nHeight) > (1024 * 1024))
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "glyph too large: %" PRIu32 "x%" PRIu32 "", nWidth, nHeight);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
Stream_Read_UINT16(s, glyphIndex);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if (glyphIndex >= 4000)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Invalid glyphIndex %" PRIu16 "", glyphIndex);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if (glyphFlags & CLEARCODEC_FLAG_GLYPH_HIT)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 nSrcStep = 0;
|
2016-07-14 17:08:06 +03:00
|
|
|
CLEAR_GLYPH_ENTRY* glyphEntry = &(clear->GlyphCache[glyphIndex]);
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE* glyphData = NULL;
|
2016-10-20 12:09:37 +03:00
|
|
|
|
|
|
|
if (!glyphEntry)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "clear->GlyphCache[%" PRIu16 "]=NULL", glyphIndex);
|
2016-10-20 12:09:37 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
glyphData = (BYTE*)glyphEntry->pixels;
|
2016-07-14 17:08:06 +03:00
|
|
|
|
|
|
|
if (!glyphData)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "clear->GlyphCache[%" PRIu16 "]->pixels=NULL", glyphIndex);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2016-07-14 17:08:06 +03:00
|
|
|
|
2016-10-20 12:09:37 +03:00
|
|
|
if ((nWidth * nHeight) > glyphEntry->count)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG,
|
|
|
|
"(nWidth %" PRIu32 " * nHeight %" PRIu32 ") > glyphEntry->count %" PRIu32 "",
|
|
|
|
nWidth, nHeight, glyphEntry->count);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2022-04-28 06:43:31 +03:00
|
|
|
nSrcStep = nWidth * FreeRDPGetBytesPerPixel(clear->format);
|
2019-11-06 17:24:51 +03:00
|
|
|
return convert_color(pDstData, nDstStep, DstFormat, nXDst, nYDst, nWidth, nHeight,
|
|
|
|
glyphData, nSrcStep, clear->format, nDstWidth, nDstHeight, palette);
|
2014-06-13 20:17:16 +04:00
|
|
|
}
|
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if (glyphFlags & CLEARCODEC_FLAG_GLYPH_INDEX)
|
2014-06-13 20:17:16 +04:00
|
|
|
{
|
2022-04-28 06:43:31 +03:00
|
|
|
const UINT32 bpp = FreeRDPGetBytesPerPixel(clear->format);
|
2016-07-14 17:08:06 +03:00
|
|
|
CLEAR_GLYPH_ENTRY* glyphEntry = &(clear->GlyphCache[glyphIndex]);
|
|
|
|
glyphEntry->count = nWidth * nHeight;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if (glyphEntry->count > glyphEntry->size)
|
|
|
|
{
|
2023-06-05 13:16:57 +03:00
|
|
|
BYTE* tmp =
|
2023-08-22 10:41:28 +03:00
|
|
|
winpr_aligned_recalloc(glyphEntry->pixels, glyphEntry->count, 1ull * bpp, 32);
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if (!tmp)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
2023-03-24 14:14:08 +03:00
|
|
|
WLog_ERR(TAG, "glyphEntry->pixels winpr_aligned_recalloc %" PRIu32 " failed!",
|
2019-11-06 17:24:51 +03:00
|
|
|
glyphEntry->count * bpp);
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2017-01-10 16:15:53 +03:00
|
|
|
glyphEntry->size = glyphEntry->count;
|
2016-12-12 19:04:41 +03:00
|
|
|
glyphEntry->pixels = (UINT32*)tmp;
|
2016-07-14 17:08:06 +03:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if (!glyphEntry->pixels)
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "glyphEntry->pixels=NULL");
|
2016-07-14 17:08:06 +03:00
|
|
|
return FALSE;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2016-12-07 14:49:04 +03:00
|
|
|
if (ppGlyphData)
|
2016-12-12 19:04:41 +03:00
|
|
|
*ppGlyphData = (BYTE*)glyphEntry->pixels;
|
2016-10-20 12:09:37 +03:00
|
|
|
|
2016-12-07 14:49:04 +03:00
|
|
|
return TRUE;
|
2016-07-14 17:08:06 +03:00
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2016-12-12 19:04:41 +03:00
|
|
|
static INLINE BOOL updateContextFormat(CLEAR_CONTEXT* clear, UINT32 DstFormat)
|
|
|
|
{
|
|
|
|
if (!clear || !clear->nsc)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
clear->format = DstFormat;
|
2021-06-21 13:28:51 +03:00
|
|
|
return nsc_context_set_parameters(clear->nsc, NSC_COLOR_FORMAT, DstFormat);
|
2016-12-12 19:04:41 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
INT32 clear_decompress(CLEAR_CONTEXT* clear, const BYTE* pSrcData, UINT32 SrcSize, UINT32 nWidth,
|
|
|
|
UINT32 nHeight, BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep,
|
|
|
|
UINT32 nXDst, UINT32 nYDst, UINT32 nDstWidth, UINT32 nDstHeight,
|
|
|
|
const gdiPalette* palette)
|
2016-07-14 17:08:06 +03:00
|
|
|
{
|
|
|
|
INT32 rc = -1;
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE seqNumber = 0;
|
|
|
|
BYTE glyphFlags = 0;
|
|
|
|
UINT32 residualByteCount = 0;
|
|
|
|
UINT32 bandsByteCount = 0;
|
|
|
|
UINT32 subcodecByteCount = 0;
|
2022-04-27 22:02:18 +03:00
|
|
|
wStream sbuffer = { 0 };
|
2024-01-23 18:49:54 +03:00
|
|
|
wStream* s = NULL;
|
2016-12-07 14:49:04 +03:00
|
|
|
BYTE* glyphData = NULL;
|
2014-07-02 21:45:19 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if (!pDstData)
|
|
|
|
return -1002;
|
2014-07-07 23:48:56 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if ((nDstWidth == 0) || (nDstHeight == 0))
|
|
|
|
return -1022;
|
2014-07-07 23:48:56 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if ((nWidth > 0xFFFF) || (nHeight > 0xFFFF))
|
|
|
|
return -1004;
|
2014-07-07 22:16:05 +04:00
|
|
|
|
2022-04-27 22:02:18 +03:00
|
|
|
s = Stream_StaticConstInit(&sbuffer, pSrcData, SrcSize);
|
2014-07-07 22:16:05 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if (!s)
|
|
|
|
return -2005;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2022-04-19 15:29:17 +03:00
|
|
|
if (!Stream_CheckAndLogRequiredLength(TAG, s, 2))
|
2016-07-14 17:08:06 +03:00
|
|
|
goto fail;
|
2014-07-02 00:32:36 +04:00
|
|
|
|
2016-12-12 19:04:41 +03:00
|
|
|
if (!updateContextFormat(clear, DstFormat))
|
|
|
|
goto fail;
|
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
Stream_Read_UINT8(s, glyphFlags);
|
|
|
|
Stream_Read_UINT8(s, seqNumber);
|
2014-06-27 01:08:51 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if (!clear->seqNumber && seqNumber)
|
|
|
|
clear->seqNumber = seqNumber;
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if (seqNumber != clear->seqNumber)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "Sequence number unexpected %" PRIu8 " - %" PRIu32 "", seqNumber,
|
|
|
|
clear->seqNumber);
|
|
|
|
WLog_ERR(TAG, "seqNumber %" PRIu8 " != clear->seqNumber %" PRIu32 "", seqNumber,
|
|
|
|
clear->seqNumber);
|
2016-07-14 17:08:06 +03:00
|
|
|
goto fail;
|
2014-06-13 20:17:16 +04:00
|
|
|
}
|
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
clear->seqNumber = (seqNumber + 1) % 256;
|
|
|
|
|
|
|
|
if (glyphFlags & CLEARCODEC_FLAG_CACHE_RESET)
|
2014-06-13 20:17:16 +04:00
|
|
|
{
|
2022-05-26 16:07:21 +03:00
|
|
|
clear_reset_vbar_storage(clear, FALSE);
|
2016-07-14 17:08:06 +03:00
|
|
|
}
|
2014-07-01 17:55:52 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!clear_decompress_glyph_data(clear, s, glyphFlags, nWidth, nHeight, pDstData, DstFormat,
|
|
|
|
nDstStep, nXDst, nYDst, nDstWidth, nDstHeight, palette,
|
|
|
|
&glyphData))
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "clear_decompress_glyph_data failed!");
|
2016-07-14 17:08:06 +03:00
|
|
|
goto fail;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
/* Read composition payload header parameters */
|
2022-04-22 17:28:11 +03:00
|
|
|
if (Stream_GetRemainingLength(s) < 12)
|
2016-07-14 18:39:39 +03:00
|
|
|
{
|
|
|
|
const UINT32 mask = (CLEARCODEC_FLAG_GLYPH_HIT | CLEARCODEC_FLAG_GLYPH_INDEX);
|
|
|
|
|
|
|
|
if ((glyphFlags & mask) == mask)
|
|
|
|
goto finish;
|
|
|
|
|
2022-04-22 17:28:11 +03:00
|
|
|
WLog_ERR(TAG,
|
2023-07-28 12:45:58 +03:00
|
|
|
"invalid glyphFlags, missing flags: 0x%02" PRIx8 " & 0x%02" PRIx32
|
2022-04-22 17:28:11 +03:00
|
|
|
" == 0x%02" PRIx32,
|
|
|
|
glyphFlags, mask, glyphFlags & mask);
|
2016-07-14 17:08:06 +03:00
|
|
|
goto fail;
|
2016-07-14 18:39:39 +03:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
Stream_Read_UINT32(s, residualByteCount);
|
|
|
|
Stream_Read_UINT32(s, bandsByteCount);
|
|
|
|
Stream_Read_UINT32(s, subcodecByteCount);
|
2014-07-01 17:55:52 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if (residualByteCount > 0)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!clear_decompress_residual_data(clear, s, residualByteCount, nWidth, nHeight, pDstData,
|
|
|
|
DstFormat, nDstStep, nXDst, nYDst, nDstWidth,
|
|
|
|
nDstHeight, palette))
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "clear_decompress_residual_data failed!");
|
2016-07-14 17:08:06 +03:00
|
|
|
goto fail;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2016-07-14 17:08:06 +03:00
|
|
|
}
|
2014-07-01 17:55:52 +04:00
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if (bandsByteCount > 0)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!clear_decompress_bands_data(clear, s, bandsByteCount, nWidth, nHeight, pDstData,
|
2023-08-22 15:44:57 +03:00
|
|
|
DstFormat, nDstStep, nXDst, nYDst, nDstWidth, nDstHeight))
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "clear_decompress_bands_data failed!");
|
2016-07-14 17:08:06 +03:00
|
|
|
goto fail;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
}
|
|
|
|
|
2016-07-14 17:08:06 +03:00
|
|
|
if (subcodecByteCount > 0)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!clear_decompress_subcodecs_data(clear, s, subcodecByteCount, nWidth, nHeight, pDstData,
|
|
|
|
DstFormat, nDstStep, nXDst, nYDst, nDstWidth,
|
|
|
|
nDstHeight, palette))
|
2016-10-20 12:09:37 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "clear_decompress_subcodecs_data failed!");
|
2016-07-14 17:08:06 +03:00
|
|
|
goto fail;
|
2016-10-20 12:09:37 +03:00
|
|
|
}
|
2016-07-14 17:08:06 +03:00
|
|
|
}
|
2014-06-13 20:17:16 +04:00
|
|
|
|
2016-12-07 14:49:04 +03:00
|
|
|
if (glyphData)
|
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!freerdp_image_copy(glyphData, clear->format, 0, 0, 0, nWidth, nHeight, pDstData,
|
2023-01-09 10:07:43 +03:00
|
|
|
DstFormat, nDstStep, nXDst, nYDst, palette, FREERDP_KEEP_DST_ALPHA))
|
2016-12-07 14:49:04 +03:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2016-07-14 18:39:39 +03:00
|
|
|
finish:
|
2016-07-14 17:08:06 +03:00
|
|
|
rc = 0;
|
|
|
|
fail:
|
|
|
|
return rc;
|
2014-06-04 04:51:28 +04:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
int clear_compress(CLEAR_CONTEXT* clear, const BYTE* pSrcData, UINT32 SrcSize, BYTE** ppDstData,
|
|
|
|
UINT32* pDstSize)
|
2014-06-04 04:51:28 +04:00
|
|
|
{
|
2023-01-23 14:03:18 +03:00
|
|
|
WLog_ERR(TAG, "TODO: not implemented!");
|
2014-06-04 04:51:28 +04:00
|
|
|
return 1;
|
|
|
|
}
|
2022-05-26 16:07:21 +03:00
|
|
|
|
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)
|
2022-06-23 08:57:38 +03:00
|
|
|
return FALSE;
|
2016-03-01 18:17:28 +03:00
|
|
|
|
2022-05-26 16:07:21 +03:00
|
|
|
/**
|
|
|
|
* The ClearCodec context is not bound to a particular surface,
|
|
|
|
* and its internal caches must NOT be reset on the ResetGraphics PDU.
|
|
|
|
*/
|
2014-07-06 00:29:28 +04:00
|
|
|
clear->seqNumber = 0;
|
2016-03-01 18:17:28 +03:00
|
|
|
return TRUE;
|
2014-06-04 04:51:28 +04:00
|
|
|
}
|
2022-05-26 16:07:21 +03:00
|
|
|
|
2016-12-12 19:04:41 +03:00
|
|
|
CLEAR_CONTEXT* clear_context_new(BOOL Compressor)
|
2014-06-04 04:51:28 +04:00
|
|
|
{
|
2023-03-24 14:14:08 +03:00
|
|
|
CLEAR_CONTEXT* clear = (CLEAR_CONTEXT*)winpr_aligned_calloc(1, sizeof(CLEAR_CONTEXT), 32);
|
2014-06-04 04:51:28 +04:00
|
|
|
|
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;
|
|
|
|
clear->nsc = nsc_context_new();
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!clear->nsc)
|
|
|
|
goto error_nsc;
|
2014-07-02 00:32:36 +04:00
|
|
|
|
2016-12-12 19:04:41 +03:00
|
|
|
if (!updateContextFormat(clear, PIXEL_FORMAT_BGRX32))
|
|
|
|
goto error_nsc;
|
|
|
|
|
2017-01-10 16:15:53 +03:00
|
|
|
if (!clear_resize_buffer(clear, 512, 512))
|
|
|
|
goto error_nsc;
|
2016-10-20 12:09:37 +03:00
|
|
|
|
|
|
|
if (!clear->TempBuffer)
|
|
|
|
goto error_nsc;
|
|
|
|
|
|
|
|
if (!clear_context_reset(clear))
|
|
|
|
goto error_nsc;
|
|
|
|
|
2014-06-04 04:51:28 +04:00
|
|
|
return clear;
|
2015-06-16 16:42:07 +03:00
|
|
|
error_nsc:
|
2024-04-17 10:20:29 +03:00
|
|
|
WINPR_PRAGMA_DIAG_PUSH
|
|
|
|
WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
|
2016-10-20 12:09:37 +03:00
|
|
|
clear_context_free(clear);
|
2024-04-17 10:20:29 +03:00
|
|
|
WINPR_PRAGMA_DIAG_POP
|
2015-06-16 16:42:07 +03:00
|
|
|
return NULL;
|
2014-06-04 04:51:28 +04:00
|
|
|
}
|
2022-05-26 16:07:21 +03:00
|
|
|
|
2014-06-04 04:51:28 +04:00
|
|
|
void clear_context_free(CLEAR_CONTEXT* clear)
|
|
|
|
{
|
2014-07-01 17:55:52 +04:00
|
|
|
if (!clear)
|
|
|
|
return;
|
|
|
|
|
2014-07-02 00:32:36 +04:00
|
|
|
nsc_context_free(clear->nsc);
|
2023-03-24 14:14:08 +03:00
|
|
|
winpr_aligned_free(clear->TempBuffer);
|
2014-07-07 22:16:05 +04:00
|
|
|
|
2022-05-26 16:07:21 +03:00
|
|
|
clear_reset_vbar_storage(clear, TRUE);
|
|
|
|
clear_reset_glyph_cache(clear);
|
2014-07-01 22:38:54 +04:00
|
|
|
|
2023-03-24 14:14:08 +03:00
|
|
|
winpr_aligned_free(clear);
|
2014-06-04 04:51:28 +04:00
|
|
|
}
|