コード例 #1
0
ファイル: TestGdiCreate.c プロジェクト: C4rt/FreeRDP
int test_gdi_SetPixel(void)
{
	HGDI_DC hdc;
	int width = 128;
	int height = 64;
	HGDI_BITMAP hBitmap;

	if (!(hdc = gdi_GetDC()))
	{
		printf("failed to get gdi device context\n");
		return -1;
	}

	hdc->bytesPerPixel = 4;
	hdc->bitsPerPixel = 32;

	hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);
	gdi_SelectObject(hdc, (HGDIOBJECT) hBitmap);

	gdi_SetPixel(hdc, 32, 64, 0xAABBCCDD);

	if (gdi_GetPixel(hdc, 32, 64) != 0xAABBCCDD)
		return -1;

	gdi_SetPixel(hdc, width - 1, height - 1, 0xAABBCCDD);

	if (gdi_GetPixel(hdc, width - 1, height - 1) != 0xAABBCCDD)
		return -1;

	gdi_DeleteObject((HGDIOBJECT) hBitmap);

	return 0;
}
コード例 #2
0
ファイル: TestGdiRect.c プロジェクト: Devolutions/FreeRDP
int test_gdi_FillRect(void)
{
	int rc = -1;
	HGDI_DC hdc = NULL;
	HGDI_RECT hRect = NULL;
	HGDI_BRUSH hBrush = NULL;
	HGDI_BITMAP hBitmap = NULL;
	UINT32 color;
	UINT32 pixel;
	UINT32 rawPixel;
	UINT32 x, y;
	UINT32 badPixels;
	UINT32 goodPixels;
	UINT32 width = 200;
	UINT32 height = 300;
	UINT32 left = 20;
	UINT32 top = 40;
	UINT32 right = 60;
	UINT32 bottom = 80;

	if (!(hdc = gdi_GetDC()))
	{
		printf("failed to get gdi device context\n");
		goto fail;
	}

	hdc->format = PIXEL_FORMAT_XRGB32;

	if (!(hRect = gdi_CreateRect(left, top, right, bottom)))
	{
		printf("gdi_CreateRect failed\n");
		goto fail;
	}

	hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);
	ZeroMemory(hBitmap->data, width * height * GetBytesPerPixel(hdc->format));
	gdi_SelectObject(hdc, (HGDIOBJECT) hBitmap);
	color = FreeRDPGetColor(PIXEL_FORMAT_ARGB32, 0xAA, 0xBB, 0xCC, 0xFF);
	hBrush = gdi_CreateSolidBrush(color);
	gdi_FillRect(hdc, hRect, hBrush);
	badPixels = 0;
	goodPixels = 0;

	for (x = 0; x < width; x++)
	{
		for (y = 0; y < height; y++)
		{
			rawPixel = gdi_GetPixel(hdc, x, y);
			pixel = FreeRDPConvertColor(rawPixel, hdc->format, PIXEL_FORMAT_ARGB32, NULL);

			if (gdi_PtInRect(hRect, x, y))
			{
				if (pixel == color)
				{
					goodPixels++;
				}
				else
				{
					printf("actual:%08"PRIX32" expected:%08"PRIX32"\n", gdi_GetPixel(hdc, x, y), color);
					badPixels++;
				}
			}
			else
			{
				if (pixel == color)
				{
					badPixels++;
				}
				else
				{
					goodPixels++;
				}
			}
		}
	}

	if (goodPixels != width * height)
		goto fail;

	if (badPixels != 0)
		goto fail;

	rc = 0;
fail:
	gdi_DeleteObject((HGDIOBJECT) hBrush);
	gdi_DeleteObject((HGDIOBJECT) hBitmap);
	gdi_DeleteObject((HGDIOBJECT)hRect);
	gdi_DeleteDC(hdc);
	return rc;
}