📄 dctview.cpp
字号:
// dctView.cpp : implementation of the CDctView class
//
#include "stdafx.h"
#include "dct.h"
#include "math.h"
#include "dctDoc.h"
#include "dctView.h"
#include "f0"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define pi 3.1416926
float k(int t)
{
if(t==0)
return float(1/(sqrt(2)));
else
return 1;
}
/////////////////////////////////////////////////////////////////////////////
// CDctView
IMPLEMENT_DYNCREATE(CDctView, CView)
BEGIN_MESSAGE_MAP(CDctView, CView)
//{{AFX_MSG_MAP(CDctView)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CDctView construction/destruction
CDctView::CDctView()
{
// TODO: add construction code here
}
CDctView::~CDctView()
{
}
BOOL CDctView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CDctView drawing
void CDctView::OnDraw(CDC* pDC)
{
CDctDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CString cs,cs1;
// TODO: add draw code for native data here
int m=8,n=8,block[64],num;
float coff[64];
for(int i=0;i<8;i++)
for(int j=0;j<8;j++)
{
coff[i*8+j]=1.0;
block[i*8+j]=t0[i][j];
cs.Format("%d",t0[i][j]);
pDC->TextOut(i*20+10,j*20+50,cs);
}
SYSTEMTIME mytime,my1time;
GetSystemTime(&mytime);
num=100000;
for(i=0;i<num;i++)
Dct(block,coff);
GetSystemTime(&my1time);
cs.Format("快速算法计算%d次的时间:%d:%d - %d:%d",num,mytime.wSecond,
mytime.wMilliseconds,my1time.wSecond,my1time.wMilliseconds);
pDC->TextOut(0,0,cs);
static float s=0,f[8][8];
num=100;
for( i=0;i<m;i++)
for(int j=0;j<n;j++)
{
for(int l=0;l<num;l++)
{
f[i][j]=0;
for(int x=0;x<m;x++)
for(int y=0;y<n;y++)
{
f[i][j]+=(float)(2/sqrt(8*8)*k(i)*k(j)*t0[x][y]*cos(((2*x+1)*i*pi)/16)*cos(((2*y+1)*j*pi)/16));
}
}
cs.Format("%5.2f",f[i][j]);
pDC->TextOut(i*40+200,j*20+50,cs);
}
GetSystemTime(&mytime);
cs.Format("传统算法计算%d次的时间:%d:%d - %d:%d",num,my1time.wSecond,my1time.wMilliseconds,
mytime.wSecond,mytime.wMilliseconds);
pDC->TextOut(0,20,cs);
}
/////////////////////////////////////////////////////////////////////////////
// CDctView printing
BOOL CDctView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CDctView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CDctView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CDctView diagnostics
#ifdef _DEBUG
void CDctView::AssertValid() const
{
CView::AssertValid();
}
void CDctView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CDctDoc* CDctView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDctDoc)));
return (CDctDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CDctView message handlers
int CDctView::Dct (int *block, float *coeff)
{
int j1, i, j, k;
float b[8];
float b1[8];
float d[8][8];
float f0 = (float) .7071068;
float f1 = (float) .4903926;
float f2 = (float) .4619398;
float f3 = (float) .4157348;
float f4 = (float) .3535534;
float f5 = (float) .2777851;
float f6 = (float) .1913417;
float f7 = (float) .0975452;
for (i = 0, k = 0; i < 8; i++, k += 8)
{
for (j = 0; j < 8; j++)
{
b[j] = (float) block[k + j];
}
/* Horizontal transform */
for (j = 0; j < 4; j++)
{
j1 = 7 - j;
b1[j] = b[j] + b[j1];
b1[j1] = b[j] - b[j1];
}
b[0] = b1[0] + b1[3];
b[1] = b1[1] + b1[2];
b[2] = b1[1] - b1[2];
b[3] = b1[0] - b1[3];
b[4] = b1[4];
b[5] = (b1[6] - b1[5]) * f0;
b[6] = (b1[6] + b1[5]) * f0;
b[7] = b1[7];
d[i][0] = (b[0] + b[1]) * f4;
d[i][4] = (b[0] - b[1]) * f4;
d[i][2] = b[2] * f6 + b[3] * f2;
d[i][6] = b[3] * f6 - b[2] * f2;
b1[4] = b[4] + b[5];
b1[7] = b[7] + b[6];
b1[5] = b[4] - b[5];
b1[6] = b[7] - b[6];
d[i][1] = b1[4] * f7 + b1[7] * f1;
d[i][5] = b1[5] * f3 + b1[6] * f5;
d[i][7] = b1[7] * f7 - b1[4] * f1;
d[i][3] = b1[6] * f3 - b1[5] * f5;
}
/* Vertical transform */
for (i = 0; i < 8; i++)
{
for (j = 0; j < 4; j++)
{
j1 = 7 - j;
b1[j] = d[j][i] + d[j1][i];
b1[j1] = d[j][i] - d[j1][i];
}
b[0] = b1[0] + b1[3];
b[1] = b1[1] + b1[2];
b[2] = b1[1] - b1[2];
b[3] = b1[0] - b1[3];
b[4] = b1[4];
b[5] = (b1[6] - b1[5]) * f0;
b[6] = (b1[6] + b1[5]) * f0;
b[7] = b1[7];
d[0][i] = (b[0] + b[1]) * f4;
d[4][i] = (b[0] - b[1]) * f4;
d[2][i] = b[2] * f6 + b[3] * f2;
d[6][i] = b[3] * f6 - b[2] * f2;
b1[4] = b[4] + b[5];
b1[7] = b[7] + b[6];
b1[5] = b[4] - b[5];
b1[6] = b[7] - b[6];
d[1][i] = b1[4] * f7 + b1[7] * f1;
d[5][i] = b1[5] * f3 + b1[6] * f5;
d[7][i] = b1[7] * f7 - b1[4] * f1;
d[3][i] = b1[6] * f3 - b1[5] * f5;
}
for (i = 0; i < 8; i++)
{
for (j = 0; j < 8; j++)
{
coeff [ j + i * 8] = (float) (d[i][j]);
}
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -