Changeset 97 in 3DVCSoftware for branches/HTM-3.1-LG/source/Lib/TLibCommon


Ignore:
Timestamp:
6 Aug 2012, 05:35:11 (13 years ago)
Author:
lg
Message:

Implemented the Region boundary chain coding (A0070) and R/D selection between Non-Zero Residual and All-Zero Residual Intra Coding (A0087) with macro: "LGE_EDGE_INTRA" and "LG_ZEROINTRADEPTHRESI_M26039"

Location:
branches/HTM-3.1-LG/source/Lib/TLibCommon
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified branches/HTM-3.1-LG/source/Lib/TLibCommon/ContextTables.h

    r56 r97  
    152152#endif
    153153
     154#if LGE_EDGE_INTRA
     155#define NUM_EDGE_INTRA_CTX            1
     156#if LGE_EDGE_INTRA_DELTA_DC
     157#define NUM_EDGE_INTRA_DELTA_DC_CTX   2 // one for Delta_DC flag, another for Delta_DC value
     158#endif
     159#endif
     160
    154161// ====================================================================================================================
    155162// Tables
     
    12721279  }
    12731280};
     1281
     1282#if LGE_EDGE_INTRA
     1283static const Short
     1284INIT_EDGE_INTRA[3][NUM_EDGE_INTRA_CTX] =
     1285{
     1286        {
     1287                CNU
     1288        },
     1289        {
     1290                CNU
     1291                },
     1292                {
     1293                        CNU
     1294                }
     1295};
     1296
     1297#if LGE_EDGE_INTRA_DELTA_DC
     1298static const Short
     1299INIT_EDGE_INTRA_DELTA_DC[3][NUM_EDGE_INTRA_DELTA_DC_CTX] =
     1300{
     1301        {
     1302                CNU, CNU
     1303        },
     1304        {
     1305                CNU, CNU
     1306                },
     1307                {
     1308                        CNU, CNU
     1309                }
     1310};
     1311#endif
     1312#endif
     1313
    12741314#endif
    12751315
    12761316//! \}
    12771317
    1278 
    1279 #endif
    1280 
     1318#endif
     1319
  • TabularUnified branches/HTM-3.1-LG/source/Lib/TLibCommon/TComDataCU.cpp

    r92 r97  
    141141  m_pbResPredFlag      = NULL;
    142142#endif
     143#if LGE_EDGE_INTRA
     144  m_pucEdgeCode         = NULL;
     145  m_pucEdgeNumber       = NULL;
     146  m_pucEdgeStartPos     = NULL;
     147  m_pbEdgeLeftFirst     = NULL;
     148  m_pbEdgePartition     = NULL;
     149#if LGE_EDGE_INTRA_DELTA_DC
     150  m_piEdgeDeltaDC0      = NULL;
     151  m_piEdgeDeltaDC1      = NULL;
     152#endif
     153#endif
    143154}
    144155
     
    259270    m_piContourPredTexDeltaDC2 = (Int* )xMalloc(Int,  uiNumPartition);
    260271#endif
     272#if LGE_EDGE_INTRA
     273        m_pucEdgeCode       = (UChar*)xMalloc(UChar, uiNumPartition * LGE_EDGE_INTRA_MAX_EDGE_NUM_PER_4x4);
     274        m_pucEdgeNumber     = (UChar*)xMalloc(UChar, uiNumPartition);
     275        m_pucEdgeStartPos   = (UChar*)xMalloc(UChar, uiNumPartition);
     276        m_pbEdgeLeftFirst   = (Bool*) xMalloc(Bool,  uiNumPartition);
     277        m_pbEdgePartition   = (Bool*) xMalloc(Bool,  uiNumPartition * 16);
     278#if LGE_EDGE_INTRA_DELTA_DC
     279        m_piEdgeDeltaDC0    = (Int* ) xMalloc(Int,   uiNumPartition);
     280        m_piEdgeDeltaDC1    = (Int* ) xMalloc(Int,   uiNumPartition);
     281#endif
     282#endif
    261283  }
    262284  else
     
    359381    if ( m_piContourPredTexDeltaDC2 ) { xFree(m_piContourPredTexDeltaDC2); m_piContourPredTexDeltaDC2 = NULL; }
    360382#endif   
     383#if LGE_EDGE_INTRA
     384        if ( m_pbEdgeLeftFirst  ) { xFree(m_pbEdgeLeftFirst);   m_pbEdgeLeftFirst = NULL; }
     385        if ( m_pucEdgeStartPos  ) { xFree(m_pucEdgeStartPos);   m_pucEdgeStartPos = NULL; }
     386        if ( m_pucEdgeNumber    ) { xFree(m_pucEdgeNumber);     m_pucEdgeNumber   = NULL; }
     387        if ( m_pucEdgeCode      ) { xFree(m_pucEdgeCode);       m_pucEdgeCode     = NULL; }
     388        if ( m_pbEdgePartition    ) { xFree(m_pbEdgePartition); m_pbEdgePartition = NULL; }
     389#if LGE_EDGE_INTRA_DELTA_DC
     390        if ( m_piEdgeDeltaDC0     ) { xFree(m_piEdgeDeltaDC0);  m_piEdgeDeltaDC0  = NULL; }
     391        if ( m_piEdgeDeltaDC1     ) { xFree(m_piEdgeDeltaDC1);  m_piEdgeDeltaDC1  = NULL; }
     392#endif
     393#endif
    361394    m_acCUMvField[0].destroy();
    362395    m_acCUMvField[1].destroy();
     
    10931126  m_piContourPredTexDeltaDC2 = pcCU->getContourPredTexDeltaDC2() + uiPart;   
    10941127#endif
     1128#if LGE_EDGE_INTRA
     1129  if( pcCU->getSlice()->getSPS()->isDepth() )
     1130  {
     1131          m_pucEdgeCode         = pcCU->getEdgeCode( uiPart );
     1132          m_pucEdgeNumber       = pcCU->getEdgeNumber() + uiPart;
     1133          m_pucEdgeStartPos     = pcCU->getEdgeStartPos() + uiPart;
     1134          m_pbEdgeLeftFirst     = pcCU->getEdgeLeftFirst() + uiPart;
     1135          m_pbEdgePartition     = pcCU->getEdgePartition( uiPart );
     1136#if LGE_EDGE_INTRA_DELTA_DC
     1137          m_piEdgeDeltaDC0      = pcCU->getEdgeDeltaDC0() + uiPart;
     1138          m_piEdgeDeltaDC1      = pcCU->getEdgeDeltaDC1() + uiPart;
     1139#endif
     1140  }
     1141#endif
    10951142}
    10961143
     
    12501297  memcpy( m_piContourPredTexDeltaDC2 + uiOffset, pcCU->getContourPredTexDeltaDC2(), sizeof( Int  ) * uiNumPartition );
    12511298#endif
     1299
     1300#if LGE_EDGE_INTRA
     1301  if( getSlice()->getSPS()->isDepth() )
     1302  {
     1303          memcpy( getEdgeCode( uiOffset ), pcCU->getEdgeCode(0), iSizeInUchar * LGE_EDGE_INTRA_MAX_EDGE_NUM_PER_4x4 );
     1304          memcpy( getEdgeNumber() + uiOffset, pcCU->getEdgeNumber(), iSizeInUchar );
     1305          memcpy( getEdgeStartPos() + uiOffset, pcCU->getEdgeStartPos(), iSizeInUchar );
     1306          memcpy( getEdgeLeftFirst() + uiOffset, pcCU->getEdgeLeftFirst(), iSizeInBool );
     1307          memcpy( getEdgePartition( uiOffset ), pcCU->getEdgePartition(0), iSizeInBool * 16 );
     1308#if LGE_EDGE_INTRA_DELTA_DC
     1309          memcpy( getEdgeDeltaDC0() + uiOffset, pcCU->getEdgeDeltaDC0(), sizeof( Int  ) * uiNumPartition );
     1310          memcpy( getEdgeDeltaDC1() + uiOffset, pcCU->getEdgeDeltaDC1(), sizeof( Int  ) * uiNumPartition );
     1311#endif
     1312  }
     1313#endif
     1314
    12521315#if HHI_MPI
    12531316  memcpy( m_piTextureModeDepth + uiOffset, pcCU->getTextureModeDepth(), sizeof( Int ) * uiNumPartition );
     
    13521415  memcpy( rpcCU->getContourPredTexDeltaDC2() + m_uiAbsIdxInLCU, m_piContourPredTexDeltaDC2, sizeof( Int  ) * m_uiNumPartition );
    13531416#endif
     1417
     1418#if LGE_EDGE_INTRA
     1419  if( rpcCU->getSlice()->getSPS()->isDepth() )
     1420  {
     1421          memcpy( rpcCU->getEdgeCode( m_uiAbsIdxInLCU ),        m_pucEdgeCode,    iSizeInUchar * LGE_EDGE_INTRA_MAX_EDGE_NUM_PER_4x4 );
     1422          memcpy( rpcCU->getEdgeNumber()    + m_uiAbsIdxInLCU,  m_pucEdgeNumber,  iSizeInUchar );
     1423          memcpy( rpcCU->getEdgeStartPos()  + m_uiAbsIdxInLCU,  m_pucEdgeStartPos,iSizeInUchar );
     1424          memcpy( rpcCU->getEdgeLeftFirst() + m_uiAbsIdxInLCU,  m_pbEdgeLeftFirst,iSizeInBool );
     1425          memcpy( rpcCU->getEdgePartition( m_uiAbsIdxInLCU ),   m_pbEdgePartition,iSizeInBool * 16 );
     1426#if LGE_EDGE_INTRA_DELTA_DC
     1427          memcpy( rpcCU->getEdgeDeltaDC0() + m_uiAbsIdxInLCU,   m_piEdgeDeltaDC0, sizeof( Int  ) * m_uiNumPartition );
     1428          memcpy( rpcCU->getEdgeDeltaDC1() + m_uiAbsIdxInLCU,   m_piEdgeDeltaDC1, sizeof( Int  ) * m_uiNumPartition );
     1429#endif
     1430  }
     1431#endif
     1432
    13541433#if HHI_MPI
    13551434  memcpy( rpcCU->getTextureModeDepth() + m_uiAbsIdxInLCU, m_piTextureModeDepth, sizeof( Int ) * m_uiNumPartition );
     
    14551534  memcpy( rpcCU->getContourPredTexDeltaDC2() + uiPartOffset, m_piContourPredTexDeltaDC2, sizeof( Int  ) * uiQNumPart );
    14561535#endif
     1536
     1537#if LGE_EDGE_INTRA
     1538  if( rpcCU->getSlice()->getSPS()->isDepth() )
     1539  {
     1540          memcpy( rpcCU->getEdgeCode( uiPartOffset ),       m_pucEdgeCode,    iSizeInUchar * LGE_EDGE_INTRA_MAX_EDGE_NUM_PER_4x4 );
     1541          memcpy( rpcCU->getEdgeNumber()    + uiPartOffset, m_pucEdgeNumber,  iSizeInUchar );
     1542          memcpy( rpcCU->getEdgeStartPos()  + uiPartOffset, m_pucEdgeStartPos,iSizeInUchar );
     1543          memcpy( rpcCU->getEdgeLeftFirst() + uiPartOffset, m_pbEdgeLeftFirst,iSizeInBool );
     1544          memcpy( rpcCU->getEdgePartition( uiPartOffset ),  m_pbEdgePartition,iSizeInBool * 16 );
     1545#if LGE_EDGE_INTRA_DELTA_DC
     1546          memcpy( rpcCU->getEdgeDeltaDC0() + uiPartOffset,  m_piEdgeDeltaDC0, sizeof( Int  ) * uiQNumPart  );
     1547          memcpy( rpcCU->getEdgeDeltaDC1() + uiPartOffset,  m_piEdgeDeltaDC1, sizeof( Int  ) * uiQNumPart  );
     1548#endif
     1549  }
     1550#endif
     1551
    14571552#if HHI_MPI
    14581553  memcpy( rpcCU->getTextureModeDepth() + uiPartOffset, m_piTextureModeDepth, sizeof( Int ) * uiQNumPart  );
     
    23322427  mapDMMtoIntraMode( iLeftIntraDir );
    23332428#endif
     2429#if LGE_EDGE_INTRA
     2430  mapEdgeIntratoDC( iLeftIntraDir );
     2431#endif
    23342432 
    23352433  // Get intra direction of above PU
     
    23432441#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
    23442442  mapDMMtoIntraMode( iAboveIntraDir );
     2443#endif
     2444#if LGE_EDGE_INTRA
     2445  mapEdgeIntratoDC( iAboveIntraDir );
    23452446#endif
    23462447 
     
    24262527  return uiPredNum;
    24272528}
     2529
     2530#if LGE_EDGE_INTRA
     2531UInt TComDataCU::getCtxEdgeIntra( UInt uiAbsPartIdx )
     2532{
     2533        UInt        uiCtx = 0;
     2534        return uiCtx;
     2535}
     2536#endif
    24282537
    24292538UInt TComDataCU::getCtxSplitFlag( UInt uiAbsPartIdx, UInt uiDepth )
     
    33623471  cDisInfo.iN = 0;
    33633472  if(!bNoPdmMerge)
     3473  {
     3474#if USE_DVMCP
     3475    getDisMvpCand2(uiPUIdx, uiAbsPartIdx, &cDisInfo, true );
     3476#else
    33643477          getDisMvpCand (uiPUIdx, uiAbsPartIdx, &cDisInfo );
     3478#endif
     3479  }
    33653480  if(cDisInfo.iN==0)
    33663481  {
     
    34283543      pcCULeft->getMvField( pcCULeft, uiLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
    34293544    }
     3545#if USE_DVMCP
     3546    pcMvFieldNeighbours[iCount<<1    ].getMv().m_bDvMcp = false;
     3547    pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
     3548#endif
    34303549#if SIMP_MRG_PRUN
    34313550    if ( mrgCandIdx == iCount )
     
    35003619      pcCUAbove->getMvField( pcCUAbove, uiAbovePartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
    35013620    }
     3621#if USE_DVMCP
     3622    pcMvFieldNeighbours[iCount<<1    ].getMv().m_bDvMcp = false;
     3623    pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
     3624#endif
    35023625#if SIMP_MRG_PRUN
    35033626    if ( mrgCandIdx == iCount )
     
    35673690      pcCUAboveRight->getMvField( pcCUAboveRight, uiAboveRightPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
    35683691    }
     3692#if USE_DVMCP
     3693    pcMvFieldNeighbours[iCount<<1    ].getMv().m_bDvMcp = false;
     3694    pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
     3695#endif
    35693696#if SIMP_MRG_PRUN
    35703697    if ( mrgCandIdx == iCount )
     
    36313758      pcCULeftBottom->getMvField( pcCULeftBottom, uiLeftBottomPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
    36323759    }
     3760#if USE_DVMCP
     3761    pcMvFieldNeighbours[iCount<<1    ].getMv().m_bDvMcp = false;
     3762    pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
     3763#endif
    36333764#if SIMP_MRG_PRUN
    36343765    if ( mrgCandIdx == iCount )
     
    37043835        pcCUAboveLeft->getMvField( pcCUAboveLeft, uiAboveLeftPartIdx, REF_PIC_LIST_1, pcMvFieldNeighbours[(iCount<<1)+1] );
    37053836      }
     3837#if USE_DVMCP
     3838      pcMvFieldNeighbours[iCount<<1    ].getMv().m_bDvMcp = false;
     3839      pcMvFieldNeighbours[(iCount<<1)+1].getMv().m_bDvMcp = false;
     3840#endif
    37063841#if SIMP_MRG_PRUN
    37073842      if ( mrgCandIdx == iCount )
     
    38203955        puhInterDirNeighbours[uiArrayAddr] = 1;
    38213956      }
     3957#if USE_DVMCP
     3958      pcMvFieldNeighbours[uiArrayAddr<<1    ].getMv().m_bDvMcp = false;
     3959      pcMvFieldNeighbours[(uiArrayAddr<<1)+1].getMv().m_bDvMcp = false;
     3960#endif
    38223961#if SIMP_MRG_PRUN
    38233962      if ( mrgCandIdx == iCount )
     
    46144753        }//remaining pictures
    46154754}
     4755
     4756#if USE_DVMCP
     4757Void TComDataCU::getDisMvpCand2( UInt uiPartIdx, UInt uiPartAddr,DisInfo* pDInfo, Bool bMerge, RefPicList eRefPicList0, Int iRefIdx0 )
     4758{
     4759  PartSize eCUMode = getPartitionSize( uiPartAddr );
     4760  TComDataCU* pcTmpCU = NULL;
     4761  TComDataCU* pcCULeft = NULL;
     4762  pDInfo->iN = 0;
     4763
     4764  RefPicList eRefPicList = REF_PIC_LIST_0 ;
     4765  //-- Get Spatial MV
     4766  UInt uiPartIdxLT, uiPartIdxRT, uiPartIdxLB;
     4767  UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
     4768
     4769  Int   aiDvMcpDvCand[2][7] = {{0,},    {0,}}; // dummy, 5 spatial + 1 temporal, DV-MCP ÁÖº¯ ºí·°¿¡¼­ »ç¿ëµÈ DV¸¦ ÀúÀå
     4770  Bool  abDvMcpFlag  [2][7] = {{false,},{false,}};
     4771  //Int   aiRefPOC     [2][7] = {{-1,},{-1}}; // debug
     4772  TComMv cTmpMvPred, cMv;
     4773  Bool  bTmpIsSkipped = false;
     4774  Bool  bDvMcpIsFound = false;
     4775
     4776  deriveLeftRightTopIdxGeneral( eCUMode, uiPartAddr, uiPartIdx, uiPartIdxLT, uiPartIdxRT );
     4777  deriveLeftBottomIdxGeneral( eCUMode, uiPartAddr, uiPartIdx, uiPartIdxLB );
     4778
     4779  UInt uiIdx = 0;
     4780#if MVP_AT_ENTROPYSLICE_BOUNDARY
     4781  pcTmpCU = getPULeft(uiIdx, uiPartIdxLB, true, false);
     4782#else
     4783  pcTmpCU = getPULeft(uiIdx, uiPartIdxLB);
     4784#endif
     4785
     4786  pcCULeft = pcTmpCU;
     4787  UInt uiLeftPartIdx = uiIdx;
     4788  if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ) )
     4789  {
     4790    bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
     4791    for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
     4792    {
     4793      eRefPicList = RefPicList(iList);
     4794      Int refId = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ;
     4795      if( refId >= 0)
     4796      {
     4797        Int refViewIdx  = pcTmpCU->getSlice()->getRefViewId( eRefPicList, refId);
     4798        if (refViewIdx!= m_pcSlice->getViewId()) // DCP
     4799        {
     4800          TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
     4801          clipMv(cMvPred);
     4802          pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred;
     4803          pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
     4804          return;
     4805        }
     4806        else // MCP
     4807        {
     4808          cTmpMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
     4809          if( cTmpMvPred.m_bDvMcp && bTmpIsSkipped )
     4810          {
     4811            aiDvMcpDvCand[iList][DVFROM_LEFT] = cTmpMvPred.m_iDvMcpDispX;
     4812            abDvMcpFlag  [iList][DVFROM_LEFT] = true;
     4813            bDvMcpIsFound = true;
     4814          }
     4815#if USE_DVMCP_MSG
     4816          //printf("skipped %d =%d, curCUAddr=%d, leftCUAddr=%d\n",DVFROM_LEFT, iList, getAddr(), pcTmpCU->getAddr() );
     4817          aiRefPOC     [iList][DVFROM_LEFT] = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx);
     4818          if( aiRefPOC[iList][DVFROM_LEFT]<0 )
     4819          {
     4820            printf("error\n");
     4821          }
     4822          //aiRefPOC     [iList][DVFROM_LEFT] = pcTmpCU->getSlice()->getRefPOC( eRefPicList, );
     4823#endif
     4824        }
     4825      }
     4826    }
     4827  }
     4828
     4829#if MVP_AT_ENTROPYSLICE_BOUNDARY
     4830  pcTmpCU = getPUAbove(uiIdx, uiPartIdxRT, true, false, true);
     4831#else
     4832  pcTmpCU = getPUAbove(uiIdx, uiPartIdxRT);
     4833#endif
     4834
     4835  if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ))
     4836  {
     4837    bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
     4838    for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
     4839    {
     4840      eRefPicList = RefPicList(iList);
     4841      Int refId = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ;
     4842      if( refId >= 0)
     4843      {
     4844        Int refViewIdx  = pcTmpCU->getSlice()->getRefViewId( eRefPicList, refId);
     4845        if (refViewIdx!= m_pcSlice->getViewId())
     4846        {
     4847          TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
     4848          clipMv(cMvPred);
     4849          pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred;
     4850          pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
     4851          return;
     4852        }
     4853        else // MCP
     4854        {
     4855          cTmpMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
     4856          if( cTmpMvPred.m_bDvMcp  && bTmpIsSkipped )
     4857          {
     4858            aiDvMcpDvCand[iList][DVFROM_ABOVE] = cTmpMvPred.m_iDvMcpDispX;
     4859            abDvMcpFlag  [iList][DVFROM_ABOVE] = true;
     4860            bDvMcpIsFound = true;
     4861          }
     4862#if USE_DVMCP_MSG
     4863          //printf("skipped %d =%d, curCUAddr=%d, leftCUAddr=%d\n",DVFROM_ABOVE, iList, getAddr(), pcTmpCU->getAddr() );
     4864          aiRefPOC     [iList][DVFROM_ABOVE] = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx);
     4865          if( aiRefPOC[iList][DVFROM_ABOVE]<0 )
     4866          {
     4867            printf("error\n");
     4868          }
     4869#endif
     4870        }
     4871      }
     4872    }
     4873  }
     4874
     4875#if MVP_AT_ENTROPYSLICE_BOUNDARY
     4876  pcTmpCU = getPUAboveRight(uiIdx, uiPartIdxRT, true, false, true);
     4877#else
     4878  pcTmpCU = getPUAboveRight(uiIdx, uiPartIdxRT, true, true, true);
     4879#endif
     4880  if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ) )
     4881  {
     4882    bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
     4883    for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
     4884    {
     4885      eRefPicList = RefPicList(iList);
     4886      Int refId = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ;
     4887      if( refId >= 0)
     4888      {
     4889        Int refViewIdx  = pcTmpCU->getSlice()->getRefViewId( eRefPicList, refId);
     4890        if (refViewIdx!= m_pcSlice->getViewId())
     4891        {
     4892          TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
     4893          clipMv(cMvPred);
     4894          pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred;
     4895          pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
     4896          return;
     4897        }
     4898        else  // MCP
     4899        {
     4900          cTmpMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
     4901          if( cTmpMvPred.m_bDvMcp && bTmpIsSkipped )
     4902          {
     4903            aiDvMcpDvCand[iList][DVFROM_ABOVERIGHT] = cTmpMvPred.m_iDvMcpDispX;
     4904            abDvMcpFlag  [iList][DVFROM_ABOVERIGHT] = true;
     4905            bDvMcpIsFound = true;
     4906          }
     4907#if USE_DVMCP_MSG
     4908          //printf("skipped %d =%d, curCUAddr=%d, leftCUAddr=%d\n",DVFROM_ABOVERIGHT, iList, getAddr(), pcTmpCU->getAddr() );
     4909          aiRefPOC     [iList][DVFROM_ABOVERIGHT] = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx);
     4910#endif
     4911        }
     4912      }
     4913    }
     4914  }
     4915
     4916#if MVP_AT_ENTROPYSLICE_BOUNDARY
     4917  pcTmpCU = getPUBelowLeft(uiIdx, uiPartIdxLB, true, false);
     4918#else
     4919  pcTmpCU = getPUBelowLeft(uiIdx, uiPartIdxLB);
     4920#endif
     4921  if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ))
     4922  {
     4923    bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
     4924    for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
     4925    {
     4926      eRefPicList = RefPicList(iList);
     4927      Int refId = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ;
     4928      if( refId >= 0)
     4929      {
     4930        Int refViewIdx  = pcTmpCU->getSlice()->getRefViewId( eRefPicList, refId);
     4931        if (refViewIdx!= m_pcSlice->getViewId())
     4932        {
     4933          TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
     4934          clipMv(cMvPred);
     4935          pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred;
     4936          pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
     4937          return;
     4938        }
     4939        else // MCP
     4940        {
     4941          cTmpMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
     4942          if( cTmpMvPred.m_bDvMcp && bTmpIsSkipped )
     4943          {
     4944            aiDvMcpDvCand[iList][DVFROM_LEFTBELOW] = cTmpMvPred.m_iDvMcpDispX;
     4945            abDvMcpFlag  [iList][DVFROM_LEFTBELOW] = true;
     4946            bDvMcpIsFound = true;
     4947          }
     4948#if USE_DVMCP_MSG
     4949          //printf("skipped %d =%d, curCUAddr=%d, leftCUAddr=%d\n",DVFROM_LEFTBELOW, iList, getAddr(), pcTmpCU->getAddr() );
     4950          aiRefPOC     [iList][DVFROM_LEFTBELOW] = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx);
     4951#endif
     4952        }
     4953      }
     4954    }
     4955  }
     4956
     4957  // Above predictor search
     4958#if MVP_AT_ENTROPYSLICE_BOUNDARY
     4959  pcTmpCU = getPUAboveLeft(uiIdx, (m_uiAbsIdxInLCU + uiPartAddr), true, false, true);
     4960  assert(uiPartIdxLT == (m_uiAbsIdxInLCU + uiPartAddr));
     4961#else
     4962  pcTmpCU = getPUAboveLeft(uiIdx, uiPartIdxLT, true, true, true);
     4963#endif
     4964  if(pcTmpCU != NULL && !pcTmpCU->isIntra( uiIdx ))
     4965  {
     4966    bTmpIsSkipped = pcTmpCU->isSkipped( uiIdx );
     4967    for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
     4968    {
     4969      eRefPicList = RefPicList(iList);
     4970      Int refId = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx) ;
     4971      if( refId >= 0)
     4972      {
     4973        Int refViewIdx  = pcTmpCU->getSlice()->getRefViewId( eRefPicList, refId);
     4974        if (refViewIdx!= m_pcSlice->getViewId())
     4975        {
     4976          TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
     4977          clipMv(cMvPred);
     4978          pDInfo->m_acMvCand[ pDInfo->iN] = cMvPred;
     4979          pDInfo->m_aVIdxCan[ pDInfo->iN++] = refViewIdx;
     4980          return;
     4981        }
     4982        else // MCP
     4983        {
     4984          cTmpMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
     4985          if( cTmpMvPred.m_bDvMcp && bTmpIsSkipped )
     4986          {
     4987            aiDvMcpDvCand[iList][DVFROM_ABOVELEFT] = cTmpMvPred.m_iDvMcpDispX;
     4988            abDvMcpFlag  [iList][DVFROM_ABOVELEFT] = true;
     4989            bDvMcpIsFound = true;
     4990          }
     4991#if USE_DVMCP_MSG
     4992          aiRefPOC     [iList][DVFROM_ABOVELEFT] = pcTmpCU->getCUMvField(eRefPicList)->getRefIdx(uiIdx);
     4993          //printf("skipped %d =%d, curCUAddr=%d, leftCUAddr=%d\n",DVFROM_ABOVELEFT, iList, getAddr(), pcTmpCU->getAddr() );
     4994#endif
     4995        }
     4996      }
     4997    }
     4998  }
     4999
     5000  // copied from getInterMergeCand()
     5001  if ( getSlice()->getPPS()->getEnableTMVPFlag() )
     5002  {
     5003    UInt uiPUIdx = uiPartIdx;
     5004    UInt uiAbsPartAddr = uiPartAddr;
     5005
     5006    // col [2]
     5007    Int iRefIdxSkip[2] = {-1, -1};
     5008    if( !bMerge )
     5009    {
     5010      iRefIdxSkip[ eRefPicList0 ] = iRefIdx0;
     5011    }
     5012    else
     5013    {
     5014      for (Int i=0; i<2; i++)
     5015      {
     5016        RefPicList  eRefPicList1 = ( i==1 ? REF_PIC_LIST_1 : REF_PIC_LIST_0 );
     5017#if SET_MERGE_TMVP_REFIDX
     5018        Int iRefIdxTmp;
     5019        if ( uiPUIdx != 0 )
     5020        {
     5021          iRefIdxTmp = 0;
     5022        }
     5023        else
     5024        {   
     5025          iRefIdxTmp = (pcCULeft != NULL) ? pcCULeft->getCUMvField(eRefPicList1)->getRefIdx(uiLeftPartIdx) : -1;
     5026        }
     5027#else     
     5028        Int iRefIdxTmp = (pcCULeft != NULL) ? pcCULeft->getCUMvField(eRefPicList1)->getRefIdx(uiLeftPartIdx) : -1;
     5029#endif
     5030        iRefIdxSkip[i] = (iRefIdxTmp != -1) ? iRefIdxTmp : 0;
     5031      }
     5032    }
     5033
     5034    //>> MTK colocated-RightBottom
     5035    UInt uiPartIdxRB;
     5036    Int uiLCUIdx = getAddr();
     5037    eCUMode = getPartitionSize( 0 );
     5038
     5039    deriveRightBottomIdx( eCUMode, uiPUIdx, uiPartIdxRB ); 
     5040
     5041    UInt uiAbsPartIdxTmp = g_auiZscanToRaster[uiPartIdxRB];
     5042    //UInt uiNumPartInCUWidth = m_pcPic->getNumPartInWidth();
     5043
     5044    TComMv cColMv;
     5045    Int iRefIdx;
     5046
     5047    if      ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelX() + g_auiRasterToPelX[uiAbsPartIdxTmp] + m_pcPic->getMinCUWidth() ) >= m_pcSlice->getSPS()->getPicWidthInLumaSamples() )  // image boundary check
     5048    {
     5049      uiLCUIdx = -1;
     5050    }
     5051    else if ( ( m_pcPic->getCU(m_uiCUAddr)->getCUPelY() + g_auiRasterToPelY[uiAbsPartIdxTmp] + m_pcPic->getMinCUHeight() ) >= m_pcSlice->getSPS()->getPicHeightInLumaSamples() )
     5052    {
     5053      uiLCUIdx = -1;
     5054    }
     5055    else
     5056    {
     5057      if ( ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 ) &&           // is not at the last column of LCU
     5058        ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) ) // is not at the last row    of LCU
     5059      {
     5060        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + uiNumPartInCUWidth + 1 ];
     5061        uiLCUIdx = getAddr();
     5062      }
     5063      else if ( uiAbsPartIdxTmp % uiNumPartInCUWidth < uiNumPartInCUWidth - 1 )           // is not at the last column of LCU But is last row of LCU
     5064      {
     5065        uiAbsPartAddr = g_auiRasterToZscan[ (uiAbsPartIdxTmp + uiNumPartInCUWidth + 1) % m_pcPic->getNumPartInCU() ];
     5066        uiLCUIdx = -1 ;
     5067      }
     5068      else if ( uiAbsPartIdxTmp / uiNumPartInCUWidth < m_pcPic->getNumPartInHeight() - 1 ) // is not at the last row of LCU But is last column of LCU
     5069      {
     5070        uiAbsPartAddr = g_auiRasterToZscan[ uiAbsPartIdxTmp + 1 ];
     5071        uiLCUIdx = getAddr() + 1;
     5072      }
     5073      else //is the right bottom corner of LCU                       
     5074      {
     5075        uiAbsPartAddr = 0;
     5076        uiLCUIdx = -1 ;
     5077      }
     5078    }
     5079
     5080    Bool bExistMV = false;
     5081    UInt uiPartIdxCenter;
     5082    UInt uiCurLCUIdx = getAddr();
     5083    xDeriveCenterIdx( eCUMode, uiPUIdx, uiPartIdxCenter );
     5084
     5085    Int iTargetView, iStartView;
     5086    if( !bMerge ) // AMVP
     5087    {
     5088      bExistMV = uiLCUIdx >= 0 && xGetColDisMV( eRefPicList0, iRefIdx0, uiLCUIdx, uiAbsPartAddr, cColMv, iTargetView, iStartView );
     5089      if( bExistMV == false )
     5090      {
     5091        bExistMV = xGetColDisMV( eRefPicList0, iRefIdx0, uiCurLCUIdx, uiPartIdxCenter, cColMv, iTargetView, iStartView );
     5092      }
     5093      if( bExistMV ) // DV is found
     5094      {
     5095        if( cColMv.m_bDvMcp == false ) //=> DCP, if true => DV-MCP
     5096        {
     5097          clipMv(cColMv);
     5098          pDInfo->m_acMvCand[ pDInfo->iN] = cColMv;
     5099          pDInfo->m_aVIdxCan[ pDInfo->iN++] = iTargetView;
     5100          return;
     5101        }
     5102        else // DV-MCP
     5103        {
     5104          aiDvMcpDvCand[eRefPicList0][DVFROM_COL] = cColMv.getHor();
     5105          abDvMcpFlag  [eRefPicList0][DVFROM_COL] = true;
     5106          bDvMcpIsFound = true;
     5107        }
     5108      }
     5109    }
     5110    else // MERGE
     5111    {
     5112      iRefIdx = iRefIdxSkip[0];
     5113      bExistMV = uiLCUIdx >= 0 && xGetColDisMV( REF_PIC_LIST_0, iRefIdx, uiLCUIdx, uiAbsPartAddr, cColMv, iTargetView, iStartView );
     5114      if( bExistMV == false )
     5115      {
     5116        bExistMV = xGetColDisMV( REF_PIC_LIST_0, iRefIdx, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iTargetView, iStartView );
     5117      }
     5118      if( bExistMV )
     5119      {
     5120        if( cColMv.m_bDvMcp == false ) // DCP
     5121        {
     5122          clipMv(cColMv);
     5123          pDInfo->m_acMvCand[ pDInfo->iN] = cColMv;
     5124          pDInfo->m_aVIdxCan[ pDInfo->iN++] = iTargetView;
     5125          return;
     5126        }
     5127        else { // // DV-MCP
     5128          aiDvMcpDvCand[0][DVFROM_COL] = cColMv.getHor();
     5129          abDvMcpFlag  [0][DVFROM_COL] = true;
     5130          bDvMcpIsFound = true;
     5131        };
     5132
     5133        if ( getSlice()->isInterB() )
     5134        {       
     5135          iRefIdx = iRefIdxSkip[1];
     5136          bExistMV = uiLCUIdx >= 0 && xGetColDisMV( REF_PIC_LIST_1, iRefIdx, uiLCUIdx, uiAbsPartAddr, cColMv, iTargetView, iStartView );
     5137          if( bExistMV == false )
     5138          {
     5139            bExistMV = xGetColDisMV( REF_PIC_LIST_1, iRefIdx, uiCurLCUIdx, uiPartIdxCenter,  cColMv, iTargetView, iStartView );
     5140          }
     5141          if( bExistMV )
     5142          {
     5143            if( cColMv.m_bDvMcp == false ) // DCP
     5144            {
     5145              clipMv(cColMv);
     5146              pDInfo->m_acMvCand[ pDInfo->iN] = cColMv;
     5147              pDInfo->m_aVIdxCan[ pDInfo->iN++] = iTargetView;
     5148              return;
     5149            }
     5150            else // DV-MCP
     5151            {
     5152              aiDvMcpDvCand[1][DVFROM_COL] = cColMv.getHor();
     5153              abDvMcpFlag  [1][DVFROM_COL] = true;
     5154              bDvMcpIsFound = true;
     5155            };
     5156          }
     5157        }
     5158      }
     5159    }
     5160  } // if TMVP Flag
     5161
     5162  if( bDvMcpIsFound ) // skip dvmcp
     5163  {
     5164    for( Int i=1 ; i<7 ; i++ ) // 5 spatial + 1 temporal
     5165    {
     5166      for(Int iList = 0; iList < (getSlice()->isInterB() ? 2: 1); iList ++)
     5167      {
     5168        if( abDvMcpFlag[iList][i]==true )
     5169        {
     5170          TComMv dv( aiDvMcpDvCand[iList][ i ], 0 );
     5171          clipMv( dv );
     5172          pDInfo->m_acMvCand[ pDInfo->iN  ] = dv;
     5173          pDInfo->m_aVIdxCan[ pDInfo->iN++] = 0;
     5174          return;
     5175        }
     5176
     5177      }
     5178    }
     5179  }
     5180
     5181  return;
     5182
     5183}
     5184#endif
     5185
    46165186#endif
    46175187
     
    46405210  cDisInfo.iN = 0;
    46415211  if(m_pcSlice->getSPS()->getViewId() && m_pcSlice->getSPS()->getMultiviewMvPredMode())
    4642          getDisMvpCand (uiPartIdx, uiPartAddr, &cDisInfo );
     5212  {
     5213#if USE_DVMCP
     5214    getDisMvpCand2(uiPartIdx, uiPartAddr, &cDisInfo, false, eRefPicList, iRefIdx );
     5215#else
     5216          getDisMvpCand (uiPartIdx, uiPartAddr, &cDisInfo );
     5217#endif
     5218  }
    46435219  if(cDisInfo.iN==0)
    46445220  {
     
    50645640  {
    50655641    TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList)->getMv(uiIdx);
    5066    
     5642#if USE_DVMCP
     5643    cMvPred.m_bDvMcp = false;
     5644#endif
    50675645    pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
    50685646    return true;
     
    50995677    {
    51005678      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
     5679#if USE_DVMCP
     5680      cMvPred.m_bDvMcp = false;
     5681#endif
    51015682      pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
    51025683      return true;
     
    52395820    {
    52405821      TComMv cMvPred = pcTmpCU->getCUMvField(eRefPicList2nd)->getMv(uiIdx);
    5241 
     5822#if USE_DVMCP
     5823      cMvPred.m_bDvMcp = false;
     5824#endif
    52425825      clipMv(cMvPred);
    52435826      pInfo->m_acMvCand[ pInfo->iN++] = cMvPred;
     
    52675850      rcMv = cMvPred.scaleMv( iScale );
    52685851    }
     5852#if USE_DVMCP
     5853    rcMv.m_bDvMcp = false;
     5854#endif
    52695855    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
    52705856    return true;
     
    52915877      rcMv = cMvPred.scaleMv( iScale );
    52925878    }
     5879#if USE_DVMCP
     5880    rcMv.m_bDvMcp = false;
     5881#endif
    52935882    pInfo->m_acMvCand[ pInfo->iN++] = rcMv;
    52945883    return true;
     
    53015890Bool TComDataCU::xGetColDisMV( RefPicList eRefPicList, Int refidx, Int uiCUAddr, Int uiPartUnitIdx, TComMv& rcMv , Int & iTargetViewIdx, Int & iStartViewIdx )
    53025891{
     5892#if USE_DVMCP
     5893  Int  iDvMcpDispX[2] = {-1,};
     5894  Bool bDvMcpFlag [2] = { false, };
     5895  Int iCurrViewIdx = m_pcSlice->getViewId();
     5896#endif
    53035897
    53045898  UInt uiAbsPartAddr = uiPartUnitIdx;
     
    53105904  iColViewIdx = pColCU->getSlice()->getViewId();
    53115905
     5906
    53125907  if (pColCU->getPic()==0||pColCU->getPartitionSize(uiPartUnitIdx)==SIZE_NONE||pColCU->isIntra(uiAbsPartAddr))
    53135908  {
    53145909    return false;
    53155910  }
     5911#if USE_DVMCP
     5912  Bool bColIsSkipped = pColCU->isSkipped( uiAbsPartAddr );
     5913#endif
    53165914  for (Int ilist = 0; ilist < (pColCU->getSlice()->isInterB()? 2:1); ilist++)
    53175915  {
     
    53305928        iColRefViewIdx = pColCU->getSlice()->getRefPic(eColRefPicList, iColRefIdx)->getViewId();
    53315929    if ( iColViewIdx    == iColRefViewIdx ) // temporal vector
     5930    {
     5931#if USE_DVMCP
     5932      if( iColViewIdx >0 )
     5933      {
     5934        TComMv tmpMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
     5935        if( tmpMv.m_bDvMcp && bColIsSkipped ) // DV-MCP SKIP
     5936        {
     5937          iDvMcpDispX[ilist] = tmpMv.m_iDvMcpDispX;
     5938          bDvMcpFlag [ilist] = true;
     5939          iTargetViewIdx  = 0; //iColRefViewIdx ;
     5940          iStartViewIdx   = 0; //iCurrViewIdx; //iColViewIdx   ;
     5941        }
     5942      }
     5943#endif
    53325944      continue;
     5945    }
    53335946    else
    53345947    {
    53355948          rcMv = pColCU->getCUMvField(eColRefPicList)->getMv(uiAbsPartAddr);
     5949#if USE_DVMCP
     5950    rcMv.m_bDvMcp = false;
     5951#endif
    53365952      iTargetViewIdx  = iColRefViewIdx ;
    53375953      iStartViewIdx   = iColViewIdx   ;
     
    53395955    }
    53405956  }
     5957
     5958#if USE_DVMCP
     5959  for( Int ilist=0 ; ilist<2 ; ilist++ )
     5960  {
     5961    if( bDvMcpFlag[ilist] )
     5962    {
     5963      rcMv.setHor( iDvMcpDispX[ilist] );
     5964      rcMv.setVer( 0 );
     5965      rcMv.m_bDvMcp = true;
     5966      iTargetViewIdx  = 0; //iColRefViewIdx ;
     5967      iStartViewIdx   = iCurrViewIdx; //iColViewIdx   ;
     5968      return true;
     5969    }
     5970  }
     5971#endif
     5972
    53415973  return false;
    53425974}
     
    64467078   PartSize m_peSaved =  getPartitionSize( 0 );
    64477079   m_pePartSize[0] =  SIZE_2Nx2N;
     7080#if USE_DVMCP
     7081   getDisMvpCand2( 0, 0,  &cDisInfo, true );
     7082#else
    64487083   getDisMvpCand        ( 0, 0,  &cDisInfo );
     7084#endif
    64497085   if( cDisInfo.iN == 0)
    64507086   {
     
    64727108#endif
    64737109
     7110#if LGE_EDGE_INTRA
     7111Void TComDataCU::reconPartition( UInt uiAbsPartIdx, UInt uiDepth, Bool bLeft, UChar ucStartPos, UChar ucNumEdge, UChar* pucEdgeCode, Bool* pbRegion )
     7112{
     7113        Int iWidth;
     7114        Int iHeight;
     7115        if( uiDepth == 0 )
     7116        {
     7117                iWidth = 64;
     7118                iHeight = 64;
     7119        }
     7120        else if( uiDepth == 1 )
     7121        {
     7122                iWidth = 32;
     7123                iHeight = 32;
     7124        }
     7125        else if( uiDepth == 2 )
     7126        {
     7127                iWidth = 16;
     7128                iHeight = 16;
     7129        }
     7130        else if( uiDepth == 3 )
     7131        {
     7132                iWidth = 8;
     7133                iHeight = 8;
     7134        }
     7135        else // uiDepth == 4
     7136        {
     7137                iWidth = 4;
     7138                iHeight = 4;
     7139        }
     7140
     7141        Int iPtr = 0;
     7142        Int iX, iY;
     7143        Int iDir = -1;
     7144        Int iDiffX = 0, iDiffY = 0;
     7145
     7146        // 1. Edge Code -> Vert & Horz Edges
     7147        Bool*  pbEdge = (Bool*) xMalloc( Bool, 4 * iWidth * iHeight );
     7148
     7149        for( UInt ui = 0; ui < 4 * iWidth * iHeight; ui++ )
     7150                pbEdge  [ ui ] = false;
     7151
     7152        // Direction : left(0), right(1), top(2), bottom(3), left-top(4), right-top(5), left-bottom(6), right-bottom(7)
     7153        // Code      : 0deg(0), 45deg(1), -45deg(2), 90deg(3), -90deg(4), 135deg(5), -135deg(6)
     7154        const UChar tableDir[8][7] = { { 0, 6, 4, 3, 2, 7, 5 },
     7155        { 1, 5, 7, 2, 3, 4, 6 },
     7156        { 2, 4, 5, 0, 1, 6, 7 },
     7157        { 3, 7, 6, 1, 0, 5, 4 },
     7158        { 4, 0, 2, 6, 5, 3, 1 },
     7159        { 5, 2, 1, 4, 7, 0, 3 },
     7160        { 6, 3, 0, 7, 4, 1, 2 },
     7161        { 7, 1, 3, 5, 6, 2, 0 }};
     7162
     7163        UChar ucCode = pucEdgeCode[iPtr++];
     7164
     7165        if( !bLeft )
     7166        {
     7167                iX = ucStartPos;
     7168                iY = 0;
     7169
     7170                switch(ucCode)
     7171                {
     7172                case 0: // bottom
     7173                        iDir = 3;
     7174                        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
     7175                        break;
     7176                case 2: // left-bottom
     7177                        iDir = 6;
     7178                        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
     7179                        break;
     7180                case 1: // right-bottom
     7181                        iDir = 7;
     7182                        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
     7183                        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
     7184                        break;
     7185                case 4: // left
     7186                        iDir = 0;
     7187                        assert(false);
     7188                        break;
     7189                case 3: // right
     7190                        iDir = 1;
     7191                        if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
     7192                        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
     7193                        break;
     7194                }
     7195        }
     7196        else
     7197        {
     7198                iX = 0;
     7199                iY = ucStartPos;
     7200
     7201                switch(ucCode)
     7202                {
     7203                case 0: // right
     7204                        iDir = 1;
     7205                        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
     7206                        break;
     7207                case 1: // right-top
     7208                        iDir = 5;
     7209                        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
     7210                        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
     7211                        break;
     7212                case 2: // right-bottom
     7213                        iDir = 7;
     7214                        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
     7215                        break;
     7216                case 3: // top
     7217                        iDir = 2;
     7218                        if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
     7219                        if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
     7220                        break;
     7221                case 4: // bottom
     7222                        iDir = 3;
     7223                        assert(false);
     7224                        break;
     7225                }
     7226        }
     7227
     7228        switch( iDir )
     7229        {
     7230        case 0: // left
     7231                iDiffX = -1;
     7232                iDiffY = 0;
     7233                break;
     7234        case 1: // right
     7235                iDiffX = +1;
     7236                iDiffY = 0;
     7237                break;
     7238        case 2: // top
     7239                iDiffX = 0;
     7240                iDiffY = -1;
     7241                break;
     7242        case 3: // bottom
     7243                iDiffX = 0;
     7244                iDiffY = +1;
     7245                break;
     7246        case 4: // left-top
     7247                iDiffX = -1;
     7248                iDiffY = -1;
     7249                break;
     7250        case 5: // right-top
     7251                iDiffX = +1;
     7252                iDiffY = -1;
     7253                break;
     7254        case 6: // left-bottom
     7255                iDiffX = -1;
     7256                iDiffY = +1;
     7257                break;
     7258        case 7: // right-bottom
     7259                iDiffX = +1;
     7260                iDiffY = +1;
     7261                break;
     7262        }
     7263
     7264        iX += iDiffX;
     7265        iY += iDiffY;
     7266
     7267        while( iPtr < ucNumEdge )
     7268        {
     7269                ucCode = pucEdgeCode[iPtr++];
     7270
     7271                Int iNewDir = tableDir[iDir][ucCode];
     7272
     7273                switch( iNewDir )
     7274                {
     7275                case 0: // left
     7276                        iDiffX = -1;
     7277                        iDiffY = 0;
     7278                        break;
     7279                case 1: // right
     7280                        iDiffX = +1;
     7281                        iDiffY = 0;
     7282                        break;
     7283                case 2: // top
     7284                        iDiffX = 0;
     7285                        iDiffY = -1;
     7286                        break;
     7287                case 3: // bottom
     7288                        iDiffX = 0;
     7289                        iDiffY = +1;
     7290                        break;
     7291                case 4: // left-top
     7292                        iDiffX = -1;
     7293                        iDiffY = -1;
     7294                        break;
     7295                case 5: // right-top
     7296                        iDiffX = +1;
     7297                        iDiffY = -1;
     7298                        break;
     7299                case 6: // left-bottom
     7300                        iDiffX = -1;
     7301                        iDiffY = +1;
     7302                        break;
     7303                case 7: // right-bottom
     7304                        iDiffX = +1;
     7305                        iDiffY = +1;
     7306                        break;
     7307                }
     7308
     7309                switch( iDir )
     7310                {
     7311                case 0: // left
     7312                        switch( ucCode )
     7313                        {
     7314                        case 0:
     7315                        case 2:
     7316                                if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
     7317                                break;
     7318                        case 1:
     7319                        case 3:
     7320                                if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
     7321                                if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
     7322                                break;
     7323                        case 4:
     7324                        case 6:
     7325                                // no
     7326                                break;
     7327                        case 5:
     7328                                if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
     7329                                if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
     7330                                if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
     7331                                break;
     7332                        }
     7333                        break;
     7334                case 1: // right
     7335                        switch( ucCode )
     7336                        {
     7337                        case 0:
     7338                        case 2:
     7339                                if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
     7340                                break;
     7341                        case 1:
     7342                        case 3:
     7343                                if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
     7344                                if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
     7345                                break;
     7346                        case 4:
     7347                        case 6:
     7348                                // no
     7349                                break;
     7350                        case 5:
     7351                                if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
     7352                                if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
     7353                                if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
     7354                                break;
     7355                        }
     7356                        break;
     7357                case 2: // top
     7358                        switch( ucCode )
     7359                        {
     7360                        case 0:
     7361                        case 2:
     7362                                if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
     7363                                break;
     7364                        case 1:
     7365                        case 3:
     7366                                if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
     7367                                if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
     7368                                break;
     7369                        case 4:
     7370                        case 6:
     7371                                // no
     7372                                break;
     7373                        case 5:
     7374                                if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
     7375                                if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
     7376                                if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
     7377                                break;
     7378                        }
     7379                        break;
     7380                case 3: // bottom
     7381                        switch( ucCode )
     7382                        {
     7383                        case 0:
     7384                        case 2:
     7385                                if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
     7386                                break;
     7387                        case 1:
     7388                        case 3:
     7389                                if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
     7390                                if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
     7391                                break;
     7392                        case 4:
     7393                        case 6:
     7394                                // no
     7395                                break;
     7396                        case 5:
     7397                                if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
     7398                                if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
     7399                                if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
     7400                                break;
     7401                        }
     7402                        break;
     7403                case 4: // left-top
     7404                        switch( ucCode )
     7405                        {
     7406                        case 0:
     7407                        case 1:
     7408                                if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
     7409                                if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
     7410                                break;
     7411                        case 2:
     7412                        case 4:
     7413                                if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
     7414                                break;
     7415                        case 3:
     7416                        case 5:
     7417                                if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
     7418                                if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
     7419                                if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
     7420                                break;
     7421                        case 6:
     7422                                // no
     7423                                break;
     7424                        }
     7425                        break;
     7426                case 5: // right-top
     7427                        switch( ucCode )
     7428                        {
     7429                        case 0:
     7430                        case 1:
     7431                                if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
     7432                                if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
     7433                                break;
     7434                        case 2:
     7435                        case 4:
     7436                                if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
     7437                                break;
     7438                        case 3:
     7439                        case 5:
     7440                                if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
     7441                                if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
     7442                                if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
     7443                                break;
     7444                        case 6:
     7445                                // no
     7446                                break;
     7447                        }
     7448                        break;
     7449                case 6: // left-bottom
     7450                        switch( ucCode )
     7451                        {
     7452                        case 0:
     7453                        case 1:
     7454                                if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
     7455                                if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
     7456                                break;
     7457                        case 2:
     7458                        case 4:
     7459                                if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
     7460                                break;
     7461                        case 3:
     7462                        case 5:
     7463                                if(iY > 0) pbEdge[ 2 * iX + (2 * (iY - 1) + 1) * 2 * iWidth ] = true;
     7464                                if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
     7465                                if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
     7466                                break;
     7467                        case 6:
     7468                                // no
     7469                                break;
     7470                        }
     7471                        break;
     7472                case 7: // right-bottom
     7473                        switch( ucCode )
     7474                        {
     7475                        case 0:
     7476                        case 1:
     7477                                if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
     7478                                if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
     7479                                break;
     7480                        case 2:
     7481                        case 4:
     7482                                if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
     7483                                break;
     7484                        case 3:
     7485                        case 5:
     7486                                if(iX > 0) pbEdge[ 2 * (iX - 1) + 1 + iY * 4 * iWidth ] = true;
     7487                                if(iX < iWidth - 1) pbEdge[ 2 * (iX + 0) + 1 + iY * 4 * iWidth ] = true;
     7488                                if(iY < iHeight - 1) pbEdge[ 2 * iX + (2 * (iY + 0) + 1) * 2 * iWidth ] = true;
     7489                                break;
     7490                        case 6:
     7491                                // no
     7492                                break;
     7493                        }
     7494                        break;
     7495                }
     7496
     7497                assert( iX >= 0 && iX <= iWidth );
     7498                assert( iY >= 0 && iY <= iHeight );
     7499
     7500                iX += iDiffX;
     7501                iY += iDiffY;
     7502                iDir = iNewDir;
     7503        }
     7504
     7505        // finalize edge chain
     7506        if( iX == iWidth-1 )
     7507        {
     7508                if( iY == 0 )
     7509                {
     7510                        if( iDir == 1 )
     7511                        {
     7512                                pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
     7513                        }
     7514                        else if( iDir == 5 )
     7515                        {
     7516                                pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
     7517                        }
     7518                        else
     7519                        {
     7520                                assert(false);
     7521                        }
     7522                }
     7523                else if( iY == iHeight-1 )
     7524                {
     7525                        if( iDir == 3 )
     7526                        {
     7527                                pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
     7528                        }
     7529                        else if( iDir == 7 )
     7530                        {
     7531                                pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
     7532                        }
     7533                        else
     7534                        {
     7535                                assert(false);
     7536                        }
     7537                }
     7538                else
     7539                {
     7540                        if( iDir == 1 )
     7541                        {
     7542                                pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
     7543                        }
     7544                        else if( iDir == 3 )
     7545                        {
     7546                                pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
     7547                                pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
     7548                        }
     7549                        else if( iDir == 5 )
     7550                        {
     7551                                pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
     7552                        }
     7553                        else if( iDir == 7 )
     7554                        {
     7555                                pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
     7556                                pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
     7557                        }
     7558                        else
     7559                        {
     7560                                assert(false);
     7561                        }
     7562                }
     7563        }
     7564        else if( iX == 0 )
     7565        {
     7566                if( iY == 0 )
     7567                {
     7568                        if( iDir == 2 )
     7569                        {
     7570                                pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
     7571                        }
     7572                        else if( iDir == 4 )
     7573                        {
     7574                                pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
     7575                        }
     7576                        else
     7577                        {
     7578                                assert(false);
     7579                        }
     7580                }
     7581                else if( iY == iHeight-1 )
     7582                {
     7583                        if( iDir == 0 )
     7584                        {
     7585                                pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
     7586                        }
     7587                        else if( iDir == 6 )
     7588                        {
     7589                                pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
     7590                        }
     7591                        else
     7592                        {
     7593                                assert(false);
     7594                        }
     7595                }
     7596                else
     7597                {
     7598                        if( iDir == 0 )
     7599                        {
     7600                                pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
     7601                        }
     7602                        else if( iDir == 2 )
     7603                        {
     7604                                pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
     7605                                pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
     7606                        }
     7607                        else if( iDir == 4 )
     7608                        {
     7609                                pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
     7610                                pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
     7611                        }
     7612                        else if( iDir == 6 )
     7613                        {
     7614                                pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
     7615                        }
     7616                        else
     7617                        {
     7618                                assert(false);
     7619                        }
     7620                }
     7621        }
     7622        else if( iY == 0 )
     7623        {
     7624                if( iDir == 1 )
     7625                {
     7626                        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
     7627                        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
     7628                }
     7629                else if( iDir == 2 )
     7630                {
     7631                        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
     7632                }
     7633                else if( iDir == 4 )
     7634                {
     7635                        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
     7636                }
     7637                else if( iDir == 5 )
     7638                {
     7639                        pbEdge[ 2 * iX + (2 * iY + 1) * 2 * iWidth ] = true;
     7640                        pbEdge[ 2 * iX + 1 + 2 * iY * 2 * iWidth ] = true;
     7641                }
     7642                else
     7643                {
     7644                        assert(false);
     7645                }
     7646        }
     7647        else if( iY == iHeight-1 )
     7648        {
     7649                if( iDir == 0 )
     7650                {
     7651                        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
     7652                        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
     7653                }
     7654                else if( iDir == 3 )
     7655                {
     7656                        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
     7657                }
     7658                else if( iDir == 6 )
     7659                {
     7660                        pbEdge[ 2 * iX + (2 * iY - 1) * 2 * iWidth ] = true;
     7661                        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
     7662                }
     7663                else if( iDir == 7 )
     7664                {
     7665                        pbEdge[ 2 * iX - 1 + 2 * iY * 2 * iWidth ] = true;
     7666                }
     7667                else
     7668                {
     7669                        assert(false);
     7670                }
     7671        }
     7672        else
     7673        {
     7674                printf("xPredIntraEdge: wrong termination\n");
     7675                assert(false);
     7676        }
     7677
     7678        // Reconstruct Region from Chain Code
     7679        Bool* pbVisit  = (Bool*) xMalloc( Bool, iWidth * iHeight );
     7680        Int*  piStack  = (Int* ) xMalloc( Int,  iWidth * iHeight );
     7681
     7682        for( UInt ui = 0; ui < iWidth * iHeight; ui++ )
     7683        {
     7684                pbRegion[ ui ] = true; // fill it as region 1 (we'll discover region 0 next)
     7685                pbVisit [ ui ] = false;
     7686        }
     7687
     7688        iPtr = 0;
     7689        piStack[iPtr++] = (0 << 8) | (0);
     7690        pbRegion[ 0 ] = false;
     7691
     7692        while(iPtr > 0)
     7693        {
     7694                Int iTmp = piStack[--iPtr];
     7695                Int iX1, iY1;
     7696                iX1 = iTmp & 0xff;
     7697                iY1 = (iTmp >> 8) & 0xff;
     7698
     7699                pbVisit[ iX1 + iY1 * iWidth ] = true;
     7700
     7701                assert( iX1 >= 0 && iX1 < iWidth );
     7702                assert( iY1 >= 0 && iY1 < iHeight );
     7703
     7704                if( iX1 > 0 && !pbEdge[ 2 * iX1 - 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 - 1 + iY1 * iWidth ] )
     7705                {
     7706                        piStack[iPtr++] = (iY1 << 8) | (iX1 - 1);
     7707                        pbRegion[ iX1 - 1 + iY1 * iWidth ] = false;
     7708                }
     7709                if( iX1 < iWidth - 1 && !pbEdge[ 2 * iX1 + 1 + 4 * iY1 * iWidth ] && !pbVisit[ iX1 + 1 + iY1 * iWidth ] )
     7710                {
     7711                        piStack[iPtr++] = (iY1 << 8) | (iX1 + 1);
     7712                        pbRegion[ iX1 + 1 + iY1 * iWidth ] = false;
     7713                }
     7714                if( iY1 > 0 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 - 1) * iWidth ] && !pbVisit[ iX1 + (iY1 - 1) * iWidth ] )
     7715                {
     7716                        piStack[iPtr++] = ((iY1 - 1) << 8) | iX1;
     7717                        pbRegion[ iX1 + (iY1 - 1) * iWidth ] = false;
     7718                }
     7719                if( iY1 < iHeight - 1 && !pbEdge[ 2 * iX1 + 2 * (2 * iY1 + 1) * iWidth ] && !pbVisit[ iX1 + (iY1 + 1) * iWidth ] )
     7720                {
     7721                        piStack[iPtr++] = ((iY1 + 1) << 8) | iX1;
     7722                        pbRegion[ iX1 + (iY1 + 1) * iWidth ] = false;
     7723                }
     7724        }
     7725
     7726        xFree( pbEdge );
     7727        xFree( pbVisit );
     7728        xFree( piStack );
     7729}
     7730
     7731#endif
     7732
    64747733//! \}
  • TabularUnified branches/HTM-3.1-LG/source/Lib/TLibCommon/TComDataCU.h

    r91 r97  
    214214#endif
    215215
     216#if LGE_EDGE_INTRA
     217  UChar*        m_pucEdgeCode;          ///< array of edge code
     218  UChar*        m_pucEdgeNumber;        ///< total number of edge
     219  UChar*        m_pucEdgeStartPos;      ///< starting point position
     220  Bool*         m_pbEdgeLeftFirst;      ///< true if edge should be checked in left boundary first
     221  Bool*         m_pbEdgePartition;      ///< true if it belongs to region 1, otherwise, region 0
     222#if LGE_EDGE_INTRA_DELTA_DC
     223  Int*          m_piEdgeDeltaDC0;
     224  Int*          m_piEdgeDeltaDC1;
     225#endif
     226#endif
     227
    216228  // -------------------------------------------------------------------------------------------------------------------
    217229  // misc. variables
     
    513525  Int           getPdmMergeCandidateDisCan( UInt uiPartIdx, Int* paiPdmRefIdx, TComMv* pacPdmMv, DisInfo* pDInfo );
    514526  Void          getDisMvpCand        ( UInt uiPartIdx, UInt uiPartAddr, DisInfo* pDInfo );
     527#if USE_DVMCP
     528  Void          getDisMvpCand2( UInt uiPartIdx, UInt uiPartAddr, DisInfo* pDInfo, Bool bMerge=false, RefPicList eRefPicList=REF_PIC_LIST_X, Int iRefIdx=-1 );
     529#endif
     530
    515531#endif
    516532  Bool          getIViewOrgDepthMvPred( UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv );
     
    668684  UInt          getEntropySliceStartCU  ( UInt pos )                  { return m_uiEntropySliceStartCU[pos-m_uiAbsIdxInLCU];                                                                                   }
    669685  UInt&         getTotalBins            ()                            { return m_uiTotalBins;                                                                                                  }
     686
     687#if LGE_EDGE_INTRA
     688  UInt          getCtxEdgeIntra ( UInt uiAbsPartIdx );
     689#endif
     690
    670691  // -------------------------------------------------------------------------------------------------------------------
    671692  // member functions for RD cost storage
     
    743764  Void  setContourPredTexDeltaDC2SubParts ( Int iDC2, UInt uiAbsPartIdx, UInt uiDepth );
    744765#endif
     766
     767#if LGE_EDGE_INTRA
     768  UChar*        getEdgeCode( UInt uiIdx )                 { return &m_pucEdgeCode[uiIdx * LGE_EDGE_INTRA_MAX_EDGE_NUM_PER_4x4]; }
     769  UChar*        getEdgeNumber( )                          { return m_pucEdgeNumber;           }
     770  UChar         getEdgeNumber( UInt uiIdx )               { return m_pucEdgeNumber[uiIdx];    }
     771  Void          setEdgeNumber( UInt uiIdx, UChar val )    { m_pucEdgeNumber[uiIdx] = val;     }
     772  UChar*        getEdgeStartPos( )                        { return m_pucEdgeStartPos;         }
     773  UChar         getEdgeStartPos( UInt uiIdx )             { return m_pucEdgeStartPos[uiIdx];  }
     774  Void          setEdgeStartPos( UInt uiIdx, UChar val )  { m_pucEdgeStartPos[uiIdx] = val;   }
     775  Bool*         getEdgeLeftFirst( )                       { return m_pbEdgeLeftFirst;         }
     776  Bool          getEdgeLeftFirst( UInt uiIdx )            { return m_pbEdgeLeftFirst[uiIdx];  }
     777  Void          setEdgeLeftFirst( UInt uiIdx, Bool val )  { m_pbEdgeLeftFirst[uiIdx] = val;   }
     778  Bool*         getEdgePartition( UInt uiIdx )              { return &m_pbEdgePartition[uiIdx * 16]; }
     779  Void          reconPartition( UInt uiAbsPartIdx, UInt uiDepth, Bool bLeft, UChar ucStartPos, UChar ucNumEdge, UChar* pucEdgeCode, Bool* pbRegion );
     780
     781#if LGE_EDGE_INTRA_DELTA_DC
     782  Int*          getEdgeDeltaDC0( )                          { return m_piEdgeDeltaDC0; }
     783  Int*          getEdgeDeltaDC1( )                          { return m_piEdgeDeltaDC1; }
     784  Int           getEdgeDeltaDC0( UInt uiIdx )               { return m_piEdgeDeltaDC0[uiIdx]; }
     785  Int           getEdgeDeltaDC1( UInt uiIdx )               { return m_piEdgeDeltaDC1[uiIdx]; }
     786  Void          setEdgeDeltaDC0( UInt uiIdx, Int val )      { m_piEdgeDeltaDC0[uiIdx] = val;  }
     787  Void          setEdgeDeltaDC1( UInt uiIdx, Int val )      { m_piEdgeDeltaDC1[uiIdx] = val;  }
     788#endif
     789#endif
    745790};
    746791
  • TabularUnified branches/HTM-3.1-LG/source/Lib/TLibCommon/TComDepthMapGenerator.cpp

    r95 r97  
    831831TComDepthMapGenerator::getDisCanPdmMvPred    ( TComDataCU*   pcCU, UInt uiPartIdx, RefPicList eRefPicList, Int iRefIdx, TComMv& rcMv, DisInfo* pDInfo, Bool bMerge )
    832832{
     833#if USE_DVMCP
     834  rcMv.m_bDvMcp = false;
     835#endif
    833836  AOF  ( m_bCreated && m_bInit );
    834837  AOF  ( iRefIdx >= 0 );
     
    892895      {
    893896        rcMv.set( cBaseMvField.getHor(), cBaseMvField.getVer() );
     897#if USE_DVMCP
     898        // save disparity vector when a merge candidate for IVMP is set as DV-MCP
     899        if( bMerge )
     900        {
     901          rcMv.m_bDvMcp = true;
     902          rcMv.m_iDvMcpDispX = pDInfo->m_acMvCand[0].getHor();
     903        }
     904        else { // AMVP ?
     905          rcMv.m_bDvMcp = false;
     906        }
     907#endif
    894908        return true;
    895909      }
  • TabularUnified branches/HTM-3.1-LG/source/Lib/TLibCommon/TComMv.h

    r56 r97  
    5757public:
    5858 
     59#if USE_DVMCP
     60  Bool  m_bDvMcp;       // is dv-mcp ?
     61  Int   m_iDvMcpDispX;  // disparity for dv-mcp
     62#endif
     63
    5964  // ------------------------------------------------------------------------------------------------------------------
    6065  // constructors
     
    6469  m_iHor(0),
    6570  m_iVer(0)
     71#if USE_DVMCP
     72  , m_bDvMcp(false)
     73  , m_iDvMcpDispX(0)
     74#endif
    6675  {
    6776  }
     
    7079  m_iHor(iHor),
    7180  m_iVer(iVer)
     81#if USE_DVMCP
     82  , m_bDvMcp(false)
     83  , m_iDvMcpDispX(0)
     84#endif
    7285  {
    7386  }
  • TabularUnified branches/HTM-3.1-LG/source/Lib/TLibCommon/TComPattern.cpp

    r56 r97  
    675675{
    676676  Int* piSrc;
     677#if LGE_EDGE_INTRA
     678  mapEdgeIntratoDC( uiDirMode );
     679#endif
    677680  assert(log2BlkSize >= 2 && log2BlkSize < 7);
    678681#if HHI_DMM_WEDGE_INTRA || HHI_DMM_PRED_TEX
  • TabularUnified branches/HTM-3.1-LG/source/Lib/TLibCommon/TComPic.h

    r93 r97  
    7373#endif
    7474
     75#if LG_ZEROINTRADEPTHRESI_M26039
     76  Int                   m_uiIntraPeriod;
     77#endif
     78
    7579#if HHI_INTER_VIEW_MOTION_PRED
    7680  TComPicYuv*           m_pcOrgDepthMap;          //  original depth map
     
    129133#if VIDYO_VPS_INTEGRATION
    130134  TComVPS*      getVPS()              { return  m_apcPicSym->getSlice(m_uiCurrSliceIdx)->getVPS();  }
     135#endif
     136#if LG_ZEROINTRADEPTHRESI_M26039
     137  Int           getIntraPeriod()                           { return  m_uiIntraPeriod; }
     138  Void          setIntraPeriod(Int uiIntraPeriod)          { m_uiIntraPeriod = uiIntraPeriod; }
    131139#endif
    132140  TComSPS*      getSPS()              { return  m_apcPicSym->getSlice(m_uiCurrSliceIdx)->getSPS();  }
  • TabularUnified branches/HTM-3.1-LG/source/Lib/TLibCommon/TComPrediction.cpp

    r93 r97  
    419419}
    420420
     421#if LGE_EDGE_INTRA
     422Void TComPrediction::predIntraLumaEdge ( TComDataCU* pcCU, TComPattern* pcTComPattern, UInt uiAbsPartIdx, Int iWidth, Int iHeight, Pel* piPred, UInt uiStride, Bool bDelta )
     423{
     424        Pel *piDst = piPred;
     425        Int *piSrc;
     426        Int iSrcStride = ( iWidth<<1 ) + 1;
     427        Int iDstStride = uiStride;
     428
     429        piSrc = pcTComPattern->getPredictorPtr( 0, g_aucConvertToBit[ iWidth ] + 2, m_piYuvExt );
     430
     431        xPredIntraEdge ( pcCU, uiAbsPartIdx, iWidth, iHeight, piSrc, iSrcStride, piDst, iDstStride
     432#if LGE_EDGE_INTRA_DELTA_DC
     433                , bDelta
     434#endif
     435                );
     436}
     437
     438Pel  TComPrediction::xGetNearestNeighbor( Int x, Int y, Int* pSrc, Int srcStride, Int iWidth, Int iHeight, Bool* bpRegion )
     439{
     440        Bool bLeft = (x < y) ? true : false;
     441        Bool bFound = false;
     442        Int  iFoundX = -1, iFoundY = -1;
     443        Int  cResult = 0;
     444
     445#define MAX_DISTANCE_EDGEINTRA 255
     446
     447        UChar* piTopDistance = new UChar[iWidth];
     448        UChar* piLeftDistance = new UChar[iHeight];
     449
     450        for( Int i = 0; i < iWidth; i++ )
     451        {
     452                int Abs = x > i ? x - i : i - x;
     453                piTopDistance[ i ] = y + Abs;
     454
     455                Abs = y > i ? y - i : i - y;
     456                piLeftDistance[ i ] = x + Abs;
     457        }
     458
     459        for( Int dist = 0; dist < MAX_DISTANCE_EDGEINTRA && !bFound; dist++ )
     460        {
     461                if( !bLeft )
     462                {
     463                        for( Int i = 0; i < iWidth; i++ )
     464                        {
     465                                if( piTopDistance[ i ] == dist )
     466                                {
     467                                        if( bpRegion[ i ] == bpRegion[ x + y * iWidth ] )
     468                                        {
     469                                                iFoundX = i;
     470                                                iFoundY = 0;
     471                                                bFound = true;
     472                                        }
     473                                }
     474                        }
     475                        for( Int i = 0; i < iHeight; i++ )
     476                        {
     477                                if( piLeftDistance[ i ] == dist )
     478                                {
     479                                        if( bpRegion[ i * iWidth ] == bpRegion[ x + y * iWidth ] )
     480                                        {
     481                                                iFoundX = 0;
     482                                                iFoundY = i;
     483                                                bFound = true;
     484                                        }
     485                                }
     486                        }
     487                }
     488                else
     489                {
     490                        for( Int i = 0; i < iHeight; i++ )
     491                        {
     492                                if( piLeftDistance[ i ] == dist )
     493                                {
     494                                        if( bpRegion[ i * iWidth ] == bpRegion[ x + y * iWidth ] )
     495                                        {
     496                                                iFoundX = 0;
     497                                                iFoundY = i;
     498                                                bFound = true;
     499                                        }
     500                                }
     501                        }
     502                        for( Int i = 0; i < iWidth; i++ )
     503                        {
     504                                if( piTopDistance[ i ] == dist )
     505                                {
     506                                        if( bpRegion[ i ] == bpRegion[ x + y * iWidth ] )
     507                                        {
     508                                                iFoundX = i;
     509                                                iFoundY = 0;
     510                                                bFound = true;
     511                                        }
     512                                }
     513                        }
     514                }
     515        }
     516
     517        if( iFoundY == 0 )
     518        {
     519                cResult = pSrc[ iFoundX + 1 ];
     520        }
     521        else // iFoundX == 0
     522        {
     523                cResult = pSrc[ (iFoundY + 1) * srcStride ];
     524        }
     525
     526        delete[] piTopDistance;  piTopDistance = NULL;
     527        delete[] piLeftDistance; piLeftDistance = NULL;
     528
     529        assert( bFound );
     530
     531        return cResult;
     532}
     533
     534Void TComPrediction::xPredIntraEdge( TComDataCU* pcCU, UInt uiAbsPartIdx, Int iWidth, Int iHeight, Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, Bool bDelta )
     535{
     536        Pel* pDst = rpDst;
     537        Bool* pbRegion = pcCU->getEdgePartition( uiAbsPartIdx );
     538
     539        // Do prediction
     540        {
     541                UInt uiSum0 = 0, uiSum1 = 0;
     542                UInt uiMean0, uiMean1;
     543                UInt uiCount0 = 0, uiCount1 = 0;
     544                for( UInt ui = 0; ui < iWidth; ui++ )
     545                {
     546                        if( pbRegion[ ui ] == false )
     547                        {
     548                                uiSum0 += (pSrc[ ui + 1 ]);
     549                                uiCount0++;
     550                        }
     551                        else
     552                        {
     553                                uiSum1 += (pSrc[ ui + 1 ]);
     554                                uiCount1++;
     555                        }
     556                }
     557                for( UInt ui = 0; ui < iHeight; ui++ ) // (0,0) recount (to avoid division)
     558                {
     559                        if( pbRegion[ ui * iWidth ] == false )
     560                        {
     561                                uiSum0 += (pSrc[ (ui + 1) * srcStride ]);
     562                                uiCount0++;
     563                        }
     564                        else
     565                        {
     566                                uiSum1 += (pSrc[ (ui + 1) * srcStride ]);
     567                                uiCount1++;
     568                        }
     569                }
     570                if( uiCount0 == 0 )
     571                        assert(false);
     572                if( uiCount1 == 0 )
     573                        assert(false);
     574                uiMean0 = uiSum0 / uiCount0; // TODO : integer op.
     575                uiMean1 = uiSum1 / uiCount1;
     576#if LGE_EDGE_INTRA_DELTA_DC
     577                if( bDelta )
     578                {
     579                        Int iDeltaDC0 = pcCU->getEdgeDeltaDC0( uiAbsPartIdx );
     580                        Int iDeltaDC1 = pcCU->getEdgeDeltaDC1( uiAbsPartIdx );
     581                        xDeltaDCQuantScaleUp( pcCU, iDeltaDC0 );
     582                        xDeltaDCQuantScaleUp( pcCU, iDeltaDC1 );
     583                        uiMean0 = Clip( uiMean0 + iDeltaDC0 );
     584                        uiMean1 = Clip( uiMean1 + iDeltaDC1 );
     585                }
     586#endif
     587                for( UInt ui = 0; ui < iHeight; ui++ )
     588                {
     589                        for( UInt uii = 0; uii < iWidth; uii++ )
     590                        {
     591                                if( pbRegion[ uii + ui * iWidth ] == false )
     592                                        pDst[ uii + ui * dstStride ] = uiMean0;
     593                                else
     594                                        pDst[ uii + ui * dstStride ] = uiMean1;
     595                        }
     596                }
     597        }
     598}
     599#endif
     600
    421601#if DEPTH_MAP_GENERATION
    422602Void TComPrediction::motionCompensation( TComDataCU* pcCU, TComYuv* pcYuvPred, RefPicList eRefPicList, Int iPartIdx, Bool bPrdDepthMap, UInt uiSubSampExpX, UInt uiSubSampExpY )
  • TabularUnified branches/HTM-3.1-LG/source/Lib/TLibCommon/TComPrediction.h

    r56 r97  
    125125#endif
    126126
     127#if LGE_EDGE_INTRA
     128  Pel  xGetNearestNeighbor  ( Int x, Int y, Int* pSrc, Int srcStride, Int iWidth, Int iHeight, Bool* bpRegion );
     129  Void xPredIntraEdge       ( TComDataCU* pcCU, UInt uiAbsPartIdx, Int iWidth, Int iHeight, Int* pSrc, Int srcStride, Pel*& rpDst, Int dstStride, Bool bDelta = false );
     130#endif
     131
    127132public:
    128133  TComPrediction();
     
    170175  Bool  getWedgePatternIdx      ( WedgeRefList* pcWedgeRefList, UInt& ruiTabIdx, UChar uhXs, UChar uhYs, UChar uhXe, UChar uhYe );
    171176#endif
     177#if LGE_EDGE_INTRA
     178  Void predIntraLumaEdge          ( TComDataCU* pcCU, TComPattern* pcTComPattern, UInt uiAbsPartIdx, Int iWidth, Int iHeight, Pel* piPred, UInt uiStride, Bool bDelta = false );
     179#endif
    172180
    173181  // simplified intra pred for "virtual" depth maps
  • TabularUnified branches/HTM-3.1-LG/source/Lib/TLibCommon/TComRom.h

    r56 r97  
    206206#endif
    207207
     208#if LGE_EDGE_INTRA
     209__inline Void mapEdgeIntratoDC( UChar& curDir ) { curDir = (curDir >= EDGE_INTRA_IDX) ? DC_IDX : curDir; }
     210__inline Void mapEdgeIntratoDC(  UInt& curDir ) { curDir = (curDir >= EDGE_INTRA_IDX) ? DC_IDX : curDir; }
     211__inline Void mapEdgeIntratoDC(   Int& curDir ) { curDir = (curDir >= EDGE_INTRA_IDX) ? DC_IDX : curDir; }
     212#endif
     213
    208214// ==========================================
    209215// Mode-Dependent DST Matrices
  • TabularUnified branches/HTM-3.1-LG/source/Lib/TLibCommon/TypeDef.h

    r95 r97  
    4242//! \{
    4343
     44#define LGE_EDGE_INTRA                  1       //JCT2-A0070
     45#if LGE_EDGE_INTRA
     46#define LGE_EDGE_INTRA_MIN_SIZE         4
     47#define LGE_EDGE_INTRA_MAX_SIZE        32
     48#define LGE_EDGE_INTRA_THRESHOLD       20
     49#define LGE_EDGE_INTRA_MAX_EDGE_NUM_PER_4x4 8
     50#define LGE_EDGE_INTRA_DELTA_DC         1
     51#define LGE_EDGE_INTRA_PIXEL_DIFFERENCE 1
     52#endif
     53
     54#define LG_ZEROINTRADEPTHRESI_M26039      1  //JCT2-A0087
     55
    4456#define SONY_COLPIC_AVAILABILITY          1
    4557
     
    5466#define MTK_INTERVIEW_MERGE_A0049         1 //  JCT2-A0049 second part
    5567
     68#if QC_MULTI_DIS_CAN                    // JCT2-A0126
     69#define USE_DVMCP         0
     70
     71#define DVFROM_LEFTBELOW  1
     72#define DVFROM_LEFT       2
     73#define DVFROM_ABOVERIGHT 3
     74#define DVFROM_ABOVE      4
     75#define DVFROM_ABOVELEFT  5
     76#define DVFROM_COL        6
     77#endif
     78
    5679
    5780#define HHI_VSO                           1
     
    231254#define LOG2_SCAN_SET_SIZE                4
    232255
     256#if LGE_EDGE_INTRA
     257#if LGE_EDGE_INTRA_DELTA_DC
     258#define FAST_UDI_MAX_RDMODE_NUM               37          ///< maximum number of RD comparison in fast-UDI estimation loop
     259#else
     260#define FAST_UDI_MAX_RDMODE_NUM               36          ///< maximum number of RD comparison in fast-UDI estimation loop
     261#endif
     262#else
    233263#define FAST_UDI_MAX_RDMODE_NUM               35          ///< maximum number of RD comparison in fast-UDI estimation loop
     264#endif
    234265
    235266#define ZERO_MVD_EST                          0           ///< Zero Mvd Estimation in normal mode
     
    270301#define NUM_DMM_MODE 4
    271302#endif
     303
     304#if LGE_EDGE_INTRA
     305#if HHI_DMM_WEDGE_INTRA && HHI_DMM_PRED_TEX
     306#define EDGE_INTRA_IDX  (NUM_INTRA_MODE+NUM_DMM_MODE)
     307#endif // HHI_DMM_WEDGE_INTRA && HHI_DMM_PRED_TEX
     308#if LGE_EDGE_INTRA_DELTA_DC
     309#define EDGE_INTRA_DELTA_IDX          (EDGE_INTRA_IDX+1)
     310#endif
     311#endif // LGE_EDGE_INTRA
    272312
    273313#define IBDI_DISTORTION                0           ///< enable/disable SSE modification when IBDI is used (JCTVC-D152)
Note: See TracChangeset for help on using the changeset viewer.