Ignore:
Timestamp:
22 May 2015, 05:38:04 (9 years ago)
Author:
sharpjp-htm
Message:

Migration of illumination compensation(NH_3D_IC) and small fix(H_MV_ENC_DEC_TRAC_FIX)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HTM-14.1-update-dev2-Sharp/source/Lib/TLibCommon/TComPrediction.cpp

    r1200 r1225  
    201201    }
    202202  }
    203 #if H_3D_IC
     203#if NH_3D_IC
    204204  m_uiaShift[0] = 0;
    205205  for( Int i = 1; i < 64; i++ )
     
    13981398    {
    13991399#endif
    1400 #if H_3D_IC
    1401       Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() );
    1402       xPredInterLumaBlk  ( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
     1400  for (UInt comp=COMPONENT_Y; comp<pcYuvPred->getNumberValidComponents(); comp++)
     1401  {
     1402    const ComponentID compID=ComponentID(comp);
     1403#if NH_3D_IC
     1404    Bool bICFlag = pcCU->getICFlag( uiPartAddr ) && ( pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getViewIndex() != pcCU->getSlice()->getViewIndex() ) && ( isLuma(compID) || (iWidth > 8) );
     1405      xPredInterBlk(compID,  pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID))
    14031406#if H_3D_ARP
    14041407        , false
    14051408#endif
    14061409        , bICFlag );
    1407       bICFlag = bICFlag && (iWidth > 8);
    1408       xPredInterChromaBlk( pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, rpcYuvPred, bi
    1409 #if H_3D_ARP
    1410         , false
    1411 #endif
    1412         , bICFlag );
    14131410#else
    1414 
    1415   for (UInt comp=COMPONENT_Y; comp<pcYuvPred->getNumberValidComponents(); comp++)
    1416   {
    1417     const ComponentID compID=ComponentID(comp);
    14181411    xPredInterBlk  (compID,  pcCU, pcCU->getSlice()->getRefPic( eRefPicList, iRefIdx )->getPicYuvRec(), uiPartAddr, &cMv, iWidth, iHeight, pcYuvPred, bi, pcCU->getSlice()->getSPS()->getBitDepth(toChannelType(compID)) );
    1419   }
    1420 #endif
     1412#endif
     1413  }
    14211414#if H_3D_ARP
    14221415    }
     
    19021895    , Bool filterType
    19031896#endif
    1904 #if H_3D_IC
     1897#if NH_3D_IC
    19051898    , Bool bICFlag
    19061899#endif
     
    19251918  {
    19261919    refOffset = mv->getHor() + mv->getVer() * refStride;
    1927     ref       = refPic->getLumaAddr( cu->getAddr(), cu->getZorderIdxInCU() + partAddr ) + refOffset;
     1920    ref       = refPic->getAddr(compID, cu->getCtuRsAddr(), cu->getZorderIdxInCtu() + partAddr ) + refOffset;
     1921
    19281922    xFrac     = 0;
    19291923    yFrac     = 0;
     
    19381932  if ( yFrac == 0 )
    19391933  {
    1940 #if H_3D_IC
    1941     m_if.filterHorLuma( ref, refStride, dst, dstStride, width, height, xFrac,       !bi || bICFlag
     1934#if NH_3D_IC
     1935    m_if.filterHor(compID, ref, refStride, dst,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag, chFmt, bitDepth
    19421936#else
    19431937    m_if.filterHor(compID, ref, refStride, dst,  dstStride, cxWidth, cxHeight, xFrac, !bi, chFmt, bitDepth
     
    19501944  else if ( xFrac == 0 )
    19511945  {
    1952 #if H_3D_IC
    1953     m_if.filterVerLuma( ref, refStride, dst, dstStride, width, height, yFrac, true, !bi || bICFlag
     1946#if NH_3D_IC
     1947    m_if.filterVer(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag, chFmt, bitDepth
    19541948#else
    19551949    m_if.filterVer(compID, ref, refStride, dst, dstStride, cxWidth, cxHeight, yFrac, true, !bi, chFmt, bitDepth
     
    19721966#endif
    19731967);
    1974 #if H_3D_IC
    1975     m_if.filterVerLuma(tmp + (halfFilterSize-1)*tmpStride, tmpStride, dst, dstStride, width, height,              yFrac, false, !bi || bICFlag
     1968#if NH_3D_IC
     1969    m_if.filterVer(compID, tmp + ((vFilterSize>>1) -1)*tmpStride, tmpStride, dst, dstStride, cxWidth, cxHeight,               yFrac, false, !bi || bICFlag, chFmt, bitDepth
    19761970#else
    19771971    m_if.filterVer(compID, tmp + ((vFilterSize>>1) -1)*tmpStride, tmpStride, dst, dstStride, cxWidth, cxHeight,               yFrac, false, !bi, chFmt, bitDepth
     
    19831977  }
    19841978
    1985 #if H_3D_IC
     1979#if NH_3D_IC
    19861980  if( bICFlag )
    19871981  {
    19881982    Int a, b, i, j;
    19891983    const Int iShift = IC_CONST_SHIFT;
    1990 
    1991     xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_LUMA );
    1992 
    1993 
    1994     for ( i = 0; i < height; i++ )
    1995     {
    1996       for ( j = 0; j < width; j++ )
    1997       {
    1998           dst[j] = Clip3( 0, ( 1 << g_bitDepthY ) - 1, ( ( a*dst[j] ) >> iShift ) + b );
     1984    Pel *dst2 = dst;
     1985
     1986    xGetLLSICPrediction( compID, cu, mv, refPic, a, b, bitDepth );
     1987
     1988    for ( i = 0; i < cxHeight; i++ )
     1989    {
     1990      for ( j = 0; j < cxWidth; j++ )
     1991      {
     1992        dst[j] = Clip3( 0, ( 1 << bitDepth ) - 1, ( ( a*dst[j] ) >> iShift ) + b );
    19991993      }
    20001994      dst += dstStride;
     
    20031997    if(bi)
    20041998    {
    2005       Pel *dst2      = dstPic->getLumaAddr( partAddr );
    2006       Int shift = IF_INTERNAL_PREC - g_bitDepthY;
    2007       for (i = 0; i < height; i++)
    2008       {
    2009         for (j = 0; j < width; j++)
     1999      Int shift = IF_INTERNAL_PREC - bitDepth;
     2000      for (i = 0; i < cxHeight; i++)
     2001      {
     2002        for (j = 0; j < cxWidth; j++)
    20102003        {
    2011           Short val = dst2[j] << shift;
    2012           dst2[j] = val - (Short)IF_INTERNAL_OFFS;
     2004          Pel val = dst2[j] << shift;
     2005          dst2[j] = val - (Pel)IF_INTERNAL_OFFS;
    20132006        }
    20142007        dst2 += dstStride;
     
    20202013}
    20212014
    2022 
    2023 #if H_3D_ARP
    2024     , Bool filterType
    2025 #endif
    2026 #if H_3D_IC
    2027     , Bool bICFlag
    2028 #endif
    2029 #if H_3D_IC
    2030     m_if.filterHorChroma(refCb, refStride, dstCb,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
    2031 #else
    2032 #endif
    2033 #if H_3D_ARP
    2034     , filterType
    2035 #endif
    2036 #if H_3D_IC
    2037     m_if.filterHorChroma(refCr, refStride, dstCr,  dstStride, cxWidth, cxHeight, xFrac, !bi || bICFlag
    2038 #else
    2039 #endif
    2040 #if H_3D_ARP
    2041     , filterType
    2042 #endif
    2043 #if H_3D_IC
    2044     m_if.filterVerChroma(refCb, refStride, dstCb, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
    2045 #else
    2046 #endif
    2047 #if H_3D_ARP
    2048     , filterType
    2049 #endif
    2050 #if H_3D_IC
    2051     m_if.filterVerChroma(refCr, refStride, dstCr, dstStride, cxWidth, cxHeight, yFrac, true, !bi || bICFlag
    2052 #else
    2053 #endif
    2054 #if H_3D_ARP
    2055     , filterType
    2056 #endif
    2057 #if H_3D_ARP
    2058     , filterType
    2059 #endif 
    2060 #if H_3D_IC
    2061     m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCb, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
    2062 #else
    2063 #endif
    2064 #if H_3D_ARP
    2065     , filterType
    2066 #endif
    2067 #if H_3D_ARP
    2068     , filterType
    2069 #endif
    2070 #if H_3D_IC
    2071     m_if.filterVerChroma(extY  + (halfFilterSize-1)*extStride, extStride, dstCr, dstStride, cxWidth, cxHeight  , yFrac, false, !bi || bICFlag
    2072 #else
    2073 #endif
    2074 #if H_3D_ARP
    2075     , filterType
    2076 #endif
    2077 #if H_3D_IC
    2078   if( bICFlag )
    2079   {
    2080     Int a, b, i, j;
    2081     const Int iShift = IC_CONST_SHIFT;
    2082 
    2083     xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_U ); // Cb
    2084     for ( i = 0; i < cxHeight; i++ )
    2085     {
    2086       for ( j = 0; j < cxWidth; j++ )
    2087       {
    2088           dstCb[j] = Clip3(  0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCb[j] ) >> iShift ) + b );
    2089       }
    2090       dstCb += dstStride;
    2091     }
    2092     xGetLLSICPrediction( cu, mv, refPic, a, b, TEXT_CHROMA_V ); // Cr
    2093     for ( i = 0; i < cxHeight; i++ )
    2094     {
    2095       for ( j = 0; j < cxWidth; j++ )
    2096       {
    2097           dstCr[j] = Clip3( 0, ( 1 << g_bitDepthC ) - 1, ( ( a*dstCr[j] ) >> iShift ) + b );
    2098       }
    2099       dstCr += dstStride;
    2100     }
    2101 
    2102     if(bi)
    2103     {
    2104       Pel* dstCb2 = dstPic->getCbAddr( partAddr );
    2105       Pel* dstCr2 = dstPic->getCrAddr( partAddr );
    2106       Int shift = IF_INTERNAL_PREC - g_bitDepthC;
    2107       for (i = 0; i < cxHeight; i++)
    2108       {
    2109         for (j = 0; j < cxWidth; j++)
    2110         {
    2111           Short val = dstCb2[j] << shift;
    2112           dstCb2[j] = val - (Short)IF_INTERNAL_OFFS;
    2113 
    2114           val = dstCr2[j] << shift;
    2115           dstCr2[j] = val - (Short)IF_INTERNAL_OFFS;
    2116         }
    2117         dstCb2 += dstStride;
    2118         dstCr2 += dstStride;
    2119       }
    2120     }
    2121   }
    2122 #endif
    21232015Void TComPrediction::xWeightedAverage( TComYuv* pcYuvSrc0, TComYuv* pcYuvSrc1, Int iRefIdx0, Int iRefIdx1, UInt uiPartIdx, Int iWidth, Int iHeight, TComYuv* pcYuvDst, const BitDepths &clipBitDepths
    21242016 )
     
    22652157          (uiDirMode==HOR_IDX || uiDirMode==VER_IDX);
    22662158}
    2267 #if H_3D_IC
     2159#if NH_3D_IC
    22682160/** Function for deriving the position of first non-zero binary bit of a value
    22692161 * \param x input value
     
    22952187/** Function for deriving LM illumination compensation.
    22962188 */
    2297 Void TComPrediction::xGetLLSICPrediction( TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, TextType eType )
     2189Void TComPrediction::xGetLLSICPrediction( const ComponentID compID, TComDataCU* pcCU, TComMv *pMv, TComPicYuv *pRefPic, Int &a, Int &b, const Int bitDepth )
    22982190{
    22992191  TComPicYuv *pRecPic = pcCU->getPic()->getPicYuvRec();
    23002192  Pel *pRec = NULL, *pRef = NULL;
    23012193  UInt uiWidth, uiHeight, uiTmpPartIdx;
    2302   Int iRecStride = ( eType == TEXT_LUMA ) ? pRecPic->getStride() : pRecPic->getCStride();
    2303   Int iRefStride = ( eType == TEXT_LUMA ) ? pRefPic->getStride() : pRefPic->getCStride();
     2194  Int iRecStride = pRecPic->getStride(compID);
     2195  Int iRefStride = pRefPic->getStride(compID);
    23042196  Int iRefOffset, iHor, iVer;
    23052197  iHor = pcCU->getSlice()->getIsDepth() ? pMv->getHor() : ( ( pMv->getHor() + 2 ) >> 2 );
    23062198  iVer = pcCU->getSlice()->getIsDepth() ? pMv->getVer() : ( ( pMv->getVer() + 2 ) >> 2 );
    2307   if( eType != TEXT_LUMA )
     2199  if( !isLuma(compID) )
    23082200  {
    23092201    iHor = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getHor() + 1 ) >> 1 ) : ( ( pMv->getHor() + 4 ) >> 3 );
    23102202    iVer = pcCU->getSlice()->getIsDepth() ? ( ( pMv->getVer() + 1 ) >> 1 ) : ( ( pMv->getVer() + 4 ) >> 3 );
    23112203  }
    2312   uiWidth  = ( eType == TEXT_LUMA ) ? pcCU->getWidth( 0 )  : ( pcCU->getWidth( 0 )  >> 1 );
    2313   uiHeight = ( eType == TEXT_LUMA ) ? pcCU->getHeight( 0 ) : ( pcCU->getHeight( 0 ) >> 1 );
     2204  uiWidth  = pcCU->getWidth( 0 ) >> pRefPic->getComponentScaleX(compID);
     2205  uiHeight = pcCU->getHeight( 0 ) >> pRefPic->getComponentScaleY(compID);
    23142206
    23152207  Int i, j, iCountShift = 0;
    23162208
    2317   // LLS parameters estimation -->
    2318 
     2209  // LLS parameters estimation
    23192210  Int x = 0, y = 0, xx = 0, xy = 0;
    2320   Int precShift = std::max(0, (( eType == TEXT_LUMA ) ? g_bitDepthY : g_bitDepthC) - 12);
    2321 
    2322   if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) )
     2211  Int precShift = std::max(0, bitDepth - 12);
     2212
     2213  UInt partAddr = 0;
     2214  if( pcCU->getPUAbove( uiTmpPartIdx, pcCU->getZorderIdxInCtu() ) )
    23232215  {
    23242216    iRefOffset = iHor + iVer * iRefStride - iRefStride;
    2325     if( eType == TEXT_LUMA )
    2326     {
    2327       pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    2328       pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
    2329     }
    2330     else if( eType == TEXT_CHROMA_U )
    2331     {
    2332       pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    2333       pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
    2334     }
    2335     else
    2336     {
    2337       assert( eType == TEXT_CHROMA_V );
    2338       pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    2339       pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - iRecStride;
    2340     }
    2341 
     2217    pRef = pRefPic->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + partAddr ) + iRefOffset;
     2218    pRec = pRecPic->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + partAddr ) - iRecStride;
    23422219    for( j = 0; j < uiWidth; j+=2 )
    23432220    {
    23442221      x += pRef[j];
    23452222      y += pRec[j];
    2346       if ( eType == TEXT_LUMA )
     2223      if( isLuma(compID) )
    23472224      {
    23482225        xx += (pRef[j] * pRef[j])>>precShift;
     
    23532230  }
    23542231
    2355   if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCU() ) )
     2232  if( pcCU->getPULeft( uiTmpPartIdx, pcCU->getZorderIdxInCtu() ) )
    23562233  {
    23572234    iRefOffset = iHor + iVer * iRefStride - 1;
    2358     if( eType == TEXT_LUMA )
    2359     {
    2360       pRef = pRefPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    2361       pRec = pRecPic->getLumaAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
    2362     }
    2363     else if( eType == TEXT_CHROMA_U )
    2364     {
    2365       pRef = pRefPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    2366       pRec = pRecPic->getCbAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
    2367     }
    2368     else
    2369     {
    2370       assert( eType == TEXT_CHROMA_V );
    2371       pRef = pRefPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) + iRefOffset;
    2372       pRec = pRecPic->getCrAddr( pcCU->getAddr(), pcCU->getZorderIdxInCU() ) - 1;
    2373     }
    2374 
     2235    pRef = pRefPic->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + partAddr ) + iRefOffset;
     2236    pRec = pRecPic->getAddr(compID, pcCU->getCtuRsAddr(), pcCU->getZorderIdxInCtu() + partAddr ) - 1;
    23752237    for( i = 0; i < uiHeight; i+=2 )
    23762238    {
    23772239      x += pRef[0];
    23782240      y += pRec[0];
    2379       if ( eType == TEXT_LUMA )
     2241      if( isLuma(compID) )
    23802242      {
    23812243        xx += (pRef[0] * pRef[0])>>precShift;
     
    23952257  }
    23962258
    2397   if (  eType != TEXT_LUMA )
    2398   {
    2399     a = 32;
     2259  if( !isLuma(compID) )
     2260  {
     2261    a = ( 1 << IC_CONST_SHIFT );
    24002262    b = (  y - x + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
    24012263  }
    24022264  else
    24032265  {
    2404   xy += xx >> IC_REG_COST_SHIFT;
    2405   xx += xx >> IC_REG_COST_SHIFT;
    2406   Int a1 = ( xy << iCountShift ) - ((y * x) >> precShift);
    2407   Int a2 = ( xx << iCountShift ) - ((x * x) >> precShift);
    2408   const Int iShift = IC_CONST_SHIFT;
    2409   {
    2410     {
    2411       const Int iShiftA2 = 6;
    2412       const Int iAccuracyShift = 15;
    2413 
    2414       Int iScaleShiftA2 = 0;
    2415       Int iScaleShiftA1 = 0;
    2416       Int a1s = a1;
    2417       Int a2s = a2;
    2418 
    2419       a1 = Clip3(0, 2*a2, a1);
    2420       iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2;
    2421       iScaleShiftA1 = iScaleShiftA2 - IC_SHIFT_DIFF;
    2422 
    2423       if( iScaleShiftA1 < 0 )
    2424       {
    2425         iScaleShiftA1 = 0;
    2426       }
    2427 
    2428       if( iScaleShiftA2 < 0 )
    2429       {
    2430         iScaleShiftA2 = 0;
    2431       }
    2432 
    2433       Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1;
    2434 
    2435 
    2436       a2s = a2 >> iScaleShiftA2;
    2437 
    2438       a1s = a1 >> iScaleShiftA1;
    2439 
    2440       a = a1s * m_uiaShift[ a2s ];
    2441       a = a >> iScaleShiftA;
    2442       b = (  y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
    2443     }
    2444   }   
     2266    xy += xx >> IC_REG_COST_SHIFT;
     2267    xx += xx >> IC_REG_COST_SHIFT;
     2268    Int a1 = ( xy << iCountShift ) - ((y * x) >> precShift);
     2269    Int a2 = ( xx << iCountShift ) - ((x * x) >> precShift);
     2270    const Int iShift = IC_CONST_SHIFT;
     2271    const Int iShiftA2 = 6;
     2272    const Int iAccuracyShift = 15;
     2273    Int iScaleShiftA2 = 0;
     2274    Int iScaleShiftA1 = 0;
     2275    Int a1s;
     2276    Int a2s;
     2277   
     2278    a1 = Clip3(0, 2*a2, a1);
     2279    iScaleShiftA2 = GetMSB( abs( a2 ) ) - iShiftA2;
     2280    iScaleShiftA1 = iScaleShiftA2 - IC_SHIFT_DIFF;
     2281   
     2282    if( iScaleShiftA1 < 0 )
     2283    {
     2284      iScaleShiftA1 = 0;
     2285    }
     2286    if( iScaleShiftA2 < 0 )
     2287    {
     2288      iScaleShiftA2 = 0;
     2289    }
     2290   
     2291    Int iScaleShiftA = iScaleShiftA2 + iAccuracyShift - iShift - iScaleShiftA1;
     2292
     2293    a2s = a2 >> iScaleShiftA2;
     2294    a1s = a1 >> iScaleShiftA1;
     2295   
     2296    a = a1s * m_uiaShift[ a2s ];
     2297    a = a >> iScaleShiftA;
     2298    b = (  y - ( ( a * x ) >> iShift ) + ( 1 << ( iCountShift - 1 ) ) ) >> iCountShift;
    24452299  }
    24462300}
Note: See TracChangeset for help on using the changeset viewer.