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 padHeight = 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 < padHeight; 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;
150 memcpy(pX, Ya, nWidth);
154 for (UINT32 y = 0; y < halfHeight; y++)
156 const UINT32 val2y = (y * 2UL + evenY);
157 const BYTE* Ua = pSrc[1] + 1ULL * y * srcStep[1];
158 const BYTE* Va = pSrc[2] + 1ULL * y * srcStep[2];
159 BYTE* pU = pDst[1] + 1ULL * dstStep[1] * val2y;
160 BYTE* pV = pDst[2] + 1ULL * dstStep[2] * val2y;
162 for (UINT32 x = 0; x < halfWidth; x++)
164 const UINT32 val2x1 = (x * 2 + oddX);
170 return PRIMITIVES_SUCCESS;
173static inline pstatus_t general_ChromaV2ToYUV444(
const BYTE* WINPR_RESTRICT pSrc[3],
174 const UINT32 srcStep[3], UINT32 nTotalWidth,
175 WINPR_ATTR_UNUSED UINT32 nTotalHeight,
176 BYTE* WINPR_RESTRICT pDst[3],
177 const UINT32 dstStep[3],
180 const UINT32 nWidth = roi->right - roi->left;
181 const UINT32 nHeight = roi->bottom - roi->top;
182 const UINT32 halfWidth = (nWidth + 1) / 2;
183 const UINT32 halfHeight = (nHeight + 1) / 2;
184 const UINT32 quaterWidth = (nWidth + 3) / 4;
187 for (UINT32 y = 0; y < nHeight; y++)
189 const UINT32 yTop = y + roi->top;
190 const BYTE* pYaU = pSrc[0] + 1ULL * srcStep[0] * yTop + roi->left / 2;
191 const BYTE* pYaV = pYaU + nTotalWidth / 2;
192 BYTE* pU = pDst[1] + 1ULL * dstStep[1] * yTop + roi->left;
193 BYTE* pV = pDst[2] + 1ULL * dstStep[2] * yTop + roi->left;
195 for (UINT32 x = 0; x < halfWidth; x++)
197 const UINT32 odd = 2UL * x + 1UL;
204 for (
size_t y = 0; y < halfHeight; y++)
206 const BYTE* pUaU = pSrc[1] + srcStep[1] * (y + roi->top / 2) + roi->left / 4;
207 const BYTE* pUaV = pUaU + nTotalWidth / 4;
208 const BYTE* pVaU = pSrc[2] + srcStep[2] * (y + roi->top / 2) + roi->left / 4;
209 const BYTE* pVaV = pVaU + nTotalWidth / 4;
210 BYTE* pU = pDst[1] + 1ULL * dstStep[1] * (2ULL * y + 1 + roi->top) + roi->left;
211 BYTE* pV = pDst[2] + 1ULL * dstStep[2] * (2ULL * y + 1 + roi->top) + roi->left;
213 for (
size_t x = 0; x < quaterWidth; x++)
215 pU[4 * x + 0] = *pUaU++;
216 pV[4 * x + 0] = *pUaV++;
217 pU[4 * x + 2] = *pVaU++;
218 pV[4 * x + 2] = *pVaV++;
222 return PRIMITIVES_SUCCESS;
225static pstatus_t general_YUV420CombineToYUV444(avc444_frame_type type,
226 const BYTE* WINPR_RESTRICT pSrc[3],
227 const UINT32 srcStep[3], UINT32 nWidth,
228 UINT32 nHeight, BYTE* WINPR_RESTRICT pDst[3],
229 const UINT32 dstStep[3],
232 if (!pSrc || !pSrc[0] || !pSrc[1] || !pSrc[2])
235 if (!pDst || !pDst[0] || !pDst[1] || !pDst[2])
244 return general_LumaToYUV444(pSrc, srcStep, pDst, dstStep, roi);
246 case AVC444_CHROMAv1:
247 return general_ChromaV1ToYUV444(pSrc, srcStep, pDst, dstStep, roi);
249 case AVC444_CHROMAv2:
250 return general_ChromaV2ToYUV444(pSrc, srcStep, nWidth, nHeight, pDst, dstStep, roi);
258general_YUV444SplitToYUV420(
const BYTE* WINPR_RESTRICT pSrc[3],
const UINT32 srcStep[3],
259 BYTE* WINPR_RESTRICT pMainDst[3],
const UINT32 dstMainStep[3],
260 BYTE* WINPR_RESTRICT pAuxDst[3],
const UINT32 dstAuxStep[3],
268 const UINT32 padHeight = roi->height + 16 - roi->height % 16;
269 const UINT32 halfWidth = (roi->width + 1) / 2;
270 const UINT32 halfHeight = (roi->height + 1) / 2;
273 for (
size_t y = 0; y < roi->height; y++)
275 const BYTE* pSrcY = pSrc[0] + y * srcStep[0];
276 BYTE* pY = pMainDst[0] + y * dstMainStep[0];
277 memcpy(pY, pSrcY, roi->width);
281 for (
size_t y = 0; y < halfHeight; y++)
283 const BYTE* pSrcU = pSrc[1] + 2ULL * y * srcStep[1];
284 const BYTE* pSrcV = pSrc[2] + 2ULL * y * srcStep[2];
285 BYTE* pU = pMainDst[1] + y * dstMainStep[1];
286 BYTE* pV = pMainDst[2] + y * dstMainStep[2];
288 for (
size_t x = 0; x < halfWidth; x++)
290 pU[x] = pSrcV[2 * x];
291 pV[x] = pSrcU[2 * x];
296 for (
size_t y = 0; y < padHeight; y++)
298 BYTE* pY = pAuxDst[0] + y * dstAuxStep[0];
302 const size_t pos = (2 * uY++ + 1);
303 const BYTE* pSrcU = pSrc[1] + pos * srcStep[1];
305 if (pos >= roi->height)
308 memcpy(pY, pSrcU, roi->width);
312 const size_t pos = (2 * vY++ + 1);
313 const BYTE* pSrcV = pSrc[2] + pos * srcStep[2];
315 if (pos >= roi->height)
318 memcpy(pY, pSrcV, roi->width);
323 for (
size_t y = 0; y < halfHeight; y++)
325 const BYTE* pSrcU = pSrc[1] + 2 * y * srcStep[1];
326 const BYTE* pSrcV = pSrc[2] + 2 * y * srcStep[2];
327 BYTE* pU = pAuxDst[1] + y * dstAuxStep[1];
328 BYTE* pV = pAuxDst[2] + y * dstAuxStep[2];
330 for (
size_t x = 0; x < halfWidth; x++)
332 pU[x] = pSrcU[2 * x + 1];
333 pV[x] = pSrcV[2 * x + 1];
337 return PRIMITIVES_SUCCESS;
340static inline void general_YUV444ToRGB_DOUBLE_ROW(BYTE* WINPR_RESTRICT pRGB[2], UINT32 DstFormat,
341 const BYTE* WINPR_RESTRICT pY[2],
342 const BYTE* WINPR_RESTRICT pU[2],
343 const BYTE* WINPR_RESTRICT pV[2],
size_t nWidth)
345 fkt_writePixel writePixel = getPixelWriteFunction(DstFormat, FALSE);
347 WINPR_ASSERT(nWidth % 2 == 0);
348 for (
size_t x = 0; x < nWidth; x += 2)
350 for (
size_t i = 0; i < 2; i++)
352 for (
size_t j = 0; j < 2; j++)
354 const BYTE y = pY[i][x + j];
355 INT32 u = pU[i][x + j];
356 INT32 v = pV[i][x + j];
357 if ((i == 0) && (j == 0))
359 const INT32 subU = (INT32)pU[0][x + 1] + pU[1][x] + pU[1][x + 1];
360 const INT32 avgU = ((4 * u) - subU);
361 u = CONDITIONAL_CLIP(avgU, WINPR_ASSERTING_INT_CAST(BYTE, u));
363 const INT32 subV = (INT32)pV[0][x + 1] + pV[1][x] + pV[1][x + 1];
364 const INT32 avgV = ((4 * v) - subV);
365 v = CONDITIONAL_CLIP(avgV, WINPR_ASSERTING_INT_CAST(BYTE, v));
367 pRGB[i] = writeYUVPixel(pRGB[i], DstFormat, y, u, v, writePixel);
373static inline void general_YUV444ToRGB_SINGLE_ROW(BYTE* WINPR_RESTRICT pRGB, UINT32 DstFormat,
374 const BYTE* WINPR_RESTRICT pY,
375 const BYTE* WINPR_RESTRICT pU,
376 const BYTE* WINPR_RESTRICT pV,
size_t nWidth)
378 fkt_writePixel writePixel = getPixelWriteFunction(DstFormat, FALSE);
380 WINPR_ASSERT(nWidth % 2 == 0);
381 for (
size_t x = 0; x < nWidth; x += 2)
383 for (
size_t j = 0; j < 2; j++)
385 const BYTE y = pY[x + j];
386 const BYTE u = pU[x + j];
387 const BYTE v = pV[x + j];
388 pRGB = writeYUVPixel(pRGB, DstFormat, y, u, v, writePixel);
393static inline pstatus_t general_YUV444ToRGB_8u_P3AC4R_general(
const BYTE* WINPR_RESTRICT pSrc[3],
394 const UINT32 srcStep[3],
395 BYTE* WINPR_RESTRICT pDst,
396 UINT32 dstStep, UINT32 DstFormat,
403 const UINT32 nWidth = roi->width;
404 const UINT32 nHeight = roi->height;
407 for (; y < nHeight - nHeight % 2; y += 2)
409 const BYTE* WINPR_RESTRICT pY[2] = { pSrc[0] + y * srcStep[0],
410 pSrc[0] + (y + 1) * srcStep[0] };
411 const BYTE* WINPR_RESTRICT pU[2] = { pSrc[1] + y * srcStep[1],
412 pSrc[1] + (y + 1) * srcStep[1] };
413 const BYTE* WINPR_RESTRICT pV[2] = { pSrc[2] + y * srcStep[2],
414 pSrc[2] + (y + 1) * srcStep[2] };
415 BYTE* WINPR_RESTRICT pRGB[] = { pDst + y * dstStep, pDst + (y + 1) * dstStep };
417 general_YUV444ToRGB_DOUBLE_ROW(pRGB, DstFormat, pY, pU, pV, nWidth);
419 for (; y < nHeight; y++)
421 const BYTE* WINPR_RESTRICT pY = pSrc[0] + y * srcStep[0];
422 const BYTE* WINPR_RESTRICT pU = pSrc[1] + y * srcStep[1];
423 const BYTE* WINPR_RESTRICT pV = pSrc[2] + y * srcStep[2];
424 BYTE* WINPR_RESTRICT pRGB = pDst + y * dstStep;
426 general_YUV444ToRGB_SINGLE_ROW(pRGB, DstFormat, pY, pU, pV, nWidth);
429 return PRIMITIVES_SUCCESS;
432static inline void general_YUV444ToBGRX_DOUBLE_ROW(BYTE* WINPR_RESTRICT pRGB[2], UINT32 DstFormat,
433 const BYTE* WINPR_RESTRICT pY[2],
434 const BYTE* WINPR_RESTRICT pU[2],
435 const BYTE* WINPR_RESTRICT pV[2],
size_t nWidth)
437 WINPR_ASSERT(nWidth % 2 == 0);
438 for (
size_t x = 0; x < nWidth; x += 2)
440 const INT32 subU = pU[0][x + 1] + pU[1][x] + pU[1][x + 1];
441 const INT32 avgU = ((4 * pU[0][x]) - subU);
442 const BYTE useU = CONDITIONAL_CLIP(avgU, pU[0][x]);
443 const INT32 subV = pV[0][x + 1] + pV[1][x] + pV[1][x + 1];
444 const INT32 avgV = ((4 * pV[0][x]) - subV);
445 const BYTE useV = CONDITIONAL_CLIP(avgV, pV[0][x]);
447 const BYTE U[2][2] = { { useU, pU[0][x + 1] }, { pU[1][x], pU[1][x + 1] } };
448 const BYTE V[2][2] = { { useV, pV[0][x + 1] }, { pV[1][x], pV[1][x + 1] } };
450 for (
size_t i = 0; i < 2; i++)
452 for (
size_t j = 0; j < 2; j++)
454 const BYTE y = pY[i][x + j];
455 const BYTE u = U[i][j];
456 const BYTE v = V[i][j];
457 pRGB[i] = writeYUVPixel(pRGB[i], DstFormat, y, u, v, writePixelBGRX);
463static inline void general_YUV444ToBGRX_SINGLE_ROW(BYTE* WINPR_RESTRICT pRGB, UINT32 DstFormat,
464 const BYTE* WINPR_RESTRICT pY,
465 const BYTE* WINPR_RESTRICT pU,
466 const BYTE* WINPR_RESTRICT pV,
size_t nWidth)
468 WINPR_ASSERT(nWidth % 2 == 0);
469 for (
size_t x = 0; x < nWidth; x += 2)
471 for (
size_t j = 0; j < 2; j++)
473 const BYTE Y = pY[x + j];
474 const BYTE U = pU[x + j];
475 const BYTE V = pV[x + j];
476 pRGB = writeYUVPixel(pRGB, DstFormat, Y, U, V, writePixelBGRX);
481static inline pstatus_t general_YUV444ToRGB_8u_P3AC4R_BGRX(
const BYTE* WINPR_RESTRICT pSrc[3],
482 const UINT32 srcStep[3],
483 BYTE* WINPR_RESTRICT pDst,
484 UINT32 dstStep, UINT32 DstFormat,
491 const UINT32 nWidth = roi->width;
492 const UINT32 nHeight = roi->height;
495 for (; y < nHeight - nHeight % 2; y += 2)
497 const BYTE* pY[2] = { pSrc[0] + y * srcStep[0], pSrc[0] + (y + 1) * srcStep[0] };
498 const BYTE* pU[2] = { pSrc[1] + y * srcStep[1], pSrc[1] + (y + 1) * srcStep[1] };
499 const BYTE* pV[2] = { pSrc[2] + y * srcStep[2], pSrc[2] + (y + 1) * srcStep[2] };
500 BYTE* pRGB[] = { pDst + y * dstStep, pDst + (y + 1) * dstStep };
502 general_YUV444ToBGRX_DOUBLE_ROW(pRGB, DstFormat, pY, pU, pV, nWidth);
505 for (; y < nHeight; y++)
507 const BYTE* WINPR_RESTRICT pY = pSrc[0] + y * srcStep[0];
508 const BYTE* WINPR_RESTRICT pU = pSrc[1] + y * srcStep[1];
509 const BYTE* WINPR_RESTRICT pV = pSrc[2] + y * srcStep[2];
510 BYTE* WINPR_RESTRICT pRGB = pDst + y * dstStep;
512 general_YUV444ToBGRX_SINGLE_ROW(pRGB, DstFormat, pY, pU, pV, nWidth);
514 return PRIMITIVES_SUCCESS;
517static pstatus_t general_YUV444ToRGB_8u_P3AC4R(
const BYTE* WINPR_RESTRICT pSrc[3],
518 const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pDst,
519 UINT32 dstStep, UINT32 DstFormat,
524 case PIXEL_FORMAT_BGRA32:
525 case PIXEL_FORMAT_BGRX32:
526 return general_YUV444ToRGB_8u_P3AC4R_BGRX(pSrc, srcStep, pDst, dstStep, DstFormat, roi);
529 return general_YUV444ToRGB_8u_P3AC4R_general(pSrc, srcStep, pDst, dstStep, DstFormat,
538static void general_YUV420ToRGB_8u_P3AC4R_double_line(BYTE* WINPR_RESTRICT pEven,
539 BYTE* WINPR_RESTRICT pOdd, UINT32 DstFormat,
540 const BYTE* WINPR_RESTRICT pYeven,
541 const BYTE* WINPR_RESTRICT pYodd,
542 const BYTE* WINPR_RESTRICT pU,
543 const BYTE* WINPR_RESTRICT pV, UINT32 width,
544 fkt_writePixel writePixel, UINT32 formatSize)
548 for (; x < width / 2; x++)
550 const BYTE U = pU[x];
551 const BYTE V = pV[x];
552 const BYTE eY0 = pYeven[2ULL * x + 0];
553 const BYTE eY1 = pYeven[2ULL * x + 1];
554 writeYUVPixel(&pEven[2ULL * x * formatSize], DstFormat, eY0, U, V, writePixel);
555 writeYUVPixel(&pEven[(2ULL * x + 1) * formatSize], DstFormat, eY1, U, V, writePixel);
557 const BYTE oY0 = pYodd[2ULL * x + 0];
558 const BYTE oY1 = pYodd[2ULL * x + 1];
559 writeYUVPixel(&pOdd[2ULL * x * formatSize], DstFormat, oY0, U, V, writePixel);
560 writeYUVPixel(&pOdd[(2ULL * x + 1) * formatSize], DstFormat, oY1, U, V, writePixel);
563 for (; x < (width + 1) / 2; x++)
565 const BYTE U = pU[x];
566 const BYTE V = pV[x];
567 const BYTE eY0 = pYeven[2ULL * x + 0];
568 writeYUVPixel(&pEven[2ULL * x * formatSize], DstFormat, eY0, U, V, writePixel);
570 const BYTE oY0 = pYodd[2ULL * x + 0];
571 writeYUVPixel(&pOdd[2ULL * x * formatSize], DstFormat, oY0, U, V, writePixel);
575static void general_YUV420ToRGB_8u_P3AC4R_single_line(BYTE* WINPR_RESTRICT pEven, UINT32 DstFormat,
576 const BYTE* WINPR_RESTRICT pYeven,
577 const BYTE* WINPR_RESTRICT pU,
578 const BYTE* WINPR_RESTRICT pV, UINT32 width,
579 fkt_writePixel writePixel, UINT32 formatSize)
583 for (; x < width / 2; x++)
585 const BYTE U = pU[x];
586 const BYTE V = pV[x];
587 const BYTE eY0 = pYeven[2ULL * x + 0];
588 const BYTE eY1 = pYeven[2ULL * x + 1];
589 writeYUVPixel(&pEven[2ULL * x * formatSize], DstFormat, eY0, U, V, writePixel);
590 writeYUVPixel(&pEven[(2ULL * x + 1) * formatSize], DstFormat, eY1, U, V, writePixel);
593 for (; x < (width + 1) / 2; x++)
595 const BYTE U = pU[x];
596 const BYTE V = pV[x];
597 const BYTE eY0 = pYeven[2ULL * x + 0];
598 writeYUVPixel(&pEven[2ULL * x * formatSize], DstFormat, eY0, U, V, writePixel);
602static pstatus_t general_YUV420ToRGB_8u_P3AC4R(
const BYTE* WINPR_RESTRICT pSrc[3],
603 const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pDst,
604 UINT32 dstStep, UINT32 DstFormat,
608 const DWORD formatSize = FreeRDPGetBytesPerPixel(DstFormat);
609 fkt_writePixel writePixel = getPixelWriteFunction(DstFormat, FALSE);
610 const UINT32 nWidth = roi->width;
611 const UINT32 nHeight = roi->height;
614 for (; y < nHeight / 2; y++)
616 const BYTE* pYe = &pSrc[0][(2ULL * y + 0) * srcStep[0]];
617 const BYTE* pYo = &pSrc[0][(2ULL * y + 1) * srcStep[0]];
618 const BYTE* pU = &pSrc[1][1ULL * srcStep[1] * y];
619 const BYTE* pV = &pSrc[2][1ULL * srcStep[2] * y];
620 BYTE* pRGBeven = &pDst[2ULL * y * dstStep];
621 BYTE* pRGBodd = &pDst[(2ULL * y + 1) * dstStep];
622 general_YUV420ToRGB_8u_P3AC4R_double_line(pRGBeven, pRGBodd, DstFormat, pYe, pYo, pU, pV,
623 nWidth, writePixel, formatSize);
627 for (; y < (nHeight + 1) / 2; y++)
629 const BYTE* pY = &pSrc[0][2ULL * srcStep[0] * y];
630 const BYTE* pU = &pSrc[1][1ULL * srcStep[1] * y];
631 const BYTE* pV = &pSrc[2][1ULL * srcStep[2] * y];
632 BYTE* pEven = &pDst[2ULL * y * dstStep];
634 general_YUV420ToRGB_8u_P3AC4R_single_line(pEven, DstFormat, pY, pU, pV, nWidth, writePixel,
638 return PRIMITIVES_SUCCESS;
641static inline void BGRX_fillYUV(
size_t offset,
const BYTE* WINPR_RESTRICT pRGB[2],
642 BYTE* WINPR_RESTRICT pY[2], BYTE* WINPR_RESTRICT pU[2],
643 BYTE* WINPR_RESTRICT pV[2])
650 const UINT32 SrcFormat = PIXEL_FORMAT_BGRX32;
651 const UINT32 bpp = 4;
653 for (
size_t i = 0; i < 2; i++)
655 for (
size_t j = 0; j < 2; j++)
660 const UINT32 color = FreeRDPReadColor(&pRGB[i][(offset + j) * bpp], SrcFormat);
661 FreeRDPSplitColor(color, SrcFormat, &R, &G, &B,
nullptr,
nullptr);
662 pY[i][offset + j] = RGB2Y(R, G, B);
663 pU[i][offset + j] = RGB2U(R, G, B);
664 pV[i][offset + j] = RGB2V(R, G, B);
669 const INT32 avgU = (pU[0][offset] + pU[0][offset + 1] + pU[1][offset] + pU[1][offset + 1]) / 4;
670 pU[0][offset] = CONDITIONAL_CLIP(avgU, pU[0][offset]);
671 const INT32 avgV = (pV[0][offset] + pV[0][offset + 1] + pV[1][offset] + pV[1][offset + 1]) / 4;
672 pV[0][offset] = CONDITIONAL_CLIP(avgV, pV[0][offset]);
675static inline void BGRX_fillYUV_single(
size_t offset,
const BYTE* WINPR_RESTRICT pRGB,
676 BYTE* WINPR_RESTRICT pY, BYTE* WINPR_RESTRICT pU,
677 BYTE* WINPR_RESTRICT pV)
684 const UINT32 SrcFormat = PIXEL_FORMAT_BGRX32;
685 const UINT32 bpp = 4;
687 for (
size_t j = 0; j < 2; j++)
692 const UINT32 color = FreeRDPReadColor(&pRGB[(offset + j) * bpp], SrcFormat);
693 FreeRDPSplitColor(color, SrcFormat, &R, &G, &B,
nullptr,
nullptr);
694 pY[offset + j] = RGB2Y(R, G, B);
695 pU[offset + j] = RGB2U(R, G, B);
696 pV[offset + j] = RGB2V(R, G, B);
700static inline void general_BGRXToYUV444_DOUBLE_ROW(
const BYTE* WINPR_RESTRICT pRGB[2],
701 BYTE* WINPR_RESTRICT pY[2],
702 BYTE* WINPR_RESTRICT pU[2],
703 BYTE* WINPR_RESTRICT pV[2], UINT32 nWidth)
706 WINPR_ASSERT((nWidth % 2) == 0);
707 for (
size_t x = 0; x < nWidth; x += 2)
709 BGRX_fillYUV(x, pRGB, pY, pU, pV);
713static inline void general_BGRXToYUV444_SINGLE_ROW(
const BYTE* WINPR_RESTRICT pRGB,
714 BYTE* WINPR_RESTRICT pY, BYTE* WINPR_RESTRICT pU,
715 BYTE* WINPR_RESTRICT pV, UINT32 nWidth)
718 WINPR_ASSERT((nWidth % 2) == 0);
719 for (
size_t x = 0; x < nWidth; x += 2)
721 BGRX_fillYUV_single(x, pRGB, pY, pU, pV);
725static inline pstatus_t general_RGBToYUV444_8u_P3AC4R_BGRX(
const BYTE* WINPR_RESTRICT pSrc,
726 const UINT32 srcStep,
727 BYTE* WINPR_RESTRICT pDst[3],
728 const UINT32 dstStep[3],
731 const UINT32 nWidth = roi->width;
732 const UINT32 nHeight = roi->height;
735 for (; y < nHeight - nHeight % 2; y += 2)
737 const BYTE* pRGB[] = { pSrc + y * srcStep, pSrc + (y + 1) * srcStep };
738 BYTE* pY[] = { pDst[0] + y * dstStep[0], pDst[0] + (y + 1) * dstStep[0] };
739 BYTE* pU[] = { pDst[1] + y * dstStep[1], pDst[1] + (y + 1) * dstStep[1] };
740 BYTE* pV[] = { pDst[2] + y * dstStep[2], pDst[2] + (y + 1) * dstStep[2] };
742 general_BGRXToYUV444_DOUBLE_ROW(pRGB, pY, pU, pV, nWidth);
745 for (; y < nHeight; y++)
747 const BYTE* pRGB = pSrc + y * srcStep;
748 BYTE* pY = pDst[0] + y * dstStep[0];
749 BYTE* pU = pDst[1] + y * dstStep[1];
750 BYTE* pV = pDst[2] + y * dstStep[2];
752 general_BGRXToYUV444_SINGLE_ROW(pRGB, pY, pU, pV, nWidth);
755 return PRIMITIVES_SUCCESS;
758static inline void fillYUV(
size_t offset,
const BYTE* WINPR_RESTRICT pRGB[2], UINT32 SrcFormat,
759 BYTE* WINPR_RESTRICT pY[2], BYTE* WINPR_RESTRICT pU[2],
760 BYTE* WINPR_RESTRICT pV[2])
766 const UINT32 bpp = FreeRDPGetBytesPerPixel(SrcFormat);
770 for (
size_t i = 0; i < 2; i++)
772 for (
size_t j = 0; j < 2; j++)
777 const UINT32 color = FreeRDPReadColor(&pRGB[i][(offset + j) * bpp], SrcFormat);
778 FreeRDPSplitColor(color, SrcFormat, &R, &G, &B,
nullptr,
nullptr);
779 const BYTE y = RGB2Y(R, G, B);
780 const BYTE u = RGB2U(R, G, B);
781 const BYTE v = RGB2V(R, G, B);
784 pY[i][offset + j] = y;
785 pU[i][offset + j] = u;
786 pV[i][offset + j] = v;
792 pU[0][offset] = CLIP(avgU);
795 pV[0][offset] = CLIP(avgV);
798static inline void fillYUV_single(
size_t offset,
const BYTE* WINPR_RESTRICT pRGB, UINT32 SrcFormat,
799 BYTE* WINPR_RESTRICT pY, BYTE* WINPR_RESTRICT pU,
800 BYTE* WINPR_RESTRICT pV)
806 const UINT32 bpp = FreeRDPGetBytesPerPixel(SrcFormat);
808 for (
size_t j = 0; j < 2; j++)
813 const UINT32 color = FreeRDPReadColor(&pRGB[(offset + j) * bpp], SrcFormat);
814 FreeRDPSplitColor(color, SrcFormat, &R, &G, &B,
nullptr,
nullptr);
815 const BYTE y = RGB2Y(R, G, B);
816 const BYTE u = RGB2U(R, G, B);
817 const BYTE v = RGB2V(R, G, B);
824static inline void general_RGBToYUV444_DOUBLE_ROW(
const BYTE* WINPR_RESTRICT pRGB[2],
825 UINT32 SrcFormat, BYTE* WINPR_RESTRICT pY[2],
826 BYTE* WINPR_RESTRICT pU[2],
827 BYTE* WINPR_RESTRICT pV[2], UINT32 nWidth)
830 WINPR_ASSERT((nWidth % 2) == 0);
831 for (
size_t x = 0; x < nWidth; x += 2)
833 fillYUV(x, pRGB, SrcFormat, pY, pU, pV);
837static inline void general_RGBToYUV444_SINGLE_ROW(
const BYTE* WINPR_RESTRICT pRGB, UINT32 SrcFormat,
838 BYTE* WINPR_RESTRICT pY, BYTE* WINPR_RESTRICT pU,
839 BYTE* WINPR_RESTRICT pV, UINT32 nWidth)
842 WINPR_ASSERT((nWidth % 2) == 0);
843 for (
size_t x = 0; x < nWidth; x += 2)
845 fillYUV_single(x, pRGB, SrcFormat, pY, pU, pV);
849static inline pstatus_t general_RGBToYUV444_8u_P3AC4R_RGB(
const BYTE* WINPR_RESTRICT pSrc,
850 UINT32 SrcFormat,
const UINT32 srcStep,
851 BYTE* WINPR_RESTRICT pDst[3],
852 const UINT32 dstStep[3],
855 const UINT32 nWidth = roi->width;
856 const UINT32 nHeight = roi->height;
859 for (; y < nHeight - nHeight % 2; y += 2)
861 const BYTE* pRGB[] = { pSrc + y * srcStep, pSrc + (y + 1) * srcStep };
862 BYTE* pY[] = { &pDst[0][y * dstStep[0]], &pDst[0][(y + 1) * dstStep[0]] };
863 BYTE* pU[] = { &pDst[1][y * dstStep[1]], &pDst[1][(y + 1) * dstStep[1]] };
864 BYTE* pV[] = { &pDst[2][y * dstStep[2]], &pDst[2][(y + 1) * dstStep[2]] };
866 general_RGBToYUV444_DOUBLE_ROW(pRGB, SrcFormat, pY, pU, pV, nWidth);
868 for (; y < nHeight; y++)
870 const BYTE* pRGB = pSrc + y * srcStep;
871 BYTE* pY = &pDst[0][y * dstStep[0]];
872 BYTE* pU = &pDst[1][y * dstStep[1]];
873 BYTE* pV = &pDst[2][y * dstStep[2]];
875 general_RGBToYUV444_SINGLE_ROW(pRGB, SrcFormat, pY, pU, pV, nWidth);
878 return PRIMITIVES_SUCCESS;
881static pstatus_t general_RGBToYUV444_8u_P3AC4R(
const BYTE* WINPR_RESTRICT pSrc, UINT32 SrcFormat,
882 const UINT32 srcStep, BYTE* WINPR_RESTRICT pDst[3],
883 const UINT32 dstStep[3],
888 case PIXEL_FORMAT_BGRA32:
889 case PIXEL_FORMAT_BGRX32:
890 return general_RGBToYUV444_8u_P3AC4R_BGRX(pSrc, srcStep, pDst, dstStep, roi);
892 return general_RGBToYUV444_8u_P3AC4R_RGB(pSrc, SrcFormat, srcStep, pDst, dstStep, roi);
896static inline void fillI444_single(
size_t offset,
const BYTE* WINPR_RESTRICT pRGB, UINT32 SrcFormat,
897 BYTE* WINPR_RESTRICT pY, BYTE* WINPR_RESTRICT pU,
898 BYTE* WINPR_RESTRICT pV)
905 const UINT32 bpp = FreeRDPGetBytesPerPixel(SrcFormat);
910 const UINT32 color = FreeRDPReadColor(&pRGB[offset * bpp], SrcFormat);
911 FreeRDPSplitColor(color, SrcFormat, &R, &G, &B,
nullptr,
nullptr);
912 const BYTE y = RGB2Y(R, G, B);
913 const BYTE u = RGB2U(R, G, B);
914 const BYTE v = RGB2V(R, G, B);
920static inline void general_RGBToI444_SINGLE_ROW(
const BYTE* WINPR_RESTRICT pRGB, UINT32 SrcFormat,
921 BYTE* WINPR_RESTRICT pY, BYTE* WINPR_RESTRICT pU,
922 BYTE* WINPR_RESTRICT pV, UINT32 nWidth)
924 for (
size_t x = 0; x < nWidth; x++)
926 fillI444_single(x, pRGB, SrcFormat, pY, pU, pV);
930static inline pstatus_t general_RGBToI444_8u_RGB(
const BYTE* WINPR_RESTRICT pSrc, UINT32 SrcFormat,
931 const UINT32 srcStep, BYTE* WINPR_RESTRICT pDst[3],
932 const UINT32 dstStep[3],
935 const UINT32 nWidth = roi->width;
936 const UINT32 nHeight = roi->height;
938 for (
size_t y = 0; y < nHeight; y++)
940 const BYTE* pRGB = pSrc + y * srcStep;
941 BYTE* pY = &pDst[0][y * dstStep[0]];
942 BYTE* pU = &pDst[1][y * dstStep[1]];
943 BYTE* pV = &pDst[2][y * dstStep[2]];
945 general_RGBToI444_SINGLE_ROW(pRGB, SrcFormat, pY, pU, pV, nWidth);
948 return PRIMITIVES_SUCCESS;
951static pstatus_t general_RGBToI444_8u(
const BYTE* WINPR_RESTRICT pSrc, UINT32 SrcFormat,
952 const UINT32 srcStep, BYTE* WINPR_RESTRICT pDst[3],
953 const UINT32 dstStep[3],
959 return general_RGBToI444_8u_RGB(pSrc, SrcFormat, srcStep, pDst, dstStep, roi);
963static inline pstatus_t general_RGBToYUV420_BGRX(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcStep,
964 BYTE* WINPR_RESTRICT pDst[3],
965 const UINT32 dstStep[3],
971 size_t x4 = srcStep + 4;
974 size_t y3 = dstStep[0];
975 size_t y4 = dstStep[0] + 1;
976 UINT32 max_x = roi->width - 1;
979 for (
size_t i = 0; y < roi->height - roi->height % 2; y += 2, i++)
981 const BYTE* src = pSrc + y * srcStep;
982 BYTE* ydst = pDst[0] + y * dstStep[0];
983 BYTE* udst = pDst[1] + i * dstStep[1];
984 BYTE* vdst = pDst[2] + i * dstStep[2];
986 for (
size_t x = 0; x < roi->width; x += 2)
995 Ba = B = *(src + x1 + 0);
996 Ga = G = *(src + x1 + 1);
997 Ra = R = *(src + x1 + 2);
998 ydst[y1] = RGB2Y(R, G, B);
1003 Ba += B = *(src + x2 + 0);
1004 Ga += G = *(src + x2 + 1);
1005 Ra += R = *(src + x2 + 2);
1006 ydst[y2] = RGB2Y(R, G, B);
1010 Ba += B = *(src + x3 + 0);
1011 Ga += G = *(src + x3 + 1);
1012 Ra += R = *(src + x3 + 2);
1013 ydst[y3] = RGB2Y(R, G, B);
1018 Ba += B = *(src + x4 + 0);
1019 Ga += G = *(src + x4 + 1);
1020 Ra += R = *(src + x4 + 2);
1021 ydst[y4] = RGB2Y(R, G, B);
1027 *udst++ = RGB2U(Ra, Ga, Ba);
1028 *vdst++ = RGB2V(Ra, Ga, Ba);
1034 for (; y < roi->height; y++)
1036 const BYTE* src = pSrc + y * srcStep;
1037 BYTE* ydst = pDst[0] + y * dstStep[0];
1038 BYTE* udst = pDst[1] + (y / 2) * dstStep[1];
1039 BYTE* vdst = pDst[2] + (y / 2) * dstStep[2];
1041 for (
size_t x = 0; x < roi->width; x += 2)
1050 Ba = B = *(src + x1 + 0);
1051 Ga = G = *(src + x1 + 1);
1052 Ra = R = *(src + x1 + 2);
1053 ydst[y1] = RGB2Y(R, G, B);
1058 Ba += B = *(src + x2 + 0);
1059 Ga += G = *(src + x2 + 1);
1060 Ra += R = *(src + x2 + 2);
1061 ydst[y2] = RGB2Y(R, G, B);
1067 *udst++ = RGB2U(Ra, Ga, Ba);
1068 *vdst++ = RGB2V(Ra, Ga, Ba);
1074 return PRIMITIVES_SUCCESS;
1077static inline pstatus_t general_RGBToYUV420_RGBX(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcStep,
1078 BYTE* WINPR_RESTRICT pDst[3],
1079 const UINT32 dstStep[3],
1084 size_t x3 = srcStep;
1085 size_t x4 = srcStep + 4;
1088 size_t y3 = dstStep[0];
1089 size_t y4 = dstStep[0] + 1;
1090 UINT32 max_x = roi->width - 1;
1093 for (
size_t i = 0; y < roi->height - roi->height % 2; y += 2, i++)
1095 const BYTE* src = pSrc + y * srcStep;
1096 BYTE* ydst = pDst[0] + y * dstStep[0];
1097 BYTE* udst = pDst[1] + i * dstStep[1];
1098 BYTE* vdst = pDst[2] + i * dstStep[2];
1100 for (UINT32 x = 0; x < roi->width; x += 2)
1102 BYTE R = *(src + x1 + 0);
1103 BYTE G = *(src + x1 + 1);
1104 BYTE B = *(src + x1 + 2);
1109 ydst[y1] = RGB2Y(R, G, B);
1114 R = *(src + x2 + 0);
1115 G = *(src + x2 + 1);
1116 B = *(src + x2 + 2);
1120 ydst[y2] = RGB2Y(R, G, B);
1124 R = *(src + x3 + 0);
1125 G = *(src + x3 + 1);
1126 B = *(src + x3 + 2);
1131 ydst[y3] = RGB2Y(R, G, B);
1136 R = *(src + x4 + 0);
1137 G = *(src + x4 + 1);
1138 B = *(src + x4 + 2);
1143 ydst[y4] = RGB2Y(R, G, B);
1149 *udst++ = RGB2U(Ra, Ga, Ba);
1150 *vdst++ = RGB2V(Ra, Ga, Ba);
1156 for (; y < roi->height; y++)
1158 const BYTE* src = pSrc + y * srcStep;
1159 BYTE* ydst = pDst[0] + y * dstStep[0];
1160 BYTE* udst = pDst[1] + (y / 2) * dstStep[1];
1161 BYTE* vdst = pDst[2] + (y / 2) * dstStep[2];
1163 for (UINT32 x = 0; x < roi->width; x += 2)
1165 BYTE R = *(src + x1 + 0);
1166 BYTE G = *(src + x1 + 1);
1167 BYTE B = *(src + x1 + 2);
1172 ydst[y1] = RGB2Y(R, G, B);
1177 R = *(src + x2 + 0);
1178 G = *(src + x2 + 1);
1179 B = *(src + x2 + 2);
1183 ydst[y2] = RGB2Y(R, G, B);
1189 *udst++ = RGB2U(Ra, Ga, Ba);
1190 *vdst++ = RGB2V(Ra, Ga, Ba);
1196 return PRIMITIVES_SUCCESS;
1199static inline pstatus_t general_RGBToYUV420_ANY(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcFormat,
1200 UINT32 srcStep, BYTE* WINPR_RESTRICT pDst[3],
1201 const UINT32 dstStep[3],
1204 const UINT32 bpp = FreeRDPGetBytesPerPixel(srcFormat);
1207 size_t x3 = srcStep;
1208 size_t x4 = srcStep + bpp;
1211 size_t y3 = dstStep[0];
1212 size_t y4 = dstStep[0] + 1;
1213 UINT32 max_x = roi->width - 1;
1216 for (
size_t i = 0; y < roi->height - roi->height % 2; y += 2, i++)
1218 const BYTE* src = pSrc + y * srcStep;
1219 BYTE* ydst = pDst[0] + y * dstStep[0];
1220 BYTE* udst = pDst[1] + i * dstStep[1];
1221 BYTE* vdst = pDst[2] + i * dstStep[2];
1223 for (
size_t x = 0; x < roi->width; x += 2)
1233 color = FreeRDPReadColor(src + x1, srcFormat);
1234 FreeRDPSplitColor(color, srcFormat, &R, &G, &B,
nullptr,
nullptr);
1238 ydst[y1] = RGB2Y(R, G, B);
1243 color = FreeRDPReadColor(src + x2, srcFormat);
1244 FreeRDPSplitColor(color, srcFormat, &R, &G, &B,
nullptr,
nullptr);
1248 ydst[y2] = RGB2Y(R, G, B);
1252 color = FreeRDPReadColor(src + x3, srcFormat);
1253 FreeRDPSplitColor(color, srcFormat, &R, &G, &B,
nullptr,
nullptr);
1257 ydst[y3] = RGB2Y(R, G, B);
1262 color = FreeRDPReadColor(src + x4, srcFormat);
1263 FreeRDPSplitColor(color, srcFormat, &R, &G, &B,
nullptr,
nullptr);
1267 ydst[y4] = RGB2Y(R, G, B);
1273 *udst++ = RGB2U(Ra, Ga, Ba);
1274 *vdst++ = RGB2V(Ra, Ga, Ba);
1280 for (; y < roi->height; y++)
1282 const BYTE* src = pSrc + y * srcStep;
1283 BYTE* ydst = pDst[0] + y * dstStep[0];
1284 BYTE* udst = pDst[1] + (y / 2) * dstStep[1];
1285 BYTE* vdst = pDst[2] + (y / 2) * dstStep[2];
1287 for (
size_t x = 0; x < roi->width; x += 2)
1293 UINT32 color = FreeRDPReadColor(src + x1, srcFormat);
1294 FreeRDPSplitColor(color, srcFormat, &R, &G, &B,
nullptr,
nullptr);
1298 ydst[y1] = RGB2Y(R, G, B);
1303 color = FreeRDPReadColor(src + x2, srcFormat);
1304 FreeRDPSplitColor(color, srcFormat, &R, &G, &B,
nullptr,
nullptr);
1308 ydst[y2] = RGB2Y(R, G, B);
1314 *udst++ = RGB2U(Ra, Ga, Ba);
1315 *vdst++ = RGB2V(Ra, Ga, Ba);
1321 return PRIMITIVES_SUCCESS;
1324static pstatus_t general_RGBToYUV420_8u_P3AC4R(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcFormat,
1325 UINT32 srcStep, BYTE* WINPR_RESTRICT pDst[3],
1326 const UINT32 dstStep[3],
1331 case PIXEL_FORMAT_BGRA32:
1332 case PIXEL_FORMAT_BGRX32:
1333 return general_RGBToYUV420_BGRX(pSrc, srcStep, pDst, dstStep, roi);
1335 case PIXEL_FORMAT_RGBA32:
1336 case PIXEL_FORMAT_RGBX32:
1337 return general_RGBToYUV420_RGBX(pSrc, srcStep, pDst, dstStep, roi);
1340 return general_RGBToYUV420_ANY(pSrc, srcFormat, srcStep, pDst, dstStep, roi);
1344static inline void int_general_RGBToAVC444YUV_BGRX_DOUBLE_ROW(
1345 size_t offset,
const BYTE* WINPR_RESTRICT pSrcEven,
const BYTE* WINPR_RESTRICT pSrcOdd,
1346 BYTE* WINPR_RESTRICT b1Even, BYTE* WINPR_RESTRICT b1Odd, BYTE* WINPR_RESTRICT b2,
1347 BYTE* WINPR_RESTRICT b3, BYTE* WINPR_RESTRICT b4, BYTE* WINPR_RESTRICT b5,
1348 BYTE* WINPR_RESTRICT b6, BYTE* WINPR_RESTRICT b7, UINT32 width)
1350 WINPR_ASSERT((width % 2) == 0);
1351 for (
size_t x = offset; x < width; x += 2)
1353 const BYTE* srcEven = &pSrcEven[4ULL * x];
1354 const BYTE* srcOdd = &pSrcOdd[4ULL * x];
1355 const BOOL lastX = (x + 1) >= width;
1370 const BYTE b = *srcEven++;
1371 const BYTE g = *srcEven++;
1372 const BYTE r = *srcEven++;
1374 Y1e = Y2e = Y1o = Y2o = RGB2Y(r, g, b);
1375 U1e = U2e = U1o = U2o = RGB2U(r, g, b);
1376 V1e = V2e = V1o = V2o = RGB2V(r, g, b);
1381 const BYTE b = *srcEven++;
1382 const BYTE g = *srcEven++;
1383 const BYTE r = *srcEven++;
1385 Y2e = RGB2Y(r, g, b);
1386 U2e = RGB2U(r, g, b);
1387 V2e = RGB2V(r, g, b);
1392 const BYTE b = *srcOdd++;
1393 const BYTE g = *srcOdd++;
1394 const BYTE r = *srcOdd++;
1396 Y1o = Y2o = RGB2Y(r, g, b);
1397 U1o = U2o = RGB2U(r, g, b);
1398 V1o = V2o = RGB2V(r, g, b);
1401 if (b1Odd && !lastX)
1403 const BYTE b = *srcOdd++;
1404 const BYTE g = *srcOdd++;
1405 const BYTE r = *srcOdd++;
1407 Y2o = RGB2Y(r, g, b);
1408 U2o = RGB2U(r, g, b);
1409 V2o = RGB2V(r, g, b);
1425 const BYTE Uavg = WINPR_ASSERTING_INT_CAST(BYTE, ((UINT16)U1e + U2e + U1o + U2o) / 4);
1426 const BYTE Vavg = WINPR_ASSERTING_INT_CAST(BYTE, ((UINT16)V1e + V2e + V1o + V2o) / 4);
1453void general_RGBToAVC444YUV_BGRX_DOUBLE_ROW(
size_t offset,
const BYTE* WINPR_RESTRICT pSrcEven,
1454 const BYTE* WINPR_RESTRICT pSrcOdd,
1455 BYTE* WINPR_RESTRICT b1Even, BYTE* WINPR_RESTRICT b1Odd,
1456 BYTE* WINPR_RESTRICT b2, BYTE* WINPR_RESTRICT b3,
1457 BYTE* WINPR_RESTRICT b4, BYTE* WINPR_RESTRICT b5,
1458 BYTE* WINPR_RESTRICT b6, BYTE* WINPR_RESTRICT b7,
1461 int_general_RGBToAVC444YUV_BGRX_DOUBLE_ROW(offset, pSrcEven, pSrcOdd, b1Even, b1Odd, b2, b3, b4,
1465static inline pstatus_t general_RGBToAVC444YUV_BGRX(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcStep,
1466 BYTE* WINPR_RESTRICT pDst1[3],
1467 const UINT32 dst1Step[3],
1468 BYTE* WINPR_RESTRICT pDst2[3],
1469 const UINT32 dst2Step[3],
1477 for (; y < roi->height - roi->height % 2; y += 2)
1479 const BYTE* srcEven = pSrc + 1ULL * y * srcStep;
1480 const BYTE* srcOdd = pSrc + 1ULL * (y + 1) * srcStep;
1481 const size_t i = y >> 1;
1482 const size_t n = (i & (uint32_t)~7) + i;
1483 BYTE* b1Even = pDst1[0] + 1ULL * y * dst1Step[0];
1484 BYTE* b1Odd = (b1Even + dst1Step[0]);
1485 BYTE* b2 = pDst1[1] + 1ULL * (y / 2) * dst1Step[1];
1486 BYTE* b3 = pDst1[2] + 1ULL * (y / 2) * dst1Step[2];
1487 BYTE* b4 = pDst2[0] + 1ULL * dst2Step[0] * n;
1488 BYTE* b5 = b4 + 8ULL * dst2Step[0];
1489 BYTE* b6 = pDst2[1] + 1ULL * (y / 2) * dst2Step[1];
1490 BYTE* b7 = pDst2[2] + 1ULL * (y / 2) * dst2Step[2];
1491 int_general_RGBToAVC444YUV_BGRX_DOUBLE_ROW(0, srcEven, srcOdd, b1Even, b1Odd, b2, b3, b4,
1492 b5, b6, b7, roi->width);
1494 for (; y < roi->height; y++)
1496 const BYTE* srcEven = pSrc + 1ULL * y * srcStep;
1497 BYTE* b1Even = pDst1[0] + 1ULL * y * dst1Step[0];
1498 BYTE* b2 = pDst1[1] + 1ULL * (y / 2) * dst1Step[1];
1499 BYTE* b3 = pDst1[2] + 1ULL * (y / 2) * dst1Step[2];
1500 BYTE* b6 = pDst2[1] + 1ULL * (y / 2) * dst2Step[1];
1501 BYTE* b7 = pDst2[2] + 1ULL * (y / 2) * dst2Step[2];
1502 int_general_RGBToAVC444YUV_BGRX_DOUBLE_ROW(0, srcEven,
nullptr, b1Even,
nullptr, b2, b3,
1503 nullptr,
nullptr, b6, b7, roi->width);
1506 return PRIMITIVES_SUCCESS;
1509static inline void general_RGBToAVC444YUV_RGBX_DOUBLE_ROW(
1510 const BYTE* WINPR_RESTRICT srcEven,
const BYTE* WINPR_RESTRICT srcOdd,
1511 BYTE* WINPR_RESTRICT b1Even, BYTE* WINPR_RESTRICT b1Odd, BYTE* WINPR_RESTRICT b2,
1512 BYTE* WINPR_RESTRICT b3, BYTE* WINPR_RESTRICT b4, BYTE* WINPR_RESTRICT b5,
1513 BYTE* WINPR_RESTRICT b6, BYTE* WINPR_RESTRICT b7, UINT32 width)
1515 WINPR_ASSERT((width % 2) == 0);
1516 for (UINT32 x = 0; x < width; x += 2)
1518 const BOOL lastX = (x + 1) >= width;
1533 const BYTE r = *srcEven++;
1534 const BYTE g = *srcEven++;
1535 const BYTE b = *srcEven++;
1537 Y1e = Y2e = Y1o = Y2o = RGB2Y(r, g, b);
1538 U1e = U2e = U1o = U2o = RGB2U(r, g, b);
1539 V1e = V2e = V1o = V2o = RGB2V(r, g, b);
1544 const BYTE r = *srcEven++;
1545 const BYTE g = *srcEven++;
1546 const BYTE b = *srcEven++;
1548 Y2e = RGB2Y(r, g, b);
1549 U2e = RGB2U(r, g, b);
1550 V2e = RGB2V(r, g, b);
1555 const BYTE r = *srcOdd++;
1556 const BYTE g = *srcOdd++;
1557 const BYTE b = *srcOdd++;
1559 Y1o = Y2o = RGB2Y(r, g, b);
1560 U1o = U2o = RGB2U(r, g, b);
1561 V1o = V2o = RGB2V(r, g, b);
1564 if (b1Odd && !lastX)
1566 const BYTE r = *srcOdd++;
1567 const BYTE g = *srcOdd++;
1568 const BYTE b = *srcOdd++;
1570 Y2o = RGB2Y(r, g, b);
1571 U2o = RGB2U(r, g, b);
1572 V2o = RGB2V(r, g, b);
1588 const BYTE Uavg = WINPR_ASSERTING_INT_CAST(BYTE, ((UINT16)U1e + U2e + U1o + U2o) / 4);
1589 const BYTE Vavg = WINPR_ASSERTING_INT_CAST(BYTE, ((UINT16)V1e + V2e + V1o + V2o) / 4);
1616static inline pstatus_t general_RGBToAVC444YUV_RGBX(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcStep,
1617 BYTE* WINPR_RESTRICT pDst1[3],
1618 const UINT32 dst1Step[3],
1619 BYTE* WINPR_RESTRICT pDst2[3],
1620 const UINT32 dst2Step[3],
1629 for (; y < roi->height - roi->height % 2; y += 2)
1631 const BOOL last = (y >= (roi->height - 1));
1632 const BYTE* srcEven = pSrc + 1ULL * y * srcStep;
1633 const BYTE* srcOdd = pSrc + 1ULL * (y + 1) * srcStep;
1634 const size_t i = y >> 1;
1635 const size_t n = (i & (size_t)~7) + i;
1636 BYTE* b1Even = pDst1[0] + 1ULL * y * dst1Step[0];
1637 BYTE* b1Odd = !last ? (b1Even + dst1Step[0]) : nullptr;
1638 BYTE* b2 = pDst1[1] + 1ULL * (y / 2) * dst1Step[1];
1639 BYTE* b3 = pDst1[2] + 1ULL * (y / 2) * dst1Step[2];
1640 BYTE* b4 = pDst2[0] + 1ULL * dst2Step[0] * n;
1641 BYTE* b5 = b4 + 8ULL * dst2Step[0];
1642 BYTE* b6 = pDst2[1] + 1ULL * (y / 2) * dst2Step[1];
1643 BYTE* b7 = pDst2[2] + 1ULL * (y / 2) * dst2Step[2];
1644 general_RGBToAVC444YUV_RGBX_DOUBLE_ROW(srcEven, srcOdd, b1Even, b1Odd, b2, b3, b4, b5, b6,
1647 for (; y < roi->height; y++)
1649 const BYTE* srcEven = pSrc + 1ULL * y * srcStep;
1650 BYTE* b1Even = pDst1[0] + 1ULL * y * dst1Step[0];
1651 BYTE* b2 = pDst1[1] + 1ULL * (y / 2) * dst1Step[1];
1652 BYTE* b3 = pDst1[2] + 1ULL * (y / 2) * dst1Step[2];
1653 BYTE* b6 = pDst2[1] + 1ULL * (y / 2) * dst2Step[1];
1654 BYTE* b7 = pDst2[2] + 1ULL * (y / 2) * dst2Step[2];
1655 general_RGBToAVC444YUV_RGBX_DOUBLE_ROW(srcEven,
nullptr, b1Even,
nullptr, b2, b3,
nullptr,
1656 nullptr, b6, b7, roi->width);
1658 return PRIMITIVES_SUCCESS;
1661static inline void general_RGBToAVC444YUV_ANY_DOUBLE_ROW(
1662 const BYTE* WINPR_RESTRICT srcEven,
const BYTE* WINPR_RESTRICT srcOdd, UINT32 srcFormat,
1663 BYTE* WINPR_RESTRICT b1Even, BYTE* WINPR_RESTRICT b1Odd, BYTE* WINPR_RESTRICT b2,
1664 BYTE* WINPR_RESTRICT b3, BYTE* WINPR_RESTRICT b4, BYTE* WINPR_RESTRICT b5,
1665 BYTE* WINPR_RESTRICT b6, BYTE* WINPR_RESTRICT b7, UINT32 width)
1667 const UINT32 bpp = FreeRDPGetBytesPerPixel(srcFormat);
1668 for (UINT32 x = 0; x < width; x += 2)
1670 const BOOL lastX = (x + 1) >= width;
1688 const UINT32 color = FreeRDPReadColor(srcEven, srcFormat);
1690 FreeRDPSplitColor(color, srcFormat, &r, &g, &b,
nullptr,
nullptr);
1691 Y1e = Y2e = Y1o = Y2o = RGB2Y(r, g, b);
1692 U1e = U2e = U1o = U2o = RGB2U(r, g, b);
1693 V1e = V2e = V1o = V2o = RGB2V(r, g, b);
1701 const UINT32 color = FreeRDPReadColor(srcEven, srcFormat);
1703 FreeRDPSplitColor(color, srcFormat, &r, &g, &b,
nullptr,
nullptr);
1704 Y2e = RGB2Y(r, g, b);
1705 U2e = RGB2U(r, g, b);
1706 V2e = RGB2V(r, g, b);
1714 const UINT32 color = FreeRDPReadColor(srcOdd, srcFormat);
1716 FreeRDPSplitColor(color, srcFormat, &r, &g, &b,
nullptr,
nullptr);
1717 Y1o = Y2o = RGB2Y(r, g, b);
1718 U1o = U2o = RGB2U(r, g, b);
1719 V1o = V2o = RGB2V(r, g, b);
1722 if (b1Odd && !lastX)
1727 const UINT32 color = FreeRDPReadColor(srcOdd, srcFormat);
1729 FreeRDPSplitColor(color, srcFormat, &r, &g, &b,
nullptr,
nullptr);
1730 Y2o = RGB2Y(r, g, b);
1731 U2o = RGB2U(r, g, b);
1732 V2o = RGB2V(r, g, b);
1748 const BYTE Uavg = WINPR_ASSERTING_INT_CAST(
1749 BYTE, ((UINT16)U1e + (UINT16)U2e + (UINT16)U1o + (UINT16)U2o) / 4);
1750 const BYTE Vavg = WINPR_ASSERTING_INT_CAST(
1751 BYTE, ((UINT16)V1e + (UINT16)V2e + (UINT16)V1o + (UINT16)V2o) / 4);
1778static inline pstatus_t
1779general_RGBToAVC444YUV_ANY(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcFormat, UINT32 srcStep,
1780 BYTE* WINPR_RESTRICT pDst1[3],
const UINT32 dst1Step[3],
1781 BYTE* WINPR_RESTRICT pDst2[3],
const UINT32 dst2Step[3],
1841 const BYTE* pMaxSrc = pSrc + 1ULL * (roi->height - 1) * srcStep;
1843 for (
size_t y = 0; y < roi->height; y += 2)
1845 WINPR_ASSERT(y < UINT32_MAX);
1847 const BOOL last = (y >= (roi->height - 1));
1848 const BYTE* srcEven = y < roi->height ? pSrc + y * srcStep : pMaxSrc;
1849 const BYTE* srcOdd = !last ? pSrc + (y + 1) * srcStep : pMaxSrc;
1850 const UINT32 i = (UINT32)y >> 1;
1851 const UINT32 n = (i & (uint32_t)~7) + i;
1852 BYTE* b1Even = pDst1[0] + y * dst1Step[0];
1853 BYTE* b1Odd = !last ? (b1Even + dst1Step[0]) : nullptr;
1854 BYTE* b2 = pDst1[1] + (y / 2) * dst1Step[1];
1855 BYTE* b3 = pDst1[2] + (y / 2) * dst1Step[2];
1856 BYTE* b4 = pDst2[0] + 1ULL * dst2Step[0] * n;
1857 BYTE* b5 = b4 + 8ULL * dst2Step[0];
1858 BYTE* b6 = pDst2[1] + (y / 2) * dst2Step[1];
1859 BYTE* b7 = pDst2[2] + (y / 2) * dst2Step[2];
1860 general_RGBToAVC444YUV_ANY_DOUBLE_ROW(srcEven, srcOdd, srcFormat, b1Even, b1Odd, b2, b3, b4,
1861 b5, b6, b7, roi->width);
1864 return PRIMITIVES_SUCCESS;
1867static inline pstatus_t general_RGBToAVC444YUV(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcFormat,
1868 UINT32 srcStep, BYTE* WINPR_RESTRICT pDst1[3],
1869 const UINT32 dst1Step[3],
1870 BYTE* WINPR_RESTRICT pDst2[3],
1871 const UINT32 dst2Step[3],
1874 if (!pSrc || !pDst1 || !dst1Step || !pDst2 || !dst2Step)
1877 if (!pDst1[0] || !pDst1[1] || !pDst1[2])
1880 if (!dst1Step[0] || !dst1Step[1] || !dst1Step[2])
1883 if (!pDst2[0] || !pDst2[1] || !pDst2[2])
1886 if (!dst2Step[0] || !dst2Step[1] || !dst2Step[2])
1892 case PIXEL_FORMAT_BGRA32:
1893 case PIXEL_FORMAT_BGRX32:
1894 return general_RGBToAVC444YUV_BGRX(pSrc, srcStep, pDst1, dst1Step, pDst2, dst2Step,
1897 case PIXEL_FORMAT_RGBA32:
1898 case PIXEL_FORMAT_RGBX32:
1899 return general_RGBToAVC444YUV_RGBX(pSrc, srcStep, pDst1, dst1Step, pDst2, dst2Step,
1903 return general_RGBToAVC444YUV_ANY(pSrc, srcFormat, srcStep, pDst1, dst1Step, pDst2,
1907 return !PRIMITIVES_SUCCESS;
1910static inline void general_RGBToAVC444YUVv2_ANY_DOUBLE_ROW(
1911 const BYTE* WINPR_RESTRICT srcEven,
const BYTE* WINPR_RESTRICT srcOdd, UINT32 srcFormat,
1912 BYTE* WINPR_RESTRICT yLumaDstEven, BYTE* WINPR_RESTRICT yLumaDstOdd,
1913 BYTE* WINPR_RESTRICT uLumaDst, BYTE* WINPR_RESTRICT vLumaDst,
1914 BYTE* WINPR_RESTRICT yEvenChromaDst1, BYTE* WINPR_RESTRICT yEvenChromaDst2,
1915 BYTE* WINPR_RESTRICT yOddChromaDst1, BYTE* WINPR_RESTRICT yOddChromaDst2,
1916 BYTE* WINPR_RESTRICT uChromaDst1, BYTE* WINPR_RESTRICT uChromaDst2,
1917 BYTE* WINPR_RESTRICT vChromaDst1, BYTE* WINPR_RESTRICT vChromaDst2, UINT32 width)
1919 const UINT32 bpp = FreeRDPGetBytesPerPixel(srcFormat);
1921 WINPR_ASSERT((width % 2) == 0);
1922 for (UINT32 x = 0; x < width; x += 2)
1940 const UINT32 color = FreeRDPReadColor(srcEven, srcFormat);
1942 FreeRDPSplitColor(color, srcFormat, &r, &g, &b,
nullptr,
nullptr);
1943 Ya = RGB2Y(r, g, b);
1944 Ua = RGB2U(r, g, b);
1945 Va = RGB2V(r, g, b);
1953 const UINT32 color = FreeRDPReadColor(srcEven, srcFormat);
1955 FreeRDPSplitColor(color, srcFormat, &r, &g, &b,
nullptr,
nullptr);
1956 Yb = RGB2Y(r, g, b);
1957 Ub = RGB2U(r, g, b);
1958 Vb = RGB2V(r, g, b);
1972 const UINT32 color = FreeRDPReadColor(srcOdd, srcFormat);
1974 FreeRDPSplitColor(color, srcFormat, &r, &g, &b,
nullptr,
nullptr);
1975 Yc = RGB2Y(r, g, b);
1976 Uc = RGB2U(r, g, b);
1977 Vc = RGB2V(r, g, b);
1986 if (srcOdd && (x < width - 1))
1991 const UINT32 color = FreeRDPReadColor(srcOdd, srcFormat);
1993 FreeRDPSplitColor(color, srcFormat, &r, &g, &b,
nullptr,
nullptr);
1994 Yd = RGB2Y(r, g, b);
1995 Ud = RGB2U(r, g, b);
1996 Vd = RGB2V(r, g, b);
2006 *yLumaDstEven++ = Ya;
2009 *yLumaDstEven++ = Yb;
2012 *yLumaDstOdd++ = Yc;
2014 if (srcOdd && (x < width - 1))
2015 *yLumaDstOdd++ = Yd;
2018 *uLumaDst++ = (Ua + Ub + Uc + Ud) / 4;
2019 *vLumaDst++ = (Va + Vb + Vc + Vd) / 4;
2024 *yEvenChromaDst1++ = Ub;
2025 *yEvenChromaDst2++ = Vb;
2033 *yOddChromaDst1++ = Ud;
2034 *yOddChromaDst2++ = Vd;
2040 *uChromaDst1++ = Uc;
2041 *uChromaDst2++ = Vc;
2046 *vChromaDst1++ = Uc;
2047 *vChromaDst2++ = Vc;
2053static inline pstatus_t
2054general_RGBToAVC444YUVv2_ANY(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcFormat, UINT32 srcStep,
2055 BYTE* WINPR_RESTRICT pDst1[3],
const UINT32 dst1Step[3],
2056 BYTE* WINPR_RESTRICT pDst2[3],
const UINT32 dst2Step[3],
2109 if (roi->height < 1 || roi->width < 1)
2110 return !PRIMITIVES_SUCCESS;
2113 for (; y < roi->height - roi->height % 2; y += 2)
2115 const BYTE* srcEven = (pSrc + y * srcStep);
2116 const BYTE* srcOdd = (y < roi->height - 1) ? (srcEven + srcStep) :
nullptr;
2117 BYTE* dstLumaYEven = (pDst1[0] + y * dst1Step[0]);
2118 BYTE* dstLumaYOdd = (dstLumaYEven + dst1Step[0]);
2119 BYTE* dstLumaU = (pDst1[1] + (y / 2) * dst1Step[1]);
2120 BYTE* dstLumaV = (pDst1[2] + (y / 2) * dst1Step[2]);
2121 BYTE* dstEvenChromaY1 = (pDst2[0] + y * dst2Step[0]);
2122 BYTE* dstEvenChromaY2 = dstEvenChromaY1 + roi->width / 2;
2123 BYTE* dstOddChromaY1 = dstEvenChromaY1 + dst2Step[0];
2124 BYTE* dstOddChromaY2 = dstEvenChromaY2 + dst2Step[0];
2125 BYTE* dstChromaU1 = (pDst2[1] + (y / 2) * dst2Step[1]);
2126 BYTE* dstChromaV1 = (pDst2[2] + (y / 2) * dst2Step[2]);
2127 BYTE* dstChromaU2 = dstChromaU1 + roi->width / 4;
2128 BYTE* dstChromaV2 = dstChromaV1 + roi->width / 4;
2129 general_RGBToAVC444YUVv2_ANY_DOUBLE_ROW(
2130 srcEven, srcOdd, srcFormat, dstLumaYEven, dstLumaYOdd, dstLumaU, dstLumaV,
2131 dstEvenChromaY1, dstEvenChromaY2, dstOddChromaY1, dstOddChromaY2, dstChromaU1,
2132 dstChromaU2, dstChromaV1, dstChromaV2, roi->width);
2134 for (; y < roi->height; y++)
2136 const BYTE* srcEven = (pSrc + y * srcStep);
2137 BYTE* dstLumaYEven = (pDst1[0] + y * dst1Step[0]);
2138 BYTE* dstLumaU = (pDst1[1] + (y / 2) * dst1Step[1]);
2139 BYTE* dstLumaV = (pDst1[2] + (y / 2) * dst1Step[2]);
2140 BYTE* dstEvenChromaY1 = (pDst2[0] + y * dst2Step[0]);
2141 BYTE* dstEvenChromaY2 = dstEvenChromaY1 + roi->width / 2;
2142 general_RGBToAVC444YUVv2_ANY_DOUBLE_ROW(
2143 srcEven,
nullptr, srcFormat, dstLumaYEven,
nullptr, dstLumaU, dstLumaV, dstEvenChromaY1,
2144 dstEvenChromaY2,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, roi->width);
2147 return PRIMITIVES_SUCCESS;
2150static inline void int_general_RGBToAVC444YUVv2_BGRX_DOUBLE_ROW(
2151 size_t offset,
const BYTE* WINPR_RESTRICT pSrcEven,
const BYTE* WINPR_RESTRICT pSrcOdd,
2152 BYTE* WINPR_RESTRICT yLumaDstEven, BYTE* WINPR_RESTRICT yLumaDstOdd,
2153 BYTE* WINPR_RESTRICT uLumaDst, BYTE* WINPR_RESTRICT vLumaDst,
2154 BYTE* WINPR_RESTRICT yEvenChromaDst1, BYTE* WINPR_RESTRICT yEvenChromaDst2,
2155 BYTE* WINPR_RESTRICT yOddChromaDst1, BYTE* WINPR_RESTRICT yOddChromaDst2,
2156 BYTE* WINPR_RESTRICT uChromaDst1, BYTE* WINPR_RESTRICT uChromaDst2,
2157 BYTE* WINPR_RESTRICT vChromaDst1, BYTE* WINPR_RESTRICT vChromaDst2, UINT32 width)
2159 WINPR_ASSERT((width % 2) == 0);
2160 WINPR_ASSERT(pSrcEven);
2161 WINPR_ASSERT(yLumaDstEven);
2162 WINPR_ASSERT(uLumaDst);
2163 WINPR_ASSERT(vLumaDst);
2165 for (
size_t x = offset; x < width; x += 2)
2167 const BYTE* srcEven = &pSrcEven[4ULL * x];
2168 const BYTE* srcOdd = pSrcOdd ? &pSrcOdd[4ULL * x] :
nullptr;
2182 const BYTE b = *srcEven++;
2183 const BYTE g = *srcEven++;
2184 const BYTE r = *srcEven++;
2186 Ya = RGB2Y(r, g, b);
2187 Ua = RGB2U(r, g, b);
2188 Va = RGB2V(r, g, b);
2193 const BYTE b = *srcEven++;
2194 const BYTE g = *srcEven++;
2195 const BYTE r = *srcEven++;
2197 Yb = RGB2Y(r, g, b);
2198 Ub = RGB2U(r, g, b);
2199 Vb = RGB2V(r, g, b);
2210 const BYTE b = *srcOdd++;
2211 const BYTE g = *srcOdd++;
2212 const BYTE r = *srcOdd++;
2214 Yc = RGB2Y(r, g, b);
2215 Uc = RGB2U(r, g, b);
2216 Vc = RGB2V(r, g, b);
2225 if (srcOdd && (x < width - 1))
2227 const BYTE b = *srcOdd++;
2228 const BYTE g = *srcOdd++;
2229 const BYTE r = *srcOdd++;
2231 Yd = RGB2Y(r, g, b);
2232 Ud = RGB2U(r, g, b);
2233 Vd = RGB2V(r, g, b);
2243 *yLumaDstEven++ = Ya;
2246 *yLumaDstEven++ = Yb;
2248 if (srcOdd && yLumaDstOdd)
2249 *yLumaDstOdd++ = Yc;
2251 if (srcOdd && (x < width - 1) && yLumaDstOdd)
2252 *yLumaDstOdd++ = Yd;
2255 *uLumaDst++ = (Ua + Ub + Uc + Ud) / 4;
2256 *vLumaDst++ = (Va + Vb + Vc + Vd) / 4;
2261 *yEvenChromaDst1++ = Ub;
2262 *yEvenChromaDst2++ = Vb;
2270 *yOddChromaDst1++ = Ud;
2271 *yOddChromaDst2++ = Vd;
2277 *uChromaDst1++ = Uc;
2278 *uChromaDst2++ = Vc;
2283 *vChromaDst1++ = Uc;
2284 *vChromaDst2++ = Vc;
2290void general_RGBToAVC444YUVv2_BGRX_DOUBLE_ROW(
2291 size_t offset,
const BYTE* WINPR_RESTRICT pSrcEven,
const BYTE* WINPR_RESTRICT pSrcOdd,
2292 BYTE* WINPR_RESTRICT yLumaDstEven, BYTE* WINPR_RESTRICT yLumaDstOdd,
2293 BYTE* WINPR_RESTRICT uLumaDst, BYTE* WINPR_RESTRICT vLumaDst,
2294 BYTE* WINPR_RESTRICT yEvenChromaDst1, BYTE* WINPR_RESTRICT yEvenChromaDst2,
2295 BYTE* WINPR_RESTRICT yOddChromaDst1, BYTE* WINPR_RESTRICT yOddChromaDst2,
2296 BYTE* WINPR_RESTRICT uChromaDst1, BYTE* WINPR_RESTRICT uChromaDst2,
2297 BYTE* WINPR_RESTRICT vChromaDst1, BYTE* WINPR_RESTRICT vChromaDst2, UINT32 width)
2299 int_general_RGBToAVC444YUVv2_BGRX_DOUBLE_ROW(
2300 offset, pSrcEven, pSrcOdd, yLumaDstEven, yLumaDstOdd, uLumaDst, vLumaDst, yEvenChromaDst1,
2301 yEvenChromaDst2, yOddChromaDst1, yOddChromaDst2, uChromaDst1, uChromaDst2, vChromaDst1,
2302 vChromaDst2, width);
2305static inline pstatus_t general_RGBToAVC444YUVv2_BGRX(
const BYTE* WINPR_RESTRICT pSrc,
2306 UINT32 srcStep, BYTE* WINPR_RESTRICT pDst1[3],
2307 const UINT32 dst1Step[3],
2308 BYTE* WINPR_RESTRICT pDst2[3],
2309 const UINT32 dst2Step[3],
2312 if (roi->height < 1 || roi->width < 1)
2313 return !PRIMITIVES_SUCCESS;
2316 for (; y < roi->height - roi->height % 2; y += 2)
2318 const BYTE* srcEven = (pSrc + y * srcStep);
2319 const BYTE* srcOdd = (srcEven + srcStep);
2320 BYTE* dstLumaYEven = (pDst1[0] + y * dst1Step[0]);
2321 BYTE* dstLumaYOdd = (dstLumaYEven + dst1Step[0]);
2322 BYTE* dstLumaU = (pDst1[1] + (y / 2) * dst1Step[1]);
2323 BYTE* dstLumaV = (pDst1[2] + (y / 2) * dst1Step[2]);
2324 BYTE* dstEvenChromaY1 = (pDst2[0] + y * dst2Step[0]);
2325 BYTE* dstEvenChromaY2 = dstEvenChromaY1 + roi->width / 2;
2326 BYTE* dstOddChromaY1 = dstEvenChromaY1 + dst2Step[0];
2327 BYTE* dstOddChromaY2 = dstEvenChromaY2 + dst2Step[0];
2328 BYTE* dstChromaU1 = (pDst2[1] + (y / 2) * dst2Step[1]);
2329 BYTE* dstChromaV1 = (pDst2[2] + (y / 2) * dst2Step[2]);
2330 BYTE* dstChromaU2 = dstChromaU1 + roi->width / 4;
2331 BYTE* dstChromaV2 = dstChromaV1 + roi->width / 4;
2332 int_general_RGBToAVC444YUVv2_BGRX_DOUBLE_ROW(
2333 0, srcEven, srcOdd, dstLumaYEven, dstLumaYOdd, dstLumaU, dstLumaV, dstEvenChromaY1,
2334 dstEvenChromaY2, dstOddChromaY1, dstOddChromaY2, dstChromaU1, dstChromaU2, dstChromaV1,
2335 dstChromaV2, roi->width);
2337 for (; y < roi->height; y++)
2339 const BYTE* srcEven = (pSrc + y * srcStep);
2340 BYTE* dstLumaYEven = (pDst1[0] + y * dst1Step[0]);
2341 BYTE* dstLumaU = (pDst1[1] + (y / 2) * dst1Step[1]);
2342 BYTE* dstLumaV = (pDst1[2] + (y / 2) * dst1Step[2]);
2343 BYTE* dstEvenChromaY1 = (pDst2[0] + y * dst2Step[0]);
2344 BYTE* dstEvenChromaY2 = dstEvenChromaY1 + roi->width / 2;
2345 int_general_RGBToAVC444YUVv2_BGRX_DOUBLE_ROW(
2346 0, srcEven,
nullptr, dstLumaYEven,
nullptr, dstLumaU, dstLumaV, dstEvenChromaY1,
2347 dstEvenChromaY2,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, roi->width);
2350 return PRIMITIVES_SUCCESS;
2353static pstatus_t general_RGBToAVC444YUVv2(
const BYTE* WINPR_RESTRICT pSrc, UINT32 srcFormat,
2354 UINT32 srcStep, BYTE* WINPR_RESTRICT pDst1[3],
2355 const UINT32 dst1Step[3], BYTE* WINPR_RESTRICT pDst2[3],
2356 const UINT32 dst2Step[3],
2361 case PIXEL_FORMAT_BGRA32:
2362 case PIXEL_FORMAT_BGRX32:
2363 return general_RGBToAVC444YUVv2_BGRX(pSrc, srcStep, pDst1, dst1Step, pDst2, dst2Step,
2367 return general_RGBToAVC444YUVv2_ANY(pSrc, srcFormat, srcStep, pDst1, dst1Step, pDst2,
2371 return !PRIMITIVES_SUCCESS;
2374void primitives_init_YUV(
primitives_t* WINPR_RESTRICT prims)
2376 prims->YUV420ToRGB_8u_P3AC4R = general_YUV420ToRGB_8u_P3AC4R;
2377 prims->YUV444ToRGB_8u_P3AC4R = general_YUV444ToRGB_8u_P3AC4R;
2378 prims->RGBToYUV420_8u_P3AC4R = general_RGBToYUV420_8u_P3AC4R;
2379 prims->RGBToYUV444_8u_P3AC4R = general_RGBToYUV444_8u_P3AC4R;
2380 prims->RGBToI444_8u = general_RGBToI444_8u;
2381 prims->YUV420CombineToYUV444 = general_YUV420CombineToYUV444;
2382 prims->YUV444SplitToYUV420 = general_YUV444SplitToYUV420;
2383 prims->RGBToAVC444YUV = general_RGBToAVC444YUV;
2384 prims->RGBToAVC444YUVv2 = general_RGBToAVC444YUVv2;
2387void primitives_init_YUV_opt(
primitives_t* WINPR_RESTRICT prims)
2389 primitives_init_YUV(prims);
2390 primitives_init_YUV_sse41(prims);
2391 primitives_init_YUV_neon(prims);