104 lines
2.5 KiB
C++
104 lines
2.5 KiB
C++
#include "Image.h"
|
|
#include "PngWriter.h"
|
|
|
|
#include "File.h"
|
|
#include "BitStream.h"
|
|
#include "ByteUtils.h"
|
|
#include "ImagePrimitives.h"
|
|
|
|
#include "TestFramework.h"
|
|
|
|
#include <iostream>
|
|
|
|
TEST_CASE(TestCompressedPng, "image")
|
|
{
|
|
unsigned width = 20;
|
|
unsigned height = 20;
|
|
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 = 255 * idx /(width*height);
|
|
data[idx] = val;
|
|
}
|
|
|
|
image->setData(data);
|
|
|
|
PngWriter writer;
|
|
writer.setPath("test_compressed.png");
|
|
writer.setCompressionMethod(Deflate::CompressionMethod::NONE);
|
|
writer.write(image);
|
|
|
|
return;
|
|
File test_file("test_compressed.png");
|
|
test_file.SetAccessMode(File::AccessMode::Read);
|
|
test_file.Open(true);
|
|
|
|
while(auto byte = test_file.readNextByte())
|
|
{
|
|
std::cout << static_cast<unsigned>(*byte) << std::endl;
|
|
}
|
|
test_file.Close();
|
|
}
|
|
|
|
TEST_CASE(TestFixedPng, "image")
|
|
{
|
|
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_fixed.png");
|
|
writer.setCompressionMethod(Deflate::CompressionMethod::FIXED_HUFFMAN);
|
|
writer.write(image);
|
|
|
|
//return;
|
|
File test_file("test_fixed.png");
|
|
std::cout << test_file.dumpBinary();
|
|
|
|
}
|
|
|
|
TEST_CASE(TestDynamicCompressedPng, "image")
|
|
{
|
|
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();
|
|
}
|