FilterDlg.cpp
上传用户:yatsl7111
上传日期:2007-01-08
资源大小:1433k
文件大小:14k
源码类别:

图形图象

开发平台:

Visual C++

  1. // FilterDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "flt_mass.h"
  5. #include "FilterDlg.h"
  6. #include "DrawPreView.h"
  7. #include "System.h"
  8. #include "ConvoluteKernel.h"
  9. #include "EdgeEnhance.h"
  10. #include "Filter.h"
  11. #include "draw.h"
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17. #define HIGH_FILTER 0
  18. #define MEDIAN_FILTER 1
  19. #define LOW_FILTER 2
  20. #define DELAYTIME 500
  21. #define LEFT 8
  22. #define TOP 8
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CFilterDlg dialog
  25. CFilterDlg::CFilterDlg(CWnd* pParent /*=NULL*/)
  26. : CDialog(CFilterDlg::IDD, pParent)
  27. {
  28. //{{AFX_DATA_INIT(CFilterDlg)
  29. m_Check_PreView = TRUE;
  30. m_strFilter = _T("");
  31. //}}AFX_DATA_INIT
  32. m_bMouseDown=FALSE;
  33. m_bMouseShow=TRUE;
  34. m_nFilter=0;
  35. m_nStrength=100;
  36. }
  37. void CFilterDlg::DoDataExchange(CDataExchange* pDX)
  38. {
  39. CDialog::DoDataExchange(pDX);
  40. //{{AFX_DATA_MAP(CFilterDlg)
  41. DDX_Control(pDX, IDC_BUTTON_EDIT, m_ButEdit);
  42. DDX_Control(pDX, IDC_EDIT_FILTER, m_EditFilter);
  43. DDX_Control(pDX, IDC_TAB_FILTER, m_TabInfo);
  44. DDX_Control(pDX, IDC_COMBO_FILTER, m_Combo_Stype);
  45. DDX_Check(pDX, IDC_CHECK_PREVFILTER, m_Check_PreView);
  46. DDX_Text(pDX, IDC_EDIT_FILTER, m_strFilter);
  47. DDV_MaxChars(pDX, m_strFilter, 3);
  48. //}}AFX_DATA_MAP
  49. }
  50. BEGIN_MESSAGE_MAP(CFilterDlg, CDialog)
  51. //{{AFX_MSG_MAP(CFilterDlg)
  52. ON_WM_DRAWITEM()
  53. ON_CBN_SELCHANGE(IDC_COMBO_FILTER, OnSelchangeComboFilter)
  54. ON_WM_TIMER()
  55. ON_WM_PAINT()
  56. ON_WM_LBUTTONDOWN()
  57. ON_WM_LBUTTONUP()
  58. ON_WM_MOUSEMOVE()
  59. ON_BN_CLICKED(IDC_CHECK_PREVFILTER, OnCheckPrevfilter)
  60. ON_NOTIFY(TCN_SELCHANGE, IDC_TAB_FILTER, OnSelchangeTabFilter)
  61. ON_EN_CHANGE(IDC_EDIT_FILTER, OnChangeEditFilter)
  62. //}}AFX_MSG_MAP
  63. END_MESSAGE_MAP()
  64. /////////////////////////////////////////////////////////////////////////////
  65. // CFilterDlg message handlers
  66. BOOL CFilterDlg::OnInitDialog() 
  67. {
  68. CDialog::OnInitDialog();
  69. // TODO: Add extra initialization here
  70. //创建内存图像
  71. CreatMemImage(lpProcInfo);
  72. if(lpProcInfo->sImageInfo .height <PREV_HEIGHT && lpProcInfo->sImageInfo .width <PREV_WIDTH)
  73. {
  74. m_bMouseShow=FALSE;
  75. }
  76. m_nPosx=(lpProcInfo->sImageInfo .width -PREV_WIDTH)/2;
  77. m_nPosy=(lpProcInfo->sImageInfo .height-PREV_HEIGHT)/2;
  78. _fnCOM_SetPos_xy(m_nPosx,m_nPosy);
  79. Oldpoint.x=Oldpoint.y=-1;
  80. m_curDown = LoadCursor(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDC_MOVE_DOWN));
  81. m_curUp = LoadCursor(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDC_MOVE_UP));
  82. m_curNormal=GetCursor();
  83. m_wndFilterBar.SubclassDlgItem(IDC_LINETRACK_FILTER, this);
  84. m_wndFilterBar.InitControl(IDC_EDIT_FILTER,RGB(0,0,0),0, m_nStrength,200,1);
  85. // m_wndFilterBar.SetDisabled ();
  86. // DWORD dwStyle=GetWindowLong((HWND)m_wndFilterBar.GetDlgItem (IDC_LINETRACK_FILTER),GWL_STYLE);
  87. // dwStyle+=WS_DISABLED;
  88. // SetWindowLong((HWND)m_wndFilterBar.GetDlgItem (IDC_LINETRACK_FILTER),GWL_STYLE,dwStyle);
  89. m_wndLogo.SubclassDlgItem (IDC_LOGO_FILTER,this);
  90. m_wndLogo.SetLogoFont ("SIMSUN");
  91. m_wndLogo.SetLogoText ("iSee特效滤镜");
  92. InitDraw();
  93. InitCombo();
  94. if(m_TabInfo.GetItemCount()!=3)
  95. {
  96. m_TabInfo.InsertItem (0,"高通滤波");
  97. m_TabInfo.InsertItem (1,"中值滤波");
  98. m_TabInfo.InsertItem (2,"低通滤波");
  99. m_TabInfo.InsertItem (3,"自定义");
  100. }
  101. m_wndFilterBar.ShowWindow (SW_SHOWNORMAL);
  102. // GetDlgItem(IDC_BUTTON_EDIT)->ShowWindow(SW_SHOWNORMAL);
  103. m_ButEdit.EnableWindow (FALSE);
  104. KillTimer(1);
  105. SetTimer(1,DELAYTIME,NULL);
  106. return TRUE;  // return TRUE unless you set the focus to a control
  107.               // EXCEPTION: OCX Property Pages should return FALSE
  108. }
  109. void CFilterDlg::OnOK() 
  110. {
  111. // TODO: Add extra validation here
  112. KillTimer(1);
  113. BeginWaitCursor ();
  114. ClearPreView();
  115. CDialog::OnOK();
  116. Filter();
  117. EndWaitCursor ();
  118. }
  119. void CFilterDlg::OnCancel() 
  120. {
  121. // TODO: Add extra cleanup here
  122. KillTimer(1);
  123. ClearPreView();
  124. Del(lpProcInfo->_pdbdata );
  125. CDialog::OnCancel();
  126. }
  127. void CFilterDlg::Filter()
  128. {
  129. static int nSelect=m_Combo_Stype.GetCurSel();
  130. switch(m_nFilter)
  131. {
  132. case 0:
  133. switch(nSelect)
  134. {
  135. case 0:
  136. //  _fnCOM_Convolute(lpProcInfo,1,100,&HP1);
  137.  _fnCOM_HighFilter(lpProcInfo,m_nStrength,0);
  138. break;
  139. case 1:
  140. _fnCOM_Convolute(lpProcInfo,1,m_nStrength,&HP1);
  141. break;
  142. case 2:
  143. _fnCOM_Convolute(lpProcInfo,1,m_nStrength,&HP2);
  144. break;
  145. case 3:
  146. _fnCOM_Convolute(lpProcInfo,1,m_nStrength,&HP3);
  147. break;
  148. }
  149. break;
  150. case 1:
  151. _fnCOM_MedianFilter(lpProcInfo,m_nStrength,nSelect);
  152. break;
  153. case 2:
  154. switch(nSelect)
  155. {
  156. case 0:
  157.  _fnCOM_Convolute(lpProcInfo,1,m_nStrength,&LP1);
  158. break;
  159. case 1:
  160.  _fnCOM_Convolute(lpProcInfo,1,m_nStrength,&LP2);
  161. break;
  162. case 2:
  163.  _fnCOM_Convolute(lpProcInfo,1,m_nStrength,&LP3);
  164. break;
  165. }
  166. break;
  167. case 3:
  168. switch(m_Combo_Stype.GetCurSel())
  169. {
  170. case 0:
  171. break;
  172. case 1:
  173. break;
  174. case 2:
  175. break;
  176. case 3:
  177. break;
  178. case 4:
  179. break;
  180. case 5:
  181. break;
  182. case 6:
  183. break;
  184. case 7:
  185. break;
  186. case 8:
  187. break;
  188. }
  189. break;
  190. }
  191. }
  192. void CFilterDlg::InitCombo()
  193. {
  194. m_Combo_Stype.ResetContent ();
  195. switch(m_nFilter)
  196. {
  197. case 0:
  198. m_Combo_Stype.AddString ("清晰画面-[强度无效]");
  199. m_Combo_Stype.AddString ("高通滤波1");
  200. m_Combo_Stype.AddString ("高通滤波2");
  201. m_Combo_Stype.AddString ("高通滤波3");
  202. // GetDlgItem(IDC_STATIC_FILTER)->SetWindowText("强度:");
  203. m_ButEdit.EnableWindow (FALSE);
  204. break;
  205. case 1:
  206. m_Combo_Stype.AddString ("中间值-[去斑点]");
  207. m_Combo_Stype.AddString ("最小值");
  208. m_Combo_Stype.AddString ("最大值");
  209. // GetDlgItem(IDC_STATIC_FILTER)->SetWindowText("半径:");
  210. m_ButEdit.EnableWindow (FALSE);
  211. break;
  212. case 2:
  213. m_Combo_Stype.AddString ("低通滤波1");
  214. m_Combo_Stype.AddString ("低通滤波2");
  215. m_Combo_Stype.AddString ("低通滤波3");
  216. // GetDlgItem(IDC_STATIC_FILTER)->SetWindowText("强度:");
  217. m_ButEdit.EnableWindow (FALSE);
  218. break;
  219. case 3:
  220. m_Combo_Stype.AddString ("自定义风格1");
  221. m_Combo_Stype.AddString ("自定义风格2");
  222. m_Combo_Stype.AddString ("自定义风格3");
  223. m_Combo_Stype.AddString ("自定义风格4");
  224. m_Combo_Stype.AddString ("自定义风格5");
  225. m_Combo_Stype.AddString ("自定义风格6");
  226. m_Combo_Stype.AddString ("自定义风格7");
  227. m_Combo_Stype.AddString ("自定义风格8");
  228. m_Combo_Stype.AddString ("自定义风格9");
  229. m_ButEdit.EnableWindow ();
  230. // GetDlgItem(IDC_STATIC_FILTER)->SetWindowText("强度:");
  231. break;
  232. }
  233. m_Combo_Stype.SetCurSel (0);
  234. }
  235. void CFilterDlg::PreView()
  236. {
  237. switch(m_nFilter)
  238. {
  239. case 0:
  240. switch(m_Combo_Stype.GetCurSel())
  241. {
  242. case 0:
  243. _fnCOM_HighFilterPreView(m_nStrength,0);
  244. break;
  245. case 1:
  246.  _fnCOM_AdjustConvolutePreView(1,m_nStrength,&HP1);
  247. break;
  248. case 2:
  249. _fnCOM_AdjustConvolutePreView(1,m_nStrength,&HP2);
  250. break;
  251. case 3:
  252. _fnCOM_AdjustConvolutePreView(1,m_nStrength,&HP3);
  253. break;
  254. }
  255. break;
  256. case 1:
  257. _fnCOM_MedianFilterPreView(m_nStrength,m_Combo_Stype.GetCurSel());
  258. break;
  259. case 2:
  260. switch(m_Combo_Stype.GetCurSel())
  261. {
  262. case 0:
  263.  _fnCOM_AdjustConvolutePreView(1,m_nStrength,&LP1);
  264. break;
  265. case 1:
  266.  _fnCOM_AdjustConvolutePreView(1,m_nStrength,&LP2);
  267. break;
  268. case 2:
  269.  _fnCOM_AdjustConvolutePreView(1,m_nStrength,&LP3);
  270. break;
  271. }
  272. break;
  273. case 3:
  274. switch(m_Combo_Stype.GetCurSel())
  275. {
  276. case 0:
  277. break;
  278. case 1:
  279. break;
  280. case 2:
  281. break;
  282. case 3:
  283. break;
  284. case 4:
  285. break;
  286. case 5:
  287. break;
  288. case 6:
  289. break;
  290. case 7:
  291. break;
  292. case 8:
  293. break;
  294. }
  295. break;
  296. }
  297. GetDlgItem (IDC_PRVIEW_FILTER)->InvalidateRect (NULL,TRUE);
  298. GetDlgItem (IDC_PRVIEW_FILTER)->UpdateWindow();
  299. }
  300. void CFilterDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
  301. {
  302. // TODO: Add your message handler code here and/or call default
  303. if(m_Check_PreView==TRUE)
  304. _fnCOM_DrawResizePrView(nIDCtl,lpDrawItemStruct);
  305. else
  306. _fnCOM_DrawPrView(nIDCtl,lpDrawItemStruct);
  307. CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
  308. }
  309. void CFilterDlg::OnSelchangeComboFilter() 
  310. {
  311. // TODO: Add your control notification handler code here
  312. KillTimer(1);
  313. SetTimer(1,DELAYTIME,NULL);
  314. }
  315. void CFilterDlg::OnTimer(UINT nIDEvent) 
  316. {
  317. // TODO: Add your message handler code here and/or call default
  318. PreView();
  319. switch(nIDEvent)
  320. {
  321. case 1:
  322. KillTimer(1);
  323. break;
  324. }
  325. CDialog::OnTimer(nIDEvent);
  326. }
  327. void CFilterDlg::OnPaint() 
  328. {
  329. CPaintDC dc(this); // device context for painting
  330. // TODO: Add your message handler code here
  331. CRect rcClient;
  332. GetClientRect(rcClient);
  333. // draw scale
  334. if (m_MemDC.GetSafeHdc() == NULL)
  335. {
  336. m_MemDC.CreateCompatibleDC(&dc);
  337. m_Bitmap.CreateCompatibleBitmap(&dc,rcClient.Width(),rcClient.Height());
  338. m_MemDC.SelectObject(m_Bitmap);
  339. // draw scale
  340. m_MemDC.SetBkColor(RGB(255,255,255));
  341. CBrush bkBrush;
  342. bkBrush.CreateSysColorBrush(COLOR_ACTIVEBORDER);
  343. m_MemDC.FillRect(rcClient,&bkBrush);
  344. }
  345. if (m_MemDC.GetSafeHdc() != NULL)
  346. dc.BitBlt(0, 0, rcClient.Width(), rcClient.Height(), &m_MemDC, 0, 0, SRCCOPY);
  347. // Do not call CDialog::OnPaint() for painting messages
  348. }
  349. void CFilterDlg::OnLButtonDown(UINT nFlags, CPoint point) 
  350. {
  351. // TODO: Add your message handler code here and/or call default
  352. if(point.x>LEFT && point.x<LEFT+PREV_WIDTH && point.y>TOP && 
  353. point.y<TOP+PREV_HEIGHT && m_Check_PreView==FALSE && m_bMouseShow==TRUE)
  354. {
  355. SetCursor(m_curDown);
  356. ::SetCapture((HWND)(*this));
  357. m_bMouseDown=TRUE;
  358. }
  359. Oldpoint.x=point.x;
  360. Oldpoint.y=point.y;
  361. CDialog::OnLButtonDown(nFlags, point);
  362. }
  363. void CFilterDlg::OnLButtonUp(UINT nFlags, CPoint point) 
  364. {
  365. // TODO: Add your message handler code here and/or call default
  366. if(point.x>LEFT && point.x<LEFT+PREV_WIDTH && point.y>TOP && 
  367. point.y<TOP+PREV_HEIGHT && m_Check_PreView==FALSE && m_bMouseShow==TRUE)
  368. {
  369. SetCursor(m_curUp);
  370. ::SetCapture((HWND)(*this));
  371. }
  372. else
  373. {
  374. SetCursor(m_curNormal);
  375. ::ReleaseCapture();
  376. }
  377. m_bMouseDown=FALSE;
  378. CDialog::OnLButtonUp(nFlags, point);
  379. }
  380. void CFilterDlg::OnMouseMove(UINT nFlags, CPoint point) 
  381. {
  382. // TODO: Add your message handler code here and/or call default
  383. static x,y;
  384. CRect rcClient;
  385. GetClientRect(rcClient);
  386. if(nFlags==MK_LBUTTON && m_Check_PreView==FALSE && m_bMouseDown==TRUE && m_bMouseShow==TRUE)
  387. {
  388. SetCursor(m_curDown);
  389. ::SetCapture((HWND)(*this));
  390. ClearPreView();
  391. InitDraw();
  392. x=point.x-Oldpoint.x;
  393. y=point.y-Oldpoint.y;
  394. if(m_nPosx<lpProcInfo->sImageInfo.width-PREV_WIDTH+3 && m_nPosx>=0)
  395. {
  396. m_nPosx=_fnCOM_GetPosx()-x;
  397. }
  398. else if(m_nPosx>=lpProcInfo->sImageInfo.width-PREV_WIDTH+3 && x>=0)
  399. {
  400. m_nPosx=_fnCOM_GetPosx()-x;
  401. }
  402. else if(m_nPosx<=0 && x<0)
  403. {
  404. m_nPosx=_fnCOM_GetPosx()-(point.x-Oldpoint.x);
  405. }
  406. if(m_nPosy<lpProcInfo->sImageInfo.height -PREV_HEIGHT && m_nPosy>=0)
  407. {
  408. m_nPosy=_fnCOM_GetPosy()+y;
  409. }
  410. else if(m_nPosy>=lpProcInfo->sImageInfo.height -PREV_HEIGHT && y<0)
  411. {
  412. m_nPosy=_fnCOM_GetPosy()+y;
  413. }
  414. else if(m_nPosy<0 && y>=0)
  415. {
  416. m_nPosy=_fnCOM_GetPosy()+y;
  417. }
  418. if(lpProcInfo->sImageInfo.height>PREV_HEIGHT && lpProcInfo->sImageInfo.width>PREV_WIDTH)
  419. {
  420. if(m_nPosx<=lpProcInfo->sImageInfo.width-PREV_WIDTH+3 &&
  421. m_nPosx>=0 && m_nPosy<=lpProcInfo->sImageInfo.height -PREV_HEIGHT &&
  422. m_nPosy>=0)
  423. {
  424. _fnCOM_SetPos_xy(m_nPosx,m_nPosy);
  425. }
  426. }
  427. else if(lpProcInfo->sImageInfo.height>PREV_HEIGHT && lpProcInfo->sImageInfo.width<=PREV_WIDTH)
  428. {
  429. if(m_nPosy<lpProcInfo->sImageInfo.height -PREV_HEIGHT &&
  430. m_nPosy>=0)
  431. {
  432. _fnCOM_SetPos_xy(m_nPosx,m_nPosy);
  433. }
  434. }
  435. else if(lpProcInfo->sImageInfo.height<=PREV_HEIGHT && lpProcInfo->sImageInfo.width>PREV_WIDTH)
  436. {
  437. if(m_nPosx<=lpProcInfo->sImageInfo.width-PREV_WIDTH+3 &&
  438. m_nPosx>=0 )
  439. {
  440. _fnCOM_SetPos_xy(m_nPosx,m_nPosy);
  441. }
  442. }
  443. Oldpoint.x=point.x;
  444. Oldpoint.y=point.y;
  445. GetDlgItem (IDC_PRVIEW_FILTER)->InvalidateRect (NULL,TRUE);
  446. GetDlgItem (IDC_PRVIEW_FILTER)->UpdateWindow();
  447. KillTimer(1);
  448. SetTimer(1,DELAYTIME,NULL);
  449. }
  450. else if(m_Check_PreView==FALSE && m_bMouseShow==TRUE && m_bMouseDown==FALSE && 
  451. point.x>LEFT && point.x<LEFT+PREV_WIDTH && point.y>TOP && 
  452. point.y<TOP+PREV_HEIGHT)
  453. {
  454. SetCursor(m_curUp);
  455. ::SetCapture((HWND)(*this));
  456. }
  457. else
  458. {
  459. SetCursor(m_curNormal);
  460. ::ReleaseCapture();
  461. }
  462. CDialog::OnMouseMove(nFlags, point);
  463. }
  464. void CFilterDlg::OnCheckPrevfilter() 
  465. {
  466. // TODO: Add your control notification handler code here
  467. m_Check_PreView=!m_Check_PreView;
  468. UpdateData(FALSE);
  469. ClearPreView();
  470. InitDraw();
  471. GetDlgItem (IDC_PRVIEW_FILTER)->InvalidateRect (NULL,TRUE);
  472. GetDlgItem (IDC_PRVIEW_FILTER)->UpdateWindow();
  473. CRect rcClient;
  474. rcClient.left=LEFT;
  475. rcClient.top =TOP;
  476. rcClient.right =LEFT+PREV_WIDTH+3;
  477. rcClient.bottom =TOP+PREV_HEIGHT+3;
  478. InvalidateRect (rcClient,TRUE);
  479. UpdateWindow();
  480. KillTimer(1);
  481. SetTimer(1,DELAYTIME,NULL);
  482. }
  483. void CFilterDlg::OnSelchangeTabFilter(NMHDR* pNMHDR, LRESULT* pResult) 
  484. {
  485. // TODO: Add your control notification handler code here
  486. m_nFilter=m_TabInfo.GetCurSel ();
  487. InitCombo();
  488. KillTimer(1);
  489. SetTimer(1,DELAYTIME,NULL);
  490. *pResult = 0;
  491. }
  492. void CFilterDlg::OnChangeEditFilter() 
  493. {
  494. // TODO: If this is a RICHEDIT control, the control will not
  495. // send this notification unless you override the CDialog::OnInitDialog()
  496. // function and call CRichEditCtrl().SetEventMask()
  497. // with the ENM_CHANGE flag ORed into the mask.
  498. // TODO: Add your control notification handler code here
  499. UpdateData();
  500. m_nStrength=atoi(m_strFilter);
  501. m_nStrength=atoi(m_strFilter);
  502. if(m_nStrength>200)
  503. {
  504. m_nStrength=200;
  505. }
  506. m_wndFilterBar.SetPos (m_nStrength);
  507. KillTimer(1);
  508. SetTimer(1,DELAYTIME,NULL);
  509. UpdateData(FALSE);
  510. }