Changeset 296 in 3DVCSoftware for trunk/source/Lib/TLibEncoder


Ignore:
Timestamp:
20 Feb 2013, 22:07:43 (11 years ago)
Author:
tech
Message:

Reintegrated branch 5.1-dev0 rev. 295.

Location:
trunk/source/Lib/TLibEncoder
Files:
26 edited

Legend:

Unmodified
Added
Removed
  • trunk/source/Lib/TLibEncoder/NALwrite.cpp

    r210 r296  
    5656
    5757  bsNALUHeader.write(0,1); // forbidden_zero_flag
    58 #if NAL_REF_FLAG
    5958  bsNALUHeader.write(nalu.m_nalRefFlag? 1 : 0, 1); // nal_ref_flag
    6059  bsNALUHeader.write(nalu.m_nalUnitType, 6);          // nal_unit_type
    61 #else
    62   bsNALUHeader.write(nalu.m_nalRefIDC, 2); // nal_ref_idc
    63   bsNALUHeader.write(nalu.m_nalUnitType, 5); // nal_unit_type
    64 #endif
    6560
    6661#if QC_MVHEVC_B0046
     
    7267  bsNALUHeader.write(nalu.m_layerId + 1, 5); // layer_id_plus1
    7368#else
    74 #if H0388
    7569  bsNALUHeader.write(nalu.m_temporalId, 3); // temporal_id
    7670 // bsNALUHeader.write(1, 5); // reserved_one_5bits
    7771  bsNALUHeader.write(nalu.m_viewId+1,4);
    7872  bsNALUHeader.write(nalu.m_isDepth,1);
    79 #else
    80   switch (nalu.m_nalUnitType)
    81   {
    82   case NAL_UNIT_CODED_SLICE:
    83   case NAL_UNIT_CODED_SLICE_IDR:
    84 #if H0566_TLA
    85 #if !QC_REM_IDV_B0046
    86   case NAL_UNIT_CODED_SLICE_IDV:
    87 #endif
    88   case NAL_UNIT_CODED_SLICE_CRA:
    89   case NAL_UNIT_CODED_SLICE_TLA:
    90 #else
    91   case NAL_UNIT_CODED_SLICE_CDR:
    92 #endif
    93     bsNALUHeader.write(nalu.m_temporalId, 3); // temporal_id
    94     bsNALUHeader.write(nalu.m_OutputFlag, 1); // output_flag
    95   //  bsNALUHeader.write(1, 4); // reserved_one_4bits
    96     bsNALUHeader.write(nalu.m_viewId+1,3);
    97     bsNALUHeader.write(nalu.m_isDepth,1);
    98     break;
    99   default: break;
    100   }
    101 #endif
    10273#endif
    10374#endif
     
    209180{
    210181  naluDest.m_nalUnitType = naluSrc.m_nalUnitType;
    211 #if NAL_REF_FLAG
    212182  naluDest.m_nalRefFlag  = naluSrc.m_nalRefFlag;
    213 #else
    214   naluDest.m_nalRefIDC   = naluSrc.m_nalRefIDC;
    215 #endif
    216183#if !VIDYO_VPS_INTEGRATION
    217184  naluDest.m_viewId      = naluSrc.m_viewId;
     
    223190#else
    224191 
    225 #if !H0388
    226   naluDest.m_OutputFlag  = naluSrc.m_OutputFlag;
    227 #endif
    228192#endif
    229193  naluDest.m_Bitstream   = naluSrc.m_Bitstream;
  • trunk/source/Lib/TLibEncoder/NALwrite.h

    r210 r296  
    5454   * written to the bitstream.
    5555   */
    56 #if H0388
    5756  OutputNALUnit(
    5857    NalUnitType nalUnitType,
    59 #if NAL_REF_FLAG
    6058    Bool nalRefFlag,
    61 #else
    62     NalRefIdc nalRefIDC,
    63 #endif
    6459#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
    6560    unsigned layerId,
     
    6964#endif
    7065    unsigned temporalID = 0)
    71 #if NAL_REF_FLAG
    7266#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
    7367  : NALUnit(nalUnitType, nalRefFlag, layerId, temporalID)
     
    7569  : NALUnit(nalUnitType, nalRefFlag, viewId, isDepth, temporalID)
    7670#endif
    77 #else
    78 #if VIDYO_VPS_INTEGRATION
    79   : NALUnit(nalUnitType, nalRefIDC, layerId, temporalID)
    80 #else
    81   : NALUnit(nalUnitType, nalRefIDC, viewId, isDepth, temporalID)
    82 #endif
    83 #endif
    8471  , m_Bitstream()
    8572  {}
    86 #else
    87   OutputNALUnit(
    88     NalUnitType nalUnitType,
    89     NalRefIdc nalRefIDC,
    90     Int viewId,
    91     Bool isDepth,
    92     unsigned temporalID = 0,
    93     bool outputFlag = true)
    94   : NALUnit(nalUnitType, nalRefIDC, viewId, isDepth, temporalID, outputFlag)
    95   , m_Bitstream()
    96   {}
    97 #endif
    9873
    9974  OutputNALUnit(const NALUnit& src)
  • trunk/source/Lib/TLibEncoder/TEncAdaptiveLoopFilter.cpp

    r56 r296  
    4747// Constants
    4848// ====================================================================================================================
    49 #if LCU_SYNTAX_ALF
    5049#define ALF_NUM_OF_REDESIGN 1
    51 #else
    52 #define ALF_NUM_OF_REDESIGN 3
    53 #endif
    5450// ====================================================================================================================
    5551// Tables
    5652// ====================================================================================================================
    57 #if LCU_SYNTAX_ALF
    5853const Int TEncAdaptiveLoopFilter::m_alfNumPartsInRowTab[5] =
    5954{
     
    8277  341,  //level 4
    8378};
    84 #endif
    8579// ====================================================================================================================
    8680// Constructor / destructor
    8781// ====================================================================================================================
    8882
    89 #if LCU_SYNTAX_ALF
    9083///AlfCorrData
    9184AlfCorrData::AlfCorrData()
     
    376369  return *this;
    377370}
    378 #endif
    379371
    380372
    381373TEncAdaptiveLoopFilter::TEncAdaptiveLoopFilter()
    382374{
    383 #if !LCU_SYNTAX_ALF
    384   m_ppdAlfCorr = NULL;
    385   m_ppdAlfCorrCb = NULL;
    386   m_ppdAlfCorrCr = NULL;
    387   m_pdDoubleAlfCoeff = NULL;
    388 #endif
    389375  m_pcEntropyCoder = NULL;
    390 #if !LCU_SYNTAX_ALF
    391   m_pcBestAlfParam = NULL;
    392   m_pcTempAlfParam = NULL;
    393 #endif
    394376  m_pcPicYuvBest = NULL;
    395377  m_pcPicYuvTmp = NULL;
    396 #if !LCU_SYNTAX_ALF
    397   pcAlfParamShape0 = NULL;
    398   pcAlfParamShape1 = NULL;
    399   pcPicYuvRecShape0 = NULL;
    400   pcPicYuvRecShape1 = NULL;
    401   m_pcSliceYuvTmp = NULL;
    402 #endif
    403378
    404379  m_iALFMaxNumberFilters = NO_FILTERS;
     
    411386// ====================================================================================================================
    412387
    413 #if LCU_SYNTAX_ALF
    414388/** convert Level Row Col to Idx
    415389 * \param   level,  row,  col
     
    799773}
    800774
    801 #else
    802 
    803 /** create ALF global buffers
    804  * \param iALFEncodePassReduction 0: 16-pass encoding, 1: 1-pass encoding, 2: 2-pass encoding
    805  * This function is used to create the filter buffers to perform time-delay filtering.
    806  */
    807 Void TEncAdaptiveLoopFilter::createAlfGlobalBuffers(Int iALFEncodePassReduction)
    808 {
    809   if(iALFEncodePassReduction)
    810   {
    811     Int iNumOfBuffer = m_iGOPSize +1;
    812 
    813     for(Int i=0; i< NUM_ALF_CLASS_METHOD; i++)
    814     {
    815       m_mergeTableSavedMethods[i] = new Int*[iNumOfBuffer];
    816       m_aiFilterCoeffSavedMethods[i] = new Int**[iNumOfBuffer];
    817       for(Int j=0; j< iNumOfBuffer; j++)
    818       {
    819         m_mergeTableSavedMethods[i][j] = new Int[NO_VAR_BINS];
    820         m_aiFilterCoeffSavedMethods[i][j] = new Int*[NO_VAR_BINS];
    821         for(Int k=0; k< NO_VAR_BINS; k++)
    822         {
    823           m_aiFilterCoeffSavedMethods[i][j][k] = new Int[ALF_MAX_NUM_COEF];
    824         }
    825       }
    826       m_iPreviousFilterShapeMethods[i] = new Int[iNumOfBuffer];
    827     }
    828 
    829   }
    830 }
    831 /** destroy ALF global buffers
    832  * This function is used to destroy the filter buffers.
    833  */
    834 
    835 Void TEncAdaptiveLoopFilter::destroyAlfGlobalBuffers()
    836 {
    837   if(m_iALFEncodePassReduction)
    838   {
    839     for(Int i=0; i< NUM_ALF_CLASS_METHOD; i++)
    840     {
    841       for(Int j=0; j< m_iGOPSize+1; j++)
    842       {
    843         for(Int k=0; k< NO_VAR_BINS; k++)
    844         {
    845           delete[] m_aiFilterCoeffSavedMethods[i][j][k];
    846         }
    847         delete[] m_aiFilterCoeffSavedMethods[i][j];
    848         delete[] m_mergeTableSavedMethods[i][j];
    849       }
    850       delete[] m_aiFilterCoeffSavedMethods[i];
    851       delete[] m_iPreviousFilterShapeMethods[i];
    852       delete[] m_mergeTableSavedMethods[i];
    853 
    854     }
    855 
    856   }
    857 
    858 }
    859 #endif
    860775/**
    861776 \param pcPic           picture (TComPic) pointer
     
    865780{
    866781  m_pcEntropyCoder = pcEntropyCoder;
    867 #if !LCU_SYNTAX_ALF
    868   xInitParam();
    869 #endif
    870782  xCreateTmpAlfCtrlFlags();
    871783 
     
    876788  m_pcPicYuvTmp->createLuma(iWidth, iHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
    877789  m_pcPicYuvBest = pcPic->getPicYuvPred();
    878 #if !LCU_SYNTAX_ALF 
    879   m_pcBestAlfParam = new ALFParam;
    880   m_pcTempAlfParam = new ALFParam;
    881   allocALFParam(m_pcBestAlfParam);
    882   allocALFParam(m_pcTempAlfParam);
    883   pcPicYuvRecShape0 = new TComPicYuv();
    884   pcPicYuvRecShape0->createLuma(iWidth, iHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
    885  
    886   pcPicYuvRecShape1 = new TComPicYuv();
    887   pcPicYuvRecShape1->createLuma(iWidth, iHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
    888 
    889   pcAlfParamShape0 = new ALFParam;
    890   pcAlfParamShape1 = new ALFParam;
    891 
    892   allocALFParam(pcAlfParamShape0); 
    893   allocALFParam(pcAlfParamShape1);
    894 
    895   // init qc_filter
    896   initMatrix4D_double(&m_EGlobalSym, NUM_ALF_FILTER_SHAPE+1,  NO_VAR_BINS, MAX_SQR_FILT_LENGTH, MAX_SQR_FILT_LENGTH);
    897   initMatrix3D_double(&m_yGlobalSym, NUM_ALF_FILTER_SHAPE+1, NO_VAR_BINS, MAX_SQR_FILT_LENGTH);
    898 #endif
    899790  initMatrix_int(&m_filterCoeffSymQuant, NO_VAR_BINS, ALF_MAX_NUM_COEF);
    900 #if !LCU_SYNTAX_ALF
    901   m_pixAcc = (double *) calloc(NO_VAR_BINS, sizeof(double));
    902 #endif
    903791  initMatrix_Pel(&m_maskImg, m_img_height, m_img_width);
    904792  initMatrix_double(&m_E_temp, MAX_SQR_FILT_LENGTH, MAX_SQR_FILT_LENGTH);//
     
    913801  initMatrix_int(&m_FilterCoeffQuantTemp, NO_VAR_BINS, ALF_MAX_NUM_COEF);//
    914802
    915 #if LCU_SYNTAX_ALF
    916803  m_tempALFp = new ALFParam(ALF_Y);
    917 #else
    918   m_tempALFp = new ALFParam;
    919   allocALFParam(m_tempALFp);
    920   if( m_bUseNonCrossALF )
    921   {
    922     m_pcSliceYuvTmp = new TComPicYuv();
    923     m_pcSliceYuvTmp->create(iWidth, iHeight, g_uiMaxCUWidth, g_uiMaxCUHeight, g_uiMaxCUDepth);
    924   }
    925 #endif
    926804}
    927805
    928806Void TEncAdaptiveLoopFilter::endALFEnc()
    929807{
    930 #if !LCU_SYNTAX_ALF
    931   xUninitParam();
    932 #endif
    933808  xDestroyTmpAlfCtrlFlags();
    934809 
     
    938813  m_pcPic = NULL;
    939814  m_pcEntropyCoder = NULL;
    940 #if !LCU_SYNTAX_ALF
    941   freeALFParam(m_pcBestAlfParam);
    942   freeALFParam(m_pcTempAlfParam);
    943   delete m_pcBestAlfParam;
    944   delete m_pcTempAlfParam;
    945 
    946   pcPicYuvRecShape0->destroyLuma();
    947   delete pcPicYuvRecShape0;
    948   pcPicYuvRecShape0 = NULL;
    949 
    950   pcPicYuvRecShape1->destroyLuma();
    951   delete pcPicYuvRecShape1;
    952   pcPicYuvRecShape1 = NULL;
    953 
    954   freeALFParam(pcAlfParamShape0);
    955   freeALFParam(pcAlfParamShape1);
    956 
    957   delete pcAlfParamShape0;
    958   delete pcAlfParamShape1;
    959 
    960   // delete qc filters
    961   destroyMatrix4D_double(m_EGlobalSym, NUM_ALF_FILTER_SHAPE+1,  NO_VAR_BINS);
    962   destroyMatrix3D_double(m_yGlobalSym, NUM_ALF_FILTER_SHAPE+1);
    963 #endif
    964815  destroyMatrix_int(m_filterCoeffSymQuant);
    965 #if !LCU_SYNTAX_ALF 
    966   free(m_pixAcc);
    967 #endif
    968816  destroyMatrix_Pel(m_maskImg);
    969817  destroyMatrix3D_double(m_E_merged, NO_VAR_BINS);
     
    980828  destroyMatrix_int(m_FilterCoeffQuantTemp);
    981829 
    982 #if LCU_SYNTAX_ALF
    983830  delete m_tempALFp;
    984 #else
    985   freeALFParam(m_tempALFp);
    986   delete m_tempALFp;
    987 
    988   if(m_bUseNonCrossALF)
    989   {
    990     m_pcSliceYuvTmp->destroy();
    991     delete m_pcSliceYuvTmp;
    992     m_pcSliceYuvTmp = NULL;
    993   }
    994 #endif
    995 }
    996 
    997 #if LCU_SYNTAX_ALF
     831}
     832
    998833
    999834/** Assign output ALF parameters
     
    27622597#endif
    27632598
    2764 #if ALF_SINGLE_FILTER_SHAPE
    27652599        calcCorrOneCompRegionChma(pPicOrg, pPicSrc, stride, ypos, xpos, height, width, alfCorr->ECorr[0], alfCorr->yCorr[0], isLastBlock);
    2766 #endif
    27672600      }
    27682601    }
     
    28222655#endif
    28232656
    2824 #if ALF_SINGLE_FILTER_SHAPE
    28252657        calcCorrOneCompRegionLuma(pPicOrg, pPicSrc, stride, ypos, xpos, height, width, alfCorr->ECorr, alfCorr->yCorr, alfCorr->pixAcc, forceCollection, isLastBlock);
    2826 #endif       
    28272658      }
    28282659    }
     
    28382669
    28392670
    2840 #if ALF_SINGLE_FILTER_SHAPE
    28412671/** Gather correlations for one region for chroma component
    28422672 * \param [in] imgOrg picture buffer for original picture
     
    30862916
    30872917}
    3088 #endif
    3089 
    3090 #else
    3091 
    3092 
    3093 #if ALF_CHROMA_LAMBDA 
    3094 /**
    3095  \param pcAlfParam           ALF parameter
    3096  \param [out] pvAlfCtrlParam ALF CU control parameters container for slices
    3097  \param dLambdaLuma          luma lambda value for RD cost computation
    3098  \param dLambdaChroma        chroma lambda value for RD cost computation
    3099  \retval ruiDist             distortion
    3100  \retval ruiBits             required bits
    3101  \retval ruiMaxAlfCtrlDepth  optimal partition depth
    3102  */
    3103 #if HHI_INTERVIEW_SKIP
    3104 Void TEncAdaptiveLoopFilter::ALFProcess( ALFParam* pcAlfParam, std::vector<AlfCUCtrlInfo>* pvAlfCtrlParam, Double dLambdaLuma, Double dLambdaChroma, UInt64& ruiDist, UInt64& ruiBits, Bool bInterviewSkip)
    3105 #else
    3106 Void TEncAdaptiveLoopFilter::ALFProcess( ALFParam* pcAlfParam, std::vector<AlfCUCtrlInfo>* pvAlfCtrlParam, Double dLambdaLuma, Double dLambdaChroma, UInt64& ruiDist, UInt64& ruiBits)
    3107 
    3108 #endif
    3109 #else
    3110 /**
    3111  \param pcAlfParam           ALF parameter
    3112  \param dLambda              lambda value for RD cost computation
    3113  \retval ruiDist             distortion
    3114  \retval ruiBits             required bits
    3115  \retval ruiMaxAlfCtrlDepth  optimal partition depth
    3116  */
    3117 #if HHI_INTERVIEW_SKIP
    3118 Void TEncAdaptiveLoopFilter::ALFProcess( ALFParam* pcAlfParam, std::vector<AlfCUCtrlInfo>* pvAlfCtrlParam, Double dLambda, UInt64& ruiDist, UInt64& ruiBits, Bool bInterviewSkip)
    3119 #else
    3120 Void TEncAdaptiveLoopFilter::ALFProcess( ALFParam* pcAlfParam, std::vector<AlfCUCtrlInfo>* pvAlfCtrlParam, Double dLambda, UInt64& ruiDist, UInt64& ruiBits)
    3121 
    3122 #endif
    3123 #endif
    3124 {
    3125  
    3126   // set lambda
    3127 #if ALF_CHROMA_LAMBDA 
    3128   m_dLambdaLuma   = dLambdaLuma;
    3129   m_dLambdaChroma = dLambdaChroma;
    3130 #else
    3131   m_dLambdaLuma   = dLambda;
    3132   m_dLambdaChroma = dLambda;
    3133 #endif
    3134 
    3135   m_lcuHeight = m_pcPic->getSlice(0)->getSPS()->getMaxCUHeight();
    3136 
    3137 #if ALF_SINGLE_FILTER_SHAPE
    3138   m_lineIdxPadBot = m_lcuHeight - 4 - 3; // DFRegion, Vertical Taps
    3139 #else
    3140   m_lineIdxPadBot = m_lcuHeight - 4 - 4; // DFRegion, Vertical Taps
    3141 #endif
    3142   m_lineIdxPadTop = m_lcuHeight - 4; // DFRegion
    3143 
    3144   m_lcuHeightChroma = m_lcuHeight>>1;
    3145 #if ALF_SINGLE_FILTER_SHAPE
    3146   m_lineIdxPadBotChroma = m_lcuHeightChroma - 2 - 3; // DFRegion, Vertical Taps
    3147 #else
    3148   m_lineIdxPadBotChroma = m_lcuHeightChroma - 2 - 4; // DFRegion, Vertical Taps
    3149 #endif
    3150   m_lineIdxPadTopChroma = m_lcuHeightChroma - 2 ; // DFRegion
    3151 
    3152   TComPicYuv* pcPicOrg = m_pcPic->getPicYuvOrg();
    3153  
    3154   // extend image for filtering
    3155   TComPicYuv* pcPicYuvRec    = m_pcPic->getPicYuvRec();
    3156   TComPicYuv* pcPicYuvExtRec = m_pcTempPicYuv;
    3157 #if HHI_INTERVIEW_SKIP
    3158   TComPicYuv* pcUsedPelMap   = m_pcPic->getUsedPelsMap() ;
    3159   if(bInterviewSkip)
    3160     assert( pcUsedPelMap ) ;
    3161 #endif
    3162  
    3163   pcPicYuvRec->copyToPic(pcPicYuvExtRec);
    3164   if(!m_bUseNonCrossALF)
    3165   {
    3166   pcPicYuvExtRec->setBorderExtension( false );
    3167   pcPicYuvExtRec->extendPicBorder   ();
    3168   }
    3169  
    3170   // set min cost
    3171   UInt64 uiMinRate = MAX_INT;
    3172   UInt64 uiMinDist = MAX_INT;
    3173   Double dMinCost  = MAX_DOUBLE;
    3174  
    3175   UInt64  uiOrigRate;
    3176   UInt64  uiOrigDist;
    3177   Double  dOrigCost;
    3178  
    3179   // calc original cost
    3180 #if HHI_INTERVIEW_SKIP
    3181   xCalcRDCost( pcPicOrg, pcPicYuvRec, pcUsedPelMap, NULL, uiOrigRate, uiOrigDist, dOrigCost );
    3182 #else
    3183   xCalcRDCost( pcPicOrg, pcPicYuvRec, NULL, uiOrigRate, uiOrigDist, dOrigCost );
    3184 #endif
    3185   m_pcBestAlfParam->alf_flag = 0;
    3186   // initialize temp_alfps
    3187   m_pcTempAlfParam->alf_flag        = 1;
    3188   m_pcTempAlfParam->chroma_idc      = 0;
    3189 
    3190   m_bAlfCUCtrlEnabled = (pvAlfCtrlParam != NULL)?true:false;
    3191   if(m_bAlfCUCtrlEnabled)
    3192   {
    3193     m_vBestAlfCUCtrlParam.resize(m_uiNumSlicesInPic);
    3194     for(Int s=0; s< m_uiNumSlicesInPic; s++)
    3195     {
    3196       m_vBestAlfCUCtrlParam[s].cu_control_flag = 0;
    3197     }
    3198   }
    3199   else
    3200   {
    3201     m_vBestAlfCUCtrlParam.clear();
    3202   }
    3203 
    3204   setALFEncodingParam(m_pcPic);
    3205 
    3206   // adaptive in-loop wiener filtering
    3207 #if HHI_INTERVIEW_SKIP
    3208   xEncALFLuma( pcPicOrg, pcPicYuvExtRec, pcPicYuvRec, uiMinRate, uiMinDist, dMinCost, bInterviewSkip );
    3209 #else
    3210   xEncALFLuma( pcPicOrg, pcPicYuvExtRec, pcPicYuvRec, uiMinRate, uiMinDist, dMinCost );
    3211 #endif
    3212 
    3213   // cu-based filter on/off control
    3214 #if HHI_INTERVIEW_SKIP
    3215   xCUAdaptiveControl_qc( pcPicOrg, pcPicYuvExtRec, pcPicYuvRec, pcUsedPelMap, uiMinRate, uiMinDist, dMinCost );
    3216 #else
    3217   xCUAdaptiveControl_qc( pcPicOrg, pcPicYuvExtRec, pcPicYuvRec, uiMinRate, uiMinDist, dMinCost );
    3218 #endif
    3219  
    3220   // compare RD cost to non-ALF case
    3221   if( dMinCost < dOrigCost )
    3222   {
    3223     m_pcBestAlfParam->alf_flag = 1;
    3224    
    3225     ruiBits = uiMinRate;
    3226     ruiDist = uiMinDist;
    3227   }
    3228   else
    3229   {
    3230     m_pcBestAlfParam->alf_flag        = 0;
    3231 
    3232     uiMinRate = uiOrigRate;
    3233     uiMinDist = uiOrigDist;
    3234    
    3235     m_pcEntropyCoder->setAlfCtrl(false);
    3236     if(m_bAlfCUCtrlEnabled)
    3237     {
    3238       for(Int s=0; s< m_uiNumSlicesInPic; s++)
    3239       {
    3240         m_vBestAlfCUCtrlParam[s].cu_control_flag = 0;
    3241       }
    3242     }
    3243     pcPicYuvExtRec->copyToPicLuma(pcPicYuvRec);
    3244    
    3245     ruiBits = uiOrigRate;
    3246     ruiDist = uiOrigDist;
    3247   }
    3248   // if ALF works
    3249   if( m_pcBestAlfParam->alf_flag )
    3250   {
    3251     // do additional ALF process for chroma
    3252     xFilterTapDecisionChroma( uiMinRate, pcPicOrg, pcPicYuvExtRec, pcPicYuvRec, ruiDist, ruiBits );
    3253   }
    3254  
    3255   // copy to best storage
    3256   copyALFParam(pcAlfParam, m_pcBestAlfParam);
    3257  
    3258   if(m_bAlfCUCtrlEnabled)
    3259   {
    3260     for(Int s=0; s< m_uiNumSlicesInPic; s++)
    3261     {
    3262       (*pvAlfCtrlParam)[s]= m_vBestAlfCUCtrlParam[s];
    3263     }
    3264   }
    3265 }
    3266 #endif
     2918
    32672919
    32682920/** PCM LF disable process.
     
    32842936// Private member functions
    32852937// ====================================================================================================================
    3286 #if !LCU_SYNTAX_ALF
    3287 Void TEncAdaptiveLoopFilter::xInitParam()
    3288 {
    3289   Int i, j;
    3290  
    3291   if (m_ppdAlfCorr != NULL)
    3292   {
    3293     for (i = 0; i < ALF_MAX_NUM_COEF; i++)
    3294     {
    3295       for (j = 0; j < ALF_MAX_NUM_COEF+1; j++)
    3296       {
    3297         m_ppdAlfCorr[i][j] = 0;
    3298       }
    3299     }
    3300   }
    3301   else
    3302   {
    3303     m_ppdAlfCorr = new Double*[ALF_MAX_NUM_COEF];
    3304     for (i = 0; i < ALF_MAX_NUM_COEF; i++)
    3305     {
    3306       m_ppdAlfCorr[i] = new Double[ALF_MAX_NUM_COEF+1];
    3307       for (j = 0; j < ALF_MAX_NUM_COEF+1; j++)
    3308       {
    3309         m_ppdAlfCorr[i][j] = 0;
    3310       }
    3311     }
    3312   }
    3313  
    3314   if (m_pdDoubleAlfCoeff != NULL)
    3315   {
    3316     for (i = 0; i < ALF_MAX_NUM_COEF; i++)
    3317     {
    3318       m_pdDoubleAlfCoeff[i] = 0;
    3319     }
    3320   }
    3321   else
    3322   {
    3323     m_pdDoubleAlfCoeff = new Double[ALF_MAX_NUM_COEF];
    3324     for (i = 0; i < ALF_MAX_NUM_COEF; i++)
    3325     {
    3326       m_pdDoubleAlfCoeff[i] = 0;
    3327     }
    3328   }
    3329   if (m_ppdAlfCorrCb != NULL)
    3330   {
    3331     for (i = 0; i < ALF_MAX_NUM_COEF; i++)
    3332     {
    3333       for (j = 0; j < ALF_MAX_NUM_COEF+1; j++)
    3334       {
    3335         m_ppdAlfCorrCb[i][j] = 0;
    3336       }
    3337     }
    3338   }
    3339   else
    3340   {
    3341     m_ppdAlfCorrCb = new Double*[ALF_MAX_NUM_COEF];
    3342     for (i = 0; i < ALF_MAX_NUM_COEF; i++)
    3343     {
    3344       m_ppdAlfCorrCb[i] = new Double[ALF_MAX_NUM_COEF+1];
    3345       for (j = 0; j < ALF_MAX_NUM_COEF+1; j++)
    3346       {
    3347         m_ppdAlfCorrCb[i][j] = 0;
    3348       }
    3349     }
    3350   }
    3351  
    3352   if (m_ppdAlfCorrCr != NULL)
    3353   {
    3354     for (i = 0; i < ALF_MAX_NUM_COEF; i++)
    3355     {
    3356       for (j = 0; j < ALF_MAX_NUM_COEF+1; j++)
    3357       {
    3358         m_ppdAlfCorrCr[i][j] = 0;
    3359       }
    3360     }
    3361   }
    3362   else
    3363   {
    3364     m_ppdAlfCorrCr = new Double*[ALF_MAX_NUM_COEF];
    3365     for (i = 0; i < ALF_MAX_NUM_COEF; i++)
    3366     {
    3367       m_ppdAlfCorrCr[i] = new Double[ALF_MAX_NUM_COEF+1];
    3368       for (j = 0; j < ALF_MAX_NUM_COEF+1; j++)
    3369       {
    3370         m_ppdAlfCorrCr[i][j] = 0;
    3371       }
    3372     }
    3373   }
    3374 }
    3375 
    3376 Void TEncAdaptiveLoopFilter::xUninitParam()
    3377 {
    3378   Int i;
    3379  
    3380   if (m_ppdAlfCorr != NULL)
    3381   {
    3382     for (i = 0; i < ALF_MAX_NUM_COEF; i++)
    3383     {
    3384       delete[] m_ppdAlfCorr[i];
    3385       m_ppdAlfCorr[i] = NULL;
    3386     }
    3387     delete[] m_ppdAlfCorr;
    3388     m_ppdAlfCorr = NULL;
    3389   }
    3390  
    3391   if (m_pdDoubleAlfCoeff != NULL)
    3392   {
    3393     delete[] m_pdDoubleAlfCoeff;
    3394     m_pdDoubleAlfCoeff = NULL;
    3395   }
    3396   if (m_ppdAlfCorrCb != NULL)
    3397   {
    3398     for (i = 0; i < ALF_MAX_NUM_COEF; i++)
    3399     {
    3400       delete[] m_ppdAlfCorrCb[i];
    3401       m_ppdAlfCorrCb[i] = NULL;
    3402     }
    3403     delete[] m_ppdAlfCorrCb;
    3404     m_ppdAlfCorrCb = NULL;
    3405   }
    3406  
    3407   if (m_ppdAlfCorrCr != NULL)
    3408   {
    3409     for (i = 0; i < ALF_MAX_NUM_COEF; i++)
    3410     {
    3411       delete[] m_ppdAlfCorrCr[i];
    3412       m_ppdAlfCorrCr[i] = NULL;
    3413     }
    3414     delete[] m_ppdAlfCorrCr;
    3415     m_ppdAlfCorrCr = NULL;
    3416   }
    3417 }
    3418 #endif
    34192938Void TEncAdaptiveLoopFilter::xCreateTmpAlfCtrlFlags()
    34202939{
     
    35123031}
    35133032
    3514 #if !LCU_SYNTAX_ALF
    3515 
    3516 Void TEncAdaptiveLoopFilter::xCalcCorrelationFunc(Int ypos, Int xpos, Pel* pImgOrg, Pel* pImgPad, Int filtNo, Int iWidth, Int iHeight, Int iOrgStride, Int iCmpStride, Bool bSymmCopyBlockMatrix)
    3517 {
    3518   Int     yposEnd = ypos + iHeight -1;
    3519   Int     xposEnd = xpos + iWidth  -1;
    3520   Int     N       = m_sqrFiltLengthTab[filtNo];
    3521 
    3522   Int imgHeightChroma = m_img_height>>1;
    3523   Int yLineInLCU;
    3524   Int paddingline ;
    3525 
    3526   Int ELocal[ALF_MAX_NUM_COEF];
    3527   Pel *pImgPad1, *pImgPad2, *pImgPad3, *pImgPad4;
    3528   Int i, j, k, l;
    3529   Int yLocal;
    3530 
    3531   pImgPad += (ypos*iCmpStride);
    3532   pImgOrg += (ypos*iOrgStride);
    3533 
    3534   switch(filtNo)
    3535   {
    3536 #if !ALF_SINGLE_FILTER_SHAPE
    3537   case ALF_STAR5x5:
    3538     {
    3539       for (i= ypos; i<= yposEnd; i++)
    3540       {
    3541         yLineInLCU = i % m_lcuHeightChroma;
    3542 
    3543         if (yLineInLCU < m_lineIdxPadBotChroma || i-yLineInLCU+m_lcuHeightChroma >= imgHeightChroma )
    3544         {
    3545           pImgPad1 = pImgPad +   iCmpStride;
    3546           pImgPad2 = pImgPad -   iCmpStride;
    3547           pImgPad3 = pImgPad + 2*iCmpStride;
    3548           pImgPad4 = pImgPad - 2*iCmpStride;
    3549         }
    3550         else if (yLineInLCU < m_lineIdxPadTopChroma)
    3551         {
    3552           paddingline = - yLineInLCU + m_lineIdxPadTopChroma - 1;
    3553           pImgPad1 = pImgPad + min(paddingline, 1)*iCmpStride;
    3554           pImgPad2 = pImgPad -   iCmpStride;
    3555           pImgPad3 = pImgPad + min(paddingline, 2)*iCmpStride;
    3556           pImgPad4 = pImgPad - 2*iCmpStride;
    3557         }
    3558         else
    3559         {
    3560           paddingline = yLineInLCU - m_lineIdxPadTopChroma ;
    3561           pImgPad1 = pImgPad +   iCmpStride;
    3562           pImgPad2 = pImgPad - min(paddingline, 1)*iCmpStride;
    3563           pImgPad3 = pImgPad + 2*iCmpStride;
    3564           pImgPad4 = pImgPad - min(paddingline, 2)*iCmpStride;
    3565         }
    3566 
    3567         if ( (yLineInLCU == m_lineIdxPadTopChroma || yLineInLCU == m_lineIdxPadTopChroma-1) && i-yLineInLCU+m_lcuHeightChroma < imgHeightChroma )
    3568         {
    3569           pImgPad+= iCmpStride;
    3570           pImgOrg+= iOrgStride;
    3571           continue;
    3572         }
    3573         else
    3574         {
    3575         for (j= xpos; j<= xposEnd; j++)
    3576         {
    3577           memset(ELocal, 0, N*sizeof(Int));
    3578 
    3579           ELocal[0] = (pImgPad3[j+2] + pImgPad4[j-2]);
    3580           ELocal[1] = (pImgPad3[j  ] + pImgPad4[j  ]);
    3581           ELocal[2] = (pImgPad3[j-2] + pImgPad4[j+2]);
    3582 
    3583           ELocal[3] = (pImgPad1[j+1] + pImgPad2[j-1]);
    3584           ELocal[4] = (pImgPad1[j  ] + pImgPad2[j  ]);
    3585           ELocal[5] = (pImgPad1[j-1] + pImgPad2[j+1]);
    3586 
    3587           ELocal[6] = (pImgPad[j+2] + pImgPad[j-2]);
    3588           ELocal[7] = (pImgPad[j+1] + pImgPad[j-1]);
    3589           ELocal[8] = (pImgPad[j  ]);
    3590 
    3591           yLocal= (Int)pImgOrg[j];
    3592 
    3593           for(k=0; k<N; k++)
    3594           {
    3595             m_ppdAlfCorr[k][k] += ELocal[k]*ELocal[k];
    3596             for(l=k+1; l<N; l++)
    3597             {
    3598               m_ppdAlfCorr[k][l] += ELocal[k]*ELocal[l];
    3599             }
    3600 
    3601             m_ppdAlfCorr[k][N] += yLocal*ELocal[k];
    3602           }
    3603         }
    3604         pImgPad+= iCmpStride;
    3605         pImgOrg+= iOrgStride;
    3606       }
    3607 
    3608       }
    3609     }
    3610     break;
    3611   case ALF_CROSS9x9:
    3612     {
    3613       Pel *pImgPad5, *pImgPad6, *pImgPad7, *pImgPad8;
    3614 #else
    3615   case ALF_CROSS9x7_SQUARE3x3:
    3616     {
    3617       Pel *pImgPad5, *pImgPad6;
    3618 #endif
    3619       for (i= ypos; i<= yposEnd; i++)
    3620       {
    3621         yLineInLCU = i % m_lcuHeightChroma;
    3622 
    3623         if (yLineInLCU<2 && i> 2)
    3624         {
    3625           paddingline = yLineInLCU + 2 ;
    3626           pImgPad1 = pImgPad +   iCmpStride;
    3627           pImgPad2 = pImgPad -   iCmpStride;
    3628           pImgPad3 = pImgPad + 2*iCmpStride;
    3629           pImgPad4 = pImgPad - 2*iCmpStride;
    3630           pImgPad5 = (paddingline < 3) ? pImgPad : pImgPad + 3*iCmpStride;
    3631           pImgPad6 = (paddingline < 3) ? pImgPad : pImgPad - min(paddingline, 3)*iCmpStride;;
    3632 #if !ALF_SINGLE_FILTER_SHAPE
    3633           pImgPad7 = (paddingline < 4) ? pImgPad : pImgPad + 4*iCmpStride;
    3634           pImgPad8 = (paddingline < 4) ? pImgPad : pImgPad - min(paddingline, 4)*iCmpStride;;     
    3635 #endif
    3636         }
    3637         else if (yLineInLCU < m_lineIdxPadBotChroma || i-yLineInLCU+m_lcuHeightChroma >= imgHeightChroma )
    3638         {
    3639           pImgPad1 = pImgPad +   iCmpStride;
    3640           pImgPad2 = pImgPad -   iCmpStride;
    3641           pImgPad3 = pImgPad + 2*iCmpStride;
    3642           pImgPad4 = pImgPad - 2*iCmpStride;
    3643           pImgPad5 = pImgPad + 3*iCmpStride;
    3644           pImgPad6 = pImgPad - 3*iCmpStride;
    3645 #if !ALF_SINGLE_FILTER_SHAPE
    3646           pImgPad7 = pImgPad + 4*iCmpStride;
    3647           pImgPad8 = pImgPad - 4*iCmpStride;
    3648 #endif
    3649         }
    3650         else if (yLineInLCU < m_lineIdxPadTopChroma)
    3651         {
    3652           paddingline = - yLineInLCU + m_lineIdxPadTopChroma - 1;
    3653           pImgPad1 = (paddingline < 1) ? pImgPad : pImgPad + min(paddingline, 1)*iCmpStride;
    3654           pImgPad2 = (paddingline < 1) ? pImgPad : pImgPad -   iCmpStride;
    3655           pImgPad3 = (paddingline < 2) ? pImgPad : pImgPad + min(paddingline, 2)*iCmpStride;
    3656           pImgPad4 = (paddingline < 2) ? pImgPad : pImgPad - 2*iCmpStride;
    3657           pImgPad5 = (paddingline < 3) ? pImgPad : pImgPad + min(paddingline, 3)*iCmpStride;
    3658           pImgPad6 = (paddingline < 3) ? pImgPad : pImgPad - 3*iCmpStride;
    3659 #if !ALF_SINGLE_FILTER_SHAPE
    3660           pImgPad7 = (paddingline < 4) ? pImgPad : pImgPad + min(paddingline, 4)*iCmpStride;
    3661           pImgPad8 = (paddingline < 4) ? pImgPad : pImgPad - 4*iCmpStride;
    3662 #endif
    3663         }
    3664         else
    3665         {
    3666           paddingline = yLineInLCU - m_lineIdxPadTopChroma ;
    3667           pImgPad1 = (paddingline < 1) ? pImgPad : pImgPad +   iCmpStride;
    3668           pImgPad2 = (paddingline < 1) ? pImgPad : pImgPad - min(paddingline, 1)*iCmpStride;
    3669           pImgPad3 = (paddingline < 2) ? pImgPad : pImgPad + 2*iCmpStride;
    3670           pImgPad4 = (paddingline < 2) ? pImgPad : pImgPad - min(paddingline, 2)*iCmpStride;
    3671           pImgPad5 = (paddingline < 3) ? pImgPad : pImgPad + 3*iCmpStride;
    3672           pImgPad6 = (paddingline < 3) ? pImgPad : pImgPad - min(paddingline, 3)*iCmpStride;
    3673 #if !ALF_SINGLE_FILTER_SHAPE
    3674           pImgPad7 = (paddingline < 4) ? pImgPad : pImgPad + 4*iCmpStride;
    3675           pImgPad8 = (paddingline < 4) ? pImgPad : pImgPad - min(paddingline, 4)*iCmpStride;
    3676 #endif
    3677         }
    3678 
    3679         for (j= xpos; j<= xposEnd; j++)
    3680         {
    3681           memset(ELocal, 0, N*sizeof(Int));
    3682 #if ALF_SINGLE_FILTER_SHAPE
    3683           ELocal[0] = (pImgPad5[j]+pImgPad6[j]);
    3684           ELocal[1] = (pImgPad3[j]+pImgPad4[j]);
    3685           ELocal[2] = (pImgPad1[j-1]+pImgPad2[j+1]);
    3686           ELocal[3] = (pImgPad1[j]+pImgPad2[j]);
    3687           ELocal[4] = (pImgPad1[j+1]+pImgPad2[j-1]);
    3688           ELocal[5] = (pImgPad[j+4]+pImgPad[j-4]);
    3689           ELocal[6] = (pImgPad[j+3]+pImgPad[j-3]);
    3690           ELocal[7] = (pImgPad[j+2]+pImgPad[j-2]);
    3691           ELocal[8] = (pImgPad[j+1]+pImgPad[j-1]);
    3692           ELocal[9] = (pImgPad[j  ]);
    3693 #else
    3694           ELocal[0] = (pImgPad7[j] + pImgPad8[j]);
    3695 
    3696           ELocal[1] = (pImgPad5[j] + pImgPad6[j]);
    3697 
    3698           ELocal[2] = (pImgPad3[j] + pImgPad4[j]);
    3699 
    3700           ELocal[3] = (pImgPad1[j] + pImgPad2[j]);
    3701 
    3702           ELocal[4] = (pImgPad[j+4] + pImgPad[j-4]);
    3703           ELocal[5] = (pImgPad[j+3] + pImgPad[j-3]);
    3704           ELocal[6] = (pImgPad[j+2] + pImgPad[j-2]);
    3705           ELocal[7] = (pImgPad[j+1] + pImgPad[j-1]);
    3706           ELocal[8] = (pImgPad[j  ] );
    3707 #endif
    3708           yLocal= (Int)pImgOrg[j];
    3709 
    3710           for(k=0; k<N; k++)
    3711           {
    3712             m_ppdAlfCorr[k][k] += ELocal[k]*ELocal[k];
    3713             for(l=k+1; l<N; l++)
    3714             {
    3715               m_ppdAlfCorr[k][l] += ELocal[k]*ELocal[l];
    3716             }
    3717 
    3718             m_ppdAlfCorr[k][N] += yLocal*ELocal[k];
    3719           }
    3720         }
    3721         pImgPad+= iCmpStride;
    3722         pImgOrg+= iOrgStride;
    3723       }
    3724 
    3725     }
    3726     break;
    3727   default:
    3728     {
    3729       printf("Not a supported filter shape\n");
    3730       assert(0);
    3731       exit(1);
    3732     }
    3733   }
    3734 
    3735   if(bSymmCopyBlockMatrix)
    3736   {
    3737     for(j=0; j<N-1; j++)
    3738     {
    3739       for(i=j+1; i<N; i++)
    3740       {
    3741         m_ppdAlfCorr[i][j] = m_ppdAlfCorr[j][i];
    3742       }
    3743     }
    3744   }
    3745 }
    3746 
    3747 #endif
    37483033#if IBDI_DISTORTION
    37493034#if HHI_INTERVIEW_SKIP
     
    39463231  Int    *nc;
    39473232  const Int    *pFiltMag;
    3948 #if LCU_SYNTAX_ALF && LCUALF_QP_DEPENDENT_BITS
     3233#if LCUALF_QP_DEPENDENT_BITS
    39493234  Int alfPrecisionBit = getAlfPrecisionBit( m_alfQP );
    39503235#endif
    39513236
    39523237  N = m_sqrFiltLengthTab[tap];
    3953 #if ALF_SINGLE_FILTER_SHAPE
    39543238  pFiltMag = weightsShape1Sym;
    3955 #else
    3956   // star shape
    3957   if(tap == 0)
    3958   {
    3959     pFiltMag = weightsShape0Sym;
    3960   }
    3961   // cross shape
    3962   else
    3963   {
    3964     pFiltMag = weightsShape1Sym;
    3965   }
    3966 #endif
    39673239
    39683240  dh = new Double[N];
    39693241  nc = new Int[N];
    39703242 
    3971 #if LCU_SYNTAX_ALF && LCUALF_QP_DEPENDENT_BITS 
     3243#if LCUALF_QP_DEPENDENT_BITS 
    39723244  max_value =   (1<<(1+alfPrecisionBit))-1;
    39733245  min_value = 0-(1<<(1+alfPrecisionBit));
     
    39833255    if(h[i]>=0.0)
    39843256    {
    3985 #if LCU_SYNTAX_ALF && LCUALF_QP_DEPENDENT_BITS
     3257#if LCUALF_QP_DEPENDENT_BITS
    39863258      qh[i] =  (Int)( h[i]*(1<<alfPrecisionBit)+0.5);
    39873259#else
     
    39913263    else
    39923264    {
    3993 #if LCU_SYNTAX_ALF && LCUALF_QP_DEPENDENT_BITS
     3265#if LCUALF_QP_DEPENDENT_BITS
    39943266      qh[i] = -(Int)(-h[i]*(1<<alfPrecisionBit)+0.5);
    39953267#else
     
    39983270    }
    39993271
    4000 #if LCU_SYNTAX_ALF && LCUALF_QP_DEPENDENT_BITS
     3272#if LCUALF_QP_DEPENDENT_BITS
    40013273    dh[i] = (Double)qh[i]/(Double)(1<<alfPrecisionBit) - h[i];
    40023274#else
     
    40103282 
    40113283  // modification of quantized filter coefficients
    4012 #if LCU_SYNTAX_ALF && LCUALF_QP_DEPENDENT_BITS
     3284#if LCUALF_QP_DEPENDENT_BITS
    40133285  total_gain = (Int)(dbl_total_gain*(1<<alfPrecisionBit)+0.5);
    40143286#else
     
    40823354  nc = NULL;
    40833355}
    4084 #if !LCU_SYNTAX_ALF
    4085 Void TEncAdaptiveLoopFilter::xClearFilterCoefInt(Int* qh, Int N)
    4086 {
    4087   // clear
    4088   memset( qh, 0, sizeof( Int ) * N );
    4089  
    4090   // center pos
    4091   qh[N-1]  = 1<<ALF_NUM_BIT_SHIFT;
    4092 }
    4093 /** Calculate RD cost
    4094  * \param [in] pAlfParam ALF parameters
    4095  * \param [out] ruiRate coding bits
    4096  * \param [in] uiDist distortion
    4097  * \param [out] rdCost rate-distortion cost
    4098  * \param [in] pvAlfCUCtrlParam ALF CU control parameters
    4099  */
    4100 Void TEncAdaptiveLoopFilter::xCalcRDCost(ALFParam* pAlfParam, UInt64& ruiRate, UInt64 uiDist, Double& rdCost, std::vector<AlfCUCtrlInfo>* pvAlfCUCtrlParam)
    4101 {
    4102   if(pAlfParam != NULL)
    4103   {
    4104     m_pcEntropyCoder->resetEntropy();
    4105     m_pcEntropyCoder->resetBits();
    4106     m_pcEntropyCoder->encodeAlfParam(pAlfParam);
    4107 
    4108     ruiRate = m_pcEntropyCoder->getNumberOfWrittenBits();
    4109 
    4110     if(pvAlfCUCtrlParam != NULL)
    4111     {
    4112       for(UInt s=0; s< m_uiNumSlicesInPic; s++)
    4113       {
    4114         if(!m_pcPic->getValidSlice(s))
    4115         {
    4116           continue;
    4117         }
    4118         m_pcEntropyCoder->resetEntropy();
    4119         m_pcEntropyCoder->resetBits();
    4120         m_pcEntropyCoder->encodeAlfCtrlParam( (*pvAlfCUCtrlParam)[s], m_uiNumCUsInFrame);
    4121         ruiRate += m_pcEntropyCoder->getNumberOfWrittenBits();
    4122       }
    4123     }
    4124     else
    4125     {
    4126       ruiRate += m_uiNumSlicesInPic;
    4127     }
    4128   }
    4129   else
    4130   {
    4131     ruiRate = 1;
    4132   }
    4133  
    4134   rdCost      = (Double)(ruiRate) * m_dLambdaLuma + (Double)(uiDist);
    4135 }
    4136 
    4137 /** Calculate RD cost
    4138  * \param [in] pcPicOrg original picture buffer
    4139  * \param [in] pcPicCmp compared picture buffer
    4140  * \param [in] pAlfParam ALF parameters
    4141  * \param [out] ruiRate coding bits
    4142  * \param [out] ruiDist distortion
    4143  * \param [out] rdCost rate-distortion cost
    4144  * \param [in] pvAlfCUCtrlParam ALF CU control parameters
    4145  */
    4146 #if HHI_INTERVIEW_SKIP
    4147 Void TEncAdaptiveLoopFilter::xCalcRDCost(TComPicYuv* pcPicOrg, TComPicYuv* pcPicCmp, TComPicYuv* pcUsedPelMap, ALFParam* pAlfParam, UInt64& ruiRate, UInt64& ruiDist, Double& rdCost, std::vector<AlfCUCtrlInfo>* pvAlfCUCtrlParam)
    4148 #else
    4149 Void TEncAdaptiveLoopFilter::xCalcRDCost(TComPicYuv* pcPicOrg, TComPicYuv* pcPicCmp, ALFParam* pAlfParam, UInt64& ruiRate, UInt64& ruiDist, Double& rdCost, std::vector<AlfCUCtrlInfo>* pvAlfCUCtrlParam)
    4150 #endif
    4151 {
    4152   if(pAlfParam != NULL)
    4153   {
    4154     m_pcEntropyCoder->resetEntropy();
    4155     m_pcEntropyCoder->resetBits();
    4156     m_pcEntropyCoder->encodeAlfParam(pAlfParam);
    4157    
    4158     ruiRate = m_pcEntropyCoder->getNumberOfWrittenBits();
    4159 
    4160     if(pvAlfCUCtrlParam != NULL)
    4161     {
    4162       for(UInt s=0; s< m_uiNumSlicesInPic; s++)
    4163       {
    4164         if(! m_pcPic->getValidSlice(s))
    4165         {
    4166           continue;
    4167         }
    4168         m_pcEntropyCoder->resetEntropy();
    4169         m_pcEntropyCoder->resetBits();
    4170         m_pcEntropyCoder->encodeAlfCtrlParam( (*pvAlfCUCtrlParam)[s], m_uiNumCUsInFrame);
    4171         ruiRate += m_pcEntropyCoder->getNumberOfWrittenBits();
    4172       }
    4173 
    4174     }
    4175     else
    4176     {
    4177       ruiRate += m_uiNumSlicesInPic;
    4178     }
    4179   }
    4180   else
    4181   {
    4182     ruiRate = 1;
    4183   }
    4184  
    4185   ruiDist     = xCalcSSD(pcPicOrg->getLumaAddr(), pcPicCmp->getLumaAddr(), pcPicOrg->getWidth(), pcPicOrg->getHeight(), pcPicOrg->getStride());
    4186   rdCost      = (Double)(ruiRate) * m_dLambdaLuma + (Double)(ruiDist);
    4187 }
    4188 /** Calculate RD cost for chroma ALF
    4189  * \param pcPicOrg original picture buffer
    4190  * \param pcPicCmp compared picture buffer
    4191  * \param pAlfParam ALF parameters
    4192  * \returns ruiRate bitrate
    4193  * \returns uiDist distortion
    4194  * \returns rdCost RD cost
    4195  */
    4196 Void TEncAdaptiveLoopFilter::xCalcRDCostChroma(TComPicYuv* pcPicOrg, TComPicYuv* pcPicCmp, ALFParam* pAlfParam, UInt64& ruiRate, UInt64& ruiDist, Double& rdCost)
    4197 {
    4198   if(pAlfParam->chroma_idc)
    4199   {
    4200     ruiRate = xCalcRateChroma(pAlfParam);
    4201   }
    4202   ruiDist = 0;
    4203   ruiDist += xCalcSSD(pcPicOrg->getCbAddr(), pcPicCmp->getCbAddr(), (pcPicOrg->getWidth()>>1), (pcPicOrg->getHeight()>>1), pcPicOrg->getCStride());
    4204   ruiDist += xCalcSSD(pcPicOrg->getCrAddr(), pcPicCmp->getCrAddr(), (pcPicOrg->getWidth()>>1), (pcPicOrg->getHeight()>>1), pcPicOrg->getCStride());
    4205   rdCost  = (Double)(ruiRate) * m_dLambdaChroma + (Double)(ruiDist);
    4206 }
    4207 
    4208 Void TEncAdaptiveLoopFilter::xFilteringFrameChroma(ALFParam* pcAlfParam, TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest)
    4209 {
    4210   Int filtNo = pcAlfParam->filter_shape_chroma;
    4211   Int *coeff = pcAlfParam->coeff_chroma;
    4212   Int iChromaFormatShift = 1; //4:2:0
    4213 
    4214   if ((pcAlfParam->chroma_idc>>1)&0x01)
    4215   {
    4216     if(!m_bUseNonCrossALF)
    4217     {
    4218       Int iStride   = pcPicRest->getCStride();
    4219       Pel* pDec  = pcPicDec->getCbAddr();
    4220       Pel* pRest = pcPicRest->getCbAddr();
    4221 
    4222       filterChroma(pRest, pDec, iStride, 0, (Int)(m_img_height>>1) -1, 0, (Int)(m_img_width>>1)-1, filtNo,  coeff);
    4223     }
    4224     else
    4225     {
    4226       xFilterChromaSlices(ALF_Cb, pcPicDec, pcPicRest, coeff, filtNo, iChromaFormatShift);
    4227     }
    4228   }
    4229   if ((pcAlfParam->chroma_idc)&0x01)
    4230   {
    4231     if(!m_bUseNonCrossALF)
    4232     {
    4233       Int iStride   = pcPicRest->getCStride();
    4234       Pel* pDec  = pcPicDec->getCrAddr();
    4235       Pel* pRest = pcPicRest->getCrAddr();
    4236 
    4237       filterChroma(pRest, pDec, iStride, 0, (Int)(m_img_height>>1) -1, 0, (Int)(m_img_width>>1)-1, filtNo,  coeff);
    4238     }
    4239     else
    4240     {
    4241       xFilterChromaSlices(ALF_Cr, pcPicDec, pcPicRest, coeff, filtNo, iChromaFormatShift);
    4242     }
    4243   }
    4244 
    4245   if(pcAlfParam->chroma_idc<3)
    4246   {
    4247     if(pcAlfParam->chroma_idc==1)
    4248     {
    4249       pcPicDec->copyToPicCb(pcPicRest);
    4250     }
    4251     if(pcAlfParam->chroma_idc==2)
    4252     {
    4253       pcPicDec->copyToPicCr(pcPicRest);
    4254     }
    4255   }
    4256 
    4257 }
    4258 #endif
    4259 #if LCU_SYNTAX_ALF
    42603356/** Restore the not-filtered pixels
    42613357 * \param [in] imgDec picture buffer before filtering
     
    42643360 */
    42653361Void TEncAdaptiveLoopFilter::xCopyDecToRestCUs(Pel* imgDec, Pel* imgRest, Int stride)
    4266 #else
    4267 /** Restore the not-filtered pixels
    4268  * \param pcPicDec picture buffer before filtering
    4269  * \param pcPicRest picture buffer after filtering
    4270  */
    4271 Void TEncAdaptiveLoopFilter::xCopyDecToRestCUs(TComPicYuv* pcPicDec, TComPicYuv* pcPicRest)
    4272 #endif
    42733362{
    42743363
    42753364  if(m_uiNumSlicesInPic > 1)
    42763365  {
    4277 #if LCU_SYNTAX_ALF
    42783366    Pel* pPicDecLuma  = imgDec;
    42793367    Pel* pPicRestLuma = imgRest;
    4280 #else
    4281     Pel* pPicDecLuma  = pcPicDec->getLumaAddr();
    4282     Pel* pPicRestLuma = pcPicRest->getLumaAddr();
    4283     Int  stride       = pcPicDec->getStride();
    4284 #endif
    42853368    UInt SUWidth      = m_pcPic->getMinCUWidth();
    42863369    UInt SUHeight     = m_pcPic->getMinCUHeight();
     
    43353418  {
    43363419    TComDataCU* pcCU = m_pcPic->getCU( uiCUAddr );
    4337 #if LCU_SYNTAX_ALF
    43383420    xCopyDecToRestCU(pcCU, 0, 0, imgDec, imgRest, stride);
    4339 #else
    4340     xCopyDecToRestCU(pcCU, 0, 0, pcPicDec, pcPicRest);
    4341 #endif
    4342   }
    4343 }
    4344 
    4345 #if LCU_SYNTAX_ALF
     3421  }
     3422}
     3423
    43463424Void TEncAdaptiveLoopFilter::xCopyDecToRestCU(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Pel* imgDec, Pel* imgRest, Int stride)
    4347 #else
    4348 Void TEncAdaptiveLoopFilter::xCopyDecToRestCU(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest)
    4349 #endif
    43503425{
    43513426  Bool bBoundary = false;
     
    43693444     
    43703445      if( ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )     
    4371 #if LCU_SYNTAX_ALF
    43723446        xCopyDecToRestCU(pcCU, uiAbsPartIdx, uiDepth+1, imgDec, imgRest, stride);
    4373 #else
    4374         xCopyDecToRestCU(pcCU, uiAbsPartIdx, uiDepth+1, pcPicDec, pcPicRest);
    4375 #endif
    43763447    }
    43773448    return;
     
    43803451  if (!pcCU->getAlfCtrlFlag(uiAbsPartIdx))
    43813452  {
    4382 #if !LCU_SYNTAX_ALF
    4383     UInt uiCUAddr = pcCU->getAddr();
    4384 #endif   
    43853453    Int iWidth = pcCU->getWidth(uiAbsPartIdx);
    43863454    Int iHeight = pcCU->getHeight(uiAbsPartIdx);
    4387 #if LCU_SYNTAX_ALF
    43883455    copyPixelsInOneRegion(imgRest, imgDec, stride, (Int)uiTPelY, iHeight, (Int)uiLPelX, iWidth);
    4389 #else
    4390     Pel* pRec = pcPicDec->getLumaAddr(uiCUAddr, uiAbsPartIdx);
    4391     Pel* pFilt = pcPicRest->getLumaAddr(uiCUAddr, uiAbsPartIdx);
    4392    
    4393     Int iRecStride = pcPicDec->getStride();
    4394     Int iFiltStride = pcPicRest->getStride();
    4395    
    4396     for (Int y = 0; y < iHeight; y++)
    4397     {
    4398       for (Int x = 0; x < iWidth; x++)
    4399       {
    4400         pFilt[x] = pRec[x];
    4401       }
    4402       pRec += iRecStride;
    4403       pFilt += iFiltStride;
    4404     }
    4405 #endif
    44063456  }
    44073457}
     
    44263476Void TEncAdaptiveLoopFilter::predictALFCoeffLumaEnc(ALFParam* pcAlfParam, Int **pfilterCoeffSym, Int filter_shape)
    44273477{
    4428 #if LCU_SYNTAX_ALF && LCUALF_QP_DEPENDENT_BITS
     3478#if LCUALF_QP_DEPENDENT_BITS
    44293479  Int alfPrecisionBit = getAlfPrecisionBit( m_alfQP );
    44303480#endif
     
    44423492    if((pcAlfParam->predMethod==0)|(ind==0))
    44433493    {
    4444 #if LCU_SYNTAX_ALF && LCUALF_QP_DEPENDENT_BITS
     3494#if LCUALF_QP_DEPENDENT_BITS
    44453495      coeffPred = ((1<<alfPrecisionBit)-sum) >> 2;
    44463496#else
     
    44653515    if((pcAlfParam->predMethod==0)|(ind==0))
    44663516    {
    4467 #if LCU_SYNTAX_ALF && LCUALF_QP_DEPENDENT_BITS
     3517#if LCUALF_QP_DEPENDENT_BITS
    44683518      coeffPred = (1<<alfPrecisionBit)-sum;
    44693519#else
     
    46003650    *pDepthInt=NULL, kMinTab[MAX_SCAN_VAL], bitsCoeffScan[MAX_SCAN_VAL][MAX_EXP_GOLOMB],
    46013651  minKStart, minBitsKStart, bitsKStart;
    4602 #if ALF_SINGLE_FILTER_SHAPE
    46033652  Int minScanVal = MIN_SCAN_POS_CROSS;
    4604 #else 
    4605   int minScanVal = (fl==ALF_STAR5x5) ? 0 : MIN_SCAN_POS_CROSS;
    4606 #endif
    46073653  pDepthInt = pDepthIntTabShapes[fl];
    46083654 
     
    46723718  // Coding parameters
    46733719  //  len += lengthFilterCodingParams(minKStart, maxScanVal, kMinTab, createBitstream);
    4674 #if LCU_SYNTAX_ALF
    46753720  if (filters_per_group == 1)
    46763721  {
     
    46803725  else
    46813726  {
    4682 #endif
    46833727  len += (3 + maxScanVal);
    46843728 
     
    46863730  len += lengthFilterCoeffs(sqrFiltLength, filters_per_group, pDepthInt, pDiffQFilterCoeffIntPP,
    46873731                            kMinTab, createBitstream);
    4688 #if LCU_SYNTAX_ALF
    4689   }
    4690 #endif
     3732  }
    46913733
    46923734  return len;
     
    47353777    {
    47363778      scanPos = pDepthInt[i] - 1;
    4737 #if LCU_SYNTAX_ALF
    47383779      Int k = (filters_per_group == 1) ? kMinTab[i] : kMinTab[scanPos];
    47393780      bit_cnt += lengthGolomb(abs(FilterCoeff[ind][i]), k);
    4740 #else
    4741       bit_cnt += lengthGolomb(abs(FilterCoeff[ind][i]), kMinTab[scanPos]);
    4742 #endif
    47433781    }
    47443782  }
     
    47463784}
    47473785
    4748 #if !LCU_SYNTAX_ALF
    4749 
    4750 Void   TEncAdaptiveLoopFilter::xEncALFLuma ( TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiMinRate, UInt64& ruiMinDist, Double& rdMinCost )
    4751 {
    4752   //pcPicDec: extended decoded
    4753   //pcPicRest: original decoded: filtered signal will be stored
    4754 
    4755   UInt64  uiRate;
    4756   UInt64  uiDist;
    4757   Double dCost;
    4758   Int    LumaStride = pcPicOrg->getStride();
    4759   Pel* pOrg  = pcPicOrg->getLumaAddr();
    4760   Pel* pRest = pcPicRest->getLumaAddr();
    4761   Pel* pDec  = pcPicDec->getLumaAddr();
    4762 
    4763   Double    dMinMethodCost  = MAX_DOUBLE;
    4764   UInt64    uiMinMethodDist = MAX_UINT;
    4765   UInt64    uiMinMethodRate = MAX_UINT;
    4766   Int       iBestClassMethod = ALF_RA;
    4767   Double    adExtraCostReduction[NUM_ALF_CLASS_METHOD];
    4768   ALFParam  cFrmAlfParam        [NUM_ALF_CLASS_METHOD];
    4769   ALFParam* pcAlfParam = NULL;
    4770 
    4771   for(Int i=0; i< NUM_ALF_CLASS_METHOD; i++)
    4772   {
    4773     pcAlfParam = &(cFrmAlfParam[i]);
    4774     allocALFParam(pcAlfParam);
    4775 
    4776     pcAlfParam->alf_flag        = 1;
    4777     pcAlfParam->chroma_idc      = 0;
    4778 
    4779     switch(i)
    4780     {
    4781     case ALF_RA:
    4782       {
    4783         adExtraCostReduction[i] = (double)(m_img_height * m_img_width) * m_dLambdaLuma * 2.0 / 4096.0;
    4784       }
    4785       break;
    4786     case ALF_BA:
    4787       {
    4788         adExtraCostReduction[i] = 0.0;
    4789       }
    4790       break;
    4791     default:
    4792       {
    4793         printf("Not a support adaptation method\n");
    4794         assert(0);
    4795         exit(-1);
    4796       }
    4797     }
    4798   }
    4799 
    4800 
    4801   for(Int i=0; i< NUM_ALF_CLASS_METHOD; i++)
    4802   {
    4803     m_uiVarGenMethod = i;
    4804 
    4805     pcAlfParam       = &(cFrmAlfParam[m_uiVarGenMethod]);
    4806     m_varImg         = m_varImgMethods[m_uiVarGenMethod];
    4807 
    4808     pcAlfParam->alf_pcr_region_flag = m_uiVarGenMethod;
    4809 
    4810     setInitialMask(pcPicOrg, pcPicDec);
    4811 
    4812     if(m_iALFEncodePassReduction == 0)
    4813     {
    4814       static Int best_filter_shape = 0;
    4815       if (m_uiVarGenMethod == 0)
    4816       {
    4817         UInt64 MinRate_Shape0 = MAX_INT;
    4818         UInt64 MinDist_Shape0 = MAX_INT;
    4819         Double MinCost_Shape0 = MAX_DOUBLE;
    4820 
    4821         UInt64 MinRate_Shape1 = MAX_INT;
    4822         UInt64 MinDist_Shape1 = MAX_INT;
    4823         Double MinCost_Shape1 = MAX_DOUBLE;
    4824 
    4825 #if ALF_SINGLE_FILTER_SHAPE
    4826         Int filter_shape = 0;
    4827 #else       
    4828         for (Int filter_shape = 0; filter_shape < 2 ;filter_shape ++)
    4829 #endif
    4830         {
    4831           pcAlfParam->filter_shape = filter_shape;
    4832           pcAlfParam->num_coeff = m_pcTempAlfParam->num_coeff = m_sqrFiltLengthTab[filter_shape];
    4833           xFirstFilteringFrameLuma(pOrg, pDec, m_pcPicYuvTmp->getLumaAddr(), pcAlfParam, pcAlfParam->filter_shape, LumaStride);
    4834           xCalcRDCost(pcPicOrg, m_pcPicYuvTmp, pcAlfParam, uiRate, uiDist, dCost);
    4835           if (filter_shape == 0)
    4836           {
    4837             // copy Shape0
    4838             MinRate_Shape0 = uiRate;
    4839             MinDist_Shape0 = uiDist;
    4840             MinCost_Shape0 = dCost;
    4841             m_pcPicYuvTmp->copyToPicLuma(pcPicYuvRecShape0);
    4842             copyALFParam(pcAlfParamShape0, pcAlfParam);
    4843           }
    4844           else //if (filter_shape == 1)
    4845           {
    4846             // copy Shape1
    4847             MinRate_Shape1 = uiRate;
    4848             MinDist_Shape1 = uiDist;
    4849             MinCost_Shape1  = dCost;
    4850             m_pcPicYuvTmp->copyToPicLuma(pcPicYuvRecShape1);
    4851             copyALFParam(pcAlfParamShape1, pcAlfParam);
    4852           }
    4853         }
    4854 
    4855         if (MinCost_Shape0 <= MinCost_Shape1)
    4856         {
    4857           pcPicYuvRecShape0->copyToPicLuma(m_pcPicYuvTmp);
    4858           copyALFParam(pcAlfParam, pcAlfParamShape0);
    4859           uiRate = MinRate_Shape0;
    4860           uiDist = MinDist_Shape0;
    4861           dCost = MinCost_Shape0;
    4862           best_filter_shape = 0;
    4863         }
    4864         else //if (MinCost_Shape1 < MinCost_Shape0)
    4865         {
    4866           pcPicYuvRecShape1->copyToPicLuma(m_pcPicYuvTmp);
    4867           copyALFParam(pcAlfParam, pcAlfParamShape1);
    4868           uiRate = MinRate_Shape1;
    4869           uiDist = MinDist_Shape1;
    4870           dCost = MinCost_Shape1;
    4871           best_filter_shape = 1;
    4872         }
    4873       }
    4874       else
    4875       {
    4876         pcAlfParam->filter_shape = best_filter_shape;
    4877         pcAlfParam->num_coeff = m_pcTempAlfParam->num_coeff = m_sqrFiltLengthTab[best_filter_shape];
    4878         xFirstFilteringFrameLuma(pOrg, pDec, m_pcPicYuvTmp->getLumaAddr(), pcAlfParam, best_filter_shape, LumaStride);
    4879         xCalcRDCost(pcPicOrg, m_pcPicYuvTmp, pcAlfParam, uiRate, uiDist, dCost);
    4880       }
    4881     }
    4882     else
    4883     {
    4884       decideFilterShapeLuma(pOrg, pDec, LumaStride, pcAlfParam, uiRate, uiDist, dCost);
    4885     }
    4886 
    4887     dCost -= adExtraCostReduction[m_uiVarGenMethod];
    4888 
    4889     if(dCost < dMinMethodCost)
    4890     {
    4891       iBestClassMethod = m_uiVarGenMethod;
    4892       dMinMethodCost = dCost;
    4893       uiMinMethodRate= uiRate;
    4894       uiMinMethodDist = uiDist;
    4895 
    4896       if(m_iALFEncodePassReduction == 0)
    4897       {
    4898         m_pcPicYuvTmp->copyToPicLuma(pcPicRest);
    4899       }
    4900     } 
    4901   }
    4902 
    4903   m_uiVarGenMethod = iBestClassMethod;
    4904   dMinMethodCost += adExtraCostReduction[m_uiVarGenMethod];
    4905   m_varImg= m_varImgMethods[m_uiVarGenMethod];
    4906 
    4907   pcAlfParam = &(cFrmAlfParam[m_uiVarGenMethod]);
    4908 
    4909   ALFParam  cAlfParamWithBestMethod;
    4910   allocALFParam(&cAlfParamWithBestMethod); 
    4911 
    4912 
    4913   if(m_iALFEncodePassReduction ==0)
    4914   {
    4915     copyALFParam(&cAlfParamWithBestMethod, pcAlfParam);
    4916   }
    4917   else
    4918   {
    4919     cAlfParamWithBestMethod.alf_flag = 1;
    4920     cAlfParamWithBestMethod.chroma_idc = 0;
    4921     cAlfParamWithBestMethod.alf_pcr_region_flag = m_uiVarGenMethod;
    4922     cAlfParamWithBestMethod.filter_shape= pcAlfParam->filter_shape;
    4923     cAlfParamWithBestMethod.num_coeff = m_sqrFiltLengthTab[cAlfParamWithBestMethod.filter_shape];
    4924     decodeFilterSet(pcAlfParam, m_varIndTab, m_filterCoeffSym);
    4925     if(!m_bUseNonCrossALF)
    4926     {
    4927       filterLuma(pRest, pDec, LumaStride, 0, m_img_height-1, 0, m_img_width-1,  pcAlfParam->filter_shape, m_filterCoeffSym, m_varIndTab, m_varImg);
    4928     }
    4929     else
    4930     {
    4931       xfilterSlicesEncoder(pDec, pRest, LumaStride, pcAlfParam->filter_shape, m_filterCoeffSym, m_varIndTab, m_varImg);
    4932     }
    4933     xcodeFiltCoeff(m_filterCoeffSym, pcAlfParam->filter_shape, m_varIndTab, pcAlfParam->filters_per_group,&cAlfParamWithBestMethod);
    4934 
    4935     xCalcRDCost(pcPicOrg, pcPicRest, &cAlfParamWithBestMethod, uiMinMethodRate, uiMinMethodDist, dMinMethodCost);
    4936 
    4937   }
    4938 
    4939   if(dMinMethodCost < rdMinCost )
    4940   {
    4941     ruiMinRate = uiMinMethodRate;
    4942     ruiMinDist = uiMinMethodDist;
    4943     rdMinCost =  dMinMethodCost;
    4944     copyALFParam(m_pcBestAlfParam, &cAlfParamWithBestMethod);
    4945   }
    4946 
    4947   freeALFParam(&cAlfParamWithBestMethod);
    4948   for(Int i=0; i< NUM_ALF_CLASS_METHOD; i++)
    4949   {
    4950     freeALFParam(&cFrmAlfParam[i]);
    4951   }
    4952 }
    4953 
    4954 
    4955 
    4956 Void   TEncAdaptiveLoopFilter::xFirstFilteringFrameLuma(Pel* imgOrg, Pel* imgDec, Pel* imgRest, ALFParam* ALFp, Int filtNo, Int stride)
    4957 {
    4958   if(!m_bUseNonCrossALF)
    4959   {
    4960     xstoreInBlockMatrix(0, 0, m_img_height, m_img_width, true, true, imgOrg, imgDec, filtNo, stride);
    4961   }
    4962   else
    4963   {
    4964     xstoreInBlockMatrixforSlices(imgOrg, imgDec, filtNo, stride);
    4965   }
    4966 
    4967 
    4968   xFilteringFrameLuma(imgOrg, imgDec, imgRest, ALFp, filtNo, stride);
    4969 }
    4970 
    4971 Void   TEncAdaptiveLoopFilter::xstoreInBlockMatrix(Int ypos, Int xpos, Int iheight, Int iwidth, Bool bResetBlockMatrix, Bool bSymmCopyBlockMatrix, Pel* pImgOrg, Pel* pImgPad, Int filtNo, Int stride)
    4972 {
    4973 
    4974   Pel  regionOfInterested = (m_iDesignCurrentFilter ==1)?(1):(0);
    4975   Int     sqrFiltLength      = (filtNo == 2)?((Int)(MAX_SQR_FILT_LENGTH)):(m_sqrFiltLengthTab[filtNo]);
    4976   Int     yposEnd            = ypos + iheight -1;
    4977   Int     xposEnd            = xpos + iwidth  -1;
    4978   Double ***EShape           = m_EGlobalSym[filtNo];
    4979   Double **yShape            = m_yGlobalSym[filtNo];
    4980 
    4981   Int ELocal[MAX_SQR_FILT_LENGTH];
    4982   Pel *pImgPad1, *pImgPad2, *pImgPad3, *pImgPad4;
    4983   Int i,j,k,l,varInd, yLocal;
    4984   double **E,*yy;
    4985 
    4986   static Int numValidPels;
    4987   if(bResetBlockMatrix)
    4988   {
    4989     numValidPels = 0;
    4990     memset( m_pixAcc, 0,sizeof(double)*NO_VAR_BINS);
    4991     for (varInd=0; varInd<NO_VAR_BINS; varInd++)
    4992     {
    4993       memset(yShape[varInd],0,sizeof(double)*MAX_SQR_FILT_LENGTH);
    4994       for (k=0; k<sqrFiltLength; k++)
    4995       {
    4996         memset(EShape[varInd][k],0,sizeof(double)*MAX_SQR_FILT_LENGTH);
    4997       }
    4998     }
    4999     for (i = 0; i < m_img_height; i++)
    5000     {
    5001       for (j = 0; j < m_img_width; j++)
    5002       {
    5003         if (m_maskImg[i][j] == regionOfInterested)
    5004         {
    5005           numValidPels++;
    5006         }
    5007       }
    5008     }
    5009   }
    5010 
    5011   Int yLineInLCU;
    5012   Int paddingLine ;
    5013 
    5014   pImgPad += (ypos* stride);
    5015   pImgOrg += (ypos* stride);
    5016 
    5017   switch(filtNo)
    5018   {
    5019 #if !ALF_SINGLE_FILTER_SHAPE
    5020   case ALF_STAR5x5:
    5021     {
    5022       for (i= ypos; i<= yposEnd; i++)
    5023       {
    5024         yLineInLCU = i % m_lcuHeight;
    5025 
    5026         if (yLineInLCU < m_lineIdxPadBot || i-yLineInLCU+m_lcuHeight >= m_img_height )
    5027         {
    5028           pImgPad1 = pImgPad +   stride;
    5029           pImgPad2 = pImgPad -   stride;
    5030           pImgPad3 = pImgPad + 2*stride;
    5031           pImgPad4 = pImgPad - 2*stride;
    5032         }
    5033         else if (yLineInLCU < m_lineIdxPadTop)
    5034         {
    5035           paddingLine = - yLineInLCU + m_lineIdxPadTop - 1;
    5036           pImgPad1 = pImgPad + min(paddingLine, 1)*stride;
    5037           pImgPad2 = pImgPad -   stride;
    5038           pImgPad3 = pImgPad + min(paddingLine, 2)*stride;
    5039           pImgPad4 = pImgPad - 2*stride;
    5040         }
    5041         else
    5042         {
    5043           paddingLine = yLineInLCU - m_lineIdxPadTop;
    5044           pImgPad1 = pImgPad +   stride;
    5045           pImgPad2 = pImgPad - min(paddingLine, 1)*stride;
    5046           pImgPad3 = pImgPad + 2*stride;
    5047           pImgPad4 = pImgPad - min(paddingLine, 2)*stride;
    5048         }
    5049 
    5050         if ( (yLineInLCU == m_lineIdxPadTop || yLineInLCU == m_lineIdxPadTop-1) && i-yLineInLCU+m_lcuHeight < m_img_height )
    5051         {
    5052           pImgPad+= stride;
    5053           pImgOrg+= stride;
    5054           continue;
    5055         }
    5056         else
    5057         {
    5058         for (j= xpos; j<= xposEnd; j++)
    5059         {
    5060           if ( (m_maskImg[i][j] == regionOfInterested) || (numValidPels == 0) )
    5061           {
    5062             varInd = m_varImg[i/VAR_SIZE_H][j/VAR_SIZE_W];
    5063             memset(ELocal, 0, 10*sizeof(Int));
    5064 
    5065             ELocal[0] = (pImgPad3[j+2] + pImgPad4[j-2]);
    5066             ELocal[1] = (pImgPad3[j  ] + pImgPad4[j  ]);
    5067             ELocal[2] = (pImgPad3[j-2] + pImgPad4[j+2]);
    5068 
    5069             ELocal[3] = (pImgPad1[j+1] + pImgPad2[j-1]);
    5070             ELocal[4] = (pImgPad1[j  ] + pImgPad2[j  ]);
    5071             ELocal[5] = (pImgPad1[j-1] + pImgPad2[j+1]);
    5072 
    5073             ELocal[6] = (pImgPad[j+2] + pImgPad[j-2]);
    5074             ELocal[7] = (pImgPad[j+1] + pImgPad[j-1]);
    5075             ELocal[8] = (pImgPad[j  ]);
    5076 
    5077             yLocal= pImgOrg[j];
    5078             m_pixAcc[varInd]+=(yLocal*yLocal);
    5079             E= EShape[varInd]; 
    5080             yy= yShape[varInd];
    5081 
    5082             for (k=0; k<10; k++)
    5083             {
    5084               for (l=k; l<10; l++)
    5085               {
    5086                 E[k][l]+=(double)(ELocal[k]*ELocal[l]);
    5087               }
    5088               yy[k]+=(double)(ELocal[k]*yLocal);
    5089             }
    5090 
    5091           }
    5092         }
    5093         pImgPad+= stride;
    5094         pImgOrg+= stride;
    5095         }
    5096       }
    5097     }
    5098     break;
    5099   case ALF_CROSS9x9:
    5100     {
    5101       Pel *pImgPad5, *pImgPad6, *pImgPad7, *pImgPad8;
    5102 #else
    5103   case ALF_CROSS9x7_SQUARE3x3:
    5104     {
    5105       Pel *pImgPad5, *pImgPad6;
    5106 #endif
    5107       for (i= ypos; i<= yposEnd; i++)
    5108       {
    5109         yLineInLCU = i % m_lcuHeight;
    5110 
    5111         if (yLineInLCU<m_lineIdxPadBot || i-yLineInLCU+m_lcuHeight >= m_img_height)
    5112         {
    5113           pImgPad1 = pImgPad +   stride;
    5114           pImgPad2 = pImgPad -   stride;
    5115           pImgPad3 = pImgPad + 2*stride;
    5116           pImgPad4 = pImgPad - 2*stride;
    5117           pImgPad5 = pImgPad + 3*stride;
    5118           pImgPad6 = pImgPad - 3*stride;
    5119 #if !ALF_SINGLE_FILTER_SHAPE
    5120           pImgPad7 = pImgPad + 4*stride;
    5121           pImgPad8 = pImgPad - 4*stride;
    5122 #endif
    5123         }
    5124         else if (yLineInLCU<m_lineIdxPadTop)
    5125         {
    5126           paddingLine = - yLineInLCU + m_lineIdxPadTop - 1;
    5127           pImgPad1 = (paddingLine < 1) ? pImgPad : pImgPad + min(paddingLine, 1)*stride;
    5128           pImgPad2 = (paddingLine < 1) ? pImgPad : pImgPad -   stride;
    5129           pImgPad3 = (paddingLine < 2) ? pImgPad : pImgPad + min(paddingLine, 2)*stride;
    5130           pImgPad4 = (paddingLine < 2) ? pImgPad : pImgPad - 2*stride;
    5131           pImgPad5 = (paddingLine < 3) ? pImgPad : pImgPad + min(paddingLine, 3)*stride;
    5132           pImgPad6 = (paddingLine < 3) ? pImgPad : pImgPad - 3*stride;
    5133 #if !ALF_SINGLE_FILTER_SHAPE
    5134           pImgPad7 = (paddingLine < 4) ? pImgPad : pImgPad + min(paddingLine, 4)*stride;
    5135           pImgPad8 = (paddingLine < 4) ? pImgPad : pImgPad - 4*stride;
    5136 #endif
    5137         }
    5138         else
    5139         {
    5140           paddingLine = yLineInLCU - m_lineIdxPadTop;
    5141           pImgPad1 = (paddingLine < 1) ? pImgPad : pImgPad +   stride;
    5142           pImgPad2 = (paddingLine < 1) ? pImgPad : pImgPad - min(paddingLine, 1)*stride;
    5143           pImgPad3 = (paddingLine < 2) ? pImgPad : pImgPad + 2*stride;
    5144           pImgPad4 = (paddingLine < 2) ? pImgPad : pImgPad - min(paddingLine, 2)*stride;
    5145           pImgPad5 = (paddingLine < 3) ? pImgPad : pImgPad + 3*stride;
    5146           pImgPad6 = (paddingLine < 3) ? pImgPad : pImgPad - min(paddingLine, 3)*stride;
    5147 #if !ALF_SINGLE_FILTER_SHAPE
    5148           pImgPad7 = (paddingLine < 4) ? pImgPad : pImgPad + 4*stride;
    5149           pImgPad8 = (paddingLine < 4) ? pImgPad : pImgPad - min(paddingLine, 4)*stride;
    5150 #endif
    5151         }         
    5152 
    5153         for (j= xpos; j<= xposEnd; j++)
    5154         {
    5155           if ( (m_maskImg[i][j] == regionOfInterested) || (numValidPels == 0) )
    5156           {
    5157             varInd = m_varImg[i/VAR_SIZE_H][j/VAR_SIZE_W];
    5158 
    5159 #if ALF_SINGLE_FILTER_SHAPE
    5160             memset(ELocal, 0, (sqrFiltLength+1)*sizeof(Int));
    5161 
    5162             ELocal[0] = (pImgPad5[j]+pImgPad6[j]);
    5163             ELocal[1] = (pImgPad3[j]+pImgPad4[j]);
    5164             ELocal[2] = (pImgPad1[j-1]+pImgPad2[j+1]);
    5165             ELocal[3] = (pImgPad1[j]+pImgPad2[j]);
    5166             ELocal[4] = (pImgPad1[j+1]+pImgPad2[j-1]);
    5167             ELocal[5] = (pImgPad[j+4]+pImgPad[j-4]);
    5168             ELocal[6] = (pImgPad[j+3]+pImgPad[j-3]);
    5169             ELocal[7] = (pImgPad[j+2]+pImgPad[j-2]);
    5170             ELocal[8] = (pImgPad[j+1]+pImgPad[j-1]);
    5171             ELocal[9] = (pImgPad[j  ]);
    5172 #else
    5173             memset(ELocal, 0, 10*sizeof(Int));
    5174 
    5175             ELocal[0] = (pImgPad7[j] + pImgPad8[j]);
    5176 
    5177             ELocal[1] = (pImgPad5[j] + pImgPad6[j]);
    5178 
    5179             ELocal[2] = (pImgPad3[j] + pImgPad4[j]);
    5180 
    5181             ELocal[3] = (pImgPad1[j] + pImgPad2[j]);
    5182 
    5183             ELocal[4] = (pImgPad[j+4] + pImgPad[j-4]);
    5184             ELocal[5] = (pImgPad[j+3] + pImgPad[j-3]);
    5185             ELocal[6] = (pImgPad[j+2] + pImgPad[j-2]);
    5186             ELocal[7] = (pImgPad[j+1] + pImgPad[j-1]);
    5187             ELocal[8] = (pImgPad[j  ] );
    5188 #endif
    5189             yLocal= pImgOrg[j];
    5190             m_pixAcc[varInd]+=(yLocal*yLocal);
    5191             E= EShape[varInd];
    5192             yy= yShape[varInd];
    5193 
    5194 #if ALF_SINGLE_FILTER_SHAPE
    5195             for (k=0; k<(sqrFiltLength+1); k++)
    5196             {
    5197               for (l=k; l<(sqrFiltLength+1); l++)
    5198               {
    5199                 E[k][l]+=(double)(ELocal[k]*ELocal[l]);
    5200               }
    5201               yy[k]+=(double)(ELocal[k]*yLocal);
    5202             }
    5203 #else
    5204             for (k=0; k<10; k++)
    5205             {
    5206               for (l=k; l<10; l++)
    5207               {
    5208                 E[k][l]+=(double)(ELocal[k]*ELocal[l]);
    5209               }
    5210               yy[k]+=(double)(ELocal[k]*yLocal);
    5211             }
    5212 #endif
    5213           }
    5214         }
    5215         pImgPad+= stride;
    5216         pImgOrg+= stride;
    5217       }
    5218 
    5219     }
    5220     break;
    5221   default:
    5222     {
    5223       printf("Not a supported filter shape\n");
    5224       assert(0);
    5225       exit(1);
    5226     }
    5227   }
    5228 
    5229   if(bSymmCopyBlockMatrix)
    5230   {
    5231     for (varInd=0; varInd<NO_VAR_BINS; varInd++)
    5232     {
    5233       double **pE = EShape[varInd];
    5234       for (k=1; k<sqrFiltLength; k++)
    5235       {
    5236         for (l=0; l<k; l++)
    5237         {
    5238           pE[k][l]=pE[l][k];
    5239         }
    5240       }
    5241     }
    5242   }
    5243 }
    5244 
    5245 
    5246 Void   TEncAdaptiveLoopFilter::xFilteringFrameLuma(Pel* imgOrg, Pel* imgPad, Pel* imgFilt, ALFParam* ALFp, Int filtNo, Int stride)
    5247 {
    5248   static double **ySym, ***ESym;
    5249   Int  filters_per_fr;
    5250   Int lambdaVal = (Int) m_dLambdaLuma;
    5251   lambdaVal = lambdaVal * (1<<(2*g_uiBitIncrement));
    5252 
    5253   ESym=m_EGlobalSym[filtNo]; 
    5254   ySym=m_yGlobalSym[filtNo];
    5255 
    5256   xfindBestFilterVarPred(ySym, ESym, m_pixAcc, m_filterCoeffSym, m_filterCoeffSymQuant, filtNo, &filters_per_fr,m_varIndTab, NULL, m_varImg, m_maskImg, NULL, lambdaVal);
    5257 
    5258   if(!m_bUseNonCrossALF)
    5259   {
    5260     filterLuma(imgFilt, imgPad, stride, 0, m_img_height-1, 0, m_img_width-1,  ALFp->filter_shape, m_filterCoeffSym, m_varIndTab, m_varImg);
    5261   }
    5262   else
    5263   {
    5264     xfilterSlicesEncoder(imgPad, imgFilt, stride, filtNo, m_filterCoeffSym, m_varIndTab, m_varImg);
    5265   }
    5266 
    5267   xcodeFiltCoeff(m_filterCoeffSymQuant, filtNo, m_varIndTab, filters_per_fr,ALFp);
    5268 }
    5269 #endif
    5270 
    5271 #if LCU_SYNTAX_ALF
     3786
    52723787Void TEncAdaptiveLoopFilter::xfindBestFilterVarPred(double **ySym, double ***ESym, double *pixAcc, Int **filterCoeffSym, Int **filterCoeffSymQuant, Int filter_shape, Int *filters_per_fr_best, Int varIndTab[], Pel **imgY_rec, Pel **varImg, Pel **maskImg, Pel **imgY_pad, double lambda_val, Int numMaxFilters)
    5273 #else
    5274 Void TEncAdaptiveLoopFilter::xfindBestFilterVarPred(double **ySym, double ***ESym, double *pixAcc, Int **filterCoeffSym, Int **filterCoeffSymQuant, Int filter_shape, Int *filters_per_fr_best, Int varIndTab[], Pel **imgY_rec, Pel **varImg, Pel **maskImg, Pel **imgY_pad, double lambda_val)
    5275 #endif
    52763788{
    52773789  Int filters_per_fr, firstFilt, interval[NO_VAR_BINS][2], intervalBest[NO_VAR_BINS][2];
     
    53053817
    53063818    lagrangian=xfindBestCoeffCodMethod(filterCoeffSymQuant, filter_shape, sqrFiltLength, filters_per_fr, errorForce0CoeffTab, lambda_val);
    5307 #if LCU_SYNTAX_ALF
    53083819    if (lagrangian<lagrangianMin || firstFilt==1 || filters_per_fr == numMaxFilters)
    5309 #else
    5310     if (lagrangian<lagrangianMin || firstFilt==1 || filters_per_fr == m_iALFMaxNumberFilters)
    5311 #endif
    53123820    {
    53133821      firstFilt=0;
     
    53193827    filters_per_fr--;
    53203828  }
    5321 #if !ALF_16_BA_GROUPS
    5322   if ( (m_uiVarGenMethod == ALF_BA) && ((*filters_per_fr_best) > 1) )
    5323   {
    5324     Int iLastFilter = (*filters_per_fr_best)-1;
    5325     if (intervalBest[iLastFilter][0] == NO_VAR_BINS-1)
    5326     {
    5327       intervalBest[iLastFilter-1][1] = NO_VAR_BINS-1;
    5328       (*filters_per_fr_best) = iLastFilter;
    5329     }
    5330   }
    5331 #endif
    53323829  findFilterCoeff(ESym, ySym, pixAcc, filterCoeffSym, filterCoeffSymQuant, intervalBest,
    53333830    varIndTab, sqrFiltLength, (*filters_per_fr_best), weights, errorForce0CoeffTab);
     
    54893986 * \param [in,out]vAlfCUCtrlParam ALF CU control parameters
    54903987 */
    5491 #if LCU_SYNTAX_ALF 
    54923988#if HHI_INTERVIEW_SKIP
    54933989Void TEncAdaptiveLoopFilter::setCUAlfCtrlFlags(UInt uiAlfCtrlDepth, Pel* imgOrg, Pel* imgDec, Pel* imgRest, Pel* imgUsed, Int stride, UInt64& ruiDist, std::vector<AlfCUCtrlInfo>& vAlfCUCtrlParam)
     
    54953991Void TEncAdaptiveLoopFilter::setCUAlfCtrlFlags(UInt uiAlfCtrlDepth, Pel* imgOrg, Pel* imgDec, Pel* imgRest, Int stride, UInt64& ruiDist, std::vector<AlfCUCtrlInfo>& vAlfCUCtrlParam)
    54963992#endif
    5497 #else
    5498 #if HHI_INTERVIEW_SKIP
    5499 Void TEncAdaptiveLoopFilter::xSetCUAlfCtrlFlags_qc(UInt uiAlfCtrlDepth, TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, TComPicYuv* pUsedPelMap, UInt64& ruiDist, std::vector<AlfCUCtrlInfo>& vAlfCUCtrlParam)
    5500 #else
    5501 Void TEncAdaptiveLoopFilter::xSetCUAlfCtrlFlags_qc(UInt uiAlfCtrlDepth, TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiDist, std::vector<AlfCUCtrlInfo>& vAlfCUCtrlParam)
    5502 #endif
    5503 #endif
    55043993{
    55053994  ruiDist = 0;
     
    55204009  {
    55214010    TComDataCU* pcCU = m_pcPic->getCU( CUAddr );
    5522 #if LCU_SYNTAX_ALF
    55234011#if HHI_INTERVIEW_SKIP
    55244012    setCUAlfCtrlFlag(pcCU, 0, 0, uiAlfCtrlDepth, imgOrg, imgDec, imgRest, imgUsed, stride, ruiDist, vAlfCUCtrlParam[0].alf_cu_flag);
    55254013#else
    55264014    setCUAlfCtrlFlag(pcCU, 0, 0, uiAlfCtrlDepth, imgOrg, imgDec, imgRest, stride, ruiDist, vAlfCUCtrlParam[0].alf_cu_flag);
    5527 #endif
    5528 #else
    5529 #if HHI_INTERVIEW_SKIP
    5530     xSetCUAlfCtrlFlag_qc(pcCU, 0, 0, uiAlfCtrlDepth, pcPicOrg, pcPicDec, pcPicRest,imgUsed, ruiDist, vAlfCUCtrlParam[0].alf_cu_flag);
    5531 #else
    5532     xSetCUAlfCtrlFlag_qc(pcCU, 0, 0, uiAlfCtrlDepth, pcPicOrg, pcPicDec, pcPicRest, ruiDist, vAlfCUCtrlParam[0].alf_cu_flag);
    5533 #endif
    55344015#endif
    55354016  }
     
    55694050}
    55704051
    5571 #if LCU_SYNTAX_ALF
    55724052#if HHI_INTERVIEW_SKIP
    55734053Void TEncAdaptiveLoopFilter::setCUAlfCtrlFlag(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiAlfCtrlDepth, Pel* imgOrg, Pel* imgDec, Pel* imgRest, Pel* imgUsed, Int stride, UInt64& ruiDist, std::vector<UInt>& vCUCtrlFlag)
    55744054#else
    55754055Void TEncAdaptiveLoopFilter::setCUAlfCtrlFlag(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiAlfCtrlDepth, Pel* imgOrg, Pel* imgDec, Pel* imgRest, Int stride, UInt64& ruiDist, std::vector<UInt>& vCUCtrlFlag)
    5576 #endif
    5577 #else
    5578 #if HHI_INTERVIEW_SKIP
    5579 Void TEncAdaptiveLoopFilter::xSetCUAlfCtrlFlag_qc(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiAlfCtrlDepth, TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, TComPicYuv* pcUsedPelMap, UInt64& ruiDist, std::vector<UInt>& vCUCtrlFlag)
    5580 #else
    5581 Void TEncAdaptiveLoopFilter::xSetCUAlfCtrlFlag_qc(TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiAlfCtrlDepth, TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiDist, std::vector<UInt>& vCUCtrlFlag)
    5582 #endif
    55834056#endif
    55844057{
     
    56034076     
    56044077      if( ( uiLPelX < pcCU->getSlice()->getSPS()->getPicWidthInLumaSamples() ) && ( uiTPelY < pcCU->getSlice()->getSPS()->getPicHeightInLumaSamples() ) )
    5605 #if LCU_SYNTAX_ALF
    56064078#if HHI_INTERVIEW_SKIP
    56074079        setCUAlfCtrlFlag(pcCU, uiAbsPartIdx, uiDepth+1, uiAlfCtrlDepth, imgOrg, imgDec, imgRest, imgUsed, stride, ruiDist, vCUCtrlFlag);
     
    56094081        setCUAlfCtrlFlag(pcCU, uiAbsPartIdx, uiDepth+1, uiAlfCtrlDepth, imgOrg, imgDec, imgRest, stride, ruiDist, vCUCtrlFlag);
    56104082#endif
    5611 #else
    5612 #if HHI_INTERVIEW_SKIP
    5613         xSetCUAlfCtrlFlag_qc(pcCU, uiAbsPartIdx, uiDepth+1, uiAlfCtrlDepth, pcPicOrg, pcPicDec, pcPicRest, imgUsed, ruiDist, vCUCtrlFlag);
    5614 #else
    5615         xSetCUAlfCtrlFlag_qc(pcCU, uiAbsPartIdx, uiDepth+1, uiAlfCtrlDepth, pcPicOrg, pcPicDec, pcPicRest, ruiDist, vCUCtrlFlag);
    5616 #endif
    5617 #endif
    56184083    }
    56194084    return;
     
    56244089    return;
    56254090  }
    5626 #if !LCU_SYNTAX_ALF
    5627   UInt uiCUAddr = pcCU->getAddr();
    5628 #endif
    56294091  UInt64 uiRecSSD = 0;
    56304092  UInt64 uiFiltSSD = 0;
     
    56614123  }
    56624124 
    5663 #if LCU_SYNTAX_ALF
    56644125  Int  offset = uiTPelY*stride + uiLPelX;
    56654126  Pel* pOrg  = imgOrg  + offset;
     
    56794140  uiFiltSSD += xCalcSSD( pOrg, pFilt, iWidth, iHeight, stride );
    56804141#endif
    5681 #else
    5682   Pel* pOrg = pcPicOrg->getLumaAddr(uiCUAddr, uiAbsPartIdx);
    5683   Pel* pRec = pcPicDec->getLumaAddr(uiCUAddr, uiAbsPartIdx);
    5684   Pel* pFilt = pcPicRest->getLumaAddr(uiCUAddr, uiAbsPartIdx);
    5685  
    5686 #if HHI_INTERVIEW_SKIP
    5687   Pel* pUsed = pcUsedPelMap->getLumaAddr(uiCUAddr, uiAbsPartIdx);
    5688   uiRecSSD  += xCalcSSD( pOrg, pRec, pUsed, iWidth, iHeight, pcPicOrg->getStride() );
    5689   uiFiltSSD += xCalcSSD( pOrg, pFilt, pUsed, iWidth, iHeight, pcPicOrg->getStride() );
    5690 #else
    5691   uiRecSSD  += xCalcSSD( pOrg, pRec,  iWidth, iHeight, pcPicOrg->getStride() );
    5692   uiFiltSSD += xCalcSSD( pOrg, pFilt, iWidth, iHeight, pcPicOrg->getStride() );
    5693 #endif
    5694 #endif
    56954142  if (uiFiltSSD < uiRecSSD)
    56964143  {
     
    56994146    vCUCtrlFlag.push_back(1);
    57004147
    5701 #if LCU_SYNTAX_ALF
    57024148    for (int i=uiTPelY ;i<=min(uiBPelY,(unsigned int)(m_img_height-1))  ;i++)
    57034149    {
    57044150      for (int j=uiLPelX ;j<=min(uiRPelX,(unsigned int)(m_img_width-1)) ;j++)
    57054151      {
    5706 #else
    5707     for (int i=uiTPelY ;i<=min(uiBPelY,(unsigned int)(pcPicOrg->getHeight()-1))  ;i++)
    5708     {
    5709       for (int j=uiLPelX ;j<=min(uiRPelX,(unsigned int)(pcPicOrg->getWidth()-1)) ;j++)
    5710       {
    5711 #endif
    57124152        m_maskImg[i][j]=1;
    57134153      }
     
    57194159    pcCU->setAlfCtrlFlagSubParts(0, uiAbsPartIdx, uiSetDepth);
    57204160    vCUCtrlFlag.push_back(0);
    5721 #if LCU_SYNTAX_ALF
    57224161    for (int i=uiTPelY ;i<=min(uiBPelY,(unsigned int)(m_img_height-1))  ;i++)
    57234162    {
    57244163      for (int j=uiLPelX ;j<=min(uiRPelX,(unsigned int)(m_img_width-1)) ;j++)
    57254164      {
    5726 #else
    5727     for (int i=uiTPelY ;i<=min(uiBPelY,(unsigned int)(pcPicOrg->getHeight()-1))  ;i++)
    5728     {
    5729       for (int j=uiLPelX ;j<=min(uiRPelX,(unsigned int)(pcPicOrg->getWidth()-1)) ;j++)
    5730       {
    5731 #endif
    57324165        m_maskImg[i][j]=0;
    57334166      }
     
    57364169}
    57374170
    5738 #if !LCU_SYNTAX_ALF
    5739 
    5740 Void TEncAdaptiveLoopFilter::xReDesignFilterCoeff_qc(TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, Bool bReadCorr)
    5741 {
    5742   Int tap = m_pcTempAlfParam->filter_shape;
    5743   Int    LumaStride = pcPicOrg->getStride();
    5744   Pel* pOrg  = pcPicOrg->getLumaAddr();
    5745   Pel* pDec  = pcPicDec->getLumaAddr();
    5746   Pel* pRest = pcPicRest->getLumaAddr();
    5747   xFirstFilteringFrameLuma(pOrg, pDec, pRest, m_pcTempAlfParam, tap, LumaStride);
    5748  
    5749   if (m_iALFEncodePassReduction)
    5750   {
    5751     if(!m_iUsePreviousFilter)
    5752     {
    5753       saveFilterCoeffToBuffer(m_filterCoeffSym, m_pcTempAlfParam->filters_per_group, m_varIndTab, m_pcTempAlfParam->alf_pcr_region_flag, tap);
    5754     }
    5755   }
    5756 }
    5757 
    5758 Void TEncAdaptiveLoopFilter::xCUAdaptiveControl_qc(TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiMinRate, UInt64& ruiMinDist, Double& rdMinCost)
    5759 {
    5760   if(!m_bAlfCUCtrlEnabled) return;
    5761   Bool bChanged = false;
    5762   std::vector<AlfCUCtrlInfo> vAlfCUCtrlParamTemp(m_vBestAlfCUCtrlParam);
    5763 
    5764   Pel** maskImgTemp;
    5765 
    5766   if(m_iALFEncodePassReduction == 2)
    5767   {
    5768     initMatrix_Pel(&maskImgTemp, m_img_height, m_img_width);
    5769   }
    5770 
    5771   m_pcEntropyCoder->setAlfCtrl(true);
    5772  
    5773   UInt uiBestDepth = 0;
    5774  
    5775   ALFParam cFrmAlfParam;
    5776   allocALFParam(&cFrmAlfParam);
    5777   copyALFParam(&cFrmAlfParam, m_pcBestAlfParam);
    5778  
    5779   for (UInt uiDepth = 0; uiDepth < g_uiMaxCUDepth; uiDepth++)
    5780   {
    5781     m_pcEntropyCoder->setMaxAlfCtrlDepth(uiDepth);
    5782     pcPicRest->copyToPicLuma(m_pcPicYuvTmp);
    5783     copyALFParam(m_pcTempAlfParam, &cFrmAlfParam);
    5784 
    5785     for (UInt uiRD = 0; uiRD <= m_iALFNumOfRedesign; uiRD++)
    5786     {
    5787       if (uiRD)
    5788       {
    5789         // re-design filter coefficients
    5790         xReDesignFilterCoeff_qc(pcPicOrg, pcPicDec, m_pcPicYuvTmp, true); //use filtering of mine
    5791       }
    5792      
    5793       UInt64 uiRate, uiDist;
    5794       Double dCost;
    5795      //m_pcPicYuvTmp: filtered signal, pcPicDec: orig reconst
    5796       xSetCUAlfCtrlFlags_qc(uiDepth, pcPicOrg, pcPicDec, m_pcPicYuvTmp, uiDist, vAlfCUCtrlParamTemp);
    5797       xCalcRDCost(m_pcTempAlfParam, uiRate, uiDist, dCost, &vAlfCUCtrlParamTemp);
    5798       if (dCost < rdMinCost)
    5799       {
    5800         bChanged = true;
    5801         m_vBestAlfCUCtrlParam = vAlfCUCtrlParamTemp;
    5802         uiBestDepth = uiDepth;
    5803         rdMinCost = dCost;
    5804         ruiMinDist = uiDist;
    5805         ruiMinRate = uiRate;
    5806         m_pcPicYuvTmp->copyToPicLuma(m_pcPicYuvBest);
    5807         copyALFParam(m_pcBestAlfParam, m_pcTempAlfParam);
    5808         //save maskImg
    5809         xCopyTmpAlfCtrlFlagsFrom();
    5810         if(m_iALFEncodePassReduction == 2)
    5811         {
    5812           ::memcpy(maskImgTemp[0], m_maskImg[0], sizeof(Pel)*m_img_height* m_img_width);
    5813         }
    5814       }
    5815     }
    5816   }
    5817 
    5818   if(bChanged)
    5819   {
    5820     if(m_iALFEncodePassReduction == 2)
    5821     {
    5822       UInt uiDepth = uiBestDepth;
    5823       ::memcpy(m_maskImg[0], maskImgTemp[0], sizeof(Pel)*m_img_height* m_img_width);
    5824       xCopyTmpAlfCtrlFlagsTo();
    5825  
    5826       copyALFParam(&cFrmAlfParam, m_pcBestAlfParam);
    5827 
    5828       m_pcEntropyCoder->setAlfCtrl(true);
    5829       m_pcEntropyCoder->setMaxAlfCtrlDepth(uiDepth);
    5830       copyALFParam(m_pcTempAlfParam, &cFrmAlfParam);
    5831 
    5832       xReDesignFilterCoeff_qc(pcPicOrg, pcPicDec, m_pcPicYuvTmp, true); //use filtering of mine
    5833 
    5834       UInt64 uiRate, uiDist;
    5835       Double dCost;
    5836       xSetCUAlfCtrlFlags_qc(uiDepth, pcPicOrg, pcPicDec, m_pcPicYuvTmp, uiDist, vAlfCUCtrlParamTemp);
    5837       xCalcRDCost(m_pcTempAlfParam, uiRate, uiDist, dCost, &vAlfCUCtrlParamTemp);
    5838       if (dCost < rdMinCost)
    5839       {
    5840         rdMinCost = dCost;
    5841         ruiMinDist = uiDist;
    5842         ruiMinRate = uiRate;
    5843         m_pcPicYuvTmp->copyToPicLuma(m_pcPicYuvBest);
    5844         copyALFParam(m_pcBestAlfParam, m_pcTempAlfParam);
    5845         xCopyTmpAlfCtrlFlagsFrom();
    5846         m_vBestAlfCUCtrlParam = vAlfCUCtrlParamTemp;
    5847       }
    5848     }
    5849 
    5850     m_pcEntropyCoder->setAlfCtrl(true);
    5851     m_pcEntropyCoder->setMaxAlfCtrlDepth(uiBestDepth);
    5852     xCopyTmpAlfCtrlFlagsTo();
    5853 
    5854     m_pcPicYuvBest->copyToPicLuma(pcPicRest);//copy m_pcPicYuvBest to pcPicRest
    5855     xCopyDecToRestCUs(pcPicDec, pcPicRest); //pcPicRest = pcPicDec
    5856   }
    5857   else
    5858   {
    5859     m_pcEntropyCoder->setAlfCtrl(false);
    5860     m_pcEntropyCoder->setMaxAlfCtrlDepth(0);
    5861   }
    5862   freeALFParam(&cFrmAlfParam);
    5863 
    5864   if(m_iALFEncodePassReduction == 2)
    5865   {
    5866     destroyMatrix_Pel(maskImgTemp);
    5867   }
    5868 }
    5869 
    5870 #endif
    58714171
    58724172#define ROUND(a)  (((a) < 0)? (int)((a) - 0.5) : (int)((a) + 0.5))
     
    62424542{
    62434543  double error;
    6244 #if LCU_SYNTAX_ALF && LCUALF_QP_DEPENDENT_BITS
     4544#if LCUALF_QP_DEPENDENT_BITS
    62454545  Int factor = (1<<(getAlfPrecisionBit(m_alfQP)));
    62464546#else
     
    63844684}
    63854685
    6386 #if !LCU_SYNTAX_ALF
    6387 
    6388 /** Save redesigned filter set to buffer
    6389  * \param filterCoeffPrevSelected filter set buffer
    6390  */
    6391 Void TEncAdaptiveLoopFilter::saveFilterCoeffToBuffer(Int **filterSet, Int numFilter, Int* mergeTable, Int mode, Int filtNo)
    6392 {
    6393   Int iBufferIndex = m_iCurrentPOC % m_iGOPSize;
    6394 
    6395   static Bool bFirst = true;
    6396   static Bool* pbFirstAccess;
    6397   if(bFirst)
    6398   {
    6399     pbFirstAccess = new Bool[NUM_ALF_CLASS_METHOD];
    6400     for(Int i=0; i< NUM_ALF_CLASS_METHOD; i++)
    6401     {
    6402       pbFirstAccess[i]= true;
    6403     }
    6404     bFirst = false;
    6405   }
    6406 
    6407   if(iBufferIndex == 0)
    6408   {
    6409     if(pbFirstAccess[mode])
    6410     {
    6411       //store merge table
    6412       ::memcpy(m_mergeTableSavedMethods[mode][m_iGOPSize], mergeTable, sizeof(Int)*NO_VAR_BINS);
    6413       //store coefficients
    6414       for(Int varInd=0; varInd< numFilter; varInd++)
    6415       {
    6416         ::memcpy(m_aiFilterCoeffSavedMethods[mode][m_iGOPSize][varInd],filterSet[varInd], sizeof(Int)*ALF_MAX_NUM_COEF );
    6417       }
    6418       //store filter shape
    6419       m_iPreviousFilterShapeMethods[mode][m_iGOPSize]= filtNo;
    6420 
    6421       pbFirstAccess[mode] = false;
    6422     }
    6423 
    6424 
    6425     //store merge table
    6426     ::memcpy(m_mergeTableSavedMethods[mode][0         ], m_mergeTableSavedMethods[mode][m_iGOPSize], sizeof(Int)*NO_VAR_BINS);
    6427     ::memcpy(m_mergeTableSavedMethods[mode][m_iGOPSize], mergeTable,                          sizeof(Int)*NO_VAR_BINS);
    6428 
    6429     //store coefficients
    6430     for(Int varInd=0; varInd< NO_VAR_BINS; varInd++)
    6431     {
    6432       ::memcpy(m_aiFilterCoeffSavedMethods[mode][0][varInd],m_aiFilterCoeffSavedMethods[mode][m_iGOPSize][varInd], sizeof(Int)*ALF_MAX_NUM_COEF );
    6433     }
    6434 
    6435     for(Int varInd=0; varInd< numFilter; varInd++)
    6436     {
    6437       ::memcpy(m_aiFilterCoeffSavedMethods[mode][m_iGOPSize][varInd],filterSet[varInd], sizeof(Int)*ALF_MAX_NUM_COEF );
    6438     }
    6439 
    6440     //store filter shape
    6441     m_iPreviousFilterShapeMethods[mode][0]= m_iPreviousFilterShapeMethods[mode][m_iGOPSize];
    6442     m_iPreviousFilterShapeMethods[mode][m_iGOPSize]= filtNo;
    6443   }
    6444   else
    6445   {
    6446 
    6447     //store merge table
    6448     ::memcpy(m_mergeTableSavedMethods[mode][iBufferIndex], mergeTable, sizeof(Int)*NO_VAR_BINS);
    6449 
    6450     //store coefficients
    6451     for(Int varInd=0; varInd< numFilter; varInd++)
    6452     {
    6453       ::memcpy(m_aiFilterCoeffSavedMethods[mode][iBufferIndex][varInd],filterSet[varInd], sizeof(Int)*ALF_MAX_NUM_COEF );
    6454     }
    6455     //store filter_shape
    6456     m_iPreviousFilterShapeMethods[mode][iBufferIndex]= filtNo;
    6457 
    6458   }
    6459 }
    6460 
    6461 
    6462 /** set initial m_maskImg with previous (time-delayed) filters
    6463  * \param pcPicOrg original picture
    6464  * \param pcPicDec reconstructed picture after deblocking
    6465  */
    6466 Void TEncAdaptiveLoopFilter::setMaskWithTimeDelayedResults(TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec)
    6467 {
    6468 
    6469   static Pel** bestImgMask;
    6470   static Bool bFirst = true;
    6471   if(bFirst)
    6472   {
    6473     initMatrix_Pel(&bestImgMask, m_img_height, m_img_width);
    6474     bFirst = false;
    6475   }
    6476 
    6477   Pel*    pDec       = pcPicDec->getLumaAddr();
    6478   Pel*    pOrg       = pcPicOrg->getLumaAddr();
    6479   Pel*    pRest      = m_pcPicYuvTmp->getLumaAddr();
    6480   Int     LumaStride = pcPicOrg->getStride();
    6481   Int***   pppCoeffSaved     = m_aiFilterCoeffSavedMethods  [m_uiVarGenMethod];
    6482   Int**    ppMergeTableSaved = m_mergeTableSavedMethods     [m_uiVarGenMethod];
    6483   Int*     pFilterShapeSaved = m_iPreviousFilterShapeMethods[m_uiVarGenMethod];
    6484   Int      iBufIdx;
    6485 
    6486   UInt64    uiRate, uiDist;
    6487   Double    dCost, dMinCost = MAX_DOUBLE;
    6488   ALFParam  cAlfParam;
    6489   allocALFParam(&cAlfParam);
    6490   cAlfParam.alf_flag        = 0;
    6491   cAlfParam.chroma_idc      = 0;
    6492 
    6493   //filter frame with the previous time-delayed filters
    6494   Int filtNo;
    6495   Int maxDepth = (pcPicOrg->getWidth() < 1000) ?(2):(g_uiMaxCUDepth);
    6496   m_pcEntropyCoder->setAlfCtrl(true);
    6497   m_pcTempAlfParam->alf_flag = 1;
    6498   m_pcTempAlfParam->alf_pcr_region_flag = m_uiVarGenMethod;
    6499 
    6500   for (Int index=0; index<2; index++)
    6501   {
    6502     iBufIdx = setFilterIdx(index);
    6503     filtNo = m_pcTempAlfParam->filter_shape = pFilterShapeSaved[iBufIdx];
    6504 #if ALF_SINGLE_FILTER_SHAPE
    6505     assert(filtNo == ALF_CROSS9x7_SQUARE3x3);
    6506 #else
    6507     assert(filtNo == ALF_STAR5x5 || filtNo == ALF_CROSS9x9);
    6508 #endif
    6509     m_pcTempAlfParam->num_coeff = m_sqrFiltLengthTab[filtNo];
    6510     if(!m_bUseNonCrossALF)
    6511     {
    6512       filterLuma(pRest, pDec, LumaStride, 0, m_img_height-1, 0, m_img_width-1,  filtNo, pppCoeffSaved[iBufIdx], ppMergeTableSaved[iBufIdx], m_varImg);
    6513     }
    6514     else
    6515     {
    6516       xfilterSlicesEncoder(pDec, pRest, LumaStride, filtNo, pppCoeffSaved[iBufIdx], ppMergeTableSaved[iBufIdx], m_varImg);
    6517     }
    6518 
    6519     for (UInt uiDepth = 0; uiDepth < maxDepth; uiDepth++)
    6520     {
    6521       m_pcEntropyCoder->setMaxAlfCtrlDepth(uiDepth);
    6522       std::vector<AlfCUCtrlInfo> vAlfCUCtrlParamTemp(m_uiNumSlicesInPic);
    6523       xSetCUAlfCtrlFlags_qc(uiDepth, pcPicOrg, pcPicDec, m_pcPicYuvTmp, uiDist, vAlfCUCtrlParamTemp);
    6524       m_pcEntropyCoder->resetEntropy();
    6525       m_pcEntropyCoder->resetBits();
    6526       xEncodeCUAlfCtrlFlags(vAlfCUCtrlParamTemp);
    6527       uiRate = m_pcEntropyCoder->getNumberOfWrittenBits();
    6528       dCost  = (Double)(uiRate) * m_dLambdaLuma + (Double)(uiDist);
    6529 
    6530       if (dCost < dMinCost)
    6531       {
    6532         dMinCost    = dCost;
    6533         copyALFParam(&cAlfParam, m_pcTempAlfParam);
    6534         ::memcpy(bestImgMask[0], m_maskImg[0], sizeof(Pel)*m_img_height* m_img_width);
    6535       }
    6536     }
    6537   }
    6538   filtNo = cAlfParam.filter_shape;
    6539 
    6540 
    6541   ::memcpy(m_maskImg[0], bestImgMask[0], sizeof(Pel)*m_img_height* m_img_width);
    6542 
    6543   m_pcEntropyCoder->setAlfCtrl(false);
    6544   m_pcEntropyCoder->setMaxAlfCtrlDepth(0);
    6545 
    6546   // generate filters for future reference
    6547   m_iDesignCurrentFilter = 0;
    6548 
    6549   int  filters_per_fr;
    6550   int  lambda_val = (Int)m_dLambdaLuma;
    6551 
    6552   lambda_val = lambda_val * (1<<(2*g_uiBitIncrement));
    6553 
    6554   if(!m_bUseNonCrossALF)
    6555   {
    6556     xstoreInBlockMatrix(0, 0, m_img_height, m_img_width, true, true, pOrg, pDec, cAlfParam.filter_shape, LumaStride);
    6557   }
    6558   else
    6559   {
    6560     xstoreInBlockMatrixforSlices(pOrg, pDec, cAlfParam.filter_shape, LumaStride);
    6561   }
    6562   xfindBestFilterVarPred(m_yGlobalSym[filtNo], m_EGlobalSym[filtNo], m_pixAcc,
    6563     m_filterCoeffSym, m_filterCoeffSymQuant,
    6564     filtNo, &filters_per_fr,
    6565     m_varIndTab, NULL, m_varImg, m_maskImg, NULL, lambda_val);
    6566 
    6567   saveFilterCoeffToBuffer(m_filterCoeffSym, filters_per_fr, m_varIndTab, cAlfParam.alf_pcr_region_flag, filtNo);
    6568   m_iDesignCurrentFilter = 1;
    6569 
    6570   freeALFParam(&cAlfParam);
    6571 
    6572 }
    6573 
    6574 
    6575 /** set ALF encoding parameters
    6576  * \param pcPic picture pointer
    6577  */
    6578 Void TEncAdaptiveLoopFilter::setALFEncodingParam(TComPic *pcPic)
    6579 {
    6580   if(m_iALFEncodePassReduction)
    6581   {
    6582     m_iALFNumOfRedesign = 0;
    6583     m_iCurrentPOC = m_pcPic->getPOC();
    6584     if((pcPic->getSlice(0)->getSliceType() == I_SLICE) || (m_iGOPSize==8 && (m_iCurrentPOC % 4 == 0)))
    6585     {
    6586       m_iUsePreviousFilter = 0;
    6587     }
    6588     else
    6589     {
    6590       m_iUsePreviousFilter = 1;
    6591     }
    6592   }
    6593   else
    6594   {
    6595     m_iALFNumOfRedesign = ALF_NUM_OF_REDESIGN;
    6596   }
    6597   m_iDesignCurrentFilter = 1;
    6598 
    6599 }
    6600 
    6601 /** set filter buffer index
    6602  * \param index the processing order of time-delayed filtering
    6603  */
    6604 Int TEncAdaptiveLoopFilter::setFilterIdx(Int index)
    6605 {
    6606   Int iBufIdx;
    6607 
    6608   if (m_iGOPSize == 8)
    6609   {
    6610     switch(m_iCurrentPOC % m_iGOPSize)
    6611     {
    6612     case 0:
    6613       {
    6614         iBufIdx = (index == 0)?0:m_iGOPSize;
    6615       }
    6616       break;
    6617     case 1:
    6618       {
    6619         iBufIdx = (index == 0)?0:2;
    6620       }
    6621       break;
    6622     case 2:
    6623       {
    6624         iBufIdx = (index == 0)?0:4;
    6625       }
    6626       break;
    6627     case 3:
    6628       {
    6629         iBufIdx = (index == 0)?2:4;
    6630       }
    6631       break;
    6632     case 4:
    6633       {
    6634         iBufIdx = (index == 0)?0:m_iGOPSize;
    6635       }
    6636       break;
    6637     case 5:
    6638       {
    6639         iBufIdx = (index == 0)?4:6;
    6640       }
    6641       break;
    6642     case 6:
    6643       {
    6644         iBufIdx = (index == 0)?4:m_iGOPSize;
    6645       }
    6646       break;
    6647     case 7:
    6648       {
    6649         iBufIdx = (index == 0)?6:m_iGOPSize;
    6650       }
    6651       break;
    6652     default:
    6653       {
    6654         printf("error\n");
    6655         assert(0);
    6656       }
    6657     }
    6658   }
    6659   else
    6660   {
    6661     iBufIdx = (index == 0)?0:m_iGOPSize;
    6662   }
    6663 
    6664   return iBufIdx;
    6665 }
    6666 
    6667 
    6668 /** set initial m_maskImg
    6669  * \param pcPicOrg original picture pointer
    6670  * \param pcPicDec reconstructed picture pointer
    6671  */
    6672 Void TEncAdaptiveLoopFilter::setInitialMask(TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec)
    6673 {
    6674   Int Height = pcPicOrg->getHeight();
    6675   Int Width = pcPicOrg->getWidth();
    6676   Int LumaStride = pcPicOrg->getStride();
    6677   Pel* pDec = pcPicDec->getLumaAddr();
    6678 
    6679   calcVar(m_varImg, pDec, LumaStride, m_uiVarGenMethod);
    6680 
    6681   if(!m_iALFEncodePassReduction || !m_iUsePreviousFilter)
    6682   {
    6683     for(Int y=0; y<Height; y++)
    6684     {
    6685       for(Int x=0; x<Width; x++)
    6686       {
    6687         m_maskImg[y][x] = 1;
    6688       }
    6689     }
    6690   }
    6691   else
    6692   {
    6693     setMaskWithTimeDelayedResults(pcPicOrg, pcPicDec);
    6694   }
    6695 }
    6696 
    6697 
    6698 
    6699 /** Estimate RD cost of all filter size & store the best one
    6700  * \param ImgOrg original picture
    6701  * \param ImgDec reconstructed picture after deblocking
    6702  * \param Sride  line buffer size of picture buffer
    6703  * \param pcAlfSaved the best Alf parameters
    6704  * \returns ruiDist             estimated distortion
    6705  * \returns ruiRate             required bits
    6706  * \returns rdCost              estimated R-D cost
    6707  */
    6708 
    6709 Void  TEncAdaptiveLoopFilter::decideFilterShapeLuma(Pel* ImgOrg, Pel* ImgDec, Int Stride, ALFParam* pcAlfSaved, UInt64& ruiRate, UInt64& ruiDist, Double& rdCost)
    6710 {
    6711   static Double **ySym, ***ESym;
    6712   Int    lambda_val = ((Int) m_dLambdaLuma) * (1<<(2*g_uiBitIncrement));
    6713   Int    filtNo, filters_per_fr;
    6714   Int64  iEstimatedDist;
    6715   UInt64 uiRate;
    6716   Double dEstimatedCost, dEstimatedMinCost = MAX_DOUBLE;;
    6717 
    6718   UInt   uiBitShift = (g_uiBitIncrement<<1);
    6719   Int64  iEstimateDistBeforeFilter;
    6720   Int*   coeffNoFilter[NUM_ALF_FILTER_SHAPE][NO_VAR_BINS];
    6721   for(Int filter_shape = 0; filter_shape < NUM_ALF_FILTER_SHAPE; filter_shape++)
    6722   {
    6723     for(Int i=0; i< NO_VAR_BINS; i++)
    6724     {
    6725       coeffNoFilter[filter_shape][i]= new Int[ALF_MAX_NUM_COEF];
    6726       ::memset(coeffNoFilter[filter_shape][i], 0, sizeof(Int)*ALF_MAX_NUM_COEF);
    6727       coeffNoFilter[filter_shape][i][ m_sqrFiltLengthTab[filter_shape]-1 ] = (1 << ((Int)ALF_NUM_BIT_SHIFT));
    6728     }
    6729   }
    6730 
    6731   m_pcTempAlfParam->alf_flag = 1;
    6732   m_pcTempAlfParam->chroma_idc = 0;
    6733   m_pcTempAlfParam->alf_pcr_region_flag = m_uiVarGenMethod;
    6734 
    6735   for (int filter_shape = 0; filter_shape < NUM_ALF_FILTER_SHAPE ;filter_shape ++)
    6736   {
    6737     m_pcTempAlfParam->filter_shape = filtNo = filter_shape;
    6738     m_pcTempAlfParam->num_coeff = m_sqrFiltLengthTab[filtNo] ; 
    6739 
    6740     ESym     = m_EGlobalSym     [filtNo];
    6741     ySym     = m_yGlobalSym     [filtNo];
    6742 
    6743     if(!m_bUseNonCrossALF)
    6744     {
    6745       xstoreInBlockMatrix(0, 0, m_img_height, m_img_width, true, true, ImgOrg, ImgDec, filter_shape, Stride);
    6746     }
    6747     else
    6748     {
    6749       xstoreInBlockMatrixforSlices(ImgOrg, ImgDec, filter_shape, Stride);
    6750     }
    6751     xfindBestFilterVarPred(ySym, ESym, m_pixAcc, m_filterCoeffSym, m_filterCoeffSymQuant, filtNo, &filters_per_fr, m_varIndTab, NULL, m_varImg, m_maskImg, NULL, lambda_val);
    6752 
    6753     //estimate R-D cost
    6754     uiRate         = xcodeFiltCoeff(m_filterCoeffSymQuant, filtNo, m_varIndTab, filters_per_fr, m_pcTempAlfParam);
    6755     iEstimatedDist = xEstimateFiltDist(filters_per_fr, m_varIndTab, ESym, ySym, m_filterCoeffSym, m_pcTempAlfParam->num_coeff);
    6756     iEstimateDistBeforeFilter = xEstimateFiltDist(filters_per_fr, m_varIndTab, ESym, ySym, coeffNoFilter[filter_shape], m_pcTempAlfParam->num_coeff);
    6757     iEstimatedDist -= iEstimateDistBeforeFilter;
    6758     dEstimatedCost = (Double)(uiRate) * m_dLambdaLuma + (Double)(iEstimatedDist);
    6759 
    6760     if(dEstimatedCost < dEstimatedMinCost)
    6761     {
    6762       dEstimatedMinCost   = dEstimatedCost;
    6763       copyALFParam(pcAlfSaved, m_pcTempAlfParam);
    6764       iEstimatedDist += iEstimateDistBeforeFilter;
    6765 
    6766       for(Int i=0; i< filters_per_fr; i++ )
    6767       {
    6768         iEstimatedDist += (((Int64)m_pixAcc_merged[i]) >> uiBitShift);
    6769       }
    6770       ruiDist = (iEstimatedDist > 0)?((UInt64)iEstimatedDist):(0);
    6771       rdCost  = dEstimatedMinCost + (Double)(ruiDist);
    6772       ruiRate = uiRate;
    6773     }
    6774   }
    6775 
    6776   if (!m_iUsePreviousFilter)
    6777   {
    6778     decodeFilterSet(pcAlfSaved, m_varIndTab, m_filterCoeffSym);
    6779     saveFilterCoeffToBuffer(m_filterCoeffSym, pcAlfSaved->filters_per_group, m_varIndTab, pcAlfSaved->alf_pcr_region_flag, pcAlfSaved->filter_shape);
    6780   }
    6781 
    6782   if( m_iUsePreviousFilter )
    6783   {
    6784     UInt64 uiOffRegionDistortion = 0;
    6785     Int    iPelDiff;
    6786     Pel*   pOrgTemp = (Pel*)ImgOrg;
    6787     Pel*   pDecTemp = (Pel*)ImgDec;
    6788     for(Int y=0; y< m_img_height; y++)
    6789     {
    6790       for(Int x=0; x< m_img_width; x++)
    6791       {
    6792         if(m_maskImg[y][x] == 0)
    6793         {
    6794           iPelDiff = pOrgTemp[x] - pDecTemp[x];
    6795           uiOffRegionDistortion += (UInt64)(  (iPelDiff*iPelDiff) >> uiBitShift );
    6796         }
    6797       }
    6798       pOrgTemp += Stride;
    6799       pDecTemp += Stride;
    6800 
    6801       ruiDist += uiOffRegionDistortion;
    6802       rdCost  += (Double)uiOffRegionDistortion;
    6803     }
    6804   }
    6805  
    6806 #if !ALF_SINGLE_FILTER_SHAPE
    6807   // if ALF_STAR5x5 is selected, the distortion of 2 skipped lines per LCU should be added.
    6808   if(pcAlfSaved->filter_shape == ALF_STAR5x5)
    6809   {
    6810     Int    iPelDiff;
    6811     UInt64  uiSkipPelsDistortion = 0;
    6812     Pel   *pOrgTemp, *pDecTemp;
    6813     for(Int y= m_lineIdxPadTop-1; y< m_img_height - m_lcuHeight ; y += m_lcuHeight)
    6814     {
    6815       pOrgTemp = ImgOrg + y*Stride;
    6816       pDecTemp = ImgDec + y*Stride;
    6817       for(Int x=0; x< m_img_width; x++)
    6818       {
    6819         if(m_maskImg[y][x] == 1)
    6820         {
    6821           iPelDiff = pOrgTemp[x] - pDecTemp[x];
    6822           uiSkipPelsDistortion += (UInt64)(  (iPelDiff*iPelDiff) >> uiBitShift );
    6823         }
    6824       }
    6825 
    6826       pOrgTemp += Stride;
    6827       pDecTemp += Stride;
    6828       for(Int x=0; x< m_img_width; x++)
    6829       {
    6830         if(m_maskImg[y+1][x] == 1)
    6831         {
    6832           iPelDiff = pOrgTemp[x] - pDecTemp[x];
    6833           uiSkipPelsDistortion += (UInt64)(  (iPelDiff*iPelDiff) >> uiBitShift );
    6834         }
    6835       }
    6836     }
    6837     ruiDist += uiSkipPelsDistortion;
    6838     rdCost  += (Double)uiSkipPelsDistortion;
    6839   }
    6840 #endif
    6841 
    6842   for(Int filter_shape = 0; filter_shape < NUM_ALF_FILTER_SHAPE; filter_shape++)
    6843   {
    6844     for(Int i=0; i< NO_VAR_BINS; i++)
    6845     {
    6846       delete[] coeffNoFilter[filter_shape][i];
    6847     }
    6848   }
    6849 }
    6850 
    6851 
    6852 #endif
    68534686
    68544687/** Estimate filtering distortion by correlation values and filter coefficients
     
    68674700  Int64  iDist;
    68684701  Double dDist, dsum;
    6869 #if LCU_SYNTAX_ALF && LCUALF_QP_DEPENDENT_BITS
     4702#if LCUALF_QP_DEPENDENT_BITS
    68704703  Int alfPrecisionBit = getAlfPrecisionBit( m_alfQP );
    68714704#endif
     
    68734706  for(i=0; i< iFiltLength; i++)
    68744707  {
    6875 #if LCU_SYNTAX_ALF && LCUALF_QP_DEPENDENT_BITS
     4708#if LCUALF_QP_DEPENDENT_BITS
    68764709    pdcoeff[i]= (Double)piCoeff[i] / (Double)(1<<alfPrecisionBit);
    68774710#else
     
    69084741
    69094742
    6910 #if !LCU_SYNTAX_ALF
    6911 
    6912 /** Estimate total filtering cost of all groups
    6913  * \param filters_per_fr number of filters for the slice
    6914  * \param VarIndTab merge index of all groups
    6915  * \param pppdE  auto-correlation matrix pointer for all groups
    6916  * \param ppdy cross-correlation array pointer for all groups
    6917  * \returns estimated distortion
    6918  */
    6919 Int64 TEncAdaptiveLoopFilter::xEstimateFiltDist(Int filters_per_fr, Int* VarIndTab,
    6920                                                 Double*** pppdE, Double** ppdy,
    6921                                                 Int** ppiCoeffSet, Int iFiltLength)
    6922 
    6923 {
    6924   Int64     iDist;
    6925   Double**  ppdDstE;
    6926   Double**  ppdSrcE;
    6927   Double*   pdDsty; 
    6928   Double*   pdSrcy;
    6929   Int       f, j, i, varInd;
    6930   Int*      piCoeff;
    6931 
    6932   //clean m_E_merged & m_y_merged
    6933   for(f=0; f< filters_per_fr; f++)
    6934   {
    6935     for(j =0; j < iFiltLength; j++)
    6936     {
    6937       //clean m_E_merged one line
    6938       for(i=0; i < iFiltLength; i++)
    6939       {
    6940         m_E_merged[f][j][i] = 0;
    6941       }
    6942 
    6943       //clean m_y_merged
    6944       m_y_merged[f][j] = 0;
    6945     }
    6946     m_pixAcc_merged[f] = 0;
    6947   }
    6948 
    6949 
    6950   //merge correlation values
    6951   for (varInd=0; varInd< NO_VAR_BINS; varInd++)
    6952   {
    6953     ppdSrcE = pppdE[varInd];
    6954     ppdDstE = m_E_merged[ VarIndTab[varInd] ];
    6955 
    6956     pdSrcy  = ppdy[varInd];
    6957     pdDsty  = m_y_merged[ VarIndTab[varInd] ];
    6958 
    6959     for(j=0; j< iFiltLength; j++)
    6960     {
    6961       for(i=0; i< iFiltLength; i++)
    6962       {
    6963         ppdDstE[j][i] += ppdSrcE[j][i];
    6964       }
    6965 
    6966       pdDsty[j] += pdSrcy[j];
    6967     }
    6968     m_pixAcc_merged[ VarIndTab[varInd]  ] += m_pixAcc[varInd];
    6969 
    6970   }
    6971 
    6972   //estimate distortion reduction by using FFDE (JCTVC-C143)
    6973   iDist = 0;
    6974   for(f=0; f< filters_per_fr; f++)
    6975   {
    6976     piCoeff = ppiCoeffSet[f];
    6977     ppdDstE = m_E_merged [f];
    6978     pdDsty  = m_y_merged [f];
    6979 
    6980     iDist += xFastFiltDistEstimation(ppdDstE, pdDsty, piCoeff, iFiltLength);
    6981   }
    6982 
    6983 
    6984   return iDist;
    6985 
    6986 }
    6987 
    6988 /** Calculate ALF grouping indices for ALF slices
    6989  * \param varmap grouping indices buffer
    6990  * \param imgY_Dec picture buffer
    6991  * \param pad_size (max. filter tap)/2
    6992  * \param fl  VAR_SIZE
    6993  * \param img_stride picture buffer stride
    6994  */
    6995 Void TEncAdaptiveLoopFilter::xfilterSlicesEncoder(Pel* ImgDec, Pel* ImgRest, Int iStride, Int filtNo, Int** filterCoeff, Int* mergeTable, Pel** varImg)
    6996 {
    6997   Pel* pPicSrc   = (Pel *)ImgDec;
    6998   Pel* pPicSlice = m_pcSliceYuvTmp->getLumaAddr();
    6999 
    7000   for(UInt s=0; s< m_uiNumSlicesInPic; s++)
    7001   {
    7002     if(!m_pcPic->getValidSlice(s))
    7003     {
    7004       continue;
    7005     }
    7006     std::vector< std::vector<AlfLCUInfo*> > & vpSliceTileAlfLCU = m_pvpSliceTileAlfLCU[s];
    7007 
    7008     for(Int t=0; t< (Int)vpSliceTileAlfLCU.size(); t++)
    7009     {
    7010       std::vector<AlfLCUInfo*> & vpAlfLCU = vpSliceTileAlfLCU[t];
    7011       copyRegion(vpAlfLCU, pPicSlice, pPicSrc, iStride);
    7012       extendRegionBorder(vpAlfLCU, pPicSlice, iStride);
    7013       filterLumaRegion(vpAlfLCU, pPicSlice, ImgRest, iStride, filtNo, filterCoeff, mergeTable, varImg);
    7014     }
    7015   }
    7016 }
    7017 
    7018 /** Calculate block autocorrelations and crosscorrelations for ALF slices
    7019  * \param ImgOrg original picture
    7020  * \param ImgDec picture before filtering
    7021  * \param tap  filter tap size
    7022  * \param iStride picture buffer stride
    7023  */
    7024 Void   TEncAdaptiveLoopFilter::xstoreInBlockMatrixforSlices(Pel* ImgOrg, Pel* ImgDec, Int tap, Int iStride)
    7025 {
    7026   Pel* pPicSrc   = (Pel *)ImgDec;
    7027   Pel* pPicSlice = m_pcSliceYuvTmp->getLumaAddr();
    7028 
    7029   UInt iLastValidSliceID =0;
    7030   for(UInt s=0; s< m_uiNumSlicesInPic; s++)
    7031   {
    7032     if(m_pcPic->getValidSlice(s))
    7033     {
    7034       iLastValidSliceID = s;
    7035     }
    7036   }
    7037 
    7038   for(UInt s=0; s<= iLastValidSliceID; s++)
    7039   {
    7040     if(!m_pcPic->getValidSlice(s))
    7041     {
    7042       continue;
    7043     }
    7044     std::vector< std::vector<AlfLCUInfo*> > & vpSliceTileAlfLCU = m_pvpSliceTileAlfLCU[s];
    7045     Int numValidTilesInSlice = (Int)vpSliceTileAlfLCU.size();
    7046     for(Int t=0; t< numValidTilesInSlice; t++)
    7047     {
    7048       std::vector<AlfLCUInfo*> & vpAlfLCU = vpSliceTileAlfLCU[t];
    7049       copyRegion(vpAlfLCU, pPicSlice, pPicSrc, iStride);
    7050       extendRegionBorder(vpAlfLCU, pPicSlice, iStride);
    7051       xstoreInBlockMatrixforRegion(vpAlfLCU, ImgOrg, pPicSlice, tap, iStride, (s==0)&&(t==0), (s== iLastValidSliceID)&&(t==numValidTilesInSlice-1));
    7052     }
    7053   }
    7054 }
    7055 
    7056 /** Calculate block autocorrelations and crosscorrelations for one ALF region
    7057  * \param vpAlfLCU ALF LCU data container
    7058  * \param ImgOrg original picture
    7059  * \param ImgDec picture before filtering
    7060  * \param tap  filter tap size
    7061  * \param iStride picture buffer stride
    7062  * \param bFirstSlice  true for the first processing slice of the picture
    7063  * \param bLastSlice true for the last processing slice of the picture
    7064  */
    7065 Void   TEncAdaptiveLoopFilter::xstoreInBlockMatrixforRegion(std::vector< AlfLCUInfo* > &vpAlfLCU,
    7066                                                               Pel* ImgOrg, Pel* ImgDec,
    7067                                                               Int tap, Int iStride,
    7068                                                               Bool bFirstSlice,
    7069                                                               Bool bLastSlice
    7070                                                               )
    7071 {
    7072 
    7073   UInt uiNumLCUs = (UInt)vpAlfLCU.size();
    7074   Int iHeight, iWidth;
    7075   Int ypos, xpos;
    7076   Bool bFirstLCU, bLastLCU;
    7077   Bool bFirstSGU, bLastSGU;
    7078   UInt numSGUs;
    7079 
    7080   for(UInt i=0; i< uiNumLCUs; i++)
    7081   {
    7082     bFirstLCU = (i==0);
    7083     bLastLCU  = (i== uiNumLCUs -1);
    7084     AlfLCUInfo& cAlfLCU = *(vpAlfLCU[i]);
    7085     numSGUs = cAlfLCU.numSGU;
    7086     for(UInt j=0; j< numSGUs; j++)
    7087     {
    7088       bFirstSGU= (j ==0);
    7089       bLastSGU = (j == numSGUs -1);
    7090 
    7091       ypos    = (Int)(cAlfLCU[j].posY  );
    7092       xpos    = (Int)(cAlfLCU[j].posX  );
    7093       iHeight = (Int)(cAlfLCU[j].height);
    7094       iWidth  = (Int)(cAlfLCU[j].width );
    7095 
    7096       xstoreInBlockMatrix(ypos, xpos, iHeight, iWidth,
    7097         (bFirstSlice && bFirstLCU && bFirstSGU),(bLastSlice && bLastLCU && bLastSGU),
    7098         ImgOrg, ImgDec,tap, iStride);
    7099     }
    7100   }
    7101 }
    7102 
    7103 
    7104 /** Calculate autocorrelations and crosscorrelations for chroma slices
    7105  * \param ComponentID Cb or Cr
    7106  * \param pOrg original picture
    7107  * \param pCmp picture before filtering
    7108  * \param iTap  filter tap size
    7109  * \param iOrgStride picture buffer stride for pOrg
    7110  * \param iCmpStride picture buffer stride for pCmp
    7111  */
    7112 Void TEncAdaptiveLoopFilter::xCalcCorrelationFuncforChromaSlices(Int ComponentID, Pel* pOrg, Pel* pCmp, Int iTap, Int iOrgStride, Int iCmpStride)
    7113 {
    7114 
    7115   assert(iOrgStride == iCmpStride);
    7116 
    7117   Pel* pPicSrc   = pCmp;
    7118   Pel* pPicSlice = (ComponentID == ALF_Cb)?(m_pcSliceYuvTmp->getCbAddr()):(m_pcSliceYuvTmp->getCrAddr());
    7119   Int chromaFormatShift = 1;
    7120 
    7121   UInt iLastValidSliceID =0;
    7122   for(UInt s=0; s< m_uiNumSlicesInPic; s++)
    7123   {
    7124     if(m_pcPic->getValidSlice(s))
    7125     {
    7126       iLastValidSliceID = s;
    7127     }
    7128   }
    7129 
    7130   for(UInt s=0; s<= iLastValidSliceID; s++)
    7131   {
    7132     if(!m_pcPic->getValidSlice(s))
    7133     {
    7134       continue;
    7135     }
    7136     std::vector< std::vector<AlfLCUInfo*> > & vpSliceTileAlfLCU = m_pvpSliceTileAlfLCU[s];
    7137     Int numValidTilesInSlice = (Int)vpSliceTileAlfLCU.size();
    7138     for(Int t=0; t< numValidTilesInSlice; t++)
    7139     {
    7140       std::vector<AlfLCUInfo*> & vpAlfLCU = vpSliceTileAlfLCU[t];
    7141       copyRegion(vpAlfLCU, pPicSlice, pPicSrc, iCmpStride, chromaFormatShift);
    7142       extendRegionBorder(vpAlfLCU, pPicSlice, iCmpStride, chromaFormatShift);
    7143       xCalcCorrelationFuncforChromaRegion(vpAlfLCU, pOrg, pPicSlice, iTap, iCmpStride,(s== iLastValidSliceID)&&(t== numValidTilesInSlice-1), chromaFormatShift);
    7144     }
    7145   }
    7146 }
    7147 
    7148 /** Calculate autocorrelations and crosscorrelations for one chroma slice
    7149  * \param vpAlfLCU ALF LCU data container
    7150  * \param pOrg original picture
    7151  * \param pCmp picture before filtering
    7152  * \param iTap  filter tap size
    7153  * \param iStride picture buffer stride
    7154  * \param bLastSlice the last processing slice of picture
    7155  */
    7156 Void TEncAdaptiveLoopFilter::xCalcCorrelationFuncforChromaRegion(std::vector< AlfLCUInfo* > &vpAlfLCU, Pel* pOrg, Pel* pCmp, Int filtNo, Int iStride, Bool bLastSlice, Int iFormatShift)
    7157 {
    7158   UInt uiNumLCUs = (UInt)vpAlfLCU.size();
    7159 
    7160   Int iHeight, iWidth;
    7161   Int ypos, xpos;
    7162   Bool bLastLCU;
    7163   Bool bLastSGU;
    7164   UInt numSGUs;
    7165 
    7166   for(UInt i=0; i< uiNumLCUs; i++)
    7167   {
    7168     bLastLCU  = (i== uiNumLCUs -1);
    7169 
    7170     AlfLCUInfo& cAlfLCU = *(vpAlfLCU[i]);
    7171     numSGUs = cAlfLCU.numSGU;
    7172     for(UInt j=0; j< numSGUs; j++)
    7173     {
    7174       bLastSGU = (j == numSGUs -1);
    7175       ypos    = (Int)(cAlfLCU[j].posY   >> iFormatShift);
    7176       xpos    = (Int)(cAlfLCU[j].posX   >> iFormatShift);
    7177       iHeight = (Int)(cAlfLCU[j].height >> iFormatShift);
    7178       iWidth  = (Int)(cAlfLCU[j].width  >> iFormatShift);
    7179       xCalcCorrelationFunc(ypos, xpos, pOrg, pCmp, filtNo, iWidth, iHeight, iStride, iStride, (bLastSlice && bLastLCU && bLastSGU) );
    7180     }
    7181   }
    7182 }
    7183 
    7184 // ====================================================================================================================
    7185 // Protected member functions
    7186 // ====================================================================================================================
    7187 
    7188 Void TEncAdaptiveLoopFilter::xFilterTapDecisionChroma( UInt64 uiLumaRate, TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiDist, UInt64& ruiBits )
    7189 {
    7190   Int   iShape, num_coeff;
    7191   Int64 iOrgDistCb, iOrgDistCr, iFiltDistCb, iFiltDistCr, iDist;
    7192   Bool  bChanged = false;
    7193   Int*  qh = m_pcTempAlfParam->coeff_chroma;
    7194 
    7195   UInt64 uiMinRate = uiLumaRate;
    7196   UInt64 uiMinDist = MAX_INT;
    7197   Double dMinCost  = MAX_DOUBLE;
    7198   Double dLocalMinCost = MAX_DOUBLE;
    7199 
    7200   copyALFParam(m_pcTempAlfParam, m_pcBestAlfParam);
    7201   xCalcRDCostChroma(pcPicOrg, pcPicRest, m_pcTempAlfParam, uiMinRate, uiMinDist, dMinCost);
    7202 
    7203 #if ALF_SINGLE_FILTER_SHAPE
    7204   iShape = 0;
    7205 #else
    7206   for(iShape = 0; iShape < 2; iShape++)
    7207 #endif 
    7208   {
    7209     // set global variables
    7210     num_coeff = m_sqrFiltLengthTab[iShape];
    7211     m_pcTempAlfParam->chroma_idc = 3;
    7212     m_pcTempAlfParam->filter_shape_chroma = iShape;
    7213     m_pcTempAlfParam->num_coeff_chroma = num_coeff;
    7214 
    7215     // keep original corr pointer
    7216     Double **ppdTmpCorr = m_ppdAlfCorr;
    7217 
    7218     // calc Cb matrix
    7219     m_pcTempAlfParam->chroma_idc = 2;
    7220     m_ppdAlfCorr = m_ppdAlfCorrCb;
    7221     for(Int i=0; i<ALF_MAX_NUM_COEF; i++)
    7222     {
    7223       ::memset(m_ppdAlfCorr[i], 0, sizeof(Double) * (ALF_MAX_NUM_COEF + 1));
    7224     }
    7225     Pel *pOrg = pcPicOrg->getCbAddr();
    7226     Pel *pCmp = pcPicDec->getCbAddr();
    7227     if(!m_bUseNonCrossALF)
    7228     {
    7229       xCalcCorrelationFunc(0, 0, pOrg, pCmp, iShape, (pcPicOrg->getWidth()>>1), (pcPicOrg->getHeight()>>1), pcPicOrg->getCStride(), pcPicDec->getCStride(), true);
    7230     }
    7231     else
    7232     {
    7233       xCalcCorrelationFuncforChromaSlices(ALF_Cb, pOrg, pCmp, iShape, pcPicOrg->getCStride(), pcPicDec->getCStride());
    7234     }
    7235 
    7236     // calc Cr matrix
    7237     m_pcTempAlfParam->chroma_idc = 1;
    7238     m_ppdAlfCorr = m_ppdAlfCorrCr;
    7239     for(Int i=0; i<ALF_MAX_NUM_COEF; i++)
    7240     {
    7241       ::memset(m_ppdAlfCorr[i], 0, sizeof(Double) * (ALF_MAX_NUM_COEF + 1));
    7242     }
    7243     pOrg = pcPicOrg->getCrAddr();
    7244     pCmp = pcPicDec->getCrAddr();
    7245     if(!m_bUseNonCrossALF)
    7246     {
    7247       xCalcCorrelationFunc(0, 0, pOrg, pCmp, iShape, (pcPicOrg->getWidth()>>1), (pcPicOrg->getHeight()>>1), pcPicOrg->getCStride(), pcPicDec->getCStride(), true);
    7248     }
    7249     else
    7250     {
    7251       xCalcCorrelationFuncforChromaSlices(ALF_Cr, pOrg, pCmp, iShape, pcPicOrg->getCStride(), pcPicDec->getCStride());
    7252     }
    7253 
    7254     // restore original corr pointer
    7255     m_ppdAlfCorr = ppdTmpCorr;
    7256 
    7257     // calc original dist
    7258     memset(qh, 0, sizeof(Int)*num_coeff);
    7259     qh[num_coeff-1] = 1<<((Int)ALF_NUM_BIT_SHIFT);
    7260     iOrgDistCb = xFastFiltDistEstimationChroma(m_ppdAlfCorrCb, qh, num_coeff);
    7261     iOrgDistCr = xFastFiltDistEstimationChroma(m_ppdAlfCorrCr, qh, num_coeff);
    7262 
    7263     for(Int iCmp=1; iCmp<=3; iCmp++)
    7264     {
    7265       m_pcTempAlfParam->chroma_idc = iCmp;
    7266       xCalcALFCoeffChroma(iCmp, iShape, qh);
    7267       iFiltDistCb = ((iCmp>>1)&0x1) ? xFastFiltDistEstimationChroma(m_ppdAlfCorrCb, qh, num_coeff) : iOrgDistCb;
    7268       iFiltDistCr = ((iCmp)   &0x1) ? xFastFiltDistEstimationChroma(m_ppdAlfCorrCr, qh, num_coeff) : iOrgDistCr;
    7269       iDist = iFiltDistCb + iFiltDistCr;
    7270       UInt64 uiRate = xCalcRateChroma(m_pcTempAlfParam);
    7271       Double dCost  = (Double)iDist + m_dLambdaChroma * (Double)uiRate;
    7272       if(dCost < dLocalMinCost)
    7273       {
    7274         dLocalMinCost = dCost;
    7275         copyALFParam(m_pcBestAlfParam, m_pcTempAlfParam);
    7276         bChanged = true;
    7277       }
    7278     }
    7279   }
    7280   copyALFParam(m_pcTempAlfParam, m_pcBestAlfParam);
    7281   if(!bChanged)
    7282   {
    7283     m_pcBestAlfParam->chroma_idc = 0;
    7284     return;
    7285   }
    7286 
    7287   // Adaptive in-loop wiener filtering for chroma
    7288   xFilteringFrameChroma(m_pcTempAlfParam, pcPicOrg, pcPicDec, pcPicRest);
    7289 
    7290   // filter on/off decision for chroma
    7291   Int iCWidth = (pcPicOrg->getWidth()>>1);
    7292   Int iCHeight = (pcPicOrg->getHeight()>>1);
    7293   Int iCStride = pcPicOrg->getCStride();
    7294   UInt64 uiFiltDistCb = xCalcSSD(pcPicOrg->getCbAddr(), pcPicRest->getCbAddr(), iCWidth, iCHeight, iCStride);
    7295   UInt64 uiFiltDistCr = xCalcSSD(pcPicOrg->getCrAddr(), pcPicRest->getCrAddr(), iCWidth, iCHeight, iCStride);
    7296   UInt64 uiOrgDistCb  = xCalcSSD(pcPicOrg->getCbAddr(), pcPicDec->getCbAddr(), iCWidth, iCHeight, iCStride);
    7297   UInt64 uiOrgDistCr  = xCalcSSD(pcPicOrg->getCrAddr(), pcPicDec->getCrAddr(), iCWidth, iCHeight, iCStride);
    7298   if(((m_pcTempAlfParam->chroma_idc)>>1 & 0x1) && (uiOrgDistCb<=uiFiltDistCb))
    7299   {
    7300     m_pcTempAlfParam->chroma_idc -= 2;
    7301     pcPicDec->copyToPicCb(pcPicRest);
    7302   }
    7303   if(((m_pcTempAlfParam->chroma_idc)    & 0x1) && (uiOrgDistCr<=uiFiltDistCr))
    7304   {
    7305     m_pcTempAlfParam->chroma_idc -= 1;
    7306     pcPicDec->copyToPicCr(pcPicRest);
    7307   }
    7308 
    7309   if(m_pcTempAlfParam->chroma_idc)
    7310   {
    7311     UInt64 uiRate, uiDist;
    7312     Double dCost;
    7313     xCalcRDCostChroma(pcPicOrg, pcPicRest, m_pcTempAlfParam, uiRate, uiDist, dCost);
    7314 
    7315     if( dCost < dMinCost )
    7316     {
    7317       copyALFParam(m_pcBestAlfParam, m_pcTempAlfParam);
    7318       predictALFCoeffChroma(m_pcBestAlfParam);
    7319      
    7320       ruiBits += uiRate;
    7321       ruiDist += uiDist;
    7322     }
    7323     else
    7324     {
    7325       m_pcBestAlfParam->chroma_idc = 0;
    7326      
    7327       if((m_pcTempAlfParam->chroma_idc>>1)&0x01)
    7328       {
    7329         pcPicDec->copyToPicCb(pcPicRest);
    7330       }
    7331       if(m_pcTempAlfParam->chroma_idc&0x01)
    7332       {
    7333         pcPicDec->copyToPicCr(pcPicRest);
    7334       }
    7335      
    7336       ruiBits += uiMinRate;
    7337       ruiDist += uiMinDist;
    7338     }
    7339   }
    7340   else
    7341   {
    7342     m_pcBestAlfParam->chroma_idc = 0;
    7343    
    7344     ruiBits += uiMinRate;
    7345     ruiDist += uiMinDist;
    7346    
    7347     pcPicDec->copyToPicCb(pcPicRest);
    7348     pcPicDec->copyToPicCr(pcPicRest);
    7349   }
    7350 }
    7351 
    7352 Int64 TEncAdaptiveLoopFilter::xFastFiltDistEstimationChroma(Double** ppdCorr, Int* piCoeff, Int iSqrFiltLength)
    7353 {
    7354   Double pdcoeff[ALF_MAX_NUM_COEF];
    7355   Int    i,j;
    7356   Int64  iDist;
    7357   Double dDist, dsum;
    7358   for(i=0; i< iSqrFiltLength; i++)
    7359   {
    7360     pdcoeff[i]= (Double)piCoeff[i] / (Double)(1<< ((Int)ALF_NUM_BIT_SHIFT) );
    7361   }
    7362 
    7363   dDist =0;
    7364   for(i=0; i< iSqrFiltLength; i++)
    7365   {
    7366     dsum= ((Double)ppdCorr[i][i]) * pdcoeff[i];
    7367     for(j=i+1; j< iSqrFiltLength; j++)
    7368     {
    7369       dsum += (Double)(2*ppdCorr[i][j])* pdcoeff[j];
    7370     }
    7371 
    7372     dDist += ((dsum - 2.0 * ppdCorr[i][iSqrFiltLength])* pdcoeff[i] );
    7373   }
    7374 
    7375   UInt uiShift = g_uiBitIncrement<<1;
    7376   if(dDist < 0)
    7377   {
    7378     iDist = -(((Int64)(-dDist + 0.5)) >> uiShift);
    7379   }
    7380   else //dDist >=0
    7381   {
    7382     iDist= ((Int64)(dDist+0.5)) >> uiShift;
    7383   }
    7384 
    7385   return iDist;
    7386 }
    7387 
    7388 Void TEncAdaptiveLoopFilter::xCalcALFCoeffChroma(Int iChromaIdc, Int iShape, Int* piCoeff)
    7389 {
    7390   Int iSqrFiltLength = m_sqrFiltLengthTab[iShape];
    7391 
    7392   for(Int i=0; i<iSqrFiltLength; i++)
    7393   {
    7394     memset(m_ppdAlfCorr[i], 0, sizeof(Double)*(iSqrFiltLength + 1));
    7395   }
    7396 
    7397   // retrive
    7398   if((iChromaIdc>>1) & 0x1)
    7399   {
    7400     for(Int i=0; i<iSqrFiltLength; i++)
    7401     {
    7402       for(Int j=i; j<iSqrFiltLength+1; j++)
    7403       {
    7404         m_ppdAlfCorr[i][j] += m_ppdAlfCorrCb[i][j];
    7405       }
    7406     }
    7407   }
    7408   if(iChromaIdc & 0x1)
    7409   {
    7410     for(Int i=0; i<iSqrFiltLength; i++)
    7411     {
    7412       for(Int j=i; j<iSqrFiltLength+1; j++)
    7413       {
    7414         m_ppdAlfCorr[i][j] += m_ppdAlfCorrCr[i][j];
    7415       }
    7416     }
    7417   }
    7418 
    7419   // copy
    7420   for(Int i=1; i<iSqrFiltLength; i++)
    7421   {
    7422     for(Int j=0; j<i; j++)
    7423     {
    7424       m_ppdAlfCorr[i][j] = m_ppdAlfCorr[j][i];
    7425     }
    7426   }
    7427 
    7428   Double *corr = new Double[iSqrFiltLength];
    7429   for(Int i=0; i<iSqrFiltLength; i++)
    7430   {
    7431     corr[i] = m_ppdAlfCorr[i][iSqrFiltLength];
    7432   }
    7433 
    7434   // calc coeff
    7435   gnsSolveByChol(m_ppdAlfCorr, corr, m_pdDoubleAlfCoeff, iSqrFiltLength);
    7436   xQuantFilterCoef(m_pdDoubleAlfCoeff, piCoeff, iShape, g_uiBitDepth + g_uiBitIncrement);
    7437   delete [] corr;
    7438 }
    7439 
    7440 UInt64 TEncAdaptiveLoopFilter::xCalcRateChroma(ALFParam* pAlfParam)
    7441 {
    7442   UInt64 uiRate;
    7443   Int* piTmpCoef;
    7444   piTmpCoef = new Int[ALF_MAX_NUM_COEF];
    7445   memcpy(piTmpCoef, pAlfParam->coeff_chroma, sizeof(Int)*pAlfParam->num_coeff_chroma);
    7446 
    7447   predictALFCoeffChroma(pAlfParam);
    7448 
    7449   m_pcEntropyCoder->resetEntropy();
    7450   m_pcEntropyCoder->resetBits();
    7451   m_pcEntropyCoder->encodeAlfParam(pAlfParam);
    7452   uiRate = m_pcEntropyCoder->getNumberOfWrittenBits();
    7453   if (m_vBestAlfCUCtrlParam.size() != 0)
    7454   {
    7455     for(UInt s=0; s< m_uiNumSlicesInPic; s++)
    7456     {
    7457       if(!m_pcPic->getValidSlice(s))
    7458       {
    7459         continue;
    7460       }
    7461       m_pcEntropyCoder->resetEntropy();
    7462       m_pcEntropyCoder->resetBits();
    7463       m_pcEntropyCoder->encodeAlfCtrlParam( m_vBestAlfCUCtrlParam[s], m_uiNumCUsInFrame);
    7464       uiRate += m_pcEntropyCoder->getNumberOfWrittenBits();
    7465     }
    7466   }
    7467   else
    7468   {
    7469     uiRate += m_uiNumSlicesInPic;
    7470   }
    7471   memcpy(pAlfParam->coeff_chroma, piTmpCoef, sizeof(int)*pAlfParam->num_coeff_chroma);
    7472   delete[] piTmpCoef;
    7473   piTmpCoef = NULL;
    7474 
    7475   return uiRate;
    7476 }
    7477 #endif
    74784743
    74794744//! \}
  • trunk/source/Lib/TLibEncoder/TEncAdaptiveLoopFilter.h

    r56 r296  
    4949//! \{
    5050
    51 #if LCU_SYNTAX_ALF
    5251#define LCUALF_FILTER_BUDGET_CONTROL_ENC        1 //!< filter budget control
    5352#define LCUALF_AVOID_USING_BOTTOM_LINES_ENCODER 1 //!< avoid using LCU bottom lines when lcu-based encoder RDO is used
    54 #endif
    5553
    5654// ====================================================================================================================
     
    5856// ====================================================================================================================
    5957
    60 #if LCU_SYNTAX_ALF
    6158/// correlation info
    6259struct AlfCorrData
     
    110107};
    111108
    112 #endif
    113109
    114110
     
    120116  /// variables for correlation calculation
    121117  ///
    122 #if !LCU_SYNTAX_ALF
    123   Double** m_ppdAlfCorr;
    124   Double* m_pdDoubleAlfCoeff;
    125   Double** m_ppdAlfCorrCb;
    126   Double** m_ppdAlfCorrCr;
    127   double ***m_yGlobalSym;
    128   double ****m_EGlobalSym;
    129   double *m_pixAcc;
    130 #endif
    131118  double **m_y_merged;
    132119  double ***m_E_merged;
     
    134121  double *m_y_temp;
    135122  double **m_E_temp;
    136 #if LCU_SYNTAX_ALF
    137123  static const Int  m_alfNumPartsInRowTab[5];
    138124  static const Int  m_alfNumPartsLevelTab[5];
     
    154140  Int    m_alfUsedFilterNum;
    155141#endif
    156 #endif
    157142
    158143  ///
    159144  /// ALF parameters
    160145  ///
    161 #if !LCU_SYNTAX_ALF
    162   ALFParam* m_pcBestAlfParam;
    163   ALFParam* m_pcTempAlfParam;
    164   ALFParam* pcAlfParamShape0;
    165   ALFParam* pcAlfParamShape1;
    166 #endif
    167146  ALFParam *m_tempALFp;
    168147
     
    172151  TComPicYuv* m_pcPicYuvBest;
    173152  TComPicYuv* m_pcPicYuvTmp;
    174 #if !LCU_SYNTAX_ALF
    175   TComPicYuv* pcPicYuvRecShape0;
    176   TComPicYuv* pcPicYuvRecShape1;
    177 #endif
    178153
    179154  ///
     
    186161  Int    **m_diffFilterCoeffQuant;
    187162  Int    **m_FilterCoeffQuantTemp;
    188 #if !LCU_SYNTAX_ALF
    189   Int**  m_mergeTableSavedMethods[NUM_ALF_CLASS_METHOD];
    190   Int*** m_aiFilterCoeffSavedMethods[NUM_ALF_CLASS_METHOD];  //!< time-delayed filter set buffer
    191   Int*   m_iPreviousFilterShapeMethods[NUM_ALF_CLASS_METHOD];
    192 #endif
    193163  ///
    194164  /// coding control parameters
     
    196166  Double m_dLambdaLuma;
    197167  Double m_dLambdaChroma;
    198 #if !LCU_SYNTAX_ALF
    199   Int  m_iUsePreviousFilter;     //!< for N-pass encoding- 1: time-delayed filtering is allowed. 0: not allowed.
    200   Int  m_iDesignCurrentFilter;   //!< for N-pass encoding- 1: design filters for current slice. 0: design filters for future slice reference
    201   Int  m_iGOPSize;                //!< GOP size
    202   Int  m_iCurrentPOC;             //!< POC
    203 #endif
    204168  Int  m_iALFEncodePassReduction; //!< 0: 16-pass encoding, 1: 1-pass encoding, 2: 2-pass encoding
    205169
     
    221185private:
    222186
    223 #if LCU_SYNTAX_ALF
    224187  Void disableComponentAlfParam(Int compIdx, AlfParamSet* alfParamSet, AlfUnitParam* alfUnitPic);
    225188  Void copyAlfParamSet(AlfParamSet* dst, AlfParamSet* src);
     
    252215  Void xCopyDecToRestCUs( Pel* imgDec, Pel* imgRest, Int stride );
    253216  Void xCopyDecToRestCU( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, Pel* imgDec, Pel* imgRest, Int stride );
    254 #if ALF_SINGLE_FILTER_SHAPE
    255217  Void calcCorrOneCompRegionChma(Pel* imgOrg, Pel* imgPad, Int stride, Int yPos, Int xPos, Int height, Int width, Double **eCorr, Double *yCorr, Bool isSymmCopyBlockMatrix); //!< Calculate correlations for chroma                                       
    256218  Void calcCorrOneCompRegionLuma(Pel* imgOrg, Pel* imgPad, Int stride, Int yPos, Int xPos, Int height, Int width, Double ***eCorr, Double **yCorr, Double *pixAcc, Bool isforceCollection, Bool isSymmCopyBlockMatrix);
    257 #endif
    258219
    259220  //LCU-based mode decision
     
    291252  Void transferToAlfParamSet(Int compIdx, AlfUnitParam* alfUnitPic, AlfParamSet* & alfParamSet);
    292253  Int  calculateAlfParamSetRateRDO(Int compIdx, AlfParamSet* alfParamSet, std::vector<AlfCUCtrlInfo>* alfCUCtrlParam);
    293 #endif
    294 #if !LCU_SYNTAX_ALF
    295   // init / uninit internal variables
    296   Void xInitParam      ();
    297   Void xUninitParam    ();
    298 #endif
    299254  // ALF on/off control related functions
    300255  Void xCreateTmpAlfCtrlFlags   ();
     
    305260  Void xEncodeCUAlfCtrlFlags  (std::vector<AlfCUCtrlInfo> &vAlfCUCtrlParam);
    306261  Void xEncodeCUAlfCtrlFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth);
    307 #if !LCU_SYNTAX_ALF 
    308   Void xCUAdaptiveControl_qc           ( TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiMinRate, UInt64& ruiMinDist, Double& rdMinCost );
    309   Void xSetCUAlfCtrlFlags_qc            (UInt uiAlfCtrlDepth, TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiDist, std::vector<AlfCUCtrlInfo>& vAlfCUCtrlParam);
    310   Void xSetCUAlfCtrlFlag_qc             (TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, UInt uiAlfCtrlDepth, TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiDist, std::vector<UInt>& vCUCtrlFlag);
    311 
    312   // functions related to correlation computation
    313   Void xstoreInBlockMatrix(Int ypos, Int xpos, Int iheight, Int iwidth, Bool bResetBlockMatrix, Bool bSymmCopyBlockMatrix, Pel* pImgOrg, Pel* pImgPad, Int filtNo, Int stride); //!< Calculate correlations for luma
    314   Void xstoreInBlockMatrixforRegion(std::vector< AlfLCUInfo* > &vpAlfLCU, Pel* ImgOrg, Pel* ImgDec, Int tap, Int iStride, Bool bFirstSlice, Bool bLastSlice); //!< Calculate block autocorrelations and crosscorrelations for one ALF slice
    315   Void xstoreInBlockMatrixforSlices  (Pel* ImgOrg, Pel* ImgDec, Int tap, Int iStride); //!< Calculate block autocorrelations and crosscorrelations for ALF slices
    316   Void xCalcCorrelationFunc(Int ypos, Int xpos, Pel* pImgOrg, Pel* pImgPad, Int filtNo, Int iWidth, Int iHeight, Int iOrgStride, Int iCmpStride, Bool bSymmCopyBlockMatrix); //!< Calculate correlations for chroma
    317   Void xCalcCorrelationFuncforChromaRegion(std::vector< AlfLCUInfo* > &vpAlfLCU, Pel* pOrg, Pel* pCmp, Int filtNo, Int iStride, Bool bLastSlice, Int iFormatShift); //!< Calculate autocorrelations and crosscorrelations for one chroma slice
    318   Void xCalcCorrelationFuncforChromaSlices  (Int ComponentID, Pel* pOrg, Pel* pCmp, Int iTap, Int iOrgStride, Int iCmpStride); //!< Calculate autocorrelations and crosscorrelations for chroma slices
    319 #endif
    320262  // functions related to filtering
    321263  Void xFilterCoefQuickSort   ( Double *coef_data, Int *coef_num, Int upper, Int lower );
    322264  Void xQuantFilterCoef       ( Double* h, Int* qh, Int tap, int bit_depth );
    323 #if !LCU_SYNTAX_ALF
    324   Void xClearFilterCoefInt    ( Int* qh, Int N );
    325   Void xCopyDecToRestCUs      ( TComPicYuv* pcPicDec, TComPicYuv* pcPicRest );
    326   Void xCopyDecToRestCU       ( TComDataCU* pcCU, UInt uiAbsPartIdx, UInt uiDepth, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest );
    327   Void xFilteringFrameChroma  (ALFParam* pcAlfParam, TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest);
    328   Int  setFilterIdx(Int index); //!< set filter buffer index
    329   Void setInitialMask(TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec); //!< set initial m_maskImg
    330   Void saveFilterCoeffToBuffer(Int **filterSet, Int numFilter, Int* mergeTable, Int mode, Int filtNo); //!< save filter coefficients to buffer
    331   Void setMaskWithTimeDelayedResults(TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec); //!< set initial m_maskImg with previous (time-delayed) filters
    332   Void decideFilterShapeLuma(Pel* ImgOrg, Pel* ImgDec, Int Stride, ALFParam* pcAlfSaved, UInt64& ruiRate, UInt64& ruiDist,Double& rdCost); //!< Estimate RD cost of all filter size & store the best one
    333   Void   xFilterTapDecisionChroma      (UInt64 uiLumaRate, TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiDist, UInt64& ruiBits);
    334   Int64  xFastFiltDistEstimationChroma (Double** ppdCorr, Int* piCoeff, Int iSqrFiltLength);
    335   Void  xfilterSlicesEncoder(Pel* ImgDec, Pel* ImgRest, Int iStride, Int filtNo, Int** filterCoeff, Int* mergeTable, Pel** varImg); //!< Calculate ALF grouping indices for ALF slices
    336   Void  setALFEncodingParam(TComPic *pcPic); //!< set ALF encoding parameters
    337   Void xReDesignFilterCoeff_qc          (TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec,  TComPicYuv* pcPicRest, Bool bReadCorr);
    338   Void xFirstFilteringFrameLuma (Pel* imgOrg, Pel* imgDec, Pel* imgRest, ALFParam* ALFp, Int filtNo, Int stride);
    339   Void xFilteringFrameLuma(Pel* imgOrg, Pel* imgPad, Pel* imgFilt, ALFParam* ALFp, Int filtNo, Int stride);
    340   Void xEncALFLuma  ( TComPicYuv* pcPicOrg, TComPicYuv* pcPicDec, TComPicYuv* pcPicRest, UInt64& ruiMinRate, UInt64& ruiMinDist, Double& rdMinCost ); //!< estimate adaptation mode and filter shape
    341 #endif
    342265  // distortion / misc functions
    343266#if HHI_INTERVIEW_SKIP
     
    346269  UInt64 xCalcSSD             ( Pel* pOrg, Pel* pCmp, Int iWidth, Int iHeight, Int iStride );
    347270#endif
    348 #if !LCU_SYNTAX_ALF
    349 #if HHI_INTERVIEW_SKIP
    350   Void  xCalcRDCost          ( TComPicYuv* pcPicOrg, TComPicYuv* pcPicCmp, ALFParam* pAlfParam, UInt64& ruiRate, UInt64& ruiDist, Double& rdCost, std::vector<AlfCUCtrlInfo>* pvAlfCUCtrlParam = NULL);
    351   Void  xCalcRDCost          ( ALFParam* pAlfParam, UInt64& ruiRate, UInt64 uiDist, Double& rdCost, std::vector<AlfCUCtrlInfo>* pvAlfCUCtrlParam = NULL);
    352   Void  xCalcRDCostChroma    ( TComPicYuv* pcPicOrg, TComPicYuv* pcPicCmp, ALFParam* pAlfParam, UInt64& ruiRate, UInt64& ruiDist, Double& rdCost );
    353 #else
    354   Void  xCalcRDCost          ( TComPicYuv* pcPicOrg, TComPicYuv* pcPicCmp, ALFParam* pAlfParam, UInt64& ruiRate, UInt64& ruiDist, Double& rdCost, std::vector<AlfCUCtrlInfo>* pvAlfCUCtrlParam = NULL);
    355   Void  xCalcRDCost          ( ALFParam* pAlfParam, UInt64& ruiRate, UInt64 uiDist, Double& rdCost, std::vector<AlfCUCtrlInfo>* pvAlfCUCtrlParam = NULL);
    356   Void  xCalcRDCostChroma    ( TComPicYuv* pcPicOrg, TComPicYuv* pcPicCmp, ALFParam* pAlfParam, UInt64& ruiRate, UInt64& ruiDist, Double& rdCost );
    357 #endif
    358 #endif
    359271  Int64 xFastFiltDistEstimation(Double** ppdE, Double* pdy, Int* piCoeff, Int iFiltLength); //!< Estimate filtering distortion by correlation values and filter coefficients
    360 #if !LCU_SYNTAX_ALF
    361   Int64 xEstimateFiltDist      (Int filters_per_fr, Int* VarIndTab, Double*** pppdE, Double** ppdy, Int** ppiCoeffSet, Int iFiltLength); //!< Estimate total filtering cost of all groups 
    362   UInt64 xCalcRateChroma               (ALFParam* pAlfParam);
    363   Void   xCalcALFCoeffChroma           (Int iChromaIdc, Int iShape, Int* piCoeff);
    364 #endif
    365272
    366273  /// code filter coefficients
    367274  UInt xcodeFiltCoeff(Int **filterCoeffSymQuant, Int filter_shape, Int varIndTab[], Int filters_per_fr_best, ALFParam* ALFp);
    368 #if LCU_SYNTAX_ALF
    369275  Void xfindBestFilterVarPred(double **ySym, double ***ESym, double *pixAcc, Int **filterCoeffSym, Int **filterCoeffSymQuant,Int filter_shape, Int *filters_per_fr_best, Int varIndTab[], Pel **imgY_rec, Pel **varImg, Pel **maskImg, Pel **imgY_pad, double lambda_val, Int numMaxFilters = NO_FILTERS);
    370 #else
    371   Void xfindBestFilterVarPred(double **ySym, double ***ESym, double *pixAcc, Int **filterCoeffSym, Int **filterCoeffSymQuant,Int filter_shape, Int *filters_per_fr_best, Int varIndTab[], Pel **imgY_rec, Pel **varImg, Pel **maskImg, Pel **imgY_pad, double lambda_val);
    372 #endif
    373276  double xfindBestCoeffCodMethod(int **filterCoeffSymQuant, int filter_shape, int sqrFiltLength, int filters_per_fr, double errorForce0CoeffTab[NO_VAR_BINS][2], double lambda);
    374277  Int xsendAllFiltersPPPred(int **FilterCoeffQuant, int filter_shape, int sqrFiltLength, int filters_per_group, int createBistream, ALFParam* ALFp);
     
    400303  Void startALFEnc(TComPic* pcPic, TEncEntropy* pcEntropyCoder); //!< allocate temporal memory
    401304  Void endALFEnc(); //!< destroy temporal memory
    402 #if LCU_SYNTAX_ALF
    403305#if ALF_CHROMA_LAMBDA
    404306#if HHI_INTERVIEW_SKIP
     
    418320  Void resetPicAlfUnit();
    419321  Void setAlfCoefInSlice(Bool b) {m_alfCoefInSlice = b;}
    420 #else
    421 #if ALF_CHROMA_LAMBDA 
    422 #if HHI_INTERVIEW_SKIP
    423   Void ALFProcess(ALFParam* pcAlfParam, std::vector<AlfCUCtrlInfo>* pvAlfCtrlParam, Double dLambdaLuma, Double dLambdaChroma, UInt64& ruiDist, UInt64& ruiBits, Bool bInterviewSkip); //!< estimate ALF parameters
    424 #else
    425   Void ALFProcess(ALFParam* pcAlfParam, std::vector<AlfCUCtrlInfo>* pvAlfCtrlParam, Double dLambdaLuma, Double dLambdaChroma, UInt64& ruiDist, UInt64& ruiBits); //!< estimate ALF parameters
    426 #endif
    427 #else
    428 #if HHI_INTERVIEW_SKIP
    429   Void ALFProcess(ALFParam* pcAlfParam, std::vector<AlfCUCtrlInfo>* pvAlfCtrlParam, Double dLambda, UInt64& ruiDist, UInt64& ruiBits, Bool bInterviewSkip); //!< estimate ALF parameters
    430 #else
    431   Void ALFProcess(ALFParam* pcAlfParam, std::vector<AlfCUCtrlInfo>* pvAlfCtrlParam, Double dLambda, UInt64& ruiDist, UInt64& ruiBits); //!< estimate ALF parameters
    432 #endif
    433 #endif
    434 
    435   Void setGOPSize(Int val) { m_iGOPSize = val; } //!< set GOP size
    436 #endif
    437322  Void setALFEncodePassReduction (Int iVal) {m_iALFEncodePassReduction = iVal;} //!< set N-pass encoding. 0: 16(14)-pass encoding, 1: 1-pass encoding, 2: 2-pass encoding
    438323
    439324  Void setALFMaxNumberFilters    (Int iVal) {m_iALFMaxNumberFilters = iVal;} //!< set ALF Max Number of Filters
    440325
    441 #if LCU_SYNTAX_ALF
    442326  Void createAlfGlobalBuffers(); //!< create ALF global buffers
    443327  Void initPicQuadTreePartition(Bool isPicBasedEncode);
    444 #else
    445   Void createAlfGlobalBuffers(Int iALFEncodePassReduction); //!< create ALF global buffers
    446 #endif
    447328  Void destroyAlfGlobalBuffers(); //!< destroy ALF global buffers
    448329  Void PCMLFDisableProcess (TComPic* pcPic);
  • trunk/source/Lib/TLibEncoder/TEncBinCoder.h

    r56 r296  
    5656  virtual Void  finish            ()                                          = 0;
    5757  virtual Void  copyState         ( TEncBinIf* pcTEncBinIf )                  = 0;
    58 #if OL_FLUSH
    5958  virtual Void  flush            ()                                           = 0;
    60 #endif
    6159
    6260  virtual Void  encodeFlush     (Bool bEnd) = 0;
    6361
    6462  virtual Void  resetBac          ()                                          = 0;
    65 #if BURST_IPCM
    6663  virtual Void  encodeNumSubseqIPCM( Int numSubseqIPCM )                   = 0;
    67 #endif
    6864  virtual Void  encodePCMAlignBits()                                          = 0;
    6965  virtual Void  xWritePCMCode     ( UInt uiCode, UInt uiLength )              = 0;
  • trunk/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp

    r56 r296  
    105105}
    106106
    107 #if OL_FLUSH
    108107Void TEncBinCABAC::flush()
    109108{
     
    117116  start();
    118117}
    119 #endif
    120118
    121119/** Reset BAC register and counter values.
     
    127125}
    128126
    129 #if BURST_IPCM
    130127/** Encode # of subsequent IPCM blocks.
    131128 * \param numSubseqIPCM
     
    153150  }
    154151}
    155 #endif
    156152
    157153/** Encode PCM alignment zero bits.
     
    160156Void TEncBinCABAC::encodePCMAlignBits()
    161157{
    162 #if !BURST_IPCM
    163   finish();
    164   m_pcTComBitIf->write( 1, 1 ); // stop bit
    165 #endif
    166158  m_pcTComBitIf->writeAlignZero(); // pcm align zero
    167159}
  • trunk/source/Lib/TLibEncoder/TEncBinCoderCABAC.h

    r56 r296  
    5757  Void  finish            ();
    5858  Void  copyState         ( TEncBinIf* pcTEncBinIf );
    59 #if OL_FLUSH
    6059  Void  flush            ();
    61 #endif
    6260
    6361  Void  resetBac          ();
    64 #if BURST_IPCM
    6562  Void  encodeNumSubseqIPCM( Int numSubseqIPCM );
    66 #endif
    6763  Void  encodePCMAlignBits();
    6864  Void  xWritePCMCode     ( UInt uiCode, UInt uiLength );
  • trunk/source/Lib/TLibEncoder/TEncCavlc.cpp

    r210 r296  
    161161  //DF flag
    162162  WRITE_FLAG(pcAPS->getLoopFilterOffsetInAPS()?1:0, "aps_deblocking_filter_flag");
    163 #if !SAO_UNIT_INTERLEAVING
    164   //SAO flag
    165   WRITE_FLAG( pcAPS->getSaoEnabled()?1:0, "aps_sample_adaptive_offset_flag");
    166 #endif
    167 #if !LCU_SYNTAX_ALF
    168   //ALF flag
    169   WRITE_FLAG( pcAPS->getAlfEnabled()?1:0, "aps_adaptive_loop_filter_flag");
    170 #endif
    171 }
    172 #if LCU_SYNTAX_ALF
     163}
    173164Void TEncCavlc::codeAPSAlflag(UInt uiCode)
    174165{
    175166  WRITE_FLAG(uiCode, "aps_adaptive_loop_filter_flag");
    176167}
    177 #endif
    178168
    179169Void TEncCavlc::codeDFFlag(UInt uiCode, const Char *pSymbolName)
     
    186176}
    187177
    188 #if RPS_IN_SPS
    189178Void TEncCavlc::codeShortTermRefPicSet( TComSPS* pcSPS, TComReferencePictureSet* rps )
    190 #else
    191 Void TEncCavlc::codeShortTermRefPicSet( TComPPS* pcPPS, TComReferencePictureSet* rps )
    192 #endif
    193179{
    194180#if PRINT_RPS_INFO
     
    245231  xTracePPSHeader (pcPPS);
    246232#endif
    247 #if !RPS_IN_SPS
    248   TComRPSList* rpsList = pcPPS->getRPSList();
    249 #endif
    250233 
    251234  WRITE_UVLC( pcPPS->getPPSId(),                             "pic_parameter_set_id" );
    252235  WRITE_UVLC( pcPPS->getSPSId(),                             "seq_parameter_set_id" );
    253236
    254 #if MULTIBITS_DATA_HIDING
    255237  WRITE_FLAG( pcPPS->getSignHideFlag(), "sign_data_hiding_flag" );
    256238  if( pcPPS->getSignHideFlag() )
     
    258240    WRITE_CODE(pcPPS->getTSIG(), 4, "sign_hiding_threshold");
    259241  }
    260 #endif
    261242#if CABAC_INIT_FLAG
    262243  WRITE_FLAG( pcPPS->getCabacInitPresentFlag() ? 1 : 0,   "cabac_init_present_flag" );
    263 #endif
    264 #if !RPS_IN_SPS
    265   // RPS is put before entropy_coding_mode_flag
    266   // since entropy_coding_mode_flag will probably be removed from the WD
    267   TComReferencePictureSet*      rps;
    268 
    269   WRITE_UVLC(rpsList->getNumberOfReferencePictureSets(), "num_short_term_ref_pic_sets" );
    270   for(UInt i=0; i < rpsList->getNumberOfReferencePictureSets(); i++)
    271   {
    272     rps = rpsList->getReferencePictureSet(i);
    273     codeShortTermRefPicSet(pcPPS,rps);
    274   }
    275   WRITE_FLAG( pcPPS->getLongTermRefsPresent() ? 1 : 0,         "long_term_ref_pics_present_flag" );
    276244#endif
    277245  // entropy_coding_mode_flag
     
    280248  if (pcPPS->getEntropyCodingMode())
    281249  {
    282 #if !WPP_SIMPLIFICATION
    283     WRITE_UVLC( pcPPS->getEntropyCodingSynchro(),            "entropy_coding_synchro" );
    284     WRITE_FLAG( pcPPS->getCabacIstateReset() ? 1 : 0,        "cabac_istate_reset" );
    285 #endif
    286 #if !TILES_OR_ENTROPY_SYNC_IDC
    287 #if !WPP_SIMPLIFICATION
    288     if ( pcPPS->getEntropyCodingSynchro() )
    289 #endif
    290     {
    291       WRITE_UVLC( pcPPS->getNumSubstreams()-1,               "num_substreams_minus1" );
    292     }
    293 #endif
    294   }
    295 #if !H0566_TLA
    296   WRITE_UVLC( pcPPS->getNumTLayerSwitchingFlags(),           "num_temporal_layer_switching_point_flags" );
    297   for( UInt i = 0; i < pcPPS->getNumTLayerSwitchingFlags(); i++ )
    298   {
    299     WRITE_FLAG( pcPPS->getTLayerSwitchingFlag( i ) ? 1 : 0 , "temporal_layer_switching_point_flag" );
    300   }
    301 #endif
     250  }
    302251  //   num_ref_idx_l0_default_active_minus1
    303252  //   num_ref_idx_l1_default_active_minus1
     
    313262  WRITE_FLAG( pcPPS->getUseWP() ? 1 : 0,  "weighted_pred_flag" );   // Use of Weighting Prediction (P_SLICE)
    314263  WRITE_CODE( pcPPS->getWPBiPredIdc(), 2, "weighted_bipred_idc" );  // Use of Weighting Bi-Prediction (B_SLICE)
    315 #if H0388
    316264  WRITE_FLAG( pcPPS->getOutputFlagPresentFlag() ? 1 : 0,  "output_flag_present_flag" );
    317 #endif
    318 #if TILES_OR_ENTROPY_SYNC_IDC
    319265  if(pcPPS->getSPS()->getTilesOrEntropyCodingSyncIdc()==1)
    320266  {
    321 #endif
    322267    WRITE_FLAG( pcPPS->getColumnRowInfoPresent(),           "tile_info_present_flag" );
    323268    WRITE_FLAG( pcPPS->getTileBehaviorControlPresentFlag(),  "tile_control_present_flag");
     
    347292      if(iNumColTilesMinus1 !=0 || iNumRowTilesMinus1 !=0)
    348293      {
    349 #if !REMOVE_TILE_DEPENDENCE
    350         WRITE_FLAG( pcPPS->getTileBoundaryIndependenceIdr(),                         "tile_boundary_independence_flag" );
    351         if(pcPPS->getTileBoundaryIndependenceIdr() == 1)
    352         {
    353 #endif
    354294          WRITE_FLAG( pcPPS->getLFCrossTileBoundaryFlag()?1 : 0,            "loop_filter_across_tile_flag");
    355 #if !REMOVE_TILE_DEPENDENCE
    356         }
    357 #endif
    358       }
    359     }
    360 #if TILES_OR_ENTROPY_SYNC_IDC
     295      }
     296    }
    361297  }
    362298  else if(pcPPS->getSPS()->getTilesOrEntropyCodingSyncIdc()==2)
     
    364300    WRITE_UVLC( pcPPS->getNumSubstreams()-1,               "num_substreams_minus1" );
    365301  }
    366 #endif
    367 
    368 #if DBL_CONTROL
     302
    369303  WRITE_FLAG( pcPPS->getDeblockingFilterControlPresent()?1 : 0, "deblocking_filter_control_present_flag");
    370 #endif
    371 #if PARALLEL_MERGE
    372304  WRITE_UVLC( pcPPS->getLog2ParallelMergeLevelMinus2(), "log2_parallel_merge_level_minus2");
    373 #endif
    374305  WRITE_FLAG( 0, "pps_extension_flag" );
    375306}
     
    498429      }
    499430    }
     431#if INTER_VIEW_VECTOR_SCALING_C0115
     432      WRITE_FLAG( pcVPS->getIVScalingFlag(),                      "inter_view_vector_scaling_flag" );
     433#endif
    500434  }
    501435 
     
    508442#endif
    509443#endif
    510 #if HHI_MPI
     444#if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068
    511445Void TEncCavlc::codeSPS( TComSPS* pcSPS, Bool bIsDepth )
    512446#else
     
    528462  WRITE_UVLC( pcSPS->getPicWidthInLumaSamples (),   "pic_width_in_luma_samples" );
    529463  WRITE_UVLC( pcSPS->getPicHeightInLumaSamples(),   "pic_height_in_luma_samples" );
    530 #if PIC_CROPPING
    531464  WRITE_FLAG( pcSPS->getPicCroppingFlag(),          "pic_cropping_flag" );
    532465  if (pcSPS->getPicCroppingFlag())
     
    537470    WRITE_UVLC( pcSPS->getPicCropBottomOffset(),    "pic_crop_bottom_offset" );
    538471  }
    539 #endif
    540472
    541473#if FULL_NBIT
     
    563495
    564496  WRITE_UVLC( pcSPS->getBitsForPOC()-4,                 "log2_max_pic_order_cnt_lsb_minus4" );
    565 #if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
    566497  for(UInt i=0; i <= pcSPS->getMaxTLayers()-1; i++)
    567498  {
     
    570501    WRITE_UVLC( pcSPS->getMaxLatencyIncrease(i),           "max_latency_increase[i]" );
    571502  }
    572 #else
    573   WRITE_UVLC( pcSPS->getMaxNumberOfReferencePictures(), "max_num_ref_pics" );
    574   WRITE_UVLC( pcSPS->getNumReorderFrames(),             "num_reorder_frames" );
    575   WRITE_UVLC(pcSPS->getMaxDecFrameBuffering(),          "max_dec_frame_buffering" );
    576   WRITE_UVLC(pcSPS->getMaxLatencyIncrease(),            "max_latency_increase"    );
    577 #endif
    578503  assert( pcSPS->getMaxCUWidth() == pcSPS->getMaxCUHeight() );
    579504 
     
    586511  }
    587512
    588 #if H0412_REF_PIC_LIST_RESTRICTION
    589513  WRITE_FLAG( pcSPS->getRestrictedRefPicListsFlag(),                                 "restricted_ref_pic_lists_flag" );
    590514  if( pcSPS->getRestrictedRefPicListsFlag() )
     
    592516    WRITE_FLAG( pcSPS->getListsModificationPresentFlag(),                            "lists_modification_present_flag" );
    593517  }
    594 #endif
    595518  WRITE_UVLC( log2MinCUSize - 3,                                                     "log2_min_coding_block_size_minus3" );
    596519  WRITE_UVLC( pcSPS->getMaxCUDepth()-g_uiAddCUDepth,                                 "log2_diff_max_min_coding_block_size" );
     
    618541  WRITE_FLAG( pcSPS->getUseSAO() ? 1 : 0,                                            "sample_adaptive_offset_enabled_flag");
    619542  WRITE_FLAG( pcSPS->getUseALF () ? 1 : 0,                                           "adaptive_loop_filter_enabled_flag");
    620 #if LCU_SYNTAX_ALF
    621543  if(pcSPS->getUseALF())
    622544  {
    623545    WRITE_FLAG( (pcSPS->getUseALFCoefInSlice()) ? 1 : 0,                             "alf_coef_in_slice_flag");
    624546  }
    625 #endif
    626547
    627548  if( pcSPS->getUsePCM() )
     
    634555  WRITE_FLAG( pcSPS->getTemporalIdNestingFlag() ? 1 : 0,                             "temporal_id_nesting_flag" );
    635556
    636 #if RPS_IN_SPS
    637557  TComRPSList* rpsList = pcSPS->getRPSList();
    638558  TComReferencePictureSet*      rps;
     
    645565  }   
    646566  WRITE_FLAG( pcSPS->getLongTermRefsPresent() ? 1 : 0,         "long_term_ref_pics_present_flag" );
    647 #endif
    648 #if !PIC_CROPPING
    649   //!!!KS: Syntax not in WD !!!
    650  
    651   xWriteUvlc  ( pcSPS->getPad (0) );
    652   xWriteUvlc  ( pcSPS->getPad (1) );
    653 #endif
    654567  // AMVP mode for each depth
    655568  for (Int i = 0; i < pcSPS->getMaxCUDepth(); i++)
     
    658571  }
    659572
    660 #if TILES_WPP_ENTRY_POINT_SIGNALLING
    661573  Int tilesOrEntropyCodingSyncIdc = 0;
    662574  if ( pcSPS->getNumColumnsMinus1() > 0 || pcSPS->getNumRowsMinus1() > 0)
     
    670582  pcSPS->setTilesOrEntropyCodingSyncIdc( tilesOrEntropyCodingSyncIdc );
    671583  WRITE_CODE(tilesOrEntropyCodingSyncIdc, 2, "tiles_or_entropy_coding_sync_idc");
    672 #endif
    673 
    674 #if TILES_OR_ENTROPY_SYNC_IDC
     584
    675585  if(tilesOrEntropyCodingSyncIdc == 1)
    676586  {
    677 #endif
    678587    WRITE_UVLC( pcSPS->getNumColumnsMinus1(),                           "num_tile_columns_minus1" );
    679588    WRITE_UVLC( pcSPS->getNumRowsMinus1(),                              "num_tile_rows_minus1" );
     
    694603    if( pcSPS->getNumColumnsMinus1() !=0 || pcSPS->getNumRowsMinus1() != 0)
    695604    {
    696 #if !REMOVE_TILE_DEPENDENCE
    697       WRITE_FLAG( pcSPS->getTileBoundaryIndependenceIdr(),                "tile_boundary_independence_flag" );
    698       if(pcSPS->getTileBoundaryIndependenceIdr() == 1)
    699       {
    700 #endif
    701605        WRITE_FLAG( pcSPS->getLFCrossTileBoundaryFlag()?1 : 0,            "loop_filter_across_tile_flag");
    702 #if !REMOVE_TILE_DEPENDENCE
    703       }
    704 #endif
    705     }
    706 #if TILES_OR_ENTROPY_SYNC_IDC
    707   }
    708 #endif
     606    }
     607  }
    709608  WRITE_FLAG( 1, "sps_extension_flag" );
    710609#if !QC_MVHEVC_B0046
     
    792691          WRITE_SVLC( pcSPS->getPdmOffset       ()[ uiId ], "Pdm_offset" );
    793692        }
    794 #if HHI_INTER_VIEW_MOTION_PRED
     693#if H3D_IVMP
    795694        WRITE_UVLC( pcSPS->getMultiviewMvPredMode(), "multi_view_mv_pred_mode" );
    796695#endif
    797 #if HHI_INTER_VIEW_RESIDUAL_PRED
     696#if H3D_IVRP
    798697        WRITE_FLAG  ( pcSPS->getMultiviewResPredMode(), "multi_view_residual_pred_mode" );
    799698#endif
     
    866765  if (address==0)
    867766  {
    868     if( pcSlice->getSPS()->getViewId() && !pcSlice->getIsDepth() )
     767    if( pcSlice->getSPS()->getViewId()
     768#if !LGE_ILLUCOMP_DEPTH_C0046
     769        && !pcSlice->getIsDepth()
     770#endif
     771        )
    869772    {
    870773      WRITE_FLAG( pcSlice->getApplyIC() ? 1 : 0, "applying IC flag" );
     
    889792    WRITE_UVLC( pcSlice->getPPS()->getPPSId(), "pic_parameter_set_id" );
    890793#endif
    891 #if H0388
    892794    if( pcSlice->getPPS()->getOutputFlagPresentFlag() )
    893795    {
    894796      WRITE_FLAG( pcSlice->getPicOutputFlag() ? 1 : 0, "pic_output_flag" );
    895797    }
    896 #endif
    897798#if QC_REM_IDV_B0046
    898799    if(pcSlice->getNalUnitType()==NAL_UNIT_CODED_SLICE_IDR && pcSlice->getViewId() == 0)
     
    917818        {
    918819          WRITE_FLAG( 0, "short_term_ref_pic_set_sps_flag");
    919 #if RPS_IN_SPS
    920820          codeShortTermRefPicSet(pcSlice->getSPS(), rps);
    921 #else
    922           codeShortTermRefPicSet(pcSlice->getPPS(), rps);
    923 #endif
    924821        }
    925822        else
     
    928825          WRITE_UVLC( pcSlice->getRPSidx(), "short_term_ref_pic_set_idx" );
    929826        }
    930 #if RPS_IN_SPS
    931827        if(pcSlice->getSPS()->getLongTermRefsPresent())
    932 #else
    933         if(pcSlice->getPPS()->getLongTermRefsPresent())
    934 #endif
    935828        {
    936829          WRITE_UVLC( rps->getNumberOfLongtermPictures(), "num_long_term_pics");
    937830          Int maxPocLsb = 1<<pcSlice->getSPS()->getBitsForPOC();
    938831          Int prev = 0;
    939 #if LTRP_MULT
    940832          Int prevDeltaPocLt=0;
    941833          Int currDeltaPocLt=0;
    942 #endif
    943834          for(Int i=rps->getNumberOfPictures()-1 ; i > rps->getNumberOfPictures()-rps->getNumberOfLongtermPictures()-1; i--)
    944835          {
    945836            WRITE_UVLC((maxPocLsb-rps->getDeltaPOC(i)+prev)%maxPocLsb, "delta_poc_lsb_lt");
    946837         
    947 #if LTRP_MULT
    948838            currDeltaPocLt=((maxPocLsb-rps->getDeltaPOC(i)+prev)%maxPocLsb)+prevDeltaPocLt;
    949839
     
    976866            }
    977867            prevDeltaPocLt=currDeltaPocLt;
    978 #endif
    979868            prev = rps->getDeltaPOC(i);
    980869            WRITE_FLAG( rps->getUsed(i), "used_by_curr_pic_lt_flag");
     
    988877        {
    989878          WRITE_FLAG( 0, "short_term_ref_pic_set_sps_flag");
    990 #if RPS_IN_SPS
    991879          codeShortTermRefPicSet(pcSlice->getSPS(), rps);
    992 #else
    993           codeShortTermRefPicSet(pcSlice->getPPS(), rps);
    994 #endif
    995880        }
    996881        else
     
    999884          WRITE_UVLC( pcSlice->getRPSidx(), "short_term_ref_pic_set_idx" );
    1000885        }
    1001 #if RPS_IN_SPS
    1002886        if(pcSlice->getSPS()->getLongTermRefsPresent())
    1003 #else
    1004         if(pcSlice->getPPS()->getLongTermRefsPresent())
    1005 #endif
    1006887        {
    1007888          WRITE_UVLC( rps->getNumberOfLongtermPictures(), "num_long_term_pics");
    1008889          Int maxPocLsb = 1<<pcSlice->getSPS()->getBitsForPOC();
    1009890          Int prev = 0;
    1010 #if LTRP_MULT
    1011891          Int prevDeltaPocLt=0;
    1012892          Int currDeltaPocLt=0;
    1013 #endif
    1014893          for(Int i=rps->getNumberOfPictures()-1 ; i > rps->getNumberOfPictures()-rps->getNumberOfLongtermPictures()-1; i--)
    1015894          {
    1016895            WRITE_UVLC((maxPocLsb-rps->getDeltaPOC(i)+prev)%maxPocLsb, "delta_poc_lsb_lt");
    1017896         
    1018 #if LTRP_MULT
    1019897            currDeltaPocLt=((maxPocLsb-rps->getDeltaPOC(i)+prev)%maxPocLsb)+prevDeltaPocLt;
    1020898
     
    1047925            }
    1048926            prevDeltaPocLt=currDeltaPocLt;
    1049 #endif
    1050927            prev = rps->getDeltaPOC(i);
    1051928            WRITE_FLAG( rps->getUsed(i), "used_by_curr_pic_lt_flag");
     
    1059936      if (pcSlice->getSPS()->getUseALF())
    1060937      {
    1061 #if !LCU_SYNTAX_ALF
    1062          if (pcSlice->getAlfEnabledFlag())
    1063          {
    1064            assert (pcSlice->getAPS()->getAlfEnabled());
    1065          }
    1066 #endif
    1067938         WRITE_FLAG( pcSlice->getAlfEnabledFlag(), "ALF on/off flag in slice header" );
    1068939      }
    1069940      if (pcSlice->getSPS()->getUseSAO())
    1070941      {
    1071 #if SAO_UNIT_INTERLEAVING
    1072942        WRITE_FLAG( pcSlice->getSaoInterleavingFlag(), "SAO interleaving flag" );
    1073 #endif
    1074943         assert (pcSlice->getSaoEnabledFlag() == pcSlice->getAPS()->getSaoEnabled());
    1075944         WRITE_FLAG( pcSlice->getSaoEnabledFlag(), "SAO on/off flag in slice header" );
    1076 #if SAO_UNIT_INTERLEAVING
    1077945         if (pcSlice->getSaoInterleavingFlag()&&pcSlice->getSaoEnabledFlag() )
    1078946         {
     
    1080948           WRITE_FLAG( pcSlice->getAPS()->getSaoParam()->bSaoFlag[2], "SAO on/off flag for Cr in slice header" );
    1081949         }
    1082 #endif
    1083950      }
    1084951      WRITE_UVLC( pcSlice->getAPS()->getAPSID(), "aps_id");
     
    1103970      pcSlice->setNumRefIdx(REF_PIC_LIST_1, 0);
    1104971    }
    1105 #if H0412_REF_PIC_LIST_RESTRICTION
    1106972    if( pcSlice->getSPS()->getListsModificationPresentFlag() )
    1107973    {
    1108 #endif
    1109974    TComRefPicListModification* refPicListModification = pcSlice->getRefPicListModification();
    1110 #if H0137_0138_LIST_MODIFICATION
    1111975    if( !pcSlice->isIntra() )
    1112976    {
     
    11511015      }
    11521016    }
    1153 #else
    1154       if(!pcSlice->isIntra())
    1155       {
    1156         WRITE_FLAG(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL0() ? 1 : 0,       "ref_pic_list_modification_flag" );   
    1157         for(Int i = 0; i < refPicListModification->getNumberOfRefPicListModificationsL0(); i++)
    1158         {
    1159           WRITE_UVLC( refPicListModification->getListIdcL0(i), "ref_pic_list_modification_idc");
    1160           WRITE_UVLC( refPicListModification->getRefPicSetIdxL0(i), "ref_pic_set_idx");
    1161         }
    1162         if(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL0())
    1163           WRITE_UVLC( 3, "ref_pic_list_modification_idc");
    1164       }
    1165       if(pcSlice->isInterB())
    1166       {   
    1167         WRITE_FLAG(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL1() ? 1 : 0,       "ref_pic_list_modification_flag" );
    1168         for(Int i = 0; i < refPicListModification->getNumberOfRefPicListModificationsL1(); i++)
    1169         {
    1170           WRITE_UVLC( refPicListModification->getListIdcL1(i), "ref_pic_list_modification_idc");
    1171           WRITE_UVLC( refPicListModification->getRefPicSetIdxL1(i), "ref_pic_set_idx");
    1172         }
    1173         if(pcSlice->getRefPicListModification()->getRefPicListModificationFlagL1())
    1174           WRITE_UVLC( 3, "ref_pic_list_modification_idc");
    1175       }
    1176 #endif
    1177     }
    1178 #if H0412_REF_PIC_LIST_RESTRICTION
    1179   }
    1180 #endif
     1017    }
     1018  }
    11811019  // ref_pic_list_combination( )
    11821020  // maybe move to own function?
     
    11881026      WRITE_UVLC( pcSlice->getNumRefIdx(REF_PIC_LIST_C) - 1,          "num_ref_idx lc_active_minus1");
    11891027     
    1190 #if H0412_REF_PIC_LIST_RESTRICTION
    11911028      if( pcSlice->getSPS()->getListsModificationPresentFlag() )
    11921029      {
    1193 #endif
    11941030        WRITE_FLAG( pcSlice->getRefPicListModificationFlagLC() ? 1 : 0, "ref_pic_list_modification_flag_lc" );
    11951031        if(pcSlice->getRefPicListModificationFlagLC())
     
    11981034          {
    11991035            WRITE_FLAG( pcSlice->getListIdFromIdxOfLC(i),               "pic_from_list_0_flag" );
    1200 #if H0137_0138_LIST_MODIFICATION
    12011036          if (((pcSlice->getListIdFromIdxOfLC(i)==REF_PIC_LIST_0) && pcSlice->getNumRefIdx( REF_PIC_LIST_0 )>1 ) || ((pcSlice->getListIdFromIdxOfLC(i)==REF_PIC_LIST_1) && pcSlice->getNumRefIdx( REF_PIC_LIST_1 )>1 ) )
    12021037          {
    12031038            WRITE_UVLC( pcSlice->getRefIdxFromIdxOfLC(i),               "ref_idx_list_curr" );
    12041039          }
    1205 #else
    1206             WRITE_UVLC( pcSlice->getRefIdxFromIdxOfLC(i),               "ref_idx_list_curr" );
    1207 #endif
    12081040          }
    12091041        }
    1210 #if H0412_REF_PIC_LIST_RESTRICTION
    1211       }
    1212 #endif
     1042      }
    12131043    }
    12141044  }
    12151045   
    1216 #if H0111_MVD_L1_ZERO
    12171046  if (pcSlice->isInterB())
    12181047  {
    12191048    WRITE_FLAG( pcSlice->getMvdL1ZeroFlag() ? 1 : 0,   "mvd_l1_zero_flag");
    12201049  }
    1221 #endif
    12221050
    12231051  if(pcSlice->getPPS()->getEntropyCodingMode() && !pcSlice->isIntra())
     
    12421070    Int iCode = pcSlice->getSliceQp() - ( pcSlice->getPPS()->getPicInitQPMinus26() + 26 );
    12431071    WRITE_SVLC( iCode, "slice_qp_delta" );
    1244 #if DBL_CONTROL
    12451072    if (pcSlice->getPPS()->getDeblockingFilterControlPresent())
    12461073    {
     
    12491076        WRITE_FLAG(pcSlice->getInheritDblParamFromAPS(), "inherit_dbl_param_from_APS_flag");
    12501077      }
    1251 #else
    1252     WRITE_FLAG(pcSlice->getInheritDblParamFromAPS(), "inherit_dbl_param_from_APS_flag");
    1253 #endif
    12541078      if (!pcSlice->getInheritDblParamFromAPS())
    12551079      {
     
    12611085        }
    12621086      }
    1263 #if DBL_CONTROL
    1264     }
    1265 #endif
     1087    }
    12661088    if ( pcSlice->getSliceType() == B_SLICE )
    12671089    {
     
    12991121  }
    13001122 
    1301 #if ( HHI_MPI || HHI_INTER_VIEW_MOTION_PRED )
    1302   #if ( HHI_MPI && HHI_INTER_VIEW_MOTION_PRED )
     1123#if ( HHI_MPI || H3D_IVMP )
     1124  #if ( HHI_MPI && H3D_IVMP )
    13031125  const int iExtraMergeCandidates = ( pcSlice->getSPS()->getUseMVI() || pcSlice->getSPS()->getMultiviewMvPredMode() ) ? 1 : 0;
    13041126  #elif HHI_MPI
    13051127  const int iExtraMergeCandidates = pcSlice->getSPS()->getUseMVI() ? 1 : 0;
     1128  #elif MTK_DEPTH_MERGE_TEXTURE_CANDIDATE_C0137
     1129  const int iExtraMergeCandidates = ( pcSlice->getIsDepth() || pcSlice->getSPS()->getMultiviewMvPredMode() ) ? 1 : 0;
    13061130  #else
    13071131  const int iExtraMergeCandidates = pcSlice->getSPS()->getMultiviewMvPredMode() ? 1 : 0;
     
    13321156 \param pcSlice Where we find the substream size information.
    13331157 */
    1334 #if TILES_WPP_ENTRY_POINT_SIGNALLING
    13351158Void  TEncCavlc::codeTilesWPPEntryPoint( TComSlice* pSlice )
    13361159{
     
    14321255  delete [] entryPointOffset;
    14331256}
    1434 #else
    1435 Void TEncCavlc::codeSliceHeaderSubstreamTable( TComSlice* pcSlice )
    1436 {
    1437   UInt uiNumSubstreams = pcSlice->getPPS()->getNumSubstreams();
    1438   UInt*puiSubstreamSizes = pcSlice->getSubstreamSizes();
    1439 
    1440   // Write header information for all substreams except the last.
    1441   for (UInt ui = 0; ui+1 < uiNumSubstreams; ui++)
    1442   {
    1443     UInt uiNumbits = puiSubstreamSizes[ui];
    1444 
    1445     //the 2 first bits are used to give the size of the header
    1446     if ( uiNumbits < (1<<8) )
    1447     {
    1448       xWriteCode(0,         2  );
    1449       xWriteCode(uiNumbits, 8  );
    1450     }
    1451     else if ( uiNumbits < (1<<16) )
    1452     {
    1453       xWriteCode(1,         2  );
    1454       xWriteCode(uiNumbits, 16 );
    1455     }
    1456     else if ( uiNumbits < (1<<24) )
    1457     {
    1458       xWriteCode(2,         2  );
    1459       xWriteCode(uiNumbits, 24 );
    1460     }
    1461     else if ( uiNumbits < (1<<31) )
    1462     {
    1463       xWriteCode(3,         2  );
    1464       xWriteCode(uiNumbits, 32 );
    1465     }
    1466     else
    1467     {
    1468       printf("Error in codeSliceHeaderTable\n");
    1469       exit(-1);
    1470     }
    1471   }
    1472 }
    1473 #endif
    14741257
    14751258Void TEncCavlc::codeTerminatingBit      ( UInt uilsLast )
     
    14811264}
    14821265
    1483 #if HHI_INTER_VIEW_MOTION_PRED
     1266#if H3D_IVMP
    14841267Void TEncCavlc::codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList, Int iNum )
    14851268#else
     
    15101293}
    15111294
    1512 #if HHI_INTER_VIEW_RESIDUAL_PRED
     1295#if H3D_IVRP
    15131296Void
    15141297TEncCavlc::codeResPredFlag( TComDataCU* pcCU, UInt uiAbsPartIdx )
     
    15901373}
    15911374
    1592 #if BURST_IPCM
    15931375/** Code I_PCM information.
    15941376 * \param pcCU pointer to CU
     
    16021384  assert(0);
    16031385}
    1604 #else
    1605 /** Code I_PCM information.
    1606  * \param pcCU pointer to CU
    1607  * \param uiAbsPartIdx CU index
    1608  * \returns Void
    1609  *
    1610  * If I_PCM flag indicates that the CU is I_PCM, code its PCM alignment bits and codes. 
    1611  */
    1612 Void TEncCavlc::codeIPCMInfo( TComDataCU* pcCU, UInt uiAbsPartIdx)
    1613 {
    1614   UInt uiIPCM = (pcCU->getIPCMFlag(uiAbsPartIdx) == true)? 1 : 0;
    1615 
    1616   xWriteFlag(uiIPCM);
    1617 
    1618   if (uiIPCM)
    1619   {
    1620     xWritePCMAlignZero();
    1621 
    1622     UInt uiMinCoeffSize = pcCU->getPic()->getMinCUWidth()*pcCU->getPic()->getMinCUHeight();
    1623     UInt uiLumaOffset   = uiMinCoeffSize*uiAbsPartIdx;
    1624     UInt uiChromaOffset = uiLumaOffset>>2;
    1625 
    1626     Pel* piPCMSample;
    1627     UInt uiWidth;
    1628     UInt uiHeight;
    1629     UInt uiSampleBits;
    1630     UInt uiX, uiY;
    1631 
    1632     piPCMSample = pcCU->getPCMSampleY() + uiLumaOffset;
    1633     uiWidth = pcCU->getWidth(uiAbsPartIdx);
    1634     uiHeight = pcCU->getHeight(uiAbsPartIdx);
    1635     uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthLuma();
    1636 
    1637     for(uiY = 0; uiY < uiHeight; uiY++)
    1638     {
    1639       for(uiX = 0; uiX < uiWidth; uiX++)
    1640       {
    1641         UInt uiSample = piPCMSample[uiX];
    1642 
    1643         xWriteCode(uiSample, uiSampleBits);
    1644       }
    1645       piPCMSample += uiWidth;
    1646     }
    1647 
    1648     piPCMSample = pcCU->getPCMSampleCb() + uiChromaOffset;
    1649     uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
    1650     uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
    1651     uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
    1652 
    1653     for(uiY = 0; uiY < uiHeight; uiY++)
    1654     {
    1655       for(uiX = 0; uiX < uiWidth; uiX++)
    1656       {
    1657         UInt uiSample = piPCMSample[uiX];
    1658 
    1659         xWriteCode(uiSample, uiSampleBits);
    1660       }
    1661       piPCMSample += uiWidth;
    1662     }
    1663 
    1664     piPCMSample = pcCU->getPCMSampleCr() + uiChromaOffset;
    1665     uiWidth = pcCU->getWidth(uiAbsPartIdx)/2;
    1666     uiHeight = pcCU->getHeight(uiAbsPartIdx)/2;
    1667     uiSampleBits = pcCU->getSlice()->getSPS()->getPCMBitDepthChroma();
    1668 
    1669     for(uiY = 0; uiY < uiHeight; uiY++)
    1670     {
    1671       for(uiX = 0; uiX < uiWidth; uiX++)
    1672       {
    1673         UInt uiSample = piPCMSample[uiX];
    1674 
    1675         xWriteCode(uiSample, uiSampleBits);
    1676       }
    1677       piPCMSample += uiWidth;
    1678     }
    1679   }
    1680 }
    1681 #endif
    16821386
    16831387Void TEncCavlc::codeIntraDirLumaAng( TComDataCU* pcCU, UInt uiAbsPartIdx )
     
    17101414  Int iDQp  = pcCU->getQP( uiAbsPartIdx ) - pcCU->getRefQP( uiAbsPartIdx );
    17111415
    1712 #if H0736_AVC_STYLE_QP_RANGE
    17131416  Int qpBdOffsetY =  pcCU->getSlice()->getSPS()->getQpBDOffsetY();
    17141417  iDQp = (iDQp + 78 + qpBdOffsetY + (qpBdOffsetY/2)) % (52 + qpBdOffsetY) - 26 - (qpBdOffsetY/2);
    1715 #endif
    17161418
    17171419  xWriteSvlc( iDQp );
     
    17441446  xWriteSvlc( iCode );
    17451447}
    1746 #if LCU_SYNTAX_ALF
    17471448/** Code the fixed length code (smaller than one max value) in OSALF
    17481449 * \param idx:  coded value
     
    17691470  }
    17701471}
    1771 #endif
    17721472
    17731473Void TEncCavlc::codeSaoFlag( UInt uiCode )
     
    17851485    xWriteSvlc( iCode );
    17861486}
    1787 #if SAO_UNIT_INTERLEAVING
    17881487/** Code SAO run.
    17891488 * \param uiCode
     
    18091508  WRITE_CODE( uiCode, uiLength, "sao_run_diff");
    18101509}
    1811 #endif
    18121510
    18131511Void TEncCavlc::estBit( estBitsSbacStruct* pcEstBitsCabac, Int width, Int height, TextType eTType )
     
    21141812Void TEncCavlc::xCodeScalingList(TComScalingList* scalingList, UInt sizeId, UInt listId)
    21151813{
    2116 #if SCALING_LIST
    21171814  Int coefNum = min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId]);
    21181815  UInt* scan    = g_auiFrameScanXY [ (sizeId == 0)? 1 : 2];
    2119 #else
    2120   Int coefNum = (Int)g_scalingListSize[sizeId];
    2121   UInt* scan    = g_auiFrameScanXY [ sizeId + 1];
    2122 #endif
    21231816  Int nextCoef = SCALING_LIST_START_VALUE;
    21241817  Int data;
    21251818  Int *src = scalingList->getScalingListAddress(sizeId, listId);
    2126 #if SCALING_LIST
    21271819  if(sizeId > SCALING_LIST_8x8 && scalingList->getUseDefaultScalingMatrixFlag(sizeId,listId))
    21281820  {
     
    21551847    }
    21561848  }
    2157 #else
    2158   for(Int i=0;i<coefNum;i++)
    2159   {
    2160     data = src[scan[i]] - nextCoef;
    2161     nextCoef = src[scan[i]];
    2162     if(data > 127)
    2163     {
    2164       data = data - 256;
    2165     }
    2166     if(data < -128)
    2167     {
    2168       data = data + 256;
    2169     }
    2170 
    2171     WRITE_SVLC( data,  "delta_coef");
    2172   }
    2173 #endif
    21741849}
    21751850Bool TComScalingList::checkPredMode(UInt sizeId, UInt listId)
     
    21771852  for(Int predListIdx = (Int)listId -1 ; predListIdx >= 0; predListIdx--)
    21781853  {
    2179 #if SCALING_LIST
    21801854    if( !memcmp(getScalingListAddress(sizeId,listId),getScalingListAddress(sizeId, predListIdx),sizeof(Int)*min(MAX_MATRIX_COEF_NUM,(Int)g_scalingListSize[sizeId])) // check value of matrix
    21811855     && ((sizeId < SCALING_LIST_16x16) || (getScalingListDC(sizeId,listId) == getScalingListDC(sizeId,predListIdx)))) // check DC value
    2182 #else
    2183     if( !memcmp(getScalingListAddress(sizeId,listId),getScalingListAddress(sizeId, predListIdx),sizeof(Int)*(Int)g_scalingListSize[sizeId])) // check value of matrix
    2184 #endif
    21851856    {
    21861857      setRefMatrixId(sizeId, listId, predListIdx);
  • trunk/source/Lib/TLibEncoder/TEncCavlc.h

    r210 r296  
    8888  Void  xWriteUnaryMaxSymbol  ( UInt uiSymbol, UInt uiMaxSymbol );
    8989
    90 #if RPS_IN_SPS
    9190  Void codeShortTermRefPicSet              ( TComSPS* pcSPS, TComReferencePictureSet* pcRPS );
    92 #else
    93   Void codeShortTermRefPicSet              ( TComPPS* pcPPS, TComReferencePictureSet* pcRPS );
    94 #endif
    9591 
    9692  UInt  xConvertToUInt        ( Int iValue ) {  return ( iValue <= 0) ? -iValue<<1 : (iValue<<1)-1; }
     
    118114#endif
    119115
    120 #if HHI_MPI
     116#if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068
    121117  Void  codeSPS                 ( TComSPS* pcSPS, Bool bIsDepth );
    122118#else
     
    129125  Void codeTileMarkerFlag(TComSlice* pcSlice);
    130126
    131 #if TILES_WPP_ENTRY_POINT_SIGNALLING
    132127  Void  codeTilesWPPEntryPoint( TComSlice* pSlice );
    133 #else
    134   Void  codeSliceHeaderSubstreamTable( TComSlice* pcSlice );
    135 #endif
    136128  Void  codeTerminatingBit      ( UInt uilsLast );
    137129  Void  codeSliceFinish         ();
     
    139131  Void  encodeStart             () {}
    140132 
    141 #if HHI_INTER_VIEW_MOTION_PRED
     133#if H3D_IVMP
    142134  Void codeMVPIdx ( TComDataCU* pcCU, UInt uiAbsPartIdx, RefPicList eRefList, Int iNum );
    143135#else
     
    148140  Void codeAlfSvlc       ( Int   iCode );
    149141  Void codeAlfCtrlDepth();
    150 #if LCU_SYNTAX_ALF
    151142  Void codeAPSAlflag(UInt uiCode);
    152143  Void codeAlfFixedLengthIdx( UInt idx, UInt numFilterSetsInBuffer);
    153 #endif
    154144  Void codeSaoFlag       ( UInt uiCode );
    155145  Void codeSaoUvlc       ( UInt uiCode );
    156146  Void codeSaoSvlc       ( Int   iCode );
    157 #if SAO_UNIT_INTERLEAVING
    158147  Void codeSaoRun        ( UInt uiCode, UInt maxValue  );
    159148  Void codeSaoMergeLeft  ( UInt uiCode, UInt compIdx ){;}
     
    161150  Void codeSaoTypeIdx    ( UInt uiCode ){ xWriteUvlc(uiCode   );}
    162151  Void codeSaoUflc       ( UInt uiCode ){ assert(uiCode < 32); xWriteCode(uiCode, 5);}
    163 #endif
    164152
    165153  Void codeSkipFlag      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
     
    169157  Void codeMergeFlag     ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    170158  Void codeMergeIndex    ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    171 #if HHI_INTER_VIEW_RESIDUAL_PRED
     159#if H3D_IVRP
    172160  Void codeResPredFlag   ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    173161#endif
     
    189177  Void codePredMode      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    190178 
    191 #if BURST_IPCM
    192179  Void codeIPCMInfo      ( TComDataCU* pcCU, UInt uiAbsPartIdx, Int numIPCM, Bool firstIPCMFlag);
    193 #else
    194   Void codeIPCMInfo      ( TComDataCU* pcCU, UInt uiAbsPartIdx );
    195 #endif
    196180
    197181  Void codeTransformSubdivFlag( UInt uiSymbol, UInt uiCtx );
  • trunk/source/Lib/TLibEncoder/TEncCfg.h

    r210 r296  
    109109  Int       m_iSourceWidth;
    110110  Int       m_iSourceHeight;
    111 #if PIC_CROPPING
    112111  Int       m_croppingMode;
    113112  Int       m_cropLeft;
     
    115114  Int       m_cropTop;
    116115  Int       m_cropBottom;
    117 #endif
    118116  Int       m_iFrameToBeEncoded;
    119117  Double    m_adLambdaModifier[ MAX_TLAYER ];
     
    125123  GOPEntryMvc m_GOPList[MAX_GOP+1];
    126124  Int       m_extraRPSs;
    127 #if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
    128125  Int       m_maxDecPicBuffering[MAX_TLAYER];
    129126  Int       m_numReorderPics[MAX_TLAYER];
    130 #else
    131   Int       m_maxNumberOfReferencePictures;
    132   Int       m_numReorderFrames;
    133 #endif
    134127 
    135128  Int       m_iQP;                              //  if (AdaptiveQP == OFF)
     
    142135                                                 // TODO: We need to have a common sliding mechanism used by both the encoder and decoder
    143136
    144 #if H0566_TLA
    145137  Int       m_maxTempLayer;                      ///< Max temporal layer
    146 #else
    147   Bool      m_bTLayering;                        ///< indicates whether temporal IDs are set based on the hierarchical coding structure
    148   Bool      m_abTLayerSwitchingFlag[MAX_TLAYER]; ///< temporal layer switching flags corresponding to temporal layer
    149 #endif
    150138  Bool      m_bDisInter4x4;
    151139  Bool m_useAMP;
     
    163151  Int       m_loopFilterBetaOffsetDiv2;
    164152  Int       m_loopFilterTcOffsetDiv2;
    165 #if DBL_CONTROL
    166153  Bool      m_DeblockingFilterControlPresent;
    167 #endif
    168154  Bool      m_bUseSAO;
    169155#if LGE_ILLUCOMP_B0045
    170156  Bool      m_bUseIC;
    171157#endif
    172 #if SAO_UNIT_INTERLEAVING
     158#if INTER_VIEW_VECTOR_SCALING_C0115
     159  Bool      m_bUseIVS;
     160#endif
    173161  Int       m_maxNumOffsetsPerPic;
    174162  Bool      m_saoInterleavingFlag;
    175 #endif
    176163
    177164  //====== Lossless ========
     
    229216
    230217  Int       m_iALFMaxNumberFilters;
    231 #if LCU_SYNTAX_ALF
    232218  Bool      m_bALFParamInSlice;
    233219  Bool      m_bALFPicBasedEncode;
    234 #endif
    235220
    236221  Bool      m_bUseASR;
     
    239224  Bool      m_bLCMod;
    240225  Bool      m_bUseRDOQ;
    241 #if !PIC_CROPPING
    242   Bool      m_bUsePAD;
    243 #endif
    244226  Bool      m_bUseFastEnc;
    245227  Bool      m_bUseEarlyCU;
    246228
    247 #if FAST_DECISION_FOR_MRG_RD_COST
    248229  Bool      m_useFastDecisionForMerge;
    249 #endif
    250230  Bool      m_bUseCbfFastMode;
    251231  Bool      m_bUseLMChroma;
     
    305285
    306286  Bool      m_bEnableTMVP;
    307 #if MULTIBITS_DATA_HIDING
    308287  Int       m_signHideFlag;
    309288  Int       m_signHidingThreshold;
    310 #endif
    311289
    312290#if VIDYO_VPS_INTEGRATION|QC_MVHEVC_B0046
     
    349327#endif
    350328
    351 #if HHI_INTER_VIEW_MOTION_PRED
     329#if H3D_IVMP
    352330  UInt        m_uiMultiviewMvPredMode;
    353331  UInt        m_uiMultiviewMvRegMode;
    354332  Double      m_dMultiviewMvRegLambdaScale;
    355333#endif
    356 #if HHI_INTER_VIEW_RESIDUAL_PRED
     334#if H3D_IVRP
    357335  UInt        m_uiMultiviewResPredMode;
    358336#endif
     
    383361  Void      setSourceWidth                  ( Int   i )      { m_iSourceWidth = i; }
    384362  Void      setSourceHeight                 ( Int   i )      { m_iSourceHeight = i; }
    385 #if PIC_CROPPING
    386363  Void      setCroppingMode                 ( Int   i )      { m_croppingMode = i; }
    387364  Void      setCropLeft                     ( Int   i )      { m_cropLeft = i; }
     
    389366  Void      setCropTop                      ( Int   i )      { m_cropTop = i; }
    390367  Void      setCropBottom                   ( Int   i )      { m_cropBottom = i; }
    391 #endif
    392368  Void      setFrameToBeEncoded             ( Int   i )      { m_iFrameToBeEncoded = i; }
    393369 
     
    399375  Void      setExtraRPSs                    ( Int   i )      { m_extraRPSs = i; }
    400376  GOPEntryMvc getGOPEntry                   ( Int   i )      { return m_GOPList[i]; }
    401 #if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
    402377  Void      setMaxDecPicBuffering           ( UInt u, UInt tlayer ) { m_maxDecPicBuffering[tlayer] = u;    }
    403378  Void      setNumReorderPics               ( Int  i, UInt tlayer ) { m_numReorderPics[tlayer] = i;    }
    404 #else
    405   Void      setMaxNumberOfReferencePictures ( Int u )       { m_maxNumberOfReferencePictures = u;    }
    406   Void      setNumReorderFrames             ( Int  i )       { m_numReorderFrames = i;    }
    407 #endif
    408379 
    409380#if HHI_INTERVIEW_SKIP
     
    423394  Void      setMaxRefPicNum                 ( Int iMaxRefPicNum )           { m_iMaxRefPicNum = iMaxRefPicNum;  }
    424395
    425 #if H0566_TLA
    426396  Bool      getMaxTempLayer                 ()                              { return m_maxTempLayer;              }
    427397  Void      setMaxTempLayer                 ( Int maxTempLayer )            { m_maxTempLayer = maxTempLayer;      }
    428 #else
    429   Bool      getTLayering                    ()                              { return m_bTLayering;              }
    430   Void      setTLayering                    ( Bool bTLayering )             { m_bTLayering = bTLayering;        }
    431   Bool      getTLayerSwitchingFlag          ( UInt uiTLayer )               { assert (uiTLayer < MAX_TLAYER ); return  m_abTLayerSwitchingFlag[uiTLayer];                   }
    432   Void      setTLayerSwitchingFlag          ( Bool* pbTLayerSwitchingFlag ) { for ( Int i = 0; i < MAX_TLAYER; i++ ) m_abTLayerSwitchingFlag[i] = pbTLayerSwitchingFlag[i]; }
    433 #endif
    434398
    435399  Bool      getDisInter4x4                  ()              { return m_bDisInter4x4;        }
     
    444408#endif
    445409
    446 #if HHI_INTER_VIEW_MOTION_PRED
     410#if H3D_IVMP
    447411  Void      setMultiviewMvPredMode          ( UInt  u )      { m_uiMultiviewMvPredMode      = u; }
    448412  Void      setMultiviewMvRegMode           ( UInt  u )      { m_uiMultiviewMvRegMode       = u; }
    449413  Void      setMultiviewMvRegLambdaScale    ( Double d)      { m_dMultiviewMvRegLambdaScale = d; }
    450414#endif
    451 #if HHI_INTER_VIEW_RESIDUAL_PRED
     415#if H3D_IVRP
    452416  Void      setMultiviewResPredMode         ( UInt  u )      { m_uiMultiviewResPredMode     = u; }
    453417#endif
     
    467431  Void      setLoopFilterBetaOffset         ( Int   i )      { m_loopFilterBetaOffsetDiv2  = i; }
    468432  Void      setLoopFilterTcOffset           ( Int   i )      { m_loopFilterTcOffsetDiv2    = i; }
    469 #if DBL_CONTROL
    470433  Void      setDeblockingFilterControlPresent ( Bool b ) { m_DeblockingFilterControlPresent = b; }
    471 #endif
    472434
    473435  //====== Motion search ========
     
    479441  Void      setVerticalDisparitySearchRange ( Int   i )      { m_iVerticalDisparitySearchRange = i; }
    480442#endif
    481 #if HHI_INTER_VIEW_MOTION_PRED
     443#if H3D_IVMP
    482444  UInt      getMultiviewMvRegMode           ()      { return  m_uiMultiviewMvRegMode; }
    483445  Double    getMultiviewMvRegLambdaScale    ()      { return  m_dMultiviewMvRegLambdaScale; }
     
    524486  Int       getSourceWidth                  ()      { return  m_iSourceWidth; }
    525487  Int       getSourceHeight                 ()      { return  m_iSourceHeight; }
    526 #if PIC_CROPPING
    527488  Int       getCroppingMode                 ()      { return  m_croppingMode; }
    528489  Int       getCropLeft                     ()      { return  m_cropLeft; }
     
    530491  Int       getCropTop                      ()      { return  m_cropTop; }
    531492  Int       getCropBottom                   ()      { return  m_cropBottom; }
    532 #endif
    533493  Int       getFrameToBeEncoded             ()      { return  m_iFrameToBeEncoded; }
    534494  void setLambdaModifier                    ( UInt uiIndex, Double dValue ) { m_adLambdaModifier[ uiIndex ] = dValue; }
     
    539499  UInt      getDecodingRefreshType          ()      { return  m_uiDecodingRefreshType; }
    540500  Int       getGOPSize                      ()      { return  m_iGOPSize; }
    541 #if H0567_DPB_PARAMETERS_PER_TEMPORAL_LAYER
    542501  Int       getMaxDecPicBuffering           (UInt tlayer) { return m_maxDecPicBuffering[tlayer]; }
    543502  Int       getNumReorderPics               (UInt tlayer) { return m_numReorderPics[tlayer]; }
    544 #else
    545   Int      getMaxNumberOfReferencePictures ()      { return m_maxNumberOfReferencePictures; }
    546   Int       geNumReorderFrames              ()      { return m_numReorderFrames; }
    547 #endif
    548503  Int       getQP                           ()      { return  m_iQP; }
    549504 
     
    562517  Int       getLoopFilterBetaOffset         ()      { return m_loopFilterBetaOffsetDiv2; }
    563518  Int       getLoopFilterTcOffset           ()      { return m_loopFilterTcOffsetDiv2; }
    564 #if DBL_CONTROL
    565519  Bool      getDeblockingFilterControlPresent()  { return  m_DeblockingFilterControlPresent; }
    566 #endif
    567520
    568521  //==== Motion search ========
     
    607560  Void      setLCMod                        ( Bool  b )     { m_bLCMod   = b;    }
    608561  Void      setUseRDOQ                      ( Bool  b )     { m_bUseRDOQ    = b; }
    609 #if !PIC_CROPPING
    610   Void      setUsePAD                       ( Bool  b )     { m_bUsePAD     = b; }
    611 #endif
    612562#if HHI_VSO
    613563  Void      setUseVSO                       ( Bool  b )     { m_bUseVSO     = b; }
     
    621571  Void      setUseFastEnc                   ( Bool  b )     { m_bUseFastEnc = b; }
    622572  Void      setUseEarlyCU                   ( Bool  b )     { m_bUseEarlyCU = b; }
    623 #if FAST_DECISION_FOR_MRG_RD_COST
    624573  Void      setUseFastDecisionForMerge      ( Bool  b )     { m_useFastDecisionForMerge = b; }
    625 #endif
    626574  Void      setUseCbfFastMode            ( Bool  b )     { m_bUseCbfFastMode = b; }
    627575  Void      setUseConstrainedIntraPred      ( Bool  b )     { m_bUseConstrainedIntraPred = b; }
     
    642590  Void      setALFMaxNumberFilters          (Int i)  { m_iALFMaxNumberFilters = i; }
    643591  Int       getALFMaxNumberFilters          ()       { return m_iALFMaxNumberFilters; }
    644 #if LCU_SYNTAX_ALF
    645592  Void      setALFParamInSlice              (Bool b) {m_bALFParamInSlice = b;}
    646593  Bool      getALFParamInSlice              ()       {return m_bALFParamInSlice;}
    647594  Void      setALFPicBasedEncode            (Bool b) {m_bALFPicBasedEncode = b;}
    648595  Bool      getALFPicBasedEncode            ()       {return m_bALFPicBasedEncode;}
    649 #endif
    650596
    651597  Bool      getUseLComb                     ()      { return m_bUseLComb;   }
    652598  Bool      getLCMod                        ()      { return m_bLCMod; }
    653599  Bool      getUseRDOQ                      ()      { return m_bUseRDOQ;    }
    654 #if !PIC_CROPPING
    655   Bool      getUsePAD                       ()      { return m_bUsePAD;     }
    656 #endif
    657600
    658601#if HHI_VSO
     
    666609  Bool      getUseFastEnc                   ()      { return m_bUseFastEnc; }
    667610  Bool      getUseEarlyCU                   ()      { return m_bUseEarlyCU; }
    668 #if FAST_DECISION_FOR_MRG_RD_COST
    669611  Bool      getUseFastDecisionForMerge      ()      { return m_useFastDecisionForMerge; }
    670 #endif
    671612  Bool      getUseCbfFastMode           ()      { return m_bUseCbfFastMode; }
    672613  Bool      getUseConstrainedIntraPred      ()      { return m_bUseConstrainedIntraPred; }
     
    714655  Bool  getUseIC                       ()              {return m_bUseIC;}
    715656#endif
    716 #if SAO_UNIT_INTERLEAVING
     657#if INTER_VIEW_VECTOR_SCALING_C0115
     658  Void  setUseIVS                       ( Bool bVal )   {m_bUseIVS = bVal;}
     659  Bool  getUseIVS                       ()              {return m_bUseIVS;}
     660#endif
    717661  Void  setMaxNumOffsetsPerPic                   (Int iVal)            { m_maxNumOffsetsPerPic = iVal; }
    718662  Int   getMaxNumOffsetsPerPic                   ()                    { return m_maxNumOffsetsPerPic; }
    719663  Void  setSaoInterleavingFlag                   (bool bVal)           { m_saoInterleavingFlag = bVal; }
    720664  Bool  getSaoInterleavingFlag                   ()                    { return m_saoInterleavingFlag; }
    721 #endif
    722665  Void  setTileBehaviorControlPresentFlag        ( Int i )             { m_iTileBehaviorControlPresentFlag = i;    }
    723666  Int   getTileBehaviorControlPresentFlag        ()                    { return m_iTileBehaviorControlPresentFlag; }
     
    728671  Void  setUniformSpacingIdr           ( Int i )           { m_iUniformSpacingIdr = i; }
    729672  Int   getUniformSpacingIdr           ()                  { return m_iUniformSpacingIdr; }
    730 #if !REMOVE_TILE_DEPENDENCE
    731   Void  setTileBoundaryIndependenceIdr ( Int i )           { m_iTileBoundaryIndependenceIdr = i; }
    732   Int   getTileBoundaryIndependenceIdr ()                  { return m_iTileBoundaryIndependenceIdr; }
    733 #endif
    734673  Void  setNumColumnsMinus1            ( Int i )           { m_iNumColumnsMinus1 = i; }
    735674  Int   getNumColumnsMinus1            ()                  { return m_iNumColumnsMinus1; }
     
    827766  Void      setEnableTMVP          ( Bool b )    { m_bEnableTMVP = b;    }
    828767  Bool      getEnableTMVP          ()            { return m_bEnableTMVP; }
    829 #if MULTIBITS_DATA_HIDING
    830768  Void      setSignHideFlag( Int signHideFlag )  { m_signHideFlag = signHideFlag; }
    831769  Void      setTSIG( Int tsig )                  { m_signHidingThreshold = tsig; }
    832770  Int       getSignHideFlag()                    { return m_signHideFlag; }
    833771  Int       getTSIG()                            { return m_signHidingThreshold; }
    834 #endif
    835772#if VIDYO_VPS_INTEGRATION |QC_MVHEVC_B0046
    836773  Void      setLayerId             ( UInt layerId )   { m_layerId = layerId; }
     
    869806  Void      setCodedOffset                  ( Int** p )      { m_aaiCodedOffset         = p; }
    870807
    871 #if SONY_COLPIC_AVAILABILITY
    872   Int       getViewOrderIdx                 ()      { return  m_iViewOrderIdx; }
     808#if INTER_VIEW_VECTOR_SCALING_C0115
     809  Int       getViewOrderIdx                 ()      { return  m_iViewOrderIdx; }    // will be changed to view_id
    873810#endif
    874811};
  • trunk/source/Lib/TLibEncoder/TEncCu.cpp

    r189 r296  
    7272  m_ppcRecoYuvTemp = new TComYuv*[m_uhTotalDepth-1];
    7373  m_ppcOrigYuv     = new TComYuv*[m_uhTotalDepth-1];
    74 #if HHI_INTER_VIEW_RESIDUAL_PRED
     74#if H3D_IVRP
    7575  m_ppcResPredTmp  = new TComYuv*[m_uhTotalDepth-1];
    7676#endif
     
    101101   
    102102    m_ppcOrigYuv    [i] = new TComYuv; m_ppcOrigYuv    [i]->create(uiWidth, uiHeight);
    103 #if HHI_INTER_VIEW_RESIDUAL_PRED
     103#if H3D_IVRP
    104104    m_ppcResPredTmp [i] = new TComYuv; m_ppcResPredTmp [i]->create(uiWidth, uiHeight);
    105105#endif
     
    107107 
    108108  m_bEncodeDQP = false;
    109 #if BURST_IPCM
    110109  m_checkBurstIPCMFlag = false;
    111 #endif
    112110
    113111  // initialize partition order.
     
    168166      m_ppcOrigYuv[i]->destroy();     delete m_ppcOrigYuv[i];     m_ppcOrigYuv[i] = NULL;
    169167    }
    170 #if HHI_INTER_VIEW_RESIDUAL_PRED
     168#if H3D_IVRP
    171169    if(m_ppcResPredTmp[i])
    172170    {
     
    221219    m_ppcOrigYuv = NULL;
    222220  }
    223 #if HHI_INTER_VIEW_RESIDUAL_PRED
     221#if H3D_IVRP
    224222  if(m_ppcResPredTmp)
    225223  {
     
    285283  }
    286284
    287 #if BURST_IPCM
    288285  TComPic* pcPic = pcCU->getPic();
    289286  Bool checkBurstIPCMFlag = (pcPic->getSlice(0)->getSPS()->getUsePCM())? true : false;
     
    293290  pcCU->setNumSucIPCM(0);
    294291  pcCU->setLastCUSucIPCMFlag(false);
    295 #endif
    296292
    297293  // Encode CU data
    298294  xEncodeCU( pcCU, 0, 0 );
    299295 
    300 #if OL_FLUSH
    301296  bool bTerminateSlice = bForceTerminate;
    302297  UInt uiCUAddr = pcCU->getAddr();
    303298    /* If at the end of an LCU line but not at the end of a substream, perform CABAC flush */
    304 #if WPP_SIMPLIFICATION
    305299    if (!bTerminateSlice && pcCU->getSlice()->getPPS()->getNumSubstreams() > 1)
    306 #else
    307     if (!bTerminateSlice && pcCU->getSlice()->getPPS()->getCabacIstateReset())
    308 #endif
    309300    {
    310301      Int iNumSubstreams = pcCU->getSlice()->getPPS()->getNumSubstreams();
     
    312303      UInt uiCol     = uiCUAddr % uiWidthInLCUs;
    313304      UInt uiLin     = uiCUAddr / uiWidthInLCUs;
    314 #if !REMOVE_TILE_DEPENDENCE
    315       Int iBreakDep = pcCU->getPic()->getPicSym()->getTileBoundaryIndependenceIdr();
    316 #endif
    317305      UInt uiTileStartLCU = pcCU->getPic()->getPicSym()->getTComTile(pcCU->getPic()->getPicSym()->getTileIdxMap(uiCUAddr))->getFirstCUAddr();
    318306      UInt uiTileLCUX = uiTileStartLCU % uiWidthInLCUs;
     
    321309      UInt uiTileHeight = pcCU->getPic()->getPicSym()->getTComTile(pcCU->getPic()->getPicSym()->getTileIdxMap(uiCUAddr))->getTileHeight();
    322310      Int iNumSubstreamsPerTile = iNumSubstreams;
    323 #if !REMOVE_TILE_DEPENDENCE
    324 #if WPP_SIMPLIFICATION
    325       if (iBreakDep && pcCU->getSlice()->getPPS()->getNumSubstreams() > 1)
    326 #else
    327       if (iBreakDep && pcCU->getSlice()->getPPS()->getEntropyCodingSynchro())
    328 #endif
     311      if (pcCU->getSlice()->getPPS()->getNumSubstreams() > 1)
     312      {
    329313        iNumSubstreamsPerTile /= pcCU->getPic()->getPicSym()->getNumTiles();
    330       if ((iBreakDep && (uiCol == uiTileLCUX+uiTileWidth-1) && (uiLin+iNumSubstreamsPerTile < uiTileLCUY+uiTileHeight))
    331           || (!iBreakDep && (uiCol == uiWidthInLCUs-1) && (uiLin+iNumSubstreams < pcCU->getPic()->getFrameHeightInCU())))
     314      }
     315      if ((uiCol == uiTileLCUX+uiTileWidth-1) && (uiLin+iNumSubstreamsPerTile < uiTileLCUY+uiTileHeight))
    332316      {
    333317        m_pcEntropyCoder->encodeFlush();
    334318      }
    335 #else
    336 #if WPP_SIMPLIFICATION
    337       if (pcCU->getSlice()->getPPS()->getNumSubstreams() > 1)
    338 #else
    339       if (pcCU->getSlice()->getPPS()->getEntropyCodingSynchro())
    340 #endif
    341       {
    342         iNumSubstreamsPerTile /= pcCU->getPic()->getPicSym()->getNumTiles();
    343       }
    344       if ((uiCol == uiTileLCUX+uiTileWidth-1) && (uiLin+iNumSubstreamsPerTile < uiTileLCUY+uiTileHeight))
    345       {
    346         m_pcEntropyCoder->encodeFlush();
    347       }
    348 #endif
    349     }
    350 #endif // OL_FLUSH
     319    }
    351320}
    352321
     
    458427  Bool  bIntraSliceDetect = (rpcBestCU->getSlice()->getSliceType() == I_SLICE);
    459428
     429#if HHI_QTLPC_RAU_OFF_C0160
     430  Bool rapPic     = (rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA);
     431#endif
     432
    460433  Bool bTry2NxN = true;
    461434  Bool bTryNx2N = true;
     
    494467
    495468#if LGE_ILLUCOMP_B0045
    496   Bool bICEnabled = (!rpcTempCU->getSlice()->getIsDepth() && rpcTempCU->getSlice()->getViewId());
     469  Bool bICEnabled = (
     470#if !LGE_ILLUCOMP_DEPTH_C0046
     471      !rpcTempCU->getSlice()->getIsDepth() &&
     472#endif
     473      rpcTempCU->getSlice()->getViewId());
    497474
    498475  bICEnabled = bICEnabled && rpcTempCU->getSlice()->getApplyIC();
     
    548525#if LOSSLESS_CODING
    549526  Bool isAddLowestQP = false;
    550 #if H0736_AVC_STYLE_QP_RANGE
    551527  Int lowestQP = -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY();
    552 #else
    553   Int lowestQP = 0;
    554 #endif
    555528#endif
    556529
     
    558531  {
    559532    Int idQP = m_pcEncCfg->getMaxDeltaQP();
    560 #if H0736_AVC_STYLE_QP_RANGE
    561533    iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
    562534    iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
     
    568540
    569541    }
    570 #endif
    571 #else
    572     iMinQP = Clip3( MIN_QP, MAX_QP, iBaseQP-idQP );
    573     iMaxQP = Clip3( MIN_QP, MAX_QP, iBaseQP+idQP );
    574 #if LOSSLESS_CODING
    575     if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )
    576     {
    577       isAddLowestQP = true;
    578       iMinQP = iMinQP - 1;
    579     }
    580 #endif
    581542#endif
    582543  }
     
    612573#if OL_QTLIMIT_PREDCODING_B0068
    613574      //logic for setting bTrySplit using the partition information that is stored of the texture colocated CU
     575
     576#if HHI_QTLPC_RAU_OFF_C0160
     577      if(depthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTLPC())
     578#else
    614579      if(depthMapDetect && !bIntraSliceDetect && sps->getUseQTLPC())
     580#endif
    615581      {
    616582        TComDataCU* pcTextureCU = pcTexture->getCU( rpcBestCU->getAddr() ); //Corresponding texture LCU
     
    635601      if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
    636602      {
    637 #if HHI_INTER_VIEW_RESIDUAL_PRED
     603#if H3D_IVRP
     604#if MTK_MDIVRP_C0138
     605        Bool  bResPredAvailable   = false;
     606        UInt uiResPrdId = 0;
     607#else
    638608        // check availability of residual prediction
    639609        Bool  bResPredAvailable   = false;
     
    643613        if( bResPredAllowed )
    644614        {
    645           bResPredAvailable       = rpcBestCU->getResidualSamples( 0,
    646 #if QC_SIMPLIFIEDIVRP_M24938
    647             true ,
    648 #endif
    649             m_ppcResPredTmp[uiDepth] );
     615          bResPredAvailable       = rpcBestCU->getResidualSamples( 0, true , m_ppcResPredTmp[uiDepth] );
    650616        }
    651617
    652618        for( UInt uiResPrdId = 0; uiResPrdId < ( bResPredAvailable ? 2 : 1 ); uiResPrdId++ )
     619#endif
    653620        {
    654621          Bool bResPredFlag  = ( uiResPrdId > 0 );
     
    660627#endif
    661628#endif
    662 #if HHI_INTER_VIEW_RESIDUAL_PRED
     629#if H3D_IVRP
    663630          rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag );
    664631#endif
     
    691658          if ( !bEarlySkip )
    692659          {
    693 #if HHI_INTER_VIEW_RESIDUAL_PRED
     660#if H3D_IVRP
    694661            rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag );
     662#endif
     663#if FIX_LGE_ILLUCOMP_B0045
     664            rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
    695665#endif
    696666#if HHI_INTERVIEW_SKIP
     
    709679         }
    710680#endif
    711 #if HHI_INTER_VIEW_RESIDUAL_PRED
     681#if H3D_IVRP
    712682        } // uiResPrdId
    713683#endif
     
    719689
    720690#if OL_QTLIMIT_PREDCODING_B0068
     691
     692#if HHI_QTLPC_RAU_OFF_C0160
     693      if(depthMapDetect && !bIntraSliceDetect && !rapPic && sps->getUseQTLPC())
     694#else
    721695      if(depthMapDetect && !bIntraSliceDetect  && sps->getUseQTLPC())
     696#endif
    722697      {
    723698        bTrySplitDQP = bTrySplit;
     
    763738      if( rpcBestCU->getSlice()->getSliceType() != I_SLICE )
    764739      {
    765 #if HHI_INTER_VIEW_RESIDUAL_PRED
     740#if H3D_IVRP
     741#if MTK_MDIVRP_C0138
     742        Bool  bResPredAvailable   = false;
     743        UInt uiResPrdId = 0;
     744#else
    766745        // check availability of residual prediction
    767746        Bool  bResPredAvailable   = false;
     
    771750        if( bResPredAllowed )
    772751        {
    773           bResPredAvailable       = rpcBestCU->getResidualSamples( 0,
    774 #if QC_SIMPLIFIEDIVRP_M24938
    775             true,
    776 #endif
    777             m_ppcResPredTmp[uiDepth] );
     752          bResPredAvailable       = rpcBestCU->getResidualSamples( 0, true, m_ppcResPredTmp[uiDepth] );
    778753        }
    779754
    780755        for( UInt uiResPrdId = 0; uiResPrdId < ( bResPredAvailable ? 2 : 1 ); uiResPrdId++ )
     756#endif
    781757        {
    782758          Bool bResPredFlag  = ( uiResPrdId > 0 );
     
    800776                {
    801777#endif
    802 #if HHI_INTER_VIEW_RESIDUAL_PRED
     778#if H3D_IVRP
    803779                  rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag );
    804780#endif
     
    823799              if(doNotBlockPu)
    824800              {
    825 #if HHI_INTER_VIEW_RESIDUAL_PRED
     801#if H3D_IVRP
    826802                rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag );
     803#endif
     804#if FIX_LGE_ILLUCOMP_B0045
     805                rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
    827806#endif
    828807#if HHI_INTERVIEW_SKIP
     
    847826              if(doNotBlockPu)
    848827              {
    849 #if HHI_INTER_VIEW_RESIDUAL_PRED
     828#if H3D_IVRP
    850829                rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag );
     830#endif
     831#if FIX_LGE_ILLUCOMP_B0045
     832                rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
    851833#endif
    852834#if HHI_INTERVIEW_SKIP
     
    890872                if(doNotBlockPu)
    891873                {
    892 #if HHI_INTER_VIEW_RESIDUAL_PRED
     874#if H3D_IVRP
    893875                  rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag );
     876#endif
     877#if FIX_LGE_ILLUCOMP_B0045
     878                  rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
    894879#endif
    895880#if HHI_INTERVIEW_SKIP
     
    906891                if(doNotBlockPu)
    907892                {
    908 #if HHI_INTER_VIEW_RESIDUAL_PRED
     893#if H3D_IVRP
    909894                  rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag );
     895#endif
     896#if FIX_LGE_ILLUCOMP_B0045
     897                  rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
    910898#endif
    911899#if HHI_INTERVIEW_SKIP
     
    933921                if(doNotBlockPu)
    934922                {
    935 #if HHI_INTER_VIEW_RESIDUAL_PRED
     923#if H3D_IVRP
    936924                  rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag );
     925#endif
     926#if FIX_LGE_ILLUCOMP_B0045
     927                  rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
    937928#endif
    938929#if HHI_INTERVIEW_SKIP
     
    949940                if(doNotBlockPu)
    950941                {
    951 #if HHI_INTER_VIEW_RESIDUAL_PRED
     942#if H3D_IVRP
    952943                  rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag );
     944#endif
     945#if FIX_LGE_ILLUCOMP_B0045
     946                  rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
    953947#endif
    954948#if HHI_INTERVIEW_SKIP
     
    978972                if(doNotBlockPu)
    979973                {
    980 #if HHI_INTER_VIEW_RESIDUAL_PRED
     974#if H3D_IVRP
    981975                  rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag );
     976#endif
     977#if FIX_LGE_ILLUCOMP_B0045
     978                  rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
    982979#endif
    983980#if HHI_INTERVIEW_SKIP
     
    994991                if(doNotBlockPu)
    995992                {
    996 #if HHI_INTER_VIEW_RESIDUAL_PRED
     993#if H3D_IVRP
    997994                  rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag );
     995#endif
     996#if FIX_LGE_ILLUCOMP_B0045
     997                  rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
    998998#endif
    999999#if HHI_INTERVIEW_SKIP
     
    10171017                if(doNotBlockPu)
    10181018                {
    1019 #if HHI_INTER_VIEW_RESIDUAL_PRED
     1019#if H3D_IVRP
    10201020                  rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag );
     1021#endif
     1022#if FIX_LGE_ILLUCOMP_B0045
     1023                  rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
    10211024#endif
    10221025#if HHI_INTERVIEW_SKIP
     
    10331036                if(doNotBlockPu)
    10341037                {
    1035 #if HHI_INTER_VIEW_RESIDUAL_PRED
     1038#if H3D_IVRP
    10361039                  rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag );
     1040#endif
     1041#if FIX_LGE_ILLUCOMP_B0045
     1042                  rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
    10371043#endif
    10381044#if HHI_INTERVIEW_SKIP
     
    10501056
    10511057#else
    1052 #if HHI_INTER_VIEW_RESIDUAL_PRED
     1058#if H3D_IVRP
    10531059            rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag );
    10541060#endif
     
    10591065#endif
    10601066            rpcTempCU->initEstData( uiDepth, iQP );
    1061 #if HHI_INTER_VIEW_RESIDUAL_PRED
     1067#if H3D_IVRP
    10621068            rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag );
    10631069#endif
     
    10681074#endif
    10691075            rpcTempCU->initEstData( uiDepth, iQP );
    1070 #if HHI_INTER_VIEW_RESIDUAL_PRED
     1076#if H3D_IVRP
    10711077            rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag );
    10721078#endif
     
    10771083#endif
    10781084            rpcTempCU->initEstData( uiDepth, iQP );
    1079 #if HHI_INTER_VIEW_RESIDUAL_PRED
     1085#if H3D_IVRP
    10801086            rpcTempCU->setResPredIndicator( bResPredAvailable, bResPredFlag );
    10811087#endif
     
    10931099         }
    10941100#endif
    1095 #if HHI_INTER_VIEW_RESIDUAL_PRED
     1101#if H3D_IVRP
    10961102        } // uiResPrdId
    10971103#endif
     
    11031109
    11041110      // do normal intra modes
    1105       if ( !bEarlySkip )
     1111      if ( !bEarlySkip
     1112#if HHI_DEPTH_INTRA_SEARCH_RAU_C0160
     1113        || ((rpcBestCU->getSlice()->getIsDepth() == true) && (rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA))
     1114#endif
     1115        )
    11061116      {
    11071117        // speedup for inter frames
     
    11101120          rpcBestCU->getCbf( 0, TEXT_LUMA     ) != 0   ||
    11111121          rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0   ||
    1112           rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0 ) && !bFullyRenderedSec ) // avoid very complex intra if it is unlikely
     1122          rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0
     1123#if HHI_DEPTH_INTRA_SEARCH_RAU_C0160
     1124          || ((rpcBestCU->getSlice()->getIsDepth() == true) && (rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA))
     1125#endif           
     1126          ) && !bFullyRenderedSec ) // avoid very complex intra if it is unlikely
    11131127#else
    11141128        if( rpcBestCU->getSlice()->getSliceType() == I_SLICE ||
    11151129          rpcBestCU->getCbf( 0, TEXT_LUMA     ) != 0   ||
    11161130          rpcBestCU->getCbf( 0, TEXT_CHROMA_U ) != 0   ||
    1117           rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0     ) // avoid very complex intra if it is unlikely
     1131          rpcBestCU->getCbf( 0, TEXT_CHROMA_V ) != 0     
     1132#if HHI_DEPTH_INTRA_SEARCH_RAU_C0160
     1133          || ((rpcBestCU->getSlice()->getIsDepth() == true) && (rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_IDR || rpcBestCU->getSlice()->getNalUnitType() == NAL_UNIT_CODED_SLICE_CRA))
     1134#endif     
     1135          ) // avoid very complex intra if it is unlikely
    11181136#endif
    11191137        {
     
    11681186      if( rpcBestCU->getSlice()->getSPS()->getUseMVI() && rpcBestCU->getSlice()->getSliceType() != I_SLICE )
    11691187      {
     1188#if LGE_ILLUCOMP_DEPTH_C0046
     1189        for(UInt uiICId = 0; uiICId < (bICEnabled ? 2 : 1); uiICId++)
     1190        {
     1191          Bool bICFlag = (uiICId ? true : false);
     1192          rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
     1193#endif
    11701194        xCheckRDCostMvInheritance( rpcBestCU, rpcTempCU, uiDepth, false, false );
    11711195        rpcTempCU->initEstData( uiDepth, iQP );
     1196#if FIX_ILLUCOMP_DEPTH
     1197        rpcTempCU->setICFlagSubParts(bICFlag, 0, 0, uiDepth);
     1198#endif
    11721199        xCheckRDCostMvInheritance( rpcBestCU, rpcTempCU, uiDepth, true, false );
    11731200        rpcTempCU->initEstData( uiDepth, iQP );
     1201#if LGE_ILLUCOMP_DEPTH_C0046
     1202        }
     1203#endif
    11741204      }
    11751205#endif
     
    12401270  {
    12411271    Int idQP = m_pcEncCfg->getMaxDeltaQP();
    1242 #if H0736_AVC_STYLE_QP_RANGE
    12431272    iMinQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP-idQP );
    12441273    iMaxQP = Clip3( -rpcTempCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQP+idQP );
     
    12491278      iMinQP = iMinQP - 1;     
    12501279    }
    1251 #endif
    1252 #else
    1253     iMinQP = Clip3( MIN_QP, MAX_QP, iBaseQP-idQP );
    1254     iMaxQP = Clip3( MIN_QP, MAX_QP, iBaseQP+idQP );
    1255 #if LOSSLESS_CODING
    1256     if ( (rpcTempCU->getSlice()->getSPS()->getUseLossless()) && (lowestQP < iMinQP) && rpcTempCU->getSlice()->getPPS()->getUseDQP() )
    1257     {
    1258       isAddLowestQP = true;
    1259       iMinQP = iMinQP - 1;
    1260     }
    1261 #endif
    12621280#endif
    12631281  }
     
    15581576    &&((uiPosY+pcCU->getHeight(uiAbsPartIdx))%uiGranularityWidth==0||(uiPosY+pcCU->getHeight(uiAbsPartIdx)==uiHeight));
    15591577 
    1560 #if BURST_IPCM
    15611578  if(granularityBoundary && (!(pcCU->getIPCMFlag(uiAbsPartIdx) && ( pcCU->getNumSucIPCM() > 1 ))))
    1562 #else
    1563   if(granularityBoundary)
    1564 #endif
    15651579  {
    15661580    // The 1-terminating bit is added to all streams, so don't add it here when it's 1.
     
    16541668    iQpOffset = Int(floor( dQpOffset + 0.49999 ));
    16551669  }
    1656 #if H0736_AVC_STYLE_QP_RANGE
    16571670  return Clip3(-pcCU->getSlice()->getSPS()->getQpBDOffsetY(), MAX_QP, iBaseQp+iQpOffset );
    1658 #else
    1659   return Clip3( MIN_QP, MAX_QP, iBaseQp+iQpOffset );
    1660 #endif
    16611671}
    16621672
     
    16771687  UInt uiBPelY   = uiTPelY + (g_uiMaxCUHeight>>uiDepth) - 1;
    16781688 
    1679 #if BURST_IPCM
    16801689  if( getCheckBurstIPCMFlag() )
    16811690  {
     
    16831692    pcCU->setNumSucIPCM( countNumSucIPCM ( pcCU, uiAbsPartIdx ) );
    16841693  }
    1685 #endif
    16861694
    16871695  TComSlice * pcSlice = pcCU->getPic()->getSlice(pcCU->getPic()->getCurrSliceIdx());
     
    17281736    {
    17291737      m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx, 0 );
     1738#if LGE_ILLUCOMP_DEPTH_C0046
     1739      m_pcEntropyCoder->encodeICFlag  ( pcCU, uiAbsPartIdx, false, uiDepth );
     1740#endif
    17301741      finishCU(pcCU,uiAbsPartIdx,uiDepth);
    17311742      xRestoreDepthWidthHeight( pcCU );
     
    17391750    // prediction Info ( Intra : direction mode, Inter : Mv, reference idx )
    17401751    m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx );
     1752#if LGE_ILLUCOMP_DEPTH_C0046
     1753    m_pcEntropyCoder->encodeICFlag  ( pcCU, uiAbsPartIdx, false, uiDepth );
     1754#endif
    17411755    xRestoreDepthWidthHeight( pcCU );
    17421756  }
     
    17501764      setdQPFlag(true);
    17511765    }
    1752 #if BURST_IPCM
    17531766    pcCU->setNumSucIPCM(0);
    17541767    pcCU->setLastCUSucIPCMFlag(false);
    1755 #endif
    17561768    for ( UInt uiPartUnitIdx = 0; uiPartUnitIdx < 4; uiPartUnitIdx++, uiAbsPartIdx+=uiQNumParts )
    17571769    {
     
    17871799    m_pcEntropyCoder->encodeMergeIndex( pcCU, uiAbsPartIdx, 0 );
    17881800#if LGE_ILLUCOMP_B0045
    1789     m_pcEntropyCoder->encodeICFlag  ( pcCU, uiAbsPartIdx );
    1790 #endif
    1791 #if HHI_INTER_VIEW_RESIDUAL_PRED
     1801    m_pcEntropyCoder->encodeICFlag  ( pcCU, uiAbsPartIdx
     1802#if LGE_ILLUCOMP_DEPTH_C0046
     1803        , false, uiDepth
     1804#endif
     1805        );
     1806#endif
     1807#if H3D_IVRP && !MTK_MDIVRP_C0138
    17921808    m_pcEntropyCoder->encodeResPredFlag( pcCU, uiAbsPartIdx, 0 );
    17931809#endif
     
    18181834  m_pcEntropyCoder->encodePredInfo( pcCU, uiAbsPartIdx );
    18191835#if LGE_ILLUCOMP_B0045
    1820     m_pcEntropyCoder->encodeICFlag  ( pcCU, uiAbsPartIdx );
    1821 #endif
    1822 #if HHI_INTER_VIEW_RESIDUAL_PRED
     1836    m_pcEntropyCoder->encodeICFlag  ( pcCU, uiAbsPartIdx
     1837#if LGE_ILLUCOMP_DEPTH_C0046
     1838        ,false, uiDepth
     1839#endif
     1840        );
     1841#endif
     1842#if H3D_IVRP && !MTK_MDIVRP_C0138
    18231843    if( !pcCU->isIntra( uiAbsPartIdx ) )
    18241844    {
     
    18511871{
    18521872  assert( rpcTempCU->getSlice()->getSliceType() != I_SLICE );
    1853 #if HHI_INTER_VIEW_MOTION_PRED
     1873#if H3D_IVMP
    18541874  TComMvField  cMvFieldNeighbours[MRG_MAX_NUM_CANDS_MEM << 1]; // double length for mv of both lists
    18551875  UChar uhInterDirNeighbours[MRG_MAX_NUM_CANDS_MEM];
     
    18601880  Int numValidMergeCand = 0;
    18611881
    1862 #if HHI_INTER_VIEW_RESIDUAL_PRED
     1882#if H3D_IVRP && !MTK_MDIVRP_C0138
    18631883  Bool  bResPrdAvail  = rpcTempCU->getResPredAvail( 0 );
    18641884  Bool  bResPrdFlag   = rpcTempCU->getResPredFlag ( 0 );
     
    18681888#endif
    18691889
    1870 #if HHI_INTER_VIEW_MOTION_PRED
     1890#if H3D_IVMP
    18711891  for( UInt ui = 0; ui < MRG_MAX_NUM_CANDS_MEM; ++ui )
    18721892#else
     
    18901910
    18911911  rpcTempCU->setPartSizeSubParts( SIZE_2Nx2N, 0, uhDepth ); // interprets depth relative to LCU level
    1892   rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours,uhInterDirNeighbours, numValidMergeCand );
    1893 
    1894 #if FAST_DECISION_FOR_MRG_RD_COST
     1912#if MERL_VSP_C0152
     1913  Int iVSPIndexTrue[3] = {-1, -1, -1};
     1914  rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand, iVSPIndexTrue );
     1915#else
     1916  rpcTempCU->getInterMergeCandidates( 0, 0, uhDepth, cMvFieldNeighbours, uhInterDirNeighbours, numValidMergeCand );
     1917#endif
     1918#if MTK_MDIVRP_C0138
     1919  Bool bResPredAvail = rpcTempCU->getResPredAvail(0);
     1920#endif
     1921
    18951922  Bool bestIsSkip = false;
    1896 #endif
    18971923 
    18981924  for( UInt uiMergeCand = 0; uiMergeCand < numValidMergeCand; ++uiMergeCand )
     
    19241950#endif
    19251951      {
    1926 #if FAST_DECISION_FOR_MRG_RD_COST
    19271952        if( !(bestIsSkip && uiNoResidual == 0) )
    19281953        {
    1929 #endif
    19301954          // set MC parameters
    19311955          rpcTempCU->setPredModeSubParts( MODE_SKIP, 0, uhDepth ); // interprets depth relative to LCU level
     
    19331957          rpcTempCU->setMergeFlagSubParts( true, 0, 0, uhDepth ); // interprets depth relative to LCU level
    19341958          rpcTempCU->setMergeIndexSubParts( uiMergeCand, 0, 0, uhDepth ); // interprets depth relative to LCU level
     1959#if MERL_VSP_C0152
     1960          {
     1961            Int iVSPIdx = 0;
     1962            Int numVSPIdx;
     1963            numVSPIdx = 3;
     1964            for (Int i = 0; i < numVSPIdx; i++)
     1965            {
     1966              if (iVSPIndexTrue[i] == uiMergeCand)
     1967                {
     1968                  iVSPIdx = i+1;
     1969                  break;
     1970                }
     1971            }
     1972            rpcTempCU->setVSPIndexSubParts( iVSPIdx, 0, 0, uhDepth );
     1973          }
     1974#endif
    19351975          rpcTempCU->setInterDirSubParts( uhInterDirNeighbours[uiMergeCand], 0, 0, uhDepth ); // interprets depth relative to LCU level
    19361976          rpcTempCU->getCUMvField( REF_PIC_LIST_0 )->setAllMvField( cMvFieldNeighbours[0 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
    19371977          rpcTempCU->getCUMvField( REF_PIC_LIST_1 )->setAllMvField( cMvFieldNeighbours[1 + 2*uiMergeCand], SIZE_2Nx2N, 0, 0 ); // interprets depth relative to rpcTempCU level
    19381978
    1939 #if HHI_INTER_VIEW_RESIDUAL_PRED
     1979#if H3D_IVRP
     1980#if MTK_MDIVRP_C0138
     1981          rpcTempCU->setResPredAvailSubParts(bResPredAvail, 0, 0, uhDepth);
     1982#else
    19401983          rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth );
    19411984          rpcTempCU->setResPredFlagSubParts ( bResPrdFlag,  0, 0, uhDepth );
     1985#endif
    19421986#endif
    19431987#if LGE_ILLUCOMP_B0045
     
    19521996#endif
    19531997        {
     1998#if MERL_VSP_C0152
     1999            m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth],  rpcTempCU->getZorderIdxInCU() );
     2000#else
    19542001            m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
     2002#endif
     2003#if MTK_MDIVRP_C0138
     2004            if (uiMergeCand == 0 && rpcTempCU->getResPredAvail(0))
     2005            {
     2006              m_pcPredSearch->residualPrediction(rpcTempCU, m_ppcPredYuvTemp[uhDepth], m_ppcResPredTmp [uhDepth]);
     2007            }
     2008#endif
    19552009            // save pred adress
    19562010            pcPredYuvTemp = m_ppcPredYuvTemp[uhDepth];
     
    19592013          else
    19602014          {
    1961 #if FAST_DECISION_FOR_MRG_RD_COST
    19622015            if( bestIsSkip)
    19632016            {
     2017#if MERL_VSP_C0152
     2018              m_pcPredSearch->motionCompensation( rpcTempCU, m_ppcPredYuvTemp[uhDepth], rpcTempCU->getZorderIdxInCU() );
     2019#else
    19642020              m_pcPredSearch->motionCompensation ( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
     2021#endif
     2022#if MTK_MDIVRP_C0138
     2023              if (uiMergeCand == 0 && rpcTempCU->getResPredAvail(0))
     2024              {
     2025                m_pcPredSearch->residualPrediction(rpcTempCU, m_ppcPredYuvTemp[uhDepth], m_ppcResPredTmp [uhDepth]);
     2026              }
     2027#endif
    19652028              // save pred adress
    19662029              pcPredYuvTemp = m_ppcPredYuvTemp[uhDepth];
     
    19682031            else
    19692032            {
    1970 #endif
    19712033              if ( pcPredYuvTemp != m_ppcPredYuvTemp[uhDepth])
    19722034              {
     
    19742036                pcPredYuvTemp = m_ppcPredYuvBest[uhDepth];
    19752037              }
    1976 #if FAST_DECISION_FOR_MRG_RD_COST
    19772038            }
    1978 #endif
    19792039          }
    19802040#if HHI_VSO
     
    19952055            m_ppcResiYuvBest[uhDepth],
    19962056            m_ppcRecoYuvTemp[uhDepth],
    1997 #if HHI_INTER_VIEW_RESIDUAL_PRED
     2057#if H3D_IVRP
    19982058                                                     m_ppcResPredTmp [uhDepth],
    19992059#endif
     
    20012061          Bool bQtRootCbf = rpcTempCU->getQtRootCbf(0) == 1;
    20022062
    2003 #if H0736_AVC_STYLE_QP_RANGE
    20042063          Int orgQP = rpcTempCU->getQP( 0 );
    20052064          xCheckDQP( rpcTempCU );
    20062065          xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
    20072066          rpcTempCU->initEstData( uhDepth, orgQP );
    2008 #else
    2009           UInt uiOrgQP = rpcTempCU->getQP( 0 );
    2010           xCheckDQP( rpcTempCU );
    2011           xCheckBestMode(rpcBestCU, rpcTempCU, uhDepth);
    2012           rpcTempCU->initEstData( uhDepth, uiOrgQP );
    2013 #endif
    2014 
    2015 #if FAST_DECISION_FOR_MRG_RD_COST
     2067
    20162068          if( m_pcEncCfg->getUseFastDecisionForMerge() && !bestIsSkip )
    20172069          {
    20182070            bestIsSkip = rpcBestCU->getQtRootCbf(0) == 0;
    20192071          }
    2020 #endif
    20212072
    20222073          if (!bQtRootCbf)
    20232074            break;
    2024 #if FAST_DECISION_FOR_MRG_RD_COST
    20252075        }
    2026 #endif
    20272076      }
    20282077    }
     
    20592108  rpcTempCU->setDepthSubParts( uhDepth, 0 );
    20602109 
    2061 #if HHI_INTER_VIEW_RESIDUAL_PRED
     2110#if H3D_IVRP
    20622111  Bool  bResPrdAvail  = rpcTempCU->getResPredAvail( 0 );
    20632112  Bool  bResPrdFlag   = rpcTempCU->getResPredFlag ( 0 );
     
    20652114 
    20662115  rpcTempCU->setPartSizeSubParts  ( ePartSize,  0, uhDepth );
    2067 #if HHI_INTER_VIEW_RESIDUAL_PRED
     2116
     2117#if H3D_IVRP
    20682118  rpcTempCU->setResPredAvailSubParts( bResPrdAvail, 0, 0, uhDepth );
    20692119  rpcTempCU->setResPredFlagSubParts ( bResPrdFlag,  0, 0, uhDepth );
     
    20712121  rpcTempCU->setPredModeSubParts  ( MODE_INTER, 0, uhDepth );
    20722122 
    2073 #if HHI_INTER_VIEW_RESIDUAL_PRED
     2123#if H3D_IVRP
    20742124#if !LG_RESTRICTEDRESPRED_M24766
    20752125  if( rpcTempCU->getResPredFlag( 0 ) )
     
    20832133  rpcTempCU->setMergeAMP (true);
    20842134  #if HHI_INTERVIEW_SKIP
    2085 #if LG_RESTRICTEDRESPRED_M24766
    2086   m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcResPredTmp[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes, bUseMRG  );
     2135#if LG_RESTRICTEDRESPRED_M24766 && !MTK_MDIVRP_C0138
     2136  m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcResPredTmp[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes, bUseMRG);
    20872137#else
    20882138  m_pcPredSearch->predInterSearch ( rpcTempCU, m_ppcOrigYuv[uhDepth], m_ppcPredYuvTemp[uhDepth], m_ppcResiYuvTemp[uhDepth], m_ppcRecoYuvTemp[uhDepth], bSkipRes, bUseMRG  );
     
    20992149#endif
    21002150
    2101 #if HHI_INTER_VIEW_RESIDUAL_PRED
     2151#if H3D_IVRP
    21022152#if !LG_RESTRICTEDRESPRED_M24766
    21032153  if( rpcTempCU->getResPredFlag( 0 ) )
     
    21222172                                             m_ppcResiYuvBest[uhDepth],
    21232173                                             m_ppcRecoYuvTemp[uhDepth],
    2124 #if HHI_INTER_VIEW_RESIDUAL_PRED
     2174#if H3D_IVRP
    21252175                                             m_ppcResPredTmp [uhDepth],
    21262176#endif
     
    21332183                                             m_ppcResiYuvBest[uhDepth],
    21342184                                             m_ppcRecoYuvTemp[uhDepth],
    2135 #if HHI_INTER_VIEW_RESIDUAL_PRED
     2185#if H3D_IVRP
    21362186                                             m_ppcResPredTmp [uhDepth],
    21372187#endif
     
    23752425}
    23762426
    2377 #if BURST_IPCM
    23782427/** Check whether the last CU shares the same root as the current CU and is IPCM or not. 
    23792428 * \param pcCU
     
    24672516  return numSucIPCM;
    24682517}
    2469 #endif
    24702518
    24712519Void TEncCu::xCopyAMVPInfo (AMVPInfo* pSrc, AMVPInfo* pDst)
     
    27872835      assert( rpcTempCU->getInterDir( ui ) != 0 );
    27882836      assert( rpcTempCU->getPredictionMode( ui ) != MODE_NONE );
    2789     }
     2837#if MERL_VSP_C0152
     2838      Int vspIdx = pcTextureCU->getVSPIndex( rpcTempCU->getZorderIdxInCU() + ui);
     2839      rpcTempCU->setVSPIndex( ui , vspIdx);
     2840#endif
     2841    }
     2842
    27902843    rpcTempCU->setPredModeSubParts( bSkipResidual ? MODE_SKIP : MODE_INTER, 0, uhDepth );
     2844#if MERL_VSP_C0152
     2845    m_pcPredSearch->motionCompensation( rpcTempCU, m_ppcPredYuvTemp[uhDepth], rpcTempCU->getZorderIdxInCU()  );
     2846#else
    27912847    m_pcPredSearch->motionCompensation( rpcTempCU, m_ppcPredYuvTemp[uhDepth] );
    2792 
     2848#endif
    27932849    // get Original YUV data from picture
    27942850    m_ppcOrigYuv[uhDepth]->copyFromPicYuv( rpcBestCU->getPic()->getPicYuvOrg(), rpcBestCU->getAddr(), rpcBestCU->getZorderIdxInCU() );
     
    27992855                                               m_ppcResiYuvBest[uhDepth],
    28002856                                               m_ppcRecoYuvTemp[uhDepth],
    2801 #if HHI_INTER_VIEW_RESIDUAL_PRED
     2857#if H3D_IVRP
    28022858                                               m_ppcResPredTmp [uhDepth],
    28032859#endif
     
    28762932    m_pcEntropyCoder->encodeMergeIndex( pcCU, 0, 0, true );
    28772933#if LGE_ILLUCOMP_B0045
    2878     m_pcEntropyCoder->encodeICFlag( pcCU, 0, true );
     2934    m_pcEntropyCoder->encodeICFlag( pcCU, 0, true
     2935#if LGE_ILLUCOMP_DEPTH_C0046
     2936        , uhDepth
     2937#endif
     2938        );
    28792939#endif
    28802940  }
     
    28862946    m_pcEntropyCoder->encodePredInfo( pcCU, 0, true );
    28872947#if LGE_ILLUCOMP_B0045
    2888     m_pcEntropyCoder->encodeICFlag( pcCU, 0,          true );
     2948    m_pcEntropyCoder->encodeICFlag( pcCU, 0,          true
     2949#if LGE_ILLUCOMP_DEPTH_C0046
     2950        , uhDepth
     2951#endif
     2952        );
    28892953#endif
    28902954  }
  • trunk/source/Lib/TLibEncoder/TEncCu.h

    r56 r296  
    7878  TComYuv**               m_ppcRecoYuvTemp; ///< Temporary Reconstruction Yuv for each depth
    7979  TComYuv**               m_ppcOrigYuv;     ///< Original Yuv for each depth
    80 #if HHI_INTER_VIEW_RESIDUAL_PRED
     80#if H3D_IVRP
    8181  TComYuv**               m_ppcResPredTmp;  ///< Temporary residual prediction for each depth
    8282#endif
    83  
     83
    8484  //  Data : encoder control
    8585  Bool                    m_bEncodeDQP;
    86 #if BURST_IPCM
    8786  Bool                    m_checkBurstIPCMFlag;
    88 #endif
    8987
    9088  //  Access channel
     
    121119  /// destroy internal buffers
    122120  Void  destroy             ();
    123  
     121
    124122  /// CU analysis function
    125123  Void  compressCU          ( TComDataCU*&  rpcCU );
     
    173171  Void setdQPFlag           ( Bool b )                { m_bEncodeDQP = b;           }
    174172
    175 #if BURST_IPCM
    176173  Bool getCheckBurstIPCMFlag()                        { return m_checkBurstIPCMFlag;   }
    177174  Void setCheckBurstIPCMFlag( Bool b )                { m_checkBurstIPCMFlag = b;      }
     
    179176  Bool checkLastCUSucIPCM   ( TComDataCU* pcCU, UInt uiCurAbsPartIdx );
    180177  Int  countNumSucIPCM      ( TComDataCU* pcCU, UInt uiCurAbsPartIdx );
    181 #endif
    182178
    183179#if ADAPTIVE_QP_SELECTION
  • trunk/source/Lib/TLibEncoder/TEncEntropy.cpp

    r210 r296  
    5252Void TEncEntropy::encodeSliceHeader ( TComSlice* pcSlice )
    5353{
    54 #if SAO_UNIT_INTERLEAVING
    5554  if (pcSlice->getSPS()->getUseSAO())
    5655  {
     
    6867    }
    6968  }
    70 #endif
    7169
    7270  m_pcEntropyCoderIf->codeSliceHeader( pcSlice );
     
    7472}
    7573
    76 #if TILES_WPP_ENTRY_POINT_SIGNALLING
    7774Void  TEncEntropy::encodeTilesWPPEntryPoint( TComSlice* pSlice )
    7875{
    7976  m_pcEntropyCoderIf->codeTilesWPPEntryPoint( pSlice );
    8077}
    81 #else
    82 Void TEncEntropy::encodeSliceHeaderSubstreamTable( TComSlice* pcSlice )
    83 {
    84   m_pcEntropyCoderIf->codeSliceHeaderSubstreamTable( pcSlice );
    85 }
    86 #endif
    8778
    8879Void TEncEntropy::encodeTerminatingBit      ( UInt uiIsLast )
     
    9889}
    9990
    100 #if OL_FLUSH
    10191Void TEncEntropy::encodeFlush()
    10292{
     
    10797  m_pcEntropyCoderIf->encodeStart();
    10898}
    109 #endif
    11099
    111100Void TEncEntropy::encodeSEI(const SEI& sei)
     
    133122#endif
    134123
    135 #if HHI_MPI
     124#if HHI_MPI || OL_QTLIMIT_PREDCODING_B0068
    136125Void TEncEntropy::encodeSPS( TComSPS* pcSPS, Bool bIsDepth )
    137126{
     
    157146    uiAbsPartIdx = 0;
    158147  }
    159 #if BURST_IPCM
    160148  if( !bRD )
    161149  {
     
    165153    }
    166154  }
    167 #endif
    168155  m_pcEntropyCoderIf->codeSkipFlag( pcCU, uiAbsPartIdx );
    169156}
    170157
    171158#if LGE_ILLUCOMP_B0045
    172 Void TEncEntropy::encodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD )
    173 {
    174   if (pcCU->isIntra(uiAbsPartIdx) || (pcCU->getSlice()->getViewId() == 0) || pcCU->getSlice()->getSPS()->isDepth())
     159Void TEncEntropy::encodeICFlag( TComDataCU* pcCU, UInt uiAbsPartIdx, Bool bRD
     160#if LGE_ILLUCOMP_DEPTH_C0046
     161    , UInt uiDepth
     162#endif
     163    )
     164{
     165  if (pcCU->isIntra(uiAbsPartIdx) || (pcCU->getSlice()->getViewId() == 0)
     166#if !LGE_ILLUCOMP_DEPTH_C0046
     167      || pcCU->getSlice()->getSPS()->isDepth()
     168#endif
     169      )
    175170  {
    176171    return;