Unified clipping of byte values.

This commit is contained in:
Armin Novak 2017-01-12 15:30:06 +01:00
parent a4f5964cf9
commit ebfa0ccc7d
6 changed files with 44 additions and 82 deletions

View File

@ -26,11 +26,6 @@
#include "prim_internal.h"
#ifndef MINMAX
#define MINMAX(_v_, _l_, _h_) \
((_v_) < (_l_) ? (_l_) : ((_v_) > (_h_) ? (_h_) : (_v_)))
#endif /* !MINMAX */
/* ------------------------------------------------------------------------- */
static pstatus_t general_YCoCgToRGB_8u_AC4R(
const BYTE* pSrc, INT32 srcStep,
@ -67,8 +62,8 @@ static pstatus_t general_YCoCgToRGB_8u_AC4R(
R = T + Co;
G = Y + Cg;
B = T - Co;
dptr = (*writePixel)(dptr, formatSize, DstFormat, MINMAX(R, 0, 255),
MINMAX(G, 0, 255), MINMAX(B, 0, 255), A);
dptr = (*writePixel)(dptr, formatSize, DstFormat, CLIP(R),
CLIP(G), CLIP(B), A);
}
sptr += srcPad;

View File

@ -25,17 +25,6 @@
#include <freerdp/codec/color.h>
#include "prim_internal.h"
static INLINE BYTE CLIP(INT32 X)
{
if (X > 255L)
return 255L;
if (X < 0L)
return 0L;
return X;
}
/**
* @brief general_YUV420CombineToYUV444
*

View File

@ -35,11 +35,9 @@ static pstatus_t ssse3_YUV420ToRGB_8u_P3AC4R(
UINT32 i, nWidth, nHeight, VaddDst, VaddY, VaddU, VaddV;
__m128i r0, r1, r2, r3, r4, r5, r6, r7;
__m128i* buffer;
// TODO: Need to implement proper color conversion!!!!!
return generic->YUV420ToRGB_8u_P3AC4R(pSrc, srcStep, pDst, dstStep,
DstFormat, roi);
DstFormat, roi);
/* last_line: if the last (U,V doubled) line should be skipped, set to 10B
* last_column: if it's the last column in a line, set to 10B (for handling line-endings not multiple by four) */
buffer = _aligned_malloc(4 * 16, 16);

View File

@ -31,7 +31,6 @@
#define MINMAX(_v_, _l_, _h_) \
((_v_) < (_l_) ? (_l_) : ((_v_) > (_h_) ? (_h_) : (_v_)))
#endif /* !MINMAX */
/* ------------------------------------------------------------------------- */
static pstatus_t general_yCbCrToRGB_16s8u_P3AC4R(
const INT16* pSrc[3], UINT32 srcStep,
@ -60,23 +59,8 @@ static pstatus_t general_yCbCrToRGB_16s8u_P3AC4R(
R = ((INT16)(((Cr * 1.402525f) + Y + 16.0f)) >> 5);
G = ((INT16)((Y - (Cb * 0.343730f) - (Cr * 0.714401f) + 16.0f)) >> 5);
B = ((INT16)(((Cb * 1.769905f) + Y + 16.0f)) >> 5);
if (R < 0)
R = 0;
else if (R > 255)
R = 255;
if (G < 0)
G = 0;
else if (G > 255)
G = 255;
if (B < 0)
B = 0;
else if (B > 255)
B = 255;
pRGB = (*writePixel)(pRGB, formatSize, DstFormat, R, G, B, 0xFF);
pRGB = (*writePixel)(pRGB, formatSize, DstFormat, CLIP(R), CLIP(G),
CLIP(B), 0xFF);
pY++;
pCb++;
pCr++;
@ -118,23 +102,8 @@ static pstatus_t general_yCbCrToBGR_16s8u_P3AC4R(
R = ((INT16)(((Cr * 1.402525f) + Y + 16.0f)) >> 5);
G = ((INT16)((Y - (Cb * 0.343730f) - (Cr * 0.714401f) + 16.0f)) >> 5);
B = ((INT16)(((Cb * 1.769905f) + Y + 16.0f)) >> 5);
if (R < 0)
R = 0;
else if (R > 255)
R = 255;
if (G < 0)
G = 0;
else if (G > 255)
G = 255;
if (B < 0)
B = 0;
else if (B > 255)
B = 255;
pRGB = (*writePixel)(pRGB, formatSize, DstFormat, R, G, B, 0xFF);
pRGB = (*writePixel)(pRGB, formatSize, DstFormat, CLIP(R), CLIP(G),
CLIP(B), 0xFF);
pY++;
pCb++;
pCr++;
@ -196,9 +165,9 @@ static pstatus_t general_yCbCrToRGB_16s16s_P3P3(
* r = y + cr*1.403f;
* g = y - cb*0.344f - cr*0.714f;
* b = y + cb*1.770f;
* y_r_buf[i] = MINMAX(r>>5, 0, 255);
* cb_g_buf[i] = MINMAX(g>>5, 0, 255);
* cr_b_buf[i] = MINMAX(b>>5, 0, 255);
* y_r_buf[i] = CLIP(r>>5);
* cb_g_buf[i] = CLIP(g>>5);
* cr_b_buf[i] = CLIP(b>>5);
*/
/*
* We scale the factors by << 16 into 32-bit integers in order to
@ -214,9 +183,9 @@ static pstatus_t general_yCbCrToRGB_16s16s_P3P3(
r = y + cr * 91947;
g = y - cb * 22544 - cr * 46792;
b = y + cb * 115998;
*rptr++ = MINMAX(r >> 21, 0, 255);
*gptr++ = MINMAX(g >> 21, 0, 255);
*bptr++ = MINMAX(b >> 21, 0, 255);
*rptr++ = CLIP(r >> 21);
*gptr++ = CLIP(g >> 21);
*bptr++ = CLIP(b >> 21);
}
yptr += srcbump;

View File

@ -172,20 +172,20 @@ static pstatus_t sse2_yCbCrToRGB_16s16s_P3P3(
/* (y + HIWORD(cr*22986)) >> 3 */
r = _mm_add_epi16(y, _mm_mulhi_epi16(cr, r_cr));
r = _mm_srai_epi16(r, 3);
/* r_buf[i] = MINMAX(r, 0, 255); */
/* r_buf[i] = CLIP(r); */
_mm_between_epi16(r, zero, max);
_mm_store_si128(r_buf + i, r);
/* (y + HIWORD(cb*-5636) + HIWORD(cr*-11698)) >> 3 */
g = _mm_add_epi16(y, _mm_mulhi_epi16(cb, g_cb));
g = _mm_add_epi16(g, _mm_mulhi_epi16(cr, g_cr));
g = _mm_srai_epi16(g, 3);
/* g_buf[i] = MINMAX(g, 0, 255); */
/* g_buf[i] = CLIP(g); */
_mm_between_epi16(g, zero, max);
_mm_store_si128(g_buf + i, g);
/* (y + HIWORD(cb*28999)) >> 3 */
b = _mm_add_epi16(y, _mm_mulhi_epi16(cb, b_cb));
b = _mm_srai_epi16(b, 3);
/* b_buf[i] = MINMAX(b, 0, 255); */
/* b_buf[i] = CLIP(b); */
_mm_between_epi16(b, zero, max);
_mm_store_si128(b_buf + i, b);
}
@ -517,20 +517,20 @@ static pstatus_t neon_yCbCrToRGB_16s16s_P3P3(
/* (y + HIWORD(cr*22986)) >> 3 */
int16x8_t r = vaddq_s16(y, vshrq_n_s16(vqdmulhq_s16(cr, r_cr), 1));
r = vshrq_n_s16(r, 3);
/* r_buf[i] = MINMAX(r, 0, 255); */
/* r_buf[i] = CLIP(r); */
r = vminq_s16(vmaxq_s16(r, zero), max);
vst1q_s16((INT16*)&r_buf[i], r);
/* (y + HIWORD(cb*-5636) + HIWORD(cr*-11698)) >> 3 */
int16x8_t g = vaddq_s16(y, vshrq_n_s16(vqdmulhq_s16(cb, g_cb), 1));
g = vaddq_s16(g, vshrq_n_s16(vqdmulhq_s16(cr, g_cr), 1));
g = vshrq_n_s16(g, 3);
/* g_buf[i] = MINMAX(g, 0, 255); */
/* g_buf[i] = CLIP(g); */
g = vminq_s16(vmaxq_s16(g, zero), max);
vst1q_s16((INT16*)&g_buf[i], g);
/* (y + HIWORD(cb*28999)) >> 3 */
int16x8_t b = vaddq_s16(y, vshrq_n_s16(vqdmulhq_s16(cb, b_cb), 1));
b = vshrq_n_s16(b, 3);
/* b_buf[i] = MINMAX(b, 0, 255); */
/* b_buf[i] = CLIP(b); */
b = vminq_s16(vmaxq_s16(b, zero), max);
vst1q_s16((INT16*)&b_buf[i], b);
}

View File

@ -88,27 +88,38 @@ static INLINE fkt_writePixel getPixelWriteFunction(DWORD format)
{
switch (format)
{
case PIXEL_FORMAT_ARGB32:
case PIXEL_FORMAT_XRGB32:
return writePixelXRGB;
case PIXEL_FORMAT_ARGB32:
case PIXEL_FORMAT_XRGB32:
return writePixelXRGB;
case PIXEL_FORMAT_ABGR32:
case PIXEL_FORMAT_XBGR32:
return writePixelXBGR;
case PIXEL_FORMAT_ABGR32:
case PIXEL_FORMAT_XBGR32:
return writePixelXBGR;
case PIXEL_FORMAT_RGBA32:
case PIXEL_FORMAT_RGBX32:
return writePixelRGBX;
case PIXEL_FORMAT_RGBA32:
case PIXEL_FORMAT_RGBX32:
return writePixelRGBX;
case PIXEL_FORMAT_BGRA32:
case PIXEL_FORMAT_BGRX32:
return writePixelBGRX;
case PIXEL_FORMAT_BGRA32:
case PIXEL_FORMAT_BGRX32:
return writePixelBGRX;
default:
return writePixelGeneric;
default:
return writePixelGeneric;
}
}
static INLINE BYTE CLIP(INT32 X)
{
if (X > 255L)
return 255L;
if (X < 0L)
return 0L;
return X;
}
/* Function prototypes for all the init/deinit routines. */
FREERDP_LOCAL void primitives_init_copy(primitives_t* prims);
FREERDP_LOCAL void primitives_init_set(primitives_t* prims);