stuff-from-scratch/test/image/TestPngWriter.cpp

39 lines
891 B
C++
Raw Normal View History

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-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-01-01 18:46:31 +00:00
int main()
{
2022-11-24 09:05:39 +00:00
unsigned width = 20;
unsigned height = 20;
2022-01-01 18:46:31 +00:00
unsigned numChannels = 3;
auto image = Image<unsigned char>::Create(width, height);
image->setNumChannels(numChannels);
2022-01-01 18:46:31 +00:00
std::vector<unsigned char> data(image->getBytesPerRow()*height, 0);
2022-11-21 17:45:12 +00:00
2022-11-24 09:05:39 +00:00
ImagePrimitives::drawAlternatingStrips(data, width, height, numChannels, image->getBytesPerRow());
image->setData(data);
2022-01-01 18:46:31 +00:00
PngWriter writer;
2022-11-21 17:45:12 +00:00
writer.setPath("test.png");
writer.write(image);
2022-01-01 18:46:31 +00:00
2022-11-23 17:51:36 +00:00
File test_file("test.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();
2022-01-01 18:46:31 +00:00
return 0;
}