HebingDlg.cpp
上传用户:aqingfeng
上传日期:2014-03-25
资源大小:1839k
文件大小:11k
源码类别:

波变换

开发平台:

Visual C++

  1. // HebingDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "小波变换.h"
  5. #include "HebingDlg.h"
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // CHebingDlg dialog
  13. CHebingDlg::CHebingDlg(CWnd* pParent /*=NULL*/)
  14. : CDialog(CHebingDlg::IDD, pParent)
  15. {
  16. //{{AFX_DATA_INIT(CHebingDlg)
  17. // NOTE: the ClassWizard will add member initialization here
  18. //}}AFX_DATA_INIT
  19. }
  20. void CHebingDlg::DoDataExchange(CDataExchange* pDX)
  21. {
  22. CDialog::DoDataExchange(pDX);
  23. //{{AFX_DATA_MAP(CHebingDlg)
  24. // NOTE: the ClassWizard will add DDX and DDV calls here
  25. //}}AFX_DATA_MAP
  26. }
  27. BEGIN_MESSAGE_MAP(CHebingDlg, CDialog)
  28. //{{AFX_MSG_MAP(CHebingDlg)
  29. ON_WM_PAINT()
  30. ON_WM_QUERYDRAGICON()
  31. ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
  32. ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
  33. ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
  34. ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
  35. ON_BN_CLICKED(IDC_BUTTON5, OnButton5) // NOTE: the ClassWizard will add message map macros here
  36. //}}AFX_MSG_MAP
  37. END_MESSAGE_MAP()
  38. /////////////////////////////////////////////////////////////////////////////
  39. // CHebingDlg message handlers
  40. BOOL CHebingDlg::OnInitDialog()
  41. {
  42. CDialog::OnInitDialog();
  43. // Add "About..." menu item to system menu.
  44. // IDM_ABOUTBOX must be in the system command range.
  45. // TODO: Add extra initialization here
  46. return TRUE;  // return TRUE  unless you set the focus to a control
  47. }
  48. // If you add a minimize button to your dialog, you will need the code below
  49. //  to draw the icon.  For MFC applications using the document/view model,
  50. //  this is automatically done for you by the framework.
  51. void CHebingDlg::OnPaint() 
  52. {
  53. if (IsIconic())
  54. {
  55. CPaintDC dc(this); // device context for painting
  56. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  57. // Center icon in client rectangle
  58. int cxIcon = GetSystemMetrics(SM_CXICON);
  59. int cyIcon = GetSystemMetrics(SM_CYICON);
  60. CRect rect;
  61. GetClientRect(&rect);
  62. int x = (rect.Width() - cxIcon + 1) / 2;
  63. int y = (rect.Height() - cyIcon + 1) / 2;
  64. // Draw the icon
  65. dc.DrawIcon(x, y, m_hIcon);
  66. }
  67. else
  68. {
  69. CDialog::OnPaint();
  70. }
  71. }
  72. // The system calls this to obtain the cursor to display while the user drags
  73. //  the minimized window.
  74. HCURSOR CHebingDlg::OnQueryDragIcon()
  75. {
  76. return (HCURSOR) m_hIcon;
  77. }
  78. void CHebingDlg::OnButton1() 
  79. {
  80. // TODO: Add your control notification handler code here
  81.     static char BASED_CODE szFilter[] = "bitmap Files (*.bmp)|*.bmp||";
  82.     CFileDialog fd(true,NULL,NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,NULL);
  83.    if(fd.DoModal()==IDOK)
  84.       filename1=fd.GetPathName();
  85. }
  86. void CHebingDlg::OnButton2() 
  87. {
  88. // TODO: Add your control notification handler code here
  89. static char BASED_CODE szFilter[] = "bitmap Files (*.bmp)|*.bmp||";
  90.     CFileDialog fd(true,NULL,NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,NULL);
  91.     if(fd.DoModal()==IDOK)
  92.       filename2=fd.GetPathName();
  93. }
  94. void CHebingDlg::OnButton3() 
  95. {
  96. // TODO: Add your control notification handler code here
  97. static char BASED_CODE szFilter[] = "bitmap Files (*.bmp)|*.bmp||";
  98. CFileDialog fd(true,NULL,NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,NULL);
  99. if(fd.DoModal()==IDOK)
  100.  filename3=fd.GetPathName();
  101. }
  102. void CHebingDlg::OnButton4() 
  103. {
  104. // TODO: Add your control notification handler code here
  105. static char BASED_CODE szFilter[] = "bitmap Files (*.bmp)|*.bmp||";
  106. CFileDialog fd(true,NULL,NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,NULL);
  107. if(fd.DoModal()==IDOK)
  108.  filename4=fd.GetPathName();
  109. }
  110. void CHebingDlg::OnButton5() 
  111. {
  112. // TODO: Add your control notification handler code here
  113. if(filename1.IsEmpty())
  114.    {
  115.    MessageBox("未选择图片!");
  116.    return;
  117.    }
  118.    if(filename2.IsEmpty())
  119.    {
  120.    MessageBox("未选择图片");
  121.    return;
  122.    }
  123.   if(filename3.IsEmpty())
  124.    {
  125.    MessageBox("未选择图片!");
  126.    return;
  127.    }
  128.   if(filename4.IsEmpty())
  129.    {
  130.    MessageBox("未选择图片!");
  131.    return;
  132.    }
  133. CFile file1,file3,file2,file5,file4;
  134. //打开文件1和2
  135. static char BASED_CODE szFilter[] = "bitmap Files (*.bmp)|*.bmp||";
  136. CFileDialog fd(false,"*.bmp","*.bmp", OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,szFilter,NULL);
  137. CString filename;
  138. if(fd.DoModal()==IDOK)
  139. { filename=fd.GetPathName();
  140.    
  141. file1.Open(filename1,CFile::modeRead|CFile::shareDenyWrite,NULL);
  142. file2.Open(filename2,CFile::modeRead|CFile::shareDenyWrite,NULL);
  143. file3.Open(filename3,CFile::modeRead|CFile::shareDenyWrite,NULL);
  144. file4.Open(filename4,CFile::modeRead|CFile::shareDenyWrite,NULL);
  145. LPBITMAPFILEHEADER bmpfilehead1,bmpfilehead2,bmpfilehead3,bmpfilehead4,bmpfilehead5;
  146. LPBITMAPINFOHEADER bmpfileinfo1,bmpfileinfo2,bmpfileinfo3,bmpfileinfo4,bmpfileinfo5;
  147. //分配三个文件头的内存
  148.  
  149. bmpfilehead1=(LPBITMAPFILEHEADER)::malloc(sizeof(BITMAPFILEHEADER));
  150. bmpfilehead2=(LPBITMAPFILEHEADER)::malloc(sizeof(BITMAPFILEHEADER));
  151. bmpfilehead3=(LPBITMAPFILEHEADER)::malloc(sizeof(BITMAPFILEHEADER));
  152. bmpfilehead4=(LPBITMAPFILEHEADER)::malloc(sizeof(BITMAPFILEHEADER));
  153. bmpfilehead5=(LPBITMAPFILEHEADER)::malloc(sizeof(BITMAPFILEHEADER));
  154. //分配三个信息头的内存
  155. bmpfileinfo1=(LPBITMAPINFOHEADER)::malloc(sizeof(BITMAPINFOHEADER));
  156. bmpfileinfo2=(LPBITMAPINFOHEADER)::malloc(sizeof(BITMAPINFOHEADER));
  157. bmpfileinfo3=(LPBITMAPINFOHEADER)::malloc(sizeof(BITMAPINFOHEADER));
  158. bmpfileinfo4=(LPBITMAPINFOHEADER)::malloc(sizeof(BITMAPINFOHEADER));
  159. bmpfileinfo5=(LPBITMAPINFOHEADER)::malloc(sizeof(BITMAPINFOHEADER));
  160.  
  161. //读file1和file2的文件头和信息头
  162. file1.Read(bmpfilehead1,sizeof(BITMAPFILEHEADER));
  163. file1.Read(bmpfileinfo1,sizeof(BITMAPINFOHEADER));
  164. file2.Read(bmpfilehead2,sizeof(BITMAPFILEHEADER));
  165. file2.Read(bmpfileinfo2,sizeof(BITMAPINFOHEADER));
  166. file3.Read(bmpfilehead3,sizeof(BITMAPFILEHEADER));
  167. file3.Read(bmpfileinfo3,sizeof(BITMAPINFOHEADER));
  168. file4.Read(bmpfilehead4,sizeof(BITMAPFILEHEADER));
  169. file4.Read(bmpfileinfo4,sizeof(BITMAPINFOHEADER));
  170. if(bmpfileinfo1->biHeight!=bmpfileinfo2->biHeight)
  171. {
  172. MessageBox("两文件高不一致,不能合并");
  173. exit(0);
  174. }
  175. //复制一个文件头和信息头到file3中
  176. ::CopyMemory(bmpfileinfo5,bmpfileinfo1,sizeof(BITMAPINFOHEADER));
  177. ::CopyMemory (bmpfilehead5,bmpfilehead1,sizeof(BITMAPFILEHEADER));
  178. //分配file1的数据区内存
  179. DWORD bmp1size;
  180. bmp1size=bmpfilehead1->bfSize-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER)-1024;
  181. char *bmpdata1;
  182. bmpdata1=(char*)::VirtualAlloc(NULL,bmp1size,MEM_COMMIT,PAGE_READWRITE);
  183. //HGLOBAL tempbmpdata1=::GlobalAlloc(GHND,bmp1size);
  184. //bmpdata1=(char*)::GlobalLock (tempbmpdata1); 
  185. //分配file2的数据区内存
  186. DWORD bmp2size;
  187. bmp2size=bmpfilehead2->bfSize-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER)-1024;
  188. char *bmpdata2;
  189. bmpdata2=(char*)::VirtualAlloc(NULL,bmp2size,MEM_COMMIT,PAGE_READWRITE);
  190. //HGLOBAL tempbmpdata2=::GlobalAlloc(GHND, bmp2size);
  191. //bmpdata2=(char*)::GlobalLock (tempbmpdata2);
  192. DWORD bmp3size;
  193. bmp3size=bmpfilehead3->bfSize-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER)-1024;
  194. char *bmpdata3;
  195. bmpdata3=(char*)::VirtualAlloc(NULL,bmp2size,MEM_COMMIT,PAGE_READWRITE);
  196. //HGLOBAL tempbmpdata2=::GlobalAlloc(GHND, bmp2size);
  197. //bmpdata2=(char*)::GlobalLock (tempbmpdata2);
  198. DWORD bmp4size;
  199. bmp4size=bmpfilehead4->bfSize-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER)-1024;
  200. char *bmpdata4;
  201. bmpdata4=(char*)::VirtualAlloc(NULL,bmp2size,MEM_COMMIT,PAGE_READWRITE);
  202. //HGLOBAL tempbmpdata2=::GlobalAlloc(GHND, bmp2size);
  203. //bmpdata2=(char*)::GlobalLock (tempbmpdata2);
  204. //读file1和file2的数据区
  205. file1.Seek(1024+54,CFile::begin); 
  206. file1.ReadHuge(bmpdata1,(bmpfilehead1->bfSize-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER)-1024));
  207. file2.Seek(1024+54,CFile::begin);
  208. file2.ReadHuge(bmpdata2,(bmpfilehead2->bfSize-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER)-1024));
  209. file3.Seek(1024+54,CFile::begin);
  210. file3.ReadHuge(bmpdata3,(bmpfilehead2->bfSize-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER)-1024));
  211. file4.Seek(1024+54,CFile::begin);
  212. file4.ReadHuge(bmpdata4,(bmpfilehead2->bfSize-sizeof(BITMAPFILEHEADER)-sizeof(BITMAPINFOHEADER)-1024));
  213. //把file1和file2的数据区合并到file3的数据区中
  214. DWORD endbmpsize;
  215. endbmpsize=bmpfilehead1->bfSize-3*sizeof(BITMAPFILEHEADER)-
  216.             3*sizeof(BITMAPINFOHEADER)-2048*2+bmpfilehead2->bfSize+bmpfilehead3->bfSize+bmpfilehead4->bfSize;
  217. char *endbmp;
  218. endbmp=(char*)::VirtualAlloc(NULL,endbmpsize,MEM_COMMIT,PAGE_READWRITE);
  219. //HGLOBAL endbmpdata=::GlobalAlloc(GHND,endbmpsize);
  220. //endbmp=(char*)::GlobalLock (endbmpdata); 
  221.  
  222. char *temp1=NULL;
  223. char *temp2=NULL;
  224. char *temp3=NULL;
  225. char *temp4=NULL;
  226. char *temp5=NULL;
  227. temp1=bmpdata1;
  228. temp2=bmpdata2;
  229. temp3=bmpdata3;
  230. temp4=bmpdata4;
  231. temp5=endbmp;
  232. for(int j=0;j<bmpfileinfo1->biHeight;j++)//
  233. {
  234.    ::CopyMemory(temp5,temp1,bmpfileinfo1->biWidth);
  235.   //if((temp1-bmpdata1)<=bmp1size)
  236.   temp1+=bmpfileinfo1->biWidth ;
  237.   //if((temp3-endbmp)<= endbmpsize)
  238.   temp5+=bmpfileinfo1->biWidth ;
  239.   ::CopyMemory(temp5,temp2,bmpfileinfo2->biWidth);
  240.   //if((temp2-bmpdata2)<= bmp2size)
  241.   temp2+=bmpfileinfo2->biWidth;
  242.   //if((temp3-endbmp)<= endbmpsize)
  243.   temp5+=bmpfileinfo2->biWidth;
  244.     ::CopyMemory(temp5,temp3,bmpfileinfo3->biWidth);
  245.   //if((temp2-bmpdata2)<= bmp2size)
  246.   temp3+=bmpfileinfo3->biWidth;
  247.   //if((temp3-endbmp)<= endbmpsize)
  248.   temp5+=bmpfileinfo3->biWidth;
  249.     ::CopyMemory(temp5,temp4,bmpfileinfo4->biWidth);
  250.   //if((temp2-bmpdata2)<= bmp2size)
  251.   temp4+=bmpfileinfo4->biWidth;
  252.   //if((temp3-endbmp)<= endbmpsize)
  253.   temp5+=bmpfileinfo4->biWidth;
  254.     
  255. }
  256.  
  257. file5.Open(filename,CFile::modeNoTruncate|CFile::modeCreate|CFile::modeReadWrite,NULL);
  258. //设置file3的调色板
  259. char temp[1024];
  260. for(int i=0;i<256;i++)
  261. {
  262. temp[i*4]=i;
  263. temp[i*4+1]=i;
  264. temp[i*4+2]=i;
  265. temp[i*4+3]=0;
  266. }
  267. bmpfilehead5->bfSize=bmpfilehead2->bfSize -3*sizeof(BITMAPFILEHEADER)-
  268.             3*sizeof(BITMAPINFOHEADER)-3*1024+bmpfilehead1->bfSize+bmpfilehead3->bfSize+bmpfilehead4->bfSize;
  269. bmpfileinfo5->biWidth=bmpfileinfo1->biWidth+bmpfileinfo2->biWidth+bmpfileinfo3->biWidth+bmpfileinfo4->biWidth;
  270. file5.Write(bmpfilehead5,sizeof(BITMAPFILEHEADER));//写file3的文件头
  271. file5.Write(bmpfileinfo5,sizeof(BITMAPINFOHEADER));//写file3的信息头
  272. file5.Write(temp,1024);//写file3的调色板
  273. file5.Write(endbmp,endbmpsize);
  274. free(bmpfilehead1);
  275. free(bmpfilehead2);
  276. free(bmpfilehead3);
  277. free(bmpfilehead4);
  278. free(bmpfilehead5);
  279. free(bmpfileinfo1);
  280. free(bmpfileinfo2);
  281. free(bmpfileinfo3);
  282. free(bmpfileinfo4);
  283. free(bmpfileinfo5);
  284. //::GlobalFree(tempbmpdata1);
  285. //::GlobalFree(tempbmpdata2);
  286. //::GlobalFree(endbmpdata);
  287. ::VirtualFree(bmpdata1,bmp1size,MEM_COMMIT);
  288. ::VirtualFree(bmpdata2,bmp2size,MEM_COMMIT);
  289. ::VirtualFree(bmpdata3,bmp2size,MEM_COMMIT);
  290. ::VirtualFree(bmpdata4,bmp2size,MEM_COMMIT);
  291. ::VirtualFree(endbmp,endbmpsize,MEM_COMMIT);
  292. file1.Close();
  293. file2.Close();
  294. file3.Close();
  295. file4.Close();
  296. file5.Close();
  297. MessageBox("合并完成");
  298. }
  299. }