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

图形图象

开发平台:

Visual C++

  1. // EdgeEnhanceDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "flt_mass.h"
  5. #include "draw.h"
  6. #include "AdjustContrast.h"
  7. #include "DrawPreView.h"
  8. #include "System.h"
  9. #include "EdgeEnhance.h"
  10. #include "ConvoluteKernel.h"
  11. #include "EdgeEnhanceDlg.h"
  12. #ifdef _DEBUG
  13. #define new DEBUG_NEW
  14. #undef THIS_FILE
  15. static char THIS_FILE[] = __FILE__;
  16. #endif
  17. #define DELAYTIME 300
  18. #define LEFT 8
  19. #define TOP 8
  20. /////////////////////////////////////////////////////////////////////////////
  21. // CEdgeEnhanceDlg dialog
  22. CEdgeEnhanceDlg::CEdgeEnhanceDlg(CWnd* pParent /*=NULL*/)
  23. : CDialog(CEdgeEnhanceDlg::IDD, pParent)
  24. {
  25. //{{AFX_DATA_INIT(CEdgeEnhanceDlg)
  26. m_strEdge = _T("100");
  27. m_Check_PreView = TRUE;
  28. //}}AFX_DATA_INIT
  29. m_nComboIndex=0;
  30. m_bMouseDown=FALSE;
  31. m_bMouseShow=TRUE;
  32. m_nEdge=90;
  33. }
  34. void CEdgeEnhanceDlg::DoDataExchange(CDataExchange* pDX)
  35. {
  36. CDialog::DoDataExchange(pDX);
  37. //{{AFX_DATA_MAP(CEdgeEnhanceDlg)
  38. DDX_Control(pDX, IDC_COMBO_FILTER, m_Combo_Filter);
  39. DDX_Control(pDX, IDC_EDIT_EDGE, m_EditEdge);
  40. DDX_Text(pDX, IDC_EDIT_EDGE, m_strEdge);
  41. DDV_MaxChars(pDX, m_strEdge, 3);
  42. DDX_Check(pDX, IDC_CHECK_PRVIEW, m_Check_PreView);
  43. //}}AFX_DATA_MAP
  44. }
  45. BEGIN_MESSAGE_MAP(CEdgeEnhanceDlg, CDialog)
  46. //{{AFX_MSG_MAP(CEdgeEnhanceDlg)
  47. ON_WM_DRAWITEM()
  48. ON_EN_CHANGE(IDC_EDIT_EDGE, OnChangeEditEdge)
  49. ON_WM_TIMER()
  50. ON_CBN_SELCHANGE(IDC_COMBO_FILTER, OnSelchangeComboFilter)
  51. ON_BN_CLICKED(IDC_CHECK_PRVIEW, OnCheckPrview)
  52. ON_WM_MOUSEMOVE()
  53. ON_WM_LBUTTONDOWN()
  54. ON_WM_LBUTTONUP()
  55. ON_WM_PAINT()
  56. //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CEdgeEnhanceDlg message handlers
  60. BOOL CEdgeEnhanceDlg::OnInitDialog() 
  61. {
  62. CDialog::OnInitDialog();
  63. // TODO: Add extra initialization here
  64. CreatMemImage(lpProcInfo);
  65. if(lpProcInfo->sImageInfo .height <PREV_HEIGHT && lpProcInfo->sImageInfo .width <PREV_WIDTH)
  66. {
  67. m_bMouseShow=FALSE;
  68. }
  69. m_nPosx=(lpProcInfo->sImageInfo .width -PREV_WIDTH)/2;
  70. m_nPosy=(lpProcInfo->sImageInfo .height-PREV_HEIGHT)/2;
  71. _fnCOM_SetPos_xy(m_nPosx,m_nPosy);
  72. Oldpoint.x=Oldpoint.y=-1;
  73. m_wndEdgeBar.SubclassDlgItem(IDC_LINETRACK_EDGE, this);
  74. m_wndEdgeBar.InitControl(IDC_EDIT_EDGE,RGB(0,0,0),0, m_nEdge,100,2);
  75. m_wndLogo.SubclassDlgItem (IDC_LOGO_EDGE,this);
  76. m_wndLogo.SetLogoFont ("SIMSUN");
  77. m_wndLogo.SetLogoText ("iSee特效滤镜");
  78. m_curDown = LoadCursor(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDC_MOVE_DOWN));
  79. m_curUp = LoadCursor(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDC_MOVE_UP));
  80. m_curNormal=GetCursor();
  81. InitDraw();
  82. InitComBo();
  83. return TRUE;  // return TRUE unless you set the focus to a control
  84.               // EXCEPTION: OCX Property Pages should return FALSE
  85. }
  86. void CEdgeEnhanceDlg::OnCancel() 
  87. {
  88. // TODO: Add extra cleanup here
  89. KillTimer(1);
  90. ClearPreView();
  91. Del(lpProcInfo->_pdbdata );
  92. CDialog::OnCancel();
  93. }
  94. void CEdgeEnhanceDlg::OnOK() 
  95. {
  96. // TODO: Add extra validation here
  97. KillTimer(1);
  98. BeginWaitCursor ();
  99. ClearPreView();
  100. if(m_nEdge>100)
  101. {
  102. m_nEdge=100;
  103. }
  104. CDialog::OnOK();
  105. EdgeEnhance();
  106. EndWaitCursor ();
  107. }
  108. void CEdgeEnhanceDlg::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
  109. {
  110. // TODO: Add your message handler code here and/or call default
  111. if(m_Check_PreView==TRUE)
  112. _fnCOM_DrawResizePrView(nIDCtl,lpDrawItemStruct);
  113. else
  114. _fnCOM_DrawPrView(nIDCtl,lpDrawItemStruct);
  115. CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
  116. }
  117. void CEdgeEnhanceDlg::OnChangeEditEdge() 
  118. {
  119. // TODO: If this is a RICHEDIT control, the control will not
  120. // send this notification unless you override the CDialog::OnInitDialog()
  121. // function and call CRichEditCtrl().SetEventMask()
  122. // with the ENM_CHANGE flag ORed into the mask.
  123. // TODO: Add your control notification handler code here
  124. UpdateData();
  125. m_nEdge=atoi(m_strEdge);
  126. m_nEdge=atoi(m_strEdge);
  127. if(m_nEdge>100)
  128. {
  129. m_nEdge=100;
  130. }
  131. m_wndEdgeBar.SetPos (m_nEdge);
  132. KillTimer(1);
  133. SetTimer(1,DELAYTIME,NULL);
  134. UpdateData(FALSE);
  135. }
  136. void CEdgeEnhanceDlg::OnTimer(UINT nIDEvent) 
  137. {
  138. // TODO: Add your message handler code here and/or call default
  139. PreViewEdge();
  140. switch(nIDEvent)
  141. {
  142. case 1:
  143. KillTimer(1);
  144. break;
  145. }
  146. CDialog::OnTimer(nIDEvent);
  147. }
  148. void CEdgeEnhanceDlg::InitComBo()
  149. {
  150. m_Combo_Filter.AddString ("炭笔勾廓");
  151. m_Combo_Filter.AddString ("高亮边缘");
  152. m_Combo_Filter.AddString ("水平增强-[平移增强]");
  153. m_Combo_Filter.AddString ("垂直增强-[平移增强]");
  154. m_Combo_Filter.AddString ("垂直水平增强-[平移增强]");
  155. m_Combo_Filter.AddString ("北方向增强-[梯度增强]");
  156. m_Combo_Filter.AddString ("东北方向增强-[梯度增强]");
  157. m_Combo_Filter.AddString ("东方向增强-[梯度增强]");
  158. m_Combo_Filter.AddString ("南方向增强-[梯度增强]");
  159. m_Combo_Filter.AddString ("东南方向增强-[梯度增强]");
  160. m_Combo_Filter.AddString ("西南方向增强-[梯度增强]");
  161. m_Combo_Filter.AddString ("西南方向增强-[梯度增强]");
  162. m_Combo_Filter.AddString ("西北方向增强-[梯度增强]");
  163. m_Combo_Filter.AddString ("调和量算子1-[拉普拉斯算子]");
  164. m_Combo_Filter.AddString ("调和量算子2-[拉普拉斯算子]");
  165. m_Combo_Filter.AddString ("调和量算子3-[拉普拉斯算子]");
  166. m_Combo_Filter.AddString ("调和量算子4-[拉普拉斯算子]");
  167. m_Combo_Filter.AddString ("SOBEL边缘增强");
  168. m_Combo_Filter.AddString ("HOUGH边缘增强");
  169. m_Combo_Filter.SetCurSel (0);
  170. }
  171. void CEdgeEnhanceDlg::OnSelchangeComboFilter() 
  172. {
  173. // TODO: Add your control notification handler code here
  174. KillTimer(1);
  175. SetTimer(1,DELAYTIME,NULL);
  176. }
  177. void CEdgeEnhanceDlg::OnCheckPrview() 
  178. {
  179. // TODO: Add your control notification handler code here
  180. m_Check_PreView=!m_Check_PreView;
  181. UpdateData(FALSE);
  182. ClearPreView();
  183. InitDraw();
  184. GetDlgItem (IDC_PRVIEW_EDGE)->InvalidateRect (NULL,TRUE);
  185. GetDlgItem (IDC_PRVIEW_EDGE)->UpdateWindow();
  186. CRect rcClient;
  187. rcClient.left=LEFT;
  188. rcClient.top =TOP;
  189. rcClient.right =LEFT+PREV_WIDTH+3;
  190. rcClient.bottom =TOP+PREV_HEIGHT+3;
  191. InvalidateRect (rcClient,TRUE);
  192. UpdateWindow();
  193. KillTimer(1);
  194. SetTimer(1,DELAYTIME,NULL);
  195. }
  196. void CEdgeEnhanceDlg::EdgeEnhance()
  197. {
  198. switch(m_Combo_Filter.GetCurSel())
  199. {
  200. case BLACK:
  201. _fnCOM_Edge(lpProcInfo,110-m_nEdge,FALSE);
  202. break;
  203. case HIGHT:
  204. _fnCOM_Edge(lpProcInfo,110-m_nEdge,TRUE);
  205. break;
  206. case VERT:
  207. _fnCOM_Convolute(lpProcInfo,1,m_nEdge+10,&VertEdge);
  208. break;
  209. case HORZ:
  210. _fnCOM_Convolute(lpProcInfo,1,m_nEdge+10,&HorzEdge);
  211. break;
  212. case VERTHORZ:
  213. _fnCOM_Convolute(lpProcInfo,1,m_nEdge+10,&VertHorzEdge);
  214. break;
  215. case NORTH:
  216. _fnCOM_Convolute(lpProcInfo,1,m_nEdge+10,&EdgeNorth);
  217. break;
  218. case NORTHEAST:
  219. _fnCOM_Convolute(lpProcInfo,1,m_nEdge+10,&EdgeNorthEast);
  220. break;
  221. case EAST:
  222. _fnCOM_Convolute(lpProcInfo,1,m_nEdge+10,&EdgeEast);
  223. break;
  224. case SOUTH:
  225. _fnCOM_Convolute(lpProcInfo,1,m_nEdge+10,&EdgeSouth);
  226. break;
  227. case SOUTHEAST:
  228. _fnCOM_Convolute(lpProcInfo,1,m_nEdge+10,&EdgeSouthEast);
  229. break;
  230. case SOUTHWEST:
  231. _fnCOM_Convolute(lpProcInfo,1,m_nEdge+10,&EdgeSouthWest);
  232. break;
  233. case WEST:
  234. _fnCOM_Convolute(lpProcInfo,1,m_nEdge+10,&EdgeWest);
  235. break;
  236. case NORTHWEST:
  237. _fnCOM_Convolute(lpProcInfo,1,m_nEdge+10,&EdgeNorthWest);
  238. break;
  239. case LAP1:
  240. _fnCOM_Convolute(lpProcInfo,1,m_nEdge+10,&Lap1);
  241. break;
  242. case LAP2:
  243. _fnCOM_Convolute(lpProcInfo,1,m_nEdge+10,&Lap2);
  244. break;
  245. case LAP3:
  246. _fnCOM_Convolute(lpProcInfo,1,m_nEdge+10,&Lap3);
  247. break;
  248. case LAP4:
  249. _fnCOM_Convolute(lpProcInfo,1,m_nEdge+10,&Lap4);
  250. break;
  251. case SOBEL:
  252. _fnCOM_Convolute(lpProcInfo,4,m_nEdge+10,Sobel);
  253. break;
  254. case HOUGH:
  255. _fnCOM_Convolute(lpProcInfo,4,m_nEdge+10,Hough);
  256. break;
  257. }
  258. }
  259. void CEdgeEnhanceDlg::PreViewEdge()
  260. {
  261. switch(m_Combo_Filter.GetCurSel())
  262. {
  263. case BLACK:
  264. _fnCOM_AdjustEdgePreView(110-m_nEdge,FALSE);
  265. break;
  266. case HIGHT:
  267. _fnCOM_AdjustEdgePreView(110-m_nEdge,TRUE);
  268. break;
  269. case VERT:
  270. _fnCOM_AdjustConvolutePreView(1,m_nEdge+10,&VertEdge);
  271. break;
  272. case HORZ:
  273. _fnCOM_AdjustConvolutePreView(1,m_nEdge+10,&HorzEdge);
  274. break;
  275. case VERTHORZ:
  276. _fnCOM_AdjustConvolutePreView(1,m_nEdge+10,&VertHorzEdge);
  277. break;
  278. case NORTH:
  279. _fnCOM_AdjustConvolutePreView(1,m_nEdge+10,&EdgeNorth);
  280. break;
  281. case NORTHEAST:
  282. _fnCOM_AdjustConvolutePreView(1,m_nEdge+10,&EdgeNorthEast);
  283. break;
  284. case EAST:
  285. _fnCOM_AdjustConvolutePreView(1,m_nEdge+10,&EdgeEast);
  286. break;
  287. case SOUTH:
  288. _fnCOM_AdjustConvolutePreView(1,m_nEdge+10,&EdgeSouth);
  289. break;
  290. case SOUTHEAST:
  291. _fnCOM_AdjustConvolutePreView(1,m_nEdge+10,&EdgeSouthEast);
  292. break;
  293. case SOUTHWEST:
  294. _fnCOM_AdjustConvolutePreView(1,m_nEdge+10,&EdgeSouthWest);
  295. break;
  296. case WEST:
  297. _fnCOM_AdjustConvolutePreView(1,m_nEdge+10,&EdgeWest);
  298. break;
  299. case NORTHWEST:
  300. _fnCOM_AdjustConvolutePreView(1,m_nEdge+10,&EdgeNorthWest);
  301. break;
  302. case LAP1:
  303. _fnCOM_AdjustConvolutePreView(1,m_nEdge+10,&Lap1);
  304. break;
  305. case LAP2:
  306. _fnCOM_AdjustConvolutePreView(1,m_nEdge+10,&Lap2);
  307. break;
  308. case LAP3:
  309. _fnCOM_AdjustConvolutePreView(1,m_nEdge+10,&Lap3);
  310. break;
  311. case LAP4:
  312. _fnCOM_AdjustConvolutePreView(1,m_nEdge+10,&Lap4);
  313. break;
  314. case SOBEL:
  315. _fnCOM_AdjustConvolutePreView(4,m_nEdge+10,Sobel);
  316. break;
  317. case HOUGH:
  318. _fnCOM_AdjustConvolutePreView(4,m_nEdge+10,Hough);
  319. break;
  320. }
  321. // _fnCOM_PreThresh();
  322. GetDlgItem (IDC_PRVIEW_EDGE)->InvalidateRect (NULL,TRUE);
  323. GetDlgItem (IDC_PRVIEW_EDGE)->UpdateWindow();
  324. }
  325. void CEdgeEnhanceDlg::OnMouseMove(UINT nFlags, CPoint point) 
  326. {
  327. // TODO: Add your message handler code here and/or call default
  328. static x,y;
  329. CRect rcClient;
  330. GetClientRect(rcClient);
  331. if(nFlags==MK_LBUTTON && m_Check_PreView==FALSE && m_bMouseDown==TRUE && m_bMouseShow==TRUE)
  332. {
  333. SetCursor(m_curDown);
  334. ::SetCapture((HWND)(*this));
  335. ClearPreView();
  336. InitDraw();
  337. x=point.x-Oldpoint.x;
  338. y=point.y-Oldpoint.y;
  339. if(m_nPosx<lpProcInfo->sImageInfo.width-PREV_WIDTH+3 && m_nPosx>=0)
  340. {
  341. m_nPosx=_fnCOM_GetPosx()-x;
  342. }
  343. else if(m_nPosx>=lpProcInfo->sImageInfo.width-PREV_WIDTH+3 && x>=0)
  344. {
  345. m_nPosx=_fnCOM_GetPosx()-x;
  346. }
  347. else if(m_nPosx<=0 && x<0)
  348. {
  349. m_nPosx=_fnCOM_GetPosx()-(point.x-Oldpoint.x);
  350. }
  351. if(m_nPosy<lpProcInfo->sImageInfo.height -PREV_HEIGHT && m_nPosy>=0)
  352. {
  353. m_nPosy=_fnCOM_GetPosy()+y;
  354. }
  355. else if(m_nPosy>=lpProcInfo->sImageInfo.height -PREV_HEIGHT && y<0)
  356. {
  357. m_nPosy=_fnCOM_GetPosy()+y;
  358. }
  359. else if(m_nPosy<0 && y>=0)
  360. {
  361. m_nPosy=_fnCOM_GetPosy()+y;
  362. }
  363. if(lpProcInfo->sImageInfo.height>PREV_HEIGHT && lpProcInfo->sImageInfo.width>PREV_WIDTH)
  364. {
  365. if(m_nPosx<=lpProcInfo->sImageInfo.width-PREV_WIDTH+3 &&
  366. m_nPosx>=0 && m_nPosy<=lpProcInfo->sImageInfo.height -PREV_HEIGHT &&
  367. m_nPosy>=0)
  368. {
  369. _fnCOM_SetPos_xy(m_nPosx,m_nPosy);
  370. }
  371. }
  372. else if(lpProcInfo->sImageInfo.height>PREV_HEIGHT && lpProcInfo->sImageInfo.width<=PREV_WIDTH)
  373. {
  374. if(m_nPosy<lpProcInfo->sImageInfo.height -PREV_HEIGHT &&
  375. m_nPosy>=0)
  376. {
  377. _fnCOM_SetPos_xy(m_nPosx,m_nPosy);
  378. }
  379. }
  380. else if(lpProcInfo->sImageInfo.height<=PREV_HEIGHT && lpProcInfo->sImageInfo.width>PREV_WIDTH)
  381. {
  382. if(m_nPosx<=lpProcInfo->sImageInfo.width-PREV_WIDTH+3 &&
  383. m_nPosx>=0 )
  384. {
  385. _fnCOM_SetPos_xy(m_nPosx,m_nPosy);
  386. }
  387. }
  388. Oldpoint.x=point.x;
  389. Oldpoint.y=point.y;
  390. GetDlgItem (IDC_PRVIEW_EDGE)->InvalidateRect (NULL,TRUE);
  391. GetDlgItem (IDC_PRVIEW_EDGE)->UpdateWindow();
  392. KillTimer(1);
  393. SetTimer(1,DELAYTIME,NULL);
  394. }
  395. else if(m_Check_PreView==FALSE && m_bMouseShow==TRUE && m_bMouseDown==FALSE && 
  396. point.x>LEFT && point.x<LEFT+PREV_WIDTH && point.y>TOP && 
  397. point.y<TOP+PREV_HEIGHT)
  398. {
  399. SetCursor(m_curUp);
  400. ::SetCapture((HWND)(*this));
  401. }
  402. else
  403. {
  404. SetCursor(m_curNormal);
  405. ::ReleaseCapture();
  406. }
  407. CDialog::OnMouseMove(nFlags, point);
  408. }
  409. void CEdgeEnhanceDlg::OnLButtonDown(UINT nFlags, CPoint point) 
  410. {
  411. // TODO: Add your message handler code here and/or call default
  412. if(point.x>LEFT && point.x<LEFT+PREV_WIDTH && point.y>TOP && 
  413. point.y<TOP+PREV_HEIGHT && m_Check_PreView==FALSE && m_bMouseShow==TRUE)
  414. {
  415. SetCursor(m_curDown);
  416. ::SetCapture((HWND)(*this));
  417. m_bMouseDown=TRUE;
  418. }
  419. Oldpoint.x=point.x;
  420. Oldpoint.y=point.y;
  421. CDialog::OnLButtonDown(nFlags, point);
  422. }
  423. void CEdgeEnhanceDlg::OnLButtonUp(UINT nFlags, CPoint point) 
  424. {
  425. // TODO: Add your message handler code here and/or call default
  426. if(point.x>LEFT && point.x<LEFT+PREV_WIDTH && point.y>TOP && 
  427. point.y<TOP+PREV_HEIGHT && m_Check_PreView==FALSE && m_bMouseShow==TRUE)
  428. {
  429. SetCursor(m_curUp);
  430. ::SetCapture((HWND)(*this));
  431. }
  432. else
  433. {
  434. SetCursor(m_curNormal);
  435. ::ReleaseCapture();
  436. }
  437. m_bMouseDown=FALSE;
  438. CDialog::OnLButtonUp(nFlags, point);
  439. }
  440. void CEdgeEnhanceDlg::OnPaint() 
  441. {
  442. CPaintDC dc(this); // device context for painting
  443. // TODO: Add your message handler code here
  444. CRect rcClient;
  445. GetClientRect(rcClient);
  446. // draw scale
  447. if (m_MemDC.GetSafeHdc() == NULL)
  448. {
  449. m_MemDC.CreateCompatibleDC(&dc);
  450. m_Bitmap.CreateCompatibleBitmap(&dc,rcClient.Width(),rcClient.Height());
  451. m_MemDC.SelectObject(m_Bitmap);
  452. // draw scale
  453. m_MemDC.SetBkColor(RGB(255,255,255));
  454. CBrush bkBrush;
  455. bkBrush.CreateSysColorBrush(COLOR_ACTIVEBORDER);
  456. m_MemDC.FillRect(rcClient,&bkBrush);
  457. }
  458. if (m_MemDC.GetSafeHdc() != NULL)
  459. dc.BitBlt(0, 0, rcClient.Width(), rcClient.Height(), &m_MemDC, 0, 0, SRCCOPY);
  460. // Do not call CDialog::OnPaint() for painting messages
  461. }