forked from JainiShah/WClust_src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
VideoDlg.cpp
164 lines (133 loc) · 4.11 KB
/
VideoDlg.cpp
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
// $Id: VideoDlg.cpp,v 1.1 2008/03/29 03:12:37 samn Exp $
// VideoDlg.cpp : implementation file
//
#include "stdafx.h"
#include "WClust.h"
#include "VideoDlg.h"
#include "Log.h"
const int IDT_VID_FRAME = 164;
// VideoDlg dialog
IMPLEMENT_DYNAMIC(VideoDlg, CDialog)
VideoDlg::VideoDlg(CWnd* pParent /*=NULL*/)
: cdxCSizingDialog(VideoDlg::IDD, pParent)
{
m_hdd=DrawDibOpen();
}
VideoDlg::~VideoDlg()
{
m_oAVIReader.Close();
DrawDibClose(m_hdd);
}
void VideoDlg::DoDataExchange(CDataExchange* pDX)
{
cdxCSizingDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(VideoDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(VideoDlg, cdxCSizingDialog)
//{{AFX_MSG_MAP(VideoDlg)
ON_BN_CLICKED(IDC_BUTTON_PICK_VID, OnBnClickedButtonPickVid)
ON_WM_PAINT()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL VideoDlg::OnInitDialog()
{
return TRUE;
}
bool SaveBMP(BITMAPINFOHEADER* pBMP, char* fname)
{
BITMAPFILEHEADER bfh;
bfh.bfType=19778; //BM header
//bfh.bfSize=55 + pBMP->biSizeImage;
bfh.bfSize=sizeof(BITMAPINFOHEADER) + sizeof(BITMAPFILEHEADER) + pBMP->biSizeImage;
bfh.bfReserved1=0;
bfh.bfReserved2=0;
bfh.bfOffBits=sizeof(BITMAPINFOHEADER) + sizeof(BITMAPFILEHEADER); //54
FILE* fp=fopen(fname, "wb");
if (fp!=NULL)
{
fwrite(&bfh, sizeof(bfh), 1, fp);
fwrite(pBMP, sizeof(BITMAPINFOHEADER), 1, fp);
byte* bits = (byte*)pBMP+pBMP->biSize+pBMP->biClrUsed*sizeof(RGBQUAD);
fwrite(bits, pBMP->biSizeImage, 1, fp);
fclose(fp);
}
else
{
Write2Log("Error writing the bitmap file");
return false;
}
return true;
}
void VideoDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
/*
CRect rect;
GetClientRect(&rect);
CFont font;
int nHeight = -((dc.GetDeviceCaps (LOGPIXELSY) * 20) / 72);
font.CreateFont (nHeight, 0, 0, 0, FW_BOLD, TRUE, 0, 0,
DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, "Times New Roman");
//dc.SetBkMode (TRANSPARENT);
dc.SetBkColor(RGB(255,0,255));
dc.SetTextColor (RGB (255, 255, 255));
CFont* pOldFont = dc.SelectObject (&font);
dc.DrawText ("Hello, MFC", -1, &rect, DT_SINGLELINE | DT_CENTER |
DT_VCENTER);
dc.SelectObject (pOldFont);*/
Write2Log("Up to frame %d",m_oAVIReader.CurrentFrame());
LPBITMAPINFOHEADER pBMP = m_oAVIReader.GetCurrentFrame();
if(!pBMP)
return;
SaveBMP(pBMP,"test.bmp");
byte* pdata=(byte*)pBMP+pBMP->biSize+pBMP->biClrUsed*sizeof(RGBQUAD);
// Convert Data To Requested Bitmap Format & Draw IT!!!
DrawDibDraw(m_hdd, dc.GetSafeHdc(), 32, 32, pBMP->biWidth, pBMP->biHeight, pBMP, pdata, 0, 0, m_oAVIReader.Width(), m_oAVIReader.Height(), 0);
}
void VideoDlg::OnShowWindow(BOOL bShow, UINT nStatus)
{
cdxCSizingDialog::OnShowWindow(bShow, nStatus);
}
// VideoDlg message handlers
void VideoDlg::OnBnClickedButtonPickVid()
{
m_oAVIReader.Close(); //close before re-opening
static char BASED_CODE szFilter[] = "AVI video files (*.avi)|*.avi|All Files (*.*)|*.*||";
CFileDialog dlg(TRUE, "avi", "*.avi", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter);
if(dlg.DoModal()!=IDOK)
return;
CString cstrAVIPath=dlg.GetPathName();
CString strMsg;
if(!m_oAVIReader.Open(cstrAVIPath))
{ strMsg.Format("Couldn't open %s",cstrAVIPath);
MessageBox(strMsg);
}
else
{
strMsg.Format("Opened %s w=%d h=%d firstf=%d lastf=%d",
cstrAVIPath,
m_oAVIReader.Width(),
m_oAVIReader.Height(),
m_oAVIReader.FirstFrame(),
m_oAVIReader.LastFrame());
MessageBox(strMsg);
}
m_oAVIReader.GoToFrame(m_oAVIReader.FirstFrame());
if(!SetTimer(IDT_VID_FRAME,10,NULL))
{
Write2Log("Couldn't start timer!");
}
InvalidateRect(NULL,FALSE);
}
void VideoDlg::OnTimer(UINT nIDEvent)
{
InvalidateRect(NULL,FALSE);
if(m_oAVIReader.CurrentFrame()+1<m_oAVIReader.LastFrame())
m_oAVIReader.GoToFrame(m_oAVIReader.CurrentFrame()+1);
else
m_oAVIReader.GoToFrame(m_oAVIReader.FirstFrame());
cdxCSizingDialog::OnTimer(nIDEvent);
}