mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
[primitives] unify writing YUV data as RGB pixel
This commit is contained in:
@@ -341,7 +341,6 @@ static inline void general_YUV444ToRGB_DOUBLE_ROW(BYTE* WINPR_RESTRICT pRGB[2],
|
||||
const BYTE* WINPR_RESTRICT pU[2],
|
||||
const BYTE* WINPR_RESTRICT pV[2], size_t nWidth)
|
||||
{
|
||||
const DWORD formatSize = FreeRDPGetBytesPerPixel(DstFormat);
|
||||
fkt_writePixel writePixel = getPixelWriteFunction(DstFormat, FALSE);
|
||||
|
||||
WINPR_ASSERT(nWidth % 2 == 0);
|
||||
@@ -364,10 +363,7 @@ static inline void general_YUV444ToRGB_DOUBLE_ROW(BYTE* WINPR_RESTRICT pRGB[2],
|
||||
const INT32 avgV = ((4 * v) - subV);
|
||||
v = CONDITIONAL_CLIP(avgV, WINPR_ASSERTING_INT_CAST(BYTE, v));
|
||||
}
|
||||
const BYTE r = YUV2R(y, u, v);
|
||||
const BYTE g = YUV2G(y, u, v);
|
||||
const BYTE b = YUV2B(y, u, v);
|
||||
pRGB[i] = writePixel(pRGB[i], formatSize, DstFormat, r, g, b, 0);
|
||||
pRGB[i] = writeYUVPixel(pRGB[i], DstFormat, y, u, v, writePixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -379,17 +375,16 @@ static inline void general_YUV444ToRGB_SINGLE_ROW(BYTE* WINPR_RESTRICT pRGB, UIN
|
||||
const BYTE* WINPR_RESTRICT pV, size_t nWidth)
|
||||
{
|
||||
fkt_writePixel writePixel = getPixelWriteFunction(DstFormat, FALSE);
|
||||
const DWORD formatSize = FreeRDPGetBytesPerPixel(DstFormat);
|
||||
|
||||
WINPR_ASSERT(nWidth % 2 == 0);
|
||||
for (size_t x = 0; x < nWidth; x += 2)
|
||||
{
|
||||
for (size_t j = 0; j < 2; j++)
|
||||
{
|
||||
const BYTE r = YUV2R(pY[x + j], pU[x + j], pV[x + j]);
|
||||
const BYTE g = YUV2G(pY[x + j], pU[x + j], pV[x + j]);
|
||||
const BYTE b = YUV2B(pY[x + j], pU[x + j], pV[x + j]);
|
||||
pRGB = writePixel(pRGB, formatSize, DstFormat, r, g, b, 0);
|
||||
const BYTE y = pY[x + j];
|
||||
const BYTE u = pU[x + j];
|
||||
const BYTE v = pV[x + j];
|
||||
pRGB = writeYUVPixel(pRGB, DstFormat, y, u, v, writePixel);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -438,8 +433,6 @@ static inline void general_YUV444ToBGRX_DOUBLE_ROW(BYTE* WINPR_RESTRICT pRGB[2],
|
||||
const BYTE* WINPR_RESTRICT pU[2],
|
||||
const BYTE* WINPR_RESTRICT pV[2], size_t nWidth)
|
||||
{
|
||||
const DWORD formatSize = FreeRDPGetBytesPerPixel(DstFormat);
|
||||
|
||||
WINPR_ASSERT(nWidth % 2 == 0);
|
||||
for (size_t x = 0; x < nWidth; x += 2)
|
||||
{
|
||||
@@ -457,10 +450,10 @@ static inline void general_YUV444ToBGRX_DOUBLE_ROW(BYTE* WINPR_RESTRICT pRGB[2],
|
||||
{
|
||||
for (size_t j = 0; j < 2; j++)
|
||||
{
|
||||
const BYTE r = YUV2R(pY[i][x + j], U[i][j], V[i][j]);
|
||||
const BYTE g = YUV2G(pY[i][x + j], U[i][j], V[i][j]);
|
||||
const BYTE b = YUV2B(pY[i][x + j], U[i][j], V[i][j]);
|
||||
pRGB[i] = writePixelBGRX(pRGB[i], formatSize, DstFormat, r, g, b, 0);
|
||||
const BYTE y = pY[i][x + j];
|
||||
const BYTE u = U[i][j];
|
||||
const BYTE v = V[i][j];
|
||||
pRGB[i] = writeYUVPixel(pRGB[i], DstFormat, y, u, v, writePixelBGRX);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -471,17 +464,15 @@ static inline void general_YUV444ToBGRX_SINGLE_ROW(BYTE* WINPR_RESTRICT pRGB, UI
|
||||
const BYTE* WINPR_RESTRICT pU,
|
||||
const BYTE* WINPR_RESTRICT pV, size_t nWidth)
|
||||
{
|
||||
const DWORD formatSize = FreeRDPGetBytesPerPixel(DstFormat);
|
||||
|
||||
WINPR_ASSERT(nWidth % 2 == 0);
|
||||
for (size_t x = 0; x < nWidth; x += 2)
|
||||
{
|
||||
for (size_t j = 0; j < 2; j++)
|
||||
{
|
||||
const BYTE r = YUV2R(pY[x + j], pU[x + j], pV[x + j]);
|
||||
const BYTE g = YUV2G(pY[x + j], pU[x + j], pV[x + j]);
|
||||
const BYTE b = YUV2B(pY[x + j], pU[x + j], pV[x + j]);
|
||||
pRGB = writePixelBGRX(pRGB, formatSize, DstFormat, r, g, b, 0);
|
||||
const BYTE Y = pY[x + j];
|
||||
const BYTE U = pU[x + j];
|
||||
const BYTE V = pV[x + j];
|
||||
pRGB = writeYUVPixel(pRGB, DstFormat, Y, U, V, writePixelBGRX);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -579,20 +570,14 @@ static pstatus_t general_YUV420ToRGB_8u_P3AC4R(const BYTE* WINPR_RESTRICT pSrc[3
|
||||
/* 1st pixel */
|
||||
{
|
||||
const BYTE Y = *pY++;
|
||||
const BYTE r = YUV2R(Y, U, V);
|
||||
const BYTE g = YUV2G(Y, U, V);
|
||||
const BYTE b = YUV2B(Y, U, V);
|
||||
pRGBeven = writePixel(pRGBeven, formatSize, DstFormat, r, g, b, 0);
|
||||
pRGBeven = writeYUVPixel(pRGBeven, DstFormat, Y, U, V, writePixel);
|
||||
}
|
||||
|
||||
/* 2nd pixel */
|
||||
if (!(lastCol & 0x02))
|
||||
{
|
||||
const BYTE Y1 = *pY++;
|
||||
const BYTE r = YUV2R(Y1, U, V);
|
||||
const BYTE g = YUV2G(Y1, U, V);
|
||||
const BYTE b = YUV2B(Y1, U, V);
|
||||
pRGBeven = writePixel(pRGBeven, formatSize, DstFormat, r, g, b, 0);
|
||||
pRGBeven = writeYUVPixel(pRGBeven, DstFormat, Y1, U, V, writePixel);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -621,20 +606,14 @@ static pstatus_t general_YUV420ToRGB_8u_P3AC4R(const BYTE* WINPR_RESTRICT pSrc[3
|
||||
/* 3rd pixel */
|
||||
{
|
||||
const BYTE Y = *pY++;
|
||||
const BYTE r = YUV2R(Y, U, V);
|
||||
const BYTE g = YUV2G(Y, U, V);
|
||||
const BYTE b = YUV2B(Y, U, V);
|
||||
pRGBodd = writePixel(pRGBodd, formatSize, DstFormat, r, g, b, 0);
|
||||
pRGBodd = writeYUVPixel(pRGBodd, DstFormat, Y, U, V, writePixel);
|
||||
}
|
||||
|
||||
/* 4th pixel */
|
||||
if (!(lastCol & 0x02))
|
||||
{
|
||||
const BYTE Y1 = *pY++;
|
||||
const BYTE r = YUV2R(Y1, U, V);
|
||||
const BYTE g = YUV2G(Y1, U, V);
|
||||
const BYTE b = YUV2B(Y1, U, V);
|
||||
pRGBodd = writePixel(pRGBodd, formatSize, DstFormat, r, g, b, 0);
|
||||
pRGBodd = writeYUVPixel(pRGBodd, DstFormat, Y1, U, V, writePixel);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -286,6 +286,17 @@ static INLINE BYTE RGB2V(INT32 R, INT32 G, INT32 B)
|
||||
return WINPR_ASSERTING_INT_CAST(BYTE, val);
|
||||
}
|
||||
|
||||
static inline BYTE* writeYUVPixel(BYTE* dst, UINT32 DstFormat, INT32 y, INT32 u, INT32 v,
|
||||
fkt_writePixel fkt)
|
||||
{
|
||||
WINPR_ASSERT(fkt);
|
||||
const BYTE r = YUV2R(y, u, v);
|
||||
const BYTE g = YUV2G(y, u, v);
|
||||
const BYTE b = YUV2B(y, u, v);
|
||||
const DWORD formatSize = FreeRDPGetBytesPerPixel(DstFormat);
|
||||
return fkt(dst, formatSize, DstFormat, r, g, b, 0);
|
||||
}
|
||||
|
||||
FREERDP_LOCAL void general_RGBToAVC444YUV_BGRX_DOUBLE_ROW(
|
||||
size_t offset, const BYTE* WINPR_RESTRICT srcEven, const BYTE* WINPR_RESTRICT srcOdd,
|
||||
BYTE* WINPR_RESTRICT b1Even, BYTE* WINPR_RESTRICT b1Odd, BYTE* WINPR_RESTRICT b2,
|
||||
|
||||
@@ -160,10 +160,7 @@ static inline pstatus_t sse41_YUV420ToRGB_BGRX(const BYTE* WINPR_RESTRICT pSrc[]
|
||||
const BYTE Y = *YData++;
|
||||
const BYTE U = *UData;
|
||||
const BYTE V = *VData;
|
||||
const BYTE r = YUV2R(Y, U, V);
|
||||
const BYTE g = YUV2G(Y, U, V);
|
||||
const BYTE b = YUV2B(Y, U, V);
|
||||
dst = (__m128i*)writePixelBGRX((BYTE*)dst, 4, PIXEL_FORMAT_BGRX32, r, g, b, 0);
|
||||
dst = (__m128i*)writeYUVPixel((BYTE*)dst, PIXEL_FORMAT_BGRX32, Y, U, V, writePixelBGRX);
|
||||
|
||||
if (x % 2)
|
||||
{
|
||||
@@ -221,10 +218,7 @@ static inline void BGRX_fillRGB(size_t offset, BYTE* WINPR_RESTRICT pRGB[2],
|
||||
V = CONDITIONAL_CLIP(avgV, pV[0][offset]);
|
||||
}
|
||||
|
||||
const BYTE r = YUV2R(Y, U, V);
|
||||
const BYTE g = YUV2G(Y, U, V);
|
||||
const BYTE b = YUV2B(Y, U, V);
|
||||
writePixelBGRX(&pRGB[i][(j + offset) * bpp], bpp, DstFormat, r, g, b, 0);
|
||||
writeYUVPixel(&pRGB[i][(j + offset) * bpp], DstFormat, Y, U, V, writePixelBGRX);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -455,7 +449,6 @@ static inline void BGRX_fillRGB_single(size_t offset, BYTE* WINPR_RESTRICT pRGB,
|
||||
WINPR_ASSERT(pU);
|
||||
WINPR_ASSERT(pV);
|
||||
|
||||
const UINT32 DstFormat = PIXEL_FORMAT_BGRX32;
|
||||
const UINT32 bpp = 4;
|
||||
|
||||
for (size_t j = 0; j < 2; j++)
|
||||
@@ -464,10 +457,7 @@ static inline void BGRX_fillRGB_single(size_t offset, BYTE* WINPR_RESTRICT pRGB,
|
||||
BYTE U = pU[offset + j];
|
||||
BYTE V = pV[offset + j];
|
||||
|
||||
const BYTE r = YUV2R(Y, U, V);
|
||||
const BYTE g = YUV2G(Y, U, V);
|
||||
const BYTE b = YUV2B(Y, U, V);
|
||||
writePixelBGRX(&pRGB[(j + offset) * bpp], bpp, DstFormat, r, g, b, 0);
|
||||
writeYUVPixel(&pRGB[(j + offset) * bpp], PIXEL_FORMAT_BGRX32, Y, U, V, writePixelBGRX);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1001,10 +1001,8 @@ static BOOL yuv444_to_rgb(BYTE* rgb, size_t stride, const BYTE* yuv[3], const UI
|
||||
const BYTE Y = yline[0][x];
|
||||
const BYTE U = yline[1][x];
|
||||
const BYTE V = yline[2][x];
|
||||
const BYTE r = YUV2R(Y, U, V);
|
||||
const BYTE g = YUV2G(Y, U, V);
|
||||
const BYTE b = YUV2B(Y, U, V);
|
||||
writePixelBGRX(&line[x * 4], 4, PIXEL_FORMAT_BGRX32, r, g, b, 0xFF);
|
||||
|
||||
writeYUVPixel(&line[x * 4], PIXEL_FORMAT_BGRX32, Y, U, V, writePixelBGRX);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user