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


Ignore:
Timestamp:
28 Aug 2014, 06:22:48 (10 years ago)
Author:
interdigital
Message:

Integrated the encoder changes for RD-based 3D LUT size selection from R0179 (macro R0179_ENC_OPT_3DLUT_SIZE)

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

Legend:

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

    r855 r877  
    1414  m_pColorInfoC = NULL;
    1515  m_pEncCuboid = NULL;
     16
    1617  m_pBestEncCuboid = NULL;
    1718#if R0151_CGS_3D_ASYMLUT_IMPROVE
     
    2930  m_nPPSBit = 0;
    3031  m_pDsOrigPic = NULL;
     32#if R0179_ENC_OPT_3DLUT_SIZE
     33  m_pMaxColorInfo = NULL;
     34  m_pMaxColorInfoC = NULL;
     35
     36 
     37  // fixed m_dDistFactor
     38  Double dTmpFactor[3];   
     39  dTmpFactor[I_SLICE] = 1.0;
     40  dTmpFactor[P_SLICE] = 4./3.;
     41  dTmpFactor[B_SLICE] = 1.5;
     42  for( Int iSliceType = 0; iSliceType < 3; iSliceType++)
     43  {
     44    for(Int iLayer = 0; iLayer < MAX_TLAYER; iLayer++)
     45    {
     46      m_dDistFactor[iSliceType][iLayer] = dTmpFactor[iSliceType]*(Double)(1<<iLayer);     
     47    }
     48  }
     49  // initialization with approximate number of bits to code the LUT
     50  m_nNumLUTBits[0][0] = 200; // 1x1x1
     51  m_nNumLUTBits[1][0] = 400; // 2x1x1 
     52  m_nNumLUTBits[1][1] = 1500; // 2x2x2 
     53  m_nNumLUTBits[2][0] = 800; // 4x1x1
     54  m_nNumLUTBits[2][1] = 3200; // 4x2x2 
     55  m_nNumLUTBits[2][2] = 8500; // 4x4x4 
     56  m_nNumLUTBits[3][0] = 1200; // 8x1x1
     57  m_nNumLUTBits[3][1] = 4500; // 8x2x2 
     58  m_nNumLUTBits[3][2] = 10000; // 8x4x4 
     59  m_nNumLUTBits[3][3] = 12000; // 8x8x8
     60#endif
    3161}
    3262
     
    4777  xAllocate3DArray( m_pEncCuboid , xGetYSize() , xGetUSize() , xGetVSize() );
    4878  xAllocate3DArray( m_pBestEncCuboid , xGetYSize() , xGetUSize() , xGetVSize() );
     79#if R0179_ENC_OPT_3DLUT_SIZE
     80  xAllocate3DArray( m_pMaxColorInfo , xGetYSize() , xGetUSize() , xGetVSize() );
     81  xAllocate3DArray( m_pMaxColorInfoC , xGetYSize() , xGetUSize() , xGetVSize() );
     82
     83  m_pEncCavlc = new TEncCavlc;
     84  m_pBitstreamRedirect = new TComOutputBitstream;
     85  m_pEncCavlc->setBitstream(m_pBitstreamRedirect);
     86#endif
    4987}
    5088
     
    5593  xFree3DArray( m_pEncCuboid );
    5694  xFree3DArray( m_pBestEncCuboid );
     95#if R0179_ENC_OPT_3DLUT_SIZE
     96  xFree3DArray( m_pMaxColorInfo );
     97  xFree3DArray( m_pMaxColorInfoC );
     98  delete m_pBitstreamRedirect;
     99  delete m_pEncCavlc;
     100#endif
    57101  TCom3DAsymLUT::destroy();
    58102}
     
    287331
    288332#if R0151_CGS_3D_ASYMLUT_IMPROVE
     333#if R0179_ENC_OPT_3DLUT_SIZE
     334Double TEnc3DAsymLUT::derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB, Double dFrameLambda )
     335{
     336  m_nLUTBitDepth = pCfg->getCGSLUTBit();
     337
     338  Int nBestAdaptCThresholdU = 1 << ( getInputBitDepthC() - 1 );
     339  Int nBestAdaptCThresholdV = 1 << ( getInputBitDepthC() - 1 );
     340  Int nAdaptCThresholdU, nAdaptCThresholdV;
     341
     342  Int nTmpLutBits[MAX_Y_SIZE][MAX_C_SIZE] ;
     343  memset(nTmpLutBits, 0, sizeof(nTmpLutBits));
     344
     345  SLUTSize sMaxLutSize; 
     346
     347  // collect stats for the most partitions
     348  Int nCurYPartNumLog2 = 0 , nCurOctantDepth = 0;
     349  Int nMaxPartNumLog2 = xGetMaxPartNumLog2();
     350
     351  xxMapPartNum2DepthYPart( nMaxPartNumLog2 , nCurOctantDepth , nCurYPartNumLog2 );
     352  xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2, nBestAdaptCThresholdU, nBestAdaptCThresholdV );
     353  xxCollectData( pCurPic , refLayerIdc );
     354  xxCopyColorInfo(m_pMaxColorInfo, m_pColorInfo, m_pMaxColorInfoC, m_pColorInfoC);
     355 
     356  sMaxLutSize.iCPartNumLog2 = nCurOctantDepth;
     357  sMaxLutSize.iYPartNumLog2 = nCurOctantDepth + nCurYPartNumLog2;
     358
     359  m_pBitstreamRedirect->clear();
     360
     361  // find the best partition based on RD cost
     362  Int i;
     363  Double dMinCost, dCurCost;
     364
     365  Int iBestLUTSizeIdx = 0;   
     366  Int nBestResQuanBit = 0;
     367  Double dCurError, dMinError;
     368  Int iNumBitsCurSize;
     369  Int iNumBitsCurSizeSave = m_pEncCavlc->getNumberOfWrittenBits();
     370  Double dDistFactor = getDistFactor(pSlice->getSliceType(), pSlice->getDepth());
     371
     372  // check all LUT sizes
     373  xxGetAllLutSizes(pSlice); 
     374  if (m_nTotalLutSizes == 0) // return if no valid size is found, LUT will not be updated
     375  {
     376    nCurOctantDepth = sMaxLutSize.iCPartNumLog2;
     377    nCurYPartNumLog2 = sMaxLutSize.iYPartNumLog2-nCurOctantDepth;
     378    xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2, nBestAdaptCThresholdU, nBestAdaptCThresholdV );
     379    return MAX_DOUBLE;
     380  }
     381
     382  dMinCost = MAX_DOUBLE; dMinError = MAX_DOUBLE;
     383  for (i = 0; i < m_nTotalLutSizes; i++)
     384  {
     385    // add up the stats
     386    nCurOctantDepth = m_sLutSizes[i].iCPartNumLog2;
     387    nCurYPartNumLog2 = m_sLutSizes[i].iYPartNumLog2-nCurOctantDepth;
     388    xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2, nBestAdaptCThresholdU, nBestAdaptCThresholdV );
     389    xxConsolidateData( &m_sLutSizes[i], &sMaxLutSize );
     390 
     391    dCurError = xxDeriveVertexes(nBestResQuanBit, m_pEncCuboid);
     392
     393    setResQuantBit( nBestResQuanBit );
     394    xSaveCuboids( m_pEncCuboid );
     395    m_pEncCavlc->xCode3DAsymLUT( this );
     396    iNumBitsCurSize = m_pEncCavlc->getNumberOfWrittenBits();
     397    dCurCost = dCurError/dDistFactor + dFrameLambda*(Double)(iNumBitsCurSize-iNumBitsCurSizeSave); 
     398    nTmpLutBits[m_sLutSizes[i].iYPartNumLog2][m_sLutSizes[i].iCPartNumLog2] = iNumBitsCurSize-iNumBitsCurSizeSave; // store LUT size
     399    iNumBitsCurSizeSave = iNumBitsCurSize;
     400    if(dCurCost < dMinCost )
     401    {
     402      SCuboid *** tmp = m_pBestEncCuboid;
     403      m_pBestEncCuboid = m_pEncCuboid;
     404      m_pEncCuboid = tmp;
     405      dMinCost = dCurCost;
     406      dMinError = dCurError;
     407      iBestLUTSizeIdx = i;
     408    }
     409  }
     410
     411  nCurOctantDepth = m_sLutSizes[iBestLUTSizeIdx].iCPartNumLog2;
     412  nCurYPartNumLog2 = m_sLutSizes[iBestLUTSizeIdx].iYPartNumLog2-nCurOctantDepth;
     413
     414  xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2, nBestAdaptCThresholdU, nBestAdaptCThresholdV );
     415
     416  Bool bUseNewColorInfo = false;
     417  if( pCfg->getCGSAdaptChroma() && nCurOctantDepth <= 1 ) // if the best size found so far has depth = 0 or 1, then check AdaptC U/V thresholds
     418  {
     419    nAdaptCThresholdU = ( Int )( m_dSumU / m_nNChroma + 0.5 );
     420    nAdaptCThresholdV = ( Int )( m_dSumV / m_nNChroma + 0.5 );
     421    if( !(nAdaptCThresholdU == nBestAdaptCThresholdU && nAdaptCThresholdV == nBestAdaptCThresholdV ) )
     422    {
     423      nCurOctantDepth = 1;
     424      if( nCurOctantDepth + nCurYPartNumLog2 > getMaxYPartNumLog2()+getMaxOctantDepth() )
     425        nCurYPartNumLog2 = getMaxYPartNumLog2()+getMaxOctantDepth()-nCurOctantDepth;
     426      xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2 , nAdaptCThresholdU , nAdaptCThresholdV );
     427      xxCollectData( pCurPic , refLayerIdc );
     428
     429      dCurError = xxDeriveVertexes( nBestResQuanBit , m_pEncCuboid ) ;
     430      setResQuantBit( nBestResQuanBit );
     431      xSaveCuboids( m_pEncCuboid );
     432      m_pEncCavlc->xCode3DAsymLUT( this );
     433      iNumBitsCurSize = m_pEncCavlc->getNumberOfWrittenBits();
     434      dCurCost = dCurError/dDistFactor + dFrameLambda*(Double)(iNumBitsCurSize-iNumBitsCurSizeSave); 
     435      iNumBitsCurSizeSave = iNumBitsCurSize;
     436      if(dCurCost < dMinCost )
     437      {
     438        SCuboid *** tmp = m_pBestEncCuboid;
     439        m_pBestEncCuboid = m_pEncCuboid;
     440        m_pEncCuboid = tmp;
     441        dMinCost = dCurCost;
     442        dMinError = dCurError;
     443        nBestAdaptCThresholdU = nAdaptCThresholdU;
     444        nBestAdaptCThresholdV = nAdaptCThresholdV;
     445        bUseNewColorInfo = true;
     446      }
     447    }
     448  }
     449
     450  xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2, nBestAdaptCThresholdU, nBestAdaptCThresholdV );
     451
     452  // check res_quant_bits only for the best table size and best U/V threshold
     453  if( !bUseNewColorInfo )
     454    xxConsolidateData( &m_sLutSizes[iBestLUTSizeIdx], &sMaxLutSize );
     455
     456  //    xxCollectData( pCurPic , refLayerIdc );
     457  for( Int nResQuanBit = 1 ; nResQuanBit < 4 ; nResQuanBit++ )
     458  {
     459    dCurError = xxDeriveVertexes( nResQuanBit , m_pEncCuboid );
     460
     461    setResQuantBit( nResQuanBit );
     462    xSaveCuboids( m_pEncCuboid );
     463    m_pEncCavlc->xCode3DAsymLUT( this );
     464    iNumBitsCurSize = m_pEncCavlc->getNumberOfWrittenBits();
     465    dCurCost = dCurError/dDistFactor + dFrameLambda*(Double)(iNumBitsCurSize-iNumBitsCurSizeSave);   
     466
     467    iNumBitsCurSizeSave = iNumBitsCurSize;
     468    if(dCurCost < dMinCost)
     469    {
     470      nBestResQuanBit = nResQuanBit;
     471      SCuboid *** tmp = m_pBestEncCuboid;
     472      m_pBestEncCuboid = m_pEncCuboid;
     473      m_pEncCuboid = tmp;
     474      dMinCost = dCurCost;
     475      dMinError = dCurError;
     476    }
     477    else
     478    {
     479      break;
     480    }
     481  }
     482   
     483  setResQuantBit( nBestResQuanBit );
     484  xSaveCuboids( m_pBestEncCuboid );
     485
     486  // update LUT size stats
     487  for(Int iLutSizeY = 0; iLutSizeY < MAX_Y_SIZE; iLutSizeY++)
     488  {
     489    for(Int iLutSizeC = 0; iLutSizeC < MAX_C_SIZE; iLutSizeC++)
     490    {
     491      if(nTmpLutBits[iLutSizeY][iLutSizeC] != 0)
     492        m_nNumLUTBits[iLutSizeY][iLutSizeC] =  (m_nNumLUTBits[iLutSizeY][iLutSizeC] + nTmpLutBits[iLutSizeY][iLutSizeC]*3+2)>>2; // update with new stats
     493    }
     494  }
     495
     496  // return cost rather than error
     497  return( dMinCost );
     498}
     499#endif
     500
     501
    289502Double TEnc3DAsymLUT::derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB )
    290503{
     
    317530        break;
    318531    }
     532
    319533    xUpdatePartitioning( nCurOctantDepth , nCurYPartNumLog2 , nAdaptCThresholdU , nAdaptCThresholdV );
    320534    xxCollectData( pCurPic , refLayerIdc );
     
    340554    }
    341555  }
     556
    342557  setResQuantBit( nBestResQuanBit );
    343558  xUpdatePartitioning( nBestOctantDepth , nBestYPartNumLog2 , nBestAdaptCThresholdU , nBestAdaptCThresholdV );
     559
    344560  xSaveCuboids( m_pBestEncCuboid );
    345561  return( dMinError );
     
    460676  Int nStrideILRY = pRecPic->getStride();
    461677  Int nStrideILRC = pRecPic->getCStride();
     678#if R0179_ENC_OPT_3DLUT_SIZE
     679  xReset3DArray( m_pColorInfo  , getMaxYSize() , getMaxCSize() , getMaxCSize() );
     680  xReset3DArray( m_pColorInfoC , getMaxYSize() , getMaxCSize() , getMaxCSize() );
     681#else
    462682  xReset3DArray( m_pColorInfo , xGetYSize() , xGetUSize() , xGetVSize() );
    463683  xReset3DArray( m_pColorInfoC , xGetYSize() , xGetUSize() , xGetVSize() );
     684#endif
    464685
    465686  //alignment padding
     
    693914  m_nPrevFrameCGSPartNumLog2[nSliceType][nSliceTempLevel] = getCurOctantDepth() * 3 + getCurYPartNumLog2();
    694915#endif
    695 }
    696 
    697 #endif
     916#if R0179_ENC_OPT_3DLUT_SIZE
     917  Int nCurELFrameBit = pcSlice->getPic()->getFrameBit();
     918  const Int nSliceType = pcSlice->getSliceType();
     919  const Int nSliceTempLevel = pcSlice->getDepth();
     920  m_nPrevELFrameBit[nSliceType][nSliceTempLevel] = m_nPrevELFrameBit[nSliceType][nSliceTempLevel] == 0 ? nCurELFrameBit:((m_nPrevELFrameBit[nSliceType][nSliceTempLevel]+nCurELFrameBit)>>1);
     921#endif
     922}
     923
     924#if R0179_ENC_OPT_3DLUT_SIZE
     925
     926Void TEnc3DAsymLUT::xxGetAllLutSizes(TComSlice *pSlice)
     927{
     928  Int iMaxYPartNumLog2, iMaxCPartNumLog2;
     929  Int iCurYPartNumLog2, iCurCPartNumLog2;
     930  Int iMaxAddYPartNumLog2;
     931  Int iNumELFrameBits = m_nPrevELFrameBit[pSlice->getSliceType()][pSlice->getDepth()];
     932
     933  xxMapPartNum2DepthYPart( xGetMaxPartNumLog2() , iMaxCPartNumLog2 , iMaxYPartNumLog2 );
     934  iMaxAddYPartNumLog2 = iMaxYPartNumLog2;
     935  iMaxYPartNumLog2 += iMaxCPartNumLog2;
     936
     937  //m_sLutSizes[0].iYPartNumLog2 = iMaxYPartNumLog2;
     938  //m_sLutSizes[0].iCPartNumLog2 = iMaxCPartNumLog2;
     939  m_nTotalLutSizes = 0;
     940
     941
     942  for(iCurYPartNumLog2 = iMaxYPartNumLog2; iCurYPartNumLog2 >= 0; iCurYPartNumLog2--)
     943  {
     944    for(iCurCPartNumLog2 = iMaxCPartNumLog2; iCurCPartNumLog2 >= 0; iCurCPartNumLog2--)
     945    {
     946       // try more sizes
     947      if(iCurCPartNumLog2 <= iCurYPartNumLog2  &&
     948         (m_nNumLUTBits[iCurYPartNumLog2][iCurCPartNumLog2] < (iNumELFrameBits>>1)) &&
     949         m_nTotalLutSizes < MAX_NUM_LUT_SIZES)
     950      {
     951        m_sLutSizes[m_nTotalLutSizes].iYPartNumLog2 = iCurYPartNumLog2;
     952        m_sLutSizes[m_nTotalLutSizes].iCPartNumLog2 = iCurCPartNumLog2;
     953        m_nTotalLutSizes ++;
     954      }
     955    }
     956  }
     957
     958}
     959
     960Void TEnc3DAsymLUT::xxCopyColorInfo( SColorInfo *** dst, SColorInfo *** src ,  SColorInfo *** dstC, SColorInfo *** srcC )
     961{
     962  Int yIdx, uIdx, vIdx;
     963
     964  // copy from pColorInfo to pMaxColorInfo
     965  for(yIdx = 0; yIdx < xGetYSize(); yIdx++)
     966  {
     967    for(uIdx = 0; uIdx < xGetUSize(); uIdx++)
     968    {
     969      for(vIdx = 0; vIdx < xGetVSize(); vIdx++)
     970      {
     971        dst [yIdx][uIdx][vIdx] = src [yIdx][uIdx][vIdx];
     972        dstC[yIdx][uIdx][vIdx] = srcC[yIdx][uIdx][vIdx];
     973      }
     974    }
     975  }
     976}
     977
     978Void TEnc3DAsymLUT::xxAddColorInfo( Int yIdx, Int uIdx, Int vIdx, Int iYDiffLog2, Int iCDiffLog2 )
     979{
     980  SColorInfo & rCuboidColorInfo  = m_pColorInfo [yIdx][uIdx][vIdx];
     981  SColorInfo & rCuboidColorInfoC = m_pColorInfoC[yIdx][uIdx][vIdx];
     982 
     983  for( Int i = 0; i < (1<<iYDiffLog2); i++)
     984  {
     985    for (Int j = 0; j < (1<<iCDiffLog2); j++)
     986    {
     987      for(Int k = 0; k < (1<<iCDiffLog2); k++)
     988      {
     989        rCuboidColorInfo  += m_pMaxColorInfo [(yIdx<<iYDiffLog2)+i][(uIdx<<iCDiffLog2)+j][(vIdx<<iCDiffLog2)+k];
     990        rCuboidColorInfoC += m_pMaxColorInfoC[(yIdx<<iYDiffLog2)+i][(uIdx<<iCDiffLog2)+j][(vIdx<<iCDiffLog2)+k];
     991      }
     992    }
     993  }
     994}
     995
     996Void TEnc3DAsymLUT::xxConsolidateData( SLUTSize *pCurLUTSize, SLUTSize *pMaxLUTSize )
     997{
     998  Int yIdx, uIdx, vIdx;
     999  Int iYDiffLog2, iCDiffLog2;
     1000  Int nYSize = 1<< pMaxLUTSize->iYPartNumLog2;
     1001  Int nCSize = 1<< pMaxLUTSize->iCPartNumLog2;
     1002
     1003  iYDiffLog2 = pMaxLUTSize->iYPartNumLog2-pCurLUTSize->iYPartNumLog2;
     1004  iCDiffLog2 = pMaxLUTSize->iCPartNumLog2-pCurLUTSize->iCPartNumLog2;
     1005
     1006  //assert(pMaxLUTSize->iCPartNumLog2 >= pCurLUTSize->iCPartNumLog2 && pMaxLUTSize->iYPartNumLog2 >= pCurLUTSize->iYPartNumLog2);
     1007  if (iYDiffLog2 == 0 && iCDiffLog2 == 0) // shouldn't have to do anything
     1008  {
     1009    xxCopyColorInfo(m_pColorInfo, m_pMaxColorInfo, m_pColorInfoC, m_pMaxColorInfoC);
     1010    return;
     1011  }
     1012
     1013  xReset3DArray( m_pColorInfo  ,  1<<pMaxLUTSize->iYPartNumLog2, 1<<pMaxLUTSize->iCPartNumLog2, 1<<pMaxLUTSize->iCPartNumLog2 );
     1014  xReset3DArray( m_pColorInfoC ,  1<<pMaxLUTSize->iYPartNumLog2, 1<<pMaxLUTSize->iCPartNumLog2, 1<<pMaxLUTSize->iCPartNumLog2 );
     1015
     1016  for(yIdx = 0; yIdx < nYSize; yIdx++)
     1017  {
     1018    for(uIdx = 0; uIdx < nCSize; uIdx++)
     1019    {
     1020      for(vIdx = 0; vIdx < nCSize; vIdx++)
     1021      {
     1022        const SColorInfo & rCuboidSrc   = m_pMaxColorInfo [yIdx][uIdx][vIdx];
     1023        const SColorInfo & rCuboidSrcC  = m_pMaxColorInfoC[yIdx][uIdx][vIdx];
     1024       
     1025        Int yIdx2, uIdx2, vIdx2;
     1026        yIdx2 = yIdx>>iYDiffLog2;
     1027        uIdx2 = uIdx>>iCDiffLog2;
     1028        vIdx2 = vIdx>>iCDiffLog2;
     1029
     1030        m_pColorInfo [yIdx2][uIdx2][vIdx2] += rCuboidSrc;
     1031        m_pColorInfoC[yIdx2][uIdx2][vIdx2] += rCuboidSrcC;
     1032      }
     1033    }
     1034  }
     1035}
     1036
     1037Void TEnc3DAsymLUT::update3DAsymLUTParam( TEnc3DAsymLUT * pSrc )
     1038{
     1039  assert( pSrc->getMaxOctantDepth() == getMaxOctantDepth() && pSrc->getMaxYPartNumLog2() == getMaxYPartNumLog2() );
     1040  xUpdatePartitioning( pSrc->getCurOctantDepth() , pSrc->getCurYPartNumLog2()
     1041#if R0151_CGS_3D_ASYMLUT_IMPROVE
     1042    , pSrc->getAdaptChromaThresholdU() , pSrc->getAdaptChromaThresholdV()
     1043#endif
     1044    );
     1045  setResQuantBit( pSrc->getResQuantBit() );
     1046}
     1047
     1048#endif
     1049#endif
  • branches/SHM-dev/source/Lib/TLibEncoder/TEnc3DAsymLUT.h

    r855 r877  
    88#include "../TLibCommon/TComPic.h"
    99#include "TEncCfg.h"
     10#if R0179_ENC_OPT_3DLUT_SIZE
     11#include "TEncCavlc.h"
     12#define MAX_NUM_LUT_SIZES               10   // 4+3+2+1
     13#define MAX_Y_SIZE                       4
     14#define MAX_C_SIZE                       4
     15#endif
    1016
    1117#if Q0048_CGS_3D_ASYMLUT
     
    5561}SColorInfo;
    5662
     63#if R0179_ENC_OPT_3DLUT_SIZE
     64typedef struct _LUTSize
     65{
     66  Int iYPartNumLog2;
     67  Int iCPartNumLog2;
     68} SLUTSize;
     69#endif
    5770
    5871class TEnc3DAsymLUT : public TCom3DAsymLUT
     
    6679  Double derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB );
    6780  Double estimateDistWithCur3DAsymLUT( TComPic * pCurPic , UInt refLayerIdc );
     81#if R0179_ENC_OPT_3DLUT_SIZE
     82  Double getDistFactor( Int iSliceType, Int iLayer) { return m_dDistFactor[iSliceType][iLayer];}
     83  Double derive3DAsymLUT( TComSlice * pSlice , TComPic * pCurPic , UInt refLayerIdc , TEncCfg * pCfg , Bool bSignalPPS , Bool bElRapSliceTypeB, Double dFrameLambda );
     84  Void   update3DAsymLUTParam( TEnc3DAsymLUT * pSrc );
     85#endif
    6886
    6987  Void  updatePicCGSBits( TComSlice * pcSlice , Int nPPSBit );
     
    7593  SColorInfo *** m_pColorInfo;
    7694  SColorInfo *** m_pColorInfoC;
     95#if R0179_ENC_OPT_3DLUT_SIZE
     96  SColorInfo *** m_pMaxColorInfo;
     97  SColorInfo *** m_pMaxColorInfoC;
     98#endif
    7799  TComPicYuv* m_pDsOrigPic;
    78100  SCuboid *** m_pEncCuboid;
     
    92114  Int   m_nPPSBit;
    93115  Int   m_nLUTBitDepth;
     116#if R0179_ENC_OPT_3DLUT_SIZE
     117
     118  Double m_dDistFactor[3][MAX_TLAYER];         
     119  Int    m_nNumLUTBits[MAX_Y_SIZE][MAX_C_SIZE];
     120  Int    m_nPrevELFrameBit[3][MAX_TLAYER];   
     121
     122
     123  Int   m_nTotalLutSizes;
     124  SLUTSize m_sLutSizes[MAX_NUM_LUT_SIZES];
     125#endif
    94126#if R0151_CGS_3D_ASYMLUT_IMPROVE
    95127  Double m_dSumU;
     
    97129  Int    m_nNChroma;
    98130#endif
     131#if R0179_ENC_OPT_3DLUT_SIZE
     132  TComOutputBitstream  *m_pBitstreamRedirect;
     133  TEncCavlc *m_pEncCavlc;
     134#endif
    99135
    100136private:
     
    111147  Int     xxCoeff2Vertex( Double a , Double b , Double c , Double d , Int y , Int u , Int v ) { return ( ( Int )( a * y + b * u + c * v + d + 0.5 ) ); }
    112148  Void    xxCollectData( TComPic * pCurPic , UInt refLayerIdc );
     149
    113150  Double  xxDeriveVertexes( Int nResQuantBit , SCuboid *** pCurCuboid );
    114151  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 ,
     
    120157    Pel nP0 , Pel nP1 , Pel nP3 , Pel nP7 );
    121158#endif
     159#if R0179_ENC_OPT_3DLUT_SIZE
     160  Void    xxConsolidateData( SLUTSize *pCurLUTSize, SLUTSize *pMaxLUTSize );
     161  Void    xxGetAllLutSizes(TComSlice *pSlice);
     162  Void    xxCopyColorInfo( SColorInfo *** dst, SColorInfo *** src ,  SColorInfo *** dstC, SColorInfo *** srcC );
     163  Void    xxAddColorInfo( Int yIdx, Int uIdx, Int vIdx, Int iYDiffLog2, Int iCDiffLog2 );
     164#endif
    122165};
    123166
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncCavlc.h

    r826 r877  
    170170#endif
    171171#if Q0048_CGS_3D_ASYMLUT
     172#if R0179_ENC_OPT_3DLUT_SIZE
     173public:
     174  Void xCode3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT );
     175protected:
     176  Void xCode3DAsymLUTOctant( TCom3DAsymLUT * pc3DAsymLUT , Int nDepth , Int yIdx , Int uIdx , Int vIdx , Int nLength );
     177#else
    172178protected:
    173179  Void xCode3DAsymLUT( TCom3DAsymLUT * pc3DAsymLUT );
    174180  Void xCode3DAsymLUTOctant( TCom3DAsymLUT * pc3DAsymLUT , Int nDepth , Int yIdx , Int uIdx , Int vIdx , Int nLength );
     181#endif
    175182#if R0151_CGS_3D_ASYMLUT_IMPROVE
    176183#if R0300_CGS_RES_COEFF_CODING
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncCfg.h

    r868 r877  
    369369#if R0151_CGS_3D_ASYMLUT_IMPROVE
    370370  Int  m_nCGSAdaptiveChroma;
     371#endif
     372#if R0179_ENC_OPT_3DLUT_SIZE
     373  Int  m_nCGSLutSizeRDO;
    371374#endif
    372375#endif
     
    10041007  Int       getCGSAdaptChroma()           { return m_nCGSAdaptiveChroma; }
    10051008#endif
     1009#if R0179_ENC_OPT_3DLUT_SIZE
     1010  Void      setCGSLutSizeRDO(Int n)      { m_nCGSLutSizeRDO = n;  }
     1011  Int       getCGSLutSizeRDO()           { return m_nCGSLutSizeRDO; }
     1012#endif
    10061013#endif
    10071014#endif
  • branches/SHM-dev/source/Lib/TLibEncoder/TEncGOP.cpp

    r874 r877  
    40324032  if( m_layerId && pcSlice->getPPS()->getCGSFlag() )
    40334033  {
     4034#if R0179_ENC_OPT_3DLUT_SIZE
     4035      m_Enc3DAsymLUTPicUpdate.update3DAsymLUTParam( &m_Enc3DAsymLUTPPS );
     4036#else
    40344037    if( m_Enc3DAsymLUTPPS.getPPSBit() > 0 )
    40354038      m_Enc3DAsymLUTPicUpdate.copy3DAsymLUT( &m_Enc3DAsymLUTPPS );
     4039#endif
    40364040    m_Enc3DAsymLUTPicUpdate.updatePicCGSBits( pcSlice , m_Enc3DAsymLUTPPS.getPPSBit() );
    40374041  }
     
    47564760  m_Enc3DAsymLUTPPS.setPPSBit( 0 );
    47574761  Double dErrorUpdatedPPS = 0 , dErrorPPS = 0;
    4758   dErrorUpdatedPPS = m_Enc3DAsymLUTPicUpdate.derive3DAsymLUT( pSlice , pCurPic , refLayerIdc , pCfg , bSignalPPS , m_pcEncTop->getElRapSliceTypeB() );
     4762
     4763#if R0179_ENC_OPT_3DLUT_SIZE
     4764  Int nTLthres = m_pcCfg->getCGSLutSizeRDO() ? 2:7;
     4765  Double dFrameLambda;
     4766#if FULL_NBIT
     4767  Int    SHIFT_QP = 12 + 6 * (pSlice->getBitDepthY() - 8);
     4768#else
     4769  Int    SHIFT_QP = 12;
     4770#endif
     4771  Int QP = pSlice->getSliceQp();
     4772
     4773  // set frame lambda
     4774  dFrameLambda = 0.68 * pow (2, (QP  - SHIFT_QP) / 3.0) * (m_pcCfg->getGOPSize() > 1 && pSlice->isInterB()? 2 : 1);
     4775
     4776  if(m_pcCfg->getCGSLutSizeRDO() == 1 && (!bSignalPPS && (pSlice->getDepth() < nTLthres)))
     4777    dErrorUpdatedPPS = m_Enc3DAsymLUTPicUpdate.derive3DAsymLUT( pSlice , pCurPic , refLayerIdc , pCfg , bSignalPPS , m_pcEncTop->getElRapSliceTypeB(), dFrameLambda );
     4778  else if (pSlice->getDepth() >= nTLthres)
     4779    dErrorUpdatedPPS = MAX_DOUBLE;
     4780  else // if (m_pcCfg->getCGSLutSizeRDO() = 0 || bSignalPPS)
     4781#endif   
     4782    dErrorUpdatedPPS = m_Enc3DAsymLUTPicUpdate.derive3DAsymLUT( pSlice , pCurPic , refLayerIdc , pCfg , bSignalPPS , m_pcEncTop->getElRapSliceTypeB() );
     4783
     4784
    47594785  if( bSignalPPS )
    47604786  {
     
    47644790  else if( nCGSFlag )
    47654791  {
    4766     dErrorPPS = m_Enc3DAsymLUTPPS.estimateDistWithCur3DAsymLUT( pCurPic , refLayerIdc );
    4767     Double dFactor = pCfg->getIntraPeriod() == 1 ? 0.99 : 0.9;
    4768     pSlice->setCGSOverWritePPS( dErrorUpdatedPPS < dFactor * dErrorPPS );
     4792#if R0179_ENC_OPT_3DLUT_SIZE
     4793    if(pSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_R || pSlice->getNalUnitType() == NAL_UNIT_CODED_SLICE_RASL_N)
     4794    {
     4795      pSlice->setCGSOverWritePPS( 0 );
     4796    }
     4797    else if (pSlice->getDepth() >= nTLthres)
     4798    {
     4799      pSlice->setCGSOverWritePPS( 0 );
     4800    }
     4801    else
     4802    {
     4803#endif   
     4804      dErrorPPS = m_Enc3DAsymLUTPPS.estimateDistWithCur3DAsymLUT( pCurPic , refLayerIdc );
     4805      Double dFactor = pCfg->getIntraPeriod() == 1 ? 0.99 : 0.9;
     4806
     4807#if R0179_ENC_OPT_3DLUT_SIZE
     4808      if( m_pcCfg->getCGSLutSizeRDO() )
     4809      {
     4810        dErrorPPS = dErrorPPS/m_Enc3DAsymLUTPicUpdate.getDistFactor(pSlice->getSliceType(), pSlice->getDepth());
     4811      }
     4812#endif
     4813      pSlice->setCGSOverWritePPS( dErrorUpdatedPPS < dFactor * dErrorPPS );
     4814#if R0179_ENC_OPT_3DLUT_SIZE
     4815    }
     4816#endif
    47694817    if( pSlice->getCGSOverWritePPS() )
    47704818    {
Note: See TracChangeset for help on using the changeset viewer.