Initial fixed huffman coding for png.
This commit is contained in:
parent
e4f9393ee7
commit
7f5009fb5e
39 changed files with 1294 additions and 440 deletions
|
@ -3,9 +3,13 @@
|
|||
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
void testReading()
|
||||
{
|
||||
std::vector<std::string> bytes{"11100101", "00110101", "00010001"};
|
||||
std::vector<std::string> bytes{
|
||||
"11101101",
|
||||
"01011101",
|
||||
"00001001",
|
||||
"01111111"};
|
||||
|
||||
BufferBitStream stream;
|
||||
for(const auto& byte : bytes)
|
||||
|
@ -14,17 +18,67 @@ int main()
|
|||
}
|
||||
|
||||
unsigned char buffer{0} ;
|
||||
auto valid = stream.readNextNBits(3, buffer);
|
||||
auto valid = stream.readNextNBits(1, buffer);
|
||||
std::cout << "Slice0 is " << ByteUtils::toString(buffer) << std::endl;
|
||||
|
||||
valid = stream.readNextNBits(3, buffer);
|
||||
valid = stream.readNextNBits(2, buffer);
|
||||
std::cout << "Slice1 is " << ByteUtils::toString(buffer) << std::endl;
|
||||
|
||||
valid = stream.readNextNBits(5, buffer);
|
||||
std::cout << "Slice2 is " << ByteUtils::toString(buffer) << std::endl;
|
||||
|
||||
valid = stream.readNextNBits(7, buffer);
|
||||
valid = stream.readNextNBits(5, buffer);
|
||||
std::cout << "Slice3 is " << ByteUtils::toString(buffer) << std::endl;
|
||||
|
||||
valid = stream.readNextNBits(4, buffer);
|
||||
std::cout << "Slice3 is " << ByteUtils::toString(buffer) << " and int " << static_cast<int>(buffer) << std::endl;
|
||||
|
||||
valid = stream.readNextNBits(3, buffer);
|
||||
std::cout << "Slice3 is " << ByteUtils::toString(buffer) << std::endl;
|
||||
}
|
||||
|
||||
void testWriting()
|
||||
{
|
||||
BufferBitStream stream;
|
||||
|
||||
stream.writeByte(ByteUtils::getFromString("01100000"));
|
||||
|
||||
auto bits0 = ByteUtils::getFromString("00000111");
|
||||
stream.writeNBits(bits0, 3);
|
||||
|
||||
stream.writeByte(ByteUtils::getFromString("11110000"));
|
||||
|
||||
auto bits1 = ByteUtils::getFromString("01001101");
|
||||
stream.writeNBits(bits1, 7);
|
||||
|
||||
stream.writeByte(ByteUtils::getFromString("11110000"));
|
||||
|
||||
auto bits2 = ByteUtils::getFromString("00000001");
|
||||
stream.writeNBits(bits2, 1);
|
||||
|
||||
stream.flushRemainingBits();
|
||||
|
||||
stream.resetOffsets();
|
||||
|
||||
auto byte0 = ByteUtils::toString(*stream.readNextByte());
|
||||
auto byte1 = ByteUtils::toString(*stream.readNextByte());
|
||||
auto byte2 = ByteUtils::toString(*stream.readNextByte());
|
||||
auto byte3 = ByteUtils::toString(*stream.readNextByte());
|
||||
auto byte4 = ByteUtils::toString(*stream.readNextByte());
|
||||
|
||||
std::cout << "Got bytes 0 " << byte0 << std::endl;
|
||||
std::cout << "Got bytes 1 " << byte1 << std::endl;
|
||||
std::cout << "Got bytes 2 " << byte2 << std::endl;
|
||||
std::cout << "Got bytes 3 " << byte3 << std::endl;
|
||||
std::cout << "Got bytes 4 " << byte4 << std::endl;
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
//testReading()
|
||||
|
||||
testWriting();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -24,5 +24,10 @@ int main()
|
|||
std::cout << "Byte2 is " << ByteUtils::toString(byte2) << std::endl;
|
||||
std::cout << "Byte3 is " << ByteUtils::toString(byte3) << std::endl;
|
||||
|
||||
std::cout << "Mirroring" << std::endl;
|
||||
|
||||
auto out = ByteUtils::mirror(byte);
|
||||
std::cout << "Mirror is " << ByteUtils::toString(out) << std::endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue