23#include <freerdp/config.h>
25#include <winpr/sysinfo.h>
27#include <freerdp/types.h>
28#include <freerdp/primitives.h>
30#include "prim_internal.h"
33#if defined(NEON_INTRINSICS_ENABLED)
38static inline uint8x8_t neon_YUV2R_single(uint16x8_t C, int16x8_t D, int16x8_t E)
41 const int32x4_t Ch = vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(C)));
42 const int32x4_t e403h = vmull_n_s16(vget_high_s16(E), 403);
43 const int32x4_t cehm = vaddq_s32(Ch, e403h);
44 const int32x4_t ceh = vshrq_n_s32(cehm, 8);
46 const int32x4_t Cl = vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(C)));
47 const int32x4_t e403l = vmull_n_s16(vget_low_s16(E), 403);
48 const int32x4_t celm = vaddq_s32(Cl, e403l);
49 const int32x4_t cel = vshrq_n_s32(celm, 8);
50 const int16x8_t ce = vcombine_s16(vqmovn_s32(cel), vqmovn_s32(ceh));
51 return vqmovun_s16(ce);
54static inline uint8x8x2_t neon_YUV2R(uint16x8x2_t C, int16x8x2_t D, int16x8x2_t E)
56 uint8x8x2_t res = { { neon_YUV2R_single(C.val[0], D.val[0], E.val[0]),
57 neon_YUV2R_single(C.val[1], D.val[1], E.val[1]) } };
61static inline uint8x8_t neon_YUV2G_single(uint16x8_t C, int16x8_t D, int16x8_t E)
64 const int16x8_t d48 = vmulq_n_s16(D, 48);
65 const int16x8_t e120 = vmulq_n_s16(E, 120);
66 const int32x4_t deh = vaddl_s16(vget_high_s16(d48), vget_high_s16(e120));
67 const int32x4_t Ch = vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(C)));
68 const int32x4_t cdeh32m = vsubq_s32(Ch, deh);
69 const int32x4_t cdeh32 = vshrq_n_s32(cdeh32m, 8);
70 const int16x4_t cdeh = vqmovn_s32(cdeh32);
72 const int32x4_t del = vaddl_s16(vget_low_s16(d48), vget_low_s16(e120));
73 const int32x4_t Cl = vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(C)));
74 const int32x4_t cdel32m = vsubq_s32(Cl, del);
75 const int32x4_t cdel32 = vshrq_n_s32(cdel32m, 8);
76 const int16x4_t cdel = vqmovn_s32(cdel32);
77 const int16x8_t cde = vcombine_s16(cdel, cdeh);
78 return vqmovun_s16(cde);
81static inline uint8x8x2_t neon_YUV2G(uint16x8x2_t C, int16x8x2_t D, int16x8x2_t E)
83 uint8x8x2_t res = { { neon_YUV2G_single(C.val[0], D.val[0], E.val[0]),
84 neon_YUV2G_single(C.val[1], D.val[1], E.val[1]) } };
88static inline uint8x8_t neon_YUV2B_single(uint16x8_t C, int16x8_t D, int16x8_t E)
91 const int32x4_t Ch = vreinterpretq_s32_u32(vmovl_u16(vget_high_u16(C)));
92 const int32x4_t d475h = vmull_n_s16(vget_high_s16(D), 475);
93 const int32x4_t cdhm = vaddq_s32(Ch, d475h);
94 const int32x4_t cdh = vshrq_n_s32(cdhm, 8);
96 const int32x4_t Cl = vreinterpretq_s32_u32(vmovl_u16(vget_low_u16(C)));
97 const int32x4_t d475l = vmull_n_s16(vget_low_s16(D), 475);
98 const int32x4_t cdlm = vaddq_s32(Cl, d475l);
99 const int32x4_t cdl = vshrq_n_s32(cdlm, 8);
100 const int16x8_t cd = vcombine_s16(vqmovn_s32(cdl), vqmovn_s32(cdh));
101 return vqmovun_s16(cd);
104static inline uint8x8x2_t neon_YUV2B(uint16x8x2_t C, int16x8x2_t D, int16x8x2_t E)
106 uint8x8x2_t res = { { neon_YUV2B_single(C.val[0], D.val[0], E.val[0]),
107 neon_YUV2B_single(C.val[1], D.val[1], E.val[1]) } };
111static inline void neon_store_bgrx(BYTE* WINPR_RESTRICT pRGB, uint8x8_t r, uint8x8_t g, uint8x8_t b,
112 uint8_t rPos, uint8_t gPos, uint8_t bPos, uint8_t aPos)
114 uint8x8x4_t bgrx = vld4_u8(pRGB);
121static inline void neon_YuvToRgbPixel(BYTE* pRGB, uint8x8x2_t Y, int16x8x2_t D, int16x8x2_t E,
122 const uint8_t rPos,
const uint8_t gPos,
const uint8_t bPos,
126 const uint16x8x2_t C = { { vshlq_n_u16(vmovl_u8(Y.val[0]), 8),
127 vshlq_n_u16(vmovl_u8(Y.val[1]), 8) } };
129 const uint8x8x2_t r = neon_YUV2R(C, D, E);
130 const uint8x8x2_t g = neon_YUV2G(C, D, E);
131 const uint8x8x2_t b = neon_YUV2B(C, D, E);
133 neon_store_bgrx(pRGB, r.val[0], g.val[0], b.val[0], rPos, gPos, bPos, aPos);
134 neon_store_bgrx(pRGB +
sizeof(uint8x8x4_t), r.val[1], g.val[1], b.val[1], rPos, gPos, bPos,
138static inline int16x8x2_t loadUV(
const BYTE* WINPR_RESTRICT pV,
size_t x)
140 const uint8x8_t Vraw = vld1_u8(&pV[x / 2]);
141 const int16x8_t V = vreinterpretq_s16_u16(vmovl_u8(Vraw));
142 const int16x8_t c128 = vdupq_n_s16(128);
143 const int16x8_t E = vsubq_s16(V, c128);
144 return vzipq_s16(E, E);
147static inline void neon_write_pixel(BYTE* pRGB, BYTE Y, BYTE U, BYTE V,
const uint8_t rPos,
148 const uint8_t gPos,
const uint8_t bPos,
const uint8_t aPos)
150 const BYTE r = YUV2R(Y, U, V);
151 const BYTE g = YUV2G(Y, U, V);
152 const BYTE b = YUV2B(Y, U, V);
159static inline void neon_YUV420ToX_DOUBLE_ROW(
const BYTE* WINPR_RESTRICT pY[2],
160 const BYTE* WINPR_RESTRICT pU,
161 const BYTE* WINPR_RESTRICT pV,
162 BYTE* WINPR_RESTRICT pRGB[2],
size_t width,
163 const uint8_t rPos,
const uint8_t gPos,
164 const uint8_t bPos,
const uint8_t aPos)
168 for (; x < width - width % 16; x += 16)
170 const uint8x16_t Y0raw = vld1q_u8(&pY[0][x]);
171 const uint8x8x2_t Y0 = { { vget_low_u8(Y0raw), vget_high_u8(Y0raw) } };
172 const int16x8x2_t D = loadUV(pU, x);
173 const int16x8x2_t E = loadUV(pV, x);
174 neon_YuvToRgbPixel(&pRGB[0][4ULL * x], Y0, D, E, rPos, gPos, bPos, aPos);
176 const uint8x16_t Y1raw = vld1q_u8(&pY[1][x]);
177 const uint8x8x2_t Y1 = { { vget_low_u8(Y1raw), vget_high_u8(Y1raw) } };
178 neon_YuvToRgbPixel(&pRGB[1][4ULL * x], Y1, D, E, rPos, gPos, bPos, aPos);
181 for (; x < width - width % 2; x += 2)
183 const BYTE U = pU[x / 2];
184 const BYTE V = pV[x / 2];
186 neon_write_pixel(&pRGB[0][4 * x], pY[0][x], U, V, rPos, gPos, bPos, aPos);
187 neon_write_pixel(&pRGB[0][4 * (1ULL + x)], pY[0][1ULL + x], U, V, rPos, gPos, bPos, aPos);
188 neon_write_pixel(&pRGB[1][4 * x], pY[1][x], U, V, rPos, gPos, bPos, aPos);
189 neon_write_pixel(&pRGB[1][4 * (1ULL + x)], pY[1][1ULL + x], U, V, rPos, gPos, bPos, aPos);
192 for (; x < width; x++)
194 const BYTE U = pU[x / 2];
195 const BYTE V = pV[x / 2];
197 neon_write_pixel(&pRGB[0][4 * x], pY[0][x], U, V, rPos, gPos, bPos, aPos);
198 neon_write_pixel(&pRGB[1][4 * x], pY[1][x], U, V, rPos, gPos, bPos, aPos);
202static inline void neon_YUV420ToX_SINGLE_ROW(
const BYTE* WINPR_RESTRICT pY,
203 const BYTE* WINPR_RESTRICT pU,
204 const BYTE* WINPR_RESTRICT pV,
205 BYTE* WINPR_RESTRICT pRGB,
size_t width,
206 const uint8_t rPos,
const uint8_t gPos,
207 const uint8_t bPos,
const uint8_t aPos)
211 for (; x < width - width % 16; x += 16)
213 const uint8x16_t Y0raw = vld1q_u8(&pY[x]);
214 const uint8x8x2_t Y0 = { { vget_low_u8(Y0raw), vget_high_u8(Y0raw) } };
215 const int16x8x2_t D = loadUV(pU, x);
216 const int16x8x2_t E = loadUV(pV, x);
217 neon_YuvToRgbPixel(&pRGB[4ULL * x], Y0, D, E, rPos, gPos, bPos, aPos);
220 for (; x < width - width % 2; x += 2)
222 const BYTE U = pU[x / 2];
223 const BYTE V = pV[x / 2];
225 neon_write_pixel(&pRGB[4 * x], pY[x], U, V, rPos, gPos, bPos, aPos);
226 neon_write_pixel(&pRGB[4 * (1ULL + x)], pY[1ULL + x], U, V, rPos, gPos, bPos, aPos);
228 for (; x < width; x++)
230 const BYTE U = pU[x / 2];
231 const BYTE V = pV[x / 2];
233 neon_write_pixel(&pRGB[4 * x], pY[x], U, V, rPos, gPos, bPos, aPos);
237static inline pstatus_t neon_YUV420ToX(
const BYTE* WINPR_RESTRICT pSrc[3],
const UINT32 srcStep[3],
238 BYTE* WINPR_RESTRICT pDst, UINT32 dstStep,
239 const prim_size_t* WINPR_RESTRICT roi,
const uint8_t rPos,
240 const uint8_t gPos,
const uint8_t bPos,
const uint8_t aPos)
242 const UINT32 nWidth = roi->width;
243 const UINT32 nHeight = roi->height;
245 WINPR_ASSERT(nHeight > 0);
247 for (; y < (nHeight - 1); y += 2)
249 const uint8_t* pY[2] = { pSrc[0] + y * srcStep[0], pSrc[0] + (1ULL + y) * srcStep[0] };
250 const uint8_t* pU = pSrc[1] + (y / 2) * srcStep[1];
251 const uint8_t* pV = pSrc[2] + (y / 2) * srcStep[2];
252 uint8_t* pRGB[2] = { pDst + y * dstStep, pDst + (1ULL + y) * dstStep };
254 neon_YUV420ToX_DOUBLE_ROW(pY, pU, pV, pRGB, nWidth, rPos, gPos, bPos, aPos);
256 for (; y < nHeight; y++)
258 const uint8_t* pY = pSrc[0] + y * srcStep[0];
259 const uint8_t* pU = pSrc[1] + (y / 2) * srcStep[1];
260 const uint8_t* pV = pSrc[2] + (y / 2) * srcStep[2];
261 uint8_t* pRGB = pDst + y * dstStep;
263 neon_YUV420ToX_SINGLE_ROW(pY, pU, pV, pRGB, nWidth, rPos, gPos, bPos, aPos);
265 return PRIMITIVES_SUCCESS;
268static pstatus_t neon_YUV420ToRGB_8u_P3AC4R(
const BYTE* WINPR_RESTRICT pSrc[3],
269 const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pDst,
270 UINT32 dstStep, UINT32 DstFormat,
275 case PIXEL_FORMAT_BGRA32:
276 case PIXEL_FORMAT_BGRX32:
277 return neon_YUV420ToX(pSrc, srcStep, pDst, dstStep, roi, 2, 1, 0, 3);
279 case PIXEL_FORMAT_RGBA32:
280 case PIXEL_FORMAT_RGBX32:
281 return neon_YUV420ToX(pSrc, srcStep, pDst, dstStep, roi, 0, 1, 2, 3);
283 case PIXEL_FORMAT_ARGB32:
284 case PIXEL_FORMAT_XRGB32:
285 return neon_YUV420ToX(pSrc, srcStep, pDst, dstStep, roi, 1, 2, 3, 0);
287 case PIXEL_FORMAT_ABGR32:
288 case PIXEL_FORMAT_XBGR32:
289 return neon_YUV420ToX(pSrc, srcStep, pDst, dstStep, roi, 3, 2, 1, 0);
292 return generic->YUV420ToRGB_8u_P3AC4R(pSrc, srcStep, pDst, dstStep, DstFormat, roi);
296static inline int16x8_t loadUVreg(uint8x8_t Vraw)
298 const int16x8_t V = vreinterpretq_s16_u16(vmovl_u8(Vraw));
299 const int16x8_t c128 = vdupq_n_s16(128);
300 const int16x8_t E = vsubq_s16(V, c128);
304static inline int16x8x2_t loadUV444(uint8x16_t Vld)
306 const uint8x8x2_t V = { { vget_low_u8(Vld), vget_high_u8(Vld) } };
307 const int16x8x2_t res = { {
314static inline void avgUV(BYTE U[2][2])
316 const BYTE u00 = U[0][0];
317 const INT16 umul = (INT16)u00 << 2;
318 const INT16 sum = (INT16)U[0][1] + U[1][0] + U[1][1];
319 const INT16 wavg = umul - sum;
320 const BYTE val = CONDITIONAL_CLIP(wavg, u00);
324static inline void neon_avgUV(uint8x16_t pU[2])
328 const uint8x16x2_t usplit = vuzpq_u8(pU[0], pU[1]);
329 const uint8x16_t ueven = usplit.val[0];
330 const uint8x16_t uodd = usplit.val[1];
332 const uint8x8_t u00 = vget_low_u8(ueven);
333 const uint8x8_t u01 = vget_low_u8(uodd);
334 const uint8x8_t u10 = vget_high_u8(ueven);
335 const uint8x8_t u11 = vget_high_u8(uodd);
338 const uint16x8_t uoddsum = vaddl_u8(u01, u10);
339 const uint16x8_t usum = vaddq_u16(uoddsum, vmovl_u8(u11));
342 const uint16x8_t umul = vshll_n_u8(u00, 2);
345 const int16x8_t wavg = vsubq_s16(vreinterpretq_s16_u16(umul), vreinterpretq_s16_u16(usum));
346 const uint8x8_t avg = vqmovun_s16(wavg);
349 const uint8x8_t absdiff = vabd_u8(avg, u00);
352 const uint8x8_t mask = vclt_u8(absdiff, vdup_n_u8(30));
355 const uint8x8_t out1 = vand_u8(u00, mask);
358 const uint8x8_t notmask = vmvn_u8(mask);
361 const uint8x8_t out2 = vand_u8(avg, notmask);
364 const uint8x8_t out = vorr_u8(out1, out2);
366 const uint8x8x2_t ua = vzip_u8(out, u01);
367 const uint8x16_t u = vcombine_u8(ua.val[0], ua.val[1]);
371static inline pstatus_t neon_YUV444ToX_SINGLE_ROW(
const BYTE* WINPR_RESTRICT pY,
372 const BYTE* WINPR_RESTRICT pU,
373 const BYTE* WINPR_RESTRICT pV,
374 BYTE* WINPR_RESTRICT pRGB,
size_t width,
375 const uint8_t rPos,
const uint8_t gPos,
376 const uint8_t bPos,
const uint8_t aPos)
380 for (; x < width - width % 16; x += 16)
382 uint8x16_t U = vld1q_u8(&pU[x]);
383 uint8x16_t V = vld1q_u8(&pV[x]);
384 const uint8x16_t Y0raw = vld1q_u8(&pY[x]);
385 const uint8x8x2_t Y0 = { { vget_low_u8(Y0raw), vget_high_u8(Y0raw) } };
386 const int16x8x2_t D0 = loadUV444(U);
387 const int16x8x2_t E0 = loadUV444(V);
388 neon_YuvToRgbPixel(&pRGB[4ULL * x], Y0, D0, E0, rPos, gPos, bPos, aPos);
391 for (; x < width; x += 2)
393 BYTE* rgb = &pRGB[x * 4];
395 for (
size_t j = 0; j < 2; j++)
397 const BYTE y = pY[x + j];
398 const BYTE u = pU[x + j];
399 const BYTE v = pV[x + j];
401 neon_write_pixel(&rgb[4 * (j)], y, u, v, rPos, gPos, bPos, aPos);
405 return PRIMITIVES_SUCCESS;
408static inline pstatus_t neon_YUV444ToX_DOUBLE_ROW(
const BYTE* WINPR_RESTRICT pY[2],
409 const BYTE* WINPR_RESTRICT pU[2],
410 const BYTE* WINPR_RESTRICT pV[2],
411 BYTE* WINPR_RESTRICT pRGB[2],
size_t width,
412 const uint8_t rPos,
const uint8_t gPos,
413 const uint8_t bPos,
const uint8_t aPos)
417 for (; x < width - width % 16; x += 16)
419 uint8x16_t U[2] = { vld1q_u8(&pU[0][x]), vld1q_u8(&pU[1][x]) };
422 uint8x16_t V[2] = { vld1q_u8(&pV[0][x]), vld1q_u8(&pV[1][x]) };
425 const uint8x16_t Y0raw = vld1q_u8(&pY[0][x]);
426 const uint8x8x2_t Y0 = { { vget_low_u8(Y0raw), vget_high_u8(Y0raw) } };
427 const int16x8x2_t D0 = loadUV444(U[0]);
428 const int16x8x2_t E0 = loadUV444(V[0]);
429 neon_YuvToRgbPixel(&pRGB[0][4ULL * x], Y0, D0, E0, rPos, gPos, bPos, aPos);
431 const uint8x16_t Y1raw = vld1q_u8(&pY[1][x]);
432 const uint8x8x2_t Y1 = { { vget_low_u8(Y1raw), vget_high_u8(Y1raw) } };
433 const int16x8x2_t D1 = loadUV444(U[1]);
434 const int16x8x2_t E1 = loadUV444(V[1]);
435 neon_YuvToRgbPixel(&pRGB[1][4ULL * x], Y1, D1, E1, rPos, gPos, bPos, aPos);
438 for (; x < width; x += 2)
440 BYTE* rgb[2] = { &pRGB[0][x * 4], &pRGB[1][x * 4] };
441 BYTE U[2][2] = { { pU[0][x], pU[0][x + 1] }, { pU[1][x], pU[1][x + 1] } };
444 BYTE V[2][2] = { { pV[0][x], pV[0][x + 1] }, { pV[1][x], pV[1][x + 1] } };
447 for (
size_t i = 0; i < 2; i++)
449 for (
size_t j = 0; j < 2; j++)
451 const BYTE y = pY[i][x + j];
452 const BYTE u = U[i][j];
453 const BYTE v = V[i][j];
455 neon_write_pixel(&rgb[i][4 * (j)], y, u, v, rPos, gPos, bPos, aPos);
460 return PRIMITIVES_SUCCESS;
463static inline pstatus_t neon_YUV444ToX(
const BYTE* WINPR_RESTRICT pSrc[3],
const UINT32 srcStep[3],
464 BYTE* WINPR_RESTRICT pDst, UINT32 dstStep,
465 const prim_size_t* WINPR_RESTRICT roi,
const uint8_t rPos,
466 const uint8_t gPos,
const uint8_t bPos,
const uint8_t aPos)
469 const UINT32 nWidth = roi->width;
470 const UINT32 nHeight = roi->height;
473 for (; y < nHeight - nHeight % 2; y += 2)
475 const uint8_t* WINPR_RESTRICT pY[2] = { pSrc[0] + y * srcStep[0],
476 pSrc[0] + (y + 1) * srcStep[0] };
477 const uint8_t* WINPR_RESTRICT pU[2] = { pSrc[1] + y * srcStep[1],
478 pSrc[1] + (y + 1) * srcStep[1] };
479 const uint8_t* WINPR_RESTRICT pV[2] = { pSrc[2] + y * srcStep[2],
480 pSrc[2] + (y + 1) * srcStep[2] };
482 uint8_t* WINPR_RESTRICT pRGB[2] = { &pDst[y * dstStep], &pDst[(y + 1) * dstStep] };
485 neon_YUV444ToX_DOUBLE_ROW(pY, pU, pV, pRGB, nWidth, rPos, gPos, bPos, aPos);
486 if (rc != PRIMITIVES_SUCCESS)
489 for (; y < nHeight; y++)
491 const uint8_t* WINPR_RESTRICT pY = pSrc[0] + y * srcStep[0];
492 const uint8_t* WINPR_RESTRICT pU = pSrc[1] + y * srcStep[1];
493 const uint8_t* WINPR_RESTRICT pV = pSrc[2] + y * srcStep[2];
494 uint8_t* WINPR_RESTRICT pRGB = &pDst[y * dstStep];
497 neon_YUV444ToX_SINGLE_ROW(pY, pU, pV, pRGB, nWidth, rPos, gPos, bPos, aPos);
498 if (rc != PRIMITIVES_SUCCESS)
502 return PRIMITIVES_SUCCESS;
505static pstatus_t neon_YUV444ToRGB_8u_P3AC4R(
const BYTE* WINPR_RESTRICT pSrc[3],
506 const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pDst,
507 UINT32 dstStep, UINT32 DstFormat,
512 case PIXEL_FORMAT_BGRA32:
513 case PIXEL_FORMAT_BGRX32:
514 return neon_YUV444ToX(pSrc, srcStep, pDst, dstStep, roi, 2, 1, 0, 3);
516 case PIXEL_FORMAT_RGBA32:
517 case PIXEL_FORMAT_RGBX32:
518 return neon_YUV444ToX(pSrc, srcStep, pDst, dstStep, roi, 0, 1, 2, 3);
520 case PIXEL_FORMAT_ARGB32:
521 case PIXEL_FORMAT_XRGB32:
522 return neon_YUV444ToX(pSrc, srcStep, pDst, dstStep, roi, 1, 2, 3, 0);
524 case PIXEL_FORMAT_ABGR32:
525 case PIXEL_FORMAT_XBGR32:
526 return neon_YUV444ToX(pSrc, srcStep, pDst, dstStep, roi, 3, 2, 1, 0);
529 return generic->YUV444ToRGB_8u_P3AC4R(pSrc, srcStep, pDst, dstStep, DstFormat, roi);
533static inline void neon_I444ToX_ROW(
const BYTE* WINPR_RESTRICT pY,
const BYTE* WINPR_RESTRICT pU,
534 const BYTE* WINPR_RESTRICT pV, BYTE* WINPR_RESTRICT pRGB,
535 size_t width,
const uint8_t rPos,
const uint8_t gPos,
536 const uint8_t bPos,
const uint8_t aPos)
540 for (; x < width - width % 16; x += 16)
542 const uint8x16_t Yraw = vld1q_u8(&pY[x]);
543 const uint8x8x2_t Y = { { vget_low_u8(Yraw), vget_high_u8(Yraw) } };
544 const int16x8x2_t D = loadUV444(vld1q_u8(&pU[x]));
545 const int16x8x2_t E = loadUV444(vld1q_u8(&pV[x]));
546 neon_YuvToRgbPixel(&pRGB[4ULL * x], Y, D, E, rPos, gPos, bPos, aPos);
549 for (; x < width; x++)
550 neon_write_pixel(&pRGB[4ULL * x], pY[x], pU[x], pV[x], rPos, gPos, bPos, aPos);
553static inline pstatus_t neon_I444ToX(
const BYTE* WINPR_RESTRICT pSrc[3],
const UINT32 srcStep[3],
554 BYTE* WINPR_RESTRICT pDst, UINT32 dstStep,
555 const prim_size_t* WINPR_RESTRICT roi,
const uint8_t rPos,
556 const uint8_t gPos,
const uint8_t bPos,
const uint8_t aPos)
560 for (
size_t y = 0; y < roi->height; y++)
562 const uint8_t* WINPR_RESTRICT pY = pSrc[0] + y * srcStep[0];
563 const uint8_t* WINPR_RESTRICT pU = pSrc[1] + y * srcStep[1];
564 const uint8_t* WINPR_RESTRICT pV = pSrc[2] + y * srcStep[2];
565 uint8_t* WINPR_RESTRICT pRGB = &pDst[y * dstStep];
567 neon_I444ToX_ROW(pY, pU, pV, pRGB, roi->width, rPos, gPos, bPos, aPos);
570 return PRIMITIVES_SUCCESS;
573static pstatus_t neon_I444ToRGB_8u(
const BYTE* WINPR_RESTRICT pSrc[3],
const UINT32 srcStep[3],
574 BYTE* WINPR_RESTRICT pDst, UINT32 dstStep, UINT32 DstFormat,
579 case PIXEL_FORMAT_BGRA32:
580 case PIXEL_FORMAT_BGRX32:
581 return neon_I444ToX(pSrc, srcStep, pDst, dstStep, roi, 2, 1, 0, 3);
583 case PIXEL_FORMAT_RGBA32:
584 case PIXEL_FORMAT_RGBX32:
585 return neon_I444ToX(pSrc, srcStep, pDst, dstStep, roi, 0, 1, 2, 3);
587 case PIXEL_FORMAT_ARGB32:
588 case PIXEL_FORMAT_XRGB32:
589 return neon_I444ToX(pSrc, srcStep, pDst, dstStep, roi, 1, 2, 3, 0);
591 case PIXEL_FORMAT_ABGR32:
592 case PIXEL_FORMAT_XBGR32:
593 return neon_I444ToX(pSrc, srcStep, pDst, dstStep, roi, 3, 2, 1, 0);
596 return generic->I444ToRGB_8u(pSrc, srcStep, pDst, dstStep, DstFormat, roi);
600static pstatus_t neon_LumaToYUV444(
const BYTE* WINPR_RESTRICT pSrcRaw[3],
const UINT32 srcStep[3],
601 BYTE* WINPR_RESTRICT pDstRaw[3],
const UINT32 dstStep[3],
604 const UINT32 nWidth = roi->right - roi->left;
605 const UINT32 nHeight = roi->bottom - roi->top;
606 const UINT32 halfWidth = (nWidth + 1) / 2;
607 const UINT32 halfHeight = (nHeight + 1) / 2;
608 const UINT32 evenY = 0;
609 const BYTE* pSrc[3] = { pSrcRaw[0] + roi->top * srcStep[0] + roi->left,
610 pSrcRaw[1] + roi->top / 2 * srcStep[1] + roi->left / 2,
611 pSrcRaw[2] + roi->top / 2 * srcStep[2] + roi->left / 2 };
612 BYTE* pDst[3] = { pDstRaw[0] + roi->top * dstStep[0] + roi->left,
613 pDstRaw[1] + roi->top * dstStep[1] + roi->left,
614 pDstRaw[2] + roi->top * dstStep[2] + roi->left };
618 for (UINT32 y = 0; y < nHeight; y++)
620 const BYTE* Ym = pSrc[0] + srcStep[0] * y;
621 BYTE* pY = pDst[0] + dstStep[0] * y;
622 memcpy(pY, Ym, nWidth);
627 for (UINT32 y = 0; y < halfHeight; y++)
629 const UINT32 val2y = (2 * y + evenY);
630 const BYTE* Um = pSrc[1] + srcStep[1] * y;
631 const BYTE* Vm = pSrc[2] + srcStep[2] * y;
632 BYTE* pU = pDst[1] + dstStep[1] * val2y;
633 BYTE* pV = pDst[2] + dstStep[2] * val2y;
634 BYTE* pU1 = pU + dstStep[1];
635 BYTE* pV1 = pV + dstStep[2];
638 for (; x + 16 < halfWidth; x += 16)
641 const uint8x16_t u = vld1q_u8(Um);
652 const uint8x16_t v = vld1q_u8(Vm);
664 for (; x < halfWidth; x++)
666 const BYTE u = *Um++;
667 const BYTE v = *Vm++;
679 return PRIMITIVES_SUCCESS;
682static pstatus_t neon_ChromaV1ToYUV444(
const BYTE* WINPR_RESTRICT pSrcRaw[3],
683 const UINT32 srcStep[3], BYTE* WINPR_RESTRICT pDstRaw[3],
684 const UINT32 dstStep[3],
687 const UINT32 mod = 16;
690 const UINT32 nWidth = roi->right - roi->left;
691 const UINT32 nHeight = roi->bottom - roi->top;
692 const UINT32 halfWidth = (nWidth) / 2;
693 const UINT32 halfHeight = (nHeight) / 2;
694 const UINT32 oddY = 1;
695 const UINT32 evenY = 0;
696 const UINT32 oddX = 1;
699 const UINT32 padHeight = nHeight + 16 - nHeight % 16;
700 const UINT32 halfPad = halfWidth % 16;
701 const BYTE* pSrc[3] = { pSrcRaw[0] + roi->top * srcStep[0] + roi->left,
702 pSrcRaw[1] + roi->top / 2 * srcStep[1] + roi->left / 2,
703 pSrcRaw[2] + roi->top / 2 * srcStep[2] + roi->left / 2 };
704 BYTE* pDst[3] = { pDstRaw[0] + roi->top * dstStep[0] + roi->left,
705 pDstRaw[1] + roi->top * dstStep[1] + roi->left,
706 pDstRaw[2] + roi->top * dstStep[2] + roi->left };
710 for (UINT32 y = 0; y < padHeight; y++)
712 const BYTE* Ya = pSrc[0] + srcStep[0] * y;
715 if ((y) % mod < (mod + 1) / 2)
717 const UINT32 pos = (2 * uY++ + oddY);
722 pX = pDst[1] + dstStep[1] * pos;
726 const UINT32 pos = (2 * vY++ + oddY);
731 pX = pDst[2] + dstStep[2] * pos;
735 memcpy(pX, Ya, nWidth);
739 for (UINT32 y = 0; y < halfHeight; y++)
741 const UINT32 val2y = (y * 2 + evenY);
742 const BYTE* Ua = pSrc[1] + srcStep[1] * y;
743 const BYTE* Va = pSrc[2] + srcStep[2] * y;
744 BYTE* pU = pDst[1] + dstStep[1] * val2y;
745 BYTE* pV = pDst[2] + dstStep[2] * val2y;
748 for (; x < halfWidth - halfPad; x += 16)
751 uint8x16x2_t u = vld2q_u8(&pU[2 * x]);
752 u.val[1] = vld1q_u8(&Ua[x]);
753 vst2q_u8(&pU[2 * x], u);
756 uint8x16x2_t v = vld2q_u8(&pV[2 * x]);
757 v.val[1] = vld1q_u8(&Va[x]);
758 vst2q_u8(&pV[2 * x], v);
762 for (; x < halfWidth; x++)
764 const UINT32 val2x1 = (x * 2 + oddX);
770 return PRIMITIVES_SUCCESS;
773static pstatus_t neon_ChromaV2ToYUV444(
const BYTE* WINPR_RESTRICT pSrc[3],
const UINT32 srcStep[3],
774 UINT32 nTotalWidth, UINT32 nTotalHeight,
775 BYTE* WINPR_RESTRICT pDst[3],
const UINT32 dstStep[3],
778 const UINT32 nWidth = roi->right - roi->left;
779 const UINT32 nHeight = roi->bottom - roi->top;
780 const UINT32 halfWidth = (nWidth + 1) / 2;
781 const UINT32 halfPad = halfWidth % 16;
782 const UINT32 halfHeight = (nHeight + 1) / 2;
783 const UINT32 quaterWidth = (nWidth + 3) / 4;
784 const UINT32 quaterPad = quaterWidth % 16;
787 for (UINT32 y = 0; y < nHeight; y++)
789 const UINT32 yTop = y + roi->top;
790 const BYTE* pYaU = pSrc[0] + srcStep[0] * yTop + roi->left / 2;
791 const BYTE* pYaV = pYaU + nTotalWidth / 2;
792 BYTE* pU = pDst[1] + dstStep[1] * yTop + roi->left;
793 BYTE* pV = pDst[2] + dstStep[2] * yTop + roi->left;
796 for (; x < halfWidth - halfPad; x += 16)
799 uint8x16x2_t u = vld2q_u8(&pU[2 * x]);
800 u.val[1] = vld1q_u8(&pYaU[x]);
801 vst2q_u8(&pU[2 * x], u);
804 uint8x16x2_t v = vld2q_u8(&pV[2 * x]);
805 v.val[1] = vld1q_u8(&pYaV[x]);
806 vst2q_u8(&pV[2 * x], v);
810 for (; x < halfWidth; x++)
812 const UINT32 odd = 2 * x + 1;
819 for (UINT32 y = 0; y < halfHeight; y++)
821 const BYTE* pUaU = pSrc[1] + srcStep[1] * (y + roi->top / 2) + roi->left / 4;
822 const BYTE* pUaV = pUaU + nTotalWidth / 4;
823 const BYTE* pVaU = pSrc[2] + srcStep[2] * (y + roi->top / 2) + roi->left / 4;
824 const BYTE* pVaV = pVaU + nTotalWidth / 4;
825 BYTE* pU = pDst[1] + dstStep[1] * (2 * y + 1 + roi->top) + roi->left;
826 BYTE* pV = pDst[2] + dstStep[2] * (2 * y + 1 + roi->top) + roi->left;
829 for (; x < quaterWidth - quaterPad; x += 16)
832 uint8x16x4_t u = vld4q_u8(&pU[4 * x]);
833 u.val[0] = vld1q_u8(&pUaU[x]);
834 u.val[2] = vld1q_u8(&pVaU[x]);
835 vst4q_u8(&pU[4 * x], u);
838 uint8x16x4_t v = vld4q_u8(&pV[4 * x]);
839 v.val[0] = vld1q_u8(&pUaV[x]);
840 v.val[2] = vld1q_u8(&pVaV[x]);
841 vst4q_u8(&pV[4 * x], v);
845 for (; x < quaterWidth; x++)
847 pU[4 * x + 0] = pUaU[x];
848 pV[4 * x + 0] = pUaV[x];
849 pU[4 * x + 2] = pVaU[x];
850 pV[4 * x + 2] = pVaV[x];
854 return PRIMITIVES_SUCCESS;
857static pstatus_t neon_YUV420CombineToYUV444(avc444_frame_type type,
858 const BYTE* WINPR_RESTRICT pSrc[3],
859 const UINT32 srcStep[3], UINT32 nWidth, UINT32 nHeight,
860 BYTE* WINPR_RESTRICT pDst[3],
const UINT32 dstStep[3],
863 if (!pSrc || !pSrc[0] || !pSrc[1] || !pSrc[2])
866 if (!pDst || !pDst[0] || !pDst[1] || !pDst[2])
875 return neon_LumaToYUV444(pSrc, srcStep, pDst, dstStep, roi);
877 case AVC444_CHROMAv1:
878 return neon_ChromaV1ToYUV444(pSrc, srcStep, pDst, dstStep, roi);
880 case AVC444_CHROMAv2:
881 return neon_ChromaV2ToYUV444(pSrc, srcStep, nWidth, nHeight, pDst, dstStep, roi);
889void primitives_init_YUV_neon_int(
primitives_t* WINPR_RESTRICT prims)
891#if defined(NEON_INTRINSICS_ENABLED)
892 generic = primitives_get_generic();
893 WLog_VRB(PRIM_TAG,
"NEON optimizations");
894 prims->YUV420ToRGB_8u_P3AC4R = neon_YUV420ToRGB_8u_P3AC4R;
895 prims->YUV444ToRGB_8u_P3AC4R = neon_YUV444ToRGB_8u_P3AC4R;
896 prims->I444ToRGB_8u = neon_I444ToRGB_8u;
897 prims->YUV420CombineToYUV444 = neon_YUV420CombineToYUV444;
899 WLog_VRB(PRIM_TAG,
"undefined WITH_SIMD or neon intrinsics not available");