-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathVideoWnd.h
164 lines (138 loc) · 3.74 KB
/
VideoWnd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#if !defined(AFX_VIDEOWND_H__2D780DDC_26E5_4561_91CC_53BCF9292071__INCLUDED_)
#define AFX_VIDEOWND_H__2D780DDC_26E5_4561_91CC_53BCF9292071__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// VideoWnd.h : header file
//
#include <mutex>
typedef HANDLE HDRAWDIB;
//Video buffer class
class CVideoBuffer
{
public:
CVideoBuffer();
~CVideoBuffer();
BYTE *GetBuffer(int w = 0, int h = 0);
void ReleaseBuffer();
void CleanUpBuffer();
int stride() const { return (m_w * 3 + 3) / 4 * 4; }
int width() const { return m_w; }
int height()const { return m_h; }
protected:
void *m_buf;
int m_w;
int m_h;
std::mutex m_mutex;
};
///////////////////////////////////////////////////////////////////////////////
// Win32Window
///////////////////////////////////////////////////////////////////////////////
class Win32Window {
public:
Win32Window();
virtual ~Win32Window();
HWND handle() const { return wnd_; }
bool Create(HWND parent, const wchar_t* title, DWORD style, DWORD exstyle,
int x, int y, int cx, int cy);
void Destroy();
// Call this when your DLL unloads.
static void Shutdown();
protected:
virtual bool OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam,
LRESULT& result);
virtual bool OnClose() { return true; }
virtual void OnNcDestroy() { }
private:
static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam,
LPARAM lParam);
HWND wnd_;
static HINSTANCE instance_;
static ATOM window_class_;
};
/**
CVideoWnd window
由于CImage的Bits指向RGB数据底部,因此CImage调用方式
CImage img("videoback.jpg");
pWnd->FillBuffer((BYTE*)img.GetPixelAddress(0, img.GetHeight()-1), img.GetWidth(), img.GetHeight());
*/
class CVideoWnd : public Win32Window
{
// Construction
public:
CVideoWnd();
virtual ~CVideoWnd();
static bool SetDefaultImage(const char* path);
// implement from IVideoWnd
BYTE* GetBuffer(int w, int h);
BOOL ReleaseBuffer();
void Clear();
bool SetVisible(bool bShow);
bool GetVisible();
/*
填充RGB.
@arg pRgb 原始RGB数据
@arg width 原始宽度
@arg height 原始高度
@arg orgin 旋转标记,为如下
- 0 不旋转
- 1 90度
- 2 180度
- 3 270度
@return BOOL
@retval
*/
BOOL FillBuffer(BYTE* pRgb, int width, int height, int orgin);
BOOL FillBuffer(BYTE* pRgb, int width, int height) {
return FillBuffer(pRgb, width, height, m_nDefOrgin);
}
// 设置缺省旋转方向
void SetDefOrgin(int orgin) { m_nDefOrgin = orgin; }
// 设置窗口适应模式
void SetFitMode(BOOL bFit);
void SetBkColor(COLORREF color);
BOOL TaskSnap(LPCTSTR path);
/*
设置文本.
@arg text 内容
@arg clr 颜色
@arg mode 绘制模式
*/
void SetText(const char* text, COLORREF clr, DWORD mode = DT_BOTTOM | DT_SINGLELINE);
void Refresh();
// Attributes
public:
// Operations
public:
// Implementation
BOOL m_bShowVol;
void SetPoint(std::vector<POINT>& pts);
protected:
std::vector<POINT> points;
int m_nVol;
BOOL m_bUseGDI;
// 背景色
COLORREF m_clrBK;
// 适应窗口
BOOL m_bFit;
// 缺省旋转方向
int m_nDefOrgin;
// 文本
std::string m_szText;
// 格式 DrawText格式
DWORD m_nTextFmt;
// 文本颜色
COLORREF m_clrText;
BOOL m_bSizeChanged;
BITMAPINFO m_bmi;
HDRAWDIB m_hDrawDIB;
CVideoBuffer m_buffer;
// Generated message map functions
protected:
virtual bool OnMessage(UINT uMsg, WPARAM wParam, LPARAM lParam, LRESULT& result);
BOOL OnEraseBkgnd(HDC pDC);
};
/////////////////////////////////////////////////////////////////////////////
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_VIDEOWND_H__2D780DDC_26E5_4561_91CC_53BCF9292071__INCLUDED_)