Ticket #285: Patch_ticket285.patch

File Patch_ticket285.patch, 3.5 KB (added by ksuehring, 13 years ago)

requested patch from Chia-Yang Tsai (send via email)

  • Lib/TLibEncoder/TEncAdaptiveLoopFilter.cpp

     
    44024402  Double dEstimatedCost, dEstimatedMinCost = MAX_DOUBLE;;
    44034403
    44044404  UInt   uiBitShift = (g_uiBitIncrement<<1);
     4405#if G212_CROSS9x9_VB && G1023_FIX_NPASS_ALF
     4406  Int64  iEstimateDistBeforeFilter;
     4407  Int*   coeffNoFilter[NUM_ALF_FILTER_SHAPE][NO_VAR_BINS];
     4408  for(Int filter_shape = 0; filter_shape < NUM_ALF_FILTER_SHAPE; filter_shape++)
     4409  {
     4410    for(Int i=0; i< NO_VAR_BINS; i++)
     4411    {
     4412      coeffNoFilter[filter_shape][i]= new Int[ALF_MAX_NUM_COEF];
     4413      ::memset(coeffNoFilter[filter_shape][i], 0, sizeof(Int)*ALF_MAX_NUM_COEF);
     4414#if ALF_DC_OFFSET_REMOVAL
     4415      coeffNoFilter[filter_shape][i][ m_sqrFiltLengthTab[filter_shape]-1 ] = (1 << ((Int)ALF_NUM_BIT_SHIFT));
     4416#else
     4417      coeffNoFilter[filter_shape][i][ m_sqrFiltLengthTab[filter_shape]-2 ] = (1 << ((Int)ALF_NUM_BIT_SHIFT));
     4418#endif
     4419    }
     4420  }
     4421#endif
    44054422
    44064423  m_pcTempAlfParam->alf_flag = 1;
    44074424#if !F747_APS
     
    44484465    //estimate R-D cost
    44494466    uiRate         = xcodeFiltCoeff(m_filterCoeffSymQuant, filtNo, m_varIndTab, filters_per_fr, m_pcTempAlfParam);
    44504467    iEstimatedDist = xEstimateFiltDist(filters_per_fr, m_varIndTab, ESym, ySym, m_filterCoeffSym, m_pcTempAlfParam->num_coeff);
     4468#if G212_CROSS9x9_VB && G1023_FIX_NPASS_ALF
     4469    iEstimateDistBeforeFilter = xEstimateFiltDist(filters_per_fr, m_varIndTab, ESym, ySym, coeffNoFilter[filter_shape], m_pcTempAlfParam->num_coeff);
     4470    iEstimatedDist -= iEstimateDistBeforeFilter;
     4471#endif
    44514472    dEstimatedCost = (Double)(uiRate) * m_dLambdaLuma + (Double)(iEstimatedDist);
    44524473
    44534474    if(dEstimatedCost < dEstimatedMinCost)
    44544475    {
    44554476      dEstimatedMinCost   = dEstimatedCost;
    44564477      copyALFParam(pcAlfSaved, m_pcTempAlfParam);
     4478#if G212_CROSS9x9_VB && G1023_FIX_NPASS_ALF
     4479      iEstimatedDist += iEstimateDistBeforeFilter;
     4480#endif
     4481
    44574482      for(Int i=0; i< filters_per_fr; i++ )
    44584483      {
    44594484        iEstimatedDist += (((Int64)m_pixAcc_merged[i]) >> uiBitShift);
     
    44934518      rdCost  += (Double)uiOffRegionDistortion;
    44944519    }
    44954520  }
     4521#if G212_CROSS9x9_VB && G1023_FIX_NPASS_ALF
     4522  // if ALF_STAR5x5 is selected, the distortion of 2 skipped lines per LCU should be added.
     4523  if(pcAlfSaved->filter_shape == ALF_STAR5x5)
     4524  {
     4525    Int    iPelDiff;
     4526    UInt64  uiSkipPelsDistortion = 0;
     4527    Pel   *pOrgTemp, *pDecTemp;
     4528    for(Int y= m_lineIdxPadTop-1; y< m_img_height - m_lcuHeight ; y += m_lcuHeight)
     4529    {
     4530      pOrgTemp = ImgOrg + y*Stride;
     4531      pDecTemp = ImgDec + y*Stride;
     4532      for(Int x=0; x< m_img_width; x++)
     4533      {
     4534        if(m_maskImg[y][x] == 1)
     4535        {
     4536          iPelDiff = pOrgTemp[x] - pDecTemp[x];
     4537          uiSkipPelsDistortion += (UInt64)(  (iPelDiff*iPelDiff) >> uiBitShift );
     4538        }
     4539      }
     4540
     4541      pOrgTemp += Stride;
     4542      pDecTemp += Stride;
     4543      for(Int x=0; x< m_img_width; x++)
     4544      {
     4545        if(m_maskImg[y+1][x] == 1)
     4546        {
     4547          iPelDiff = pOrgTemp[x] - pDecTemp[x];
     4548          uiSkipPelsDistortion += (UInt64)(  (iPelDiff*iPelDiff) >> uiBitShift );
     4549        }
     4550      }
     4551    }
     4552    ruiDist += uiSkipPelsDistortion;
     4553    rdCost  += (Double)uiSkipPelsDistortion;
     4554  }
     4555
     4556  for(Int filter_shape = 0; filter_shape < NUM_ALF_FILTER_SHAPE; filter_shape++)
     4557  {
     4558    for(Int i=0; i< NO_VAR_BINS; i++)
     4559    {
     4560      delete[] coeffNoFilter[filter_shape][i];
     4561    }
     4562  }
     4563#endif
     4564
    44964565}
    44974566
    44984567#if !G212_CROSS9x9_VB