ImageViewView.cpp
上传用户:alisonmail
上传日期:2013-02-28
资源大小:500k
文件大小:25k
- // ImageViewView.cpp : implementation of the CImageViewView class
- //
- #include "stdafx.h"
- #include "ImageView.h"
- #include "ImageViewDoc.h"
- #include "ImageViewView.h"
- #include "MainFrm.h"
- #include "ChildFrm.h"
- #include "NewImageSize.h"
- #include "RotateImage.h"
- #include "PaletteCreationType.h"
- #include "NewColorDepth.h"
- #include "Brightness.h"
- #include "ViewHistogram.h"
- #include "ImagePointProcesses.h"
- #include "ImageAreaProcesses.h"
- #include "DlgEdgeDetect.h"
- #include "DlgAddNoise.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CImageViewView
- IMPLEMENT_DYNCREATE(CImageViewView, CScrollView)
- BEGIN_MESSAGE_MAP(CImageViewView, CScrollView)
- //{{AFX_MSG_MAP(CImageViewView)
- ON_WM_SETFOCUS()
- ON_COMMAND(ID_OPERATIONS_SHOWCROPBOX, OnOperationsShowcropbox)
- ON_UPDATE_COMMAND_UI(ID_OPERATIONS_SHOWCROPBOX, OnUpdateOperationsShowcropbox)
- ON_WM_LBUTTONDOWN()
- ON_WM_SETCURSOR()
- ON_COMMAND(ID_OPERATIONS_CROP, OnOperationsCrop)
- ON_COMMAND(ID_OPERATIONS_STRETCH, OnOperationsStretch)
- ON_COMMAND(ID_OPERATIONS_FLIP, OnOperationsFlip)
- ON_COMMAND(ID_OPERATIONS_INVERT, OnOperationsInvert)
- ON_COMMAND(ID_OPERATIONS_ROTATE, OnOperationsRotate)
- ON_COMMAND(ID_OPERATIONS_SETPALETTECREATIONTYPE, OnOperationsSetpalettecreationtype)
- ON_COMMAND(ID_OPERATIONS_CHANGEIMAGECOLORDEPTH, OnOperationsChangeimagecolordepth)
- ON_COMMAND(ID_POINTPROCESSES_CHANGEBRIGHTNESS, OnPointprocessesChangebrightness)
- ON_COMMAND(ID_POINTPROCESSES_COLORIZE, OnPointprocessesColorize)
- ON_COMMAND(ID_POINTPROCESSES_MAKEGRAY, OnPointprocessesMakegray)
- ON_COMMAND(ID_POINTPROCESSES_REVERSECOLORS, OnPointprocessesReversecolors)
- ON_COMMAND(ID_POINTPROCESSES_VIEWHISTOGRAM, OnPointprocessesViewhistogram)
- ON_COMMAND(ID_AREAPROCESSES_CHANGECONTRACT, OnAreaprocessesChangecontract)
- ON_COMMAND(ID_AREAPROCESSES_EDGEENHANCE, OnAreaprocessesEdgeenhance)
- ON_COMMAND(ID_AREAPROCESSES_EQUALIZECONTRAST, OnAreaprocessesEqualizecontrast)
- ON_COMMAND(ID_AREAPROCESSES_HIGHPASSFILTER, OnAreaprocessesHighpassfilter)
- ON_COMMAND(ID_AREAPROCESSES_LOWPASSFILTER, OnAreaprocessesLowpassfilter)
- ON_COMMAND(ID_AREAPROCESSES_MEDIANFILTER, OnAreaprocessesMedianfilter)
- ON_COMMAND(ID_POINTPROCESSES_FFT, OnPointprocessesFft)
- ON_COMMAND(ID_POINTPROCESSES_IFFT, OnPointprocessesIfft)
- ON_COMMAND(ID_POINTPROCESSES_DCT, OnPointprocessesDct)
- ON_COMMAND(ID_EDGEDETECT, OnEdgedetect)
- ON_WM_RBUTTONUP()
- ON_COMMAND(ID_RELOAD, OnReload)
- ON_COMMAND(ID_ADDNOISE, OnAddnoise)
- ON_COMMAND(ID_RIVER_EXTRACT, OnRiverExtract)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CImageViewView construction/destruction
- CImageViewView::CImageViewView()
- {
- m_pImageObject = NULL;
- m_bImageLoaded = FALSE;
- m_bCropBoxShowing = FALSE;
- CRect Rect( 10, 10, 200, 100 );
- m_pTracker = new CRectTracker( &Rect, CRectTracker::solidLine | CRectTracker::resizeOutside );
- }
- CImageViewView::~CImageViewView()
- {
- if( m_pImageObject != NULL ) delete m_pImageObject;
- if( m_pTracker ) delete m_pTracker;
- }
- BOOL CImageViewView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
- return CScrollView::PreCreateWindow(cs);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CImageViewView drawing
- void CImageViewView::OnDraw(CDC* pDC)
- {
- CImageViewDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- if( !m_bImageLoaded ){
- CString PathName = pDoc->GetPathName ();
- BeginWaitCursor ();
- m_pImageObject = new CImageObject( PathName.GetBuffer( 3 ), pDC );
- EndWaitCursor ();
- if( m_pImageObject == NULL ){
- AfxMessageBox( "Could not create picture class!" );
- return;
- }
-
- CSize SizeTotal;
- SizeTotal.cx = m_pImageObject->GetWidth();
- SizeTotal.cy = m_pImageObject->GetHeight();
- SetScrollSizes (MM_TEXT, SizeTotal);
- CMainFrame *pFrame = (CMainFrame *) AfxGetMainWnd();
- CChildFrame *pChild = (CChildFrame *) pFrame->MDIGetActive();
- pChild->m_nWidth = m_pImageObject->GetWidth();
- pChild->m_nHeight = m_pImageObject->GetHeight();
- pChild->SetWindowPos( NULL, 0, 0, 2500, 2500, SWP_NOZORDER | SWP_NOMOVE );
- m_bImageLoaded = TRUE;
- }
- OnPrepareDC (pDC);
- if( GetFocus() == this ) m_pImageObject->SetPalette( pDC );
- m_pImageObject->Draw( pDC );
- if( m_pTracker != NULL && m_bCropBoxShowing )
- m_pTracker->Draw( pDC );
- }
- void CImageViewView::OnInitialUpdate()
- {
- CScrollView::OnInitialUpdate();
- CSize sizeTotal;
- // TODO: calculate the total size of this view
- sizeTotal.cx = sizeTotal.cy = 100;
- SetScrollSizes(MM_TEXT, sizeTotal);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CImageViewView diagnostics
- #ifdef _DEBUG
- void CImageViewView::AssertValid() const
- {
- CScrollView::AssertValid();
- }
- void CImageViewView::Dump(CDumpContext& dc) const
- {
- CScrollView::Dump(dc);
- }
- CImageViewDoc* CImageViewView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CImageViewDoc)));
- return (CImageViewDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CImageViewView message handlers
- void CImageViewView::OnSetFocus(CWnd* pOldWnd)
- {
- CScrollView::OnSetFocus(pOldWnd);
-
- if( m_pImageObject != NULL ){
- CClientDC ClientDC( this );
- OnPrepareDC( &ClientDC );
- m_pImageObject->SetPalette( &ClientDC );
- m_pImageObject->Draw( &ClientDC );
- }
-
- }
- void CImageViewView::OnOperationsShowcropbox()
- {
- if( m_pTracker != NULL ){
- m_bCropBoxShowing = !m_bCropBoxShowing;
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
- }
- }
- void CImageViewView::OnUpdateOperationsShowcropbox(CCmdUI* pCmdUI)
- {
- if( !m_pTracker ) pCmdUI->Enable( FALSE );
- else{
- if( m_bCropBoxShowing ) pCmdUI->SetCheck( TRUE );
- else pCmdUI->SetCheck( FALSE );
- }
- }
- void CImageViewView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- if( m_pTracker != NULL && m_bCropBoxShowing && m_pTracker->Track( this, point, FALSE ) ){
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
- }
-
- CScrollView::OnLButtonDown(nFlags, point);
- }
- BOOL CImageViewView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
- {
- if( m_pTracker != NULL && m_bCropBoxShowing && pWnd == this && m_pTracker->SetCursor( this, nHitTest ) )
- return( TRUE );
-
- return CScrollView::OnSetCursor(pWnd, nHitTest, message);
- }
- void CImageViewView::OnOperationsCrop()
- {
- if( m_pTracker == NULL || m_pImageObject == NULL ) return;
- int nX1 = m_pTracker->m_rect.left;
- int nY1 = m_pTracker->m_rect.top;
- int nX2 = m_pTracker->m_rect.right;
- int nY2 = m_pTracker->m_rect.bottom;
- if( nX1 < 0 ) nX1 = 0;
- if( nX1 > m_pImageObject->GetWidth() - 1 ) nX1 = m_pImageObject->GetWidth() - 1;
- if( nY1 < 0 ) nY1 = 0;
- if( nY1 > m_pImageObject->GetHeight() - 1 ) nY1 = m_pImageObject->GetHeight() - 1;
- if( nX2 < 0 ) nX2 = 0;
- if( nX2 > m_pImageObject->GetWidth() - 1 ) nX2 = m_pImageObject->GetWidth() - 1;
- if( nY2 < 0 ) nY2 = 0;
- if( nY2 > m_pImageObject->GetHeight() - 1 ) nY2 = m_pImageObject->GetHeight() - 1;
- m_pImageObject->Crop( nX1, nY1, nX2, nY2 );
- if( m_pTracker->m_rect.right > m_pImageObject->GetWidth() - 1 ) m_pTracker->m_rect.right = m_pImageObject->GetWidth() - 1;
- if( m_pTracker->m_rect.bottom > m_pImageObject->GetHeight() - 1 ) m_pTracker->m_rect.bottom = m_pImageObject->GetHeight() - 1;
- if( m_pTracker->m_rect.left > m_pImageObject->GetWidth() - 40 ) m_pTracker->m_rect.left = m_pImageObject->GetWidth() - 40;
- if( m_pTracker->m_rect.left < 0 ) m_pTracker->m_rect.left = 0;
- if( m_pTracker->m_rect.top > m_pImageObject->GetHeight() - 40 ) m_pTracker->m_rect.top = m_pImageObject->GetHeight() - 40;
- if( m_pTracker->m_rect.top < 0 ) m_pTracker->m_rect.top = 0;
- m_bCropBoxShowing = FALSE;
- ResizeWindow();
- }
- void CImageViewView::OnOperationsStretch()
- {
- if( m_pImageObject == NULL ) return;
- CNewImageSize NewImageSize;
- NewImageSize.m_nWidth = m_pImageObject->GetWidth();
- NewImageSize.m_nHeight = m_pImageObject->GetHeight();
- char junk[200];
- wsprintf( junk, "The current size is %d by %d", NewImageSize.m_nWidth, NewImageSize.m_nHeight );
- NewImageSize.m_CurrentSize = junk;
- if( NewImageSize.DoModal() == IDOK ){
- m_pImageObject->Stretch( NewImageSize.m_nWidth, NewImageSize.m_nHeight );
- if( m_pTracker != NULL ){
- if( m_pTracker->m_rect.right > m_pImageObject->GetWidth() - 1 ) m_pTracker->m_rect.right = m_pImageObject->GetWidth() - 1;
- if( m_pTracker->m_rect.bottom > m_pImageObject->GetHeight() - 1 ) m_pTracker->m_rect.bottom = m_pImageObject->GetHeight() - 1;
- if( m_pTracker->m_rect.left > m_pImageObject->GetWidth() - 40 ) m_pTracker->m_rect.left = m_pImageObject->GetWidth() - 40;
- if( m_pTracker->m_rect.left < 0 ) m_pTracker->m_rect.left = 0;
- if( m_pTracker->m_rect.top > m_pImageObject->GetHeight() - 40 ) m_pTracker->m_rect.top = m_pImageObject->GetHeight() - 40;
- if( m_pTracker->m_rect.top < 0 ) m_pTracker->m_rect.top = 0;
- }
- m_bCropBoxShowing = FALSE;
- ResizeWindow();
- }
- }
- void CImageViewView::OnOperationsFlip()
- {
- if( m_pImageObject == NULL ) return;
- m_pImageObject->Reverse();
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
-
- }
- void CImageViewView::OnOperationsInvert()
- {
- if( m_pImageObject == NULL ) return;
- m_pImageObject->Invert();
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
-
- }
- void CImageViewView::OnOperationsRotate()
- {
- if( m_pImageObject == NULL ) return;
-
- CRotateImage RotateImage;
- RotateImage.m_Rotate = 0;
- if( RotateImage.DoModal() == IDOK ){
- m_pImageObject->Rotate( 90 + RotateImage.m_Rotate * 90 );
- if( RotateImage.m_Rotate == 1 ){
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
- }
- else ResizeWindow();
- }
- }
- void CImageViewView::ResizeWindow( void )
- {
- CSize SizeTotal;
- SizeTotal.cx = m_pImageObject->GetWidth();
- SizeTotal.cy = m_pImageObject->GetHeight();
- SetScrollSizes (MM_TEXT, SizeTotal);
- CMainFrame *pFrame = (CMainFrame *) AfxGetMainWnd();
- CChildFrame *pChild = (CChildFrame *) pFrame->MDIGetActive();
- pChild->m_nWidth = m_pImageObject->GetWidth();
- pChild->m_nHeight = m_pImageObject->GetHeight();
- pChild->SetWindowPos( NULL, 0, 0, 2500, 2500, SWP_NOZORDER | SWP_NOMOVE );
- }
- void CImageViewView::OnOperationsSetpalettecreationtype()
- {
- if( m_pImageObject == NULL ) return;
- CPaletteCreationType PaletteCreationType;
- PaletteCreationType.m_PaletteCreationType = m_pImageObject->GetPaletteCreationType();
- if( PaletteCreationType.DoModal() == IDOK ){
- m_pImageObject->SetPaletteCreationType( PaletteCreationType.m_PaletteCreationType );
- }
-
- }
- void CImageViewView::OnOperationsChangeimagecolordepth()
- {
- if( m_pImageObject == NULL ) return;
- CNewColorDepth NewColorDepth;
- switch( m_pImageObject->GetNumBits() ){
- case 1:
- case 4:
- NewColorDepth.m_nCurrentColorDepth = -1;
- NewColorDepth.m_nNewColorDepth = 0;
- break;
- case 8:
- NewColorDepth.m_nCurrentColorDepth = 0;
- NewColorDepth.m_nNewColorDepth = 2;
- break;
- case 16:
- NewColorDepth.m_nCurrentColorDepth = 1;
- NewColorDepth.m_nNewColorDepth = 2;
- break;
- case 24:
- NewColorDepth.m_nCurrentColorDepth = 2;
- NewColorDepth.m_nNewColorDepth = 1;
- break;
- case 32:
- NewColorDepth.m_nCurrentColorDepth = 3;
- NewColorDepth.m_nNewColorDepth = 2;
- break;
- }
- if( NewColorDepth.DoModal() == IDOK ){
- BeginWaitCursor();
- m_pImageObject->ChangeFormat( 8 + NewColorDepth.m_nNewColorDepth * 8 );
- EndWaitCursor();
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
- }
- }
- void CImageViewView::OnPointprocessesChangebrightness()
- {
- if( m_pTracker == NULL || m_pImageObject == NULL ) return;
- int nX1 = m_pTracker->m_rect.left;
- int nY1 = m_pTracker->m_rect.top;
- int nX2 = m_pTracker->m_rect.right;
- int nY2 = m_pTracker->m_rect.bottom;
- if( nX1 < 0 ) nX1 = 0;
- if( nX1 > m_pImageObject->GetWidth() - 1 ) nX1 = m_pImageObject->GetWidth() - 1;
- if( nY1 < 0 ) nY1 = 0;
- if( nY1 > m_pImageObject->GetHeight() - 1 ) nY1 = m_pImageObject->GetHeight() - 1;
- if( nX2 < 0 ) nX2 = 0;
- if( nX2 > m_pImageObject->GetWidth() - 1 ) nX2 = m_pImageObject->GetWidth() - 1;
- if( nY2 < 0 ) nY2 = 0;
- if( nY2 > m_pImageObject->GetHeight() - 1 ) nY2 = m_pImageObject->GetHeight() - 1;
- if( !m_bCropBoxShowing ){
- nX1 = nY1 = 0;
- nX2 = m_pImageObject->GetWidth() - 1;
- nY2 = m_pImageObject->GetHeight() - 1;
- }
- CBrightness Brightness;
- if( Brightness.DoModal() != IDOK ) return;
- CImagePointProcesses PointProcesses( m_pImageObject );
- BeginWaitCursor();
- PointProcesses.ChangeBrightness( Brightness.m_nBrightness, nX1, nY1, nX2, nY2 );
- EndWaitCursor();
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
- }
- void CImageViewView::OnPointprocessesColorize()
- {
- if( m_pTracker == NULL || m_pImageObject == NULL ) return;
- int nX1 = m_pTracker->m_rect.left;
- int nY1 = m_pTracker->m_rect.top;
- int nX2 = m_pTracker->m_rect.right;
- int nY2 = m_pTracker->m_rect.bottom;
- if( nX1 < 0 ) nX1 = 0;
- if( nX1 > m_pImageObject->GetWidth() - 1 ) nX1 = m_pImageObject->GetWidth() - 1;
- if( nY1 < 0 ) nY1 = 0;
- if( nY1 > m_pImageObject->GetHeight() - 1 ) nY1 = m_pImageObject->GetHeight() - 1;
- if( nX2 < 0 ) nX2 = 0;
- if( nX2 > m_pImageObject->GetWidth() - 1 ) nX2 = m_pImageObject->GetWidth() - 1;
- if( nY2 < 0 ) nY2 = 0;
- if( nY2 > m_pImageObject->GetHeight() - 1 ) nY2 = m_pImageObject->GetHeight() - 1;
- if( !m_bCropBoxShowing ){
- nX1 = nY1 = 0;
- nX2 = m_pImageObject->GetWidth() - 1;
- nY2 = m_pImageObject->GetHeight() - 1;
- }
- CColorDialog ColorDialog;
- if( ColorDialog.DoModal() != IDOK ) return;
- CImagePointProcesses PointProcesses( m_pImageObject );
- BeginWaitCursor();
- PointProcesses.Colorize( nX1, nY1, nX2, nY2, ColorDialog.GetColor() );
- EndWaitCursor();
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
-
- }
- void CImageViewView::OnPointprocessesMakegray()
- {
- if( m_pImageObject == NULL ) return;
- CImagePointProcesses PointProcesses( m_pImageObject );
- PointProcesses.MakeGray( TRUE );
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
- }
- void CImageViewView::OnPointprocessesReversecolors()
- {
- if( m_pTracker == NULL || m_pImageObject == NULL ) return;
- int nX1 = m_pTracker->m_rect.left;
- int nY1 = m_pTracker->m_rect.top;
- int nX2 = m_pTracker->m_rect.right;
- int nY2 = m_pTracker->m_rect.bottom;
- if( nX1 < 0 ) nX1 = 0;
- if( nX1 > m_pImageObject->GetWidth() - 1 ) nX1 = m_pImageObject->GetWidth() - 1;
- if( nY1 < 0 ) nY1 = 0;
- if( nY1 > m_pImageObject->GetHeight() - 1 ) nY1 = m_pImageObject->GetHeight() - 1;
- if( nX2 < 0 ) nX2 = 0;
- if( nX2 > m_pImageObject->GetWidth() - 1 ) nX2 = m_pImageObject->GetWidth() - 1;
- if( nY2 < 0 ) nY2 = 0;
- if( nY2 > m_pImageObject->GetHeight() - 1 ) nY2 = m_pImageObject->GetHeight() - 1;
- if( !m_bCropBoxShowing ){
- nX1 = nY1 = 0;
- nX2 = m_pImageObject->GetWidth() - 1;
- nY2 = m_pImageObject->GetHeight() - 1;
- }
- CImagePointProcesses PointProcesses( m_pImageObject );
- BeginWaitCursor();
- PointProcesses.ReverseColors( nX1, nY1, nX2, nY2 );
- EndWaitCursor();
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
-
- }
- void CImageViewView::OnPointprocessesViewhistogram()
- {
- if( m_pImageObject == NULL ) return;
-
- HGLOBAL hDib = m_pImageObject->GetDib();
- if( hDib == NULL ) return;
- unsigned char *pBits, *pPalette;
- pBits = (unsigned char *) ::GlobalLock( hDib );
- pBits += ( sizeof( BITMAPFILEHEADER ) + sizeof( BITMAPINFOHEADER ) );
- pPalette = pBits;
- pBits += m_pImageObject->GetPaletteBytes();
- CImagePointProcesses ImagePointProcesses( m_pImageObject );
- int *pHistogram = ImagePointProcesses.CreateHistogram( 0, 0,
- m_pImageObject->GetWidth() - 1,
- m_pImageObject->GetHeight() - 1,
- pBits, (RGBQUAD *) pPalette,
- m_pImageObject->WidthBytes( m_pImageObject->GetNumBits(),
- m_pImageObject->GetWidth() ) );
- if( pHistogram != NULL ){
- CViewHistogram ViewHistogram;
- ViewHistogram.m_pnHistogram = pHistogram;
- ViewHistogram.DoModal();
- delete [] pHistogram;
- }
- }
- void CImageViewView::OnAreaprocessesChangecontract()
- {
- if( m_pTracker == NULL || m_pImageObject == NULL ) return;
- int nX1 = m_pTracker->m_rect.left;
- int nY1 = m_pTracker->m_rect.top;
- int nX2 = m_pTracker->m_rect.right;
- int nY2 = m_pTracker->m_rect.bottom;
- if( nX1 < 0 ) nX1 = 0;
- if( nX1 > m_pImageObject->GetWidth() - 1 ) nX1 = m_pImageObject->GetWidth() - 1;
- if( nY1 < 0 ) nY1 = 0;
- if( nY1 > m_pImageObject->GetHeight() - 1 ) nY1 = m_pImageObject->GetHeight() - 1;
- if( nX2 < 0 ) nX2 = 0;
- if( nX2 > m_pImageObject->GetWidth() - 1 ) nX2 = m_pImageObject->GetWidth() - 1;
- if( nY2 < 0 ) nY2 = 0;
- if( nY2 > m_pImageObject->GetHeight() - 1 ) nY2 = m_pImageObject->GetHeight() - 1;
- if( !m_bCropBoxShowing ){
- nX1 = nY1 = 0;
- nX2 = m_pImageObject->GetWidth() - 1;
- nY2 = m_pImageObject->GetHeight() - 1;
- }
- CBrightness Brightness;
- strcpy( Brightness.m_szTitle, "Set Contrast" );
- strcpy( Brightness.m_szLabel, "Contrast" );
- if( Brightness.DoModal() != IDOK ) return;
- CImageAreaProcesses AreaProcesses( m_pImageObject );
- BeginWaitCursor();
- AreaProcesses.ChangeContrast( Brightness.m_nBrightness, nX1, nY1, nX2, nY2 );
- EndWaitCursor();
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
-
- }
- void CImageViewView::OnAreaprocessesEdgeenhance()
- {
- if( m_pTracker == NULL || m_pImageObject == NULL ) return;
- int nX1 = m_pTracker->m_rect.left;
- int nY1 = m_pTracker->m_rect.top;
- int nX2 = m_pTracker->m_rect.right;
- int nY2 = m_pTracker->m_rect.bottom;
- if( nX1 < 0 ) nX1 = 0;
- if( nX1 > m_pImageObject->GetWidth() - 1 ) nX1 = m_pImageObject->GetWidth() - 1;
- if( nY1 < 0 ) nY1 = 0;
- if( nY1 > m_pImageObject->GetHeight() - 1 ) nY1 = m_pImageObject->GetHeight() - 1;
- if( nX2 < 0 ) nX2 = 0;
- if( nX2 > m_pImageObject->GetWidth() - 1 ) nX2 = m_pImageObject->GetWidth() - 1;
- if( nY2 < 0 ) nY2 = 0;
- if( nY2 > m_pImageObject->GetHeight() - 1 ) nY2 = m_pImageObject->GetHeight() - 1;
- if( !m_bCropBoxShowing ){
- nX1 = nY1 = 0;
- nX2 = m_pImageObject->GetWidth() - 1;
- nY2 = m_pImageObject->GetHeight() - 1;
- }
- CImageAreaProcesses AreaProcesses( m_pImageObject );
- BeginWaitCursor();
- AreaProcesses.EdgeEnhance( nX1, nY1, nX2, nY2 );
- EndWaitCursor();
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
-
- }
- void CImageViewView::OnAreaprocessesEqualizecontrast()
- {
- if( m_pTracker == NULL || m_pImageObject == NULL ) return;
- int nX1 = m_pTracker->m_rect.left;
- int nY1 = m_pTracker->m_rect.top;
- int nX2 = m_pTracker->m_rect.right;
- int nY2 = m_pTracker->m_rect.bottom;
- if( nX1 < 0 ) nX1 = 0;
- if( nX1 > m_pImageObject->GetWidth() - 1 ) nX1 = m_pImageObject->GetWidth() - 1;
- if( nY1 < 0 ) nY1 = 0;
- if( nY1 > m_pImageObject->GetHeight() - 1 ) nY1 = m_pImageObject->GetHeight() - 1;
- if( nX2 < 0 ) nX2 = 0;
- if( nX2 > m_pImageObject->GetWidth() - 1 ) nX2 = m_pImageObject->GetWidth() - 1;
- if( nY2 < 0 ) nY2 = 0;
- if( nY2 > m_pImageObject->GetHeight() - 1 ) nY2 = m_pImageObject->GetHeight() - 1;
- if( !m_bCropBoxShowing ){
- nX1 = nY1 = 0;
- nX2 = m_pImageObject->GetWidth() - 1;
- nY2 = m_pImageObject->GetHeight() - 1;
- }
- CImageAreaProcesses AreaProcesses( m_pImageObject );
- BeginWaitCursor();
- AreaProcesses.EqualizeContrast( nX1, nY1, nX2, nY2 );
- EndWaitCursor();
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
-
- }
- void CImageViewView::OnAreaprocessesHighpassfilter()
- {
- if( m_pTracker == NULL || m_pImageObject == NULL ) return;
- int nX1 = m_pTracker->m_rect.left;
- int nY1 = m_pTracker->m_rect.top;
- int nX2 = m_pTracker->m_rect.right;
- int nY2 = m_pTracker->m_rect.bottom;
- if( nX1 < 0 ) nX1 = 0;
- if( nX1 > m_pImageObject->GetWidth() - 1 ) nX1 = m_pImageObject->GetWidth() - 1;
- if( nY1 < 0 ) nY1 = 0;
- if( nY1 > m_pImageObject->GetHeight() - 1 ) nY1 = m_pImageObject->GetHeight() - 1;
- if( nX2 < 0 ) nX2 = 0;
- if( nX2 > m_pImageObject->GetWidth() - 1 ) nX2 = m_pImageObject->GetWidth() - 1;
- if( nY2 < 0 ) nY2 = 0;
- if( nY2 > m_pImageObject->GetHeight() - 1 ) nY2 = m_pImageObject->GetHeight() - 1;
- if( !m_bCropBoxShowing ){
- nX1 = nY1 = 0;
- nX2 = m_pImageObject->GetWidth() - 1;
- nY2 = m_pImageObject->GetHeight() - 1;
- }
- CImageAreaProcesses AreaProcesses( m_pImageObject );
- BeginWaitCursor();
- AreaProcesses.HighpassFilter( nX1, nY1, nX2, nY2 );
- EndWaitCursor();
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
-
- }
- void CImageViewView::OnAreaprocessesLowpassfilter()
- {
- if( m_pTracker == NULL || m_pImageObject == NULL ) return;
- int nX1 = m_pTracker->m_rect.left;
- int nY1 = m_pTracker->m_rect.top;
- int nX2 = m_pTracker->m_rect.right;
- int nY2 = m_pTracker->m_rect.bottom;
- if( nX1 < 0 ) nX1 = 0;
- if( nX1 > m_pImageObject->GetWidth() - 1 ) nX1 = m_pImageObject->GetWidth() - 1;
- if( nY1 < 0 ) nY1 = 0;
- if( nY1 > m_pImageObject->GetHeight() - 1 ) nY1 = m_pImageObject->GetHeight() - 1;
- if( nX2 < 0 ) nX2 = 0;
- if( nX2 > m_pImageObject->GetWidth() - 1 ) nX2 = m_pImageObject->GetWidth() - 1;
- if( nY2 < 0 ) nY2 = 0;
- if( nY2 > m_pImageObject->GetHeight() - 1 ) nY2 = m_pImageObject->GetHeight() - 1;
- if( !m_bCropBoxShowing ){
- nX1 = nY1 = 0;
- nX2 = m_pImageObject->GetWidth() - 1;
- nY2 = m_pImageObject->GetHeight() - 1;
- }
- CImageAreaProcesses AreaProcesses( m_pImageObject );
- BeginWaitCursor();
- AreaProcesses.LowpassFilter( nX1, nY1, nX2, nY2 );
- EndWaitCursor();
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
-
- }
- void CImageViewView::OnAreaprocessesMedianfilter()
- {
- if( m_pTracker == NULL || m_pImageObject == NULL ) return;
- int nX1 = m_pTracker->m_rect.left;
- int nY1 = m_pTracker->m_rect.top;
- int nX2 = m_pTracker->m_rect.right;
- int nY2 = m_pTracker->m_rect.bottom;
- if( nX1 < 0 ) nX1 = 0;
- if( nX1 > m_pImageObject->GetWidth() - 1 ) nX1 = m_pImageObject->GetWidth() - 1;
- if( nY1 < 0 ) nY1 = 0;
- if( nY1 > m_pImageObject->GetHeight() - 1 ) nY1 = m_pImageObject->GetHeight() - 1;
- if( nX2 < 0 ) nX2 = 0;
- if( nX2 > m_pImageObject->GetWidth() - 1 ) nX2 = m_pImageObject->GetWidth() - 1;
- if( nY2 < 0 ) nY2 = 0;
- if( nY2 > m_pImageObject->GetHeight() - 1 ) nY2 = m_pImageObject->GetHeight() - 1;
- if( !m_bCropBoxShowing ){
- nX1 = nY1 = 0;
- nX2 = m_pImageObject->GetWidth() - 1;
- nY2 = m_pImageObject->GetHeight() - 1;
- }
- CImageAreaProcesses AreaProcesses( m_pImageObject );
- BeginWaitCursor();
- AreaProcesses.MedianFilter( nX1, nY1, nX2, nY2 );
- EndWaitCursor();
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
-
- }
- void CImageViewView::OnPointprocessesFft()
- {
- if( m_pTracker == NULL || m_pImageObject == NULL ) return;
- /*
- int nX1 = m_pTracker->m_rect.left;
- int nY1 = m_pTracker->m_rect.top;
- int nX2 = m_pTracker->m_rect.right;
- int nY2 = m_pTracker->m_rect.bottom;
- if( nX1 < 0 ) nX1 = 0;
- if( nX1 > m_pImageObject->GetWidth() - 1 ) nX1 = m_pImageObject->GetWidth() - 1;
- if( nY1 < 0 ) nY1 = 0;
- if( nY1 > m_pImageObject->GetHeight() - 1 ) nY1 = m_pImageObject->GetHeight() - 1;
- if( nX2 < 0 ) nX2 = 0;
- if( nX2 > m_pImageObject->GetWidth() - 1 ) nX2 = m_pImageObject->GetWidth() - 1;
- if( nY2 < 0 ) nY2 = 0;
- if( nY2 > m_pImageObject->GetHeight() - 1 ) nY2 = m_pImageObject->GetHeight() - 1;
- if( !m_bCropBoxShowing ){
- nX1 = nY1 = 0;
- nX2 = m_pImageObject->GetWidth() - 1;
- nY2 = m_pImageObject->GetHeight() - 1;
- }
- */
- CImagePointProcesses PointProcesses( m_pImageObject );
- BeginWaitCursor();
- PointProcesses.FFTTrans(m_pImageObject);
- EndWaitCursor();
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
- }
- void CImageViewView::OnPointprocessesIfft()
- {
- // OnPointp
- }
- void CImageViewView::OnPointprocessesDct()
- {
- if( m_pTracker == NULL || m_pImageObject == NULL ) return;
- CImagePointProcesses PointProcesses( m_pImageObject );
- BeginWaitCursor();
- PointProcesses.DCTTrans(m_pImageObject);
- EndWaitCursor();
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
- }
- void CImageViewView::OnEdgedetect()
- {
- if( m_pTracker == NULL || m_pImageObject == NULL ) return;
- CDlgEdgeDetect setupDlg;
- if(setupDlg.DoModal() == IDOK)
- {
- CImagePointProcesses PointProcesses( m_pImageObject );
- PointProcesses.EdgeDetectType = setupDlg.m_nEdgeDetectType;
- PointProcesses.Embossed = setupDlg.m_bEmbossed;
- BeginWaitCursor();
- PointProcesses.EdgeDetect(m_pImageObject);
- EndWaitCursor();
- }
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
- }
- void CImageViewView::OnRButtonUp(UINT nFlags, CPoint point)
- {
- CMenu popupMenu;
- popupMenu.LoadMenu(IDR_POPUPMENU);
- ClientToScreen(&point);
- popupMenu.GetSubMenu(0)->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, this);
-
- CScrollView::OnRButtonUp(nFlags, point);
- }
- void CImageViewView::OnReload()
- {
- m_bImageLoaded = FALSE;
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
- }
- void CImageViewView::OnAddnoise()
- {
- if( m_pTracker == NULL || m_pImageObject == NULL ) return;
-
- CImagePointProcesses PointProcesses( m_pImageObject );
- CDlgAddNoise dlg;
- if(dlg.DoModal() == IDOK)
- {
- BeginWaitCursor();
- PointProcesses.AddNoise(m_pImageObject, dlg.m_nNoiseRatio);
- EndWaitCursor();
- }
-
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
- }
- void CImageViewView::OnRiverExtract()
- {
- if( m_pTracker == NULL || m_pImageObject == NULL ) return;
- CImagePointProcesses PointProcesses( m_pImageObject );
- BeginWaitCursor();
- PointProcesses.ExtractRiver(NULL, m_pImageObject);
- EndWaitCursor();
-
- InvalidateRect( NULL, FALSE );
- UpdateWindow();
- }