/src/FreeRDP/libfreerdp/gdi/bitmap.c
Line | Count | Source (jump to first uncovered line) |
1 | | /** |
2 | | * FreeRDP: A Remote Desktop Protocol Implementation |
3 | | * GDI Bitmap Functions |
4 | | * |
5 | | * Copyright 2010-2011 Marc-Andre Moreau <marcandre.moreau@gmail.com> |
6 | | * Copyright 2016 Armin Novak <armin.novak@thincast.com> |
7 | | * Copyright 2016 Thincast Technologies GmbH |
8 | | * |
9 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
10 | | * you may not use this file except in compliance with the License. |
11 | | * You may obtain a copy of the License at |
12 | | * |
13 | | * http://www.apache.org/licenses/LICENSE-2.0 |
14 | | * |
15 | | * Unless required by applicable law or agreed to in writing, software |
16 | | * distributed under the License is distributed on an "AS IS" BASIS, |
17 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
18 | | * See the License for the specific language governing permissions and |
19 | | * limitations under the License. |
20 | | */ |
21 | | |
22 | | #include <freerdp/config.h> |
23 | | |
24 | | #include <stdio.h> |
25 | | #include <string.h> |
26 | | #include <stdlib.h> |
27 | | |
28 | | #include <freerdp/api.h> |
29 | | #include <freerdp/freerdp.h> |
30 | | #include <freerdp/gdi/gdi.h> |
31 | | #include <freerdp/codec/color.h> |
32 | | |
33 | | #include <freerdp/gdi/region.h> |
34 | | #include <freerdp/gdi/bitmap.h> |
35 | | #include <freerdp/log.h> |
36 | | #include <freerdp/gdi/shape.h> |
37 | | |
38 | | #include "brush.h" |
39 | | #include "clipping.h" |
40 | | #include "../gdi/gdi.h" |
41 | | |
42 | | #define TAG FREERDP_TAG("gdi.bitmap") |
43 | | |
44 | | /** |
45 | | * Get pixel at the given coordinates. msdn{dd144909} |
46 | | * @param hdc device context |
47 | | * @param nXPos pixel x position |
48 | | * @param nYPos pixel y position |
49 | | * @return pixel color |
50 | | */ |
51 | | |
52 | | UINT32 gdi_GetPixel(HGDI_DC hdc, UINT32 nXPos, UINT32 nYPos) |
53 | 0 | { |
54 | 0 | HGDI_BITMAP hBmp = (HGDI_BITMAP)hdc->selectedObject; |
55 | 0 | BYTE* data = |
56 | 0 | &(hBmp->data[(nYPos * hBmp->scanline) + nXPos * FreeRDPGetBytesPerPixel(hBmp->format)]); |
57 | 0 | return FreeRDPReadColor(data, hBmp->format); |
58 | 0 | } |
59 | | |
60 | | BYTE* gdi_GetPointer(HGDI_BITMAP hBmp, UINT32 X, UINT32 Y) |
61 | 0 | { |
62 | 0 | UINT32 bpp = FreeRDPGetBytesPerPixel(hBmp->format); |
63 | 0 | return &hBmp->data[(Y * hBmp->width * bpp) + X * bpp]; |
64 | 0 | } |
65 | | |
66 | | /** |
67 | | * Set pixel at the given coordinates. msdn{dd145078} |
68 | | * |
69 | | * @param hBmp device context |
70 | | * @param X pixel x position |
71 | | * @param Y pixel y position |
72 | | * @param crColor new pixel color |
73 | | * @return the color written |
74 | | */ |
75 | | |
76 | | static INLINE UINT32 gdi_SetPixelBmp(HGDI_BITMAP hBmp, UINT32 X, UINT32 Y, UINT32 crColor) |
77 | 0 | { |
78 | 0 | BYTE* p = &hBmp->data[(Y * hBmp->scanline) + X * FreeRDPGetBytesPerPixel(hBmp->format)]; |
79 | 0 | FreeRDPWriteColor(p, hBmp->format, crColor); |
80 | 0 | return crColor; |
81 | 0 | } |
82 | | |
83 | | UINT32 gdi_SetPixel(HGDI_DC hdc, UINT32 X, UINT32 Y, UINT32 crColor) |
84 | 0 | { |
85 | 0 | HGDI_BITMAP hBmp = (HGDI_BITMAP)hdc->selectedObject; |
86 | 0 | return gdi_SetPixelBmp(hBmp, X, Y, crColor); |
87 | 0 | } |
88 | | |
89 | | /** |
90 | | * Create a new bitmap with the given width, height, color format and pixel buffer. msdn{dd183485} |
91 | | * |
92 | | * @param nWidth width |
93 | | * @param nHeight height |
94 | | * @param format the color format used |
95 | | * @param data pixel buffer |
96 | | * @return new bitmap |
97 | | */ |
98 | | |
99 | | HGDI_BITMAP gdi_CreateBitmap(UINT32 nWidth, UINT32 nHeight, UINT32 format, BYTE* data) |
100 | 0 | { |
101 | 0 | return gdi_CreateBitmapEx(nWidth, nHeight, format, 0, data, winpr_aligned_free); |
102 | 0 | } |
103 | | |
104 | | /** |
105 | | * Create a new bitmap with the given width, height, color format and pixel buffer. msdn{dd183485} |
106 | | * |
107 | | * @param nWidth width |
108 | | * @param nHeight height |
109 | | * @param format the color format used |
110 | | * @param data pixel buffer |
111 | | * @param fkt_free The function used for deallocation of the buffer, NULL for none. |
112 | | * @return new bitmap |
113 | | */ |
114 | | |
115 | | HGDI_BITMAP gdi_CreateBitmapEx(UINT32 nWidth, UINT32 nHeight, UINT32 format, UINT32 stride, |
116 | | BYTE* data, void (*fkt_free)(void*)) |
117 | 0 | { |
118 | 0 | HGDI_BITMAP hBitmap = (HGDI_BITMAP)calloc(1, sizeof(GDI_BITMAP)); |
119 | |
|
120 | 0 | if (!hBitmap) |
121 | 0 | return NULL; |
122 | | |
123 | 0 | hBitmap->objectType = GDIOBJECT_BITMAP; |
124 | 0 | hBitmap->format = format; |
125 | |
|
126 | 0 | if (stride > 0) |
127 | 0 | hBitmap->scanline = stride; |
128 | 0 | else |
129 | 0 | hBitmap->scanline = nWidth * FreeRDPGetBytesPerPixel(hBitmap->format); |
130 | |
|
131 | 0 | hBitmap->width = nWidth; |
132 | 0 | hBitmap->height = nHeight; |
133 | 0 | hBitmap->data = data; |
134 | 0 | hBitmap->free = fkt_free; |
135 | 0 | return hBitmap; |
136 | 0 | } |
137 | | |
138 | | /** |
139 | | * Create a new bitmap of the given width and height compatible with the current device context. |
140 | | * msdn{dd183488} |
141 | | * |
142 | | * @param hdc device context |
143 | | * @param nWidth width |
144 | | * @param nHeight height |
145 | | * |
146 | | * @return new bitmap |
147 | | */ |
148 | | |
149 | | HGDI_BITMAP gdi_CreateCompatibleBitmap(HGDI_DC hdc, UINT32 nWidth, UINT32 nHeight) |
150 | 0 | { |
151 | 0 | HGDI_BITMAP hBitmap = (HGDI_BITMAP)calloc(1, sizeof(GDI_BITMAP)); |
152 | |
|
153 | 0 | if (!hBitmap) |
154 | 0 | return NULL; |
155 | | |
156 | 0 | hBitmap->objectType = GDIOBJECT_BITMAP; |
157 | 0 | hBitmap->format = hdc->format; |
158 | 0 | hBitmap->width = nWidth; |
159 | 0 | hBitmap->height = nHeight; |
160 | 0 | hBitmap->data = winpr_aligned_malloc( |
161 | 0 | 1ull * nWidth * nHeight * FreeRDPGetBytesPerPixel(hBitmap->format), 16); |
162 | 0 | hBitmap->free = winpr_aligned_free; |
163 | |
|
164 | 0 | if (!hBitmap->data) |
165 | 0 | { |
166 | 0 | free(hBitmap); |
167 | 0 | return NULL; |
168 | 0 | } |
169 | | |
170 | 0 | hBitmap->scanline = nWidth * FreeRDPGetBytesPerPixel(hBitmap->format); |
171 | 0 | return hBitmap; |
172 | 0 | } |
173 | | |
174 | | static BOOL op_not(UINT32* stack, UINT32* stackp) |
175 | 0 | { |
176 | 0 | if (!stack || !stackp) |
177 | 0 | return FALSE; |
178 | | |
179 | 0 | if (*stackp < 1) |
180 | 0 | return FALSE; |
181 | | |
182 | 0 | stack[(*stackp) - 1] = ~stack[(*stackp) - 1]; |
183 | 0 | return TRUE; |
184 | 0 | } |
185 | | |
186 | | static BOOL op_and(UINT32* stack, UINT32* stackp) |
187 | 0 | { |
188 | 0 | if (!stack || !stackp) |
189 | 0 | return FALSE; |
190 | | |
191 | 0 | if (*stackp < 2) |
192 | 0 | return FALSE; |
193 | | |
194 | 0 | (*stackp)--; |
195 | 0 | stack[(*stackp) - 1] &= stack[(*stackp)]; |
196 | 0 | return TRUE; |
197 | 0 | } |
198 | | |
199 | | static BOOL op_or(UINT32* stack, UINT32* stackp) |
200 | 0 | { |
201 | 0 | if (!stack || !stackp) |
202 | 0 | return FALSE; |
203 | | |
204 | 0 | if (*stackp < 2) |
205 | 0 | return FALSE; |
206 | | |
207 | 0 | (*stackp)--; |
208 | 0 | stack[(*stackp) - 1] |= stack[(*stackp)]; |
209 | 0 | return TRUE; |
210 | 0 | } |
211 | | |
212 | | static BOOL op_xor(UINT32* stack, UINT32* stackp) |
213 | 0 | { |
214 | 0 | if (!stack || !stackp) |
215 | 0 | return FALSE; |
216 | | |
217 | 0 | if (*stackp < 2) |
218 | 0 | return FALSE; |
219 | | |
220 | 0 | (*stackp)--; |
221 | 0 | stack[(*stackp) - 1] ^= stack[(*stackp)]; |
222 | 0 | return TRUE; |
223 | 0 | } |
224 | | |
225 | | static UINT32 process_rop(UINT32 src, UINT32 dst, UINT32 pat, const char* rop, UINT32 format) |
226 | 0 | { |
227 | 0 | UINT32 stack[10] = { 0 }; |
228 | 0 | UINT32 stackp = 0; |
229 | |
|
230 | 0 | while (*rop != '\0') |
231 | 0 | { |
232 | 0 | char op = *rop++; |
233 | |
|
234 | 0 | switch (op) |
235 | 0 | { |
236 | 0 | case '0': |
237 | 0 | stack[stackp++] = FreeRDPGetColor(format, 0, 0, 0, 0xFF); |
238 | 0 | break; |
239 | | |
240 | 0 | case '1': |
241 | 0 | stack[stackp++] = FreeRDPGetColor(format, 0xFF, 0xFF, 0xFF, 0xFF); |
242 | 0 | break; |
243 | | |
244 | 0 | case 'D': |
245 | 0 | stack[stackp++] = dst; |
246 | 0 | break; |
247 | | |
248 | 0 | case 'S': |
249 | 0 | stack[stackp++] = src; |
250 | 0 | break; |
251 | | |
252 | 0 | case 'P': |
253 | 0 | stack[stackp++] = pat; |
254 | 0 | break; |
255 | | |
256 | 0 | case 'x': |
257 | 0 | op_xor(stack, &stackp); |
258 | 0 | break; |
259 | | |
260 | 0 | case 'a': |
261 | 0 | op_and(stack, &stackp); |
262 | 0 | break; |
263 | | |
264 | 0 | case 'o': |
265 | 0 | op_or(stack, &stackp); |
266 | 0 | break; |
267 | | |
268 | 0 | case 'n': |
269 | 0 | op_not(stack, &stackp); |
270 | 0 | break; |
271 | | |
272 | 0 | default: |
273 | 0 | break; |
274 | 0 | } |
275 | 0 | } |
276 | | |
277 | 0 | return stack[0]; |
278 | 0 | } |
279 | | |
280 | | static INLINE BOOL BitBlt_write(HGDI_DC hdcDest, HGDI_DC hdcSrc, INT32 nXDest, INT32 nYDest, |
281 | | INT32 nXSrc, INT32 nYSrc, INT32 x, INT32 y, BOOL useSrc, |
282 | | BOOL usePat, UINT32 style, const char* rop, |
283 | | const gdiPalette* palette) |
284 | 0 | { |
285 | 0 | UINT32 dstColor = 0; |
286 | 0 | UINT32 colorA = 0; |
287 | 0 | UINT32 colorB = 0; |
288 | 0 | UINT32 colorC = 0; |
289 | 0 | const INT32 dstX = nXDest + x; |
290 | 0 | const INT32 dstY = nYDest + y; |
291 | 0 | BYTE* dstp = gdi_get_bitmap_pointer(hdcDest, dstX, dstY); |
292 | |
|
293 | 0 | if (!dstp) |
294 | 0 | { |
295 | 0 | WLog_ERR(TAG, "dstp=%p", (const void*)dstp); |
296 | 0 | return FALSE; |
297 | 0 | } |
298 | | |
299 | 0 | colorA = FreeRDPReadColor(dstp, hdcDest->format); |
300 | |
|
301 | 0 | if (useSrc) |
302 | 0 | { |
303 | 0 | const BYTE* srcp = gdi_get_bitmap_pointer(hdcSrc, nXSrc + x, nYSrc + y); |
304 | |
|
305 | 0 | if (!srcp) |
306 | 0 | { |
307 | 0 | WLog_ERR(TAG, "srcp=%p", (const void*)srcp); |
308 | 0 | return FALSE; |
309 | 0 | } |
310 | | |
311 | 0 | colorC = FreeRDPReadColor(srcp, hdcSrc->format); |
312 | 0 | colorC = FreeRDPConvertColor(colorC, hdcSrc->format, hdcDest->format, palette); |
313 | 0 | } |
314 | | |
315 | 0 | if (usePat) |
316 | 0 | { |
317 | 0 | switch (style) |
318 | 0 | { |
319 | 0 | case GDI_BS_SOLID: |
320 | 0 | colorB = hdcDest->brush->color; |
321 | 0 | break; |
322 | | |
323 | 0 | case GDI_BS_HATCHED: |
324 | 0 | case GDI_BS_PATTERN: |
325 | 0 | { |
326 | 0 | const BYTE* patp = gdi_get_brush_pointer(hdcDest, nXDest + x, nYDest + y); |
327 | |
|
328 | 0 | if (!patp) |
329 | 0 | { |
330 | 0 | WLog_ERR(TAG, "patp=%p", (const void*)patp); |
331 | 0 | return FALSE; |
332 | 0 | } |
333 | | |
334 | 0 | colorB = FreeRDPReadColor(patp, hdcDest->format); |
335 | 0 | } |
336 | 0 | break; |
337 | | |
338 | 0 | default: |
339 | 0 | break; |
340 | 0 | } |
341 | 0 | } |
342 | | |
343 | 0 | dstColor = process_rop(colorC, colorA, colorB, rop, hdcDest->format); |
344 | 0 | return FreeRDPWriteColor(dstp, hdcDest->format, dstColor); |
345 | 0 | } |
346 | | |
347 | | static BOOL adjust_src_coordinates(HGDI_DC hdcSrc, INT32 nWidth, INT32 nHeight, INT32* px, |
348 | | INT32* py) |
349 | 0 | { |
350 | 0 | HGDI_BITMAP hSrcBmp = NULL; |
351 | 0 | INT32 nXSrc = 0; |
352 | 0 | INT32 nYSrc = 0; |
353 | |
|
354 | 0 | if (!hdcSrc || (nWidth < 0) || (nHeight < 0) || !px || !py) |
355 | 0 | return FALSE; |
356 | | |
357 | 0 | hSrcBmp = (HGDI_BITMAP)hdcSrc->selectedObject; |
358 | 0 | nXSrc = *px; |
359 | 0 | nYSrc = *py; |
360 | |
|
361 | 0 | if (!hSrcBmp) |
362 | 0 | return FALSE; |
363 | | |
364 | 0 | if (nYSrc < 0) |
365 | 0 | { |
366 | 0 | nYSrc = 0; |
367 | 0 | nHeight = nHeight + nYSrc; |
368 | 0 | } |
369 | |
|
370 | 0 | if ((nXSrc) < 0) |
371 | 0 | { |
372 | 0 | nXSrc = 0; |
373 | 0 | nWidth = nWidth + nXSrc; |
374 | 0 | } |
375 | |
|
376 | 0 | if (hSrcBmp->width < (nXSrc + nWidth)) |
377 | 0 | nXSrc = hSrcBmp->width - nWidth; |
378 | |
|
379 | 0 | if (hSrcBmp->height < (nYSrc + nHeight)) |
380 | 0 | nYSrc = hSrcBmp->height - nHeight; |
381 | |
|
382 | 0 | if ((nXSrc < 0) || (nYSrc < 0)) |
383 | 0 | return FALSE; |
384 | | |
385 | 0 | *px = nXSrc; |
386 | 0 | *py = nYSrc; |
387 | 0 | return TRUE; |
388 | 0 | } |
389 | | |
390 | | static BOOL adjust_src_dst_coordinates(HGDI_DC hdcDest, INT32* pnXSrc, INT32* pnYSrc, INT32* pnXDst, |
391 | | INT32* pnYDst, INT32* pnWidth, INT32* pnHeight) |
392 | 0 | { |
393 | 0 | HGDI_BITMAP hDstBmp = NULL; |
394 | 0 | volatile INT32 diffX = 0; |
395 | 0 | volatile INT32 diffY = 0; |
396 | 0 | volatile INT32 nXSrc = 0; |
397 | 0 | volatile INT32 nYSrc = 0; |
398 | 0 | volatile INT32 nXDst = 0; |
399 | 0 | volatile INT32 nYDst = 0; |
400 | 0 | volatile INT32 nWidth = 0; |
401 | 0 | volatile INT32 nHeight = 0; |
402 | |
|
403 | 0 | if (!hdcDest || !pnXSrc || !pnYSrc || !pnXDst || !pnYDst || !pnWidth || !pnHeight) |
404 | 0 | return FALSE; |
405 | | |
406 | 0 | hDstBmp = (HGDI_BITMAP)hdcDest->selectedObject; |
407 | 0 | nXSrc = *pnXSrc; |
408 | 0 | nYSrc = *pnYSrc; |
409 | 0 | nXDst = *pnXDst; |
410 | 0 | nYDst = *pnYDst; |
411 | 0 | nWidth = *pnWidth; |
412 | 0 | nHeight = *pnHeight; |
413 | |
|
414 | 0 | if (!hDstBmp) |
415 | 0 | return FALSE; |
416 | | |
417 | 0 | if (nXDst < 0) |
418 | 0 | { |
419 | 0 | nXSrc -= nXDst; |
420 | 0 | nWidth += nXDst; |
421 | 0 | nXDst = 0; |
422 | 0 | } |
423 | |
|
424 | 0 | if (nYDst < 0) |
425 | 0 | { |
426 | 0 | nYSrc -= nYDst; |
427 | 0 | nHeight += nYDst; |
428 | 0 | nYDst = 0; |
429 | 0 | } |
430 | |
|
431 | 0 | diffX = hDstBmp->width - nXDst - nWidth; |
432 | |
|
433 | 0 | if (diffX < 0) |
434 | 0 | nWidth += diffX; |
435 | |
|
436 | 0 | diffY = hDstBmp->height - nYDst - nHeight; |
437 | |
|
438 | 0 | if (diffY < 0) |
439 | 0 | nHeight += diffY; |
440 | |
|
441 | 0 | if ((nXDst < 0) || (nYDst < 0) || (nWidth < 0) || (nHeight < 0)) |
442 | 0 | { |
443 | 0 | nXDst = 0; |
444 | 0 | nYDst = 0; |
445 | 0 | nWidth = 0; |
446 | 0 | nHeight = 0; |
447 | 0 | } |
448 | |
|
449 | 0 | *pnXSrc = nXSrc; |
450 | 0 | *pnYSrc = nYSrc; |
451 | 0 | *pnXDst = nXDst; |
452 | 0 | *pnYDst = nYDst; |
453 | 0 | *pnWidth = nWidth; |
454 | 0 | *pnHeight = nHeight; |
455 | 0 | return TRUE; |
456 | 0 | } |
457 | | |
458 | | static BOOL BitBlt_process(HGDI_DC hdcDest, INT32 nXDest, INT32 nYDest, INT32 nWidth, INT32 nHeight, |
459 | | HGDI_DC hdcSrc, INT32 nXSrc, INT32 nYSrc, const char* rop, |
460 | | const gdiPalette* palette) |
461 | 0 | { |
462 | 0 | UINT32 style = 0; |
463 | 0 | BOOL useSrc = FALSE; |
464 | 0 | BOOL usePat = FALSE; |
465 | 0 | const char* iter = rop; |
466 | |
|
467 | 0 | while (*iter != '\0') |
468 | 0 | { |
469 | 0 | switch (*iter++) |
470 | 0 | { |
471 | 0 | case 'P': |
472 | 0 | usePat = TRUE; |
473 | 0 | break; |
474 | | |
475 | 0 | case 'S': |
476 | 0 | useSrc = TRUE; |
477 | 0 | break; |
478 | | |
479 | 0 | default: |
480 | 0 | break; |
481 | 0 | } |
482 | 0 | } |
483 | | |
484 | 0 | if (!hdcDest) |
485 | 0 | return FALSE; |
486 | | |
487 | 0 | if (!adjust_src_dst_coordinates(hdcDest, &nXSrc, &nYSrc, &nXDest, &nYDest, &nWidth, &nHeight)) |
488 | 0 | return FALSE; |
489 | | |
490 | 0 | if (useSrc && !hdcSrc) |
491 | 0 | return FALSE; |
492 | | |
493 | 0 | if (useSrc) |
494 | 0 | { |
495 | 0 | if (!adjust_src_coordinates(hdcSrc, nWidth, nHeight, &nXSrc, &nYSrc)) |
496 | 0 | return FALSE; |
497 | 0 | } |
498 | | |
499 | 0 | if (usePat) |
500 | 0 | { |
501 | 0 | style = gdi_GetBrushStyle(hdcDest); |
502 | |
|
503 | 0 | switch (style) |
504 | 0 | { |
505 | 0 | case GDI_BS_SOLID: |
506 | 0 | case GDI_BS_HATCHED: |
507 | 0 | case GDI_BS_PATTERN: |
508 | 0 | break; |
509 | | |
510 | 0 | default: |
511 | 0 | WLog_ERR(TAG, "Invalid brush!!"); |
512 | 0 | return FALSE; |
513 | 0 | } |
514 | 0 | } |
515 | | |
516 | 0 | if ((nXDest > nXSrc) && (nYDest > nYSrc)) |
517 | 0 | { |
518 | 0 | for (INT32 y = nHeight - 1; y >= 0; y--) |
519 | 0 | { |
520 | 0 | for (INT32 x = nWidth - 1; x >= 0; x--) |
521 | 0 | { |
522 | 0 | if (!BitBlt_write(hdcDest, hdcSrc, nXDest, nYDest, nXSrc, nYSrc, x, y, useSrc, |
523 | 0 | usePat, style, rop, palette)) |
524 | 0 | return FALSE; |
525 | 0 | } |
526 | 0 | } |
527 | 0 | } |
528 | 0 | else if (nXDest > nXSrc) |
529 | 0 | { |
530 | 0 | for (INT32 y = 0; y < nHeight; y++) |
531 | 0 | { |
532 | 0 | for (INT32 x = nWidth - 1; x >= 0; x--) |
533 | 0 | { |
534 | 0 | if (!BitBlt_write(hdcDest, hdcSrc, nXDest, nYDest, nXSrc, nYSrc, x, y, useSrc, |
535 | 0 | usePat, style, rop, palette)) |
536 | 0 | return FALSE; |
537 | 0 | } |
538 | 0 | } |
539 | 0 | } |
540 | 0 | else if (nYDest > nYSrc) |
541 | 0 | { |
542 | 0 | for (INT32 y = nHeight - 1; y >= 0; y--) |
543 | 0 | { |
544 | 0 | for (INT32 x = 0; x < nWidth; x++) |
545 | 0 | { |
546 | 0 | if (!BitBlt_write(hdcDest, hdcSrc, nXDest, nYDest, nXSrc, nYSrc, x, y, useSrc, |
547 | 0 | usePat, style, rop, palette)) |
548 | 0 | return FALSE; |
549 | 0 | } |
550 | 0 | } |
551 | 0 | } |
552 | 0 | else |
553 | 0 | { |
554 | 0 | for (INT32 y = 0; y < nHeight; y++) |
555 | 0 | { |
556 | 0 | for (INT32 x = 0; x < nWidth; x++) |
557 | 0 | { |
558 | 0 | if (!BitBlt_write(hdcDest, hdcSrc, nXDest, nYDest, nXSrc, nYSrc, x, y, useSrc, |
559 | 0 | usePat, style, rop, palette)) |
560 | 0 | return FALSE; |
561 | 0 | } |
562 | 0 | } |
563 | 0 | } |
564 | | |
565 | 0 | return TRUE; |
566 | 0 | } |
567 | | |
568 | | /** |
569 | | * Perform a bit blit operation on the given pixel buffers. |
570 | | * msdn{dd183370} |
571 | | * |
572 | | * @param hdcDest destination device context |
573 | | * @param nXDest destination x1 |
574 | | * @param nYDest destination y1 |
575 | | * @param nWidth width |
576 | | * @param nHeight height |
577 | | * @param hdcSrc source device context |
578 | | * @param nXSrc source x1 |
579 | | * @param nYSrc source y1 |
580 | | * @param rop raster operation code |
581 | | * @return 0 on failure, non-zero otherwise |
582 | | */ |
583 | | BOOL gdi_BitBlt(HGDI_DC hdcDest, INT32 nXDest, INT32 nYDest, INT32 nWidth, INT32 nHeight, |
584 | | HGDI_DC hdcSrc, INT32 nXSrc, INT32 nYSrc, DWORD rop, const gdiPalette* palette) |
585 | 0 | { |
586 | 0 | HGDI_BITMAP hSrcBmp = NULL; |
587 | 0 | HGDI_BITMAP hDstBmp = NULL; |
588 | |
|
589 | 0 | if (!hdcDest) |
590 | 0 | return FALSE; |
591 | | |
592 | 0 | if (!gdi_ClipCoords(hdcDest, &nXDest, &nYDest, &nWidth, &nHeight, &nXSrc, &nYSrc)) |
593 | 0 | return TRUE; |
594 | | |
595 | | /* Check which ROP should be performed. |
596 | | * Some specific ROP are used heavily and are resource intensive, |
597 | | * add optimized versions for these here. |
598 | | * |
599 | | * For all others fall back to the generic implementation. |
600 | | */ |
601 | 0 | switch (rop) |
602 | 0 | { |
603 | 0 | case GDI_SRCCOPY: |
604 | 0 | if (!hdcSrc) |
605 | 0 | return FALSE; |
606 | | |
607 | 0 | if (!adjust_src_dst_coordinates(hdcDest, &nXSrc, &nYSrc, &nXDest, &nYDest, &nWidth, |
608 | 0 | &nHeight)) |
609 | 0 | return FALSE; |
610 | | |
611 | 0 | if (!adjust_src_coordinates(hdcSrc, nWidth, nHeight, &nXSrc, &nYSrc)) |
612 | 0 | return FALSE; |
613 | | |
614 | 0 | hSrcBmp = (HGDI_BITMAP)hdcSrc->selectedObject; |
615 | 0 | hDstBmp = (HGDI_BITMAP)hdcDest->selectedObject; |
616 | |
|
617 | 0 | if (!hSrcBmp || !hDstBmp) |
618 | 0 | return FALSE; |
619 | | |
620 | 0 | if (!freerdp_image_copy(hDstBmp->data, hDstBmp->format, hDstBmp->scanline, nXDest, |
621 | 0 | nYDest, nWidth, nHeight, hSrcBmp->data, hSrcBmp->format, |
622 | 0 | hSrcBmp->scanline, nXSrc, nYSrc, palette, FREERDP_FLIP_NONE)) |
623 | 0 | return FALSE; |
624 | | |
625 | 0 | break; |
626 | | |
627 | 0 | case GDI_DSTCOPY: |
628 | 0 | hSrcBmp = (HGDI_BITMAP)hdcDest->selectedObject; |
629 | 0 | hDstBmp = (HGDI_BITMAP)hdcDest->selectedObject; |
630 | |
|
631 | 0 | if (!adjust_src_dst_coordinates(hdcDest, &nXSrc, &nYSrc, &nXDest, &nYDest, &nWidth, |
632 | 0 | &nHeight)) |
633 | 0 | return FALSE; |
634 | | |
635 | 0 | if (!adjust_src_coordinates(hdcDest, nWidth, nHeight, &nXSrc, &nYSrc)) |
636 | 0 | return FALSE; |
637 | | |
638 | 0 | if (!hSrcBmp || !hDstBmp) |
639 | 0 | return FALSE; |
640 | | |
641 | 0 | if (!freerdp_image_copy(hDstBmp->data, hDstBmp->format, hDstBmp->scanline, nXDest, |
642 | 0 | nYDest, nWidth, nHeight, hSrcBmp->data, hSrcBmp->format, |
643 | 0 | hSrcBmp->scanline, nXSrc, nYSrc, palette, FREERDP_FLIP_NONE)) |
644 | 0 | return FALSE; |
645 | | |
646 | 0 | break; |
647 | | |
648 | 0 | default: |
649 | 0 | if (!BitBlt_process(hdcDest, nXDest, nYDest, nWidth, nHeight, hdcSrc, nXSrc, nYSrc, |
650 | 0 | gdi_rop_to_string(rop), palette)) |
651 | 0 | return FALSE; |
652 | | |
653 | 0 | break; |
654 | 0 | } |
655 | | |
656 | 0 | if (!gdi_InvalidateRegion(hdcDest, nXDest, nYDest, nWidth, nHeight)) |
657 | 0 | return FALSE; |
658 | | |
659 | 0 | return TRUE; |
660 | 0 | } |