📄 signbox.cpp
字号:
// SignBox.cpp : implementation file
//
#include "stdafx.h"
#include "OkMfc.h"
#include "SignBox.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "okapi32.h"
int videotype; //视频类型
int scanlines; //扫描线数
int fieldfrq; //场频
extern HANDLE hBoard; //图像卡句柄
int exAutoSetVideoParams(int videotype, int scanlines, int fieldfrq, int sample43 );
/////////////////////////////////////////////////////////////////////////////
// CSignBox dialog
CSignBox::CSignBox(CWnd* pParent /*=NULL*/)
: CDialog(CSignBox::IDD, pParent)
{
//{{AFX_DATA_INIT(CSignBox)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CSignBox::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSignBox)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSignBox, CDialog)
//{{AFX_MSG_MAP(CSignBox)
ON_BN_CLICKED(IDC_SETVIDEO, OnSetvideo)
ON_BN_CLICKED(IDC_REDETECT, OnRedetect)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSignBox message handlers
BOOL CSignBox::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
char str[128];
int extsign = 0;
int vidcolor = -1;
int ret;
//video exist
extsign = okGetSignalParam(hBoard, SIGNAL_VIDEOEXIST);
if (extsign == 1)
{
sprintf(str, "检测到了信号源");
}
else if (extsign == 0)
sprintf(str, "没有信号源");
else //-1
sprintf(str, "不支持");
if (extsign == 1)
{
vidcolor = okGetSignalParam(hBoard, SIGNAL_VIDEOCOLOR);
if (vidcolor == 1)
strcat(str, "(Color)");
else if (vidcolor == 0)
strcat(str, "(B/W)");
}
SetDlgItemText(IDC_VIDEOEXIST, str);
//video type
if (extsign == 1)
{
okWaitSignalEvent(hBoard, EVENT_ODDFIELD, 40);
videotype = okGetSignalParam(hBoard, SIGNAL_VIDEOTYPE);
if (videotype == 1)
sprintf(str, "隔行信号(Interlaced)");
else if (videotype == 0)
sprintf(str, "逐行信号(Non-interlaced)");
else if (videotype == -1)
sprintf(str, "不支持");
}
else
sprintf(str, "未知");
SetDlgItemText(IDC_VIDEOTYPE, str);
//video scanlines
scanlines = -1;
if (extsign == 1)
{
scanlines = okGetSignalParam(hBoard, SIGNAL_SCANLINES);
if (scanlines == -1)
sprintf(str, "不支持");
else
sprintf(str, "%d 行数/幅", scanlines);
}
else
sprintf(str, "未知");
SetDlgItemText(IDC_SCANLINES, str);
//video field frequency
if (extsign == 1)
{
fieldfrq = okGetSignalParam(hBoard, SIGNAL_FIELDFREQ);
if (fieldfrq == -1)
sprintf(str, "未知");
else
sprintf(str, "%d 场数/秒", fieldfrq);
}
else if (extsign == -1)
sprintf(str, "未知");
SetDlgItemText(IDC_FRAMEFREQ, str);
//extern trigger
ret = okGetSignalParam(hBoard, SIGNAL_EXTTRIGGER);
if (ret == -1)
sprintf(str, "不支持");
else if (ret == 1)
sprintf(str, "触发状态");
else
sprintf(str, "无触发");
SetDlgItemText(IDC_EXTTRIGGER, str);
CheckDlgButton(IDC_SAMPLERATIO43, BST_CHECKED);
if (scanlines == -1) //can not detect signal infos
{
GetDlgItem(IDC_SETVIDEO)->EnableWindow(FALSE);
GetDlgItem(IDC_SAMPLERATIO43)->EnableWindow(FALSE);
GetDlgItem(IDC_SAMPLERATIO11)->EnableWindow(FALSE);
}
else
{
GetDlgItem(IDC_SETVIDEO)->EnableWindow(TRUE);
GetDlgItem(IDC_SAMPLERATIO43)->EnableWindow(TRUE);
GetDlgItem(IDC_SAMPLERATIO11)->EnableWindow(TRUE);
}
//test out trigger
okPutSignalParam(hBoard, PUTSIGNAL_TRIGGER, 0xf);
return (TRUE);
}
void CSignBox::OnSetvideo()
{
// TODO: Add your control notification handler code here
exAutoSetVideoParams(videotype, scanlines, fieldfrq,
IsDlgButtonChecked(IDC_SAMPLERATIO43) );
EndDialog(TRUE);
}
//--demo to auto-set video and pcapture params according to input signal infos
//just be used M20, M40, M30, M60. M70
int exAutoSetVideoParams(int videotype, int scanlines, int fieldfrq, int sample43 )
{
long tvstandard;
long samppixel,sampfreq,videoshift;
RECT rect;
//1.video type, 2. sample mode as video type
okSetVideoParam(hBoard, VIDEO_SIGNALTYPE, videotype);
okSetCaptureParam(hBoard, CAPTURE_SAMPLEFIELD, videotype); //0: field 1: frame
//3.video standard 4.hp and vl, 5.frq segment
//6 vidoe shift 7, sample rect
//4:3
if ((scanlines==625) && (videotype==1)) //interlace
{
if (sample43) //4:3
{
tvstandard = 0; //PAL
okSetVideoParam(hBoard, VIDEO_TVSTANDARD, tvstandard);
okSetVideoParam(hBoard, VIDEO_FREQSEG, 0); //lo seg
SetRect(&rect, 0, 0, 768, 576);
}
else //1:1
{
//first do vidoe rect shift
videoshift = MAKELONG((short)100, HIWORD(okSetVideoParam(hBoard,VIDEO_RECTSHIFT,-1)));
okSetVideoParam(hBoard, VIDEO_RECTSHIFT, videoshift);
tvstandard = 2; //non-standard
okSetVideoParam(hBoard, VIDEO_TVSTANDARD, tvstandard);
okSetVideoParam(hBoard, VIDEO_FREQSEG, 0); //lo seg
okSetCaptureParam(hBoard, CAPTURE_HORZPIXELS, 709);
okSetCaptureParam(hBoard, CAPTURE_VERTLINES, 625);
SetRect(&rect, 0, 0, 576, 576);
}
}else if(sample43 && (scanlines==525) && (videotype==1))
{
if (sample43) //4:3
{
tvstandard = 1; //NTSC
okSetVideoParam(hBoard, VIDEO_TVSTANDARD, tvstandard);
okSetVideoParam(hBoard, VIDEO_FREQSEG, 0); //lo seg
SetRect(&rect, 0, 0, 640, 480);
}
else //1:1
{
//first do vidoe rect shift
videoshift = MAKELONG((short)70, HIWORD(okSetVideoParam(hBoard, VIDEO_RECTSHIFT,-1)));
okSetVideoParam(hBoard, VIDEO_RECTSHIFT, videoshift);
tvstandard = 2; //non-standard
okSetVideoParam(hBoard, VIDEO_TVSTANDARD, tvstandard);
okSetVideoParam(hBoard, VIDEO_FREQSEG, 0); //lo seg
okSetCaptureParam(hBoard, CAPTURE_HORZPIXELS, 591);
okSetCaptureParam(hBoard, CAPTURE_VERTLINES, 525);
SetRect(&rect, 0, 0, 480, 480);
}
}
else
{
tvstandard = 2;//non-standard
okSetVideoParam(hBoard, VIDEO_TVSTANDARD, tvstandard);
if (sample43)
samppixel = (long)(scanlines*1.5104); //1.0 sample in 4:3
else
samppixel = (long)(scanlines*1.1328); //0.76 sample in 1:1
re_calc:
sampfreq = scanlines*samppixel/1000*fieldfrq/1000; //to unit MHz
if (videotype == 1) //interlaced
sampfreq /= 2;
if (sampfreq < 14.75)
sampfreq = 0; //low
else if (sampfreq < 30)
sampfreq = 1; //middle
else if (sampfreq <= 60)
sampfreq = 2; //high
else
{
samppixel = 60000000/(scanlines*(fieldfrq>>videotype)); //
goto re_calc;
}
okSetCaptureParam(hBoard, CAPTURE_HORZPIXELS, samppixel);
okSetCaptureParam(hBoard, CAPTURE_VERTLINES, scanlines);
okSetVideoParam(hBoard, VIDEO_FREQSEG, sampfreq);
//vidoe rect shift
//videoshift=MAKELONG( (short)(samppixel*0.165),(short)(samppixel*0.0512));
videoshift = MAKELONG((short)(samppixel*0.18), (short)(scanlines*0.08));
okSetVideoParam(hBoard, VIDEO_RECTSHIFT, videoshift);
//do again after set shift
okSetVideoParam(hBoard, VIDEO_TVSTANDARD, tvstandard);
SetRect(&rect, 0, 0, (long)(samppixel*0.8), (long)(scanlines*0.9));
}
okSetTargetRect(hBoard, VIDEO, &rect);
okSetTargetRect(hBoard, BUFFER, &rect);
return tvstandard;
}
BOOL CSignBox::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
return CDialog::Create(IDD, pParentWnd);
}
void CSignBox::OnRedetect()
{
SendMessage(WM_INITDIALOG, 0, 0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -