IntraSearch.cpp 112 KB
Newer Older
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
        cs.getOrgResiBuf(cbArea).copyFrom(saveCS.getOrgResiBuf(cbArea));
        cs.getPredBuf   (crArea).copyFrom(saveCS.getPredBuf   (crArea));
        cs.getOrgResiBuf(crArea).copyFrom(saveCS.getOrgResiBuf(crArea));
#endif
        cs.getPredBuf   (cbArea).copyFrom(saveCS.getPredBuf   (cbArea));
        cs.getPredBuf   (crArea).copyFrom(saveCS.getPredBuf   (crArea));

        if( keepResi )
        {
          cs.getResiBuf (cbArea).copyFrom(saveCS.getResiBuf   (cbArea));
          cs.getResiBuf (crArea).copyFrom(saveCS.getResiBuf   (crArea));
        }
        cs.getRecoBuf   (cbArea).copyFrom(saveCS.getRecoBuf   (cbArea));
        cs.getRecoBuf   (crArea).copyFrom(saveCS.getRecoBuf   (crArea));
        
        currTU.copyComponentFrom(tmpTU, COMPONENT_Cb);
        currTU.copyComponentFrom(tmpTU, COMPONENT_Cr);
        
        m_CABACEstimator->getCtx() = ctxBest;
      }
      
      // Copy results to the picture structures
      cs.picture->getRecoBuf(cbArea).copyFrom(cs.getRecoBuf(cbArea));
      cs.picture->getRecoBuf(crArea).copyFrom(cs.getRecoBuf(crArea));
      cs.picture->getPredBuf(cbArea).copyFrom(cs.getPredBuf(cbArea));
      cs.picture->getPredBuf(crArea).copyFrom(cs.getPredBuf(crArea));
      
      cbfs.cbf(COMPONENT_Cb) = TU::getCbf(currTU, COMPONENT_Cb);
      cbfs.cbf(COMPONENT_Cr) = TU::getCbf(currTU, COMPONENT_Cr);
      
      currTU.jointCbCr = cbfs.cbf(COMPONENT_Cb) ? bestJointCbCr : 0;
      cs.dist         += bestDistCbCr;
3033
    }
3034
#endif // JVET_N0054_JOINT_CHROMA
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
  }
  else
  {
    unsigned    numValidTBlocks   = ::getNumberValidTBlocks( *cs.pcv );
    ChromaCbfs  SplitCbfs         ( false );

    if( partitioner.canSplit( TU_MAX_TR_SPLIT, cs ) )
    {
      partitioner.splitCurrArea( TU_MAX_TR_SPLIT, cs );
    }
3045
3046
3047
3048
    else if( currTU.cu->ispMode )
    {
      partitioner.splitCurrArea( ispType, cs );
    }
3049
3050
3051
3052
3053
    else
      THROW( "Implicit TU split not available" );

    do
    {
3054
      ChromaCbfs subCbfs = xRecurIntraChromaCodingQT( cs, partitioner, bestCostSoFar, ispType );
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064

      for( uint32_t ch = COMPONENT_Cb; ch < numValidTBlocks; ch++ )
      {
        const ComponentID compID = ComponentID( ch );
        SplitCbfs.cbf( compID ) |= subCbfs.cbf( compID );
      }
    } while( partitioner.nextPart( cs ) );

    partitioner.exitCurrSplit();

3065
3066
3067
3068
    if( lumaUsesISP && cs.dist == MAX_UINT )
    {
      return cbfs;
    }
3069
3070
3071
3072
3073
    {

      cbfs.Cb |= SplitCbfs.Cb;
      cbfs.Cr |= SplitCbfs.Cr;

3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
      if( !lumaUsesISP )
      {
        for( auto &ptu : cs.tus )
        {
          if( currArea.Cb().contains( ptu->Cb() ) || ( !ptu->Cb().valid() && currArea.Y().contains( ptu->Y() ) ) )
          {
            TU::setCbfAtDepth( *ptu, COMPONENT_Cb, currDepth, SplitCbfs.Cb );
            TU::setCbfAtDepth( *ptu, COMPONENT_Cr, currDepth, SplitCbfs.Cr );
          }
        }
      }
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
    }
  }

  return cbfs;
}

uint64_t IntraSearch::xFracModeBitsIntra(PredictionUnit &pu, const uint32_t &uiMode, const ChannelType &chType)
{
  uint32_t orgMode = uiMode;

3095
  if (!pu.mhIntraFlag)
3096
3097
3098
3099
3100
3101
  std::swap(orgMode, pu.intraDir[chType]);

  m_CABACEstimator->resetBits();

  if( isLuma( chType ) )
  {
Luong Pham Van's avatar
Luong Pham Van committed
3102
#if !JVET_N0302_SIMPLFIED_CIIP
3103
    if ( pu.mhIntraFlag )
3104
3105
      m_CABACEstimator->MHIntra_luma_pred_modes(*pu.cu);
    else
Luong Pham Van's avatar
Luong Pham Van committed
3106
3107
3108
#else
    if (!pu.mhIntraFlag)
#endif
3109
    {
3110
#if !JVET_N0217_MATRIX_INTRAPRED
3111
      m_CABACEstimator->extend_ref_line(pu);
3112
#endif
3113
3114
      m_CABACEstimator->intra_luma_pred_mode(pu);
    }
3115
3116
3117
3118
3119
3120
  }
  else
  {
    m_CABACEstimator->intra_chroma_pred_mode( pu );
  }

3121
  if ( !pu.mhIntraFlag )
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
  std::swap(orgMode, pu.intraDir[chType]);

  return m_CABACEstimator->getEstFracBits();
}



