Exemplo n.º 1
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.º 2
0
gdiBitmap* gdi_bitmap_new_ex(rdpGdi* gdi, int width, int height, int bpp,
                             BYTE* data)
{
	gdiBitmap* bitmap;
	bitmap = (gdiBitmap*) calloc(1, sizeof(gdiBitmap));

	if (!bitmap)
		goto fail_bitmap;

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

	WLog_Print(gdi->log, WLOG_DEBUG, "gdi_bitmap_new: width:%d height:%d bpp:%d",
	           width, height, bpp);

	if (!data)
		bitmap->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, width, height);
	else
		bitmap->bitmap = gdi_create_bitmap(gdi, width, height, bpp, data);

	if (!bitmap->bitmap)
		goto fail_bitmap_bitmap;

	gdi_SelectObject(bitmap->hdc, (HGDIOBJECT) bitmap->bitmap);
	bitmap->org_bitmap = NULL;
	return bitmap;
fail_bitmap_bitmap:
	gdi_DeleteDC(bitmap->hdc);
fail_hdc:
	free(bitmap);
fail_bitmap:
	return NULL;
}
Exemplo n.º 3
0
static BOOL gdi_Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
{
    gdiBitmap* gdi_bitmap;
    rdpGdi* gdi = context->gdi;
    gdi_bitmap = (gdiBitmap*) bitmap;
    gdi_bitmap->hdc = gdi_CreateCompatibleDC(gdi->hdc);

    if (!gdi_bitmap->hdc)
        return FALSE;

    if (!bitmap->data)
        gdi_bitmap->bitmap = gdi_CreateCompatibleBitmap(
                                 gdi->hdc, bitmap->width,
                                 bitmap->height);
    else
    {
        UINT32 format = bitmap->format;
        gdi_bitmap->bitmap = gdi_create_bitmap(gdi, bitmap->width,
                                               bitmap->height,
                                               format, bitmap->data);
    }

    if (!gdi_bitmap->bitmap)
    {
        gdi_DeleteDC(gdi_bitmap->hdc);
        return FALSE;
    }

    gdi_bitmap->hdc->format = gdi_bitmap->bitmap->format;
    gdi_SelectObject(gdi_bitmap->hdc, (HGDIOBJECT) gdi_bitmap->bitmap);
    gdi_bitmap->org_bitmap = NULL;
    return TRUE;
}
Exemplo n.º 4
0
HGDI_DC gdi_CreateDC(UINT32 format)
{
	HGDI_DC hDC;

	if (!(hDC = (HGDI_DC) calloc(1, sizeof(GDI_DC))))
		return NULL;

	hDC->drawMode = GDI_R2_BLACK;

	if (!(hDC->clip = gdi_CreateRectRgn(0, 0, 0, 0)))
		goto fail;

	hDC->clip->null = TRUE;
	hDC->hwnd = NULL;
	hDC->format = format;

	if (!(hDC->hwnd = (HGDI_WND) calloc(1, sizeof(GDI_WND))))
		goto fail;

	if (!(hDC->hwnd->invalid = gdi_CreateRectRgn(0, 0, 0, 0)))
		goto fail;

	hDC->hwnd->invalid->null = TRUE;
	hDC->hwnd->count = 32;

	if (!(hDC->hwnd->cinvalid = (HGDI_RGN) calloc(hDC->hwnd->count,
	                            sizeof(GDI_RGN))))
		goto fail;

	hDC->hwnd->ninvalid = 0;
	return hDC;
fail:
	gdi_DeleteDC(hDC);
	return NULL;
}
Exemplo n.º 5
0
Arquivo: gdi.c Projeto: AMV007/FreeRDP
void gdi_bitmap_free_ex(gdiBitmap* bitmap)
{
	if (bitmap)
	{
		gdi_SelectObject(bitmap->hdc, (HGDIOBJECT) bitmap->org_bitmap);
		gdi_DeleteObject((HGDIOBJECT) bitmap->bitmap);
		gdi_DeleteDC(bitmap->hdc);
		free(bitmap);
	}
}
Exemplo n.º 6
0
void gdi_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
{
	gdiBitmap* gdi_bitmap = (gdiBitmap*) bitmap;

	if (gdi_bitmap != NULL)
	{
		gdi_SelectObject(gdi_bitmap->hdc, (HGDIOBJECT) gdi_bitmap->org_bitmap);
		gdi_DeleteObject((HGDIOBJECT) gdi_bitmap->bitmap);
		gdi_DeleteDC(gdi_bitmap->hdc);
	}
}
Exemplo n.º 7
0
void gdi_Glyph_Free(rdpContext* context, rdpGlyph* glyph)
{
	gdiGlyph* gdi_glyph;

	gdi_glyph = (gdiGlyph*) glyph;

	if (gdi_glyph != 0)
	{
		gdi_SelectObject(gdi_glyph->hdc, (HGDIOBJECT) gdi_glyph->org_bitmap);
		gdi_DeleteObject((HGDIOBJECT) gdi_glyph->bitmap);
		gdi_DeleteDC(gdi_glyph->hdc);
	}
}
Exemplo n.º 8
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_CreateBitmapEx(gdi->width, gdi->height, gdi->dstBpp,
												gdi->primary_buffer, NULL);

	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.º 9
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.º 10
0
Arquivo: gdi.c Projeto: AMV007/FreeRDP
void gdi_free(freerdp* instance)
{
	rdpGdi* gdi = instance->context->gdi;

	if (gdi)
	{
		gdi_bitmap_free_ex(gdi->primary);
		gdi_bitmap_free_ex(gdi->tile);
		gdi_bitmap_free_ex(gdi->image);
		gdi_DeleteDC(gdi->hdc);
		_aligned_free(gdi->bitmap_buffer);
		free(gdi);
	}
	
	instance->context->gdi = (rdpGdi*) NULL;
}
Exemplo n.º 11
0
static void gdi_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
{
	gdiBitmap* gdi_bitmap = (gdiBitmap*) bitmap;

	if (gdi_bitmap)
	{
		if (gdi_bitmap->hdc)
			gdi_SelectObject(gdi_bitmap->hdc, (HGDIOBJECT) gdi_bitmap->org_bitmap);

		gdi_DeleteObject((HGDIOBJECT) gdi_bitmap->bitmap);
		gdi_DeleteDC(gdi_bitmap->hdc);
		_aligned_free(bitmap->data);
	}

	free(bitmap);
}
Exemplo n.º 12
0
void gdi_free(freerdp* instance)
{
	rdpGdi* gdi;
	rdpContext* context;

	if (!instance || !instance->context)
		return;

	gdi = instance->context->gdi;

	if (gdi)
	{
		gdi_bitmap_free_ex(gdi->primary);
		gdi_DeleteDC(gdi->hdc);
		free(gdi);
	}

	context = instance->context;
	cache_free(context->cache);
	context->cache = NULL;
	instance->context->gdi = (rdpGdi*) NULL;
}
Exemplo n.º 13
0
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;
}
Exemplo n.º 14
0
BOOL gdi_init(freerdp* instance, UINT32 flags, BYTE* buffer)
{
	BOOL rgb555;
	rdpGdi* gdi;
	rdpCache* cache = NULL;

	gdi = (rdpGdi*) calloc(1, sizeof(rdpGdi));

	if (!gdi)
		goto fail_gdi;

	instance->context->gdi = gdi;
	gdi->context = instance->context;
	gdi->codecs = instance->context->codecs;
	gdi->width = instance->settings->DesktopWidth;
	gdi->height = instance->settings->DesktopHeight;
	gdi->srcBpp = instance->settings->ColorDepth;
	gdi->primary_buffer = buffer;

	/* default internal buffer format */
	gdi->dstBpp = 32;
	gdi->bytesPerPixel = 4;
	gdi->format = PIXEL_FORMAT_XRGB32;

	if (flags & CLRCONV_INVERT)
		gdi->invert = TRUE;

	rgb555 = (flags & CLRCONV_RGB555) ? TRUE : FALSE;

	if (gdi->srcBpp > 16)
	{
		if (flags & CLRBUF_32BPP)
		{
			gdi->dstBpp = 32;
			gdi->bytesPerPixel = 4;
		}
		else if (flags & CLRBUF_16BPP)
		{
			gdi->dstBpp = rgb555 ? 15 : 16;
			gdi->bytesPerPixel = 2;
		}
	}
	else
	{
		if (flags & CLRBUF_16BPP)
		{
			gdi->dstBpp = rgb555 ? 15 : 16;
			gdi->bytesPerPixel = 2;
		}
		else if (flags & CLRBUF_32BPP)
		{
			gdi->dstBpp = 32;
			gdi->bytesPerPixel = 4;
		}
	}

	if (!gdi->invert)
	{
		if (gdi->bytesPerPixel == 4)
			gdi->format = PIXEL_FORMAT_XRGB32;
		else if ((gdi->bytesPerPixel == 2) && (gdi->dstBpp == 16))
			gdi->format = PIXEL_FORMAT_RGB565;
		else if ((gdi->bytesPerPixel == 2) && (gdi->dstBpp == 15))
			gdi->format = PIXEL_FORMAT_RGB555;
	}
	else
	{
		if (gdi->bytesPerPixel == 4)
			gdi->format = PIXEL_FORMAT_XBGR32;
		else if ((gdi->bytesPerPixel == 2) && (gdi->dstBpp == 16))
			gdi->format = PIXEL_FORMAT_BGR565;
		else if ((gdi->bytesPerPixel == 2) && (gdi->dstBpp == 15))
			gdi->format = PIXEL_FORMAT_BGR555;
	}

	if (!(gdi->hdc = gdi_GetDC()))
		goto fail_get_hdc;

	gdi->hdc->bitsPerPixel = gdi->dstBpp;
	gdi->hdc->bytesPerPixel = gdi->bytesPerPixel;

	gdi->hdc->alpha = (flags & CLRCONV_ALPHA) ? TRUE : FALSE;
	gdi->hdc->invert = (flags & CLRCONV_INVERT) ? TRUE : FALSE;
	gdi->hdc->rgb555 = (flags & CLRCONV_RGB555) ? TRUE : FALSE;

	if (!gdi_init_primary(gdi))
		goto fail_init_primary;

	if (!(gdi->tile = gdi_bitmap_new_ex(gdi, 64, 64, 32, NULL)))
		goto fail_tile_bitmap;
	if (!(gdi->image = gdi_bitmap_new_ex(gdi, 64, 64, 32, NULL)))
		goto fail_image_bitmap;

	if (!instance->context->cache) {
		if (!(cache = cache_new(instance->settings)))
			goto fail_cache;

		instance->context->cache = cache;
	}

	gdi_register_update_callbacks(instance->update);

	brush_cache_register_callbacks(instance->update);
	glyph_cache_register_callbacks(instance->update);
	bitmap_cache_register_callbacks(instance->update);
	offscreen_cache_register_callbacks(instance->update);
	palette_cache_register_callbacks(instance->update);

	if (!gdi_register_graphics(instance->context->graphics))
		goto fail_register_graphics;

	instance->update->BitmapUpdate = gdi_bitmap_update;

	return TRUE;

fail_register_graphics:
	free(cache);
fail_cache:
	gdi_bitmap_free_ex(gdi->image);
fail_image_bitmap:
	gdi_bitmap_free_ex(gdi->tile);
fail_tile_bitmap:
	gdi_bitmap_free_ex(gdi->primary);
fail_init_primary:
	gdi_DeleteDC(gdi->hdc);
fail_get_hdc:
	free(gdi);
fail_gdi:
	WLog_ERR(TAG,  "failed to initialize gdi");
	return FALSE;
}
Exemplo n.º 15
0
static BOOL gdi_init_primary(rdpGdi* gdi, UINT32 stride, UINT32 format,
                             BYTE* buffer, void (*pfree)(void*))
{
	gdi->primary = (gdiBitmap*) calloc(1, sizeof(gdiBitmap));

	if (format > 0)
		gdi->dstFormat = format;

	if (stride > 0)
		gdi->stride = stride;
	else
		gdi->stride = gdi->width * GetBytesPerPixel(gdi->dstFormat);

	if (!gdi->primary)
		goto fail_primary;

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

	if (!buffer)
	{
		gdi->primary->bitmap = gdi_CreateCompatibleBitmap(
		                           gdi->hdc, gdi->width, gdi->height);
	}
	else
	{
		gdi->primary->bitmap = gdi_CreateBitmapEx(gdi->width, gdi->height,
		                       gdi->dstFormat,
		                       gdi->stride,
		                       buffer, pfree);
	}

	gdi->stride = gdi->primary->bitmap->scanline;

	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 = TRUE;
	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.º 16
0
int TestGdiEllipse(int argc, char* argv[])
{
	int rc = -1;
	UINT32 i, j;
	const UINT32 RawFormat = PIXEL_FORMAT_RGB8;
	const UINT32 colorFormats[] =
	{
		PIXEL_FORMAT_RGB15,
		PIXEL_FORMAT_ARGB15,
		PIXEL_FORMAT_RGB16,
		PIXEL_FORMAT_RGB24,
		PIXEL_FORMAT_ARGB32,
		PIXEL_FORMAT_XRGB32,
		PIXEL_FORMAT_RGBA32,
		PIXEL_FORMAT_RGBX32,
		PIXEL_FORMAT_BGR15,
		PIXEL_FORMAT_ABGR15,
		PIXEL_FORMAT_BGR16,
		PIXEL_FORMAT_BGR24,
		PIXEL_FORMAT_ABGR32,
		PIXEL_FORMAT_XBGR32,
		PIXEL_FORMAT_BGRA32,
		PIXEL_FORMAT_BGRX32
	};
	const UINT32 number_formats = sizeof(colorFormats) / sizeof(colorFormats[0]);
	gdiPalette g;

	for (i = 0; i < number_formats; i++)
	{
		HGDI_DC hdc = NULL;
		HGDI_PEN pen = NULL;
		HGDI_BITMAP hBmp = NULL;
		HGDI_BITMAP hBmp_Ellipse_1 = NULL;
		HGDI_BITMAP hBmp_Ellipse_2 = NULL;
		HGDI_BITMAP hBmp_Ellipse_3 = NULL;
		const UINT32 format = colorFormats[i];
		gdiPalette* hPalette = &g;
		g.format = format;

		for (j = 0; j < 256; j++)
			g.palette[i] = GetColor(format, j, j, j, 0xFF);

		rc = -1;

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

		hdc->format = format;
		gdi_SetNullClipRgn(hdc);

		if (!(pen = gdi_CreatePen(1, 1, 0, format, hPalette)))
		{
			printf("gdi_CreatePen failed\n");
			goto fail;
		}

		gdi_SelectObject(hdc, (HGDIOBJECT) pen);
		hBmp = gdi_CreateCompatibleBitmap(hdc, 16, 16);
		gdi_SelectObject(hdc, (HGDIOBJECT) hBmp);
		hBmp_Ellipse_1 = test_convert_to_bitmap(ellipse_case_1, RawFormat, 0, 0, 0,
		                                        format, 0, 0, 0, 16, 16, hPalette);

		if (!hBmp_Ellipse_1)
			goto fail;

		hBmp_Ellipse_2 = test_convert_to_bitmap(ellipse_case_2, RawFormat, 0, 0, 0,
		                                        format, 0, 0, 0, 16, 16, hPalette);

		if (!hBmp_Ellipse_2)
			goto fail;

		hBmp_Ellipse_3 = test_convert_to_bitmap(ellipse_case_3, RawFormat, 0, 0, 0,
		                                        format, 0, 0, 0, 16, 16, hPalette);

		if (!hBmp_Ellipse_3)
			goto fail;

		/* Test Case 1: (0,0) -> (16, 16) */
		if (!gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS, hPalette))
		{
			printf("gdi_BitBlt failed (line #%u)\n", __LINE__);
			goto fail;
		}

		if (!gdi_Ellipse(hdc, 0, 0, 15, 15))
			goto fail;

		rc = 0;
	fail:
		gdi_DeleteObject((HGDIOBJECT) hBmp_Ellipse_1);
		gdi_DeleteObject((HGDIOBJECT) hBmp_Ellipse_2);
		gdi_DeleteObject((HGDIOBJECT) hBmp_Ellipse_3);
		gdi_DeleteObject((HGDIOBJECT) hBmp);
		gdi_DeleteObject((HGDIOBJECT) pen);
		gdi_DeleteDC(hdc);

		if (rc != 0)
			break;
	}

	return rc;
}
Exemplo n.º 17
0
int TestGdiLine(int argc, char* argv[])
{
	int rc = -1;
	UINT32 x, i;
	gdiPalette g;
	const UINT32 RawFormat = PIXEL_FORMAT_RGB8;
	const UINT32 colorFormats[] =
	{
		PIXEL_FORMAT_RGB15,
		PIXEL_FORMAT_ARGB15,
		PIXEL_FORMAT_RGB16,
		PIXEL_FORMAT_RGB24,
		PIXEL_FORMAT_ARGB32,
		PIXEL_FORMAT_XRGB32,
		PIXEL_FORMAT_RGBA32,
		PIXEL_FORMAT_RGBX32,
		PIXEL_FORMAT_BGR15,
		PIXEL_FORMAT_ABGR15,
		PIXEL_FORMAT_BGR16,
		PIXEL_FORMAT_BGR24,
		PIXEL_FORMAT_ABGR32,
		PIXEL_FORMAT_XBGR32,
		PIXEL_FORMAT_BGRA32,
		PIXEL_FORMAT_BGRX32
	};
	const UINT32 number_formats = sizeof(colorFormats) / sizeof(colorFormats[0]);

	for (i = 0; i < number_formats; i++)
	{
		HGDI_DC hdc = NULL;
		HGDI_PEN pen = NULL;
		HGDI_BITMAP hBmp = NULL;
		struct ropMap rop_map[] =
		{
			{GDI_R2_BLACK, NULL, line_to_R2_BLACK},
			{GDI_R2_NOTMERGEPEN, NULL, line_to_R2_NOTMERGEPEN},
			{GDI_R2_MASKNOTPEN, NULL, line_to_R2_MASKNOTPEN},
			{GDI_R2_NOTCOPYPEN, NULL, line_to_R2_NOTCOPYPEN},
			{GDI_R2_MASKPENNOT, NULL, line_to_R2_MASKPENNOT},
			{GDI_R2_NOT, NULL, line_to_R2_NOT},
			{GDI_R2_XORPEN, NULL, line_to_R2_XORPEN},
			{GDI_R2_NOTMASKPEN, NULL, line_to_R2_NOTMASKPEN},
			{GDI_R2_MASKPEN, NULL, line_to_R2_MASKPEN},
			{GDI_R2_NOTXORPEN, NULL, line_to_R2_NOTXORPEN},
			{GDI_R2_NOP, NULL, line_to_R2_NOP},
			{GDI_R2_MERGENOTPEN, NULL, line_to_R2_MERGENOTPEN},
			{GDI_R2_COPYPEN, NULL, line_to_R2_COPYPEN},
			{GDI_R2_MERGEPENNOT, NULL, line_to_R2_MERGEPENNOT},
			{GDI_R2_MERGEPEN, NULL, line_to_R2_MERGEPEN},
			{GDI_R2_WHITE, NULL, line_to_R2_WHITE}
		};
		const UINT32 map_size = sizeof(rop_map) / sizeof(rop_map[0]);
		HGDI_BITMAP hBmp_LineTo[LINTETO_NUMBER] = {NULL};
		gdiPalette* hPalette = &g;
		UINT32 penColor;
		const UINT32 format = colorFormats[i];
		g.format = format;

		for (i = 0; i < 256; i++)
			g.palette[i] = GetColor(format, i, i, i, 0xFF);

		rc = -1;

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

		hdc->format = format;
		gdi_SetNullClipRgn(hdc);
		penColor = GetColor(format, 0xFF, 0xFF, 0xFF, 0xFF);

		if (!(pen = gdi_CreatePen(1, 1, penColor, format, hPalette)))
		{
			printf("gdi_CreatePen failed\n");
			goto fail;
		}

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

		for (x = 0; x < LINTETO_NUMBER; x++)
		{
			hBmp_LineTo[x] = test_convert_to_bitmap(line_to_case[x], RawFormat, 0, 0, 0,
			                                        format, 0, 0, 0, 16, 16, hPalette);

			if (!hBmp_LineTo[x])
				goto fail;
		}

		for (x = 0; x < map_size; x++)
		{
			rop_map[x].bmp = test_convert_to_bitmap(rop_map[x].src, RawFormat, 0, 0, 0,
			                                        format, 0, 0, 0, 16, 16, hPalette);

			if (!rop_map[x].bmp)
				goto fail;
		}

		if (!test_line(hdc, hPalette, 0, 0, 15, 15, hBmp, hBmp_LineTo[0], 0, 0, 16, 16))
			goto fail;

		if (!test_line(hdc, hPalette, 15, 15, 0, 0, hBmp, hBmp_LineTo[1], 0, 0, 16, 16))
			goto fail;

		if (!test_line(hdc, hPalette, 15, 0, 0, 15, hBmp, hBmp_LineTo[2], 0, 0, 16, 16))
			goto fail;

		if (!test_line(hdc, hPalette, 0, 15, 15, 0, hBmp, hBmp_LineTo[3], 0, 0, 16, 16))
			goto fail;

		if (!test_line(hdc, hPalette, 0, 8, 15, 8, hBmp, hBmp_LineTo[4], 0, 0, 16, 16))
			goto fail;

		if (!test_line(hdc, hPalette, 15, 8, 0, 8, hBmp, hBmp_LineTo[5], 0, 0, 16, 16))
			goto fail;

		if (!test_line(hdc, hPalette, 8, 0, 8, 15, hBmp, hBmp_LineTo[6], 0, 0, 16, 16))
			goto fail;

		if (!test_line(hdc, hPalette, 8, 15, 8, 0, hBmp, hBmp_LineTo[7], 0, 0, 16, 16))
			goto fail;

		if (!test_line(hdc, hPalette, 4, 4, 12, 12, hBmp, hBmp_LineTo[8], 0, 0, 16, 16))
			goto fail;

		if (!test_line(hdc, hPalette, 0, 0, 16, 16, hBmp, hBmp_LineTo[9], 5, 5, 8, 8))
			goto fail;

		if (!test_line(hdc, hPalette, 0, 0, 26, 26, hBmp, hBmp_LineTo[10], 0, 0, 16,
		               16))
			goto fail;

		for (x = 0; x < map_size; x++)
		{
			char name[1024];
			_snprintf(name, sizeof(name), "%s [%s]", gdi_rop_to_string(rop_map[x].rop),
			          GetColorFormatName(hdc->format));

			/* Test Case 13: (0,0) -> (16,16), R2_NOTMERGEPEN */
			if (!gdi_BitBlt(hdc, 0, 0, 16, 16, hdc, 0, 0, GDI_WHITENESS, hPalette))
			{
				printf("gdi_BitBlt failed (line #%u)\n", __LINE__);
				goto fail;
			}

			gdi_SetClipRgn(hdc, 0, 0, 16, 16);
			gdi_MoveToEx(hdc, 0, 0, NULL);
			gdi_SetROP2(hdc, rop_map[x].rop);
			gdi_LineTo(hdc, 16, 16);

			if (!test_assert_bitmaps_equal(hBmp, rop_map[x].bmp,
			                               name,
			                               hPalette))
				goto fail;
		}

		rc = 0;
	fail:

		for (x = 0; x < LINTETO_NUMBER; x++)
			gdi_DeleteObject((HGDIOBJECT) hBmp_LineTo[x]);

		for (x = 0; x < map_size; x++)
			gdi_DeleteObject((HGDIOBJECT) rop_map[x].bmp);

		gdi_DeleteObject((HGDIOBJECT) pen);
		gdi_DeleteDC(hdc);

		if (rc != 0)
			break;
	}

	return rc;
}
Exemplo n.º 18
0
void xf_window_free(xfContext* xfc)
{
	if (xfc->gc_mono)
	{
		XFreeGC(xfc->display, xfc->gc_mono);
		xfc->gc_mono = 0;
	}

	if (xfc->window)
	{
		xf_DestroyDesktopWindow(xfc, xfc->window);
		xfc->window = NULL;
	}

	if (xfc->hdc)
	{
		gdi_DeleteDC(xfc->hdc);
		xfc->hdc = NULL;
	}

	if (xfc->xv_context)
	{
		xf_tsmf_uninit(xfc, NULL);
		xfc->xv_context = NULL;
	}

	if (xfc->bitmap_buffer)
	{
		_aligned_free(xfc->bitmap_buffer);
		xfc->bitmap_buffer = NULL;
		xfc->bitmap_size = 0;
	}

	if (xfc->image)
	{
		xfc->image->data = NULL;
		XDestroyImage(xfc->image);
		xfc->image = NULL;
	}

	if (xfc->bitmap_mono)
	{
		XFreePixmap(xfc->display, xfc->bitmap_mono);
		xfc->bitmap_mono = 0;
	}

	if (xfc->primary)
	{
		XFreePixmap(xfc->display, xfc->primary);
		xfc->primary = 0;
	}

	if (xfc->gc)
	{
		XFreeGC(xfc->display, xfc->gc);
		xfc->gc = 0;
	}

	if (xfc->modifierMap)
	{
		XFreeModifiermap(xfc->modifierMap);
		xfc->modifierMap = NULL;
	}
}