⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ccapture.cpp

📁 CONAXCA的源代码
💻 CPP
字号:
/*                */
/* 	CCapture	  */
/*                */

#include "stdafx.h"
#include "CCapture.h"

CCapture::CCapture(void)
{
    Port_n=-1;
    bActive=0;
}

CCapture::~CCapture(void)
{
}

int  CCapture::OpenCard(HWND hWnd,int *Dx,int *Dy)
{
    BOOL 	 bReturn;
    HDC		 hdc;
    MEMORYSTATUS Status;
    long	 iCurrUsedNo=-1;//
    DWORD	 dwMaxMemSize=30*1024*1024;
    DWORD	 dwBufSize;
    int		 nBits,dx,dy;

    hBoard=okOpenBoard(&iCurrUsedNo);
    if (!hBoard) return FALSE;

    hdc = GetDC( hWnd );
               //  retrieves the x- and y-coordinates of the origin of the window
    bReturn = GetWindowOrgEx( hdc, &winOrgPoint );
    if ( bReturn == 0x00 ) return FALSE;
    ClientToScreen( hWnd, &winOrgPoint );
    nBits   = GetDeviceCaps(hdc,BITSPIXEL);
    ReleaseDC( hWnd, hdc );

    if (nBits==24)
    	okSetCaptureParam(hBoard,CAPTURE_SCRRGBFORMAT,FORM_RGB888);
    else if (nBits==32)
    	okSetCaptureParam(hBoard,CAPTURE_SCRRGBFORMAT,FORM_RGB8888);

    GetWindowRect(hWnd,&winRect);
    dx=winRect.right  - winOrgPoint.x;
    dy=winRect.bottom - winOrgPoint.y;
    if (dx<768) dx-=24;
	if (dy<576) dy-=26;
    *Dx=dx/4*4;		*Dy=dy; 

	//check if pre_allocated buffer
    okGetBufferSize(hBoard,NULL,&dwBufSize);//
    if(dwBufSize==0)
    	MessageBox(hWnd, "There are no buffer pre-allocated !","Warning",MB_OK);

    GlobalMemoryStatus(&Status);

    dwMaxMemSize=Status.dwTotalPhys-dwBufSize-32*(1<<20);
    if(dwMaxMemSize<=0)
    	dwMaxMemSize=5*(1<<20);
    if( dwMaxMemSize<Status.dwAvailPhys )
    	dwMaxMemSize=Status.dwAvailPhys;
    else
    	dwMaxMemSize=(dwMaxMemSize+Status.dwAvailPhys)/2;

    InvalidateRect(hWnd,NULL,FALSE);

    return((int) hBoard);
}

void CCapture::CloseCard(void)
{
    okCloseBoard(hBoard);
}

void CCapture::SetSize(HWND hWnd,int x,int y,int Dx,int Dy)
{
    RECT    rect;

    okSetToWndRect(hBoard,hWnd);

    rect.left  = 0;
    rect.top   = 0;
    rect.right = rect.left + Dx;
    rect.bottom= rect.top  + Dy;
    okSetTargetRect(hBoard, VIDEO, &rect);

    rect.left  = winOrgPoint.x + x;
    rect.top   = winOrgPoint.y + y;
    rect.right = rect.left + Dx;
    rect.bottom= rect.top  + Dy;
    okSetTargetRect(hBoard, SCREEN, &rect);

    if (bActive==1)
       okCaptureToScreen(hBoard);
}

void CCapture::CaptToVideo(int port)
{
    BOOL   bCaptureMark;
    MSG    msg;

    if (port!=Port_n) {
       okSetVideoParam(hBoard,VIDEO_SOURCECHAN,port);
       Port_n=port;
    }

    ShowCursor( FALSE );
    bActive=1;
    if ( okCaptureToScreen(hBoard)<=0 ) {
    	 ShowCursor(TRUE);
    	 return;
    }
    bActive=0;

    bCaptureMark = TRUE;
    while (bCaptureMark == TRUE) {
    	 PeekMessage(&msg, NULL, 0, 0, PM_REMOVE);
		 if (msg.message == WM_KEYDOWN||
			 msg.message == WM_LBUTTONDOWN||
			 msg.message == WM_NCLBUTTONDOWN)
    		bCaptureMark = FALSE;
    }

    okStopCapture(hBoard);
    ShowCursor( TRUE );
}

void CCapture::CaptToBuffer(int port)
{
    if (port!=Port_n) {
       okSetVideoParam(hBoard,VIDEO_SOURCECHAN,port);
       Port_n=port;
    }

    okCaptureTo(hBoard,BUFFER,0,1);
    okGetCaptureStatus(hBoard,1);
    Sleep(40);
}

void CCapture::CaptPause(void)
{
   if(bActive==1)
      okStopCapture(hBoard);
}

void CCapture::CaptStop(void)
{
   if(bActive==1)
      okStopCapture(hBoard);
   bActive=0;
}

void CCapture::VideoToDib(BYTE* lpbits,int Dx,int Dy,int Bits)
{
    BLOCKINFO		blk;

    blk.lpBits   = lpbits;
    blk.iWidth   = (short) Dx;
    blk.iHeight  =-(short) Dy; //!!!to invert y
    blk.iBitCount= Bits;
    okConvertRect(hBoard,(TARGET)&blk,0,SCREEN,0,1);
}

void CCapture::BufferToDib(BYTE* lpbits,int Dx,int Dy,int Bits)
{
    BLOCKINFO		blk;

    blk.lpBits   = lpbits;
    blk.iWidth   = (short) Dx;
    blk.iHeight  =-(short) Dy; //!!!to invert y
    blk.iBitCount= Bits;
    okConvertRect(hBoard,(TARGET)&blk,0,BUFFER,0,1);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -