|
| 1 | +//############################################################################# |
| 2 | +// |
| 3 | +// This file is part of ImagePlay. |
| 4 | +// |
| 5 | +// ImagePlay is free software: you can redistribute it and/or modify |
| 6 | +// it under the terms of the GNU General Public License as published by |
| 7 | +// the Free Software Foundation, either version 3 of the License, or |
| 8 | +// (at your option) any later version. |
| 9 | +// |
| 10 | +// ImagePlay is distributed in the hope that it will be useful, |
| 11 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | +// GNU General Public License for more details. |
| 14 | +// |
| 15 | +// You should have received a copy of the GNU General Public License |
| 16 | +// along with ImagePlay. If not, see <http://www.gnu.org/licenses/>. |
| 17 | +// |
| 18 | +//############################################################################# |
| 19 | + |
| 20 | +#include "IPLScreenshot.h" |
| 21 | + |
| 22 | +void IPLScreenshot::init() |
| 23 | +{ |
| 24 | + // init |
| 25 | + _result = NULL; |
| 26 | + _winId = 0; |
| 27 | + |
| 28 | + // basic settings |
| 29 | + setClassName("IPLScreenshot"); |
| 30 | + setTitle("Load from another running window/desktop"); |
| 31 | + setCategory(IPLProcess::CATEGORY_IO); |
| 32 | + setIsSource(true); |
| 33 | + |
| 34 | + // inputs and outputs |
| 35 | + addOutput("Image", IPL_IMAGE_COLOR); |
| 36 | + |
| 37 | + addProcessPropertyUnsignedInt("trigger", "Trigger Image", "", 0, IPL_WIDGET_BUTTON); |
| 38 | + addProcessPropertyBool("continuous", "Run continuously", "", false, IPL_WIDGET_CHECKBOXES); |
| 39 | + // addProcessPropertyInt("wid", "Window Selector", "", ...); |
| 40 | +} |
| 41 | + |
| 42 | +void IPLScreenshot::destroy() |
| 43 | +{ |
| 44 | + delete _result; |
| 45 | +} |
| 46 | + |
| 47 | +bool IPLScreenshot::processInputData(IPLData*, int, bool) |
| 48 | +{ |
| 49 | + // delete previous result |
| 50 | + delete _result; |
| 51 | + _result = NULL; |
| 52 | + _continuous = getProcessPropertyBool("continuous"); |
| 53 | + |
| 54 | + notifyProgressEventHandler(-1); |
| 55 | + |
| 56 | + // if (const QWindow *window = windowHandle()) |
| 57 | + // screen = window->screen(); |
| 58 | + QScreen *screen = QGuiApplication::primaryScreen(); |
| 59 | + // QDesktopWidget* dw = QApplication::desktop(); |
| 60 | + if (!screen) |
| 61 | + return NULL; |
| 62 | + _pixmap = screen->grabWindow(0); |
| 63 | + |
| 64 | + _qimage = _pixmap.toImage(); |
| 65 | + _mat = cv::Mat(_qimage.height(), _qimage.width(), CV_8UC4, (uchar*)_qimage.bits(), _qimage.bytesPerLine()); |
| 66 | + _result = new IPLImage(_mat); |
| 67 | + |
| 68 | + if(!_result) |
| 69 | + { |
| 70 | + addError("Could not fetch screenshot."); |
| 71 | + return false; |
| 72 | + } |
| 73 | + |
| 74 | + /* |
| 75 | + std::stringstream s; |
| 76 | + s << "Foo "; |
| 77 | + addInformation(s.str()); |
| 78 | + */ |
| 79 | + |
| 80 | + return true; |
| 81 | +} |
| 82 | + |
| 83 | +IPLImage *IPLScreenshot::getResultData(int) |
| 84 | +{ |
| 85 | + return _result; |
| 86 | +} |
| 87 | + |
| 88 | +void IPLScreenshot::afterProcessing() |
| 89 | +{ |
| 90 | + if(_continuous) |
| 91 | + { |
| 92 | + notifyPropertyChangedEventHandler(); |
| 93 | + } |
| 94 | +} |
0 commit comments