www.pudn.com > GreyScalDevideDaJing.rar > GreyScalDevideDaJingView.cpp
// GreyScalDevideDaJingView.cpp : implementation of the CGreyScalDevideDaJingView class
//
#include "stdafx.h"
#include "GreyScalDevideDaJing.h"
#include "GreyScalDevideDaJingDoc.h"
#include "GreyScalDevideDaJingView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGreyScalDevideDaJingView
IMPLEMENT_DYNCREATE(CGreyScalDevideDaJingView, CView)
BEGIN_MESSAGE_MAP(CGreyScalDevideDaJingView, CView)
//{{AFX_MSG_MAP(CGreyScalDevideDaJingView)
// 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()
/////////////////////////////////////////////////////////////////////////////
// CGreyScalDevideDaJingView construction/destruction
CGreyScalDevideDaJingView::CGreyScalDevideDaJingView()
{
// TODO: add construction code here
}
CGreyScalDevideDaJingView::~CGreyScalDevideDaJingView()
{
}
BOOL CGreyScalDevideDaJingView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CGreyScalDevideDaJingView drawing
void CGreyScalDevideDaJingView::OnDraw(CDC* pDC)
{
CGreyScalDevideDaJingDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CGreyScalDevideDaJingView printing
BOOL CGreyScalDevideDaJingView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CGreyScalDevideDaJingView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CGreyScalDevideDaJingView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CGreyScalDevideDaJingView diagnostics
#ifdef _DEBUG
void CGreyScalDevideDaJingView::AssertValid() const
{
CView::AssertValid();
}
void CGreyScalDevideDaJingView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CGreyScalDevideDaJingDoc* CGreyScalDevideDaJingView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGreyScalDevideDaJingDoc)));
return (CGreyScalDevideDaJingDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGreyScalDevideDaJingView message handlers
//----------------------------------------------------------
// name: GetGreyValveDajing()
// desc: caculate grey image valve by dajing method.
//----------------------------------------------------------
int CGreyScalDevideDaJingView::GetGreyValveDajing(char *pData,int lWidth,int lHeight)
{
int i;
int j;
int nCountGreyLevel;
int nCount;
int nSumPelsArr[256];
int nTotalPels;
int nSumPels;
int nGreyTable[256];
double dTotalPoint;
long lCurrentPoint;
BYTE bGrayValue;
BYTE bGrayValueSwitch;
double dW0;
double dW1;
double dU0;
double dU1;
double dR1Temp0;
double dR1Temp0Max;
dR1Temp0Max = 0;
memset(nGreyTable, 0, 1024);
dTotalPoint = (double)lWidth * lHeight;
if(pData==NULL)
{
AfxMessageBox("图像数据为空,请读取图像数据!");
return -1;
}
//calculate 直方 image //统计各个灰度级出现的次数;
for(j=lHeight; j>0; j--)
{
for(i=0; i dR1Temp0Max)
{
dR1Temp0Max = dR1Temp0;
bGrayValueSwitch = nCountGreyLevel;
}
}
}
return bGrayValueSwitch;
}