24#include <winpr/wtypes.h>
25#include <winpr/assert.h>
26#include <winpr/cast.h>
28#include <freerdp/config.h>
30#include <freerdp/types.h>
31#include <freerdp/primitives.h>
32#include <freerdp/codec/color.h>
33#include "prim_internal.h"
36static inline pstatus_t general_LumaToYUV444(
const BYTE* WINPR_RESTRICT pSrcRaw[3],
37 const UINT32 srcStep[3],
38 BYTE* WINPR_RESTRICT pDstRaw[3],
39 const UINT32 dstStep[3],
42 const UINT32 nWidth = roi->right - roi->left;
43 const UINT32 nHeight = roi->bottom - roi->top;
44 const UINT32 halfWidth = (nWidth + 1) / 2;
45 const UINT32 halfHeight = (nHeight + 1) / 2;
46 const UINT32 oddY = 1;
47 const UINT32 evenY = 0;
48 const UINT32 oddX = 1;
49 const UINT32 evenX = 0;
50 const BYTE* pSrc[3] = { pSrcRaw[0] + 1ULL * roi->top * srcStep[0] + roi->left,
51 pSrcRaw[1] + 1ULL * roi->top / 2 * srcStep[1] + roi->left / 2,
52 pSrcRaw[2] + 1ULL * roi->top / 2 * srcStep[2] + roi->left / 2 };
53 BYTE* pDst[3] = { pDstRaw[0] + 1ULL * roi->top * dstStep[0] + roi->left,
54 pDstRaw[1] + 1ULL * roi->top * dstStep[1] + roi->left,
55 pDstRaw[2] + 1ULL * roi->top * dstStep[2] + roi->left };
59 for (
size_t y = 0; y < nHeight; y++)
61 const BYTE* Ym = pSrc[0] + y * srcStep[0];
62 BYTE* pY = pDst[0] + dstStep[0] * y;
63 memcpy(pY, Ym, nWidth);
68 for (UINT32 y = 0; y < halfHeight; y++)
70 const UINT32 val2y = (2UL * y + evenY);
71 const UINT32 val2y1 = val2y + oddY;
72 const BYTE* Um = pSrc[1] + 1ULL * y * srcStep[1];
73 const BYTE* Vm = pSrc[2] + 1ULL * y * srcStep[2];
74 BYTE* pU = pDst[1] + 1ULL * dstStep[1] * val2y;
75 BYTE* pV = pDst[2] + 1ULL * dstStep[2] * val2y;
76 BYTE* pU1 = pDst[1] + 1ULL * dstStep[1] * val2y1;
77 BYTE* pV1 = pDst[2] + 1ULL * dstStep[2] * val2y1;
79 for (UINT32 x = 0; x < halfWidth; x++)
81 const UINT32 val2x = 2UL * x + evenX;
82 const UINT32 val2x1 = val2x + oddX;
94 return PRIMITIVES_SUCCESS;
97static inline pstatus_t general_ChromaV1ToYUV444(
const BYTE* WINPR_RESTRICT pSrcRaw[3],
98 const UINT32 srcStep[3],
99 BYTE* WINPR_RESTRICT pDstRaw[3],
100 const UINT32 dstStep[3],
103 const UINT32 mod = 16;
106 const UINT32 nWidth = roi->right - roi->left;
107 const UINT32 nHeight = roi->bottom - roi->top;
108 const UINT32 halfWidth = (nWidth) / 2;
109 const UINT32 halfHeight = (nHeight) / 2;
110 const UINT32 oddY = 1;
111 const UINT32 evenY = 0;
112 const UINT32 oddX = 1;
115 const UINT32 padHeigth = nHeight + 16 - nHeight % 16;
116 const BYTE* pSrc[3] = { pSrcRaw[0] + 1ULL * roi->top * srcStep[0] + roi->left,
117 pSrcRaw[1] + 1ULL * roi->top / 2 * srcStep[1] + roi->left / 2,
118 pSrcRaw[2] + 1ULL * roi->top / 2 * srcStep[2] + roi->left / 2 };
119 BYTE* pDst[3] = { pDstRaw[0] + 1ULL * roi->top * dstStep[0] + roi->left,
120 pDstRaw[1] + 1ULL * roi->top * dstStep[1] + roi->left,
121 pDstRaw[2] + 1ULL * roi->top * dstStep[2] + roi->left };
125 for (
size_t y = 0; y < padHeigth; y++)
127 const BYTE* Ya = pSrc[0] + y * srcStep[0];
130 if ((y) % mod < (mod + 1) / 2)
132 const size_t pos = (2 * uY++ + oddY);
137 pX = pDst[1] + dstStep[1] * pos;
141 const size_t pos = (2 * vY++ + oddY);
146 pX = pDst[2] + dstStep[2] * pos;
149 memcpy(pX, Ya, nWidth);
153 for (UINT32 y = 0; y < halfHeight; y++)
155 const UINT32 val2y = (y * 2UL + evenY);
156 const BYTE* Ua = pSrc[1] + 1ULL * y * srcStep[1];
157 const BYTE* Va = pSrc[2] + 1ULL * y * srcStep[2];
158 BYTE* pU = pDst[1] + 1ULL * dstStep[1] * val2y;
159 BYTE* pV = pDst[2] + 1ULL * dstStep[2] * val2y;
161 for (UINT32 x = 0; x < halfWidth; x++)
163 const UINT32 val2x1 = (x * 2 + oddX);
169 return PRIMITIVES_SUCCESS;
172static inline pstatus_t general_ChromaV2ToYUV444(
const BYTE* WINPR_RESTRICT pSrc[3],
173 const UINT32 srcStep[3], UINT32 nTotalWidth,
174 WINPR_ATTR_UNUSED UINT32 nTotalHeight,
175 BYTE* WINPR_RESTRICT pDst[3],
176 const UINT32 dstStep[3],
179 const UINT32 nWidth = roi->right - roi->left;
180 const UINT32 nHeight = roi->bottom - roi->top;
181 const UINT32 halfWidth = (nWidth + 1) / 2;
182 const UINT32 halfHeight = (nHeight + 1) / 2;
183 const UINT32 quaterWidth = (nWidth + 3) / 4;
186 for (UINT32 y = 0; y < nHeight; y++)
188 const UINT32 yTop = y + roi->top;
189 const BYTE* pYaU = pSrc[0] + 1ULL * srcStep[0] * yTop + roi->left / 2;
190 const BYTE* pYaV = pYaU + nTotalWidth / 2;
191 BYTE* pU = pDst[1] + 1ULL * dstStep[1] * yTop + roi->left;
192 BYTE* pV = pDst[2] + 1ULL * dstStep[2] * yTop + roi->left;
194 for (UINT32 x = 0; x < halfWidth; x++)
196 const UINT32 odd = 2UL * x + 1UL;
203 for (
size_t y = 0; y < halfHeight; y++)
205 const BYTE* pUaU = pSrc[1] + srcStep[1] * (y + roi->top / 2) + roi->left / 4;
206 const BYTE* pUaV = pUaU + nTotalWidth / 4;
207 const BYTE* pVaU = pSrc[2] + srcStep[2] * (y + roi->top / 2) + roi->left / 4;
208 const BYTE* pVaV = pVaU + nTotalWidth / 4;
209 BYTE* pU = pDst[1] + 1ULL * dstStep[1] * (2ULL * y + 1 + roi->top) + roi->left;
210 BYTE* pV = pDst[2] + 1ULL * dstStep[2] * (2ULL * y + 1 + roi->top) + roi->left;
212 for (
size_t x = 0; x < quaterWidth; x++)
214 pU[4 * x + 0] = *pUaU++;
215 pV[4 * x + 0] = *pUaV++;
216 pU[4 * x + 2] = *pVaU++;
217 pV[4 * x + 2] = *pVaV++;
221 return PRIMITIVES_SUCCESS;
224static pstatus_t general_YUV420CombineToYUV444(avc444_frame_type type,
225 const BYTE* WINPR_RESTRICT pSrc[3],
226 const UINT32 srcStep[3], UINT32 nWidth,
227 UINT32 nHeight, BYTE* WINPR_RESTRICT pDst[3],
228 const UINT32 dstStep[3],
231 if (!pSrc || !pSrc[0] || !pSrc[1] || !pSrc[2])
234 if (!pDst || !pDst[0] || !pDst[1] || !pDst[2])
243 return general_LumaToYUV444(pSrc, srcStep, pDst, dstStep, roi);
245 case AVC444_CHROMAv1:
246 return general_ChromaV1ToYUV444(pSrc, srcStep, pDst, dstStep, roi);
248 case AVC444_CHROMAv2:
249 return general_ChromaV2ToYUV444(pSrc, srcStep, nWidth, nHeight, pDst, dstStep, roi);
257general_YUV444SplitToYUV420(
const BYTE* WINPR_RESTRICT pSrc[3],
const UINT32 srcStep[3],
258 BYTE* WINPR_RESTRICT pMainDst[3],
const UINT32 dstMainStep[3],
259 BYTE* WINPR_RESTRICT pAuxDst[3],
const UINT32 dstAuxStep[3],
267 const UINT32 padHeigth = roi->height + 16 - roi->height % 16;
268 const UINT32 halfWidth = (roi->width + 1) / 2;
269 const UINT32 halfHeight = (roi->height + 1) / 2;
272 for (
size_t y = 0; y < roi->height; y++)
274 const BYTE* pSrcY = pSrc[0] + y * srcStep[0];
275 BYTE* pY = pMainDst[0] + y * dstMainStep[0];
276 memcpy(pY, pSrcY, roi->width);
280 for (
size_t y = 0; y < halfHeight; y++)
282 const BYTE* pSrcU = pSrc[1] + 2ULL * y * srcStep[1];
283 const BYTE* pSrcV = pSrc[2] + 2ULL * y * srcStep[2];
284 BYTE* pU = pMainDst[1] + y * dstMainStep[1];
285 BYTE* pV = pMainDst[2] + y * dstMainStep[2];
287 for (
size_t x = 0; x < halfWidth; x++)
289 pU[x] = pSrcV[2 * x];
290 pV[x] = pSrcU[2 * x];
295 for (
size_t y = 0; y < padHeigth; y++)
297 BYTE* pY = pAuxDst[0] + y * dstAuxStep[0];
301 const size_t pos = (2 * uY++ + 1);
302 const BYTE* pSrcU = pSrc[1] + pos * srcStep[1];
304 if (pos >= roi->height)
307 memcpy(pY, pSrcU, roi->width);
311 const size_t pos = (2 * vY++ + 1);
312 const BYTE* pSrcV = pSrc[2] + pos * srcStep[2];
314 if (pos >= roi->height)
317 memcpy(pY, pSrcV, roi->width);
322 for (
size_t y = 0; y < halfHeight; y++)
324 const BYTE* pSrcU = pSrc[1] + 2 * y * srcStep[1];
325 const BYTE* pSrcV = pSrc[2] + 2 * y * srcStep[2];
326 BYTE* pU = pAuxDst[1] + y * dstAuxStep[1];
327 BYTE* pV = pAuxDst[2] + y * dstAuxStep[2];
329 for (
size_t x = 0; x < halfWidth; x++)
331 pU[x] = pSrcU[2 * x + 1];
332 pV[x] = pSrcV[2 * x + 1];
336 return PRIMITIVES_SUCCESS;
339static inline void general_YUV444ToRGB_DOUBLE_ROW(BYTE* WINPR_RESTRICT pRGB[2], UINT32 DstFormat,
340 const BYTE* WINPR_RESTRICT pY[2],
341 const BYTE* WINPR_RESTRICT pU[2],
342 const BYTE* WINPR_RESTRICT pV[2],
size_t nWidth)
344 fkt_writePixel writePixel = getPixelWriteFunction(DstFormat, FALSE);
346 WINPR_ASSERT(nWidth % 2 == 0);
347 for (
size_t x = 0; x < nWidth; x += 2)
349 for (
size_t i = 0; i < 2; i++)
351 for (
size_t j = 0; j < 2; j++)
353 const BYTE y = pY[i][x + j];
354 INT32 u = pU[i][x + j];
355 INT32 v = pV[i][x + j];
356 if ((i == 0) && (j == 0))
358 const INT32 subU = (INT32)pU[0][x + 1] + pU[1][x] + pU[1][x + 1];
359 const INT32 avgU = ((4 * u) - subU);
360 u = CONDITIONAL_CLIP(avgU, WINPR_ASSERTING_INT_CAST(BYTE, u));
362 const INT32 subV = (INT32)pV[0][x + 1] + pV[1][x] + pV[1][x + 1];
363 const INT32 avgV = ((4 * v) - subV);
364 v = CONDITIONAL_CLIP(avgV, WINPR_ASSERTING_INT_CAST(BYTE, v));
366 pRGB[i] = writeYUVPixel(pRGB[i], DstFormat, y, u, v, writePixel);
372static inline void general_YUV444ToRGB_SINGLE_ROW(BYTE* WINPR_RESTRICT pRGB, UINT32 DstFormat,
373 const BYTE* WINPR_RESTRICT pY,
374 const BYTE* WINPR_RESTRICT pU,
375 const BYTE* WINPR_RESTRICT pV,
size_t nWidth)
377 fkt_writePixel writePixel = getPixelWriteFunction(DstFormat, FALSE);
379 WINPR_ASSERT(nWidth % 2 == 0);
380 for (
size_t x = 0; x < nWidth; x += 2)
382 for (
size_t j = 0; j < 2; j++)
384 const BYTE y = pY[x + j];
385 const BYTE u = pU[x + j];
386 const BYTE v = pV[x + j];
387 pRGB = writeYUVPixel(pRGB, DstFormat, y, u, v, writePixel);
392static inline pstatus_t general_YUV444ToRGB_8u_P3AC4R_general(
const BYTE* WINPR_RESTRICT pSrc[3],
393 const UINT32 srcStep[3],
394 BYTE* WINPR_RESTRICT pDst,
395 UINT32 dstStep, UINT32 DstFormat,
402 const UINT32 nWidth = roi->width;
403 const UINT32 nHeight = roi->height;
406 for (; y < nHeight - nHeight % 2; y += 2)
408 const BYTE* WINPR_RESTRICT pY[2] = { pSrc[0] + y * srcStep[0],
409 pSrc[0] + (y + 1) * srcStep[0] };
410 const BYTE* WINPR_RESTRICT pU[2] = { pSrc[1] + y * srcStep[1],
411 pSrc[1] + (y + 1) * srcStep[1] };
412 const BYTE* WINPR_RESTRICT pV[2] = { pSrc[2] + y * srcStep[2],
413 pSrc[2] + (y + 1) * srcStep[2] };
414 BYTE* WINPR_RESTRICT pRGB[] = { pDst + y * dstStep, pDst + (y + 1) * dstStep };
416 general_YUV444ToRGB_DOUBLE_ROW(pRGB, DstFormat, pY, pU, pV, nWidth);
418 for (; y < nHeight; y++)
420 const BYTE* WINPR_RESTRICT pY = pSrc[0] + y * srcStep[0];
421 const BYTE* WINPR_RESTRICT pU = pSrc[1] + y * srcStep[1];
422 const BYTE* WINPR_RESTRICT pV = pSrc[2] + y * srcStep[2];
423 BYTE* WINPR_RESTRICT pRGB = pDst + y * dstStep;
425 general_YUV444ToRGB_SINGLE_ROW(pRGB, DstFormat, pY, pU, pV, nWidth);
428 return PRIMITIVES_SUCCESS;
431static inline void general_YUV444ToBGRX_DOUBLE_ROW(BYTE* WINPR_RESTRICT pRGB[2], UINT32 DstFormat,
432 const BYTE* WINPR_RESTRICT pY[2],
433 const BYTE* WINPR_RESTRICT pU[2],
434 const BYTE* WINPR_RESTRICT pV[2],
size_t nWidth)
436 WINPR_ASSERT(nWidth % 2 == 0);
437 for (
size_t x = 0; x < nWidth; x += 2)
439 const INT32 subU = pU[0][x + 1] + pU[1][x] + pU[1][x + 1];
440 const INT32 avgU = ((4 * pU[0][x]) - subU);
441 const BYTE useU = CONDITIONAL_CLIP(avgU, pU[0][x]);
442 const INT32 subV = pV[0][x + 1] + pV[1][x] + pV[1][x + 1];
443 const INT32 avgV = ((4 * pV[0][x]) - subV);
444 const BYTE useV = CONDITIONAL_CLIP(avgV, pV[0][x]);
446 const BYTE U[2][2] = { { useU, pU[0][x + 1] }, { pU[1][x], pU[1][x + 1] } };
447 const BYTE V[2][2] = { { useV, pV[0][x + 1] }, { pV[1][x], pV[1][x + 1] } };
449 for (
size_t i = 0; i < 2; i++)
451 for (
size_t j = 0; j < 2; j++)
453 const BYTE y = pY[i][x + j];
454 const BYTE u = U[i][j];
455 const BYTE v = V[i][j];
456 pRGB[i] = writeYUVPixel(pRGB[i], DstFormat, y, u, v, writePixelBGRX);
462static inline void general_YUV444ToBGRX_SINGLE_ROW(BYTE* WINPR_RESTRICT pRGB, UINT32 DstFormat,
463 const BYTE* WINPR_RESTRICT pY,
464 const BYTE* WINPR_RESTRICT pU,
465 const BYTE* WINPR_RESTRICT pV,
size_t nWidth)
467 WINPR_ASSERT(nWidth % 2 == 0);
468 for (
size_t x = 0; x < nWidth; x += 2)
470 for (
size_t j = 0; j < 2; j++)
472 const BYTE Y = pY[x + j];
473 const BYTE U = pU[x + j];
474 const BYTE V = pV[x + j];
475 pRGB = writeYUVPixel(pRGB, DstFormat, Y, U, V, writePixelBGRX);
480static inline pstatus_t general_YUV444ToRGB_8u_P3AC4R_BGRX(
const BYTE* WINPR_RESTRICT pSrc[3],
481 const UINT32 srcStep[3],
482 BYTE* WINPR_RESTRICT pDst,
483 UINT32 dstStep, UINT32 DstFormat,
490 const UINT32 nWidth = roi->width;
491 const UINT32 nHeight = roi->height;
494 for (; y < nHeight - nHeight % 2; y += 2)
496 const BYTE* pY[2] = { pSrc[0] + y * srcStep[0], pSrc[0] + (y + 1) * srcStep[0] };
497 const BYTE* pU[2] = { pSrc[1] + y * srcStep[1], pSrc[1] + (y + 1) * srcStep[1] };
498 const BYTE* pV[2] = { pSrc[2] + y * srcStep[2], pSrc[2] + (y + 1) * srcStep[2] };
499 BYTE* pRGB[] = { pDst + y * dstStep, pDst + (y + 1) * dstStep };
501 general_YUV444ToBGRX_DOUBLE_ROW(pRGB, DstFormat, pY, pU, pV, nWidth);
504 for (; y < nHeight; y++)
506 const BYTE* WINPR_RESTRICT pY = pSrc[0] + y * srcStep[0];
507 const BYTE* WINPR_RESTRICT pU = pSrc[1] + y * srcStep[1];
508 const BYTE* WINPR_RESTRICT pV = pSrc[2] + y * srcStep[2];
509 BYTE* WINPR_RESTRICT pRGB = pDst + y * dstStep;
511 general_YUV444ToBGRX_SINGLE_ROW(pRGB, DstFormat, pY, pU, pV, nWidth);
513 return PRIMITIVES_SUCCESS;
516static pstatus_t general_YUV444ToRGB_8u_P3AC4R(
const BYTE* WINPR_RESTRICT pSrc[3],
517 const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pDst,
518 UINT32 dstStep, UINT32 DstFormat,
523 case PIXEL_FORMAT_BGRA32:
524 case PIXEL_FORMAT_BGRX32:
525 return general_YUV444ToRGB_8u_P3AC4R_BGRX(pSrc, srcStep, pDst, dstStep, DstFormat, roi);
528 return general_YUV444ToRGB_8u_P3AC4R_general(pSrc, srcStep, pDst, dstStep, DstFormat,
537static void general_YUV420ToRGB_8u_P3AC4R_double_line(BYTE* WINPR_RESTRICT pEven,
538 BYTE* WINPR_RESTRICT pOdd, UINT32 DstFormat,
539 const BYTE* WINPR_RESTRICT pYeven,
540 const BYTE* WINPR_RESTRICT pYodd,
541 const BYTE* WINPR_RESTRICT pU,
542 const BYTE* WINPR_RESTRICT pV, UINT32 width,
543 fkt_writePixel writePixel, UINT32 formatSize)
547 for (; x < width / 2; x++)
549 const BYTE U = pU[x];
550 const BYTE V = pV[x];
551 const BYTE eY0 = pYeven[2ULL * x + 0];
552 const BYTE eY1 = pYeven[2ULL * x + 1];
553 writeYUVPixel(&pEven[2ULL * x * formatSize], DstFormat, eY0, U, V, writePixel);
554 writeYUVPixel(&pEven[(2ULL * x + 1) * formatSize], DstFormat, eY1, U, V, writePixel);
556 const BYTE oY0 = pYodd[2ULL * x + 0];
557 const BYTE oY1 = pYodd[2ULL * x + 1];
558 writeYUVPixel(&pOdd[2ULL * x * formatSize], DstFormat, oY0, U, V, writePixel);
559 writeYUVPixel(&pOdd[(2ULL * x + 1) * formatSize], DstFormat, oY1, U, V, writePixel);
562 for (; x < (width + 1) / 2; x++)
564 const BYTE U = pU[x];
565 const BYTE V = pV[x];
566 const BYTE eY0 = pYeven[2ULL * x + 0];
567 writeYUVPixel(&pEven[2ULL * x * formatSize], DstFormat, eY0, U, V, writePixel);
569 const BYTE oY0 = pYodd[2ULL * x + 0];
570 writeYUVPixel(&pOdd[2ULL * x * formatSize], DstFormat, oY0, U, V, writePixel);
574static void general_YUV420ToRGB_8u_P3AC4R_single_line(BYTE* WINPR_RESTRICT pEven, UINT32 DstFormat,
575 const BYTE* WINPR_RESTRICT pYeven,
576 const BYTE* WINPR_RESTRICT pU,
577 const BYTE* WINPR_RESTRICT pV, UINT32 width,
578 fkt_writePixel writePixel, UINT32 formatSize)
582 for (; x < width / 2; x++)
584 const BYTE U = pU[x];
585 const BYTE V = pV[x];
586 const BYTE eY0 = pYeven[2ULL * x + 0];
587 const BYTE eY1 = pYeven[2ULL * x + 1];
588 writeYUVPixel(&pEven[2ULL * x * formatSize], DstFormat, eY0, U, V, writePixel);
589 writeYUVPixel(&pEven[(2ULL * x + 1) * formatSize], DstFormat, eY1, U, V, writePixel);
592 for (; x < (width + 1) / 2; x++)
594 const BYTE U = pU[x];
595 const BYTE V = pV[x];
596 const BYTE eY0 = pYeven[2ULL * x + 0];
597 writeYUVPixel(&pEven[2ULL * x * formatSize], DstFormat, eY0, U, V, writePixel);
601static pstatus_t general_YUV420ToRGB_8u_P3AC4R(
const BYTE* WINPR_RESTRICT pSrc[3],
602 const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pDst,
603 UINT32 dstStep, UINT32 DstFormat,
607 const DWORD formatSize = FreeRDPGetBytesPerPixel(DstFormat);
608 fkt_writePixel writePixel = getPixelWriteFunction(DstFormat, FALSE);
609 const UINT32 nWidth = roi->width;
610 const UINT32 nHeight = roi->height;
613 for (; y < nHeight / 2; y++)
615 const BYTE* pYe = &pSrc[0][(2ULL * y + 0) * srcStep[0]];
616 const BYTE* pYo = &pSrc[0][(2ULL * y + 1) * srcStep[0]];
617 const BYTE* pU = &pSrc[1][1ULL * srcStep[1] * y];
618 const BYTE* pV = &pSrc[2][1ULL * srcStep[2] * y];
619 BYTE* pRGBeven = &pDst[2ULL * y * dstStep];
620 BYTE* pRGBodd = &pDst[(2ULL * y + 1) * dstStep];
621 general_YUV420ToRGB_8u_P3AC4R_double_line(pRGBeven, pRGBodd, DstFormat, pYe, pYo, pU, pV,
622 nWidth, writePixel, formatSize);
626 for (; y < (nHeight + 1) / 2; y++)
628 const BYTE* pY = &pSrc[0][2ULL * srcStep[0] * y];
629 const BYTE* pU = &pSrc[1][1ULL * srcStep[1] * y];
630 const BYTE* pV = &pSrc[2][1ULL * srcStep[2] * y];
631 BYTE* pEven = &pDst[2ULL * y * dstStep];
633 general_YUV420ToRGB_8u_P3AC4R_single_line(pEven, DstFormat, pY, pU, pV, nWidth, writePixel,
637 return PRIMITIVES_SUCCESS;
640static inline void BGRX_fillYUV(
size_t offset,
const BYTE* WINPR_RESTRICT pRGB[2],
641 BYTE* WINPR_RESTRICT pY[2], BYTE* WINPR_RESTRICT pU[2],
642 BYTE* WINPR_RESTRICT pV[2])
649 const UINT32 SrcFormat = PIXEL_FORMAT_BGRX32;
650 const UINT32 bpp = 4;
652 for (
size_t i = 0; i < 2; i++)
654 for (
size_t j = 0; j < 2; j++)
659 const UINT32 color = FreeRDPReadColor(&pRGB[i][(offset + j) * bpp], SrcFormat);
660 FreeRDPSplitColor(color, SrcFormat, &R, &G, &B,
nullptr,
nullptr);
661 pY[i][offset + j] = RGB2Y(R, G, B);
662 pU[i][offset + j] = RGB2U(R, G, B);
663 pV[i][offset + j] = RGB2V(R, G, B);
668 const INT32 avgU = (pU[0][offset] + pU[0][offset + 1] + pU[1][offset] + pU[1][offset + 1]) / 4;
669 pU[0][offset] = CONDITIONAL_CLIP(avgU, pU[0][offset]);
670 const INT32 avgV = (pV[0][offset] + pV[0][offset + 1] + pV[1][offset] + pV[1][offset + 1]) / 4;
671 pV[0][offset] = CONDITIONAL_CLIP(avgV, pV[0][offset]);
674static inline void BGRX_fillYUV_single(
size_t offset,
const BYTE* WINPR_RESTRICT pRGB,
675 BYTE* WINPR_RESTRICT pY, BYTE* WINPR_RESTRICT pU,
676 BYTE* WINPR_RESTRICT pV)
683 const UINT32 SrcFormat = PIXEL_FORMAT_BGRX32;
684 const UINT32 bpp = 4;
686 for (
size_t j = 0; j < 2; j++)
691 const UINT32 color = FreeRDPReadColor(&pRGB[(offset + j) * bpp], SrcFormat);
692 FreeRDPSplitColor(color, SrcFormat, &R, &G, &B,
nullptr,
nullptr);
693 pY[offset + j] = RGB2Y(R, G, B);
694 pU[offset + j] = RGB2U(R, G, B);
695 pV[offset + j] = RGB2V(R, G, B);
699static inline void general_BGRXToYUV444_DOUBLE_ROW(
const BYTE* WINPR_RESTRICT pRGB[2],
700 BYTE* WINPR_RESTRICT pY[2],
701 BYTE* WINPR_RESTRICT pU[2],
702 BYTE* WINPR_RESTRICT pV[2], UINT32 nWidth)
705 WINPR_ASSERT((nWidth % 2) == 0);
706 for (
size_t x = 0; x < nWidth; x += 2)
708 BGRX_fillYUV(x, pRGB, pY, pU, pV);
712static inline void general_BGRXToYUV444_SINGLE_ROW(
const BYTE* WINPR_RESTRICT pRGB,
713 BYTE* WINPR_RESTRICT pY, BYTE* WINPR_RESTRICT pU,
714 BYTE* WINPR_RESTRICT pV, UINT32 nWidth)
717 WINPR_ASSERT((nWidth % 2) == 0);
718 for (
size_t x = 0; x < nWidth; x += 2)
720 BGRX_fillYUV_single(x, pRGB, pY, pU, pV);
724static inline pstatus_t general_RGBToYUV444_8u_P3AC4R_BGRX(
const BYTE* WINPR_RESTRICT pSrc,
725 const UINT32 srcStep,
726 BYTE* WINPR_RESTRICT pDst[3],
727 const UINT32 dstStep[3],
730 const UINT32 nWidth = roi->width;
731 const UINT32 nHeight = roi->height;
734 for (; y < nHeight - nHeight % 2; y += 2)
736 const BYTE* pRGB[] = { pSrc + y * srcStep, pSrc + (y + 1) * srcStep };
737 BYTE* pY[] = { pDst[0] + y * dstStep[0], pDst[0] + (y + 1) * dstStep[0] };
738 BYTE* pU[] = { pDst[1] + y * dstStep[1], pDst[1] + (y + 1) * dstStep[1] };
739 BYTE* pV[] = { pDst[2] + y * dstStep[2], pDst[2] + (y + 1) * dstStep[2] };
741 general_BGRXToYUV444_DOUBLE_ROW(pRGB, pY, pU, pV, nWidth);
744 for (; y < nHeight; y++)
746 const BYTE* pRGB = pSrc + y * srcStep;
747 BYTE* pY = pDst[0] + y * dstStep[0];
748 BYTE* pU = pDst[1] + y * dstStep[1];
749 BYTE* pV = pDst[2] + y * dstStep[2];
751 general_BGRXToYUV444_SINGLE_ROW(pRGB, pY, pU, pV, nWidth);
754 return PRIMITIVES_SUCCESS;
757static inline void fillYUV(
size_t offset,
const BYTE* WINPR_RESTRICT pRGB[2], UINT32 SrcFormat,
758 BYTE* WINPR_RESTRICT pY[2], BYTE* WINPR_RESTRICT pU[2],
759 BYTE* WINPR_RESTRICT pV[2])
765 const UINT32 bpp = FreeRDPGetBytesPerPixel(SrcFormat);
769 for (
size_t i = 0; i < 2; i++)
771 for (
size_t j = 0; j < 2; j++)
776 const UINT32 color = FreeRDPReadColor(&pRGB[i][(offset + j) * bpp], SrcFormat);
777 FreeRDPSplitColor(color, SrcFormat, &R, &G, &B,
nullptr,
nullptr);
778 const BYTE y = RGB2Y(R, G, B);
779 const BYTE u = RGB2U(R, G, B);
780 const BYTE v = RGB2V(R, G, B);
783 pY[i][offset + j] = y;
784 pU[i][offset + j] = u;
785 pV[i][offset + j] = v;
791 pU[0][offset] = CLIP(avgU);
794 pV[0][offset] = CLIP(avgV);
797static inline void fillYUV_single(
size_t offset,
const BYTE* WINPR_RESTRICT pRGB, UINT32 SrcFormat,
798 BYTE* WINPR_RESTRICT pY, BYTE* WINPR_RESTRICT pU,
799 BYTE* WINPR_RESTRICT pV)
805 const UINT32 bpp = FreeRDPGetBytesPerPixel(SrcFormat);
807 for (
size_t j = 0; j < 2; j++)
812 const UINT32 color = FreeRDPReadColor(&pRGB[(offset + j) * bpp], SrcFormat);
813 FreeRDPSplitColor(color, SrcFormat, &R, &G, &B,
nullptr,
nullptr);
814 const BYTE y = RGB2Y(R, G, B);
815 const BYTE u = RGB2U(R, G, B);
816 const BYTE v = RGB2V(R, G, B);
823static inline void general_RGBToYUV444_DOUBLE_ROW(
const BYTE* WINPR_RESTRICT pRGB[2],
824 UINT32 SrcFormat, BYTE* WINPR_RESTRICT pY[2],
825 BYTE* WINPR_RESTRICT pU[2],
826 BYTE* WINPR_RESTRICT pV[2], UINT32 nWidth)
829 WINPR_ASSERT((nWidth % 2) == 0);
830 for (
size_t x = 0; x < nWidth; x += 2)
832 fillYUV(x, pRGB, SrcFormat, pY, pU, pV);
836static inline void general_RGBToYUV444_SINGLE_ROW(
const BYTE* WINPR_RESTRICT pRGB, UINT32 SrcFormat,
837 BYTE* WINPR_RESTRICT pY, BYTE* WINPR_RESTRICT pU,
838 BYTE* WINPR_RESTRICT pV, UINT32 nWidth)
841 WINPR_ASSERT((nWidth % 2) == 0);
842 for (
size_t x = 0; x < nWidth; x += 2)
844 fillYUV_single(x, pRGB, SrcFormat, pY, pU, pV);
848static inline pstatus_t general_RGBToYUV444_8u_P3AC4R_RGB(
const BYTE* WINPR_RESTRICT pSrc,
849 UINT32 SrcFormat,
const UINT32 srcStep,
850 BYTE* WINPR_RESTRICT pDst[3],
851 const UINT32 dstStep[3],
854 const UINT32 nWidth = roi->width;
855 const UINT32 nHeight = roi->height;
858 for (; y < nHeight - nHeight % 2; y += 2)
860 const BYTE* pRGB[] = { pSrc + y * srcStep, pSrc + (y + 1) * srcStep };
861 BYTE* pY[] = { &pDst[0][y * dstStep[0]], &pDst[0][(y + 1) * dstStep[0]] };
862 BYTE* pU[] = { &pDst[1][y * dstStep[1]], &pDst[1][(y + 1) * dstStep[1]] };
863 BYTE* pV[] = { &pDst[2][y * dstStep[2]], &pDst[2][(y + 1) * dstStep[2]] };
865 general_RGBToYUV444_DOUBLE_ROW(pRGB, SrcFormat, pY, pU, pV, nWidth);
867 for (; y < nHeight; y++)
869 const BYTE* pRGB = pSrc + y * srcStep;
870 BYTE* pY = &pDst[0][y * dstStep[0]];
871 BYTE* pU = &pDst[1][y * dstStep[1]];
872 BYTE* pV = &pDst[2][y * dstStep[2]];
874 general_RGBToYUV444_SINGLE_ROW(pRGB, SrcFormat, pY, pU, pV, nWidth);
877 return PRIMITIVES_SUCCESS;
880static pstatus_t general_RGBToYUV444_8u_P3AC4R(
const BYTE* WINPR_RESTRICT pSrc, UINT32 SrcFormat,
881 const UINT32 srcStep, BYTE* WINPR_RESTRICT pDst[3],
882 const UINT32 dstStep[3],
887 case PIXEL_FORMAT_BGRA32:
888 case PIXEL_FORMAT_BGRX32:
889 return general_RGBToYUV444_8u_P3AC4R_BGRX(pSrc, srcStep, pDst, dstStep, roi);
891 return general_RGBToYUV444_8u_P3AC4R_RGB(pSrc, SrcFormat, srcStep, pDst, dstStep, roi);
895static inline void fillI444_single(
size_t offset,
const BYTE* WINPR_RESTRICT pRGB, UINT32 SrcFormat,
896 BYTE* WINPR_RESTRICT pY, BYTE* WINPR_RESTRICT pU,
897 BYTE* WINPR_RESTRICT pV)
904 const UINT32 bpp = FreeRDPGetBytesPerPixel(SrcFormat);
909 const UINT32 color = FreeRDPReadColor(&pRGB[offset * bpp], SrcFormat);
910 FreeRDPSplitColor(color, SrcFormat, &R, &G, &B,
nullptr,
nullptr);
911 const BYTE y = RGB2Y(R, G, B);
912 const BYTE u = RGB2U(R, G, B);
913 const BYTE v = RGB2V(R, G, B);
919static inline void general_RGBToI444_SINGLE_ROW(
const BYTE* WINPR_RESTRICT pRGB, UINT32 SrcFormat,
920 BYTE* WINPR_RESTRICT pY, BYTE* WINPR_RESTRICT pU,
921 BYTE* WINPR_RESTRICT pV, UINT32 nWidth)
923 for (
size_t x = 0; x < nWidth; x++)
925 fillI444_single(x, pRGB, SrcFormat, pY, pU, pV);
929static inline pstatus_t general_RGBToI444_8u_RGB(
const BYTE* WINPR_RESTRICT pSrc, UINT32 SrcFormat,
930 const UINT32 srcStep, BYTE* WINPR_RESTRICT pDst[3],
931 const UINT32 dstStep[3],
934 const UINT32 nWidth = roi->width;
935 const UINT32 nHeight = roi->height;
937 for (
size_t y = 0; y < nHeight; y++)
939 const BYTE* pRGB = pSrc + y * srcStep;
940 BYTE* pY = &pDst[0][y * dstStep[0]];
941 BYTE* pU = &pDst[1][y * dstStep[1]];
942 BYTE* pV = &pDst[2][y * dstStep[2]];
944 general_RGBToI444_SINGLE_ROW(pRGB, SrcFormat, pY, pU, pV, nWidth);
947 return PRIMITIVES_SUCCESS;
950static pstatus_t general_RGBToI444_8u(
const BYTE* WINPR_RESTRICT pSrc, UINT32 SrcFormat,
951 const UINT32 srcStep, BYTE* WINPR_RESTRICT pDst[3],
952 const UINT32 dstStep[3],
958 return general_RGBToI444_8u_RGB(pSrc, SrcFormat, srcStep, pDst, dstStep, roi);
962static inline pstatus_t general_RGBToYUV420_BGRX(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcStep,
963 BYTE* WINPR_RESTRICT pDst[3],
964 const UINT32 dstStep[3],
970 size_t x4 = srcStep + 4;
973 size_t y3 = dstStep[0];
974 size_t y4 = dstStep[0] + 1;
975 UINT32 max_x = roi->width - 1;
978 for (
size_t i = 0; y < roi->height - roi->height % 2; y += 2, i++)
980 const BYTE* src = pSrc + y * srcStep;
981 BYTE* ydst = pDst[0] + y * dstStep[0];
982 BYTE* udst = pDst[1] + i * dstStep[1];
983 BYTE* vdst = pDst[2] + i * dstStep[2];
985 for (
size_t x = 0; x < roi->width; x += 2)
994 Ba = B = *(src + x1 + 0);
995 Ga = G = *(src + x1 + 1);
996 Ra = R = *(src + x1 + 2);
997 ydst[y1] = RGB2Y(R, G, B);
1002 Ba += B = *(src + x2 + 0);
1003 Ga += G = *(src + x2 + 1);
1004 Ra += R = *(src + x2 + 2);
1005 ydst[y2] = RGB2Y(R, G, B);
1009 Ba += B = *(src + x3 + 0);
1010 Ga += G = *(src + x3 + 1);
1011 Ra += R = *(src + x3 + 2);
1012 ydst[y3] = RGB2Y(R, G, B);
1017 Ba += B = *(src + x4 + 0);
1018 Ga += G = *(src + x4 + 1);
1019 Ra += R = *(src + x4 + 2);
1020 ydst[y4] = RGB2Y(R, G, B);
1026 *udst++ = RGB2U(Ra, Ga, Ba);
1027 *vdst++ = RGB2V(Ra, Ga, Ba);
1033 for (; y < roi->height; y++)
1035 const BYTE* src = pSrc + y * srcStep;
1036 BYTE* ydst = pDst[0] + y * dstStep[0];
1037 BYTE* udst = pDst[1] + (y / 2) * dstStep[1];
1038 BYTE* vdst = pDst[2] + (y / 2) * dstStep[2];
1040 for (
size_t x = 0; x < roi->width; x += 2)
1049 Ba = B = *(src + x1 + 0);
1050 Ga = G = *(src + x1 + 1);
1051 Ra = R = *(src + x1 + 2);
1052 ydst[y1] = RGB2Y(R, G, B);
1057 Ba += B = *(src + x2 + 0);
1058 Ga += G = *(src + x2 + 1);
1059 Ra += R = *(src + x2 + 2);
1060 ydst[y2] = RGB2Y(R, G, B);
1066 *udst++ = RGB2U(Ra, Ga, Ba);
1067 *vdst++ = RGB2V(Ra, Ga, Ba);
1073 return PRIMITIVES_SUCCESS;
1076static inline pstatus_t general_RGBToYUV420_RGBX(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcStep,
1077 BYTE* WINPR_RESTRICT pDst[3],
1078 const UINT32 dstStep[3],
1083 size_t x3 = srcStep;
1084 size_t x4 = srcStep + 4;
1087 size_t y3 = dstStep[0];
1088 size_t y4 = dstStep[0] + 1;
1089 UINT32 max_x = roi->width - 1;
1092 for (
size_t i = 0; y < roi->height - roi->height % 2; y += 2, i++)
1094 const BYTE* src = pSrc + y * srcStep;
1095 BYTE* ydst = pDst[0] + y * dstStep[0];
1096 BYTE* udst = pDst[1] + i * dstStep[1];
1097 BYTE* vdst = pDst[2] + i * dstStep[2];
1099 for (UINT32 x = 0; x < roi->width; x += 2)
1101 BYTE R = *(src + x1 + 0);
1102 BYTE G = *(src + x1 + 1);
1103 BYTE B = *(src + x1 + 2);
1108 ydst[y1] = RGB2Y(R, G, B);
1113 R = *(src + x2 + 0);
1114 G = *(src + x2 + 1);
1115 B = *(src + x2 + 2);
1119 ydst[y2] = RGB2Y(R, G, B);
1123 R = *(src + x3 + 0);
1124 G = *(src + x3 + 1);
1125 B = *(src + x3 + 2);
1130 ydst[y3] = RGB2Y(R, G, B);
1135 R = *(src + x4 + 0);
1136 G = *(src + x4 + 1);
1137 B = *(src + x4 + 2);
1142 ydst[y4] = RGB2Y(R, G, B);
1148 *udst++ = RGB2U(Ra, Ga, Ba);
1149 *vdst++ = RGB2V(Ra, Ga, Ba);
1155 for (; y < roi->height; y++)
1157 const BYTE* src = pSrc + y * srcStep;
1158 BYTE* ydst = pDst[0] + y * dstStep[0];
1159 BYTE* udst = pDst[1] + (y / 2) * dstStep[1];
1160 BYTE* vdst = pDst[2] + (y / 2) * dstStep[2];
1162 for (UINT32 x = 0; x < roi->width; x += 2)
1164 BYTE R = *(src + x1 + 0);
1165 BYTE G = *(src + x1 + 1);
1166 BYTE B = *(src + x1 + 2);
1171 ydst[y1] = RGB2Y(R, G, B);
1176 R = *(src + x2 + 0);
1177 G = *(src + x2 + 1);
1178 B = *(src + x2 + 2);
1182 ydst[y2] = RGB2Y(R, G, B);
1188 *udst++ = RGB2U(Ra, Ga, Ba);
1189 *vdst++ = RGB2V(Ra, Ga, Ba);
1195 return PRIMITIVES_SUCCESS;
1198static inline pstatus_t general_RGBToYUV420_ANY(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcFormat,
1199 UINT32 srcStep, BYTE* WINPR_RESTRICT pDst[3],
1200 const UINT32 dstStep[3],
1203 const UINT32 bpp = FreeRDPGetBytesPerPixel(srcFormat);
1206 size_t x3 = srcStep;
1207 size_t x4 = srcStep + bpp;
1210 size_t y3 = dstStep[0];
1211 size_t y4 = dstStep[0] + 1;
1212 UINT32 max_x = roi->width - 1;
1215 for (
size_t i = 0; y < roi->height - roi->height % 2; y += 2, i++)
1217 const BYTE* src = pSrc + y * srcStep;
1218 BYTE* ydst = pDst[0] + y * dstStep[0];
1219 BYTE* udst = pDst[1] + i * dstStep[1];
1220 BYTE* vdst = pDst[2] + i * dstStep[2];
1222 for (
size_t x = 0; x < roi->width; x += 2)
1232 color = FreeRDPReadColor(src + x1, srcFormat);
1233 FreeRDPSplitColor(color, srcFormat, &R, &G, &B,
nullptr,
nullptr);
1237 ydst[y1] = RGB2Y(R, G, B);
1242 color = FreeRDPReadColor(src + x2, srcFormat);
1243 FreeRDPSplitColor(color, srcFormat, &R, &G, &B,
nullptr,
nullptr);
1247 ydst[y2] = RGB2Y(R, G, B);
1251 color = FreeRDPReadColor(src + x3, srcFormat);
1252 FreeRDPSplitColor(color, srcFormat, &R, &G, &B,
nullptr,
nullptr);
1256 ydst[y3] = RGB2Y(R, G, B);
1261 color = FreeRDPReadColor(src + x4, srcFormat);
1262 FreeRDPSplitColor(color, srcFormat, &R, &G, &B,
nullptr,
nullptr);
1266 ydst[y4] = RGB2Y(R, G, B);
1272 *udst++ = RGB2U(Ra, Ga, Ba);
1273 *vdst++ = RGB2V(Ra, Ga, Ba);
1279 for (; y < roi->height; y++)
1281 const BYTE* src = pSrc + y * srcStep;
1282 BYTE* ydst = pDst[0] + y * dstStep[0];
1283 BYTE* udst = pDst[1] + (y / 2) * dstStep[1];
1284 BYTE* vdst = pDst[2] + (y / 2) * dstStep[2];
1286 for (
size_t x = 0; x < roi->width; x += 2)
1292 UINT32 color = FreeRDPReadColor(src + x1, srcFormat);
1293 FreeRDPSplitColor(color, srcFormat, &R, &G, &B,
nullptr,
nullptr);
1297 ydst[y1] = RGB2Y(R, G, B);
1302 color = FreeRDPReadColor(src + x2, srcFormat);
1303 FreeRDPSplitColor(color, srcFormat, &R, &G, &B,
nullptr,
nullptr);
1307 ydst[y2] = RGB2Y(R, G, B);
1313 *udst++ = RGB2U(Ra, Ga, Ba);
1314 *vdst++ = RGB2V(Ra, Ga, Ba);
1320 return PRIMITIVES_SUCCESS;
1323static pstatus_t general_RGBToYUV420_8u_P3AC4R(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcFormat,
1324 UINT32 srcStep, BYTE* WINPR_RESTRICT pDst[3],
1325 const UINT32 dstStep[3],
1330 case PIXEL_FORMAT_BGRA32:
1331 case PIXEL_FORMAT_BGRX32:
1332 return general_RGBToYUV420_BGRX(pSrc, srcStep, pDst, dstStep, roi);
1334 case PIXEL_FORMAT_RGBA32:
1335 case PIXEL_FORMAT_RGBX32:
1336 return general_RGBToYUV420_RGBX(pSrc, srcStep, pDst, dstStep, roi);
1339 return general_RGBToYUV420_ANY(pSrc, srcFormat, srcStep, pDst, dstStep, roi);
1343static inline void int_general_RGBToAVC444YUV_BGRX_DOUBLE_ROW(
1344 size_t offset,
const BYTE* WINPR_RESTRICT pSrcEven,
const BYTE* WINPR_RESTRICT pSrcOdd,
1345 BYTE* WINPR_RESTRICT b1Even, BYTE* WINPR_RESTRICT b1Odd, BYTE* WINPR_RESTRICT b2,
1346 BYTE* WINPR_RESTRICT b3, BYTE* WINPR_RESTRICT b4, BYTE* WINPR_RESTRICT b5,
1347 BYTE* WINPR_RESTRICT b6, BYTE* WINPR_RESTRICT b7, UINT32 width)
1349 WINPR_ASSERT((width % 2) == 0);
1350 for (
size_t x = offset; x < width; x += 2)
1352 const BYTE* srcEven = &pSrcEven[4ULL * x];
1353 const BYTE* srcOdd = &pSrcOdd[4ULL * x];
1354 const BOOL lastX = (x + 1) >= width;
1369 const BYTE b = *srcEven++;
1370 const BYTE g = *srcEven++;
1371 const BYTE r = *srcEven++;
1373 Y1e = Y2e = Y1o = Y2o = RGB2Y(r, g, b);
1374 U1e = U2e = U1o = U2o = RGB2U(r, g, b);
1375 V1e = V2e = V1o = V2o = RGB2V(r, g, b);
1380 const BYTE b = *srcEven++;
1381 const BYTE g = *srcEven++;
1382 const BYTE r = *srcEven++;
1384 Y2e = RGB2Y(r, g, b);
1385 U2e = RGB2U(r, g, b);
1386 V2e = RGB2V(r, g, b);
1391 const BYTE b = *srcOdd++;
1392 const BYTE g = *srcOdd++;
1393 const BYTE r = *srcOdd++;
1395 Y1o = Y2o = RGB2Y(r, g, b);
1396 U1o = U2o = RGB2U(r, g, b);
1397 V1o = V2o = RGB2V(r, g, b);
1400 if (b1Odd && !lastX)
1402 const BYTE b = *srcOdd++;
1403 const BYTE g = *srcOdd++;
1404 const BYTE r = *srcOdd++;
1406 Y2o = RGB2Y(r, g, b);
1407 U2o = RGB2U(r, g, b);
1408 V2o = RGB2V(r, g, b);
1424 const BYTE Uavg = WINPR_ASSERTING_INT_CAST(BYTE, ((UINT16)U1e + U2e + U1o + U2o) / 4);
1425 const BYTE Vavg = WINPR_ASSERTING_INT_CAST(BYTE, ((UINT16)V1e + V2e + V1o + V2o) / 4);
1452void general_RGBToAVC444YUV_BGRX_DOUBLE_ROW(
size_t offset,
const BYTE* WINPR_RESTRICT pSrcEven,
1453 const BYTE* WINPR_RESTRICT pSrcOdd,
1454 BYTE* WINPR_RESTRICT b1Even, BYTE* WINPR_RESTRICT b1Odd,
1455 BYTE* WINPR_RESTRICT b2, BYTE* WINPR_RESTRICT b3,
1456 BYTE* WINPR_RESTRICT b4, BYTE* WINPR_RESTRICT b5,
1457 BYTE* WINPR_RESTRICT b6, BYTE* WINPR_RESTRICT b7,
1460 int_general_RGBToAVC444YUV_BGRX_DOUBLE_ROW(offset, pSrcEven, pSrcOdd, b1Even, b1Odd, b2, b3, b4,
1464static inline pstatus_t general_RGBToAVC444YUV_BGRX(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcStep,
1465 BYTE* WINPR_RESTRICT pDst1[3],
1466 const UINT32 dst1Step[3],
1467 BYTE* WINPR_RESTRICT pDst2[3],
1468 const UINT32 dst2Step[3],
1476 for (; y < roi->height - roi->height % 2; y += 2)
1478 const BYTE* srcEven = pSrc + 1ULL * y * srcStep;
1479 const BYTE* srcOdd = pSrc + 1ULL * (y + 1) * srcStep;
1480 const size_t i = y >> 1;
1481 const size_t n = (i & (uint32_t)~7) + i;
1482 BYTE* b1Even = pDst1[0] + 1ULL * y * dst1Step[0];
1483 BYTE* b1Odd = (b1Even + dst1Step[0]);
1484 BYTE* b2 = pDst1[1] + 1ULL * (y / 2) * dst1Step[1];
1485 BYTE* b3 = pDst1[2] + 1ULL * (y / 2) * dst1Step[2];
1486 BYTE* b4 = pDst2[0] + 1ULL * dst2Step[0] * n;
1487 BYTE* b5 = b4 + 8ULL * dst2Step[0];
1488 BYTE* b6 = pDst2[1] + 1ULL * (y / 2) * dst2Step[1];
1489 BYTE* b7 = pDst2[2] + 1ULL * (y / 2) * dst2Step[2];
1490 int_general_RGBToAVC444YUV_BGRX_DOUBLE_ROW(0, srcEven, srcOdd, b1Even, b1Odd, b2, b3, b4,
1491 b5, b6, b7, roi->width);
1493 for (; y < roi->height; y++)
1495 const BYTE* srcEven = pSrc + 1ULL * y * srcStep;
1496 BYTE* b1Even = pDst1[0] + 1ULL * y * dst1Step[0];
1497 BYTE* b2 = pDst1[1] + 1ULL * (y / 2) * dst1Step[1];
1498 BYTE* b3 = pDst1[2] + 1ULL * (y / 2) * dst1Step[2];
1499 BYTE* b6 = pDst2[1] + 1ULL * (y / 2) * dst2Step[1];
1500 BYTE* b7 = pDst2[2] + 1ULL * (y / 2) * dst2Step[2];
1501 int_general_RGBToAVC444YUV_BGRX_DOUBLE_ROW(0, srcEven,
nullptr, b1Even,
nullptr, b2, b3,
1502 nullptr,
nullptr, b6, b7, roi->width);
1505 return PRIMITIVES_SUCCESS;
1508static inline void general_RGBToAVC444YUV_RGBX_DOUBLE_ROW(
1509 const BYTE* WINPR_RESTRICT srcEven,
const BYTE* WINPR_RESTRICT srcOdd,
1510 BYTE* WINPR_RESTRICT b1Even, BYTE* WINPR_RESTRICT b1Odd, BYTE* WINPR_RESTRICT b2,
1511 BYTE* WINPR_RESTRICT b3, BYTE* WINPR_RESTRICT b4, BYTE* WINPR_RESTRICT b5,
1512 BYTE* WINPR_RESTRICT b6, BYTE* WINPR_RESTRICT b7, UINT32 width)
1514 WINPR_ASSERT((width % 2) == 0);
1515 for (UINT32 x = 0; x < width; x += 2)
1517 const BOOL lastX = (x + 1) >= width;
1532 const BYTE r = *srcEven++;
1533 const BYTE g = *srcEven++;
1534 const BYTE b = *srcEven++;
1536 Y1e = Y2e = Y1o = Y2o = RGB2Y(r, g, b);
1537 U1e = U2e = U1o = U2o = RGB2U(r, g, b);
1538 V1e = V2e = V1o = V2o = RGB2V(r, g, b);
1543 const BYTE r = *srcEven++;
1544 const BYTE g = *srcEven++;
1545 const BYTE b = *srcEven++;
1547 Y2e = RGB2Y(r, g, b);
1548 U2e = RGB2U(r, g, b);
1549 V2e = RGB2V(r, g, b);
1554 const BYTE r = *srcOdd++;
1555 const BYTE g = *srcOdd++;
1556 const BYTE b = *srcOdd++;
1558 Y1o = Y2o = RGB2Y(r, g, b);
1559 U1o = U2o = RGB2U(r, g, b);
1560 V1o = V2o = RGB2V(r, g, b);
1563 if (b1Odd && !lastX)
1565 const BYTE r = *srcOdd++;
1566 const BYTE g = *srcOdd++;
1567 const BYTE b = *srcOdd++;
1569 Y2o = RGB2Y(r, g, b);
1570 U2o = RGB2U(r, g, b);
1571 V2o = RGB2V(r, g, b);
1587 const BYTE Uavg = WINPR_ASSERTING_INT_CAST(BYTE, ((UINT16)U1e + U2e + U1o + U2o) / 4);
1588 const BYTE Vavg = WINPR_ASSERTING_INT_CAST(BYTE, ((UINT16)V1e + V2e + V1o + V2o) / 4);
1615static inline pstatus_t general_RGBToAVC444YUV_RGBX(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcStep,
1616 BYTE* WINPR_RESTRICT pDst1[3],
1617 const UINT32 dst1Step[3],
1618 BYTE* WINPR_RESTRICT pDst2[3],
1619 const UINT32 dst2Step[3],
1628 for (; y < roi->height - roi->height % 2; y += 2)
1630 const BOOL last = (y >= (roi->height - 1));
1631 const BYTE* srcEven = pSrc + 1ULL * y * srcStep;
1632 const BYTE* srcOdd = pSrc + 1ULL * (y + 1) * srcStep;
1633 const size_t i = y >> 1;
1634 const size_t n = (i & (size_t)~7) + i;
1635 BYTE* b1Even = pDst1[0] + 1ULL * y * dst1Step[0];
1636 BYTE* b1Odd = !last ? (b1Even + dst1Step[0]) : nullptr;
1637 BYTE* b2 = pDst1[1] + 1ULL * (y / 2) * dst1Step[1];
1638 BYTE* b3 = pDst1[2] + 1ULL * (y / 2) * dst1Step[2];
1639 BYTE* b4 = pDst2[0] + 1ULL * dst2Step[0] * n;
1640 BYTE* b5 = b4 + 8ULL * dst2Step[0];
1641 BYTE* b6 = pDst2[1] + 1ULL * (y / 2) * dst2Step[1];
1642 BYTE* b7 = pDst2[2] + 1ULL * (y / 2) * dst2Step[2];
1643 general_RGBToAVC444YUV_RGBX_DOUBLE_ROW(srcEven, srcOdd, b1Even, b1Odd, b2, b3, b4, b5, b6,
1646 for (; y < roi->height; y++)
1648 const BYTE* srcEven = pSrc + 1ULL * y * srcStep;
1649 BYTE* b1Even = pDst1[0] + 1ULL * y * dst1Step[0];
1650 BYTE* b2 = pDst1[1] + 1ULL * (y / 2) * dst1Step[1];
1651 BYTE* b3 = pDst1[2] + 1ULL * (y / 2) * dst1Step[2];
1652 BYTE* b6 = pDst2[1] + 1ULL * (y / 2) * dst2Step[1];
1653 BYTE* b7 = pDst2[2] + 1ULL * (y / 2) * dst2Step[2];
1654 general_RGBToAVC444YUV_RGBX_DOUBLE_ROW(srcEven,
nullptr, b1Even,
nullptr, b2, b3,
nullptr,
1655 nullptr, b6, b7, roi->width);
1657 return PRIMITIVES_SUCCESS;
1660static inline void general_RGBToAVC444YUV_ANY_DOUBLE_ROW(
1661 const BYTE* WINPR_RESTRICT srcEven,
const BYTE* WINPR_RESTRICT srcOdd, UINT32 srcFormat,
1662 BYTE* WINPR_RESTRICT b1Even, BYTE* WINPR_RESTRICT b1Odd, BYTE* WINPR_RESTRICT b2,
1663 BYTE* WINPR_RESTRICT b3, BYTE* WINPR_RESTRICT b4, BYTE* WINPR_RESTRICT b5,
1664 BYTE* WINPR_RESTRICT b6, BYTE* WINPR_RESTRICT b7, UINT32 width)
1666 const UINT32 bpp = FreeRDPGetBytesPerPixel(srcFormat);
1667 for (UINT32 x = 0; x < width; x += 2)
1669 const BOOL lastX = (x + 1) >= width;
1687 const UINT32 color = FreeRDPReadColor(srcEven, srcFormat);
1689 FreeRDPSplitColor(color, srcFormat, &r, &g, &b,
nullptr,
nullptr);
1690 Y1e = Y2e = Y1o = Y2o = RGB2Y(r, g, b);
1691 U1e = U2e = U1o = U2o = RGB2U(r, g, b);
1692 V1e = V2e = V1o = V2o = RGB2V(r, g, b);
1700 const UINT32 color = FreeRDPReadColor(srcEven, srcFormat);
1702 FreeRDPSplitColor(color, srcFormat, &r, &g, &b,
nullptr,
nullptr);
1703 Y2e = RGB2Y(r, g, b);
1704 U2e = RGB2U(r, g, b);
1705 V2e = RGB2V(r, g, b);
1713 const UINT32 color = FreeRDPReadColor(srcOdd, srcFormat);
1715 FreeRDPSplitColor(color, srcFormat, &r, &g, &b,
nullptr,
nullptr);
1716 Y1o = Y2o = RGB2Y(r, g, b);
1717 U1o = U2o = RGB2U(r, g, b);
1718 V1o = V2o = RGB2V(r, g, b);
1721 if (b1Odd && !lastX)
1726 const UINT32 color = FreeRDPReadColor(srcOdd, srcFormat);
1728 FreeRDPSplitColor(color, srcFormat, &r, &g, &b,
nullptr,
nullptr);
1729 Y2o = RGB2Y(r, g, b);
1730 U2o = RGB2U(r, g, b);
1731 V2o = RGB2V(r, g, b);
1747 const BYTE Uavg = WINPR_ASSERTING_INT_CAST(
1748 BYTE, ((UINT16)U1e + (UINT16)U2e + (UINT16)U1o + (UINT16)U2o) / 4);
1749 const BYTE Vavg = WINPR_ASSERTING_INT_CAST(
1750 BYTE, ((UINT16)V1e + (UINT16)V2e + (UINT16)V1o + (UINT16)V2o) / 4);
1777static inline pstatus_t
1778general_RGBToAVC444YUV_ANY(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcFormat, UINT32 srcStep,
1779 BYTE* WINPR_RESTRICT pDst1[3],
const UINT32 dst1Step[3],
1780 BYTE* WINPR_RESTRICT pDst2[3],
const UINT32 dst2Step[3],
1840 const BYTE* pMaxSrc = pSrc + 1ULL * (roi->height - 1) * srcStep;
1842 for (
size_t y = 0; y < roi->height; y += 2)
1844 WINPR_ASSERT(y < UINT32_MAX);
1846 const BOOL last = (y >= (roi->height - 1));
1847 const BYTE* srcEven = y < roi->height ? pSrc + y * srcStep : pMaxSrc;
1848 const BYTE* srcOdd = !last ? pSrc + (y + 1) * srcStep : pMaxSrc;
1849 const UINT32 i = (UINT32)y >> 1;
1850 const UINT32 n = (i & (uint32_t)~7) + i;
1851 BYTE* b1Even = pDst1[0] + y * dst1Step[0];
1852 BYTE* b1Odd = !last ? (b1Even + dst1Step[0]) : nullptr;
1853 BYTE* b2 = pDst1[1] + (y / 2) * dst1Step[1];
1854 BYTE* b3 = pDst1[2] + (y / 2) * dst1Step[2];
1855 BYTE* b4 = pDst2[0] + 1ULL * dst2Step[0] * n;
1856 BYTE* b5 = b4 + 8ULL * dst2Step[0];
1857 BYTE* b6 = pDst2[1] + (y / 2) * dst2Step[1];
1858 BYTE* b7 = pDst2[2] + (y / 2) * dst2Step[2];
1859 general_RGBToAVC444YUV_ANY_DOUBLE_ROW(srcEven, srcOdd, srcFormat, b1Even, b1Odd, b2, b3, b4,
1860 b5, b6, b7, roi->width);
1863 return PRIMITIVES_SUCCESS;
1866static inline pstatus_t general_RGBToAVC444YUV(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcFormat,
1867 UINT32 srcStep, BYTE* WINPR_RESTRICT pDst1[3],
1868 const UINT32 dst1Step[3],
1869 BYTE* WINPR_RESTRICT pDst2[3],
1870 const UINT32 dst2Step[3],
1873 if (!pSrc || !pDst1 || !dst1Step || !pDst2 || !dst2Step)
1876 if (!pDst1[0] || !pDst1[1] || !pDst1[2])
1879 if (!dst1Step[0] || !dst1Step[1] || !dst1Step[2])
1882 if (!pDst2[0] || !pDst2[1] || !pDst2[2])
1885 if (!dst2Step[0] || !dst2Step[1] || !dst2Step[2])
1891 case PIXEL_FORMAT_BGRA32:
1892 case PIXEL_FORMAT_BGRX32:
1893 return general_RGBToAVC444YUV_BGRX(pSrc, srcStep, pDst1, dst1Step, pDst2, dst2Step,
1896 case PIXEL_FORMAT_RGBA32:
1897 case PIXEL_FORMAT_RGBX32:
1898 return general_RGBToAVC444YUV_RGBX(pSrc, srcStep, pDst1, dst1Step, pDst2, dst2Step,
1902 return general_RGBToAVC444YUV_ANY(pSrc, srcFormat, srcStep, pDst1, dst1Step, pDst2,
1906 return !PRIMITIVES_SUCCESS;
1909static inline void general_RGBToAVC444YUVv2_ANY_DOUBLE_ROW(
1910 const BYTE* WINPR_RESTRICT srcEven,
const BYTE* WINPR_RESTRICT srcOdd, UINT32 srcFormat,
1911 BYTE* WINPR_RESTRICT yLumaDstEven, BYTE* WINPR_RESTRICT yLumaDstOdd,
1912 BYTE* WINPR_RESTRICT uLumaDst, BYTE* WINPR_RESTRICT vLumaDst,
1913 BYTE* WINPR_RESTRICT yEvenChromaDst1, BYTE* WINPR_RESTRICT yEvenChromaDst2,
1914 BYTE* WINPR_RESTRICT yOddChromaDst1, BYTE* WINPR_RESTRICT yOddChromaDst2,
1915 BYTE* WINPR_RESTRICT uChromaDst1, BYTE* WINPR_RESTRICT uChromaDst2,
1916 BYTE* WINPR_RESTRICT vChromaDst1, BYTE* WINPR_RESTRICT vChromaDst2, UINT32 width)
1918 const UINT32 bpp = FreeRDPGetBytesPerPixel(srcFormat);
1920 WINPR_ASSERT((width % 2) == 0);
1921 for (UINT32 x = 0; x < width; x += 2)
1939 const UINT32 color = FreeRDPReadColor(srcEven, srcFormat);
1941 FreeRDPSplitColor(color, srcFormat, &r, &g, &b,
nullptr,
nullptr);
1942 Ya = RGB2Y(r, g, b);
1943 Ua = RGB2U(r, g, b);
1944 Va = RGB2V(r, g, b);
1952 const UINT32 color = FreeRDPReadColor(srcEven, srcFormat);
1954 FreeRDPSplitColor(color, srcFormat, &r, &g, &b,
nullptr,
nullptr);
1955 Yb = RGB2Y(r, g, b);
1956 Ub = RGB2U(r, g, b);
1957 Vb = RGB2V(r, g, b);
1971 const UINT32 color = FreeRDPReadColor(srcOdd, srcFormat);
1973 FreeRDPSplitColor(color, srcFormat, &r, &g, &b,
nullptr,
nullptr);
1974 Yc = RGB2Y(r, g, b);
1975 Uc = RGB2U(r, g, b);
1976 Vc = RGB2V(r, g, b);
1985 if (srcOdd && (x < width - 1))
1990 const UINT32 color = FreeRDPReadColor(srcOdd, srcFormat);
1992 FreeRDPSplitColor(color, srcFormat, &r, &g, &b,
nullptr,
nullptr);
1993 Yd = RGB2Y(r, g, b);
1994 Ud = RGB2U(r, g, b);
1995 Vd = RGB2V(r, g, b);
2005 *yLumaDstEven++ = Ya;
2008 *yLumaDstEven++ = Yb;
2011 *yLumaDstOdd++ = Yc;
2013 if (srcOdd && (x < width - 1))
2014 *yLumaDstOdd++ = Yd;
2017 *uLumaDst++ = (Ua + Ub + Uc + Ud) / 4;
2018 *vLumaDst++ = (Va + Vb + Vc + Vd) / 4;
2023 *yEvenChromaDst1++ = Ub;
2024 *yEvenChromaDst2++ = Vb;
2032 *yOddChromaDst1++ = Ud;
2033 *yOddChromaDst2++ = Vd;
2039 *uChromaDst1++ = Uc;
2040 *uChromaDst2++ = Vc;
2045 *vChromaDst1++ = Uc;
2046 *vChromaDst2++ = Vc;
2052static inline pstatus_t
2053general_RGBToAVC444YUVv2_ANY(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcFormat, UINT32 srcStep,
2054 BYTE* WINPR_RESTRICT pDst1[3],
const UINT32 dst1Step[3],
2055 BYTE* WINPR_RESTRICT pDst2[3],
const UINT32 dst2Step[3],
2108 if (roi->height < 1 || roi->width < 1)
2109 return !PRIMITIVES_SUCCESS;
2112 for (; y < roi->height - roi->height % 2; y += 2)
2114 const BYTE* srcEven = (pSrc + y * srcStep);
2115 const BYTE* srcOdd = (y < roi->height - 1) ? (srcEven + srcStep) :
nullptr;
2116 BYTE* dstLumaYEven = (pDst1[0] + y * dst1Step[0]);
2117 BYTE* dstLumaYOdd = (dstLumaYEven + dst1Step[0]);
2118 BYTE* dstLumaU = (pDst1[1] + (y / 2) * dst1Step[1]);
2119 BYTE* dstLumaV = (pDst1[2] + (y / 2) * dst1Step[2]);
2120 BYTE* dstEvenChromaY1 = (pDst2[0] + y * dst2Step[0]);
2121 BYTE* dstEvenChromaY2 = dstEvenChromaY1 + roi->width / 2;
2122 BYTE* dstOddChromaY1 = dstEvenChromaY1 + dst2Step[0];
2123 BYTE* dstOddChromaY2 = dstEvenChromaY2 + dst2Step[0];
2124 BYTE* dstChromaU1 = (pDst2[1] + (y / 2) * dst2Step[1]);
2125 BYTE* dstChromaV1 = (pDst2[2] + (y / 2) * dst2Step[2]);
2126 BYTE* dstChromaU2 = dstChromaU1 + roi->width / 4;
2127 BYTE* dstChromaV2 = dstChromaV1 + roi->width / 4;
2128 general_RGBToAVC444YUVv2_ANY_DOUBLE_ROW(
2129 srcEven, srcOdd, srcFormat, dstLumaYEven, dstLumaYOdd, dstLumaU, dstLumaV,
2130 dstEvenChromaY1, dstEvenChromaY2, dstOddChromaY1, dstOddChromaY2, dstChromaU1,
2131 dstChromaU2, dstChromaV1, dstChromaV2, roi->width);
2133 for (; y < roi->height; y++)
2135 const BYTE* srcEven = (pSrc + y * srcStep);
2136 BYTE* dstLumaYEven = (pDst1[0] + y * dst1Step[0]);
2137 BYTE* dstLumaU = (pDst1[1] + (y / 2) * dst1Step[1]);
2138 BYTE* dstLumaV = (pDst1[2] + (y / 2) * dst1Step[2]);
2139 BYTE* dstEvenChromaY1 = (pDst2[0] + y * dst2Step[0]);
2140 BYTE* dstEvenChromaY2 = dstEvenChromaY1 + roi->width / 2;
2141 general_RGBToAVC444YUVv2_ANY_DOUBLE_ROW(
2142 srcEven,
nullptr, srcFormat, dstLumaYEven,
nullptr, dstLumaU, dstLumaV, dstEvenChromaY1,
2143 dstEvenChromaY2,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, roi->width);
2146 return PRIMITIVES_SUCCESS;
2149static inline void int_general_RGBToAVC444YUVv2_BGRX_DOUBLE_ROW(
2150 size_t offset,
const BYTE* WINPR_RESTRICT pSrcEven,
const BYTE* WINPR_RESTRICT pSrcOdd,
2151 BYTE* WINPR_RESTRICT yLumaDstEven, BYTE* WINPR_RESTRICT yLumaDstOdd,
2152 BYTE* WINPR_RESTRICT uLumaDst, BYTE* WINPR_RESTRICT vLumaDst,
2153 BYTE* WINPR_RESTRICT yEvenChromaDst1, BYTE* WINPR_RESTRICT yEvenChromaDst2,
2154 BYTE* WINPR_RESTRICT yOddChromaDst1, BYTE* WINPR_RESTRICT yOddChromaDst2,
2155 BYTE* WINPR_RESTRICT uChromaDst1, BYTE* WINPR_RESTRICT uChromaDst2,
2156 BYTE* WINPR_RESTRICT vChromaDst1, BYTE* WINPR_RESTRICT vChromaDst2, UINT32 width)
2158 WINPR_ASSERT((width % 2) == 0);
2159 WINPR_ASSERT(pSrcEven);
2160 WINPR_ASSERT(yLumaDstEven);
2161 WINPR_ASSERT(uLumaDst);
2162 WINPR_ASSERT(vLumaDst);
2164 for (
size_t x = offset; x < width; x += 2)
2166 const BYTE* srcEven = &pSrcEven[4ULL * x];
2167 const BYTE* srcOdd = pSrcOdd ? &pSrcOdd[4ULL * x] :
nullptr;
2181 const BYTE b = *srcEven++;
2182 const BYTE g = *srcEven++;
2183 const BYTE r = *srcEven++;
2185 Ya = RGB2Y(r, g, b);
2186 Ua = RGB2U(r, g, b);
2187 Va = RGB2V(r, g, b);
2192 const BYTE b = *srcEven++;
2193 const BYTE g = *srcEven++;
2194 const BYTE r = *srcEven++;
2196 Yb = RGB2Y(r, g, b);
2197 Ub = RGB2U(r, g, b);
2198 Vb = RGB2V(r, g, b);
2209 const BYTE b = *srcOdd++;
2210 const BYTE g = *srcOdd++;
2211 const BYTE r = *srcOdd++;
2213 Yc = RGB2Y(r, g, b);
2214 Uc = RGB2U(r, g, b);
2215 Vc = RGB2V(r, g, b);
2224 if (srcOdd && (x < width - 1))
2226 const BYTE b = *srcOdd++;
2227 const BYTE g = *srcOdd++;
2228 const BYTE r = *srcOdd++;
2230 Yd = RGB2Y(r, g, b);
2231 Ud = RGB2U(r, g, b);
2232 Vd = RGB2V(r, g, b);
2242 *yLumaDstEven++ = Ya;
2245 *yLumaDstEven++ = Yb;
2247 if (srcOdd && yLumaDstOdd)
2248 *yLumaDstOdd++ = Yc;
2250 if (srcOdd && (x < width - 1) && yLumaDstOdd)
2251 *yLumaDstOdd++ = Yd;
2254 *uLumaDst++ = (Ua + Ub + Uc + Ud) / 4;
2255 *vLumaDst++ = (Va + Vb + Vc + Vd) / 4;
2260 *yEvenChromaDst1++ = Ub;
2261 *yEvenChromaDst2++ = Vb;
2269 *yOddChromaDst1++ = Ud;
2270 *yOddChromaDst2++ = Vd;
2276 *uChromaDst1++ = Uc;
2277 *uChromaDst2++ = Vc;
2282 *vChromaDst1++ = Uc;
2283 *vChromaDst2++ = Vc;
2289void general_RGBToAVC444YUVv2_BGRX_DOUBLE_ROW(
2290 size_t offset,
const BYTE* WINPR_RESTRICT pSrcEven,
const BYTE* WINPR_RESTRICT pSrcOdd,
2291 BYTE* WINPR_RESTRICT yLumaDstEven, BYTE* WINPR_RESTRICT yLumaDstOdd,
2292 BYTE* WINPR_RESTRICT uLumaDst, BYTE* WINPR_RESTRICT vLumaDst,
2293 BYTE* WINPR_RESTRICT yEvenChromaDst1, BYTE* WINPR_RESTRICT yEvenChromaDst2,
2294 BYTE* WINPR_RESTRICT yOddChromaDst1, BYTE* WINPR_RESTRICT yOddChromaDst2,
2295 BYTE* WINPR_RESTRICT uChromaDst1, BYTE* WINPR_RESTRICT uChromaDst2,
2296 BYTE* WINPR_RESTRICT vChromaDst1, BYTE* WINPR_RESTRICT vChromaDst2, UINT32 width)
2298 int_general_RGBToAVC444YUVv2_BGRX_DOUBLE_ROW(
2299 offset, pSrcEven, pSrcOdd, yLumaDstEven, yLumaDstOdd, uLumaDst, vLumaDst, yEvenChromaDst1,
2300 yEvenChromaDst2, yOddChromaDst1, yOddChromaDst2, uChromaDst1, uChromaDst2, vChromaDst1,
2301 vChromaDst2, width);
2304static inline pstatus_t general_RGBToAVC444YUVv2_BGRX(
const BYTE* WINPR_RESTRICT pSrc,
2305 UINT32 srcStep, BYTE* WINPR_RESTRICT pDst1[3],
2306 const UINT32 dst1Step[3],
2307 BYTE* WINPR_RESTRICT pDst2[3],
2308 const UINT32 dst2Step[3],
2311 if (roi->height < 1 || roi->width < 1)
2312 return !PRIMITIVES_SUCCESS;
2315 for (; y < roi->height - roi->height % 2; y += 2)
2317 const BYTE* srcEven = (pSrc + y * srcStep);
2318 const BYTE* srcOdd = (srcEven + srcStep);
2319 BYTE* dstLumaYEven = (pDst1[0] + y * dst1Step[0]);
2320 BYTE* dstLumaYOdd = (dstLumaYEven + dst1Step[0]);
2321 BYTE* dstLumaU = (pDst1[1] + (y / 2) * dst1Step[1]);
2322 BYTE* dstLumaV = (pDst1[2] + (y / 2) * dst1Step[2]);
2323 BYTE* dstEvenChromaY1 = (pDst2[0] + y * dst2Step[0]);
2324 BYTE* dstEvenChromaY2 = dstEvenChromaY1 + roi->width / 2;
2325 BYTE* dstOddChromaY1 = dstEvenChromaY1 + dst2Step[0];
2326 BYTE* dstOddChromaY2 = dstEvenChromaY2 + dst2Step[0];
2327 BYTE* dstChromaU1 = (pDst2[1] + (y / 2) * dst2Step[1]);
2328 BYTE* dstChromaV1 = (pDst2[2] + (y / 2) * dst2Step[2]);
2329 BYTE* dstChromaU2 = dstChromaU1 + roi->width / 4;
2330 BYTE* dstChromaV2 = dstChromaV1 + roi->width / 4;
2331 int_general_RGBToAVC444YUVv2_BGRX_DOUBLE_ROW(
2332 0, srcEven, srcOdd, dstLumaYEven, dstLumaYOdd, dstLumaU, dstLumaV, dstEvenChromaY1,
2333 dstEvenChromaY2, dstOddChromaY1, dstOddChromaY2, dstChromaU1, dstChromaU2, dstChromaV1,
2334 dstChromaV2, roi->width);
2336 for (; y < roi->height; y++)
2338 const BYTE* srcEven = (pSrc + y * srcStep);
2339 BYTE* dstLumaYEven = (pDst1[0] + y * dst1Step[0]);
2340 BYTE* dstLumaU = (pDst1[1] + (y / 2) * dst1Step[1]);
2341 BYTE* dstLumaV = (pDst1[2] + (y / 2) * dst1Step[2]);
2342 BYTE* dstEvenChromaY1 = (pDst2[0] + y * dst2Step[0]);
2343 BYTE* dstEvenChromaY2 = dstEvenChromaY1 + roi->width / 2;
2344 int_general_RGBToAVC444YUVv2_BGRX_DOUBLE_ROW(
2345 0, srcEven,
nullptr, dstLumaYEven,
nullptr, dstLumaU, dstLumaV, dstEvenChromaY1,
2346 dstEvenChromaY2,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, roi->width);
2349 return PRIMITIVES_SUCCESS;
2352static pstatus_t general_RGBToAVC444YUVv2(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcFormat,
2353 UINT32 srcStep, BYTE* WINPR_RESTRICT pDst1[3],
2354 const UINT32 dst1Step[3], BYTE* WINPR_RESTRICT pDst2[3],
2355 const UINT32 dst2Step[3],
2360 case PIXEL_FORMAT_BGRA32:
2361 case PIXEL_FORMAT_BGRX32:
2362 return general_RGBToAVC444YUVv2_BGRX(pSrc, srcStep, pDst1, dst1Step, pDst2, dst2Step,
2366 return general_RGBToAVC444YUVv2_ANY(pSrc, srcFormat, srcStep, pDst1, dst1Step, pDst2,
2370 return !PRIMITIVES_SUCCESS;
2373void primitives_init_YUV(
primitives_t* WINPR_RESTRICT prims)
2375 prims->YUV420ToRGB_8u_P3AC4R = general_YUV420ToRGB_8u_P3AC4R;
2376 prims->YUV444ToRGB_8u_P3AC4R = general_YUV444ToRGB_8u_P3AC4R;
2377 prims->RGBToYUV420_8u_P3AC4R = general_RGBToYUV420_8u_P3AC4R;
2378 prims->RGBToYUV444_8u_P3AC4R = general_RGBToYUV444_8u_P3AC4R;
2379 prims->RGBToI444_8u = general_RGBToI444_8u;
2380 prims->YUV420CombineToYUV444 = general_YUV420CombineToYUV444;
2381 prims->YUV444SplitToYUV420 = general_YUV444SplitToYUV420;
2382 prims->RGBToAVC444YUV = general_RGBToAVC444YUV;
2383 prims->RGBToAVC444YUVv2 = general_RGBToAVC444YUVv2;
2386void primitives_init_YUV_opt(
primitives_t* WINPR_RESTRICT prims)
2388 primitives_init_YUV(prims);
2389 primitives_init_YUV_sse41(prims);
2390 primitives_init_YUV_neon(prims);