?? testview.cpp
字號(hào):
// testView.cpp : implementation of the CTestView class
//
#include "stdafx.h"
#include "test.h"
#include "testDoc.h"
#include "testView.h"
#include "DlgDispResult.h"
#include "math.h"
#include "memory.h"
#include "Dialog1.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
int **origin;
////////////////////////////////////////////////////
int **ori_HalPixel_interp;
int **ori_QuartPixel_interp;
int **Predict_direc;
int **Block_energy;
int **ori_QuartPixel_interp1;
int **Predict_direc1;
int **Block_energy1;
int **total_preDrection; //存儲(chǔ)列預(yù)測(cè)的方向
int **total_preDrection1; //存儲(chǔ)行預(yù)測(cè)的方向
double **Sinc_interpolation;//sinc插值的權(quán)值
int M_sample;//sinc插值所需的樣本值數(shù)
double PI=3.14159;
/////////////////////////////////////////////////////////////////////////////
int Predict_Direction[2][8]={0,1,0,2,1,2,0,1,1,2,0,1,0,-1,0,-2};
int Predict_Direction1[2][8]={0,1,1,3,1,3,1,1,1,3,1,1,0,-1,-1,-3};
///////////////////////////////////////////////////////////////////////////
// CTestView
IMPLEMENT_DYNCREATE(CTestView, CScrollView)
BEGIN_MESSAGE_MAP(CTestView, CScrollView)
//{{AFX_MSG_MAP(CTestView)
ON_COMMAND(ID_INT_WAVELET_FORWARD, OnIntWaveletForward)
ON_COMMAND(ID_INT_WAVELET_BACKWARD, OnIntWaveletBackward)
ON_COMMAND(ID_INT_ADL_WAVELET_FORWARD, OnIntAdlWaveletForward)
ON_COMMAND(ID_INT_ADL_WAVELET_BACKWARD, OnIntAdlWaveletBackward)
ON_COMMAND(ID_INT_Quincunx_WAVELET_FORWARD, OnINTQuincunxWAVELETFORWARD)
ON_COMMAND(ID_INT_Quincunx_WAVELET_BACKWARD, OnINTQuincunxWAVELETBACKWARD)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CTestView construction/destruction
CTestView::CTestView()
{
}
CTestView::~CTestView()
{
if(origin!=NULL)
{delete origin;}
if(ori_HalPixel_interp!=NULL)
{delete ori_HalPixel_interp;}
if(ori_QuartPixel_interp!=NULL)
{delete ori_QuartPixel_interp;}
if(Predict_direc!=NULL)
{delete Predict_direc;}
if(Block_energy!=NULL)
{delete Block_energy;}
if(ori_QuartPixel_interp1!=NULL)
{delete ori_QuartPixel_interp1;}
if(Predict_direc1!=NULL)
{delete Predict_direc1;}
if(Block_energy1!=NULL)
{delete Block_energy1;}
if(total_preDrection!=NULL)
{delete total_preDrection;}
if(total_preDrection1!=NULL)
{delete total_preDrection1;}
}
BOOL CTestView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CTestView drawing
void CTestView::OnDraw(CDC* pDC)
{
// 顯示等待光標(biāo)
BeginWaitCursor();
// 獲取文檔
CTestDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// 獲取DIB
HDIB hDIB = pDoc->GetHDIB();
// 判斷DIB是否為空
if (hDIB != NULL)
{
LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
// 獲取DIB寬度
int cxDIB = (int) ::DIBWidth(lpDIB);
// 獲取DIB高度
int cyDIB = (int) ::DIBHeight(lpDIB);
::GlobalUnlock((HGLOBAL) hDIB);
CRect rcDIB;
rcDIB.top = rcDIB.left = 0;
rcDIB.right = cxDIB;
rcDIB.bottom = cyDIB;
CRect rcDest;
// 判斷是否是打印
if (pDC->IsPrinting())
{
// 是打印,計(jì)算輸出圖像的位置和大小,以便符合頁(yè)面
// 獲取打印頁(yè)面的水平寬度(象素)
int cxPage = pDC->GetDeviceCaps(HORZRES);
// 獲取打印頁(yè)面的垂直高度(象素)
int cyPage = pDC->GetDeviceCaps(VERTRES);
// 獲取打印機(jī)每英寸象素?cái)?shù)
int cxInch = pDC->GetDeviceCaps(LOGPIXELSX);
int cyInch = pDC->GetDeviceCaps(LOGPIXELSY);
// 計(jì)算打印圖像大小(縮放,根據(jù)頁(yè)面寬度調(diào)整圖像大小)
rcDest.top = rcDest.left = 0;
rcDest.bottom = (int)(((double)cyDIB * cxPage * cyInch)
/ ((double)cxDIB * cxInch));
rcDest.right = cxPage;
// 計(jì)算打印圖像位置(垂直居中)
int temp = cyPage - (rcDest.bottom - rcDest.top);
rcDest.bottom += temp/2;
rcDest.top += temp/2;
}
else
// 非打印
{
// 不必縮放圖像
rcDest = rcDIB;
}
// 輸出DIB
::PaintDIB(pDC->m_hDC, &rcDest, pDoc->GetHDIB(),
&rcDIB, pDoc->GetDocPalette());
}
// 恢復(fù)正常光標(biāo)
EndWaitCursor();
}
void CTestView::OnInitialUpdate()
{
CScrollView::OnInitialUpdate();
CSize sizeTotal;
// TODO: calculate the total size of this view
sizeTotal.cx = sizeTotal.cy = 100;
SetScrollSizes(MM_TEXT, sizeTotal);
}
/////////////////////////////////////////////////////////////////////////////
// CTestView printing
/////////////////////////////////////////////////////////////////////////////
// CTestView diagnostics
#ifdef _DEBUG
void CTestView::AssertValid() const
{
CScrollView::AssertValid();
}
void CTestView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CTestDoc* CTestView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTestDoc)));
return (CTestDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CTestView message handlers
//////////////////////////////////////////////////////////////////////////////////////////////
////以下是小波變換函數(shù)
void CTestView::wavelet_transform(LPSTR dst,const int width,const int height,const int levels)
{
int l;
LPSTR tmp_lastrow=(LPSTR)malloc((width+height+height)*sizeof(char));
LPSTR tmp_column_in=tmp_lastrow+width;
LPSTR tmp_column_out=tmp_lastrow+width+height;
for(l=0;l<levels;l++)
{ int w=width>>l;
int h=height>>l;
int i;
//首先是行變換
wavelet_row(tmp_lastrow,dst+(height-h)*width,w);
for(i=(height-h)*width;i<(height-1)*width;i+=width)
wavelet_row(dst+i,dst+i+width,w);
//然后是列變換
for(i=0;i<w;i++)
{ int j;
for(j=1;j<h;j++)
tmp_column_in[j-1]=dst[(height-j-1)*width+i]; //倒序處理
tmp_column_in[h-1]=tmp_lastrow[i]; //最后一列數(shù)據(jù)的處理
wavelet_row(tmp_column_out,tmp_column_in,h);
for(j=0;j<h;j++)
dst[(height-j-1)*width+i]=tmp_column_out[j];
}
}
free(tmp_lastrow);
}
void CTestView::wavelet_transform(int **dst,const int width,const int height,const int levels)
{
int l;
int* tmp_lastrow=(int*)malloc((width+height+height)*sizeof(int));
int* tmp_column_in=tmp_lastrow+width;
int* tmp_column_out=tmp_lastrow+width+height;
for(l=0;l<levels;l++)
{ int w=width>>l;
int h=height>>l;
int i;
//首先是行變換
wavelet_row(tmp_lastrow,dst[h-1],w);
for(i=h-2;i>=0;i--)
wavelet_row(dst[i+1],dst[i],w);
//然后是列變換
for(i=0;i<w;i++)
{ int j;
for(j=1;j<h;j++)
tmp_column_in[j-1]=dst[j][i]; //倒序處理
tmp_column_in[h-1]=tmp_lastrow[i]; //最后一列數(shù)據(jù)的處理
wavelet_row(tmp_column_out,tmp_column_in,h);
for(j=0;j<h;j++)
dst[j][i]=tmp_column_out[j];
}
}
free(tmp_lastrow);
}
void CTestView::wavelet_row(LPSTR dst, const LPSTR src, const int len)
{
int i,mid;
LPSTR ptr=src;
LPSTR avg,det;
mid=len/2;
avg=dst; //低頻小波系數(shù)
det=dst+mid; //高頻小波系數(shù)
*det=(char)(ptr[1]-(ptr[2]+ptr[0])/2); //預(yù)測(cè)信號(hào)高頻
*avg=(char)(ptr[0]+(det[0]+det[0])/4); //進(jìn)一步提升
ptr+=2;
det++;
avg++;
for(i=1;i<mid-1;i++)
{ *det=(char)(ptr[1]-(ptr[2]+ptr[0])/2);
*avg=(char)(ptr[0]+(det[0]+det[-1])/4);
ptr+=2;
det++;
avg++;
}
*det=(char)(ptr[1]-(ptr[0]+ptr[0])/2);
*avg=(char)(ptr[0]+(det[0]+det[-1])/4);
}
void CTestView::wavelet_row(int *dst, int *src, const int len)
{
int i,mid;
int* ptr=src;
int* avg,*det;
mid=len/2;
avg=dst; //低頻小波系數(shù)
det=dst+mid; //高頻小波系數(shù)
*det=(ptr[1]-(ptr[2]+ptr[0])/2); //預(yù)測(cè)信號(hào)高頻
*avg=(ptr[0]+(det[0]+det[0])/4); //進(jìn)一步提升
ptr+=2;
det++;
avg++;
for(i=1;i<mid-1;i++)
{ *det=(ptr[1]-(ptr[2]+ptr[0])/2);
*avg=(ptr[0]+(det[0]+det[-1])/4);
ptr+=2;
det++;
avg++;
}
*det=(ptr[1]-(ptr[0]+ptr[0])/2);
*avg=(ptr[0]+(det[0]+det[-1])/4);
}
void CTestView::inverse_wavelet_transform(LPSTR dst, const int width, const int height, const int levels)
{
int l;
LPSTR tmp_lastrow=(LPSTR)malloc((width+height+height)*sizeof(char));
LPSTR tmp_column_in=tmp_lastrow+width;
LPSTR tmp_column_out=tmp_lastrow+width+height;
for(l=levels-1;l>=0;l--)
{ int w=width>>l;
int h=height>>l;
int i;
//豎直方向逆變換
for(i=0;i<w;i++)
{ int j;
for(j=0;j<h;j++)
tmp_column_in[j]=dst[(height-j-1)*width+i]; //倒序處理
inverse_wavelet_row(tmp_column_out,tmp_column_in,h);
for(j=0;j<h-1;j++)
dst[(height-j-2)*width+i]=tmp_column_out[j]; //再一次倒序處理
tmp_lastrow[i]=tmp_column_out[h-1]; //保存最后一列數(shù)據(jù)的處理結(jié)果
}
//水平方向逆變換
for(i=(height-2)*width;i>=(height-h)*width;i-=width)
inverse_wavelet_row(dst+i+width,dst+i,w);
inverse_wavelet_row(dst+(height-h)*width,tmp_lastrow,w);
}
free(tmp_lastrow);
}
void CTestView::inverse_wavelet_transform(int** dst, const int width, const int height, const int levels)
{
int l;
int* tmp_lastrow=(int*)malloc((width+height+height)*sizeof(int));
int* tmp_column_in=tmp_lastrow+width;
int* tmp_column_out=tmp_lastrow+width+height;
for(l=levels-1;l>=0;l--)
{ int w=width>>l;
int h=height>>l;
int i;
//豎直方向逆變換
for(i=0;i<w;i++)
{ int j;
for(j=0;j<h;j++)
tmp_column_in[j]=dst[j][i]; //倒序處理
inverse_wavelet_row(tmp_column_out,tmp_column_in,h);
for(j=0;j<h-1;j++)
dst[j+1][i]=tmp_column_out[j]; //再一次倒序處理
tmp_lastrow[i]=tmp_column_out[h-1]; //保存最后一列數(shù)據(jù)的處理結(jié)果
}
//水平方向逆變換
for(i=1;i<h;i++)
inverse_wavelet_row(dst[i-1],dst[i],w);
inverse_wavelet_row(dst[h-1],tmp_lastrow,w);
}
free(tmp_lastrow);
}
void CTestView::inverse_wavelet_row(LPSTR dst,const LPSTR src,const int len)
{
int i,mid;
LPSTR ptr;
LPSTR avg,det;
mid=len/2;
ptr=dst;
avg=src; //低頻小波系數(shù)的逆變換結(jié)果
det=src+mid; //高頻小波系數(shù)的逆變換結(jié)果
//圖像逆變換的邊緣處理
*ptr=(char)(avg[0]-(det[0]+det[0])/4);
ptr+=2;
det++;
avg++;
for(i=0;i<mid-1;i++)
{ ptr[0]=(char)(avg[0]-(det[0]+det[-1])/4);
ptr[-1]=(char)(det[-1]+(ptr[0]+ptr[-2])/2);
ptr+=2;
det++;
avg++;
}
ptr[-1]=(char)(det[-1]+(ptr[-2]+ptr[-2])/2); //邊緣處理
}
void CTestView::inverse_wavelet_row(int *dst,int* src,const int len)
{
int i,mid;
int* ptr;
int* avg,*det;
mid=len/2;
ptr=dst;
avg=src; //低頻小波系數(shù)的逆變換結(jié)果
det=src+mid; //高頻小波系數(shù)的逆變換結(jié)果
//圖像逆變換的邊緣處理
*ptr=(avg[0]-(det[0]+det[0])/4);
ptr+=2;
det++;
avg++;
for(i=0;i<mid-1;i++)
{ ptr[0]=(avg[0]-(det[0]+det[-1])/4);
ptr[-1]=(det[-1]+(ptr[0]+ptr[-2])/2);
ptr+=2;
det++;
avg++;
}
ptr[-1]=(det[-1]+(ptr[-2]+ptr[-2])/2); //邊緣處理
}
void CTestView::wavelet_transform_overlap(int **dst, const int width, const int height, const int levels)
{
int l;
int* tmp_lastrow=(int*)malloc((width+height+height)*sizeof(int));
int* tmp_column_in=tmp_lastrow+width;
int* tmp_column_out=tmp_lastrow+width+height;
// int t[16]={180,183,187,185,190,192,192,185,187,190,193,198,200,195,200,203};
// for(int i=0;i<16;i++)
// t[i]=2*(i+1)+200;
// for(l=0;l<levels;l++)
// {
// int w=16>>l;
// wavelet_row(tmp_lastrow,t,w);
// memcpy(t,tmp_lastrow,w*sizeof(int));
// }
for(l=0;l<levels;l++)
{ int w=width>>l;
int h=height>>l;
int i;
//首先是行變換
for(i=0;i<h;i++)
{
wavelet_row(tmp_lastrow,dst[i],w);
memcpy(dst[i],tmp_lastrow,w*sizeof(int));
}
//然后是列變換
for(i=0;i<w;i++)
{ int j;
for(j=0;j<h;j++)
tmp_column_in[j]=dst[j][i];
wavelet_row(tmp_column_out,tmp_column_in,h);
for(j=0;j<h;j++)
dst[j][i]=tmp_column_out[j];
}
}
free(tmp_lastrow);
}
void CTestView::inverse_wavelet_transform_overlap(int **dst, const int width, const int height, const int levels)
{
int l;
int* tmp_lastrow=(int*)malloc((width+height+height)*sizeof(int));
int* tmp_column_in=tmp_lastrow+width;
int* tmp_column_out=tmp_lastrow+width+height;
for(l=levels-1;l>=0;l--)
{ int w=width>>l;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -