2013-11-26 03:58:01 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
|
|
|
* RDP6 Planar Codec
|
|
|
|
*
|
|
|
|
* Copyright 2013 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
|
2013-11-26 03:58:01 +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 16:42:03 +03:00
|
|
|
#include <freerdp/config.h>
|
2013-11-26 03:58:01 +04:00
|
|
|
|
2013-11-26 07:26:08 +04:00
|
|
|
#include <winpr/crt.h>
|
2024-05-30 01:17:52 +03:00
|
|
|
#include <winpr/wtypes.h>
|
2021-07-02 09:49:07 +03:00
|
|
|
#include <winpr/assert.h>
|
2013-11-26 07:26:08 +04:00
|
|
|
#include <winpr/print.h>
|
|
|
|
|
2014-09-07 22:08:29 +04:00
|
|
|
#include <freerdp/primitives.h>
|
2014-09-12 16:36:29 +04:00
|
|
|
#include <freerdp/log.h>
|
2013-11-26 07:26:08 +04:00
|
|
|
#include <freerdp/codec/bitmap.h>
|
2014-09-10 08:42:41 +04:00
|
|
|
#include <freerdp/codec/planar.h>
|
2013-11-26 03:58:01 +04:00
|
|
|
|
2014-09-12 16:36:29 +04:00
|
|
|
#define TAG FREERDP_TAG("codec")
|
|
|
|
|
2021-06-09 12:40:46 +03:00
|
|
|
#define PLANAR_ALIGN(val, align) \
|
|
|
|
((val) % (align) == 0) ? (val) : ((val) + (align) - (val) % (align))
|
2021-06-02 11:47:10 +03:00
|
|
|
|
2023-04-06 17:47:49 +03:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* controlByte:
|
|
|
|
* [0-3]: nRunLength
|
|
|
|
* [4-7]: cRawBytes
|
|
|
|
*/
|
|
|
|
BYTE controlByte;
|
|
|
|
BYTE* rawValues;
|
|
|
|
} RDP6_RLE_SEGMENT;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
UINT32 cSegments;
|
|
|
|
RDP6_RLE_SEGMENT* segments;
|
|
|
|
} RDP6_RLE_SEGMENTS;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* formatHeader:
|
|
|
|
* [0-2]: Color Loss Level (CLL)
|
|
|
|
* [3] : Chroma Subsampling (CS)
|
|
|
|
* [4] : Run Length Encoding (RLE)
|
|
|
|
* [5] : No Alpha (NA)
|
|
|
|
* [6-7]: Reserved
|
|
|
|
*/
|
|
|
|
BYTE formatHeader;
|
|
|
|
} RDP6_BITMAP_STREAM;
|
|
|
|
|
|
|
|
struct S_BITMAP_PLANAR_CONTEXT
|
|
|
|
{
|
|
|
|
UINT32 maxWidth;
|
|
|
|
UINT32 maxHeight;
|
|
|
|
UINT32 maxPlaneSize;
|
|
|
|
|
|
|
|
BOOL AllowSkipAlpha;
|
|
|
|
BOOL AllowRunLengthEncoding;
|
|
|
|
BOOL AllowColorSubsampling;
|
|
|
|
BOOL AllowDynamicColorFidelity;
|
|
|
|
|
|
|
|
UINT32 ColorLossLevel;
|
|
|
|
|
|
|
|
BYTE* planes[4];
|
|
|
|
BYTE* planesBuffer;
|
|
|
|
|
|
|
|
BYTE* deltaPlanes[4];
|
|
|
|
BYTE* deltaPlanesBuffer;
|
|
|
|
|
|
|
|
BYTE* rlePlanes[4];
|
|
|
|
BYTE* rlePlanesBuffer;
|
|
|
|
|
|
|
|
BYTE* pTempData;
|
|
|
|
UINT32 nTempStep;
|
|
|
|
|
|
|
|
BOOL bgr;
|
|
|
|
BOOL topdown;
|
|
|
|
};
|
|
|
|
|
2024-05-30 01:17:52 +03:00
|
|
|
static INLINE UINT32 planar_invert_format(BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT planar, BOOL alpha,
|
2021-01-18 11:18:55 +03:00
|
|
|
UINT32 DstFormat)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (planar->bgr && alpha)
|
|
|
|
{
|
|
|
|
switch (DstFormat)
|
|
|
|
{
|
|
|
|
case PIXEL_FORMAT_ARGB32:
|
|
|
|
DstFormat = PIXEL_FORMAT_ABGR32;
|
|
|
|
break;
|
|
|
|
case PIXEL_FORMAT_XRGB32:
|
|
|
|
DstFormat = PIXEL_FORMAT_XBGR32;
|
|
|
|
break;
|
|
|
|
case PIXEL_FORMAT_ABGR32:
|
|
|
|
DstFormat = PIXEL_FORMAT_ARGB32;
|
|
|
|
break;
|
|
|
|
case PIXEL_FORMAT_XBGR32:
|
|
|
|
DstFormat = PIXEL_FORMAT_XRGB32;
|
|
|
|
break;
|
|
|
|
case PIXEL_FORMAT_BGRA32:
|
|
|
|
DstFormat = PIXEL_FORMAT_RGBA32;
|
|
|
|
break;
|
|
|
|
case PIXEL_FORMAT_BGRX32:
|
|
|
|
DstFormat = PIXEL_FORMAT_RGBX32;
|
|
|
|
break;
|
|
|
|
case PIXEL_FORMAT_RGBA32:
|
|
|
|
DstFormat = PIXEL_FORMAT_BGRA32;
|
|
|
|
break;
|
|
|
|
case PIXEL_FORMAT_RGBX32:
|
|
|
|
DstFormat = PIXEL_FORMAT_BGRX32;
|
|
|
|
break;
|
|
|
|
case PIXEL_FORMAT_RGB24:
|
|
|
|
DstFormat = PIXEL_FORMAT_BGR24;
|
|
|
|
break;
|
|
|
|
case PIXEL_FORMAT_BGR24:
|
|
|
|
DstFormat = PIXEL_FORMAT_RGB24;
|
|
|
|
break;
|
|
|
|
case PIXEL_FORMAT_RGB16:
|
|
|
|
DstFormat = PIXEL_FORMAT_BGR16;
|
|
|
|
break;
|
|
|
|
case PIXEL_FORMAT_BGR16:
|
|
|
|
DstFormat = PIXEL_FORMAT_RGB16;
|
|
|
|
break;
|
|
|
|
case PIXEL_FORMAT_ARGB15:
|
|
|
|
DstFormat = PIXEL_FORMAT_ABGR15;
|
|
|
|
break;
|
|
|
|
case PIXEL_FORMAT_RGB15:
|
|
|
|
DstFormat = PIXEL_FORMAT_BGR15;
|
|
|
|
break;
|
|
|
|
case PIXEL_FORMAT_ABGR15:
|
|
|
|
DstFormat = PIXEL_FORMAT_ARGB15;
|
|
|
|
break;
|
|
|
|
case PIXEL_FORMAT_BGR15:
|
|
|
|
DstFormat = PIXEL_FORMAT_RGB15;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return DstFormat;
|
|
|
|
}
|
|
|
|
|
2024-09-12 13:52:21 +03:00
|
|
|
static INLINE BOOL freerdp_bitmap_planar_compress_plane_rle(const BYTE* WINPR_RESTRICT inPlane,
|
2024-05-30 01:17:52 +03:00
|
|
|
UINT32 width, UINT32 height,
|
2024-09-12 13:52:21 +03:00
|
|
|
BYTE* WINPR_RESTRICT outPlane,
|
2024-05-30 01:17:52 +03:00
|
|
|
UINT32* WINPR_RESTRICT dstSize);
|
|
|
|
static INLINE BYTE* freerdp_bitmap_planar_delta_encode_plane(const BYTE* WINPR_RESTRICT inPlane,
|
|
|
|
UINT32 width, UINT32 height,
|
|
|
|
BYTE* WINPR_RESTRICT outPlane);
|
2016-07-18 12:11:59 +03:00
|
|
|
|
2024-05-30 01:17:52 +03:00
|
|
|
static INLINE INT32 planar_skip_plane_rle(const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize,
|
|
|
|
UINT32 nWidth, UINT32 nHeight)
|
2014-09-07 23:40:36 +04:00
|
|
|
{
|
2020-03-30 19:18:12 +03:00
|
|
|
UINT32 used = 0;
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE controlByte = 0;
|
2014-09-07 23:40:36 +04:00
|
|
|
|
2022-06-22 13:17:24 +03:00
|
|
|
WINPR_ASSERT(pSrcData);
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 y = 0; y < nHeight; y++)
|
2014-09-07 23:40:36 +04:00
|
|
|
{
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 x = 0; x < nWidth;)
|
2014-09-07 23:40:36 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
int cRawBytes = 0;
|
|
|
|
int nRunLength = 0;
|
2017-02-20 16:15:25 +03:00
|
|
|
|
2020-03-30 19:18:12 +03:00
|
|
|
if (used >= SrcSize)
|
2022-06-22 13:17:24 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "planar plane used %" PRIu32 " exceeds SrcSize %" PRIu32, used,
|
|
|
|
SrcSize);
|
2014-09-07 23:40:36 +04:00
|
|
|
return -1;
|
2022-06-22 13:17:24 +03:00
|
|
|
}
|
2014-09-07 23:40:36 +04:00
|
|
|
|
2020-03-30 19:18:12 +03:00
|
|
|
controlByte = pSrcData[used++];
|
2014-09-07 23:40:36 +04:00
|
|
|
nRunLength = PLANAR_CONTROL_BYTE_RUN_LENGTH(controlByte);
|
|
|
|
cRawBytes = PLANAR_CONTROL_BYTE_RAW_BYTES(controlByte);
|
|
|
|
|
|
|
|
if (nRunLength == 1)
|
|
|
|
{
|
|
|
|
nRunLength = cRawBytes + 16;
|
|
|
|
cRawBytes = 0;
|
|
|
|
}
|
|
|
|
else if (nRunLength == 2)
|
|
|
|
{
|
|
|
|
nRunLength = cRawBytes + 32;
|
|
|
|
cRawBytes = 0;
|
|
|
|
}
|
|
|
|
|
2020-03-30 19:18:12 +03:00
|
|
|
used += cRawBytes;
|
2014-09-07 23:40:36 +04:00
|
|
|
x += cRawBytes;
|
|
|
|
x += nRunLength;
|
|
|
|
|
|
|
|
if (x > nWidth)
|
2022-06-22 13:17:24 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "planar plane x %" PRIu32 " exceeds width %" PRIu32, x, nWidth);
|
2014-09-07 23:40:36 +04:00
|
|
|
return -1;
|
2022-06-22 13:17:24 +03:00
|
|
|
}
|
2014-09-07 23:40:36 +04:00
|
|
|
|
2020-03-30 19:18:12 +03:00
|
|
|
if (used > SrcSize)
|
2022-06-22 13:17:24 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "planar plane used %" PRIu32 " exceeds SrcSize %" PRIu32, used,
|
|
|
|
INT32_MAX);
|
2014-09-07 23:40:36 +04:00
|
|
|
return -1;
|
2022-06-22 13:17:24 +03:00
|
|
|
}
|
2014-09-07 23:40:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-30 19:18:12 +03:00
|
|
|
if (used > INT32_MAX)
|
2022-06-22 13:17:24 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "planar plane used %" PRIu32 " exceeds SrcSize %" PRIu32, used, SrcSize);
|
2020-03-30 19:18:12 +03:00
|
|
|
return -1;
|
2022-06-22 13:17:24 +03:00
|
|
|
}
|
2020-03-30 19:18:12 +03:00
|
|
|
return (INT32)used;
|
2014-09-07 23:40:36 +04:00
|
|
|
}
|
|
|
|
|
2024-05-30 01:17:52 +03:00
|
|
|
static INLINE INT32 planar_decompress_plane_rle_only(const BYTE* WINPR_RESTRICT pSrcData,
|
|
|
|
UINT32 SrcSize, BYTE* WINPR_RESTRICT pDstData,
|
|
|
|
UINT32 nWidth, UINT32 nHeight)
|
2020-01-14 15:22:45 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 pixel = 0;
|
|
|
|
UINT32 cRawBytes = 0;
|
|
|
|
UINT32 nRunLength = 0;
|
|
|
|
INT32 deltaValue = 0;
|
|
|
|
BYTE controlByte = 0;
|
|
|
|
BYTE* currentScanline = NULL;
|
|
|
|
BYTE* previousScanline = NULL;
|
2020-01-14 15:22:45 +03:00
|
|
|
const BYTE* srcp = pSrcData;
|
|
|
|
|
2022-06-22 13:17:24 +03:00
|
|
|
WINPR_ASSERT(nHeight <= INT32_MAX);
|
|
|
|
WINPR_ASSERT(nWidth <= INT32_MAX);
|
2020-01-14 15:22:45 +03:00
|
|
|
|
|
|
|
previousScanline = NULL;
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (INT32 y = 0; y < (INT32)nHeight; y++)
|
2020-01-14 15:22:45 +03:00
|
|
|
{
|
2024-08-26 17:33:59 +03:00
|
|
|
BYTE* dstp = &pDstData[(1ULL * (y) * (INT32)nWidth)];
|
2020-01-14 15:22:45 +03:00
|
|
|
pixel = 0;
|
|
|
|
currentScanline = dstp;
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (INT32 x = 0; x < (INT32)nWidth;)
|
2020-01-14 15:22:45 +03:00
|
|
|
{
|
|
|
|
controlByte = *srcp;
|
|
|
|
srcp++;
|
|
|
|
|
2023-07-28 09:17:41 +03:00
|
|
|
if ((srcp - pSrcData) > SrcSize * 1ll)
|
2020-01-14 15:22:45 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "error reading input buffer");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nRunLength = PLANAR_CONTROL_BYTE_RUN_LENGTH(controlByte);
|
|
|
|
cRawBytes = PLANAR_CONTROL_BYTE_RAW_BYTES(controlByte);
|
|
|
|
|
|
|
|
if (nRunLength == 1)
|
|
|
|
{
|
|
|
|
nRunLength = cRawBytes + 16;
|
|
|
|
cRawBytes = 0;
|
|
|
|
}
|
|
|
|
else if (nRunLength == 2)
|
|
|
|
{
|
|
|
|
nRunLength = cRawBytes + 32;
|
|
|
|
cRawBytes = 0;
|
|
|
|
}
|
|
|
|
|
2023-07-28 09:17:41 +03:00
|
|
|
if (((dstp + (cRawBytes + nRunLength)) - currentScanline) > nWidth * 1ll)
|
2020-01-14 15:22:45 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "too many pixels in scanline");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!previousScanline)
|
|
|
|
{
|
|
|
|
/* first scanline, absolute values */
|
|
|
|
while (cRawBytes > 0)
|
|
|
|
{
|
|
|
|
pixel = *srcp;
|
|
|
|
srcp++;
|
|
|
|
*dstp = pixel;
|
|
|
|
dstp++;
|
|
|
|
x++;
|
|
|
|
cRawBytes--;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (nRunLength > 0)
|
|
|
|
{
|
|
|
|
*dstp = pixel;
|
|
|
|
dstp++;
|
|
|
|
x++;
|
|
|
|
nRunLength--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* delta values relative to previous scanline */
|
|
|
|
while (cRawBytes > 0)
|
|
|
|
{
|
|
|
|
deltaValue = *srcp;
|
|
|
|
srcp++;
|
|
|
|
|
|
|
|
if (deltaValue & 1)
|
|
|
|
{
|
|
|
|
deltaValue = deltaValue >> 1;
|
|
|
|
deltaValue = deltaValue + 1;
|
|
|
|
pixel = -deltaValue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
deltaValue = deltaValue >> 1;
|
|
|
|
pixel = deltaValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
deltaValue = previousScanline[x] + pixel;
|
|
|
|
*dstp = deltaValue;
|
|
|
|
dstp++;
|
|
|
|
x++;
|
|
|
|
cRawBytes--;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (nRunLength > 0)
|
|
|
|
{
|
|
|
|
deltaValue = previousScanline[x] + pixel;
|
|
|
|
*dstp = deltaValue;
|
|
|
|
dstp++;
|
|
|
|
x++;
|
|
|
|
nRunLength--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
previousScanline = currentScanline;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (INT32)(srcp - pSrcData);
|
|
|
|
}
|
|
|
|
|
2024-05-30 01:17:52 +03:00
|
|
|
static INLINE INT32 planar_decompress_plane_rle(const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize,
|
|
|
|
BYTE* WINPR_RESTRICT pDstData, INT32 nDstStep,
|
|
|
|
UINT32 nXDst, UINT32 nYDst, UINT32 nWidth,
|
|
|
|
UINT32 nHeight, UINT32 nChannel, BOOL vFlip)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 pixel = 0;
|
|
|
|
UINT32 cRawBytes = 0;
|
|
|
|
UINT32 nRunLength = 0;
|
|
|
|
INT32 deltaValue = 0;
|
|
|
|
INT32 beg = 0;
|
|
|
|
INT32 end = 0;
|
|
|
|
INT32 inc = 0;
|
|
|
|
BYTE controlByte = 0;
|
|
|
|
BYTE* currentScanline = NULL;
|
|
|
|
BYTE* previousScanline = NULL;
|
2014-09-07 23:40:36 +04:00
|
|
|
const BYTE* srcp = pSrcData;
|
2019-02-07 16:17:35 +03:00
|
|
|
|
2022-06-22 13:17:24 +03:00
|
|
|
WINPR_ASSERT(nHeight <= INT32_MAX);
|
|
|
|
WINPR_ASSERT(nWidth <= INT32_MAX);
|
|
|
|
WINPR_ASSERT(nDstStep <= INT32_MAX);
|
2019-02-07 16:17:35 +03:00
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
previousScanline = NULL;
|
|
|
|
|
2014-06-19 21:08:07 +04:00
|
|
|
if (vFlip)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2019-02-07 16:17:35 +03:00
|
|
|
beg = (INT32)nHeight - 1;
|
2014-06-19 21:08:07 +04:00
|
|
|
end = -1;
|
|
|
|
inc = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
beg = 0;
|
2019-02-07 16:17:35 +03:00
|
|
|
end = (INT32)nHeight;
|
2014-06-19 21:08:07 +04:00
|
|
|
inc = 1;
|
|
|
|
}
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (INT32 y = beg; y != end; y += inc)
|
2014-06-19 21:08:07 +04:00
|
|
|
{
|
2024-08-29 12:11:11 +03:00
|
|
|
BYTE* dstp = &pDstData[((nYDst + y) * nDstStep) + (nXDst * 4) + nChannel];
|
2013-11-29 12:06:39 +04:00
|
|
|
pixel = 0;
|
|
|
|
currentScanline = dstp;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (INT32 x = 0; x < (INT32)nWidth;)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
controlByte = *srcp;
|
|
|
|
srcp++;
|
|
|
|
|
2023-07-28 09:17:41 +03:00
|
|
|
if ((srcp - pSrcData) > SrcSize * 1ll)
|
2013-11-29 13:12:59 +04:00
|
|
|
{
|
2019-06-13 10:19:42 +03:00
|
|
|
WLog_ERR(TAG, "error reading input buffer");
|
2013-11-29 13:12:59 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
nRunLength = PLANAR_CONTROL_BYTE_RUN_LENGTH(controlByte);
|
|
|
|
cRawBytes = PLANAR_CONTROL_BYTE_RAW_BYTES(controlByte);
|
|
|
|
|
|
|
|
if (nRunLength == 1)
|
|
|
|
{
|
|
|
|
nRunLength = cRawBytes + 16;
|
|
|
|
cRawBytes = 0;
|
|
|
|
}
|
|
|
|
else if (nRunLength == 2)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
nRunLength = cRawBytes + 32;
|
|
|
|
cRawBytes = 0;
|
|
|
|
}
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2023-07-28 09:17:41 +03:00
|
|
|
if (((dstp + (cRawBytes + nRunLength)) - currentScanline) > nWidth * 4ll)
|
2013-11-29 13:12:59 +04:00
|
|
|
{
|
2019-06-13 10:19:42 +03:00
|
|
|
WLog_ERR(TAG, "too many pixels in scanline");
|
2013-11-29 13:12:59 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
if (!previousScanline)
|
|
|
|
{
|
|
|
|
/* first scanline, absolute values */
|
|
|
|
while (cRawBytes > 0)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
pixel = *srcp;
|
|
|
|
srcp++;
|
|
|
|
*dstp = pixel;
|
|
|
|
dstp += 4;
|
|
|
|
x++;
|
|
|
|
cRawBytes--;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
while (nRunLength > 0)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
*dstp = pixel;
|
|
|
|
dstp += 4;
|
|
|
|
x++;
|
|
|
|
nRunLength--;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
}
|
2013-11-29 12:06:39 +04:00
|
|
|
else
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
/* delta values relative to previous scanline */
|
|
|
|
while (cRawBytes > 0)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
deltaValue = *srcp;
|
|
|
|
srcp++;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
if (deltaValue & 1)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
deltaValue = deltaValue >> 1;
|
|
|
|
deltaValue = deltaValue + 1;
|
|
|
|
pixel = -deltaValue;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-29 12:06:39 +04:00
|
|
|
deltaValue = deltaValue >> 1;
|
|
|
|
pixel = deltaValue;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
|
2024-08-26 17:33:59 +03:00
|
|
|
deltaValue = previousScanline[4LL * x] + pixel;
|
2013-11-29 12:06:39 +04:00
|
|
|
*dstp = deltaValue;
|
|
|
|
dstp += 4;
|
|
|
|
x++;
|
|
|
|
cRawBytes--;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
while (nRunLength > 0)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2024-08-26 17:33:59 +03:00
|
|
|
deltaValue = previousScanline[4LL * x] + pixel;
|
2013-11-29 12:06:39 +04:00
|
|
|
*dstp = deltaValue;
|
|
|
|
dstp += 4;
|
|
|
|
x++;
|
|
|
|
nRunLength--;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-29 12:06:39 +04:00
|
|
|
previousScanline = currentScanline;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
|
2016-07-18 12:11:59 +03:00
|
|
|
return (INT32)(srcp - pSrcData);
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
|
2019-06-13 10:19:42 +03:00
|
|
|
static INLINE INT32 planar_set_plane(BYTE bValue, BYTE* pDstData, INT32 nDstStep, UINT32 nXDst,
|
|
|
|
UINT32 nYDst, UINT32 nWidth, UINT32 nHeight, UINT32 nChannel,
|
|
|
|
BOOL vFlip)
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
INT32 beg = 0;
|
|
|
|
INT32 end = 0;
|
|
|
|
INT32 inc = 0;
|
2019-06-13 10:19:42 +03:00
|
|
|
|
2022-06-22 13:17:24 +03:00
|
|
|
WINPR_ASSERT(nHeight <= INT32_MAX);
|
|
|
|
WINPR_ASSERT(nWidth <= INT32_MAX);
|
|
|
|
WINPR_ASSERT(nDstStep <= INT32_MAX);
|
2019-06-13 10:19:42 +03:00
|
|
|
|
|
|
|
if (vFlip)
|
|
|
|
{
|
|
|
|
beg = (INT32)nHeight - 1;
|
|
|
|
end = -1;
|
|
|
|
inc = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
beg = 0;
|
|
|
|
end = (INT32)nHeight;
|
|
|
|
inc = 1;
|
|
|
|
}
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (INT32 y = beg; y != end; y += inc)
|
2019-06-13 10:19:42 +03:00
|
|
|
{
|
2024-08-29 12:11:11 +03:00
|
|
|
BYTE* dstp = &pDstData[((nYDst + y) * nDstStep) + (nXDst * 4) + nChannel];
|
2019-06-13 10:19:42 +03:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (INT32 x = 0; x < (INT32)nWidth; ++x)
|
2019-06-13 10:19:42 +03:00
|
|
|
{
|
|
|
|
*dstp = bValue;
|
|
|
|
dstp += 4;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-05-30 01:17:52 +03:00
|
|
|
static INLINE BOOL writeLine(BYTE** WINPR_RESTRICT ppRgba, UINT32 DstFormat, UINT32 width,
|
|
|
|
const BYTE** WINPR_RESTRICT ppR, const BYTE** WINPR_RESTRICT ppG,
|
|
|
|
const BYTE** WINPR_RESTRICT ppB, const BYTE** WINPR_RESTRICT ppA)
|
2017-01-19 19:13:07 +03:00
|
|
|
{
|
2022-06-22 13:17:24 +03:00
|
|
|
WINPR_ASSERT(ppRgba);
|
|
|
|
WINPR_ASSERT(ppR);
|
|
|
|
WINPR_ASSERT(ppG);
|
|
|
|
WINPR_ASSERT(ppB);
|
2017-01-19 19:13:07 +03:00
|
|
|
|
|
|
|
switch (DstFormat)
|
|
|
|
{
|
2021-01-18 11:18:55 +03:00
|
|
|
case PIXEL_FORMAT_BGRA32:
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 x = 0; x < width; x++)
|
2021-01-18 11:18:55 +03:00
|
|
|
{
|
|
|
|
*(*ppRgba)++ = *(*ppB)++;
|
|
|
|
*(*ppRgba)++ = *(*ppG)++;
|
|
|
|
*(*ppRgba)++ = *(*ppR)++;
|
|
|
|
*(*ppRgba)++ = *(*ppA)++;
|
|
|
|
}
|
2017-01-19 19:13:07 +03:00
|
|
|
|
2021-01-18 11:18:55 +03:00
|
|
|
return TRUE;
|
2017-01-19 19:13:07 +03:00
|
|
|
|
2021-01-18 11:18:55 +03:00
|
|
|
case PIXEL_FORMAT_BGRX32:
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 x = 0; x < width; x++)
|
2017-01-23 11:26:56 +03:00
|
|
|
{
|
2021-01-18 11:18:55 +03:00
|
|
|
*(*ppRgba)++ = *(*ppB)++;
|
|
|
|
*(*ppRgba)++ = *(*ppG)++;
|
|
|
|
*(*ppRgba)++ = *(*ppR)++;
|
|
|
|
*(*ppRgba)++ = 0xFF;
|
2017-01-23 11:26:56 +03:00
|
|
|
}
|
|
|
|
|
2021-01-18 11:18:55 +03:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (ppA)
|
2019-06-13 10:19:42 +03:00
|
|
|
{
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 x = 0; x < width; x++)
|
2021-01-18 11:18:55 +03:00
|
|
|
{
|
|
|
|
BYTE alpha = *(*ppA)++;
|
|
|
|
UINT32 color =
|
|
|
|
FreeRDPGetColor(DstFormat, *(*ppR)++, *(*ppG)++, *(*ppB)++, alpha);
|
2022-04-28 06:43:31 +03:00
|
|
|
FreeRDPWriteColor(*ppRgba, DstFormat, color);
|
|
|
|
*ppRgba += FreeRDPGetBytesPerPixel(DstFormat);
|
2021-01-18 11:18:55 +03:00
|
|
|
}
|
2017-01-19 19:13:07 +03:00
|
|
|
}
|
2021-01-18 11:18:55 +03:00
|
|
|
else
|
|
|
|
{
|
|
|
|
const BYTE alpha = 0xFF;
|
2017-01-19 19:13:07 +03:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 x = 0; x < width; x++)
|
2021-01-18 11:18:55 +03:00
|
|
|
{
|
|
|
|
UINT32 color =
|
|
|
|
FreeRDPGetColor(DstFormat, *(*ppR)++, *(*ppG)++, *(*ppB)++, alpha);
|
2022-04-28 06:43:31 +03:00
|
|
|
FreeRDPWriteColor(*ppRgba, DstFormat, color);
|
|
|
|
*ppRgba += FreeRDPGetBytesPerPixel(DstFormat);
|
2021-01-18 11:18:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2017-01-19 19:13:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-05-30 01:17:52 +03:00
|
|
|
static INLINE BOOL planar_decompress_planes_raw(const BYTE* WINPR_RESTRICT pSrcData[4],
|
|
|
|
BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat,
|
|
|
|
UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
|
|
|
|
UINT32 nWidth, UINT32 nHeight, BOOL vFlip,
|
|
|
|
UINT32 totalHeight)
|
2014-09-07 22:08:29 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
INT32 beg = 0;
|
|
|
|
INT32 end = 0;
|
|
|
|
INT32 inc = 0;
|
2014-09-07 22:08:29 +04:00
|
|
|
const BYTE* pR = pSrcData[0];
|
|
|
|
const BYTE* pG = pSrcData[1];
|
|
|
|
const BYTE* pB = pSrcData[2];
|
|
|
|
const BYTE* pA = pSrcData[3];
|
2022-04-28 06:43:31 +03:00
|
|
|
const UINT32 bpp = FreeRDPGetBytesPerPixel(DstFormat);
|
2014-09-07 22:08:29 +04:00
|
|
|
|
|
|
|
if (vFlip)
|
|
|
|
{
|
|
|
|
beg = nHeight - 1;
|
|
|
|
end = -1;
|
|
|
|
inc = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
beg = 0;
|
|
|
|
end = nHeight;
|
|
|
|
inc = 1;
|
|
|
|
}
|
|
|
|
|
2021-03-12 12:15:51 +03:00
|
|
|
if (nYDst + nHeight > totalHeight)
|
2022-06-22 13:17:24 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG,
|
|
|
|
"planar plane destination Y %" PRIu32 " + height %" PRIu32
|
|
|
|
" exceeds totalHeight %" PRIu32,
|
|
|
|
nYDst, nHeight, totalHeight);
|
2021-03-12 12:15:51 +03:00
|
|
|
return FALSE;
|
2022-06-22 13:17:24 +03:00
|
|
|
}
|
2021-03-12 12:15:51 +03:00
|
|
|
|
|
|
|
if ((nXDst + nWidth) * bpp > nDstStep)
|
2022-06-22 13:17:24 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG,
|
|
|
|
"planar plane destination (X %" PRIu32 " + width %" PRIu32 ") * bpp %" PRIu32
|
|
|
|
" exceeds stride %" PRIu32,
|
|
|
|
nXDst, nWidth, bpp, nDstStep);
|
2021-03-12 12:15:51 +03:00
|
|
|
return FALSE;
|
2022-06-22 13:17:24 +03:00
|
|
|
}
|
2021-03-12 12:15:51 +03:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (INT32 y = beg; y != end; y += inc)
|
2014-09-07 22:08:29 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE* pRGB = NULL;
|
2021-03-12 12:15:51 +03:00
|
|
|
|
|
|
|
if (y > (INT64)nHeight)
|
2022-06-22 13:17:24 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "planar plane destination Y %" PRId32 " exceeds height %" PRIu32, y,
|
|
|
|
nHeight);
|
2021-03-12 12:15:51 +03:00
|
|
|
return FALSE;
|
2022-06-22 13:17:24 +03:00
|
|
|
}
|
2021-03-12 12:15:51 +03:00
|
|
|
|
|
|
|
pRGB = &pDstData[((nYDst + y) * nDstStep) + (nXDst * bpp)];
|
2014-09-07 22:08:29 +04:00
|
|
|
|
2018-10-16 13:17:25 +03:00
|
|
|
if (!writeLine(&pRGB, DstFormat, nWidth, &pR, &pG, &pB, &pA))
|
|
|
|
return FALSE;
|
2014-09-07 22:08:29 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
return TRUE;
|
2014-09-07 22:08:29 +04:00
|
|
|
}
|
|
|
|
|
2024-05-30 01:17:52 +03:00
|
|
|
static BOOL planar_subsample_expand(const BYTE* WINPR_RESTRICT plane, size_t planeLength,
|
|
|
|
UINT32 nWidth, UINT32 nHeight, UINT32 nPlaneWidth,
|
|
|
|
UINT32 nPlaneHeight, BYTE* WINPR_RESTRICT deltaPlane)
|
2020-01-14 19:46:13 +03:00
|
|
|
{
|
|
|
|
size_t pos = 0;
|
2020-08-10 13:04:02 +03:00
|
|
|
WINPR_UNUSED(planeLength);
|
|
|
|
|
2022-06-22 13:17:24 +03:00
|
|
|
WINPR_ASSERT(plane);
|
|
|
|
WINPR_ASSERT(deltaPlane);
|
2020-01-14 19:46:13 +03:00
|
|
|
|
|
|
|
if (nWidth > nPlaneWidth * 2)
|
2022-06-22 13:17:24 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "planar subsample width %" PRIu32 " > PlaneWidth %" PRIu32 " * 2", nWidth,
|
|
|
|
nPlaneWidth);
|
2020-01-14 19:46:13 +03:00
|
|
|
return FALSE;
|
2022-06-22 13:17:24 +03:00
|
|
|
}
|
2020-01-14 19:46:13 +03:00
|
|
|
|
|
|
|
if (nHeight > nPlaneHeight * 2)
|
2022-06-22 13:17:24 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "planar subsample height %" PRIu32 " > PlaneHeight %" PRIu32 " * 2", nHeight,
|
|
|
|
nPlaneHeight);
|
2020-01-14 19:46:13 +03:00
|
|
|
return FALSE;
|
2022-06-22 13:17:24 +03:00
|
|
|
}
|
2020-01-14 19:46:13 +03:00
|
|
|
|
2024-08-26 17:33:59 +03:00
|
|
|
for (size_t y = 0; y < nHeight; y++)
|
2020-01-14 19:46:13 +03:00
|
|
|
{
|
|
|
|
const BYTE* src = plane + y / 2 * nPlaneWidth;
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 x = 0; x < nWidth; x++)
|
2020-01-14 19:46:13 +03:00
|
|
|
{
|
|
|
|
deltaPlane[pos++] = src[x / 2];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2024-05-30 01:17:52 +03:00
|
|
|
BOOL planar_decompress(BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT planar,
|
|
|
|
const BYTE* WINPR_RESTRICT pSrcData, UINT32 SrcSize, UINT32 nSrcWidth,
|
|
|
|
UINT32 nSrcHeight, BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat,
|
2019-06-13 10:19:42 +03:00
|
|
|
UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, UINT32 nDstWidth,
|
|
|
|
UINT32 nDstHeight, BOOL vFlip)
|
2014-06-18 00:44:24 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BOOL cs = 0;
|
|
|
|
BOOL rle = 0;
|
|
|
|
UINT32 cll = 0;
|
|
|
|
BOOL alpha = 0;
|
2018-10-16 13:17:25 +03:00
|
|
|
BOOL useAlpha = FALSE;
|
2024-01-23 18:49:54 +03:00
|
|
|
INT32 status = 0;
|
|
|
|
const BYTE* srcp = NULL;
|
|
|
|
UINT32 subSize = 0;
|
|
|
|
UINT32 subWidth = 0;
|
|
|
|
UINT32 subHeight = 0;
|
|
|
|
UINT32 planeSize = 0;
|
2016-10-11 12:20:26 +03:00
|
|
|
INT32 rleSizes[4] = { 0, 0, 0, 0 };
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 rawSizes[4];
|
|
|
|
UINT32 rawWidths[4];
|
|
|
|
UINT32 rawHeights[4];
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE FormatHeader = 0;
|
2018-11-29 12:57:46 +03:00
|
|
|
const BYTE* planes[4] = { 0 };
|
2016-07-19 17:15:38 +03:00
|
|
|
const UINT32 w = MIN(nSrcWidth, nDstWidth);
|
|
|
|
const UINT32 h = MIN(nSrcHeight, nDstHeight);
|
2014-09-07 22:08:29 +04:00
|
|
|
const primitives_t* prims = primitives_get();
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2023-05-22 11:12:08 +03:00
|
|
|
WINPR_ASSERT(planar);
|
|
|
|
WINPR_ASSERT(prims);
|
|
|
|
|
2016-04-19 22:30:28 +03:00
|
|
|
if (nDstStep <= 0)
|
2022-04-28 06:43:31 +03:00
|
|
|
nDstStep = nDstWidth * FreeRDPGetBytesPerPixel(DstFormat);
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2014-06-18 00:44:24 +04:00
|
|
|
srcp = pSrcData;
|
|
|
|
|
2023-05-22 11:12:08 +03:00
|
|
|
if (!pSrcData)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Invalid argument pSrcData=NULL");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-06-18 00:44:24 +04:00
|
|
|
if (!pDstData)
|
|
|
|
{
|
2016-10-04 11:06:27 +03:00
|
|
|
WLog_ERR(TAG, "Invalid argument pDstData=NULL");
|
2016-07-18 12:11:59 +03:00
|
|
|
return FALSE;
|
2014-06-18 00:44:24 +04:00
|
|
|
}
|
|
|
|
|
2014-09-07 23:40:36 +04:00
|
|
|
FormatHeader = *srcp++;
|
2014-09-07 22:08:29 +04:00
|
|
|
cll = (FormatHeader & PLANAR_FORMAT_HEADER_CLL_MASK);
|
|
|
|
cs = (FormatHeader & PLANAR_FORMAT_HEADER_CS) ? TRUE : FALSE;
|
|
|
|
rle = (FormatHeader & PLANAR_FORMAT_HEADER_RLE) ? TRUE : FALSE;
|
|
|
|
alpha = (FormatHeader & PLANAR_FORMAT_HEADER_NA) ? FALSE : TRUE;
|
|
|
|
|
2021-01-18 11:18:55 +03:00
|
|
|
DstFormat = planar_invert_format(planar, alpha, DstFormat);
|
|
|
|
|
2018-10-16 13:17:25 +03:00
|
|
|
if (alpha)
|
2022-04-28 06:43:31 +03:00
|
|
|
useAlpha = FreeRDPColorHasAlpha(DstFormat);
|
2018-10-16 13:17:25 +03:00
|
|
|
|
2019-06-13 10:19:42 +03:00
|
|
|
// WLog_INFO(TAG, "CLL: %"PRIu32" CS: %"PRIu8" RLE: %"PRIu8" ALPHA: %"PRIu8"", cll, cs, rle,
|
|
|
|
// alpha);
|
2014-09-07 22:08:29 +04:00
|
|
|
|
2014-09-07 23:40:36 +04:00
|
|
|
if (!cll && cs)
|
2020-01-14 19:46:13 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Chroma subsampling requires YCoCg and does not work with RGB data");
|
2016-07-18 12:11:59 +03:00
|
|
|
return FALSE; /* Chroma subsampling requires YCoCg */
|
2020-01-14 19:46:13 +03:00
|
|
|
}
|
2014-09-07 22:08:29 +04:00
|
|
|
|
2016-07-19 17:15:38 +03:00
|
|
|
subWidth = (nSrcWidth / 2) + (nSrcWidth % 2);
|
|
|
|
subHeight = (nSrcHeight / 2) + (nSrcHeight % 2);
|
|
|
|
planeSize = nSrcWidth * nSrcHeight;
|
2014-09-07 23:40:36 +04:00
|
|
|
subSize = subWidth * subHeight;
|
2014-09-07 22:08:29 +04:00
|
|
|
|
2014-09-07 23:40:36 +04:00
|
|
|
if (!cs)
|
|
|
|
{
|
|
|
|
rawSizes[0] = planeSize; /* LumaOrRedPlane */
|
2016-07-19 17:15:38 +03:00
|
|
|
rawWidths[0] = nSrcWidth;
|
|
|
|
rawHeights[0] = nSrcHeight;
|
2014-09-07 23:40:36 +04:00
|
|
|
rawSizes[1] = planeSize; /* OrangeChromaOrGreenPlane */
|
2016-07-19 17:15:38 +03:00
|
|
|
rawWidths[1] = nSrcWidth;
|
|
|
|
rawHeights[1] = nSrcHeight;
|
2014-09-07 23:40:36 +04:00
|
|
|
rawSizes[2] = planeSize; /* GreenChromaOrBluePlane */
|
2016-07-19 17:15:38 +03:00
|
|
|
rawWidths[2] = nSrcWidth;
|
|
|
|
rawHeights[2] = nSrcHeight;
|
2014-09-07 23:40:36 +04:00
|
|
|
rawSizes[3] = planeSize; /* AlphaPlane */
|
2016-07-19 17:15:38 +03:00
|
|
|
rawWidths[3] = nSrcWidth;
|
|
|
|
rawHeights[3] = nSrcHeight;
|
2014-09-07 23:40:36 +04:00
|
|
|
}
|
|
|
|
else /* Chroma Subsampling */
|
|
|
|
{
|
|
|
|
rawSizes[0] = planeSize; /* LumaOrRedPlane */
|
2016-07-19 17:15:38 +03:00
|
|
|
rawWidths[0] = nSrcWidth;
|
|
|
|
rawHeights[0] = nSrcHeight;
|
2014-09-07 23:40:36 +04:00
|
|
|
rawSizes[1] = subSize; /* OrangeChromaOrGreenPlane */
|
|
|
|
rawWidths[1] = subWidth;
|
|
|
|
rawHeights[1] = subHeight;
|
|
|
|
rawSizes[2] = subSize; /* GreenChromaOrBluePlane */
|
|
|
|
rawWidths[2] = subWidth;
|
|
|
|
rawHeights[2] = subHeight;
|
|
|
|
rawSizes[3] = planeSize; /* AlphaPlane */
|
2016-07-19 17:15:38 +03:00
|
|
|
rawWidths[3] = nSrcWidth;
|
|
|
|
rawHeights[3] = nSrcHeight;
|
2014-09-07 23:40:36 +04:00
|
|
|
}
|
2014-09-07 22:08:29 +04:00
|
|
|
|
2024-04-16 09:42:52 +03:00
|
|
|
const size_t diff = srcp - pSrcData;
|
|
|
|
if (SrcSize < diff)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Size mismatch %" PRIu32 " < %" PRIuz, SrcSize, diff);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-09-07 23:40:36 +04:00
|
|
|
if (!rle) /* RAW */
|
|
|
|
{
|
2024-04-16 09:42:52 +03:00
|
|
|
|
2020-01-14 17:14:40 +03:00
|
|
|
UINT32 base = planeSize * 3;
|
|
|
|
if (cs)
|
|
|
|
base = planeSize + planeSize / 2;
|
|
|
|
|
2014-09-07 23:40:36 +04:00
|
|
|
if (alpha)
|
|
|
|
{
|
2024-04-16 09:42:52 +03:00
|
|
|
if ((SrcSize - diff) < (planeSize + base))
|
2022-06-22 13:17:24 +03:00
|
|
|
{
|
2024-04-16 09:42:52 +03:00
|
|
|
WLog_ERR(TAG, "Alpha plane size mismatch %" PRIuz " < %" PRIu32, SrcSize - diff,
|
|
|
|
(planeSize + base));
|
2018-10-16 11:05:33 +03:00
|
|
|
return FALSE;
|
2022-06-22 13:17:24 +03:00
|
|
|
}
|
2018-10-16 11:05:33 +03:00
|
|
|
|
2019-06-13 10:19:42 +03:00
|
|
|
planes[3] = srcp; /* AlphaPlane */
|
2014-09-07 23:40:36 +04:00
|
|
|
planes[0] = planes[3] + rawSizes[3]; /* LumaOrRedPlane */
|
|
|
|
planes[1] = planes[0] + rawSizes[0]; /* OrangeChromaOrGreenPlane */
|
|
|
|
planes[2] = planes[1] + rawSizes[1]; /* GreenChromaOrBluePlane */
|
2014-09-07 22:08:29 +04:00
|
|
|
|
2014-09-07 23:40:36 +04:00
|
|
|
if ((planes[2] + rawSizes[2]) > &pSrcData[SrcSize])
|
2022-06-22 13:17:24 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "plane size mismatch %p + %" PRIu32 " > %p", planes[2], rawSizes[2],
|
|
|
|
&pSrcData[SrcSize]);
|
2016-07-18 12:11:59 +03:00
|
|
|
return FALSE;
|
2022-06-22 13:17:24 +03:00
|
|
|
}
|
2014-09-07 23:40:36 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-04-16 09:42:52 +03:00
|
|
|
if ((SrcSize - diff) < base)
|
2022-06-22 13:17:24 +03:00
|
|
|
{
|
2024-04-16 09:42:52 +03:00
|
|
|
WLog_ERR(TAG, "plane size mismatch %" PRIu32 " < %" PRIu32, SrcSize - diff, base);
|
2016-07-18 12:11:59 +03:00
|
|
|
return FALSE;
|
2022-06-22 13:17:24 +03:00
|
|
|
}
|
2014-09-07 22:08:29 +04:00
|
|
|
|
2019-06-13 10:19:42 +03:00
|
|
|
planes[0] = srcp; /* LumaOrRedPlane */
|
2014-09-07 23:40:36 +04:00
|
|
|
planes[1] = planes[0] + rawSizes[0]; /* OrangeChromaOrGreenPlane */
|
|
|
|
planes[2] = planes[1] + rawSizes[1]; /* GreenChromaOrBluePlane */
|
2014-09-07 22:08:29 +04:00
|
|
|
|
2014-09-07 23:40:36 +04:00
|
|
|
if ((planes[2] + rawSizes[2]) > &pSrcData[SrcSize])
|
2022-06-22 13:17:24 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "plane size mismatch %p + %" PRIu32 " > %p", planes[2], rawSizes[2],
|
|
|
|
&pSrcData[SrcSize]);
|
2016-07-18 12:11:59 +03:00
|
|
|
return FALSE;
|
2022-06-22 13:17:24 +03:00
|
|
|
}
|
2014-09-07 23:40:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else /* RLE */
|
|
|
|
{
|
|
|
|
if (alpha)
|
|
|
|
{
|
|
|
|
planes[3] = srcp;
|
2024-04-16 09:42:52 +03:00
|
|
|
rleSizes[3] = planar_skip_plane_rle(planes[3], SrcSize - diff, rawWidths[3],
|
|
|
|
rawHeights[3]); /* AlphaPlane */
|
2014-09-07 22:08:29 +04:00
|
|
|
|
2014-09-07 23:40:36 +04:00
|
|
|
if (rleSizes[3] < 0)
|
2016-07-18 12:11:59 +03:00
|
|
|
return FALSE;
|
2014-09-07 22:08:29 +04:00
|
|
|
|
2014-09-07 23:40:36 +04:00
|
|
|
planes[0] = planes[3] + rleSizes[3];
|
2014-09-07 22:08:29 +04:00
|
|
|
}
|
2014-09-07 23:40:36 +04:00
|
|
|
else
|
|
|
|
planes[0] = srcp;
|
2014-06-18 00:44:24 +04:00
|
|
|
|
2024-04-16 09:42:52 +03:00
|
|
|
const size_t diff0 = (planes[0] - pSrcData);
|
|
|
|
if (SrcSize < diff0)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Size mismatch %" PRIu32 " < %" PRIuz, SrcSize, diff0);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
rleSizes[0] = planar_skip_plane_rle(planes[0], SrcSize - diff0, rawWidths[0],
|
|
|
|
rawHeights[0]); /* RedPlane */
|
2014-06-18 00:44:24 +04:00
|
|
|
|
2018-10-16 11:05:33 +03:00
|
|
|
if (rleSizes[0] < 0)
|
|
|
|
return FALSE;
|
2014-06-19 20:11:06 +04:00
|
|
|
|
2018-10-16 11:05:33 +03:00
|
|
|
planes[1] = planes[0] + rleSizes[0];
|
2024-04-16 09:42:52 +03:00
|
|
|
|
|
|
|
const size_t diff1 = (planes[1] - pSrcData);
|
|
|
|
if (SrcSize < diff1)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Size mismatch %" PRIu32 " < %" PRIuz, SrcSize, diff1);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
rleSizes[1] = planar_skip_plane_rle(planes[1], SrcSize - diff1, rawWidths[1],
|
|
|
|
rawHeights[1]); /* GreenPlane */
|
2014-06-18 00:44:24 +04:00
|
|
|
|
2018-10-16 11:05:33 +03:00
|
|
|
if (rleSizes[1] < 1)
|
|
|
|
return FALSE;
|
2014-09-07 23:40:36 +04:00
|
|
|
|
2018-10-16 11:05:33 +03:00
|
|
|
planes[2] = planes[1] + rleSizes[1];
|
2024-04-16 09:42:52 +03:00
|
|
|
const size_t diff2 = (planes[2] - pSrcData);
|
|
|
|
if (SrcSize < diff2)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "Size mismatch %" PRIu32 " < %" PRIuz, SrcSize, diff);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
rleSizes[2] = planar_skip_plane_rle(planes[2], SrcSize - diff2, rawWidths[2],
|
|
|
|
rawHeights[2]); /* BluePlane */
|
2018-10-16 11:05:33 +03:00
|
|
|
|
|
|
|
if (rleSizes[2] < 1)
|
|
|
|
return FALSE;
|
2014-06-18 00:44:24 +04:00
|
|
|
}
|
|
|
|
|
2014-09-07 23:40:36 +04:00
|
|
|
if (!cll) /* RGB */
|
2014-06-18 00:44:24 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 TempFormat = 0;
|
2016-07-19 17:15:38 +03:00
|
|
|
BYTE* pTempData = pDstData;
|
|
|
|
UINT32 nTempStep = nDstStep;
|
2021-03-12 12:15:51 +03:00
|
|
|
UINT32 nTotalHeight = nYDst + nDstHeight;
|
2016-07-19 17:15:38 +03:00
|
|
|
|
2018-10-16 13:17:25 +03:00
|
|
|
if (useAlpha)
|
2016-07-19 17:15:38 +03:00
|
|
|
TempFormat = PIXEL_FORMAT_BGRA32;
|
|
|
|
else
|
|
|
|
TempFormat = PIXEL_FORMAT_BGRX32;
|
|
|
|
|
2023-06-28 11:08:04 +03:00
|
|
|
TempFormat = planar_invert_format(planar, alpha, TempFormat);
|
|
|
|
|
2019-06-13 10:19:42 +03:00
|
|
|
if ((TempFormat != DstFormat) || (nSrcWidth != nDstWidth) || (nSrcHeight != nDstHeight))
|
2016-07-19 17:15:38 +03:00
|
|
|
{
|
|
|
|
pTempData = planar->pTempData;
|
2017-01-19 19:13:07 +03:00
|
|
|
nTempStep = planar->nTempStep;
|
2021-03-12 12:15:51 +03:00
|
|
|
nTotalHeight = planar->maxHeight;
|
2016-07-19 17:15:38 +03:00
|
|
|
}
|
|
|
|
|
2014-09-07 23:40:36 +04:00
|
|
|
if (!rle) /* RAW */
|
|
|
|
{
|
2019-06-13 10:19:42 +03:00
|
|
|
if (!planar_decompress_planes_raw(planes, pTempData, TempFormat, nTempStep, nXDst,
|
2021-03-12 12:15:51 +03:00
|
|
|
nYDst, nSrcWidth, nSrcHeight, vFlip, nTotalHeight))
|
2018-10-16 11:05:33 +03:00
|
|
|
return FALSE;
|
2016-07-18 12:11:59 +03:00
|
|
|
|
2018-10-16 11:05:33 +03:00
|
|
|
if (alpha)
|
2014-09-07 23:40:36 +04:00
|
|
|
srcp += rawSizes[0] + rawSizes[1] + rawSizes[2] + rawSizes[3];
|
|
|
|
else /* NoAlpha */
|
|
|
|
srcp += rawSizes[0] + rawSizes[1] + rawSizes[2];
|
2014-06-18 00:44:24 +04:00
|
|
|
|
2014-09-07 23:40:36 +04:00
|
|
|
if ((SrcSize - (srcp - pSrcData)) == 1)
|
|
|
|
srcp++; /* pad */
|
|
|
|
}
|
|
|
|
else /* RLE */
|
|
|
|
{
|
2019-06-13 10:19:42 +03:00
|
|
|
status =
|
|
|
|
planar_decompress_plane_rle(planes[0], rleSizes[0], pTempData, nTempStep, nXDst,
|
|
|
|
nYDst, nSrcWidth, nSrcHeight, 2, vFlip); /* RedPlane */
|
2016-07-18 12:11:59 +03:00
|
|
|
|
2018-10-16 11:05:33 +03:00
|
|
|
if (status < 0)
|
|
|
|
return FALSE;
|
2016-07-18 12:11:59 +03:00
|
|
|
|
2019-06-13 10:19:42 +03:00
|
|
|
status = planar_decompress_plane_rle(planes[1], rleSizes[1], pTempData, nTempStep,
|
|
|
|
nXDst, nYDst, nSrcWidth, nSrcHeight, 1,
|
2018-10-16 11:05:33 +03:00
|
|
|
vFlip); /* GreenPlane */
|
2016-07-18 12:11:59 +03:00
|
|
|
|
2018-10-16 11:05:33 +03:00
|
|
|
if (status < 0)
|
|
|
|
return FALSE;
|
2016-07-18 12:11:59 +03:00
|
|
|
|
2019-06-13 10:19:42 +03:00
|
|
|
status =
|
|
|
|
planar_decompress_plane_rle(planes[2], rleSizes[2], pTempData, nTempStep, nXDst,
|
|
|
|
nYDst, nSrcWidth, nSrcHeight, 0, vFlip); /* BluePlane */
|
2016-07-18 12:11:59 +03:00
|
|
|
|
2018-10-16 11:05:33 +03:00
|
|
|
if (status < 0)
|
|
|
|
return FALSE;
|
2016-07-18 12:11:59 +03:00
|
|
|
|
2018-10-16 11:05:33 +03:00
|
|
|
srcp += rleSizes[0] + rleSizes[1] + rleSizes[2];
|
2016-07-18 12:11:59 +03:00
|
|
|
|
2018-10-16 13:17:25 +03:00
|
|
|
if (useAlpha)
|
2014-09-07 23:40:36 +04:00
|
|
|
{
|
2019-06-13 10:19:42 +03:00
|
|
|
status = planar_decompress_plane_rle(planes[3], rleSizes[3], pTempData, nTempStep,
|
|
|
|
nXDst, nYDst, nSrcWidth, nSrcHeight, 3,
|
2018-10-16 11:05:33 +03:00
|
|
|
vFlip); /* AlphaPlane */
|
2018-10-16 13:17:25 +03:00
|
|
|
}
|
2019-06-13 10:19:42 +03:00
|
|
|
else
|
|
|
|
status = planar_set_plane(0xFF, pTempData, nTempStep, nXDst, nYDst, nSrcWidth,
|
|
|
|
nSrcHeight, 3, vFlip);
|
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
return FALSE;
|
2016-07-18 12:11:59 +03:00
|
|
|
|
2018-10-16 13:17:25 +03:00
|
|
|
if (alpha)
|
2018-10-16 11:05:33 +03:00
|
|
|
srcp += rleSizes[3];
|
2016-07-19 17:15:38 +03:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-07-19 17:15:38 +03:00
|
|
|
if (pTempData != pDstData)
|
|
|
|
{
|
2024-05-23 11:07:14 +03:00
|
|
|
if (!freerdp_image_copy_no_overlap(pDstData, DstFormat, nDstStep, nXDst, nYDst, w, h,
|
|
|
|
pTempData, TempFormat, nTempStep, nXDst, nYDst, NULL,
|
|
|
|
FREERDP_FLIP_NONE))
|
2022-06-22 13:17:24 +03:00
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "planar image copy failed");
|
2016-07-19 17:15:38 +03:00
|
|
|
return FALSE;
|
2022-06-22 13:17:24 +03:00
|
|
|
}
|
2014-09-07 23:40:36 +04:00
|
|
|
}
|
2014-06-18 00:44:24 +04:00
|
|
|
}
|
2014-09-07 23:40:36 +04:00
|
|
|
else /* YCoCg */
|
2014-06-18 00:44:24 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 TempFormat = 0;
|
2016-04-11 15:14:17 +03:00
|
|
|
BYTE* pTempData = planar->pTempData;
|
|
|
|
UINT32 nTempStep = planar->nTempStep;
|
2021-03-12 12:15:51 +03:00
|
|
|
UINT32 nTotalHeight = planar->maxHeight;
|
2022-04-28 06:43:31 +03:00
|
|
|
BYTE* dst = &pDstData[nXDst * FreeRDPGetBytesPerPixel(DstFormat) + nYDst * nDstStep];
|
2018-03-02 21:42:04 +03:00
|
|
|
|
2018-10-16 13:17:25 +03:00
|
|
|
if (useAlpha)
|
2018-03-02 21:42:04 +03:00
|
|
|
TempFormat = PIXEL_FORMAT_BGRA32;
|
|
|
|
else
|
|
|
|
TempFormat = PIXEL_FORMAT_BGRX32;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
|
|
|
if (!pTempData)
|
2016-07-18 12:11:59 +03:00
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2020-01-14 15:22:45 +03:00
|
|
|
if (rle) /* RLE encoded data. Decode and handle it like raw data. */
|
|
|
|
{
|
|
|
|
BYTE* rleBuffer[4] = { 0 };
|
|
|
|
|
2023-08-05 11:15:41 +03:00
|
|
|
if (!planar->rlePlanesBuffer)
|
|
|
|
return FALSE;
|
|
|
|
|
2020-01-14 15:22:45 +03:00
|
|
|
rleBuffer[3] = planar->rlePlanesBuffer; /* AlphaPlane */
|
|
|
|
rleBuffer[0] = rleBuffer[3] + planeSize; /* LumaOrRedPlane */
|
|
|
|
rleBuffer[1] = rleBuffer[0] + planeSize; /* OrangeChromaOrGreenPlane */
|
|
|
|
rleBuffer[2] = rleBuffer[1] + planeSize; /* GreenChromaOrBluePlane */
|
|
|
|
if (useAlpha)
|
|
|
|
{
|
2020-01-14 17:14:40 +03:00
|
|
|
status =
|
|
|
|
planar_decompress_plane_rle_only(planes[3], rleSizes[3], rleBuffer[3],
|
|
|
|
rawWidths[3], rawHeights[3]); /* AlphaPlane */
|
2020-01-14 15:22:45 +03:00
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (alpha)
|
|
|
|
srcp += rleSizes[3];
|
|
|
|
|
|
|
|
status = planar_decompress_plane_rle_only(planes[0], rleSizes[0], rleBuffer[0],
|
2020-01-14 17:14:40 +03:00
|
|
|
rawWidths[0], rawHeights[0]); /* LumaPlane */
|
2020-01-14 15:22:45 +03:00
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
status =
|
2020-01-14 17:14:40 +03:00
|
|
|
planar_decompress_plane_rle_only(planes[1], rleSizes[1], rleBuffer[1], rawWidths[1],
|
|
|
|
rawHeights[1]); /* OrangeChromaPlane */
|
2020-01-14 15:22:45 +03:00
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2020-01-14 17:14:40 +03:00
|
|
|
status =
|
|
|
|
planar_decompress_plane_rle_only(planes[2], rleSizes[2], rleBuffer[2], rawWidths[2],
|
|
|
|
rawHeights[2]); /* GreenChromaPlane */
|
2020-01-14 15:22:45 +03:00
|
|
|
|
|
|
|
if (status < 0)
|
|
|
|
return FALSE;
|
|
|
|
|
2020-01-14 19:46:13 +03:00
|
|
|
planes[0] = rleBuffer[0];
|
|
|
|
planes[1] = rleBuffer[1];
|
|
|
|
planes[2] = rleBuffer[2];
|
|
|
|
planes[3] = rleBuffer[3];
|
2020-01-14 15:22:45 +03:00
|
|
|
}
|
|
|
|
|
2020-01-14 17:14:40 +03:00
|
|
|
/* RAW */
|
2014-09-07 23:40:36 +04:00
|
|
|
{
|
2020-01-14 14:17:12 +03:00
|
|
|
if (cs)
|
|
|
|
{ /* Chroma subsampling for Co and Cg:
|
|
|
|
* Each pixel contains the value that should be expanded to
|
|
|
|
* [2x,2y;2x+1,2y;2x+1,2y+1;2x;2y+1] */
|
2020-01-14 19:46:13 +03:00
|
|
|
if (!planar_subsample_expand(planes[1], rawSizes[1], nSrcWidth, nSrcHeight,
|
|
|
|
rawWidths[1], rawHeights[1], planar->deltaPlanes[0]))
|
|
|
|
return FALSE;
|
2020-01-14 14:17:12 +03:00
|
|
|
|
|
|
|
planes[1] = planar->deltaPlanes[0];
|
|
|
|
rawSizes[1] = planeSize; /* OrangeChromaOrGreenPlane */
|
|
|
|
rawWidths[1] = nSrcWidth;
|
|
|
|
rawHeights[1] = nSrcHeight;
|
|
|
|
|
2020-01-14 19:46:13 +03:00
|
|
|
if (!planar_subsample_expand(planes[2], rawSizes[2], nSrcWidth, nSrcHeight,
|
|
|
|
rawWidths[2], rawHeights[2], planar->deltaPlanes[1]))
|
|
|
|
return FALSE;
|
2020-01-14 14:17:12 +03:00
|
|
|
|
|
|
|
planes[2] = planar->deltaPlanes[1];
|
|
|
|
rawSizes[2] = planeSize; /* GreenChromaOrBluePlane */
|
|
|
|
rawWidths[2] = nSrcWidth;
|
|
|
|
rawHeights[2] = nSrcHeight;
|
|
|
|
}
|
|
|
|
|
2019-06-13 10:19:42 +03:00
|
|
|
if (!planar_decompress_planes_raw(planes, pTempData, TempFormat, nTempStep, nXDst,
|
2021-03-12 12:15:51 +03:00
|
|
|
nYDst, nSrcWidth, nSrcHeight, vFlip, nTotalHeight))
|
2018-10-16 11:05:33 +03:00
|
|
|
return FALSE;
|
2016-07-18 12:11:59 +03:00
|
|
|
|
2018-10-16 11:05:33 +03:00
|
|
|
if (alpha)
|
2014-09-07 23:40:36 +04:00
|
|
|
srcp += rawSizes[0] + rawSizes[1] + rawSizes[2] + rawSizes[3];
|
|
|
|
else /* NoAlpha */
|
|
|
|
srcp += rawSizes[0] + rawSizes[1] + rawSizes[2];
|
2014-06-18 00:44:24 +04:00
|
|
|
|
2014-09-07 23:40:36 +04:00
|
|
|
if ((SrcSize - (srcp - pSrcData)) == 1)
|
|
|
|
srcp++; /* pad */
|
|
|
|
}
|
|
|
|
|
2022-06-22 13:17:24 +03:00
|
|
|
WINPR_ASSERT(prims->YCoCgToRGB_8u_AC4R);
|
|
|
|
int rc = prims->YCoCgToRGB_8u_AC4R(pTempData, nTempStep, dst, DstFormat, nDstStep, w, h,
|
|
|
|
cll, useAlpha);
|
|
|
|
if (rc != PRIMITIVES_SUCCESS)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "YCoCgToRGB_8u_AC4R failed with %d", rc);
|
2016-07-19 17:15:38 +03:00
|
|
|
return FALSE;
|
2022-06-22 13:17:24 +03:00
|
|
|
}
|
2014-07-03 00:30:04 +04:00
|
|
|
}
|
|
|
|
|
2022-04-28 10:56:11 +03:00
|
|
|
WINPR_UNUSED(srcp);
|
2020-01-14 17:14:40 +03:00
|
|
|
return TRUE;
|
2014-06-18 00:44:24 +04:00
|
|
|
}
|
|
|
|
|
2024-05-30 01:17:52 +03:00
|
|
|
static INLINE BOOL freerdp_split_color_planes(BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT planar,
|
|
|
|
const BYTE* WINPR_RESTRICT data, UINT32 format,
|
|
|
|
UINT32 width, UINT32 height, UINT32 scanline,
|
|
|
|
BYTE* WINPR_RESTRICT planes[4])
|
2013-11-26 03:58:01 +04:00
|
|
|
{
|
2021-07-02 09:49:07 +03:00
|
|
|
WINPR_ASSERT(planar);
|
|
|
|
|
2019-02-07 16:17:35 +03:00
|
|
|
if ((width > INT32_MAX) || (height > INT32_MAX) || (scanline > INT32_MAX))
|
|
|
|
return FALSE;
|
|
|
|
|
2016-08-01 17:37:26 +03:00
|
|
|
if (scanline == 0)
|
2022-04-28 06:43:31 +03:00
|
|
|
scanline = width * FreeRDPGetBytesPerPixel(format);
|
2016-08-01 17:37:26 +03:00
|
|
|
|
2021-07-02 09:49:07 +03:00
|
|
|
if (planar->topdown)
|
2013-11-26 07:26:08 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 k = 0;
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 i = 0; i < height; i++)
|
2013-11-26 07:26:08 +04:00
|
|
|
{
|
2024-08-29 12:11:11 +03:00
|
|
|
const BYTE* pixel = &data[1ULL * scanline * i];
|
2021-07-02 09:49:07 +03:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 j = 0; j < width; j++)
|
2021-07-02 09:49:07 +03:00
|
|
|
{
|
2022-04-28 06:43:31 +03:00
|
|
|
const UINT32 color = FreeRDPReadColor(pixel, format);
|
|
|
|
pixel += FreeRDPGetBytesPerPixel(format);
|
|
|
|
FreeRDPSplitColor(color, format, &planes[1][k], &planes[2][k], &planes[3][k],
|
2022-06-23 08:57:38 +03:00
|
|
|
&planes[0][k], NULL);
|
2021-07-02 09:49:07 +03:00
|
|
|
k++;
|
|
|
|
}
|
2013-11-26 07:26:08 +04:00
|
|
|
}
|
2013-11-26 03:58:01 +04:00
|
|
|
}
|
2021-07-02 09:49:07 +03:00
|
|
|
else
|
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 k = 0;
|
2013-11-26 03:58:01 +04:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (INT64 i = (INT64)height - 1; i >= 0; i--)
|
2021-07-02 09:49:07 +03:00
|
|
|
{
|
2024-08-26 17:33:59 +03:00
|
|
|
const BYTE* pixel = &data[1ULL * scanline * (UINT32)i];
|
2021-07-02 09:49:07 +03:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 j = 0; j < width; j++)
|
2021-07-02 09:49:07 +03:00
|
|
|
{
|
2022-04-28 06:43:31 +03:00
|
|
|
const UINT32 color = FreeRDPReadColor(pixel, format);
|
|
|
|
pixel += FreeRDPGetBytesPerPixel(format);
|
|
|
|
FreeRDPSplitColor(color, format, &planes[1][k], &planes[2][k], &planes[3][k],
|
2022-06-23 08:57:38 +03:00
|
|
|
&planes[0][k], NULL);
|
2021-07-02 09:49:07 +03:00
|
|
|
k++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
return TRUE;
|
2013-11-26 03:58:01 +04:00
|
|
|
}
|
2013-11-26 07:26:08 +04:00
|
|
|
|
2024-05-30 01:17:52 +03:00
|
|
|
static INLINE UINT32 freerdp_bitmap_planar_write_rle_bytes(const BYTE* WINPR_RESTRICT pInBuffer,
|
|
|
|
UINT32 cRawBytes, UINT32 nRunLength,
|
|
|
|
BYTE* WINPR_RESTRICT pOutBuffer,
|
2019-06-13 10:19:42 +03:00
|
|
|
UINT32 outBufferSize)
|
2013-11-27 00:16:40 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
const BYTE* pInput = NULL;
|
|
|
|
BYTE* pOutput = NULL;
|
|
|
|
BYTE controlByte = 0;
|
|
|
|
UINT32 nBytesToWrite = 0;
|
2014-01-14 07:16:10 +04:00
|
|
|
pInput = pInBuffer;
|
|
|
|
pOutput = pOutBuffer;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (!cRawBytes && !nRunLength)
|
|
|
|
return 0;
|
2013-11-27 00:16:40 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (nRunLength < 3)
|
|
|
|
{
|
|
|
|
cRawBytes += nRunLength;
|
|
|
|
nRunLength = 0;
|
2013-12-04 03:50:22 +04:00
|
|
|
}
|
2013-11-27 03:04:29 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
while (cRawBytes)
|
2013-11-27 00:16:40 +04:00
|
|
|
{
|
2014-01-14 07:16:10 +04:00
|
|
|
if (cRawBytes < 16)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2014-01-14 07:16:10 +04:00
|
|
|
if (nRunLength > 15)
|
|
|
|
{
|
|
|
|
if (nRunLength < 18)
|
|
|
|
{
|
|
|
|
controlByte = PLANAR_CONTROL_BYTE(13, cRawBytes);
|
|
|
|
nRunLength -= 13;
|
|
|
|
cRawBytes = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
controlByte = PLANAR_CONTROL_BYTE(15, cRawBytes);
|
|
|
|
nRunLength -= 15;
|
|
|
|
cRawBytes = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
controlByte = PLANAR_CONTROL_BYTE(nRunLength, cRawBytes);
|
|
|
|
nRunLength = 0;
|
|
|
|
cRawBytes = 0;
|
|
|
|
}
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
2014-01-14 07:16:10 +04:00
|
|
|
else
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2014-01-14 07:16:10 +04:00
|
|
|
controlByte = PLANAR_CONTROL_BYTE(0, 15);
|
|
|
|
cRawBytes -= 15;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
2013-11-27 03:04:29 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (outBufferSize < 1)
|
|
|
|
return 0;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
outBufferSize--;
|
|
|
|
*pOutput = controlByte;
|
|
|
|
pOutput++;
|
2024-08-29 12:11:11 +03:00
|
|
|
nBytesToWrite = (controlByte >> 4);
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (nBytesToWrite)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2014-01-14 07:16:10 +04:00
|
|
|
if (outBufferSize < nBytesToWrite)
|
|
|
|
return 0;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
outBufferSize -= nBytesToWrite;
|
|
|
|
CopyMemory(pOutput, pInput, nBytesToWrite);
|
|
|
|
pOutput += nBytesToWrite;
|
|
|
|
pInput += nBytesToWrite;
|
|
|
|
}
|
|
|
|
}
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
while (nRunLength)
|
|
|
|
{
|
|
|
|
if (nRunLength > 47)
|
|
|
|
{
|
|
|
|
if (nRunLength < 50)
|
|
|
|
{
|
|
|
|
controlByte = PLANAR_CONTROL_BYTE(2, 13);
|
|
|
|
nRunLength -= 45;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
2014-01-14 07:16:10 +04:00
|
|
|
else
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2014-01-14 07:16:10 +04:00
|
|
|
controlByte = PLANAR_CONTROL_BYTE(2, 15);
|
|
|
|
nRunLength -= 47;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nRunLength > 31)
|
|
|
|
{
|
|
|
|
controlByte = PLANAR_CONTROL_BYTE(2, (nRunLength - 32));
|
|
|
|
nRunLength = 0;
|
|
|
|
}
|
|
|
|
else if (nRunLength > 15)
|
|
|
|
{
|
|
|
|
controlByte = PLANAR_CONTROL_BYTE(1, (nRunLength - 16));
|
|
|
|
nRunLength = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
controlByte = PLANAR_CONTROL_BYTE(nRunLength, 0);
|
|
|
|
nRunLength = 0;
|
|
|
|
}
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (outBufferSize < 1)
|
|
|
|
return 0;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
--outBufferSize;
|
|
|
|
*pOutput = controlByte;
|
|
|
|
pOutput++;
|
|
|
|
}
|
2013-12-20 11:41:25 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
return (pOutput - pOutBuffer);
|
|
|
|
}
|
2013-12-20 11:41:25 +04:00
|
|
|
|
2024-05-30 01:17:52 +03:00
|
|
|
static INLINE UINT32 freerdp_bitmap_planar_encode_rle_bytes(const BYTE* WINPR_RESTRICT pInBuffer,
|
|
|
|
UINT32 inBufferSize,
|
|
|
|
BYTE* WINPR_RESTRICT pOutBuffer,
|
2019-06-13 10:19:42 +03:00
|
|
|
UINT32 outBufferSize)
|
2014-01-14 07:16:10 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE symbol = 0;
|
|
|
|
const BYTE* pInput = NULL;
|
|
|
|
BYTE* pOutput = NULL;
|
|
|
|
const BYTE* pBytes = NULL;
|
|
|
|
UINT32 cRawBytes = 0;
|
|
|
|
UINT32 nRunLength = 0;
|
|
|
|
UINT32 bSymbolMatch = 0;
|
|
|
|
UINT32 nBytesWritten = 0;
|
|
|
|
UINT32 nTotalBytesWritten = 0;
|
2014-01-14 07:16:10 +04:00
|
|
|
symbol = 0;
|
|
|
|
cRawBytes = 0;
|
|
|
|
nRunLength = 0;
|
|
|
|
pInput = pInBuffer;
|
|
|
|
pOutput = pOutBuffer;
|
|
|
|
nTotalBytesWritten = 0;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (!outBufferSize)
|
|
|
|
return 0;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (!inBufferSize)
|
|
|
|
break;
|
2013-12-20 11:41:25 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
bSymbolMatch = (symbol == *pInput) ? TRUE : FALSE;
|
|
|
|
symbol = *pInput;
|
|
|
|
pInput++;
|
|
|
|
inBufferSize--;
|
2013-12-20 11:41:25 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (nRunLength && !bSymbolMatch)
|
|
|
|
{
|
|
|
|
if (nRunLength < 3)
|
|
|
|
{
|
|
|
|
cRawBytes += nRunLength;
|
|
|
|
nRunLength = 0;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
else
|
2013-11-29 04:51:29 +04:00
|
|
|
{
|
2014-01-14 07:16:10 +04:00
|
|
|
pBytes = pInput - (cRawBytes + nRunLength + 1);
|
2019-06-13 10:19:42 +03:00
|
|
|
nBytesWritten = freerdp_bitmap_planar_write_rle_bytes(pBytes, cRawBytes, nRunLength,
|
|
|
|
pOutput, outBufferSize);
|
2014-01-14 07:16:10 +04:00
|
|
|
nRunLength = 0;
|
2013-11-27 00:16:40 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (!nBytesWritten || (nBytesWritten > outBufferSize))
|
|
|
|
return nRunLength;
|
2013-11-27 00:16:40 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
nTotalBytesWritten += nBytesWritten;
|
|
|
|
outBufferSize -= nBytesWritten;
|
|
|
|
pOutput += nBytesWritten;
|
|
|
|
cRawBytes = 0;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
}
|
2014-01-13 01:28:06 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
nRunLength += bSymbolMatch;
|
|
|
|
cRawBytes += (!bSymbolMatch) ? TRUE : FALSE;
|
2019-06-13 10:19:42 +03:00
|
|
|
} while (outBufferSize);
|
2013-11-27 01:07:55 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (cRawBytes || nRunLength)
|
|
|
|
{
|
|
|
|
pBytes = pInput - (cRawBytes + nRunLength);
|
2019-06-13 10:19:42 +03:00
|
|
|
nBytesWritten = freerdp_bitmap_planar_write_rle_bytes(pBytes, cRawBytes, nRunLength,
|
|
|
|
pOutput, outBufferSize);
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (!nBytesWritten)
|
|
|
|
return 0;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
nTotalBytesWritten += nBytesWritten;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (inBufferSize)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return nTotalBytesWritten;
|
2013-11-29 11:16:16 +04:00
|
|
|
}
|
|
|
|
|
2024-05-30 01:17:52 +03:00
|
|
|
BOOL freerdp_bitmap_planar_compress_plane_rle(const BYTE* WINPR_RESTRICT inPlane, UINT32 width,
|
|
|
|
UINT32 height, BYTE* WINPR_RESTRICT outPlane,
|
|
|
|
UINT32* WINPR_RESTRICT dstSize)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 index = 0;
|
|
|
|
const BYTE* pInput = NULL;
|
|
|
|
BYTE* pOutput = NULL;
|
|
|
|
UINT32 outBufferSize = 0;
|
|
|
|
UINT32 nBytesWritten = 0;
|
|
|
|
UINT32 nTotalBytesWritten = 0;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
|
|
|
if (!outPlane)
|
2018-08-21 10:16:47 +03:00
|
|
|
return FALSE;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
index = 0;
|
|
|
|
pInput = inPlane;
|
|
|
|
pOutput = outPlane;
|
2018-08-21 10:16:47 +03:00
|
|
|
outBufferSize = *dstSize;
|
2014-01-14 07:16:10 +04:00
|
|
|
nTotalBytesWritten = 0;
|
2013-11-29 11:16:16 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
while (outBufferSize)
|
2013-11-29 11:16:16 +04:00
|
|
|
{
|
2019-06-13 10:19:42 +03:00
|
|
|
nBytesWritten =
|
|
|
|
freerdp_bitmap_planar_encode_rle_bytes(pInput, width, pOutput, outBufferSize);
|
2013-12-04 03:50:22 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if ((!nBytesWritten) || (nBytesWritten > outBufferSize))
|
2018-08-21 10:16:47 +03:00
|
|
|
return FALSE;
|
2013-11-29 13:12:59 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
outBufferSize -= nBytesWritten;
|
|
|
|
nTotalBytesWritten += nBytesWritten;
|
|
|
|
pOutput += nBytesWritten;
|
|
|
|
pInput += width;
|
|
|
|
index++;
|
2013-12-20 11:41:25 +04:00
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
if (index >= height)
|
|
|
|
break;
|
2013-11-27 01:07:55 +04:00
|
|
|
}
|
|
|
|
|
2014-01-14 07:16:10 +04:00
|
|
|
*dstSize = nTotalBytesWritten;
|
2018-08-21 10:16:47 +03:00
|
|
|
return TRUE;
|
2013-11-27 03:04:29 +04:00
|
|
|
}
|
2013-11-27 01:30:43 +04:00
|
|
|
|
2024-05-30 01:17:52 +03:00
|
|
|
static INLINE BOOL freerdp_bitmap_planar_compress_planes_rle(BYTE* WINPR_RESTRICT inPlanes[4],
|
|
|
|
UINT32 width, UINT32 height,
|
|
|
|
BYTE* WINPR_RESTRICT outPlanes,
|
|
|
|
UINT32* WINPR_RESTRICT dstSizes,
|
|
|
|
BOOL skipAlpha)
|
2013-11-27 03:04:29 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 outPlanesSize = width * height * 4;
|
2013-11-28 01:23:20 +04:00
|
|
|
|
2013-12-09 21:02:05 +04:00
|
|
|
/* AlphaPlane */
|
|
|
|
if (skipAlpha)
|
|
|
|
{
|
|
|
|
dstSizes[0] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dstSizes[0] = outPlanesSize;
|
|
|
|
|
2019-06-13 10:19:42 +03:00
|
|
|
if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[0], width, height, outPlanes,
|
|
|
|
&dstSizes[0]))
|
2017-11-14 15:58:55 +03:00
|
|
|
return FALSE;
|
2013-12-09 21:02:05 +04:00
|
|
|
|
|
|
|
outPlanes += dstSizes[0];
|
|
|
|
outPlanesSize -= dstSizes[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* LumaOrRedPlane */
|
2013-11-28 01:23:20 +04:00
|
|
|
dstSizes[1] = outPlanesSize;
|
|
|
|
|
2019-06-13 10:19:42 +03:00
|
|
|
if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[1], width, height, outPlanes,
|
|
|
|
&dstSizes[1]))
|
2017-11-14 15:58:55 +03:00
|
|
|
return FALSE;
|
2013-11-27 07:16:31 +04:00
|
|
|
|
2013-11-28 01:23:20 +04:00
|
|
|
outPlanes += dstSizes[1];
|
|
|
|
outPlanesSize -= dstSizes[1];
|
2013-12-09 21:02:05 +04:00
|
|
|
/* OrangeChromaOrGreenPlane */
|
2013-11-28 01:23:20 +04:00
|
|
|
dstSizes[2] = outPlanesSize;
|
|
|
|
|
2019-06-13 10:19:42 +03:00
|
|
|
if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[2], width, height, outPlanes,
|
|
|
|
&dstSizes[2]))
|
2017-11-14 15:58:55 +03:00
|
|
|
return FALSE;
|
2013-11-27 07:16:31 +04:00
|
|
|
|
2013-11-28 01:23:20 +04:00
|
|
|
outPlanes += dstSizes[2];
|
|
|
|
outPlanesSize -= dstSizes[2];
|
2013-12-09 21:02:05 +04:00
|
|
|
/* GreenChromeOrBluePlane */
|
2013-11-28 01:23:20 +04:00
|
|
|
dstSizes[3] = outPlanesSize;
|
|
|
|
|
2019-06-13 10:19:42 +03:00
|
|
|
if (!freerdp_bitmap_planar_compress_plane_rle(inPlanes[3], width, height, outPlanes,
|
|
|
|
&dstSizes[3]))
|
2017-11-14 15:58:55 +03:00
|
|
|
return FALSE;
|
2013-11-27 07:16:31 +04:00
|
|
|
|
2017-11-14 15:58:55 +03:00
|
|
|
return TRUE;
|
2013-11-27 03:04:29 +04:00
|
|
|
}
|
2013-11-27 01:30:43 +04:00
|
|
|
|
2024-05-30 01:17:52 +03:00
|
|
|
BYTE* freerdp_bitmap_planar_delta_encode_plane(const BYTE* WINPR_RESTRICT inPlane, UINT32 width,
|
|
|
|
UINT32 height, BYTE* WINPR_RESTRICT outPlane)
|
2013-11-27 03:04:29 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
char s2c = 0;
|
|
|
|
BYTE* outPtr = NULL;
|
|
|
|
const BYTE* srcPtr = NULL;
|
|
|
|
const BYTE* prevLinePtr = NULL;
|
2013-11-27 01:30:43 +04:00
|
|
|
|
2013-11-27 03:04:29 +04:00
|
|
|
if (!outPlane)
|
2015-06-16 16:42:07 +03:00
|
|
|
{
|
2016-07-13 14:12:27 +03:00
|
|
|
if (width * height == 0)
|
|
|
|
return NULL;
|
2016-07-18 12:11:59 +03:00
|
|
|
|
2019-06-13 10:19:42 +03:00
|
|
|
if (!(outPlane = (BYTE*)calloc(height, width)))
|
2015-06-16 16:42:07 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
2013-11-27 01:30:43 +04:00
|
|
|
|
2014-01-14 12:44:38 +04:00
|
|
|
// first line is copied as is
|
|
|
|
CopyMemory(outPlane, inPlane, width);
|
|
|
|
outPtr = outPlane + width;
|
|
|
|
srcPtr = inPlane + width;
|
|
|
|
prevLinePtr = inPlane;
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 y = 1; y < height; y++)
|
2013-11-27 01:30:43 +04:00
|
|
|
{
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 x = 0; x < width; x++, outPtr++, srcPtr++, prevLinePtr++)
|
2013-11-27 01:30:43 +04:00
|
|
|
{
|
2020-05-15 16:34:42 +03:00
|
|
|
INT32 delta = *srcPtr - *prevLinePtr;
|
2019-06-13 10:19:42 +03:00
|
|
|
s2c = (delta >= 0) ? (char)delta : (char)(~((BYTE)(-delta)) + 1);
|
2020-08-10 13:04:02 +03:00
|
|
|
s2c = (s2c >= 0) ? (char)((UINT32)s2c << 1)
|
|
|
|
: (char)(((UINT32)(~((BYTE)s2c) + 1) << 1) - 1);
|
2014-01-14 12:44:38 +04:00
|
|
|
*outPtr = (BYTE)s2c;
|
2013-11-27 01:30:43 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-27 03:04:29 +04:00
|
|
|
return outPlane;
|
|
|
|
}
|
|
|
|
|
2024-05-30 01:17:52 +03:00
|
|
|
static INLINE BOOL freerdp_bitmap_planar_delta_encode_planes(BYTE* WINPR_RESTRICT inPlanes[4],
|
|
|
|
UINT32 width, UINT32 height,
|
|
|
|
BYTE* WINPR_RESTRICT outPlanes[4])
|
2013-11-27 03:04:29 +04:00
|
|
|
{
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 i = 0; i < 4; i++)
|
2015-06-16 16:42:07 +03:00
|
|
|
{
|
2019-06-13 10:19:42 +03:00
|
|
|
outPlanes[i] =
|
|
|
|
freerdp_bitmap_planar_delta_encode_plane(inPlanes[i], width, height, outPlanes[i]);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!outPlanes[i])
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2013-11-27 01:07:55 +04:00
|
|
|
}
|
|
|
|
|
2024-05-30 01:17:52 +03:00
|
|
|
BYTE* freerdp_bitmap_compress_planar(BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT context,
|
|
|
|
const BYTE* WINPR_RESTRICT data, UINT32 format, UINT32 width,
|
|
|
|
UINT32 height, UINT32 scanline, BYTE* WINPR_RESTRICT dstData,
|
|
|
|
UINT32* WINPR_RESTRICT pDstSize)
|
2013-11-26 07:26:08 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 size = 0;
|
|
|
|
BYTE* dstp = NULL;
|
|
|
|
UINT32 planeSize = 0;
|
2017-01-23 15:27:30 +03:00
|
|
|
UINT32 dstSizes[4] = { 0 };
|
2013-11-27 03:04:29 +04:00
|
|
|
BYTE FormatHeader = 0;
|
2013-11-26 07:26:08 +04:00
|
|
|
|
2016-10-04 15:12:51 +03:00
|
|
|
if (!context || !context->rlePlanesBuffer)
|
2016-08-10 11:29:59 +03:00
|
|
|
return NULL;
|
|
|
|
|
2013-12-09 02:06:59 +04:00
|
|
|
if (context->AllowSkipAlpha)
|
|
|
|
FormatHeader |= PLANAR_FORMAT_HEADER_NA;
|
2013-11-26 07:26:08 +04:00
|
|
|
|
2013-11-26 08:29:20 +04:00
|
|
|
planeSize = width * height;
|
2013-11-27 03:04:29 +04:00
|
|
|
|
2021-01-18 11:18:55 +03:00
|
|
|
if (!context->AllowSkipAlpha)
|
|
|
|
format = planar_invert_format(context, TRUE, format);
|
|
|
|
|
2021-07-02 09:49:07 +03:00
|
|
|
if (!freerdp_split_color_planes(context, data, format, width, height, scanline,
|
|
|
|
context->planes))
|
2014-11-17 03:10:45 +03:00
|
|
|
return NULL;
|
2013-11-27 03:04:29 +04:00
|
|
|
|
2013-12-09 02:06:59 +04:00
|
|
|
if (context->AllowRunLengthEncoding)
|
2013-12-04 05:14:07 +04:00
|
|
|
{
|
2019-06-13 10:19:42 +03:00
|
|
|
if (!freerdp_bitmap_planar_delta_encode_planes(context->planes, width, height,
|
|
|
|
context->deltaPlanes))
|
2017-02-20 20:31:58 +03:00
|
|
|
return NULL;
|
2013-12-04 05:14:07 +04:00
|
|
|
|
2019-06-13 10:19:42 +03:00
|
|
|
if (!freerdp_bitmap_planar_compress_planes_rle(context->deltaPlanes, width, height,
|
|
|
|
context->rlePlanesBuffer, dstSizes,
|
|
|
|
context->AllowSkipAlpha))
|
2017-11-14 15:58:55 +03:00
|
|
|
return NULL;
|
|
|
|
|
2013-12-09 02:06:59 +04:00
|
|
|
{
|
|
|
|
int offset = 0;
|
|
|
|
FormatHeader |= PLANAR_FORMAT_HEADER_RLE;
|
|
|
|
context->rlePlanes[0] = &context->rlePlanesBuffer[offset];
|
|
|
|
offset += dstSizes[0];
|
|
|
|
context->rlePlanes[1] = &context->rlePlanesBuffer[offset];
|
|
|
|
offset += dstSizes[1];
|
|
|
|
context->rlePlanes[2] = &context->rlePlanesBuffer[offset];
|
|
|
|
offset += dstSizes[2];
|
|
|
|
context->rlePlanes[3] = &context->rlePlanesBuffer[offset];
|
2022-12-13 13:18:11 +03:00
|
|
|
|
|
|
|
#if defined(WITH_DEBUG_CODECS)
|
|
|
|
WLog_DBG(TAG,
|
2023-07-28 12:45:58 +03:00
|
|
|
"R: [%" PRIu32 "/%" PRIu32 "] G: [%" PRIu32 "/%" PRIu32 "] B: [%" PRIu32
|
2022-12-13 13:18:11 +03:00
|
|
|
" / %" PRIu32 "] ",
|
|
|
|
dstSizes[1], planeSize, dstSizes[2], planeSize, dstSizes[3], planeSize);
|
|
|
|
#endif
|
2013-12-09 02:06:59 +04:00
|
|
|
}
|
2013-11-27 07:16:31 +04:00
|
|
|
}
|
2013-11-27 03:04:29 +04:00
|
|
|
|
2017-11-14 15:58:55 +03:00
|
|
|
if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
|
|
|
|
{
|
|
|
|
if (!context->AllowRunLengthEncoding)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (context->rlePlanes[0] == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (context->rlePlanes[1] == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (context->rlePlanes[2] == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (context->rlePlanes[3] == NULL)
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-11-26 07:26:08 +04:00
|
|
|
if (!dstData)
|
|
|
|
{
|
2013-11-27 07:16:31 +04:00
|
|
|
size = 1;
|
2013-11-26 07:26:08 +04:00
|
|
|
|
|
|
|
if (!(FormatHeader & PLANAR_FORMAT_HEADER_NA))
|
2013-11-27 07:16:31 +04:00
|
|
|
{
|
|
|
|
if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
|
|
|
|
size += dstSizes[0];
|
|
|
|
else
|
|
|
|
size += planeSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
|
|
|
|
size += (dstSizes[1] + dstSizes[2] + dstSizes[3]);
|
|
|
|
else
|
|
|
|
size += (planeSize * 3);
|
2013-11-26 07:26:08 +04:00
|
|
|
|
2013-11-27 07:16:31 +04:00
|
|
|
if (!(FormatHeader & PLANAR_FORMAT_HEADER_RLE))
|
|
|
|
size++;
|
2013-11-26 07:26:08 +04:00
|
|
|
|
|
|
|
dstData = malloc(size);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-06-16 16:42:07 +03:00
|
|
|
if (!dstData)
|
|
|
|
return NULL;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2014-09-20 23:25:33 +04:00
|
|
|
*pDstSize = size;
|
2013-11-26 07:26:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
dstp = dstData;
|
|
|
|
*dstp = FormatHeader; /* FormatHeader */
|
|
|
|
dstp++;
|
|
|
|
|
|
|
|
/* AlphaPlane */
|
|
|
|
|
|
|
|
if (!(FormatHeader & PLANAR_FORMAT_HEADER_NA))
|
|
|
|
{
|
2013-11-27 07:16:31 +04:00
|
|
|
if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
|
|
|
|
{
|
2013-12-09 02:06:59 +04:00
|
|
|
CopyMemory(dstp, context->rlePlanes[0], dstSizes[0]); /* Alpha */
|
2013-11-27 07:16:31 +04:00
|
|
|
dstp += dstSizes[0];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-09 02:06:59 +04:00
|
|
|
CopyMemory(dstp, context->planes[0], planeSize); /* Alpha */
|
2013-11-27 07:16:31 +04:00
|
|
|
dstp += planeSize;
|
|
|
|
}
|
2013-11-26 07:26:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* LumaOrRedPlane */
|
|
|
|
|
2013-11-27 07:16:31 +04:00
|
|
|
if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
|
|
|
|
{
|
2013-12-09 02:06:59 +04:00
|
|
|
CopyMemory(dstp, context->rlePlanes[1], dstSizes[1]); /* Red */
|
2013-11-27 07:16:31 +04:00
|
|
|
dstp += dstSizes[1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-09 02:06:59 +04:00
|
|
|
CopyMemory(dstp, context->planes[1], planeSize); /* Red */
|
2013-11-27 07:16:31 +04:00
|
|
|
dstp += planeSize;
|
|
|
|
}
|
2013-11-26 07:26:08 +04:00
|
|
|
|
|
|
|
/* OrangeChromaOrGreenPlane */
|
|
|
|
|
2013-11-27 07:16:31 +04:00
|
|
|
if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
|
|
|
|
{
|
2013-12-09 02:06:59 +04:00
|
|
|
CopyMemory(dstp, context->rlePlanes[2], dstSizes[2]); /* Green */
|
2013-11-27 07:16:31 +04:00
|
|
|
dstp += dstSizes[2];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-09 02:06:59 +04:00
|
|
|
CopyMemory(dstp, context->planes[2], planeSize); /* Green */
|
2013-11-27 07:16:31 +04:00
|
|
|
dstp += planeSize;
|
|
|
|
}
|
2013-11-26 07:26:08 +04:00
|
|
|
|
|
|
|
/* GreenChromeOrBluePlane */
|
|
|
|
|
2013-11-27 07:16:31 +04:00
|
|
|
if (FormatHeader & PLANAR_FORMAT_HEADER_RLE)
|
|
|
|
{
|
2013-12-09 02:06:59 +04:00
|
|
|
CopyMemory(dstp, context->rlePlanes[3], dstSizes[3]); /* Blue */
|
2013-11-27 07:16:31 +04:00
|
|
|
dstp += dstSizes[3];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-09 02:06:59 +04:00
|
|
|
CopyMemory(dstp, context->planes[3], planeSize); /* Blue */
|
2013-11-27 07:16:31 +04:00
|
|
|
dstp += planeSize;
|
|
|
|
}
|
2013-11-26 07:26:08 +04:00
|
|
|
|
|
|
|
/* Pad1 (1 byte) */
|
|
|
|
|
|
|
|
if (!(FormatHeader & PLANAR_FORMAT_HEADER_RLE))
|
|
|
|
{
|
|
|
|
*dstp = 0;
|
|
|
|
dstp++;
|
|
|
|
}
|
|
|
|
|
|
|
|
size = (dstp - dstData);
|
2014-09-20 23:25:33 +04:00
|
|
|
*pDstSize = size;
|
2013-11-26 07:26:08 +04:00
|
|
|
return dstData;
|
|
|
|
}
|
2013-12-09 02:06:59 +04:00
|
|
|
|
2024-05-30 01:17:52 +03:00
|
|
|
BOOL freerdp_bitmap_planar_context_reset(BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT context,
|
|
|
|
UINT32 width, UINT32 height)
|
2014-09-12 22:57:44 +04:00
|
|
|
{
|
2016-03-01 18:17:28 +03:00
|
|
|
if (!context)
|
|
|
|
return FALSE;
|
|
|
|
|
2021-01-18 11:18:55 +03:00
|
|
|
context->bgr = FALSE;
|
2021-06-09 12:40:46 +03:00
|
|
|
context->maxWidth = PLANAR_ALIGN(width, 4);
|
|
|
|
context->maxHeight = PLANAR_ALIGN(height, 4);
|
2024-05-08 16:10:42 +03:00
|
|
|
{
|
|
|
|
const UINT64 tmp = (UINT64)context->maxWidth * context->maxHeight;
|
|
|
|
if (tmp > UINT32_MAX)
|
|
|
|
return FALSE;
|
|
|
|
context->maxPlaneSize = tmp;
|
|
|
|
}
|
2024-01-13 23:01:55 +03:00
|
|
|
|
|
|
|
if (context->maxWidth > UINT32_MAX / 4)
|
|
|
|
return FALSE;
|
2016-04-14 00:18:55 +03:00
|
|
|
context->nTempStep = context->maxWidth * 4;
|
2023-03-24 14:30:42 +03:00
|
|
|
|
2023-08-05 11:15:41 +03:00
|
|
|
memset(context->planes, 0, sizeof(context->planes));
|
|
|
|
memset(context->rlePlanes, 0, sizeof(context->rlePlanes));
|
|
|
|
memset(context->deltaPlanes, 0, sizeof(context->deltaPlanes));
|
2023-03-24 14:30:42 +03:00
|
|
|
|
2023-08-05 11:15:41 +03:00
|
|
|
if (context->maxPlaneSize > 0)
|
|
|
|
{
|
|
|
|
void* tmp = winpr_aligned_recalloc(context->planesBuffer, context->maxPlaneSize, 4, 32);
|
|
|
|
if (!tmp)
|
|
|
|
return FALSE;
|
|
|
|
context->planesBuffer = tmp;
|
2023-03-24 14:30:42 +03:00
|
|
|
|
2023-08-05 11:15:41 +03:00
|
|
|
tmp = winpr_aligned_recalloc(context->pTempData, context->maxPlaneSize, 6, 32);
|
|
|
|
if (!tmp)
|
|
|
|
return FALSE;
|
|
|
|
context->pTempData = tmp;
|
2023-03-24 14:30:42 +03:00
|
|
|
|
2023-08-05 11:15:41 +03:00
|
|
|
tmp = winpr_aligned_recalloc(context->deltaPlanesBuffer, context->maxPlaneSize, 4, 32);
|
|
|
|
if (!tmp)
|
|
|
|
return FALSE;
|
|
|
|
context->deltaPlanesBuffer = tmp;
|
|
|
|
|
|
|
|
tmp = winpr_aligned_recalloc(context->rlePlanesBuffer, context->maxPlaneSize, 4, 32);
|
|
|
|
if (!tmp)
|
|
|
|
return FALSE;
|
|
|
|
context->rlePlanesBuffer = tmp;
|
|
|
|
|
2024-08-26 17:33:59 +03:00
|
|
|
context->planes[0] = &context->planesBuffer[0ULL * context->maxPlaneSize];
|
|
|
|
context->planes[1] = &context->planesBuffer[1ULL * context->maxPlaneSize];
|
|
|
|
context->planes[2] = &context->planesBuffer[2ULL * context->maxPlaneSize];
|
|
|
|
context->planes[3] = &context->planesBuffer[3ULL * context->maxPlaneSize];
|
|
|
|
context->deltaPlanes[0] = &context->deltaPlanesBuffer[0ULL * context->maxPlaneSize];
|
|
|
|
context->deltaPlanes[1] = &context->deltaPlanesBuffer[1ULL * context->maxPlaneSize];
|
|
|
|
context->deltaPlanes[2] = &context->deltaPlanesBuffer[2ULL * context->maxPlaneSize];
|
|
|
|
context->deltaPlanes[3] = &context->deltaPlanesBuffer[3ULL * context->maxPlaneSize];
|
2023-08-05 11:15:41 +03:00
|
|
|
}
|
2016-03-01 18:17:28 +03:00
|
|
|
return TRUE;
|
2014-09-12 22:57:44 +04:00
|
|
|
}
|
|
|
|
|
2019-06-13 10:19:42 +03:00
|
|
|
BITMAP_PLANAR_CONTEXT* freerdp_bitmap_planar_context_new(DWORD flags, UINT32 maxWidth,
|
|
|
|
UINT32 maxHeight)
|
2013-12-09 02:06:59 +04:00
|
|
|
{
|
2023-03-24 14:30:42 +03:00
|
|
|
BITMAP_PLANAR_CONTEXT* context =
|
|
|
|
(BITMAP_PLANAR_CONTEXT*)winpr_aligned_calloc(1, sizeof(BITMAP_PLANAR_CONTEXT), 32);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2013-12-09 02:06:59 +04:00
|
|
|
if (!context)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (flags & PLANAR_FORMAT_HEADER_NA)
|
|
|
|
context->AllowSkipAlpha = TRUE;
|
|
|
|
|
|
|
|
if (flags & PLANAR_FORMAT_HEADER_RLE)
|
|
|
|
context->AllowRunLengthEncoding = TRUE;
|
|
|
|
|
|
|
|
if (flags & PLANAR_FORMAT_HEADER_CS)
|
|
|
|
context->AllowColorSubsampling = TRUE;
|
|
|
|
|
|
|
|
context->ColorLossLevel = flags & PLANAR_FORMAT_HEADER_CLL_MASK;
|
|
|
|
|
|
|
|
if (context->ColorLossLevel)
|
|
|
|
context->AllowDynamicColorFidelity = TRUE;
|
|
|
|
|
2016-04-14 00:18:55 +03:00
|
|
|
if (!freerdp_bitmap_planar_context_reset(context, maxWidth, maxHeight))
|
|
|
|
{
|
2024-04-17 10:20:29 +03:00
|
|
|
WINPR_PRAGMA_DIAG_PUSH
|
|
|
|
WINPR_PRAGMA_DIAG_IGNORED_MISMATCHED_DEALLOC
|
2016-04-14 00:18:55 +03:00
|
|
|
freerdp_bitmap_planar_context_free(context);
|
2024-04-17 10:20:29 +03:00
|
|
|
WINPR_PRAGMA_DIAG_POP
|
2016-04-14 00:18:55 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
2013-12-09 02:06:59 +04:00
|
|
|
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
void freerdp_bitmap_planar_context_free(BITMAP_PLANAR_CONTEXT* context)
|
|
|
|
{
|
|
|
|
if (!context)
|
|
|
|
return;
|
|
|
|
|
2023-03-24 14:30:42 +03:00
|
|
|
winpr_aligned_free(context->pTempData);
|
|
|
|
winpr_aligned_free(context->planesBuffer);
|
|
|
|
winpr_aligned_free(context->deltaPlanesBuffer);
|
|
|
|
winpr_aligned_free(context->rlePlanesBuffer);
|
|
|
|
winpr_aligned_free(context);
|
2013-12-09 02:06:59 +04:00
|
|
|
}
|
2021-01-18 11:18:55 +03:00
|
|
|
|
2024-05-30 01:17:52 +03:00
|
|
|
void freerdp_planar_switch_bgr(BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT planar, BOOL bgr)
|
2021-01-18 11:18:55 +03:00
|
|
|
{
|
2021-07-02 09:49:07 +03:00
|
|
|
WINPR_ASSERT(planar);
|
2021-01-18 11:18:55 +03:00
|
|
|
planar->bgr = bgr;
|
|
|
|
}
|
2021-07-02 09:49:07 +03:00
|
|
|
|
2024-05-30 01:17:52 +03:00
|
|
|
void freerdp_planar_topdown_image(BITMAP_PLANAR_CONTEXT* WINPR_RESTRICT planar, BOOL topdown)
|
2021-07-02 09:49:07 +03:00
|
|
|
{
|
|
|
|
WINPR_ASSERT(planar);
|
|
|
|
planar->topdown = topdown;
|
|
|
|
}
|