ED256View.cpp
上传用户:dfwb928
上传日期:2013-04-20
资源大小:228k
文件大小:16k
源码类别:

图形图象

开发平台:

Visual C++

  1. //////////////////////////////////////////////////////////////////
  2. // CED256View class (17/10/2000)
  3. // Author: James Matthews
  4. //
  5. // Implements a simple edge detection algorithm and 
  6. // prototyping system.
  7. //
  8. // Written for Generation5 (http://www.generation5.org/)
  9. //
  10. // See http://www.generation5.org/vision.shtml
  11. //     http://www.generation5.org/edgedetect.shtml for details.
  12. //
  13. #include "stdafx.h"
  14. #include "ED256.h"
  15. #include "ED256Doc.h"
  16. #include "ED256View.h"
  17. #include "Mainfrm.h"
  18. #include <math.h>
  19. #include <memory.h>
  20. #include "FilterDlg.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CED256View
  28. IMPLEMENT_DYNCREATE(CED256View, CView)
  29. BEGIN_MESSAGE_MAP(CED256View, CView)
  30. //{{AFX_MSG_MAP(CED256View)
  31. ON_COMMAND(ID_EDIT_EDGEDETECT, OnEditEdgeDetect)
  32. ON_COMMAND(ID_COLOURTYPE, OnColourType)
  33. ON_COMMAND(ID_FORMULA, OnFormula)
  34. ON_COMMAND(ID_EDIT_FORMULATYPE_DIFFERENCEAND, OnEditFormulatypeDifferenceand)
  35. ON_COMMAND(ID_EDIT_FORMULATYPE_DIFFERENCEOR, OnEditFormulatypeDifferenceor)
  36. ON_COMMAND(ID_EDIT_FORMULATYPE_SUMMATION, OnEditFormulatypeSummation)
  37. ON_COMMAND(ID_INVERSE, OnInverse)
  38. ON_COMMAND(ID_FILTER, OnFilter)
  39. ON_UPDATE_COMMAND_UI(ID_COLOURTYPE, OnUpdateColourtype)
  40. ON_UPDATE_COMMAND_UI(ID_INVERSE, OnUpdateInverse)
  41. ON_COMMAND(ID_EDIT_OUTPUT_BLACKANDWHITE, OnEditOutputBlackandwhite)
  42. ON_COMMAND(ID_EDIT_OUTPUT_COLOUR, OnEditOutputColour)
  43. ON_UPDATE_COMMAND_UI(ID_EDIT_OUTPUT_BLACKANDWHITE, OnUpdateEditOutputBlackandwhite)
  44. ON_UPDATE_COMMAND_UI(ID_EDIT_OUTPUT_COLOUR, OnUpdateEditOutputColour)
  45. ON_UPDATE_COMMAND_UI(ID_EDIT_FORMULATYPE_DIFFERENCEAND, OnUpdateEditFormulatypeDifferenceand)
  46. ON_UPDATE_COMMAND_UI(ID_EDIT_FORMULATYPE_DIFFERENCEOR, OnUpdateEditFormulatypeDifferenceor)
  47. ON_UPDATE_COMMAND_UI(ID_EDIT_FORMULATYPE_SUMMATION, OnUpdateEditFormulatypeSummation)
  48. ON_WM_ERASEBKGND()
  49. ON_COMMAND(ID_EDIT_PROTOTYPING, OnEditPrototyping)
  50. ON_COMMAND(ID_CHANGERESOLUTION, OnChangeResolution)
  51. ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
  52. ON_UPDATE_COMMAND_UI(ID_RES_LOW, OnUpdateResLow)
  53. ON_UPDATE_COMMAND_UI(ID_RES_MEDIUM, OnUpdateResMedium)
  54. ON_UPDATE_COMMAND_UI(ID_RES_HIGH, OnUpdateResHigh)
  55. //}}AFX_MSG_MAP
  56. ON_COMMAND_RANGE(ID_RES_LOW, ID_RES_HIGH, OnResolution)
  57. END_MESSAGE_MAP()
  58. /////////////////////////////////////////////////////////////////////////////
  59. // CED256View construction/destruction
  60. CED256View::CED256View() {
  61. m_iFormula = 0;
  62. m_iResolution = 4;
  63. m_bColour = true;
  64. m_bInverse = false;
  65. m_crPlot = RGB(0,0,0);
  66. m_crNoPlot = RGB(255,255,255);
  67. m_fFilter[0] = 1/6.0f;
  68. m_fFilter[1] = 2/3.0f;
  69. m_fFilter[2] = 1/6.0f;
  70. m_fFilter[3] = 2/3.0f;
  71. m_fFilter[4] = -10/3.0f;
  72. m_fFilter[5] = 2/3.0f;
  73. m_fFilter[6] = 1/6.0f;
  74. m_fFilter[7] = 2/3.0f;
  75. m_fFilter[8] = 1/6.0f;
  76. m_crProtoColours[0] = RGB(255,0,0);
  77. m_crProtoColours[1] = RGB(128,0,0);
  78. m_crProtoColours[2] = RGB(0,255,0);
  79. m_crProtoColours[3] = RGB(0,128,0);
  80. m_crProtoColours[4] = RGB(0,0,255);
  81. m_crProtoColours[5] = RGB(0,0,128);
  82. m_crProtoColours[6] = RGB(255,0,255);
  83. m_crProtoColours[7] = RGB(128,0,128);
  84. m_crProtoColours[8] = RGB(0,0,0);
  85. m_crProtoColours[9] = RGB(255,255,255);
  86. }
  87. CED256View::~CED256View() {}
  88. BOOL CED256View::PreCreateWindow(CREATESTRUCT& cs) {
  89. return CView::PreCreateWindow(cs);
  90. }
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CED256View drawing
  93. void CED256View::OnDraw(CDC* pDC) {
  94. CED256Doc* pDoc = GetDocument();
  95. ASSERT_VALID(pDoc);
  96. CRect rect;
  97. GetClientRect(&rect);
  98. CDC dc;
  99. CBitmap bmp, *oldbmp;
  100. dc.CreateCompatibleDC(pDC);
  101. bmp.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height());
  102. oldbmp = dc.SelectObject(&bmp);
  103. dc.FillSolidRect(rect, RGB(255,255,255));
  104. int cxDIB = 0, cyDIB = 0;
  105. HDIB hDIB = pDoc->GetHDIB();
  106. if (hDIB) {
  107. LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
  108. cxDIB = (int) ::DIBWidth(lpDIB);
  109. cyDIB = (int) ::DIBHeight(lpDIB);
  110. ::GlobalUnlock((HGLOBAL) hDIB);
  111. CRect rcDIB;
  112. rcDIB.top = rcDIB.left = 0;
  113. rcDIB.right = cxDIB;
  114. rcDIB.bottom = cyDIB;
  115. CRect rcDest = rcDIB;
  116. if (cxDIB * 2 <= rect.Width() || !(HBITMAP(m_bmpEdges))) {
  117. ::PaintDIB(dc.m_hDC, &rcDest, hDIB,
  118. &rcDIB, pDoc->GetDocPalette());
  119. }
  120. }
  121. if ((HBITMAP)(m_bmpEdges)) {
  122. CDC cdc;
  123. CBitmap *oldbmp;
  124. cdc.CreateCompatibleDC(pDC);
  125. oldbmp = cdc.SelectObject(&m_bmpEdges);
  126. if (cxDIB * 2 < rect.Width()) {
  127. dc.BitBlt(cxDIB+1,0,cxDIB,cyDIB+m_iOffset,&cdc,0,0,SRCCOPY);
  128. } else {
  129. dc.BitBlt(0,0,cxDIB,cyDIB+m_iOffset,&cdc,0,0,SRCCOPY);
  130. }
  131. }
  132. pDC->BitBlt(0,0,rect.Width(),rect.Height(),&dc,0,0,SRCCOPY);
  133. dc.SelectObject(oldbmp);
  134. }
  135. /////////////////////////////////////////////////////////////////////////////
  136. // CED256View diagnostics
  137. #ifdef _DEBUG
  138. void CED256View::AssertValid() const {
  139. CView::AssertValid();
  140. }
  141. void CED256View::Dump(CDumpContext& dc) const {
  142. CView::Dump(dc);
  143. }
  144. CED256Doc* CED256View::GetDocument() {
  145. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CED256Doc)));
  146. return (CED256Doc*)m_pDocument;
  147. }
  148. #endif //_DEBUG
  149. /////////////////////////////////////////////////////////////////////////////
  150. // CED256View message handlers
  151. void CED256View::OnEditEdgeDetect() {
  152. CWaitCursor wait;
  153. CMainFrame* pMfm = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  154. m_iOffset = 0;
  155. int thresh = pMfm->m_iThreshold;
  156. CDC sc1,sc2; 
  157. CClientDC dc(this);
  158. sc1.CreateCompatibleDC(&dc);
  159. sc2.CreateCompatibleDC(&dc);
  160. CBitmap *src1old, bmsrc, *src2old;
  161. int cxDIB, cyDIB;
  162. CED256Doc* pDoc = GetDocument();
  163. HDIB hDIB = pDoc->GetHDIB();
  164. GetDIBSize(cxDIB, cyDIB);
  165. if ((HBITMAP)(m_bmpEdges)) m_bmpEdges.Detach();
  166. bmsrc.CreateCompatibleBitmap(&dc, cxDIB, cyDIB);
  167. m_bmpEdges.CreateCompatibleBitmap(&dc, cxDIB, cyDIB);
  168.    
  169. src1old = sc1.SelectObject(&bmsrc);
  170. src2old = sc2.SelectObject(&m_bmpEdges);
  171. ::PaintDIB(sc1.m_hDC, &CRect(0,0,cxDIB,cyDIB), hDIB,
  172. &CRect(0,0,cxDIB,cyDIB), pDoc->GetDocPalette());
  173. float red, blue, green;
  174. // int red, blue, green;
  175. for (int i=1;i<cxDIB-1;i++) {
  176. for (int j=1;j<cyDIB-1;j++) {
  177. red = blue = green = 0;
  178. UpdateTotals(red, blue, green, m_fFilter[4], sc1.GetPixel(i,j));
  179. UpdateTotals(red, blue, green, m_fFilter[0], sc1.GetPixel(i-1,j));
  180. UpdateTotals(red, blue, green, m_fFilter[2], sc1.GetPixel(i+1,j));
  181. UpdateTotals(red, blue, green, m_fFilter[6], sc1.GetPixel(i,j-1));
  182. UpdateTotals(red, blue, green, m_fFilter[8], sc1.GetPixel(i,j+1));
  183. UpdateTotals(red, blue, green, m_fFilter[1], sc1.GetPixel(i-1,j-1));
  184. UpdateTotals(red, blue, green, m_fFilter[3], sc1.GetPixel(i+1,j-1));
  185. UpdateTotals(red, blue, green, m_fFilter[5], sc1.GetPixel(i-1,j+1));
  186. UpdateTotals(red, blue, green, m_fFilter[7], sc1.GetPixel(i+1,j+1));
  187. // Get the threshold value, and check whether any of the
  188. // values exceed the threshold value.
  189. if (Plot(int(red),int(green),int(blue),thresh)) {
  190. if (m_bColour)
  191. sc2.SetPixel(i,j, RGB(int(red),int(blue),int(green)));
  192. else sc2.SetPixel(i,j, m_crPlot);
  193. } else {
  194. sc2.SetPixel(i,j, m_crNoPlot);
  195. }
  196. }
  197. pMfm->PercentComplete(i / float(cxDIB) * 100);
  198. }
  199. CBrush br(RGB(0,0,0));
  200. sc2.FrameRect(&CRect(0,0,cxDIB, cyDIB), &br);
  201. sc1.SelectObject(src1old);
  202. sc2.SelectObject(src2old);
  203. Invalidate();
  204. pMfm->SetStatusMessage(AFX_IDS_IDLEMESSAGE);
  205. }
  206. void CED256View::UpdateTotals(float &r, float &g, float &b, float filter, COLORREF cr) {
  207. r += GetRValue(cr)*filter;
  208. b += GetBValue(cr)*filter;
  209. g += GetGValue(cr)*filter;
  210. }
  211. void CED256View::OnColourType() {
  212. m_bColour = !m_bColour;
  213. }
  214. void CED256View::OnFormula() {
  215. CMainFrame* pMfm = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  216. PullDownToolBar(pMfm->GetToolbar(), ID_FORMULA, IDR_FORMULA, m_iFormula);
  217. }
  218. void CED256View::PullDownToolBar(CToolBar *bar, UINT uButton, UINT uMenu, int bold) {
  219. // To be professional, get the index from the command ID.
  220. int ind = bar->CommandToIndex(uButton);
  221. if (ind == -1) return;
  222. CRect rect;
  223. bar->GetItemRect(ind,&rect);
  224. bar->ClientToScreen(&rect);
  225. CMenu menu;
  226. VERIFY(menu.LoadMenu(uMenu));
  227. CMenu* pPopup = menu.GetSubMenu(0);
  228. ASSERT(pPopup != NULL); 
  229. if (bold > -1) SetMenuDefaultItem(pPopup->m_hMenu, bold, true);
  230. pPopup->TrackPopupMenu(TPM_LEFTALIGN, rect.TopLeft().x, rect.BottomRight().y, this);
  231. }
  232. bool CED256View::Plot(int r, int g, int b, int t) {
  233. switch(m_iFormula) {
  234. case 0: return (r > t && g > t && b > t);
  235. case 1: return (r > t || g > t || b > t);
  236. case 2: return (r+g+b > t);
  237. }
  238.   return false;
  239. }
  240. void CED256View::OnEditFormulatypeDifferenceand() {
  241. m_iFormula = 0;
  242. }
  243. void CED256View::OnEditFormulatypeDifferenceor() {
  244. m_iFormula = 1;
  245. }
  246. void CED256View::OnEditFormulatypeSummation() {
  247. m_iFormula = 2;
  248. }
  249. void CED256View::OnInverse() {
  250. m_bInverse = !m_bInverse;
  251. if (!m_bInverse) {
  252. m_crPlot = RGB(0,0,0);
  253. m_crNoPlot = RGB(255,255,255);
  254. } else {
  255. m_crPlot = RGB(255,255,255);
  256. m_crNoPlot = RGB(0,0,0);
  257. }
  258. }
  259. void CED256View::OnFilter() {
  260. CFilterDlg dlg;
  261. dlg.SetFilter(&m_fFilter[0]);
  262. dlg.DoModal();
  263. m_fFilter[0] = dlg.m_fEdit1;
  264. m_fFilter[1] = dlg.m_fEdit2;
  265. m_fFilter[2] = dlg.m_fEdit3;
  266. m_fFilter[3] = dlg.m_fEdit4;
  267. m_fFilter[4] = dlg.m_fEdit5;
  268. m_fFilter[5] = dlg.m_fEdit6;
  269. m_fFilter[6] = dlg.m_fEdit7;
  270. m_fFilter[7] = dlg.m_fEdit8;
  271. m_fFilter[8] = dlg.m_fEdit9;
  272. }
  273. void CED256View::OnUpdateColourtype(CCmdUI* pCmdUI) {
  274. pCmdUI->SetCheck(m_bColour);
  275. }
  276. void CED256View::OnUpdateInverse(CCmdUI* pCmdUI) {
  277. pCmdUI->SetCheck(m_bInverse);
  278. }
  279. void CED256View::OnEditOutputBlackandwhite() {
  280. m_bColour = false;
  281. }
  282. void CED256View::OnEditOutputColour() {
  283. m_bColour = true;
  284. }
  285. void CED256View::OnInitialUpdate() {
  286. CView::OnInitialUpdate();
  287. if ((HBITMAP)(m_bmpEdges)) m_bmpEdges.Detach();
  288. }
  289. BOOL CED256View::OnEraseBkgnd(CDC* pDC) {
  290. return FALSE;
  291. }
  292. void CED256View::OnEditPrototyping() {
  293. CWaitCursor wait;
  294. CMainFrame* pMfm = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  295. m_iOffset = 50;
  296. int thresh = pMfm->m_iThreshold;
  297. CDC sc1,sc2; 
  298. CClientDC dc(this);
  299. sc1.CreateCompatibleDC(&dc);
  300. sc2.CreateCompatibleDC(&dc);
  301. CBitmap *src1old, bmsrc, *src2old;
  302. int cxDIB, cyDIB; // The width/height of the bitmap
  303. CED256Doc* pDoc = GetDocument();
  304. HDIB hDIB = pDoc->GetHDIB();
  305. GetDIBSize(cxDIB, cyDIB);
  306. if ((HBITMAP)(m_bmpEdges)) m_bmpEdges.Detach();
  307. bmsrc.CreateCompatibleBitmap(&dc, cxDIB, cyDIB);
  308. m_bmpEdges.CreateCompatibleBitmap(&dc, cxDIB, cyDIB + 100);
  309.    
  310. src1old = sc1.SelectObject(&bmsrc);
  311. src2old = sc2.SelectObject(&m_bmpEdges);
  312. ::PaintDIB(sc1.m_hDC, &CRect(0,0,cxDIB,cyDIB), hDIB,
  313. &CRect(0,0,cxDIB,cyDIB), pDoc->GetDocPalette());
  314. ::PaintDIB(sc2.m_hDC, &CRect(0,0,cxDIB,cyDIB), hDIB,
  315. &CRect(0,0,cxDIB,cyDIB), pDoc->GetDocPalette());
  316. ////////////////////////////////////////////////
  317. // START PROTOTYPING
  318. _protoBmp samples[MAX_SAMPLES];
  319. _protoBmp prototypes[MAX_PROTOTYPES];
  320. int x,y;
  321. srand(unsigned(time(NULL)));
  322. pMfm->SetStatusMessage("Creating samples and prototypes...");
  323. // Initialize the samples
  324. for (int i=0;i<MAX_SAMPLES;i++) {
  325. x = rand() % cxDIB;
  326. y = rand() % cyDIB;
  327. for (int j=0;j<15;j++) {
  328. for (int k=0;k<15;k++) {
  329. samples[i].pixels[j][k] = char(sc1.GetPixel(x+j,y+k) & 0xFF);
  330. }
  331. }
  332. }
  333. // Initialize the prototypes
  334. for (i=0;i<MAX_PROTOTYPES;i++) {
  335. for (int j=0;j<15;j++) {
  336. for (int k=0;k<15;k++) {
  337. prototypes[i].pixels[j][k] = rand() % 255;
  338. }
  339. }
  340. }
  341. pMfm->SetStatusMessage("Competitive learning initialized...");
  342. int ind, k = 2, avg, bestavg, bestind, pavg[MAX_PROTOTYPES];
  343. for (i=0;i<MAX_PITERATIONS;i++) {
  344. memset(pavg,0,sizeof(avg));
  345. ind = rand() % MAX_SAMPLES;
  346. for (int j=0;j<MAX_PROTOTYPES;j++) {
  347. avg = 0;
  348. for (int k=0;k<15;k++) {
  349. for (int l=0;l<15;l++) {
  350. avg += abs(prototypes[j].pixels[k][l] - samples[ind].pixels[k][l]);
  351. }
  352. }
  353. pavg[j] = avg / (15*15);
  354. }
  355. bestind = 0; bestavg = pavg[0];
  356. for (j=1;j<MAX_PROTOTYPES;j++) {
  357. if (pavg[j] < bestavg) {
  358. bestind = j;
  359. bestavg = pavg[j];
  360. }
  361. }
  362. for (j=0;j<15;j++) {
  363. for (int k=0;k<15;k++) {
  364. prototypes[bestind].pixels[j][k] = 
  365. (prototypes[bestind].pixels[j][k] - samples[ind].pixels[j][k]) / 100 * k + samples[ind].pixels[j][k];
  366. }
  367. }
  368. }
  369. // Create the picture.
  370. _protoBmp test; 
  371. int minus = (m_iResolution/2);
  372. for (i=0;i<cxDIB+m_iResolution;i+=m_iResolution) {
  373. for (int j=0;j<cyDIB+m_iResolution;j+=m_iResolution) {
  374. // Get the pixels;
  375. for (int k=-7;k<8;k++) {
  376. for (int l=-7;l<8;l++) {
  377. test.pixels[k+7][l+7] = char(sc1.GetPixel(i+k,j+l) & 0xFF);
  378. }
  379. }
  380. for (int m=0;m<MAX_PROTOTYPES;m++) {
  381. avg = 0;
  382. for (int k=0;k<15;k++) {
  383. for (int l=0;l<15;l++) {
  384. avg += abs(prototypes[m].pixels[k][l] - test.pixels[k][l]);
  385. }
  386. }
  387. pavg[m] = avg / (15*15);
  388. }
  389. bestind = 0; bestavg = pavg[0];
  390. for (m=1;m<MAX_PROTOTYPES;m++) {
  391. if (pavg[m] < bestavg) {
  392. bestind = m;
  393. bestavg = pavg[m];
  394. }
  395. }
  396. sc2.FillSolidRect(i-minus,j-minus,m_iResolution,m_iResolution,m_crProtoColours[bestind]);
  397. }
  398. pMfm->PercentComplete(i/float(cxDIB)*100);
  399. }
  400. // Draw the prototypes and colours
  401. sc2.FillSolidRect(0,cyDIB,cxDIB,m_iOffset,RGB(255,255,255));
  402. for (i=0;i<MAX_PROTOTYPES;i++) {
  403. for (int j=0;j<15;j++) {
  404. for (int k=0;k<15;k++) {
  405. BYTE col = prototypes[i].pixels[j][k];
  406. sc2.SetPixel(j+(i*16),k+cyDIB+5,RGB(col,col,col));
  407. }
  408. }
  409. sc2.FillSolidRect(i*16,20+cyDIB+5,15,5,m_crProtoColours[i]);
  410. }
  411. CBrush br(RGB(0,0,0));
  412. sc2.FrameRect(&CRect(0,0,cxDIB, cyDIB), &br);
  413. sc1.SelectObject(src1old);
  414. sc2.SelectObject(src2old);
  415. Invalidate();
  416. pMfm->SetStatusMessage(AFX_IDS_IDLEMESSAGE);
  417. }
  418. void CED256View::OnChangeResolution() {
  419. int bold;
  420. switch (m_iResolution) {
  421. case 15: bold = 0; break;
  422. case 4:  bold = 1; break;
  423. case 1:  bold = 2; break;
  424. }
  425. CMainFrame* pMfm = STATIC_DOWNCAST(CMainFrame, AfxGetMainWnd());
  426. PullDownToolBar(&(pMfm->m_wndProtoBar), ID_CHANGERESOLUTION, IDR_RESOLUTION, bold);
  427. }
  428. void CED256View::OnResolution(UINT uID) {
  429. switch (uID) {
  430. case ID_RES_LOW: m_iResolution = 15; break;
  431. case ID_RES_MEDIUM: m_iResolution = 4; break;
  432. case ID_RES_HIGH: m_iResolution = 1; break;
  433. }
  434. }
  435. void CED256View::CopyBitmap() {
  436. CClientDC dc(this);
  437. CDC bmpdc, memdc;
  438. CBitmap bmp, *oldbmp1, *oldbmp2;
  439. int cxDIB, cyDIB; // The width/height of the bitmap
  440. GetDIBSize(cxDIB, cyDIB);
  441. bmpdc.CreateCompatibleDC(GetDC());
  442. memdc.CreateCompatibleDC(GetDC());
  443. bmp.CreateCompatibleBitmap(&dc, cxDIB, cyDIB);
  444. oldbmp1 = bmpdc.SelectObject(&m_bmpEdges);
  445. oldbmp2 = memdc.SelectObject(&bmp);
  446. CBrush br(RGB(0,0,0));
  447. memdc.BitBlt(0,0,cxDIB,cyDIB,&bmpdc,0,0,SRCCOPY);
  448. memdc.FrameRect(&CRect(0,0,cxDIB, cyDIB), &br);
  449. OpenClipboard();
  450. EmptyClipboard();
  451. SetClipboardData(CF_BITMAP, bmp.GetSafeHandle());
  452. CloseClipboard();
  453. bmp.Detach();
  454. bmpdc.SelectObject(oldbmp1);
  455. memdc.SelectObject(oldbmp2);
  456. }
  457. void CED256View::OnEditCopy() {
  458. CopyBitmap();
  459. }
  460. // FIXME: The DIB size really should be a class member!
  461. void CED256View::GetDIBSize(int &cx, int &cy) {
  462. CED256Doc* pDoc = GetDocument();
  463. HDIB hDIB = pDoc->GetHDIB();
  464. if (hDIB) {
  465. LPSTR lpDIB = (LPSTR) ::GlobalLock((HGLOBAL) hDIB);
  466. cx = (int) ::DIBWidth(lpDIB);
  467. cy = (int) ::DIBHeight(lpDIB);
  468. ::GlobalUnlock((HGLOBAL) hDIB);
  469. } else return;
  470. }
  471. // ON_COMMAND_UPDATE SCHTUFF
  472. void CED256View::OnUpdateEditOutputBlackandwhite(CCmdUI* pCmdUI) {
  473. pCmdUI->SetCheck(!m_bColour);
  474. }
  475. void CED256View::OnUpdateEditOutputColour(CCmdUI* pCmdUI) {
  476. pCmdUI->SetCheck(m_bColour);
  477. }
  478. void CED256View::OnUpdateEditFormulatypeDifferenceand(CCmdUI* pCmdUI) {
  479. pCmdUI->SetCheck(m_iFormula == 0);
  480. }
  481. void CED256View::OnUpdateEditFormulatypeDifferenceor(CCmdUI* pCmdUI) {
  482. pCmdUI->SetCheck(m_iFormula == 1);
  483. }
  484. void CED256View::OnUpdateEditFormulatypeSummation(CCmdUI* pCmdUI) {
  485. pCmdUI->SetCheck(m_iFormula == 2);
  486. }
  487. void CED256View::OnUpdateResLow(CCmdUI* pCmdUI) {
  488. pCmdUI->SetCheck(m_iResolution == 15);
  489. }
  490. void CED256View::OnUpdateResMedium(CCmdUI* pCmdUI) {
  491. pCmdUI->SetCheck(m_iResolution == 4);
  492. }
  493. void CED256View::OnUpdateResHigh(CCmdUI* pCmdUI) {
  494. pCmdUI->SetCheck(m_iResolution == 1);
  495. }