📄 conentbase.cpp
字号:
// ConentBase.cpp : implementation file
//
#include "stdafx.h"
#include "MoinorCentre.h"
#include "ConentBase.h"
#include "PictureList.h"
#include "Dib.h"
#include "Jpeg.h"
#include "math.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CConentBase dialog
CConentBase::CConentBase(CWnd* pParent /*=NULL*/)
: CDialog(CConentBase::IDD, pParent)
{
//{{AFX_DATA_INIT(CConentBase)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CConentBase::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CConentBase)
DDX_Control(pDX, IDC_LIST2, m_dstlist);
DDX_Control(pDX, IDC_LIST1, m_srclist);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CConentBase, CDialog)
//{{AFX_MSG_MAP(CConentBase)
ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_LBN_SELCHANGE(IDC_LIST2, OnSelchangeList2)
ON_WM_CTLCOLOR()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CConentBase message handlers
BOOL CConentBase::OnInitDialog()
{
CDialog::OnInitDialog();
LONG bf=((CPictureList*)GetParent())->picrs.GetAbsolutePosition();
((CPictureList*)GetParent())->picrs.MoveFirst();
while(!((CPictureList*)GetParent())->picrs.IsEOF())
{
CString datatime= ((CPictureList*)GetParent())->picrs.m_picturepath;
m_srclist.AddString(datatime);
((CPictureList*)GetParent())->picrs.MoveNext();
}
((CPictureList*)GetParent())->picrs.SetAbsolutePosition(bf);
// TODO: Add extra initialization here
CDib beijing;
beijing.Load(".//res//dd.bmp");
CRect ff;
GetWindowRect(ff);
beijing.ChangeImageSize(ff.Width(),ff.Height());
m_brush.CreateDIBPatternBrush(beijing.m_hDib,DIB_PAL_COLORS);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CConentBase::OnSelchangeList1()
{
CJpeg jpg; // TODO: Add your control notification handler code here
CString temp;
m_srclist.GetText(m_srclist.GetCurSel(),temp);
((CPictureList*)GetParent())->picrs.SetAbsolutePosition(m_srclist.GetCurSel());
jpg.Load(temp);
CDib dsp;
HDIB hdib=CopyHandle(jpg.GetDib()->GetHandle());
dsp.Attach(hdib);
dsp.Display(GetDlgItem(IDC_PREVIEW)->GetDC(),0,0);
}
void CConentBase::OnButton1()
{
CByteArray src;
CByteArray dst;
src.Copy(((CPictureList*)GetParent())->picrs.m_dct);
const LONG sum=((CPictureList*)GetParent())->picrs.GetRecordCount();
if(src.GetSize()>30)
{
double* ao=new double[sum];
int* sort=new int[sum];
int j=0;
((CPictureList*)GetParent())->picrs.MoveFirst();
double *dcsrc=new double[64];
double *acsrc=new double[64];
double* dcdst=new double[64];
double* acdst=new double[64];
zhifangtu(src.GetData(),dcsrc,acsrc,4,src.GetSize()/2);
while(!((CPictureList*)GetParent())->picrs.IsEOF())
{ double aac=0;
//for(int i=0;i<src.GetSize();i++)
//{
//aac=aac+fabs(src.GetAt(i)-((CPictureList*)GetParent())->picrs.m_dct.GetAt(i));
//}
if( ((CPictureList*)GetParent())->picrs.m_dct.GetSize()>30)
{
zhifangtu(((CPictureList*)GetParent())->picrs.m_dct.GetData(),dcdst,acdst,4,((CPictureList*)GetParent())->picrs.m_dct.GetSize()/2);
for(int i=0;i<64;i++)
{aac=aac+0.3*fabs(dcsrc[i]-dcdst[i]);
}
for(i=0;i<64;i++)
{aac=aac+0.7*fabs(acsrc[i]-acdst[i]);
}
ao[j]=aac;
sort[j]=j;
}
else
{ao[j]=2000;
sort[j]=j;
}
j++;
((CPictureList*)GetParent())->picrs.MoveNext();
}
delete dcsrc;
delete acsrc;
delete dcdst;
delete acdst;
maopao(ao,sort,sum-1);
m_dstlist.ResetContent();
for(int k=0;k<50;k++)
{
((CPictureList*)GetParent())->picrs.SetAbsolutePosition(sort[k]);
CString ds;
ds=((CPictureList*)GetParent())->picrs.m_picturepath;
m_dstlist.AddString(ds);
}
delete ao;
delete sort;
}
else
AfxMessageBox("你选择的图像没有dct特征值");
}
BOOL zhifangtu(BYTE* dac,double* dc,double* ac,int steplen,int l)
{ int num=256/steplen;
int* dccnt=new int[num];
memset(dccnt,0,num*sizeof(int));
int* accnt=new int[num];
memset(accnt,0,num*sizeof(int));
for(int i=0;i<l;i++)
{
int k=dac[i]/steplen;
dccnt[k]++;
}
for(i=l;i<2l;i++)
{int k=dac[i]/steplen;
accnt[k]++;
}
for(int r=0;r<num;r++)
{dc[r]=(double)dccnt[r]/l;
ac[r]=(double)accnt[r]/l;
}
delete dccnt;
delete accnt;
return TRUE;
}
BOOL maopao(double* list ,int* sort,int num)
{
int i,j;
double temp;
int temp2;
for(i=0;i<num;i++)
{
for(j=0;j<num-i;j++)
{
if(list[j]>list[j+1])
{
temp=list[j];
temp2=sort[j];
list[j]=list[j+1];
sort[j]=sort[j+1];
list[j+1]=temp;
sort[j+1]=temp2;
}
}
}
return TRUE;
}
void CConentBase::OnSelchangeList2()
{
CJpeg jpg; // TODO: Add your control notification handler code here
CString temp;
m_dstlist.GetText(m_dstlist.GetCurSel(),temp);
jpg.Load(temp);
CDib dsp;
HDIB hdib=CopyHandle(jpg.GetDib()->GetHandle());
dsp.Attach(hdib);
dsp.Display(GetDlgItem(IDC_PREVIEW)->GetDC(),0,0);
}
HBRUSH CConentBase::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(nCtlColor==CTLCOLOR_DLG)
{
return m_brush;
}
if(nCtlColor == CTLCOLOR_STATIC)
{ pDC->SetBkMode(0);
pDC->SetTextColor(RGB(255,100,70));
hbr = (HBRUSH)::GetStockObject(NULL_BRUSH);
return hbr;
}
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CConentBase::OnTimer(UINT nIDEvent)
{
CDialog::OnTimer(nIDEvent);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -