Exemplo n.º 1
0
int test_gdi_CreateBitmap(void)
{
	int bpp;
	int width;
	int height;
	BYTE* data;
	HGDI_BITMAP hBitmap;

	bpp = 32;
	width = 32;
	height = 16;
	data = (BYTE*) malloc(width * height * 4);
	hBitmap = gdi_CreateBitmap(width, height, bpp, data);

	if (hBitmap->objectType != GDIOBJECT_BITMAP)
		return -1;

	if (hBitmap->bitsPerPixel != bpp)
		return -1;

	if (hBitmap->width != width)
		return -1;

	if (hBitmap->height != height)
		return -1;

	if (hBitmap->data != data)
		return -1;

	gdi_DeleteObject((HGDIOBJECT) hBitmap);

	return 0;
}
Exemplo n.º 2
0
Arquivo: gdi.c Projeto: AMV007/FreeRDP
void gdi_init_primary(rdpGdi* gdi)
{
	gdi->primary = (gdiBitmap*) malloc(sizeof(gdiBitmap));

	if (!gdi->primary)
		return;

	gdi->primary->hdc = gdi_CreateCompatibleDC(gdi->hdc);

	if (!gdi->primary_buffer)
		gdi->primary->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, gdi->width, gdi->height);
	else
		gdi->primary->bitmap = gdi_CreateBitmap(gdi->width, gdi->height, gdi->dstBpp, gdi->primary_buffer);

	gdi_SelectObject(gdi->primary->hdc, (HGDIOBJECT) gdi->primary->bitmap);
	gdi->primary->org_bitmap = NULL;

	gdi->primary_buffer = gdi->primary->bitmap->data;

	if (!gdi->drawing)
		gdi->drawing = gdi->primary;

	gdi->primary->hdc->hwnd = (HGDI_WND) malloc(sizeof(GDI_WND));
	gdi->primary->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0);
	gdi->primary->hdc->hwnd->invalid->null = 1;

	gdi->primary->hdc->hwnd->count = 32;
	gdi->primary->hdc->hwnd->cinvalid = (HGDI_RGN) malloc(sizeof(GDI_RGN) * gdi->primary->hdc->hwnd->count);
	gdi->primary->hdc->hwnd->ninvalid = 0;
}
Exemplo n.º 3
0
HGDI_BITMAP gdi_create_bitmap(rdpGdi* gdi, UINT32 nWidth, UINT32 nHeight,
                              UINT32 SrcFormat, BYTE* data)
{
    UINT32 nSrcStep;
    UINT32 nDstStep;
    BYTE* pSrcData;
    BYTE* pDstData;
    HGDI_BITMAP bitmap;

    if (!gdi)
        return NULL;

    nDstStep = nWidth * GetBytesPerPixel(gdi->dstFormat);
    pDstData = _aligned_malloc(nHeight * nDstStep, 16);

    if (!pDstData)
        return NULL;

    pSrcData = data;
    nSrcStep = nWidth * GetBytesPerPixel(SrcFormat);

    if (!freerdp_image_copy(pDstData, gdi->dstFormat, nDstStep, 0, 0,
                            nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, 0, 0,
                            &gdi->palette, FREERDP_FLIP_NONE))
    {
        _aligned_free(pDstData);
        return NULL;
    }

    bitmap = gdi_CreateBitmap(nWidth, nHeight, gdi->dstFormat, pDstData);
    return bitmap;
}
Exemplo n.º 4
0
HGDI_BITMAP gdi_create_bitmap(rdpGdi* gdi, int nWidth, int nHeight, int bpp, BYTE* data)
{
	int nSrcStep;
	int nDstStep;
	BYTE* pSrcData;
	BYTE* pDstData;
	UINT32 SrcFormat;
	int bytesPerPixel;
	HGDI_BITMAP bitmap;

	nDstStep = nWidth * gdi->bytesPerPixel;
	pDstData = _aligned_malloc(nHeight * nDstStep, 16);

	if (!pDstData)
		return NULL;

	pSrcData = data;

	switch (bpp)
	{
		case 32:
			bytesPerPixel = 4;
			SrcFormat = PIXEL_FORMAT_XRGB32;
			break;

		case 24:
			bytesPerPixel = 3;
			SrcFormat = PIXEL_FORMAT_RGB24;
			break;

		case 16:
			bytesPerPixel = 2;
			SrcFormat = PIXEL_FORMAT_RGB565;
			break;

		case 15:
			bytesPerPixel = 2;
			SrcFormat = PIXEL_FORMAT_RGB555;
			break;

		case 8:
			bytesPerPixel = 1;
			SrcFormat = PIXEL_FORMAT_RGB8;
			break;

		default:
			SrcFormat = PIXEL_FORMAT_RGB565;
			bytesPerPixel = 2;
			break;
	}

	nSrcStep = nWidth * bytesPerPixel;

	freerdp_image_copy(pDstData, gdi->format, nDstStep, 0, 0,
			nWidth, nHeight, pSrcData, SrcFormat, nSrcStep, 0, 0, gdi->palette);

	bitmap = gdi_CreateBitmap(nWidth, nHeight, gdi->dstBpp, pDstData);

	return bitmap;
}
Exemplo n.º 5
0
BOOL gdi_Glyph_New(rdpContext* context, rdpGlyph* glyph)
{
	BYTE* data;
	gdiGlyph* gdi_glyph;

	gdi_glyph = (gdiGlyph*) glyph;

	gdi_glyph->hdc = gdi_GetDC();
	if (!gdi_glyph->hdc)
		return FALSE;
	gdi_glyph->hdc->bytesPerPixel = 1;
	gdi_glyph->hdc->bitsPerPixel = 1;

	data = freerdp_glyph_convert(glyph->cx, glyph->cy, glyph->aj);
	if (!data)
	{
		gdi_DeleteDC(gdi_glyph->hdc);
		return FALSE;
	}
	gdi_glyph->bitmap = gdi_CreateBitmap(glyph->cx, glyph->cy, 1, data);
	if (!gdi_glyph->bitmap)
	{
		gdi_DeleteDC(gdi_glyph->hdc);
		_aligned_free(data);
		return FALSE;
	}
	gdi_glyph->bitmap->bytesPerPixel = 1;
	gdi_glyph->bitmap->bitsPerPixel = 1;

	gdi_SelectObject(gdi_glyph->hdc, (HGDIOBJECT) gdi_glyph->bitmap);
	gdi_glyph->org_bitmap = NULL;
	return TRUE;
}
Exemplo n.º 6
0
HGDI_BITMAP gdi_create_bitmap(rdpGdi* gdi, int width, int height, int bpp, uint8* data)
{
	uint8* bmpData;
	HGDI_BITMAP bitmap;

	bmpData = freerdp_image_convert(data, NULL, width, height, gdi->srcBpp, bpp, gdi->clrconv);
	bitmap = gdi_CreateBitmap(width, height, gdi->dstBpp, bmpData);

	return bitmap;
}
Exemplo n.º 7
0
BOOL gdi_init_primary(rdpGdi* gdi)
{
	gdi->primary = (gdiBitmap*) calloc(1, sizeof(gdiBitmap));

	if (!gdi->primary)
		goto fail_primary;

	if (!(gdi->primary->hdc = gdi_CreateCompatibleDC(gdi->hdc)))
		goto fail_hdc;

	if (!gdi->primary_buffer)
		gdi->primary->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, gdi->width, gdi->height);
	else
		gdi->primary->bitmap = gdi_CreateBitmap(gdi->width, gdi->height, gdi->dstBpp, gdi->primary_buffer);

	if (!gdi->primary->bitmap)
		goto fail_bitmap;

	gdi_SelectObject(gdi->primary->hdc, (HGDIOBJECT) gdi->primary->bitmap);
	gdi->primary->org_bitmap = NULL;

	gdi->primary_buffer = gdi->primary->bitmap->data;

	if (!(gdi->primary->hdc->hwnd = (HGDI_WND) calloc(1, sizeof(GDI_WND))))
		goto fail_hwnd;
	if (!(gdi->primary->hdc->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0)))
		goto fail_hwnd;
	gdi->primary->hdc->hwnd->invalid->null = 1;

	gdi->primary->hdc->hwnd->count = 32;
	if (!(gdi->primary->hdc->hwnd->cinvalid = (HGDI_RGN) calloc(gdi->primary->hdc->hwnd->count, sizeof(GDI_RGN))))
		goto fail_hwnd;
	gdi->primary->hdc->hwnd->ninvalid = 0;

	if (!gdi->drawing)
		gdi->drawing = gdi->primary;

	return TRUE;

