2011-07-01 05:23:36 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-09-14 00:30:16 +04:00
|
|
|
* Color Conversion Routines
|
2011-07-01 05:23:36 +04:00
|
|
|
*
|
|
|
|
* Copyright 2010 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
|
2011-07-01 05:23:36 +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>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2011-07-01 05:23:36 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2012-11-22 05:21:08 +04:00
|
|
|
#include <winpr/crt.h>
|
|
|
|
|
2014-11-16 14:21:38 +03:00
|
|
|
#include <freerdp/log.h>
|
2011-07-01 05:23:36 +04:00
|
|
|
#include <freerdp/freerdp.h>
|
2014-07-03 00:30:04 +04:00
|
|
|
#include <freerdp/primitives.h>
|
2011-07-01 05:23:36 +04:00
|
|
|
|
2022-07-06 15:04:06 +03:00
|
|
|
#if defined(WITH_CAIRO)
|
2019-05-06 14:18:31 +03:00
|
|
|
#include <cairo.h>
|
|
|
|
#endif
|
|
|
|
|
2022-07-06 15:04:06 +03:00
|
|
|
#if defined(WITH_SWSCALE)
|
2019-05-06 14:18:31 +03:00
|
|
|
#include <libswscale/swscale.h>
|
|
|
|
#endif
|
|
|
|
|
2014-11-16 14:21:38 +03:00
|
|
|
#define TAG FREERDP_TAG("color")
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
BYTE* freerdp_glyph_convert(UINT32 width, UINT32 height, const BYTE* data)
|
2011-09-29 08:33:16 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
/*
|
|
|
|
* converts a 1-bit-per-pixel glyph to a one-byte-per-pixel glyph:
|
|
|
|
* this approach uses a little more memory, but provides faster
|
|
|
|
* means of accessing individual pixels in blitting operations
|
|
|
|
*/
|
2024-01-30 12:25:38 +03:00
|
|
|
const UINT32 scanline = (width + 7) / 8;
|
|
|
|
BYTE* dstData = (BYTE*)winpr_aligned_malloc(1ull * width * height, 16);
|
2014-03-01 06:51:29 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!dstData)
|
|
|
|
return NULL;
|
2014-03-01 06:51:29 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
ZeroMemory(dstData, width * height);
|
2024-01-30 12:25:38 +03:00
|
|
|
BYTE* dstp = dstData;
|
2014-03-01 06:51:29 +04:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 y = 0; y < height; y++)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2024-02-15 15:10:45 +03:00
|
|
|
const BYTE* srcp = &data[1ull * y * scanline];
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 x = 0; x < width; x++)
|
2014-09-12 04:12:32 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
if ((*srcp & (0x80 >> (x % 8))) != 0)
|
|
|
|
*dstp = 0xFF;
|
2014-09-12 04:12:32 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
dstp++;
|
2014-09-17 03:12:26 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (((x + 1) % 8 == 0) && x != 0)
|
|
|
|
srcp++;
|
2014-09-12 04:12:32 +04:00
|
|
|
}
|
2014-09-17 20:17:41 +04:00
|
|
|
}
|
2014-09-17 03:12:26 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
return dstData;
|
2014-09-17 20:17:41 +04:00
|
|
|
}
|
2014-09-17 03:12:26 +04:00
|
|
|
|
2023-08-23 16:10:04 +03:00
|
|
|
BOOL freerdp_image_copy_from_monochrome(BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat,
|
|
|
|
UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, UINT32 nWidth,
|
|
|
|
UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData,
|
|
|
|
UINT32 backColor, UINT32 foreColor,
|
|
|
|
const gdiPalette* WINPR_RESTRICT palette)
|
2014-09-17 20:17:41 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BOOL vFlip = 0;
|
|
|
|
UINT32 monoStep = 0;
|
2022-04-28 06:43:31 +03:00
|
|
|
const UINT32 dstBytesPerPixel = FreeRDPGetBytesPerPixel(DstFormat);
|
2014-09-18 02:30:09 +04:00
|
|
|
|
2018-10-16 18:14:56 +03:00
|
|
|
if (!pDstData || !pSrcData || !palette)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-04-11 18:30:29 +03:00
|
|
|
if (nDstStep == 0)
|
2014-09-18 02:30:09 +04:00
|
|
|
nDstStep = dstBytesPerPixel * nWidth;
|
|
|
|
|
2016-10-14 11:01:02 +03:00
|
|
|
vFlip = FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
monoStep = (nWidth + 7) / 8;
|
2014-09-17 03:12:26 +04:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 y = 0; y < nHeight; y++)
|
2014-09-17 20:17:41 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
const BYTE* monoBits = NULL;
|
2016-04-05 18:07:45 +03:00
|
|
|
BYTE* pDstLine = &pDstData[((nYDst + y) * nDstStep)];
|
2016-04-11 18:30:29 +03:00
|
|
|
UINT32 monoBit = 0x80;
|
2014-09-12 04:12:32 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!vFlip)
|
|
|
|
monoBits = &pSrcData[monoStep * y];
|
|
|
|
else
|
|
|
|
monoBits = &pSrcData[monoStep * (nHeight - y - 1)];
|
2014-09-15 22:59:45 +04:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 x = 0; x < nWidth; x++)
|
2014-09-17 20:17:41 +04:00
|
|
|
{
|
2022-04-28 06:43:31 +03:00
|
|
|
BYTE* pDstPixel = &pDstLine[((nXDst + x) * FreeRDPGetBytesPerPixel(DstFormat))];
|
2016-04-11 18:30:29 +03:00
|
|
|
BOOL monoPixel = (*monoBits & monoBit) ? TRUE : FALSE;
|
2014-09-15 22:59:45 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!(monoBit >>= 1))
|
2014-09-17 03:12:26 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
monoBits++;
|
|
|
|
monoBit = 0x80;
|
2014-09-17 20:17:41 +04:00
|
|
|
}
|
2014-09-17 03:12:26 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (monoPixel)
|
2022-04-28 06:43:31 +03:00
|
|
|
FreeRDPWriteColor(pDstPixel, DstFormat, backColor);
|
2014-09-17 20:17:41 +04:00
|
|
|
else
|
2022-04-28 06:43:31 +03:00
|
|
|
FreeRDPWriteColor(pDstPixel, DstFormat, foreColor);
|
2014-09-17 20:17:41 +04:00
|
|
|
}
|
2014-09-12 04:12:32 +04:00
|
|
|
}
|
|
|
|
|
2016-12-05 15:44:08 +03:00
|
|
|
return TRUE;
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static INLINE UINT32 freerdp_image_inverted_pointer_color(UINT32 x, UINT32 y, UINT32 format)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
|
|
|
#if 1
|
|
|
|
/**
|
|
|
|
* Inverted pointer colors (where individual pixels can change their
|
|
|
|
* color to accommodate the background behind them) only seem to be
|
|
|
|
* supported on Windows.
|
|
|
|
* Using a static replacement color for these pixels (e.g. black)
|
|
|
|
* might result in invisible pointers depending on the background.
|
|
|
|
* This function returns either black or white, depending on the
|
|
|
|
* pixel's position.
|
|
|
|
*/
|
2016-08-02 16:21:28 +03:00
|
|
|
BYTE fill = (x + y) & 1 ? 0x00 : 0xFF;
|
2016-04-05 18:07:45 +03:00
|
|
|
#else
|
2016-08-02 16:21:28 +03:00
|
|
|
BYTE fill = 0x00;
|
2016-04-05 18:07:45 +03:00
|
|
|
#endif
|
2017-11-24 15:19:48 +03:00
|
|
|
return FreeRDPGetColor(format, fill, fill, fill, 0xFF);
|
2014-03-01 06:51:29 +04:00
|
|
|
}
|
2014-06-13 16:36:09 +04:00
|
|
|
|
2019-05-08 16:03:06 +03:00
|
|
|
/*
|
|
|
|
* DIB color palettes are arrays of RGBQUAD structs with colors in BGRX format.
|
|
|
|
* They are used only by 1, 2, 4, and 8-bit bitmaps.
|
|
|
|
*/
|
2019-11-06 17:24:51 +03:00
|
|
|
static void fill_gdi_palette_for_icon(const BYTE* colorTable, UINT16 cbColorTable,
|
|
|
|
gdiPalette* palette)
|
2019-05-08 16:03:06 +03:00
|
|
|
{
|
2022-10-13 17:25:36 +03:00
|
|
|
WINPR_ASSERT(palette);
|
|
|
|
|
2019-05-08 16:03:06 +03:00
|
|
|
palette->format = PIXEL_FORMAT_BGRX32;
|
|
|
|
ZeroMemory(palette->palette, sizeof(palette->palette));
|
|
|
|
|
|
|
|
if (!cbColorTable)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ((cbColorTable % 4 != 0) || (cbColorTable / 4 > 256))
|
|
|
|
{
|
|
|
|
WLog_WARN(TAG, "weird palette size: %u", cbColorTable);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT16 i = 0; i < cbColorTable / 4; i++)
|
2019-05-08 16:03:06 +03:00
|
|
|
{
|
2022-04-28 06:43:31 +03:00
|
|
|
palette->palette[i] = FreeRDPReadColor(&colorTable[4 * i], palette->format);
|
2019-05-08 16:03:06 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static INLINE UINT32 div_ceil(UINT32 a, UINT32 b)
|
|
|
|
{
|
|
|
|
return (a + (b - 1)) / b;
|
|
|
|
}
|
|
|
|
|
|
|
|
static INLINE UINT32 round_up(UINT32 a, UINT32 b)
|
|
|
|
{
|
|
|
|
return b * div_ceil(a, b);
|
|
|
|
}
|
|
|
|
|
2023-08-23 16:10:04 +03:00
|
|
|
BOOL freerdp_image_copy_from_icon_data(BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat,
|
|
|
|
UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst, UINT16 nWidth,
|
|
|
|
UINT16 nHeight, const BYTE* WINPR_RESTRICT bitsColor,
|
|
|
|
UINT16 cbBitsColor, const BYTE* WINPR_RESTRICT bitsMask,
|
|
|
|
UINT16 cbBitsMask, const BYTE* WINPR_RESTRICT colorTable,
|
|
|
|
UINT16 cbColorTable, UINT32 bpp)
|
2019-05-08 16:03:06 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
DWORD format = 0;
|
2019-05-08 16:03:06 +03:00
|
|
|
gdiPalette palette;
|
|
|
|
|
|
|
|
if (!pDstData || !bitsColor)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Color formats used by icons are DIB bitmap formats (2-bit format
|
|
|
|
* is not used by MS-RDPERP). Note that 16-bit is RGB555, not RGB565,
|
|
|
|
* and that 32-bit format uses BGRA order.
|
|
|
|
*/
|
|
|
|
switch (bpp)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
case 4:
|
|
|
|
/*
|
|
|
|
* These formats are not supported by freerdp_image_copy().
|
|
|
|
* PIXEL_FORMAT_MONO and PIXEL_FORMAT_A4 are *not* correct
|
|
|
|
* color formats for this. Please fix freerdp_image_copy()
|
|
|
|
* if you came here to fix a broken icon of some weird app
|
|
|
|
* that still uses 1 or 4bpp format in the 21st century.
|
|
|
|
*/
|
|
|
|
WLog_WARN(TAG, "1bpp and 4bpp icons are not supported");
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
format = PIXEL_FORMAT_RGB8;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 16:
|
|
|
|
format = PIXEL_FORMAT_RGB15;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 24:
|
|
|
|
format = PIXEL_FORMAT_RGB24;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 32:
|
|
|
|
format = PIXEL_FORMAT_BGRA32;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2022-09-29 15:55:27 +03:00
|
|
|
WLog_WARN(TAG, "invalid icon bpp: %" PRIu32, bpp);
|
2019-05-08 16:03:06 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2020-08-10 13:26:33 +03:00
|
|
|
/* Ensure we have enough source data bytes for image copy. */
|
2022-04-28 06:43:31 +03:00
|
|
|
if (cbBitsColor < nWidth * nHeight * FreeRDPGetBytesPerPixel(format))
|
2020-08-10 13:26:33 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2019-05-08 16:03:06 +03:00
|
|
|
fill_gdi_palette_for_icon(colorTable, cbColorTable, &palette);
|
2019-11-06 17:24:51 +03:00
|
|
|
if (!freerdp_image_copy(pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth, nHeight, bitsColor,
|
|
|
|
format, 0, 0, 0, &palette, FREERDP_FLIP_VERTICAL))
|
2019-05-08 16:03:06 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
/* apply alpha mask */
|
2022-04-28 06:43:31 +03:00
|
|
|
if (FreeRDPColorHasAlpha(DstFormat) && cbBitsMask)
|
2019-05-08 16:03:06 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE nextBit = 0;
|
|
|
|
const BYTE* maskByte = NULL;
|
|
|
|
UINT32 stride = 0;
|
|
|
|
BYTE r = 0;
|
|
|
|
BYTE g = 0;
|
|
|
|
BYTE b = 0;
|
2019-05-08 16:03:06 +03:00
|
|
|
BYTE* dstBuf = pDstData;
|
2022-04-28 06:43:31 +03:00
|
|
|
UINT32 dstBpp = FreeRDPGetBytesPerPixel(DstFormat);
|
2019-05-08 16:03:06 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Each byte encodes 8 adjacent pixels (with LSB padding as needed).
|
|
|
|
* And due to hysterical raisins, stride of DIB bitmaps must be
|
|
|
|
* a multiple of 4 bytes.
|
|
|
|
*/
|
|
|
|
stride = round_up(div_ceil(nWidth, 8), 4);
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 y = 0; y < nHeight; y++)
|
2019-05-08 16:03:06 +03:00
|
|
|
{
|
|
|
|
maskByte = &bitsMask[stride * (nHeight - 1 - y)];
|
|
|
|
nextBit = 0x80;
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 x = 0; x < nWidth; x++)
|
2019-05-08 16:03:06 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 color = 0;
|
2019-05-08 16:03:06 +03:00
|
|
|
BYTE alpha = (*maskByte & nextBit) ? 0x00 : 0xFF;
|
|
|
|
|
|
|
|
/* read color back, add alpha and write it back */
|
2022-04-28 06:43:31 +03:00
|
|
|
color = FreeRDPReadColor(dstBuf, DstFormat);
|
|
|
|
FreeRDPSplitColor(color, DstFormat, &r, &g, &b, NULL, &palette);
|
2019-05-08 16:03:06 +03:00
|
|
|
color = FreeRDPGetColor(DstFormat, r, g, b, alpha);
|
2022-04-28 06:43:31 +03:00
|
|
|
FreeRDPWriteColor(dstBuf, DstFormat, color);
|
2019-05-08 16:03:06 +03:00
|
|
|
|
|
|
|
nextBit >>= 1;
|
|
|
|
dstBuf += dstBpp;
|
|
|
|
if (!nextBit)
|
|
|
|
{
|
|
|
|
nextBit = 0x80;
|
|
|
|
maskByte++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-08-23 16:10:04 +03:00
|
|
|
static BOOL freerdp_image_copy_from_pointer_data_1bpp(
|
|
|
|
BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
|
|
|
|
UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT xorMask, UINT32 xorMaskLength,
|
|
|
|
const BYTE* WINPR_RESTRICT andMask, UINT32 andMaskLength, UINT32 xorBpp)
|
2014-09-17 20:17:41 +04:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BOOL vFlip = 0;
|
|
|
|
UINT32 xorStep = 0;
|
|
|
|
UINT32 andStep = 0;
|
|
|
|
UINT32 xorBit = 0;
|
|
|
|
UINT32 andBit = 0;
|
|
|
|
UINT32 xorPixel = 0;
|
|
|
|
UINT32 andPixel = 0;
|
2014-09-18 02:30:09 +04:00
|
|
|
|
2020-04-22 12:23:14 +03:00
|
|
|
vFlip = (xorBpp == 1) ? FALSE : TRUE;
|
|
|
|
andStep = (nWidth + 7) / 8;
|
|
|
|
andStep += (andStep % 2);
|
2014-09-18 02:30:09 +04:00
|
|
|
|
2020-04-22 12:23:14 +03:00
|
|
|
if (!xorMask || (xorMaskLength == 0))
|
|
|
|
return FALSE;
|
|
|
|
if (!andMask || (andMaskLength == 0))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
xorStep = (nWidth + 7) / 8;
|
|
|
|
xorStep += (xorStep % 2);
|
|
|
|
|
|
|
|
if (xorStep * nHeight > xorMaskLength)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (andStep * nHeight > andMaskLength)
|
|
|
|
return FALSE;
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 y = 0; y < nHeight; y++)
|
2018-11-23 11:16:23 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
const BYTE* andBits = NULL;
|
|
|
|
const BYTE* xorBits = NULL;
|
2020-04-22 12:23:14 +03:00
|
|
|
BYTE* pDstPixel =
|
2022-04-28 06:43:31 +03:00
|
|
|
&pDstData[((nYDst + y) * nDstStep) + (nXDst * FreeRDPGetBytesPerPixel(DstFormat))];
|
2020-04-22 12:23:14 +03:00
|
|
|
xorBit = andBit = 0x80;
|
|
|
|
|
|
|
|
if (!vFlip)
|
|
|
|
{
|
|
|
|
xorBits = &xorMask[xorStep * y];
|
|
|
|
andBits = &andMask[andStep * y];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
xorBits = &xorMask[xorStep * (nHeight - y - 1)];
|
|
|
|
andBits = &andMask[andStep * (nHeight - y - 1)];
|
|
|
|
}
|
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 x = 0; x < nWidth; x++)
|
2020-04-22 12:23:14 +03:00
|
|
|
{
|
|
|
|
UINT32 color = 0;
|
|
|
|
xorPixel = (*xorBits & xorBit) ? 1 : 0;
|
|
|
|
|
|
|
|
if (!(xorBit >>= 1))
|
|
|
|
{
|
|
|
|
xorBits++;
|
|
|
|
xorBit = 0x80;
|
|
|
|
}
|
|
|
|
|
|
|
|
andPixel = (*andBits & andBit) ? 1 : 0;
|
|
|
|
|
|
|
|
if (!(andBit >>= 1))
|
|
|
|
{
|
|
|
|
andBits++;
|
|
|
|
andBit = 0x80;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!andPixel && !xorPixel)
|
|
|
|
color = FreeRDPGetColor(DstFormat, 0, 0, 0, 0xFF); /* black */
|
|
|
|
else if (!andPixel && xorPixel)
|
|
|
|
color = FreeRDPGetColor(DstFormat, 0xFF, 0xFF, 0xFF, 0xFF); /* white */
|
|
|
|
else if (andPixel && !xorPixel)
|
|
|
|
color = FreeRDPGetColor(DstFormat, 0, 0, 0, 0); /* transparent */
|
|
|
|
else if (andPixel && xorPixel)
|
|
|
|
color = freerdp_image_inverted_pointer_color(x, y, DstFormat); /* inverted */
|
|
|
|
|
2022-04-28 06:43:31 +03:00
|
|
|
FreeRDPWriteColor(pDstPixel, DstFormat, color);
|
|
|
|
pDstPixel += FreeRDPGetBytesPerPixel(DstFormat);
|
2020-04-22 12:23:14 +03:00
|
|
|
}
|
2018-11-23 11:16:23 +03:00
|
|
|
}
|
|
|
|
|
2020-04-22 12:23:14 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-08-23 16:10:04 +03:00
|
|
|
static BOOL freerdp_image_copy_from_pointer_data_xbpp(
|
|
|
|
BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
|
|
|
|
UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT xorMask, UINT32 xorMaskLength,
|
|
|
|
const BYTE* WINPR_RESTRICT andMask, UINT32 andMaskLength, UINT32 xorBpp,
|
|
|
|
const gdiPalette* palette)
|
2020-04-22 12:23:14 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
BOOL vFlip = 0;
|
|
|
|
UINT32 xorStep = 0;
|
|
|
|
UINT32 andStep = 0;
|
|
|
|
UINT32 andBit = 0;
|
|
|
|
UINT32 xorPixel = 0;
|
|
|
|
UINT32 andPixel = 0;
|
|
|
|
UINT32 dstBitsPerPixel = 0;
|
|
|
|
UINT32 xorBytesPerPixel = 0;
|
2022-04-28 06:43:31 +03:00
|
|
|
dstBitsPerPixel = FreeRDPGetBitsPerPixel(DstFormat);
|
2020-04-22 12:23:14 +03:00
|
|
|
|
2016-10-14 11:01:02 +03:00
|
|
|
vFlip = (xorBpp == 1) ? FALSE : TRUE;
|
2016-04-05 18:07:45 +03:00
|
|
|
andStep = (nWidth + 7) / 8;
|
|
|
|
andStep += (andStep % 2);
|
2014-10-15 04:59:22 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!xorMask || (xorMaskLength == 0))
|
2016-12-05 15:44:08 +03:00
|
|
|
return FALSE;
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2020-04-22 12:23:14 +03:00
|
|
|
xorBytesPerPixel = xorBpp >> 3;
|
|
|
|
xorStep = nWidth * xorBytesPerPixel;
|
|
|
|
xorStep += (xorStep % 2);
|
2014-10-13 20:29:06 +04:00
|
|
|
|
2020-04-22 12:23:14 +03:00
|
|
|
if (xorBpp == 8 && !palette)
|
|
|
|
{
|
|
|
|
WLog_ERR(TAG, "null palette in conversion from %" PRIu32 " bpp to %" PRIu32 " bpp", xorBpp,
|
|
|
|
dstBitsPerPixel);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2020-04-22 12:23:14 +03:00
|
|
|
if (xorStep * nHeight > xorMaskLength)
|
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2020-04-22 12:23:14 +03:00
|
|
|
if (andMask)
|
|
|
|
{
|
|
|
|
if (andStep * nHeight > andMaskLength)
|
|
|
|
return FALSE;
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 y = 0; y < nHeight; y++)
|
2020-04-22 12:23:14 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
const BYTE* xorBits = NULL;
|
2020-04-22 12:23:14 +03:00
|
|
|
const BYTE* andBits = NULL;
|
|
|
|
BYTE* pDstPixel =
|
2022-04-28 06:43:31 +03:00
|
|
|
&pDstData[((nYDst + y) * nDstStep) + (nXDst * FreeRDPGetBytesPerPixel(DstFormat))];
|
2020-04-22 12:23:14 +03:00
|
|
|
andBit = 0x80;
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2020-04-22 12:23:14 +03:00
|
|
|
if (!vFlip)
|
|
|
|
{
|
|
|
|
if (andMask)
|
|
|
|
andBits = &andMask[andStep * y];
|
2014-10-13 20:29:06 +04:00
|
|
|
|
2020-04-22 12:23:14 +03:00
|
|
|
xorBits = &xorMask[xorStep * y];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (andMask)
|
|
|
|
andBits = &andMask[andStep * (nHeight - y - 1)];
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2020-04-22 12:23:14 +03:00
|
|
|
xorBits = &xorMask[xorStep * (nHeight - y - 1)];
|
|
|
|
}
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2024-01-30 12:25:38 +03:00
|
|
|
for (UINT32 x = 0; x < nWidth; x++)
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 pixelFormat = 0;
|
|
|
|
UINT32 color = 0;
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2020-04-22 12:23:14 +03:00
|
|
|
if (xorBpp == 32)
|
|
|
|
{
|
|
|
|
pixelFormat = PIXEL_FORMAT_BGRA32;
|
2022-04-28 06:43:31 +03:00
|
|
|
xorPixel = FreeRDPReadColor(xorBits, pixelFormat);
|
2020-04-22 12:23:14 +03:00
|
|
|
}
|
|
|
|
else if (xorBpp == 16)
|
|
|
|
{
|
|
|
|
pixelFormat = PIXEL_FORMAT_RGB15;
|
2022-04-28 06:43:31 +03:00
|
|
|
xorPixel = FreeRDPReadColor(xorBits, pixelFormat);
|
2020-04-22 12:23:14 +03:00
|
|
|
}
|
|
|
|
else if (xorBpp == 8)
|
2014-09-17 20:17:41 +04:00
|
|
|
{
|
2020-04-22 12:23:14 +03:00
|
|
|
pixelFormat = palette->format;
|
|
|
|
xorPixel = palette->palette[xorBits[0]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pixelFormat = PIXEL_FORMAT_BGR24;
|
2022-04-28 06:43:31 +03:00
|
|
|
xorPixel = FreeRDPReadColor(xorBits, pixelFormat);
|
2019-11-06 17:24:51 +03:00
|
|
|
}
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2020-04-22 12:23:14 +03:00
|
|
|
xorPixel = FreeRDPConvertColor(xorPixel, pixelFormat, PIXEL_FORMAT_ARGB32, palette);
|
|
|
|
xorBits += xorBytesPerPixel;
|
|
|
|
andPixel = 0;
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
if (andMask)
|
|
|
|
{
|
2020-04-22 12:23:14 +03:00
|
|
|
andPixel = (*andBits & andBit) ? 1 : 0;
|
|
|
|
|
|
|
|
if (!(andBit >>= 1))
|
|
|
|
{
|
|
|
|
andBits++;
|
|
|
|
andBit = 0x80;
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
}
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2020-04-22 12:23:14 +03:00
|
|
|
if (andPixel)
|
2019-11-06 17:24:51 +03:00
|
|
|
{
|
2020-04-22 12:23:14 +03:00
|
|
|
if (xorPixel == 0xFF000000) /* black -> transparent */
|
|
|
|
xorPixel = 0x00000000;
|
|
|
|
else if (xorPixel == 0xFFFFFFFF) /* white -> inverted */
|
|
|
|
xorPixel = freerdp_image_inverted_pointer_color(x, y, PIXEL_FORMAT_ARGB32);
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2020-04-22 12:23:14 +03:00
|
|
|
color = FreeRDPConvertColor(xorPixel, PIXEL_FORMAT_ARGB32, DstFormat, palette);
|
2022-04-28 06:43:31 +03:00
|
|
|
FreeRDPWriteColor(pDstPixel, DstFormat, color);
|
|
|
|
pDstPixel += FreeRDPGetBytesPerPixel(DstFormat);
|
2020-04-22 12:23:14 +03:00
|
|
|
}
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2020-04-22 12:23:14 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2020-04-22 12:23:14 +03:00
|
|
|
/**
|
|
|
|
* Drawing Monochrome Pointers:
|
|
|
|
* http://msdn.microsoft.com/en-us/library/windows/hardware/ff556143/
|
|
|
|
*
|
|
|
|
* Drawing Color Pointers:
|
|
|
|
* http://msdn.microsoft.com/en-us/library/windows/hardware/ff556138/
|
|
|
|
*/
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2023-08-23 16:10:04 +03:00
|
|
|
BOOL freerdp_image_copy_from_pointer_data(BYTE* WINPR_RESTRICT pDstData, UINT32 DstFormat,
|
|
|
|
UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
|
|
|
|
UINT32 nWidth, UINT32 nHeight,
|
|
|
|
const BYTE* WINPR_RESTRICT xorMask, UINT32 xorMaskLength,
|
|
|
|
const BYTE* WINPR_RESTRICT andMask, UINT32 andMaskLength,
|
|
|
|
UINT32 xorBpp, const gdiPalette* palette)
|
2020-04-22 12:23:14 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 dstBitsPerPixel = 0;
|
|
|
|
UINT32 dstBytesPerPixel = 0;
|
2022-04-28 06:43:31 +03:00
|
|
|
dstBitsPerPixel = FreeRDPGetBitsPerPixel(DstFormat);
|
|
|
|
dstBytesPerPixel = FreeRDPGetBytesPerPixel(DstFormat);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2020-04-22 12:23:14 +03:00
|
|
|
if (nDstStep <= 0)
|
|
|
|
nDstStep = dstBytesPerPixel * nWidth;
|
|
|
|
|
2023-08-23 16:10:04 +03:00
|
|
|
for (UINT32 y = nYDst; y < nHeight; y++)
|
2020-04-22 12:23:14 +03:00
|
|
|
{
|
2023-08-23 16:10:04 +03:00
|
|
|
BYTE* WINPR_RESTRICT pDstLine = &pDstData[y * nDstStep + nXDst * dstBytesPerPixel];
|
2023-08-22 10:41:28 +03:00
|
|
|
memset(pDstLine, 0, 1ull * dstBytesPerPixel * (nWidth - nXDst));
|
2020-04-22 12:23:14 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (xorBpp)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
return freerdp_image_copy_from_pointer_data_1bpp(
|
|
|
|
pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth, nHeight, xorMask,
|
|
|
|
xorMaskLength, andMask, andMaskLength, xorBpp);
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
case 16:
|
|
|
|
case 24:
|
|
|
|
case 32:
|
|
|
|
return freerdp_image_copy_from_pointer_data_xbpp(
|
|
|
|
pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth, nHeight, xorMask,
|
|
|
|
xorMaskLength, andMask, andMaskLength, xorBpp, palette);
|
2019-11-06 17:24:51 +03:00
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
default:
|
2019-11-06 17:24:51 +03:00
|
|
|
WLog_ERR(TAG, "failed to convert from %" PRIu32 " bpp to %" PRIu32 " bpp", xorBpp,
|
|
|
|
dstBitsPerPixel);
|
2016-12-05 15:44:08 +03:00
|
|
|
return FALSE;
|
2014-09-17 20:17:41 +04:00
|
|
|
}
|
2014-03-01 06:51:29 +04:00
|
|
|
}
|
2014-06-13 16:36:09 +04:00
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
static INLINE BOOL overlapping(const BYTE* pDstData, UINT32 nXDst, UINT32 nYDst, UINT32 nDstStep,
|
|
|
|
UINT32 dstBytesPerPixel, const BYTE* pSrcData, UINT32 nXSrc,
|
|
|
|
UINT32 nYSrc, UINT32 nSrcStep, UINT32 srcBytesPerPixel,
|
2017-01-16 13:45:53 +03:00
|
|
|
UINT32 nWidth, UINT32 nHeight)
|
2016-04-23 12:25:55 +03:00
|
|
|
{
|
|
|
|
const BYTE* pDstStart = &pDstData[nXDst * dstBytesPerPixel + nYDst * nDstStep];
|
|
|
|
const BYTE* pDstEnd = pDstStart + nHeight * nDstStep;
|
|
|
|
const BYTE* pSrcStart = &pSrcData[nXSrc * srcBytesPerPixel + nYSrc * nSrcStep];
|
|
|
|
const BYTE* pSrcEnd = pSrcStart + nHeight * nSrcStep;
|
|
|
|
|
2020-08-10 13:26:33 +03:00
|
|
|
WINPR_UNUSED(nWidth);
|
|
|
|
|
2016-04-23 12:25:55 +03:00
|
|
|
if ((pDstStart >= pSrcStart) && (pDstStart <= pSrcEnd))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if ((pDstEnd >= pSrcStart) && (pDstEnd <= pSrcEnd))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2023-08-23 16:10:04 +03:00
|
|
|
static BOOL freerdp_image_copy_no_overlap(BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat,
|
|
|
|
UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
|
|
|
|
UINT32 nWidth, UINT32 nHeight,
|
|
|
|
const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat,
|
|
|
|
UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc,
|
|
|
|
const gdiPalette* WINPR_RESTRICT palette, UINT32 flags)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2024-04-20 18:16:25 +03:00
|
|
|
const SSIZE_T dstByte = FreeRDPGetBytesPerPixel(DstFormat);
|
|
|
|
const SSIZE_T srcByte = FreeRDPGetBytesPerPixel(SrcFormat);
|
|
|
|
const SSIZE_T copyDstWidth = nWidth * dstByte;
|
|
|
|
const SSIZE_T xSrcOffset = nXSrc * srcByte;
|
|
|
|
const SSIZE_T xDstOffset = nXDst * dstByte;
|
2023-07-04 10:26:52 +03:00
|
|
|
const BOOL vSrcVFlip = (flags & FREERDP_FLIP_VERTICAL) ? TRUE : FALSE;
|
2024-04-20 18:16:25 +03:00
|
|
|
SSIZE_T srcVOffset = 0;
|
|
|
|
SSIZE_T srcVMultiplier = 1;
|
|
|
|
SSIZE_T dstVOffset = 0;
|
|
|
|
SSIZE_T dstVMultiplier = 1;
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2019-02-07 16:17:35 +03:00
|
|
|
if ((nHeight > INT32_MAX) || (nWidth > INT32_MAX))
|
|
|
|
return FALSE;
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!pDstData || !pSrcData)
|
|
|
|
return FALSE;
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2016-09-06 15:20:07 +03:00
|
|
|
if (nDstStep == 0)
|
2022-04-28 06:43:31 +03:00
|
|
|
nDstStep = nWidth * FreeRDPGetBytesPerPixel(DstFormat);
|
2014-09-17 01:41:24 +04:00
|
|
|
|
2016-09-06 15:20:07 +03:00
|
|
|
if (nSrcStep == 0)
|
2022-04-28 06:43:31 +03:00
|
|
|
nSrcStep = nWidth * FreeRDPGetBytesPerPixel(SrcFormat);
|
2014-09-17 01:41:24 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (vSrcVFlip)
|
2014-09-17 01:41:24 +04:00
|
|
|
{
|
2024-04-20 18:16:25 +03:00
|
|
|
srcVOffset = (nHeight - 1ll) * nSrcStep;
|
2016-04-05 18:07:45 +03:00
|
|
|
srcVMultiplier = -1;
|
2014-09-17 01:41:24 +04:00
|
|
|
}
|
|
|
|
|
2023-01-09 09:56:58 +03:00
|
|
|
if (((flags & FREERDP_KEEP_DST_ALPHA) != 0) && FreeRDPColorHasAlpha(DstFormat))
|
|
|
|
{
|
2024-04-20 18:16:25 +03:00
|
|
|
for (SSIZE_T y = 0; y < nHeight; y++)
|
2023-01-09 09:56:58 +03:00
|
|
|
{
|
2023-08-23 16:10:04 +03:00
|
|
|
const BYTE* WINPR_RESTRICT srcLine =
|
2024-04-20 18:16:25 +03:00
|
|
|
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
|
2023-08-23 16:10:04 +03:00
|
|
|
BYTE* WINPR_RESTRICT dstLine =
|
2024-04-20 18:16:25 +03:00
|
|
|
&pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
|
2023-01-09 09:56:58 +03:00
|
|
|
|
|
|
|
UINT32 color = FreeRDPReadColor(&srcLine[nXSrc * srcByte], SrcFormat);
|
|
|
|
UINT32 oldColor = color;
|
|
|
|
UINT32 dstColor = FreeRDPConvertColor(color, SrcFormat, DstFormat, palette);
|
|
|
|
FreeRDPWriteColorIgnoreAlpha(&dstLine[nXDst * dstByte], DstFormat, dstColor);
|
2024-04-20 18:16:25 +03:00
|
|
|
for (SSIZE_T x = 1; x < nWidth; x++)
|
2023-01-09 09:56:58 +03:00
|
|
|
{
|
|
|
|
color = FreeRDPReadColor(&srcLine[(x + nXSrc) * srcByte], SrcFormat);
|
|
|
|
if (color == oldColor)
|
|
|
|
{
|
|
|
|
FreeRDPWriteColorIgnoreAlpha(&dstLine[(x + nXDst) * dstByte], DstFormat,
|
|
|
|
dstColor);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
oldColor = color;
|
|
|
|
dstColor = FreeRDPConvertColor(color, SrcFormat, DstFormat, palette);
|
|
|
|
FreeRDPWriteColorIgnoreAlpha(&dstLine[(x + nXDst) * dstByte], DstFormat,
|
|
|
|
dstColor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (FreeRDPAreColorFormatsEqualNoAlpha(SrcFormat, DstFormat))
|
2014-06-13 16:36:09 +04:00
|
|
|
{
|
2024-04-20 18:16:25 +03:00
|
|
|
for (SSIZE_T y = 0; y < nHeight; y++)
|
2014-06-13 16:36:09 +04:00
|
|
|
{
|
2023-08-23 16:10:04 +03:00
|
|
|
const BYTE* WINPR_RESTRICT srcLine =
|
2024-04-20 18:16:25 +03:00
|
|
|
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
|
2023-08-23 16:10:04 +03:00
|
|
|
BYTE* WINPR_RESTRICT dstLine =
|
2024-04-20 18:16:25 +03:00
|
|
|
&pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
|
2023-08-23 16:10:04 +03:00
|
|
|
memcpy(&dstLine[xDstOffset], &srcLine[xSrcOffset], copyDstWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-04-20 18:16:25 +03:00
|
|
|
for (SSIZE_T y = 0; y < nHeight; y++)
|
2023-08-23 16:10:04 +03:00
|
|
|
{
|
|
|
|
const BYTE* WINPR_RESTRICT srcLine =
|
2024-04-20 18:16:25 +03:00
|
|
|
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
|
2023-08-23 16:10:04 +03:00
|
|
|
BYTE* WINPR_RESTRICT dstLine =
|
2024-04-20 18:16:25 +03:00
|
|
|
&pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
|
2023-08-23 16:10:04 +03:00
|
|
|
|
|
|
|
UINT32 color = FreeRDPReadColor(&srcLine[nXSrc * srcByte], SrcFormat);
|
|
|
|
UINT32 oldColor = color;
|
|
|
|
UINT32 dstColor = FreeRDPConvertColor(color, SrcFormat, DstFormat, palette);
|
|
|
|
FreeRDPWriteColor(&dstLine[nXDst * dstByte], DstFormat, dstColor);
|
2024-04-20 18:16:25 +03:00
|
|
|
for (SSIZE_T x = 1; x < nWidth; x++)
|
2016-04-20 10:57:42 +03:00
|
|
|
{
|
2023-08-23 16:10:04 +03:00
|
|
|
color = FreeRDPReadColor(&srcLine[(x + nXSrc) * srcByte], SrcFormat);
|
|
|
|
if (color == oldColor)
|
2016-04-20 10:57:42 +03:00
|
|
|
{
|
2023-08-23 16:10:04 +03:00
|
|
|
FreeRDPWriteColor(&dstLine[(x + nXDst) * dstByte], DstFormat, dstColor);
|
2016-04-20 10:57:42 +03:00
|
|
|
}
|
2023-08-23 16:10:04 +03:00
|
|
|
else
|
2016-04-20 10:57:42 +03:00
|
|
|
{
|
2023-08-23 16:10:04 +03:00
|
|
|
oldColor = color;
|
|
|
|
dstColor = FreeRDPConvertColor(color, SrcFormat, DstFormat, palette);
|
|
|
|
FreeRDPWriteColor(&dstLine[(x + nXDst) * dstByte], DstFormat, dstColor);
|
2016-04-20 10:57:42 +03:00
|
|
|
}
|
|
|
|
}
|
2023-08-23 16:10:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL freerdp_image_copy_overlap(BYTE* pDstData, DWORD DstFormat, UINT32 nDstStep,
|
|
|
|
UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight,
|
|
|
|
const BYTE* pSrcData, DWORD SrcFormat, UINT32 nSrcStep,
|
|
|
|
UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* palette,
|
|
|
|
UINT32 flags)
|
|
|
|
{
|
|
|
|
const UINT32 dstByte = FreeRDPGetBytesPerPixel(DstFormat);
|
|
|
|
const UINT32 srcByte = FreeRDPGetBytesPerPixel(SrcFormat);
|
|
|
|
const UINT32 copyDstWidth = nWidth * dstByte;
|
|
|
|
const UINT32 xSrcOffset = nXSrc * srcByte;
|
|
|
|
const UINT32 xDstOffset = nXDst * dstByte;
|
|
|
|
const BOOL vSrcVFlip = (flags & FREERDP_FLIP_VERTICAL) ? TRUE : FALSE;
|
2024-04-20 18:16:25 +03:00
|
|
|
SSIZE_T srcVOffset = 0;
|
|
|
|
SSIZE_T srcVMultiplier = 1;
|
|
|
|
SSIZE_T dstVOffset = 0;
|
|
|
|
SSIZE_T dstVMultiplier = 1;
|
2023-08-23 16:10:04 +03:00
|
|
|
|
|
|
|
if ((nHeight > INT32_MAX) || (nWidth > INT32_MAX))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!pDstData || !pSrcData)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (nDstStep == 0)
|
|
|
|
nDstStep = nWidth * FreeRDPGetBytesPerPixel(DstFormat);
|
|
|
|
|
|
|
|
if (nSrcStep == 0)
|
|
|
|
nSrcStep = nWidth * FreeRDPGetBytesPerPixel(SrcFormat);
|
|
|
|
|
|
|
|
if (vSrcVFlip)
|
|
|
|
{
|
2024-04-20 18:16:25 +03:00
|
|
|
srcVOffset = (nHeight - 1ll) * nSrcStep;
|
2023-08-23 16:10:04 +03:00
|
|
|
srcVMultiplier = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((flags & FREERDP_KEEP_DST_ALPHA) != 0) && FreeRDPColorHasAlpha(DstFormat))
|
|
|
|
{
|
2024-04-20 18:16:25 +03:00
|
|
|
for (SSIZE_T y = 0; y < nHeight; y++)
|
2023-08-23 16:10:04 +03:00
|
|
|
{
|
2024-04-20 18:16:25 +03:00
|
|
|
const BYTE* srcLine = &pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
|
|
|
|
BYTE* dstLine = &pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
|
2023-08-23 16:10:04 +03:00
|
|
|
|
|
|
|
UINT32 color = FreeRDPReadColor(&srcLine[nXSrc * srcByte], SrcFormat);
|
|
|
|
UINT32 oldColor = color;
|
|
|
|
UINT32 dstColor = FreeRDPConvertColor(color, SrcFormat, DstFormat, palette);
|
|
|
|
FreeRDPWriteColorIgnoreAlpha(&dstLine[nXDst * dstByte], DstFormat, dstColor);
|
|
|
|
for (UINT32 x = 1; x < nWidth; x++)
|
2016-04-20 10:57:42 +03:00
|
|
|
{
|
2023-08-23 16:10:04 +03:00
|
|
|
color = FreeRDPReadColor(&srcLine[(x + nXSrc) * srcByte], SrcFormat);
|
|
|
|
if (color == oldColor)
|
2016-04-20 10:57:42 +03:00
|
|
|
{
|
2023-08-23 16:10:04 +03:00
|
|
|
FreeRDPWriteColorIgnoreAlpha(&dstLine[(x + nXDst) * dstByte], DstFormat,
|
|
|
|
dstColor);
|
2016-04-20 10:57:42 +03:00
|
|
|
}
|
2023-08-23 16:10:04 +03:00
|
|
|
else
|
2016-04-20 10:57:42 +03:00
|
|
|
{
|
2023-08-23 16:10:04 +03:00
|
|
|
oldColor = color;
|
|
|
|
dstColor = FreeRDPConvertColor(color, SrcFormat, DstFormat, palette);
|
|
|
|
FreeRDPWriteColorIgnoreAlpha(&dstLine[(x + nXDst) * dstByte], DstFormat,
|
|
|
|
dstColor);
|
2016-04-20 10:57:42 +03:00
|
|
|
}
|
|
|
|
}
|
2023-08-23 16:10:04 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (FreeRDPAreColorFormatsEqualNoAlpha(SrcFormat, DstFormat))
|
|
|
|
{
|
|
|
|
/* Copy down */
|
|
|
|
if (nYDst < nYSrc)
|
|
|
|
{
|
2024-04-20 18:16:25 +03:00
|
|
|
for (SSIZE_T y = 0; y < nHeight; y++)
|
2016-04-20 10:57:42 +03:00
|
|
|
{
|
2023-08-23 16:10:04 +03:00
|
|
|
const BYTE* srcLine =
|
|
|
|
&pSrcData[(y + nYSrc) * nSrcStep * srcVMultiplier + srcVOffset];
|
2024-04-20 18:16:25 +03:00
|
|
|
BYTE* dstLine = &pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
|
2023-08-23 16:10:04 +03:00
|
|
|
memcpy(&dstLine[xDstOffset], &srcLine[xSrcOffset], copyDstWidth);
|
2016-04-20 10:57:42 +03:00
|
|
|
}
|
|
|
|
}
|
2023-08-23 16:10:04 +03:00
|
|
|
/* Copy up */
|
|
|
|
else if (nYDst > nYSrc)
|
2016-04-20 10:57:42 +03:00
|
|
|
{
|
2024-04-20 18:16:25 +03:00
|
|
|
for (SSIZE_T y = nHeight - 1; y >= 0; y--)
|
2016-04-20 10:57:42 +03:00
|
|
|
{
|
2019-11-06 17:24:51 +03:00
|
|
|
const BYTE* srcLine =
|
2024-04-20 18:16:25 +03:00
|
|
|
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
|
|
|
|
BYTE* dstLine = &pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
|
2019-11-06 17:24:51 +03:00
|
|
|
memcpy(&dstLine[xDstOffset], &srcLine[xSrcOffset], copyDstWidth);
|
2016-04-20 10:57:42 +03:00
|
|
|
}
|
2014-06-13 16:36:09 +04:00
|
|
|
}
|
2023-08-23 16:10:04 +03:00
|
|
|
/* Copy left */
|
|
|
|
else if (nXSrc > nXDst)
|
|
|
|
{
|
2024-04-20 18:16:25 +03:00
|
|
|
for (SSIZE_T y = 0; y < nHeight; y++)
|
2023-08-23 16:10:04 +03:00
|
|
|
{
|
|
|
|
const BYTE* srcLine =
|
2024-04-20 18:16:25 +03:00
|
|
|
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
|
|
|
|
BYTE* dstLine = &pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
|
2023-08-23 16:10:04 +03:00
|
|
|
memmove(&dstLine[xDstOffset], &srcLine[xSrcOffset], copyDstWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Copy right */
|
|
|
|
else if (nXSrc < nXDst)
|
|
|
|
{
|
2024-04-20 18:16:25 +03:00
|
|
|
for (SSIZE_T y = nHeight - 1; y >= 0; y--)
|
2023-08-23 16:10:04 +03:00
|
|
|
{
|
|
|
|
const BYTE* srcLine =
|
2024-04-20 18:16:25 +03:00
|
|
|
&pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
|
|
|
|
BYTE* dstLine = &pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
|
2023-08-23 16:10:04 +03:00
|
|
|
memmove(&dstLine[xDstOffset], &srcLine[xSrcOffset], copyDstWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Source and destination are equal... */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
}
|
2014-06-13 16:36:09 +04:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
else
|
2014-06-13 16:36:09 +04:00
|
|
|
{
|
2024-04-20 18:16:25 +03:00
|
|
|
for (SSIZE_T y = 0; y < nHeight; y++)
|
2014-06-13 16:36:09 +04:00
|
|
|
{
|
2024-04-20 18:16:25 +03:00
|
|
|
const BYTE* srcLine = &pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
|
|
|
|
BYTE* dstLine = &pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
|
2014-06-13 16:36:09 +04:00
|
|
|
|
2022-04-28 06:43:31 +03:00
|
|
|
UINT32 color = FreeRDPReadColor(&srcLine[nXSrc * srcByte], SrcFormat);
|
2020-04-11 03:35:39 +03:00
|
|
|
UINT32 oldColor = color;
|
|
|
|
UINT32 dstColor = FreeRDPConvertColor(color, SrcFormat, DstFormat, palette);
|
2022-04-28 06:43:31 +03:00
|
|
|
FreeRDPWriteColor(&dstLine[nXDst * dstByte], DstFormat, dstColor);
|
2024-04-20 18:16:25 +03:00
|
|
|
for (SSIZE_T x = 1; x < nWidth; x++)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2022-04-28 06:43:31 +03:00
|
|
|
color = FreeRDPReadColor(&srcLine[(x + nXSrc) * srcByte], SrcFormat);
|
2020-04-11 03:35:39 +03:00
|
|
|
if (color == oldColor)
|
|
|
|
{
|
2022-04-28 06:43:31 +03:00
|
|
|
FreeRDPWriteColor(&dstLine[(x + nXDst) * dstByte], DstFormat, dstColor);
|
2020-04-11 03:35:39 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
oldColor = color;
|
|
|
|
dstColor = FreeRDPConvertColor(color, SrcFormat, DstFormat, palette);
|
2022-04-28 06:43:31 +03:00
|
|
|
FreeRDPWriteColor(&dstLine[(x + nXDst) * dstByte], DstFormat, dstColor);
|
2020-04-11 03:35:39 +03:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2014-06-13 16:36:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
return TRUE;
|
2014-06-13 16:36:09 +04:00
|
|
|
}
|
|
|
|
|
2023-08-23 16:10:04 +03:00
|
|
|
BOOL freerdp_image_copy(BYTE* pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst,
|
|
|
|
UINT32 nYDst, UINT32 nWidth, UINT32 nHeight, const BYTE* pSrcData,
|
|
|
|
DWORD SrcFormat, UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc,
|
|
|
|
const gdiPalette* palette, UINT32 flags)
|
|
|
|
{
|
|
|
|
const UINT32 dstByte = FreeRDPGetBytesPerPixel(DstFormat);
|
|
|
|
const UINT32 srcByte = FreeRDPGetBytesPerPixel(SrcFormat);
|
|
|
|
|
|
|
|
if ((nHeight > INT32_MAX) || (nWidth > INT32_MAX))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!pDstData || !pSrcData)
|
|
|
|
return FALSE;
|
|
|
|
|
2024-04-21 11:18:43 +03:00
|
|
|
if ((nWidth == 0) || (nHeight == 0))
|
|
|
|
return TRUE;
|
|
|
|
|
2023-08-23 16:10:04 +03:00
|
|
|
if (nDstStep == 0)
|
|
|
|
nDstStep = nWidth * FreeRDPGetBytesPerPixel(DstFormat);
|
|
|
|
|
|
|
|
if (nSrcStep == 0)
|
|
|
|
nSrcStep = nWidth * FreeRDPGetBytesPerPixel(SrcFormat);
|
|
|
|
|
|
|
|
const BOOL ovl = overlapping(pDstData, nXDst, nYDst, nDstStep, dstByte, pSrcData, nXSrc, nYSrc,
|
|
|
|
nSrcStep, srcByte, nWidth, nHeight);
|
|
|
|
if (ovl)
|
|
|
|
return freerdp_image_copy_overlap(pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth,
|
|
|
|
nHeight, pSrcData, SrcFormat, nSrcStep, nXSrc, nYSrc,
|
|
|
|
palette, flags);
|
|
|
|
return freerdp_image_copy_no_overlap(pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth,
|
|
|
|
nHeight, pSrcData, SrcFormat, nSrcStep, nXSrc, nYSrc,
|
|
|
|
palette, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL freerdp_image_fill(BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, UINT32 nDstStep,
|
|
|
|
UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight, UINT32 color)
|
2014-09-15 04:08:38 +04:00
|
|
|
{
|
2023-08-04 17:42:05 +03:00
|
|
|
if ((nWidth == 0) || (nHeight == 0))
|
|
|
|
return TRUE;
|
2022-04-28 06:43:31 +03:00
|
|
|
const UINT32 bpp = FreeRDPGetBytesPerPixel(DstFormat);
|
2024-01-23 18:49:54 +03:00
|
|
|
BYTE* WINPR_RESTRICT pFirstDstLine = NULL;
|
|
|
|
BYTE* WINPR_RESTRICT pFirstDstLineXOffset = NULL;
|
2021-10-18 11:15:25 +03:00
|
|
|
|
|
|
|
if (nDstStep == 0)
|
2022-04-28 06:43:31 +03:00
|
|
|
nDstStep = (nXDst + nWidth) * FreeRDPGetBytesPerPixel(DstFormat);
|
2021-10-18 11:15:25 +03:00
|
|
|
|
|
|
|
pFirstDstLine = &pDstData[nYDst * nDstStep];
|
|
|
|
pFirstDstLineXOffset = &pFirstDstLine[nXDst * bpp];
|
2015-08-06 12:24:42 +03:00
|
|
|
|
2023-08-04 17:42:05 +03:00
|
|
|
for (UINT32 x = 0; x < nWidth; x++)
|
2014-09-15 04:08:38 +04:00
|
|
|
{
|
2017-01-16 13:36:35 +03:00
|
|
|
BYTE* pDst = &pFirstDstLine[(x + nXDst) * bpp];
|
2022-04-28 06:43:31 +03:00
|
|
|
FreeRDPWriteColor(pDst, DstFormat, color);
|
2017-01-16 13:36:35 +03:00
|
|
|
}
|
2015-08-06 12:24:42 +03:00
|
|
|
|
2023-08-04 17:42:05 +03:00
|
|
|
for (UINT32 y = 1; y < nHeight; y++)
|
2017-01-16 13:36:35 +03:00
|
|
|
{
|
|
|
|
BYTE* pDstLine = &pDstData[(y + nYDst) * nDstStep + nXDst * bpp];
|
2023-08-22 10:41:28 +03:00
|
|
|
memcpy(pDstLine, pFirstDstLineXOffset, 1ull * nWidth * bpp);
|
2014-09-15 04:08:38 +04:00
|
|
|
}
|
2015-08-06 12:24:42 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
return TRUE;
|
2014-09-15 04:08:38 +04:00
|
|
|
}
|
2019-05-06 14:18:31 +03:00
|
|
|
|
2022-07-06 15:04:06 +03:00
|
|
|
#if defined(WITH_SWSCALE)
|
2019-05-06 14:18:31 +03:00
|
|
|
static int av_format_for_buffer(UINT32 format)
|
|
|
|
{
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
case PIXEL_FORMAT_ARGB32:
|
|
|
|
return AV_PIX_FMT_BGRA;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_XRGB32:
|
|
|
|
return AV_PIX_FMT_BGR0;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_BGRA32:
|
|
|
|
return AV_PIX_FMT_RGBA;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_BGRX32:
|
|
|
|
return AV_PIX_FMT_RGB0;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return AV_PIX_FMT_NONE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-08-23 16:10:04 +03:00
|
|
|
BOOL freerdp_image_scale(BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, UINT32 nDstStep,
|
|
|
|
UINT32 nXDst, UINT32 nYDst, UINT32 nDstWidth, UINT32 nDstHeight,
|
|
|
|
const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat, UINT32 nSrcStep,
|
|
|
|
UINT32 nXSrc, UINT32 nYSrc, UINT32 nSrcWidth, UINT32 nSrcHeight)
|
2019-05-06 14:18:31 +03:00
|
|
|
{
|
|
|
|
BOOL rc = FALSE;
|
2020-09-07 05:14:17 +03:00
|
|
|
|
|
|
|
if (nDstStep == 0)
|
2022-04-28 06:43:31 +03:00
|
|
|
nDstStep = nDstWidth * FreeRDPGetBytesPerPixel(DstFormat);
|
2020-09-07 05:14:17 +03:00
|
|
|
|
|
|
|
if (nSrcStep == 0)
|
2022-04-28 06:43:31 +03:00
|
|
|
nSrcStep = nSrcWidth * FreeRDPGetBytesPerPixel(SrcFormat);
|
2020-09-07 05:14:17 +03:00
|
|
|
|
2022-07-06 15:04:06 +03:00
|
|
|
#if defined(WITH_SWSCALE) || defined(WITH_CAIRO)
|
2023-12-13 12:39:15 +03:00
|
|
|
const BYTE* src = &pSrcData[nXSrc * FreeRDPGetBytesPerPixel(SrcFormat) + nYSrc * nSrcStep];
|
|
|
|
BYTE* dst = &pDstData[nXDst * FreeRDPGetBytesPerPixel(DstFormat) + nYDst * nDstStep];
|
2020-08-10 13:26:33 +03:00
|
|
|
#endif
|
2019-05-07 13:10:23 +03:00
|
|
|
|
|
|
|
/* direct copy is much faster than scaling, so check if we can simply copy... */
|
|
|
|
if ((nDstWidth == nSrcWidth) && (nDstHeight == nSrcHeight))
|
|
|
|
{
|
2023-08-23 16:10:04 +03:00
|
|
|
return freerdp_image_copy_no_overlap(pDstData, DstFormat, nDstStep, nXDst, nYDst, nDstWidth,
|
|
|
|
nDstHeight, pSrcData, SrcFormat, nSrcStep, nXSrc,
|
|
|
|
nYSrc, NULL, FREERDP_FLIP_NONE);
|
2019-05-07 13:10:23 +03:00
|
|
|
}
|
|
|
|
else
|
2022-07-06 15:04:06 +03:00
|
|
|
#if defined(WITH_SWSCALE)
|
2019-05-06 14:18:31 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
int res = 0;
|
|
|
|
struct SwsContext* resize = NULL;
|
2019-05-06 14:18:31 +03:00
|
|
|
int srcFormat = av_format_for_buffer(SrcFormat);
|
|
|
|
int dstFormat = av_format_for_buffer(DstFormat);
|
2019-05-07 13:10:23 +03:00
|
|
|
const int srcStep[1] = { (int)nSrcStep };
|
|
|
|
const int dstStep[1] = { (int)nDstStep };
|
2019-05-06 14:18:31 +03:00
|
|
|
|
|
|
|
if ((srcFormat == AV_PIX_FMT_NONE) || (dstFormat == AV_PIX_FMT_NONE))
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
resize = sws_getContext((int)nSrcWidth, (int)nSrcHeight, srcFormat, (int)nDstWidth,
|
|
|
|
(int)nDstHeight, dstFormat, SWS_BILINEAR, NULL, NULL, NULL);
|
2019-05-06 14:18:31 +03:00
|
|
|
|
|
|
|
if (!resize)
|
|
|
|
goto fail;
|
|
|
|
|
2019-05-07 13:10:23 +03:00
|
|
|
res = sws_scale(resize, &src, srcStep, 0, (int)nSrcHeight, &dst, dstStep);
|
|
|
|
rc = (res == ((int)nDstHeight));
|
2019-05-06 14:18:31 +03:00
|
|
|
fail:
|
|
|
|
sws_freeContext(resize);
|
|
|
|
}
|
2019-05-07 13:10:23 +03:00
|
|
|
|
2022-07-06 15:04:06 +03:00
|
|
|
#elif defined(WITH_CAIRO)
|
2019-05-06 14:18:31 +03:00
|
|
|
{
|
|
|
|
const double sx = (double)nDstWidth / (double)nSrcWidth;
|
|
|
|
const double sy = (double)nDstHeight / (double)nSrcHeight;
|
|
|
|
cairo_t* cairo_context;
|
2019-11-06 17:24:51 +03:00
|
|
|
cairo_surface_t *csrc, *cdst;
|
2019-05-06 14:18:31 +03:00
|
|
|
|
|
|
|
if ((nSrcWidth > INT_MAX) || (nSrcHeight > INT_MAX) || (nSrcStep > INT_MAX))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if ((nDstWidth > INT_MAX) || (nDstHeight > INT_MAX) || (nDstStep > INT_MAX))
|
|
|
|
return FALSE;
|
|
|
|
|
2019-11-06 17:24:51 +03:00
|
|
|
csrc = cairo_image_surface_create_for_data((void*)src, CAIRO_FORMAT_ARGB32, (int)nSrcWidth,
|
|
|
|
(int)nSrcHeight, (int)nSrcStep);
|
|
|
|
cdst = cairo_image_surface_create_for_data(dst, CAIRO_FORMAT_ARGB32, (int)nDstWidth,
|
|
|
|
(int)nDstHeight, (int)nDstStep);
|
2019-05-06 14:18:31 +03:00
|
|
|
|
|
|
|
if (!csrc || !cdst)
|
|
|
|
goto fail;
|
|
|
|
|
|
|
|
cairo_context = cairo_create(cdst);
|
|
|
|
|
|
|
|
if (!cairo_context)
|
|
|
|
goto fail2;
|
|
|
|
|
|
|
|
cairo_scale(cairo_context, sx, sy);
|
|
|
|
cairo_set_operator(cairo_context, CAIRO_OPERATOR_SOURCE);
|
|
|
|
cairo_set_source_surface(cairo_context, csrc, 0, 0);
|
|
|
|
cairo_paint(cairo_context);
|
|
|
|
rc = TRUE;
|
|
|
|
fail2:
|
|
|
|
cairo_destroy(cairo_context);
|
|
|
|
fail:
|
|
|
|
cairo_surface_destroy(csrc);
|
|
|
|
cairo_surface_destroy(cdst);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
{
|
2019-05-07 13:10:23 +03:00
|
|
|
WLog_WARN(TAG, "SmartScaling requested but compiled without libcairo support!");
|
2019-05-06 14:18:31 +03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return rc;
|
|
|
|
}
|
2022-04-28 06:43:31 +03:00
|
|
|
|
|
|
|
DWORD FreeRDPAreColorFormatsEqualNoAlpha(DWORD first, DWORD second)
|
|
|
|
{
|
|
|
|
const DWORD mask = (DWORD) ~(8UL << 12UL);
|
|
|
|
return (first & mask) == (second & mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* FreeRDPGetColorFormatName(UINT32 format)
|
|
|
|
{
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
/* 32bpp formats */
|
|
|
|
case PIXEL_FORMAT_ARGB32:
|
|
|
|
return "PIXEL_FORMAT_ARGB32";
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_XRGB32:
|
|
|
|
return "PIXEL_FORMAT_XRGB32";
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_ABGR32:
|
|
|
|
return "PIXEL_FORMAT_ABGR32";
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_XBGR32:
|
|
|
|
return "PIXEL_FORMAT_XBGR32";
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_BGRA32:
|
|
|
|
return "PIXEL_FORMAT_BGRA32";
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_BGRX32:
|
|
|
|
return "PIXEL_FORMAT_BGRX32";
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_RGBA32:
|
|
|
|
return "PIXEL_FORMAT_RGBA32";
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_RGBX32:
|
|
|
|
return "PIXEL_FORMAT_RGBX32";
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_BGRX32_DEPTH30:
|
|
|
|
return "PIXEL_FORMAT_BGRX32_DEPTH30";
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_RGBX32_DEPTH30:
|
|
|
|
return "PIXEL_FORMAT_RGBX32_DEPTH30";
|
|
|
|
|
|
|
|
/* 24bpp formats */
|
|
|
|
case PIXEL_FORMAT_RGB24:
|
|
|
|
return "PIXEL_FORMAT_RGB24";
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_BGR24:
|
|
|
|
return "PIXEL_FORMAT_BGR24";
|
|
|
|
|
|
|
|
/* 16bpp formats */
|
|
|
|
case PIXEL_FORMAT_RGB16:
|
|
|
|
return "PIXEL_FORMAT_RGB16";
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_BGR16:
|
|
|
|
return "PIXEL_FORMAT_BGR16";
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_ARGB15:
|
|
|
|
return "PIXEL_FORMAT_ARGB15";
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_RGB15:
|
|
|
|
return "PIXEL_FORMAT_RGB15";
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_ABGR15:
|
|
|
|
return "PIXEL_FORMAT_ABGR15";
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_BGR15:
|
|
|
|
return "PIXEL_FORMAT_BGR15";
|
|
|
|
|
|
|
|
/* 8bpp formats */
|
|
|
|
case PIXEL_FORMAT_RGB8:
|
|
|
|
return "PIXEL_FORMAT_RGB8";
|
|
|
|
|
|
|
|
/* 4 bpp formats */
|
|
|
|
case PIXEL_FORMAT_A4:
|
|
|
|
return "PIXEL_FORMAT_A4";
|
|
|
|
|
|
|
|
/* 1bpp formats */
|
|
|
|
case PIXEL_FORMAT_MONO:
|
|
|
|
return "PIXEL_FORMAT_MONO";
|
|
|
|
|
|
|
|
default:
|
|
|
|
return "UNKNOWN";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FreeRDPSplitColor(UINT32 color, UINT32 format, BYTE* _r, BYTE* _g, BYTE* _b, BYTE* _a,
|
2022-06-23 08:57:38 +03:00
|
|
|
const gdiPalette* palette)
|
2022-04-28 06:43:31 +03:00
|
|
|
{
|
2023-06-05 13:16:57 +03:00
|
|
|
UINT32 tmp = 0;
|
2022-04-28 06:43:31 +03:00
|
|
|
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
/* 32bpp formats */
|
|
|
|
case PIXEL_FORMAT_ARGB32:
|
|
|
|
if (_a)
|
|
|
|
*_a = (BYTE)(color >> 24);
|
|
|
|
|
|
|
|
if (_r)
|
|
|
|
*_r = (BYTE)(color >> 16);
|
|
|
|
|
|
|
|
if (_g)
|
|
|
|
*_g = (BYTE)(color >> 8);
|
|
|
|
|
|
|
|
if (_b)
|
|
|
|
*_b = (BYTE)color;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_XRGB32:
|
|
|
|
if (_r)
|
|
|
|
*_r = (BYTE)(color >> 16);
|
|
|
|
|
|
|
|
if (_g)
|
|
|
|
*_g = (BYTE)(color >> 8);
|
|
|
|
|
|
|
|
if (_b)
|
|
|
|
*_b = (BYTE)color;
|
|
|
|
|
|
|
|
if (_a)
|
|
|
|
*_a = 0xFF;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_ABGR32:
|
|
|
|
if (_a)
|
|
|
|
*_a = (BYTE)(color >> 24);
|
|
|
|
|
|
|
|
if (_b)
|
|
|
|
*_b = (BYTE)(color >> 16);
|
|
|
|
|
|
|
|
if (_g)
|
|
|
|
*_g = (BYTE)(color >> 8);
|
|
|
|
|
|
|
|
if (_r)
|
|
|
|
*_r = (BYTE)color;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_XBGR32:
|
|
|
|
if (_b)
|
|
|
|
*_b = (BYTE)(color >> 16);
|
|
|
|
|
|
|
|
if (_g)
|
|
|
|
*_g = (BYTE)(color >> 8);
|
|
|
|
|
|
|
|
if (_r)
|
|
|
|
*_r = (BYTE)color;
|
|
|
|
|
|
|
|
if (_a)
|
|
|
|
*_a = 0xFF;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_RGBA32:
|
|
|
|
if (_r)
|
|
|
|
*_r = (BYTE)(color >> 24);
|
|
|
|
|
|
|
|
if (_g)
|
|
|
|
*_g = (BYTE)(color >> 16);
|
|
|
|
|
|
|
|
if (_b)
|
|
|
|
*_b = (BYTE)(color >> 8);
|
|
|
|
|
|
|
|
if (_a)
|
|
|
|
*_a = (BYTE)color;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_RGBX32:
|
|
|
|
if (_r)
|
|
|
|
*_r = (BYTE)(color >> 24);
|
|
|
|
|
|
|
|
if (_g)
|
|
|
|
*_g = (BYTE)(color >> 16);
|
|
|
|
|
|
|
|
if (_b)
|
|
|
|
*_b = (BYTE)(color >> 8);
|
|
|
|
|
|
|
|
if (_a)
|
|
|
|
*_a = 0xFF;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_BGRA32:
|
|
|
|
if (_b)
|
|
|
|
*_b = (BYTE)(color >> 24);
|
|
|
|
|
|
|
|
if (_g)
|
|
|
|
*_g = (BYTE)(color >> 16);
|
|
|
|
|
|
|
|
if (_r)
|
|
|
|
*_r = (BYTE)(color >> 8);
|
|
|
|
|
|
|
|
if (_a)
|
|
|
|
*_a = (BYTE)color;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_BGRX32:
|
|
|
|
if (_b)
|
|
|
|
*_b = (BYTE)(color >> 24);
|
|
|
|
|
|
|
|
if (_g)
|
|
|
|
*_g = (BYTE)(color >> 16);
|
|
|
|
|
|
|
|
if (_r)
|
|
|
|
*_r = (BYTE)(color >> 8);
|
|
|
|
|
|
|
|
if (_a)
|
|
|
|
*_a = 0xFF;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* 24bpp formats */
|
|
|
|
case PIXEL_FORMAT_RGB24:
|
|
|
|
if (_r)
|
|
|
|
*_r = (BYTE)(color >> 16);
|
|
|
|
|
|
|
|
if (_g)
|
|
|
|
*_g = (BYTE)(color >> 8);
|
|
|
|
|
|
|
|
if (_b)
|
|
|
|
*_b = (BYTE)color;
|
|
|
|
|
|
|
|
if (_a)
|
|
|
|
*_a = 0xFF;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_BGR24:
|
|
|
|
if (_b)
|
|
|
|
*_b = (BYTE)(color >> 16);
|
|
|
|
|
|
|
|
if (_g)
|
|
|
|
*_g = (BYTE)(color >> 8);
|
|
|
|
|
|
|
|
if (_r)
|
|
|
|
*_r = (BYTE)color;
|
|
|
|
|
|
|
|
if (_a)
|
|
|
|
*_a = 0xFF;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* 16bpp formats */
|
|
|
|
case PIXEL_FORMAT_RGB16:
|
|
|
|
if (_r)
|
|
|
|
{
|
|
|
|
const UINT32 c = (color >> 11) & 0x1F;
|
|
|
|
const UINT32 val = (c << 3) + c / 4;
|
|
|
|
*_r = (BYTE)(val > 255 ? 255 : val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_g)
|
|
|
|
{
|
|
|
|
const UINT32 c = (color >> 5) & 0x3F;
|
|
|
|
const UINT32 val = (c << 2) + c / 4 / 2;
|
|
|
|
*_g = (BYTE)(val > 255 ? 255 : val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_b)
|
|
|
|
{
|
|
|
|
const UINT32 c = (color)&0x1F;
|
|
|
|
const UINT32 val = (c << 3) + c / 4;
|
|
|
|
*_b = (BYTE)(val > 255 ? 255 : val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_a)
|
|
|
|
*_a = 0xFF;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_BGR16:
|
|
|
|
if (_r)
|
|
|
|
{
|
|
|
|
const UINT32 c = (color)&0x1F;
|
|
|
|
const UINT32 val = (c << 3) + c / 4;
|
|
|
|
*_r = (BYTE)(val > 255 ? 255 : val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_g)
|
|
|
|
{
|
|
|
|
const UINT32 c = (color >> 5) & 0x3F;
|
|
|
|
const UINT32 val = (c << 2) + c / 4 / 2;
|
|
|
|
*_g = (BYTE)(val > 255 ? 255 : val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_b)
|
|
|
|
{
|
|
|
|
const UINT32 c = (color >> 11) & 0x1F;
|
|
|
|
const UINT32 val = (c << 3) + c / 4;
|
|
|
|
*_b = (BYTE)(val > 255 ? 255 : val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_a)
|
|
|
|
*_a = 0xFF;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_ARGB15:
|
|
|
|
if (_r)
|
|
|
|
{
|
|
|
|
const UINT32 c = (color >> 10) & 0x1F;
|
|
|
|
const UINT32 val = (c << 3) + c / 4;
|
|
|
|
*_r = (BYTE)(val > 255 ? 255 : val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_g)
|
|
|
|
{
|
|
|
|
const UINT32 c = (color >> 5) & 0x1F;
|
|
|
|
const UINT32 val = (c << 3) + c / 4;
|
|
|
|
*_g = (BYTE)(val > 255 ? 255 : val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_b)
|
|
|
|
{
|
|
|
|
const UINT32 c = (color)&0x1F;
|
|
|
|
const UINT32 val = (c << 3) + c / 4;
|
|
|
|
*_b = (BYTE)(val > 255 ? 255 : val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_a)
|
|
|
|
*_a = color & 0x8000 ? 0xFF : 0x00;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_ABGR15:
|
|
|
|
if (_r)
|
|
|
|
{
|
|
|
|
const UINT32 c = (color)&0x1F;
|
|
|
|
const UINT32 val = (c << 3) + c / 4;
|
|
|
|
*_r = (BYTE)(val > 255 ? 255 : val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_g)
|
|
|
|
{
|
|
|
|
const UINT32 c = (color >> 5) & 0x1F;
|
|
|
|
const UINT32 val = (c << 3) + c / 4;
|
|
|
|
*_g = (BYTE)(val > 255 ? 255 : val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_b)
|
|
|
|
{
|
|
|
|
const UINT32 c = (color >> 10) & 0x1F;
|
|
|
|
const UINT32 val = (c << 3) + c / 4;
|
|
|
|
*_b = (BYTE)(val > 255 ? 255 : val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_a)
|
|
|
|
*_a = color & 0x8000 ? 0xFF : 0x00;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* 15bpp formats */
|
|
|
|
case PIXEL_FORMAT_RGB15:
|
|
|
|
if (_r)
|
|
|
|
{
|
|
|
|
const UINT32 c = (color >> 10) & 0x1F;
|
|
|
|
const UINT32 val = (c << 3) + c / 4;
|
|
|
|
*_r = (BYTE)(val > 255 ? 255 : val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_g)
|
|
|
|
{
|
|
|
|
const UINT32 c = (color >> 5) & 0x1F;
|
|
|
|
const UINT32 val = (c << 3) + c / 4;
|
|
|
|
*_g = (BYTE)(val > 255 ? 255 : val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_b)
|
|
|
|
{
|
|
|
|
const UINT32 c = (color)&0x1F;
|
|
|
|
const UINT32 val = (c << 3) + c / 4;
|
|
|
|
*_b = (BYTE)(val > 255 ? 255 : val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_a)
|
|
|
|
*_a = 0xFF;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_BGR15:
|
|
|
|
if (_r)
|
|
|
|
{
|
|
|
|
const UINT32 c = (color)&0x1F;
|
|
|
|
const UINT32 val = (c << 3) + c / 4;
|
|
|
|
*_r = (BYTE)(val > 255 ? 255 : val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_g)
|
|
|
|
{
|
|
|
|
const UINT32 c = (color >> 5) & 0x1F;
|
|
|
|
const UINT32 val = (c << 3) + c / 4;
|
|
|
|
*_g = (BYTE)(val > 255 ? 255 : val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_b)
|
|
|
|
{
|
|
|
|
const UINT32 c = (color >> 10) & 0x1F;
|
|
|
|
const UINT32 val = (c << 3) + c / 4;
|
|
|
|
*_b = (BYTE)(val > 255 ? 255 : val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_a)
|
|
|
|
*_a = 0xFF;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* 8bpp formats */
|
|
|
|
case PIXEL_FORMAT_RGB8:
|
|
|
|
if (color <= 0xFF)
|
|
|
|
{
|
|
|
|
tmp = palette->palette[color];
|
|
|
|
FreeRDPSplitColor(tmp, palette->format, _r, _g, _b, _a, NULL);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_r)
|
|
|
|
*_r = 0x00;
|
|
|
|
|
|
|
|
if (_g)
|
|
|
|
*_g = 0x00;
|
|
|
|
|
|
|
|
if (_b)
|
|
|
|
*_b = 0x00;
|
|
|
|
|
|
|
|
if (_a)
|
|
|
|
*_a = 0x00;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* 1bpp formats */
|
|
|
|
case PIXEL_FORMAT_MONO:
|
|
|
|
if (_r)
|
|
|
|
*_r = (color) ? 0xFF : 0x00;
|
|
|
|
|
|
|
|
if (_g)
|
|
|
|
*_g = (color) ? 0xFF : 0x00;
|
|
|
|
|
|
|
|
if (_b)
|
|
|
|
*_b = (color) ? 0xFF : 0x00;
|
|
|
|
|
|
|
|
if (_a)
|
|
|
|
*_a = (color) ? 0xFF : 0x00;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* 4 bpp formats */
|
|
|
|
case PIXEL_FORMAT_A4:
|
|
|
|
default:
|
|
|
|
if (_r)
|
|
|
|
*_r = 0x00;
|
|
|
|
|
|
|
|
if (_g)
|
|
|
|
*_g = 0x00;
|
|
|
|
|
|
|
|
if (_b)
|
|
|
|
*_b = 0x00;
|
|
|
|
|
|
|
|
if (_a)
|
|
|
|
*_a = 0x00;
|
|
|
|
|
|
|
|
WLog_ERR(TAG, "Unsupported format %s", FreeRDPGetColorFormatName(format));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-23 16:10:04 +03:00
|
|
|
BOOL FreeRDPWriteColorIgnoreAlpha(BYTE* WINPR_RESTRICT dst, UINT32 format, UINT32 color)
|
2022-04-28 06:43:31 +03:00
|
|
|
{
|
|
|
|
switch (format)
|
|
|
|
{
|
2023-01-09 09:56:58 +03:00
|
|
|
case PIXEL_FORMAT_XBGR32:
|
|
|
|
case PIXEL_FORMAT_XRGB32:
|
2022-04-28 06:43:31 +03:00
|
|
|
case PIXEL_FORMAT_ABGR32:
|
|
|
|
case PIXEL_FORMAT_ARGB32:
|
|
|
|
{
|
|
|
|
const UINT32 tmp = ((UINT32)dst[0] << 24ULL) | (color & 0x00FFFFFFULL);
|
|
|
|
return FreeRDPWriteColor(dst, format, tmp);
|
|
|
|
}
|
2023-01-09 09:56:58 +03:00
|
|
|
case PIXEL_FORMAT_BGRX32:
|
|
|
|
case PIXEL_FORMAT_RGBX32:
|
2022-04-28 06:43:31 +03:00
|
|
|
case PIXEL_FORMAT_BGRA32:
|
|
|
|
case PIXEL_FORMAT_RGBA32:
|
|
|
|
{
|
|
|
|
const UINT32 tmp = ((UINT32)dst[3]) | (color & 0xFFFFFF00ULL);
|
|
|
|
return FreeRDPWriteColor(dst, format, tmp);
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return FreeRDPWriteColor(dst, format, color);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-23 16:10:04 +03:00
|
|
|
BOOL FreeRDPWriteColor(BYTE* WINPR_RESTRICT dst, UINT32 format, UINT32 color)
|
2022-04-28 06:43:31 +03:00
|
|
|
{
|
|
|
|
switch (FreeRDPGetBitsPerPixel(format))
|
|
|
|
{
|
|
|
|
case 32:
|
|
|
|
dst[0] = (BYTE)(color >> 24);
|
|
|
|
dst[1] = (BYTE)(color >> 16);
|
|
|
|
dst[2] = (BYTE)(color >> 8);
|
|
|
|
dst[3] = (BYTE)color;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 24:
|
|
|
|
dst[0] = (BYTE)(color >> 16);
|
|
|
|
dst[1] = (BYTE)(color >> 8);
|
|
|
|
dst[2] = (BYTE)color;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 16:
|
|
|
|
dst[1] = (BYTE)(color >> 8);
|
|
|
|
dst[0] = (BYTE)color;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 15:
|
|
|
|
if (!FreeRDPColorHasAlpha(format))
|
|
|
|
color = color & 0x7FFF;
|
|
|
|
|
|
|
|
dst[1] = (BYTE)(color >> 8);
|
|
|
|
dst[0] = (BYTE)color;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
dst[0] = (BYTE)color;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
WLog_ERR(TAG, "Unsupported format %s", FreeRDPGetColorFormatName(format));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2023-08-23 16:10:04 +03:00
|
|
|
UINT32 FreeRDPReadColor(const BYTE* WINPR_RESTRICT src, UINT32 format)
|
2022-04-28 06:43:31 +03:00
|
|
|
{
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 color = 0;
|
2022-04-28 06:43:31 +03:00
|
|
|
|
|
|
|
switch (FreeRDPGetBitsPerPixel(format))
|
|
|
|
{
|
|
|
|
case 32:
|
|
|
|
color =
|
|
|
|
((UINT32)src[0] << 24) | ((UINT32)src[1] << 16) | ((UINT32)src[2] << 8) | src[3];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 24:
|
|
|
|
color = ((UINT32)src[0] << 16) | ((UINT32)src[1] << 8) | src[2];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 16:
|
|
|
|
color = ((UINT32)src[1] << 8) | src[0];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 15:
|
|
|
|
color = ((UINT32)src[1] << 8) | src[0];
|
|
|
|
|
|
|
|
if (!FreeRDPColorHasAlpha(format))
|
|
|
|
color = color & 0x7FFF;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
case 4:
|
|
|
|
case 1:
|
|
|
|
color = *src;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
WLog_ERR(TAG, "Unsupported format %s", FreeRDPGetColorFormatName(format));
|
|
|
|
color = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return color;
|
|
|
|
}
|
|
|
|
|
|
|
|
UINT32 FreeRDPGetColor(UINT32 format, BYTE r, BYTE g, BYTE b, BYTE a)
|
|
|
|
{
|
|
|
|
UINT32 _r = r;
|
|
|
|
UINT32 _g = g;
|
|
|
|
UINT32 _b = b;
|
|
|
|
UINT32 _a = a;
|
2024-01-23 18:49:54 +03:00
|
|
|
UINT32 t = 0;
|
2022-04-28 06:43:31 +03:00
|
|
|
|
|
|
|
switch (format)
|
|
|
|
{
|
|
|
|
/* 32bpp formats */
|
|
|
|
case PIXEL_FORMAT_ARGB32:
|
|
|
|
return (_a << 24) | (_r << 16) | (_g << 8) | _b;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_XRGB32:
|
|
|
|
return (_r << 16) | (_g << 8) | _b;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_ABGR32:
|
|
|
|
return (_a << 24) | (_b << 16) | (_g << 8) | _r;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_XBGR32:
|
|
|
|
return (_b << 16) | (_g << 8) | _r;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_RGBA32:
|
|
|
|
return (_r << 24) | (_g << 16) | (_b << 8) | _a;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_RGBX32:
|
|
|
|
return (_r << 24) | (_g << 16) | (_b << 8) | _a;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_BGRA32:
|
|
|
|
return (_b << 24) | (_g << 16) | (_r << 8) | _a;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_BGRX32:
|
|
|
|
return (_b << 24) | (_g << 16) | (_r << 8) | _a;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_RGBX32_DEPTH30:
|
|
|
|
// TODO: Not tested
|
|
|
|
t = (_r << 22) | (_g << 12) | (_b << 2);
|
|
|
|
// NOTE: Swapping byte-order because FreeRDPWriteColor written UINT32 in big-endian
|
|
|
|
return ((t & 0xff) << 24) | (((t >> 8) & 0xff) << 16) | (((t >> 16) & 0xff) << 8) |
|
|
|
|
(t >> 24);
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_BGRX32_DEPTH30:
|
|
|
|
// NOTE: Swapping b and r channel (unknown reason)
|
|
|
|
t = (_r << 22) | (_g << 12) | (_b << 2);
|
|
|
|
// NOTE: Swapping byte-order because FreeRDPWriteColor written UINT32 in big-endian
|
|
|
|
return ((t & 0xff) << 24) | (((t >> 8) & 0xff) << 16) | (((t >> 16) & 0xff) << 8) |
|
|
|
|
(t >> 24);
|
|
|
|
|
|
|
|
/* 24bpp formats */
|
|
|
|
case PIXEL_FORMAT_RGB24:
|
|
|
|
return (_r << 16) | (_g << 8) | _b;
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_BGR24:
|
|
|
|
return (_b << 16) | (_g << 8) | _r;
|
|
|
|
|
|
|
|
/* 16bpp formats */
|
|
|
|
case PIXEL_FORMAT_RGB16:
|
|
|
|
return (((_r >> 3) & 0x1F) << 11) | (((_g >> 2) & 0x3F) << 5) | ((_b >> 3) & 0x1F);
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_BGR16:
|
|
|
|
return (((_b >> 3) & 0x1F) << 11) | (((_g >> 2) & 0x3F) << 5) | ((_r >> 3) & 0x1F);
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_ARGB15:
|
|
|
|
return (((_r >> 3) & 0x1F) << 10) | (((_g >> 3) & 0x1F) << 5) | ((_b >> 3) & 0x1F) |
|
|
|
|
(_a ? 0x8000 : 0x0000);
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_ABGR15:
|
|
|
|
return (((_b >> 3) & 0x1F) << 10) | (((_g >> 3) & 0x1F) << 5) | ((_r >> 3) & 0x1F) |
|
|
|
|
(_a ? 0x8000 : 0x0000);
|
|
|
|
|
|
|
|
/* 15bpp formats */
|
|
|
|
case PIXEL_FORMAT_RGB15:
|
|
|
|
return (((_r >> 3) & 0x1F) << 10) | (((_g >> 3) & 0x1F) << 5) | ((_b >> 3) & 0x1F);
|
|
|
|
|
|
|
|
case PIXEL_FORMAT_BGR15:
|
|
|
|
return (((_b >> 3) & 0x1F) << 10) | (((_g >> 3) & 0x1F) << 5) | ((_r >> 3) & 0x1F);
|
|
|
|
|
|
|
|
/* 8bpp formats */
|
|
|
|
case PIXEL_FORMAT_RGB8:
|
|
|
|
|
|
|
|
/* 4 bpp formats */
|
|
|
|
case PIXEL_FORMAT_A4:
|
|
|
|
|
|
|
|
/* 1bpp formats */
|
|
|
|
case PIXEL_FORMAT_MONO:
|
|
|
|
default:
|
|
|
|
WLog_ERR(TAG, "Unsupported format %s", FreeRDPGetColorFormatName(format));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|