📄 dlghandle.cpp
字号:
// DlgHandle.cpp : implementation file
//
#include "stdafx.h"
#include "pgm.h"
#include "DlgHandle.h"
#include "engine.h"
#include "matrix.h"
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// DlgHandle dialog
DlgHandle::DlgHandle(CWnd* pParent /*=NULL*/)
: CDialog(DlgHandle::IDD, pParent)
{
//{{AFX_DATA_INIT(DlgHandle)
m_text_in = _T("");
m_text_out = _T("");
m_nButton53 = -1;
//}}AFX_DATA_INIT
}
void DlgHandle::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(DlgHandle)
DDX_Text(pDX, IDC_EDIT11, m_text_in);
DDX_Text(pDX, IDC_EDIT22, m_text_out);
DDX_Radio(pDX, IDC_RADIO53, m_nButton53);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(DlgHandle, CDialog)
//{{AFX_MSG_MAP(DlgHandle)
ON_BN_CLICKED(IDC_BUTTON_BUILD, OnButtonBuild)
ON_BN_CLICKED(IDC_BUTTON5_INJECT, OnButton5Inject)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// DlgHandle message handlers
void DlgHandle::OnButtonBuild()
{
// TODO: Add your control notification handler code here
srand( (unsigned)time( NULL ) );
m_rand=rand();
/*
UpdateData(TRUE);
AfxMessageBox(m_rand);
*/
GetDlgItem(IDC_EDIT33)->SetWindowText(m_rand);
}
void DlgHandle::OnButton5Inject()
{
// TODO: Add your control notification handler code here
int injectRadioButton;
injectRadioButton=m_nButton53;
UpdateData(TRUE);
Engine *ep;
if(m_nButton53==0)
{
UpdateData(TRUE);
AfxMessageBox(m_text_in);
}
else if(m_nButton53==1)
{
//double t[1];
//t[0]=6.28;
// mxArray *T=NULL;
Engine *ep;
if(!(ep=engOpen(NULL)))
{
AfxMessageBox("Can not open the matlab engine!");
exit(-1);
}
engEvalString(ep,"wmark()");
/* int fs=44100,nbits=16;
int i,m;
mxArray* y=NULL;
mxArray* y_mark=NULL;
mxArray* count=NULL;
mxArray* m_LCR=NULL;
mxArray* LC=NULL;
mxArray* LCR=NULL;
y=mxCreateDoubleMatrix(1,5000000,mxREAL);
y_mark=mxCreateDoubleMatrix(1,5000000,mxREAL);
LCR=mxCreateDoubleMatrix(1,625000,mxREAL);
count=mxCreateDoubleMatrix(1,5,mxREAL);
LC=mxCreateDoubleMatrix(1,5000000,mxREAL);
CString fname3,pname3;
CString fname4,pname4;
engEvalString(ep,"[fname3,pname3]=uigetfile('*.png;*.jpg;*.gif','open the watermark picure')");
engEvalString(ep,"[fname4,pname4]=uigetfile('*.wav','open the watermarkaudio file')");
mxArray* mark=NULL;
mxArray* W_mark=NULL;
mxArray* W_mark1=NULL;
//mxArray* L_mark=NULL;
mxArray* L_len=NULL;
L_len=mxCreateDoubleMatrix(1,1,mxREAL);
mark=mxCreateDoubleMatrix(16,16,mxREAL);
W_mark=mxCreateDoubleMatrix(1,256,mxREAL);
W_mark1=mxCreateDoubleMatrix(1,256,mxREAL);
engPutVariable(ep, "W_mark",W_mark);
//L_mark=mxCreateDoubleMatrix(1,1,mxREAL);Logical
engEvalString(ep,"mark=imread(fname3)");
engEvalString(ep,"W_mark=reshape(mark,1,256)");
//engEvalString(ep,"L_mark=length(W_mark)");
engEvalString(ep,"[y,fs,nbits]=wavread(fname4)");
engEvalString(ep,"[LC,count]=wavedec(y,3,'db4')");
engEvalString(ep,"LCR=appcoef(LC,count,3,'db4')");
engEvalString(ep,"L_len=floor(length(LCR)/256)");
L_len=engGetVariable(ep,"L_len");
double *temp=new double[sizeof(double)];
memcpy((double *)temp,(double *)mxGetPr(L_len),sizeof(double));
int temp1;
temp1=(int)(*temp);
m_LCR=mxCreateDoubleMatrix(256,1,mxREAL);
/*double x[256];
int p[256];
W_mark=engGetArray(ep,"W_mark");
memcpy(x,mxGetPr(W_mark),256*sizeof(double));
p[0]=(int)x[0];
CString str;
str.Format("%d",p[0]);
AfxMessageBox(str);
//engEvalString(ep,"L_len=L_len/2");*/
/*int cc[256]={1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,0,1,1,
1,0,0,1,1,0,1,1,1,1,1,0,0,
0,0,0,0,1,0,1,0,1,1,1,1,1,
1,1,1,0,1,1,1,1,0,0,1,1,1,
1,1,1,1,1,1,0,0,0,0,0,1,0,
1,0,1,1,1,1,1,1,0,1,1,1,1,
1,0,1,0,1,1,1,1,1,1,0,0,0,
0,0,0,1,0,0,1,1,1,1,1,1,1,
1,0,1,0,1,0,1,0,1,1,1,1,1,
1,1,1,1,0,1,0,1,0,0,0,0,0,
0,1,1,1,1,1,1,0,1,0,1,0,1,
0,0,1,1,1,1,1,1,1,0,0,0,0,
0,0,1,0,1,0,1,1,1,1,1,1,1,
0,1,1,1,1,1,0,1,1,0,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1,1,1,1,1,
1,1,1,1,1,1,1,1,1};
for(i=1;i<=256;i++)
{
engEvalString(ep,"m_LCR(i,:)=mean(LCR((i-1)*L_len+1:L_len*i))");
if (cc[i-1]==1)
{
for (m=1;m<=temp1;m++)
engEvalString(ep,"LC((i-1)*temp1+m)=LC((i-1)*temp1+m)-m_LCR(i,:)+0.005");
}
else
{
for (m=1;m<=temp1;m++)
engEvalString(ep,"LC((i-1)*temp1+m)=LC((i-1)*temp1+m)-m_LCR(i,:)-0.005");
}
}
engEvalString(ep,"y_mark=waverec(LC,count,'db4')");
engEvalString(ep,"y(1:length(y_mark))=y_mark");
engEvalString(ep,"wavwrite(y,fs,nbits,'mlhwm')");
AfxMessageBox("ok");*/
}
else if(m_nButton53==2)
{
UpdateData(TRUE);
AfxMessageBox(m_rand);
}
//engClose(ep);
UpdateData(false);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -