|
| 1 | + |
| 2 | + |
| 3 | +// QT includes |
| 4 | +#include <QCoreApplication> |
| 5 | +#include <QImage> |
| 6 | + |
| 7 | +// getoptPlusPLus includes |
| 8 | +#include <getoptPlusPlus/getoptpp.h> |
| 9 | + |
| 10 | +#include "../../libsrc/grabber/amlogic/AmlogicGrabber.h" |
| 11 | + |
| 12 | +using namespace vlofgren; |
| 13 | + |
| 14 | +// save the image as screenshot |
| 15 | +void saveScreenshot(const char * filename, const Image<ColorRgb> & image) |
| 16 | +{ |
| 17 | + // store as PNG |
| 18 | + QImage pngImage((const uint8_t *) image.memptr(), image.width(), image.height(), 3*image.width(), QImage::Format_RGB888); |
| 19 | + pngImage.save(filename); |
| 20 | +} |
| 21 | + |
| 22 | +int main(int argc, char ** argv) |
| 23 | +{ |
| 24 | + QCoreApplication app(argc, argv); |
| 25 | + |
| 26 | + try |
| 27 | + { |
| 28 | + // create the option parser and initialize all parameters |
| 29 | + OptionsParser optionParser("X11 capture application for Hyperion"); |
| 30 | + ParameterSet & parameters = optionParser.getParameters(); |
| 31 | + |
| 32 | + //IntParameter & argFps = parameters.add<IntParameter> ('f', "framerate", "Capture frame rate [default=10]"); |
| 33 | + IntParameter & argWidth = parameters.add<IntParameter> (0x0, "width", "Width of the captured image [default=128]"); |
| 34 | + IntParameter & argHeight = parameters.add<IntParameter> (0x0, "height", "Height of the captured image [default=128]"); |
| 35 | + SwitchParameter<> & argScreenshot = parameters.add<SwitchParameter<>> (0x0, "screenshot", "Take a single screenshot, save it to file and quit"); |
| 36 | + StringParameter & argAddress = parameters.add<StringParameter> ('a', "address", "Set the address of the hyperion server [default: 127.0.0.1:19445]"); |
| 37 | + IntParameter & argPriority = parameters.add<IntParameter> ('p', "priority", "Use the provided priority channel (the lower the number, the higher the priority) [default: 800]"); |
| 38 | + //SwitchParameter<> & argSkipReply = parameters.add<SwitchParameter<>> (0x0, "skip-reply", "Do not receive and check reply messages from Hyperion"); |
| 39 | + SwitchParameter<> & argHelp = parameters.add<SwitchParameter<>> ('h', "help", "Show this help message and exit"); |
| 40 | + |
| 41 | + // set defaults |
| 42 | + argWidth.setDefault(64); |
| 43 | + argHeight.setDefault(64); |
| 44 | + argAddress.setDefault("127.0.0.1:19445"); |
| 45 | + argPriority.setDefault(800); |
| 46 | + |
| 47 | + // parse all options |
| 48 | + optionParser.parse(argc, const_cast<const char **>(argv)); |
| 49 | + |
| 50 | + // check if we need to display the usage. exit if we do. |
| 51 | + if (argHelp.isSet()) |
| 52 | + { |
| 53 | + optionParser.usage(); |
| 54 | + return 0; |
| 55 | + } |
| 56 | + |
| 57 | + if (argScreenshot.isSet()) |
| 58 | + { |
| 59 | + // Create the grabber |
| 60 | + AmlogicGrabber amlGrabber(argWidth.getValue(), argHeight.getValue()); |
| 61 | + |
| 62 | + // Capture a single screenshot and finish |
| 63 | + Image<ColorRgb> screenshot; |
| 64 | + amlGrabber.grabFrame(screenshot); |
| 65 | + saveScreenshot("screenshot.png", screenshot); |
| 66 | + } |
| 67 | + else |
| 68 | + { |
| 69 | + // TODO[TvdZ]: Implement the proto-client mechanisme |
| 70 | + } |
| 71 | + |
| 72 | + } |
| 73 | + catch (const std::runtime_error & e) |
| 74 | + { |
| 75 | + // An error occured. Display error and quit |
| 76 | + std::cerr << e.what() << std::endl; |
| 77 | + return -1; |
| 78 | + } |
| 79 | + return 0; |
| 80 | +} |
0 commit comments