DataHiderView.cpp
资源名称:08.zip [点击查看]
上传用户:ynjin1970
上传日期:2014-10-13
资源大小:6438k
文件大小:9k
源码类别:
中间件编程
开发平台:
Visual C++
- // DataHiderView.cpp : implementation of the CDataHiderView class
- //
- #include "stdafx.h"
- #include "DataHider.h"
- #include "DataHiderDoc.h"
- #include "DataHiderView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDataHiderView
- IMPLEMENT_DYNCREATE(CDataHiderView, CFormView)
- BEGIN_MESSAGE_MAP(CDataHiderView, CFormView)
- //{{AFX_MSG_MAP(CDataHiderView)
- ON_BN_CLICKED(IDC_BASEBMP, OnBasebmp)
- ON_BN_CLICKED(IDC_HIDEFILE, OnHidefile)
- ON_BN_CLICKED(IDC_DOHIDE, OnDohide)
- ON_BN_CLICKED(IDC_RESUMEDATA, OnResumedata)
- ON_BN_CLICKED(IDC_BASEFILE, OnBasefile)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDataHiderView construction/destruction
- CDataHiderView::CDataHiderView()
- : CFormView(CDataHiderView::IDD)
- {
- //{{AFX_DATA_INIT(CDataHiderView)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // TODO: add construction code here
- t=0.035; //融合系数
- }
- CDataHiderView::~CDataHiderView()
- {
- }
- void CDataHiderView::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CDataHiderView)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
- BOOL CDataHiderView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CFormView::PreCreateWindow(cs);
- }
- void CDataHiderView::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
- GetParentFrame()->RecalcLayout();
- ResizeParentToFit();
- }
- /////////////////////////////////////////////////////////////////////////////
- // CDataHiderView diagnostics
- #ifdef _DEBUG
- void CDataHiderView::AssertValid() const
- {
- CFormView::AssertValid();
- }
- void CDataHiderView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
- CDataHiderDoc* CDataHiderView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDataHiderDoc)));
- return (CDataHiderDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CDataHiderView message handlers
- void CDataHiderView::OnBasebmp()
- {
- CFileDialog dlg(TRUE,"bmp","*.bmp",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"载体位图文件(*.bmp)|*.bmp||",NULL);
- if(dlg.DoModal()==IDOK)
- {
- m_bCanConv1=true;
- m_sCarrierFile=dlg.GetPathName();
- }
- else
- m_bCanConv1=false;
- }
- void CDataHiderView::OnHidefile()
- {
- CFileDialog dlg(TRUE,"*","*.*",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"待隐藏文件(*.*)|*.*||",NULL);
- if(dlg.DoModal()==IDOK)
- {
- m_bCanConv2=true;
- m_sHideFile=dlg.GetPathName();
- m_sHideFileName=dlg.GetFileName();
- }
- else
- m_bCanConv2=false;
- }
- void CDataHiderView::OnDohide()
- {
- CFile BaseFile,HideFile;
- DWORD BaseFileLen,HideFileLen;
- unsigned char* BaseData;
- unsigned char* HideData;
- if(m_bCanConv1==true && m_bCanConv2==true)
- {
- BaseFile.Open(m_sCarrierFile,CFile::modeReadWrite);
- BaseFileLen=BaseFile.GetLength();
- HideFile.Open(m_sHideFile,CFile::modeReadWrite);
- HideFileLen=HideFile.GetLength();
- //信息头:文件名*文件长*
- CString InfoHead;
- InfoHead.Format("%s*%d*",m_sHideFileName,HideFileLen);
- int HeadLen=InfoHead.GetLength();
- if(BaseFileLen<((HeadLen+HideFileLen)*8)/3+100)
- {
- AfxMessageBox("待隐藏文件过大!请换一较大载体位图文件。");
- return;
- }
- BaseData=new unsigned char[BaseFileLen];
- BaseFile.Read(BaseData,BaseFileLen);
- HideData=new unsigned char[BaseFileLen];
- //对明文进行组帧
- for(int k=0;k<HeadLen;k++)
- HideData[k]=InfoHead.GetAt(k);
- HideFile.Read(HideData+HeadLen,HideFileLen);
- for(DWORD kk=HeadLen+HideFileLen;kk<BaseFileLen;kk++)
- HideData[kk]=0;
- if(BaseData[28]!=24)
- {
- AfxMessageBox("载体文件格式错误!");
- BaseFile.Close();
- if(BaseData!=NULL)
- delete BaseData;
- return;
- }
- unsigned char Temp=0;
- DWORD j=0;
- for(DWORD i=54;i<BaseFileLen;i++)
- {
- Temp=((HideData[j]&224)>>5)<<5; //1
- BaseData[i]=HideCalculate(BaseData[i],Temp);
- i++;
- Temp=((HideData[j]&28)>>2)<<5; //2
- BaseData[i]=HideCalculate(BaseData[i],Temp);
- i++;
- Temp=(HideData[j]&3)<<1; //3
- j++;
- Temp|=(HideData[j]&128)>>7;
- Temp*=32;
- BaseData[i]=HideCalculate(BaseData[i],Temp);
- i++;
- Temp=((HideData[j]&112)>>4)<<5; //4
- BaseData[i]=HideCalculate(BaseData[i],Temp);
- i++;
- Temp=((HideData[j]&14)>>1)<<5; //5
- BaseData[i]=HideCalculate(BaseData[i],Temp);
- i++;
- Temp=(HideData[j]&1)<<2; //6
- j++;
- Temp|=(HideData[j]&192)>>6;
- Temp*=32;
- BaseData[i]=HideCalculate(BaseData[i],Temp);
- i++;
- Temp=((HideData[j]&56)>>3)<<5; //7
- BaseData[i]=HideCalculate(BaseData[i],Temp);
- i++;
- Temp=(HideData[j]&7)<<5; //8
- BaseData[i]=HideCalculate(BaseData[i],Temp);
- j++;
- }
- BaseFile.Close();
- HideFile.Close();
- CFile file;
- file.Open("融合图像.bmp",CFile::modeCreate|CFile::modeReadWrite);
- file.Write(BaseData,BaseFileLen);
- file.Close();
- if(BaseData!=NULL)
- delete BaseData;
- if(HideData!=NULL)
- delete HideData;
- }
- }
- void CDataHiderView::OnBasefile()
- {
- CFileDialog dlg(TRUE,"bmp","*.bmp",OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,"原始文件(*.bmp)|*.bmp||",NULL);
- if(dlg.DoModal()==IDOK)
- {
- m_bCanConv3=true;
- m_sBaseFile=dlg.GetPathName();
- }
- else
- m_bCanConv3=false;
- }
- void CDataHiderView::OnResumedata()
- {
- CFile BaseFile;
- CFile CarrierFile;
- DWORD BaseFileLen;
- DWORD CarrierFileLen;
- unsigned char* BaseData;
- unsigned char* CarrierData;
- if(m_bCanConv1==true && m_bCanConv3==true)
- {
- CarrierFile.Open(m_sCarrierFile,CFile::modeReadWrite);
- CarrierFileLen=CarrierFile.GetLength();
- BaseFile.Open(m_sBaseFile,CFile::modeReadWrite);
- BaseFileLen=BaseFile.GetLength();
- if(BaseFileLen!=CarrierFileLen)
- {
- AfxMessageBox("选取的不是充作载体的原始文件!");
- CarrierFile.Close();
- BaseFile.Close();
- return;
- }
- CarrierData=new unsigned char[CarrierFileLen];
- CarrierFile.Read(CarrierData,CarrierFileLen);
- BaseData=new unsigned char[CarrierFileLen];
- BaseFile.Read(BaseData,CarrierFileLen);
- if(CarrierData[28]!=24)
- {
- AfxMessageBox("载体文件格式错误!");
- CarrierFile.Close();
- BaseFile.Close();
- if(CarrierData!=NULL)
- delete CarrierData;
- if(BaseData!=NULL)
- delete BaseData;
- return;
- }
- if(BaseData[28]!=24)
- {
- AfxMessageBox("原始文件格式错误!");
- CarrierFile.Close();
- BaseFile.Close();
- if(CarrierData!=NULL)
- delete CarrierData;
- if(BaseData!=NULL)
- delete BaseData;
- return;
- }
- unsigned char Temp=0;
- DWORD j=0;
- for(DWORD i=54;i<CarrierFileLen;i++)
- {
- Temp=(ShowCalculate(CarrierData[i],BaseData[i])&7)<<5;
- i++;
- Temp|=(ShowCalculate(CarrierData[i],BaseData[i])&7)<<2;
- i++;
- Temp|=(ShowCalculate(CarrierData[i],BaseData[i])&6)>>1;
- CarrierData[j]=Temp;
- j++;
- Temp=(ShowCalculate(CarrierData[i],BaseData[i])&1)<<7;
- i++;
- Temp|=(ShowCalculate(CarrierData[i],BaseData[i])&7)<<4;
- i++;
- Temp|=(ShowCalculate(CarrierData[i],BaseData[i])&7)<<1;
- i++;
- Temp|=(ShowCalculate(CarrierData[i],BaseData[i])&4)>>2;
- CarrierData[j]=Temp;
- j++;
- Temp=(ShowCalculate(CarrierData[i],BaseData[i])&3)<<6;
- i++;
- Temp|=(ShowCalculate(CarrierData[i],BaseData[i])&7)<<3;
- i++;
- Temp|=ShowCalculate(CarrierData[i],BaseData[i])&7;
- CarrierData[j]=Temp;
- j++;
- }
- BaseFile.Close();
- CarrierFile.Close();
- j=0;
- CString FileName="";
- while(true)
- {
- if(CarrierData[j]=='*')
- {
- j++;
- break;
- }
- else
- {
- FileName+=CString(CarrierData[j]);
- j++;
- }
- }
- CString FileLen="";
- while(true)
- {
- if(CarrierData[j]=='*')
- {
- j++;
- break;
- }
- else
- {
- FileLen+=CString(CarrierData[j]);
- j++;
- }
- }
- BaseFileLen=atoi(FileLen);
- CFile file;
- file.Open(FileName,CFile::modeCreate|CFile::modeReadWrite);
- file.Write(CarrierData+j,BaseFileLen);
- file.Close();
- if(BaseData!=NULL)
- delete BaseData;
- if(CarrierData!=NULL)
- delete CarrierData;
- }
- }
- unsigned char CDataHiderView::HideCalculate(unsigned char B, unsigned char H)
- {
- unsigned char R=(int)((1-t)*B+0.5f)+(int)(t*H+0.5f);
- return R;
- }
- unsigned char CDataHiderView::ShowCalculate(unsigned char C, unsigned char B)
- {
- unsigned char R=(int)((C- (int)((1-t)*B+0.5f))/t+0.5f);
- if(R%32>15)
- R+=15;
- R=(int)(R/32.0f+0.5f);
- return R;
- }