Ticket #596: 14-bit-fixes-HM71rc1_560_595_596_20120628.patch

File 14-bit-fixes-HM71rc1_560_595_596_20120628.patch, 9.8 KB (added by pandrivon, 12 years ago)

Patch fixing tickets #560, #595, #596

  • source/Lib/TLibCommon/CommonDef.h

     
    112112
    113113#define MAX_UINT                    0xFFFFFFFFU ///< max. value of unsigned 32-bit integer
    114114#define MAX_INT                     2147483647  ///< max. value of signed 32-bit integer
     115#define MAX_INT64                                       0x7FFFFFFFFFFFFFFF  ///< max. value of signed 64-bit integer
    115116#define MAX_DOUBLE                  1.7e+308    ///< max. value of double-type value
    116117
    117118#define MIN_QP                      0
  • source/Lib/TLibCommon/TComInterpolationFilter.cpp

     
    124124  else
    125125  {
    126126    Int shift = IF_INTERNAL_PREC - ( g_uiBitDepth + g_uiBitIncrement );
    127     Short offset = IF_INTERNAL_OFFS + (1 << (shift - 1));
     127    Short offset = IF_INTERNAL_OFFS;
     128    offset += shift?(1 << (shift - 1)):0;
    128129    Short maxVal = g_uiIBDI_MAX;
    129130    Short minVal = 0;
    130131    for (row = 0; row < height; row++)
  • source/Lib/TLibCommon/TComTrQuant.cpp

     
    11731173#else
    11741174    UInt uiBitDepth = g_uiBitDepth + g_uiBitIncrement;
    11751175#endif
    1176     UInt iTransformShift = MAX_TR_DYNAMIC_RANGE - uiBitDepth - uiLog2TrSize;  // Represents scaling through forward transform
     1176    Int iTransformShift = MAX_TR_DYNAMIC_RANGE - uiBitDepth - uiLog2TrSize;  // Represents scaling through forward transform
    11771177
    11781178    Int iQBits = QUANT_SHIFT + m_cQP.m_iPer + iTransformShift;                // Right shift of non-RDOQ quantizer;  level = (coeff*uiQ + offset)>>q_bits
    11791179
     
    12521252#else
    12531253  UInt uiBitDepth = g_uiBitDepth + g_uiBitIncrement;
    12541254#endif
    1255   UInt iTransformShift = MAX_TR_DYNAMIC_RANGE - uiBitDepth - uiLog2TrSize;
     1255  Int iTransformShift = MAX_TR_DYNAMIC_RANGE - uiBitDepth - uiLog2TrSize;
    12561256
    12571257  iShift = QUANT_IQUANT_SHIFT - QUANT_SHIFT - iTransformShift;
    12581258
     
    16361636#else
    16371637  UInt uiBitDepth = g_uiBitDepth + g_uiBitIncrement;
    16381638#endif
    1639   UInt iTransformShift = MAX_TR_DYNAMIC_RANGE - uiBitDepth - uiLog2TrSize;
    1640   Int j,k;
    1641   for (j = 0; j < height; j++)
    1642   {   
    1643     for(k = 0; k < width; k ++)
    1644     {
    1645       psCoeff[j*height + k] = piBlkResi[j * uiStride + k] << iTransformShift;     
     1639  Int  shift = MAX_TR_DYNAMIC_RANGE - uiBitDepth - uiLog2TrSize;
     1640  UInt transformSkipShift;
     1641  Int  j,k;
     1642  if(shift >= 0)
     1643  {
     1644    transformSkipShift = shift;
     1645    for (j = 0; j < height; j++)
     1646    {   
     1647      for(k = 0; k < width; k ++)
     1648      {
     1649        psCoeff[j*height + k] = piBlkResi[j * uiStride + k] << transformSkipShift;     
     1650      }
    16461651    }
    16471652  }
     1653  else
     1654  {
     1655    //The case when uiBitDepth > 13
     1656    UInt iAdd;
     1657    transformSkipShift = -shift;
     1658    iAdd = (1 << (transformSkipShift -1));
     1659    for (j = 0; j < height; j++)
     1660    {   
     1661      for(k = 0; k < width; k ++)
     1662      {
     1663        psCoeff[j*height + k] = (piBlkResi[j * uiStride + k] + iAdd) >> transformSkipShift;     
     1664      }
     1665    }
     1666  }
    16481667}
    16491668
    16501669/** Wrapper function between HM interface and core NxN transform skipping
     
    16621681#else
    16631682  UInt uiBitDepth = g_uiBitDepth + g_uiBitIncrement;
    16641683#endif
    1665   UInt iTransformShift = MAX_TR_DYNAMIC_RANGE - uiBitDepth - uiLog2TrSize;
    1666   UInt iAdd = (1 << (iTransformShift -1));
    1667   Int j,k;
    1668   for ( j = 0; j < height; j++ )
    1669   {   
    1670     for(k = 0; k < width; k ++)
    1671     {
    1672       pResidual[j * uiStride + k] =  (plCoef[j*width+k] + iAdd) >> iTransformShift;
     1684  Int  shift = MAX_TR_DYNAMIC_RANGE - uiBitDepth - uiLog2TrSize;
     1685  UInt transformSkipShift;
     1686  Int  j,k;
     1687  if(shift > 0)
     1688  {
     1689    UInt iAdd;
     1690    transformSkipShift = shift;
     1691    iAdd = (1 << (transformSkipShift -1));
     1692    for ( j = 0; j < height; j++ )
     1693    {   
     1694      for(k = 0; k < width; k ++)
     1695      {
     1696        pResidual[j * uiStride + k] =  (plCoef[j*width+k] + iAdd) >> transformSkipShift;
     1697      }
    16731698    }
    16741699  }
     1700  else
     1701  {
     1702    //The case when uiBitDepth >= 13
     1703    transformSkipShift = - shift;
     1704    for ( j = 0; j < height; j++ )
     1705    {   
     1706      for(k = 0; k < width; k ++)
     1707      {
     1708        pResidual[j * uiStride + k] =  plCoef[j*width+k] << transformSkipShift;
     1709      }
     1710    }
     1711  }
    16751712}
    16761713#endif
    16771714
     
    21272164
    21282165  if( pcCU->getSlice()->getPPS()->getSignHideFlag() && uiAbsSum>=2)
    21292166  {
    2130     Int rdFactor = (Int)((Double)(g_invQuantScales[m_cQP.rem()]*g_invQuantScales[m_cQP.rem()]<<(2*m_cQP.m_iPer))/m_dLambda/16 + 0.5) ;
     2167    Int64 rdFactor = (Int64)((Double)((Int64)g_invQuantScales[m_cQP.rem()]*(Int64)g_invQuantScales[m_cQP.rem()]<<(2*(Int64)m_cQP.m_iPer))/m_dLambda/16 + 0.5) ;
    21312168#if !FIXED_SBH_THRESHOLD
    21322169    Int tsig = pcCU->getSlice()->getPPS()->getTSIG() ;
    21332170#endif
     
    21762213        if( signbit!=(absSum&0x1) )  // hide but need tune
    21772214        {
    21782215          // calculate the cost
    2179           Int minCostInc = MAX_INT,  minPos =-1, finalChange=0, curCost=MAX_INT, curChange=0;
     2216          Int64 minCostInc = MAX_INT64, curCost=MAX_INT64;
     2217          Int minPos =-1, finalChange=0, curChange=0;
    21802218
    21812219          for( n = (lastCG==1?lastNZPosInCG:SCAN_SET_SIZE-1) ; n >= 0; --n )
    21822220          {
    21832221            UInt uiBlkPos   = scan[ n + subPos ];
    21842222            if(piDstCoeff[ uiBlkPos ] != 0 )
    21852223            {
    2186               Int costUp   = rdFactor * ( - deltaU[uiBlkPos] ) + rateIncUp[uiBlkPos] ;
    2187               Int costDown = rdFactor * (  deltaU[uiBlkPos] ) + rateIncDown[uiBlkPos]
     2224              Int64 costUp   = rdFactor * ( (Int64)- deltaU[uiBlkPos] ) + rateIncUp[uiBlkPos] ;
     2225              Int64 costDown = rdFactor * ( (Int64) deltaU[uiBlkPos] ) + rateIncDown[uiBlkPos]
    21882226                -   ( abs(piDstCoeff[uiBlkPos])==1?((1<<15)+sigRateDelta[uiBlkPos]):0 );
    21892227
    21902228              if(lastCG==1 && lastNZPosInCG==n && abs(piDstCoeff[uiBlkPos])==1)
     
    22022240                curChange = -1 ;
    22032241                if(n==firstNZPosInCG && abs(piDstCoeff[uiBlkPos])==1)
    22042242                {
    2205                   curCost = MAX_INT ;
     2243                  curCost = MAX_INT64 ;
    22062244                }
    22072245                else
    22082246                {
     
    22202258                UInt thissignbit = (plSrcCoeff[uiBlkPos]>=0?0:1);
    22212259                if(thissignbit != signbit )
    22222260                {
    2223                   curCost = MAX_INT;
     2261                  curCost = MAX_INT64;
    22242262                }
    22252263              }
    22262264            }
  • source/Lib/TLibCommon/TComWeightPrediction.cpp

     
    7979  Int offset  = wp0[0].offset;
    8080  Int shiftNum = IF_INTERNAL_PREC - ( g_uiBitDepth + g_uiBitIncrement );
    8181  Int shift   = wp0[0].shift + shiftNum;
    82   Int round   = (1<<(shift-1)) * bRound;
     82  Int round   = shift?(1<<(shift-1)) * bRound:0;
    8383  Int w1      = wp1[0].w;
    8484
    8585  UInt  iSrc0Stride = pcYuvSrc0->getStride();
     
    105105  w0      = wp0[1].w;
    106106  offset  = wp0[1].offset;
    107107  shift   = wp0[1].shift + shiftNum;
    108   round   = (1<<(shift-1));
     108  round   = shift?(1<<(shift-1)):0;
    109109  w1      = wp1[1].w;
    110110
    111111  iSrc0Stride = pcYuvSrc0->getCStride();
     
    132132  w0      = wp0[2].w;
    133133  offset  = wp0[2].offset;
    134134  shift   = wp0[2].shift + shiftNum;
    135   round   = (1<<(shift-1));
     135  round   = shift?(1<<(shift-1)):0;
    136136  w1      = wp1[2].w;
    137137
    138138  for ( y = iHeight-1; y >= 0; y-- )
     
    175175  Int offset  = wp0[0].offset;
    176176  Int shiftNum = IF_INTERNAL_PREC - ( g_uiBitDepth + g_uiBitIncrement );
    177177  Int shift   = wp0[0].shift + shiftNum;
    178   Int round   = (1<<(shift-1));
     178  Int round   = shift?(1<<(shift-1)):0;
    179179  UInt  iSrc0Stride = pcYuvSrc0->getStride();
    180180  UInt  iDstStride  = rpcYuvDst->getStride();
    181181 
     
    197197  w0      = wp0[1].w;
    198198  offset  = wp0[1].offset;
    199199  shift   = wp0[1].shift + shiftNum;
    200   round   = (1<<(shift-1));
     200  round   = shift?(1<<(shift-1)):0;
    201201
    202202  iSrc0Stride = pcYuvSrc0->getCStride();
    203203  iDstStride  = rpcYuvDst->getCStride();
     
    221221  w0      = wp0[2].w;
    222222  offset  = wp0[2].offset;
    223223  shift   = wp0[2].shift + shiftNum;
    224   round   = (1<<(shift-1));
     224  round   = shift?(1<<(shift-1)):0;
    225225
    226226  for ( y = iHeight-1; y >= 0; y-- )
    227227  {
  • source/Lib/TLibDecoder/TDecSbac.cpp

     
    11141114    return;
    11151115  }
    11161116 
    1117   UInt useTansformSkip;
    1118   m_pcTDecBinIf->decodeBin( useTansformSkip , m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) );
    1119   if(eTType!= TEXT_LUMA && uiDepth == 4)
     1117  UInt useTransformSkip;
     1118  m_pcTDecBinIf->decodeBin( useTransformSkip , m_cTransformSkipSCModel.get( 0, eTType? TEXT_CHROMA: TEXT_LUMA, 0 ) );
     1119  if(eTType!= TEXT_LUMA)
    11201120  {
    1121     uiDepth --;
     1121    const UInt uiLog2TrafoSize = g_aucConvertToBit[pcCU->getSlice()->getSPS()->getMaxCUWidth()] + 2 - uiDepth;
     1122        if(uiLog2TrafoSize == 2)
     1123        {
     1124          uiDepth --;
     1125    }
    11221126  }
    11231127  DTRACE_CABAC_VL( g_nSymbolCounter++ )
    11241128  DTRACE_CABAC_T("\tparseTransformSkip()");
    11251129  DTRACE_CABAC_T( "\tsymbol=" )
    1126   DTRACE_CABAC_V( useTansformSkip )
     1130  DTRACE_CABAC_V( useTransformSkip )
    11271131  DTRACE_CABAC_T( "\tAddr=" )
    11281132  DTRACE_CABAC_V( pcCU->getAddr() )
    11291133  DTRACE_CABAC_T( "\tetype=" )
     
    11321136  DTRACE_CABAC_V( uiAbsPartIdx )
    11331137  DTRACE_CABAC_T( "\n" )
    11341138
    1135   pcCU->setTransformSkipSubParts( useTansformSkip, eTType, uiAbsPartIdx, uiDepth);
     1139  pcCU->setTransformSkipSubParts( useTransformSkip, eTType, uiAbsPartIdx, uiDepth);
    11361140}
    11371141#endif
    11381142