Ejemplo n.º 1
0
static BOOL gdi_Glyph_Draw(rdpContext* context, const rdpGlyph* glyph, UINT32 x,
                           UINT32 y, UINT32 w, UINT32 h, UINT32 sx, UINT32 sy, BOOL fOpRedundant)
{
    gdiGlyph* gdi_glyph;
    rdpGdi* gdi;
    HGDI_BRUSH brush;
    BOOL rc = FALSE;

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

    gdi = context->gdi;
    gdi_glyph = (gdiGlyph*) glyph;

    if (!fOpRedundant && 0)
    {
        GDI_RECT rect = { 0 };

        if (x > 0)
            rect.left = x;

        if (y > 0)
            rect.top = y;

        if (x + w > 0)
            rect.right = x + w - 1;

        if (y + h > 0)
            rect.bottom = y + h - 1;

        if ((rect.left < rect.right) && (rect.top < rect.bottom))
        {
            brush = gdi_CreateSolidBrush(gdi->drawing->hdc->bkColor);

            if (!brush)
                return FALSE;

            gdi_FillRect(gdi->drawing->hdc, &rect, brush);
            gdi_DeleteObject((HGDIOBJECT)brush);
        }
    }

    brush = gdi_CreateSolidBrush(gdi->drawing->hdc->textColor);

    if (!brush)
        return FALSE;

    gdi_SelectObject(gdi->drawing->hdc, (HGDIOBJECT)brush);
    rc = gdi_BitBlt(gdi->drawing->hdc, x, y, w, h, gdi_glyph->hdc, sx, sy,
                    GDI_GLYPH_ORDER, &context->gdi->palette);
    gdi_DeleteObject((HGDIOBJECT)brush);
    return rc;
}
Ejemplo n.º 2
0
static BOOL gdi_multi_opaque_rect(rdpContext* context,
                                  const MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect)
{
	UINT32 i;
	GDI_RECT rect;
	HGDI_BRUSH hBrush;
	UINT32 brush_color;
	rdpGdi* gdi = context->gdi;
	BOOL ret = TRUE;

	if (!gdi_decode_color(gdi, multi_opaque_rect->color, &brush_color, NULL))
		return FALSE;

	hBrush = gdi_CreateSolidBrush(brush_color);

	if (!hBrush)
		return FALSE;

	for (i = 0; i < multi_opaque_rect->numRectangles; i++)
	{
		const DELTA_RECT* rectangle = &multi_opaque_rect->rectangles[i];
		gdi_CRgnToRect(rectangle->left, rectangle->top,
		               rectangle->width, rectangle->height, &rect);
		ret = gdi_FillRect(gdi->drawing->hdc, &rect, hBrush);

		if (!ret)
			break;
	}

	gdi_DeleteObject((HGDIOBJECT) hBrush);
	return ret;
}
Ejemplo n.º 3
0
int test_gdi_CreateRectRgn(void)
{
	int x1 = 32;
	int y1 = 64;
	int x2 = 128;
	int y2 = 256;

	HGDI_RGN hRegion = gdi_CreateRectRgn(x1, y1, x2, y2);

	if (hRegion->objectType != GDIOBJECT_REGION)
		return -1;

	if (hRegion->x != x1)
		return -1;

	if (hRegion->y != y1)
		return -1;

	if (hRegion->w != x2 - x1 + 1)
		return -1;

	if (hRegion->h != y2 - y1 + 1)
		return -1;

	if (hRegion->null)
		return -1;

	gdi_DeleteObject((HGDIOBJECT) hRegion);

	return 0;
}
Ejemplo n.º 4
0
static BOOL gdi_polyline(rdpContext* context, const POLYLINE_ORDER* polyline)
{
	UINT32 i;
	INT32 x;
	INT32 y;
	UINT32 color;
	HGDI_PEN hPen;
	DELTA_POINT* points;
	rdpGdi* gdi = context->gdi;

	if (!gdi_decode_color(gdi, polyline->penColor, &color, NULL))
		return FALSE;

	if (!(hPen = gdi_CreatePen(GDI_PS_SOLID, 1, color, gdi->drawing->hdc->format,
	                           &gdi->palette)))
		return FALSE;

	gdi_SelectObject(gdi->drawing->hdc, (HGDIOBJECT) hPen);
	gdi_SetROP2(gdi->drawing->hdc, polyline->bRop2);
	x = polyline->xStart;
	y = polyline->yStart;
	gdi_MoveToEx(gdi->drawing->hdc, x, y, NULL);
	points = polyline->points;

	for (i = 0; i < polyline->numDeltaEntries; i++)
	{
		x += points[i].x;
		y += points[i].y;
		gdi_LineTo(gdi->drawing->hdc, x, y);
		gdi_MoveToEx(gdi->drawing->hdc, x, y, NULL);
	}

	gdi_DeleteObject((HGDIOBJECT) hPen);
	return TRUE;
}
Ejemplo n.º 5
0
static BOOL gdi_multi_opaque_rect(rdpContext* context, MULTI_OPAQUE_RECT_ORDER* multi_opaque_rect)
{
	int i;
	GDI_RECT rect;
	HGDI_BRUSH hBrush;
	UINT32 brush_color;
	DELTA_RECT* rectangle;
	rdpGdi* gdi = context->gdi;
	BOOL ret = TRUE;

	for (i = 1; i < (int) multi_opaque_rect->numRectangles + 1; i++)
	{
		rectangle = &multi_opaque_rect->rectangles[i];

		gdi_CRgnToRect(rectangle->left, rectangle->top,
				rectangle->width, rectangle->height, &rect);

		brush_color = freerdp_convert_gdi_order_color(multi_opaque_rect->color, gdi->srcBpp, gdi->format, gdi->palette);

		hBrush = gdi_CreateSolidBrush(brush_color);
		if (!hBrush)
		{
			ret = FALSE;
			break;
		}
		gdi_FillRect(gdi->drawing->hdc, &rect, hBrush);

		gdi_DeleteObject((HGDIOBJECT) hBrush);
	}
	return ret;
}
Ejemplo n.º 6
0
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;
}
Ejemplo n.º 7
0
Archivo: gdi.c Proyecto: AMV007/FreeRDP
static void gdi_polyline(rdpContext* context, POLYLINE_ORDER* polyline)
{
	int i;
	INT32 x;
	INT32 y;
	UINT32 color;
	HGDI_PEN hPen;
	DELTA_POINT* points;
	rdpGdi* gdi = context->gdi;

	color = freerdp_convert_gdi_order_color(polyline->penColor, gdi->srcBpp, gdi->format, gdi->palette);
	hPen = gdi_CreatePen(GDI_PS_SOLID, 1, (GDI_COLOR) color);
	gdi_SelectObject(gdi->drawing->hdc, (HGDIOBJECT) hPen);
	gdi_SetROP2(gdi->drawing->hdc, polyline->bRop2);

	x = polyline->xStart;
	y = polyline->yStart;
	gdi_MoveToEx(gdi->drawing->hdc, x, y, NULL);

	points = polyline->points;
	for (i = 0; i < (int) polyline->numDeltaEntries; i++)
	{
		x += points[i].x;
		y += points[i].y;
		gdi_LineTo(gdi->drawing->hdc, x, y);
		gdi_MoveToEx(gdi->drawing->hdc, x, y, NULL);
	}

	gdi_DeleteObject((HGDIOBJECT) hPen);
}
Ejemplo n.º 8
0
int test_gdi_CreateRect(void)
{
	int x1 = 32;
	int y1 = 64;
	int x2 = 128;
	int y2 = 256;

	HGDI_RECT hRect = gdi_CreateRect(x1, y1, x2, y2);
	if (!hRect)
		return -1;

	if (hRect->objectType != GDIOBJECT_RECT)
		return -1;

	if (hRect->left != x1)
		return -1;

	if (hRect->top != y1)
		return -1;

	if (hRect->right != x2)
		return -1;

	if (hRect->bottom != y2)
		return -1;

	gdi_DeleteObject((HGDIOBJECT) hRect);

	return 0;
}
Ejemplo n.º 9
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;
}
Ejemplo n.º 10
0
Archivo: gdi.c Proyecto: 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);
	}
}
Ejemplo n.º 11
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);
	}
}
Ejemplo n.º 12
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);
	}
}
Ejemplo n.º 13
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;
}
Ejemplo n.º 14
0
Archivo: dc.c Proyecto: Cyclic/FreeRDP
int gdi_DeleteObject(HGDIOBJECT hgdiobject)
{
	if (hgdiobject == NULL)
		return 0;

	if (hgdiobject->objectType == GDIOBJECT_BITMAP)
	{
		HGDI_BITMAP hBitmap = (HGDI_BITMAP) hgdiobject;

		if (hBitmap->data != NULL)
			free(hBitmap->data);

		free(hBitmap);
	}
	else if (hgdiobject->objectType == GDIOBJECT_PEN)
	{
		HGDI_PEN hPen = (HGDI_PEN) hgdiobject;
		free(hPen);
	}
	else if (hgdiobject->objectType == GDIOBJECT_BRUSH)
	{
		HGDI_BRUSH hBrush = (HGDI_BRUSH) hgdiobject;

		if(hBrush->style == GDI_BS_PATTERN)
		{
			if (hBrush->pattern != NULL)
				gdi_DeleteObject((HGDIOBJECT) hBrush->pattern);
		}

		free(hBrush);
	}
	else if (hgdiobject->objectType == GDIOBJECT_REGION)
	{
		free(hgdiobject);
	}
	else if (hgdiobject->objectType == GDIOBJECT_RECT)
	{
		free(hgdiobject);
	}
	else
	{
		/* Unknown GDI Object Type */
		free(hgdiobject);
		return 0;
	}

	return 1;
}
Ejemplo n.º 15
0
static BOOL gdi_Glyph_BeginDraw(rdpContext* context, UINT32 x, UINT32 y,
                                UINT32 width, UINT32 height, UINT32 bgcolor,
                                UINT32 fgcolor, BOOL fOpRedundant)
{
    rdpGdi* gdi;

    if (!context || !context->gdi)
        return FALSE;

    gdi = context->gdi;

    if (!gdi->drawing || !gdi->drawing->hdc)
        return FALSE;

    if (!gdi_decode_color(gdi, bgcolor, &bgcolor, NULL))
        return FALSE;

    if (!gdi_decode_color(gdi, fgcolor, &fgcolor, NULL))
        return FALSE;

    gdi_SetTextColor(gdi->drawing->hdc, bgcolor);
    gdi_SetBkColor(gdi->drawing->hdc, fgcolor);

    if (1)
    {
        GDI_RECT rect = { 0 };
        HGDI_BRUSH brush = gdi_CreateSolidBrush(fgcolor);

        if (!brush)
            return FALSE;

        if (x > 0)
            rect.left = x;

        if (y > 0)
            rect.top = y;

        rect.right = x + width - 1;
        rect.bottom = y + height - 1;

        if ((x + width > rect.left) && (y + height > rect.top))
            gdi_FillRect(gdi->drawing->hdc, &rect, brush);

        gdi_DeleteObject((HGDIOBJECT)brush);
    }

    return gdi_SetClipRgn(gdi->drawing->hdc, x, y, width, height);
}
Ejemplo n.º 16
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);
}
Ejemplo n.º 17
0
Archivo: gdi.c Proyecto: AMV007/FreeRDP
static void gdi_line_to(rdpContext* context, LINE_TO_ORDER* lineTo)
{
	UINT32 color;
	HGDI_PEN hPen;
	rdpGdi* gdi = context->gdi;

	color = freerdp_convert_gdi_order_color(lineTo->penColor, gdi->srcBpp, gdi->format, gdi->palette);
	hPen = gdi_CreatePen(lineTo->penStyle, lineTo->penWidth, (GDI_COLOR) color);
	gdi_SelectObject(gdi->drawing->hdc, (HGDIOBJECT) hPen);
	gdi_SetROP2(gdi->drawing->hdc, lineTo->bRop2);

	gdi_MoveToEx(gdi->drawing->hdc, lineTo->nXStart, lineTo->nYStart, NULL);
	gdi_LineTo(gdi->drawing->hdc, lineTo->nXEnd, lineTo->nYEnd);

	gdi_DeleteObject((HGDIOBJECT) hPen);
}
Ejemplo n.º 18
0
static int test_gdi_PtInRect(void)
{
	int rc = -1;
	HGDI_RECT hRect;
	UINT32 left = 20;
	UINT32 top = 40;
	UINT32 right = 60;
	UINT32 bottom = 80;

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

	if (gdi_PtInRect(hRect, 0, 0))
		goto fail;

	if (gdi_PtInRect(hRect, 500, 500))
		goto fail;

	if (gdi_PtInRect(hRect, 40, 100))
		goto fail;

	if (gdi_PtInRect(hRect, 10, 40))
		goto fail;

	if (!gdi_PtInRect(hRect, 30, 50))
		goto fail;

	if (!gdi_PtInRect(hRect, left, top))
		goto fail;

	if (!gdi_PtInRect(hRect, right, bottom))
		goto fail;

	if (!gdi_PtInRect(hRect, right, 60))
		goto fail;

	if (!gdi_PtInRect(hRect, 40, bottom))
		goto fail;

	rc = 0;
fail:
	gdi_DeleteObject((HGDIOBJECT)hRect);
	return rc;
}
Ejemplo n.º 19
0
int test_gdi_CreatePen(void)
{
	HGDI_PEN hPen = gdi_CreatePen(GDI_PS_SOLID, 8, 0xAABBCCDD);

	if (hPen->style != GDI_PS_SOLID)
		return -1;

	if (hPen->width != 8)
		return -1;

	if (hPen->color != 0xAABBCCDD)
		return -1;

	gdi_DeleteObject((HGDIOBJECT) hPen);

	return 0;
}
Ejemplo n.º 20
0
void gdi_Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height, UINT32 bgcolor, UINT32 fgcolor)
{
	GDI_RECT rect;
	HGDI_BRUSH brush;
	rdpGdi* gdi = context->gdi;

	bgcolor = freerdp_color_convert_var_bgr(bgcolor, gdi->srcBpp, 32, gdi->clrconv);
	fgcolor = freerdp_color_convert_var_bgr(fgcolor, gdi->srcBpp, 32, gdi->clrconv);

	gdi_CRgnToRect(x, y, width, height, &rect);

	brush = gdi_CreateSolidBrush(fgcolor);
	gdi_FillRect(gdi->drawing->hdc, &rect, brush);
	gdi_DeleteObject((HGDIOBJECT) brush);

	gdi->textColor = gdi_SetTextColor(gdi->drawing->hdc, bgcolor);
}
Ejemplo n.º 21
0
Archivo: gdi.c Proyecto: AMV007/FreeRDP
static void gdi_opaque_rect(rdpContext* context, OPAQUE_RECT_ORDER* opaque_rect)
{
	GDI_RECT rect;
	HGDI_BRUSH hBrush;
	UINT32 brush_color;
	rdpGdi* gdi = context->gdi;

	gdi_CRgnToRect(opaque_rect->nLeftRect, opaque_rect->nTopRect,
			opaque_rect->nWidth, opaque_rect->nHeight, &rect);

	brush_color = freerdp_convert_gdi_order_color(opaque_rect->color, gdi->srcBpp, gdi->format, gdi->palette);

	hBrush = gdi_CreateSolidBrush(brush_color);
	gdi_FillRect(gdi->drawing->hdc, &rect, hBrush);

	gdi_DeleteObject((HGDIOBJECT) hBrush);
}
Ejemplo n.º 22
0
int test_gdi_CreateSolidBrush(void)
{
	HGDI_BRUSH hBrush = gdi_CreateSolidBrush(0xAABBCCDD);

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

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

	if (hBrush->color != 0xAABBCCDD)
		return -1;

	gdi_DeleteObject((HGDIOBJECT) hBrush);

	return 0;
}
Ejemplo n.º 23
0
void gdi_Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height, UINT32 bgcolor, UINT32 fgcolor, BOOL fOpRedundant)
{
	GDI_RECT rect;
	HGDI_BRUSH brush;
	rdpGdi* gdi = context->gdi;

	/* TODO: handle fOpRedundant! See xf_Glyph_BeginDraw() */

	bgcolor = freerdp_convert_gdi_order_color(bgcolor, gdi->srcBpp, gdi->format, gdi->palette);
	fgcolor = freerdp_convert_gdi_order_color(fgcolor, gdi->srcBpp, gdi->format, gdi->palette);

	gdi_CRgnToRect(x, y, width, height, &rect);

	brush = gdi_CreateSolidBrush(fgcolor);
	gdi_FillRect(gdi->drawing->hdc, &rect, brush);
	gdi_DeleteObject((HGDIOBJECT) brush);

	gdi->textColor = gdi_SetTextColor(gdi->drawing->hdc, bgcolor);
}
Ejemplo n.º 24
0
int test_gdi_CreateCompatibleBitmap(void)
{
	HGDI_DC hdc;
	int width;
	int height;
	HGDI_BITMAP hBitmap;

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

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

	width = 32;
	height = 16;
	hBitmap = gdi_CreateCompatibleBitmap(hdc, width, height);

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

	if (hBitmap->bytesPerPixel != hdc->bytesPerPixel)
		return -1;

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

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

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

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

	gdi_DeleteObject((HGDIOBJECT) hBitmap);

	return 0;
}
Ejemplo n.º 25
0
static BOOL gdi_line_to(rdpContext* context, const LINE_TO_ORDER* lineTo)
{
	UINT32 color;
	HGDI_PEN hPen;
	rdpGdi* gdi = context->gdi;

	if (!gdi_decode_color(gdi, lineTo->penColor, &color, NULL))
		return FALSE;

	if (!(hPen = gdi_CreatePen(lineTo->penStyle, lineTo->penWidth, color,
	                           gdi->drawing->hdc->format, &gdi->palette)))
		return FALSE;

	gdi_SelectObject(gdi->drawing->hdc, (HGDIOBJECT) hPen);
	gdi_SetROP2(gdi->drawing->hdc, lineTo->bRop2);
	gdi_MoveToEx(gdi->drawing->hdc, lineTo->nXStart, lineTo->nYStart, NULL);
	gdi_LineTo(gdi->drawing->hdc, lineTo->nXEnd, lineTo->nYEnd);
	gdi_DeleteObject((HGDIOBJECT) hPen);
	return TRUE;
}
Ejemplo n.º 26
0
static BOOL gdi_opaque_rect(rdpContext* context,
                            const OPAQUE_RECT_ORDER* opaque_rect)
{
	GDI_RECT rect;
	HGDI_BRUSH hBrush;
	UINT32 brush_color;
	rdpGdi* gdi = context->gdi;
	BOOL ret;
	gdi_CRgnToRect(opaque_rect->nLeftRect, opaque_rect->nTopRect,
	               opaque_rect->nWidth, opaque_rect->nHeight, &rect);

	if (!gdi_decode_color(gdi, opaque_rect->color, &brush_color, NULL))
		return FALSE;

	if (!(hBrush = gdi_CreateSolidBrush(brush_color)))
		return FALSE;

	ret = gdi_FillRect(gdi->drawing->hdc, &rect, hBrush);
	gdi_DeleteObject((HGDIOBJECT) hBrush);
	return ret;
}
Ejemplo n.º 27
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;
}
Ejemplo n.º 28
0
Archivo: gdi.c Proyecto: 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);
}
Ejemplo n.º 29
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;
}
Ejemplo n.º 30
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;
}