Ignore:
Timestamp:
2 Jul 2013, 21:49:16 (11 years ago)
Author:
mitsubishi-htm
Message:

-VSP compensation part migration, not fully tested, intermediate version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HTM-DEV-0.3-dev2/source/Lib/TLibCommon/TComPrediction.cpp

    r504 r510  
    5151{
    5252  m_piYuvExt = NULL;
     53#if H_3D_VSP
     54  m_pDepthBlock = (Int*) malloc(MAX_NUM_SPU_W*MAX_NUM_SPU_W*sizeof(Int));
     55  if (m_pDepthBlock == NULL)
     56      printf("ERROR: UKTGHU, No memory allocated.\n");
     57#endif
    5358}
    5459
    5560TComPrediction::~TComPrediction()
    5661{
    57  
     62#if H_3D_VSP
     63  if (m_pDepthBlock != NULL)
     64      free(m_pDepthBlock);
     65#endif
     66
    5867  delete[] m_piYuvExt;
    5968
     
    428437  Int         iHeight;
    429438  UInt        uiPartAddr;
     439#if H_3D_VSP
     440  UInt        uiAbsPartIdx = pcCU->getZorderIdxInCU();
     441#endif
    430442
    431443  if ( iPartIdx >= 0 )
    432444  {
    433445    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
    434     if ( eRefPicList != REF_PIC_LIST_X )
    435     {
    436       if( pcCU->getSlice()->getPPS()->getUseWP())
    437       {
    438         xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
     446#if H_3D_VSP
     447    if ( 0 == pcCU->getVSPFlag(uiPartAddr) )
     448    {
     449#endif
     450      if ( eRefPicList != REF_PIC_LIST_X )
     451      {
     452        if( pcCU->getSlice()->getPPS()->getUseWP())
     453        {
     454          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
     455        }
     456        else
     457        {
     458          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
     459        }
     460        if ( pcCU->getSlice()->getPPS()->getUseWP() )
     461        {
     462          xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
     463        }
    439464      }
    440465      else
    441466      {
    442         xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
    443       }
    444       if ( pcCU->getSlice()->getPPS()->getUseWP() )
    445       {
    446         xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
    447       }
     467        if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
     468        {
     469          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
     470        }
     471        else
     472        {
     473          xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
     474        }
     475      }
     476#if H_3D_VSP
    448477    }
    449478    else
    450479    {
    451480      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
    452       {
    453         xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
    454       }
     481        xPredInterUniVSP( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
    455482      else
    456       {
    457         xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
    458       }
    459     }
     483        xPredInterBiVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, pcYuvPred );
     484    }
     485#endif
    460486    return;
    461487  }
     
    465491    pcCU->getPartIndexAndSize( iPartIdx, uiPartAddr, iWidth, iHeight );
    466492
    467     if ( eRefPicList != REF_PIC_LIST_X )
    468     {
    469       if( pcCU->getSlice()->getPPS()->getUseWP())
    470       {
    471         xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
     493#if H_3D_VSP
     494    if ( 0 == pcCU->getVSPFlag(uiPartAddr) )
     495    {
     496#endif
     497      if ( eRefPicList != REF_PIC_LIST_X )
     498      {
     499        if( pcCU->getSlice()->getPPS()->getUseWP())
     500        {
     501          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred, true );
     502        }
     503        else
     504        {
     505          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
     506        }
     507        if ( pcCU->getSlice()->getPPS()->getUseWP() )
     508        {
     509          xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
     510        }
    472511      }
    473512      else
    474513      {
    475         xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
    476       }
    477       if ( pcCU->getSlice()->getPPS()->getUseWP() )
    478       {
    479         xWeightedPredictionUni( pcCU, pcYuvPred, uiPartAddr, iWidth, iHeight, eRefPicList, pcYuvPred );
    480       }
     514        if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
     515        {
     516          xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
     517        }
     518        else
     519        {
     520          xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
     521        }
     522      }
     523#if H_3D_VSP
    481524    }
    482525    else
    483526    {
    484527      if ( xCheckIdenticalMotion( pcCU, uiPartAddr ) )
    485       {
    486         xPredInterUni (pcCU, uiPartAddr, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
    487       }
     528        xPredInterUniVSP( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, REF_PIC_LIST_0, pcYuvPred );
    488529      else
    489       {
    490         xPredInterBi  (pcCU, uiPartAddr, iWidth, iHeight, pcYuvPred );
    491       }
    492     }
     530        xPredInterBiVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, pcYuvPred );
     531    }
     532#endif
    493533  }
    494534  return;
     
    531571#endif
    532572}
     573
     574#if H_3D_VSP
     575Void TComPrediction::xPredInterUniVSP( TComDataCU* pcCU, UInt uiPartAddr, UInt uiAbsPartIdx, Int iWidth, Int iHeight, RefPicList eRefPicList, TComYuv*& rpcYuvPred, Bool bi )
     576{
     577  // Step 1: get depth reference
     578  Int depthRefViewIdx = pcCU->getDvInfo(uiPartAddr).m_aVIdxCan;
     579  TComPic* pRefPicBaseDepth = pcCU->getSlice()->getIvPic (true, depthRefViewIdx );
     580  assert(pRefPicBaseDepth != NULL);
     581  TComPicYuv* pcBaseViewDepthPicYuv = pRefPicBaseDepth->getPicYuvRec();
     582  assert(pcBaseViewDepthPicYuv != NULL);
     583
     584  // Step 2: get texture reference
     585  Int iRefIdx = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
     586  assert(iRefIdx >= 0);
     587  TComPic* pRefPicBaseTxt = pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx );
     588  TComPicYuv* pcBaseViewTxtPicYuv = pRefPicBaseTxt->getPicYuvRec();
     589  assert(pcBaseViewTxtPicYuv != NULL);
     590
     591  // Step 3: initialize the LUT according to the reference viewIdx
     592  Int txtRefViewIdx = pRefPicBaseTxt->getViewIndex();
     593  Int* pShiftLUT    = pcCU->getSlice()->getDepthToDisparityB( txtRefViewIdx );
     594
     595  // Step 4: Do compensation
     596  TComMv cMv  = pcCU->getCUMvField( eRefPicList )->getMv( uiPartAddr );
     597  pcCU->clipMv(cMv);
     598  Int iBlkX = ( pcCU->getAddr() % pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUWidth  + g_auiRasterToPelX[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
     599  Int iBlkY = ( pcCU->getAddr() / pRefPicBaseDepth->getFrameWidthInCU() ) * g_uiMaxCUHeight + g_auiRasterToPelY[ g_auiZscanToRaster[ uiAbsPartIdx ] ];
     600  xPredInterLumaBlkFromDM  ( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, &cMv, uiPartAddr, iBlkX,    iBlkY,    iWidth,    iHeight,    pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
     601  xPredInterChromaBlkFromDM( pcBaseViewTxtPicYuv, pcBaseViewDepthPicYuv, pShiftLUT, &cMv, uiPartAddr, iBlkX>>1, iBlkY>>1, iWidth>>1, iHeight>>1, pcCU->getSlice()->getIsDepth(), rpcYuvPred, bi );
     602}
     603#endif
    533604
    534605#if H_3D_ARP
     
    674745  }
    675746}
     747
     748#if H_3D_VSP
     749
     750Void TComPrediction::xPredInterBiVSP( TComDataCU* pcCU, UInt uiPartAddr, UInt uiAbsPartIdx, Int iWidth, Int iHeight, TComYuv*& rpcYuvPred )
     751{
     752  TComYuv* pcMbYuv;
     753  Int      iRefIdx[2] = {-1, -1};
     754
     755  for ( Int iRefList = 0; iRefList < 2; iRefList++ )
     756  {
     757    RefPicList eRefPicList = RefPicList(iRefList);
     758    iRefIdx[iRefList] = pcCU->getCUMvField( eRefPicList )->getRefIdx( uiPartAddr );
     759
     760    if ( iRefIdx[iRefList] < 0 )
     761      continue;
     762
     763    assert( iRefIdx[iRefList] < pcCU->getSlice()->getNumRefIdx(eRefPicList) );
     764
     765    pcMbYuv = &m_acYuvPred[iRefList];
     766    if( pcCU->getCUMvField( REF_PIC_LIST_0 )->getRefIdx( uiPartAddr ) >= 0 && pcCU->getCUMvField( REF_PIC_LIST_1 )->getRefIdx( uiPartAddr ) >= 0 )
     767      xPredInterUniVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, eRefPicList, pcMbYuv, true );
     768    else
     769      xPredInterUniVSP ( pcCU, uiPartAddr, uiAbsPartIdx, iWidth, iHeight, eRefPicList, pcMbYuv );
     770  }
     771
     772  xWeightedAverage( &m_acYuvPred[0], &m_acYuvPred[1], iRefIdx[0], iRefIdx[1], uiPartAddr, iWidth, iHeight, rpcYuvPred );
     773}
     774
     775#endif
    676776
    677777/**
     
    12831383}
    12841384#endif
     1385
     1386#if H_3D_VSP
     1387// Input:
     1388// refPic: Ref picture. Full picture, with padding
     1389// posX, posY:     PU position, texture
     1390// sizeX, sizeY: PU size
     1391// partAddr: z-order index
     1392// mv: disparity vector. derived from neighboring blocks
     1393//
     1394// Output: dstPic, PU predictor 64x64
     1395Void TComPrediction::xPredInterLumaBlkFromDM( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv* mv, UInt partAddr,Int posX, Int posY
     1396                                            , Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi )
     1397{
     1398  Int widthLuma;
     1399  Int heightLuma;
     1400
     1401  if (isDepth)
     1402  {
     1403    widthLuma   =  pPicBaseDepth->getWidth();
     1404    heightLuma  =  pPicBaseDepth->getHeight();
     1405  }
     1406  else
     1407  {
     1408    widthLuma   =  refPic->getWidth();
     1409    heightLuma  =  refPic->getHeight();
     1410  }
     1411
     1412#if H_3D_VSP_BLOCKSIZE != 1
     1413  Int widthDepth  = pPicBaseDepth->getWidth();
     1414  Int heightDepth = pPicBaseDepth->getHeight();
     1415#endif
     1416
     1417#if H_3D_VSP_CONSTRAINED
     1418  Int widthDepth  = pPicBaseDepth->getWidth();
     1419  Int heightDepth = pPicBaseDepth->getHeight();
     1420#endif
     1421
     1422  Int nTxtPerDepthX = widthLuma  / ( pPicBaseDepth->getWidth() );  // texture pixel # per depth pixel
     1423  Int nTxtPerDepthY = heightLuma / ( pPicBaseDepth->getHeight() );
     1424
     1425  Int refStride = refPic->getStride();
     1426  Int dstStride = dstPic->getStride();
     1427  Int depStride =  pPicBaseDepth->getStride();
     1428  Int depthPosX = Clip3(0,   widthLuma - sizeX,  (posX/nTxtPerDepthX) + ((mv->getHor()+2)>>2));
     1429  Int depthPosY = Clip3(0,   heightLuma- sizeY,  (posY/nTxtPerDepthY) + ((mv->getVer()+2)>>2));
     1430  Pel *ref    = refPic->getLumaAddr() + posX + posY * refStride;
     1431  Pel *dst    = dstPic->getLumaAddr(partAddr);
     1432  Pel *depth  = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride;
     1433
     1434#if H_3D_VSP_BLOCKSIZE != 1
     1435#if H_3D_VSP_BLOCKSIZE == 2
     1436  Int  dW = sizeX>>1;
     1437  Int  dH = sizeY>>1;
     1438#endif
     1439#if H_3D_VSP_BLOCKSIZE == 4
     1440  Int  dW = sizeX>>2;
     1441  Int  dH = sizeY>>2;
     1442#endif
     1443  {
     1444    Pel* depthi = depth;
     1445    for (Int j = 0; j < dH; j++)
     1446    {
     1447      for (Int i = 0; i < dW; i++)
     1448      {
     1449        Pel* depthTmp;
     1450#if H_3D_VSP_BLOCKSIZE == 2
     1451        if (depthPosX + (i<<1) < widthDepth)
     1452          depthTmp = depthi + (i << 1);
     1453        else
     1454          depthTmp = depthi + (widthDepth - depthPosX - 1);
     1455#endif
     1456#if H_3D_VSP_BLOCKSIZE == 4
     1457        if (depthPosX + (i<<2) < widthDepth)
     1458          depthTmp = depthi + (i << 2);
     1459        else
     1460          depthTmp = depthi + (widthDepth - depthPosX - 1);
     1461#endif
     1462        Int maxV = 0;
     1463        for (Int blockj = 0; blockj < H_3D_VSP_BLOCKSIZE; blockj+=(H_3D_VSP_BLOCKSIZE-1))
     1464        {
     1465          Int iX = 0;
     1466          for (Int blocki = 0; blocki < H_3D_VSP_BLOCKSIZE; blocki+=(H_3D_VSP_BLOCKSIZE-1))
     1467          {
     1468            if (maxV < depthTmp[iX])
     1469              maxV = depthTmp[iX];
     1470#if H_3D_VSP_BLOCKSIZE == 2
     1471            if (depthPosX + (i<<1) + blocki < widthDepth - 1)
     1472#else // H_3D_VSP_BLOCKSIZE == 4
     1473            if (depthPosX + (i<<2) + blocki < widthDepth - 1)
     1474#endif
     1475              iX = (H_3D_VSP_BLOCKSIZE-1);
     1476          }
     1477#if H_3D_VSP_BLOCKSIZE == 2
     1478          if (depthPosY + (j<<1) + blockj < heightDepth - 1)
     1479#else // H_3D_VSP_BLOCKSIZE == 4
     1480          if (depthPosY + (j<<2) + blockj < heightDepth - 1)
     1481#endif
     1482            depthTmp += depStride * (H_3D_VSP_BLOCKSIZE-1);
     1483        }
     1484        m_pDepthBlock[i+j*dW] = maxV;
     1485      } // end of i < dW
     1486#if H_3D_VSP_BLOCKSIZE == 2
     1487      if (depthPosY + ((j+1)<<1) < heightDepth)
     1488        depthi += (depStride << 1);
     1489      else
     1490        depthi  = depth + (heightDepth-depthPosY-1)*depStride;
     1491#endif
     1492#if H_3D_VSP_BLOCKSIZE == 4
     1493      if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1
     1494        depthi += (depStride << 2);
     1495      else
     1496        depthi  = depth + (heightDepth-depthPosY-1)*depStride; // the last line
     1497#endif
     1498    }
     1499  }
     1500#endif // H_3D_VSP_BLOCKSIZE != 1
     1501
     1502#if H_3D_VSP_BLOCKSIZE == 1
     1503#if H_3D_VSP_CONSTRAINED
     1504  //get LUT based horizontal reference range
     1505  Int range = xGetConstrainedSize(sizeX, sizeY);
     1506
     1507  // The minimum depth value
     1508  Int minRelativePos = MAX_INT;
     1509  Int maxRelativePos = MIN_INT;
     1510
     1511  Pel* depthTemp, *depthInitial=depth;
     1512  for (Int yTxt =0; yTxt<sizeY; yTxt++)
     1513  {
     1514    for (Int xTxt =0; xTxt<sizeX; xTxt++)
     1515    {
     1516      if (depthPosX+xTxt < widthDepth)
     1517        depthTemp = depthInitial + xTxt;
     1518      else
     1519        depthTemp = depthInitial + (widthDepth - depthPosX - 1);
     1520
     1521      Int disparity = pShiftLUT[ *depthTemp ]; // << iShiftPrec;
     1522      Int disparityInt = disparity >> 2;
     1523
     1524      if( disparity <= 0)
     1525      {
     1526        if (minRelativePos > disparityInt+xTxt)
     1527            minRelativePos = disparityInt+xTxt;
     1528      }
     1529      else
     1530      {
     1531        if (maxRelativePos < disparityInt+xTxt)
     1532            maxRelativePos = disparityInt+xTxt;
     1533      }
     1534    }
     1535    if (depthPosY+yTxt < heightDepth)
     1536      depthInitial = depthInitial + depStride;
     1537  }
     1538
     1539  Int disparity_tmp = pShiftLUT[ *depth ]; // << iShiftPrec;
     1540  if (disparity_tmp <= 0)
     1541    maxRelativePos = minRelativePos + range -1 ;
     1542  else
     1543    minRelativePos = maxRelativePos - range +1 ;
     1544#endif
     1545#endif // H_3D_VSP_BLOCKSIZE == 1
     1546
     1547#if H_3D_VSP_BLOCKSIZE != 1
     1548  Int yDepth = 0;
     1549#endif
     1550  for ( Int yTxt = 0; yTxt < sizeY; yTxt += nTxtPerDepthY )
     1551  {
     1552    for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth++ )
     1553    {
     1554      Pel repDepth = 0; // to store the depth value used for warping
     1555#if H_3D_VSP_BLOCKSIZE == 1
     1556      repDepth = depth[xDepth];
     1557#endif
     1558#if H_3D_VSP_BLOCKSIZE == 2
     1559      repDepth = m_pDepthBlock[(xTxt>>1) + (yTxt>>1)*dW];
     1560#endif
     1561#if H_3D_VSP_BLOCKSIZE == 4
     1562      repDepth = m_pDepthBlock[(xTxt>>2) + (yTxt>>2)*dW];
     1563#endif
     1564
     1565      assert( repDepth >= 0 && repDepth <= 255 );
     1566      Int disparity = pShiftLUT[ repDepth ]; // remove << iShiftPrec ??
     1567      Int refOffset = xTxt + (disparity >> 2);
     1568      Int xFrac = disparity & 0x3;
     1569#if H_3D_VSP_CONSTRAINED
     1570      if(refOffset<minRelativePos || refOffset>maxRelativePos)
     1571        xFrac = 0;
     1572      refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
     1573#endif
     1574      Int absX  = posX + refOffset;
     1575
     1576      if (xFrac == 0)
     1577        absX = Clip3(0, widthLuma-1, absX);
     1578      else
     1579        absX = Clip3(4, widthLuma-5, absX);
     1580
     1581      refOffset = absX - posX;
     1582
     1583      assert( ref[refOffset] >= 0 && ref[refOffset]<= 255 );
     1584      m_if.filterHorLuma( &ref[refOffset], refStride, &dst[xTxt], dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi );
     1585
     1586    }
     1587    ref   += refStride*nTxtPerDepthY;
     1588    dst   += dstStride*nTxtPerDepthY;
     1589    depth += depStride;
     1590#if H_3D_VSP_BLOCKSIZE != 1
     1591    yDepth++;
     1592#endif
     1593
     1594  }
     1595}
     1596
     1597Void TComPrediction::xPredInterChromaBlkFromDM ( TComPicYuv *refPic, TComPicYuv *pPicBaseDepth, Int* pShiftLUT, TComMv*mv, UInt partAddr, Int posX, Int posY
     1598                                               , Int sizeX, Int sizeY, Bool isDepth, TComYuv *&dstPic, Bool bi)
     1599{
     1600  Int refStride = refPic->getCStride();
     1601  Int dstStride = dstPic->getCStride();
     1602  Int depStride = pPicBaseDepth->getStride();
     1603
     1604  Int widthChroma, heightChroma;
     1605  if( isDepth)
     1606  {
     1607     widthChroma   = pPicBaseDepth->getWidth()>>1;
     1608     heightChroma  = pPicBaseDepth->getHeight()>>1;
     1609  }
     1610  else
     1611  {
     1612     widthChroma   = refPic->getWidth()>>1;
     1613     heightChroma  = refPic->getHeight()>>1;
     1614  }
     1615
     1616  // Below is only for Texture chroma component
     1617
     1618  Int widthDepth  = pPicBaseDepth->getWidth();
     1619  Int heightDepth = pPicBaseDepth->getHeight();
     1620
     1621  Int nTxtPerDepthX, nTxtPerDepthY;  // Number of texture samples per one depth sample
     1622  Int nDepthPerTxtX, nDepthPerTxtY;  // Number of depth samples per one texture sample
     1623
     1624  Int depthPosX;  // Starting position in depth image
     1625  Int depthPosY;
     1626
     1627  if ( widthChroma > widthDepth )
     1628  {
     1629    nTxtPerDepthX = widthChroma / widthDepth;
     1630    nDepthPerTxtX = 1;
     1631    depthPosX = posX / nTxtPerDepthX + ((mv->getHor()+2)>>2);
     1632  }
     1633  else
     1634  {
     1635    nTxtPerDepthX = 1;
     1636    nDepthPerTxtX = widthDepth / widthChroma;
     1637    depthPosX = posX * nDepthPerTxtX + ((mv->getHor()+2)>>2);
     1638  }
     1639  depthPosX = Clip3(0, widthDepth - (sizeX<<1), depthPosX);
     1640  if ( heightChroma > heightDepth )
     1641  {
     1642    nTxtPerDepthY = heightChroma / heightDepth;
     1643    nDepthPerTxtY = 1;
     1644    depthPosY = posY / nTxtPerDepthY + ((mv->getVer()+2)>>2);
     1645  }
     1646  else
     1647  {
     1648    nTxtPerDepthY = 1;
     1649    nDepthPerTxtY = heightDepth / heightChroma;
     1650    depthPosY = posY * nDepthPerTxtY + ((mv->getVer()+2)>>2);
     1651  }
     1652  depthPosY = Clip3(0, heightDepth - (sizeY<<1), depthPosY);
     1653
     1654  Pel *refCb  = refPic->getCbAddr() + posX + posY * refStride;
     1655  Pel *refCr  = refPic->getCrAddr() + posX + posY * refStride;
     1656  Pel *dstCb  = dstPic->getCbAddr(partAddr);
     1657  Pel *dstCr  = dstPic->getCrAddr(partAddr);
     1658  Pel *depth  = pPicBaseDepth->getLumaAddr() + depthPosX + depthPosY * depStride;  // move the pointer to the current depth pixel position
     1659
     1660  Int refStrideBlock = refStride * nTxtPerDepthY;
     1661  Int dstStrideBlock = dstStride * nTxtPerDepthY;
     1662  Int depStrideBlock = depStride * nDepthPerTxtY;
     1663
     1664  if ( widthChroma > widthDepth ) // We assume
     1665  {
     1666    assert( heightChroma > heightDepth );
     1667    printf("This branch should never been reached.\n");
     1668    exit(0);
     1669  }
     1670  else
     1671  {
     1672#if H_3D_VSP_BLOCKSIZE == 1
     1673  Int  dW = sizeX;
     1674  Int  dH = sizeY;
     1675  Int  sW = 2; // search window size
     1676  Int  sH = 2;
     1677#endif
     1678#if H_3D_VSP_BLOCKSIZE == 2
     1679  Int  dW = sizeX;
     1680  Int  dH = sizeY;
     1681  Int  sW = 2; // search window size
     1682  Int  sH = 2;
     1683#endif
     1684#if H_3D_VSP_BLOCKSIZE == 4
     1685  Int  dW = sizeX>>1;
     1686  Int  dH = sizeY>>1;
     1687  Int  sW = 4; // search window size
     1688  Int  sH = 4;
     1689#endif
     1690
     1691  {
     1692    Pel* depthi = depth;
     1693    for (Int j = 0; j < dH; j++)
     1694    {
     1695      for (Int i = 0; i < dW; i++)
     1696      {
     1697        Pel* depthTmp;
     1698#if H_3D_VSP_BLOCKSIZE == 1
     1699        depthTmp = depthi + (i << 1);
     1700#endif
     1701#if H_3D_VSP_BLOCKSIZE == 2
     1702        if (depthPosX + (i<<1) < widthDepth)
     1703          depthTmp = depthi + (i << 1);
     1704        else
     1705          depthTmp = depthi + (widthDepth - depthPosX - 1);
     1706#endif
     1707#if H_3D_VSP_BLOCKSIZE == 4
     1708        if (depthPosX + (i<<2) < widthDepth)
     1709          depthTmp = depthi + (i << 2);
     1710        else
     1711          depthTmp = depthi + (widthDepth - depthPosX - 1);
     1712#endif
     1713        Int maxV = 0;
     1714        for (Int blockj = 0; blockj < sH; blockj+=(sH-1))
     1715        {
     1716          Int iX = 0;
     1717          for (Int blocki = 0; blocki < sW; blocki+=(sW-1))
     1718          {
     1719            if (maxV < depthTmp[iX])
     1720              maxV = depthTmp[iX];
     1721            if (depthPosX + i*sW + blocki < widthDepth - 1)
     1722                iX = (sW-1);
     1723          }
     1724          if (depthPosY + j*sH + blockj < heightDepth - 1)
     1725                depthTmp += depStride * (sH-1);
     1726        }
     1727        m_pDepthBlock[i+j*dW] = maxV;
     1728      } // end of i < dW
     1729#if H_3D_VSP_BLOCKSIZE == 1
     1730      if (depthPosY + ((j+1)<<1) < heightDepth)
     1731        depthi += (depStride << 1);
     1732      else
     1733        depthi  = depth + (heightDepth-1)*depStride;
     1734#endif
     1735#if H_3D_VSP_BLOCKSIZE == 2
     1736      if (depthPosY + ((j+1)<<1) < heightDepth)
     1737        depthi += (depStride << 1);
     1738      else
     1739        depthi  = depth + (heightDepth-depthPosY-1)*depStride;
     1740#endif
     1741#if H_3D_VSP_BLOCKSIZE == 4
     1742      if (depthPosY + ((j+1)<<2) < heightDepth) // heightDepth-1
     1743        depthi += (depStride << 2);
     1744      else
     1745        depthi  = depth + (heightDepth-depthPosY-1)*depStride; // the last line
     1746#endif
     1747    }
     1748  }
     1749
     1750
     1751#if H_3D_VSP_BLOCKSIZE == 1
     1752#if H_3D_VSP_CONSTRAINED
     1753  //get LUT based horizontal reference range
     1754  Int range = xGetConstrainedSize(sizeX, sizeY, false);
     1755
     1756  // The minimum depth value
     1757  Int minRelativePos = MAX_INT;
     1758  Int maxRelativePos = MIN_INT;
     1759
     1760  Int depthTmp;
     1761  for (Int yTxt=0; yTxt<sizeY; yTxt++)
     1762  {
     1763    for (Int xTxt=0; xTxt<sizeX; xTxt++)
     1764    {
     1765      depthTmp = m_pDepthBlock[xTxt+yTxt*dW];
     1766      Int disparity = pShiftLUT[ depthTmp ]; // << iShiftPrec;
     1767      Int disparityInt = disparity >> 3;//in chroma resolution
     1768
     1769      if (disparityInt < 0)
     1770      {
     1771        if (minRelativePos > disparityInt+xTxt)
     1772            minRelativePos = disparityInt+xTxt;
     1773      }
     1774      else
     1775      {
     1776        if (maxRelativePos < disparityInt+xTxt)
     1777            maxRelativePos = disparityInt+xTxt;
     1778      }
     1779    }
     1780  }
     1781
     1782  depthTmp = m_pDepthBlock[0];
     1783  Int disparity_tmp = pShiftLUT[ depthTmp ]; // << iShiftPrec;
     1784  if ( disparity_tmp < 0 )
     1785    maxRelativePos = minRelativePos + range - 1;
     1786  else
     1787    minRelativePos = maxRelativePos - range + 1;
     1788
     1789#endif // H_3D_VSP_CONSTRAINED
     1790#endif // H_3D_VSP_BLOCKSIZE == 1
     1791
     1792    // (sizeX, sizeY) is Chroma block size
     1793    for ( Int yTxt = 0, yDepth = 0; yTxt < sizeY; yTxt += nTxtPerDepthY, yDepth += nDepthPerTxtY )
     1794    {
     1795      for ( Int xTxt = 0, xDepth = 0; xTxt < sizeX; xTxt += nTxtPerDepthX, xDepth += nDepthPerTxtX )
     1796      {
     1797        Pel repDepth = 0; // to store the depth value used for warping
     1798#if H_3D_VSP_BLOCKSIZE == 1
     1799        repDepth = m_pDepthBlock[(xTxt) + (yTxt)*dW];
     1800#endif
     1801#if H_3D_VSP_BLOCKSIZE == 2
     1802        repDepth = m_pDepthBlock[(xTxt) + (yTxt)*dW];
     1803#endif
     1804#if H_3D_VSP_BLOCKSIZE == 4
     1805        repDepth = m_pDepthBlock[(xTxt>>1) + (yTxt>>1)*dW];
     1806#endif
     1807
     1808      // calculate the offset in the reference picture
     1809        Int disparity = pShiftLUT[ repDepth ]; // Remove << iShiftPrec;
     1810        Int refOffset = xTxt + (disparity >> 3); // in integer pixel in chroma image
     1811        Int xFrac = disparity & 0x7;
     1812#if H_3D_VSP_CONSTRAINED
     1813        if(refOffset < minRelativePos || refOffset > maxRelativePos)
     1814          xFrac = 0;
     1815        refOffset = Clip3(minRelativePos, maxRelativePos, refOffset);
     1816#endif
     1817        Int absX  = posX + refOffset;
     1818
     1819        if (xFrac == 0)
     1820          absX = Clip3(0, widthChroma-1, absX);
     1821        else
     1822          absX = Clip3(4, widthChroma-5, absX);
     1823
     1824        refOffset = absX - posX;
     1825
     1826        assert( refCb[refOffset] >= 0 && refCb[refOffset]<= 255 );
     1827        assert( refCr[refOffset] >= 0 && refCr[refOffset]<= 255 );
     1828        m_if.filterHorChroma(&refCb[refOffset], refStride, &dstCb[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi);
     1829        m_if.filterHorChroma(&refCr[refOffset], refStride, &dstCr[xTxt],  dstStride, nTxtPerDepthX, nTxtPerDepthY, xFrac, !bi);
     1830      }
     1831      refCb += refStrideBlock;
     1832      refCr += refStrideBlock;
     1833      dstCb += dstStrideBlock;
     1834      dstCr += dstStrideBlock;
     1835      depth += depStrideBlock;
     1836    }
     1837  }
     1838
     1839}
     1840
     1841#if H_3D_VSP_CONSTRAINED
     1842
     1843Int TComPrediction::xGetConstrainedSize(Int nPbW, Int nPbH, Bool bLuma)
     1844{
     1845  Int iSize = 0;
     1846  if (bLuma)
     1847  {
     1848    Int iArea = (nPbW+7) * (nPbH+7);
     1849    Int iAlpha = iArea / nPbH - nPbW - 7;
     1850    iSize = iAlpha + nPbW;
     1851  }
     1852  else // chroma
     1853  {
     1854    Int iArea = (nPbW+2) * (nPbH+2);
     1855    Int iAlpha = iArea / nPbH - nPbW - 4;
     1856    iSize = iAlpha + nPbW;
     1857  }
     1858  return iSize;
     1859}
     1860
     1861#endif
     1862
     1863
     1864#endif
     1865
     1866
    12851867//! \}
Note: See TracChangeset for help on using the changeset viewer.