Initial fixed huffman coding for png.
This commit is contained in:
parent
e4f9393ee7
commit
7f5009fb5e
39 changed files with 1294 additions and 440 deletions
|
@ -26,7 +26,20 @@ unsigned char ByteUtils::getByteN(uint32_t input, unsigned n)
|
|||
return (input << 8*n) >> 24;
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getLowerNBits(unsigned char input, unsigned num)
|
||||
unsigned char ByteUtils::mirror(unsigned char byte, unsigned length)
|
||||
{
|
||||
unsigned char ret{0};
|
||||
for(unsigned idx=0; idx<length; idx++)
|
||||
{
|
||||
if (getBitN(byte, length - 1 - idx))
|
||||
{
|
||||
ret |= (0x01 << idx);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getLowerNBits(uint32_t input, unsigned num)
|
||||
{
|
||||
switch (num)
|
||||
{
|
||||
|
@ -81,7 +94,7 @@ unsigned char ByteUtils::getMBitsAtN(unsigned char input, unsigned m, unsigned n
|
|||
}
|
||||
}
|
||||
|
||||
unsigned char ByteUtils::getBitN(unsigned char input, unsigned n)
|
||||
bool ByteUtils::getBitN(uint32_t input, unsigned n)
|
||||
{
|
||||
return input & (1 << n);
|
||||
}
|
||||
|
@ -105,12 +118,34 @@ unsigned char ByteUtils::getFromString(const std::string& string)
|
|||
return ret;
|
||||
}
|
||||
|
||||
std::string ByteUtils::toString(unsigned char c)
|
||||
std::string ByteUtils::toString(uint32_t input, unsigned length)
|
||||
{
|
||||
std::string ret;
|
||||
for(unsigned idx=0; idx<8; idx++)
|
||||
std::string working;
|
||||
for(unsigned idx=0; idx<length; idx++)
|
||||
{
|
||||
ret += getBitN(c, 7 - idx) ? '1' : '0';
|
||||
if (idx > 0 && idx % 8 == 0)
|
||||
{
|
||||
if (ret.empty())
|
||||
{
|
||||
ret = working;
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = working + '-' + ret;
|
||||
}
|
||||
working = "";
|
||||
}
|
||||
working += getBitN(input, 7 - idx) ? '1' : '0';
|
||||
}
|
||||
|
||||
if (length <= 8)
|
||||
{
|
||||
ret = working;
|
||||
}
|
||||
else if(!working.empty())
|
||||
{
|
||||
ret = working + '-' + ret;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue