mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Added HyperionPng with similar interface as Hyperion to test frame-capture and handling.
This commit is contained in:
@@ -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})
|
||||
|
71
libsrc/hyperionpng/HyperionPng.cpp
Normal file
71
libsrc/hyperionpng/HyperionPng.cpp
Normal 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;
|
||||
}
|
||||
|
@@ -1,174 +0,0 @@
|
||||
|
||||
// STL includes
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
// Boblight includes
|
||||
#include <boblight.h>
|
||||
|
||||
// PNGWriter includes
|
||||
#define NO_FREETYPE
|
||||
#include "pngwriter.h"
|
||||
|
||||
struct RaspiPng
|
||||
{
|
||||
pngwriter writer;
|
||||
unsigned long fileIndex;
|
||||
|
||||
unsigned frameCnt;
|
||||
|
||||
std::ofstream logFile;
|
||||
};
|
||||
|
||||
void* boblight_init()
|
||||
{
|
||||
RaspiPng* raspiPng = new RaspiPng();
|
||||
|
||||
raspiPng->writer.pngwriter_rename("/home/pi/RASPI_0000.png");
|
||||
raspiPng->fileIndex = 0;
|
||||
raspiPng->frameCnt = 0;
|
||||
raspiPng->logFile.open("/home/pi/raspipng.log");
|
||||
|
||||
raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl;
|
||||
|
||||
return reinterpret_cast<void*>(raspiPng);
|
||||
}
|
||||
|
||||
void boblight_destroy(void* vpboblight)
|
||||
{
|
||||
RaspiPng* raspiPng = reinterpret_cast<RaspiPng*>(vpboblight);
|
||||
raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl;
|
||||
|
||||
raspiPng->logFile.close();
|
||||
delete raspiPng;
|
||||
}
|
||||
|
||||
void boblight_setscanrange(void* vpboblight, int width, int height)
|
||||
{
|
||||
RaspiPng* raspiPng = reinterpret_cast<RaspiPng*>(vpboblight);
|
||||
raspiPng->logFile << __PRETTY_FUNCTION__ << "(" << width << ", " << height << ")" << std::endl;
|
||||
|
||||
raspiPng->writer.resize(width, height);
|
||||
}
|
||||
|
||||
void boblight_addpixelxy(void* vpboblight, int x, int y, int* rgb)
|
||||
{
|
||||
RaspiPng* raspiPng = reinterpret_cast<RaspiPng*>(vpboblight);
|
||||
|
||||
if (raspiPng->frameCnt%50 == 0)
|
||||
{
|
||||
// NB libpngwriter uses a one-based indexing scheme
|
||||
raspiPng->writer.plot(x+1,y+1, rgb[0]/255.0, rgb[1]/255.0, rgb[2]/255.0);
|
||||
}
|
||||
}
|
||||
|
||||
int boblight_sendrgb(void* vpboblight, int sync, int* outputused)
|
||||
{
|
||||
RaspiPng* raspiPng = reinterpret_cast<RaspiPng*>(vpboblight);
|
||||
raspiPng->logFile << __PRETTY_FUNCTION__ << "(" << sync << ", outputused) FRAME " << raspiPng->frameCnt++ << std::endl;
|
||||
|
||||
if (raspiPng->frameCnt%50 == 0)
|
||||
{
|
||||
// Write-out the current frame and prepare for the next
|
||||
raspiPng->writer.write_png();
|
||||
|
||||
++raspiPng->fileIndex;
|
||||
char filename[64];
|
||||
|
||||
sprintf(filename, "/home/pi/RASPI_%04ld.png", raspiPng->fileIndex);
|
||||
|
||||
raspiPng->writer.pngwriter_rename(filename);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int boblight_connect(void* vpboblight, const char* address, int port, int usectimeout)
|
||||
{
|
||||
RaspiPng* raspiPng = reinterpret_cast<RaspiPng*>(vpboblight);
|
||||
raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int boblight_setpriority(void* vpboblight, int priority)
|
||||
{
|
||||
RaspiPng* raspiPng = reinterpret_cast<RaspiPng*>(vpboblight);
|
||||
raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* boblight_geterror(void* vpboblight)
|
||||
{
|
||||
RaspiPng* raspiPng = reinterpret_cast<RaspiPng*>(vpboblight);
|
||||
raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl;
|
||||
|
||||
return "ERROR";
|
||||
}
|
||||
|
||||
int boblight_getnrlights(void* vpboblight)
|
||||
{
|
||||
RaspiPng* raspiPng = reinterpret_cast<RaspiPng*>(vpboblight);
|
||||
raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl;
|
||||
|
||||
return 50;
|
||||
}
|
||||
|
||||
const char* boblight_getlightname(void* vpboblight, int lightnr)
|
||||
{
|
||||
RaspiPng* raspiPng = reinterpret_cast<RaspiPng*>(vpboblight);
|
||||
raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl;
|
||||
|
||||
return "LIGHT";
|
||||
}
|
||||
|
||||
int boblight_getnroptions(void* vpboblight)
|
||||
{
|
||||
RaspiPng* raspiPng = reinterpret_cast<RaspiPng*>(vpboblight);
|
||||
raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char* boblight_getoptiondescript(void* vpboblight, int option)
|
||||
{
|
||||
RaspiPng* raspiPng = reinterpret_cast<RaspiPng*>(vpboblight);
|
||||
raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl;
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
int boblight_setoption(void* vpboblight, int lightnr, const char* option)
|
||||
{
|
||||
RaspiPng* raspiPng = reinterpret_cast<RaspiPng*>(vpboblight);
|
||||
raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int boblight_getoption(void* vpboblight, int lightnr, const char* option, const char** output)
|
||||
{
|
||||
RaspiPng* raspiPng = reinterpret_cast<RaspiPng*>(vpboblight);
|
||||
raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int boblight_addpixel(void* vpboblight, int lightnr, int* rgb)
|
||||
{
|
||||
RaspiPng* raspiPng = reinterpret_cast<RaspiPng*>(vpboblight);
|
||||
raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int boblight_ping(void* vpboblight, int* outputused)
|
||||
{
|
||||
RaspiPng* raspiPng = reinterpret_cast<RaspiPng*>(vpboblight);
|
||||
raspiPng->logFile << __PRETTY_FUNCTION__ << std::endl;
|
||||
|
||||
return 1;
|
||||
}
|
Reference in New Issue
Block a user