2 * FreeRDP: A Remote Desktop Protocol Client
5 * Copyright 2011 Marc-Andre Moreau <marcandre.moreau@gmail.com>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
20 #include <freerdp/gdi/dc.h>
21 #include <freerdp/gdi/brush.h>
22 #include <freerdp/gdi/shape.h>
23 #include <freerdp/gdi/region.h>
24 #include <freerdp/gdi/bitmap.h>
25 #include <freerdp/gdi/drawing.h>
26 #include <freerdp/gdi/clipping.h>
27 #include <freerdp/codec/color.h>
28 #include <freerdp/codec/bitmap.h>
29 #include <freerdp/utils/memory.h>
30 #include <freerdp/codec/bitmap.h>
31 #include <freerdp/cache/glyph.h>
37 HGDI_BITMAP gdi_create_bitmap(rdpGdi* gdi, int width, int height, int bpp, uint8* data)
42 bmpData = freerdp_image_convert(data, NULL, width, height, gdi->srcBpp, bpp, gdi->clrconv);
43 bitmap = gdi_CreateBitmap(width, height, gdi->dstBpp, bmpData);
48 void gdi_Bitmap_New(rdpContext* context, rdpBitmap* bitmap)
50 gdiBitmap* gdi_bitmap;
51 rdpGdi* gdi = context->gdi;
53 gdi_bitmap = (gdiBitmap*) bitmap;
54 gdi_bitmap->hdc = gdi_CreateCompatibleDC(gdi->hdc);
56 if (bitmap->data == NULL)
57 gdi_bitmap->bitmap = gdi_CreateCompatibleBitmap(gdi->hdc, bitmap->width, bitmap->height);
59 gdi_bitmap->bitmap = gdi_create_bitmap(gdi, bitmap->width, bitmap->height, gdi->dstBpp, bitmap->data);
61 gdi_SelectObject(gdi_bitmap->hdc, (HGDIOBJECT) gdi_bitmap->bitmap);
62 gdi_bitmap->org_bitmap = NULL;
65 void gdi_Bitmap_Free(rdpContext* context, rdpBitmap* bitmap)
67 gdiBitmap* gdi_bitmap = (gdiBitmap*) bitmap;
69 if (gdi_bitmap != NULL)
71 gdi_SelectObject(gdi_bitmap->hdc, (HGDIOBJECT) gdi_bitmap->org_bitmap);
72 gdi_DeleteObject((HGDIOBJECT) gdi_bitmap->bitmap);
73 gdi_DeleteDC(gdi_bitmap->hdc);
77 void gdi_Bitmap_Paint(rdpContext* context, rdpBitmap* bitmap)
80 gdiBitmap* gdi_bitmap = (gdiBitmap*) bitmap;
82 width = bitmap->right - bitmap->left + 1;
83 height = bitmap->bottom - bitmap->top + 1;
85 gdi_BitBlt(context->gdi->primary->hdc, bitmap->left, bitmap->top,
86 width, height, gdi_bitmap->hdc, 0, 0, GDI_SRCCOPY);
89 void gdi_Bitmap_Decompress(rdpContext* context, rdpBitmap* bitmap,
90 uint8* data, int width, int height, int bpp, int length, boolean compressed)
94 size = width * height * (bpp + 7) / 8;
96 if (bitmap->data == NULL)
97 bitmap->data = (uint8*) xmalloc(size);
99 bitmap->data = (uint8*) xrealloc(bitmap->data, size);
105 status = bitmap_decompress(data, bitmap->data, width, height, length, bpp, bpp);
109 printf("Bitmap Decompression Failed\n");
114 freerdp_image_flip(data, bitmap->data, width, height, bpp);
118 bitmap->width = width;
119 bitmap->height = height;
120 bitmap->compressed = false;
121 bitmap->length = size;
125 void gdi_Bitmap_SetSurface(rdpContext* context, rdpBitmap* bitmap, boolean primary)
127 rdpGdi* gdi = context->gdi;
130 gdi->drawing = gdi->primary;
132 gdi->drawing = (gdiBitmap*) bitmap;
137 void gdi_Glyph_New(rdpContext* context, rdpGlyph* glyph)
142 gdi_glyph = (gdiGlyph*) glyph;
144 gdi_glyph->hdc = gdi_GetDC();
145 gdi_glyph->hdc->bytesPerPixel = 1;
146 gdi_glyph->hdc->bitsPerPixel = 1;
148 data = freerdp_glyph_convert(glyph->cx, glyph->cy, glyph->aj);
149 gdi_glyph->bitmap = gdi_CreateBitmap(glyph->cx, glyph->cy, 1, data);
150 gdi_glyph->bitmap->bytesPerPixel = 1;
151 gdi_glyph->bitmap->bitsPerPixel = 1;
153 gdi_SelectObject(gdi_glyph->hdc, (HGDIOBJECT) gdi_glyph->bitmap);
154 gdi_glyph->org_bitmap = NULL;
157 void gdi_Glyph_Free(rdpContext* context, rdpGlyph* glyph)
161 gdi_glyph = (gdiGlyph*) glyph;
165 gdi_SelectObject(gdi_glyph->hdc, (HGDIOBJECT) gdi_glyph->org_bitmap);
166 gdi_DeleteObject((HGDIOBJECT) gdi_glyph->bitmap);
167 gdi_DeleteDC(gdi_glyph->hdc);
171 void gdi_Glyph_Draw(rdpContext* context, rdpGlyph* glyph, int x, int y)
174 rdpGdi* gdi = context->gdi;
176 gdi_glyph = (gdiGlyph*) glyph;
178 gdi_BitBlt(gdi->drawing->hdc, x, y, gdi_glyph->bitmap->width,
179 gdi_glyph->bitmap->height, gdi_glyph->hdc, 0, 0, GDI_DSPDxax);
182 void gdi_Glyph_BeginDraw(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor)
186 rdpGdi* gdi = context->gdi;
188 bgcolor = freerdp_color_convert_var_bgr(bgcolor, gdi->srcBpp, 32, gdi->clrconv);
189 fgcolor = freerdp_color_convert_var_bgr(fgcolor, gdi->srcBpp, 32, gdi->clrconv);
191 gdi_CRgnToRect(x, y, width, height, &rect);
193 brush = gdi_CreateSolidBrush(fgcolor);
195 gdi_FillRect(gdi->drawing->hdc, &rect, brush);
197 gdi->textColor = gdi_SetTextColor(gdi->drawing->hdc, bgcolor);
200 void gdi_Glyph_EndDraw(rdpContext* context, int x, int y, int width, int height, uint32 bgcolor, uint32 fgcolor)
202 rdpGdi* gdi = context->gdi;
204 bgcolor = freerdp_color_convert_var_bgr(bgcolor, gdi->srcBpp, 32, gdi->clrconv);
205 gdi->textColor = gdi_SetTextColor(gdi->drawing->hdc, bgcolor);
208 /* Graphics Module */
210 void gdi_register_graphics(rdpGraphics* graphics)
215 bitmap = xnew(rdpBitmap);
216 bitmap->size = sizeof(gdiBitmap);
218 bitmap->New = gdi_Bitmap_New;
219 bitmap->Free = gdi_Bitmap_Free;
220 bitmap->Paint = gdi_Bitmap_Paint;
221 bitmap->Decompress = gdi_Bitmap_Decompress;
222 bitmap->SetSurface = gdi_Bitmap_SetSurface;
224 graphics_register_bitmap(graphics, bitmap);
227 glyph = xnew(rdpGlyph);
228 glyph->size = sizeof(gdiGlyph);
230 glyph->New = gdi_Glyph_New;
231 glyph->Free = gdi_Glyph_Free;
232 glyph->Draw = gdi_Glyph_Draw;
233 glyph->BeginDraw = gdi_Glyph_BeginDraw;
234 glyph->EndDraw = gdi_Glyph_EndDraw;
236 graphics_register_glyph(graphics, glyph);