Some encode/decode practice.
This commit is contained in:
parent
8a41337e2d
commit
ff962a6b16
29 changed files with 727 additions and 305 deletions
|
@ -1,14 +1,46 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "HuffmanEncoder.h"
|
||||
#include "RunLengthEncoder.h"
|
||||
|
||||
void test_run_length_encoder()
|
||||
{
|
||||
std::string test_data = "BCAAAADDDCCACACAC";
|
||||
|
||||
RunLengthEncoder encoder;
|
||||
auto encoded = encoder.encode(test_data);
|
||||
|
||||
std::cout << "Encoded: " << encoded << std::endl;
|
||||
|
||||
auto decoded = encoder.decode(encoded);
|
||||
|
||||
std::cout << "Decoded: " << decoded << std::endl;
|
||||
}
|
||||
|
||||
void test_huffman_encoder()
|
||||
{
|
||||
//std::string testData = "BCAADDDCCACACAC";
|
||||
//std::vector<unsigned char> stream(testData.begin(), testData.end());
|
||||
|
||||
std::unordered_map<unsigned char, unsigned> counts;
|
||||
counts['A'] = 1;
|
||||
counts['B'] = 1;
|
||||
counts['C'] = 1;
|
||||
counts['D'] = 2;
|
||||
counts['E'] = 3;
|
||||
counts['F'] = 5;
|
||||
counts['G'] = 5;
|
||||
counts['H'] = 12;
|
||||
|
||||
HuffmanEncoder encoder;
|
||||
encoder.encode(counts);
|
||||
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
std::string testData = "BCAADDDCCACACAC";
|
||||
std::vector<unsigned char> stream(testData.begin(), testData.end());
|
||||
|
||||
HuffmanEncoder encoder;
|
||||
encoder.encode(stream);
|
||||
test_huffman_encoder();
|
||||
|
||||
//test_run_length_encoder();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
int main()
|
||||
{
|
||||
const auto path = "/home/jmsgrogan/code/MediaTool-build/bin/test.png";
|
||||
const auto path = "/home/jmsgrogan/Downloads/test.png";
|
||||
|
||||
PngReader reader;
|
||||
reader.setPath(path);
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "Image.h"
|
||||
#include "PngWriter.h"
|
||||
#include "PngWriterImpl.h"
|
||||
|
||||
#include "ImagePrimitives.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
@ -13,22 +14,13 @@ int main()
|
|||
image->setNumChannels(numChannels);
|
||||
|
||||
std::vector<unsigned char> data(image->getBytesPerRow()*height, 0);
|
||||
for(unsigned jdx=0;jdx<height;jdx++)
|
||||
{
|
||||
const auto heightOffset = jdx*image->getBytesPerRow();
|
||||
for(unsigned idx=0;idx<width*numChannels;idx+=numChannels)
|
||||
{
|
||||
const auto index = heightOffset + idx;
|
||||
data[index] = (idx%2 == 0) ? 255*jdx/(height+1) : 0;
|
||||
data[index+1] = 0;
|
||||
data[index+2] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
ImagePrimitives::drawAlternatingStrips(data, width,height, numChannels, image->getBytesPerRow());
|
||||
image->setData(data);
|
||||
|
||||
PngWriter writer;
|
||||
writer.SetPath("test.png");
|
||||
writer.Write(image);
|
||||
writer.setPath("test.png");
|
||||
writer.write(image);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue