Changeset 1400 in SHVCSoftware
- Timestamp:
- 4 Aug 2015, 03:50:01 (9 years ago)
- Location:
- branches/SHM-dev/source
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.cpp
r1391 r1400 975 975 Int tmpInputChromaFormat; 976 976 Int tmpConstraintChromaFormat; 977 Int tmpWeightedPredictionMethod; 977 978 string inputColourSpaceConvert; 978 979 #if SVC_EXTENSION … … 1394 1395 ("WeightedPredP,-wpP", m_useWeightedPred, false, "Use weighted prediction in P slices") 1395 1396 ("WeightedPredB,-wpB", m_useWeightedBiPred, false, "Use weighted (bidirectional) prediction in B slices") 1397 ("WeightedPredMethod,-wpM", tmpWeightedPredictionMethod, Int(WP_PER_PICTURE_WITH_SIMPLE_DC_COMBINED_COMPONENT), "Weighted prediction method") 1396 1398 ("Log2ParallelMergeLevel", m_log2ParallelMergeLevel, 2u, "Parallel merge estimation region") 1397 1399 //deprecated copies of renamed tile parameters 1398 ("UniformSpacingIdc", m_tileUniformSpacingFlag, false, "deprecated alias of TileUniformSpacing")1400 ("UniformSpacingIdc", m_tileUniformSpacingFlag, false, "deprecated alias of TileUniformSpacing") 1399 1401 ("ColumnWidthArray", cfg_ColumnWidth, cfg_ColumnWidth, "deprecated alias of TileColumnWidthArray") 1400 1402 ("RowHeightArray", cfg_RowHeight, cfg_RowHeight, "deprecated alias of TileRowHeightArray") 1401 1403 1402 ("TileUniformSpacing", m_tileUniformSpacingFlag, false, "Indicates that tile columns and rows are distributed uniformly")1403 ("NumTileColumnsMinus1", m_numTileColumnsMinus1, 0, "Number of tile columns in a picture minus 1")1404 ("NumTileRowsMinus1", m_numTileRowsMinus1, 0, "Number of rows in a picture minus 1")1404 ("TileUniformSpacing", m_tileUniformSpacingFlag, false, "Indicates that tile columns and rows are distributed uniformly") 1405 ("NumTileColumnsMinus1", m_numTileColumnsMinus1, 0, "Number of tile columns in a picture minus 1") 1406 ("NumTileRowsMinus1", m_numTileRowsMinus1, 0, "Number of rows in a picture minus 1") 1405 1407 ("TileColumnWidthArray", cfg_ColumnWidth, cfg_ColumnWidth, "Array containing tile column width values in units of CTU") 1406 1408 ("TileRowHeightArray", cfg_RowHeight, cfg_RowHeight, "Array containing tile row height values in units of CTU") … … 1557 1559 "\t0: disable") 1558 1560 ("SEIDecodingUnitInfo", m_decodingUnitInfoSEIEnabled, 0, "Control generation of decoding unit information SEI message.") 1559 #if LAYERS_NOT_PRESENT_SEI1560 ("SEILayersNotPresent", m_layersNotPresentSEIEnabled, 0, "Control generation of layers not present SEI message")1561 #endif1562 1561 ("SEISOPDescription", m_SOPDescriptionSEIEnabled, 0, "Control generation of SOP description SEI messages") 1563 1562 ("SEIScalableNesting", m_scalableNestingSEIEnabled, 0, "Control generation of scalable nesting SEI messages") … … 1596 1595 ("SEIMasteringDisplayPrimaries", cfg_DisplayPrimariesCode, cfg_DisplayPrimariesCode, "Mastering display primaries for all three colour planes in CIE xy coordinates in increments of 1/50000 (results in the ranges 0 to 50000 inclusive)") 1597 1596 ("SEIMasteringDisplayWhitePoint", cfg_DisplayWhitePointCode, cfg_DisplayWhitePointCode, "Mastering display white point CIE xy coordinates in normalised increments of 1/50000 (e.g. 0.333 = 16667)") 1598 1597 1598 #if LAYERS_NOT_PRESENT_SEI 1599 ("SEILayersNotPresent", m_layersNotPresentSEIEnabled, 0, "Control generation of layers not present SEI message") 1600 #endif 1599 1601 #if P0123_ALPHA_CHANNEL_SEI 1600 1602 ("SEIAlphaChannelInfo", m_alphaSEIEnabled, false, "Enables transmission of information associated with alpha channel (default : 0)") … … 1864 1866 m_apcLayerCfg[layer]->m_MSBExtendedBitDepth[CHANNEL_TYPE_CHROMA] = m_apcLayerCfg[layer]->m_MSBExtendedBitDepth[CHANNEL_TYPE_LUMA ]; 1865 1867 1866 if (m_apcLayerCfg[layer]->m_internalBitDepth [CHANNEL_TYPE_LUMA ] == 0) { m_apcLayerCfg[layer]->m_internalBitDepth [CHANNEL_TYPE_LUMA ] = m_apcLayerCfg[layer]->m_MSBExtendedBitDepth[CHANNEL_TYPE_LUMA ]; } 1867 if (m_apcLayerCfg[layer]->m_internalBitDepth [CHANNEL_TYPE_CHROMA] == 0) { m_apcLayerCfg[layer]->m_internalBitDepth [CHANNEL_TYPE_CHROMA] = m_apcLayerCfg[layer]->m_internalBitDepth [CHANNEL_TYPE_LUMA ]; } 1868 if (m_apcLayerCfg[layer]->m_inputBitDepth [CHANNEL_TYPE_CHROMA] == 0) { m_apcLayerCfg[layer]->m_inputBitDepth [CHANNEL_TYPE_CHROMA] = m_apcLayerCfg[layer]->m_inputBitDepth [CHANNEL_TYPE_LUMA ]; } 1869 if (m_apcLayerCfg[layer]->m_outputBitDepth [CHANNEL_TYPE_LUMA ] == 0) { m_apcLayerCfg[layer]->m_outputBitDepth [CHANNEL_TYPE_LUMA ] = m_apcLayerCfg[layer]->m_internalBitDepth [CHANNEL_TYPE_LUMA ]; } 1870 if (m_apcLayerCfg[layer]->m_outputBitDepth [CHANNEL_TYPE_CHROMA] == 0) { m_apcLayerCfg[layer]->m_outputBitDepth [CHANNEL_TYPE_CHROMA] = m_apcLayerCfg[layer]->m_internalBitDepth [CHANNEL_TYPE_CHROMA]; } 1868 if (m_apcLayerCfg[layer]->m_internalBitDepth [CHANNEL_TYPE_LUMA ] == 0) 1869 { 1870 m_apcLayerCfg[layer]->m_internalBitDepth [CHANNEL_TYPE_LUMA ] = m_apcLayerCfg[layer]->m_MSBExtendedBitDepth[CHANNEL_TYPE_LUMA ]; 1871 } 1872 if (m_apcLayerCfg[layer]->m_internalBitDepth [CHANNEL_TYPE_CHROMA] == 0) 1873 { 1874 m_apcLayerCfg[layer]->m_internalBitDepth [CHANNEL_TYPE_CHROMA] = m_apcLayerCfg[layer]->m_internalBitDepth [CHANNEL_TYPE_LUMA ]; 1875 } 1876 if (m_apcLayerCfg[layer]->m_inputBitDepth [CHANNEL_TYPE_CHROMA] == 0) 1877 { 1878 m_apcLayerCfg[layer]->m_inputBitDepth [CHANNEL_TYPE_CHROMA] = m_apcLayerCfg[layer]->m_inputBitDepth [CHANNEL_TYPE_LUMA ]; 1879 } 1880 if (m_apcLayerCfg[layer]->m_outputBitDepth [CHANNEL_TYPE_LUMA ] == 0) 1881 { 1882 m_apcLayerCfg[layer]->m_outputBitDepth [CHANNEL_TYPE_LUMA ] = m_apcLayerCfg[layer]->m_internalBitDepth [CHANNEL_TYPE_LUMA ]; 1883 } 1884 if (m_apcLayerCfg[layer]->m_outputBitDepth [CHANNEL_TYPE_CHROMA] == 0) 1885 { 1886 m_apcLayerCfg[layer]->m_outputBitDepth [CHANNEL_TYPE_CHROMA] = m_apcLayerCfg[layer]->m_internalBitDepth [CHANNEL_TYPE_CHROMA]; 1887 } 1871 1888 1872 1889 m_apcLayerCfg[layer]->m_InputChromaFormatIDC = numberToChromaFormat(tmpInputChromaFormat); … … 1978 1995 m_scalingListFile = cfg_ScalingListFile.empty() ? NULL : strdup(cfg_ScalingListFile.c_str()); 1979 1996 1980 /* rules for input, output and internal bitdepths as per help text */1997 /* rules for input, output and internal bitdepths as per help text */ 1981 1998 if (m_MSBExtendedBitDepth[CHANNEL_TYPE_LUMA ] == 0) 1982 1999 { … … 2010 2027 m_InputChromaFormatIDC = numberToChromaFormat(tmpInputChromaFormat); 2011 2028 m_chromaFormatIDC = ((tmpChromaFormat == 0) ? (m_InputChromaFormatIDC) : (numberToChromaFormat(tmpChromaFormat))); 2012 2029 #endif 2030 assert(tmpWeightedPredictionMethod>=0 && tmpWeightedPredictionMethod<=WP_PER_PICTURE_WITH_HISTOGRAM_AND_PER_COMPONENT_AND_CLIPPING_AND_EXTENSION); 2031 if (!(tmpWeightedPredictionMethod>=0 && tmpWeightedPredictionMethod<=WP_PER_PICTURE_WITH_HISTOGRAM_AND_PER_COMPONENT_AND_CLIPPING_AND_EXTENSION)) 2032 { 2033 exit(EXIT_FAILURE); 2034 } 2035 m_weightedPredictionMethod = WeightedPredictionMethod(tmpWeightedPredictionMethod); 2036 2037 #if !SVC_EXTENSION 2013 2038 if (extendedProfile >= 1000 && extendedProfile <= 12316) 2014 2039 { … … 3413 3438 memset( m_extraRPSs, 0, sizeof( m_extraRPSs ) ); 3414 3439 #else 3415 m_extraRPSs=0; 3440 m_extraRPSs=0; 3416 3441 #endif 3417 3442 … … 4446 4471 #if !RC_SHVC_HARMONIZATION 4447 4472 printf("RateControl : %d\n", m_RCEnableRateControl ); 4448 4473 #endif 4474 printf("WPMethod : %d\n", Int(m_weightedPredictionMethod)); 4475 4476 #if !RC_SHVC_HARMONIZATION 4449 4477 if(m_RCEnableRateControl) 4450 4478 { -
branches/SHM-dev/source/App/TAppEncoder/TAppEncCfg.h
r1391 r1400 389 389 Bool m_useWeightedPred; ///< Use of weighted prediction in P slices 390 390 Bool m_useWeightedBiPred; ///< Use of bi-directional weighted prediction in B slices 391 WeightedPredictionMethod m_weightedPredictionMethod; 391 392 392 393 UInt m_log2ParallelMergeLevel; ///< Parallel merge estimation region -
branches/SHM-dev/source/App/TAppEncoder/TAppEncTop.cpp
r1391 r1400 585 585 m_cTEncTop.setExtendedPrecisionProcessingFlag ( m_extendedPrecisionProcessingFlag ); 586 586 m_cTEncTop.setHighPrecisionOffsetsEnabledFlag ( m_highPrecisionOffsetsEnabledFlag ); 587 588 m_cTEncTop.setWeightedPredictionMethod( m_weightedPredictionMethod ); 589 587 590 //====== Tool list ======== 588 591 m_cTEncTop.setDeltaQpRD ( m_uiDeltaQpRD ); -
branches/SHM-dev/source/Lib/TLibCommon/TComSlice.h
r1367 r1400 2008 2008 Int64 iDC; 2009 2009 #if SVC_EXTENSION 2010 Int iSamples;2010 Int numSamples; 2011 2011 #endif 2012 2012 }; … … 2186 2186 Int getPOC() const { return m_iPOC; } 2187 2187 Int getSliceQp() const { return m_iSliceQp; } 2188 Bool getUseWeightedPrediction() const { return( (m_eSliceType==P_SLICE && testWeightPred()) || (m_eSliceType==B_SLICE && testWeightBiPred()) ); } 2188 2189 Bool getDependentSliceSegmentFlag() const { return m_dependentSliceSegmentFlag; } 2189 2190 Void setDependentSliceSegmentFlag(Bool val) { m_dependentSliceSegmentFlag = val; } -
branches/SHM-dev/source/Lib/TLibCommon/TypeDef.h
r1398 r1400 659 659 }; 660 660 661 enum WeightedPredictionMethod 662 { 663 WP_PER_PICTURE_WITH_SIMPLE_DC_COMBINED_COMPONENT =0, 664 WP_PER_PICTURE_WITH_SIMPLE_DC_PER_COMPONENT =1, 665 WP_PER_PICTURE_WITH_HISTOGRAM_AND_PER_COMPONENT =2, 666 WP_PER_PICTURE_WITH_HISTOGRAM_AND_PER_COMPONENT_AND_CLIPPING =3, 667 WP_PER_PICTURE_WITH_HISTOGRAM_AND_PER_COMPONENT_AND_CLIPPING_AND_EXTENSION=4 668 }; 669 661 670 enum SPSExtensionFlagIndex 662 671 { -
branches/SHM-dev/source/Lib/TLibEncoder/TEncCfg.h
r1391 r1400 322 322 Bool m_useWeightedPred; //< Use of Weighting Prediction (P_SLICE) 323 323 Bool m_useWeightedBiPred; //< Use of Bi-directional Weighting Prediction (B_SLICE) 324 WeightedPredictionMethod m_weightedPredictionMethod; 324 325 UInt m_log2ParallelMergeLevelMinus2; ///< Parallel merge estimation region 325 326 UInt m_maxNumMergeCand; ///< Maximum number of merge candidates … … 907 908 Void setTMVPModeId ( Int u ) { m_TMVPModeId = u; } 908 909 Int getTMVPModeId () { return m_TMVPModeId; } 910 WeightedPredictionMethod getWeightedPredictionMethod() const { return m_weightedPredictionMethod; } 911 Void setWeightedPredictionMethod( WeightedPredictionMethod m ) { m_weightedPredictionMethod = m; } 909 912 Void setSignHideFlag( Bool signHideFlag ) { m_signHideFlag = signHideFlag; } 910 913 Bool getSignHideFlag() { return m_signHideFlag; } -
branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp
r1390 r1400 3268 3268 printf(" [ET %5.0f ]", dEncTime ); 3269 3269 3270 // printf(" [WP %d]", pcSlice->getUseWeightedPrediction()); 3271 3270 3272 for (Int iRefList = 0; iRefList < 2; iRefList++) 3271 3273 { -
branches/SHM-dev/source/Lib/TLibEncoder/TEncSlice.cpp
r1391 r1400 828 828 } 829 829 830 xEstimateWPParamSlice( pcSlice );830 xEstimateWPParamSlice( pcSlice, m_pcCfg->getWeightedPredictionMethod() ); 831 831 pcSlice->initWpScaling(pcSlice->getSPS()); 832 832 -
branches/SHM-dev/source/Lib/TLibEncoder/WeightPredAnalysis.cpp
r1392 r1400 41 41 #include "../TLibCommon/TComPicYuv.h" 42 42 #include "WeightPredAnalysis.h" 43 44 #define ABS(a) ((a) < 0 ? - (a) : (a)) 45 #define DTHRESH (0.99) 43 #include <limits> 44 45 static const Double WEIGHT_PRED_SAD_RELATIVE_TO_NON_WEIGHT_PRED_SAD=0.99; // NOTE: U0040 used 0.95 46 47 //! calculate SAD values for both WP version and non-WP version. 48 static 49 Int64 xCalcSADvalueWP(const Int bitDepth, 50 const Pel *pOrgPel, 51 const Pel *pRefPel, 52 const Int width, 53 const Int height, 54 const Int orgStride, 55 const Int refStride, 56 const Int log2Denom, 57 const Int weight, 58 const Int offset, 59 const Bool useHighPrecision); 60 61 //! calculate SAD values for both WP version and non-WP version. 62 static 63 Int64 xCalcSADvalueWPOptionalClip(const Int bitDepth, 64 const Pel *pOrgPel, 65 const Pel *pRefPel, 66 const Int width, 67 const Int height, 68 const Int orgStride, 69 const Int refStride, 70 const Int log2Denom, 71 const Int weight, 72 const Int offset, 73 const Bool useHighPrecision, 74 const Bool clipped); 75 76 // ----------------------------------------------------------------------------- 77 // Helper functions 78 79 80 //! calculate Histogram for array of pixels 81 static 82 Void xCalcHistogram(const Pel *pPel, 83 std::vector<Int> &histogram, 84 const Int width, 85 const Int height, 86 const Int stride, 87 const Int maxPel) 88 { 89 histogram.clear(); 90 histogram.resize(maxPel); 91 for( Int y = 0; y < height; y++ ) 92 { 93 for( Int x = 0; x < width; x++ ) 94 { 95 const Pel v=pPel[x]; 96 histogram[v<0?0:(v>=maxPel)?maxPel-1:v]++; 97 } 98 pPel += stride; 99 } 100 } 101 102 static 103 Distortion xCalcHistDistortion (const std::vector<Int> &histogram0, 104 const std::vector<Int> &histogram1) 105 { 106 Distortion distortion = 0; 107 assert(histogram0.size()==histogram1.size()); 108 const Int numElements=Int(histogram0.size()); 109 110 // Scan histograms to compute histogram distortion 111 for (Int i = 0; i <= numElements; i++) 112 { 113 distortion += (Distortion)(abs(histogram0[i] - histogram1[i])); 114 } 115 116 return distortion; 117 } 118 119 static 120 void xScaleHistogram(const std::vector<Int> &histogramInput, 121 std::vector<Int> &histogramOutput, // cannot be the same as the input 122 const Int bitDepth, 123 const Int log2Denom, 124 const Int weight, 125 const Int offset, 126 const Bool bHighPrecision) 127 { 128 assert(&histogramInput != &histogramOutput); 129 const Int numElements=Int(histogramInput.size()); 130 histogramOutput.clear(); 131 histogramOutput.resize(numElements); 132 133 const Int64 iRealLog2Denom = bHighPrecision ? 0 : (bitDepth - 8); 134 const Int64 iRealOffset = ((Int64)offset)<<iRealLog2Denom; 135 136 const Int divOffset = log2Denom == 0 ? 0 : 1 << (log2Denom - 1); 137 // Scan histogram and apply illumination parameters appropriately 138 // Then compute updated histogram. 139 // Note that this technique only works with single list weights/offsets. 140 141 for (Int i = 0; i < numElements; i++) 142 { 143 const Int j = Clip3(0, numElements - 1, (Int)(((weight * i + divOffset) >> log2Denom) + iRealOffset)); 144 histogramOutput[j] += histogramInput[i]; 145 } 146 } 147 148 static 149 Distortion xSearchHistogram(const std::vector<Int> &histogramSource, 150 const std::vector<Int> &histogramRef, 151 std::vector<Int> &outputHistogram, 152 const Int bitDepth, 153 const Int log2Denom, 154 Int &weightToUpdate, 155 Int &offsetToUpdate, 156 const Bool bHighPrecision, 157 const ComponentID compID) 158 { 159 const Int initialWeight = weightToUpdate; 160 const Int initialOffset = offsetToUpdate; 161 const Int weightRange = 10; 162 const Int offsetRange = 10; 163 const Int maxOffset = 1 << ((bHighPrecision == true) ? (bitDepth - 1) : 7); 164 const Int range = bHighPrecision ? (1<<bitDepth) / 2 : 128; 165 const Int defaultWeight = (1<<log2Denom); 166 const Int minSearchWeight = std::max<Int>(initialWeight - weightRange, defaultWeight - range); 167 const Int maxSearchWeight = std::min<Int>(initialWeight + weightRange+1, defaultWeight + range); 168 169 Distortion minDistortion = std::numeric_limits<Int64>::max(); 170 Int bestWeight = initialWeight; 171 Int bestOffset = initialOffset; 172 173 for (Int searchWeight = minSearchWeight; searchWeight < maxSearchWeight; searchWeight++) 174 { 175 if (compID == COMPONENT_Y) 176 { 177 for (Int searchOffset = std::max<Int>(initialOffset - offsetRange, -maxOffset); 178 searchOffset <= initialOffset + offsetRange && searchOffset<=(maxOffset-1); 179 searchOffset++) 180 { 181 xScaleHistogram(histogramRef, outputHistogram, bitDepth, log2Denom, searchWeight, searchOffset, bHighPrecision); 182 const Distortion distortion = xCalcHistDistortion(histogramSource, outputHistogram); 183 184 if (distortion < minDistortion) 185 { 186 minDistortion = distortion; 187 bestWeight = searchWeight; 188 bestOffset = searchOffset; 189 } 190 } 191 } 192 else 193 { 194 const Int pred = ( maxOffset - ( ( maxOffset*searchWeight)>>(log2Denom) ) ); 195 196 for (Int searchOffset = initialOffset - offsetRange; searchOffset <= initialOffset + offsetRange; searchOffset++) 197 { 198 const Int deltaOffset = Clip3( -4*maxOffset, 4*maxOffset-1, (searchOffset - pred) ); // signed 10bit (if !bHighPrecision) 199 const Int clippedOffset = Clip3( -1*maxOffset, 1*maxOffset-1, (deltaOffset + pred) ); // signed 8bit (if !bHighPrecision) 200 xScaleHistogram(histogramRef, outputHistogram, bitDepth, log2Denom, searchWeight, clippedOffset, bHighPrecision); 201 const Distortion distortion = xCalcHistDistortion(histogramSource, outputHistogram); 202 203 if (distortion < minDistortion) 204 { 205 minDistortion = distortion; 206 bestWeight = searchWeight; 207 bestOffset = clippedOffset; 208 } 209 } 210 } 211 } 212 213 weightToUpdate = bestWeight; 214 offsetToUpdate = bestOffset; 215 216 // regenerate best histogram 217 xScaleHistogram(histogramRef, outputHistogram, bitDepth, log2Denom, bestWeight, bestOffset, bHighPrecision); 218 219 return minDistortion; 220 } 221 222 //! calculate SSE values for both WP version and non-WP version. 223 /* 224 static 225 Int64 xCalcSSEvalueWP(const Int bitDepth, 226 const Pel *pOrgPel, 227 const Pel *pRefPel, 228 const Int width, 229 const Int height, 230 const Int orgStride, 231 const Int refStride, 232 const Int log2Denom, 233 const Int weight, 234 const Int offset, 235 const Bool useHighPrecision) 236 { 237 const Int64 realLog2Denom = useHighPrecision ? log2Denom : (log2Denom + (bitDepth - 8)); 238 239 Int64 SSE = 0; 240 for( Int y = 0; y < height; y++ ) 241 { 242 for( Int x = 0; x < width; x++ ) 243 { 244 Int64 distortion = (( ((Int64)pOrgPel[x]<<(Int64)log2Denom) - ( (Int64)pRefPel[x] * (Int64)weight + ((Int64)offset<<realLog2Denom) ) ) ); 245 SSE += distortion * distortion; 246 } 247 pOrgPel += orgStride; 248 pRefPel += refStride; 249 } 250 251 return SSE; 252 }*/ 253 254 // ----------------------------------------------------------------------------- 255 // Member functions 46 256 47 257 WeightPredAnalysis::WeightPredAnalysis() … … 49 259 for ( UInt lst =0 ; lst<NUM_REF_PIC_LIST_01 ; lst++ ) 50 260 { 51 for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )261 for ( Int refIdx=0 ; refIdx<MAX_NUM_REF ; refIdx++ ) 52 262 { 53 263 for ( Int comp=0 ; comp<MAX_NUM_COMPONENT ;comp++ ) 54 264 { 55 WPScalingParam *pwp = &(m_wp[lst][ iRefIdx][comp]);265 WPScalingParam *pwp = &(m_wp[lst][refIdx][comp]); 56 266 pwp->bPresentFlag = false; 57 267 pwp->uiLog2WeightDenom = 0; … … 78 288 // calculate DC/AC value for channel 79 289 80 const Int iStride = pPic->getStride(compID);81 const Int iWidth = pPic->getWidth(compID);82 const Int iHeight = pPic->getHeight(compID);83 84 const Int iSample = iWidth*iHeight;85 86 Int64 iOrgDC = 0;290 const Int stride = pPic->getStride(compID); 291 const Int width = pPic->getWidth(compID); 292 const Int height = pPic->getHeight(compID); 293 294 const Int sample = width*height; 295 296 Int64 orgDC = 0; 87 297 { 88 298 const Pel *pPel = pPic->getAddr(compID); 89 299 90 for(Int y = 0; y < iHeight; y++, pPel+=iStride )91 { 92 for(Int x = 0; x < iWidth; x++ )93 { 94 iOrgDC += (Int)( pPel[x] );95 } 96 } 97 } 98 99 const Int64 iOrgNormDC = ((iOrgDC+(iSample>>1)) / iSample);100 101 Int64 iOrgAC = 0;300 for(Int y = 0; y < height; y++, pPel+=stride ) 301 { 302 for(Int x = 0; x < width; x++ ) 303 { 304 orgDC += (Int)( pPel[x] ); 305 } 306 } 307 } 308 309 const Int64 orgNormDC = ((orgDC+(sample>>1)) / sample); 310 311 Int64 orgAC = 0; 102 312 { 103 313 const Pel *pPel = pPic->getAddr(compID); 104 314 105 for(Int y = 0; y < iHeight; y++, pPel += iStride )106 { 107 for(Int x = 0; x < iWidth; x++ )108 { 109 iOrgAC += abs( (Int)pPel[x] - (Int)iOrgNormDC );315 for(Int y = 0; y < height; y++, pPel += stride ) 316 { 317 for(Int x = 0; x < width; x++ ) 318 { 319 orgAC += abs( (Int)pPel[x] - (Int)orgNormDC ); 110 320 } 111 321 } … … 113 323 114 324 const Int fixedBitShift = (slice->getSPS()->getSpsRangeExtension().getHighPrecisionOffsetsEnabledFlag())?RExt__PREDICTION_WEIGHTING_ANALYSIS_DC_PRECISION:0; 115 weightACDCParam[compID].iDC = ((( iOrgDC<<fixedBitShift)+(iSample>>1)) / iSample);116 weightACDCParam[compID].iAC = iOrgAC;325 weightACDCParam[compID].iDC = (((orgDC<<fixedBitShift)+(sample>>1)) / sample); 326 weightACDCParam[compID].iAC = orgAC; 117 327 #if SVC_EXTENSION 118 weightACDCParam[compID]. iSamples = iSample;328 weightACDCParam[compID].numSamples = sample; 119 329 #endif 120 330 } … … 129 339 const TComPicYuv *pPic = slice->getPic()->getPicYuvOrg(); 130 340 131 Int iPresentCnt = 0;341 Int presentCnt = 0; 132 342 for ( UInt lst=0 ; lst<NUM_REF_PIC_LIST_01 ; lst++ ) 133 343 { 134 for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )344 for ( Int refIdx=0 ; refIdx<MAX_NUM_REF ; refIdx++ ) 135 345 { 136 346 for(Int componentIndex = 0; componentIndex < pPic->getNumberValidComponents(); componentIndex++) 137 347 { 138 WPScalingParam *pwp = &(m_wp[lst][ iRefIdx][componentIndex]);139 iPresentCnt += (Int)pwp->bPresentFlag;140 } 141 } 142 } 143 144 if( iPresentCnt==0)348 WPScalingParam *pwp = &(m_wp[lst][refIdx][componentIndex]); 349 presentCnt += (Int)pwp->bPresentFlag; 350 } 351 } 352 } 353 354 if(presentCnt==0) 145 355 { 146 356 slice->setTestWeightPred(false); … … 149 359 for ( UInt lst=0 ; lst<NUM_REF_PIC_LIST_01 ; lst++ ) 150 360 { 151 for ( Int iRefIdx=0 ; iRefIdx<MAX_NUM_REF ; iRefIdx++ )361 for ( Int refIdx=0 ; refIdx<MAX_NUM_REF ; refIdx++ ) 152 362 { 153 363 for(Int componentIndex = 0; componentIndex < pPic->getNumberValidComponents(); componentIndex++) 154 364 { 155 WPScalingParam *pwp = &(m_wp[lst][ iRefIdx][componentIndex]);365 WPScalingParam *pwp = &(m_wp[lst][refIdx][componentIndex]); 156 366 157 367 pwp->bPresentFlag = false; … … 166 376 else 167 377 { 168 slice->setTestWeightPred (slice->getPPS()->getUseWP());378 slice->setTestWeightPred (slice->getPPS()->getUseWP()); 169 379 slice->setTestWeightBiPred(slice->getPPS()->getWPBiPred()); 170 380 } … … 173 383 174 384 //! estimate wp tables for explicit wp 175 Void WeightPredAnalysis::xEstimateWPParamSlice(TComSlice *const slice )385 Void WeightPredAnalysis::xEstimateWPParamSlice(TComSlice *const slice, const WeightedPredictionMethod method) 176 386 { 177 387 Int iDenom = 6; … … 194 404 // selecting whether WP is used, or not (fast search) 195 405 // NOTE: This is not operating on a slice, but the entire picture. 196 xSelectWP(slice, iDenom); 406 switch (method) 407 { 408 case WP_PER_PICTURE_WITH_SIMPLE_DC_COMBINED_COMPONENT: 409 xSelectWP(slice, iDenom); 410 break; 411 case WP_PER_PICTURE_WITH_SIMPLE_DC_PER_COMPONENT: 412 xSelectWPHistExtClip(slice, iDenom, false, false, false); 413 break; 414 case WP_PER_PICTURE_WITH_HISTOGRAM_AND_PER_COMPONENT: 415 xSelectWPHistExtClip(slice, iDenom, false, false, true); 416 break; 417 case WP_PER_PICTURE_WITH_HISTOGRAM_AND_PER_COMPONENT_AND_CLIPPING: 418 xSelectWPHistExtClip(slice, iDenom, false, true, true); 419 break; 420 case WP_PER_PICTURE_WITH_HISTOGRAM_AND_PER_COMPONENT_AND_CLIPPING_AND_EXTENSION: 421 xSelectWPHistExtClip(slice, iDenom, true, true, true); 422 break; 423 default: 424 assert(0); 425 exit(1); 426 } 197 427 198 428 slice->setWpScaling( m_wp ); … … 252 482 if( validILRPic ) 253 483 { 254 refAC = ( refAC * currWeightACDCParam[comp]. iSamples ) /refWeightACDCParam[comp].iSamples;484 refAC = ( refAC * currWeightACDCParam[comp].numSamples ) / refWeightACDCParam[comp].numSamples; 255 485 256 486 const Int bitDepthLuma = slice->getBitDepth(CHANNEL_TYPE_LUMA); … … 327 557 328 558 329 //! select whether weighted pred enables or not. 330 Bool WeightPredAnalysis::xSelectWP(TComSlice *const slice, const Int log2Denom) 331 { 332 TComPicYuv *const pPic = slice->getPic()->getPicYuvOrg(); 333 const Int iDefaultWeight = ((Int)1<<log2Denom); 334 const Int iNumPredDir = slice->isInterP() ? 1 : 2; 335 const Bool useHighPrecisionPredictionWeighting = slice->getSPS()->getSpsRangeExtension().getHighPrecisionOffsetsEnabledFlag(); 336 337 assert (iNumPredDir <= Int(NUM_REF_PIC_LIST_01)); 338 339 for ( Int iRefList = 0; iRefList < iNumPredDir; iRefList++ ) 340 { 341 const RefPicList eRefPicList = ( iRefList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); 342 343 for ( Int iRefIdxTemp = 0; iRefIdxTemp < slice->getNumRefIdx(eRefPicList); iRefIdxTemp++ ) 344 { 345 Int64 iSADWP = 0, iSADnoWP = 0; 559 /** select whether weighted pred enables or not. 560 * \param TComSlice *slice 561 * \param log2Denom 562 * \returns Bool 563 */ 564 Bool WeightPredAnalysis::xSelectWPHistExtClip(TComSlice *const slice, const Int log2Denom, const Bool bDoEnhancement, const Bool bClipInitialSADWP, const Bool bUseHistogram) 565 { 566 const TComPicYuv *const pPic = slice->getPic()->getPicYuvOrg(); 567 const Int defaultWeight = 1<<log2Denom; 568 const Int numPredDir = slice->isInterP() ? 1 : 2; 569 const Bool useHighPrecision = slice->getSPS()->getSpsRangeExtension().getHighPrecisionOffsetsEnabledFlag(); 570 571 assert (numPredDir <= Int(NUM_REF_PIC_LIST_01)); 572 573 for ( Int refList = 0; refList < numPredDir; refList++ ) 574 { 575 const RefPicList eRefPicList = ( refList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); 576 577 for ( Int refIdxTemp = 0; refIdxTemp < slice->getNumRefIdx(eRefPicList); refIdxTemp++ ) 578 { 579 Bool useChromaWeight = false; 346 580 347 581 for(Int comp=0; comp<pPic->getNumberValidComponents(); comp++) 348 582 { 349 583 const ComponentID compID = ComponentID(comp); 350 351 Pel *pRef = slice->getRefPic(eRefPicList, iRefIdxTemp)->getPicYuvRec()->getAddr(compID);352 const Int iOrgStride= pPic->getStride(compID);353 const Int iRefStride = slice->getRefPic(eRefPicList, iRefIdxTemp)->getPicYuvRec()->getStride(compID);354 const Int iWidth= pPic->getWidth(compID);355 const Int iHeight= pPic->getHeight(compID);584 const Pel *pOrg = pPic->getAddr(compID); 585 const Pel *pRef = slice->getRefPic(eRefPicList, refIdxTemp)->getPicYuvRec()->getAddr(compID); 586 const Int orgStride = pPic->getStride(compID); 587 const Int refStride = slice->getRefPic(eRefPicList, refIdxTemp)->getPicYuvRec()->getStride(compID); 588 const Int width = pPic->getWidth(compID); 589 const Int height = pPic->getHeight(compID); 356 590 #if SVC_EXTENSION 357 591 const Int bitDepth = slice->getBitDepth(toChannelType(compID)); … … 359 593 const Int bitDepth = slice->getSPS()->getBitDepth(toChannelType(compID)); 360 594 #endif 595 WPScalingParam &wp = m_wp[refList][refIdxTemp][compID]; 596 Int weight = wp.iWeight; 597 Int offset = wp.iOffset; 598 Int weightDef = defaultWeight; 599 Int offsetDef = 0; 361 600 362 601 // calculate SAD costs with/without wp for luma 363 iSADWP += xCalcSADvalueWP(bitDepth, pOrg, pRef, iWidth, iHeight, iOrgStride, iRefStride, log2Denom, m_wp[iRefList][iRefIdxTemp][compID].iWeight, m_wp[iRefList][iRefIdxTemp][compID].iOffset, useHighPrecisionPredictionWeighting); 364 iSADnoWP += xCalcSADvalueWP(bitDepth, pOrg, pRef, iWidth, iHeight, iOrgStride, iRefStride, log2Denom, iDefaultWeight, 0, useHighPrecisionPredictionWeighting); 365 } 366 367 const Double dRatio = ((Double)iSADWP / (Double)iSADnoWP); 368 if(dRatio >= (Double)DTHRESH) 602 const Int64 SADnoWP = xCalcSADvalueWPOptionalClip(bitDepth, pOrg, pRef, width, height, orgStride, refStride, log2Denom, defaultWeight, 0, useHighPrecision, bClipInitialSADWP); 603 if (SADnoWP > 0) 604 { 605 const Int64 SADWP = xCalcSADvalueWPOptionalClip(bitDepth, pOrg, pRef, width, height, orgStride, refStride, log2Denom, weight, offset, useHighPrecision, bClipInitialSADWP); 606 const Double dRatioSAD = (Double)SADWP / (Double)SADnoWP; 607 Double dRatioSr0SAD = std::numeric_limits<Double>::max(); 608 Double dRatioSrSAD = std::numeric_limits<Double>::max(); 609 610 if (bUseHistogram) 611 { 612 std::vector<Int> histogramOrg;// = pPic->getHistogram(compID); 613 std::vector<Int> histogramRef;// = slice->getRefPic(eRefPicList, refIdxTemp)->getPicYuvRec()->getHistogram(compID); 614 std::vector<Int> searchedHistogram; 615 616 // Compute histograms 617 xCalcHistogram(pOrg, histogramOrg, width, height, orgStride, 1 << bitDepth); 618 xCalcHistogram(pRef, histogramRef, width, height, refStride, 1 << bitDepth); 619 620 // Do a histogram search around DC WP parameters; resulting distortion and 'searchedHistogram' is discarded 621 xSearchHistogram(histogramOrg, histogramRef, searchedHistogram, bitDepth, log2Denom, weight, offset, useHighPrecision, compID); 622 // calculate updated WP SAD 623 const Int64 SADSrWP = xCalcSADvalueWP(bitDepth, pOrg, pRef, width, height, orgStride, refStride, log2Denom, weight, offset, useHighPrecision); 624 dRatioSrSAD = (Double)SADSrWP / (Double)SADnoWP; 625 626 if (bDoEnhancement) 627 { 628 // Do the same around the default ones; resulting distortion and 'searchedHistogram' is discarded 629 xSearchHistogram(histogramOrg, histogramRef, searchedHistogram, bitDepth, log2Denom, weightDef, offsetDef, useHighPrecision, compID); 630 // calculate updated WP SAD 631 const Int64 SADSr0WP = xCalcSADvalueWP(bitDepth, pOrg, pRef, width, height, orgStride, refStride, log2Denom, weightDef, offsetDef, useHighPrecision); 632 dRatioSr0SAD = (Double)SADSr0WP / (Double)SADnoWP; 633 } 634 } 635 636 if(min(dRatioSr0SAD, min(dRatioSAD, dRatioSrSAD)) >= WEIGHT_PRED_SAD_RELATIVE_TO_NON_WEIGHT_PRED_SAD) 637 { 638 wp.bPresentFlag = false; 639 wp.iOffset = 0; 640 wp.iWeight = defaultWeight; 641 wp.uiLog2WeightDenom = log2Denom; 642 } 643 else 644 { 645 if (compID != COMPONENT_Y) 646 { 647 useChromaWeight = true; 648 } 649 650 if (dRatioSr0SAD < dRatioSrSAD && dRatioSr0SAD < dRatioSAD) 651 { 652 wp.bPresentFlag = true; 653 wp.iOffset = offsetDef; 654 wp.iWeight = weightDef; 655 wp.uiLog2WeightDenom = log2Denom; 656 } 657 else if (dRatioSrSAD < dRatioSAD) 658 { 659 wp.bPresentFlag = true; 660 wp.iOffset = offset; 661 wp.iWeight = weight; 662 wp.uiLog2WeightDenom = log2Denom; 663 } 664 } 665 } 666 else // (SADnoWP <= 0) 667 { 668 wp.bPresentFlag = false; 669 wp.iOffset = 0; 670 wp.iWeight = defaultWeight; 671 wp.uiLog2WeightDenom = log2Denom; 672 } 673 } 674 675 for(Int comp=1; comp<pPic->getNumberValidComponents(); comp++) 676 { 677 m_wp[refList][refIdxTemp][comp].bPresentFlag = useChromaWeight; 678 } 679 } 680 } 681 682 return true; 683 } 684 685 //! select whether weighted pred enables or not. 686 Bool WeightPredAnalysis::xSelectWP(TComSlice *const slice, const Int log2Denom) 687 { 688 TComPicYuv *const pPic = slice->getPic()->getPicYuvOrg(); 689 const Int defaultWeight = 1<<log2Denom; 690 const Int numPredDir = slice->isInterP() ? 1 : 2; 691 const Bool useHighPrecisionPredictionWeighting = slice->getSPS()->getSpsRangeExtension().getHighPrecisionOffsetsEnabledFlag(); 692 693 assert (numPredDir <= Int(NUM_REF_PIC_LIST_01)); 694 695 for ( Int refList = 0; refList < numPredDir; refList++ ) 696 { 697 const RefPicList eRefPicList = ( refList ? REF_PIC_LIST_1 : REF_PIC_LIST_0 ); 698 699 for ( Int refIdxTemp = 0; refIdxTemp < slice->getNumRefIdx(eRefPicList); refIdxTemp++ ) 700 { 701 Int64 SADWP = 0, SADnoWP = 0; 702 703 for(Int comp=0; comp<pPic->getNumberValidComponents(); comp++) 704 { 705 const ComponentID compID = ComponentID(comp); 706 Pel *pOrg = pPic->getAddr(compID); 707 Pel *pRef = slice->getRefPic(eRefPicList, refIdxTemp)->getPicYuvRec()->getAddr(compID); 708 const Int orgStride = pPic->getStride(compID); 709 const Int refStride = slice->getRefPic(eRefPicList, refIdxTemp)->getPicYuvRec()->getStride(compID); 710 const Int width = pPic->getWidth(compID); 711 const Int height = pPic->getHeight(compID); 712 #if SVC_EXTENSION 713 const Int bitDepth = slice->getBitDepth(toChannelType(compID)); 714 #else 715 const Int bitDepth = slice->getSPS()->getBitDepth(toChannelType(compID)); 716 #endif 717 718 // calculate SAD costs with/without wp for luma 719 SADWP += xCalcSADvalueWP(bitDepth, pOrg, pRef, width, height, orgStride, refStride, log2Denom, m_wp[refList][refIdxTemp][compID].iWeight, m_wp[refList][refIdxTemp][compID].iOffset, useHighPrecisionPredictionWeighting); 720 SADnoWP += xCalcSADvalueWP(bitDepth, pOrg, pRef, width, height, orgStride, refStride, log2Denom, defaultWeight, 0, useHighPrecisionPredictionWeighting); 721 } 722 723 const Double dRatio = SADnoWP > 0 ? (((Double)SADWP / (Double)SADnoWP)) : std::numeric_limits<Double>::max(); 724 if(dRatio >= WEIGHT_PRED_SAD_RELATIVE_TO_NON_WEIGHT_PRED_SAD) 369 725 { 370 726 for(Int comp=0; comp<pPic->getNumberValidComponents(); comp++) 371 727 { 372 m_wp[iRefList][iRefIdxTemp][comp].bPresentFlag = false; 373 m_wp[iRefList][iRefIdxTemp][comp].iOffset = 0; 374 m_wp[iRefList][iRefIdxTemp][comp].iWeight = iDefaultWeight; 375 m_wp[iRefList][iRefIdxTemp][comp].uiLog2WeightDenom = log2Denom; 728 WPScalingParam &wp=m_wp[refList][refIdxTemp][comp]; 729 wp.bPresentFlag = false; 730 wp.iOffset = 0; 731 wp.iWeight = defaultWeight; 732 wp.uiLog2WeightDenom = log2Denom; 376 733 } 377 734 } … … 382 739 } 383 740 384 385 //! calculate SAD values for both WP version and non-WP version. 386 Int64 WeightPredAnalysis::xCalcSADvalueWP(const Int bitDepth, 387 const Pel *pOrgPel, 388 const Pel *pRefPel, 389 const Int iWidth, 390 const Int iHeight, 391 const Int iOrgStride, 392 const Int iRefStride, 393 const Int iLog2Denom, 394 const Int iWeight, 395 const Int iOffset, 396 const Bool useHighPrecisionPredictionWeighting) 397 { 398 const Int64 iSize = iWidth*iHeight; 399 const Int64 iRealLog2Denom = useHighPrecisionPredictionWeighting ? iLog2Denom : (iLog2Denom + (bitDepth - 8)); 400 401 Int64 iSAD = 0; 402 for( Int y = 0; y < iHeight; y++ ) 403 { 404 for( Int x = 0; x < iWidth; x++ ) 405 { 406 iSAD += ABS(( ((Int64)pOrgPel[x]<<(Int64)iLog2Denom) - ( (Int64)pRefPel[x] * (Int64)iWeight + ((Int64)iOffset<<iRealLog2Denom) ) ) ); 407 } 408 pOrgPel += iOrgStride; 409 pRefPel += iRefStride; 410 } 411 412 return (iSAD/iSize); 413 } 741 static 742 Int64 xCalcSADvalueWP(const Int bitDepth, 743 const Pel *pOrgPel, 744 const Pel *pRefPel, 745 const Int width, 746 const Int height, 747 const Int orgStride, 748 const Int refStride, 749 const Int log2Denom, 750 const Int weight, 751 const Int offset, 752 const Bool useHighPrecision) 753 { 754 //const Int64 iSize = iWidth*iHeight; 755 const Int64 realLog2Denom = useHighPrecision ? log2Denom : (log2Denom + (bitDepth - 8)); 756 const Int64 realOffset = ((Int64)offset)<<realLog2Denom; 757 758 Int64 SAD = 0; 759 for( Int y = 0; y < height; y++ ) 760 { 761 for( Int x = 0; x < width; x++ ) 762 { 763 SAD += abs(( ((Int64)pOrgPel[x] << (Int64) log2Denom) - ( (Int64) pRefPel[x] * (Int64) weight + (realOffset) ) ) ); 764 } 765 pOrgPel += orgStride; 766 pRefPel += refStride; 767 } 768 769 //return (iSAD/iSize); 770 return SAD; 771 } 772 773 static 774 Int64 xCalcSADvalueWPOptionalClip(const Int bitDepth, 775 const Pel *pOrgPel, 776 const Pel *pRefPel, 777 const Int width, 778 const Int height, 779 const Int orgStride, 780 const Int refStride, 781 const Int log2Denom, 782 const Int weight, 783 const Int offset, 784 const Bool useHighPrecision, 785 const Bool clipped) 786 { 787 Int64 SAD = 0; 788 if (clipped) 789 { 790 const Int64 realLog2Denom = useHighPrecision ? 0 : (bitDepth - 8); 791 const Int64 realOffset = (Int64)offset<<realLog2Denom; 792 const Int64 roundOffset = (log2Denom == 0) ? 0 : 1 << (log2Denom - 1); 793 const Int64 minValue = 0; 794 const Int64 maxValue = (1 << bitDepth) - 1; 795 796 for( Int y = 0; y < height; y++ ) 797 { 798 for( Int x = 0; x < width; x++ ) 799 { 800 Int64 scaledValue = Clip3(minValue, maxValue, ((((Int64) pRefPel[x] * (Int64) weight + roundOffset) ) >> (Int64) log2Denom) + realOffset); 801 SAD += abs((Int64)pOrgPel[x] - scaledValue); 802 } 803 pOrgPel += orgStride; 804 pRefPel += refStride; 805 } 806 } 807 else 808 { 809 //const Int64 iSize = iWidth*iHeight; 810 const Int64 realLog2Denom = useHighPrecision ? log2Denom : (log2Denom + (bitDepth - 8)); 811 const Int64 realOffset = ((Int64)offset)<<realLog2Denom; 812 813 for( Int y = 0; y < height; y++ ) 814 { 815 for( Int x = 0; x < width; x++ ) 816 { 817 SAD += abs(( ((Int64)pOrgPel[x] << (Int64) log2Denom) - ( (Int64) pRefPel[x] * (Int64) weight + (realOffset) ) ) ); 818 } 819 pOrgPel += orgStride; 820 pRefPel += refStride; 821 } 822 } 823 return SAD; 824 } -
branches/SHM-dev/source/Lib/TLibEncoder/WeightPredAnalysis.h
r1335 r1400 52 52 53 53 Bool xSelectWP (TComSlice *const slice, const Int log2Denom); 54 Bool xSelectWPHistExtClip (TComSlice *const slice, const Int log2Denom, const Bool bDoEnhancement, const Bool bClipInitialSADWP, const Bool bUseHistogram); 54 55 Bool xUpdatingWPParameters(TComSlice *const slice, const Int log2Denom); 55 56 Int64 xCalcSADvalueWP (const Int bitDepth,57 const Pel *pOrgPel,58 const Pel *pRefPel,59 const Int iWidth,60 const Int iHeight,61 const Int iOrgStride,62 const Int iRefStride,63 const Int iLog2Denom,64 const Int iWeight,65 const Int iOffset,66 const Bool useHighPrecisionPredictionWeighting);67 56 68 57 public: … … 72 61 // WP analysis : 73 62 Void xCalcACDCParamSlice (TComSlice *const slice); 74 Void xEstimateWPParamSlice(TComSlice *const slice );63 Void xEstimateWPParamSlice(TComSlice *const slice, const WeightedPredictionMethod method); 75 64 Void xCheckWPEnable (TComSlice *const slice); 76 65 };
Note: See TracChangeset for help on using the changeset viewer.