Added HyperionPng with similar interface as Hyperion to test frame-capture and handling.

This commit is contained in:
T. van der Zwan
2013-08-02 11:54:09 +02:00
parent f6672499f5
commit 240218a6bd
13 changed files with 261 additions and 12 deletions

View File

@@ -10,6 +10,18 @@ target_link_libraries(bob2hyperion
hyperion
hyperion-utils)
# Find the libPNG
find_package(PNG REQUIRED QUIET)
# Add additional includes dirs
include_directories(${PNG_INCLUDE_DIR})
add_library(bob2hyperion-png SHARED
hyperion-png.cpp)
target_link_libraries(bob2hyperion-png
hyperion-png)
add_subdirectory(hyperion)
add_subdirectory(hyperionpng)
add_subdirectory(utils)

View File

@@ -9,7 +9,7 @@
// PNGWriter includes
#define NO_FREETYPE
#include "pngwriter.h"
#include "hyperionpng/pngwriter.h"
struct RaspiPng
{

View File

@@ -11,9 +11,11 @@ SET(CURRENT_SOURCE_DIR ${CMAKE_SOURCE_DIR}/libsrc/hyperionpng)
# Create the 'rasplight-png' library
add_library(hyperion-png SHARED
${CURRENT_SOURCE_DIR}/hyperion-png.cpp
${CURRENT_HEADER_DIR}/HyperionPng.h
${CURRENT_SOURCE_DIR}/HyperionPng.cpp
${CURRENT_SOURCE_DIR}/pngwriter.h
${CURRENT_SOURCE_DIR}/pngwriter.cc)
target_link_libraries(hyperion-png
hyperion-utils
${PNG_LIBRARIES})

View File

@@ -0,0 +1,71 @@
// 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;
// mWriter->close();
// delete mWriter;
}
void HyperionPng::setInputSize(const unsigned width, const unsigned height)
{
delete mBuffer;
mBuffer = new RgbImage(width, height);
}
RgbImage& HyperionPng::image()
{
return *mBuffer;
}
void HyperionPng::commit()
{
this->operator ()(*mBuffer);
}
void HyperionPng::operator() (const RgbImage& inputImage)
{
// Write only every n'th frame
if (mFrameCnt%mWriteFrequency == 0)
{
// Set the filename for the PNG
char filename[64];
sprintf(filename, "/home/pi/RASPI_%04ld.png", mFileIndex);
mWriter->pngwriter_rename(filename);
// 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);
}
}
// Write-out the current frame and prepare for the next
mWriter->write_png();
++mFileIndex;
}
++mFrameCnt;
}

View File

@@ -10,7 +10,7 @@
RgbImage::RgbImage(const unsigned width, const unsigned height, const RgbColor background) :
mWidth(width),
mHeight(height),
mColors(NULL)
mColors(nullptr)
{
mColors = new RgbColor[width*height];
for (RgbColor* color = mColors; color <= mColors+(mWidth*mHeight); ++color)
@@ -21,6 +21,8 @@ RgbImage::RgbImage(const unsigned width, const unsigned height, const RgbColor b
RgbImage::~RgbImage()
{
std::cout << "RgbImage(" << this << ") is being deleted" << std::endl;
delete[] mColors;
}