| [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 ) |
|---|
| [1246] | 94 | { |
|---|
| [1029] | 95 | for(Int x = 0; x < iWidth; x++ ) |
|---|
| [1246] | 96 | { |
|---|
| [1029] | 97 | iOrgDC += (Int)( pPel[x] ); |
|---|
| [1246] | 98 | } |
|---|
| 99 | } |
|---|
| [1029] | 100 | } |
|---|
| 101 | |
|---|
| 102 | const Int64 iOrgNormDC = ((iOrgDC+(iSample>>1)) / iSample); |
|---|
| 103 | |
|---|
| 104 | Int64 iOrgAC = 0; |
|---|
| 105 | { |
|---|
| 106 | const Pel *pPel = pPic->getAddr(compID); |
|---|
| 107 | |
|---|
| 108 | for(Int y = 0; y < iHeight; y++, pPel += iStride ) |
|---|
| [1246] | 109 | { |
|---|
| [1029] | 110 | for(Int x = 0; x < iWidth; x++ ) |
|---|
| [1246] | 111 | { |
|---|
| [1029] | 112 | iOrgAC += abs( (Int)pPel[x] - (Int)iOrgNormDC ); |
|---|
| [1246] | 113 | } |
|---|
| 114 | } |
|---|
| [1029] | 115 | } |
|---|
| 116 | |
|---|
| 117 | const Int fixedBitShift = (slice->getSPS()->getUseHighPrecisionPredictionWeighting())?RExt__PREDICTION_WEIGHTING_ANALYSIS_DC_PRECISION:0; |
|---|
| [1201] | 118 | weightACDCParam[compID].iDC = (((iOrgDC<<fixedBitShift)+(iSample>>1)) / iSample); |
|---|
| 119 | weightACDCParam[compID].iAC = iOrgAC; |
|---|
| 120 | #if SVC_EXTENSION |
|---|
| [1029] | 121 | weightACDCParam[compID].iSamples = iSample; |
|---|
| [494] | 122 | #endif |
|---|
| [1029] | 123 | } |
|---|
| [313] | 124 | |
|---|
| 125 | slice->setWpAcDcParam(weightACDCParam); |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| [1246] | 128 | |
|---|
| [313] | 129 | /** check weighted pred or non-weighted pred |
|---|
| 130 | * \param TComSlice *slice |
|---|
| 131 | * \returns Void |
|---|
| 132 | */ |
|---|
| [1029] | 133 | Void WeightPredAnalysis::xCheckWPEnable(TComSlice *const slice) |
|---|
| [313] | 134 | { |
|---|
| [1029] | 135 | const TComPicYuv *pPic = slice->getPic()->getPicYuvOrg(); |
|---|
| 136 | |
|---|
| [313] | 137 | Int iPresentCnt = 0; |
|---|
| [1029] | 138 | for ( UInt lst=0 ; lst<NUM_REF_PIC_LIST_01 ; lst++ ) |
|---|
| [313] | 139 | { |
|---|
| [494] | 140 | for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) |
|---|
| [313] | 141 | { |
|---|
| [1029] | 142 | for(Int componentIndex = 0; componentIndex < pPic->getNumberValidComponents(); componentIndex++) |
|---|
| [313] | 143 | { |
|---|
| [1029] | 144 | WPScalingParam *pwp = &(m_wp[lst][iRefIdx][componentIndex]); |
|---|
| [313] | 145 | iPresentCnt += (Int)pwp->bPresentFlag; |
|---|
| 146 | } |
|---|
| 147 | } |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | if(iPresentCnt==0) |
|---|
| 151 | { |
|---|
| [1235] | 152 | slice->setTestWeightPred(false); |
|---|
| 153 | slice->setTestWeightBiPred(false); |
|---|
| [1029] | 154 | |
|---|
| 155 | for ( UInt lst=0 ; lst<NUM_REF_PIC_LIST_01 ; lst++ ) |
|---|
| [313] | 156 | { |
|---|
| [494] | 157 | for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ ) |
|---|
| [313] | 158 | { |
|---|
| [1029] | 159 | for(Int componentIndex = 0; componentIndex < pPic->getNumberValidComponents(); componentIndex++) |
|---|
| [313] | 160 | { |
|---|
| [1029] | 161 | WPScalingParam *pwp = &(m_wp[lst][iRefIdx][componentIndex]); |
|---|
| 162 | |
|---|
| [313] | 163 | pwp->bPresentFlag = false; |
|---|
| 164 | pwp->uiLog2WeightDenom = 0; |
|---|
| 165 | pwp->iWeight = 1; |
|---|
| 166 | pwp->iOffset = 0; |
|---|
| 167 | } |
|---|
| 168 | } |
|---|
| 169 | } |
|---|
| 170 | slice->setWpScaling( m_wp ); |
|---|
| 171 | } |
|---|
| [1235] | 172 | else |
|---|
| 173 | { |
|---|
| 174 | slice->setTestWeightPred(slice->getPPS()->getUseWP()); |
|---|
| 175 | slice->setTestWeightBiPred(slice->getPPS()->getWPBiPred()); |
|---|
| 176 | } |
|---|
| [313] | 177 | } |
|---|
| 178 | |
|---|
| [1029] | 179 | |
|---|
| [313] | 180 | /** estimate wp tables for explicit wp |
|---|
| 181 | * \param TComSlice *slice |
|---|
| 182 | */ |
|---|
| [1029] | 183 | Void WeightPredAnalysis::xEstimateWPParamSlice(TComSlice *const slice) |
|---|
| [313] | 184 | { |
|---|
| [1029] | 185 | Int iDenom = 6; |
|---|
| [313] | 186 | Bool validRangeFlag = false; |
|---|
| 187 | |
|---|
| 188 | if(slice->getNumRefIdx(REF_PIC_LIST_0)>3) |
|---|
| 189 | { |
|---|
| [1029] | 190 | iDenom = 7; |
|---|
| [313] | 191 | } |
|---|
| 192 | |
|---|
| 193 | do |
|---|
| 194 | { |
|---|
| [1029] | 195 | validRangeFlag = xUpdatingWPParameters(slice, iDenom); |
|---|
| [313] | 196 | if (!validRangeFlag) |
|---|
| 197 | { |
|---|
| 198 | iDenom--; // decrement to satisfy the range limitation |
|---|
| 199 | } |
|---|
| 200 | } while (validRangeFlag == false); |
|---|
| 201 | |
|---|
| [1235] | 202 | // selecting whether WP is used, or not (fast search) |
|---|
| 203 | // NOTE: This is not operating on a slice, but the entire picture. |
|---|
| [1029] | 204 | xSelectWP(slice, iDenom); |
|---|
| [494] | 205 | |
|---|
| [313] | 206 | slice->setWpScaling( m_wp ); |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| [1029] | 209 | |
|---|
| [313] | 210 | /** update wp tables for explicit wp w.r.t ramge limitation |
|---|
| 211 | * \param TComSlice *slice |
|---|
| 212 | * \returns Bool |
|---|
| 213 | */ |
|---|
| [1029] | 214 | Bool WeightPredAnalysis::xUpdatingWPParameters(TComSlice *const slice, const Int log2Denom) |
|---|
| [313] | 215 | { |
|---|
| [1029] | 216 | const Int numComp = slice->getPic()->getPicYuvOrg()->getNumberValidComponents(); |
|---|
| 217 | const Bool bUseHighPrecisionWeighting = slice->getSPS()->getUseHighPrecisionPredictionWeighting(); |
|---|
| 218 | const Int numPredDir = slice->isInterP() ? 1 : 2; |
|---|
| 219 | |
|---|
| 220 | assert (numPredDir <= Int(NUM_REF_PIC_LIST_01)); |
|---|
| 221 | |
|---|
| [313] | 222 | for ( Int refList = 0; refList < numPredDir; refList++ ) |
|---|
| 223 | { |
|---|
| [1029] | 224 | const RefPicList eRefPicList = ( refList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); |
|---|
| 225 | |
|---|
| [313] | 226 | for ( Int refIdxTemp = 0; refIdxTemp < slice->getNumRefIdx(eRefPicList); refIdxTemp++ ) |
|---|
| 227 | { |
|---|
| [1029] | 228 | WPACDCParam *currWeightACDCParam, *refWeightACDCParam; |
|---|
| [313] | 229 | slice->getWpAcDcParam(currWeightACDCParam); |
|---|
| 230 | slice->getRefPic(eRefPicList, refIdxTemp)->getSlice(0)->getWpAcDcParam(refWeightACDCParam); |
|---|
| [1029] | 231 | |
|---|
| [1201] | 232 | #if SVC_EXTENSION |
|---|
| [494] | 233 | UInt currLayerId = slice->getLayerId(); |
|---|
| 234 | UInt refLayerId = slice->getRefPic(eRefPicList, refIdxTemp)->getLayerId(); |
|---|
| 235 | Bool validILRPic = slice->getRefPic(eRefPicList, refIdxTemp)->isILR( currLayerId ) && refLayerId == 0; |
|---|
| [313] | 236 | |
|---|
| [494] | 237 | if( validILRPic ) |
|---|
| 238 | { |
|---|
| [1029] | 239 | refWeightACDCParam = (WPACDCParam *)g_refWeightACDCParam; |
|---|
| [494] | 240 | } |
|---|
| 241 | #endif |
|---|
| 242 | |
|---|
| [1029] | 243 | for ( Int comp = 0; comp < numComp; comp++ ) |
|---|
| [313] | 244 | { |
|---|
| [1029] | 245 | const ComponentID compID = ComponentID(comp); |
|---|
| 246 | const Int range = bUseHighPrecisionWeighting ? (1<<g_bitDepth[toChannelType(compID)])/2 : 128; |
|---|
| 247 | const Int realLog2Denom = log2Denom + (bUseHighPrecisionWeighting ? RExt__PREDICTION_WEIGHTING_ANALYSIS_DC_PRECISION : (g_bitDepth[toChannelType(compID)] - 8)); |
|---|
| 248 | const Int realOffset = ((Int)1<<(realLog2Denom-1)); |
|---|
| [313] | 249 | |
|---|
| 250 | // current frame |
|---|
| [1029] | 251 | const Int64 currDC = currWeightACDCParam[comp].iDC; |
|---|
| 252 | const Int64 currAC = currWeightACDCParam[comp].iAC; |
|---|
| [313] | 253 | // reference frame |
|---|
| [1201] | 254 | #if SVC_EXTENSION |
|---|
| [1029] | 255 | Int64 refDC = refWeightACDCParam[comp].iDC; |
|---|
| 256 | Int64 refAC = refWeightACDCParam[comp].iAC; |
|---|
| 257 | |
|---|
| [494] | 258 | if( validILRPic ) |
|---|
| 259 | { |
|---|
| 260 | refAC = ( refAC * currWeightACDCParam[comp].iSamples ) /refWeightACDCParam[comp].iSamples; |
|---|
| [1202] | 261 | |
|---|
| 262 | // jonint upsampling bitshift |
|---|
| [1029] | 263 | refAC <<= (g_bitDepthLayer[CHANNEL_TYPE_LUMA][currLayerId] - g_bitDepthLayer[CHANNEL_TYPE_LUMA][refLayerId]); |
|---|
| 264 | refDC <<= (g_bitDepthLayer[CHANNEL_TYPE_LUMA][currLayerId] - g_bitDepthLayer[CHANNEL_TYPE_LUMA][refLayerId]); |
|---|
| [494] | 265 | } |
|---|
| [1029] | 266 | #else |
|---|
| 267 | const Int64 refDC = refWeightACDCParam[comp].iDC; |
|---|
| 268 | const Int64 refAC = refWeightACDCParam[comp].iAC; |
|---|
| [494] | 269 | #endif |
|---|
| [313] | 270 | |
|---|
| 271 | // calculating iWeight and iOffset params |
|---|
| [1201] | 272 | #if SVC_EXTENSION |
|---|
| [313] | 273 | Double dWeight = (refAC==0) ? (Double)1.0 : Clip3( -16.0, 15.0, ((Double)currAC / (Double)refAC) ); |
|---|
| [1029] | 274 | Int weight = (Int)( 0.5 + dWeight * (Double)(1<<log2Denom) ); |
|---|
| 275 | Int offset = (Int)( ((currDC<<log2Denom) - ((Int64)weight * refDC) + (Int64)realOffset) >> realLog2Denom ); |
|---|
| 276 | |
|---|
| [494] | 277 | if( !validILRPic ) |
|---|
| 278 | { |
|---|
| 279 | dWeight = 1; |
|---|
| 280 | offset = 0; |
|---|
| 281 | } |
|---|
| 282 | weight = (Int)( 0.5 + dWeight * (Double)(1<<log2Denom) ); |
|---|
| [1029] | 283 | #else |
|---|
| 284 | const Double dWeight = (refAC==0) ? (Double)1.0 : Clip3( -16.0, 15.0, ((Double)currAC / (Double)refAC) ); |
|---|
| 285 | const Int weight = (Int)( 0.5 + dWeight * (Double)(1<<log2Denom) ); |
|---|
| 286 | const Int offset = (Int)( ((currDC<<log2Denom) - ((Int64)weight * refDC) + (Int64)realOffset) >> realLog2Denom ); |
|---|
| [494] | 287 | #endif |
|---|
| [313] | 288 | |
|---|
| [1029] | 289 | Int clippedOffset; |
|---|
| 290 | if(isChroma(compID)) // Chroma offset range limination |
|---|
| [313] | 291 | { |
|---|
| [1029] | 292 | const Int pred = ( range - ( ( range*weight)>>(log2Denom) ) ); |
|---|
| 293 | const Int deltaOffset = Clip3( -4*range, 4*range-1, (offset - pred) ); // signed 10bit |
|---|
| 294 | |
|---|
| 295 | clippedOffset = Clip3( -range, range-1, (deltaOffset + pred) ); // signed 8bit |
|---|
| [313] | 296 | } |
|---|
| [1029] | 297 | else // Luma offset range limitation |
|---|
| [313] | 298 | { |
|---|
| [1029] | 299 | clippedOffset = Clip3( -range, range-1, offset); |
|---|
| [313] | 300 | } |
|---|
| 301 | |
|---|
| 302 | // Weighting factor limitation |
|---|
| [1029] | 303 | const Int defaultWeight = (1<<log2Denom); |
|---|
| 304 | const Int deltaWeight = (defaultWeight - weight); |
|---|
| 305 | |
|---|
| 306 | if(deltaWeight >= range || deltaWeight < -range) |
|---|
| [1246] | 307 | { |
|---|
| [1029] | 308 | return false; |
|---|
| [1246] | 309 | } |
|---|
| [1029] | 310 | |
|---|
| [1201] | 311 | #if SVC_EXTENSION |
|---|
| [494] | 312 | // make sure the reference frames other than ILR are not using weighted prediction |
|---|
| 313 | else |
|---|
| 314 | if( !validILRPic ) |
|---|
| 315 | { |
|---|
| 316 | continue; |
|---|
| 317 | } |
|---|
| 318 | #endif |
|---|
| [313] | 319 | |
|---|
| [1029] | 320 | m_wp[refList][refIdxTemp][comp].bPresentFlag = true; |
|---|
| 321 | m_wp[refList][refIdxTemp][comp].iWeight = weight; |
|---|
| 322 | m_wp[refList][refIdxTemp][comp].iOffset = clippedOffset; |
|---|
| 323 | m_wp[refList][refIdxTemp][comp].uiLog2WeightDenom = log2Denom; |
|---|
| [313] | 324 | } |
|---|
| 325 | } |
|---|
| 326 | } |
|---|
| [1029] | 327 | return true; |
|---|
| [313] | 328 | } |
|---|
| 329 | |
|---|
| [1029] | 330 | |
|---|
| [494] | 331 | /** select whether weighted pred enables or not. |
|---|
| [313] | 332 | * \param TComSlice *slice |
|---|
| [1029] | 333 | * \param log2Denom |
|---|
| [313] | 334 | * \returns Bool |
|---|
| 335 | */ |
|---|
| [1029] | 336 | Bool WeightPredAnalysis::xSelectWP(TComSlice *const slice, const Int log2Denom) |
|---|
| [313] | 337 | { |
|---|
| [1029] | 338 | TComPicYuv *const pPic = slice->getPic()->getPicYuvOrg(); |
|---|
| 339 | const Int iDefaultWeight = ((Int)1<<log2Denom); |
|---|
| 340 | const Int iNumPredDir = slice->isInterP() ? 1 : 2; |
|---|
| 341 | const Bool useHighPrecisionPredictionWeighting = slice->getSPS()->getUseHighPrecisionPredictionWeighting(); |
|---|
| [313] | 342 | |
|---|
| [1029] | 343 | assert (iNumPredDir <= Int(NUM_REF_PIC_LIST_01)); |
|---|
| 344 | |
|---|
| [313] | 345 | for ( Int iRefList = 0; iRefList < iNumPredDir; iRefList++ ) |
|---|
| 346 | { |
|---|
| [1029] | 347 | const RefPicList eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); |
|---|
| 348 | |
|---|
| [313] | 349 | for ( Int iRefIdxTemp = 0; iRefIdxTemp < slice->getNumRefIdx(eRefPicList); iRefIdxTemp++ ) |
|---|
| 350 | { |
|---|
| [1029] | 351 | Int64 iSADWP = 0, iSADnoWP = 0; |
|---|
| [313] | 352 | |
|---|
| [1029] | 353 | for(Int comp=0; comp<pPic->getNumberValidComponents(); comp++) |
|---|
| 354 | { |
|---|
| 355 | const ComponentID compID = ComponentID(comp); |
|---|
| 356 | Pel *pOrg = pPic->getAddr(compID); |
|---|
| 357 | Pel *pRef = slice->getRefPic(eRefPicList, iRefIdxTemp)->getPicYuvRec()->getAddr(compID); |
|---|
| 358 | const Int iOrgStride = pPic->getStride(compID); |
|---|
| 359 | const Int iRefStride = slice->getRefPic(eRefPicList, iRefIdxTemp)->getPicYuvRec()->getStride(compID); |
|---|
| 360 | const Int iWidth = pPic->getWidth(compID); |
|---|
| 361 | const Int iHeight = pPic->getHeight(compID); |
|---|
| 362 | const Int bitDepth = g_bitDepth[toChannelType(compID)]; |
|---|
| [313] | 363 | |
|---|
| [1029] | 364 | // calculate SAD costs with/without wp for luma |
|---|
| 365 | iSADWP += xCalcSADvalueWP(bitDepth, pOrg, pRef, iWidth, iHeight, iOrgStride, iRefStride, log2Denom, m_wp[iRefList][iRefIdxTemp][compID].iWeight, m_wp[iRefList][iRefIdxTemp][compID].iOffset, useHighPrecisionPredictionWeighting); |
|---|
| 366 | iSADnoWP += xCalcSADvalueWP(bitDepth, pOrg, pRef, iWidth, iHeight, iOrgStride, iRefStride, log2Denom, iDefaultWeight, 0, useHighPrecisionPredictionWeighting); |
|---|
| 367 | } |
|---|
| [313] | 368 | |
|---|
| [1029] | 369 | const Double dRatio = ((Double)iSADWP / (Double)iSADnoWP); |
|---|
| [313] | 370 | if(dRatio >= (Double)DTHRESH) |
|---|
| 371 | { |
|---|
| [1029] | 372 | for(Int comp=0; comp<pPic->getNumberValidComponents(); comp++) |
|---|
| [313] | 373 | { |
|---|
| [1029] | 374 | m_wp[iRefList][iRefIdxTemp][comp].bPresentFlag = false; |
|---|
| 375 | m_wp[iRefList][iRefIdxTemp][comp].iOffset = 0; |
|---|
| 376 | m_wp[iRefList][iRefIdxTemp][comp].iWeight = iDefaultWeight; |
|---|
| 377 | m_wp[iRefList][iRefIdxTemp][comp].uiLog2WeightDenom = log2Denom; |
|---|
| [313] | 378 | } |
|---|
| 379 | } |
|---|
| 380 | } |
|---|
| 381 | } |
|---|
| 382 | |
|---|
| [1029] | 383 | return true; |
|---|
| [313] | 384 | } |
|---|
| 385 | |
|---|
| 386 | |
|---|
| [494] | 387 | /** calculate SAD values for both WP version and non-WP version. |
|---|
| [313] | 388 | * \param Pel *pOrgPel |
|---|
| 389 | * \param Pel *pRefPel |
|---|
| 390 | * \param Int iWidth |
|---|
| 391 | * \param Int iHeight |
|---|
| 392 | * \param Int iOrgStride |
|---|
| 393 | * \param Int iRefStride |
|---|
| [1029] | 394 | * \param Int iLog2Denom |
|---|
| [313] | 395 | * \param Int iWeight |
|---|
| 396 | * \param Int iOffset |
|---|
| 397 | * \returns Int64 |
|---|
| 398 | */ |
|---|
| [1029] | 399 | Int64 WeightPredAnalysis::xCalcSADvalueWP(const Int bitDepth, |
|---|
| 400 | const Pel *pOrgPel, |
|---|
| 401 | const Pel *pRefPel, |
|---|
| 402 | const Int iWidth, |
|---|
| 403 | const Int iHeight, |
|---|
| 404 | const Int iOrgStride, |
|---|
| 405 | const Int iRefStride, |
|---|
| 406 | const Int iLog2Denom, |
|---|
| 407 | const Int iWeight, |
|---|
| 408 | const Int iOffset, |
|---|
| 409 | const Bool useHighPrecisionPredictionWeighting) |
|---|
| [313] | 410 | { |
|---|
| [1029] | 411 | const Int64 iSize = iWidth*iHeight; |
|---|
| 412 | const Int64 iRealLog2Denom = useHighPrecisionPredictionWeighting ? iLog2Denom : (iLog2Denom + (bitDepth - 8)); |
|---|
| 413 | |
|---|
| [313] | 414 | Int64 iSAD = 0; |
|---|
| [1029] | 415 | for( Int y = 0; y < iHeight; y++ ) |
|---|
| [313] | 416 | { |
|---|
| [1029] | 417 | for( Int x = 0; x < iWidth; x++ ) |
|---|
| [313] | 418 | { |
|---|
| [1029] | 419 | iSAD += ABS(( ((Int64)pOrgPel[x]<<(Int64)iLog2Denom) - ( (Int64)pRefPel[x] * (Int64)iWeight + ((Int64)iOffset<<iRealLog2Denom) ) ) ); |
|---|
| [313] | 420 | } |
|---|
| 421 | pOrgPel += iOrgStride; |
|---|
| 422 | pRefPel += iRefStride; |
|---|
| 423 | } |
|---|
| [1029] | 424 | |
|---|
| [313] | 425 | return (iSAD/iSize); |
|---|
| 426 | } |
|---|