#include #include "TestFramework.h" #include "HuffmanStream.h" #include "BufferBitStream.h" TEST_CASE(TestHuffmanCodeLengthTable, "compression") { HuffmanCodeLengthTable table; std::vector > mappings {{144, 8}, {112, 9}, {24, 7}, {8 ,8}}; std::vector code_length_sequence; for(const auto& entry : mappings) { for(unsigned idx=0;idx lengths = {7,4,4,7,5,5,7,7,6,6,7,6,6,6,8,6,6,8, 6,6,7,6,8,7,7,7,7,7,7,6,6,7,7,6,6,7,7,8,8,7,7,7,6,6,7,7,7,7,6,7,7,7, 7,7,7,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,4,4,5,6,7,7,9,8,8,9,9,8,8,7, 7,8,7,6,8,9,9,11,10,8,7,7,8,8,7,3,0,9,9,9,9,9,8,6,7,7,7,7,9,5,7,4,7,4,4,4,3,4,4,4,4,4,5,5,6}; HuffmanCodeLengthTable table; table.setInputLengthSequence(lengths, false); table.buildCompressedLengthSequence(); auto compressed_sequence = table.getCompressedLengthSequence(); //for (auto entry : compressed_sequence) //{ // std::cout << "Code " << entry.first << " extra bits " << entry.second << std::endl; //} auto compressed_lengths = table.getCompressedLengthCounts(); for(unsigned idx = 0; idx coding_lengths{4, 0, 6, 7, 3, 2, 4, 2, 7, 4, 6, 3, 0, 6, 0, 0, 0, 0, 0}; codingTable.setInputLengthSequence(coding_lengths, true); codingTable.buildPrefixCodes(); BufferBitStream out_stream; out_stream.writeNBits(1, 1); out_stream.writeNBits(2, 2); out_stream.writeNBits(29, 5); out_stream.writeNBits(29, 5); out_stream.writeNBits(10, 4); /* std::vector permuted(19, 0); static constexpr unsigned DEFLATE_PERMUTATION[19]{16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15}; unsigned count = 0; for (auto length : coding_lengths) { permuted[DEFLATE_PERMUTATION[count]] = length; count++; } unsigned skip_count = 0; for(unsigned idx=0; idx