FreeRDP
Loading...
Searching...
No Matches
prim_copy.c
1/* FreeRDP: A Remote Desktop Protocol Client
2 * Copy operations.
3 * vi:ts=4 sw=4:
4 *
5 * (c) Copyright 2012 Hewlett-Packard Development Company, L.P.
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may
7 * not use this file except in compliance with the License. You may obtain
8 * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12 * or implied. See the License for the specific language governing
13 * permissions and limitations under the License.
14 */
15
16#include <freerdp/config.h>
17
18#include <string.h>
19#include <freerdp/types.h>
20#include <freerdp/primitives.h>
21#include <freerdp/log.h>
22
23#include "prim_internal.h"
24#include "prim_copy.h"
25#include "../codec/color.h"
26
27#include <freerdp/codec/color.h>
28
29static primitives_t* generic = nullptr;
30
31/* ------------------------------------------------------------------------- */
32/*static inline BOOL memory_regions_overlap_1d(*/
33static BOOL memory_regions_overlap_1d(const BYTE* p1, const BYTE* p2, size_t bytes)
34{
35 const ULONG_PTR p1m = (const ULONG_PTR)p1;
36 const ULONG_PTR p2m = (const ULONG_PTR)p2;
37
38 if (p1m <= p2m)
39 {
40 if (p1m + bytes > p2m)
41 return TRUE;
42 }
43 else
44 {
45 if (p2m + bytes > p1m)
46 return TRUE;
47 }
48
49 /* else */
50 return FALSE;
51}
52
53/* ------------------------------------------------------------------------- */
54/*static inline BOOL memory_regions_overlap_2d( */
55static BOOL memory_regions_overlap_2d(const BYTE* p1, int p1Step, int p1Size, const BYTE* p2,
56 int p2Step, int p2Size, int width, int height)
57{
58 ULONG_PTR p1m = (ULONG_PTR)p1;
59 ULONG_PTR p2m = (ULONG_PTR)p2;
60
61 if (p1m <= p2m)
62 {
63 ULONG_PTR p1mEnd = p1m +
64 1ull * (WINPR_ASSERTING_INT_CAST(uint32_t, height - 1)) *
65 WINPR_ASSERTING_INT_CAST(uint32_t, p1Step) +
66 1ull * WINPR_ASSERTING_INT_CAST(uint32_t, width* p1Size);
67
68 if (p1mEnd > p2m)
69 return TRUE;
70 }
71 else
72 {
73 ULONG_PTR p2mEnd = p2m +
74 1ull * (WINPR_ASSERTING_INT_CAST(uintptr_t, height - 1)) *
75 WINPR_ASSERTING_INT_CAST(uintptr_t, p2Step) +
76 1ull * WINPR_ASSERTING_INT_CAST(uintptr_t, width* p2Size);
77
78 if (p2mEnd > p1m)
79 return TRUE;
80 }
81
82 /* else */
83 return FALSE;
84}
85
86/* ------------------------------------------------------------------------- */
87static pstatus_t general_copy_8u(const BYTE* WINPR_RESTRICT pSrc, BYTE* WINPR_RESTRICT pDst,
88 INT32 len)
89{
90 if (memory_regions_overlap_1d(pSrc, pDst, (size_t)len))
91 {
92 memmove((void*)pDst, (const void*)pSrc, (size_t)len);
93 }
94 else
95 {
96 memcpy((void*)pDst, (const void*)pSrc, (size_t)len);
97 }
98
99 return PRIMITIVES_SUCCESS;
100}
101
102/* ------------------------------------------------------------------------- */
103/* Copy a block of pixels from one buffer to another.
104 * The addresses are assumed to have been already offset to the upper-left
105 * corners of the source and destination region of interest.
106 */
107static pstatus_t general_copy_8u_AC4r(const BYTE* WINPR_RESTRICT pSrc, INT32 srcStep,
108 BYTE* WINPR_RESTRICT pDst, INT32 dstStep, INT32 width,
109 INT32 height)
110{
111 const BYTE* src = pSrc;
112 BYTE* dst = pDst;
113 const size_t rowbytes = WINPR_ASSERTING_INT_CAST(size_t, width) * sizeof(UINT32);
114
115 if ((width == 0) || (height == 0))
116 return PRIMITIVES_SUCCESS;
117
118 if (memory_regions_overlap_2d(pSrc, srcStep, sizeof(UINT32), pDst, dstStep, sizeof(UINT32),
119 width, height))
120 {
121 do
122 {
123 const pstatus_t rc =
124 generic->copy(src, dst, WINPR_ASSERTING_INT_CAST(int32_t, rowbytes));
125 if (rc != PRIMITIVES_SUCCESS)
126 return rc;
127
128 src += srcStep;
129 dst += dstStep;
130 } while (--height);
131 }
132 else
133 {
134 /* TODO: do it in one operation when the rowdata is adjacent. */
135 do
136 {
137 /* If we find a replacement for memcpy that is consistently
138 * faster, this could be replaced with that.
139 */
140 memcpy(dst, src, rowbytes);
141 src += srcStep;
142 dst += dstStep;
143 } while (--height);
144 }
145
146 return PRIMITIVES_SUCCESS;
147}
148
149static inline pstatus_t generic_image_copy_bgr24_bgrx32(BYTE* WINPR_RESTRICT pDstData,
150 UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
151 UINT32 nWidth, UINT32 nHeight,
152 const BYTE* WINPR_RESTRICT pSrcData,
153 UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc,
154 int64_t srcVMultiplier, int64_t srcVOffset,
155 int64_t dstVMultiplier, int64_t dstVOffset)
156{
157
158 const int64_t srcByte = 3;
159 const int64_t dstByte = 4;
160
161 const UINT32 width = nWidth - nWidth % 8;
162
163 for (int64_t y = 0; y < nHeight; y++)
164 {
165 const BYTE* WINPR_RESTRICT srcLine =
166 &pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
167 BYTE* WINPR_RESTRICT dstLine =
168 &pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
169
170 int64_t x = 0;
171 WINPR_PRAGMA_UNROLL_LOOP
172 for (; x < width; x++)
173 {
174 dstLine[(x + nXDst) * dstByte + 0] = srcLine[(x + nXSrc) * srcByte + 0];
175 dstLine[(x + nXDst) * dstByte + 1] = srcLine[(x + nXSrc) * srcByte + 1];
176 dstLine[(x + nXDst) * dstByte + 2] = srcLine[(x + nXSrc) * srcByte + 2];
177 }
178
179 for (; x < nWidth; x++)
180 {
181 dstLine[(x + nXDst) * dstByte + 0] = srcLine[(x + nXSrc) * srcByte + 0];
182 dstLine[(x + nXDst) * dstByte + 1] = srcLine[(x + nXSrc) * srcByte + 1];
183 dstLine[(x + nXDst) * dstByte + 2] = srcLine[(x + nXSrc) * srcByte + 2];
184 }
185 }
186
187 return PRIMITIVES_SUCCESS;
188}
189
190static inline pstatus_t
191generic_image_copy_bgrx32_bgrx32(BYTE* WINPR_RESTRICT pDstData, UINT32 nDstStep, UINT32 nXDst,
192 UINT32 nYDst, UINT32 nWidth, UINT32 nHeight,
193 const BYTE* WINPR_RESTRICT pSrcData, UINT32 nSrcStep, UINT32 nXSrc,
194 UINT32 nYSrc, int64_t srcVMultiplier, int64_t srcVOffset,
195 int64_t dstVMultiplier, int64_t dstVOffset)
196{
197
198 const int64_t srcByte = 4;
199 const int64_t dstByte = 4;
200
201 const UINT32 width = nWidth - nWidth % 8;
202
203 for (int64_t y = 0; y < nHeight; y++)
204 {
205 const BYTE* WINPR_RESTRICT srcLine =
206 &pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
207 BYTE* WINPR_RESTRICT dstLine =
208 &pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
209
210 int64_t x = 0;
211 WINPR_PRAGMA_UNROLL_LOOP
212 for (; x < width; x++)
213 {
214 dstLine[(x + nXDst) * dstByte + 0] = srcLine[(x + nXSrc) * srcByte + 0];
215 dstLine[(x + nXDst) * dstByte + 1] = srcLine[(x + nXSrc) * srcByte + 1];
216 dstLine[(x + nXDst) * dstByte + 2] = srcLine[(x + nXSrc) * srcByte + 2];
217 }
218 for (; x < nWidth; x++)
219 {
220 dstLine[(x + nXDst) * dstByte + 0] = srcLine[(x + nXSrc) * srcByte + 0];
221 dstLine[(x + nXDst) * dstByte + 1] = srcLine[(x + nXSrc) * srcByte + 1];
222 dstLine[(x + nXDst) * dstByte + 2] = srcLine[(x + nXSrc) * srcByte + 2];
223 }
224 }
225
226 return PRIMITIVES_SUCCESS;
227}
228
229static inline pstatus_t generic_image_copy_bgrx32_bgr24(BYTE* WINPR_RESTRICT pDstData,
230 UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
231 UINT32 nWidth, UINT32 nHeight,
232 const BYTE* WINPR_RESTRICT pSrcData,
233 UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc,
234 int64_t srcVMultiplier, int64_t srcVOffset,
235 int64_t dstVMultiplier, int64_t dstVOffset)
236{
237
238 const int64_t srcByte = 4;
239 const int64_t dstByte = 3;
240
241 const UINT32 width = nWidth - nWidth % 8;
242
243 for (int64_t y = 0; y < nHeight; y++)
244 {
245 const BYTE* WINPR_RESTRICT srcLine =
246 &pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
247 BYTE* WINPR_RESTRICT dstLine =
248 &pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
249
250 int64_t x = 0;
251 WINPR_PRAGMA_UNROLL_LOOP
252 for (; x < width; x++)
253 {
254 dstLine[(x + nXDst) * dstByte + 0] = srcLine[(x + nXSrc) * srcByte + 0];
255 dstLine[(x + nXDst) * dstByte + 1] = srcLine[(x + nXSrc) * srcByte + 1];
256 dstLine[(x + nXDst) * dstByte + 2] = srcLine[(x + nXSrc) * srcByte + 2];
257 }
258 for (; x < nWidth; x++)
259 {
260 dstLine[(x + nXDst) * dstByte + 0] = srcLine[(x + nXSrc) * srcByte + 0];
261 dstLine[(x + nXDst) * dstByte + 1] = srcLine[(x + nXSrc) * srcByte + 1];
262 dstLine[(x + nXDst) * dstByte + 2] = srcLine[(x + nXSrc) * srcByte + 2];
263 }
264 }
265
266 return PRIMITIVES_SUCCESS;
267}
268
269static inline pstatus_t generic_image_copy_bgrx32_rgb24(BYTE* WINPR_RESTRICT pDstData,
270 UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
271 UINT32 nWidth, UINT32 nHeight,
272 const BYTE* WINPR_RESTRICT pSrcData,
273 UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc,
274 int64_t srcVMultiplier, int64_t srcVOffset,
275 int64_t dstVMultiplier, int64_t dstVOffset)
276{
277
278 const int64_t srcByte = 4;
279 const int64_t dstByte = 3;
280
281 const UINT32 width = nWidth - nWidth % 8;
282
283 for (int64_t y = 0; y < nHeight; y++)
284 {
285 const BYTE* WINPR_RESTRICT srcLine =
286 &pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
287 BYTE* WINPR_RESTRICT dstLine =
288 &pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
289
290 int64_t x = 0;
291 WINPR_PRAGMA_UNROLL_LOOP
292 for (; x < width; x++)
293 {
294 dstLine[(x + nXDst) * dstByte + 0] = srcLine[(x + nXSrc) * srcByte + 2];
295 dstLine[(x + nXDst) * dstByte + 1] = srcLine[(x + nXSrc) * srcByte + 1];
296 dstLine[(x + nXDst) * dstByte + 2] = srcLine[(x + nXSrc) * srcByte + 0];
297 }
298 for (; x < nWidth; x++)
299 {
300 dstLine[(x + nXDst) * dstByte + 0] = srcLine[(x + nXSrc) * srcByte + 2];
301 dstLine[(x + nXDst) * dstByte + 1] = srcLine[(x + nXSrc) * srcByte + 1];
302 dstLine[(x + nXDst) * dstByte + 2] = srcLine[(x + nXSrc) * srcByte + 0];
303 }
304 }
305
306 return PRIMITIVES_SUCCESS;
307}
308
309pstatus_t generic_image_copy_no_overlap_convert(
310 BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
311 UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat,
312 UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette,
313 int64_t srcVMultiplier, int64_t srcVOffset, int64_t dstVMultiplier, int64_t dstVOffset)
314{
315 const int64_t srcByte = FreeRDPGetBytesPerPixel(SrcFormat);
316 const int64_t dstByte = FreeRDPGetBytesPerPixel(DstFormat);
317
318 const UINT32 width = nWidth - nWidth % 8;
319 for (int64_t y = 0; y < nHeight; y++)
320 {
321 const BYTE* WINPR_RESTRICT srcLine =
322 &pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
323 BYTE* WINPR_RESTRICT dstLine =
324 &pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
325
326 int64_t x = 0;
327 // WINPR_PRAGMA_UNROLL_LOOP
328 for (; x < width; x++)
329 {
330 const UINT32 color = FreeRDPReadColor_int(&srcLine[(x + nXSrc) * srcByte], SrcFormat);
331 const UINT32 dstColor = FreeRDPConvertColor(color, SrcFormat, DstFormat, palette);
332 if (!FreeRDPWriteColor_int(&dstLine[(x + nXDst) * dstByte], DstFormat, dstColor))
333 return -1;
334 }
335 for (; x < nWidth; x++)
336 {
337 const UINT32 color = FreeRDPReadColor_int(&srcLine[(x + nXSrc) * srcByte], SrcFormat);
338 const UINT32 dstColor = FreeRDPConvertColor(color, SrcFormat, DstFormat, palette);
339 if (!FreeRDPWriteColor_int(&dstLine[(x + nXDst) * dstByte], DstFormat, dstColor))
340 return -1;
341 }
342 }
343 return PRIMITIVES_SUCCESS;
344}
345
346pstatus_t generic_image_copy_no_overlap_memcpy(
347 BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
348 UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat,
349 UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc,
350 WINPR_ATTR_UNUSED const gdiPalette* WINPR_RESTRICT palette, int64_t srcVMultiplier,
351 int64_t srcVOffset, int64_t dstVMultiplier, int64_t dstVOffset, WINPR_ATTR_UNUSED UINT32 flags)
352{
353 const int64_t dstByte = FreeRDPGetBytesPerPixel(DstFormat);
354 const int64_t srcByte = FreeRDPGetBytesPerPixel(SrcFormat);
355 const int64_t copyDstWidth = nWidth * dstByte;
356 const int64_t xSrcOffset = nXSrc * srcByte;
357 const int64_t xDstOffset = nXDst * dstByte;
358
359 for (int64_t y = 0; y < nHeight; y++)
360 {
361 const BYTE* WINPR_RESTRICT srcLine =
362 &pSrcData[srcVMultiplier * (y + nYSrc) * nSrcStep + srcVOffset];
363 BYTE* WINPR_RESTRICT dstLine =
364 &pDstData[dstVMultiplier * (y + nYDst) * nDstStep + dstVOffset];
365 memcpy(&dstLine[xDstOffset], &srcLine[xSrcOffset],
366 WINPR_ASSERTING_INT_CAST(size_t, copyDstWidth));
367 }
368
369 return PRIMITIVES_SUCCESS;
370}
371
372static inline pstatus_t generic_image_copy_no_overlap_dst_alpha(
373 BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
374 UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat,
375 UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette,
376 int64_t srcVMultiplier, int64_t srcVOffset, int64_t dstVMultiplier, int64_t dstVOffset)
377{
378 WINPR_ASSERT(pDstData);
379 WINPR_ASSERT(pSrcData);
380
381 switch (SrcFormat)
382 {
383 case PIXEL_FORMAT_BGR24:
384 switch (DstFormat)
385 {
386 case PIXEL_FORMAT_BGRA32:
387 return generic_image_copy_bgr24_bgrx32(
388 pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, nSrcStep,
389 nXSrc, nYSrc, srcVMultiplier, srcVOffset, dstVMultiplier, dstVOffset);
390 default:
391 break;
392 }
393 break;
394 case PIXEL_FORMAT_BGRX32:
395 case PIXEL_FORMAT_BGRA32:
396 switch (DstFormat)
397 {
398 case PIXEL_FORMAT_BGRA32:
399 return generic_image_copy_bgrx32_bgrx32(
400 pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, nSrcStep,
401 nXSrc, nYSrc, srcVMultiplier, srcVOffset, dstVMultiplier, dstVOffset);
402 default:
403 break;
404 }
405 break;
406 case PIXEL_FORMAT_RGBX32:
407 case PIXEL_FORMAT_RGBA32:
408 switch (DstFormat)
409 {
410 case PIXEL_FORMAT_RGBA32:
411 return generic_image_copy_bgrx32_bgrx32(
412 pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, nSrcStep,
413 nXSrc, nYSrc, srcVMultiplier, srcVOffset, dstVMultiplier, dstVOffset);
414 default:
415 break;
416 }
417 break;
418 default:
419 break;
420 }
421
422 return generic_image_copy_no_overlap_convert(
423 pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, SrcFormat, nSrcStep,
424 nXSrc, nYSrc, palette, srcVMultiplier, srcVOffset, dstVMultiplier, dstVOffset);
425}
426
427static inline pstatus_t generic_image_copy_no_overlap_no_alpha(
428 BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat, UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
429 UINT32 nWidth, UINT32 nHeight, const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat,
430 UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc, const gdiPalette* WINPR_RESTRICT palette,
431 int64_t srcVMultiplier, int64_t srcVOffset, int64_t dstVMultiplier, int64_t dstVOffset,
432 UINT32 flags)
433{
434 if (FreeRDPAreColorFormatsEqualNoAlpha(SrcFormat, DstFormat))
435 return generic_image_copy_no_overlap_memcpy(pDstData, DstFormat, nDstStep, nXDst, nYDst,
436 nWidth, nHeight, pSrcData, SrcFormat, nSrcStep,
437 nXSrc, nYSrc, palette, srcVMultiplier,
438 srcVOffset, dstVMultiplier, dstVOffset, flags);
439
440 switch (SrcFormat)
441 {
442 case PIXEL_FORMAT_BGRX32:
443 case PIXEL_FORMAT_BGRA32:
444 switch (DstFormat)
445 {
446 case PIXEL_FORMAT_BGR24:
447 return generic_image_copy_bgrx32_bgr24(
448 pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, nSrcStep,
449 nXSrc, nYSrc, srcVMultiplier, srcVOffset, dstVMultiplier, dstVOffset);
450 case PIXEL_FORMAT_RGB24:
451 return generic_image_copy_bgrx32_rgb24(
452 pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, nSrcStep,
453 nXSrc, nYSrc, srcVMultiplier, srcVOffset, dstVMultiplier, dstVOffset);
454 default:
455 break;
456 }
457 break;
458 case PIXEL_FORMAT_RGBX32:
459 case PIXEL_FORMAT_RGBA32:
460 switch (DstFormat)
461 {
462 case PIXEL_FORMAT_RGB24:
463 return generic_image_copy_bgrx32_bgr24(
464 pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, nSrcStep,
465 nXSrc, nYSrc, srcVMultiplier, srcVOffset, dstVMultiplier, dstVOffset);
466 case PIXEL_FORMAT_BGR24:
467 return generic_image_copy_bgrx32_rgb24(
468 pDstData, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, nSrcStep,
469 nXSrc, nYSrc, srcVMultiplier, srcVOffset, dstVMultiplier, dstVOffset);
470 default:
471 break;
472 }
473 break;
474 default:
475 break;
476 }
477
478 return generic_image_copy_no_overlap_convert(
479 pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, SrcFormat, nSrcStep,
480 nXSrc, nYSrc, palette, srcVMultiplier, srcVOffset, dstVMultiplier, dstVOffset);
481}
482
483static pstatus_t generic_image_copy_no_overlap(BYTE* WINPR_RESTRICT pDstData, DWORD DstFormat,
484 UINT32 nDstStep, UINT32 nXDst, UINT32 nYDst,
485 UINT32 nWidth, UINT32 nHeight,
486 const BYTE* WINPR_RESTRICT pSrcData, DWORD SrcFormat,
487 UINT32 nSrcStep, UINT32 nXSrc, UINT32 nYSrc,
488 const gdiPalette* WINPR_RESTRICT palette,
489 UINT32 flags)
490{
491 const BOOL vSrcVFlip = (flags & FREERDP_FLIP_VERTICAL) != 0;
492 int64_t srcVOffset = 0;
493 int64_t srcVMultiplier = 1;
494 int64_t dstVOffset = 0;
495 int64_t dstVMultiplier = 1;
496
497 if ((nWidth == 0) || (nHeight == 0))
498 return PRIMITIVES_SUCCESS;
499
500 if ((nHeight > INT32_MAX) || (nWidth > INT32_MAX))
501 return -1;
502
503 if (!pDstData || !pSrcData)
504 return -1;
505
506 if (nDstStep == 0)
507 nDstStep = nWidth * FreeRDPGetBytesPerPixel(DstFormat);
508
509 if (nSrcStep == 0)
510 nSrcStep = nWidth * FreeRDPGetBytesPerPixel(SrcFormat);
511
512 if (vSrcVFlip)
513 {
514 srcVOffset = (nHeight - 1ll) * nSrcStep;
515 srcVMultiplier = -1;
516 }
517
518 if (((flags & FREERDP_KEEP_DST_ALPHA) != 0) && FreeRDPColorHasAlpha(DstFormat))
519 return generic_image_copy_no_overlap_dst_alpha(
520 pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, SrcFormat,
521 nSrcStep, nXSrc, nYSrc, palette, srcVMultiplier, srcVOffset, dstVMultiplier,
522 dstVOffset);
523 else
524 return generic_image_copy_no_overlap_no_alpha(
525 pDstData, DstFormat, nDstStep, nXDst, nYDst, nWidth, nHeight, pSrcData, SrcFormat,
526 nSrcStep, nXSrc, nYSrc, palette, srcVMultiplier, srcVOffset, dstVMultiplier, dstVOffset,
527 flags);
528
529 return PRIMITIVES_SUCCESS;
530}
531
532/* ------------------------------------------------------------------------- */
533void primitives_init_copy(primitives_t* WINPR_RESTRICT prims)
534{
535 /* Start with the default. */
536 prims->copy_8u = general_copy_8u;
537 prims->copy_8u_AC4r = general_copy_8u_AC4r;
538 prims->copy = WINPR_FUNC_PTR_CAST(prims->copy_8u, fn_copy_t);
539 prims->copy_no_overlap = generic_image_copy_no_overlap;
540}
541
542void primitives_init_copy_opt(primitives_t* WINPR_RESTRICT prims)
543{
544 primitives_init_copy(prims);
545 primitives_init_copy_sse41(prims);
546#if defined(WITH_AVX2)
547 primitives_init_copy_avx2(prims);
548#endif
549}