Changeset 56 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComWeightPrediction.cpp
- Timestamp:
- 11 May 2012, 21:20:17 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/source/Lib/TLibCommon/TComWeightPrediction.cpp
r5 r56 2 2 * License, included below. This software may be subject to other third party 3 3 * and contributor rights, including patent rights, and no such rights are 4 * granted under this license. 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010-201 1,ISO/IEC6 * Copyright (c) 2010-2012, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 15 15 * this list of conditions and the following disclaimer in the documentation 16 16 * and/or other materials provided with the distribution. 17 * * Neither the name of the I SO/IEC nor the names of its contributors may17 * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may 18 18 * be used to endorse or promote products derived from this software without 19 19 * specific prior written permission. … … 32 32 */ 33 33 34 35 36 34 /** \file TComWeightPrediction.h 37 35 \brief weighting prediction class (header) … … 41 39 #include "TComSlice.h" 42 40 #include "TComWeightPrediction.h" 43 44 #ifdef WEIGHT_PRED 41 #include "TComInterpolationFilter.h" 45 42 46 43 // ==================================================================================================================== … … 51 48 } 52 49 50 /** weighted averaging for bi-pred 51 * \param TComYuv* pcYuvSrc0 52 * \param TComYuv* pcYuvSrc1 53 * \param iPartUnitIdx 54 * \param iWidth 55 * \param iHeight 56 * \param wpScalingParam *wp0 57 * \param wpScalingParam *wp1 58 * \param TComYuv* rpcYuvDst 59 * \returns Void 60 */ 53 61 Void TComWeightPrediction::addWeightBi( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, UInt iPartUnitIdx, UInt iWidth, UInt iHeight, wpScalingParam *wp0, wpScalingParam *wp1, TComYuv* rpcYuvDst, Bool bRound ) 54 62 { … … 69 77 // Luma : -------------------------------------------- 70 78 Int w0 = wp0[0].w; 71 Int o0 = wp0[0].o;72 79 Int offset = wp0[0].offset; 73 Int shiftNum = 14 - (g_uiBitDepth + g_uiBitIncrement);80 Int shiftNum = IF_INTERNAL_PREC - ( g_uiBitDepth + g_uiBitIncrement ); 74 81 Int shift = wp0[0].shift + shiftNum; 75 82 Int round = (1<<(shift-1)) * bRound; 76 83 Int w1 = wp1[0].w; 77 Int o1 = wp1[0].o;78 84 79 85 UInt iSrc0Stride = pcYuvSrc0->getStride(); 80 86 UInt iSrc1Stride = pcYuvSrc1->getStride(); 81 87 UInt iDstStride = rpcYuvDst->getStride(); 82 83 for ( y = iHeight-1; y >= 0; y-- ) 84 { 85 for ( x = iWidth-1; x >= 0; ) 86 { 87 // note: luma min width is 4 88 for ( y = iHeight-1; y >= 0; y-- ) 89 { 90 for ( x = iWidth-1; x >= 0; ) 91 { 92 // note: luma min width is 4 88 93 pDstY[x] = weightBidir(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x--; 89 94 pDstY[x] = weightBidir(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x--; 90 95 pDstY[x] = weightBidir(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x--; 91 96 pDstY[x] = weightBidir(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x--; 92 97 } 93 98 pSrcY0 += iSrc0Stride; 94 99 pSrcY1 += iSrc1Stride; 95 100 pDstY += iDstStride; 96 101 } 102 97 103 98 104 // Chroma U : -------------------------------------------- 99 105 w0 = wp0[1].w; 100 o0 = wp0[1].o;101 106 offset = wp0[1].offset; 102 107 shift = wp0[1].shift + shiftNum; 103 108 round = (1<<(shift-1)); 104 109 w1 = wp1[1].w; 105 o1 = wp1[1].o;106 110 107 111 iSrc0Stride = pcYuvSrc0->getCStride(); … … 119 123 pDstU[x] = weightBidir(w0,pSrcU0[x], w1,pSrcU1[x], round, shift, offset); x--; 120 124 pDstU[x] = weightBidir(w0,pSrcU0[x], w1,pSrcU1[x], round, shift, offset); x--; 121 125 } 122 126 pSrcU0 += iSrc0Stride; 123 127 pSrcU1 += iSrc1Stride; … … 127 131 // Chroma V : -------------------------------------------- 128 132 w0 = wp0[2].w; 129 o0 = wp0[2].o;130 133 offset = wp0[2].offset; 131 134 shift = wp0[2].shift + shiftNum; 132 135 round = (1<<(shift-1)); 133 136 w1 = wp1[2].w; 134 o1 = wp1[2].o;135 137 136 138 for ( y = iHeight-1; y >= 0; y-- ) … … 139 141 { 140 142 // note: chroma min width is 2 141 pDstV[x] = weightBidir(w0,pSrcV0[x], w1,pSrcV1[x], round, shift, offset); x--;142 143 pDstV[x] = weightBidir(w0,pSrcV0[x], w1,pSrcV1[x], round, shift, offset); x--; 143 } 144 pDstV[x] = weightBidir(w0,pSrcV0[x], w1,pSrcV1[x], round, shift, offset); x--; 145 } 144 146 pSrcV0 += iSrc0Stride; 145 147 pSrcV1 += iSrc1Stride; … … 148 150 } 149 151 152 /** weighted averaging for uni-pred 153 * \param TComYuv* pcYuvSrc0 154 * \param iPartUnitIdx 155 * \param iWidth 156 * \param iHeight 157 * \param wpScalingParam *wp0 158 * \param TComYuv* rpcYuvDst 159 * \returns Void 160 */ 150 161 Void TComWeightPrediction::addWeightUni( TComYuv* pcYuvSrc0, UInt iPartUnitIdx, UInt iWidth, UInt iHeight, wpScalingParam *wp0, TComYuv* rpcYuvDst ) 151 162 { … … 163 174 Int w0 = wp0[0].w; 164 175 Int offset = wp0[0].offset; 165 Int shift = wp0[0].shift;166 Int round = wp0[0].round;167 176 Int shiftNum = IF_INTERNAL_PREC - ( g_uiBitDepth + g_uiBitIncrement ); 177 Int shift = wp0[0].shift + shiftNum; 178 Int round = (1<<(shift-1)); 168 179 UInt iSrc0Stride = pcYuvSrc0->getStride(); 169 180 UInt iDstStride = rpcYuvDst->getStride(); … … 186 197 w0 = wp0[1].w; 187 198 offset = wp0[1].offset; 188 shift = wp0[1].shift ;189 round = wp0[1].round;199 shift = wp0[1].shift + shiftNum; 200 round = (1<<(shift-1)); 190 201 191 202 iSrc0Stride = pcYuvSrc0->getCStride(); … … 200 211 { 201 212 // note: chroma min width is 2 202 pDstU[x] = weightUnidir(w0,pSrcU0[x], round, shift, offset); x--;203 213 pDstU[x] = weightUnidir(w0,pSrcU0[x], round, shift, offset); x--; 204 } 214 pDstU[x] = weightUnidir(w0,pSrcU0[x], round, shift, offset); x--; 215 } 205 216 pSrcU0 += iSrc0Stride; 206 217 pDstU += iDstStride; … … 210 221 w0 = wp0[2].w; 211 222 offset = wp0[2].offset; 212 shift = wp0[2].shift ;213 round = wp0[2].round;223 shift = wp0[2].shift + shiftNum; 224 round = (1<<(shift-1)); 214 225 215 226 for ( y = iHeight-1; y >= 0; y-- ) … … 218 229 { 219 230 // note: chroma min width is 2 220 pDstV[x] = weightUnidir(w0,pSrcV0[x], round, shift, offset); x--;221 231 pDstV[x] = weightUnidir(w0,pSrcV0[x], round, shift, offset); x--; 222 } 232 pDstV[x] = weightUnidir(w0,pSrcV0[x], round, shift, offset); x--; 233 } 223 234 pSrcV0 += iSrc0Stride; 224 235 pDstV += iDstStride; … … 228 239 //======================================================= 229 240 // getWpScaling() 230 // When called before SAD computation, ibdi is (g_uiBitDepth+g_uiBitIncrement),231 // when called before motion compensation (weighted prediction computation), ibdi is 14 (#if HIGH_ACCURACY_BI in bi-dir only).232 241 //======================================================= 233 Void TComWeightPrediction::getWpScaling( TComDataCU* pcCU, Int iRefIdx0, Int iRefIdx1, wpScalingParam *&wp0 , wpScalingParam *&wp1 , Int ibdi) 242 /** derivation of wp tables 243 * \param TComDataCU* pcCU 244 * \param iRefIdx0 245 * \param iRefIdx1 246 * \param wpScalingParam *&wp0 247 * \param wpScalingParam *&wp1 248 * \param ibdi 249 * \returns Void 250 */ 251 Void TComWeightPrediction::getWpScaling( TComDataCU* pcCU, Int iRefIdx0, Int iRefIdx1, wpScalingParam *&wp0, wpScalingParam *&wp1, Int ibdi) 234 252 { 235 253 TComSlice* pcSlice = pcCU->getSlice(); … … 313 331 wp1[yuv].w = wp1[yuv].iWeight; 314 332 wp1[yuv].o = wp1[yuv].iOffset * (1 << (m_ibdi-8)); 315 wp0[yuv].offset = ( ( wp0[yuv].o + wp1[yuv].o + 1 ) >> 1 );333 wp0[yuv].offset = wp0[yuv].o + wp1[yuv].o; 316 334 wp0[yuv].shift = wp0[yuv].uiLog2WeightDenom + 1; 317 335 wp0[yuv].round = (1 << wp0[yuv].uiLog2WeightDenom); … … 346 364 } 347 365 348 Void TComWeightPrediction::xWeightedPredictionUni( TComDataCU* pcCU, TComYuv* pcYuvSrc, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx ) 349 { 350 wpScalingParam *pwp, *pwpTmp; 351 Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); assert (iRefIdx >= 0); 352 Int ibdi = (g_uiBitDepth+g_uiBitIncrement); 353 354 if ( eRefPicList == REF_PIC_LIST_0 ) 355 { 356 getWpScaling(pcCU, iRefIdx, -1, pwp, pwpTmp, ibdi); 357 } 358 else 359 { 360 getWpScaling(pcCU, -1, iRefIdx, pwpTmp, pwp, ibdi); 361 } 362 addWeightUni( pcYuvSrc, uiPartAddr, iWidth, iHeight, pwp, rpcYuvPred ); 363 } 364 366 /** weighted prediction for bi-pred 367 * \param TComDataCU* pcCU 368 * \param TComYuv* pcYuvSrc0 369 * \param TComYuv* pcYuvSrc1 370 * \param iRefIdx0 371 * \param iRefIdx1 372 * \param uiPartIdx 373 * \param iWidth 374 * \param iHeight 375 * \param TComYuv* rpcYuvDst 376 * \returns Void 377 */ 365 378 Void TComWeightPrediction::xWeightedPredictionBi( TComDataCU* pcCU, TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv* rpcYuvDst ) 366 379 { … … 368 381 TComPPS *pps = pcCU->getSlice()->getPPS(); 369 382 370 if ( !pps->getUseWP() ) { 371 printf("TComWeightPrediction::xWeightedPredictionBi():\tassert failed: useWP is false.\n"); 372 exit(0); 373 } 383 assert( pps->getWPBiPredIdc() != 0 ); 374 384 375 385 Int ibdi = (g_uiBitDepth+g_uiBitIncrement); … … 389 399 } 390 400 else 401 { 391 402 assert (0); 392 393 } 394 395 #endif // WEIGHT_PRED 396 403 } 404 } 405 406 /** weighted prediction for uni-pred 407 * \param TComDataCU* pcCU 408 * \param TComYuv* pcYuvSrc 409 * \param uiPartAddr 410 * \param iWidth 411 * \param iHeight 412 * \param eRefPicList 413 * \param TComYuv*& rpcYuvPred 414 * \param iPartIdx 415 * \param iRefIdx 416 * \returns Void 417 */ 418 Void TComWeightPrediction::xWeightedPredictionUni( TComDataCU* pcCU, TComYuv* pcYuvSrc, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iPartIdx, Int iRefIdx) 419 { 420 wpScalingParam *pwp, *pwpTmp; 421 if ( iRefIdx < 0 ) 422 { 423 iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr ); 424 } 425 assert (iRefIdx >= 0); 426 427 Int ibdi = (g_uiBitDepth+g_uiBitIncrement); 428 429 if ( eRefPicList == REF_PIC_LIST_0 ) 430 { 431 getWpScaling(pcCU, iRefIdx, -1, pwp, pwpTmp, ibdi); 432 } 433 else 434 { 435 getWpScaling(pcCU, -1, iRefIdx, pwpTmp, pwp, ibdi); 436 } 437 addWeightUni( pcYuvSrc, uiPartAddr, iWidth, iHeight, pwp, rpcYuvPred ); 438 } 439 440
Note: See TracChangeset for help on using the changeset viewer.