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

📄 waveletdoc.cpp

📁 this walet there is pictures in it you can debug it
💻 CPP
📖 第 1 页 / 共 3 页
字号:
// waveletDoc.cpp : implementation of the CWaveletDoc class
//

#include "stdafx.h"
#include "wavelet.h"
#include"WaveletNibianhua.h"
#include "EzwCode.h"
#include "WFilter.h"
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include "waveletDoc.h"
#include "WaveletTrans.h"
#include "ompressOption.h"
#include "Diproc.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWaveletDoc

IMPLEMENT_DYNCREATE(CWaveletDoc, CDocument)

BEGIN_MESSAGE_MAP(CWaveletDoc, CDocument)
	//{{AFX_MSG_MAP(CWaveletDoc)
	ON_COMMAND(ID_WAVELET_HANG, OnWaveletHang)
	ON_COMMAND(ID_WAVELET_LIE, OnWaveletLie)
	ON_COMMAND(ID_WAVELET_ONE, OnWaveletOne)
	ON_COMMAND(ID_WAVELET_TWO, OnWaveletTwo)
	ON_COMMAND(ID_WAVELET_THREE, OnWaveletThree)
	ON_COMMAND(ID_DWT_NIBIANHUAN, OnDwtNibianhuan)
	ON_COMMAND(ID_CODE_EZW, OnCodeEzw)
	ON_COMMAND(ID_OPTION_VALUE, OnOptionValue)
	ON_COMMAND(IDM_FILTER_BLUR, OnFilterBlur)
	ON_COMMAND(IDM_FILTER_BLUR2, OnFilterBlur2)
	ON_COMMAND(IDM_FILTER_SHARPNESS, OnFilterSharpness)
	ON_COMMAND(IDM_FILTER_SHARPNESS2, OnFilterSharpness2)
	ON_COMMAND(ID_CODE_DECODE, OnCodeDecode)
	ON_COMMAND(IDM_DIPROC_FUSION, OnDiprocFusion)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWaveletDoc construction/destruction

CWaveletDoc::CWaveletDoc()
{
minthr=3;
	m_fDirty = FALSE;
	m_pBitmap = NULL ;
	m_pTransfered = NULL;
	m_pstore=NULL;
	m_WaveletCoeff=NULL;
	m_bTribl = FALSE;	
	m_bOnce = FALSE;	
	m_bTwice = FALSE;	
	m_bFilter = FALSE;
    
	return;
}

CWaveletDoc::~CWaveletDoc()
{
	if( m_pBitmap != NULL)
	{
		free( m_pBitmap);
		//MessageBox(NULL,"Free m_pBitmap","NOTICE",MB_OK);
	}
	if( m_pTransfered != NULL)
	{
		free( m_pTransfered	);
		//MessageBox(NULL,"Free m_pTrans","NOTICE",MB_OK);
	}
    if (m_pstore!=NULL)		
	{
		delete [] m_pstore;
		//MessageBox(NULL,"Free m_pstore","NOTICE",MB_OK);
	}
	if (m_WaveletCoeff!=NULL)
	{
		delete m_WaveletCoeff;
		//MessageBox(NULL,"Free m_Wvlt","NOTICE",MB_OK);
	}
	return;
}

BOOL CWaveletDoc::OnNewDocument()
{
	if (!CDocument::OnNewDocument())
		return FALSE;

	// TODO: add reinitialization code here
	// (SDI documents will reuse this document)

	return TRUE;
}



/////////////////////////////////////////////////////////////////////////////
// CWaveletDoc serialization

void CWaveletDoc::Serialize(CArchive& ar)
{
	if (ar.IsStoring())
	{
		// TODO: add storing code here
	}
	else
	{
		// TODO: add loading code here
	}
}

/////////////////////////////////////////////////////////////////////////////
// CWaveletDoc diagnostics

#ifdef _DEBUG
void CWaveletDoc::AssertValid() const
{
	CDocument::AssertValid();
}

void CWaveletDoc::Dump(CDumpContext& dc) const
{
	CDocument::Dump(dc);
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CWaveletDoc commands

BOOL CWaveletDoc::OnOpenDocument(LPCTSTR lpszPathName) 
{
	if (!CDocument::OnOpenDocument(lpszPathName))
		return FALSE;
	m_strFileName = lpszPathName;
	m_strFileFusion = m_strFileName;
	if (ReadBitmap(lpszPathName, m_pBitmap))
		UpdateAllViews(NULL);
	return TRUE;
}

BOOL CWaveletDoc::ReadBitmap(LPCTSTR lpszPathName, unsigned char *& buffer)
{
FILE *file;
	file = fopen( lpszPathName, "rb");
	if(!file)
		return FALSE;
	fpos_t posend, posbegin;

	fseek(file, 0, SEEK_END);
	fgetpos(file, &posend);
	fseek(file, 0, SEEK_SET);
	fgetpos(file,&posbegin);
	size_t filesize = (size_t)(posend - posbegin);
	
	if( buffer == NULL )
		buffer = (unsigned char*)malloc( filesize);
	if( buffer == NULL )
	{
		//AfxMessageBox(IDM_MEMORY_INSUFFICIENT, MB_OK, 0);
		return FALSE;
	}
	memset(buffer, 0, filesize);
	size_t sizeread = fread(buffer, sizeof(unsigned char), filesize, file);
	if(sizeread != filesize)
	{
		//AfxMessageBox(IDM_READFILE_ERROR, MB_OK, 0);
		free(buffer);
		buffer = NULL;
		fclose(file);
		return FALSE;
	}
	if( buffer[0] != 'B'||buffer[1] != 'M')
	{
		//AfxMessageBox(IDM_FILEFORMAT_ERROR, MB_OK, 0);
		free(buffer);
		buffer = NULL;
		fclose(file);
		return FALSE;
	}
	fclose(file);
	return TRUE;
}

void CWaveletDoc::OnWaveletHang() 
{
	// TODO: Add your command handler code here
	//读取数字图像的文件头,获取图像的属性参数
	LPBITMAPINFOHEADER lpBitmapInfoHeader = (LPBITMAPINFOHEADER)(m_pBitmap+14);
	LPBITMAPFILEHEADER lpBitmapFileHeader = (LPBITMAPFILEHEADER)m_pBitmap;
	unsigned char *lpData = m_pBitmap + lpBitmapFileHeader->bfOffBits;
	unsigned long biHeight = lpBitmapInfoHeader->biHeight;
	unsigned long biWidth = lpBitmapInfoHeader->biWidth;
	unsigned long biAlign = (biWidth*3+3)/4 *4;
	unsigned long bmSize = biHeight * biAlign;

	if(m_pTransfered==NULL)
	{
		m_pTransfered=(unsigned char*) malloc (bmSize);
		m_pstore=new short [bmSize];
	}
	if(m_pTransfered==NULL)
		return;
	//图像矩阵坐标与像素数值
	int x,y,cur;
	unsigned char tempR, tempG, tempB;
	short **spOriginData, **spTransData0;
	float fTempBufforDisp;
	short MaxPixVal,MinPixVal,Diff;
	//分配数据空间
	spOriginData = new short* [biHeight];
	spTransData0 = new short* [biHeight];
	//
	for(int i = 0; i < biHeight; i ++)
	{
		spOriginData[i] = new short [biWidth];
		spTransData0[i] = new short [biWidth];
	}
	//创建图像小波变换类
	CWaveletTrans *pTrans;
	//从设备缓存中获得原始图像数据
	for (i=0;i<=2;i++)
	{
	for(y=0; y<(int)biHeight; y++)
	{
		for( x=0; x<(int)biWidth; x++)
		{
			cur = y*biAlign+3*x;
			spOriginData[biHeight-1-y][x]=(short)(lpData[cur+i]);
		}
	}
	
	//完成图像水平方向的一次小波变换
	pTrans->Hori_Transform(spOriginData,spTransData0,biHeight,biWidth/2,1);
	//屏蔽图像复原操作标志
	m_bFilter = TRUE;
	m_bFilter = m_bFilter & ~m_bOnce & ~m_bTwice & ~m_bTribl;
	MaxPixVal=spTransData0[0][0];
	MinPixVal=spTransData0[0][0];
	//得到图像小波系数的极大值与极小值
	for( y=0; y<(int)biHeight; y++)
	{
		for( x=0; x<(int)biWidth; x++)
		{
			if(MaxPixVal<spTransData0[y][x])
				MaxPixVal=spTransData0[y][x];
			if(MinPixVal>spTransData0[y][x])
				MinPixVal=spTransData0[y][x];
		}
	}
	//计算获取图像小波系数的极值差
	Diff=MaxPixVal-MinPixVal;
	//小波经过处理后,放入显示缓存中
	for(y=0; y<(int)biHeight; y++)
	{
		for(x=0; x<(int)biWidth; x++)
		{
		//因为小波变换后的小波系数有可能超过255甚至更多,那么就将
		//小波系数的范围映射到0~255区间内,以后出现类似的处理,目的都是一样的
			fTempBufforDisp=spTransData0[biHeight-1-y][x];
			fTempBufforDisp-=MinPixVal;
			fTempBufforDisp*=255;
			fTempBufforDisp/=Diff;
			cur= y*biAlign+3*x;		//current pixel	
			m_pstore[cur+i]=spTransData0[biHeight-1-y][x];
			m_pTransfered[cur+i]	= (unsigned char)fTempBufforDisp;
		}
	}
	}
	//小波图像水平方向小波变换
	UpdateAllViews(NULL);
	//删除临时的数据空间
	delete spOriginData;
	delete spTransData0;
}



void CWaveletDoc::OnWaveletLie() 
{
	// TODO: Add your command handler code here
	//读取数字图像的文件头,获取图像的属性参数
	LPBITMAPINFOHEADER lpBitmapInfoHeader = (LPBITMAPINFOHEADER)(m_pBitmap+14);
	LPBITMAPFILEHEADER lpBitmapFileHeader = (LPBITMAPFILEHEADER)m_pBitmap;
	unsigned char *lpData = m_pBitmap + lpBitmapFileHeader->bfOffBits;
	unsigned long biHeight = lpBitmapInfoHeader->biHeight;
	unsigned long biWidth = lpBitmapInfoHeader->biWidth;
	unsigned long biAlign = (biWidth*3+3)/4 *4;
	unsigned long bmSize = biHeight * biAlign;
	if(m_pTransfered==NULL)
		m_pTransfered=(unsigned char*) malloc (bmSize);
	if(m_pTransfered==NULL)
		return;
	//图像矩阵坐标与像素数据
	int x,y,cur;
	unsigned char tempR, tempG, tempB;
	float fTempBufforDisp;
	short MaxPixVal,MinPixVal,Diff;
	short **spOriginData, **spTransData1;
	//分配图像小波变换所需的数据空间
	spOriginData = new short* [biHeight];
	spTransData1 = new short* [biHeight];

	for(int i = 0; i < biHeight; i ++)
	{
		spOriginData[i] = new short [biWidth];
		spTransData1[i] = new short [biWidth];
	}
	//创建图像小波变换类
	CWaveletTrans *pTrans;
	//从设备缓存中获取原始图像数据
	for (i=0;i<=2;i++)
	{
	for(y=0; y<(int)biHeight; y++)
	{
		for( x=0; x<(int)biWidth; x++)
		{
			cur = y*biAlign+3*x;
			spOriginData[biHeight-1-y][x]=(short)(lpData[cur+i]);  //no problem
		}
	}
	//完成一次竖直方向的图像小波变换
	pTrans->Vert_Transform(spOriginData,spTransData1,biHeight/2,biWidth,1);
	//屏蔽图像复原操作标志
	m_bFilter = TRUE;
	m_bFilter = m_bFilter & ~m_bOnce & ~m_bTwice & ~m_bTribl;
	MaxPixVal=spTransData1[0][0];
	MinPixVal=spTransData1[0][0];
	//计算得到图像小波系数的极大值和极小值
	for( y=0; y<(int)biHeight; y++)
	{
		for( x=0; x<(int)biWidth; x++)
		{
			if(MaxPixVal<spTransData1[y][x])
				MaxPixVal=spTransData1[y][x];
			if(MinPixVal>spTransData1[y][x])
				MinPixVal=spTransData1[y][x];
		}
	}
	//计算小波系数的极值差
	Diff=MaxPixVal-MinPixVal;
	//将小波系数处理后,放入显示缓存中
	for(y=0; y<(int)biHeight; y++)
	{
		for(x=0; x<(int)biWidth; x++)
		{
		//因为小波变换后的小波系数有可能超过255甚至更多,那么就将
		//小波系数的范围映射到0~255区间内,以后出现类似的处理,目的都是一样的
			fTempBufforDisp=spTransData1[biHeight-1-y][x];
			fTempBufforDisp-=MinPixVal;
			fTempBufforDisp*=255;
			fTempBufforDisp/=Diff;
			cur= y*biAlign+3*x;		//current pixel	
			m_pTransfered[cur+i]	= (unsigned char)fTempBufforDisp;
		//	m_pTransfered[cur+1]= (unsigned char)fTempBufforDisp;
		//	m_pTransfered[cur+2]= (unsigned char)fTempBufforDisp;
		}
	}
	}
	//显示图像的小波系数
	UpdateAllViews(NULL);
	//删除临时的数据空间
	delete spOriginData;
	delete spTransData1;
}

void CWaveletDoc::OnWaveletOne() 
{
	// TODO: Add your command handler code here
    //读取数字图像的文件头,获取图像的属性参数

	LPBITMAPINFOHEADER lpBitmapInfoHeader = (LPBITMAPINFOHEADER)(m_pBitmap+14);
	LPBITMAPFILEHEADER lpBitmapFileHeader = (LPBITMAPFILEHEADER)m_pBitmap;
	unsigned char *lpData = m_pBitmap + lpBitmapFileHeader->bfOffBits;
	unsigned long biHeight = lpBitmapInfoHeader->biHeight;
	unsigned long biWidth = lpBitmapInfoHeader->biWidth;
	unsigned long biAlign = (biWidth*3+3)/4 *4;
	unsigned long bmSize = biHeight * biAlign;

	if(m_pTransfered==NULL)
	{
		m_pTransfered=(unsigned char*) malloc (bmSize);
		m_pstore=new short [bmSize];
	}
	if(m_pTransfered==NULL)
		return;
	//图像矩阵坐标与像素数据	
	int x,y,cur;
	unsigned char tempR, tempG, tempB;
	float fTempBufforDisp;
	short MaxPixVal,MinPixVal,Diff;
	short **spOriginData, **spTransData0, **spTransData1;
	//分配图像小波变换所用的数据空间
	spOriginData = new short* [biHeight];
	spTransData0 = new short* [biHeight];
	spTransData1 = new short* [biHeight];
	m_WaveletCoeff	= new short * [biHeight];

	for(int i = 0; i < biHeight; i ++)
	{
		spOriginData[i] = new short [biWidth];
		spTransData0[i] = new short [biWidth];

⌨️ 快捷键说明

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