📄 recimage.cpp
字号:
// RecImage.cpp : implementation file
//
#include "stdafx.h"
#include "bxt.h"
#include "RecImage.h"
//#include "memalloc.h"
#include "pic.h"
#include "bxtdlg.h"
#include "avitools.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define NUMINFILE 30
//zlj {
#include "EncodeMpegExport.h"
/*
typedef struct ENCODEPARA
{
int width, height; // encoded frame size (pels) multiples of 16 or 32
int nframes;
int nMpeg;
char out_name[256];
unsigned char*rgb24;
HANDLE hWakeEncode;
HANDLE hUpdata;
HANDLE hFinish;
}EncodePara;
extern "C"{
extern DWORD WINAPI EncodeMpeg( LPVOID en_para );
extern DWORD WINAPI AddFrame(int nFrame, unsigned char*pFrame);
extern EncodePara en_para;
}
*/
#define W_NTSC 640
#define H_NTSC 480
#define W_PAL 768
#define H_PAL 576
#define NUM_FD_BUF 20
//#define totalNumFrame 2
long totalNumFrame;
int ntscBytesFrame =W_NTSC* H_NTSC *3;
int PALBytesFrame =W_PAL * H_PAL *3;
int nAviFile=1;
int nForwardFrame=0;
LPSTR lpForwardCapBuf=NULL;
LPSTR lpForwardBufTemp=NULL;
struct FORWORDBUF{
char * bufArry[30];
int head;
int tail;
};
FORWORDBUF fdBuf;
char * lpBackCapBuf=NULL;
LPSTR lpBackBufTemp=NULL;
//HANDLE hSemaphore;
UINT SaveDataToDisk(LPVOID lParam);
bool RecImage::bBackCap=0;
bool RecImage::bForwordCap=1;
//zlj }
//----global variables for board--------
HANDLE hBoard;
short total = 2;
long iCurrUsedNo = -1;//
short iNumImage = NUMINFILE;
short bScrnCenter = 1; //centerize
long lScrnOffset;
short sampwidth;
short sampheight;
short bMaskMode = 0; // mask disable
LPSTR seqfile = "ok.seq";
DWORD dwMaxMemSize = 30 * 1024 * 1024;
long dwBufSize;
int PlayBackDelay = 100;
LPBITMAPINFOHEADER lpbi = NULL;
LPSTR lpdib;
LPSTR lpMemory;
BLOCKINFO blkinfo;
long elapsed;
long numframe_BackDisplay;
char string[256];
long bufform;
BLOCKINFO blk;
long nBackFrame;
LPDIBINFO lpDibPlay;
BOOL bDispToScreen;
char SeqFilePath[500];
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);
long SetToWndRectEx(HANDLE hBoard, HWND hWnd, long lMode);
void DemoMask();
bool SaveBufferFile(HANDLE hBoard, HWND hWnd,char *filename);
BOOL ConvertBitmap(LPBITMAPINFOHEADER lpbi,LPSTR lpdib);
long GetFrameSize(HANDLE hBoard);
BOOL CALLBACK BackDisplay(HANDLE hBoard, long no);
BOOL CALLBACK BeginCapture(HANDLE hBoard);
BOOL CALLBACK EndCapture(HANDLE hBoard);
BOOL CALLBACK OnCapSeq(HANDLE hBoard, long no);
/////////////////////////////////////////////////////////////////////////////
// RecImage dialog
//static HINSTANCE hinstDevice; // handle of Device Drive DLL
RecImage::RecImage(CWnd* pParent /*=NULL*/)
: CDialog(RecImage::IDD, pParent)
{
//{{AFX_DATA_INIT(RecImage)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void RecImage::CloseRecImage()
{
okStopCapture(hpcih);
okCloseBoard(hpcih);
//PCIHCapture(hpcih,false);
//EndPCIH(hpcih);
//FreeLibrary( hinstDevice );
}
void RecImage::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(RecImage)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
// bBackCap = 0;
// bForwordCap = 1;
}
BEGIN_MESSAGE_MAP(RecImage, CDialog)
//{{AFX_MSG_MAP(RecImage)
ON_WM_SHOWWINDOW()
ON_WM_CLOSE()
ON_WM_PAINT()
//}}AFX_MSG_MAP
ON_MESSAGE(WX_RECONE, CapturePIcOne)
ON_MESSAGE(WX_SETDSPMODE, mSetDispMode)
ON_MESSAGE(WX_RECSETBRI, mSetRecBri)
ON_MESSAGE(WX_RECSETCON, mSetRecCon)
ON_MESSAGE(WX_RECSETFRQ, mSetRecFrq)
ON_MESSAGE(WX_RECSETCLP, mSetRecClp)
ON_MESSAGE(WX_RECSETSRC, mSetRecSrc)
ON_MESSAGE(WX_RECSETSTN, mSetRecStn)
ON_MESSAGE(WX_RECSETSYN, mSetRecSyn)
ON_MESSAGE(WX_PLAYBACK, PlayBackSeq)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// RecImage message handlers
BOOL RecImage::OnInitDialog()
{
CDialog::OnInitDialog();
CRect rcTarget;
long bb = -1;
short w, h, iWindowWidth, iWindowHeight;
long s;
hpcih = okOpenBoard(&bb);
//zlj
//hSemaphore=CreateSemaphore(NULL,0,1,0);
int a=okSetVideoParam(hpcih,1,0x100);
a=okSetVideoParam(hpcih,6,FORM_RGB888);
a=okSetVideoParam(hpcih,7,0);
a=okSetVideoParam(hpcih,8,0);
a=okSetCaptureParam(hpcih, 15, 0);
a=okSetCaptureParam(hpcih, 10, 1);
a=okSetCaptureParam(hpcih,1,0);
a=okSetCaptureParam(hBoard, 6, MAKELONG(W_PAL,H_PAL));
fdBuf.head=fdBuf.tail=0;
for(int i=0;i<30;i++){
fdBuf.bufArry[i]=new char[PALBytesFrame];
}
lpBackCapBuf=new char[PALBytesFrame*60 ];
//lpForwardCapBuf=new char[PALBytesFrame*30];
//lpForwardBufTemp=lpForwardCapBuf;
if(lpBackCapBuf==NULL) ::MessageBox(NULL,"memory is short!" ,NULL,NULL);
/*//zlj*/
okGetTargetInfo(hpcih, BUFFER, 0, &w, &h, &s);
GetWindowRect(&rcTarget);
iWindowWidth = rcTarget.Width();
iWindowHeight = rcTarget.Height();
if (w > iWindowWidth || h > iWindowHeight)
{
FLOAT fZoom, fZoomX, fZoomY;
fZoomX = (FLOAT)(iWindowWidth) / w;
fZoomY = (FLOAT)(iWindowHeight) / h;
fZoom = (fZoomX < fZoomY) ? (fZoomX) : (fZoomY);
w = (short)(w * fZoom);
h = (short)(h * fZoom);
}
rcTarget.OffsetRect((iWindowWidth - w) / 2, (iWindowHeight - h) / 2);
rcTarget.right = rcTarget.left + w;
rcTarget.bottom = rcTarget.top + h;
a=okSetTargetRect(hpcih, SCREEN, &rcTarget);
freeze = TRUE;
CapturedNum = 1 ;//Already Capture pic number
char string[100];
MEMORYSTATUS Status;
if (!lpbi)
{
GlobalMemoryStatus(&Status);
//determaine how many memory will be allocated as user memory
dwMaxMemSize=Status.dwTotalPhys-dwBufSize-32*(1<<20); //I'd keep 32M for window system
if(dwMaxMemSize<=0)
dwMaxMemSize=5*(1<<20); //5M
else if( dwMaxMemSize>Status.dwAvailPhys )
dwMaxMemSize=Status.dwAvailPhys/2;
if( dwMaxMemSize<5*(1<<20) ) //need 5M at least for user memory
dwMaxMemSize=max(5*(1<<20),Status.dwAvailPhys);
lpbi=(LPBITMAPINFOHEADER)GlobalAlloc(GPTR,dwMaxMemSize);
if(lpbi==NULL) {
dwMaxMemSize=4*(1<<20); //4M
lpbi=(LPBITMAPINFOHEADER)GlobalAlloc(GPTR,dwMaxMemSize);
}
lpdib=(LPSTR)lpbi+5120; //keep 5k for bi
lpMemory=(LPSTR)lpbi+2048*1024; //keep 2M for dib
dwMaxMemSize-=2048*1024+5120;
if(lpbi) {
sprintf(string,"Allocated memory = %d",dwMaxMemSize);
}else
sprintf(string,"Allocate memory failed !");
// MessageBox(hwnd,string,"Message",MB_OK);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
BOOL RecImage::DestroyWindow()
{
return CDialog::DestroyWindow();
}
void RecImage::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
if (bShow){
okCaptureByBuffer(hpcih, SCREEN, 0, 0);
okSetSeqCallback(hpcih, BeginCapture, OnCapSeq, EndCapture);
}
else
if( !bBackCap)
okStopCapture(hpcih);
}
void RecImage::OnClose()
{
okStopCapture(hpcih);
okCloseBoard(hpcih);
CDialog::OnClose();
}
void RecImage::OnOK()
{
}
void RecImage::OnCancel()
{
}
void RecImage::PlayBackSeq(WPARAM wParm, LPARAM lParm)
{
//((CBxtDlg *)AfxGetMainWnd())->m_m.SelectTab(0);
//((CBxtDlg *)AfxGetMainWnd())->TabSelChange(IDC_TAB1,0);
if(wParm==-1)
{
okStopCapture(hpcih);
((CBxtDlg*)AfxGetMainWnd())->imgpcs->Invalidate(true);
return;
}
if(wParm==-2)
{
PlayBackDelay = lParm;
return;
}
okStopCapture(hpcih);
bDispToScreen=1;
okSetSeqCallback(hpcih,BeginCapture,BackDisplay,EndCapture);
char *fn=(char*) lParm;
long num=okLoadImageFile(hpcih, fn, 0, SCREEN, 0, 0);
okPlaybackByBuffer(hpcih,(TARGET)fn,0,-num);
}
void RecImage::CaptureOne(char *fn)
{
okStopCapture(hpcih);
okCaptureTo(hpcih,BUFFER,0,1);//single
okGetCaptureStatus(hpcih,1);
//Sleep(20); //do waiting here
//buf->scr
GetBitmapHeader(hpcih, BUFFER, lpbi);
SetDataToDIB(BUFFER, 0, lpbi, (unsigned char*)lpdib);
//okStopCapture(hBoard);
SaveBufferFile(hpcih,m_hWnd,fn);
//short bScrnCenter=1; //centerize
//SetToWndRectEx(hpcih,m_hWnd,bScrnCenter);
okCaptureToScreen(hpcih);
}
void RecImage::mSetRecSyn( WPARAM wParm, LPARAM lParm)
{
okStopCapture(hpcih);
okSetVideoParam(hpcih,wParm,lParm);
okCaptureToScreen(hpcih);
char ss[10];
sprintf(ss,"0x%d",wParm);
WritePrivateProfileString("OK_RGB10","SyncChann",ss,"Okadrv.ini");
}
void RecImage::mSetRecStn( WPARAM wParm, LPARAM lParm)
{
okStopCapture(hpcih);
okSetVideoParam(hpcih,wParm,lParm);
okCaptureToScreen(hpcih);
char ss[10];
sprintf(ss,"0x%d",wParm);
WritePrivateProfileString("OK_RGB10","TVStandard",ss,"Okadrv.ini");
}
void RecImage::mSetRecSrc( WPARAM wParm, LPARAM lParm)
{
if(wParm==1)
{
okStopCapture(hpcih);
okSetVideoParam(hpcih,1,0x200);
okCaptureToScreen(hpcih);
WritePrivateProfileString("OK_RGB10","SourceChan","0x200","Okadrv.ini");
}
else if(wParm==2)
{
okStopCapture(hpcih);
okSetVideoParam(hpcih,1,0x201);
okCaptureToScreen(hpcih);
WritePrivateProfileString("OK_RGB10","SourceChan","0x201","Okadrv.ini");
}
else
{
}
}
void RecImage::mSetRecBri( WPARAM wParm, LPARAM lParm)
{
//PCIHSetADParam(hpcih,AD_BRIGHTNESS,wParm);
switch(wParm)
{
case 1:
case 2:
case 3:
okStopCapture(hpcih);
okSetVideoParam(hpcih,2,MAKELPARAM(lParm,0));//zlj wParm-1
okCaptureToScreen(hpcih);
break;
case 4:
case 5:
case 6:
okStopCapture(hpcih);
okSetVideoParam(hpcih,3,MAKELPARAM(lParm,wParm-4));
okCaptureToScreen(hpcih);
break;
}
}
void RecImage::mSetRecCon(WPARAM wParm, LPARAM lParm)
{
//PCIHSetADParam(hpcih, AD_CONTRAST, wParm);
}
void RecImage::mSetRecFrq(WPARAM wParm, LPARAM lParm)
{
//PCIHSetADParam(hpcih, AD_FREQUENCY, wParm);
}
void RecImage::mSetRecClp(WPARAM wParm, LPARAM lParm)
{
//PCIHSetADParam(hpcih, AD_CLAMPLEVEL, wParm);
}
void RecImage::mSetDispMode(WPARAM wParm, LPARAM lParm)
{
SetDispMode();
}
void RecImage::CapturePIcOne(WPARAM wParm, LPARAM lParm)
{
int a=okSetTargetRect(hBoard, BUFFER,CRect(0,0,W_PAL,H_PAL ));//zlj
if (0 == wParm)
{
CHAR filename[500];
sprintf(filename, "%s\\%d.jpg", ((CBxtDlg *)AfxGetMainWnd())->m_workingpath, CapturedNum);
//okCaptureByBuffer(hpcih, SCREEN, 0, 0);//
short w;
short h;
long s;
unsigned char *buf = (unsigned char*)okGetTargetInfo(hpcih,BUFFER /* hBoard,*/ , 0, &w, &h, &s);// zlj
CPic pp;
pp.m_width = w;
pp.m_height = h;
pp.m_buf = new BYTE[w * h * 3];
int i;
int j;
for (i = h - 1; i >= 0; i--) for (j = 0; j < w * 3; j++)
pp.m_buf[(h - i - 1) * w * 3 + j] = buf[i * s + j];
pp.m_filename = _T(filename);
pp.fileType = 1;
pp.flag = 1;//Color;
pp.savejpg(filename);
CapturedNum++;
}
else
{
::nBackFrame = 0;
::totalNumFrame = wParm;
//okStopCapture(hpcih);
bBackCap=1;
lpBackBufTemp=lpBackCapBuf;
//a=okCaptureByBuffer(hpcih, (TARGET)lpBackCapBuf, 0, totalNumFrame);
//a=okGetCaptureStatus( hpcih,1);
}
}
void RecImage::SetDispMode()
{
}
void RecImage::OnPaint()
{
CPaintDC dc(this); // device context for painting
}
BOOL GetBitmapHeader(HANDLE hBoard, TARGET src, LPBITMAPINFOHEADER lpbi)
{
short width,height;
long form;
form=GetTargetSize(hBoard, src, &width, &height);
//here take form as screen forever
form=okSetCaptureParam(hBoard,3,GETCURRPARAM); //-1
SetBitmapHeader(lpbi, width, height, HIWORD(form), LOWORD(form) );
return LOWORD(form);
}
//set data to dib
long SetDataToDIB(TARGET src, short start, LPBITMAPINFOHEADER lpbi, LPBYTE lpdib)
{
BLOCKINFO blk;
int aa= sizeof(blk);
//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;
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);
}
//--demo to set current capture rect on screen. mode=0: left-top, 1:centerize
long SetToWndRectEx(HANDLE hBoard, HWND hWnd, long lMode)
{
long lSize;
RECT rect;
if( !IsWindow(hWnd) )
return FALSE;
if(IsIconic(hWnd) )
return FALSE;
//get client rect
GetClientRect(hWnd,&rect);
if(lMode==1) { //set to center
short width,height;
//get available rect size
//lSize=okSetVideoParam(hBoard,VIDEO_AVAILRECTSIZE,-1);
//or set to expected size
//sampwidth=LOWORD(lSize);
//sampheight=HIWORD(lSize);
if( okGetCaptureStatus(hBoard,0) ) { //capturing
width=sampwidth;
height=sampheight;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -