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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
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
|
|
|
|
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
|
|
|
UINT32 x, y;
|
|
|
|
const BYTE* srcp;
|
|
|
|
BYTE* dstp;
|
|
|
|
BYTE* dstData;
|
|
|
|
UINT32 scanline;
|
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
scanline = (width + 7) / 8;
|
|
|
|
dstData = (BYTE*) _aligned_malloc(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);
|
|
|
|
dstp = dstData;
|
2014-03-01 06:51:29 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
for (y = 0; y < height; y++)
|
|
|
|
{
|
|
|
|
srcp = data + (y * scanline);
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
for (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
|
|
|
|
2016-04-11 18:30:29 +03:00
|
|
|
BOOL freerdp_image_copy_from_monochrome(BYTE* pDstData, UINT32 DstFormat,
|
2016-10-14 11:01:02 +03:00
|
|
|
UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
|
|
|
|
UINT32 nWidth, UINT32 nHeight,
|
|
|
|
const BYTE* pSrcData,
|
|
|
|
UINT32 backColor, UINT32 foreColor,
|
|
|
|
const gdiPalette* palette)
|
2014-09-17 20:17:41 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 x, y;
|
|
|
|
BOOL vFlip;
|
|
|
|
UINT32 nDstPad;
|
|
|
|
UINT32 monoStep;
|
|
|
|
UINT32 dstBitsPerPixel;
|
|
|
|
UINT32 dstBytesPerPixel;
|
|
|
|
dstBitsPerPixel = GetBitsPerPixel(DstFormat);
|
|
|
|
dstBytesPerPixel = GetBytesPerPixel(DstFormat);
|
2014-09-18 02:30:09 +04:00
|
|
|
|
2016-04-11 18:30:29 +03:00
|
|
|
if (nDstStep == 0)
|
2014-09-18 02:30:09 +04:00
|
|
|
nDstStep = dstBytesPerPixel * nWidth;
|
|
|
|
|
2014-09-17 20:17:41 +04:00
|
|
|
nDstPad = (nDstStep - (nWidth * dstBytesPerPixel));
|
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
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
for (y = 0; y < nHeight; y++)
|
2014-09-17 20:17:41 +04:00
|
|
|
{
|
2016-04-11 18:30:29 +03:00
|
|
|
const BYTE* monoBits;
|
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
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
for (x = 0; x < nWidth; x++)
|
2014-09-17 20:17:41 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
BYTE* pDstPixel = &pDstLine[((nXDst + x) * GetBytesPerPixel(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)
|
|
|
|
WriteColor(pDstPixel, DstFormat, backColor);
|
2014-09-17 20:17:41 +04:00
|
|
|
else
|
2016-04-05 18:07:45 +03:00
|
|
|
WriteColor(pDstPixel, DstFormat, foreColor);
|
2014-09-17 20:17:41 +04:00
|
|
|
}
|
2014-09-12 04:12:32 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
static INLINE UINT32 freerdp_image_inverted_pointer_color(UINT32 x, UINT32 y,
|
2016-10-14 11:01:02 +03:00
|
|
|
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
|
2016-08-02 16:21:28 +03:00
|
|
|
return GetColor(format, fill, fill, fill, 0xFF);
|
2014-03-01 06:51:29 +04:00
|
|
|
}
|
2014-06-13 16:36:09 +04:00
|
|
|
|
2016-04-05 18:07:45 +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/
|
|
|
|
*/
|
|
|
|
|
|
|
|
BOOL freerdp_image_copy_from_pointer_data(
|
2016-04-23 12:25:55 +03:00
|
|
|
BYTE* pDstData, UINT32 DstFormat, UINT32 nDstStep,
|
|
|
|
UINT32 nXDst, UINT32 nYDst, UINT32 nWidth, UINT32 nHeight,
|
|
|
|
const BYTE* xorMask, UINT32 xorMaskLength,
|
|
|
|
const BYTE* andMask, UINT32 andMaskLength,
|
|
|
|
UINT32 xorBpp, const gdiPalette* palette)
|
2014-09-17 20:17:41 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 x, y;
|
|
|
|
BOOL vFlip;
|
|
|
|
UINT32 nDstPad;
|
|
|
|
UINT32 xorStep;
|
|
|
|
UINT32 andStep;
|
|
|
|
UINT32 xorBit;
|
|
|
|
UINT32 andBit;
|
|
|
|
UINT32 xorPixel;
|
|
|
|
UINT32 andPixel;
|
|
|
|
UINT32 dstBitsPerPixel;
|
|
|
|
UINT32 dstBytesPerPixel;
|
|
|
|
dstBitsPerPixel = GetBitsPerPixel(DstFormat);
|
|
|
|
dstBytesPerPixel = GetBytesPerPixel(DstFormat);
|
2014-09-18 02:30:09 +04:00
|
|
|
|
2016-07-21 17:51:42 +03:00
|
|
|
if (nDstStep <= 0)
|
2014-09-18 02:30:09 +04:00
|
|
|
nDstStep = dstBytesPerPixel * nWidth;
|
|
|
|
|
2014-10-15 04:59:22 +04:00
|
|
|
nDstPad = (nDstStep - (nWidth * dstBytesPerPixel));
|
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))
|
|
|
|
return -1;
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
switch (xorBpp)
|
2014-09-17 20:17:41 +04:00
|
|
|
{
|
2016-08-02 16:21:28 +03:00
|
|
|
case 1:
|
|
|
|
if (!andMask || (andMaskLength == 0))
|
|
|
|
return -1;
|
2014-10-13 20:29:06 +04:00
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
xorStep = (nWidth + 7) / 8;
|
|
|
|
xorStep += (xorStep % 2);
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
if (xorStep * nHeight > xorMaskLength)
|
|
|
|
return -1;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
if (andStep * nHeight > andMaskLength)
|
|
|
|
return -1;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
for (y = 0; y < nHeight; y++)
|
2014-10-13 20:29:06 +04:00
|
|
|
{
|
2016-08-02 16:21:28 +03:00
|
|
|
const BYTE* andBits;
|
|
|
|
const BYTE* xorBits;
|
|
|
|
BYTE* pDstPixel = &pDstData[((nYDst + y) * nDstStep) +
|
2016-10-14 11:01:02 +03:00
|
|
|
(nXDst * GetBytesPerPixel(DstFormat))];
|
2016-08-02 16:21:28 +03:00
|
|
|
xorBit = andBit = 0x80;
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
if (!vFlip)
|
2014-10-13 20:29:06 +04:00
|
|
|
{
|
2016-08-02 16:21:28 +03:00
|
|
|
xorBits = &xorMask[xorStep * y];
|
|
|
|
andBits = &andMask[andStep * y];
|
2014-10-13 20:29:06 +04:00
|
|
|
}
|
2016-08-02 16:21:28 +03:00
|
|
|
else
|
2014-10-13 20:29:06 +04:00
|
|
|
{
|
2016-08-02 16:21:28 +03:00
|
|
|
xorBits = &xorMask[xorStep * (nHeight - y - 1)];
|
|
|
|
andBits = &andMask[andStep * (nHeight - y - 1)];
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
2014-10-13 20:29:06 +04:00
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
for (x = 0; x < nWidth; x++)
|
|
|
|
{
|
|
|
|
UINT32 color = 0;
|
|
|
|
xorPixel = (*xorBits & xorBit) ? 1 : 0;
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
if (!(xorBit >>= 1))
|
|
|
|
{
|
|
|
|
xorBits++;
|
|
|
|
xorBit = 0x80;
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
andPixel = (*andBits & andBit) ? 1 : 0;
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
if (!(andBit >>= 1))
|
|
|
|
{
|
|
|
|
andBits++;
|
|
|
|
andBit = 0x80;
|
|
|
|
}
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
if (!andPixel && !xorPixel)
|
|
|
|
color = GetColor(DstFormat, 0, 0, 0, 0xFF); /* black */
|
|
|
|
else if (!andPixel && xorPixel)
|
|
|
|
color = GetColor(DstFormat, 0xFF, 0xFF, 0xFF, 0xFF); /* white */
|
|
|
|
else if (andPixel && !xorPixel)
|
|
|
|
color = GetColor(DstFormat, 0, 0, 0, 0); /* transparent */
|
|
|
|
else if (andPixel && xorPixel)
|
|
|
|
color = freerdp_image_inverted_pointer_color(x, y, DstFormat); /* inverted */
|
|
|
|
|
|
|
|
WriteColor(pDstPixel, DstFormat, color);
|
|
|
|
pDstPixel += GetBytesPerPixel(DstFormat);
|
|
|
|
}
|
2014-09-17 20:17:41 +04:00
|
|
|
}
|
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
return 1;
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
case 8:
|
|
|
|
case 16:
|
|
|
|
case 24:
|
|
|
|
case 32:
|
2014-09-17 20:17:41 +04:00
|
|
|
{
|
2016-08-02 16:21:28 +03:00
|
|
|
UINT32 xorBytesPerPixel = xorBpp >> 3;
|
|
|
|
xorStep = nWidth * xorBytesPerPixel;
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
if (xorBpp == 8 && !palette)
|
2014-09-17 20:17:41 +04:00
|
|
|
{
|
2016-08-02 16:21:28 +03:00
|
|
|
WLog_ERR(TAG, "null palette in convertion from %d bpp to %d bpp",
|
2016-10-14 11:01:02 +03:00
|
|
|
xorBpp, dstBitsPerPixel);
|
2016-08-02 16:21:28 +03:00
|
|
|
return -1;
|
2014-09-17 20:17:41 +04:00
|
|
|
}
|
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
if (xorStep * nHeight > xorMaskLength)
|
|
|
|
return -1;
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (andMask)
|
2014-09-17 20:17:41 +04:00
|
|
|
{
|
2016-08-02 16:21:28 +03:00
|
|
|
if (andStep * nHeight > andMaskLength)
|
|
|
|
return -1;
|
2014-09-17 20:17:41 +04:00
|
|
|
}
|
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
for (y = 0; y < nHeight; y++)
|
2014-09-17 20:17:41 +04:00
|
|
|
{
|
2016-08-02 16:21:28 +03:00
|
|
|
const BYTE* xorBits;
|
|
|
|
const BYTE* andBits = NULL;
|
|
|
|
BYTE* pDstPixel = &pDstData[((nYDst + y) * nDstStep) +
|
2016-10-14 11:01:02 +03:00
|
|
|
(nXDst * GetBytesPerPixel(DstFormat))];
|
2016-08-02 16:21:28 +03:00
|
|
|
andBit = 0x80;
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
if (!vFlip)
|
|
|
|
{
|
|
|
|
if (andMask)
|
|
|
|
andBits = &andMask[andStep * y];
|
|
|
|
|
|
|
|
xorBits = &xorMask[xorStep * y];
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
else
|
2016-08-02 16:21:28 +03:00
|
|
|
{
|
|
|
|
if (andMask)
|
|
|
|
andBits = &andMask[andStep * (nHeight - y - 1)];
|
|
|
|
|
|
|
|
xorBits = &xorMask[xorStep * (nHeight - y - 1)];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (x = 0; x < nWidth; x++)
|
|
|
|
{
|
|
|
|
UINT32 pixelFormat;
|
|
|
|
UINT32 color;
|
|
|
|
BOOL ignoreAndMask = FALSE;
|
|
|
|
|
|
|
|
if (xorBpp == 32)
|
|
|
|
{
|
2016-08-02 18:11:27 +03:00
|
|
|
pixelFormat = PIXEL_FORMAT_BGRA32;
|
2016-08-02 16:21:28 +03:00
|
|
|
xorPixel = ReadColor(xorBits, pixelFormat);
|
|
|
|
|
2016-08-04 15:50:53 +03:00
|
|
|
if (xorPixel & 0xFF)
|
2016-08-02 16:21:28 +03:00
|
|
|
ignoreAndMask = TRUE;
|
2016-08-04 15:50:53 +03:00
|
|
|
else
|
|
|
|
xorPixel |= 0xFF;
|
2016-08-02 16:21:28 +03:00
|
|
|
}
|
|
|
|
else if (xorBpp == 16)
|
|
|
|
{
|
|
|
|
pixelFormat = PIXEL_FORMAT_RGB15;
|
|
|
|
xorPixel = ReadColor(xorBits, pixelFormat);
|
|
|
|
}
|
|
|
|
else if (xorBpp == 8)
|
|
|
|
{
|
|
|
|
pixelFormat = palette->format;
|
|
|
|
xorPixel = palette->palette[xorBits[0]];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-02 18:11:27 +03:00
|
|
|
pixelFormat = PIXEL_FORMAT_BGR24;
|
2016-08-02 16:21:28 +03:00
|
|
|
xorPixel = ReadColor(xorBits, pixelFormat);
|
|
|
|
}
|
|
|
|
|
|
|
|
xorPixel = ConvertColor(xorPixel,
|
2016-10-14 11:01:02 +03:00
|
|
|
pixelFormat,
|
|
|
|
PIXEL_FORMAT_ARGB32,
|
|
|
|
palette);
|
2016-08-02 16:21:28 +03:00
|
|
|
xorBits += xorBytesPerPixel;
|
|
|
|
andPixel = 0;
|
|
|
|
|
|
|
|
if (andMask)
|
|
|
|
{
|
|
|
|
andPixel = (*andBits & andBit) ? 1 : 0;
|
|
|
|
|
|
|
|
if (!(andBit >>= 1))
|
|
|
|
{
|
|
|
|
andBits++;
|
|
|
|
andBit = 0x80;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Ignore the AND mask, if the color format already supplies alpha data. */
|
2016-04-05 18:07:45 +03:00
|
|
|
color = xorPixel;
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
if (andPixel && !ignoreAndMask)
|
|
|
|
{
|
|
|
|
if (xorPixel == 0xFF000000) /* black -> transparent */
|
|
|
|
xorPixel = 0x00000000;
|
|
|
|
else if (xorPixel == 0xFFFFFFFF) /* white -> inverted */
|
|
|
|
xorPixel = freerdp_image_inverted_pointer_color(x, y, PIXEL_FORMAT_ARGB32);
|
|
|
|
}
|
|
|
|
|
|
|
|
color = ConvertColor(xorPixel, PIXEL_FORMAT_ARGB32,
|
2016-10-14 11:01:02 +03:00
|
|
|
DstFormat, palette);
|
2016-08-02 16:21:28 +03:00
|
|
|
WriteColor(pDstPixel, DstFormat, color);
|
|
|
|
pDstPixel += GetBytesPerPixel(DstFormat);
|
|
|
|
}
|
2014-09-17 20:17:41 +04:00
|
|
|
}
|
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
return 1;
|
2014-09-17 20:17:41 +04:00
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-08-02 16:21:28 +03:00
|
|
|
default:
|
|
|
|
WLog_ERR(TAG, "failed to convert from %d bpp to %d bpp",
|
2016-10-14 11:01:02 +03:00
|
|
|
xorBpp, dstBitsPerPixel);
|
2016-08-02 16:21:28 +03:00
|
|
|
return -1;
|
2014-09-17 20:17:41 +04:00
|
|
|
}
|
2014-03-01 06:51:29 +04:00
|
|
|
}
|
2014-06-13 16:36:09 +04:00
|
|
|
|
2016-04-23 12:25:55 +03:00
|
|
|
static BOOL overlapping(const BYTE* pDstData, UINT32 nXDst, UINT32 nYDst,
|
2016-10-14 11:01:02 +03:00
|
|
|
UINT32 nDstStep, UINT32 dstBytesPerPixel,
|
|
|
|
const BYTE* pSrcData, UINT32 nXSrc, UINT32 nYSrc,
|
|
|
|
UINT32 nSrcStep, UINT32 srcBytesPerPixel,
|
|
|
|
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;
|
|
|
|
|
|
|
|
if ((pDstStart >= pSrcStart) && (pDstStart <= pSrcEnd))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if ((pDstEnd >= pSrcStart) && (pDstEnd <= pSrcEnd))
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-09-17 20:17:41 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
BOOL freerdp_image_copy(BYTE* pDstData, DWORD DstFormat,
|
2016-10-14 11:01:02 +03:00
|
|
|
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)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
|
|
|
const UINT32 dstByte = GetBytesPerPixel(DstFormat);
|
|
|
|
const UINT32 srcByte = GetBytesPerPixel(SrcFormat);
|
|
|
|
const UINT32 copyDstWidth = nWidth * dstByte;
|
|
|
|
const UINT32 xSrcOffset = nXSrc * srcByte;
|
|
|
|
const UINT32 xDstOffset = nXDst * dstByte;
|
2016-10-14 11:01:02 +03:00
|
|
|
BOOL vSrcVFlip = flags & FREERDP_FLIP_VERTICAL;
|
|
|
|
BOOL vSrcHFlip = flags & FREERDP_FLIP_HORIZONTAL;
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 srcVOffset = 0;
|
|
|
|
INT32 srcVMultiplier = 1;
|
|
|
|
UINT32 dstVOffset = 0;
|
|
|
|
INT32 dstVMultiplier = 1;
|
2014-09-17 20:17:41 +04:00
|
|
|
|
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)
|
2016-04-05 18:07:45 +03:00
|
|
|
nDstStep = nWidth * GetBytesPerPixel(DstFormat);
|
2014-09-17 01:41:24 +04:00
|
|
|
|
2016-09-06 15:20:07 +03:00
|
|
|
if (nSrcStep == 0)
|
2016-04-05 18:07:45 +03:00
|
|
|
nSrcStep = nWidth * GetBytesPerPixel(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
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
srcVOffset = (nHeight - 1) * nSrcStep;
|
|
|
|
srcVMultiplier = -1;
|
2014-09-17 01:41:24 +04:00
|
|
|
}
|
|
|
|
|
2016-10-14 11:01:02 +03:00
|
|
|
if (SrcFormat == DstFormat)
|
2014-06-13 16:36:09 +04:00
|
|
|
{
|
2016-04-20 10:57:42 +03:00
|
|
|
INT32 y;
|
2014-06-13 16:36:09 +04:00
|
|
|
|
2016-04-23 12:25:55 +03:00
|
|
|
if (overlapping(pDstData, nXDst, nYDst, nDstStep, dstByte,
|
2016-10-14 11:01:02 +03:00
|
|
|
pSrcData, nXSrc, nYSrc, nSrcStep, srcByte,
|
|
|
|
nWidth, nHeight))
|
2014-06-13 16:36:09 +04:00
|
|
|
{
|
2016-04-20 10:57:42 +03:00
|
|
|
/* Copy down */
|
2016-04-23 12:25:55 +03:00
|
|
|
if (nYDst < nYSrc)
|
2016-04-20 10:57:42 +03:00
|
|
|
{
|
|
|
|
for (y = 0; y < nHeight; y++)
|
|
|
|
{
|
|
|
|
const BYTE* srcLine = &pSrcData[(y + nYSrc) *
|
2016-10-14 11:01:02 +03:00
|
|
|
nSrcStep * srcVMultiplier +
|
|
|
|
srcVOffset];
|
2016-04-20 10:57:42 +03:00
|
|
|
BYTE* dstLine = &pDstData[(y + nYDst) *
|
2016-10-14 11:01:02 +03:00
|
|
|
nDstStep * dstVMultiplier +
|
|
|
|
dstVOffset];
|
2016-04-20 10:57:42 +03:00
|
|
|
memcpy(&dstLine[xDstOffset],
|
|
|
|
&srcLine[xSrcOffset], copyDstWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Copy up */
|
2016-04-23 12:25:55 +03:00
|
|
|
else if (nYDst > nYSrc)
|
2016-04-20 10:57:42 +03:00
|
|
|
{
|
|
|
|
for (y = nHeight - 1; y >= 0; y--)
|
|
|
|
{
|
|
|
|
const BYTE* srcLine = &pSrcData[(y + nYSrc) *
|
2016-10-14 11:01:02 +03:00
|
|
|
nSrcStep * srcVMultiplier +
|
|
|
|
srcVOffset];
|
2016-04-20 10:57:42 +03:00
|
|
|
BYTE* dstLine = &pDstData[(y + nYDst) *
|
2016-10-14 11:01:02 +03:00
|
|
|
nDstStep * dstVMultiplier +
|
|
|
|
dstVOffset];
|
2016-04-20 10:57:42 +03:00
|
|
|
memcpy(&dstLine[xDstOffset],
|
|
|
|
&srcLine[xSrcOffset], copyDstWidth);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Copy left */
|
|
|
|
else if (nXSrc > nXDst)
|
|
|
|
{
|
|
|
|
for (y = 0; y < nHeight; y++)
|
|
|
|
{
|
|
|
|
const BYTE* srcLine = &pSrcData[(y + nYSrc) *
|
2016-10-14 11:01:02 +03:00
|
|
|
nSrcStep * srcVMultiplier +
|
|
|
|
srcVOffset];
|
2016-04-20 10:57:42 +03:00
|
|
|
BYTE* dstLine = &pDstData[(y + nYDst) *
|
2016-10-14 11:01:02 +03:00
|
|
|
nDstStep * dstVMultiplier +
|
|
|
|
dstVOffset];
|
2016-04-20 10:57:42 +03:00
|
|
|
memmove(&dstLine[xDstOffset],
|
2016-10-14 11:01:02 +03:00
|
|
|
&srcLine[xSrcOffset], copyDstWidth);
|
2016-04-20 10:57:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Copy right */
|
|
|
|
else if (nXSrc < nXDst)
|
|
|
|
{
|
|
|
|
for (y = nHeight - 1; y >= 0; y--)
|
|
|
|
{
|
|
|
|
const BYTE* srcLine = &pSrcData[(y + nYSrc) *
|
2016-10-14 11:01:02 +03:00
|
|
|
nSrcStep * srcVMultiplier +
|
|
|
|
srcVOffset];
|
2016-04-20 10:57:42 +03:00
|
|
|
BYTE* dstLine = &pDstData[(y + nYDst) *
|
2016-10-14 11:01:02 +03:00
|
|
|
nDstStep * dstVMultiplier +
|
|
|
|
dstVOffset];
|
2016-04-23 12:25:55 +03:00
|
|
|
memmove(&dstLine[xDstOffset],
|
2016-10-14 11:01:02 +03:00
|
|
|
&srcLine[xSrcOffset], copyDstWidth);
|
2016-04-20 10:57:42 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Source and destination are equal... */
|
|
|
|
else
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2016-04-23 12:25:55 +03:00
|
|
|
else
|
2016-04-20 10:57:42 +03:00
|
|
|
{
|
|
|
|
for (y = 0; y < nHeight; y++)
|
|
|
|
{
|
|
|
|
const BYTE* srcLine = &pSrcData[(y + nYSrc) *
|
2016-10-14 11:01:02 +03:00
|
|
|
nSrcStep * srcVMultiplier +
|
|
|
|
srcVOffset];
|
2016-04-20 10:57:42 +03:00
|
|
|
BYTE* dstLine = &pDstData[(y + nYDst) *
|
2016-10-14 11:01:02 +03:00
|
|
|
nDstStep * dstVMultiplier +
|
|
|
|
dstVOffset];
|
2016-04-20 10:57:42 +03:00
|
|
|
memcpy(&dstLine[xDstOffset],
|
|
|
|
&srcLine[xSrcOffset], copyDstWidth);
|
|
|
|
}
|
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
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 x, y;
|
2014-06-13 16:36:09 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
for (y = 0; y < nHeight; y++)
|
2014-06-13 16:36:09 +04:00
|
|
|
{
|
2016-04-20 10:57:42 +03:00
|
|
|
const BYTE* srcLine = &pSrcData[(y + nYSrc) *
|
2016-10-14 11:01:02 +03:00
|
|
|
nSrcStep * srcVMultiplier +
|
|
|
|
srcVOffset];
|
2016-04-20 10:57:42 +03:00
|
|
|
BYTE* dstLine = &pDstData[(y + nYDst) *
|
2016-10-14 11:01:02 +03:00
|
|
|
nDstStep * dstVMultiplier + dstVOffset];
|
2014-06-13 16:36:09 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
for (x = 0; x < nWidth; x++)
|
|
|
|
{
|
|
|
|
UINT32 dstColor;
|
|
|
|
UINT32 color = ReadColor(&srcLine[(x + nXSrc) * srcByte],
|
2016-10-14 11:01:02 +03:00
|
|
|
SrcFormat);
|
2016-04-05 18:07:45 +03:00
|
|
|
dstColor = ConvertColor(color, SrcFormat, DstFormat, palette);
|
|
|
|
WriteColor(&dstLine[(x + nXDst) * dstByte], DstFormat, dstColor);
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
BOOL freerdp_image_fill(BYTE* pDstData, DWORD DstFormat,
|
2016-10-14 11:01:02 +03:00
|
|
|
UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
|
|
|
|
UINT32 nWidth, UINT32 nHeight, UINT32 color)
|
2014-09-15 04:08:38 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 x, y;
|
2015-08-06 12:24:42 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
for (y = 0; y < nHeight; y++)
|
2014-09-15 04:08:38 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
BYTE* pDstLine = &pDstData[(y + nYDst) * nDstStep];
|
2015-08-06 12:24:42 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
for (x = 0; x < nWidth; x++)
|
2014-09-15 04:08:38 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
BYTE* pDst = &pDstLine[(x + nXDst) * GetBytesPerPixel(DstFormat)];
|
|
|
|
WriteColor(pDst, DstFormat, color);
|
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
|
|
|
}
|