www.pudn.com > ImgFFT.zip > Pro2View.cpp


// Pro2View.cpp : implementation of the CPro2View class 
// 
 
#include "stdafx.h" 
#include "Pro2.h" 
 
#include "Pro2Doc.h" 
#include "Pro2View.h" 
#include "CDib.h" 
#include "DialogIm.h" 
#include "math.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CPro2View 
 
IMPLEMENT_DYNCREATE(CPro2View, CView) 
 
BEGIN_MESSAGE_MAP(CPro2View, CView) 
	//{{AFX_MSG_MAP(CPro2View) 
	ON_COMMAND(ID_LINEAR, OnLinear) 
	ON_COMMAND(ID_STATISTIC, OnStatistic) 
	ON_COMMAND(ID_BALANCE, OnBalance) 
	ON_COMMAND(ID_SMOOTH, OnSmooth) 
	ON_COMMAND(ID_MIXFILTER, OnMixfilter) 
	ON_COMMAND(ID_DEFINITION, OnDefinition) 
	ON_COMMAND(ID_PICFILE, OnPicfile) 
	//}}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() 
 
///////////////////////////////////////////////////////////////////////////// 
// CPro2View construction/destruction 
 
CPro2View::CPro2View() 
{ 
	// TODO: add construction code here 
	m_nSupp=3; 
	m_nDWTCurDepth=0; 
	m_pDbImage=NULL; 
	m_nInv=0; 
	m_bOne=TRUE; 
	m_nRGBBit=3; 
	m_sFile=_T("f:\\zhj\\picture\\za.bmp"); 
 
	//the below is a strange phenomena that in CString, the character '\' is viewed as '\\', 
	//but in CString ,the successional character '\\' is viewed as '\'. It's so confusing. 
//	char u='\\'; 
//	u=m_sFile[2]; 
//	u=m_sFile[3]; 
	// 
 
} 
 
CPro2View::~CPro2View() 
{ 
} 
 
BOOL CPro2View::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return CView::PreCreateWindow(cs); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CPro2View drawing 
 
void CPro2View::OnDraw(CDC* pDC) 
{ 
	CPro2Doc* pDoc = GetDocument(); 
	ASSERT_VALID(pDoc); 
	// TODO: add draw code for native data here 
	CPoint orig; 
	CSize si; 
 
	orig.x=10; 
	orig.y=10; 
	si.cx=600; 
	si.cy=600; 
 
	Dib.Draw(pDC,orig,si); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CPro2View printing 
 
BOOL CPro2View::OnPreparePrinting(CPrintInfo* pInfo) 
{ 
	// default preparation 
	return DoPreparePrinting(pInfo); 
} 
 
void CPro2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add extra initialization before printing 
} 
 
void CPro2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add cleanup after printing 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CPro2View diagnostics 
 
#ifdef _DEBUG 
void CPro2View::AssertValid() const 
{ 
	CView::AssertValid(); 
} 
 
void CPro2View::Dump(CDumpContext& dc) const 
{ 
	CView::Dump(dc); 
} 
 
CPro2Doc* CPro2View::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPro2Doc))); 
	return (CPro2Doc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CPro2View message handlers 
////////////////////////////////////////////////////////////////////////////// 
//calculate Log2 
 
BYTE CPro2View::FloatToByte(double f) 
{ 
	if(f<=0) return (BYTE)0; 
	else if(f>=255) return (BYTE)255; 
	else return (BYTE)(f+0.5); 
} 
 
char CPro2View::FloatToChar(double f) 
{ 
	if(f>=0) 
		if(f>=127.0) 
			return (char)127; 
		else return (char)(f+0.5); 
	else 
		if(f<=-128) 
			return (char)-128; 
		else return -(char)(-f+0.5); 
} 
 
//************************************linear 
void CPro2View::OnLinear()  
{ 
	// TODO: Add your command handler code here 
	pFile=new CFile(m_sFile,CFile::modeReadWrite|CFile::typeBinary); 
	 
	Dib.Read(pFile); 
	Dib.MakePalette(); 
 
	Linear(&Dib,0,150,0,255); 
 
	if(m_bOne) 
	pFile->Close(); 
 
	Invalidate(); 
	 
} 
 
BOOL CPro2View::Linear(CDib* pDib,int Upper1,int Lower1,int Upper2,int Lower2) 
{ 
	int i,j; 
	int nWidth=pDib->m_lpBMIH->biWidth; 
	int nHeight=pDib->m_lpBMIH->biHeight; 
 
	switch(pDib->m_lpBMIH->biBitCount) 
	{ 
	case 24: 
		m_nRGBBit=3; 
		break; 
	case 32: 
		m_nRGBBit=4; 
		break; 
	default: 
		m_nRGBBit=3; 
	} 
 
	CSize sizeImageSave=pDib->GetDibSaveDim(); 
 
	double *pDbTemp; 
	BYTE *pBits; 
	int nRGB=0; 
 
	if(!m_pDbImage)	{ 
			m_pDbImage=new double[nWidth*nHeight]; 
			if(!m_pDbImage) return FALSE; 
 
	} 
 
	//get data of the source DIB 
	for(nRGB=0;nRGB<3;nRGB++) 
	{ 
 
	for(j=0;jm_lpImage+(nHeight-j-1)*sizeImageSave.cx+nRGB; 
		for(i=0;im_lpImage+(nHeight-j-1)*sizeImageSave.cx+nRGB; 
		for(i=0;im_lpBMIH->biWidth; 
	int nHeight=pDib->m_lpBMIH->biHeight; 
 
	switch(pDib->m_lpBMIH->biBitCount) 
	{ 
	case 24: 
		m_nRGBBit=3; 
		break; 
	case 32: 
		m_nRGBBit=4; 
		break; 
	default: 
		m_nRGBBit=3; 
	} 
 
	CSize sizeImageSave=pDib->GetDibSaveDim(); 
 
	unsigned char* pDbTemp; 
	unsigned char* pDbImage; 
	BYTE *pBits; 
	int nRGB=0; 
 
	pDbImage=new unsigned char[nWidth*nHeight]; 
 
	if(!pDbImage) return FALSE; 
 
	//get data of the source DIB 
	for(nRGB=0;nRGB<1;nRGB++) 
	{ 
 
	for(j=0;jm_lpImage+(nHeight-j-1)*sizeImageSave.cx+nRGB; 
		for(i=0;im_lpImage+(nHeight-j-1)*sizeImageSave.cx+nRGB; 
		for(i=0;iClose(); 
 
	Invalidate(); 
} 
 
//************************************Balance 
void CPro2View::OnBalance()  
{ 
	// TODO: Add your command handler code here 
 
	pFile=new CFile(m_sFile,CFile::modeReadWrite|CFile::typeBinary); 
	 
	Dib.Read(pFile); 
	Dib.MakePalette(); 
 
	Balance(&Dib); 
 
	m_Chart.DoModal(); 
 
	pFile->Close(); 
	Invalidate(); 
} 
 
BOOL CPro2View::Balance(CDib* pDib) 
{ 
	int i,j; 
	int m,n; 
	int nWidth=pDib->m_lpBMIH->biWidth; 
	int nHeight=pDib->m_lpBMIH->biHeight; 
 
	switch(pDib->m_lpBMIH->biBitCount) 
	{ 
	case 24: 
		m_nRGBBit=3; 
		break; 
	case 32: 
		m_nRGBBit=4; 
		break; 
	default: 
		m_nRGBBit=3; 
	} 
 
	CSize sizeImageSave=pDib->GetDibSaveDim(); 
 
	unsigned char* pDbTemp; 
	unsigned char* pDbImage; 
	BYTE *pBits; 
	int nRGB=0; 
 
	pDbImage=new unsigned char[nWidth*nHeight]; 
 
	if(!pDbImage) return FALSE; 
 
	//get data of the source DIB 
	for(nRGB=0;nRGB<1;nRGB++) 
	{ 
 
	for(j=0;jm_lpImage+(nHeight-j-1)*sizeImageSave.cx+nRGB; 
		for(i=0;im_lpImage+(nHeight-j-1)*sizeImageSave.cx+nRGB; 
		for(i=0;iClose(); 
	Invalidate(); 
	 
} 
 
BOOL CPro2View::GeneralTemplate(CDib* pDib,int nTempWidth,int nTempHeight,int nTempCenX,int nTempCenY,double* pdbTemp,double dbCoef) 
{ 
	int i,j; 
	int nWidth=pDib->m_lpBMIH->biWidth; 
	int nHeight=pDib->m_lpBMIH->biHeight; 
 
	switch(pDib->m_lpBMIH->biBitCount) 
	{ 
	case 24: 
		m_nRGBBit=3; 
		break; 
	case 32: 
		m_nRGBBit=4; 
		break; 
	default: 
		m_nRGBBit=3; 
	} 
 
	CSize sizeImageSave=pDib->GetDibSaveDim(); 
 
	unsigned char* pDbTemp; 
	unsigned char* pDbImage; 
	BYTE *pBits; 
	int nRGB=0; 
 
	pDbImage=new unsigned char[nWidth*nHeight]; 
 
	if(!pDbImage) return FALSE; 
 
	//get data of the source DIB 
	for(nRGB=0;nRGB<3;nRGB++) 
	{ 
 
	for(j=0;jm_lpImage+(nHeight-j-1)*sizeImageSave.cx+nRGB; 
		for(i=0;i255) 
				*lpDst=255; 
			else 
				*lpDst=(unsigned char)(dbResult+0.5); 
		} 
	} 
 
 
	for(j=0;jm_lpImage+(nHeight-j-1)*sizeImageSave.cx+nRGB; 
		for(i=0;iClose(); 
	Invalidate(); 
} 
 
BOOL CPro2View::Filter(CDib* pDib) 
{ 
	CPro2Doc* pDoc=GetDocument(); 
 
	int i,j; 
	int m,n; 
 
	double nRadius=100.0; 
	int nGet=0; 
	double H=0.0; 
 
	int nWidth=pDib->m_lpBMIH->biWidth; 
	int nHeight=pDib->m_lpBMIH->biHeight; 
 
	switch(pDib->m_lpBMIH->biBitCount) 
	{ 
	case 24: 
		m_nRGBBit=3; 
		break; 
	case 32: 
		m_nRGBBit=4; 
		break; 
	default: 
		m_nRGBBit=3; 
	} 
 
	CSize sizeImageSave=pDib->GetDibSaveDim(); 
 
	double *pDbTemp; 
	BYTE *pBits; 
	int nRGB=0; 
 
	if(!m_pDbImage)	{ 
			m_pDbImage=new double[nWidth*nHeight]; 
			if(!m_pDbImage) return FALSE; 
 
	} 
 
	//get data of the source DIB 
	for(nRGB=0;nRGB<3;nRGB++) 
	{ 
 
	for(j=0;jm_lpImage+(nHeight-j-1)*sizeImageSave.cx+nRGB; 
		for(i=0;i* pCTData; 
	complex* pCFData; 
 
	pCTData=new complex[nTransWidth*nTransHeight]; 
	pCFData=new complex[nTransWidth*nTransHeight]; 
 
	for(m=0;m(0,0); 
		} 
	} 
 
	for(m=0;m(pDbTemp[n],0); 
		} 
	} 
 
	//FFT 
	pDoc->FFT_2D(pCTData,nWidth,nHeight,pCFData); 
 
	//apply the Butterworth filter. 
	for(m=0;m(H*pCFData[m*nTransWidth+n].real(),H*pCFData[m*nTransWidth+n].imag()); 
		} 
	} 
 
	//IFFT 
	pDoc->IFFT_2D(pCFData,nWidth,nHeight,pCTData); 
 
	double dTemp; 
 
	for(m=0;mm_lpImage+(nHeight-j-1)*sizeImageSave.cx+nRGB; 
		for(i=0;iClose(); 
	Invalidate(); 
	 
} 
 
BOOL CPro2View::DefinFun1(CDib* pDib) 
{ 
	int i,j; 
	int nWidth=pDib->m_lpBMIH->biWidth; 
	int nHeight=pDib->m_lpBMIH->biHeight; 
 
	switch(pDib->m_lpBMIH->biBitCount) 
	{ 
	case 24: 
		m_nRGBBit=3; 
		break; 
	case 32: 
		m_nRGBBit=4; 
		break; 
	default: 
		m_nRGBBit=3; 
	} 
 
	CSize sizeImageSave=pDib->GetDibSaveDim(); 
 
	double* pDbTemp; 
	double* pDbImage; 
	BYTE *pBits; 
	int nRGB=0; 
 
	pDbImage=new double[nWidth*nHeight]; 
 
	if(!pDbImage) return FALSE; 
 
	//get data of the source DIB 
 
	for(j=0;jm_lpImage+(nHeight-j-1)*sizeImageSave.cx; 
		for(i=0;i