Changeset 608 in 3DVCSoftware for trunk/source/Lib/TLibCommon/TComWeightPrediction.cpp
 Timestamp:
 1 Sep 2013, 22:47:26 (11 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/source/Lib/TLibCommon/TComWeightPrediction.cpp
r56 r608 4 4 * granted under this license. 5 5 * 6 * Copyright (c) 2010201 2, ITU/ISO/IEC6 * Copyright (c) 20102013, ITU/ISO/IEC 7 7 * All rights reserved. 8 8 * … … 41 41 #include "TComInterpolationFilter.h" 42 42 43 static inline Pel weightBidirY( Int w0, Pel P0, Int w1, Pel P1, Int round, Int shift, Int offset) 44 { 45 return ClipY( ( (w0*(P0 + IF_INTERNAL_OFFS) + w1*(P1 + IF_INTERNAL_OFFS) + round + (offset << (shift1))) >> shift ) ); 46 } 47 static inline Pel weightBidirC( Int w0, Pel P0, Int w1, Pel P1, Int round, Int shift, Int offset) 48 { 49 return ClipC( ( (w0*(P0 + IF_INTERNAL_OFFS) + w1*(P1 + IF_INTERNAL_OFFS) + round + (offset << (shift1))) >> shift ) ); 50 } 51 52 static inline Pel weightUnidirY( Int w0, Pel P0, Int round, Int shift, Int offset) 53 { 54 return ClipY( ( (w0*(P0 + IF_INTERNAL_OFFS) + round) >> shift ) + offset ); 55 } 56 static inline Pel weightUnidirC( Int w0, Pel P0, Int round, Int shift, Int offset) 57 { 58 return ClipC( ( (w0*(P0 + IF_INTERNAL_OFFS) + round) >> shift ) + offset ); 59 } 60 43 61 // ==================================================================================================================== 44 62 // Class definition … … 78 96 Int w0 = wp0[0].w; 79 97 Int offset = wp0[0].offset; 80 Int shiftNum = IF_INTERNAL_PREC  ( g_uiBitDepth + g_uiBitIncrement );98 Int shiftNum = IF_INTERNAL_PREC  g_bitDepthY; 81 99 Int shift = wp0[0].shift + shiftNum; 82 Int round = (1<<(shift1)) * bRound;100 Int round = shift?(1<<(shift1)) * bRound:0; 83 101 Int w1 = wp1[0].w; 84 102 … … 91 109 { 92 110 // note: luma min width is 4 93 pDstY[x] = weightBidir (w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x;94 pDstY[x] = weightBidir (w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x;95 pDstY[x] = weightBidir (w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x;96 pDstY[x] = weightBidir (w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x;111 pDstY[x] = weightBidirY(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x; 112 pDstY[x] = weightBidirY(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x; 113 pDstY[x] = weightBidirY(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x; 114 pDstY[x] = weightBidirY(w0,pSrcY0[x], w1,pSrcY1[x], round, shift, offset); x; 97 115 } 98 116 pSrcY0 += iSrc0Stride; … … 105 123 w0 = wp0[1].w; 106 124 offset = wp0[1].offset; 125 shiftNum = IF_INTERNAL_PREC  g_bitDepthC; 107 126 shift = wp0[1].shift + shiftNum; 108 round = (1<<(shift1));127 round = shift?(1<<(shift1)):0; 109 128 w1 = wp1[1].w; 110 129 … … 121 140 { 122 141 // note: chroma min width is 2 123 pDstU[x] = weightBidir (w0,pSrcU0[x], w1,pSrcU1[x], round, shift, offset); x;124 pDstU[x] = weightBidir (w0,pSrcU0[x], w1,pSrcU1[x], round, shift, offset); x;142 pDstU[x] = weightBidirC(w0,pSrcU0[x], w1,pSrcU1[x], round, shift, offset); x; 143 pDstU[x] = weightBidirC(w0,pSrcU0[x], w1,pSrcU1[x], round, shift, offset); x; 125 144 } 126 145 pSrcU0 += iSrc0Stride; … … 133 152 offset = wp0[2].offset; 134 153 shift = wp0[2].shift + shiftNum; 135 round = (1<<(shift1));154 round = shift?(1<<(shift1)):0; 136 155 w1 = wp1[2].w; 137 156 … … 141 160 { 142 161 // note: chroma min width is 2 143 pDstV[x] = weightBidir (w0,pSrcV0[x], w1,pSrcV1[x], round, shift, offset); x;144 pDstV[x] = weightBidir (w0,pSrcV0[x], w1,pSrcV1[x], round, shift, offset); x;162 pDstV[x] = weightBidirC(w0,pSrcV0[x], w1,pSrcV1[x], round, shift, offset); x; 163 pDstV[x] = weightBidirC(w0,pSrcV0[x], w1,pSrcV1[x], round, shift, offset); x; 145 164 } 146 165 pSrcV0 += iSrc0Stride; … … 174 193 Int w0 = wp0[0].w; 175 194 Int offset = wp0[0].offset; 176 Int shiftNum = IF_INTERNAL_PREC  ( g_uiBitDepth + g_uiBitIncrement );195 Int shiftNum = IF_INTERNAL_PREC  g_bitDepthY; 177 196 Int shift = wp0[0].shift + shiftNum; 178 Int round = (1<<(shift1));197 Int round = shift?(1<<(shift1)):0; 179 198 UInt iSrc0Stride = pcYuvSrc0>getStride(); 180 199 UInt iDstStride = rpcYuvDst>getStride(); … … 185 204 { 186 205 // note: luma min width is 4 187 pDstY[x] = weightUnidir (w0,pSrcY0[x], round, shift, offset); x;188 pDstY[x] = weightUnidir (w0,pSrcY0[x], round, shift, offset); x;189 pDstY[x] = weightUnidir (w0,pSrcY0[x], round, shift, offset); x;190 pDstY[x] = weightUnidir (w0,pSrcY0[x], round, shift, offset); x;206 pDstY[x] = weightUnidirY(w0,pSrcY0[x], round, shift, offset); x; 207 pDstY[x] = weightUnidirY(w0,pSrcY0[x], round, shift, offset); x; 208 pDstY[x] = weightUnidirY(w0,pSrcY0[x], round, shift, offset); x; 209 pDstY[x] = weightUnidirY(w0,pSrcY0[x], round, shift, offset); x; 191 210 } 192 211 pSrcY0 += iSrc0Stride; … … 197 216 w0 = wp0[1].w; 198 217 offset = wp0[1].offset; 218 shiftNum = IF_INTERNAL_PREC  g_bitDepthC; 199 219 shift = wp0[1].shift + shiftNum; 200 round = (1<<(shift1));220 round = shift?(1<<(shift1)):0; 201 221 202 222 iSrc0Stride = pcYuvSrc0>getCStride(); … … 211 231 { 212 232 // note: chroma min width is 2 213 pDstU[x] = weightUnidir (w0,pSrcU0[x], round, shift, offset); x;214 pDstU[x] = weightUnidir (w0,pSrcU0[x], round, shift, offset); x;233 pDstU[x] = weightUnidirC(w0,pSrcU0[x], round, shift, offset); x; 234 pDstU[x] = weightUnidirC(w0,pSrcU0[x], round, shift, offset); x; 215 235 } 216 236 pSrcU0 += iSrc0Stride; … … 222 242 offset = wp0[2].offset; 223 243 shift = wp0[2].shift + shiftNum; 224 round = (1<<(shift1));244 round = shift?(1<<(shift1)):0; 225 245 226 246 for ( y = iHeight1; y >= 0; y ) … … 229 249 { 230 250 // note: chroma min width is 2 231 pDstV[x] = weightUnidir (w0,pSrcV0[x], round, shift, offset); x;232 pDstV[x] = weightUnidir (w0,pSrcV0[x], round, shift, offset); x;251 pDstV[x] = weightUnidirC(w0,pSrcV0[x], round, shift, offset); x; 252 pDstV[x] = weightUnidirC(w0,pSrcV0[x], round, shift, offset); x; 233 253 } 234 254 pSrcV0 += iSrc0Stride; … … 249 269 * \returns Void 250 270 */ 251 Void TComWeightPrediction::getWpScaling( TComDataCU* pcCU, Int iRefIdx0, Int iRefIdx1, wpScalingParam *&wp0, wpScalingParam *&wp1, Int ibdi) 252 { 271 Void TComWeightPrediction::getWpScaling( TComDataCU* pcCU, Int iRefIdx0, Int iRefIdx1, wpScalingParam *&wp0, wpScalingParam *&wp1) 272 { 273 assert(iRefIdx0 >= 0  iRefIdx1 >= 0); 274 253 275 TComSlice* pcSlice = pcCU>getSlice(); 254 276 TComPPS* pps = pcCU>getSlice()>getPPS(); 255 UInt uiWPBiPredIdc = pps>getWPBiPredIdc();277 Bool wpBiPred = pps>getWPBiPred(); 256 278 wpScalingParam* pwp; 257 279 Bool bBiDir = (iRefIdx0>=0 && iRefIdx1>=0); 258 280 Bool bUniDir = !bBiDir; 259 281 260 m_ibdi = ibdi; 261 262 if ( bUniDir  (uiWPBiPredIdc==1) ) 282 if ( bUniDir  wpBiPred ) 263 283 { // explicit  264 284 if ( iRefIdx0 >= 0 ) … … 271 291 } 272 292 } 273 else if ( uiWPBiPredIdc == 2 )274 { // implicit 275 Int poc0 = pcSlice>getRefPOC(REF_PIC_LIST_0, iRefIdx0);276 Int poc1 = pcSlice>getRefPOC(REF_PIC_LIST_1, iRefIdx1);277 Int pocCur = pcSlice>getPOC();278 Int td = Clip3(128,127,poc1  poc0);279 Int tb = Clip3(128,127,pocCur  poc0);280 Int tx = ( td != 0 ) ? ( ( 16384 + abs( td / 2 ) ) / td ) : (0);281 Int DistScaleFactor = Clip3( 1024, 1023, ( tb * tx + 32 ) >> 6 );282 283 Bool implicitScale=true;284 if ( poc1==poc0  (DistScaleFactor>>2)<(64)  (DistScaleFactor>>2)>128 )285 {286 implicitScale = false;287 }288 289 for ( int e=0 ; e<2 ; e++ )290 {291 pwp = (e==0) ? m_wp0 : m_wp1;292 for ( int k=0 ; k<3 ; k++ ) // 3 components: Y,U,V293 {294 pwp>uiLog2WeightDenom = 5; pwp>iOffset = 0; pwp>bPresentFlag = true;295 if ( implicitScale )296 {297 pwp>iWeight = (e==0) ? (64  (DistScaleFactor >> 2)) : (DistScaleFactor >> 2);298 }299 else300 {301 pwp>iWeight = 32;302 }303 pwp++;304 }305 306 }307 308 wp0 = m_wp0;309 wp1 = m_wp1;310 }311 293 else 312 294 { … … 325 307 if ( bBiDir ) 326 308 { // BiDir case 327 for ( int yuv=0 ; yuv<3 ; yuv++ ) 328 { 309 for ( Int yuv=0 ; yuv<3 ; yuv++ ) 310 { 311 Int bitDepth = yuv ? g_bitDepthC : g_bitDepthY; 329 312 wp0[yuv].w = wp0[yuv].iWeight; 330 wp0[yuv].o = wp0[yuv].iOffset * (1 << ( m_ibdi8));313 wp0[yuv].o = wp0[yuv].iOffset * (1 << (bitDepth8)); 331 314 wp1[yuv].w = wp1[yuv].iWeight; 332 wp1[yuv].o = wp1[yuv].iOffset * (1 << ( m_ibdi8));315 wp1[yuv].o = wp1[yuv].iOffset * (1 << (bitDepth8)); 333 316 wp0[yuv].offset = wp0[yuv].o + wp1[yuv].o; 334 317 wp0[yuv].shift = wp0[yuv].uiLog2WeightDenom + 1; … … 342 325 { // Unidir 343 326 pwp = (iRefIdx0>=0) ? wp0 : wp1 ; 344 if ( uiWPBiPredIdc == 2 ) 345 { 346 for ( int yuv=0 ; yuv<3 ; yuv++ ) 347 { 348 pwp[yuv].w = 1; 349 pwp[yuv].offset = 0; 350 pwp[yuv].shift = 0; 351 pwp[yuv].round = 0; 352 } 353 } 354 else { 355 for ( int yuv=0 ; yuv<3 ; yuv++ ) 356 { 357 pwp[yuv].w = pwp[yuv].iWeight; 358 pwp[yuv].offset = pwp[yuv].iOffset * (1 << (m_ibdi8)); 359 pwp[yuv].shift = pwp[yuv].uiLog2WeightDenom; 360 pwp[yuv].round = (pwp[yuv].uiLog2WeightDenom>=1) ? (1 << (pwp[yuv].uiLog2WeightDenom1)) : (0); 361 } 327 for ( Int yuv=0 ; yuv<3 ; yuv++ ) 328 { 329 Int bitDepth = yuv ? g_bitDepthC : g_bitDepthY; 330 pwp[yuv].w = pwp[yuv].iWeight; 331 pwp[yuv].offset = pwp[yuv].iOffset * (1 << (bitDepth8)); 332 pwp[yuv].shift = pwp[yuv].uiLog2WeightDenom; 333 pwp[yuv].round = (pwp[yuv].uiLog2WeightDenom>=1) ? (1 << (pwp[yuv].uiLog2WeightDenom1)) : (0); 362 334 } 363 335 } … … 380 352 wpScalingParam *pwp0, *pwp1; 381 353 TComPPS *pps = pcCU>getSlice()>getPPS(); 382 383 assert( pps>getWPBiPredIdc() != 0 ); 384 385 Int ibdi = (g_uiBitDepth+g_uiBitIncrement); 386 getWpScaling(pcCU, iRefIdx0, iRefIdx1, pwp0, pwp1, ibdi); 354 assert( pps>getWPBiPred()); 355 356 getWpScaling(pcCU, iRefIdx0, iRefIdx1, pwp0, pwp1); 387 357 388 358 if( iRefIdx0 >= 0 && iRefIdx1 >= 0 ) … … 416 386 * \returns Void 417 387 */ 418 Void TComWeightPrediction::xWeightedPredictionUni( TComDataCU* pcCU, TComYuv* pcYuvSrc, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int i PartIdx, Int iRefIdx)388 Void TComWeightPrediction::xWeightedPredictionUni( TComDataCU* pcCU, TComYuv* pcYuvSrc, UInt uiPartAddr, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Int iRefIdx) 419 389 { 420 390 wpScalingParam *pwp, *pwpTmp; … … 425 395 assert (iRefIdx >= 0); 426 396 427 Int ibdi = (g_uiBitDepth+g_uiBitIncrement);428 429 397 if ( eRefPicList == REF_PIC_LIST_0 ) 430 398 { 431 getWpScaling(pcCU, iRefIdx, 1, pwp, pwpTmp , ibdi);399 getWpScaling(pcCU, iRefIdx, 1, pwp, pwpTmp); 432 400 } 433 401 else 434 402 { 435 getWpScaling(pcCU, 1, iRefIdx, pwpTmp, pwp , ibdi);403 getWpScaling(pcCU, 1, iRefIdx, pwpTmp, pwp); 436 404 } 437 405 addWeightUni( pcYuvSrc, uiPartAddr, iWidth, iHeight, pwp, rpcYuvPred );
Note: See TracChangeset for help on using the changeset viewer.