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

📄 staticex.cpp

📁 This paper provides video capture and category CcaptureVideo example, in Win2K DirectX9 SDK VC6 thro
💻 CPP
字号:
// StaticEx.cpp : implementation file//#include "stdafx.h"#include "Console.h"#include "StaticEx.h"#ifdef _DEBUG#define new DEBUG_NEW#undef THIS_FILEstatic char THIS_FILE[] = __FILE__;#endif/////////////////////////////////////////////////////////////////////////////// CStaticExint CStaticEx::m_staticCounts = 0;           BOOL CStaticEx::m_bPalInited = FALSE;CPalette CStaticEx::m_palFor8Bit;CStaticEx::CStaticEx(){	//缺省构造函数保证CG300卡不被初始化	m_hCG300 = NULL;	m_hDDraw = NULL;}CStaticEx::CStaticEx(int iNum){	//判断卡号是否越界	if ((iNum < 1) || (iNum > MAX_CARD_NUMBER))	{		m_hCG300 = NULL;		m_bOpen = FALSE;		m_iNum = 0;	}	else	{		m_hCG300 = BeginCG300(iNum);              //打开图像卡 !linca		if ((m_hCG300 == 0) || (m_hCG300 == 1) || (m_hCG300 == 2) ||			(m_hCG300 == 3) || (m_hCG300 == 0xffffffff))		{			m_hCG300 = NULL;			m_bOpen = FALSE;			m_iNum = 0;		}		else		{			m_bOpen = TRUE;			m_iNum = iNum;		}	}		m_hDDraw = NULL;	m_iShowMode = CLIP;	m_iVideoStand = PAL;	m_iFormMode = FRAME;	m_iStoreFmt = FRAME;	//初始化回放显示参数	m_iCurFrame = 0;	m_dwLineAddrOffset = 0;	m_iImageSize = 0;	m_iFrameNum = 0;	m_pbminfo = NULL;	//m_iOpd = -1;	m_staticCounts++;}CStaticEx::~CStaticEx(){	//关闭DDraw动态库	CloseDDraw(m_hDDraw);	//关闭图像卡			CG300Capture(m_hCG300, FALSE);		EndCG300(m_hCG300);	}BEGIN_MESSAGE_MAP(CStaticEx, CStatic)	//{{AFX_MSG_MAP(CStaticEx)		// NOTE - the ClassWizard will add and remove mapping macros here.	//}}AFX_MSG_MAPEND_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////// CStaticEx message handlers/**********************************************************// 函数SetDispWindow// 输入参数 //			BOOL bEnable					是否在设置输入和显示窗口之前停止采集															// 说明//		当CG300处于采集到显卡时,若重新设置输入输出窗口,		驱动程序会先停止采集再设置,bEnable = FALSE.//		当CG300处于采集到内存时,每次设置输入输出窗口,		需要停止采集再设置,bEnable = TRUE.										**********************************************************/BOOL CStaticEx::SetDispWindow(BOOL bEnable){			CSize size;	//根据视频制式确定默认最大输入窗口	switch(m_iVideoStand)	{	case PAL:		size.cx = 768;	size.cy = 576;		break;	case NTSC:		size.cx = 640;	size.cy = 480;		break;	default:		size.cx = 768;	size.cy = 576;		break;	}	//if (bEnable == FALSE)//	{//		CG300Capture(m_hCG300, FALSE);//	}		int iHeight, iWidth;	iWidth = m_rectVideo.Width();	if (m_iFormMode == FRAME)	{		iHeight = m_rectVideo.Height();	}	else	{		iHeight = m_rectVideo.Height() * 2;			//场方式特殊处理		if (iHeight > 576)				//高度最大不能超过576		{			iHeight = 576;		}	}	//防止宽高 <= 1 的异常情况	if (iHeight <= 1)	{		iHeight = 100;	}	if (iWidth <= 1 )	{		iWidth = 100;	}	if (m_iShowMode == 0)	{		//比例模式		CG300SetInpVideoWindow(m_hCG300, 0, 0, size.cx, size.cy);	}	else	{		//裁减模式	CG300SetInpVideoWindow(m_hCG300, 0, 0, iWidth, iHeight);	}	CG300SetDispWindow(m_hCG300, m_rectVideo.left-3, m_rectVideo.top-3, 		               iWidth, iHeight);			return TRUE;}//这个函数不知为何不能用,我用了另一个方法,重载了OnCreate(),解决了问题,真聪明阿int CStaticEx::OnCreate(LPCREATESTRUCT lpCreateStruct) {	if (CStatic::OnCreate(lpCreateStruct) == -1)		return -1;	// TODO: Add your specialized creation code here	//获取桌面位深度	CDC* pDC = GetDC();	m_iScrnBitsPixel = pDC->GetDeviceCaps(PLANES) * pDC->GetDeviceCaps(BITSPIXEL); //这里获得显卡的颜色数	//由位深度转换到采集数据格式	m_iDataFormat = GetSpaceFormat(m_iScrnBitsPixel);	//设置图像卡输出的图像数据格式	CG300SetColorSpace(m_hCG300, m_iDataFormat);	//创建各播放器共用的调色板	if (m_bPalInited == FALSE)	{		LOGPALETTE *lpLogPal;		BYTE buffer[2048];		lpLogPal = (LOGPALETTE *)buffer;		lpLogPal->palNumEntries = pDC->GetDeviceCaps(SIZEPALETTE);		lpLogPal->palVersion = 0x300;		for (int k = 0; k < (int)(lpLogPal->palNumEntries); k++)		{			//创建灰度调色板			lpLogPal->palPalEntry[k].peRed = (BYTE)k + 10;			lpLogPal->palPalEntry[k].peGreen = (BYTE)k + 10;			lpLogPal->palPalEntry[k].peBlue = (BYTE)k + 10;			lpLogPal->palPalEntry[k].peFlags = 0;		}		m_palFor8Bit.CreatePalette(lpLogPal);				m_bPalInited = TRUE;	}	ReleaseDC(pDC);	//从INI文件读取相应键值,并初始化各控制参数	CString str;	str.Format("Source%d", m_iNum);	m_iSource     = GetPrivateProfileInt( "Video Parameter", str, 1, "dhvcard.ini" );	str.Format("Brightness%d", m_iNum);	m_iBrightness = GetPrivateProfileInt( "Video Parameter", str, 128, "dhvcard.ini" );	str.Format("Contrast%d", m_iNum);	m_iContrast   = GetPrivateProfileInt( "Video Parameter", str, 128, "dhvcard.ini" );	str.Format("Hue%d", m_iNum);	m_iHue        = GetPrivateProfileInt( "Video Parameter", str, 128, "dhvcard.ini" );	str.Format("Saturation%d", m_iNum);	m_iSaturation = GetPrivateProfileInt( "Video Parameter", str, 128, "dhvcard.ini" );	str.Format("LoPLLFreq%d", m_iNum);	m_iPll        = GetPrivateProfileInt("Video Parameter", str, 245, "dhvcard.ini");	str.Format("CryOSC%d", m_iNum);    m_iCryc       = GetPrivateProfileInt( "Video Parameter", str, 1, "dhvcard.ini" );	//设置默认视频源路和图像属性	CG300SetADParam(m_hCG300, AD_SOURCE, m_iSource);	CG300SetADParam(m_hCG300, AD_BRIGHTNESS, m_iBrightness);	CG300SetADParam(m_hCG300, AD_CONTRAST, m_iContrast);	CG300SetADParam(m_hCG300, AD_HUE, m_iHue);	CG300SetADParam(m_hCG300, AD_SATURATION, m_iSaturation);	//设置图像卡默认晶振	CG300SelectCryOSC(m_hCG300, m_iCryc);		//调用动态库获取DirectDraw支持	m_hDDraw = OpenDDraw(m_hCG300, GetSafeHwnd());	return 0;}BYTE CStaticEx::GetSpaceFormat(int iBitsPixel) const{	BYTE bySpaceFormat;	switch(iBitsPixel)	{	case 8:		bySpaceFormat = Limited8Bit;		break;	case 16:		bySpaceFormat = RGB565;		break;	case 24:		bySpaceFormat = RGB888;		break;	case 32:		bySpaceFormat = RGB8888;		break;	}		return bySpaceFormat;}int CStaticEx::OnCreate()//这是我重载的OnCreate函数{// TODO: Add your specialized creation code here	//获取桌面位深度	CDC* pDC = GetDC();	m_iScrnBitsPixel = pDC->GetDeviceCaps(PLANES) * pDC->GetDeviceCaps(BITSPIXEL); //这里获得显卡的颜色数	//由位深度转换到采集数据格式	m_iDataFormat = GetSpaceFormat(m_iScrnBitsPixel);	//设置图像卡输出的图像数据格式	CG300SetColorSpace(m_hCG300, m_iDataFormat);	//创建各播放器共用的调色板	if (m_bPalInited == FALSE)	{		LOGPALETTE *lpLogPal;		BYTE buffer[2048];		lpLogPal = (LOGPALETTE *)buffer;		lpLogPal->palNumEntries = pDC->GetDeviceCaps(SIZEPALETTE);		lpLogPal->palVersion = 0x300;		for (int k = 0; k < (int)(lpLogPal->palNumEntries); k++)		{			//创建灰度调色板			lpLogPal->palPalEntry[k].peRed = (BYTE)k + 10;			lpLogPal->palPalEntry[k].peGreen = (BYTE)k + 10;			lpLogPal->palPalEntry[k].peBlue = (BYTE)k + 10;			lpLogPal->palPalEntry[k].peFlags = 0;		}		m_palFor8Bit.CreatePalette(lpLogPal);				m_bPalInited = TRUE;	}	ReleaseDC(pDC);	//从INI文件读取相应键值,并初始化各控制参数	CString str;	str.Format("Source%d", m_iNum);	m_iSource     = GetPrivateProfileInt( "Video Parameter", str, 1, "dhvcard.ini" );	str.Format("Brightness%d", m_iNum);	m_iBrightness = GetPrivateProfileInt( "Video Parameter", str, 128, "dhvcard.ini" );	str.Format("Contrast%d", m_iNum);	m_iContrast   = GetPrivateProfileInt( "Video Parameter", str, 128, "dhvcard.ini" );	str.Format("Hue%d", m_iNum);	m_iHue        = GetPrivateProfileInt( "Video Parameter", str, 128, "dhvcard.ini" );	str.Format("Saturation%d", m_iNum);	m_iSaturation = GetPrivateProfileInt( "Video Parameter", str, 128, "dhvcard.ini" );	str.Format("LoPLLFreq%d", m_iNum);	m_iPll        = GetPrivateProfileInt("Video Parameter", str, 245, "dhvcard.ini");	str.Format("CryOSC%d", m_iNum);    m_iCryc       = GetPrivateProfileInt( "Video Parameter", str, 1, "dhvcard.ini" );	//设置默认视频源路和图像属性	CG300SetADParam(m_hCG300, AD_SOURCE, m_iSource);	CG300SetADParam(m_hCG300, AD_BRIGHTNESS, m_iBrightness);	CG300SetADParam(m_hCG300, AD_CONTRAST, m_iContrast);	CG300SetADParam(m_hCG300, AD_HUE, m_iHue);	CG300SetADParam(m_hCG300, AD_SATURATION, m_iSaturation);	//设置图像卡默认晶振	CG300SelectCryOSC(m_hCG300, m_iCryc);		//调用动态库获取DirectDraw支持	m_hDDraw = OpenDDraw(m_hCG300, GetSafeHwnd());	return 0;}BOOL CStaticEx::CaptureToVGA(BOOL bEnable){	CG300Capture(m_hCG300, bEnable);      		SetWatchWnd(m_hDDraw, bEnable);         //菜单窗口更新 linca											//这两个函数被封装,看不到源代码	return TRUE;}/****************************************************//	函数 SetPlayBackParam//	输入参数://			//  说明://			设置回放参数*****************************************************/BOOL CStaticEx::SetPlayBackParam(DWORD dwLineAddrOffset, int iFrameNum, 				int iImageSize, CSize szSource){	BOOL bVal;	if (dwLineAddrOffset >=0 && iFrameNum >= 0 && 		iImageSize >= 0 && szSource.cx >= 0 && szSource.cy >= 0)	{		m_dwLineAddrOffset = dwLineAddrOffset;		m_iFrameNum = iFrameNum;		m_iImageSize = iImageSize;		m_szSource = szSource;		m_iCurFrame = 0;       //初始化当前帧为0				int iBMBit;		if (m_iDataFormat == Limited8Bit || m_iDataFormat == All8Bit)		{			iBMBit = 8;		}		else		{			iBMBit = 24;		}		bVal = SetBitmapInfo(m_szSource, iBMBit);	}	else	{		bVal = FALSE;	}	return bVal;}BOOL CStaticEx::Display(){    CRect rect;	rect = m_rectVideo;	ScreenToClient(rect);//	char *lpDest = new char[768 * 576 * 4];	char *lpDest = new char[m_iImageSize];	//读取当前帧到缓冲区	DWORD dwMemSize, dwPhysMem, dwHandle, dwLineAddr;	StaticMemAlloc(&dwMemSize, &dwPhysMem, &dwHandle, &dwLineAddr);	dwMemSize *= 4 * 1024;	CG300ReadFromMem(m_hCG300, (char *)dwLineAddr + m_dwLineAddrOffset,						m_iImageSize , m_iCurFrame, lpDest);	/*HCG300 hcg300; 图像卡句柄。       char *lpSourBuf; 所申请到的内存起始线性地址。       DWORD dwMemSize; 内存的大小。       WORD Number; 所要读取的图像的编号,从第0开始。       char *lpDestBuf; 存放图像数据缓冲区指针,由用户分配 */	HDC hdc = ::GetDC(m_hWnd);	SetStretchBltMode(hdc, COLORONCOLOR);	//选取并实现灰度调色板	if (m_iDataFormat == Limited8Bit || m_iDataFormat == All8Bit)	{		SelectPalette(hdc, (HPALETTE)CStaticEx::m_palFor8Bit.GetSafeHandle(), FALSE);		RealizePalette(hdc);	}		StretchDIBits(hdc,rect.left, rect.top,rect.Width(), rect.Height(),0, 0,				m_szSource.cx, m_szSource.cy, lpDest, m_pbminfo, 				DIB_RGB_COLORS, SRCCOPY);	//	CSize m_szSource;	数据源宽高		::ReleaseDC(m_hWnd, hdc);		delete []lpDest;		return TRUE;}/****************************************************//	函数 SetBitmapInfo//	输入参数://			//  说明://			根据size和IBMBit设置BITMAPINFO结构*****************************************************/BOOL CStaticEx::SetBitmapInfo(const CSize &size, int iBMBit){	if(iBMBit != 8)	{		iBMBit = 24;	}	m_pbminfo = (BITMAPINFO *)m_byBuffer;	m_pbminfo->bmiHeader.biBitCount = iBMBit;	if (iBMBit == 8)	{		m_pbminfo->bmiHeader.biClrImportant = 256;		m_pbminfo->bmiHeader.biClrUsed = 256;	}	else	{		m_pbminfo->bmiHeader.biClrImportant = 0;		m_pbminfo->bmiHeader.biClrUsed = 0;	}		m_pbminfo->bmiHeader.biCompression = BI_RGB;	m_pbminfo->bmiHeader.biHeight = size.cy;	m_pbminfo->bmiHeader.biPlanes = 1;	m_pbminfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);	m_pbminfo->bmiHeader.biSizeImage = 0;	m_pbminfo->bmiHeader.biWidth = size.cx;	m_pbminfo->bmiHeader.biXPelsPerMeter = 0;	m_pbminfo->bmiHeader.biYPelsPerMeter = 0;	if (iBMBit == 8)	{		for( int k = 0; k < 256; ++k)		{			//设置灰度调色板			m_pbminfo->bmiColors[k].rgbBlue = (BYTE)k;			m_pbminfo->bmiColors[k].rgbGreen = (BYTE)k;			m_pbminfo->bmiColors[k].rgbRed = (BYTE)k;			m_pbminfo->bmiColors[k].rgbReserved = 0;		}	}	return TRUE;}

⌨️ 快捷键说明

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