Video DemoView.cpp
上传用户:smdfuse
上传日期:2015-11-06
资源大小:98k
文件大小:6k
- // Video DemoView.cpp : implementation of the CVideoDemoView class
- //
- #include "stdafx.h"
- #include "Video Demo.h"
- #include "Video DemoDoc.h"
- #include "Video DemoView.h"
- #include "colortrans.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CVideoDemoView
- IMPLEMENT_DYNCREATE(CVideoDemoView, CView)
- BEGIN_MESSAGE_MAP(CVideoDemoView, CView)
- //{{AFX_MSG_MAP(CVideoDemoView)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CVideoDemoView construction/destruction
- CVideoDemoView::CVideoDemoView()
- {
- // TODO: add construction code here
- this->data = NULL;
- this->outputAvailable = false;
- }
- CVideoDemoView::~CVideoDemoView()
- {
- if(this->data != NULL)
- delete[] data; // 释放输出缓冲
- }
- BOOL CVideoDemoView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CVideoDemoView drawing
- /////////////////////////////////////////////////////////////////////////////
- // CVideoDemoView printing
- BOOL CVideoDemoView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
- void CVideoDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
- void CVideoDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
- /////////////////////////////////////////////////////////////////////////////
- // CVideoDemoView diagnostics
- #ifdef _DEBUG
- void CVideoDemoView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CVideoDemoView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- CVideoDemoDoc* CVideoDemoView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CVideoDemoDoc)));
- return (CVideoDemoDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CVideoDemoView message handlers
- /************************************************************************/
- /* 绘图函数 */
- /************************************************************************/
- void CVideoDemoView::OnDraw(CDC* pDC)
- {
- if(outputAvailable) // 允许输出图像数据
- {
- pDC->SetStretchBltMode(STRETCH_DELETESCANS);
- StretchDIBits(pDC->m_hDC,0,0,imgWidth,imgHeight,
- 0,0,imgWidth,imgHeight,
- data, &bitmapInfo, DIB_RGB_COLORS,SRCCOPY);
- }
- }
- /************************************************************************/
- /* OnActiveView */
- /* 当视图切换时改变当前数据 */
- /************************************************************************/
- void CVideoDemoView::OnActivateView(BOOL bActivate,CView* pActivateView,CView* pDeactiveView)
- {
- if(bActivate == TRUE)
- {
- CVideoDemoDoc *doc = (CVideoDemoDoc*)GetDocument();
-
- theApp.lastImageData = theApp.curImageData; // 设置上一次的数据位置
- theApp.curImageData = doc->id; // 设置当前的doc
- if(doc->id != NULL)
- TRACE("Change View Index : %dn",doc->id->index);
- else
- TRACE("Change View Index NULL IDn");
- }
- }
- /************************************************************************/
- /* 允许输出数据 */
- /************************************************************************/
- void CVideoDemoView::RefreshData()
- {
- // 自动获取图像数据源
- CVideoDemoDoc* pDoc = GetDocument();
- //ASSERT_VALID(pDoc);
- // 显示图像
- ImageData *id = pDoc->id; // 图像数据
-
- if(data != NULL)
- delete[] data;
- data = new unsigned char[id->imgWidth * id->imgHeight * 3];
- ColorTrans ct;
- switch(id->format)
- {
- case IMAGE_FORMAT_GRAY8:
- // 8位灰度图像
- ct.gray2RGB2(id->data,data,id->imgWidth,id->imgHeight);
- this->imgWidth = id->imgWidth;
- this->imgHeight = id->imgHeight;
- memset(&bitmapInfo,0,sizeof(BITMAPINFO));
- bitmapInfo.bmiHeader.biHeight = (LONG)imgHeight;
- bitmapInfo.bmiHeader.biWidth = (LONG)imgWidth;
- bitmapInfo.bmiHeader.biSizeImage = (LONG)imgWidth * (LONG)imgHeight * 3;
- bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- bitmapInfo.bmiHeader.biBitCount = 24;
- bitmapInfo.bmiHeader.biCompression = 0;
- bitmapInfo.bmiHeader.biPlanes = 1;
- outputAvailable = true; //输出允许
- break;
- case IMAGE_FORMAT_RGB24:
- memcpy(this->data,id->data,id->imgWidth * id->imgHeight * sizeof(unsigned char) * 3);
- this->imgWidth = id->imgWidth;
- this->imgHeight = id->imgHeight;
- bitmapInfo.bmiHeader.biHeight = (LONG)imgHeight;
- bitmapInfo.bmiHeader.biWidth = (LONG)imgWidth;
- bitmapInfo.bmiHeader.biSizeImage = (LONG)imgWidth * (LONG)imgHeight * 3;
- bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
- bitmapInfo.bmiHeader.biBitCount = 24;
- bitmapInfo.bmiHeader.biCompression = 0;
- bitmapInfo.bmiHeader.biPlanes = 1;
- this->outputAvailable = true;
- break;
- default:
- this->outputAvailable = false; // 输出禁止
- }
- this->Invalidate(false);
- }