2011-10-21 01:28:59 +04:00
|
|
|
/**
|
|
|
|
* FreeRDP: A Remote Desktop Protocol Client
|
|
|
|
* Graphical Objects
|
|
|
|
*
|
|
|
|
* Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <freerdp/gdi/dc.h>
|
2011-11-09 08:26:44 +04:00
|
|
|
#include <freerdp/gdi/brush.h>
|
|
|
|
#include <freerdp/gdi/shape.h>
|
|
|
|
#include <freerdp/gdi/region.h>
|
2011-10-21 01:28:59 +04:00
|
|
|
#include <freerdp/gdi/bitmap.h>
|
2011-11-09 08:26:44 +04:00
|
|
|
#include <freerdp/gdi/drawing.h>
|
2011-11-09 21:16:09 +04:00
|
|
|
#include <freerdp/gdi/clipping.h>
|
2011-10-21 01:28:59 +04:00
|
|
|
#include <freerdp/codec/color.h>
|
|
|
|
#include <freerdp/codec/bitmap.h>
|
|
|
|
#include <freerdp/utils/memory.h>
|
|
|
|
#include <freerdp/codec/bitmap.h>
|
2011-11-09 08:26:44 +04:00
|
|
|
#include <freerdp/cache/glyph.h>
|
2011-10-21 01:28:59 +04:00
|
|
|
|
|
|
|
#include "graphics.h"
|
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
/* Bitmap Class */
|
|
|
|
|
2011-10-21 01:28:59 +04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void 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 (bitmap->data == NULL)
|
|
|
|
gdi_bitmap->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, bitmap->width, bitmap->height);
|
|
|
|
else
|
|
|
|
gdi_bitmap->bitmap = gdi_create_bitmap(gdi, bitmap->width, bitmap->height, gdi->dstBpp, bitmap->data);
|
|
|
|
|
|
|
|
gdi_SelectObject(gdi_bitmap->hdc, (HGDIOBJECT) gdi_bitmap->bitmap);
|
|
|
|
gdi_bitmap->org_bitmap = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-21 05:34:55 +04:00
|
|
|
void gdi_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
2011-10-21 05:34:55 +04:00
|
|
|
int width, height;
|
2011-10-21 01:28:59 +04:00
|
|
|
gdiBitmap* gdi_bitmap = (gdiBitmap*) bitmap;
|
|
|
|
|
2011-10-21 05:34:55 +04:00
|
|
|
width = bitmap->right - bitmap->left + 1;
|
|
|
|
height = bitmap->bottom - bitmap->top + 1;
|
|
|
|
|
|
|
|
gdi_BitBlt(context->gdi->primary->hdc, bitmap->left, bitmap->top,
|
|
|
|
width, height, gdi_bitmap->hdc, 0, 0, GDI_SRCCOPY);
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
|
|
|
|
uint8* data, int width, int height, int bpp, int length, boolean compressed)
|
|
|
|
{
|
|
|
|
uint16 size;
|
|
|
|
|
2011-10-25 06:04:51 +04:00
|
|
|
size = width * height * (bpp + 7) / 8;
|
2011-10-21 01:28:59 +04:00
|
|
|
|
|
|
|
if (bitmap->data == NULL)
|
|
|
|
bitmap->data = (uint8*) xmalloc(size);
|
|
|
|
else
|
|
|
|
bitmap->data = (uint8*) xrealloc(bitmap->data, size);
|
|
|
|
|
|
|
|
if (compressed)
|
|
|
|
{
|
|
|
|
boolean status;
|
|
|
|
|
|
|
|
status = bitmap_decompress(data, bitmap->data, width, height, length, bpp, bpp);
|
|
|
|
|
2011-11-19 21:19:16 +04:00
|
|
|
if (status != true)
|
2011-10-21 01:28:59 +04:00
|
|
|
{
|
|
|
|
printf("Bitmap Decompression Failed\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
freerdp_image_flip(data, bitmap->data, width, height, bpp);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bitmap->width = width;
|
|
|
|
bitmap->height = height;
|
2011-11-19 21:19:16 +04:00
|
|
|
bitmap->compressed = false;
|
2011-10-21 01:28:59 +04:00
|
|
|
bitmap->length = size;
|
|
|
|
bitmap->bpp = bpp;
|
|
|
|
}
|
|
|
|
|
2011-10-21 02:18:45 +04:00
|
|
|
void gdi_Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, boolean primary)
|
|
|
|
{
|
|
|
|
rdpGdi* gdi = context->gdi;
|
|
|
|
|
|
|
|
if (primary)
|
|
|
|
gdi->drawing = gdi->primary;
|
|
|
|
else
|
|
|
|
gdi->drawing = (gdiBitmap*) bitmap;
|
|
|
|
}
|
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
/* Glyph Class */
|
|
|
|
|
2011-11-09 09:43:56 +04:00
|
|
|
void gdi_Glyph_New(rdpContext* context, rdpGlyph* glyph)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-11-09 09:43:56 +04:00
|
|
|
void gdi_Glyph_Free(rdpContext* context, rdpGlyph* glyph)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
xfree(gdi_glyph);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-09 09:43:56 +04:00
|
|
|
void gdi_Glyph_Draw(rdpContext* context, rdpGlyph* glyph, int x, int y)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
|
|
|
gdiGlyph* gdi_glyph;
|
|
|
|
rdpGdi* gdi = context->gdi;
|
|
|
|
|
|
|
|
gdi_glyph = (gdiGlyph*) glyph;
|
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
gdi_BitBlt(gdi->drawing->hdc, x, y, gdi_glyph->bitmap->width,
|
2011-11-09 08:26:44 +04:00
|
|
|
gdi_glyph->bitmap->height, gdi_glyph->hdc, 0, 0, GDI_DSPDxax);
|
|
|
|
}
|
|
|
|
|
2011-11-09 09:43:56 +04:00
|
|
|
void gdi_Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
|
|
|
GDI_RECT rect;
|
|
|
|
HGDI_BRUSH brush;
|
|
|
|
rdpGdi* gdi = context->gdi;
|
|
|
|
|
2012-01-09 03:19:04 +04:00
|
|
|
bgcolor = freerdp_color_convert_var_bgr(bgcolor, gdi->srcBpp, 32, gdi->clrconv);
|
|
|
|
fgcolor = freerdp_color_convert_var_bgr(fgcolor, gdi->srcBpp, 32, gdi->clrconv);
|
2011-11-09 08:26:44 +04:00
|
|
|
|
|
|
|
gdi_CRgnToRect(x, y, width, height, &rect);
|
2012-01-09 03:19:04 +04:00
|
|
|
|
2011-11-09 08:26:44 +04:00
|
|
|
brush = gdi_CreateSolidBrush(fgcolor);
|
|
|
|
|
|
|
|
gdi_FillRect(gdi->drawing->hdc, &rect, brush);
|
2011-11-09 21:57:31 +04:00
|
|
|
|
|
|
|
gdi->textColor = gdi_SetTextColor(gdi->drawing->hdc, bgcolor);
|
2011-11-09 08:26:44 +04:00
|
|
|
}
|
|
|
|
|
2011-11-09 09:43:56 +04:00
|
|
|
void gdi_Glyph_EndDraw(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor)
|
2011-11-09 08:26:44 +04:00
|
|
|
{
|
|
|
|
rdpGdi* gdi = context->gdi;
|
|
|
|
|
2012-01-09 03:19:04 +04:00
|
|
|
bgcolor = freerdp_color_convert_var_bgr(bgcolor, gdi->srcBpp, 32, gdi->clrconv);
|
2011-11-09 08:26:44 +04:00
|
|
|
gdi->textColor = gdi_SetTextColor(gdi->drawing->hdc, bgcolor);
|
|
|
|
}
|
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
/* Graphics Module */
|
|
|
|
|
2011-10-21 01:28:59 +04:00
|
|
|
void gdi_register_graphics(rdpGraphics* graphics)
|
|
|
|
{
|
2011-11-09 21:16:09 +04:00
|
|
|
rdpBitmap* bitmap;
|
|
|
|
rdpGlyph* glyph;
|
2011-10-21 01:28:59 +04:00
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
bitmap = xnew(rdpBitmap);
|
|
|
|
bitmap->size = sizeof(gdiBitmap);
|
2011-10-21 01:28:59 +04:00
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
bitmap->New = gdi_Bitmap_New;
|
|
|
|
bitmap->Free = gdi_Bitmap_Free;
|
|
|
|
bitmap->Paint = gdi_Bitmap_Paint;
|
|
|
|
bitmap->Decompress = gdi_Bitmap_Decompress;
|
|
|
|
bitmap->SetSurface = gdi_Bitmap_SetSurface;
|
2011-10-21 01:28:59 +04:00
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
graphics_register_bitmap(graphics, bitmap);
|
|
|
|
xfree(bitmap);
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
glyph = xnew(rdpGlyph);
|
|
|
|
glyph->size = sizeof(gdiGlyph);
|
2011-11-09 09:43:56 +04:00
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
glyph->New = gdi_Glyph_New;
|
|
|
|
glyph->Free = gdi_Glyph_Free;
|
|
|
|
glyph->Draw = gdi_Glyph_Draw;
|
|
|
|
glyph->BeginDraw = gdi_Glyph_BeginDraw;
|
|
|
|
glyph->EndDraw = gdi_Glyph_EndDraw;
|
2011-11-09 08:26:44 +04:00
|
|
|
|
2011-11-09 21:16:09 +04:00
|
|
|
graphics_register_glyph(graphics, glyph);
|
|
|
|
xfree(glyph);
|
2011-10-21 01:28:59 +04:00
|
|
|
}
|
|
|
|
|