Work on dynamic huffman coding.
This commit is contained in:
parent
7f5009fb5e
commit
a6e31c8d39
16 changed files with 456 additions and 95 deletions
|
@ -26,9 +26,9 @@ unsigned char ByteUtils::getByteN(uint32_t input, unsigned n)
|
|||
return (input << 8*n) >> 24;
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::mirror(unsigned char byte, unsigned length)
|
||||
uint32_t ByteUtils::mirror(uint32_t byte, unsigned length)
|
||||
{
|
||||
unsigned char ret{0};
|
||||
uint32_t ret{0};
|
||||
for(unsigned idx=0; idx<length; idx++)
|
||||
{
|
||||
if (getBitN(byte, length - 1 - idx))
|
||||
|
@ -121,31 +121,25 @@ unsigned char ByteUtils::getFromString(const std::string& string)
|
|||
std::string ByteUtils::toString(uint32_t input, unsigned length)
|
||||
{
|
||||
std::string ret;
|
||||
std::string working;
|
||||
for(unsigned idx=0; idx<length; idx++)
|
||||
if (length > 8)
|
||||
{
|
||||
if (idx > 0 && idx % 8 == 0)
|
||||
unsigned overshoot = length - 8;
|
||||
for(unsigned idx=0; idx<overshoot; idx++)
|
||||
{
|
||||
if (ret.empty())
|
||||
{
|
||||
ret = working;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = working + '-' + ret;
|
||||
}
|
||||
working = "";
|
||||
ret += getBitN(input, length - 1 - idx) ? '1' : '0';
|
||||
}
|
||||
ret += "-";
|
||||
for(unsigned idx=0; idx<8; idx++)
|
||||
{
|
||||
ret += getBitN(input, 7 - idx) ? '1' : '0';
|
||||
}
|
||||
working += getBitN(input, 7 - idx) ? '1' : '0';
|
||||
}
|
||||
|
||||
if (length <= 8)
|
||||
else
|
||||
{
|
||||
ret = working;
|
||||
}
|
||||
else if(!working.empty())
|
||||
{
|
||||
ret = working + '-' + ret;
|
||||
for(unsigned idx=0; idx<length; idx++)
|
||||
{
|
||||
ret += getBitN(input, 7 - idx) ? '1' : '0';
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public:
|
|||
|
||||
static std::string toString(uint32_t input, unsigned length = 8);
|
||||
|
||||
static unsigned char mirror(unsigned char byte, unsigned length=0);
|
||||
static uint32_t mirror(uint32_t input, unsigned length=0);
|
||||
|
||||
static void ReverseBuffer(char* buffer, char* reverse, unsigned size, unsigned targetSize);
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ void BitStream::write(uint32_t data)
|
|||
unsigned num_bytes = sizeof(uint32_t);
|
||||
for(unsigned idx=0; idx<num_bytes;idx++)
|
||||
{
|
||||
std::cout << "Writing byte " << idx << " for multibyte" << std::endl;
|
||||
writeByte(ByteUtils::getByteN(data, idx));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ void BufferBitStream::writeByte(unsigned char data, bool checkOverflow)
|
|||
{
|
||||
mChecksumCalculator->addValue(out_byte);
|
||||
}
|
||||
std::cout << "Writing byte " << ByteUtils::toString(out_byte) << " had bitoffset of " << mBitOffset << std::endl;
|
||||
//std::cout << "Writing byte " << ByteUtils::toString(out_byte) << " had bitoffset of " << mBitOffset << std::endl;
|
||||
mBuffer.push_back(out_byte);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue