[313] | 1 | /* The copyright in this software is being made available under the BSD |
---|
| 2 | * License, included below. This software may be subject to other third party |
---|
| 3 | * and contributor rights, including patent rights, and no such rights are |
---|
[494] | 4 | * granted under this license. |
---|
[313] | 5 | * |
---|
[595] | 6 | * Copyright (c) 2010-2014, ITU/ISO/IEC |
---|
[313] | 7 | * All rights reserved. |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * |
---|
| 12 | * * Redistributions of source code must retain the above copyright notice, |
---|
| 13 | * this list of conditions and the following disclaimer. |
---|
| 14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
| 15 | * this list of conditions and the following disclaimer in the documentation |
---|
| 16 | * and/or other materials provided with the distribution. |
---|
| 17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
| 18 | * be used to endorse or promote products derived from this software without |
---|
| 19 | * specific prior written permission. |
---|
| 20 | * |
---|
| 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
| 22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
| 23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
| 24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
| 25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
| 26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
| 27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
| 28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
| 29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
| 31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 32 | */ |
---|
| 33 | |
---|
| 34 | /** \file WeightPredAnalysis.cpp |
---|
| 35 | \brief weighted prediction encoder class |
---|
| 36 | */ |
---|
| 37 | |
---|
| 38 | #include "../TLibCommon/TypeDef.h" |
---|
| 39 | #include "../TLibCommon/TComSlice.h" |
---|
| 40 | #include "../TLibCommon/TComPic.h" |
---|
| 41 | #include "../TLibCommon/TComPicYuv.h" |
---|
| 42 | #include "WeightPredAnalysis.h" |
---|
| 43 | |
---|
| 44 | #define ABS(a) ((a) < 0 ? - (a) : (a)) |
---|
| 45 | #define DTHRESH (0.99) |
---|
| 46 | |
---|
| 47 | WeightPredAnalysis::WeightPredAnalysis() |
---|
| 48 | { |
---|
[1029] | 49 | for ( UInt lst =0 ; lst<NUM_REF_PIC_LIST_01 ; lst++ ) |
---|
[313] | 50 | { |
---|
[494] | 51 | for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) |
---|
[313] | 52 | { |
---|
[1029] | 53 | for ( Int comp=0 ; comp<MAX_NUM_COMPONENT ;comp++ ) |
---|
[313] | 54 | { |
---|
[1029] | 55 | WPScalingParam *pwp = &(m_wp[lst][iRefIdx][comp]); |
---|
[313] | 56 | pwp->bPresentFlag = false; |
---|
| 57 | pwp->uiLog2WeightDenom = 0; |
---|
| 58 | pwp->iWeight = 1; |
---|
| 59 | pwp->iOffset = 0; |
---|
| 60 | } |
---|
| 61 | } |
---|
| 62 | } |
---|
| 63 | } |
---|
| 64 | |
---|
[1029] | 65 | |
---|
[313] | 66 | /** calculate AC and DC values for current original image |
---|
| 67 | * \param TComSlice *slice |
---|
| 68 | * \returns Void |
---|
| 69 | */ |
---|
[1029] | 70 | Void WeightPredAnalysis::xCalcACDCParamSlice(TComSlice *const slice) |
---|
[313] | 71 | { |
---|
| 72 | //===== calculate AC/DC value ===== |
---|
| 73 | TComPicYuv* pPic = slice->getPic()->getPicYuvOrg(); |
---|
| 74 | |
---|
[1029] | 75 | WPACDCParam weightACDCParam[MAX_NUM_COMPONENT]; |
---|
[313] | 76 | |
---|
[1029] | 77 | for(Int componentIndex = 0; componentIndex < pPic->getNumberValidComponents(); componentIndex++) |
---|
| 78 | { |
---|
| 79 | const ComponentID compID = ComponentID(componentIndex); |
---|
[313] | 80 | |
---|
[1029] | 81 | // calculate DC/AC value for channel |
---|
| 82 | |
---|
| 83 | const Int iStride = pPic->getStride(compID); |
---|
| 84 | const Int iWidth = pPic->getWidth(compID); |
---|
| 85 | const Int iHeight = pPic->getHeight(compID); |
---|
| 86 | |
---|
| 87 | const Int iSample = iWidth*iHeight; |
---|
| 88 | |
---|
| 89 | Int64 iOrgDC = 0; |
---|
| 90 | { |
---|
| 91 | const Pel *pPel = pPic->getAddr(compID); |
---|
| 92 | |
---|
| 93 | for(Int y = 0; y < iHeight; y++, pPel+=iStride ) |
---|
| 94 | for(Int x = 0; x < iWidth; x++ ) |
---|
| 95 | iOrgDC += (Int)( pPel[x] ); |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | const Int64 iOrgNormDC = ((iOrgDC+(iSample>>1)) / iSample); |
---|
| 99 | |
---|
| 100 | Int64 iOrgAC = 0; |
---|
| 101 | { |
---|
| 102 | const Pel *pPel = pPic->getAddr(compID); |
---|
| 103 | |
---|
| 104 | for(Int y = 0; y < iHeight; y++, pPel += iStride ) |
---|
| 105 | for(Int x = 0; x < iWidth; x++ ) |
---|
| 106 | iOrgAC += abs( (Int)pPel[x] - (Int)iOrgNormDC ); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | const Int fixedBitShift = (slice->getSPS()->getUseHighPrecisionPredictionWeighting())?RExt__PREDICTION_WEIGHTING_ANALYSIS_DC_PRECISION:0; |
---|
[1201] | 110 | weightACDCParam[compID].iDC = (((iOrgDC<<fixedBitShift)+(iSample>>1)) / iSample); |
---|
| 111 | weightACDCParam[compID].iAC = iOrgAC; |
---|
| 112 | #if SVC_EXTENSION |
---|
[1029] | 113 | weightACDCParam[compID].iSamples = iSample; |
---|
[494] | 114 | #endif |
---|
[1029] | 115 | } |
---|
[313] | 116 | |
---|
| 117 | slice->setWpAcDcParam(weightACDCParam); |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | /** check weighted pred or non-weighted pred |
---|
| 121 | * \param TComSlice *slice |
---|
| 122 | * \returns Void |
---|
| 123 | */ |
---|
[1029] | 124 | Void WeightPredAnalysis::xCheckWPEnable(TComSlice *const slice) |
---|
[313] | 125 | { |
---|
[1029] | 126 | const TComPicYuv *pPic = slice->getPic()->getPicYuvOrg(); |
---|
| 127 | |
---|
[313] | 128 | Int iPresentCnt = 0; |
---|
[1029] | 129 | for ( UInt lst=0 ; lst<NUM_REF_PIC_LIST_01 ; lst++ ) |
---|
[313] | 130 | { |
---|
[494] | 131 | for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) |
---|
[313] | 132 | { |
---|
[1029] | 133 | for(Int componentIndex = 0; componentIndex < pPic->getNumberValidComponents(); componentIndex++) |
---|
[313] | 134 | { |
---|
[1029] | 135 | WPScalingParam *pwp = &(m_wp[lst][iRefIdx][componentIndex]); |
---|
[313] | 136 | iPresentCnt += (Int)pwp->bPresentFlag; |
---|
| 137 | } |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | if(iPresentCnt==0) |
---|
| 142 | { |
---|
[1235] | 143 | slice->setTestWeightPred(false); |
---|
| 144 | slice->setTestWeightBiPred(false); |
---|
[1029] | 145 | |
---|
| 146 | for ( UInt lst=0 ; lst<NUM_REF_PIC_LIST_01 ; lst++ ) |
---|
[313] | 147 | { |
---|
[494] | 148 | for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) |
---|
[313] | 149 | { |
---|
[1029] | 150 | for(Int componentIndex = 0; componentIndex < pPic->getNumberValidComponents(); componentIndex++) |
---|
[313] | 151 | { |
---|
[1029] | 152 | WPScalingParam *pwp = &(m_wp[lst][iRefIdx][componentIndex]); |
---|
| 153 | |
---|
[313] | 154 | pwp->bPresentFlag = false; |
---|
| 155 | pwp->uiLog2WeightDenom = 0; |
---|
| 156 | pwp->iWeight = 1; |
---|
| 157 | pwp->iOffset = 0; |
---|
| 158 | } |
---|
| 159 | } |
---|
| 160 | } |
---|
| 161 | slice->setWpScaling( m_wp ); |
---|
| 162 | } |
---|
[1235] | 163 | else |
---|
| 164 | { |
---|
| 165 | slice->setTestWeightPred(slice->getPPS()->getUseWP()); |
---|
| 166 | slice->setTestWeightBiPred(slice->getPPS()->getWPBiPred()); |
---|
| 167 | } |
---|
[313] | 168 | } |
---|
| 169 | |
---|
[1029] | 170 | |
---|
[313] | 171 | /** estimate wp tables for explicit wp |
---|
| 172 | * \param TComSlice *slice |
---|
| 173 | */ |
---|
[1029] | 174 | Void WeightPredAnalysis::xEstimateWPParamSlice(TComSlice *const slice) |
---|
[313] | 175 | { |
---|
[1029] | 176 | Int iDenom = 6; |
---|
[313] | 177 | Bool validRangeFlag = false; |
---|
| 178 | |
---|
| 179 | if(slice->getNumRefIdx(REF_PIC_LIST_0)>3) |
---|
| 180 | { |
---|
[1029] | 181 | iDenom = 7; |
---|
[313] | 182 | } |
---|
| 183 | |
---|
| 184 | do |
---|
| 185 | { |
---|
[1029] | 186 | validRangeFlag = xUpdatingWPParameters(slice, iDenom); |
---|
[313] | 187 | if (!validRangeFlag) |
---|
| 188 | { |
---|
| 189 | iDenom--; // decrement to satisfy the range limitation |
---|
| 190 | } |
---|
| 191 | } while (validRangeFlag == false); |
---|
| 192 | |
---|
[1235] | 193 | // selecting whether WP is used, or not (fast search) |
---|
| 194 | // NOTE: This is not operating on a slice, but the entire picture. |
---|
[1029] | 195 | xSelectWP(slice, iDenom); |
---|
[494] | 196 | |
---|
[313] | 197 | slice->setWpScaling( m_wp ); |
---|
| 198 | } |
---|
| 199 | |
---|
[1029] | 200 | |
---|
[313] | 201 | /** update wp tables for explicit wp w.r.t ramge limitation |
---|
| 202 | * \param TComSlice *slice |
---|
| 203 | * \returns Bool |
---|
| 204 | */ |
---|
[1029] | 205 | Bool WeightPredAnalysis::xUpdatingWPParameters(TComSlice *const slice, const Int log2Denom) |
---|
[313] | 206 | { |
---|
[1029] | 207 | const Int numComp = slice->getPic()->getPicYuvOrg()->getNumberValidComponents(); |
---|
| 208 | const Bool bUseHighPrecisionWeighting = slice->getSPS()->getUseHighPrecisionPredictionWeighting(); |
---|
| 209 | const Int numPredDir = slice->isInterP() ? 1 : 2; |
---|
| 210 | |
---|
| 211 | assert (numPredDir <= Int(NUM_REF_PIC_LIST_01)); |
---|
| 212 | |
---|
[313] | 213 | for ( Int refList = 0; refList < numPredDir; refList++ ) |
---|
| 214 | { |
---|
[1029] | 215 | const RefPicList eRefPicList = ( refList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); |
---|
| 216 | |
---|
[313] | 217 | for ( Int refIdxTemp = 0; refIdxTemp < slice->getNumRefIdx(eRefPicList); refIdxTemp++ ) |
---|
| 218 | { |
---|
[1029] | 219 | WPACDCParam *currWeightACDCParam, *refWeightACDCParam; |
---|
[313] | 220 | slice->getWpAcDcParam(currWeightACDCParam); |
---|
| 221 | slice->getRefPic(eRefPicList, refIdxTemp)->getSlice(0)->getWpAcDcParam(refWeightACDCParam); |
---|
[1029] | 222 | |
---|
[1201] | 223 | #if SVC_EXTENSION |
---|
[494] | 224 | UInt currLayerId = slice->getLayerId(); |
---|
| 225 | UInt refLayerId = slice->getRefPic(eRefPicList, refIdxTemp)->getLayerId(); |
---|
| 226 | Bool validILRPic = slice->getRefPic(eRefPicList, refIdxTemp)->isILR( currLayerId ) && refLayerId == 0; |
---|
[313] | 227 | |
---|
[494] | 228 | if( validILRPic ) |
---|
| 229 | { |
---|
[1029] | 230 | refWeightACDCParam = (WPACDCParam *)g_refWeightACDCParam; |
---|
[494] | 231 | } |
---|
| 232 | #endif |
---|
| 233 | |
---|
[1029] | 234 | for ( Int comp = 0; comp < numComp; comp++ ) |
---|
[313] | 235 | { |
---|
[1029] | 236 | const ComponentID compID = ComponentID(comp); |
---|
| 237 | const Int range = bUseHighPrecisionWeighting ? (1<<g_bitDepth[toChannelType(compID)])/2 : 128; |
---|
| 238 | const Int realLog2Denom = log2Denom + (bUseHighPrecisionWeighting ? RExt__PREDICTION_WEIGHTING_ANALYSIS_DC_PRECISION : (g_bitDepth[toChannelType(compID)] - 8)); |
---|
| 239 | const Int realOffset = ((Int)1<<(realLog2Denom-1)); |
---|
[313] | 240 | |
---|
| 241 | // current frame |
---|
[1029] | 242 | const Int64 currDC = currWeightACDCParam[comp].iDC; |
---|
| 243 | const Int64 currAC = currWeightACDCParam[comp].iAC; |
---|
[313] | 244 | // reference frame |
---|
[1201] | 245 | #if SVC_EXTENSION |
---|
[1029] | 246 | Int64 refDC = refWeightACDCParam[comp].iDC; |
---|
| 247 | Int64 refAC = refWeightACDCParam[comp].iAC; |
---|
| 248 | |
---|
[494] | 249 | if( validILRPic ) |
---|
| 250 | { |
---|
| 251 | refAC = ( refAC * currWeightACDCParam[comp].iSamples ) /refWeightACDCParam[comp].iSamples; |
---|
[1202] | 252 | |
---|
| 253 | // jonint upsampling bitshift |
---|
[1029] | 254 | refAC <<= (g_bitDepthLayer[CHANNEL_TYPE_LUMA][currLayerId] - g_bitDepthLayer[CHANNEL_TYPE_LUMA][refLayerId]); |
---|
| 255 | refDC <<= (g_bitDepthLayer[CHANNEL_TYPE_LUMA][currLayerId] - g_bitDepthLayer[CHANNEL_TYPE_LUMA][refLayerId]); |
---|
[494] | 256 | } |
---|
[1029] | 257 | #else |
---|
| 258 | const Int64 refDC = refWeightACDCParam[comp].iDC; |
---|
| 259 | const Int64 refAC = refWeightACDCParam[comp].iAC; |
---|
[494] | 260 | #endif |
---|
[313] | 261 | |
---|
| 262 | // calculating iWeight and iOffset params |
---|
[1201] | 263 | #if SVC_EXTENSION |
---|
[313] | 264 | Double dWeight = (refAC==0) ? (Double)1.0 : Clip3( -16.0, 15.0, ((Double)currAC / (Double)refAC) ); |
---|
[1029] | 265 | Int weight = (Int)( 0.5 + dWeight * (Double)(1<<log2Denom) ); |
---|
| 266 | Int offset = (Int)( ((currDC<<log2Denom) - ((Int64)weight * refDC) + (Int64)realOffset) >> realLog2Denom ); |
---|
| 267 | |
---|
[494] | 268 | if( !validILRPic ) |
---|
| 269 | { |
---|
| 270 | dWeight = 1; |
---|
| 271 | offset = 0; |
---|
| 272 | } |
---|
| 273 | weight = (Int)( 0.5 + dWeight * (Double)(1<<log2Denom) ); |
---|
[1029] | 274 | #else |
---|
| 275 | const Double dWeight = (refAC==0) ? (Double)1.0 : Clip3( -16.0, 15.0, ((Double)currAC / (Double)refAC) ); |
---|
| 276 | const Int weight = (Int)( 0.5 + dWeight * (Double)(1<<log2Denom) ); |
---|
| 277 | const Int offset = (Int)( ((currDC<<log2Denom) - ((Int64)weight * refDC) + (Int64)realOffset) >> realLog2Denom ); |
---|
[494] | 278 | #endif |
---|
[313] | 279 | |
---|
[1029] | 280 | Int clippedOffset; |
---|
| 281 | if(isChroma(compID)) // Chroma offset range limination |
---|
[313] | 282 | { |
---|
[1029] | 283 | const Int pred = ( range - ( ( range*weight)>>(log2Denom) ) ); |
---|
| 284 | const Int deltaOffset = Clip3( -4*range, 4*range-1, (offset - pred) ); // signed 10bit |
---|
| 285 | |
---|
| 286 | clippedOffset = Clip3( -range, range-1, (deltaOffset + pred) ); // signed 8bit |
---|
[313] | 287 | } |
---|
[1029] | 288 | else // Luma offset range limitation |
---|
[313] | 289 | { |
---|
[1029] | 290 | clippedOffset = Clip3( -range, range-1, offset); |
---|
[313] | 291 | } |
---|
| 292 | |
---|
| 293 | // Weighting factor limitation |
---|
[1029] | 294 | const Int defaultWeight = (1<<log2Denom); |
---|
| 295 | const Int deltaWeight = (defaultWeight - weight); |
---|
| 296 | |
---|
| 297 | if(deltaWeight >= range || deltaWeight < -range) |
---|
| 298 | return false; |
---|
| 299 | |
---|
[1201] | 300 | #if SVC_EXTENSION |
---|
[494] | 301 | // make sure the reference frames other than ILR are not using weighted prediction |
---|
| 302 | else |
---|
| 303 | if( !validILRPic ) |
---|
| 304 | { |
---|
| 305 | continue; |
---|
| 306 | } |
---|
| 307 | #endif |
---|
[313] | 308 | |
---|
[1029] | 309 | m_wp[refList][refIdxTemp][comp].bPresentFlag = true; |
---|
| 310 | m_wp[refList][refIdxTemp][comp].iWeight = weight; |
---|
| 311 | m_wp[refList][refIdxTemp][comp].iOffset = clippedOffset; |
---|
| 312 | m_wp[refList][refIdxTemp][comp].uiLog2WeightDenom = log2Denom; |
---|
[313] | 313 | } |
---|
| 314 | } |
---|
| 315 | } |
---|
[1029] | 316 | return true; |
---|
[313] | 317 | } |
---|
| 318 | |
---|
[1029] | 319 | |
---|
[494] | 320 | /** select whether weighted pred enables or not. |
---|
[313] | 321 | * \param TComSlice *slice |
---|
[1029] | 322 | * \param log2Denom |
---|
[313] | 323 | * \returns Bool |
---|
| 324 | */ |
---|
[1029] | 325 | Bool WeightPredAnalysis::xSelectWP(TComSlice *const slice, const Int log2Denom) |
---|
[313] | 326 | { |
---|
[1029] | 327 | TComPicYuv *const pPic = slice->getPic()->getPicYuvOrg(); |
---|
| 328 | const Int iDefaultWeight = ((Int)1<<log2Denom); |
---|
| 329 | const Int iNumPredDir = slice->isInterP() ? 1 : 2; |
---|
| 330 | const Bool useHighPrecisionPredictionWeighting = slice->getSPS()->getUseHighPrecisionPredictionWeighting(); |
---|
[313] | 331 | |
---|
[1029] | 332 | assert (iNumPredDir <= Int(NUM_REF_PIC_LIST_01)); |
---|
| 333 | |
---|
[313] | 334 | for ( Int iRefList = 0; iRefList < iNumPredDir; iRefList++ ) |
---|
| 335 | { |
---|
[1029] | 336 | const RefPicList eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); |
---|
| 337 | |
---|
[313] | 338 | for ( Int iRefIdxTemp = 0; iRefIdxTemp < slice->getNumRefIdx(eRefPicList); iRefIdxTemp++ ) |
---|
| 339 | { |
---|
[1029] | 340 | Int64 iSADWP = 0, iSADnoWP = 0; |
---|
[313] | 341 | |
---|
[1029] | 342 | for(Int comp=0; comp<pPic->getNumberValidComponents(); comp++) |
---|
| 343 | { |
---|
| 344 | const ComponentID compID = ComponentID(comp); |
---|
| 345 | Pel *pOrg = pPic->getAddr(compID); |
---|
| 346 | Pel *pRef = slice->getRefPic(eRefPicList, iRefIdxTemp)->getPicYuvRec()->getAddr(compID); |
---|
| 347 | const Int iOrgStride = pPic->getStride(compID); |
---|
| 348 | const Int iRefStride = slice->getRefPic(eRefPicList, iRefIdxTemp)->getPicYuvRec()->getStride(compID); |
---|
| 349 | const Int iWidth = pPic->getWidth(compID); |
---|
| 350 | const Int iHeight = pPic->getHeight(compID); |
---|
| 351 | const Int bitDepth = g_bitDepth[toChannelType(compID)]; |
---|
[313] | 352 | |
---|
[1029] | 353 | // calculate SAD costs with/without wp for luma |
---|
| 354 | iSADWP += xCalcSADvalueWP(bitDepth, pOrg, pRef, iWidth, iHeight, iOrgStride, iRefStride, log2Denom, m_wp[iRefList][iRefIdxTemp][compID].iWeight, m_wp[iRefList][iRefIdxTemp][compID].iOffset, useHighPrecisionPredictionWeighting); |
---|
| 355 | iSADnoWP += xCalcSADvalueWP(bitDepth, pOrg, pRef, iWidth, iHeight, iOrgStride, iRefStride, log2Denom, iDefaultWeight, 0, useHighPrecisionPredictionWeighting); |
---|
| 356 | } |
---|
[313] | 357 | |
---|
[1029] | 358 | const Double dRatio = ((Double)iSADWP / (Double)iSADnoWP); |
---|
[313] | 359 | if(dRatio >= (Double)DTHRESH) |
---|
| 360 | { |
---|
[1029] | 361 | for(Int comp=0; comp<pPic->getNumberValidComponents(); comp++) |
---|
[313] | 362 | { |
---|
[1029] | 363 | m_wp[iRefList][iRefIdxTemp][comp].bPresentFlag = false; |
---|
| 364 | m_wp[iRefList][iRefIdxTemp][comp].iOffset = 0; |
---|
| 365 | m_wp[iRefList][iRefIdxTemp][comp].iWeight = iDefaultWeight; |
---|
| 366 | m_wp[iRefList][iRefIdxTemp][comp].uiLog2WeightDenom = log2Denom; |
---|
[313] | 367 | } |
---|
| 368 | } |
---|
| 369 | } |
---|
| 370 | } |
---|
| 371 | |
---|
[1029] | 372 | return true; |
---|
[313] | 373 | } |
---|
| 374 | |
---|
| 375 | |
---|
[494] | 376 | /** calculate SAD values for both WP version and non-WP version. |
---|
[313] | 377 | * \param Pel *pOrgPel |
---|
| 378 | * \param Pel *pRefPel |
---|
| 379 | * \param Int iWidth |
---|
| 380 | * \param Int iHeight |
---|
| 381 | * \param Int iOrgStride |
---|
| 382 | * \param Int iRefStride |
---|
[1029] | 383 | * \param Int iLog2Denom |
---|
[313] | 384 | * \param Int iWeight |
---|
| 385 | * \param Int iOffset |
---|
| 386 | * \returns Int64 |
---|
| 387 | */ |
---|
[1029] | 388 | Int64 WeightPredAnalysis::xCalcSADvalueWP(const Int bitDepth, |
---|
| 389 | const Pel *pOrgPel, |
---|
| 390 | const Pel *pRefPel, |
---|
| 391 | const Int iWidth, |
---|
| 392 | const Int iHeight, |
---|
| 393 | const Int iOrgStride, |
---|
| 394 | const Int iRefStride, |
---|
| 395 | const Int iLog2Denom, |
---|
| 396 | const Int iWeight, |
---|
| 397 | const Int iOffset, |
---|
| 398 | const Bool useHighPrecisionPredictionWeighting) |
---|
[313] | 399 | { |
---|
[1029] | 400 | const Int64 iSize = iWidth*iHeight; |
---|
| 401 | const Int64 iRealLog2Denom = useHighPrecisionPredictionWeighting ? iLog2Denom : (iLog2Denom + (bitDepth - 8)); |
---|
| 402 | |
---|
[313] | 403 | Int64 iSAD = 0; |
---|
[1029] | 404 | for( Int y = 0; y < iHeight; y++ ) |
---|
[313] | 405 | { |
---|
[1029] | 406 | for( Int x = 0; x < iWidth; x++ ) |
---|
[313] | 407 | { |
---|
[1029] | 408 | iSAD += ABS(( ((Int64)pOrgPel[x]<<(Int64)iLog2Denom) - ( (Int64)pRefPel[x] * (Int64)iWeight + ((Int64)iOffset<<iRealLog2Denom) ) ) ); |
---|
[313] | 409 | } |
---|
| 410 | pOrgPel += iOrgStride; |
---|
| 411 | pRefPel += iRefStride; |
---|
| 412 | } |
---|
[1029] | 413 | |
---|
[313] | 414 | return (iSAD/iSize); |
---|
| 415 | } |
---|