📄 blkwtdata.cpp
字号:
7;
m_nByteNums=0;
m_BitBuffer=0;
}
BitToByteOutput::~BitToByteOutput()
{
}
BitToByteOutput::BitToByteOutput(ByteOutputBuffer *pOut)
{
m_pOut=0;
m_bDelFF=false;
m_nBitPosition=7;
m_nByteNums=0;
m_BitBuffer=0;
m_pOut=pOut;
}
void BitToByteOutput::Reset()
{
m_bDelFF = false;
m_nBitPosition = 7;
m_BitBuffer = 0;
m_nByteNums = 0;
}
void BitToByteOutput::WriteBit(int nBit)
{
m_BitBuffer |= (nBit&0x01)<<(m_nBitPosition--);
if (m_nBitPosition<0) {
if (m_BitBuffer != 0xFF) { // No bit-stuffing needed
if (m_bDelFF) { // Output delayed 0xFF if any
m_pOut->Write(0xFF);
m_bDelFF = false;
m_nByteNums++;
}
// Output the bit buffer
m_pOut->Write(m_BitBuffer);
m_nByteNums++;
m_nBitPosition = 7;
}
else { // We need to do bit stuffing on next byte
m_bDelFF = true;
m_nBitPosition = 6; // One less bit in next byte
}
m_BitBuffer = 0;
}
}
void BitToByteOutput::WriteBits(int *pSymBuf, int nSymNums)
{
int i;
int bbuf,bpos;
bbuf = m_BitBuffer;
bpos = m_nBitPosition;
// Write symbol by symbol to bit buffer
for (i=0; i<nSymNums; i++) {
bbuf |= (pSymBuf[i]&0x01)<<(bpos--);
if (bpos<0) { // Bit buffer is full, write it
if (bbuf != 0xFF) { // No bit-stuffing needed
if (m_bDelFF) { // Output delayed 0xFF if any
m_pOut->Write(0xFF);
m_bDelFF = false;
m_nByteNums++;
}
m_pOut->Write(bbuf);
m_nByteNums++;
m_nBitPosition = 7;
}
else { // We need to do bit stuffing on next byte
m_bDelFF = true;
m_nBitPosition = 6; // One less bit in next byte
}
bbuf = 0;
}
}
m_BitBuffer = bbuf;
m_nBitPosition = bpos;
}
void BitToByteOutput::Flush()
{
if (m_bDelFF) { // There was a bit stuffing
if (m_nBitPosition != 6) { // Bit buffer is not empty
// Output delayed 0xFF
m_pOut->Write(0xFF);
m_bDelFF = false;
m_nByteNums++;
// Pad to byte boundary with an alternating sequence of 0's
// and 1's.
m_BitBuffer |= (PAD_SEQ >> (6-m_nBitPosition));
// Output the bit buffer
m_pOut->Write(m_BitBuffer);
m_nByteNums++;
m_nBitPosition = 7;
m_BitBuffer = 0;
}
}
else { // There was no bit stuffing
if (m_nBitPosition != 7) { // Bit buffer is not empty
// Pad to byte boundary with an alt
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -