2013-08-15 21:11:02 +02:00
|
|
|
|
|
|
|
// STL includes
|
|
|
|
#include <csignal>
|
2013-11-13 20:23:01 +01:00
|
|
|
#include <iomanip>
|
2013-08-15 21:11:02 +02:00
|
|
|
|
|
|
|
// QT includes
|
2016-06-29 16:50:14 +02:00
|
|
|
#include <QtGui/QImage>
|
2013-11-13 20:23:01 +01:00
|
|
|
|
|
|
|
// getoptPlusPLus includes
|
|
|
|
#include <getoptPlusPlus/getoptpp.h>
|
2013-08-15 21:11:02 +02:00
|
|
|
|
2013-08-17 16:12:42 +02:00
|
|
|
// Dispmanx grabber includes
|
2016-02-24 23:34:47 +01:00
|
|
|
#include <grabber/DispmanxFrameGrabber.h>
|
2013-08-15 21:11:02 +02:00
|
|
|
|
2013-11-13 20:23:01 +01:00
|
|
|
using namespace vlofgren;
|
|
|
|
|
2013-08-15 21:11:02 +02:00
|
|
|
static bool running = true;
|
|
|
|
|
|
|
|
void signal_handler(int signum)
|
|
|
|
{
|
|
|
|
running = false;
|
|
|
|
}
|
|
|
|
|
2013-11-13 20:23:01 +01:00
|
|
|
int main(int argc, char** argv)
|
2013-08-15 21:11:02 +02:00
|
|
|
{
|
|
|
|
signal(SIGTERM, signal_handler);
|
|
|
|
signal(SIGINT, signal_handler);
|
|
|
|
|
2013-11-13 20:23:01 +01:00
|
|
|
int grabFlags = 0;
|
2013-12-04 17:48:02 +01:00
|
|
|
int grabCount = -1;
|
2013-11-13 20:23:01 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
// create the option parser and initialize all parameters
|
|
|
|
OptionsParser optionParser("Simple application to send a command to hyperion using the Json interface");
|
|
|
|
ParameterSet & parameters = optionParser.getParameters();
|
|
|
|
|
|
|
|
QString flagDescr = QString("Set the grab flags of the dispmanx frame grabber [default: 0x%1]").arg(grabFlags, 8, 16, QChar('0'));
|
2016-06-29 16:50:14 +02:00
|
|
|
StringParameter & argFlags = parameters.add<StringParameter> ('f', "flags", flagDescr.toLatin1().constData());
|
2013-12-04 17:48:02 +01:00
|
|
|
IntParameter & argCount = parameters.add<IntParameter> ('n', "count", "Number of images to capture (default infinite)");
|
|
|
|
argCount.setDefault(grabCount);
|
2013-11-13 20:23:01 +01:00
|
|
|
SwitchParameter<> & argList = parameters.add<SwitchParameter<> >('l', "list", "List the possible flags");
|
|
|
|
SwitchParameter<> & argHelp = parameters.add<SwitchParameter<> >('h', "help", "Show this help message and exit");
|
|
|
|
|
|
|
|
// parse all options
|
|
|
|
optionParser.parse(argc, const_cast<const char **>(argv));
|
|
|
|
|
|
|
|
// check if we need to display the usage. exit if we do.
|
|
|
|
if (argHelp.isSet())
|
|
|
|
{
|
|
|
|
optionParser.usage();
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (argList.isSet())
|
|
|
|
{
|
|
|
|
std::cout.width(15);
|
|
|
|
std::cout.width(10);
|
|
|
|
std::cout << "Possible DISPMANX flags: " << std::endl;
|
|
|
|
std::cout << "Name | " << "Value" << std::endl;
|
|
|
|
std::cout << "--------------------------------| " << "------" << std::endl;
|
|
|
|
std::cout << "DISPMANX_NO_ROTATE | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_NO_ROTATE << std::endl;
|
|
|
|
std::cout << "DISPMANX_ROTATE_90 | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_ROTATE_90 << std::endl;
|
|
|
|
std::cout << "DISPMANX_ROTATE_180 | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_ROTATE_180 << std::endl;
|
|
|
|
std::cout << "DISPMANX_ROTATE_270 | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_ROTATE_270 << std::endl;
|
|
|
|
|
|
|
|
std::cout << "DISPMANX_FLIP_HRIZ | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_FLIP_HRIZ << std::endl;
|
|
|
|
std::cout << "DISPMANX_FLIP_VERT | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_FLIP_VERT << std::endl;
|
|
|
|
|
|
|
|
std::cout << "DISPMANX_SNAPSHOT_NO_YUV | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_SNAPSHOT_NO_YUV << std::endl;
|
|
|
|
std::cout << "DISPMANX_SNAPSHOT_NO_RGB | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_SNAPSHOT_NO_RGB << std::endl;
|
|
|
|
std::cout << "DISPMANX_SNAPSHOT_FILL | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_SNAPSHOT_FILL << std::endl;
|
|
|
|
std::cout << "DISPMANX_SNAPSHOT_SWAP_RED_BLUE | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_SNAPSHOT_SWAP_RED_BLUE << std::endl;
|
|
|
|
std::cout << "DISPMANX_SNAPSHOT_PACK | 0x" << std::hex << std::setfill('0') << std::setw(8) << DISPMANX_SNAPSHOT_PACK << std::endl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (argFlags.isSet())
|
|
|
|
{
|
|
|
|
QString flagStr = QString::fromStdString(argFlags.getValue());
|
|
|
|
|
|
|
|
bool ok = false;
|
|
|
|
// grabFlags = flagStr.toInt(&ok);
|
|
|
|
if (flagStr.startsWith("0x"))
|
|
|
|
{
|
|
|
|
grabFlags = flagStr.toInt(&ok, 16);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
grabFlags = flagStr.toInt(&ok, 10);
|
|
|
|
}
|
|
|
|
std::cout << "Resulting flags: " << grabFlags << " (=0x" << std::hex << std::setfill('0') << std::setw(8) << grabFlags << ")" << std::dec << std::endl;
|
|
|
|
if (!ok)
|
|
|
|
{
|
|
|
|
std::cerr << "Failed to parse flags (" << flagStr.toStdString().c_str() << ")" << std::endl;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
}
|
2013-12-04 17:48:02 +01:00
|
|
|
|
|
|
|
grabCount = argCount.getValue();
|
2013-11-13 20:23:01 +01:00
|
|
|
}
|
|
|
|
catch (const std::runtime_error & e)
|
|
|
|
{
|
|
|
|
// An error occured. Display error and quit
|
|
|
|
std::cerr << e.what() << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-15 21:11:02 +02:00
|
|
|
DispmanxFrameGrabber frameGrabber(64, 64);
|
2013-11-13 20:23:01 +01:00
|
|
|
frameGrabber.setFlags(grabFlags);
|
2013-08-15 21:11:02 +02:00
|
|
|
|
|
|
|
unsigned iFrame = 0;
|
2013-11-11 10:00:37 +01:00
|
|
|
QImage qImage(64, 64, QImage::Format_ARGB32);
|
|
|
|
Image<ColorRgba> imageRgba(64, 64);
|
2013-08-15 21:11:02 +02:00
|
|
|
|
2013-12-05 13:57:32 +01:00
|
|
|
for (int i=0; i<grabCount || grabCount < 0; ++i)
|
2013-08-15 21:11:02 +02:00
|
|
|
{
|
2013-11-11 10:00:37 +01:00
|
|
|
frameGrabber.grabFrame(imageRgba);
|
2013-08-15 21:11:02 +02:00
|
|
|
|
|
|
|
for (int iScanline=0; iScanline<qImage.height(); ++iScanline)
|
|
|
|
{
|
|
|
|
unsigned char* scanLinePtr = qImage.scanLine(iScanline);
|
2013-11-11 10:00:37 +01:00
|
|
|
memcpy(scanLinePtr, imageRgba.memptr()+imageRgba.width()*iScanline, imageRgba.width()*sizeof(ColorRgba));
|
2013-08-15 21:11:02 +02:00
|
|
|
}
|
|
|
|
|
2013-11-14 09:52:10 +01:00
|
|
|
const QImage qImageSwp = qImage.rgbSwapped();
|
2013-12-05 13:57:32 +01:00
|
|
|
qImageSwp.save(QString("HYPERION_f0x%1_%2.png").arg(grabFlags, 8, 16, QChar('0')).arg(iFrame));
|
2013-08-15 21:11:02 +02:00
|
|
|
++iFrame;
|
|
|
|
|
2013-11-13 20:23:01 +01:00
|
|
|
timespec sleepTime;
|
|
|
|
sleepTime.tv_sec = 1;
|
|
|
|
sleepTime.tv_nsec = 0;
|
|
|
|
nanosleep(&sleepTime, NULL);
|
2013-08-15 21:11:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-12-05 13:57:32 +01:00
|
|
|
|