📄 okmfcview.cpp
字号:
okSetConvertParam(hBoard, CONVERT_MIRROR, 0);//init to normal
m_MakeXMirror = FALSE;
m_MakeYMirror = FALSE;
//set init menu
hMenu = ::GetMenu(hWnd);
//modelcode=okGetTypeCode(hBoard,-1); //just get model code
typecode = (short)okGetTypeCode(hBoard, NULL);
if (okSetVideoParam(hBoard, VIDEO_FRAMELINES, -1) != -1) //support playback
{
EnableMenuItem(hMenu, 3, MF_BYPOSITION|MF_ENABLED);
if (typecode == OK_M30) //special for M30 without outlut
{
m_NormalLut = FALSE;
m_InverseLut = FALSE;
m_AbsoluteLut = FALSE;
m_AbsoluteDsa = FALSE;
}
}
else
{
EnableMenuItem(hMenu, 3, MF_BYPOSITION|MF_GRAYED);
//EnableMenuItem(hMenu,3,MF_BYPOSITION|MF_GRAYED);
}
if (LOWORD(okSetCaptureParam(hBoard, CAPTURE_FRMRGBFORMAT, -1)) != 0xffff)
{
m_CapToFrame = TRUE;
m_BufferToFrame = TRUE;
m_FrameToBuffer = TRUE;
m_FrameToScreen = TRUE;
}
else
{
m_CapToFrame = FALSE;
m_BufferToFrame = FALSE;
m_FrameToBuffer = FALSE;
m_FrameToScreen = FALSE;
}
if (typecode == OK_M60) //special for M60 with frame
{
m_CapToFrame = true;
m_BufferToFrame = true;
}
else if (typecode == OK_RGB30) //special for RGB30 with frame
{
m_CapToFrame = false;
m_FrameToBuffer = false;
m_FrameToScreen = false;
}
if (okOpenAudio(hBoard, 1)) //support audio funcrion
{
m_CaptureAudio = true;
}
else
{
m_CaptureAudio = false;
}
if (okOpenStream(hBoard, 1)) //support stream funcrion
{
m_CaptureMpeg2 = true;
}
else
{
m_CaptureMpeg2 = false;
}
//reg device driver for nt/2k/xp
if (okSetNTDriver(0)) // TRUE:registered already, -1:not nt system
{
m_Regdevdriver = false;
}
//okSaveInitParam(hBoard,2);
//okLoadInitParam(hBoard,2);
//get current mask mode
m_Enablemask = (short)okEnableMask(hBoard, -1);
if(m_Enablemask == -1) //not support
{
b_Enablemask = false;
m_Enablemask = false;
}
else
{
b_Enablemask = true;
exDemoMask();
}
if (okCaptureSequence(hBoard, 0, 0) == -1)
m_SeqCapToBuf = FALSE;
else
m_SeqCapToBuf = TRUE;
return hBoard;
}
/*
* 函数介绍:获得指定目标体格式
* 输入参数:hBoard 图像卡句柄
* src 目标体
* 输出参数:lpbi bitmap格式文件头
* 返 回 值:返回屏幕格式
*/
BOOL COkMfcView::exGetBitmapHeader(HANDLE hBoard, TARGET src, LPBITMAPINFOHEADER lpbi)
{
short width,height;
long form,extend;
form = exGetTargetSize(hBoard, src, &width, &height);
extend=okSetCaptureParam(hBoard,CAPTURE_SAMPLEFIELD,-1);
if(extend==0) { //in field
extend=okSetConvertParam(hBoard,CONVERT_FIELDEXTEND,-1);
if(extend==FIELD_COPYEXTEND || extend==FIELD_COPYINTERPOL)
height*=2;
}
//here take form as screen forever
if(src <= 1)
form = okSetCaptureParam(hBoard, CAPTURE_SCRRGBFORMAT, GETCURRPARAM); //-1
{ //treat rotate
short temp;
temp=(short)okSetConvertParam(hBoard,CONVERT_UPRIGHT,-1); //un
if(temp>0) {
temp=width;
width=height;
height=temp;
}
}
exSetBitmapHeader(lpbi, width, height, HIWORD(form), LOWORD(form) );
return LOWORD(form);
}
/*
* 函数介绍:获得指定目标体大小
* 输入参数:hBoard 图像卡句柄
* tgt 目标体
* 输出参数:width 指定目标体宽度
* height 指定目标体高度
* 返 回 值:返回指定目标体格式
*/
long exGetTargetSize(HANDLE hBoard, TARGET tgt, short *width, short *height)
{
RECT rect;
long form;
if ((tgt==SCREEN ) ||(tgt==BUFFER))
{
rect.right = -1;
okSetTargetRect(hBoard, tgt, &rect); //get current rect
if(width)
*width=(short)(rect.right - rect.left);
if(height)
*height=(short)(rect.bottom - rect.top);
if (tgt == SCREEN)
{
form = okSetCaptureParam(hBoard, CAPTURE_SCRRGBFORMAT, GETCURRPARAM); //-1
//limit to video rect
rect.right = -1; //max. captured rect
okSetTargetRect(hBoard, VIDEO, &rect); //get video rect
if(width)
*width = (short)min(*width, rect.right - rect.left);
if(height)
*height = (short)min(*height, rect.bottom - rect.top);
}
else if (tgt == BUFFER)
form = okSetCaptureParam(hBoard, CAPTURE_BUFRGBFORMAT, GETCURRPARAM); //-1
} else if (tgt > BUFFER) //from blkinfo
{
LPBLOCKINFO lpblk;
lpblk = (LPBLOCKINFO)tgt;
if(width)
*width = lpblk->iWidth;
if(height)
*height = abs(lpblk->iHeight);
form = MAKELONG(lpblk->iFormType, lpblk->iBitCount);
}
return form;
}
/*
* 函数介绍:设置bitmap文件头
* 输入参数:width 设置的宽度
* height 设置的高度
* form 设置的格式
* 输出参数:lpbi bitmap文件头指针
* 返 回 值:文件头格式控制字
*/
long exSetBitmapHeader(LPBITMAPINFOHEADER lpbi,short width,short height, short bits, short form)
{
long wbytes;
if(!lpbi)
return FALSE;
if(form == FORM_RGB555)
bits = 16;
wbytes = ((((width * bits) + 31) & ~31) >> 3);//bmp need 4 byte align
lpbi->biWidth = width;
lpbi->biHeight = height;
lpbi->biSize = sizeof(BITMAPINFOHEADER);
lpbi->biPlanes = 1;
lpbi->biBitCount = bits;
lpbi->biSizeImage = wbytes * height;
lpbi->biClrUsed = 0;
//special format for 555,565 & 32
if ((form==FORM_RGB555) || (form==FORM_RGB565) || (form==FORM_RGB8888))
lpbi->biCompression = BI_BITFIELDS;
else
lpbi->biCompression = 0;
if (lpbi->biCompression == BI_BITFIELDS) //
{
DWORD *lpmask;
lpmask = (DWORD *)((LPSTR)lpbi+lpbi->biSize);
if (form == FORM_RGB555)
{
lpmask[2] = 0x001f; //blue
lpmask[1] = 0x03e0;
lpmask[0] = 0x7c00;
}
else if (form == FORM_RGB565)
{
lpmask[2] = 0x001f; //blue
lpmask[1] = 0x07e0;
lpmask[0] = 0xf800;
}
else if (bits == 32)
{
lpmask[2] = 0x0000ff;
lpmask[1] = 0x00ff00;
lpmask[0] = 0xff0000;
}
}
else if (bits <= 12) // 8,10,12
{
int i;
RGBQUAD *lpRGB = (RGBQUAD *)((LPSTR)lpbi+lpbi->biSize);
lpbi->biClrUsed = (1<<bits);
for (i=0; i<(short)lpbi->biClrUsed; i++)
{
lpRGB[i].rgbBlue = i;
lpRGB[i].rgbGreen = i;
lpRGB[i].rgbRed = i;
lpRGB[i].rgbReserved = 0;
}
}
lpbi->biClrImportant = lpbi->biClrUsed;
return lpbi->biClrUsed;
}
/*
* 函数介绍:将图像数据写入指定内存区
* 输入参数:src 源目标体
* start 开始帧数
* lpbi 图像格式
* 输出参数:lpdib 待写入图像数据数据区
* 返 回 值:不支持返回-1
* 失败返回0
* 成功返回传送字节数
*/
long COkMfcView::exSetDataToDIB(TARGET src, short start, LPBITMAPINFOHEADER lpbi, LPBYTE lpdib)
{
BLOCKINFO blk;
ZeroMemory(&blk,sizeof(BLOCKINFO));
//get image to app buffer from tgt
blk.lpBits = lpdib;
blk.iWidth = (short)lpbi->biWidth;
blk.iHeight = -(short)lpbi->biHeight; //to invert y
blk.iBitCount = lpbi->biBitCount;
blk.lBlockStep = LOWORD(lpbi->biSizeImage); //must be set
blk.iHiStep = HIWORD(lpbi->biSizeImage); //must be set
if(lpbi->biCompression == BI_BITFIELDS) //
{
DWORD *lpMask;
lpMask = (DWORD *)((LPSTR)lpbi+lpbi->biSize);
if (lpMask[1] == 0x03e0) //555
blk.iFormType = FORM_RGB555;
}
return okConvertRect(hBoard, (TARGET)&blk, 0, src, start, 1);
}
/*
* 函数介绍:设置调色板
* 输入参数:hDC 应用程序绘图区句柄
* 输出参数:无
* 返 回 值:1
*/
HPALETTE COkMfcView::exSetPaletteToWnd(HDC hDC)
{
static HPALETTE hPalette;
long form;
short bits;
//get current screen(VGA) format
form = okSetCaptureParam(hBoard, CAPTURE_SCRRGBFORMAT, GETCURRPARAM); //-1
bits = HIWORD(form); //take HIWORD
form = LOWORD(form);
if (bits==8 || bits==10) { //gray
if (!hPalette)
hPalette = exMakeLogPalette(bits, (short)form);
SelectPalette(hDC, hPalette, 0);
RealizePalette(hDC); // GDI Bug
}
return (HPALETTE)1;
}
/*
* 函数介绍:生成调色板
* 输入参数:iBits 颜色深度
* rgbForm 彩色或灰度
* 输出参数:无
* 返 回 值:调色板
*/
HPALETTE COkMfcView::exMakeLogPalette(short iBits, short rgbForm)
{
HPALETTE hLogPal;
NPLOGPALETTE npPal;
WORD nNumColors;
short i;
nNumColors = (WORD)(1<<iBits);
npPal = (NPLOGPALETTE)LocalAlloc(LMEM_FIXED, sizeof(LOGPALETTE) +
nNumColors * sizeof(PALETTEENTRY));
if (!npPal) return(FALSE);
npPal->palVersion = 0x300;
npPal->palNumEntries = nNumColors;
//set palette
if (rgbForm == FORM_RGB332) //rgb 332
{
BYTE red=0, green=0, blue=0;
for (i=0; i<nNumColors; i++ )
{
npPal->palPalEntry[i].peBlue = blue;
npPal->palPalEntry[i].peGreen = green;
npPal->palPalEntry[i].peRed = red;
npPal->palPalEntry[i].peFlags = 0;
if (!(red += 32))
if (!(green += 32))
blue += 64;
}
}
else //gray 256 or 1024
{
for (i=0; i<nNumColors; i++ )
{
npPal->palPalEntry[i].peRed = (BYTE)i;
npPal->palPalEntry[i].peGreen = (BYTE)i;
npPal->palPalEntry[i].peBlue = (BYTE)i;
npPal->palPalEntry[i].peFlags = 0;
}
}
hLogPal = CreatePalette((LPLOGPALETTE)npPal);
LocalFree((HANDLE)npPal);
return(hLogPal);
}
//------------callback runtines----------
long elapsed;
long numframe;
char string[256];
long bufform;
BLOCKINFO blk;
long num;
float ratio = 25;
float exCalcCaptureRatio()
{
static long times;
if((num>=12) || ((okGetTickCount()-times)>2000))
{
times = GetTickCount() - times;
ratio = (float)num * 1000 / times;
num = 0;
}
if(num == 0)
times = GetTickCount();
num++;
return ratio;
}
/*
* 函数介绍:开始采集回调函数
* 输入参数:hBoard 图像卡句柄
* 输出参数:无
* 返 回 值:正确返回TRUE
* 错误返回FALSE
*/
BOOL CALLBACK exBeginCapture(HANDLE hBoard)
{
short width,height;
long form;
if (bDispToScreen)
{
bufform=exGetTargetSize(hBoard, BUFFER, &width, &height);
form=okSetCaptureParam(hBoard,CAPTURE_SCRRGBFORMAT,GETCURRPARAM); //-1
{ //treat rotate
short temp;
temp=(short)okSetConvertParam(hBoard,CONVERT_UPRIGHT,-1); //un
if(temp>0) {
temp=width;
width=height;
height=temp;
}
}
exSetBitmapHeader(lpbi, width, height, HIWORD(form), LOWORD(form) );
if (bDispToScreen > 1)
{ //take same bits as screen for callback exSetToScreen
if (bDispToScreen == 3)
{ //make pseudo-display
int i;
#define way1
#ifdef way1
//way1 by convert
{
PALETTEENTRY palPalEntry[256];
exSetBitmapHeader(lpbi, width, height, HIWORD(form), LOWORD(form) );
//just exam to set palette to yellow
for (i = 0; i<256; i++ ) {
palPalEntry[i].peRed = (BYTE)i;
palPalEntry[i].peGreen = (BYTE)i;
palPalEntry[i].peBlue = (BYTE)0;
palPalEntry[i].peFlags = 0;
}
//if( LOWORD(blkform)!=FORM_GRAY8) ////set mapping palette
okSetConvertParam(hBoard, CONVERT_PALETTE, (LPARAM)palPalEntry);
}
#else
//way2 by windows palette
{
RGBQUAD *lpRGB = (RGBQUAD *)((LPSTR)lpbi + lpbi->biSize);
for (i = 0; i<256; i++ )
{
lpRGB[i].rgbRed = (BYTE)i;
lpRGB[i].rgbGreen = (BYTE)i;
lpRGB[i].rgbBlue = (BYTE)0;
lpRGB[i].rgbReserved = 0;
}
}
#endif
}
}
}
blk.lpBits = (LPBYTE)lpdib;
blk.iBitCount = lpbi->biBitCount;
if (bMakeMirror & 1) //x mirror
blk.iWidth = -(short)lpbi->biWidth;
else
blk.iWidth = (short)lpbi->biWidth;
if (okSetCaptureParam(hBoard, CAPTURE_SAMPLEFIELD, -1) == 0) //sample in field by field
if (LOWORD(okSetVideoParam(hBoard, VIDEO_SIGNALTYPE, -1)) == 1) //interlace video
if (okSetConvertParam(hBoard, CONVERT_FIELDEXTEND, -1) != 0)
lpbi->biHeight *= 2; //double size for ht
if(bMakeMirror & 2) //y mirror
blk.iHeight = (short)lpbi->biHeight; // y mirror
else
blk.iHeight = -(short)lpbi->biHeight; //note: minus is for invert dib in y by ConvertRect
elapsed = GetTickCount();
numframe = 0;
return 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -