⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wltview.cpp

📁 东南大学版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// wltView.cpp : implementation of the CWltView class
//

#include "stdafx.h"
#include "wlt.h"

#include "wltDoc.h"
#include "wltView.h"
#include "CODER.H"
#include "InputDlen_Dialog1.h"
#include "InputClen_Dialog.h"
#include "SetScaleDialog.h"
#include "INPUT_HIGH.h"
#include "PASSWORD.h"
#include "spiht.h"
////////////////////////////
int N=6;
int T=4096;
int TN=12;
//////////////////
#define EZWlen   3000000
#define ClenM    2000000
#define LLLen    600000
//////////////////
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "INPUT_HIGH.h"
/////////////////////////////////////////////////////////////////////////////
// CWltView

IMPLEMENT_DYNCREATE(CWltView, CView)

BEGIN_MESSAGE_MAP(CWltView, CView)
	//{{AFX_MSG_MAP(CWltView)
	ON_COMMAND(ID_OPENBMP, OnOpenbmp)
	ON_COMMAND(ID_SAVEASEZW, OnSaveasezw)
	ON_COMMAND(ID_OPENEZW, OnOpenezw)
	ON_COMMAND(ID_WAVETR, OnWavetr)
	ON_COMMAND(ID_WAVEIN, OnWavein)
	ON_COMMAND(ID_DECODER, OnSetDecoderD)
	ON_COMMAND(ID_SAVEWAVE, OnSavewavelet)
	ON_COMMAND(ID_SAVEDCLENR, OnSavedclenrP)
	ON_COMMAND(ID_SetHFilter, OnSetHFilter)
	ON_COMMAND(ID_SAVEDRBMP, OnSavedrBMP)
	ON_COMMAND(ID_CHANGETOGRAY, OnChangetograyP)
	ON_COMMAND(ID_SAVETOSPIHT, OnSavetoSpiht)
	ON_COMMAND(ID_OPENSPIHT, OnOpenSpiht)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CWltView construction/destruction
CWltView::CWltView()
{
	// TODO: add construction code here
	OP=0;
	GP=0;
	CODER=0;
	rcs=new char[ClenM];
	gcs=new char[ClenM];
	bcs=new char[ClenM];
	pWAVdata=new BYTE[EZWlen];
	pEZWdata=new BYTE[EZWlen];
	pW=new double[EZWlen];
}

CWltView::~CWltView()
{
	if(pEZWdata)delete pEZWdata;
	if(pWAVdata)delete pWAVdata;
	if(pW)delete pW;
	if(rcs)delete rcs;
	if(gcs)delete gcs;
	if(bcs)delete bcs;
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CWltView drawing

void CWltView::OnDraw(CDC* pDC)
{
	CWltDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if(OP==1)
	{
	BYTE* pBitmapData=CDibNew1.GetData();
	LPBITMAPINFO pBitmapInfo=CDibNew1.GetInfo();
	int bitmapHeight=CDibNew1.GetHeight();
	int bitmapWidth=CDibNew1.GetWidth();
	::StretchDIBits(pDC->GetSafeHdc(),0,0,bitmapWidth/1,bitmapHeight/1,0,0,bitmapWidth,bitmapHeight,pBitmapData,pBitmapInfo,DIB_RGB_COLORS,SRCCOPY);
	}
	else if(OP==2)
	{
	BITMAPINFO pBitmapInfo;
	pBitmapInfo.bmiHeader.biSize=40;
	pBitmapInfo.bmiHeader.biWidth=width;
	pBitmapInfo.bmiHeader.biHeight=height;
	pBitmapInfo.bmiHeader.biPlanes=1;
	pBitmapInfo.bmiHeader.biBitCount=24;
	pBitmapInfo.bmiHeader.biSizeImage=width*height*3;
	pBitmapInfo.bmiHeader.biXPelsPerMeter=7;
	pBitmapInfo.bmiHeader.biYPelsPerMeter=7;
	pBitmapInfo.bmiHeader.biClrUsed=0;
	pBitmapInfo.bmiHeader.biClrImportant=0;
	pBitmapInfo.bmiHeader.biCompression=0;
	::StretchDIBits(pDC->GetSafeHdc(),0,0,width,height,0,0,width,height,pWAVdata,&pBitmapInfo,DIB_RGB_COLORS,SRCCOPY);
	}
	else if(OP==3)
	{
	BITMAPINFO pBitmapInfo;
	pBitmapInfo.bmiHeader.biSize=40;
	pBitmapInfo.bmiHeader.biWidth=width_s;
	pBitmapInfo.bmiHeader.biHeight=height_s;
	pBitmapInfo.bmiHeader.biPlanes=1;
	pBitmapInfo.bmiHeader.biBitCount=24;
	pBitmapInfo.bmiHeader.biSizeImage=width_s*height_s*3;
	pBitmapInfo.bmiHeader.biXPelsPerMeter=7;
	pBitmapInfo.bmiHeader.biYPelsPerMeter=7;
	pBitmapInfo.bmiHeader.biClrUsed=0;
	pBitmapInfo.bmiHeader.biClrImportant=0;
	pBitmapInfo.bmiHeader.biCompression=0;
	::StretchDIBits(pDC->GetSafeHdc(),0,0,width_s,height_s,0,0,width_s,height_s,pEZWdata,&pBitmapInfo,DIB_RGB_COLORS,SRCCOPY);
	}
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CWltView printing

BOOL CWltView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CWltView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CWltView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CWltView diagnostics

#ifdef _DEBUG
void CWltView::AssertValid() const
{
	CView::AssertValid();
}

void CWltView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CWltView message handlers

void CWltView::OnOpenbmp() 
{
	// TODO: Add your command handler code here
	CString fn;
	CFileDialog
		dlg(TRUE,_T("BMP"),_T("*.BMP"),OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
		_T("位图文件(*.BMP)|*.BMP|"));
	if(dlg.DoModal()==IDOK)
	{
		fn.Format("%s",dlg.GetPathName());
		CDibNew1.LoadFile(fn);
		BYTE* pBitmapData=CDibNew1.GetData();
		OP=1;
		CDC* pDC=GetDC();
		OnDraw(pDC);
	}
}
void CWltView::OnSaveasezw() 
{
	// TODO: Add your command handler code here
	if(OP==2)
	{			
		int bh=height;
		int bw=width;
		FW** p0=new FW* [bh];
		for(int i=0;i<bh;i++)
		{
			p0[i]=new FW [bw];
		}
		for(int k=0;k<3;k++)
		{
			double TT=0;
			for(int m=0;m<bh;m++)
				for(int n=0;n<bw;n++)
					{
	                    p0[m][n]=*(pW+3*(width*m+n)+k);
					}
			int T1=T;
			char* cs;
			long* lc;
			if(k==0)
			{
				cs=rcs;
				lc=&rcs_L;
			}
			else if(k==1)
			{
				cs=gcs;
				lc=&gcs_L;
			}
			else
			{
				cs=bcs;
				lc=&bcs_L;
			}
		EZW_encoder(p0,bh,bw,N,cs,lc,TN);
		}
		for(i=0;i<bh;i++)
		{
			delete p0[i];
		}
		delete p0;
		CString fn;
		CFileDialog
			dlg(TRUE,_T("ezw"),_T("*.ezw"),OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
			_T("EZW文件(*.ezw)|*.ezw|"));
		InputClen_Dialog dd;
		if(dlg.DoModal()==IDOK)
		{
			if(dd.DoModal()==IDOK)
			{
				SPIHTFile ew;
				ew.height=height;
				ew.width=width;
				ew.height_s=CDibNew1.GetHeight();
				ew.width_s=CDibNew1.GetWidth();
				ew.scale=scale;
				ew.TN=TN;
				ew.rc_L=(rcs_L/8+1)*dd.m_clenr;
				ew.gc_L=(gcs_L/8+1)*dd.m_clenr;
				ew.bc_L=(bcs_L/8+1)*dd.m_clenr;

				fn.Format("%s",dlg.GetPathName());
				CFile dib(fn,CFile::modeWrite|CFile::modeCreate);
				dib.Write(&ew,sizeof(SPIHTFile));
				dib.Write(rcs,ew.rc_L);
				dib.Write(gcs,ew.gc_L);
				dib.Write(bcs,ew.bc_L);
				dib.Close();
			}
		} 
	}
	else
	{
		MessageBox("尚未进行小波变换,请先进行小波变换!");
	}
}

void CWltView::OnOpenezw() 
{
	// TODO: Add your command handler code here
	CString fn;
	CFileDialog
		dlg(TRUE,_T("ezw"),_T("*.ezw"),OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,
		_T("EZW文件(*.ezw)|*.ezw|"));
	if(dlg.DoModal()==IDOK)
	{
		fn.Format("%s",dlg.GetPathName());
		int bh,bw;
		SPIHTFile ew;
		CFile dib(fn,CFile::modeRead);
		dib.Read(&ew,sizeof(SPIHTFile));
		dib.Read(rcs,ew.rc_L);
	    dib.Read(gcs,ew.gc_L);
		dib.Read(bcs,ew.bc_L);
		height=ew.height;
		width=ew.width;
		height_s=ew.height_s;
		width_s=ew.width_s;
		scale=ew.scale;
		TN=ew.TN;
		rcs_L=8*ew.rc_L;
		gcs_L=8*ew.gc_L;
		bcs_L=8*ew.bc_L;

		char *c;
		bh=height;
		bw=width;
		int s=scale;

		int l;
	    FW** p0=new FW* [bh];
		for(int i=0;i<bh;i++)
		{
			p0[i]=new FW [bw];
		}
		for(int k=0;k<3;k++)
		{
			if(k==0)
			{
				c=rcs;
				l=rcs_L;
			}
			else if(k==1)
			{
				c=gcs;
				l=gcs_L;
			}
			else
			{
				c=bcs;
				l=bcs_L;
			}
		    EZW_decoder(p0,bh,bw,scale,c,l,TN);
			iflwt2D(p0,bh,bw,scale);
			for(int m=0;m<height_s;m++)
				for(int n=0;n<width_s;n++)
				{
					if(p0[m][n]>255)*(pEZWdata+3*(width_s*m+n)+k)=255;
					 else if(p0[m][n]<0)*(pEZWdata+3*(width_s*m+n)+k)=0;
					 else *(pEZWdata+3*(width_s*m+n)+k)=p0[m][n];
				}
		}

	for(i=0;i<bh;i++)
	{
		delete p0[i];
	}
	delete p0;
	OP=3;
	CODER=1;
	CDC* pDC=GetDC();
	OnDraw(pDC);
	}	
}

void CWltView::OnWavetr() 
{
	// TODO: Add your command handler code here
	if(OP==1)
	{
		SetScaleDialog dd;
		if(dd.DoModal()==IDOK)
		{
			N=dd.m_scale;
			T=64<<N;
			TN=8+N;
			BYTE* pBitmapData=CDibNew1.GetData();
			int bitmapHeight=CDibNew1.GetHeight();
			int bitmapWidth=CDibNew1.GetWidth();
			int bh,bw;
			if(bitmapHeight%64>0)bh=64*(bitmapHeight/64+1);
			else bh=bitmapHeight;
			if(bitmapWidth%64>0)bw=64*(bitmapWidth/64+1);
			else bw=bitmapWidth;

			FW** p0=new FW* [bh];
			height=bh;
			width=bw;
			height_s=bitmapHeight;
			width_s=bitmapWidth;
			scale=N;
			TH=T;
			for(int i=0;i<bh;i++)
			{
				p0[i]=new FW [bw];
			}
			int s=scale;
			for(int k=0;k<3;k++)
			{
				double TT=0;
				for(int m=0;m<bh;m++)
					for(int n=0;n<bw;n++)
						{
							if(m<bitmapHeight&&n<bitmapWidth)
							{
								BYTE* px=(pBitmapData+3*(bitmapWidth*m+n)+k);
								p0[m][n]=*px;
							}
							else
							{
								p0[m][n]=0;
							}
						}
			flwt2D(p0,bh,bw,N);
//////////////////////////////////////
			/*
			for(int m=0;m<bh;m++)
				for(int n=0;n<bw;n++)
					{
					}
			*/
////////////////////////////////////

			for(m=0;m<height;m++)
				for(int n=0;n<width;n++)
				{
					if(abs(p0[m][n]>255)){*(pWAVdata+3*(width*m+n)+k)=255;*(pW+3*(width*m+n)+k)=p0[m][n];}
					else {*(pWAVdata+3*(width*m+n)+k)=abs(p0[m][n]);*(pW+3*(width*m+n)+k)=p0[m][n];}
				}
			}

			for(i=0;i<bh;i++)
			{
				delete p0[i];
			}
			delete p0;
			OP=2;
			CDC* pDC=GetDC();
			OnDraw(pDC);
		}
		else
		{
		}
	}
	else
	{
		MessageBox("尚未载入位图,请载入位图!");
	}
}

void CWltView::OnWavein() 
{
	// TODO: Add your command handler code here
	if(OP==2)
	{
		BYTE* pBitmapData=CDibNew1.GetData();
		int bitmapHeight=CDibNew1.GetHeight();
		int bitmapWidth=CDibNew1.GetWidth();
		int bh,bw;
		if(bitmapHeight%64>0)bh=64*(bitmapHeight/64+1);
		else bh=bitmapHeight;
		if(bitmapWidth%64>0)bw=64*(bitmapWidth/64+1);
		else bw=bitmapWidth;
		height=bh;
		width=bw;
		height_s=bitmapHeight;
		width_s=bitmapWidth;
		scale=N;
		TH=T;
		int s=scale;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -