2013-08-02 11:54:09 +02:00
|
|
|
// PNG includes
|
|
|
|
#ifndef NO_FREETYPE
|
|
|
|
#define NO_FREETYPE
|
|
|
|
#endif
|
|
|
|
#include "pngwriter.h"
|
|
|
|
|
|
|
|
|
|
|
|
#include <hyperionpng/HyperionPng.h>
|
|
|
|
|
|
|
|
HyperionPng::HyperionPng() :
|
|
|
|
mBuffer(nullptr),
|
|
|
|
mFrameCnt(0),
|
|
|
|
mWriter(new pngwriter()),
|
|
|
|
mFileIndex(0)
|
|
|
|
{
|
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
|
|
|
HyperionPng::~HyperionPng()
|
|
|
|
{
|
|
|
|
std::cout << "HyperionPng is being deleted" << std::endl;
|
|
|
|
delete mBuffer;
|
|
|
|
|
2013-08-03 23:24:22 +02:00
|
|
|
mWriter->close();
|
|
|
|
delete mWriter;
|
2013-08-02 11:54:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void HyperionPng::setInputSize(const unsigned width, const unsigned height)
|
|
|
|
{
|
|
|
|
delete mBuffer;
|
|
|
|
mBuffer = new RgbImage(width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
RgbImage& HyperionPng::image()
|
|
|
|
{
|
|
|
|
return *mBuffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HyperionPng::commit()
|
|
|
|
{
|
2013-08-03 23:24:22 +02:00
|
|
|
writeImage(*mBuffer);
|
2013-08-02 11:54:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void HyperionPng::operator() (const RgbImage& inputImage)
|
2013-08-03 23:24:22 +02:00
|
|
|
{
|
|
|
|
writeImage(inputImage);
|
|
|
|
}
|
|
|
|
|
|
|
|
void HyperionPng::writeImage(const RgbImage& inputImage)
|
2013-08-02 11:54:09 +02:00
|
|
|
{
|
|
|
|
// Write only every n'th frame
|
2013-08-03 23:24:22 +02:00
|
|
|
if (mFrameCnt%10 == 0)
|
2013-08-02 11:54:09 +02:00
|
|
|
{
|
|
|
|
// Set the filename for the PNG
|
|
|
|
char filename[64];
|
2013-08-03 23:24:22 +02:00
|
|
|
sprintf(filename, "/home/pi/RASPI_%04lu.png", mFileIndex);
|
2013-08-02 11:54:09 +02:00
|
|
|
mWriter->pngwriter_rename(filename);
|
2013-08-03 23:24:22 +02:00
|
|
|
mWriter->resize(inputImage.width(), inputImage.height());
|
2013-08-02 11:54:09 +02:00
|
|
|
|
|
|
|
// Plot the pixels from the image to the PNG-Writer
|
|
|
|
for (unsigned y=0; y<inputImage.width(); ++y)
|
|
|
|
{
|
|
|
|
for (unsigned x=0; x<inputImage.height(); ++x)
|
|
|
|
{
|
|
|
|
const RgbColor& color = inputImage(x,y);
|
|
|
|
mWriter->plot(x+1, inputImage.height()-y, color.red/255.0, color.green/255.0, color.blue/255.0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-03 23:24:22 +02:00
|
|
|
std::cout << "Writing the PNG" << std::endl;
|
2013-08-02 11:54:09 +02:00
|
|
|
// Write-out the current frame and prepare for the next
|
|
|
|
mWriter->write_png();
|
|
|
|
|
|
|
|
++mFileIndex;
|
2013-08-03 23:24:22 +02:00
|
|
|
std::cout << "PNGWRITER FINISHED" << std::endl;
|
2013-08-02 11:54:09 +02:00
|
|
|
}
|
|
|
|
++mFrameCnt;
|
|
|
|
}
|
|
|
|
|