From d1e2dd3281bf446675aa0c10ed9fd9ecd8beb0d7 Mon Sep 17 00:00:00 2001 From: Armin Novak Date: Thu, 24 Nov 2016 10:01:45 +0100 Subject: [PATCH] Moved format size calculation out of loop. --- libfreerdp/codec/rfx.c | 3 ++- libfreerdp/gdi/shape.c | 10 ++++++---- libfreerdp/primitives/prim_YCoCg.c | 20 ++++++++++---------- libfreerdp/primitives/prim_YUV.c | 28 ++++++++++++++-------------- 4 files changed, 32 insertions(+), 29 deletions(-) diff --git a/libfreerdp/codec/rfx.c b/libfreerdp/codec/rfx.c index 8299844..b51c06f 100644 --- a/libfreerdp/codec/rfx.c +++ b/libfreerdp/codec/rfx.c @@ -1151,6 +1151,7 @@ BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data, UINT32 nbUpdateRects; REGION16 clippingRects; const RECTANGLE_16* updateRects; + const DWORD formatSize = GetBytesPerPixel(format); region16_init(&clippingRects); for (i = 0; i < message->numRects; i++) @@ -1178,7 +1179,7 @@ BOOL rfx_process_message(RFX_CONTEXT* context, const BYTE* data, for (j = 0; j < nbUpdateRects; j++) { - UINT32 stride = 64 * GetBytesPerPixel(format); + UINT32 stride = 64 * formatSize; UINT32 nXDst = updateRects[j].left; UINT32 nYDst = updateRects[j].top; UINT32 nXSrc = nXDst - updateRect.left; diff --git a/libfreerdp/gdi/shape.c b/libfreerdp/gdi/shape.c index 9fde0ec..14a5367 100644 --- a/libfreerdp/gdi/shape.c +++ b/libfreerdp/gdi/shape.c @@ -132,6 +132,7 @@ BOOL gdi_FillRect(HGDI_DC hdc, const HGDI_RECT rect, HGDI_BRUSH hbr) UINT32 nXDest, nYDest; UINT32 nWidth, nHeight; const BYTE* srcp; + DWORD formatSize; gdi_RectToCRgn(rect, &nXDest, &nYDest, &nWidth, &nHeight); if (!hdc || !hbr) @@ -155,11 +156,12 @@ BOOL gdi_FillRect(HGDI_DC hdc, const HGDI_RECT rect, HGDI_BRUSH hbr) } srcp = gdi_get_bitmap_pointer(hdc, nXDest, nYDest); + formatSize = GetBytesPerPixel(hdc->format); for (y = 1; y < nHeight; y++) { BYTE* dstp = gdi_get_bitmap_pointer(hdc, nXDest, nYDest + y); - memcpy(dstp, srcp, nWidth * GetBytesPerPixel(hdc->format)); + memcpy(dstp, srcp, nWidth * formatSize); } break; @@ -167,15 +169,15 @@ BOOL gdi_FillRect(HGDI_DC hdc, const HGDI_RECT rect, HGDI_BRUSH hbr) case GDI_BS_HATCHED: case GDI_BS_PATTERN: monochrome = (hbr->pattern->format == PIXEL_FORMAT_MONO); + formatSize = GetBytesPerPixel(hbr->pattern->format); for (y = 0; y < nHeight; y++) { for (x = 0; x < nWidth; x++) { const UINT32 yOffset = ((nYDest + y) * hbr->pattern->width % - hbr->pattern->height) * GetBytesPerPixel(hbr->pattern->format); - const UINT32 xOffset = ((nXDest + x) % hbr->pattern->width) * GetBytesPerPixel( - hbr->pattern->format); + hbr->pattern->height) * formatSize; + const UINT32 xOffset = ((nXDest + x) % hbr->pattern->width) * formatSize; const BYTE* patp = &hbr->pattern->data[yOffset + xOffset]; BYTE* dstp = gdi_get_bitmap_pointer(hdc, nXDest + x, nYDest + y); diff --git a/libfreerdp/primitives/prim_YCoCg.c b/libfreerdp/primitives/prim_YCoCg.c index 518f248..d5a3e0b 100644 --- a/libfreerdp/primitives/prim_YCoCg.c +++ b/libfreerdp/primitives/prim_YCoCg.c @@ -33,20 +33,21 @@ /* ------------------------------------------------------------------------- */ static pstatus_t general_YCoCgToRGB_8u_AC4R( - const BYTE* pSrc, INT32 srcStep, - BYTE* pDst, UINT32 DstFormat, INT32 dstStep, - UINT32 width, UINT32 height, - UINT8 shift, - BOOL withAlpha) + const BYTE* pSrc, INT32 srcStep, + BYTE* pDst, UINT32 DstFormat, INT32 dstStep, + UINT32 width, UINT32 height, + UINT8 shift, + BOOL withAlpha) { BYTE A; UINT32 x, y; BYTE* dptr = pDst; const BYTE* sptr = pSrc; INT16 Cg, Co, Y, T, R, G, B; + const DWORD formatSize = GetBytesPerPixel(DstFormat); int cll = shift - 1; /* -1 builds in the /2's */ UINT32 srcPad = srcStep - (width * 4); - UINT32 dstPad = dstStep - (width * GetBytesPerPixel(DstFormat)); + UINT32 dstPad = dstStep - (width * formatSize); for (y = 0; y < height; y++) { @@ -66,12 +67,11 @@ static pstatus_t general_YCoCgToRGB_8u_AC4R( R = T + Co; G = Y + Cg; B = T - Co; - color = GetColor(DstFormat, - MINMAX(R, 0, 255), MINMAX(G, 0, 255), - MINMAX(B, 0, 255), A); + MINMAX(R, 0, 255), MINMAX(G, 0, 255), + MINMAX(B, 0, 255), A); WriteColor(dptr, DstFormat, color); - dptr += GetBytesPerPixel(DstFormat); + dptr += formatSize; } sptr += srcPad; diff --git a/libfreerdp/primitives/prim_YUV.c b/libfreerdp/primitives/prim_YUV.c index 5318020..420a6c0 100644 --- a/libfreerdp/primitives/prim_YUV.c +++ b/libfreerdp/primitives/prim_YUV.c @@ -232,9 +232,9 @@ static pstatus_t general_YUV444SplitToYUV420( { /* Filter */ const INT32 u = pSrcU[2 * x] + pSrcU[2 * x + 1] + pSrcU1[2 * x] - + pSrcU1[2 * x + 1]; + + pSrcU1[2 * x + 1]; const INT32 v = pSrcV[2 * x] + pSrcV[2 * x + 1] + pSrcV1[2 * x] - + pSrcV1[2 * x + 1]; + + pSrcV1[2 * x + 1]; pU[x] = CLIP(u / 4L); pV[x] = CLIP(v / 4L); } @@ -326,14 +326,15 @@ static INLINE BYTE YUV2B(INT32 Y, INT32 U, INT32 V) return CLIP(b8); } -static INLINE BYTE* writePixel(BYTE* dst, UINT32 format, BYTE Y, BYTE U, BYTE V) +static INLINE BYTE* writeYUVPixel(BYTE* dst, DWORD formatSize, UINT32 format, BYTE Y, BYTE U, + BYTE V) { const BYTE r = YUV2R(Y, U, V); const BYTE g = YUV2G(Y, U, V); const BYTE b = YUV2B(Y, U, V); UINT32 color = GetColor(format, r, g, b, 0xFF); WriteColor(dst, format, color); - return dst + GetBytesPerPixel(format); + return dst + formatSize; } static pstatus_t general_YUV444ToRGB_8u_P3AC4R( @@ -343,6 +344,7 @@ static pstatus_t general_YUV444ToRGB_8u_P3AC4R( { UINT32 x, y; UINT32 nWidth, nHeight; + const DWORD formatSize = GetBytesPerPixel(DstFormat); nWidth = roi->width; nHeight = roi->height; @@ -358,7 +360,7 @@ static pstatus_t general_YUV444ToRGB_8u_P3AC4R( const BYTE Y = pY[x]; const INT32 U = pU[x]; const INT32 V = pV[x]; - pRGB = writePixel(pRGB, DstFormat, Y, U, V); + pRGB = writeYUVPixel(pRGB, formatSize, DstFormat, Y, U, V); } } @@ -387,6 +389,7 @@ static pstatus_t general_YUV420ToRGB_8u_P3AC4R( BYTE* pRGB = pDst; UINT32 nWidth, nHeight; UINT32 lastRow, lastCol; + const DWORD formatSize = GetBytesPerPixel(DstFormat); pY = pSrc[0]; pU = pSrc[1]; pV = pSrc[2]; @@ -415,18 +418,18 @@ static pstatus_t general_YUV420ToRGB_8u_P3AC4R( V = *pV++; /* 1st pixel */ Y = *pY++; - pRGB = writePixel(pRGB, DstFormat, Y, U, V); + pRGB = writeYUVPixel(pRGB, formatSize, DstFormat, Y, U, V); /* 2nd pixel */ if (!(lastCol & 0x02)) { Y = *pY++; - pRGB = writePixel(pRGB, DstFormat, Y, U, V); + pRGB = writeYUVPixel(pRGB, formatSize, DstFormat, Y, U, V); } else { pY++; - pRGB += GetBytesPerPixel(DstFormat); + pRGB += formatSize; lastCol >>= 1; } } @@ -448,18 +451,18 @@ static pstatus_t general_YUV420ToRGB_8u_P3AC4R( V = *pV++; /* 3rd pixel */ Y = *pY++; - pRGB = writePixel(pRGB, DstFormat, Y, U, V); + pRGB = writeYUVPixel(pRGB, formatSize, DstFormat, Y, U, V); /* 4th pixel */ if (!(lastCol & 0x02)) { Y = *pY++; - pRGB = writePixel(pRGB, DstFormat, Y, U, V); + pRGB = writeYUVPixel(pRGB, formatSize, DstFormat, Y, U, V); } else { pY++; - pRGB += GetBytesPerPixel(DstFormat); + pRGB += formatSize; lastCol >>= 1; } } @@ -521,7 +524,6 @@ static pstatus_t general_RGBToYUV444_8u_P3AC4R( BYTE B, G, R; const UINT32 color = ReadColor(&pRGB[x * bpp], SrcFormat); SplitColor(color, SrcFormat, &R, &G, &B, NULL, NULL); - pY[x] = RGB2Y(R, G, B); pU[x] = RGB2U(R, G, B); pV[x] = RGB2V(R, G, B); @@ -563,11 +565,9 @@ static pstatus_t general_RGBToYUV420_8u_P3AC4R( const UINT32 val2x = (x * 2); const UINT32 val2x1 = val2x + 1; BYTE B, G, R; - /* 1st pixel */ color = ReadColor(&pRGB[val2x * bpp], SrcFormat); SplitColor(color, SrcFormat, &R, &G, &B, NULL, NULL); - Ba = B; Ga = G; Ra = R; -- 2.7.4