void IntraSearch::encPredIntraDPCM( const ComponentID &compID, PelBuf &pOrg, PelBuf &pDst, const uint32_t &uiDirMode )
{
  CHECK( pOrg.buf == 0, "Encoder DPCM called without original buffer" );

  const int srcStride = m_topRefLength + 1;
  CPelBuf   pSrc = CPelBuf(getPredictorPtr(compID), srcStride, m_leftRefLength + 1);

  // Sample Adaptive intra-Prediction (SAP)
  if( uiDirMode == HOR_IDX )
  {
    // left column filled with reference samples, remaining columns filled with pOrg data
    for( int y = 0; y < pDst.height; y++ )
    {
      pDst.at( 0, y ) = pSrc.at( 0, 1 + y );
    }
    CPelBuf orgRest  = pOrg.subBuf( 0, 0, pOrg.width - 1, pOrg.height );
    PelBuf  predRest = pDst.subBuf( 1, 0, pDst.width - 1, pDst.height );

    predRest.copyFrom( orgRest );
  }
  else // VER_IDX
  {
    // top row filled with reference samples, remaining rows filled with pOrg data
    for( int x = 0; x < pDst.width; x++ )
    {
      pDst.at( x, 0 ) = pSrc.at( 1 + x, 0 );
    }
    CPelBuf orgRest  = pOrg.subBuf( 0, 0, pOrg.width, pOrg.height - 1 );
    PelBuf  predRest = pDst.subBuf( 0, 1, pDst.width, pDst.height - 1 );

    predRest.copyFrom( orgRest );
  }
}

bool IntraSearch::useDPCMForFirstPassIntraEstimation( const PredictionUnit &pu, const uint32_t &uiDirMode )
{
  return CU::isRDPCMEnabled( *pu.cu ) && pu.cu->transQuantBypass && (uiDirMode == HOR_IDX || uiDirMode == VER_IDX);
}
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225

#if JVET_N0217_MATRIX_INTRAPRED
template<typename T, size_t N>
void IntraSearch::reduceHadCandList(static_vector<T, N>& candModeList, static_vector<double, N>& candCostList, int& numModesForFullRD, const double thresholdHadCost, const double thresholdHadCostConv)
{
  CHECKD(candModeList.size() != numModesForFullRD, "Error: list size");
  CHECKD(candCostList.size() != numModesForFullRD, "Error: list size");
  const int maxCandPerType = numModesForFullRD >> 1;
  static_vector<ModeInfo, FAST_UDI_MAX_RDMODE_NUM> tempRdModeList;
  static_vector<double, FAST_UDI_MAX_RDMODE_NUM> tempCandCostList;
  const double minCost = candCostList[0];

  int numConv = 0;
  for (int idx = 0; idx < candModeList.size(); idx++)
  {
    ModeInfo uiOrgMode = candModeList[idx];

    if (!uiOrgMode.mipFlg) { numConv++; }

    if (uiOrgMode.mipFlg || (numConv <= maxCandPerType))
    {
      tempRdModeList.push_back(uiOrgMode);
      tempCandCostList.push_back(candCostList[idx]);
    }
    else if (candCostList[idx] < thresholdHadCostConv * minCost)
    {
      tempRdModeList.push_back(uiOrgMode);
      tempCandCostList.push_back(candCostList[idx]);
    }
  }
  candModeList = tempRdModeList;
  candCostList = tempCandCostList;

  int numMip = 0;
  tempRdModeList.clear();
  tempCandCostList.clear();
  for (int idx = 0; idx < candModeList.size(); idx++)
  {
    ModeInfo uiOrgMode = candModeList[idx];
    if (uiOrgMode.mipFlg)
    {
      numMip++;
    }
    if (!uiOrgMode.mipFlg || (numMip <= maxCandPerType))
    {
      tempRdModeList.push_back(uiOrgMode);
      tempCandCostList.push_back(candCostList[idx]);
    }
    else if (candCostList[idx] < thresholdHadCost * minCost)
    {
      tempRdModeList.push_back(uiOrgMode);
      tempCandCostList.push_back(candCostList[idx]);
    }
  }
  candModeList = tempRdModeList;
  candCostList = tempCandCostList;
  numModesForFullRD = int(candModeList.size());
}
#endif