📄 bitstrm.cpp
字号:
Int CInBitStream::eof () const
{
if(m_uNumOfBitsInBuffer==0)
return (m_pInStream->eof())?(EOF):0;
else
return 0;
}
Int CInBitStream::peekBits (const UInt numBits) const
{
assert (numBits <= 32);
UInt iBitsToRet;
Int nBitsToPeek = numBits - m_uNumOfBitsInBuffer;
if (nBitsToPeek <= 0)
iBitsToRet = getbit (m_chDecBuffer, 7, numBits);
else
{
streampos strmpos = m_pInStream->tellg();
Int eofstate = m_pInStream->eof();
iBitsToRet = getbit (m_chDecBuffer, 7, m_uNumOfBitsInBuffer);
for (; nBitsToPeek > 0; nBitsToPeek -= 8) {
int chNext = m_pInStream->get(); //get the next ch
Int iNext = chNext & 0x000000FF; //clean the upper bits
if (nBitsToPeek < 8){ //fractional char
iNext = iNext >> (8 - nBitsToPeek);
iBitsToRet = iNext | (iBitsToRet << nBitsToPeek);
}
else {
iBitsToRet = iBitsToRet << 8; //full char
iBitsToRet |= iNext;
}
}
m_pInStream->seekg (strmpos); // reset the strm ptr pos
if(eofstate==0)
m_pInStream->clear(); // get rid of new eofs
}
return iBitsToRet;
}
Int CInBitStream::peekOneBit (const UInt numBits) const
{
Int iBit,chNext;
Int nBitsToPeek = numBits - m_uNumOfBitsInBuffer;
if(nBitsToPeek<=0)
iBit=m_chDecBuffer&(256>>numBits);
else
{
streampos strmpos = m_pInStream->tellg();
Int eofstate = m_pInStream->eof();
for (; nBitsToPeek > 0; nBitsToPeek -= 8)
chNext = m_pInStream->get();
nBitsToPeek += 8;
iBit=chNext&(256>>nBitsToPeek);
m_pInStream->seekg (strmpos); // reset the strm ptr pos
if(eofstate==0)
m_pInStream->clear(); // get rid of new eofs
}
return iBit!=0;
}
//wchen-9-30-97: peekflush () function name changed
//wchen-9-30-97: matching of stuffing bits done outside bitstrm.cpp because bitstrm.cpp should be generic
// Added for error resilience mode By Toshiba
Int CInBitStream::peekBitsTillByteAlign (Int& nBitsToPeek) const
{
assert (m_uNumOfBitsInBuffer != 8);
// if(m_bFlashEnable){
nBitsToPeek = (m_uNumOfBitsInBuffer == 0) ? 8 : m_uNumOfBitsInBuffer;
return peekBits(nBitsToPeek);
// }
// return 0;
}
//wchen-9-30-97: function name changed
//added by toshiba for error resilience
// Modified for error resilient mode by Toshiba(1997-11-14)
Int CInBitStream::peekBitsFromByteAlign (Int nBitsToPeek) const
//Int CInBitStream::peekBitsFromByteAlign (UInt nBitsToPeek) const
// End Toshiba(1997-11-14)
{
assert (nBitsToPeek <= 32);
UInt iBitsToRet = 0;
// if (nBitsToPeek <= 0)
// iBitsToRet = getbit (m_chDecBuffer, 7, numBits);
//wchen-9-30-97
if (nBitsToPeek == 0) // UInt can never to negative
return 0; // no need to call get bits
else
{
streampos strmpos = m_pInStream->tellg();
Int eofstate = m_pInStream->eof();
if (m_uNumOfBitsInBuffer==0)
m_pInStream->get(); //length of stuffing bit = 8bits
for (; nBitsToPeek > 0; nBitsToPeek -= 8) {
Int chNext = m_pInStream->get(); //get the next ch
Int iNext = chNext & 0x000000FF; //clean the upper bits
if (nBitsToPeek < 8){ //fractional char
iNext = iNext >> (8 - nBitsToPeek);
iBitsToRet = iNext | (iBitsToRet << nBitsToPeek);
}
else {
iBitsToRet = iBitsToRet << 8; //full char
iBitsToRet |= iNext;
}
}
m_pInStream->seekg (strmpos); // reset the strm ptr pos
if (eofstate==0)
m_pInStream->clear(); // get rid of new eofs
}
return iBitsToRet;
}
Void COutBitStream::putBits (Char *pBits, Int lNOfBits)
{
assert(lNOfBits>=0);
while(lNOfBits>0)
{
if(lNOfBits>8)
{
putBitsC((Int)(*pBits),8);
lNOfBits-=8;
pBits++;
}
else
{
putBitsC((Int)(*pBits),(UInt)lNOfBits);
break;
}
}
}
Void COutBitStream::putBitStream(COutBitStream &cStrm)
{
cStrm.m_pchBufferRun[0]=cStrm.m_chEncBuffer >> cStrm.m_uEncNumEmptyBits;
putBits(cStrm.m_pchBuffer,cStrm.m_lCounter);
}
Int COutBitStream::flush ()
{
Int nBits = 0;
if (m_uEncNumEmptyBits != 8) {
nBits = m_uEncNumEmptyBits;
putBits ((Int) 0, (UInt) 1);
putBits ((Int) 0xFFFF, nBits - 1);
/*
*m_pchBufferRun++ = m_chEncBuffer;
m_iBuffer++;
m_lCounter += m_uEncNumEmptyBits;
nBits = m_uEncNumEmptyBits;
m_uEncNumEmptyBits = 8;
m_chEncBuffer = 0;
*/
}
else {
nBits = 8;
putBits ((Int) 0x007F, nBits);
}
return nBits;
}
Void COutBitStream::trace (const Char* rgchSymbolName)
{
if (m_pstrmTrace != NULL) {
m_pstrmTrace->width (20);
(*m_pstrmTrace) << rgchSymbolName;
m_pstrmTrace->flush ();
}
}
Void COutBitStream::trace (Int iValue, const Char* rgchSymbolName)
{
if (m_pstrmTrace != NULL) {
m_pstrmTrace->width (20);
(*m_pstrmTrace) << rgchSymbolName << "= ";
(*m_pstrmTrace) << iValue << "\n";
m_pstrmTrace->flush ();
}
}
Void COutBitStream::trace (UInt uiValue, const Char* rgchSymbolName)
{
if (m_pstrmTrace != NULL) {
m_pstrmTrace->width (20);
(*m_pstrmTrace) << rgchSymbolName << "= ";
(*m_pstrmTrace) << uiValue << "\n";
m_pstrmTrace->flush ();
}
}
Void COutBitStream::trace (Float fltValue, const Char* rgchSymbolName)
{
if (m_pstrmTrace != NULL) {
m_pstrmTrace->width (20);
(*m_pstrmTrace) << rgchSymbolName << "= ";
(*m_pstrmTrace) << fltValue << "\n";
m_pstrmTrace->flush ();
}
}
#ifndef __DOUBLE_PRECISION_
Void COutBitStream::trace (Double dblValue, const Char* rgchSymbolName)
{
if (m_pstrmTrace != NULL) {
m_pstrmTrace->width (20);
(*m_pstrmTrace) << rgchSymbolName << "= ";
(*m_pstrmTrace) << dblValue << "\n";
m_pstrmTrace->flush ();
}
}
#endif
Void COutBitStream::trace (const CMotionVector& mvValue, const Char* rgchSymbolName)
{
if (m_pstrmTrace != NULL) {
m_pstrmTrace->width (20);
(*m_pstrmTrace) << rgchSymbolName << "= ";
(*m_pstrmTrace) << mvValue.iMVX + mvValue.iMVX + mvValue.iHalfX << ", ";
(*m_pstrmTrace) << mvValue.iMVY + mvValue.iMVY + mvValue.iHalfY << "\n ";
m_pstrmTrace->flush ();
}
}
Void COutBitStream::trace (const CVector2D& vctValue, const Char* rgchSymbolName)
{
if (m_pstrmTrace != NULL) {
m_pstrmTrace->width (20);
(*m_pstrmTrace) << rgchSymbolName << "= ";
(*m_pstrmTrace) << vctValue.x << ", ";
(*m_pstrmTrace) << vctValue.y << "\n ";
m_pstrmTrace->flush ();
}
}
Void COutBitStream::trace (const CSite& stValue, const Char* rgchSymbolName)
{
if (m_pstrmTrace != NULL) {
m_pstrmTrace->width (20);
(*m_pstrmTrace) << rgchSymbolName << "= ";
(*m_pstrmTrace) << stValue.x << ", ";
(*m_pstrmTrace) << stValue.y << "\n ";
m_pstrmTrace->flush ();
}
}
Void COutBitStream::trace (const CFloatImage* pfi, const Char* rgchSymbolName, CRct rct)
{
if (m_pstrmTrace == NULL)
return;
Int iValue;
(*m_pstrmTrace) << rgchSymbolName << "= \n";
if (rct.valid ()) {
for (CoordI iY = rct.top; iY < rct.bottom; iY++) {
const PixelF* ppxlf = pfi->pixels (rct.left, iY);
for (CoordI iX = rct.left; iX < rct.right; iX++) {
iValue = (Int) *ppxlf;
(*m_pstrmTrace) << iValue << " ";
ppxlf++;
}
(*m_pstrmTrace) << "\n";
}
}
else {
const PixelF* ppxlf = pfi->pixels ();
for (CoordI iY = pfi->where ().top; iY < pfi->where ().bottom; iY++) {
for (CoordI iX = pfi->where ().left; iX < pfi->where ().right; iX++) {
iValue = (Int) *ppxlf;
(*m_pstrmTrace) << iValue << " ";
ppxlf++;
}
(*m_pstrmTrace) << "\n";
}
}
m_pstrmTrace->flush ();
}
Void COutBitStream::trace (const Float* ppxlf, UInt cElem, const Char* rgchSymbolName)
{
if (m_pstrmTrace == NULL)
return;
Int iValue;
(*m_pstrmTrace) << rgchSymbolName << ": \n";
for (UInt iElem = 0; iElem < cElem; iElem++) {
iValue = (Int) *ppxlf;
(*m_pstrmTrace) << iValue << " ";
ppxlf++;
}
(*m_pstrmTrace) << "\n";
m_pstrmTrace->flush ();
}
Void COutBitStream::trace (const Int* rgi, UInt cElem, const Char* rgchSymbolName)
{
if (m_pstrmTrace == NULL)
return;
(*m_pstrmTrace) << rgchSymbolName << ": \n";
for (UInt iElem = 0; iElem < cElem; iElem++) {
(*m_pstrmTrace) << *rgi++ << " ";
}
(*m_pstrmTrace) << "\n";
m_pstrmTrace->flush ();
}
Void COutBitStream::trace (const PixelC* rgpxlc, Int cCol, Int cRow, const Char* rgchSymbolName) //this is for tracing shape buffers
{
if (m_pstrmTrace == NULL)
return;
(*m_pstrmTrace) << rgchSymbolName << ": \n";
for (Int iRow = -1; iRow < cRow; iRow++) {
for (Int iCol = -1; iCol < cCol; iCol++) {
if (iRow == -1)
(*m_pstrmTrace) << "-";
else if (iCol == -1) {
m_pstrmTrace->width (2);
(*m_pstrmTrace) << iRow << "|";
}
else
(*m_pstrmTrace) << (*rgpxlc++ == OPAQUE);
}
(*m_pstrmTrace) << "\n";
}
m_pstrmTrace->flush ();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -