Ticket #1320: fix_1320_rdpcm_accumulator.patch

File fix_1320_rdpcm_accumulator.patch, 6.3 KB (added by karlsharman, 10 years ago)

Possible fix for software.

  • source/Lib/TLibCommon/TComTrQuant.cpp

     
    16301630  UInt uiX = 0;
    16311631  UInt uiY = 0;
    16321632
     1633#if FIX_1320_RDPCM_ACCUMULATOR
     1634        UInt &majorAxis             = (mode == RDPCM_VER) ? uiX      : uiY;
     1635        UInt &minorAxis             = (mode == RDPCM_VER) ? uiY      : uiX;
     1636  const UInt  majorAxisLimit        = (mode == RDPCM_VER) ? uiWidth  : uiHeight;
     1637  const UInt  minorAxisLimit        = (mode == RDPCM_VER) ? uiHeight : uiWidth;
     1638  static const TCoeff pelMin=(Int) std::numeric_limits<Pel>::min();
     1639  static const TCoeff pelMax=(Int) std::numeric_limits<Pel>::max();
     1640#else
    16331641        UInt &majorAxis             = (mode == RDPCM_HOR) ? uiX      : uiY;
    16341642        UInt &minorAxis             = (mode == RDPCM_HOR) ? uiY      : uiX;
    16351643  const UInt  majorAxisLimit        = (mode == RDPCM_HOR) ? uiWidth  : uiHeight;
    16361644  const UInt  minorAxisLimit        = (mode == RDPCM_HOR) ? uiHeight : uiWidth;
    16371645  const UInt  referenceSampleOffset = (mode == RDPCM_HOR) ? 1        : uiWidth;
     1646#endif
    16381647
    1639   const Bool bUseHalfRoundingPoint = (mode != RDPCM_OFF);
     1648  const Bool bUseHalfRoundingPoint  = (mode != RDPCM_OFF);
    16401649
    16411650  uiAbsSum = 0;
    16421651
    16431652  for ( majorAxis = 0; majorAxis < majorAxisLimit; majorAxis++ )
    16441653  {
     1654#if FIX_1320_RDPCM_ACCUMULATOR
     1655    TCoeff accumulatorValue = 0; // 32-bit accumulator
     1656#endif
    16451657    for ( minorAxis = 0; minorAxis < minorAxisLimit; minorAxis++ )
    16461658    {
    16471659      const UInt sampleIndex      = (uiY * uiWidth) + uiX;
    16481660      const UInt coefficientIndex = (rotateResidual ? (uiSizeMinus1-sampleIndex) : sampleIndex);
    16491661      const Pel  currentSample    = pcResidual[(uiY * uiStride) + uiX];
     1662#if FIX_1320_RDPCM_ACCUMULATOR
     1663      const TCoeff encoderSideDelta = TCoeff(currentSample) - accumulatorValue;
     1664#else
    16501665      const Pel  referenceSample  = ((mode != RDPCM_OFF) && (majorAxis > 0)) ? reconstructedResi[sampleIndex - referenceSampleOffset] : 0;
    16511666
    16521667      const Pel  encoderSideDelta = currentSample - referenceSample;
     1668#endif
    16531669
    16541670      Pel reconstructedDelta;
    16551671      if ( bLossless )
     
    16651681
    16661682      uiAbsSum += abs(pcCoeff[coefficientIndex]);
    16671683
     1684#if FIX_1320_RDPCM_ACCUMULATOR
     1685      if (mode == RDPCM_OFF) { reconstructedResi[sampleIndex] = reconstructedDelta; }
     1686      else
     1687      {
     1688        accumulatorValue += reconstructedDelta;
     1689        reconstructedResi[sampleIndex] = (Pel) Clip3<TCoeff>(pelMin, pelMax, accumulatorValue);
     1690      }
     1691#else
    16681692      reconstructedResi[sampleIndex] = reconstructedDelta + referenceSample;
     1693#endif
    16691694    }
    16701695  }
    16711696}
     
    17641789      rdpcmMode = RDPCMMode(pcCU->getExplicitRdpcmMode( compID, uiAbsPartIdx ));
    17651790    }
    17661791
     1792#if FIX_1320_RDPCM_ACCUMULATOR
     1793    static const TCoeff pelMin=(Int) std::numeric_limits<Pel>::min();
     1794    static const TCoeff pelMax=(Int) std::numeric_limits<Pel>::max();
     1795#endif
    17671796    if (rdpcmMode == RDPCM_VER)
    17681797    {
     1798#if FIX_1320_RDPCM_ACCUMULATOR
     1799      for( UInt uiX = 0; uiX < uiWidth; uiX++ )
     1800      {
     1801        Pel *pcCurResidual = pcResidual+uiX;
     1802        TCoeff accumulator = *pcCurResidual; // 32-bit accumulator
     1803        pcCurResidual+=uiStride;
     1804        for( UInt uiY = 1; uiY < uiHeight; uiY++, pcCurResidual+=uiStride )
     1805        {
     1806          accumulator += *(pcCurResidual);
     1807          *pcCurResidual = (Pel)Clip3<TCoeff>(pelMin, pelMax, accumulator);
     1808        }
     1809      }
     1810#else
    17691811      pcResidual += uiStride; //start from row 1
    17701812
    17711813      for( UInt uiY = 1; uiY < uiHeight; uiY++ )
     
    17761818        }
    17771819        pcResidual += uiStride;
    17781820      }
     1821#endif
    17791822    }
    17801823    else if (rdpcmMode == RDPCM_HOR)
    17811824    {
     1825#if FIX_1320_RDPCM_ACCUMULATOR
     1826      for( UInt uiY = 0; uiY < uiHeight; uiY++ )
     1827      {
     1828        Pel *pcCurResidual = pcResidual+uiY*uiStride;
     1829        TCoeff accumulator = *pcCurResidual;
     1830        pcCurResidual++;
     1831        for( UInt uiX = 1; uiX < uiWidth; uiX++, pcCurResidual++ )
     1832        {
     1833          accumulator += *(pcCurResidual);
     1834          *pcCurResidual = (Pel)Clip3<TCoeff>(pelMin, pelMax, accumulator);
     1835        }
     1836      }
     1837#else
    17821838      for( UInt uiY = 0; uiY < uiHeight; uiY++ )
    17831839      {
    17841840        for( UInt uiX = 1; uiX < uiWidth; uiX++ )
     
    17871843        }
    17881844        pcResidual += uiStride;
    17891845      }
     1846#endif
    17901847    }
    17911848  }
    17921849}
     
    31413198  }
    31423199}
    31433200
     3201#if FIX_1320_RDPCM_ACCUMULATOR
     3202Void TComTrQuant::transformSkipQuantOneSample(TComTU &rTu, const ComponentID compID, const TCoeff resiDiff, TCoeff* pcCoeff, const UInt uiPos, const QpParam &cQP, const Bool bUseHalfRoundingPoint)
     3203#else
    31443204Void TComTrQuant::transformSkipQuantOneSample(TComTU &rTu, const ComponentID compID, const Pel resiDiff, TCoeff* pcCoeff, const UInt uiPos, const QpParam &cQP, const Bool bUseHalfRoundingPoint)
     3205#endif
    31453206{
    31463207        TComDataCU    *pcCU                           = rTu.getCU();
    31473208  const UInt           uiAbsPartIdx                   = rTu.GetAbsPartIdxTU();
  • source/Lib/TLibCommon/TypeDef.h

     
    235235
    236236#define MAX_NUM_LONG_TERM_REF_PICS                       33
    237237
     238#define FIX_1320_RDPCM_ACCUMULATOR                        1 ///< Fix for accumulator size in RDPCM.
    238239
    239240// ====================================================================================================================
    240241// RExt control settings
  • source/Lib/TLibCommon/TComTrQuant.h

     
    194194  Int*    getSliceNSamples(){ return m_sliceNsamples ;}
    195195  Double* getSliceSumC()    { return m_sliceSumC; }
    196196#endif
     197#if FIX_1320_RDPCM_ACCUMULATOR
     198  Void transformSkipQuantOneSample(TComTU &rTu, const ComponentID compID, const TCoeff resiDiff, TCoeff* pcCoeff, const UInt uiPos, const QpParam &cQP, const Bool bUseHalfRoundingPoint);
     199#else
    197200  Void transformSkipQuantOneSample(TComTU &rTu, const ComponentID compID, const Pel resiDiff, TCoeff* pcCoeff, const UInt uiPos, const QpParam &cQP, const Bool bUseHalfRoundingPoint);
     201#endif
    198202  Void invTrSkipDeQuantOneSample(TComTU &rTu, ComponentID compID, TCoeff pcCoeff, Pel &reconSample, const QpParam &cQP, UInt uiPos );
    199203
    200204protected: