2011-07-01 00:17:55 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2011-07-01 00:17:55 +04:00
|
|
|
* GDI Bitmap Functions
|
|
|
|
*
|
|
|
|
* Copyright 2010-2011 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 00:17:55 +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 00:17:55 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2012-08-15 01:09:01 +04:00
|
|
|
|
2011-08-31 12:35:50 +04:00
|
|
|
#include <freerdp/api.h>
|
2011-07-01 00:17:55 +04:00
|
|
|
#include <freerdp/freerdp.h>
|
2011-08-15 22:33:04 +04:00
|
|
|
#include <freerdp/gdi/gdi.h>
|
2011-10-03 04:28:20 +04:00
|
|
|
#include <freerdp/codec/color.h>
|
2011-07-01 00:17:55 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
#include <freerdp/gdi/region.h>
|
2011-08-22 21:08:01 +04:00
|
|
|
#include <freerdp/gdi/bitmap.h>
|
2016-04-05 18:07:45 +03:00
|
|
|
#include <freerdp/log.h>
|
2016-07-20 11:06:45 +03:00
|
|
|
#include <freerdp/gdi/shape.h>
|
2011-07-01 00:17:55 +04:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
#include "brush.h"
|
|
|
|
#include "clipping.h"
|
2016-10-10 12:09:06 +03:00
|
|
|
#include "../gdi/gdi.h"
|
2016-04-05 18:07:45 +03:00
|
|
|
|
|
|
|
#define TAG FREERDP_TAG("gdi.bitmap")
|
2011-07-01 00:17:55 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get pixel at the given coordinates.\n
|
|
|
|
* @msdn{dd144909}
|
|
|
|
* @param hdc device context
|
|
|
|
* @param nXPos pixel x position
|
|
|
|
* @param nYPos pixel y position
|
|
|
|
* @return pixel color
|
|
|
|
*/
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
INLINE UINT32 gdi_GetPixel(HGDI_DC hdc, UINT32 nXPos, UINT32 nYPos)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
|
|
|
HGDI_BITMAP hBmp = (HGDI_BITMAP) hdc->selectedObject;
|
2016-04-05 18:07:45 +03:00
|
|
|
BYTE* data = &(hBmp->data[(nYPos * hBmp->scanline) + nXPos * GetBytesPerPixel(
|
2018-10-16 18:26:57 +03:00
|
|
|
hBmp->format)]);
|
2016-04-05 18:07:45 +03:00
|
|
|
return ReadColor(data, hBmp->format);
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
INLINE BYTE* gdi_GetPointer(HGDI_BITMAP hBmp, UINT32 X, UINT32 Y)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
UINT32 bpp = GetBytesPerPixel(hBmp->format);
|
|
|
|
return &hBmp->data[(Y * hBmp->width * bpp) + X * bpp];
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set pixel at the given coordinates.\n
|
|
|
|
* @msdn{dd145078}
|
|
|
|
* @param hdc device context
|
|
|
|
* @param X pixel x position
|
|
|
|
* @param Y pixel y position
|
|
|
|
* @param crColor new pixel color
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
static INLINE UINT32 gdi_SetPixelBmp(HGDI_BITMAP hBmp, UINT32 X, UINT32 Y,
|
2016-04-23 12:25:55 +03:00
|
|
|
UINT32 crColor)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
BYTE* p = &hBmp->data[(Y * hBmp->scanline) + X * GetBytesPerPixel(
|
2018-10-16 18:26:57 +03:00
|
|
|
hBmp->format)];
|
2016-04-05 18:07:45 +03:00
|
|
|
WriteColor(p, hBmp->format, crColor);
|
2015-04-17 17:21:55 +03:00
|
|
|
return crColor;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
INLINE UINT32 gdi_SetPixel(HGDI_DC hdc, UINT32 X, UINT32 Y, UINT32 crColor)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
HGDI_BITMAP hBmp = (HGDI_BITMAP) hdc->selectedObject;
|
|
|
|
return gdi_SetPixelBmp(hBmp, X, Y, crColor);
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new bitmap with the given width, height, color format and pixel buffer.\n
|
|
|
|
* @msdn{dd183485}
|
|
|
|
* @param nWidth width
|
|
|
|
* @param nHeight height
|
|
|
|
* @param cBitsPerPixel bits per pixel
|
|
|
|
* @param data pixel buffer
|
2015-08-12 11:49:59 +03:00
|
|
|
* @param fkt_free The function used for deallocation of the buffer, NULL for none.
|
2011-07-01 00:17:55 +04:00
|
|
|
* @return new bitmap
|
|
|
|
*/
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
HGDI_BITMAP gdi_CreateBitmap(UINT32 nWidth, UINT32 nHeight, UINT32 format,
|
2016-04-23 12:25:55 +03:00
|
|
|
BYTE* data)
|
2015-08-26 13:14:46 +03:00
|
|
|
{
|
2016-04-05 18:07:45 +03:00
|
|
|
return gdi_CreateBitmapEx(nWidth, nHeight, format, 0, data, _aligned_free);
|
2015-08-26 13:14:46 +03:00
|
|
|
}
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
HGDI_BITMAP gdi_CreateBitmapEx(UINT32 nWidth, UINT32 nHeight, UINT32 format,
|
2016-04-23 12:25:55 +03:00
|
|
|
UINT32 stride, BYTE* data, void (*fkt_free)(void*))
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2015-03-16 15:55:06 +03:00
|
|
|
HGDI_BITMAP hBitmap = (HGDI_BITMAP) calloc(1, sizeof(GDI_BITMAP));
|
|
|
|
|
|
|
|
if (!hBitmap)
|
|
|
|
return NULL;
|
|
|
|
|
2011-07-01 00:17:55 +04:00
|
|
|
hBitmap->objectType = GDIOBJECT_BITMAP;
|
2016-04-05 18:07:45 +03:00
|
|
|
hBitmap->format = format;
|
|
|
|
|
|
|
|
if (stride > 0)
|
|
|
|
hBitmap->scanline = stride;
|
|
|
|
else
|
|
|
|
hBitmap->scanline = nWidth * GetBytesPerPixel(hBitmap->format);
|
|
|
|
|
2011-07-01 00:17:55 +04:00
|
|
|
hBitmap->width = nWidth;
|
|
|
|
hBitmap->height = nHeight;
|
|
|
|
hBitmap->data = data;
|
2015-08-12 11:49:59 +03:00
|
|
|
hBitmap->free = fkt_free;
|
2011-07-01 00:17:55 +04:00
|
|
|
return hBitmap;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new bitmap of the given width and height compatible with the current device context.\n
|
|
|
|
* @msdn{dd183488}
|
|
|
|
* @param hdc device context
|
|
|
|
* @param nWidth width
|
|
|
|
* @param nHeight height
|
|
|
|
* @return new bitmap
|
|
|
|
*/
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, UINT32 nWidth,
|
2016-04-23 12:25:55 +03:00
|
|
|
UINT32 nHeight)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2015-08-12 11:49:59 +03:00
|
|
|
HGDI_BITMAP hBitmap = (HGDI_BITMAP) calloc(1, sizeof(GDI_BITMAP));
|
2014-07-08 23:07:19 +04:00
|
|
|
|
|
|
|
if (!hBitmap)
|
|
|
|
return NULL;
|
|
|
|
|
2011-07-01 00:17:55 +04:00
|
|
|
hBitmap->objectType = GDIOBJECT_BITMAP;
|
2016-04-05 18:07:45 +03:00
|
|
|
hBitmap->format = hdc->format;
|
2011-07-01 00:17:55 +04:00
|
|
|
hBitmap->width = nWidth;
|
|
|
|
hBitmap->height = nHeight;
|
2016-04-05 18:07:45 +03:00
|
|
|
hBitmap->data = _aligned_malloc(nWidth * nHeight * GetBytesPerPixel(
|
2016-04-23 12:25:55 +03:00
|
|
|
hBitmap->format), 16);
|
2015-08-12 11:49:59 +03:00
|
|
|
hBitmap->free = _aligned_free;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2015-04-14 11:14:23 +03:00
|
|
|
if (!hBitmap->data)
|
|
|
|
{
|
|
|
|
free(hBitmap);
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-03-16 15:55:06 +03:00
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
hBitmap->scanline = nWidth * GetBytesPerPixel(hBitmap->format);
|
2011-07-01 00:17:55 +04:00
|
|
|
return hBitmap;
|
|
|
|
}
|
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
static BOOL op_not(UINT32* stack, UINT32* stackp)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2016-08-05 20:38:46 +03:00
|
|
|
if (!stack || !stackp)
|
2016-04-05 18:07:45 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
if (*stackp < 1)
|
2016-08-02 11:03:18 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
stack[(*stackp) - 1] = ~stack[(*stackp) - 1];
|
2016-04-05 18:07:45 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
static BOOL op_and(UINT32* stack, UINT32* stackp)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2016-08-05 20:38:46 +03:00
|
|
|
if (!stack || !stackp)
|
2016-04-05 18:07:45 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
if (*stackp < 2)
|
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
(*stackp)--;
|
|
|
|
stack[(*stackp) - 1] &= stack[(*stackp)];
|
2016-04-05 18:07:45 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
static BOOL op_or(UINT32* stack, UINT32* stackp)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2016-08-05 20:38:46 +03:00
|
|
|
if (!stack || !stackp)
|
2016-04-05 18:07:45 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
if (*stackp < 2)
|
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
(*stackp)--;
|
|
|
|
stack[(*stackp) - 1] |= stack[(*stackp)];
|
2016-04-05 18:07:45 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
static BOOL op_xor(UINT32* stack, UINT32* stackp)
|
2016-04-05 18:07:45 +03:00
|
|
|
{
|
2016-08-05 20:38:46 +03:00
|
|
|
if (!stack || !stackp)
|
2016-04-05 18:07:45 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
if (*stackp < 2)
|
|
|
|
return FALSE;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
(*stackp)--;
|
|
|
|
stack[(*stackp) - 1] ^= stack[(*stackp)];
|
2016-04-05 18:07:45 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
static UINT32 process_rop(UINT32 src, UINT32 dst, UINT32 pat, const char* rop,
|
|
|
|
UINT32 format)
|
2016-08-02 11:03:18 +03:00
|
|
|
{
|
2016-08-10 11:29:59 +03:00
|
|
|
DWORD stack[10] = { 0 };
|
2016-08-05 20:38:46 +03:00
|
|
|
DWORD stackp = 0;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
while (*rop != '\0')
|
2016-08-02 11:03:18 +03:00
|
|
|
{
|
2016-08-05 20:38:46 +03:00
|
|
|
char op = *rop++;
|
2016-08-02 11:03:18 +03:00
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
switch (op)
|
|
|
|
{
|
|
|
|
case '0':
|
2017-11-24 15:19:48 +03:00
|
|
|
stack[stackp++] = FreeRDPGetColor(format, 0, 0, 0, 0xFF);
|
2016-08-05 20:38:46 +03:00
|
|
|
break;
|
2016-08-02 11:03:18 +03:00
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
case '1':
|
2017-11-24 15:19:48 +03:00
|
|
|
stack[stackp++] = FreeRDPGetColor(format, 0xFF, 0xFF, 0xFF, 0xFF);
|
2016-08-05 20:38:46 +03:00
|
|
|
break;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
case 'D':
|
|
|
|
stack[stackp++] = dst;
|
|
|
|
break;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
case 'S':
|
|
|
|
stack[stackp++] = src;
|
|
|
|
break;
|
2016-04-05 18:07:45 +03:00
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
case 'P':
|
|
|
|
stack[stackp++] = pat;
|
|
|
|
break;
|
2016-08-02 11:03:18 +03:00
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
case 'x':
|
|
|
|
op_xor(stack, &stackp);
|
|
|
|
break;
|
2016-08-02 11:03:18 +03:00
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
case 'a':
|
|
|
|
op_and(stack, &stackp);
|
|
|
|
break;
|
2016-08-02 11:03:18 +03:00
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
case 'o':
|
|
|
|
op_or(stack, &stackp);
|
|
|
|
break;
|
2016-08-02 11:03:18 +03:00
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
case 'n':
|
|
|
|
op_not(stack, &stackp);
|
|
|
|
break;
|
2016-08-02 11:03:18 +03:00
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
default:
|
|
|
|
break;
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-05 20:38:46 +03:00
|
|
|
return stack[0];
|
2016-04-05 18:07:45 +03:00
|
|
|
}
|
|
|
|
|
2018-11-13 19:06:09 +03:00
|
|
|
static INLINE BOOL BitBlt_write(HGDI_DC hdcDest, HGDI_DC hdcSrc, INT32 nXDest,
|
|
|
|
INT32 nYDest, INT32 nXSrc, INT32 nYSrc, INT32 x, INT32 y,
|
2016-10-10 12:25:47 +03:00
|
|
|
BOOL useSrc, BOOL usePat, UINT32 style,
|
|
|
|
const char* rop, const gdiPalette* palette)
|
2016-08-02 11:03:18 +03:00
|
|
|
{
|
2016-08-09 23:51:58 +03:00
|
|
|
UINT32 dstColor;
|
|
|
|
UINT32 colorA;
|
|
|
|
UINT32 colorB = 0;
|
2016-08-10 11:29:59 +03:00
|
|
|
UINT32 colorC = 0;
|
2018-11-13 19:06:09 +03:00
|
|
|
const INT32 dstX = nXDest + x;
|
|
|
|
const INT32 dstY = nYDest + y;
|
|
|
|
BYTE* dstp = gdi_get_bitmap_pointer(hdcDest, dstX, dstY);
|
2016-08-02 11:03:18 +03:00
|
|
|
|
2016-08-09 23:51:58 +03:00
|
|
|
if (!dstp)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "dstp=%p", (void*) dstp);
|
2016-08-02 11:03:18 +03:00
|
|
|
return FALSE;
|
2016-08-09 23:51:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
colorA = ReadColor(dstp, hdcDest->format);
|
2016-08-02 11:03:18 +03:00
|
|
|
|
2016-08-09 23:51:58 +03:00
|
|
|
if (useSrc)
|
|
|
|
{
|
|
|
|
const BYTE* srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc + x, nYSrc + y);
|
|
|
|
|
|
|
|
if (!srcp)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "srcp=%p", (void*) srcp);
|
2016-08-09 23:51:58 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
colorC = ReadColor(srcp, hdcSrc->format);
|
2017-11-24 15:19:48 +03:00
|
|
|
colorC = FreeRDPConvertColor(colorC, hdcSrc->format, hdcDest->format, palette);
|
2016-08-09 23:51:58 +03:00
|
|
|
}
|
|
|
|
|
2016-08-16 12:27:27 +03:00
|
|
|
if (usePat)
|
2016-08-02 11:03:18 +03:00
|
|
|
{
|
2016-08-16 12:27:27 +03:00
|
|
|
switch (style)
|
|
|
|
{
|
|
|
|
case GDI_BS_SOLID:
|
|
|
|
colorB = hdcDest->brush->color;
|
|
|
|
break;
|
2016-08-09 23:51:58 +03:00
|
|
|
|
2016-08-16 12:27:27 +03:00
|
|
|
case GDI_BS_HATCHED:
|
|
|
|
case GDI_BS_PATTERN:
|
2016-08-02 11:03:18 +03:00
|
|
|
{
|
2016-08-16 12:27:27 +03:00
|
|
|
const BYTE* patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y);
|
2016-08-09 23:51:58 +03:00
|
|
|
|
2016-08-16 12:27:27 +03:00
|
|
|
if (!patp)
|
|
|
|
{
|
2016-12-14 00:47:08 +03:00
|
|
|
WLog_ERR(TAG, "patp=%p", (void*) patp);
|
2016-08-16 12:27:27 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
2016-08-09 23:51:58 +03:00
|
|
|
|
2016-08-16 12:27:27 +03:00
|
|
|
colorB = ReadColor(patp, hdcDest->format);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-08-09 23:51:58 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
dstColor = process_rop(colorC, colorA, colorB, rop, hdcDest->format);
|
2016-08-10 10:12:55 +03:00
|
|
|
return WriteColor(dstp, hdcDest->format, dstColor);
|
2016-08-09 23:51:58 +03:00
|
|
|
}
|
|
|
|
|
2018-11-13 19:06:09 +03:00
|
|
|
static BOOL adjust_src_coordinates(HGDI_DC hdcSrc, INT32 nWidth, INT32 nHeight,
|
|
|
|
INT32* px, INT32* py)
|
2016-08-09 23:51:58 +03:00
|
|
|
{
|
2018-11-13 19:06:09 +03:00
|
|
|
HGDI_BITMAP hSrcBmp;
|
|
|
|
INT32 nXSrc, nYSrc;
|
|
|
|
|
|
|
|
if (!hdcSrc || (nWidth < 0) || (nHeight < 0) || !px || !py)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
hSrcBmp = (HGDI_BITMAP) hdcSrc->selectedObject;
|
|
|
|
nXSrc = *px;
|
|
|
|
nYSrc = *py;
|
|
|
|
|
|
|
|
if (!hSrcBmp)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (nYSrc < 0)
|
|
|
|
{
|
|
|
|
nYSrc = 0;
|
|
|
|
nHeight = nHeight + nYSrc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((nXSrc) < 0)
|
|
|
|
{
|
|
|
|
nXSrc = 0;
|
|
|
|
nWidth = nWidth + nXSrc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hSrcBmp->width < (nXSrc + nWidth))
|
|
|
|
nXSrc = hSrcBmp->width - nWidth;
|
|
|
|
|
|
|
|
if (hSrcBmp->height < (nYSrc + nHeight))
|
|
|
|
nYSrc = hSrcBmp->height - nHeight;
|
|
|
|
|
|
|
|
if ((nXSrc < 0) || (nYSrc < 0))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
*px = nXSrc;
|
|
|
|
*py = nYSrc;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL adjust_src_dst_coordinates(HGDI_DC hdcDest, INT32* pnXSrc, INT32* pnYSrc,
|
|
|
|
INT32* pnXDst, INT32* pnYDst, INT32* pnWidth, INT32* pnHeight)
|
|
|
|
{
|
|
|
|
HGDI_BITMAP hDstBmp;
|
|
|
|
volatile INT32 diffX, diffY;
|
|
|
|
volatile INT32 nXSrc, nYSrc;
|
|
|
|
volatile INT32 nXDst, nYDst, nWidth, nHeight;
|
|
|
|
|
|
|
|
if (!hdcDest || !pnXSrc || !pnYSrc || !pnXDst || !pnYDst || !pnWidth || !pnHeight)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
hDstBmp = (HGDI_BITMAP) hdcDest->selectedObject;
|
|
|
|
nXSrc = *pnXSrc;
|
|
|
|
nYSrc = *pnYSrc;
|
|
|
|
nXDst = *pnXDst;
|
|
|
|
nYDst = *pnYDst;
|
|
|
|
nWidth = *pnWidth;
|
|
|
|
nHeight = *pnHeight;
|
|
|
|
|
2018-11-20 11:38:02 +03:00
|
|
|
if (!hDstBmp)
|
2018-11-13 19:06:09 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (nXDst < 0)
|
|
|
|
{
|
|
|
|
nXSrc -= nXDst;
|
|
|
|
nWidth += nXDst;
|
|
|
|
nXDst = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nYDst < 0)
|
|
|
|
{
|
|
|
|
nYSrc -= nYDst;
|
|
|
|
nHeight += nYDst;
|
|
|
|
nYDst = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
diffX = hDstBmp->width - nXDst - nWidth;
|
|
|
|
|
|
|
|
if (diffX < 0)
|
|
|
|
nWidth += diffX;
|
|
|
|
|
|
|
|
diffY = hDstBmp->height - nYDst - nHeight;
|
|
|
|
|
|
|
|
if (diffY < 0)
|
|
|
|
nHeight += diffY;
|
|
|
|
|
|
|
|
if ((nXDst < 0) || (nYDst < 0) || (nWidth < 0) || (nHeight < 0))
|
|
|
|
{
|
|
|
|
nXDst = 0;
|
|
|
|
nYDst = 0;
|
|
|
|
nWidth = 0;
|
|
|
|
nHeight = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
*pnXSrc = nXSrc;
|
|
|
|
*pnYSrc = nYSrc;
|
|
|
|
*pnXDst = nXDst;
|
|
|
|
*pnYDst = nYDst;
|
|
|
|
*pnWidth = nWidth;
|
|
|
|
*pnHeight = nHeight;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL BitBlt_process(HGDI_DC hdcDest, INT32 nXDest, INT32 nYDest,
|
|
|
|
INT32 nWidth, INT32 nHeight, HGDI_DC hdcSrc,
|
|
|
|
INT32 nXSrc, INT32 nYSrc, const char* rop, const gdiPalette* palette)
|
|
|
|
{
|
|
|
|
INT32 x, y;
|
2016-08-17 10:01:27 +03:00
|
|
|
UINT32 style = 0;
|
2016-08-09 23:51:58 +03:00
|
|
|
BOOL useSrc = FALSE;
|
|
|
|
BOOL usePat = FALSE;
|
|
|
|
const char* iter = rop;
|
|
|
|
|
|
|
|
while (*iter != '\0')
|
|
|
|
{
|
|
|
|
switch (*iter++)
|
|
|
|
{
|
|
|
|
case 'P':
|
|
|
|
usePat = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'S':
|
|
|
|
useSrc = TRUE;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hdcDest)
|
|
|
|
return FALSE;
|
|
|
|
|
2018-11-13 19:06:09 +03:00
|
|
|
if (!adjust_src_dst_coordinates(hdcDest, &nXSrc, &nYSrc, &nXDest, &nYDest, &nWidth, &nHeight))
|
|
|
|
return FALSE;
|
|
|
|
|
2016-08-09 23:51:58 +03:00
|
|
|
if (useSrc && !hdcSrc)
|
|
|
|
return FALSE;
|
|
|
|
|
2018-11-13 19:06:09 +03:00
|
|
|
if (useSrc)
|
|
|
|
{
|
|
|
|
if (!adjust_src_coordinates(hdcSrc, nWidth, nHeight, &nXSrc, &nYSrc))
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2016-08-16 12:27:27 +03:00
|
|
|
if (usePat)
|
2016-08-09 23:51:58 +03:00
|
|
|
{
|
2016-08-16 12:27:27 +03:00
|
|
|
style = gdi_GetBrushStyle(hdcDest);
|
2016-08-02 11:03:18 +03:00
|
|
|
|
2016-08-16 12:27:27 +03:00
|
|
|
switch (style)
|
|
|
|
{
|
|
|
|
case GDI_BS_SOLID:
|
|
|
|
case GDI_BS_HATCHED:
|
|
|
|
case GDI_BS_PATTERN:
|
|
|
|
break;
|
2016-08-02 11:03:18 +03:00
|
|
|
|
2016-08-16 12:27:27 +03:00
|
|
|
default:
|
2016-08-09 23:51:58 +03:00
|
|
|
WLog_ERR(TAG, "Invalid brush!!");
|
|
|
|
return FALSE;
|
2016-08-16 12:27:27 +03:00
|
|
|
}
|
2016-08-02 11:03:18 +03:00
|
|
|
}
|
|
|
|
|
2016-08-09 23:51:58 +03:00
|
|
|
if ((nXDest > nXSrc) && (nYDest > nYSrc))
|
|
|
|
{
|
2018-11-13 19:06:09 +03:00
|
|
|
for (y = nHeight - 1; y >= 0; y--)
|
2016-08-09 23:51:58 +03:00
|
|
|
{
|
2018-11-13 19:06:09 +03:00
|
|
|
for (x = nWidth - 1; x >= 0; x--)
|
2016-08-09 23:51:58 +03:00
|
|
|
{
|
2016-08-16 12:27:27 +03:00
|
|
|
if (!BitBlt_write(hdcDest, hdcSrc, nXDest, nYDest,
|
|
|
|
nXSrc, nYSrc, x, y, useSrc,
|
|
|
|
usePat, style, rop, palette))
|
2016-08-09 23:51:58 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nXDest > nXSrc)
|
|
|
|
{
|
|
|
|
for (y = 0; y < nHeight; y++)
|
|
|
|
{
|
2018-11-13 19:06:09 +03:00
|
|
|
for (x = nWidth - 1; x >= 0; x--)
|
2016-08-09 23:51:58 +03:00
|
|
|
{
|
2016-08-16 12:27:27 +03:00
|
|
|
if (!BitBlt_write(hdcDest, hdcSrc, nXDest, nYDest,
|
|
|
|
nXSrc, nYSrc, x, y, useSrc,
|
|
|
|
usePat, style, rop, palette))
|
2016-08-09 23:51:58 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (nYDest > nYSrc)
|
|
|
|
{
|
2018-11-13 19:06:09 +03:00
|
|
|
for (y = nHeight - 1; y >= 0; y--)
|
2016-08-09 23:51:58 +03:00
|
|
|
{
|
|
|
|
for (x = 0; x < nWidth; x++)
|
|
|
|
{
|
2016-08-16 12:27:27 +03:00
|
|
|
if (!BitBlt_write(hdcDest, hdcSrc, nXDest, nYDest,
|
|
|
|
nXSrc, nYSrc, x, y, useSrc,
|
|
|
|
usePat, style, rop, palette))
|
2016-08-09 23:51:58 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (y = 0; y < nHeight; y++)
|
|
|
|
{
|
|
|
|
for (x = 0; x < nWidth; x++)
|
|
|
|
{
|
2016-08-16 12:27:27 +03:00
|
|
|
if (!BitBlt_write(hdcDest, hdcSrc, nXDest, nYDest,
|
|
|
|
nXSrc, nYSrc, x, y, useSrc,
|
|
|
|
usePat, style, rop, palette))
|
2016-08-09 23:51:58 +03:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-02 11:03:18 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-01 00:17:55 +04:00
|
|
|
/**
|
|
|
|
* Perform a bit blit operation on the given pixel buffers.\n
|
|
|
|
* @msdn{dd183370}
|
|
|
|
* @param hdcDest destination device context
|
|
|
|
* @param nXDest destination x1
|
|
|
|
* @param nYDest destination y1
|
|
|
|
* @param nWidth width
|
|
|
|
* @param nHeight height
|
|
|
|
* @param hdcSrc source device context
|
|
|
|
* @param nXSrc source x1
|
|
|
|
* @param nYSrc source y1
|
|
|
|
* @param rop raster operation code
|
2015-04-17 17:21:55 +03:00
|
|
|
* @return 0 on failure, non-zero otherwise
|
2011-07-01 00:17:55 +04:00
|
|
|
*/
|
2018-10-19 18:02:33 +03:00
|
|
|
BOOL gdi_BitBlt(HGDI_DC hdcDest, INT32 nXDest, INT32 nYDest,
|
|
|
|
INT32 nWidth, INT32 nHeight, HGDI_DC hdcSrc,
|
|
|
|
INT32 nXSrc, INT32 nYSrc, DWORD rop, const gdiPalette* palette)
|
2011-07-01 00:17:55 +04:00
|
|
|
{
|
2016-10-11 14:10:54 +03:00
|
|
|
HGDI_BITMAP hSrcBmp, hDstBmp;
|
|
|
|
|
2016-04-05 18:07:45 +03:00
|
|
|
if (!hdcDest)
|
|
|
|
return FALSE;
|
2011-07-01 00:17:55 +04:00
|
|
|
|
2018-11-19 15:58:53 +03:00
|
|
|
if (!gdi_ClipCoords(hdcDest, &nXDest, &nYDest, &nWidth, &nHeight, &nXSrc,
|
|
|
|
&nYSrc))
|
|
|
|
return TRUE;
|
|
|
|
|
2016-10-11 14:10:54 +03:00
|
|
|
/* Check which ROP should be performed.
|
|
|
|
* Some specific ROP are used heavily and are resource intensive,
|
|
|
|
* add optimized versions for these here.
|
|
|
|
*
|
|
|
|
* For all others fall back to the generic implementation.
|
|
|
|
*/
|
|
|
|
switch (rop)
|
|
|
|
{
|
|
|
|
case GDI_SRCCOPY:
|
2018-10-16 18:26:57 +03:00
|
|
|
if (!hdcSrc)
|
|
|
|
return FALSE;
|
|
|
|
|
2018-11-13 19:06:09 +03:00
|
|
|
if (!adjust_src_dst_coordinates(hdcDest, &nXSrc, &nYSrc, &nXDest, &nYDest, &nWidth, &nHeight))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!adjust_src_coordinates(hdcSrc, nWidth, nHeight, &nXSrc, &nYSrc))
|
|
|
|
return FALSE;
|
|
|
|
|
2016-10-11 14:10:54 +03:00
|
|
|
hSrcBmp = (HGDI_BITMAP) hdcSrc->selectedObject;
|
|
|
|
hDstBmp = (HGDI_BITMAP) hdcDest->selectedObject;
|
|
|
|
|
2018-10-16 18:26:57 +03:00
|
|
|
if (!hSrcBmp || !hDstBmp)
|
|
|
|
return FALSE;
|
|
|
|
|
2017-02-14 15:39:25 +03:00
|
|
|
if (!freerdp_image_copy(hDstBmp->data, hDstBmp->format, hDstBmp->scanline,
|
2016-10-11 14:10:54 +03:00
|
|
|
nXDest, nYDest, nWidth, nHeight,
|
2017-02-14 15:39:25 +03:00
|
|
|
hSrcBmp->data, hSrcBmp->format, hSrcBmp->scanline, nXSrc, nYSrc, palette, FREERDP_FLIP_NONE))
|
2016-10-11 14:10:54 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GDI_DSTCOPY:
|
|
|
|
hSrcBmp = (HGDI_BITMAP) hdcDest->selectedObject;
|
|
|
|
hDstBmp = (HGDI_BITMAP) hdcDest->selectedObject;
|
|
|
|
|
2018-11-13 19:06:09 +03:00
|
|
|
if (!adjust_src_dst_coordinates(hdcDest, &nXSrc, &nYSrc, &nXDest, &nYDest, &nWidth, &nHeight))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (!adjust_src_coordinates(hdcDest, nWidth, nHeight, &nXSrc, &nYSrc))
|
|
|
|
return FALSE;
|
|
|
|
|
2018-10-16 18:26:57 +03:00
|
|
|
if (!hSrcBmp || !hDstBmp)
|
|
|
|
return FALSE;
|
|
|
|
|
2017-02-14 15:39:25 +03:00
|
|
|
if (!freerdp_image_copy(hDstBmp->data, hDstBmp->format, hDstBmp->scanline,
|
2016-10-11 14:10:54 +03:00
|
|
|
nXDest, nYDest, nWidth, nHeight,
|
2017-02-14 15:39:25 +03:00
|
|
|
hSrcBmp->data, hSrcBmp->format, hSrcBmp->scanline, nXSrc, nYSrc, palette, FREERDP_FLIP_NONE))
|
2016-10-11 14:10:54 +03:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
if (!BitBlt_process(hdcDest, nXDest, nYDest,
|
|
|
|
nWidth, nHeight, hdcSrc,
|
|
|
|
nXSrc, nYSrc, gdi_rop_to_string(rop), palette))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2016-04-05 18:07:45 +03:00
|
|
|
|
|
|
|
if (!gdi_InvalidateRegion(hdcDest, nXDest, nYDest, nWidth, nHeight))
|
2015-06-26 15:32:38 +03:00
|
|
|
return FALSE;
|
|
|
|
|
2016-08-09 23:51:58 +03:00
|
|
|
return TRUE;
|
2011-07-01 00:17:55 +04:00
|
|
|
}
|