shithub: openh264

Download patch

ref: d897d362ab37e6d2753ae96956fc485ed6a07f4a
parent: 197423f271794ddc8a0d0a9070ab5a4834186ef9
parent: 3b270aa901c2d8e64c94b798b5685043c1533d9a
author: Licai Guo <licaguo@cisco.com>
date: Wed Mar 19 04:50:04 EDT 2014

Merge pull request #532 from huili2/WELS_CLIP1

Modify MACRO WELS_CLIP1 as inline functions

--- a/codec/common/deblocking_common.cpp
+++ b/codec/common/deblocking_common.cpp
@@ -28,8 +28,8 @@
           iTc++;
         }
         int32_t iDeta = WELS_CLIP3 ((((q0 - p0) << 2) + (p1 - q1) + 4) >> 3, -iTc, iTc);
-        pPix[-iStrideX] = WELS_CLIP1 (p0 + iDeta);     /* p0' */
-        pPix[0]  = WELS_CLIP1 (q0 - iDeta);     /* q0' */
+        pPix[-iStrideX] = WelsClip1 (p0 + iDeta);     /* p0' */
+        pPix[0]  = WelsClip1 (q0 - iDeta);     /* q0' */
       }
     }
     pPix += iStrideY;
@@ -107,8 +107,8 @@
       bDetaQ1Q0 = WELS_ABS (q1 - q0) < iBeta;
       if (bDetaP0Q0 && bDetaP1P0 &&	bDetaQ1Q0) {
         iDeta = WELS_CLIP3 ((((q0 - p0) << 2) + (p1 - q1) + 4) >> 3, -iTc0, iTc0);
-        pPixCb[-iStrideX] = WELS_CLIP1 (p0 + iDeta);     /* p0' */
-        pPixCb[0]  = WELS_CLIP1 (q0 - iDeta);     /* q0' */
+        pPixCb[-iStrideX] = WelsClip1 (p0 + iDeta);     /* p0' */
+        pPixCb[0]  = WelsClip1 (q0 - iDeta);     /* q0' */
       }
 
 
@@ -123,8 +123,8 @@
 
       if (bDetaP0Q0 && bDetaP1P0 &&	bDetaQ1Q0) {
         iDeta = WELS_CLIP3 ((((q0 - p0) << 2) + (p1 - q1) + 4) >> 3, -iTc0, iTc0);
-        pPixCr[-iStrideX] = WELS_CLIP1 (p0 + iDeta);     /* p0' */
-        pPixCr[0]  = WELS_CLIP1 (q0 - iDeta);     /* q0' */
+        pPixCr[-iStrideX] = WelsClip1 (p0 + iDeta);     /* p0' */
+        pPixCr[0]  = WelsClip1 (q0 - iDeta);     /* q0' */
       }
     }
     pPixCb += iStrideY;
--- a/codec/common/macros.h
+++ b/codec/common/macros.h
@@ -176,11 +176,10 @@
 #define NEG_NUM(iX) (1+(~(iX)))
 #endif// NEG_NUM
 
-#ifndef WELS_CLIP1
-//#define WELS_CLIP1(x) (x & ~255) ? (-x >> 31) : x
-#define WELS_CLIP1(iX) (((iX) & ~255) ? (-(iX) >> 31) : (iX)) //iX not only a value but also can be an expression
-#endif//WELS_CLIP1
-
+static inline uint8_t WelsClip1(int32_t iX) {
+  uint8_t uiTmp = (uint8_t)(((iX) & ~255) ? (-(iX) >> 31) : (iX));
+  return uiTmp;
+}
 
 #ifndef WELS_SIGN
 #define WELS_SIGN(iX) ((int32_t)(iX) >> 31)
--- a/codec/decoder/core/src/decode_mb_aux.cpp
+++ b/codec/decoder/core/src/decode_mb_aux.cpp
@@ -92,13 +92,13 @@
     int32_t kT3	= (32 + kT1 + kT2) >> 6;
     int32_t kT4	= (32 + kT1 - kT2) >> 6;
 
