-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvideoDialog.cpp
412 lines (356 loc) · 11.9 KB
/
videoDialog.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
/*
Copyright (c) 2001-2006 Chris Lundie
http://lundie.ca/
This file is part of Fwink.
Fwink is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Fwink is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fwink; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "WebCam.h"
// Video dialog callback
//
INT_PTR CALLBACK
WebCam::DialogProcVideo(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
WebCam* cam = reinterpret_cast<WebCam*>(GetWindowLongPtr(hwndDlg, GWLP_USERDATA));
switch(uMsg)
{
case WM_NOTIFY:
{
LPNMHDR pNmhdr = reinterpret_cast<LPNMHDR>(lParam);
if (pNmhdr->code == PSN_APPLY)
{
BOOL bGotInt = FALSE;
unsigned uValue = GetDlgItemInt(hwndDlg, IDC_CUSTOMSIZEX, &bGotInt, FALSE);
if (bGotInt) cam->uCustomSizeX = uValue;
uValue = GetDlgItemInt(hwndDlg, IDC_CUSTOMSIZEY, &bGotInt, FALSE);
if (bGotInt) cam->uCustomSizeY = uValue;
if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_RADIOSTDSIZE))
cam->bCustomImageSize = false;
else
cam->bCustomImageSize = true;
uValue = GetDlgItemInt(hwndDlg, IDC_CROP_X, &bGotInt, FALSE);
if (bGotInt) cam->uCropX = uValue;
uValue = GetDlgItemInt(hwndDlg, IDC_CROP_Y, &bGotInt, FALSE);
if (bGotInt) cam->uCropY = uValue;
uValue = GetDlgItemInt(hwndDlg, IDC_CROP_WIDTH, &bGotInt, FALSE);
if (bGotInt) cam->uCropWidth = uValue;
uValue = GetDlgItemInt(hwndDlg, IDC_CROP_HEIGHT, &bGotInt, FALSE);
if (bGotInt) cam->uCropHeight = uValue;
if (BST_CHECKED == IsDlgButtonChecked(hwndDlg, IDC_CROP_ENABLE))
cam->bCrop = true;
else
cam->bCrop = false;
cam->uImageSize = SendDlgItemMessage(hwndDlg, IDC_IMAGESIZE, CB_GETCURSEL, 0, 0);
cam->uImageSize = max(min(cam->uImageSize, uMaxImageSize), uMinImageSize);
SendDlgItemMessage(hwndDlg, IDC_IMAGESIZE, CB_SETCURSEL, cam->uImageSize, 0);
cam->uJPEGQuality = SendDlgItemMessage(hwndDlg, IDC_JPEGQUALITY,
TBM_GETPOS, 0, 0);
cam->bFlipHorizontal = (IsDlgButtonChecked(hwndDlg, IDC_FLIPHORIZONTAL) == BST_CHECKED);
cam->bFlipVertical = (IsDlgButtonChecked(hwndDlg, IDC_FLIPVERTICAL) == BST_CHECKED);
if (cam->uDeviceType == deviceType_camera)
{
long lIndex = SendDlgItemMessage(hwndDlg, IDC_VIDEOSOURCE,
CB_GETCURSEL, 0, 0);
if (CB_ERR != lIndex)
{
long lSource = SendDlgItemMessage(hwndDlg, IDC_VIDEOSOURCE,
CB_GETITEMDATA, lIndex, 0);
if (CB_ERR != lSource)
{
cam->uCrossbarInput = lSource;
IPin* pinVidcapIn = cam->GetPin(cam->pVidcap, PINDIR_INPUT, PIN_CATEGORY_ANALOGVIDEOIN);
if (pinVidcapIn)
{
HRESULT hr;
CCrossbar* pCCrossbar = new CCrossbar(pinVidcapIn, &hr);
if (pCCrossbar)
{
pCCrossbar->SetInputIndex(lSource);
delete pCCrossbar;
}
pinVidcapIn->Release();
}
}
}
}
cam->GetCaptureSize();
cam->SaveVideoSettings();
cam->ApplyImageSize();
cam->CropPreview();
PropSheet_CancelToClose(GetParent(hwndDlg));
}
break;
}
case WM_HSCROLL:
{
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
break;
}
// Command message from dialog box
//
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case IDC_CUSTOMSIZEX:
case IDC_CUSTOMSIZEY:
case IDC_CROP_X:
case IDC_CROP_Y:
case IDC_CROP_WIDTH:
case IDC_CROP_HEIGHT:
{
if (HIWORD(wParam) == EN_CHANGE)
{
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
}
break;
}
case IDC_CROP_ENABLE:
{
if (HIWORD(wParam) == BN_CLICKED)
{
BOOL bCrop = (IsDlgButtonChecked(hwndDlg, IDC_CROP_ENABLE) == BST_CHECKED) ? TRUE : FALSE;
EnableWindow(GetDlgItem(hwndDlg, IDC_CROP_X), bCrop ? TRUE : FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_CROP_Y), bCrop ? TRUE : FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_CROP_WIDTH), bCrop ? TRUE : FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_CROP_HEIGHT), bCrop ? TRUE : FALSE);
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
}
break;
}
case IDC_RADIOSTDSIZE:
{
if (HIWORD(wParam) == BN_CLICKED)
{
EnableWindow(GetDlgItem(hwndDlg, IDC_IMAGESIZE), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOMSIZEX), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOMSIZEY), FALSE);
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
}
break;
}
case IDC_RADIOCUSTOMSIZE:
{
if (HIWORD(wParam) == BN_CLICKED)
{
EnableWindow(GetDlgItem(hwndDlg, IDC_IMAGESIZE), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOMSIZEX), TRUE);
EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOMSIZEY), TRUE);
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
}
break;
}
case IDC_VIDEOSOURCE:
case IDC_IMAGESIZE:
{
if (HIWORD(wParam) == CBN_SELCHANGE)
{
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
}
break;
}
case IDC_FLIPHORIZONTAL:
case IDC_FLIPVERTICAL:
{
if (HIWORD(wParam) == BN_CLICKED)
{
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
}
break;
}
case IDC_BTNTVTUNER:
{
cam->TVTunerProperties(hwndDlg, true);
break;
}
case IDC_BTNVIDCAPPROPERTIES:
{
if (cam->uDeviceType == deviceType_camera)
{
cam->ChangeVidcapProperties(hwndDlg, true);
}
break;
}
case IDC_BTNVIDEOFORMAT:
{
if (cam->uDeviceType == deviceType_camera)
{
cam->StopTimer();
cam->StopCapture();
cam->ChangeVideoFormat(hwndDlg, true);
cam->StartCapture();
cam->StartTimer();
PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
PropSheet_CancelToClose(GetParent(hwndDlg));
}
break;
}
case IDC_BTN_CHANGE_VIDEO_DEVICE:
{
cam->ShowChooseVideoDeviceDialog(hwndDlg);
break;
}
}
break;
}
// Initialize dialog
//
case WM_INITDIALOG:
{
PROPSHEETPAGE* psp = reinterpret_cast<PROPSHEETPAGE*>(lParam);
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, psp->lParam);
WebCam* cam = reinterpret_cast<WebCam*>(psp->lParam);
// Initialize JPEG quality trackbar
//
SendDlgItemMessage(hwndDlg, IDC_JPEGQUALITY, TBM_SETRANGE,
FALSE, (LPARAM) MAKELONG (0, 100));
SendDlgItemMessage(hwndDlg, IDC_JPEGQUALITY, TBM_SETTICFREQ,
25, 0);
SendDlgItemMessage(hwndDlg, IDC_JPEGQUALITY, TBM_SETPOS,
TRUE, cam->uJPEGQuality);
// Add options to image size combo box
//
TCHAR buffer[256];
LoadString(GetModuleHandle(NULL), IDS_IMAGESIZESMALL, buffer, 256);
SendDlgItemMessage(hwndDlg, IDC_IMAGESIZE, CB_ADDSTRING, 0,
reinterpret_cast<LPARAM>(buffer));
LoadString(GetModuleHandle(NULL), IDS_IMAGESIZEMEDIUM, buffer, 256);
SendDlgItemMessage(hwndDlg, IDC_IMAGESIZE, CB_ADDSTRING, 0,
reinterpret_cast<LPARAM>(buffer));
LoadString(GetModuleHandle(NULL), IDS_IMAGESIZELARGE, buffer, 256);
SendDlgItemMessage(hwndDlg, IDC_IMAGESIZE, CB_ADDSTRING, 0,
reinterpret_cast<LPARAM>(buffer));
LoadString(GetModuleHandle(NULL), IDS_IMAGESIZEXLARGE, buffer, 256);
SendDlgItemMessage(hwndDlg, IDC_IMAGESIZE, CB_ADDSTRING, 0,
reinterpret_cast<LPARAM>(buffer));
// Set image size
SendDlgItemMessage(hwndDlg, IDC_IMAGESIZE, CB_SETCURSEL, cam->uImageSize, 0);
SetDlgItemInt(hwndDlg, IDC_CUSTOMSIZEX, cam->uCustomSizeX, FALSE);
SetDlgItemInt(hwndDlg, IDC_CUSTOMSIZEY, cam->uCustomSizeY, FALSE);
if(cam->bCustomImageSize)
{
CheckDlgButton(hwndDlg, IDC_RADIOCUSTOMSIZE, BST_CHECKED);
EnableWindow(GetDlgItem(hwndDlg, IDC_IMAGESIZE), FALSE);
}
else
{
CheckDlgButton(hwndDlg, IDC_RADIOSTDSIZE, BST_CHECKED);
EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOMSIZEX), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_CUSTOMSIZEY), FALSE);
}
// Set crop settings
SetDlgItemInt(hwndDlg, IDC_CROP_X, cam->uCropX, FALSE);
SetDlgItemInt(hwndDlg, IDC_CROP_Y, cam->uCropY, FALSE);
SetDlgItemInt(hwndDlg, IDC_CROP_WIDTH, cam->uCropWidth, FALSE);
SetDlgItemInt(hwndDlg, IDC_CROP_HEIGHT, cam->uCropHeight, FALSE);
CheckDlgButton(hwndDlg, IDC_CROP_ENABLE, cam->bCrop ? BST_CHECKED : BST_UNCHECKED);
EnableWindow(GetDlgItem(hwndDlg, IDC_CROP_X), cam->bCrop ? TRUE : FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_CROP_Y), cam->bCrop ? TRUE : FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_CROP_WIDTH), cam->bCrop ? TRUE : FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_CROP_HEIGHT), cam->bCrop ? TRUE : FALSE);
// Load settings into dialog
CheckDlgButton(hwndDlg, IDC_FLIPHORIZONTAL, cam->bFlipHorizontal ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_FLIPVERTICAL, cam->bFlipVertical ? BST_CHECKED : BST_UNCHECKED);
// set up crossbar
if (cam->uDeviceType == deviceType_camera)
{
EnableWindow(GetDlgItem(hwndDlg, IDC_VIDEOSOURCE), FALSE);
HRESULT hr;
IPin* pinVidcapIn = cam->GetPin(cam->pVidcap, PINDIR_INPUT, PIN_CATEGORY_ANALOGVIDEOIN);
if (pinVidcapIn)
{
HRESULT hrCrossbar;
CCrossbar* pCCrossbar = new CCrossbar(pinVidcapIn, &hrCrossbar);
if (pCCrossbar)
{
LONG lCount = 0;
hr = pCCrossbar->GetInputCount(&lCount);
for (LONG l=0; l<lCount; ++l)
{
LONG lType;
hr = pCCrossbar->GetInputType(l, &lType);
if (SUCCEEDED(hr))
{
TCHAR buffer[256];
hr = pCCrossbar->GetInputName(l, buffer, 256);
if (SUCCEEDED(hr))
{
long lIndex = SendDlgItemMessage(hwndDlg, IDC_VIDEOSOURCE,
CB_ADDSTRING,
0, (LPARAM)buffer);
if (CB_ERR != lIndex)
{
EnableWindow(GetDlgItem(hwndDlg, IDC_VIDEOSOURCE), TRUE);
SendDlgItemMessage(hwndDlg, IDC_VIDEOSOURCE,
CB_SETITEMDATA,
lIndex,
(LPARAM)l);
if (l == cam->uCrossbarInput)
{
SendDlgItemMessage(hwndDlg, IDC_VIDEOSOURCE,
CB_SETCURSEL, lIndex, 0);
SendDlgItemMessage(hwndDlg, IDC_VIDEOSOURCE,
CB_SETTOPINDEX, lIndex, 0);
}
}
}
if (l == cam->uCrossbarInput)
{
pCCrossbar->SetInputIndex(l);
//break;
}
}
}
delete pCCrossbar;
}
pinVidcapIn->Release();
}
// Check if there is a TV tuner
//
if (cam->pBuilder)
{
IAMTVTuner* pTuner = NULL;
hr = cam->pBuilder->FindInterface(
&LOOK_UPSTREAM_ONLY,
NULL,
cam->pVidcap,
IID_IAMTVTuner,
(void**)&pTuner);
if (FAILED(hr))
{
EnableWindow(GetDlgItem(hwndDlg, IDC_BTNTVTUNER), FALSE);
}
else
{
EnableWindow(GetDlgItem(hwndDlg, IDC_BTNTVTUNER), TRUE);
pTuner->Release();
}
}
}
else
{
EnableWindow(GetDlgItem(hwndDlg, IDC_VIDEOSOURCE), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_BTNTVTUNER), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_BTNVIDCAPPROPERTIES), FALSE);
EnableWindow(GetDlgItem(hwndDlg, IDC_BTNVIDEOFORMAT), FALSE);
}
// Set video device name
SetDlgItemText(hwndDlg, IDC_VIDEO_DEVICE_NAME, cam->sDeviceName.c_str());
break;
}
default:
{
return FALSE;
}
}
return TRUE;
}