Changeset 825 in SHVCSoftware for branches/SHM-dev/source/Lib/TLibEncoder


Ignore:
Timestamp:
11 Jul 2014, 20:42:00 (11 years ago)
Author:
qualcomm
Message:

Integration of R0151(R0151_CGS_3D_ASYMLUT_IMPROVE), R0150 (R0150_CGS_SIGNAL_CONSTRAINTS), and R0164 (R0164_CGS_LUT_BUGFIX)

Location:
branches/SHM-dev/source/Lib/TLibEncoder
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • branches/SHM-dev/source/Lib/TLibEncoder/TEnc3DAsymLUT.cpp

    r815 r825  
    1515  m_pEncCuboid = NULL;
    1616  m_pBestEncCuboid = NULL;
    17   memset( m_nPrevFrameBit , 0 , sizeof( m_nPrevFrameBit ) );
    18   memset( m_nPrevFrameCGSBit , 0 , sizeof( m_nPrevFrameCGSBit ) );
    19   memset( m_nPrevFrameCGSPartNumLog2 , 0 , sizeof( m_nPrevFrameCGSPartNumLog2 ) );
    20   memset( m_nPrevFrameOverWritePPS , 0 , sizeof( m_nPrevFrameOverWritePPS ) );
     17  m_nAccuFrameBit = 0;
     18  m_nAccuFrameCGSBit = 0;
     19  m_nPrevFrameCGSPartNumLog2 = 0;
    2120  m_dTotalFrameBit = 0;
    2221  m_nTotalCGSBit = 0;
     
    3231  }
    3332
    34   TCom3DAsymLUT::create( nMaxOctantDepth , nInputBitDepth , nInputBitDepthC, nOutputBitDepth , nOutputBitDepthC, nMaxYPartNumLog2 );
     33  TCom3DAsymLUT::create( nMaxOctantDepth , nInputBitDepth , nInputBitDepthC, nOutputBitDepth , nOutputBitDepthC, nMaxYPartNumLog2
     34#if R0151_CGS_3D_ASYMLUT_IMPROVE
     35    , 1 << ( nInputBitDepthC - 1 ) , 1 << ( nInputBitDepthC - 1 )
     36#endif
     37    );
    3538  xAllocate3DArray( m_pColorInfo , xGetYSize() , xGetUSize() , xGetVSize() );
    3639  xAllocate3DArray( m_pColorInfoC , xGetYSize() , xGetUSize() , xGetVSize() );
     
    5861}
    5962
     63#if R0151_CGS_3D_ASYMLUT_IMPROVE
     64Double TEnc3DAsymLUT::xxDeriveVertexPerColor( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
     65  Pel & rP0 , Pel & rP1 , Pel & rP3 , Pel & rP7 , Int nResQuantBit )
     66{
     67  Int nInitP0 = rP0;
     68  Int nInitP1 = rP1;
     69  Int nInitP3 = rP3;
     70  Int nInitP7 = rP7;
     71
     72  const Int nOne = xGetNormCoeffOne();
     73  Double dNorm = (N * yy * vv * uu - N * yy * uv * uv - N * yv * yv * uu - N * vv * yu * yu + 2 * N * yv * uv * yu - yy * vs * vs * uu + 2 * yy * vs * uv * us - yy * vv * us * us - 2 * vs * uv * yu * ys + uv * uv * ys * ys + vs * vs * yu * yu - 2 * yv * vs * us * yu + 2 * yv * vs * ys * uu - 2 * yv * uv * us * ys + 2 * vv * yu * ys * us - vv * uu * ys * ys + yv * yv * us * us);
     74  if( N > 16 && dNorm != 0 )
     75  {
     76    Double dInitA = (-N * uu * yv * Yv + N * uu * Yy * vv - N * Yy * uv * uv + N * yv * uv * Yu - N * yu * Yu * vv + N * yu * uv * Yv + yu * us * Ys * vv - vs * ys * uv * Yu - yu * vs * us * Yv - yv * uv * us * Ys - yv * vs * us * Yu - yu * uv * vs * Ys - ys * us * uv * Yv + ys * us * Yu * vv + 2 * Yy * vs * uv * us + uu * yv * vs * Ys - uu * ys * Ys * vv + uu * vs * ys * Yv + ys * Ys * uv * uv - Yy * vv * us * us + yu * Yu * vs * vs + yv * Yv * us * us - uu * Yy * vs * vs) / dNorm;
     77    Double dInitB = (N * yy * Yu * vv - N * yy * uv * Yv - N * Yu * yv * yv - N * yu * Yy * vv + N * uv * yv * Yy + N * yv * yu * Yv - yy * us * Ys * vv + yy * uv * vs * Ys - yy * Yu * vs * vs + yy * vs * us * Yv - uv * vs * ys * Yy - yv * yu * vs * Ys + yu * Yy * vs * vs + yu * ys * Ys * vv - uv * yv * ys * Ys + 2 * Yu * yv * vs * ys + us * ys * Yy * vv - vs * ys * yu * Yv + uv * ys * ys * Yv + us * Ys * yv * yv - Yu * ys * ys * vv - yv * ys * us * Yv - vs * us * yv * Yy) / dNorm;
     78    Double dInitC = -(-N * yy * Yv * uu + N * yy * uv * Yu - N * yv * yu * Yu - N * uv * yu * Yy + N * Yv * yu * yu + N * yv * Yy * uu - yy * uv * us * Ys + yy * Yv * us * us + yy * vs * Ys * uu - yy * vs * us * Yu + yv * ys * us * Yu - vs * Ys * yu * yu - yv * ys * Ys * uu + vs * us * yu * Yy + vs * ys * yu * Yu - uv * Yu * ys * ys + Yv * uu * ys * ys - yv * Yy * us * us - 2 * Yv * yu * ys * us - vs * ys * Yy * uu + uv * us * ys * Yy + uv * yu * ys * Ys + yv * yu * us * Ys) / dNorm;
     79    nInitP0 = ( Int )( dInitA * nOne + 0.5 ) >> nResQuantBit << nResQuantBit;
     80    nInitP1 = ( Int )( dInitB * nOne + 0.5 ) >> nResQuantBit << nResQuantBit;
     81    nInitP3 = ( Int )( dInitC * nOne + 0.5 ) >> nResQuantBit << nResQuantBit;
     82  }
     83
     84  Int nMin = - ( 1 << ( m_nLUTBitDepth - 1 ) );
     85  Int nMax = - nMin - ( 1 << nResQuantBit  );
     86  Int nMask = ( 1 << nResQuantBit ) - 1;
     87
     88  Double dMinError = MAX_DOUBLE;
     89  Int nTestRange = 2;
     90  Int nStepSize = 1 << nResQuantBit;
     91  for( Int i = - nTestRange ; i <= nTestRange ; i++ )
     92  {
     93    for( Int j = - nTestRange ; j <= nTestRange ; j++ )
     94    {
     95      for( Int k = - nTestRange ; k <= nTestRange ; k++ )
     96      {
     97        Int nTestP0 = Clip3( nMin , nMax , nInitP0 + i * nStepSize );
     98        Int nTestP1 = Clip3( nMin , nMax , nInitP1 + j * nStepSize );
     99        Int nTestP3 = Clip3( nMin , nMax , nInitP3 + k * nStepSize );
     100        Double a = 1.0 * nTestP0 / nOne;
     101        Double b = 1.0 * nTestP1 / nOne;
     102        Double c = 1.0 * nTestP3 / nOne;
     103        Double d = ( Ys - a * ys - b * us - c * vs ) / N;
     104        nInitP7 = ( ( Int )d ) >> nResQuantBit << nResQuantBit;
     105        for( Int m = 0 ; m < 2 ; m++ )
     106        {
     107          Int nTestP7 = Clip3( nMin , nMax , nInitP7 + m * nStepSize );
     108          Double dError = xxCalEstDist( N , Ys , Yy , Yu , Yv , ys , us , vs , yy , yu , yv , uu , uv , vv , YY , a , b , c , nTestP7 );
     109          if( dError < dMinError )
     110          {
     111            dMinError = dError;
     112            rP0 = ( Pel )nTestP0;
     113            rP1 = ( Pel )nTestP1;
     114            rP3 = ( Pel )nTestP3;
     115            rP7 = ( Pel )nTestP7;
     116          }
     117        }
     118      }
     119    }
     120  }
     121  assert( !( rP0 & nMask ) && !( rP1 & nMask ) && !( rP3 & nMask ) && !( rP7 & nMask ) );
     122
     123  return( dMinError );
     124}
     125#else
    60126Double TEnc3DAsymLUT::xxDeriveVertexPerColor( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
    61127  Int y0 , Int u0 , Int v0 , Int nLengthY , Int nLengthUV ,
     
    134200  return( dMinError );
    135201}
    136 
     202#endif
     203
     204#if R0151_CGS_3D_ASYMLUT_IMPROVE
     205Double TEnc3DAsymLUT::estimateDistWithCur3DAsymLUT( TComPic * pCurPic , UInt refLayerIdc )
     206{
     207  xxCollectData( pCurPic , refLayerIdc );
     208
     209  Double dErrorLuma = 0 , dErrorChroma = 0;
     210  Int nYSize = 1 << ( getCurOctantDepth() + getCurYPartNumLog2() );
     211  Int nUVSize = 1 << getCurOctantDepth();
     212  for( Int yIdx = 0 ; yIdx < nYSize ; yIdx++ )
     213  {
     214    for( Int uIdx = 0 ; uIdx < nUVSize ; uIdx++ )
     215    {
     216      for( Int vIdx = 0 ; vIdx < nUVSize ; vIdx++ )
     217      {
     218        SColorInfo & rCuboidColorInfo = m_pColorInfo[yIdx][uIdx][vIdx];
     219        SColorInfo & rCuboidColorInfoC = m_pColorInfoC[yIdx][uIdx][vIdx];
     220        SCuboid & rCuboid = xGetCuboid( yIdx , uIdx , vIdx );
     221        if( rCuboidColorInfo.N > 0 )
     222        {
     223          dErrorLuma += xxCalEstDist( rCuboidColorInfo.N , rCuboidColorInfo.Ys , rCuboidColorInfo.Yy , rCuboidColorInfo.Yu , rCuboidColorInfo.Yv , rCuboidColorInfo.ys , rCuboidColorInfo.us , rCuboidColorInfo.vs , rCuboidColorInfo.yy , rCuboidColorInfo.yu , rCuboidColorInfo.yv , rCuboidColorInfo.uu , rCuboidColorInfo.uv , rCuboidColorInfo.vv , rCuboidColorInfo.YY ,
     224            rCuboid.P[0].Y , rCuboid.P[1].Y , rCuboid.P[2].Y , rCuboid.P[3].Y );
     225        }
     226        if( rCuboidColorInfoC.N > 0 )
     227        {
     228          dErrorChroma += xxCalEstDist( rCuboidColorInfoC.N , rCuboidColorInfoC.Us , rCuboidColorInfoC.Uy , rCuboidColorInfoC.Uu , rCuboidColorInfoC.Uv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.UU ,
     229            rCuboid.P[0].U , rCuboid.P[1].U , rCuboid.P[2].U , rCuboid.P[3].U );
     230          dErrorChroma += xxCalEstDist( rCuboidColorInfoC.N , rCuboidColorInfoC.Vs , rCuboidColorInfoC.Vy , rCuboidColorInfoC.Vu , rCuboidColorInfoC.Vv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.VV ,
     231            rCuboid.P[0].V , rCuboid.P[1].V , rCuboid.P[2].V , rCuboid.P[3].V );
     232        }
     233      }
     234    }
     235  }
     236
     237  return( dErrorLuma + dErrorChroma);
     238}
     239#else
    137240Double TEnc3DAsymLUT::estimateDistWithCur3DAsymLUT( TComPic * pCurPic , UInt refLayerIdc )
    138241{
     
    174277  return( dErrorLuma + dErrorChroma);
    175278}
    176 
     279#endif
     280
     281#if R0151_CGS_3D_ASYMLUT_IMPROVE
     282Double TEnc3DAsymLUT::derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB )
     283{
     284  m_nLUTBitDepth = pCfg->getCGSLUTBit();
     285  Int nCurYPartNumLog2 = 0 , nCurOctantDepth = 0;
     286  xxDerivePartNumLog2( pSlice , pCfg , nCurOctantDepth , nCurYPartNumLog2 , bSignalPPS , bElRapSliceTypeB );
     287
     288  Int nBestResQuanBit = 0;
     289  Int nBestAdaptCThresholdU = 1 << ( getInputBitDepthC() - 1 );
     290  Int nBestAdaptCThresholdV = 1 << ( getInputBitDepthC() - 1 );
     291  Int nBestOctantDepth = nCurOctantDepth;
     292  Int nBestYPartNumLog2 = nCurYPartNumLog2;
     293  Int nTargetLoop = 1 + ( pCfg->getCGSAdaptChroma() && ( nCurOctantDepth == 1 || ( nCurOctantDepth * 3 + nCurYPartNumLog2 ) >= 5 ) );
     294  Double dMinError = MAX_DOUBLE;
     295  for( Int nLoop = 0 ; nLoop < nTargetLoop ; nLoop++ )
     296  {
     297    Int nAdaptCThresholdU = 1 << ( getInputBitDepthC() - 1 );
     298    Int nAdaptCThresholdV = 1 << ( getInputBitDepthC() - 1 );
     299    if( nLoop > 0 )
     300    {
     301      nAdaptCThresholdU = ( Int )( m_dSumU / m_nNChroma + 0.5 );
     302      nAdaptCThresholdV = ( Int )( m_dSumV / m_nNChroma + 0.5 );
     303      if( nCurOctantDepth > 1 )
     304      {
     305        nCurOctantDepth = 1;
     306        nCurYPartNumLog2 = 2;
     307      }
     308      if( nAdaptCThresholdU == nBestAdaptCThresholdU && nAdaptCThresholdV == nBestAdaptCThresholdV
     309        && nCurOctantDepth == nBestOctantDepth && nCurYPartNumLog2 == nBestYPartNumLog2 )
     310        break;
     311    }
     312    xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2 , nAdaptCThresholdU , nAdaptCThresholdV );
     313    xxCollectData( pCurPic , refLayerIdc );
     314    for( Int nResQuanBit = 0 ; nResQuanBit < 4 ; nResQuanBit++ )
     315    {
     316      Double dError = xxDeriveVertexes( nResQuanBit , m_pEncCuboid ) / ( 1 + ( nResQuanBit > 0 ) * 0.001 * ( pSlice->getDepth() + 1 ) );
     317      if( dError <= dMinError )
     318      {
     319        nBestResQuanBit = nResQuanBit;
     320        nBestAdaptCThresholdU = nAdaptCThresholdU;
     321        nBestAdaptCThresholdV = nAdaptCThresholdV;
     322        nBestOctantDepth = nCurOctantDepth;
     323        nBestYPartNumLog2 = nCurYPartNumLog2;
     324        SCuboid *** tmp = m_pBestEncCuboid;
     325        m_pBestEncCuboid = m_pEncCuboid;
     326        m_pEncCuboid = tmp;
     327        dMinError = dError;
     328      }
     329      else
     330      {
     331        break;
     332      }
     333    }
     334  }
     335  setResQuantBit( nBestResQuanBit );
     336  xUpdatePartitioning( nBestOctantDepth , nBestYPartNumLog2 , nBestAdaptCThresholdU , nBestAdaptCThresholdV );
     337  xSaveCuboids( m_pBestEncCuboid );
     338  return( dMinError );
     339}
     340#else
    177341Double TEnc3DAsymLUT::derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB )
    178342{
     
    204368  setResQuantBit( nBestResQuanBit );
    205369  xSaveCuboids( m_pBestEncCuboid );
    206 
    207370  return( dCurError );
    208371}
     372#endif
    209373
    210374Double TEnc3DAsymLUT::xxDeriveVertexes( Int nResQuanBit , SCuboid *** pCurCuboid )
     
    213377  Int nYSize = 1 << ( getCurOctantDepth() + getCurYPartNumLog2() );
    214378  Int nUVSize = 1 << getCurOctantDepth();
     379#if !R0151_CGS_3D_ASYMLUT_IMPROVE
    215380  Int nLengthY = 1 << ( getInputBitDepthY() - getCurOctantDepth() - getCurYPartNumLog2() );
    216381  Int nLengthUV = 1 << ( getInputBitDepthC() - getCurOctantDepth() );
     382#endif
    217383  for( Int yIdx = 0 ; yIdx < nYSize ; yIdx++ )
    218384  {
     
    224390        SColorInfo & rCuboidColorInfoC = m_pColorInfoC[yIdx][uIdx][vIdx];
    225391        SCuboid & rCuboid = pCurCuboid[yIdx][uIdx][vIdx];
     392#if !R0151_CGS_3D_ASYMLUT_IMPROVE
    226393        Int y0 = yIdx << xGetYShift2Idx();
    227394        Int u0 = uIdx << xGetUShift2Idx();
    228395        Int v0 = vIdx << xGetVShift2Idx();
     396#endif
    229397        for( Int idxVertex = 0 ; idxVertex < 4 ; idxVertex++ )
    230398        {
     
    235403        {
    236404          dErrorLuma += xxDeriveVertexPerColor( rCuboidColorInfo.N , rCuboidColorInfo.Ys , rCuboidColorInfo.Yy , rCuboidColorInfo.Yu , rCuboidColorInfo.Yv , rCuboidColorInfo.ys , rCuboidColorInfo.us , rCuboidColorInfo.vs , rCuboidColorInfo.yy , rCuboidColorInfo.yu , rCuboidColorInfo.yv , rCuboidColorInfo.uu , rCuboidColorInfo.uv , rCuboidColorInfo.vv , rCuboidColorInfo.YY ,
    237             y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].Y , rCuboid.P[1].Y , rCuboid.P[2].Y , rCuboid.P[3].Y , nResQuanBit );
     405#if !R0151_CGS_3D_ASYMLUT_IMPROVE
     406            y0 , u0 , v0 , nLengthY , nLengthUV ,
     407#endif
     408            rCuboid.P[0].Y , rCuboid.P[1].Y , rCuboid.P[2].Y , rCuboid.P[3].Y , nResQuanBit );
    238409        }
    239410        if( rCuboidColorInfoC.N > 0 )
    240411        {
    241412          dErrorChroma += xxDeriveVertexPerColor( rCuboidColorInfoC.N , rCuboidColorInfoC.Us , rCuboidColorInfoC.Uy , rCuboidColorInfoC.Uu , rCuboidColorInfoC.Uv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.UU ,
    242             y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].U , rCuboid.P[1].U , rCuboid.P[2].U , rCuboid.P[3].U , nResQuanBit );
     413#if !R0151_CGS_3D_ASYMLUT_IMPROVE
     414            y0 , u0 , v0 , nLengthY , nLengthUV ,
     415#endif
     416            rCuboid.P[0].U , rCuboid.P[1].U , rCuboid.P[2].U , rCuboid.P[3].U , nResQuanBit );
    243417          dErrorChroma += xxDeriveVertexPerColor( rCuboidColorInfoC.N , rCuboidColorInfoC.Vs , rCuboidColorInfoC.Vy , rCuboidColorInfoC.Vu , rCuboidColorInfoC.Vv , rCuboidColorInfoC.ys , rCuboidColorInfoC.us , rCuboidColorInfoC.vs , rCuboidColorInfoC.yy , rCuboidColorInfoC.yu , rCuboidColorInfoC.yv , rCuboidColorInfoC.uu , rCuboidColorInfoC.uv , rCuboidColorInfoC.vv , rCuboidColorInfoC.VV ,
    244             y0 , u0 , v0 , nLengthY , nLengthUV , rCuboid.P[0].V , rCuboid.P[1].V , rCuboid.P[2].V , rCuboid.P[3].V , nResQuanBit );
     418#if !R0151_CGS_3D_ASYMLUT_IMPROVE
     419            y0 , u0 , v0 , nLengthY , nLengthUV ,
     420#endif
     421            rCuboid.P[0].V , rCuboid.P[1].V , rCuboid.P[2].V , rCuboid.P[3].V , nResQuanBit );
    245422        }
    246423
     
    299476  // since we do data collection only for overlapped region, the border extension is good enough
    300477
     478#if R0151_CGS_3D_ASYMLUT_IMPROVE
     479  m_dSumU = m_dSumV = 0;
     480  m_nNChroma = 0;
     481#endif
    301482  for( Int i = top ; i <= bottom ; i++ )
    302483  {
     
    330511      }
    331512
     513#if R0151_CGS_3D_ASYMLUT_IMPROVE
     514      m_dSumU += u;
     515      m_dSumV += v;
     516      m_nNChroma++;
     517#endif
    332518      SColorInfo sColorInfo;
     519#if R0151_CGS_3D_ASYMLUT_IMPROVE
     520      SColorInfo & rCuboidColorInfo = m_pColorInfo[xGetYIdx(y)][xGetUIdx(u)][xGetVIdx(v)];
     521#else
    333522      SColorInfo & rCuboidColorInfo = m_pColorInfo[y>>xGetYShift2Idx()][u>>xGetUShift2Idx()][v>>xGetVShift2Idx()];
     523#endif
    334524      memset(&sColorInfo, 0, sizeof(SColorInfo));
    335525      sColorInfo.Ys = Y;
     
    358548        u = pIRLU[posIRLUV];
    359549        v = pIRLV[posIRLUV];
     550#if R0151_CGS_3D_ASYMLUT_IMPROVE
     551        SColorInfo & rCuboidColorInfoC = m_pColorInfoC[xGetYIdx(y)][xGetUIdx(u)][xGetVIdx(v)];
     552#else
    360553        SColorInfo & rCuboidColorInfoC = m_pColorInfoC[y>>xGetYShift2Idx()][u>>xGetUShift2Idx()][v>>xGetVShift2Idx()];
     554#endif
    361555        sColorInfo.Us = U;
    362556        sColorInfo.Vs = V;
     
    389583Void TEnc3DAsymLUT::xxDerivePartNumLog2( TComSlice * pSlice , TEncCfg * pcCfg , Int & rOctantDepth , Int & rYPartNumLog2 , Bool bSignalPPS , Bool bElRapSliceTypeB )
    390584{
    391   Int nSliceType = pSlice->getSliceType();
    392   // update slice type as what will be done later
    393   if( pSlice->getActiveNumILRRefIdx() == 0 && pSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP && pSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA )
    394   {
    395     nSliceType = I_SLICE;
    396   }
    397   else if( !bElRapSliceTypeB )
    398   {
    399     if( (pSlice->getNalUnitType() >= NAL_UNIT_CODED_SLICE_BLA_W_LP) &&
    400       (pSlice->getNalUnitType() <= NAL_UNIT_CODED_SLICE_CRA) &&
    401       pSlice->getSliceType() == B_SLICE )
    402     {
    403       nSliceType = P_SLICE;
    404     }
    405   }
    406 
    407   const Int nSliceTempLevel = pSlice->getDepth();
    408585  Int nPartNumLog2 = 4;
    409586  if( pSlice->getBaseColPic( pSlice->getInterLayerPredLayerIdc( 0 ) )->getSlice( 0 )->isIntra() )
     
    411588    nPartNumLog2 = xGetMaxPartNumLog2();
    412589  }
    413   if( m_nPrevFrameBit[nSliceType][nSliceTempLevel] && pSlice->getPPS()->getCGSFlag() )
    414   {
    415     Double dBitCost = 1.0 * m_nPrevFrameCGSBit[nSliceType][nSliceTempLevel] / m_nPrevFrameBit[nSliceType][nSliceTempLevel];
    416     nPartNumLog2 = m_nPrevFrameCGSPartNumLog2[nSliceType][nSliceTempLevel];
     590  if( m_nAccuFrameBit && pSlice->getPPS()->getCGSFlag() )
     591  {
     592    Double dBitCost = 1.0 * m_nAccuFrameCGSBit / m_nAccuFrameBit;
     593    nPartNumLog2 = m_nPrevFrameCGSPartNumLog2;
    417594    Double dBitCostT = 0.03;
    418595    if( dBitCost < dBitCostT / 6.0 )
     
    425602    }
    426603  }
    427   else
    428   {
    429     nPartNumLog2 -= nSliceTempLevel;
    430   }
    431   nPartNumLog2 = Clip3( 0 , xGetMaxPartNumLog2() , nPartNumLog2 );
     604  nPartNumLog2 = Clip3( 0 , xGetMaxPartNumLog2()  , nPartNumLog2 );
    432605  xxMapPartNum2DepthYPart( nPartNumLog2 , rOctantDepth , rYPartNumLog2 );
    433606}
     
    453626Void TEnc3DAsymLUT::updatePicCGSBits( TComSlice * pcSlice , Int nPPSBit )
    454627{
    455   const Int nSliceType = pcSlice->getSliceType();
    456   const Int nSliceTempLevel = pcSlice->getDepth();
    457 
    458628  for( Int i = 0; i < pcSlice->getActiveNumILRRefIdx(); i++ )
    459629  {
    460630    UInt refLayerIdc = pcSlice->getInterLayerPredLayerIdc(i);
    461     m_nPrevFrameBit[nSliceType][nSliceTempLevel] = pcSlice->getPic()->getFrameBit() + pcSlice->getBaseColPic(refLayerIdc)->getFrameBit();
     631    m_nAccuFrameBit += pcSlice->getPic()->getFrameBit() + pcSlice->getBaseColPic(refLayerIdc)->getFrameBit();
    462632    m_dTotalFrameBit += pcSlice->getPic()->getFrameBit() + pcSlice->getBaseColPic(refLayerIdc)->getFrameBit();
    463633  }
    464   m_nPrevFrameOverWritePPS[nSliceType][nSliceTempLevel] = pcSlice->getCGSOverWritePPS();
    465   m_nPrevFrameCGSBit[nSliceType][nSliceTempLevel] = nPPSBit;
     634  m_nAccuFrameCGSBit += nPPSBit;
    466635  m_nTotalCGSBit += nPPSBit;
    467   m_nPrevFrameCGSPartNumLog2[nSliceType][nSliceTempLevel] = getCurOctantDepth() * 3 + getCurYPartNumLog2();
    468 }
    469 
    470 #endif
     636  m_nPrevFrameCGSPartNumLog2 = getCurOctantDepth() * 3 + getCurYPartNumLog2();
     637}
     638
     639#endif
  • branches/SHM-dev/source/Lib/TLibEncoder/TEnc3DAsymLUT.h

    r713 r825  
    7878  SCuboid *** m_pEncCuboid;
    7979  SCuboid *** m_pBestEncCuboid;
    80   Int   m_nPrevFrameBit[3][MAX_TLAYER];                  // base + enhancement layer
    81   Int   m_nPrevFrameCGSBit[3][MAX_TLAYER];
    82   Int   m_nPrevFrameCGSPartNumLog2[3][MAX_TLAYER];
    83   Int   m_nPrevFrameOverWritePPS[3][MAX_TLAYER];
     80  Int   m_nAccuFrameBit;                  // base + enhancement layer
     81  Int   m_nAccuFrameCGSBit;
     82  Int   m_nPrevFrameCGSPartNumLog2;
    8483  Double m_dTotalFrameBit;
    8584  Int   m_nTotalCGSBit;
    8685  Int   m_nPPSBit;
    8786  Int   m_nLUTBitDepth;
     87#if R0151_CGS_3D_ASYMLUT_IMPROVE
     88  Double m_dSumU;
     89  Double m_dSumV;
     90  Int    m_nNChroma;
     91#endif
    8892
    8993private:
     94#if R0151_CGS_3D_ASYMLUT_IMPROVE
     95  Double  xxDeriveVertexPerColor( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
     96    Pel & rP0 , Pel & rP1 , Pel & rP3 , Pel & rP7 , Int nResQuantBit );
     97#else
    9098  Double  xxDeriveVertexPerColor( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
    9199    Int y0 , Int u0 , Int v0 , Int nLengthY , Int nLengthUV ,
    92100    Pel & rP0 , Pel & rP1 , Pel & rP3 , Pel & rP7 , Int nResQuantBit );
     101#endif
    93102  Void    xxDerivePartNumLog2( TComSlice * pSlice , TEncCfg * pcCfg , Int & rOctantDepth , Int & rYPartNumLog2 , Bool bSignalPPS , Bool bElRapSliceTypeB );
    94103  Void    xxMapPartNum2DepthYPart( Int nPartNumLog2 , Int & rOctantDepth , Int & rYPartNumLog2 );
     
    100109  inline Double  xxCalEstDist( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
    101110    Double a , Double b , Double c , Double d );
     111#if R0151_CGS_3D_ASYMLUT_IMPROVE
     112  inline Double  xxCalEstDist( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
     113    Pel nP0 , Pel nP1 , Pel nP3 , Pel nP7 );
     114#endif
    102115};
    103116
     
    118131  return( dError );
    119132};
     133
     134#if R0151_CGS_3D_ASYMLUT_IMPROVE
     135Double TEnc3DAsymLUT::xxCalEstDist( Double N , Double Ys , Double Yy , Double Yu , Double Yv , Double ys , Double us , Double vs , Double yy , Double yu , Double yv , Double uu , Double uv , Double vv , Double YY ,
     136  Pel nP0 , Pel nP1 , Pel nP3 , Pel nP7 )
     137{
     138  const Int nOne = xGetNormCoeffOne();
     139  Double a = 1.0 * nP0 / nOne;
     140  Double b = 1.0 * nP1 / nOne;
     141  Double c = 1.0 * nP3 / nOne;
     142  Double d = nP7;
     143  Double dError = N * d * d + 2 * b * c * uv + 2 * a * c * yv + 2 * a * b * yu - 2 * c * Yv - 2 * b * Yu - 2 * a * Yy + 2 * c * d * vs + 2 * b * d * us + 2 * a * d * ys + a * a * yy + c * c * vv + b * b * uu - 2 * d * Ys + YY;
     144  return( dError );
     145};
    120146#endif
    121147
    122148#endif
     149
     150#endif
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.cpp

    r824 r825  
    27622762Void TEncCavlc::xCode3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT )
    27632763{
     2764#if R0150_CGS_SIGNAL_CONSTRAINTS
     2765  UInt uiNumRefLayers = ( UInt )pc3DAsymLUT->getRefLayerNum();
     2766  WRITE_UVLC( uiNumRefLayers - 1 , "num_cm_ref_layers_minus1" );
     2767  for( UInt i = 0 ; i < uiNumRefLayers ; i++ )
     2768  {
     2769    WRITE_CODE( pc3DAsymLUT->getRefLayerId( i ) , 6 , "cm_ref_layer_id" );
     2770  }
     2771#endif
    27642772  assert( pc3DAsymLUT->getCurOctantDepth() < 4 );
    27652773  WRITE_CODE( pc3DAsymLUT->getCurOctantDepth() , 2 , "cm_octant_depth" );
     
    27672775  WRITE_CODE( pc3DAsymLUT->getCurYPartNumLog2() , 2 , "cm_y_part_num_log2" );
    27682776  assert( pc3DAsymLUT->getInputBitDepthY() < 16 );
     2777#if R0150_CGS_SIGNAL_CONSTRAINTS
     2778  WRITE_CODE( pc3DAsymLUT->getInputBitDepthY() - 8 , 3 , "cm_input_luma_bit_depth_minus8" );
     2779  WRITE_CODE( pc3DAsymLUT->getInputBitDepthC() - 8 , 3 , "cm_input_chroma_bit_depth_minus8" );
     2780  WRITE_CODE( pc3DAsymLUT->getOutputBitDepthY() - 8 , 3 , "cm_output_luma_bit_depth_minus8" );
     2781  WRITE_CODE( pc3DAsymLUT->getOutputBitDepthC() - 8 , 3 , "cm_output_chroma_bit_depth_minus8" );
     2782#else
    27692783  WRITE_CODE( pc3DAsymLUT->getInputBitDepthY() - 8 , 3 , "cm_input_bit_depth_minus8" );
    27702784  WRITE_SVLC(pc3DAsymLUT->getInputBitDepthC()-pc3DAsymLUT->getInputBitDepthY(), "cm_input_bit_depth_chroma delta");
     
    27722786  WRITE_CODE( pc3DAsymLUT->getOutputBitDepthY() - 8 , 3 , "cm_output_bit_depth_minus8" );
    27732787  WRITE_SVLC(pc3DAsymLUT->getOutputBitDepthC()-pc3DAsymLUT->getOutputBitDepthY(), "cm_output_bit_depth_chroma_delta");
     2788#endif
    27742789  assert( pc3DAsymLUT->getResQuantBit() < 4 );
    27752790  WRITE_CODE( pc3DAsymLUT->getResQuantBit() , 2 , "cm_res_quant_bit" );
    2776 
     2791#if R0151_CGS_3D_ASYMLUT_IMPROVE
     2792  if( pc3DAsymLUT->getCurOctantDepth() == 1 )
     2793  {
     2794    WRITE_SVLC( pc3DAsymLUT->getAdaptChromaThresholdU() - ( 1 << ( pc3DAsymLUT->getInputBitDepthC() - 1 ) ) , "cm_adapt_threshold_u_delta" );
     2795    WRITE_SVLC( pc3DAsymLUT->getAdaptChromaThresholdV() - ( 1 << ( pc3DAsymLUT->getInputBitDepthC() - 1 ) ) , "cm_adapt_threshold_v_delta" );
     2796  }
     2797#endif
     2798
     2799#if R0164_CGS_LUT_BUGFIX
     2800  pc3DAsymLUT->xInitCuboids();
     2801#endif
    27772802  xCode3DAsymLUTOctant( pc3DAsymLUT , 0 , 0 , 0 , 0 , 1 << pc3DAsymLUT->getCurOctantDepth() );
     2803#if R0164_CGS_LUT_BUGFIX
     2804  pc3DAsymLUT->xCuboidsExplicitCheck( false );
     2805#endif
    27782806}
    27792807
     
    28022830    for( Int l = 0 ; l < nYPartNum ; l++ )
    28032831    {
     2832#if R0164_CGS_LUT_BUGFIX     
     2833      Int shift = pc3DAsymLUT->getMaxOctantDepth() - nDepth ;
     2834#endif
    28042835      for( Int nVertexIdx = 0 ; nVertexIdx < 4 ; nVertexIdx++ )
    28052836      {
     2837#if R0164_CGS_LUT_BUGFIX
     2838        SYUVP sRes = pc3DAsymLUT->getCuboidVertexResTree( yIdx + (l<<shift) , uIdx , vIdx , nVertexIdx );
     2839#else
    28062840        SYUVP sRes = pc3DAsymLUT->getCuboidVertexResTree( yIdx + l , uIdx , vIdx , nVertexIdx );
     2841#endif
    28072842        UInt uiCodeVertex = sRes.Y != 0 || sRes.U != 0 || sRes.V != 0;
    28082843        WRITE_FLAG( uiCodeVertex , "coded_vertex_flag" );
    28092844        if( uiCodeVertex )
    28102845        {
     2846#if R0151_CGS_3D_ASYMLUT_IMPROVE
     2847          xWriteParam( sRes.Y );
     2848          xWriteParam( sRes.U );
     2849          xWriteParam( sRes.V );
     2850#else
    28112851          WRITE_SVLC( sRes.Y , "resY" );
    28122852          WRITE_SVLC( sRes.U , "resU" );
    28132853          WRITE_SVLC( sRes.V , "resV" );
    2814         }
    2815       }
    2816     }
    2817   }
    2818 }
     2854#endif
     2855        }
     2856      }
     2857#if R0164_CGS_LUT_BUGFIX
     2858      pc3DAsymLUT->xSetExplicit( yIdx + (l<<shift) , uIdx , vIdx );
     2859#endif
     2860    }
     2861  }
     2862}
     2863
     2864#if R0151_CGS_3D_ASYMLUT_IMPROVE
     2865Void TEncCavlc::xWriteParam( Int param)
     2866{
     2867  const UInt rParam = 7;
     2868  Int codeNumber = abs(param);
     2869  WRITE_UVLC(codeNumber / (1 << rParam), "quotient");
     2870  WRITE_CODE((codeNumber % (1 << rParam)), rParam, "remainder");
     2871  if (abs(param))
     2872    WRITE_FLAG( param <0, "sign");
     2873}
     2874#endif
     2875
    28192876#endif
    28202877//! \}
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.h

    r815 r825  
    173173  Void xCode3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT );
    174174  Void xCode3DAsymLUTOctant( TCom3DAsymLUT * pc3DAsymLUT , Int nDepth , Int yIdx , Int uIdx , Int vIdx , Int nLength );
     175#if R0151_CGS_3D_ASYMLUT_IMPROVE
     176  Void xWriteParam( Int param);
     177#endif
    175178#endif
    176179#endif //SVC_EXTENSION
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncCfg.h

    r823 r825  
    367367  Int  m_nCGSMaxYPartNumLog2;
    368368  Int  m_nCGSLUTBit;
     369#if R0151_CGS_3D_ASYMLUT_IMPROVE
     370  Int  m_nCGSAdaptiveChroma;
     371#endif
    369372#endif
    370373#if P0050_KNEE_FUNCTION_SEI
     
    940943  Void      setCGSLUTBit(Int n)           { m_nCGSLUTBit = n;    }
    941944  Int       getCGSLUTBit()                { return m_nCGSLUTBit; }
     945#if R0151_CGS_3D_ASYMLUT_IMPROVE
     946  Void      setCGSAdaptChroma(Int n)      { m_nCGSAdaptiveChroma = n;  }
     947  Int       getCGSAdaptChroma()           { return m_nCGSAdaptiveChroma; }
     948#endif
    942949#endif
    943950#endif
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp

    r823 r825  
    11531153        if( pcSlice->getPPS()->getCGSFlag() )
    11541154        {
     1155#if R0150_CGS_SIGNAL_CONSTRAINTS
     1156          // all reference layers are currently taken as CGS reference layers
     1157          m_Enc3DAsymLUTPPS.addRefLayerId( pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc) );
     1158          m_Enc3DAsymLUTPicUpdate.addRefLayerId( pcSlice->getVPS()->getRefLayerId(m_layerId, refLayerIdc) );
     1159#endif
    11551160          if(g_posScalingFactor[refLayerIdc][0] < (1<<16) || g_posScalingFactor[refLayerIdc][1] < (1<<16)) //if(pcPic->isSpatialEnhLayer(refLayerIdc))
    11561161          {
     
    39873992  if( m_layerId && pcSlice->getPPS()->getCGSFlag() )
    39883993  {
     3994    if( m_Enc3DAsymLUTPPS.getPPSBit() > 0 )
     3995      m_Enc3DAsymLUTPicUpdate.copy3DAsymLUT( &m_Enc3DAsymLUTPPS );
    39893996    m_Enc3DAsymLUTPicUpdate.updatePicCGSBits( pcSlice , m_Enc3DAsymLUTPPS.getPPSBit() );
    39903997  }
Note: See TracChangeset for help on using the changeset viewer.