?? waveletdoc.cpp
字號:
// 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
//讀取數(shù)字圖像的文件頭,獲取圖像的屬性參數(shù)
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;
//圖像矩陣坐標與像素數(shù)值
int x,y,cur;
unsigned char tempR, tempG, tempB;
short **spOriginData, **spTransData0;
float fTempBufforDisp;
short MaxPixVal,MinPixVal,Diff;
//分配數(shù)據(jù)空間
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];
}
//創(chuàng)建圖像小波變換類
CWaveletTrans *pTrans;
//從設(shè)備緩存中獲得原始圖像數(shù)據(jù)
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);
//屏蔽圖像復(fù)原操作標志
m_bFilter = TRUE;
m_bFilter = m_bFilter & ~m_bOnce & ~m_bTwice & ~m_bTribl;
MaxPixVal=spTransData0[0][0];
MinPixVal=spTransData0[0][0];
//得到圖像小波系數(shù)的極大值與極小值
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];
}
}
//計算獲取圖像小波系數(shù)的極值差
Diff=MaxPixVal-MinPixVal;
//小波經(jīng)過處理后,放入顯示緩存中
for(y=0; y<(int)biHeight; y++)
{
for(x=0; x<(int)biWidth; x++)
{
//因為小波變換后的小波系數(shù)有可能超過255甚至更多,那么就將
//小波系數(shù)的范圍映射到0~255區(qū)間內(nèi),以后出現(xiàn)類似的處理,目的都是一樣的
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);
//刪除臨時的數(shù)據(jù)空間
delete spOriginData;
delete spTransData0;
}
void CWaveletDoc::OnWaveletLie()
{
// TODO: Add your command handler code here
//讀取數(shù)字圖像的文件頭,獲取圖像的屬性參數(shù)
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;
//圖像矩陣坐標與像素數(shù)據(jù)
int x,y,cur;
unsigned char tempR, tempG, tempB;
float fTempBufforDisp;
short MaxPixVal,MinPixVal,Diff;
short **spOriginData, **spTransData1;
//分配圖像小波變換所需的數(shù)據(jù)空間
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];
}
//創(chuàng)建圖像小波變換類
CWaveletTrans *pTrans;
//從設(shè)備緩存中獲取原始圖像數(shù)據(jù)
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);
//屏蔽圖像復(fù)原操作標志
m_bFilter = TRUE;
m_bFilter = m_bFilter & ~m_bOnce & ~m_bTwice & ~m_bTribl;
MaxPixVal=spTransData1[0][0];
MinPixVal=spTransData1[0][0];
//計算得到圖像小波系數(shù)的極大值和極小值
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];
}
}
//計算小波系數(shù)的極值差
Diff=MaxPixVal-MinPixVal;
//將小波系數(shù)處理后,放入顯示緩存中
for(y=0; y<(int)biHeight; y++)
{
for(x=0; x<(int)biWidth; x++)
{
//因為小波變換后的小波系數(shù)有可能超過255甚至更多,那么就將
//小波系數(shù)的范圍映射到0~255區(qū)間內(nèi),以后出現(xiàn)類似的處理,目的都是一樣的
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;
}
}
}
//顯示圖像的小波系數(shù)
UpdateAllViews(NULL);
//刪除臨時的數(shù)據(jù)空間
delete spOriginData;
delete spTransData1;
}
void CWaveletDoc::OnWaveletOne()
{
// TODO: Add your command handler code here
//讀取數(shù)字圖像的文件頭,獲取圖像的屬性參數(shù)
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;
//圖像矩陣坐標與像素數(shù)據(jù)
int x,y,cur;
unsigned char tempR, tempG, tempB;
float fTempBufforDisp;
short MaxPixVal,MinPixVal,Diff;
short **spOriginData, **spTransData0, **spTransData1;
//分配圖像小波變換所用的數(shù)據(jù)空間
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];
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -