Convert lz77 to use fixed buffer sizes.
This commit is contained in:
parent
a6e31c8d39
commit
af6fad72eb
9 changed files with 362 additions and 110 deletions
|
@ -19,6 +19,7 @@ list(APPEND TestFiles
|
|||
compiler/TestTemplatingEngine.cpp
|
||||
compression/TestStreamCompressor.cpp
|
||||
compression/TestHuffmanStream.cpp
|
||||
compression/TestLz77Encoder.cpp
|
||||
database/TestDatabase.cpp
|
||||
fonts/TestFontReader.cpp
|
||||
graphics/TestRasterizer.cpp
|
||||
|
|
32
test/compression/TestLz77Encoder.cpp
Normal file
32
test/compression/TestLz77Encoder.cpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "Lz77Encoder.h"
|
||||
#include "BufferBitStream.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
std::vector<unsigned> values {0, 10, 11, 12, 10, 11, 12, 0, 13, 14, 15, 10, 11, 12};
|
||||
|
||||
//std::vector<unsigned> values {0, 1, 2, 3, 0, 1, 2, 3, 0,1};
|
||||
|
||||
BufferBitStream input_stream;
|
||||
for (auto value : values)
|
||||
{
|
||||
input_stream.writeByte(value);
|
||||
}
|
||||
|
||||
BufferBitStream output_stream;
|
||||
|
||||
Lz77Encoder encoder(&input_stream, &output_stream);
|
||||
|
||||
encoder.encode();
|
||||
|
||||
auto hit_buffer = encoder.getHitBuffer();
|
||||
for(const auto& hit : hit_buffer)
|
||||
{
|
||||
const auto& [length, distance, next_char] = hit;
|
||||
std::cout << "Got hit " << length << " | " << distance << " | " << static_cast<int>(next_char) << std::endl;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -28,6 +28,7 @@ void testCompressedPng()
|
|||
|
||||
PngWriter writer;
|
||||
writer.setPath("test_compressed.png");
|
||||
writer.setCompressionMethod(Deflate::CompressionMethod::NONE);
|
||||
writer.write(image);
|
||||
|
||||
return;
|
||||
|
@ -72,9 +73,40 @@ void testFixedPng()
|
|||
|
||||
}
|
||||
|
||||
void testDynamicCompressedPng()
|
||||
{
|
||||
unsigned width = 10;
|
||||
unsigned height = 10;
|
||||
unsigned numChannels = 1;
|
||||
auto image = Image<unsigned char>::Create(width, height);
|
||||
image->setNumChannels(numChannels);
|
||||
image->setBitDepth(8);
|
||||
|
||||
std::vector<unsigned char> data(width*height, 0);
|
||||
for (unsigned idx=0; idx<width*height; idx++)
|
||||
{
|
||||
//unsigned char val = 100 * idx /(width*height);
|
||||
unsigned char val = 10;
|
||||
data[idx] = val;
|
||||
}
|
||||
|
||||
image->setData(data);
|
||||
|
||||
PngWriter writer;
|
||||
writer.setPath("test_dynamic.png");
|
||||
writer.write(image);
|
||||
|
||||
//return;
|
||||
File test_file("test_dynamic.png");
|
||||
std::cout << test_file.dumpBinary();
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
//testCompressedPng();
|
||||
testFixedPng();
|
||||
//testFixedPng();
|
||||
testDynamicCompressedPng();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue