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

📄 umc_base_bitstream.cpp

📁 这是在PCA下的基于IPP库示例代码例子,在网上下了IPP的库之后,设置相关参数就可以编译该代码.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
////               INTEL CORPORATION PROPRIETARY INFORMATION//  This software is supplied under the terms of a license agreement or//  nondisclosure agreement with Intel Corporation and may not be copied//  or disclosed except in accordance with the terms of that agreement.//        Copyright (c) 2004 - 2005 Intel Corporation. All Rights Reserved.//#include <string.h>#include "umc_base_bitstream.h"// ---------------------------------------------------------------------------//  CBaseBitstream::CBaseBitstream()//      Default constructor.// ---------------------------------------------------------------------------namespace UMC{/*long inline min( long x, long y){    if (x>y) return x;else return y;}*/CBaseBitstream::CBaseBitstream(){    m_pbs       = NULL;    m_pbsBase   = NULL;    m_bitOffset = 0;    m_localBs   = false;    m_maxBsSize = 0;    bits_encoded = 0;} // CBaseBitstream::CBaseBitstream()Ipp64s CBaseBitstream::GetBitsEncoded(){    return bits_encoded;}// ---------------------------------------------------------------------------//  CBaseBitstream::~CBaseBitstream()//      Destructor.// ---------------------------------------------------------------------------CBaseBitstream::~CBaseBitstream(){} // CBaseBitstream::~CBaseBitstream()// ---------------------------------------------------------------------------//  CBaseBitstream::CBaseBitstream()//      Constructs a new object.  Sets base pointer to point to the given//      bitstream buffer.  Neither the encoder or the decoder allocates//      memory for the bitstream buffer.//      pb      : pointer to input bitstream//      maxsize : size of bitstream// ---------------------------------------------------------------------------CBaseBitstream::CBaseBitstream(    Ipp8u* const    pb,    const Ipp32u    maxsize){    m_pbsBase   = pb;    m_pbs       = pb;    m_bitOffset = 0;    m_maxBsSize = maxsize;    m_localBs   = false;    bits_encoded =0;} // CBaseBitstream::CBaseBitstream()// ---------------------------------------------------------------------------//  [ENC] CBaseBitstream::Reset()//      Resets buffer pointer to the beginning and clears buffer.// ---------------------------------------------------------------------------void CBaseBitstream::Reset(){    m_pbs       = m_pbsBase;    m_bitOffset = 0;    ClearBs();    //bits_encoded = 0;} // CBaseBitstream::Reset()// ---------------------------------------------------------------------------//  [DEC] CBaseBitstream::Reset()//      Reset pointer to point to a new bitstream.//      pb      : pointer to new input bitstream//      maxsize : size of new bitstream// ---------------------------------------------------------------------------void CBaseBitstream::Reset(    Ipp8u* const    pb,    const Ipp32u    maxsize){    m_pbs       = pb;    m_pbsBase   = pb;    m_bitOffset = 0;    m_maxBsSize = maxsize;    //bits_encoded = 0;} // CBaseBitstream::Reset()// ---------------------------------------------------------------------------//  CBaseBitstream::GetBsSize()//      Returns the size of the bitstream data in bytes based on the//      current position of the buffer pointer, m_pbs.// ---------------------------------------------------------------------------Ipp32u CBaseBitstream::GetBsSize(){    Ipp32u size;    size = Ipp32u(m_pbs - m_pbsBase) + 1;    return(!m_bitOffset ? (size - 1) : size);} // CBaseBitstream::GetBsSize()// ---------------------------------------------------------------------------//  CBaseBitstream::GetBsOffset()//      Returns the bit position of the buffer pointer relative to the//      beginning of the buffer.// ---------------------------------------------------------------------------Ipp32u CBaseBitstream::GetBsOffset(){    return(Ipp32u(m_pbs - m_pbsBase) * 8 + m_bitOffset);} // CBaseBitstream::GetBsOffset()// ---------------------------------------------------------------------------//  CBaseBitstream::GetBsBase()//      Returns the base pointer to the beginning of the bitstream.// ---------------------------------------------------------------------------Ipp8u* CBaseBitstream::GetBsBase(){    return(m_pbsBase);} // CBaseBitstream::GetBsBase()// ---------------------------------------------------------------------------//  CBaseBitstream::GetBsMaxSize()//      Returns the maximum bitstream size.// ---------------------------------------------------------------------------Ipp32u CBaseBitstream::GetMaxBsSize(){    return(m_maxBsSize);} // CBaseBitstream::GetBsMaxSize()// ---------------------------------------------------------------------------//  CBaseBitstream::CheckBsLimit()//      Checks if read/write passed the maximum buffer size.// ---------------------------------------------------------------------------bool CBaseBitstream::CheckBsLimit(){    Ipp32u size;    size = GetBsSize();    if (size > m_maxBsSize)    {        return(false);    }    return(true);} // CBaseBitstream::CheckBsLimit()// ---------------------------------------------------------------------------//  [ENC] CBaseBitstream::SetState()//      Assigns new position to the buffer pointer.  This is only//      used to maintain the bitstream state when calling an assembly//      routine that accesses the bitstream.//      pbs         : points to new byte position//      bitOffset   : new bit offset// ---------------------------------------------------------------------------void CBaseBitstream::SetState(    Ipp8u* const    pbs,    const Ipp32u    bitOffset){    m_pbs       = pbs;    m_bitOffset = bitOffset;} // CBaseBitstream::SetState()// ---------------------------------------------------------------------------//  [ENC] CBaseBitstream::GetState()//      Obtains current position of the buffer pointer.  This is only//      used to maintain the bitstream state when calling an assembly//      routine that accesses the bitstream.//      *pbs        : to be assigned with the new pointer value//      *bitOffset  : to be assigned with the new bit offset// ---------------------------------------------------------------------------void CBaseBitstream::GetState(    Ipp8u**     pbs,    Ipp32u*     bitOffset){    *pbs       = m_pbs;    *bitOffset = m_bitOffset;} // CBaseBitstream::GetState()// ---------------------------------------------------------------------------//  [ENC] CBaseBitstream::UpdateState()//      Advances buffer pointer with given number of bits.  This is only//      used to maintain the bitstream state when calling an assembly//      routine that accesses the bitstream.//      nbits   : number of bits to advance// ---------------------------------------------------------------------------void CBaseBitstream::UpdateState(    const Ipp32u    nbits){    m_pbs      += (nbits + m_bitOffset) >> 3;    m_bitOffset = (nbits + m_bitOffset) & 0x7;} // CBaseBitstream::UpdateState()// ---------------------------------------------------------------------------//  [ENC] CBaseBitstream::ClearBs()//      Clears the bitstream buffer.// ---------------------------------------------------------------------------void CBaseBitstream::ClearBs(){    memset(m_pbsBase, 0, m_maxBsSize);} // CBaseBitstream::ClearBs()// ---------------------------------------------------------------------------//  [ENC] CBaseBitstream::PutBits()//      This is a special debug version that Detects Start Code Emulations.//      Appends bits into the bitstream buffer.  Supports only up to 24 bits.////      code        : code to be inserted into the bitstream//      code_length : length of the given code in number of bits// ---------------------------------------------------------------------------void CBaseBitstream::PutByteAligned(Ipp8u byte){    //assume that the buffer is aligned    *(m_pbs++) = byte;    bits_encoded+=8;}void CBaseBitstream::PutBits(    Ipp32u  code,    Ipp32u  length){    // make sure that the number of bits given is <= 24    // clear any nonzero bits in upper part of code    bits_encoded+=length;    code <<= (32 - length);    // shift field so that the given code begins at the current bit    // offset in the most significant byte of the 32-bit word    length += m_bitOffset;    code >>= m_bitOffset;    // write bytes back into memory, big-endian    m_pbs[0] = (Ipp8u) ((code >> 24) | (Ipp32u) *m_pbs);    m_pbs[1] = (Ipp8u) (code >> 16);    m_pbs[2] = (Ipp8u) (code >> 8);    m_pbs[3] = (Ipp8u) code;    // update bitstream pointer and bit offset    m_pbs += (length >> 3);    m_bitOffset = (length & 7);} // CBaseBitstream::PutBits()// ---------------------------------------------------------------------------//  [ENC] CBaseBitstream::PutVLCCode()//      Writes one Exp-Golomb code to the bitstream.  Automatically calculates//      the required code length.  Use only when this can not be implicitly//      known to the calling code, requiring length calculation anyway.////      code        : code to be inserted into the bitstream// ---------------------------------------------------------------------------Ipp32u CBaseBitstream::PutVLCCode(    const Ipp32u    code){    Ipp32s i, NN;    Ipp32u code_length;    NN = code + 1;    i = -1;    while (NN) {        NN >>= 1;        i++;    }    code_length = 1+(i<<1);    PutVLCBits(code,code_length);    return code_length;} // CBaseBitstream::PutVLCCode()// ---------------------------------------------------------------------------//  [ENC] CBaseBitstream::PutVLCBits()//      Writes one Exp-Golomb code to the bitstream.//      code        : code to be inserted into the bitstream//      code_length : length of the given code in number of bits// ---------------------------------------------------------------------------void CBaseBitstream::PutVLCBits(    const Ipp32u    code,    const Ipp32u    code_length){    Ipp32s info_length, bits;    if (code_length == 1)    {        PutBits(1,1);        return;    }    info_length = (code_length-1)/2;    bits = code+1-(1<<info_length);    PutBits(0,info_length);    PutBits(1,1);    PutBits (bits,info_length);} // CBaseBitstream::PutVLCBits()// ---------------------------------------------------------------------------//  [ENC] CBaseBitstream::WriteTrailingBits()//      Byte-align the buffer.// ---------------------------------------------------------------------------void CBaseBitstream::WriteTrailingBits(){    // Write Stop Bit    PutBits(1,1);    // No action needed if already byte aligned, i.e. !m_bitOffset    if (m_bitOffset)    {        // note that prior write operation automatically clears the unused        // bits in the current byte        m_pbs++;        bits_encoded+=8-m_bitOffset;        m_bitOffset = 0;    }} // CBaseBitstream::WriteTrailingBits()// ---------------------------------------------------------------------------//  [ENC] CBaseBitstream::ByteAlignWithZeros()//      Add zero bits to byte-align the buffer.// ---------------------------------------------------------------------------void CBaseBitstream::ByteAlignWithZeros(){    // No action needed if already byte aligned, i.e. !m_bitOffset    if (m_bitOffset)    {        // note that prior write operation automatically clears the unused        // bits in the current byte        m_pbs ++;        m_bitOffset = 0;        bits_encoded+=8-m_bitOffset;    }} // CBaseBitstream::ByteAlignWithZeros()// ---------------------------------------------------------------------------//  [ENC] CBaseBitstream::ByteAlignWithOnes()//      Add "1" bits to byte-align the buffer.// ---------------------------------------------------------------------------void CBaseBitstream::ByteAlignWithOnes(){    // No action needed if already byte aligned, i.e. !m_bitOffset    if (m_bitOffset)    {        PutBits(1,8-m_bitOffset);    }} // CBaseBitstream::ByteAlignWithOnes()// Standalone (not a CBaseBitstream methods) functions for bitstream decoding,// potentially with CPU-specific implementations for performance./************************* cabac part **************************/template <class T>T Clip3(T Min, T Max, T Value){    if (Value < Min)        return Min;    else if (Value > Max)        return Max;    else        return Value;}; //T Clip3(T Min, T Max, T Value)void InitializeContext(CABAC_CONTEXT *lpContext, long m, long n, long SliceQPy){    long preCtxState;    preCtxState = Clip3(1l, 126l, ((m * SliceQPy) >> 4) + n);    if (preCtxState <= 63)    {        lpContext->pStateIdx = static_cast<unsigned short int> (63 - preCtxState);        lpContext->valMPS = 0;    }    else    {        lpContext->pStateIdx = static_cast<unsigned short int> (preCtxState - 64);        lpContext->valMPS = 1;    };}; //void InitializeContext(CABAC_CONTEXT *lpContext, long m, long n, long SliceQPy)typedef struct INITIALIZE_VALUES{    short int m;    short int n;} INITIALIZE_VALUES;

⌨️ 快捷键说明

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