fail_hwnd:
	gdi_DeleteObject((HGDIOBJECT) gdi->primary->bitmap);
fail_bitmap:
	gdi_DeleteDC(gdi->primary->hdc);
fail_hdc:
	free(gdi->primary);
	gdi->primary = NULL;
fail_primary:
	return FALSE;
}
Exemplo n.º 8
0
void gdi_Glyph_New(rdpContext* context, rdpGlyph* glyph)
{
	uint8* data;
	gdiGlyph* gdi_glyph;

	gdi_glyph = (gdiGlyph*) glyph;

	gdi_glyph->hdc = gdi_GetDC();
	gdi_glyph->hdc->bytesPerPixel = 1;
	gdi_glyph->hdc->bitsPerPixel = 1;

	data = freerdp_glyph_convert(glyph->cx, glyph->cy, glyph->aj);
	gdi_glyph->bitmap = gdi_CreateBitmap(glyph->cx, glyph->cy, 1, data);
	gdi_glyph->bitmap->bytesPerPixel = 1;
	gdi_glyph->bitmap->bitsPerPixel = 1;

	gdi_SelectObject(gdi_glyph->hdc, (HGDIOBJECT) gdi_glyph->bitmap);
	gdi_glyph->org_bitmap = NULL;
}
Exemplo n.º 9
0
int test_gdi_CreatePatternBrush(void)
{
	HGDI_BRUSH hBrush;
	HGDI_BITMAP hBitmap;

	hBitmap = gdi_CreateBitmap(64, 64, 32, NULL);
	hBrush = gdi_CreatePatternBrush(hBitmap);

	if (hBrush->objectType != GDIOBJECT_BRUSH)
		return -1;

	if (hBrush->style != GDI_BS_PATTERN)
		return -1;

	if (hBrush->pattern != hBitmap)
		return -1;

	gdi_DeleteObject((HGDIOBJECT) hBitmap);

	return 0;
}
Exemplo n.º 10
0
/* Glyph Class */
static BOOL gdi_Glyph_New(rdpContext* context, const rdpGlyph* glyph)
{
    BYTE* data;
    gdiGlyph* gdi_glyph;

    if (!context || !glyph)
        return FALSE;

    gdi_glyph = (gdiGlyph*) glyph;
    gdi_glyph->hdc = gdi_GetDC();

    if (!gdi_glyph->hdc)
        return FALSE;

    gdi_glyph->hdc->format = PIXEL_FORMAT_MONO;
    data = freerdp_glyph_convert(glyph->cx, glyph->cy, glyph->aj);

    if (!data)
    {
        gdi_DeleteDC(gdi_glyph->hdc);
        return FALSE;
    }

    gdi_glyph->bitmap = gdi_CreateBitmap(glyph->cx, glyph->cy, PIXEL_FORMAT_MONO,
                                         data);

    if (!gdi_glyph->bitmap)
    {
        gdi_DeleteDC(gdi_glyph->hdc);
        _aligned_free(data);
        return FALSE;
    }

    gdi_SelectObject(gdi_glyph->hdc, (HGDIOBJECT) gdi_glyph->bitmap);
    gdi_glyph->org_bitmap = NULL;
    return TRUE;
}
Exemplo n.º 11
0
Arquivo: gdi.c Projeto: AMV007/FreeRDP
static void gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
{
	BYTE* data;
	rdpBrush* brush;
	UINT32 foreColor;
	UINT32 backColor;
	gdiBitmap* bitmap;
	GDI_COLOR originalColor;
	HGDI_BRUSH originalBrush;
	rdpGdi* gdi = context->gdi;

	brush = &mem3blt->brush;
	bitmap = (gdiBitmap*) mem3blt->bitmap;

	foreColor = freerdp_convert_gdi_order_color(mem3blt->foreColor, gdi->srcBpp, gdi->format, gdi->palette);
	backColor = freerdp_convert_gdi_order_color(mem3blt->backColor, gdi->srcBpp, gdi->format, gdi->palette);

	originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor);

	if (brush->style == GDI_BS_SOLID)
	{
		originalBrush = gdi->drawing->hdc->brush;
		gdi->drawing->hdc->brush = gdi_CreateSolidBrush(foreColor);

		gdi_BitBlt(gdi->drawing->hdc, mem3blt->nLeftRect, mem3blt->nTopRect,
				mem3blt->nWidth, mem3blt->nHeight, bitmap->hdc,
				mem3blt->nXSrc, mem3blt->nYSrc, gdi_rop3_code(mem3blt->bRop));

		gdi_DeleteObject((HGDIOBJECT) gdi->drawing->hdc->brush);
		gdi->drawing->hdc->brush = originalBrush;
	}
	else if (brush->style == GDI_BS_PATTERN)
	{
		HGDI_BITMAP hBmp;
		UINT32 brushFormat;

		if (brush->bpp > 1)
		{
			brushFormat = gdi_get_pixel_format(brush->bpp, FALSE);

			data = (BYTE*) _aligned_malloc(8 * 8 * gdi->bytesPerPixel, 16);

			freerdp_image_copy(data, gdi->format, -1, 0, 0,
					8, 8, brush->data, brushFormat, -1, 0, 0, gdi->palette);
		}
		else
		{
			data = (BYTE*) _aligned_malloc(8 * 8 * gdi->bytesPerPixel, 16);

			freerdp_image_copy_from_monochrome(data, gdi->format, -1, 0, 0, 8, 8,
					brush->data, backColor, foreColor, gdi->palette);
		}

		hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->bitsPerPixel, data);

		originalBrush = gdi->drawing->hdc->brush;
		gdi->drawing->hdc->brush = gdi_CreatePatternBrush(hBmp);

		gdi_BitBlt(gdi->drawing->hdc, mem3blt->nLeftRect, mem3blt->nTopRect,
				mem3blt->nWidth, mem3blt->nHeight, bitmap->hdc,
				mem3blt->nXSrc, mem3blt->nYSrc, gdi_rop3_code(mem3blt->bRop));

		gdi_DeleteObject((HGDIOBJECT) gdi->drawing->hdc->brush);
		gdi->drawing->hdc->brush = originalBrush;
	}
	else
	{
		WLog_ERR(TAG,  "Mem3Blt unimplemented brush style:%d", brush->style);
	}

	gdi_SetTextColor(gdi->drawing->hdc, originalColor);
}
Exemplo n.º 12
0
static BOOL gdi_mem3blt(rdpContext* context, MEM3BLT_ORDER* mem3blt)
{
	HGDI_BRUSH originalBrush;
	rdpGdi* gdi = context->gdi;
	BOOL ret = TRUE;
	const rdpBrush* brush = &mem3blt->brush;
	gdiBitmap* bitmap = (gdiBitmap*) mem3blt->bitmap;
	UINT32 foreColor;
	UINT32 backColor;
	UINT32 originalColor;

	if (!gdi_decode_color(gdi, mem3blt->foreColor, &foreColor, NULL))
		return FALSE;

	if (!gdi_decode_color(gdi, mem3blt->backColor, &backColor, NULL))
		return FALSE;

	originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor);

	switch (brush->style)
	{
		case GDI_BS_SOLID:
			originalBrush = gdi->drawing->hdc->brush;
			gdi->drawing->hdc->brush = gdi_CreateSolidBrush(foreColor);

			if (!gdi->drawing->hdc->brush)
			{
				ret = FALSE;
				goto out_fail;
			}

			ret = gdi_BitBlt(gdi->drawing->hdc, mem3blt->nLeftRect, mem3blt->nTopRect,
			                 mem3blt->nWidth, mem3blt->nHeight, bitmap->hdc,
			                 mem3blt->nXSrc, mem3blt->nYSrc, gdi_rop3_code(mem3blt->bRop),
			                 &gdi->palette);
			gdi_DeleteObject((HGDIOBJECT) gdi->drawing->hdc->brush);
			gdi->drawing->hdc->brush = originalBrush;
			break;

		case GDI_BS_PATTERN:
			{
				HGDI_BITMAP hBmp;
				UINT32 brushFormat;
				BYTE* data = (BYTE*) _aligned_malloc(8 * 8 * GetBytesPerPixel(
				        gdi->drawing->hdc->format),
				                                     16);

				if (!data)
				{
					ret = FALSE;
					goto out_fail;
				}

				if (brush->bpp > 1)
				{
					brushFormat = gdi_get_pixel_format(brush->bpp);

					if (!freerdp_image_copy(data, gdi->drawing->hdc->format, 0, 0, 0,
					                        8, 8, brush->data, brushFormat,
					                        0, 0, 0, &gdi->palette, FREERDP_FLIP_NONE))
					{
						ret = FALSE;
						_aligned_free(data);
						goto out_fail;
					}
				}
				else
				{
					if (!freerdp_image_copy_from_monochrome(data, gdi->drawing->hdc->format, 0, 0,
					                                        0, 8, 8,
					                                        brush->data, backColor, foreColor,
					                                        &gdi->palette))
					{
						ret = FALSE;
						_aligned_free(data);
						goto out_fail;
					}
				}

				hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->format, data);

				if (!hBmp)
				{
					ret = FALSE;
					_aligned_free(data);
					goto out_fail;
				}

				originalBrush = gdi->drawing->hdc->brush;
				gdi->drawing->hdc->brush = gdi_CreatePatternBrush(hBmp);

				if (!gdi->drawing->hdc->brush)
				{
					gdi_DeleteObject((HGDIOBJECT) hBmp);
					goto out_fail;
				}

				gdi->drawing->hdc->brush->nXOrg = brush->x;
				gdi->drawing->hdc->brush->nYOrg = brush->y;
				ret = gdi_BitBlt(gdi->drawing->hdc, mem3blt->nLeftRect, mem3blt->nTopRect,
				                 mem3blt->nWidth, mem3blt->nHeight, bitmap->hdc,
				                 mem3blt->nXSrc, mem3blt->nYSrc, gdi_rop3_code(mem3blt->bRop),
				                 &gdi->palette);
				gdi_DeleteObject((HGDIOBJECT) gdi->drawing->hdc->brush);
				gdi->drawing->hdc->brush = originalBrush;
			}
			break;

		default:
			WLog_ERR(TAG,  "Mem3Blt unimplemented brush style:%"PRIu32"", brush->style);
			break;
	}

out_fail:
	gdi_SetTextColor(gdi->drawing->hdc, originalColor);
	return ret;
}
Exemplo n.º 13
0
int TestGdiLine(int argc, char* argv[])
{
	HGDI_DC hdc;
	HGDI_PEN pen;
	BYTE* data;
	HGDI_BITMAP hBmp;
	HGDI_BITMAP hBmp_LineTo_1;
	HGDI_BITMAP hBmp_LineTo_2;
	HGDI_BITMAP hBmp_LineTo_3;
	HGDI_BITMAP hBmp_LineTo_4;
	HGDI_BITMAP hBmp_LineTo_5;
	HGDI_BITMAP hBmp_LineTo_6;
	HGDI_BITMAP hBmp_LineTo_7;
	HGDI_BITMAP hBmp_LineTo_8;
	HGDI_BITMAP hBmp_LineTo_9;
	HGDI_BITMAP hBmp_LineTo_10;
	HGDI_BITMAP hBmp_LineTo_11;
	HGDI_BITMAP hBmp_LineTo_R2_BLACK;
	HGDI_BITMAP hBmp_LineTo_R2_NOTMERGEPEN;
	HGDI_BITMAP hBmp_LineTo_R2_MASKNOTPEN;
	HGDI_BITMAP hBmp_LineTo_R2_NOTCOPYPEN;
	HGDI_BITMAP hBmp_LineTo_R2_MASKPENNOT;
	HGDI_BITMAP hBmp_LineTo_R2_NOT;
	HGDI_BITMAP hBmp_LineTo_R2_XORPEN;
	HGDI_BITMAP hBmp_LineTo_R2_NOTMASKPEN;
	HGDI_BITMAP hBmp_LineTo_R2_MASKPEN;
	HGDI_BITMAP hBmp_LineTo_R2_NOTXORPEN;
	HGDI_BITMAP hBmp_LineTo_R2_NOP;
	HGDI_BITMAP hBmp_LineTo_R2_MERGENOTPEN;
	HGDI_BITMAP hBmp_LineTo_R2_COPYPEN;
	HGDI_BITMAP hBmp_LineTo_R2_MERGEPENNOT;
	HGDI_BITMAP hBmp_LineTo_R2_MERGEPEN;
	HGDI_BITMAP hBmp_LineTo_R2_WHITE;
	rdpPalette* hPalette;
	HCLRCONV clrconv;
	int bitsPerPixel = 8;
	int bytesPerPixel = 1;

	hdc = gdi_GetDC();
	hdc->bitsPerPixel = bitsPerPixel;
	hdc->bytesPerPixel = bytesPerPixel;
	gdi_SetNullClipRgn(hdc);

	pen = gdi_CreatePen(1, 1, 0);
	gdi_SelectObject(hdc, (HGDIOBJECT) pen);

	hBmp = gdi_CreateCompatibleBitmap(hdc, 16, 16);
	gdi_SelectObject(hdc, (HGDIOBJECT) hBmp);

	hPalette = (rdpPalette*) gdi_GetSystemPalette();

	clrconv = (HCLRCONV) malloc(sizeof(CLRCONV));
	clrconv->alpha = 1;
	clrconv->invert = 0;
	clrconv->palette = hPalette;

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_1, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_1 = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_2, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_2 = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_3, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_3 = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_4, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_4 = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_5, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_5 = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_5, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_5 = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_6, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_6 = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_7, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_7 = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_8, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_8 = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_9, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_9 = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_10, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_10 = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_case_11, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_11 = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_BLACK, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_R2_BLACK = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTMERGEPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_R2_NOTMERGEPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MASKNOTPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_R2_MASKNOTPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTCOPYPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_R2_NOTCOPYPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MASKPENNOT, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_R2_MASKPENNOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOT, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_R2_NOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_XORPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_R2_XORPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTMASKPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_R2_NOTMASKPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MASKPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_R2_MASKPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOTXORPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_R2_NOTXORPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_NOP, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_R2_NOP = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MERGENOTPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_R2_MERGENOTPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_COPYPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_R2_COPYPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MERGEPENNOT, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_R2_MERGEPENNOT = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_MERGEPEN, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_R2_MERGEPEN = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	data = (BYTE*) freerdp_image_convert((BYTE*) line_to_R2_WHITE, NULL, 16, 16, 8, bitsPerPixel, clrconv);
	hBmp_LineTo_R2_WHITE = gdi_CreateBitmap(16, 16, bitsPerPixel, data);

	/* Test Case 1: (0,0) -> (15, 15) */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_MoveToEx(hdc, 0, 0, NULL);
	gdi_LineTo(hdc, 15, 15);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_1, "Case 1") < 0)
		return -1;

	/* Test Case 2: (15,15) -> (0,0) */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_MoveToEx(hdc, 15, 15, NULL);
	gdi_LineTo(hdc, 0, 0);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_2, "Case 2") < 0)
		return -1;

	/* Test Case 3: (15,0) -> (0,15) */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_MoveToEx(hdc, 15, 0, NULL);
	gdi_LineTo(hdc, 0, 15);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_3, "Case 3") < 0)
		return -1;

	/* Test Case 4: (0,15) -> (15,0) */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_MoveToEx(hdc, 0, 15, NULL);
	gdi_LineTo(hdc, 15, 0);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_4, "Case 4") < 0)
		return -1;

	/* Test Case 5: (0,8) -> (15,8) */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_MoveToEx(hdc, 0, 8, NULL);
	gdi_LineTo(hdc, 15, 8);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_5, "Case 5") < 0)
		return -1;

	/* Test Case 6: (15,8) -> (0,8) */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_MoveToEx(hdc, 15, 8, NULL);
	gdi_LineTo(hdc, 0, 8);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_6, "Case 6") < 0)
		return -1;

	/* Test Case 7: (8,0) -> (8,15) */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_MoveToEx(hdc, 8, 0, NULL);
	gdi_LineTo(hdc, 8, 15);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_7, "Case 7") < 0)
		return -1;

	/* Test Case 8: (8,15) -> (8,0) */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_MoveToEx(hdc, 8, 15, NULL);
	gdi_LineTo(hdc, 8, 0);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_8, "Case 8") < 0)
		return -1;

	/* Test Case 9: (4,4) -> (12,12) */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_MoveToEx(hdc, 4, 4, NULL);
	gdi_LineTo(hdc, 12, 12);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_9, "Case 9") < 0)
		return -1;

	/* Test Case 10: (12,12) -> (4,4) */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_MoveToEx(hdc, 12, 12, NULL);
	gdi_LineTo(hdc, 4, 4);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_10, "Case 10") < 0)
		return -1;

	/* Test Case 11: (0,0) -> (+10,+10) */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_SetClipRgn(hdc, 0, 0, 16, 16);
	gdi_MoveToEx(hdc, 0, 0, NULL);
	gdi_LineTo(hdc, 16 + 10, 16 + 10);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_11, "Case 11") < 0)
		return -1;

	/* Test Case 12: (0,0) -> (16,16), R2_BLACK */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_SetClipRgn(hdc, 0, 0, 16, 16);
	gdi_MoveToEx(hdc, 0, 0, NULL);
	gdi_SetROP2(hdc, GDI_R2_BLACK);
	gdi_LineTo(hdc, 16, 16);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_BLACK, "Case 12") < 0)
		return -1;

	/* Test Case 13: (0,0) -> (16,16), R2_NOTMERGEPEN */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_SetClipRgn(hdc, 0, 0, 16, 16);
	gdi_MoveToEx(hdc, 0, 0, NULL);
	gdi_SetROP2(hdc, GDI_R2_NOTMERGEPEN);
	gdi_LineTo(hdc, 16, 16);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_NOTMERGEPEN, "Case 13") < 0)
		return -1;

	/* Test Case 14: (0,0) -> (16,16), R2_MASKNOTPEN */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_SetClipRgn(hdc, 0, 0, 16, 16);
	gdi_MoveToEx(hdc, 0, 0, NULL);
	gdi_SetROP2(hdc, GDI_R2_MASKNOTPEN);
	gdi_LineTo(hdc, 16, 16);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_MASKNOTPEN, "Case 14") < 0)
		return -1;

	/* Test Case 15: (0,0) -> (16,16), R2_NOTCOPYPEN */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_SetClipRgn(hdc, 0, 0, 16, 16);
	gdi_MoveToEx(hdc, 0, 0, NULL);
	gdi_SetROP2(hdc, GDI_R2_NOTCOPYPEN);
	gdi_LineTo(hdc, 16, 16);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_NOTCOPYPEN, "Case 15") < 0)
		return -1;

	/* Test Case 16: (0,0) -> (16,16), R2_MASKPENNOT */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_SetClipRgn(hdc, 0, 0, 16, 16);
	gdi_MoveToEx(hdc, 0, 0, NULL);
	gdi_SetROP2(hdc, GDI_R2_MASKPENNOT);
	gdi_LineTo(hdc, 16, 16);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_MASKPENNOT, "Case 16") < 0)
		return -1;

	/* Test Case 17: (0,0) -> (16,16), R2_NOT */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_SetClipRgn(hdc, 0, 0, 16, 16);
	gdi_MoveToEx(hdc, 0, 0, NULL);
	gdi_SetROP2(hdc, GDI_R2_NOT);
	gdi_LineTo(hdc, 16, 16);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_NOT, "Case 17") < 0)
		return -1;

	/* Test Case 18: (0,0) -> (16,16), R2_XORPEN */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_SetClipRgn(hdc, 0, 0, 16, 16);
	gdi_MoveToEx(hdc, 0, 0, NULL);
	gdi_SetROP2(hdc, GDI_R2_XORPEN);
	gdi_LineTo(hdc, 16, 16);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_XORPEN, "Case 18") < 0)
		return -1;

	/* Test Case 19: (0,0) -> (16,16), R2_NOTMASKPEN */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_SetClipRgn(hdc, 0, 0, 16, 16);
	gdi_MoveToEx(hdc, 0, 0, NULL);
	gdi_SetROP2(hdc, GDI_R2_NOTMASKPEN);
	gdi_LineTo(hdc, 16, 16);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_NOTMASKPEN, "Case 19") < 0)
		return -1;

	/* Test Case 20: (0,0) -> (16,16), R2_MASKPEN */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_SetClipRgn(hdc, 0, 0, 16, 16);
	gdi_MoveToEx(hdc, 0, 0, NULL);
	gdi_SetROP2(hdc, GDI_R2_MASKPEN);
	gdi_LineTo(hdc, 16, 16);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_MASKPEN, "Case 20") < 0)
		return -1;

	/* Test Case 21: (0,0) -> (16,16), R2_NOTXORPEN */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_SetClipRgn(hdc, 0, 0, 16, 16);
	gdi_MoveToEx(hdc, 0, 0, NULL);
	gdi_SetROP2(hdc, GDI_R2_NOTXORPEN);
	gdi_LineTo(hdc, 16, 16);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_NOTXORPEN, "Case 21") < 0)
		return -1;

	/* Test Case 22: (0,0) -> (16,16), R2_NOP */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_SetClipRgn(hdc, 0, 0, 16, 16);
	gdi_MoveToEx(hdc, 0, 0, NULL);
	gdi_SetROP2(hdc, GDI_R2_NOP);
	gdi_LineTo(hdc, 16, 16);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_NOP, "Case 22") < 0)
		return -1;

	/* Test Case 23: (0,0) -> (16,16), R2_MERGENOTPEN */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_SetClipRgn(hdc, 0, 0, 16, 16);
	gdi_MoveToEx(hdc, 0, 0, NULL);
	gdi_SetROP2(hdc, GDI_R2_MERGENOTPEN);
	gdi_LineTo(hdc, 16, 16);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_MERGENOTPEN, "Case 23") < 0)
		return -1;

	/* Test Case 24: (0,0) -> (16,16), R2_COPYPEN */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_SetClipRgn(hdc, 0, 0, 16, 16);
	gdi_MoveToEx(hdc, 0, 0, NULL);
	gdi_SetROP2(hdc, GDI_R2_COPYPEN);
	gdi_LineTo(hdc, 16, 16);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_COPYPEN, "Case 24") < 0)
		return -1;

	/* Test Case 25: (0,0) -> (16,16), R2_MERGEPENNOT */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_SetClipRgn(hdc, 0, 0, 16, 16);
	gdi_MoveToEx(hdc, 0, 0, NULL);
	gdi_SetROP2(hdc, GDI_R2_MERGEPENNOT);
	gdi_LineTo(hdc, 16, 16);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_MERGEPENNOT, "Case 25") < 0)
		return -1;

	/* Test Case 26: (0,0) -> (16,16), R2_MERGEPEN */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_SetClipRgn(hdc, 0, 0, 16, 16);
	gdi_MoveToEx(hdc, 0, 0, NULL);
	gdi_SetROP2(hdc, GDI_R2_MERGEPEN);
	gdi_LineTo(hdc, 16, 16);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_MERGEPEN, "Case 26") < 0)
		return -1;

	/* Test Case 27: (0,0) -> (16,16), R2_WHITE */
	gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS);
	gdi_SetClipRgn(hdc, 0, 0, 16, 16);
	gdi_MoveToEx(hdc, 0, 0, NULL);
	gdi_SetROP2(hdc, GDI_R2_WHITE);
	gdi_LineTo(hdc, 16, 16);

	if (test_assert_bitmaps_equal(hBmp, hBmp_LineTo_R2_WHITE, "Case 27") < 0)
		return -1;

	return 0;
}
Exemplo n.º 14
0
static BOOL gdi_patblt(rdpContext* context, PATBLT_ORDER* patblt)
{
	BYTE* data;
	rdpBrush* brush;
	UINT32 foreColor;
	UINT32 backColor;
	GDI_COLOR originalColor;
	HGDI_BRUSH originalBrush;
	rdpGdi* gdi = context->gdi;
	BOOL ret = TRUE;

	brush = &patblt->brush;

	foreColor = freerdp_convert_gdi_order_color(patblt->foreColor, gdi->srcBpp, gdi->format, gdi->palette);
	backColor = freerdp_convert_gdi_order_color(patblt->backColor, gdi->srcBpp, gdi->format, gdi->palette);

	originalColor = gdi_SetTextColor(gdi->drawing->hdc, foreColor);

	if (brush->style == GDI_BS_SOLID)
	{
		originalBrush = gdi->drawing->hdc->brush;

		gdi->drawing->hdc->brush = gdi_CreateSolidBrush(foreColor);
		if (!gdi->drawing->hdc->brush)
		{
			ret = FALSE;
			goto out_error;
		}

		if (gdi_PatBlt(gdi->drawing->hdc, patblt->nLeftRect, patblt->nTopRect,
				patblt->nWidth, patblt->nHeight, gdi_rop3_code(patblt->bRop)) == 0)
			ret = FALSE;

		gdi_DeleteObject((HGDIOBJECT) gdi->drawing->hdc->brush);
		gdi->drawing->hdc->brush = originalBrush;
	}
	else if (brush->style == GDI_BS_HATCHED)
	{
		BYTE* hatched;
		HGDI_BITMAP hBmp;

		data = (BYTE*) _aligned_malloc(8 * 8 * gdi->bytesPerPixel, 16);
		if (!data)
		{
			ret = FALSE;
			goto out_error;
		}

		hatched = GDI_BS_HATCHED_PATTERNS + (8 * brush->hatch);

		freerdp_image_copy_from_monochrome(data, gdi->format, -1, 0, 0, 8, 8,
				hatched, backColor, foreColor, gdi->palette);

		hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->bitsPerPixel, data);
		if (!hBmp)
		{
			_aligned_free(data);
			ret = FALSE;
			goto out_error;
		}

		originalBrush = gdi->drawing->hdc->brush;
		gdi->drawing->hdc->brush = gdi_CreateHatchBrush(hBmp);
		if (!gdi->drawing->hdc->brush)
		{
			_aligned_free(data);
			ret = FALSE;
			goto out_error;
		}

		if (gdi_PatBlt(gdi->drawing->hdc, patblt->nLeftRect, patblt->nTopRect,
		patblt->nWidth, patblt->nHeight, gdi_rop3_code(patblt->bRop)) == 0)
			ret = FALSE;

		gdi_DeleteObject((HGDIOBJECT) gdi->drawing->hdc->brush);
		gdi->drawing->hdc->brush = originalBrush;
	}
	else if (brush->style == GDI_BS_PATTERN)
	{
		HGDI_BITMAP hBmp;
		UINT32 brushFormat;

		if (brush->bpp > 1)
		{
			brushFormat = gdi_get_pixel_format(brush->bpp, FALSE);

			data = (BYTE*) _aligned_malloc(8 * 8 * gdi->bytesPerPixel, 16);
			if (!data)
			{
				ret = FALSE;
				goto out_error;
			}

			freerdp_image_copy(data, gdi->format, -1, 0, 0,
					8, 8, brush->data, brushFormat, -1, 0, 0, gdi->palette);
		}
		else
		{
			data = (BYTE*) _aligned_malloc(8 * 8 * gdi->bytesPerPixel, 16);
			if (!data)
			{
				ret = FALSE;
				goto out_error;
			}

			freerdp_image_copy_from_monochrome(data, gdi->format, -1, 0, 0, 8, 8,
					brush->data, backColor, foreColor, gdi->palette);
		}

		hBmp = gdi_CreateBitmap(8, 8, gdi->drawing->hdc->bitsPerPixel, data);
		if (!hBmp)
		{
			_aligned_free(data);
			ret = FALSE;
			goto out_error;
		}

		originalBrush = gdi->drawing->hdc->brush;
		gdi->drawing->hdc->brush = gdi_CreatePatternBrush(hBmp);
		if (!gdi->drawing->hdc->brush)
		{
			_aligned_free(data);
			ret = FALSE;
			goto out_error;
		}

		if (gdi_PatBlt(gdi->drawing->hdc, patblt->nLeftRect, patblt->nTopRect,
				patblt->nWidth, patblt->nHeight, gdi_rop3_code(patblt->bRop)) == 0)
			ret = FALSE;

		gdi_DeleteObject((HGDIOBJECT) gdi->drawing->hdc->brush);
		gdi->drawing->hdc->brush = originalBrush;
	}
	else
	{
		WLog_ERR(TAG,  "unimplemented brush style:%d", brush->style);
	}

out_error:
	gdi_SetTextColor(gdi->drawing->hdc, originalColor);
	return ret;
}