Updated dispmanx2png with commandline parameters for the flags.

Former-commit-id: 80534875d36162a72c4b5dfd443350ad2e65df6e
This commit is contained in:
T. van der Zwan 2013-11-13 19:23:01 +00:00
parent 2bc84d63bf
commit d0429387ee
2 changed files with 87 additions and 5 deletions

View File

@ -4,7 +4,7 @@ find_package(BCM REQUIRED)
include_directories(${BCM_INCLUDE_DIRS})
# Configure the use of QT4
find_package(Qt4 COMPONENTS QtTest REQUIRED QUIET)
#find_package(Qt4 COMPONENTS QtTest REQUIRED QUIET)
include(${QT_USE_FILE})
add_definitions(${QT_DEFINITIONS})
link_directories(${CMAKE_FIND_ROOT_PATH}/lib/arm-linux-gnueabihf)
@ -15,4 +15,5 @@ add_executable(dispmanx2png
target_link_libraries(dispmanx2png
dispmanx-grabber
getoptPlusPlus
${QT_LIBRARIES})

View File

@ -1,14 +1,19 @@
// STL includes
#include <csignal>
#include <iomanip>
// QT includes
#include <QImage>
#include <QTest>
// getoptPlusPLus includes
#include <getoptPlusPlus/getoptpp.h>
// Dispmanx grabber includes
#include <dispmanx-grabber/DispmanxFrameGrabber.h>
using namespace vlofgren;
static bool running = true;
void signal_handler(int signum)
@ -16,13 +21,86 @@ void signal_handler(int signum)
running = false;
}
int main()
int main(int argc, char** argv)
{
signal(SIGTERM, signal_handler);
signal(SIGINT, signal_handler);
int grabFlags = 0;
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'));
StringParameter & argFlags = parameters.add<StringParameter> ('f', "flags", flagDescr.toAscii().constData());
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;
}
}
}
catch (const std::runtime_error & e)
{
// An error occured. Display error and quit
std::cerr << e.what() << std::endl;
return 1;
}
DispmanxFrameGrabber frameGrabber(64, 64);
frameGrabber.setFlags(DISPMANX_SNAPSHOT_NO_RGB|DISPMANX_SNAPSHOT_FILL);
frameGrabber.setFlags(grabFlags);
unsigned iFrame = 0;
QImage qImage(64, 64, QImage::Format_ARGB32);
@ -41,7 +119,10 @@ int main()
qImage.save(QString("HYPERION_%3.png").arg(iFrame));
++iFrame;
QTest::qSleep(1000);
timespec sleepTime;
sleepTime.tv_sec = 1;
sleepTime.tv_nsec = 0;
nanosleep(&sleepTime, NULL);
}
return 0;