?? staticex.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__;/////////////////////////////////////////////////////////////////////////////// CStaticExint CStaticEx::m_staticCounts = 0; BOOL CStaticEx::m_bPalInited = FALSE;CPalette CStaticEx::m_palFor8Bit;CStaticEx::CStaticEx(){ //缺省構造函數(shù)保證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; //初始化回放顯示參數(shù) m_iCurFrame = 0; m_dwLineAddrOffset = 0; m_iImageSize = 0; m_iFrameNum = 0; m_pbminfo = NULL; //m_iOpd = -1; m_staticCounts++;}CStaticEx::~CStaticEx(){ //關閉DDraw動態(tài)庫 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/**********************************************************// 函數(shù)SetDispWindow// 輸入?yún)?shù) // BOOL bEnable 是否在設置輸入和顯示窗口之前停止采集 // 說明// 當CG300處于采集到顯卡時,若重新設置輸入輸出窗口, 驅動程序會先停止采集再設置,bEnable = FALSE.// 當CG300處于采集到內存時,每次設置輸入輸出窗口, 需要停止采集再設置,bEnable = TRUE. **********************************************************/BOOL CStaticEx::SetDispWindow(BOOL bEnable){ CSize size; //根據(jù)視頻制式確定默認最大輸入窗口 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;}//這個函數(shù)不知為何不能用,我用了另一個方法,重載了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); //這里獲得顯卡的顏色數(shù) //由位深度轉換到采集數(shù)據(jù)格式 m_iDataFormat = GetSpaceFormat(m_iScrnBitsPixel); //設置圖像卡輸出的圖像數(shù)據(jù)格式 CG300SetColorSpace(m_hCG300, m_iDataFormat); //創(chuàng)建各播放器共用的調色板 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++) { //創(chuàng)建灰度調色板 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文件讀取相應鍵值,并初始化各控制參數(shù) 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); //調用動態(tài)庫獲取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函數(shù){// TODO: Add your specialized creation code here //獲取桌面位深度 CDC* pDC = GetDC(); m_iScrnBitsPixel = pDC->GetDeviceCaps(PLANES) * pDC->GetDeviceCaps(BITSPIXEL); //這里獲得顯卡的顏色數(shù) //由位深度轉換到采集數(shù)據(jù)格式 m_iDataFormat = GetSpaceFormat(m_iScrnBitsPixel); //設置圖像卡輸出的圖像數(shù)據(jù)格式 CG300SetColorSpace(m_hCG300, m_iDataFormat); //創(chuàng)建各播放器共用的調色板 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++) { //創(chuàng)建灰度調色板 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文件讀取相應鍵值,并初始化各控制參數(shù) 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); //調用動態(tài)庫獲取DirectDraw支持 m_hDDraw = OpenDDraw(m_hCG300, GetSafeHwnd()); return 0;}BOOL CStaticEx::CaptureToVGA(BOOL bEnable){ CG300Capture(m_hCG300, bEnable); SetWatchWnd(m_hDDraw, bEnable); //菜單窗口更新 linca //這兩個函數(shù)被封裝,看不到源代碼 return TRUE;}/****************************************************// 函數(shù) SetPlayBackParam// 輸入?yún)?shù):// // 說明:// 設置回放參數(shù)*****************************************************/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]; //讀取當前幀到緩沖區(qū) 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; 存放圖像數(shù)據(jù)緩沖區(qū)指針,由用戶分配 */ HDC hdc = ::GetDC(m_hWnd); SetStretchBltMode(hdc, COLORONCOLOR); //選取并實現(xiàn)灰度調色板 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; 數(shù)據(jù)源寬高 ::ReleaseDC(m_hWnd, hdc); delete []lpDest; return TRUE;}/****************************************************// 函數(shù) SetBitmapInfo// 輸入?yún)?shù):// // 說明:// 根據(jù)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 + -