2022-01-01 18:46:31 +00:00
|
|
|
#include "Image.h"
|
|
|
|
#include "PngWriter.h"
|
2022-11-21 17:45:12 +00:00
|
|
|
|
2022-11-23 17:51:36 +00:00
|
|
|
#include "File.h"
|
2022-11-23 15:41:33 +00:00
|
|
|
#include "BitStream.h"
|
2022-11-28 10:16:04 +00:00
|
|
|
#include "ByteUtils.h"
|
2022-11-21 17:45:12 +00:00
|
|
|
#include "ImagePrimitives.h"
|
2022-01-01 18:46:31 +00:00
|
|
|
|
2022-11-29 18:00:19 +00:00
|
|
|
#include "TestFramework.h"
|
2022-12-01 10:52:48 +00:00
|
|
|
#include "TestUtils.h"
|
2022-05-18 07:42:44 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2022-11-29 18:00:19 +00:00
|
|
|
TEST_CASE(TestCompressedPng, "image")
|
2022-01-01 18:46:31 +00:00
|
|
|
{
|
2022-11-25 09:43:14 +00:00
|
|
|
unsigned width = 20;
|
|
|
|
unsigned height = 20;
|
2022-11-24 16:15:41 +00:00
|
|
|
unsigned numChannels = 1;
|
2022-11-12 15:34:54 +00:00
|
|
|
auto image = Image<unsigned char>::Create(width, height);
|
|
|
|
image->setNumChannels(numChannels);
|
2022-11-24 16:15:41 +00:00
|
|
|
image->setBitDepth(8);
|
2022-01-01 18:46:31 +00:00
|
|
|
|
2022-11-24 16:15:41 +00:00
|
|
|
std::vector<unsigned char> data(width*height, 0);
|
|
|
|
for (unsigned idx=0; idx<width*height; idx++)
|
|
|
|
{
|
2022-11-25 09:43:14 +00:00
|
|
|
unsigned char val = 255 * idx /(width*height);
|
|
|
|
data[idx] = val;
|
2022-11-24 16:15:41 +00:00
|
|
|
}
|
2022-11-21 17:45:12 +00:00
|
|
|
|
2022-11-12 15:34:54 +00:00
|
|
|
image->setData(data);
|
2022-01-01 18:46:31 +00:00
|
|
|
|
|
|
|
PngWriter writer;
|
2022-12-01 10:52:48 +00:00
|
|
|
writer.setPath(TestUtils::getTestOutputDir() / "test_compressed.png");
|
2022-11-29 12:05:08 +00:00
|
|
|
writer.setCompressionMethod(Deflate::CompressionMethod::NONE);
|
2022-11-21 17:45:12 +00:00
|
|
|
writer.write(image);
|
2022-01-01 18:46:31 +00:00
|
|
|
|
2022-11-28 10:16:04 +00:00
|
|
|
return;
|
2022-12-01 10:52:48 +00:00
|
|
|
File test_file(TestUtils::getTestOutputDir() / "test_compressed.png");
|
|
|
|
test_file.open(File::AccessMode::Read);
|
2022-11-23 17:51:36 +00:00
|
|
|
|
|
|
|
while(auto byte = test_file.readNextByte())
|
|
|
|
{
|
2022-11-30 18:28:50 +00:00
|
|
|
//std::cout << static_cast<unsigned>(*byte) << std::endl;
|
2022-11-23 17:51:36 +00:00
|
|
|
}
|
2022-11-28 10:16:04 +00:00
|
|
|
}
|
2022-11-23 17:51:36 +00:00
|
|
|
|
2022-11-29 18:00:19 +00:00
|
|
|
TEST_CASE(TestFixedPng, "image")
|
2022-11-28 10:16:04 +00:00
|
|
|
{
|
|
|
|
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;
|
2022-12-01 10:52:48 +00:00
|
|
|
writer.setPath(TestUtils::getTestOutputDir() / "test_fixed.png");
|
2022-11-28 10:16:04 +00:00
|
|
|
writer.setCompressionMethod(Deflate::CompressionMethod::FIXED_HUFFMAN);
|
|
|
|
writer.write(image);
|
|
|
|
|
|
|
|
//return;
|
2022-12-01 10:52:48 +00:00
|
|
|
File test_file(TestUtils::getTestOutputDir() / "test_fixed.png");
|
2022-11-30 18:28:50 +00:00
|
|
|
//std::cout << test_file.dumpBinary();
|
2022-11-28 10:16:04 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-29 18:00:19 +00:00
|
|
|
TEST_CASE(TestDynamicCompressedPng, "image")
|
2022-11-29 12:05:08 +00:00
|
|
|
{
|
|
|
|
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;
|
2022-12-01 10:52:48 +00:00
|
|
|
writer.setPath(TestUtils::getTestOutputDir() / "test_dynamic.png");
|
2022-11-29 12:05:08 +00:00
|
|
|
writer.write(image);
|
|
|
|
|
|
|
|
//return;
|
2022-12-01 10:52:48 +00:00
|
|
|
File test_file(TestUtils::getTestOutputDir() / "test_dynamic.png");
|
2022-11-30 18:28:50 +00:00
|
|
|
//std::cout << test_file.dumpBinary();
|
2022-01-01 18:46:31 +00:00
|
|
|
}
|