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-05-18 07:42:44 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2022-11-28 10:16:04 +00:00
|
|
|
void testCompressedPng()
|
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-11-28 10:16:04 +00:00
|
|
|
writer.setPath("test_compressed.png");
|
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;
|
|
|
|
File test_file("test_compressed.png");
|
2022-11-23 17:51:36 +00:00
|
|
|
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();
|
2022-11-28 10:16:04 +00:00
|
|
|
}
|
2022-11-23 17:51:36 +00:00
|
|
|
|
2022-11-28 10:16:04 +00:00
|
|
|
void testFixedPng()
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
//testCompressedPng();
|
|
|
|
testFixedPng();
|
2022-01-01 18:46:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|