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/api.h>
24 #include <freerdp/freerdp.h>
25 #include <freerdp/gdi/gdi.h>
26 #include <freerdp/codec/color.h>
28 #include <freerdp/gdi/32bpp.h>
29 #include <freerdp/gdi/16bpp.h>
30 #include <freerdp/gdi/8bpp.h>
32 #include <freerdp/gdi/bitmap.h>
44 * Get pixel at the given coordinates.\n
46 * @param hdc device context
47 * @param nXPos pixel x position
48 * @param nYPos pixel y position
52 INLINE GDI_COLOR gdi_GetPixel(HGDI_DC hdc, int nXPos, int nYPos)
54 HGDI_BITMAP hBmp = (HGDI_BITMAP) hdc->selectedObject;
55 GDI_COLOR* colorp = (GDI_COLOR*)&(hBmp->data[(nYPos * hBmp->width * hdc->bytesPerPixel) + nXPos * hdc->bytesPerPixel]);
56 return (GDI_COLOR) *colorp;
59 INLINE uint8 gdi_GetPixel_8bpp(HGDI_BITMAP hBmp, int X, int Y)
61 return *((uint8*)&(hBmp->data[(Y * hBmp->width) + X]));
64 INLINE uint16 gdi_GetPixel_16bpp(HGDI_BITMAP hBmp, int X, int Y)
66 return *((uint16*)&(hBmp->data[(Y * hBmp->width * 2) + X * 2]));
69 INLINE uint32 gdi_GetPixel_32bpp(HGDI_BITMAP hBmp, int X, int Y)
71 return *((uint32*)&(hBmp->data[(Y * hBmp->width * 4) + X * 4]));
74 INLINE uint8* gdi_GetPointer_8bpp(HGDI_BITMAP hBmp, int X, int Y)
76 return ((uint8*)&(hBmp->data[(Y * hBmp->width) + X]));
79 INLINE uint16* gdi_GetPointer_16bpp(HGDI_BITMAP hBmp, int X, int Y)
81 return ((uint16*)&(hBmp->data[(Y * hBmp->width * 2) + X * 2]));
84 INLINE uint32* gdi_GetPointer_32bpp(HGDI_BITMAP hBmp, int X, int Y)
86 return ((uint32*)&(hBmp->data[(Y * hBmp->width * 4) + X * 4]));
90 * Set pixel at the given coordinates.\n
92 * @param hdc device context
93 * @param X pixel x position
94 * @param Y pixel y position
95 * @param crColor new pixel color
99 INLINE GDI_COLOR gdi_SetPixel(HGDI_DC hdc, int X, int Y, GDI_COLOR crColor)
101 HGDI_BITMAP hBmp = (HGDI_BITMAP) hdc->selectedObject;
102 *((GDI_COLOR*)&(hBmp->data[(Y * hBmp->width * hdc->bytesPerPixel) + X * hdc->bytesPerPixel])) = crColor;
106 INLINE void gdi_SetPixel_8bpp(HGDI_BITMAP hBmp, int X, int Y, uint8 pixel)
108 *((uint8*)&(hBmp->data[(Y * hBmp->width) + X])) = pixel;
111 INLINE void gdi_SetPixel_16bpp(HGDI_BITMAP hBmp, int X, int Y, uint16 pixel)
113 *((uint16*)&(hBmp->data[(Y * hBmp->width * 2) + X * 2])) = pixel;
116 INLINE void gdi_SetPixel_32bpp(HGDI_BITMAP hBmp, int X, int Y, uint32 pixel)
118 *((uint32*)&(hBmp->data[(Y * hBmp->width * 4) + X * 4])) = pixel;
122 * Create a new bitmap with the given width, height, color format and pixel buffer.\n
124 * @param nWidth width
125 * @param nHeight height
126 * @param cBitsPerPixel bits per pixel
127 * @param data pixel buffer
131 HGDI_BITMAP gdi_CreateBitmap(int nWidth, int nHeight, int cBitsPerPixel, uint8* data)
133 HGDI_BITMAP hBitmap = (HGDI_BITMAP) malloc(sizeof(GDI_BITMAP));
134 hBitmap->objectType = GDIOBJECT_BITMAP;
135 hBitmap->bitsPerPixel = cBitsPerPixel;
136 hBitmap->bytesPerPixel = (cBitsPerPixel + 1) / 8;
137 hBitmap->scanline = nWidth * hBitmap->bytesPerPixel;
138 hBitmap->width = nWidth;
139 hBitmap->height = nHeight;
140 hBitmap->data = data;
145 * Create a new bitmap of the given width and height compatible with the current device context.\n
147 * @param hdc device context
148 * @param nWidth width
149 * @param nHeight height
153 HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, int nWidth, int nHeight)
155 HGDI_BITMAP hBitmap = (HGDI_BITMAP) malloc(sizeof(GDI_BITMAP));
156 hBitmap->objectType = GDIOBJECT_BITMAP;
157 hBitmap->bytesPerPixel = hdc->bytesPerPixel;
158 hBitmap->bitsPerPixel = hdc->bitsPerPixel;
159 hBitmap->width = nWidth;
160 hBitmap->height = nHeight;
161 hBitmap->data = malloc(nWidth * nHeight * hBitmap->bytesPerPixel);
162 hBitmap->scanline = nWidth * hBitmap->bytesPerPixel;
167 * Perform a bit blit operation on the given pixel buffers.\n
169 * @param hdcDest destination device context
170 * @param nXDest destination x1
171 * @param nYDest destination y1
172 * @param nWidth width
173 * @param nHeight height
174 * @param hdcSrc source device context
175 * @param nXSrc source x1
176 * @param nYSrc source y1
177 * @param rop raster operation code
178 * @return 1 if successful, 0 otherwise
181 int gdi_BitBlt(HGDI_DC hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, HGDI_DC hdcSrc, int nXSrc, int nYSrc, int rop)
183 p_BitBlt _BitBlt = BitBlt_[IBPP(hdcDest->bitsPerPixel)];
186 return _BitBlt(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, rop);