Click here to Skip to main content
Click here to Skip to main content
 
Add your own
alternative version

High performance computing from C++ to MMX

, 30 Jul 2003
Boosting you application performance to the optimum by using hardware acceleration.
// MMXDemoView.cpp : implementation of the CMMXDemoView class
//

#include "stdafx.h"
#include "MMXDemo.h"

#include "MMXDemoDoc.h"
#include "MMXDemoView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMMXDemoView

IMPLEMENT_DYNCREATE(CMMXDemoView, CScrollView)

BEGIN_MESSAGE_MAP(CMMXDemoView, CScrollView)
	//{{AFX_MSG_MAP(CMMXDemoView)
		// 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
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMMXDemoView construction/destruction

CMMXDemoView::CMMXDemoView()
{
	// TODO: add construction code here
	m_pImg = NULL;

	DWORD bitmapInfoSize,i;

	// Bitmap info structure for the image
	bitmapInfoSize = sizeof(BITMAPINFO) + 255*sizeof(RGBQUAD);
	m_pBmiImage = (BITMAPINFO*)new BYTE[bitmapInfoSize];

	m_pBmiImage->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
	m_pBmiImage->bmiHeader.biPlanes = 1;
	m_pBmiImage->bmiHeader.biBitCount = 8;
	m_pBmiImage->bmiHeader.biCompression = BI_RGB;
	m_pBmiImage->bmiHeader.biSizeImage = 0;
	m_pBmiImage->bmiHeader.biXPelsPerMeter = 0;
	m_pBmiImage->bmiHeader.biYPelsPerMeter = 0;
	m_pBmiImage->bmiHeader.biClrUsed = 0;
	m_pBmiImage->bmiHeader.biClrImportant = 0;

	m_pBmiImage->bmiHeader.biWidth = 0;
	m_pBmiImage->bmiHeader.biHeight = 0;

	for (i = 0 ; i < 256 ; i++) {
		m_pBmiImage->bmiColors[i].rgbBlue = (BYTE)i;
		m_pBmiImage->bmiColors[i].rgbGreen = (BYTE)i;
		m_pBmiImage->bmiColors[i].rgbRed = (BYTE)i;
		m_pBmiImage->bmiColors[i].rgbReserved = 0;
	}

}

CMMXDemoView::~CMMXDemoView()
{
}

BOOL CMMXDemoView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CScrollView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMMXDemoView drawing

void CMMXDemoView::OnDraw(CDC* pDC)
{
	CMMXDemoDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);

	if (m_pImg == NULL)
		return;

	// Set bitmap header info
	m_pBmiImage->bmiHeader.biWidth = pDoc->m_iWidth;
	m_pBmiImage->bmiHeader.biHeight = -pDoc->m_iHeight;

	// Display
	SetDIBitsToDevice(pDC->GetSafeHdc(),
					  0, 0, pDoc->m_iWidth, pDoc->m_iHeight,
					  0, 0, 0, pDoc->m_iHeight,
					  m_pImg, m_pBmiImage, DIB_RGB_COLORS);

	// Display timing
	CString szTime;
	szTime.Format("Time = %.3fms", pDoc->m_el.m_dElapsed*1000);
	pDC->TextOut(10, 10, szTime);
}

void CMMXDemoView::OnInitialUpdate()
{
	CMMXDemoDoc* pDoc = GetDocument();
	CScrollView::OnInitialUpdate();

	CSize sizeTotal;
	// TODO: calculate the total size of this view
	sizeTotal.cx = pDoc->m_iWidth;
	sizeTotal.cy = pDoc->m_iHeight;
	
	// Select the source buffer pointer
	m_pImg = pDoc->m_pImg;

	SetScrollSizes(MM_TEXT, sizeTotal);
}

/////////////////////////////////////////////////////////////////////////////
// CMMXDemoView diagnostics

#ifdef _DEBUG
void CMMXDemoView::AssertValid() const
{
	CScrollView::AssertValid();
}

void CMMXDemoView::Dump(CDumpContext& dc) const
{
	CScrollView::Dump(dc);
}

CMMXDemoDoc* CMMXDemoView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMMXDemoDoc)));
	return (CMMXDemoDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMMXDemoView message handlers

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Vincent Leong77
Web Developer Cortex Imaging
Malaysia Malaysia
Interest in computer vision, biometrics, image processing & software optimizations. Known language C/C++, VC++ MFC, Win32, COM/ATL, Assembly.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141220.1 | Last Updated 31 Jul 2003
Article Copyright 2003 by Vincent Leong77
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid