• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #pragma once
2 
3 #include "pch.h"
4 #include "BasicTimer.h"
5 #include "CubeRenderer.h"
6 #include <DrawingSurfaceNative.h>
7 #include <ppltasks.h>
8 #include <windows.storage.streams.h>
9 #include <opencv2\core\core.hpp>
10 #include <opencv2\imgproc\imgproc.hpp>
11 #include <opencv2\features2d\features2d.hpp>
12 
13 namespace PhoneXamlDirect3DApp1Comp
14 {
15 
16 public enum class OCVFilterType
17 {
18     ePreview,
19     eGray,
20     eCanny,
21     eSepia,
22     eNumOCVFilterTypes
23 };
24 
25 public delegate void RequestAdditionalFrameHandler();
26 public delegate void RecreateSynchronizedTextureHandler();
27 
28 [Windows::Foundation::Metadata::WebHostHidden]
29 public ref class Direct3DInterop sealed : public Windows::Phone::Input::Interop::IDrawingSurfaceManipulationHandler
30 {
31 public:
32     Direct3DInterop();
33 
34     Windows::Phone::Graphics::Interop::IDrawingSurfaceContentProvider^ CreateContentProvider();
35 
36     // IDrawingSurfaceManipulationHandler
37     virtual void SetManipulationHost(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ manipulationHost);
38 
39     event RequestAdditionalFrameHandler^ RequestAdditionalFrame;
40     event RecreateSynchronizedTextureHandler^ RecreateSynchronizedTexture;
41 
42     property Windows::Foundation::Size WindowBounds;
43     property Windows::Foundation::Size NativeResolution;
44     property Windows::Foundation::Size RenderResolution
45     {
get()46         Windows::Foundation::Size get(){ return m_renderResolution; }
47         void set(Windows::Foundation::Size renderResolution);
48     }
49     void CreateTexture(const Platform::Array<int>^ buffer, int with, int height, OCVFilterType filter);
50 
51 
52 protected:
53     // Event Handlers
54     void OnPointerPressed(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args);
55     void OnPointerMoved(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args);
56     void OnPointerReleased(Windows::Phone::Input::Interop::DrawingSurfaceManipulationHost^ sender, Windows::UI::Core::PointerEventArgs^ args);
57 
58 internal:
59     HRESULT STDMETHODCALLTYPE Connect(_In_ IDrawingSurfaceRuntimeHostNative* host);
60     void STDMETHODCALLTYPE Disconnect();
61     HRESULT STDMETHODCALLTYPE PrepareResources(_In_ const LARGE_INTEGER* presentTargetTime, _Out_ BOOL* contentDirty);
62     HRESULT STDMETHODCALLTYPE GetTexture(_In_ const DrawingSurfaceSizeF* size, _Out_ IDrawingSurfaceSynchronizedTextureNative** synchronizedTexture, _Out_ DrawingSurfaceRectF* textureSubRectangle);
63     ID3D11Texture2D* GetTexture();
64 
65 private:
66     CubeRenderer^ m_renderer;
67     BasicTimer^ m_timer;
68     Windows::Foundation::Size m_renderResolution;
69 
70     void ApplyGrayFilter(const cv::Mat& image);
71     void ApplyCannyFilter(const cv::Mat& image);
72     void ApplySepiaFilter(const cv::Mat& image);
73 
74     void UpdateImage(const cv::Mat& image);
75 
76     cv::Mat Lena;
77     unsigned int frameWidth, frameHeight;
78 };
79 
80 }
81