⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cabacreader.cpp

📁 jsvm开发代码包括抽样,编码,抽取,解码等一系列功能,可以做工具或研究用
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  //===== last symbol ====
  if( rbLast )
  {
    UInt uiSymbol;
    UInt uiPrevSigCycle = 0;
    // there must be one significant coefficient already
    for( UInt ui = uiScanIndex - 1; ui >= 0; ui -- ) {
      if( piCoeff[pucScan[ui]] && ! piCoeffBase[pucScan[ui]] ) {
        uiPrevSigCycle = ui;
        break;
      }
    }
    RNOK( CabaDecoder::getSymbol( uiSymbol, m_cLastCCModel.get( uiCtxOffset, pos2ctx_last8x8[uiPrevSigCycle] ) ) );
    rbLast = (uiSymbol == 1);
    ROTRS( rbLast, Err::m_nOK );
  }

  //===== SIGNIFICANCE BIT =====
  UInt uiSig = 0;
  UInt uiLastScanPosition = uiScanIndex + 1;
  while (uiLastScanPosition < 64 && piCoeffBase[pucScan[uiLastScanPosition]]) uiLastScanPosition ++;
  if( uiLastScanPosition < 64 )
  {
  RNOK( CabaDecoder::getSymbol( uiSig, m_cMapCCModel.get(uiCtxOffset, pos2ctx_map8x8[uiScanIndex] ) ) );
  }
  else uiSig = 1;

  if( uiSig )
  {
    UInt  uiCoeff = uiSig;
    UInt  uiSign  = 0;
    UInt  uiCtx   = 1;

    //===== SIGN =====
    RNOK( CabaDecoder::getEpSymbol( uiSign ) );

    //===== ABSOLUTE VALUE =====
    RNOK( CabaDecoder::getSymbol  ( uiCoeff, m_cOneCCModel.get( uiCtxOffset, uiCtx ) ) );

    if( uiCoeff )
    {
      uiCtx = 0;
      RNOK( CabaDecoder::getExGolombLevel( uiCoeff, m_cAbsCCModel.get( uiCtxOffset, uiCtx ) ) );
      uiCoeff += 2;
    }
    else
    {
      uiCoeff++;
    }

    piCoeff[pucScan[uiScanIndex]] = ( uiSign ? -(Int)uiCoeff : (Int)uiCoeff );
  }

  return Err::m_nOK;
}




ErrVal
CabacReader::RQdecodeTCoeffRef_8x8( MbDataAccess&   rcMbDataAccess,
                                    MbDataAccess&   rcMbDataAccessBase,
                                    B8x8Idx         c8x8Idx,
                                    UInt            uiScanIndex,
                                    UInt            uiCtx )
{
  TCoeff*       piCoeff     = rcMbDataAccess    .getMbTCoeffs().get8x8( c8x8Idx );
  TCoeff*       piCoeffBase = rcMbDataAccessBase.getMbTCoeffs().get8x8( c8x8Idx );
  const Bool    bFrame  = ( FRAME == rcMbDataAccess.getMbPicType());
  const UChar*  pucScan = (bFrame) ? g_aucFrameScan64 : g_aucFieldScan64;

  DTRACE_T( "LUMA_8x8_REF" );
  DTRACE_V( c8x8Idx.b8x8Index() );
  DTRACE_V( uiScanIndex );
  DTRACE_V( uiCtx );
  DTRACE_N;


  UInt uiSig = 0;
  RNOK( CabaDecoder::getSymbol( uiSig, m_cRefCCModel.get( 0, 2 * uiCtx ) ) );

  if( uiSig )
  {
    UInt uiSymbol = 0;
    RNOK( CabaDecoder::getSymbol( uiSymbol, m_cRefCCModel.get( 0, 1 + 2 * uiCtx ) ) );
    UInt uiSignBL = ( piCoeffBase[pucScan[uiScanIndex]] < 0 ? 1 : 0 );
    UInt uiSignEL = ( uiSignBL ^ uiSymbol );

    piCoeff[pucScan[uiScanIndex]] = ( uiSig ? ( uiSignEL ? -1 : 1 ) : 0 );
  }

  return Err::m_nOK;
}






ErrVal
CabacReader::RQdecodeNewTCoeff_Luma ( MbDataAccess&   rcMbDataAccess,
                                      MbDataAccess&   rcMbDataAccessBase,
                                      ResidualMode    eResidualMode,
                                      Bool            b8x8, 
                                      LumaIdx         cIdx,
                                      UInt            uiScanIndex,
                                      Bool&           rbLast,
                                      UInt&           ruiNumCoefRead )
{
  TCoeff*       piCoeff     = rcMbDataAccess    .getMbTCoeffs().get( cIdx );
  TCoeff*       piCoeffBase = rcMbDataAccessBase.getMbTCoeffs().get( cIdx );
  const Bool    bFrame  = ( FRAME == rcMbDataAccess.getMbPicType());
  const UChar*  pucScan = (bFrame) ? g_aucFrameScan : g_aucFieldScan;  
  UInt          uiStop      = 16;

  ROT( piCoeffBase[pucScan[uiScanIndex]] );

  DTRACE_T( "LUMA_4x4_NEW" );
  DTRACE_V( cIdx.b4x4() );
  DTRACE_V( uiScanIndex );
  DTRACE_N;

  RNOK( xRQdecodeNewTCoeffs( piCoeff, piCoeffBase, uiStop, type2ctx1[eResidualMode], type2ctx2[eResidualMode], pucScan, uiScanIndex, rbLast, ruiNumCoefRead ) );

  return Err::m_nOK;
}



ErrVal
CabacReader::RQdecodeTCoeffRef_Luma ( MbDataAccess&   rcMbDataAccess,
                                      MbDataAccess&   rcMbDataAccessBase,
                                      LumaIdx         cIdx,
                                     UInt            uiScanIndex,
                                     UInt            uiCtx )
{
  TCoeff*       piCoeff     = rcMbDataAccess    .getMbTCoeffs().get( cIdx );
  TCoeff*       piCoeffBase = rcMbDataAccessBase.getMbTCoeffs().get( cIdx );
  const Bool    bFrame  = ( FRAME == rcMbDataAccess.getMbPicType());
  const UChar*  pucScan = (bFrame) ? g_aucFrameScan : g_aucFieldScan;

  DTRACE_T( "LUMA_4x4_REF" );
  DTRACE_V( cIdx.b4x4() );
  DTRACE_V( uiScanIndex );
  DTRACE_V( uiCtx );
  DTRACE_N;

  RNOK( xRQdecodeTCoeffsRef( piCoeff, piCoeffBase, pucScan, uiScanIndex, uiCtx ) );

  return Err::m_nOK;
}

ErrVal
CabacReader::RQdecodeNewTCoeff_Chroma ( MbDataAccess&   rcMbDataAccess,
                                        MbDataAccess&   rcMbDataAccessBase,
                                        ResidualMode    eResidualMode,
                                        ChromaIdx       cIdx,
                                        UInt            uiScanIndex,
                                        Bool&           rbLast,
                                        UInt&           ruiNumCoefRead )
{
  // == Nokia, m11509
  //ruiLast                   = 0;
  // ==
  TCoeff*       piCoeff     = rcMbDataAccess    .getMbTCoeffs().get( cIdx );
  TCoeff*       piCoeffBase = rcMbDataAccessBase.getMbTCoeffs().get( cIdx );
  const Bool    bFrame      = ( FRAME == rcMbDataAccess.getMbPicType());
  const UChar*  pucScan     = ( eResidualMode == CHROMA_DC ? g_aucIndexChromaDCScan : ((bFrame) ? g_aucFrameScan : g_aucFieldScan) );
  UInt          uiStop      = ( eResidualMode == CHROMA_DC ? 4 : 16 );

  ROT( piCoeffBase[pucScan[uiScanIndex]] );

  DTRACE_T( "CHROMA_4x4_NEW" );
  DTRACE_V( cIdx );
  DTRACE_V( uiScanIndex );
  DTRACE_N;

  RNOK( xRQdecodeNewTCoeffs( piCoeff, piCoeffBase, uiStop, type2ctx1[eResidualMode], type2ctx2[eResidualMode], pucScan, uiScanIndex, rbLast, ruiNumCoefRead ) );

  return Err::m_nOK;
}



ErrVal
CabacReader::RQdecodeTCoeffRef_Chroma ( MbDataAccess&   rcMbDataAccess,
                                        MbDataAccess&   rcMbDataAccessBase,
                                        ResidualMode    eResidualMode,
                                        ChromaIdx       cIdx,
                                        UInt            uiScanIndex,
                                        UInt            uiCtx )
{
  TCoeff*       piCoeff     = rcMbDataAccess    .getMbTCoeffs().get( cIdx );
  TCoeff*       piCoeffBase = rcMbDataAccessBase.getMbTCoeffs().get( cIdx );
  const Bool    bFrame      = ( FRAME == rcMbDataAccess.getMbPicType());
  const UChar*  pucScan     = ( eResidualMode == CHROMA_DC ? g_aucIndexChromaDCScan : ((bFrame) ? g_aucFrameScan : g_aucFieldScan) );
 
  DTRACE_T( "CHROMA_4x4_REF" );
  DTRACE_V( cIdx );
  DTRACE_V( uiScanIndex );
  DTRACE_V( uiCtx );
  DTRACE_N;
  RNOK( xRQdecodeTCoeffsRef( piCoeff, piCoeffBase, pucScan, uiScanIndex, uiCtx ) );
  return Err::m_nOK;
}




ErrVal
CabacReader::xRQdecodeNewTCoeffs( TCoeff*       piCoeff,
                                  TCoeff*       piCoeffBase,
                                  UInt          uiStop,
                                  UInt          uiCtx1,
                                  UInt          uiCtx2,
                                  const UChar*  pucScan,
                                  UInt          uiScanIndex,
                                  Bool&         rbLast,
                                  UInt&         ruiNumCoefRead,
                                  const int*    paiCtxEobMap,
                                  const int*    paiCtxSigMap,
                                  UInt          uiStride )
{
  ruiNumCoefRead = 0;
  if( rbLast )
  {
    UInt uiSymbol;
    UInt uiPrevSigCycle = 0;
    // there must be one significant coefficient already
    for( UInt ui = uiScanIndex - 1; ui >= 0; ui -- ) {
      if( piCoeff[pucScan[ui]] && ! piCoeffBase[pucScan[ui]] ) {
        uiPrevSigCycle = ui;
        break;
      }
    }

    RNOK( CabaDecoder::getSymbol( uiSymbol, m_cLastCCModel.get( uiCtx2, paiCtxEobMap[uiPrevSigCycle] ) ) );
    rbLast = (uiSymbol == 1);
    ROTRS(rbLast, Err::m_nOK);
  }

  //===== SIGNIFICANCE BIT ======
  UInt uiSig;
  do
  {
    ruiNumCoefRead++;

    UInt uiLastScanPosition = uiScanIndex + uiStride;
    while (uiLastScanPosition < uiStop && piCoeffBase[pucScan[uiLastScanPosition]])
      uiLastScanPosition += uiStride;
  
    if (uiLastScanPosition < uiStop)
    {
      RNOK( CabaDecoder::getSymbol( uiSig, m_cMapCCModel.get( uiCtx2, paiCtxSigMap[uiScanIndex] ) ) );
    } else {
      uiSig = 1;
    }

    if( uiSig )
    {
      break;
    }

    uiScanIndex += uiStride;
    while (uiScanIndex < uiStop && piCoeffBase[pucScan[uiScanIndex]])
      uiScanIndex += uiStride;
  }
  while ( true );
    UInt  uiCoeff = uiSig;
    UInt  uiSign  = 0;
    UInt  uiCtx   = 1;

    //===== SIGN =====
    RNOK( CabaDecoder::getEpSymbol( uiSign ) );

    //===== ABSOLUTE VALUE =====
    RNOK( CabaDecoder::getSymbol  ( uiCoeff, m_cOneCCModel.get( uiCtx1, uiCtx ) ) );

    if( uiCoeff )
    {
      uiCtx = 0;
      RNOK( CabaDecoder::getExGolombLevel( uiCoeff, m_cAbsCCModel.get( uiCtx1, uiCtx ) ) );

      uiCoeff += 2;
    }
    else
    {
      uiCoeff++;
    }

    piCoeff[pucScan[uiScanIndex]] = ( uiSign ? -(Int)uiCoeff : (Int)uiCoeff );


  return Err::m_nOK;
}

ErrVal
CabacReader::xRQdecodeTCoeffsRef( TCoeff*       piCoeff,
                                  TCoeff*       piCoeffBase,
                                  const UChar*  pucScan,
                                  UInt          uiScanIndex,
                                  UInt          uiCtx )
{
  UInt uiSig = 0;
  RNOK( CabaDecoder::getSymbol( uiSig, m_cRefCCModel.get( 0, 2 * uiCtx ) ) );

  if( uiSig )
  {
    UInt uiSymbol = 0;
    RNOK( CabaDecoder::getSymbol( uiSymbol, m_cRefCCModel.get( 0, 1 + 2 * uiCtx ) ) );
    UInt uiSignBL = ( piCoeffBase[pucScan[uiScanIndex]] < 0 ? 1 : 0 );
    UInt uiSignEL = ( uiSignBL ^ uiSymbol );

    piCoeff[pucScan[uiScanIndex]] = ( uiSig ? ( uiSignEL ? -1 : 1 ) : 0 );
  }

  return Err::m_nOK;
}

ErrVal
CabacReader::RQdecodeCycleSymbol( UInt& uiCycle )
{
  UInt itSymbol;
  RNOKS( CabaDecoder::getEpSymbol( itSymbol ) );
  // Changed mapping to match syntax in WD (justin.ridge@nokia.com)
  uiCycle = 1 + itSymbol;
  if (itSymbol == 1) {
    RNOKS( CabaDecoder::getEpSymbol( itSymbol ) );
    uiCycle += itSymbol;
  }
  // heiko.schwarz@hhi.fhg.de: return added
  return Err::m_nOK;
}

ErrVal
CabacReader::RQcompSepAlign()
{
  CabacReader::finish();
  // start() takes care of byte align
  CabacReader::start();
  return Err::m_nOK;
}


ErrVal
CabacReader::RQdecodeTCoeffsRef ( TCoeff*       piCoeff,
                                  TCoeff*       piCoeffBase,
                                  const UChar*  pucScan,
                                  UInt          uiScanIndex,
                                  UInt          uiCtx )
{
  DTRACE_T( "REF" );
  DTRACE_V( uiScanIndex );
  DTRACE_N;

  UInt uiSig = 0;
  RNOKS( CabaDecoder::getSymbol( uiSig, m_cRefCCModel.get( 0, 2 * uiCtx ) ) );

  if( uiSig )
  {
    UInt uiSymbol = 0;
    RNOKS( CabaDecoder::getSymbol( uiSymbol, m_cRefCCModel.get( 0, 1 + 2 * uiCtx ) ) );
    UInt uiSignBL = ( piCoeffBase[pucScan[uiScanIndex]] < 0 ? 1 : 0 );
    UInt uiSignEL = ( uiSignBL ^ uiSymbol );

    piCoeff[pucScan[uiScanIndex]] = ( uiSig ? ( uiSignEL ? -1 : 1 ) : 0 );
  }

  return Err::m_nOK;
}





ErrVal
CabacReader::RQdecodeSigCoeff       ( TCoeff*         piCoeff,
                                      TCoeff*         piCoeffBase,
                                      ResidualMode    eResidualMode,
                                      const UChar*    pucScan,
                                      Bool            bFirstSigRunCode,
                                      UInt            uiCycle,
                                      UInt            uiStartScanIdx,
                                      UInt            uiLastScanIdx,
                                      Bool&           rbEndOfBlock,
                                      TCoeff&         riCoeff,
                                      UInt&           ruiRun )
{
  static UInt uiPrevSigCycle = 0;
  UInt uiLastSig, uiSig;

    // decode last significance flag
  if( ! bFirstSigRunCode ) {
    if( eResidualMode == LUMA_8X8 ) {
      RNOKS( CabaDecoder::getSymbol( uiLastSig, m_cLastCCModel.get( 2, pos2ctx_last8x8[uiPrevSigCycle] ) ) );
    }
    else {
      RNOKS( CabaDecoder::getSymbol( uiLastSig, m_cLastCCModel.get( type2ctx2 [eResidualMode], uiPrevSigCycle ) ) );
    }
    rbEndOfBlock = ( uiLastSig == 1 ) ? 1 : 0;

  }

  uiSig = 0;

  if( ! rbEndOfBlock ) {
    if( uiCycle == uiLastScanIdx ) {
      ruiRun  = 1;
      uiSig   = 1;
    }
    else {
      UInt uiScanIndex;

      uiScanIndex   = uiCycle;
      do {
        if( ! piCoeffBase[pucScan[uiScanIndex]] ) {
          if( eResidualMode == LUMA_8X8 ) {
            RNOKS( CabaDecoder::getSymbol( uiSig, m_cMapCCModel.get( 2, pos2ctx_map8x8[uiScanIndex] ) ) );
          }
          else {
            RNOKS( CabaDecoder::getSymbol( uiSig, m_cMapCCModel.get( type2ctx2[eR

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -