?? okfunc.c
字號:
/*==============================================================================
*
* filename okFunc.c
* purpose API for okapi32.dll exam (Ok series image cards)
* language Microsoft Visual C 5.0
* author He Peng
* date 00-8-20
*-----------------------
* modify by He Peng
* purpose
* language Microsoft Visual C 5.0
* date 00-10-16
*
*-----------------------
*
* Copyright (C). All Rights Reserved.
*
*
*==============================================================================*/
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include <dos.h>
#include <memory.h>
#include <time.h>
#include<windows.h>
#include"resource.h"
#include "okapi32.h"
//---------------
#define NUMINFILE 30
#define SOURCENUMBER 3
//----global variables for board--------
HANDLE hBoard;
BYTE bActive=0;
short total=2;
long iCurrUsedNo=-1;//
short iNumImage=NUMINFILE;
short bScrnCenter=1; //centerize
long lScrnOffset;
short sampwidth,sampheight;
short bMaskMode=0; // mask disable
LPSTR seqfile="ok.seq";
DWORD dwMaxMemSize=30*1024*1024;
long dwBufSize;
TARGET CaptureTarget=SCREEN; //采集目標
short CaptureStart=1; //采集起始幀
short CaptureEnd=1; //采集結束幀
LPBITMAPINFOHEADER lpbi;
LPSTR lpdib;
LPSTR lpMemory;
BLOCKINFO blkinfo;
BOOL bDispToScreen=1;
//----local functions-------------------------------------
int PrintReport(HWND hWnd, LPBITMAPINFOHEADER lpbi, LPSTR lpdib);
long SetBitmapHeader(LPBITMAPINFOHEADER lpbi,short width,short height, short bits, short form);
long SetDataToDIB(TARGET src, short start, LPBITMAPINFOHEADER lpbi, LPBYTE lpdib);
long GetTargetSize(HANDLE hBoard, TARGET tgt, short *width, short *heigth);
BOOL GetBitmapData(HANDLE hBoard, TARGET tgt, short start, LPBITMAPINFOHEADER lpbi, LPSTR lpdib);
BOOL GetBitmapHeader(HANDLE hBoard, TARGET src, LPBITMAPINFOHEADER lpbi);
HANDLE OpenCard(HWND hWnd);
BOOL GetBitmapHeader(HANDLE hBoard, TARGET src, LPBITMAPINFOHEADER lpbi);
void EnableItem(HWND hWnd, int iMenuID, BOOL bEnable);
void DisplayDIBInfo(HWND hwnd);
void SetPaletteToWnd(HDC hDC);
HPALETTE MakeLogPalette(short iBits, short rgbForm);
//----------------------- window parts----------
HWND hwnd;
HANDLE hInst;
HANDLE hAccTable; // handle to accelerator table
BOOL InitApplication(HINSTANCE);
BOOL InitInstance(HINSTANCE, int);
APIENTRY MainWndProc(HWND,UINT,WPARAM,LPARAM );
extern BOOL APIENTRY IddSource(HWND hDlg,unsigned message,UINT wParam,LONG lParam);
extern BOOL APIENTRY IddVideoParam(HWND hDlg,unsigned message,UINT wParam,LONG lParam);
extern BOOL APIENTRY IddMask(HWND hDlg,unsigned message,UINT wParam,LONG lParam);
extern BOOL APIENTRY IddCSetup(HWND hDlg,unsigned message,UINT wParam,LONG lParam);
extern BOOL APIENTRY IddOther(HWND hDlg,unsigned message,UINT wParam,LONG lParam);
extern BOOL APIENTRY IddOutLut(HWND hDlg,unsigned message,UINT wParam,LONG lParam);
extern BOOL APIENTRY IddTo8Bit(HWND hDlg,unsigned message,UINT wParam,LONG lParam);
extern BOOL APIENTRY SelectDlgProc(HWND hDlg,unsigned message,UINT wParam,LONG lParam);
BOOL CALLBACK BeginCapture(HANDLE hBoard);
BOOL CALLBACK BackDisplay(HANDLE hBoard,long no);
BOOL CALLBACK SetToScreen(HANDLE hBoard,long no);
BOOL CALLBACK EndCapture(HANDLE hBoard);
long GetFrameSize(HANDLE hBoard);
void ScreenDisplay(void);
/****************************************************************************
FUNCTION: WinMain(HANDLE, HANDLE, LPSTR, int)
PURPOSE: calls initialization function, processes message loop
****************************************************************************/
int PASCAL WinMain(hInstance, hPrevInstance, lpCmdLine, nCmdShow)
HINSTANCE hInstance;
HINSTANCE hPrevInstance;
LPSTR lpCmdLine;
int nCmdShow;
{
MSG msg;
if (!hPrevInstance)
if (!InitApplication(hInstance))
return (FALSE);
if (!InitInstance(hInstance, nCmdShow))
return (FALSE);
hAccTable = LoadAccelerators(hInstance, "OkDemoAcc");
while (GetMessage(&msg, NULL, 0,0)) {
// Only translate message if it is not an accelerator message
if (!TranslateAccelerator(hwnd, hAccTable, &msg) ) {//|
//!TranslateMDISysAccel (hwndMDIClient, &msg) ) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return (msg.wParam);
}
/****************************************************************************
FUNCTION: InitApplication(HANDLE)
PURPOSE: Initializes window data and registers window class
****************************************************************************/
BOOL InitApplication(hInstance)
HINSTANCE hInstance;
{
WNDCLASS wc;
wc.style = CS_VREDRAW | CS_HREDRAW |CS_BYTEALIGNCLIENT ;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, "OkFuncIcon");//IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = "OkFuncMenu";
wc.lpszClassName = "OkFuncWClass";
return (RegisterClass(&wc));
}
/****************************************************************************
FUNCTION: InitInstance(HANDLE, int)
PURPOSE: Saves instance handle and creates main window
****************************************************************************/
BOOL InitInstance(hInstance, nCmdShow)
HINSTANCE hInstance;
int nCmdShow;
{
char string[100];
hInst = hInstance;
LoadString(hInst, IDS_PROGRAMNAME, string,100);
hwnd = CreateWindow("OkFuncWClass",
string,//"Demo Programm for Ok Image Device",
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL
);
if (!hwnd)
return (FALSE);
ShowWindow(hwnd, nCmdShow|SW_MAXIMIZE);
//SendMessage(hwnd,WM_SYSCOMMAND,SC_MAXIMIZE,0);
return (TRUE);
}
//****************************************************************************/
APIENTRY MainWndProc(hWnd, message, wParam, lParam)
HWND hWnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
{
switch (message)
{
case WM_CREATE: // message: create window
//新建
hBoard=OpenCard(hWnd);
break;
case WM_CLOSE: //close window
//關閉
okCloseBoard(hBoard);
GlobalFree((HGLOBAL)lpbi);
lpdib=0;
case WM_DESTROY:
//退出
PostQuitMessage(0);
break;
case WM_MOUSEMOVE:
break;
case WM_INITMENUPOPUP: //drop down menu
//顯示下拉菜單則停止采集
if(bActive)
SendMessage(hWnd,WM_COMMAND,IDM_FREEZE,0);
break;
/* case WM_SYSCOMMAND:
//最大化與最小化
DefWindowProc(hWnd, message, wParam, lParam);
if(wParam==SC_MINIMIZE || wParam==SC_RESTORE ) {
if(wParam==SC_MINIMIZE)
okStopCapture(hBoard);
InvalidateRect(NULL,NULL,TRUE);
}
break;*/
case WM_PAINT:
//重畫
{
PAINTSTRUCT ps;
HDC hDC;
LPBITMAPINFOHEADER lpBI;
LPBYTE lpDIB;
hDC=BeginPaint(hWnd,&ps);
SetPaletteToWnd(hDC);
lpBI=lpbi;
lpDIB=lpdib;
if(lpBI) {
RECT rect; POINT pt;
GetClientRect(hWnd,&rect);
if(lpBI->biHeight>rect.bottom)
rect.top=lpBI->biHeight-rect.bottom;
else
rect.top=0;
pt.x=LOWORD(lScrnOffset);
pt.y=HIWORD(lScrnOffset);
ClientToScreen(hWnd,&pt);
//adjust x abs. offset to 4 align
pt.x= pt.x%4 ? pt.x+4-pt.x%4 : pt.x;
ScreenToClient(hWnd,&pt);
SetDIBitsToDevice(hDC,pt.x,pt.y,
lpBI->biWidth,lpBI->biHeight,
0,rect.top,
0,lpBI->biHeight,
lpDIB,
(LPBITMAPINFO)lpBI,DIB_RGB_COLORS);
}
EndPaint(hWnd,&ps);
break;
}//end paint
case WM_COMMAND:
if(bActive)
okStopCapture(hBoard);
switch (LOWORD(wParam)) {
case IDM_SELECTBOARD:
//選用圖像卡,詳見okSelect.c
DialogBox(hInst, "SelectBox", hWnd, (FARPROC)SelectDlgProc);
break;
case IDM_BDISPLAY:
//回放
ScreenDisplay();
break;
case IDM_EXITOKFUN:
//退出
SendMessage(hWnd,WM_CLOSE,0,0);
break;
case IDM_ACTIVE:
//采集
switch(CaptureTarget){
case SCREEN:
//屏幕
GetBitmapHeader(hBoard, SCREEN, lpbi);
okSetToWndRect(hBoard,hWnd);
//UpdateWindow(hWnd);
okStopCapture(hBoard); //confirm
//specail capture to frame
if( okGetTypeCode(hBoard,NULL)==OK_C70 ) {
okCaptureTo(hBoard,FRAME,0,0);
EnableItem(hWnd, IDM_ACTIVE, FALSE);
EnableItem(hWnd, IDM_FREEZE, TRUE);
} //normal to screen
else if( okCaptureToScreen(hBoard)<=0 )
MessageBox(hwnd,"Current Screen (VGA) format not supported\n Or video source not connected !", "Error",MB_OK);
else {
EnableItem(hWnd, IDM_ACTIVE, FALSE);
EnableItem(hWnd, IDM_FREEZE, TRUE);
bActive=1;
}
break;
case FRAME:
//幀存
EnableItem(hWnd, IDM_FREEZE, TRUE);
okCaptureTo(hBoard,FRAME,0,0); //cont.
break;
case BUFFER:
//緩存
EnableItem(hWnd, IDM_FREEZE, TRUE);
okSetSeqCallback(hBoard,BeginCapture,BackDisplay,EndCapture);
okCaptureTo(hBoard,BUFFER,(WORD)(CaptureStart-1),(LPARAM)(CaptureEnd-CaptureStart+1));//-1: loop infiniately
break;
case USERMEMORY:
//內存
EnableItem(hWnd, IDM_FREEZE, TRUE);
okSetSeqCallback(hBoard,BeginCapture,BackDisplay,EndCapture);
if(lpbi)
okCaptureByBuffer(hBoard,(TARGET)lpMemory,(WORD)(CaptureStart-1),(LPARAM)(CaptureEnd-CaptureStart+1));
break;
case USERFILE:
//文件
EnableItem(hWnd, IDM_FREEZE, TRUE);
okSetSeqCallback(hBoard,BeginCapture,BackDisplay,EndCapture);
//first delete ok.seq
DeleteFile(seqfile);
okCaptureByBuffer(hBoard,(TARGET)seqfile,0,iNumImage);
break;
}//end select CaptureTarget
break;
case IDM_FREEZE:
//凍結
okStopCapture(hBoard);
ValidateRect(hWnd,NULL);
if(bActive)
{
//take buffer size
GetBitmapHeader(hBoard, BUFFER, lpbi);
SetDataToDIB(SCREEN, 0, lpbi, lpdib);
//GetBitmapData(hBoard, SCREEN, 0, lpbi, lpdib);
DisplayDIBInfo(hWnd);
}
bActive=0;
EnableItem(hWnd, IDM_FREEZE, FALSE);
EnableItem(hWnd, IDM_ACTIVE, TRUE);
break;
case IDM_SOURCE:
//視頻源設置 詳見okSource.c
MessageBeep(MB_ICONEXCLAMATION);
DialogBox(hInst, (LPCSTR)IDD_SOURCE, hWnd, (FARPROC)IddSource);
break;
case IDM_PARA:
//采集參數設置 詳見okParam.c
MessageBeep(MB_ICONEXCLAMATION);
DialogBox(hInst, (LPCSTR)IDD_VIDEOPARAM, hWnd, (FARPROC)IddVideoParam);
break;
case ID_MASK:
//采集位屏蔽,詳見okMask.c
MessageBeep(MB_ICONEXCLAMATION);
DialogBox(hInst, (LPCSTR)IDD_MASK, hWnd, (FARPROC)IddMask);
break;
case ID_CAPTURESETUP:
//采集設置 詳見okSetup.c
MessageBeep(MB_ICONEXCLAMATION);
DialogBox(hInst, (LPCSTR)IDD_CAPTURESETUP, hWnd, (FARPROC)IddCSetup);
if(CaptureTarget==SCREEN || CaptureTarget==FRAME) EnableItem(hWnd,IDM_BDISPLAY,FALSE);
else EnableItem(hWnd,IDM_BDISPLAY,TRUE);
break;
case IDM_OTHER:
//其它參數 詳見okOther.c
MessageBeep(MB_ICONEXCLAMATION);
DialogBox(hInst, (LPCSTR)IDD_OTHER, hWnd, (FARPROC)IddOther);
break;
case ID_OUTLUT:
//回顯設置,詳見okOutLut.c
MessageBeep(MB_ICONEXCLAMATION);
DialogBox(hInst, (LPCSTR)IDD_OUTLUT, hWnd, (FARPROC)IddOutLut);
break;
case ID_TO8BIT:
//10位卡設置,詳見okTo8Bit.c
MessageBeep(MB_ICONEXCLAMATION);
DialogBox(hInst, (LPCSTR)IDD_TO8BIT, hWnd, (FARPROC)IddTo8Bit);
break;
}//end switch command
default:
return DefWindowProc(hWnd,message,wParam,lParam);
}//end switch message
return 0;
}
void ScreenDisplay(void)
{
long no;
BLOCKINFO blk,blkTg;
short width,height;
long blkform;
long bufform;
bufform=GetTargetSize(hBoard, BUFFER, &width, &height);
if( (LOWORD(bufform)==FORM_GRAY10) || (LOWORD(bufform)==FORM_GRAY12) ) { //special
//blkform=okSetCaptureParam(hBoard,CAPTURE_SCRRGBFORMAT,GETCURRPARAM); //-1
blkform=MAKELONG(FORM_GRAY8,8);
}
else //take same bits as buffer
blkform=bufform;
SetBitmapHeader(lpbi, width, height, HIWORD(blkform), LOWORD(blkform) );
blk.lpBits=lpdib;
blk.iBitCount=lpbi->biBitCount;
blk.iWidth=(short)lpbi->biWidth;
blkTg.lpBits=lpMemory;
blkTg.iBitCount=lpbi->biBitCount;
blkTg.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
lpbi->biHeight*=2; //double size for ht
blk.iHeight=-(short)lpbi->biHeight; //note: minus is for invert dib in y by ConvertRect
blkTg.iHeight=-(short)lpbi->biHeight;
switch(CaptureTarget){
case SCREEN:
//屏幕
case FRAME:
//幀存
break;
case BUFFER:
//緩存
for(no=CaptureStart;no<=CaptureEnd;no++){
if( (LOWORD(bufform)==FORM_GRAY10) ||(LOWORD(bufform)==FORM_GRAY12) ) { //special
//way 1
okConvertRect(hBoard,(TARGET)&blk,0,BUFFER,(short)no,1);
//way 2
//okReadRectEx(hBoard,BUFFER,(short)no,lpdib, MAKELONG(FORM_GRAY8,1));
//read only red data
}
else {
//way 1
okTransferRect(hBoard,(TARGET)&blk,0,BUFFER,(short)no,1);
//way 2
//okReadRect(hBoard,BUFFER,(short)no,lpdib);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -