www.pudn.com > wavelet-vc++6.rar > CS97.cpp


// CS97.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "wavelet.h" 
#include "MainFrm.h" 
#include "waveletView.h" 
#include "CS97.h" 
#include "CS96.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
#define DD   8 
 
///////////////////////////////////////////////////////////////////////////// 
// CCS97 dialog 
float h7[DD]={(float)0.1629,(float)0.50547,(float)0.4461, 
         (float)-0.01979,(float)-0.13225,(float)0.02181, 
         (float)0.023252,(float)-0.00749}; //sum h[n]=1 
 
float g7[DD]={(float)0.00749,(float)0.023252,(float)-0.02181, 
             (float)-0.13225,(float)0.01979,(float)0.4461, 
                            (float)-0.50547,(float)0.1629};  
float hi[DD],gi[DD]; 
 
CCS97::CCS97(CWnd* pParent /*=NULL*/) 
	: CDialog(CCS97::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CCS97) 
	m_col = 0; 
	m_row = 0; 
	m_infile = _T(""); 
	m_midfile = _T(""); 
	m_outfile = _T(""); 
	//}}AFX_DATA_INIT 
} 
 
 
void CCS97::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CCS97) 
	DDX_Text(pDX, IDC_IMAGECOL, m_col); 
	DDX_Text(pDX, IDC_IMAGEROW, m_row); 
	DDX_Text(pDX, IDC_INFILE, m_infile); 
	DDX_Text(pDX, IDC_MIDFILE, m_midfile); 
	DDX_Text(pDX, IDC_OUTFILE, m_outfile); 
	//}}AFX_DATA_MAP 
} 
 
 
BEGIN_MESSAGE_MAP(CCS97, CDialog) 
	//{{AFX_MSG_MAP(CCS97) 
	ON_BN_CLICKED(IDC_FILELOOK97, OnFilelook97) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CCS97 message handlers 
 
void CCS97::mainprogram() 
{ 
    unsigned char *buf; 
	unsigned char *pm; 
	CFile inputfile; 
	CFile outputfile; 
	CFile mfile; 
   if(!inputfile.Open((LPCTSTR)m_infile,CFile::modeRead)) 
   { 
	   str.Format("Can't open %s!",m_infile); 
	   AfxMessageBox(str); 
	   return; 
   } 
   if(!outputfile.Open((LPCTSTR)m_outfile,CFile::modeCreate|CFile::modeReadWrite)) 
   { 
	   str.Format("Can't open %s!",m_outfile); 
	   AfxMessageBox(str); 
	   return; 
   } 
   if(!mfile.Open((LPCTSTR)m_midfile,CFile::modeCreate|CFile::modeReadWrite)) 
   { 
	   str.Format("Can't open %s!",m_midfile); 
	   AfxMessageBox(str); 
	   return; 
   } 
   image=new float[m_row*m_col*sizeof(float)]; 
   if(!image) 
   { 
	   AfxMessageBox("Memory Error!"); 
	   return; 
   } 
   pm=new unsigned char[m_row*m_col*sizeof(char)]; 
   if(!pm) 
   { 
	   AfxMessageBox("pm Error!"); 
	   return; 
   } 
   buf=new unsigned char[m_row*m_col*sizeof(float)]; 
   if(!buf) 
   { 
	   AfxMessageBox("Buffer Error!"); 
	   return; 
   } 
   for(i=0;iGetMainWnd(); 
   CWaveletView* pView=(CWaveletView*)pFrame->GetActiveView(); 
   CDC* dc=pView->GetDC(); 
 
   xs=(int)m_col; 
   ys=(int)m_row; 
   coef();    
   wt(xs,ys,m_col,m_row,image); 
   str.Format("First level wavelet has finished xs,ys=%d,%d!",xs,ys); 
   dc->TextOut(150,50,str); 
 
   xs=xs/2; 
   ys=ys/2; 
   wt(xs,ys,m_col,m_row,image); 
   str.Format("Second level wavelet has finished xs,ys=%d,%d!",xs,ys); 
   dc->TextOut(150,80,str); 
 
   xs=xs/2; 
   ys=ys/2; 
   wt(xs,ys,m_col,m_row,image); 
   str.Format("Third level wavelet has finished xs,ys=%d,%d!",xs,ys); 
   dc->TextOut(150,110,str); 
 
   for(i=0;iTextOut(150,140,str); 
    
   xs=xs*2; 
   ys=ys*2; 
   iwt(xs,ys,m_col,m_row,image); 
   str.Format("Iwt 2 finished,xs=%d,ys=%d!",xs,ys); 
   dc->TextOut(150,170,str); 
 
   xs=xs*2; 
   ys=ys*2; 
   iwt(xs,ys,m_col,m_row,image); 
   str.Format("Iwt 1 finished,xs=%d,ys=%d!",xs,ys); 
   dc->TextOut(150,200,str); 
 
   for(i=0;iDeleteDC(); 
   delete image; 
   delete buf; 
   delete pm; 
} 
 
//-----------Edge Process-------------- 
int CCS97::a(int x, int xsize) 
{ 
    if(x<0) x=-x; 
	if(x>=xsize) x=xsize*2-x-2; 
	return(x); 
} 
 
//-----------Threshold------------------- 
int CCS97::s(float x) 
{ 
	if(x>127) return(127); 
	if(x<-128) return(-128); 
	return((int)x); 
} 
 
//-----------Set Inverse Filter Coefficients--------- 
void CCS97::coef() 
{ 
	for(i=0;imax) max=temp1; 
             if(temp2>max) max=temp2; 
			 if(temp1