Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.10 KB | None | 0 0
  1. [vince@dozer harbour-advanced-camera]$ git diff
  2. diff --git a/harbour-advanced-camera.pro b/harbour-advanced-camera.pro
  3. index 536a25a..337222a 100644
  4. --- a/harbour-advanced-camera.pro
  5. +++ b/harbour-advanced-camera.pro
  6. @@ -25,7 +25,8 @@ SOURCES += src/harbour-advanced-camera.cpp \
  7. src/focusmodel.cpp \
  8. src/flashmodel.cpp \
  9. src/fsoperations.cpp \
  10. - src/resourcehandler.cpp
  11. + src/resourcehandler.cpp \
  12. + src/framegrabber.cpp
  13.  
  14. DISTFILES += rpm/harbour-advanced-camera.changes.in \
  15. rpm/harbour-advanced-camera.changes.run.in \
  16. @@ -70,6 +71,7 @@ HEADERS += \
  17. src/focusmodel.h \
  18. src/flashmodel.h \
  19. src/fsoperations.h \
  20. - src/resourcehandler.h
  21. + src/resourcehandler.h \
  22. + src/framegrabber.h
  23.  
  24. LIBS += -ldl
  25. diff --git a/qml/pages/VideoPlayer.qml b/qml/pages/VideoPlayer.qml
  26. index 9685679..10153d7 100644
  27. --- a/qml/pages/VideoPlayer.qml
  28. +++ b/qml/pages/VideoPlayer.qml
  29. @@ -36,12 +36,33 @@ Page {
  30. }
  31. }
  32.  
  33. + FrameGrabber {
  34. + id: frameGrabber
  35. +
  36. + active: false
  37. +
  38. + onActiveChanged: {
  39. + console.log("FrameGrabber: onActiveChanged:", active);
  40. + }
  41. +
  42. + onFinished: {
  43. + console.log("FrameGrabber: finished!");
  44. + active = false;
  45. + animFlash.start();
  46. + var path = fsOperations.writableLocation("image") + "/AdvancedCam/PIC_" + Qt.formatDateTime(new Date(), "yyyyMMdd_hhmmss") + ".jpg"
  47. + result.saveToFile(path);
  48. + console.log("Snapshot taken:", path);
  49. + fileList.append({ filePath: path, isVideo: false });
  50. + }
  51. + }
  52. +
  53. VideoOutput {
  54. id: video
  55.  
  56. anchors.fill: parent
  57. source: player
  58. fillMode: VideoOutput.PreserveAspectFit
  59. + filters: [ frameGrabber ]
  60.  
  61. MouseArea {
  62. anchors.fill: parent
  63. @@ -51,6 +72,14 @@ Page {
  64. }
  65. }
  66.  
  67. + Rectangle {
  68. + id: rectFlash
  69. + anchors.fill: parent
  70. + opacity: 0
  71. +
  72. + NumberAnimation on opacity {id:animFlash; from: 1.0; to: 0.0; duration: 200 }
  73. + }
  74. +
  75. Item {
  76. id: itemsControls
  77. anchors.fill: parent
  78. @@ -113,24 +142,11 @@ Page {
  79. }
  80.  
  81. onClicked: {
  82. - video.grabToImage(function (image) {
  83. - animFlash.start();
  84. - var path = fsOperations.writableLocation("image") + "/AdvancedCam/PIC_" + Qt.formatDateTime(new Date(), "yyyyMMdd_hhmmss") + ".jpg"
  85. - image.saveToFile(path);
  86. - console.log("Snapshot taken:", path);
  87. - fileList.append({ filePath: path, isVideo: false });
  88. - });
  89. + console.log("Snapshot button clicked!");
  90. + frameGrabber.active = true;
  91. }
  92. }
  93.  
  94. - Rectangle {
  95. - id: rectFlash
  96. - anchors.fill: parent
  97. - opacity: 0
  98. -
  99. - NumberAnimation on opacity {id:animFlash; from: 1.0; to: 0.0; duration: 200 }
  100. - }
  101. -
  102. Row {
  103. id: rowBottomVideo
  104.  
  105. diff --git a/src/framegrabber.cpp b/src/framegrabber.cpp
  106. index adf8081..f20ac03 100644
  107. --- a/src/framegrabber.cpp
  108. +++ b/src/framegrabber.cpp
  109. @@ -1,6 +1,38 @@
  110. #include "framegrabber.h"
  111. +#include <QDebug>
  112. +#include <QImage>
  113.  
  114. -FrameGrabber::FrameGrabber()
  115. +FrameGrabberRunnable::FrameGrabberRunnable(FrameGrabber *filter) :
  116. + m_filter(filter)
  117. {
  118. + qDebug() << "FrameGrabber constructor !";
  119. +}
  120. +
  121. +QVideoFilterRunnable *FrameGrabber::createFilterRunnable()
  122. +{
  123. + qDebug() << "FrameGrabber::createFilterRunnable() !!!";
  124. + return new FrameGrabberRunnable(this);
  125. +}
  126. +
  127. +QVideoFrame FrameGrabberRunnable::run(QVideoFrame *input, const QVideoSurfaceFormat &surface, RunFlags flags)
  128. +{
  129. + Q_UNUSED(surface);
  130. + Q_UNUSED(flags);
  131. +
  132. + qDebug() << "FrameGrabberRunnable::run() !!!";
  133. + if (!input->isValid() ||
  134. + (input->handleType() != QAbstractVideoBuffer::NoHandle && input->handleType() != QAbstractVideoBuffer::GLTextureHandle))
  135. + {
  136. + qWarning("Invalid input format");
  137. + return QVideoFrame();
  138. + }
  139.  
  140. + QImage img;
  141. + QImage::Format format = QVideoFrame::imageFormatFromPixelFormat(input->pixelFormat());
  142. + if (format != QImage::Format_Invalid)
  143. + img = QImage(input->bits(), input->width(), input->height(), format);
  144. + else
  145. + img = QImage::fromData(input->bits(), input->mappedBytes());
  146. + emit m_filter->finished(new QImage(img));
  147. + return *input;
  148. }
  149. diff --git a/src/framegrabber.h b/src/framegrabber.h
  150. index 95399d3..044d9ee 100644
  151. --- a/src/framegrabber.h
  152. +++ b/src/framegrabber.h
  153. @@ -1,11 +1,29 @@
  154. #ifndef FRAMEGRABBER_H
  155. #define FRAMEGRABBER_H
  156.  
  157. +#include <QAbstractVideoFilter>
  158.  
  159. -class FrameGrabber
  160. +class FrameGrabber : public QAbstractVideoFilter
  161. {
  162. + Q_OBJECT
  163. public:
  164. - FrameGrabber();
  165. + QVideoFilterRunnable *createFilterRunnable() Q_DECL_OVERRIDE ;
  166. +
  167. +signals:
  168. + void finished(QImage *result);
  169. +
  170. +private:
  171. + friend class FrameGrabberRunnable;
  172. +};
  173. +
  174. +class FrameGrabberRunnable : public QVideoFilterRunnable
  175. +{
  176. +public:
  177. + FrameGrabberRunnable(FrameGrabber *filter);
  178. + QVideoFrame run(QVideoFrame *input, const QVideoSurfaceFormat &surfaceFormat, RunFlags flags) Q_DECL_OVERRIDE ;
  179. +
  180. +private:
  181. + FrameGrabber *m_filter;
  182. };
  183.  
  184. -#endif // FRAMEGRABBER_H
  185. \ No newline at end of file
  186. +#endif // FRAMEGRABBER_H
  187. diff --git a/src/harbour-advanced-camera.cpp b/src/harbour-advanced-camera.cpp
  188. index d2b675a..0e52b33 100644
  189. --- a/src/harbour-advanced-camera.cpp
  190. +++ b/src/harbour-advanced-camera.cpp
  191. @@ -17,6 +17,7 @@
  192. #include "flashmodel.h"
  193. #include "fsoperations.h"
  194. #include "resourcehandler.h"
  195. +#include "framegrabber.h"
  196.  
  197. int main(int argc, char *argv[])
  198. {
  199. @@ -40,6 +41,7 @@ int main(int argc, char *argv[])
  200. qmlRegisterType<FocusModel>("uk.co.piggz.harbour_advanced_camera", 1, 0, "FocusModel");
  201. qmlRegisterType<FlashModel>("uk.co.piggz.harbour_advanced_camera", 1, 0, "FlashModel");
  202. qmlRegisterType<FSOperations>("uk.co.piggz.harbour_advanced_camera", 1, 0, "FSOperations");
  203. + qmlRegisterType<FrameGrabber>("uk.co.piggz.harbour_advanced_camera", 1, 0, "FrameGrabber");
  204.  
  205. ResolutionModel resolutionModel;
  206. QSortFilterProxyModel sortedResolutionModel;
  207. diff --git a/translations/harbour-advanced-camera-fr.ts b/translations/harbour-advanced-camera-fr.ts
  208. index a8ca50e..ce9332b 100644
  209. --- a/translations/harbour-advanced-camera-fr.ts
  210. +++ b/translations/harbour-advanced-camera-fr.ts
  211. @@ -296,7 +296,7 @@
  212. <context>
  213. <name>GalleryUI</name>
  214. <message>
  215. - <location filename="../qml/pages/GalleryUI.qml" line="79"/>
  216. + <location filename="../qml/pages/GalleryUI.qml" line="80"/>
  217. <source>Deleting %1</source>
  218. <translation type="unfinished"></translation>
  219. </message>
  220. [vince@dozer harbour-advanced-camera]$
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement