2 * FreeRDP: A Remote Desktop Protocol Client
5 * Copyright 2010-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.
23 #include <freerdp/freerdp.h>
24 #include <freerdp/gdi/gdi.h>
26 #include <freerdp/gdi/8bpp.h>
27 #include <freerdp/gdi/16bpp.h>
28 #include <freerdp/gdi/32bpp.h>
29 #include <freerdp/gdi/bitmap.h>
31 #include <freerdp/gdi/shape.h>
33 p_FillRect FillRect_[5] =
42 static void Ellipse_Bresenham(HGDI_DC hdc, int x1, int y1, int x2, int y2)
53 int bpp = hdc->bitsPerPixel;
55 a = (x1 < x2) ? x2 - x1 : x1 - x2;
56 b = (y1 < y2) ? y2 - y1 : y1 - y2;
59 dx = 4 * (1 - a) * b * b;
60 dy = 4 * (c + 1) * a * a;
61 e = dx + dy + c * a * a;
81 bmp = (HGDI_BITMAP) hdc->selectedObject;
87 gdi_SetPixel_32bpp(bmp, x2, y1, pixel32);
88 gdi_SetPixel_32bpp(bmp, x1, y1, pixel32);
89 gdi_SetPixel_32bpp(bmp, x1, y2, pixel32);
90 gdi_SetPixel_32bpp(bmp, x2, y2, pixel32);
94 gdi_SetPixel_16bpp(bmp, x2, y1, pixel16);
95 gdi_SetPixel_16bpp(bmp, x1, y1, pixel16);
96 gdi_SetPixel_16bpp(bmp, x1, y2, pixel16);
97 gdi_SetPixel_16bpp(bmp, x2, y2, pixel16);
101 for (i = x1; i < x2; i++)
103 gdi_SetPixel_8bpp(bmp, i, y1, pixel8);
104 gdi_SetPixel_8bpp(bmp, i, y2, pixel8);
107 for (i = y1; i < y2; i++)
109 gdi_SetPixel_8bpp(bmp, x1, i, pixel8);
110 gdi_SetPixel_8bpp(bmp, x2, i, pixel8);
136 gdi_SetPixel_32bpp(bmp, x1 - 1, ++y1, pixel32);
137 gdi_SetPixel_32bpp(bmp, x1 - 1, --y2, pixel32);
141 gdi_SetPixel_16bpp(bmp, x1 - 1, ++y1, pixel16);
142 gdi_SetPixel_16bpp(bmp, x1 - 1, --y2, pixel16);
146 gdi_SetPixel_8bpp(bmp, x1 - 1, ++y1, pixel8);
147 gdi_SetPixel_8bpp(bmp, x1 - 1, --y2, pixel8);
154 * @param hdc device context
155 * @param nLeftRect x1
157 * @param nRightRect x2
158 * @param nBottomRect y2
161 int gdi_Ellipse(HGDI_DC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect)
163 Ellipse_Bresenham(hdc, nLeftRect, nTopRect, nRightRect, nBottomRect);
168 * Fill a rectangle with the given brush.\n
170 * @param hdc device context
171 * @param rect rectangle
173 * @return 1 if successful, 0 otherwise
176 int gdi_FillRect(HGDI_DC hdc, HGDI_RECT rect, HGDI_BRUSH hbr)
178 p_FillRect _FillRect = FillRect_[IBPP(hdc->bitsPerPixel)];
180 if (_FillRect != NULL)
181 return _FillRect(hdc, rect, hbr);
188 * @param hdc device context
189 * @param lpPoints array of points
190 * @param nCount number of points
193 int gdi_Polygon(HGDI_DC hdc, GDI_POINT *lpPoints, int nCount)
199 * Draw a series of closed polygons
200 * @param hdc device context
201 * @param lpPoints array of series of points
202 * @param lpPolyCounts array of number of points in each series
203 * @param nCount count of number of points in lpPolyCounts
206 int gdi_PolyPolygon(HGDI_DC hdc, GDI_POINT *lpPoints, int *lpPolyCounts, int nCount)
213 * @param hdc device context
214 * @param nLeftRect x1
216 * @param nRightRect x2
217 * @param nBottomRect y2
220 int gdi_Rectangle(HGDI_DC hdc, int nLeftRect, int nTopRect, int nRightRect, int nBottomRect)