-    pDst[i] = WELS_CLIP1( kT3 + pPred[i] );
-    pDst[i + kiStride3] = WELS_CLIP1( kT4 + pPred[i + kiStride3] );
+    pDst[i] = WelsClip1( kT3 + pPred[i] );
+    pDst[i + kiStride3] = WelsClip1( kT4 + pPred[i + kiStride3] );
 
     kT1	= iSrc[i] - iSrc[i + 8];
     kT2	= (iSrc[i + 4] >> 1) - iSrc[i + 12];
-    pDst[i + kiStride] = WELS_CLIP1( ((32 + kT1 + kT2) >> 6) + pDst[i + kiStride] );
-    pDst[i + kiStride2] = WELS_CLIP1( ((32 + kT1 - kT2) >> 6) + pDst[i + kiStride2] );
+    pDst[i + kiStride] = WelsClip1( ((32 + kT1 + kT2) >> 6) + pDst[i + kiStride] );
+    pDst[i + kiStride2] = WelsClip1( ((32 + kT1 - kT2) >> 6) + pDst[i + kiStride2] );
   }
 }
 
--- a/codec/decoder/core/src/get_intra_predictor.cpp
+++ b/codec/decoder/core/src/get_intra_predictor.cpp
@@ -428,7 +428,7 @@
   for (i = 0 ; i < 8 ; i ++) {
     for (j = 0 ; j < 8 ; j ++) {
       int32_t iTmp = (a + b * (j - 3) + c * (i - 3) + 16) >> 5;
-      iTmp = WELS_CLIP1 (iTmp);
+      iTmp = WelsClip1 (iTmp);
       pPred[j] = iTmp;
     }
     pPred += kiStride;
@@ -567,7 +567,7 @@
   for (i = 0 ; i < 16 ; i ++) {
     for (j = 0 ; j < 16 ; j ++) {
       int32_t iTmp = (a + b * (j - 7) + c * (i - 7) + 16) >> 5;
-      iTmp = WELS_CLIP1 (iTmp);
+      iTmp = WelsClip1 (iTmp);
       pPred[j] = iTmp;
     }
     pPred += kiStride;
--- a/codec/decoder/core/src/mc.cpp
+++ b/codec/decoder/core/src/mc.cpp
@@ -181,7 +181,7 @@
   int32_t i, j;
   for (i = 0; i < iHeight; i++) {
     for (j = 0; j < iWidth; j++) {
-      pDst[j] = WELS_CLIP1 ((FilterInput8bitWithStride_c (pSrc + j, 1) + 16) >> 5);
+      pDst[j] = WelsClip1 ((FilterInput8bitWithStride_c (pSrc + j, 1) + 16) >> 5);
     }
     pDst += iDstStride;
     pSrc += iSrcStride;
@@ -193,7 +193,7 @@
   int32_t i, j;
   for (i = 0; i < iHeight; i++) {
     for (j = 0; j < iWidth; j++) {
-      pDst[j] = WELS_CLIP1 ((FilterInput8bitWithStride_c (pSrc + j, iSrcStride) + 16) >> 5);
+      pDst[j] = WelsClip1 ((FilterInput8bitWithStride_c (pSrc + j, iSrcStride) + 16) >> 5);
     }
     pDst += iDstStride;
     pSrc += iSrcStride;
@@ -210,7 +210,7 @@
       iTmp[j] = FilterInput8bitWithStride_c (pSrc - 2 + j, iSrcStride);
     }
     for (k = 0; k < iWidth; k++) {
-      pDst[k] = WELS_CLIP1 ((HorFilterInput16bit_c (&iTmp[2 + k]) + 512) >> 10);
+      pDst[k] = WelsClip1 ((HorFilterInput16bit_c (&iTmp[2 + k]) + 512) >> 10);
     }
     pSrc += iSrcStride;
     pDst += iDstStride;
--- a/codec/encoder/core/src/decode_mb_aux.cpp
+++ b/codec/encoder/core/src/decode_mb_aux.cpp
@@ -189,10 +189,10 @@
     const int32_t kiVerDelR   = (iTemp[4 + i] >> 1) - iTemp[12 + i];
     const int32_t kiVerSumR = iTemp[4 + i]             + (iTemp[12 + i] >> 1);
 
-    pRec[i				]         = WELS_CLIP1 (pPred[i              ]         + ((kiVerSumL + kiVerSumR + 32) >> 6));
-    pRec[iStride + i		]     = WELS_CLIP1 (pPred[iPredStride + i  ]  + ((kiVerDelL + kiVerDelR + 32) >> 6));
-    pRec[iDstStridex2 + i] = WELS_CLIP1 (pPred[iPredStridex2 + i] + ((kiVerDelL - kiVerDelR + 32) >> 6));
-    pRec[iDstStridex3 + i] = WELS_CLIP1 (pPred[iPredStridex3 + i] + ((kiVerSumL - kiVerSumR + 32) >> 6));
+    pRec[i				]         = WelsClip1 (pPred[i              ]         + ((kiVerSumL + kiVerSumR + 32) >> 6));
+    pRec[iStride + i		]     = WelsClip1 (pPred[iPredStride + i  ]  + ((kiVerDelL + kiVerDelR + 32) >> 6));
+    pRec[iDstStridex2 + i] = WelsClip1 (pPred[iPredStridex2 + i] + ((kiVerDelL - kiVerDelR + 32) >> 6));
+    pRec[iDstStridex3 + i] = WelsClip1 (pPred[iPredStridex3 + i] + ((kiVerSumL - kiVerSumR + 32) >> 6));
   }
 }
 
@@ -225,7 +225,7 @@
 
   for (i = 0; i < 16; i ++) {
     for (j = 0; j < 16; j++) {
-      pRec[j] = WELS_CLIP1 (pPred[j] + ((pDctDc[ (i & 0x0C) + (j >> 2)] + 32) >> 6));
+      pRec[j] = WelsClip1 (pPred[j] + ((pDctDc[ (i & 0x0C) + (j >> 2)] + 32) >> 6));
     }
     pRec += iStride;
     pPred += iPredStride;
--- a/codec/encoder/core/src/get_intra_predictor.cpp
+++ b/codec/encoder/core/src/get_intra_predictor.cpp
@@ -468,7 +468,7 @@
 
   for (i = 0 ; i < 8 ; i ++) {
     for (j = 0 ; j < 8 ; j ++) {
-      pPred[j] = (uint8_t)WELS_CLIP1 ((iLTshift + iTopshift * (j - 3) + iLeftshift * (i - 3) + 16) >> 5);
+      pPred[j] = WelsClip1 ((iLTshift + iTopshift * (j - 3) + iLeftshift * (i - 3) + 16) >> 5);
     }
     pPred += I8x8_PRED_STRIDE;
   }
@@ -622,7 +622,7 @@
 
   for (i = 0 ; i < 16 ; i ++) {
     for (j = 0 ; j < 16 ; j ++) {
-      pPred[j] = (uint8_t)WELS_CLIP1 ((iLTshift + iTopshift * (j - 7) + iLeftshift * (i - 7) + 16) >> 5);
+      pPred[j] = WelsClip1 ((iLTshift + iTopshift * (j - 7) + iLeftshift * (i - 7) + 16) >> 5);
     }
     pPred += iPredStride;
   }
--- a/codec/encoder/core/src/mc.cpp
+++ b/codec/encoder/core/src/mc.cpp
@@ -192,7 +192,7 @@
   int32_t i, j;
   for (i = 0; i < iHeight; i++) {
     for (j = 0; j < 16; j++) {
-      pDst[j] = WELS_CLIP1 ((fpHorFilter (pSrc + j) + 16) >> 5);
+      pDst[j] = WelsClip1 ((fpHorFilter (pSrc + j) + 16) >> 5);
     }
     pDst += iDstStride;
     pSrc += iSrcStride;
@@ -204,7 +204,7 @@
   int32_t i, j;
   for (i = 0; i < iHeight; i++) {
     for (j = 0; j < 16; j++) {
-      pDst[j] = WELS_CLIP1 ((fpVerFilter (pSrc + j, iSrcStride) + 16) >> 5);
+      pDst[j] = WelsClip1 ((fpVerFilter (pSrc + j, iSrcStride) + 16) >> 5);
     }
     pDst += iDstStride;
     pSrc += iSrcStride;
@@ -221,7 +221,7 @@
       pTmp[j] = fpVerFilter (pSrc - 2 + j, iSrcStride);
     }
     for (k = 0; k < 16; k++) {
-      pDst[k] = WELS_CLIP1 ((fpHorFilterInput16Bits (&pTmp[2 + k]) + 512) >> 10);
+      pDst[k] = WelsClip1 ((fpHorFilterInput16Bits (&pTmp[2 + k]) + 512) >> 10);
     }
     pSrc += iSrcStride;
     pDst += iDstStride;
@@ -328,7 +328,7 @@
   int32_t i, j;
   for (i = 0; i < iHeight; i++) {
     for (j = 0; j < iWidth; j++) {
-      pDst[j] = WELS_CLIP1 ((fpHorFilter (pSrc + j) + 16) >> 5);
+      pDst[j] = WelsClip1 ((fpHorFilter (pSrc + j) + 16) >> 5);
     }
     pDst += iDstStride;
     pSrc += iSrcStride;
@@ -340,7 +340,7 @@
   int32_t i, j;
   for (i = 0; i < iHeight; i++) {
     for (j = 0; j < iWidth; j++) {
-      pDst[j] = WELS_CLIP1 ((fpVerFilter (pSrc + j, iSrcStride) + 16) >> 5);
+      pDst[j] = WelsClip1 ((fpVerFilter (pSrc + j, iSrcStride) + 16) >> 5);
     }
     pDst += iDstStride;
     pSrc += iSrcStride;
@@ -357,7 +357,7 @@
       pTmp[j] = fpVerFilter (pSrc - 2 + j, iSrcStride);
     }
     for (k = 0; k < iWidth; k++) {
-      pDst[k] = WELS_CLIP1 ((fpHorFilterInput16Bits (&pTmp[2 + k]) + 512) >> 10);
+      pDst[k] = WelsClip1 ((fpHorFilterInput16Bits (&pTmp[2 + k]) + 512) >> 10);
     }
     pSrc += iSrcStride;
     pDst += iDstStride;
--- a/test/DecUT_IdctResAddPred.cpp
+++ b/test/DecUT_IdctResAddPred.cpp
@@ -30,13 +30,13 @@
     int32_t kT3	= (32 + kT1 + kT2) >> 6;
     int32_t kT4	= (32 + kT1 - kT2) >> 6;
 
-    pDst[i] = WELS_CLIP1 (kT3 + pPred[i]);
-    pDst[i + kiStride3] = WELS_CLIP1 (kT4 + pPred[i + kiStride3]);
+    pDst[i] = WelsClip1 (kT3 + pPred[i]);
+    pDst[i + kiStride3] = WelsClip1 (kT4 + pPred[i + kiStride3]);
 
     kT1	= iSrc[i] - iSrc[i + 8];
     kT2	= (iSrc[i + 4] >> 1) - iSrc[i + 12];
-    pDst[i + kiStride] = WELS_CLIP1 (((32 + kT1 + kT2) >> 6) + pDst[i + kiStride]);
-    pDst[i + kiStride2] = WELS_CLIP1 (((32 + kT1 - kT2) >> 6) + pDst[i + kiStride2]);
+    pDst[i + kiStride] = WelsClip1 (((32 + kT1 + kT2) >> 6) + pDst[i + kiStride]);
+    pDst[i + kiStride2] = WelsClip1 (((32 + kT1 - kT2) >> 6) + pDst[i + kiStride2]);
   }
 }