home *** CD-ROM | disk | FTP | other *** search
- // mfcdeVw.cpp : implementation of the CMfcdemoView class
- //
-
- #include "stdafx.h"
-
- #include "mfcdemo.h"
- #include "mfcdedoc.h"
- #include "mfcdevw.h"
- #include "maindemo.h"
- #include "listdlg.h"
- #include "rangedlg.h"
- #include "resizedl.h"
- #include "colorres.h"
- #include "underlay.h"
- #include "LeadDlg.h"
- #include "..\..\..\..\include\ltdlgocx.h"
-
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- extern CMfcdemoApp theApp;
-
- #define SZ_COMPASS _T("North|North-East|East|South-East|South|South-West|West|North-West|")
- #define SZ_SHIFTDIFF _T("Diagonal|Horizontal|Vertical|")
- #define SZ_LINESEG _T("Horizontal|Vertical|Left to Right|Right to Left|")
- #define SZ_LAPLACE _T("Filter 1|Filter 2|Filter 3|Diagonal|Horizontal|Vertical|")
- #define SZ_HORZVERT _T("Horizontal|Vertical|");
- #define SZ_BINARY _T("Omnidirectional|Horizontal|Vertical|Diagonal|")
-
- static int aGradientFlt[] = {
- FLT_GRADIENT_N,
- FLT_GRADIENT_NE,
- FLT_GRADIENT_E,
- FLT_GRADIENT_SE,
- FLT_GRADIENT_S,
- FLT_GRADIENT_SW,
- FLT_GRADIENT_W,
- FLT_GRADIENT_NW
- };
-
- static int aLaplaceFlt[] = {
- FLT_LAPLACE_1,
- FLT_LAPLACE_2,
- FLT_LAPLACE_3,
- FLT_LAPLACE_DIAG,
- FLT_LAPLACE_HORZ,
- FLT_LAPLACE_VERT,
- };
-
- static int aSobelFlt[] = {
- FLT_SOBEL_HORZ,
- FLT_SOBEL_VERT,
- };
-
-
- static int aPrewittFlt[] = {
- FLT_PREWITT_HORZ,
- FLT_PREWITT_VERT,
- };
-
- static int aShiftDiffFlt[] = {
- FLT_SHIFTDIFF_DIAG,
- FLT_SHIFTDIFF_HORZ,
- FLT_SHIFTDIFF_VERT,
- };
-
- static int aLineSegFlt[] = {
- FLT_LINESEG_HORZ,
- FLT_LINESEG_VERT,
- FLT_LINESEG_LTOR,
- FLT_LINESEG_RTOL,
- };
-
- static int aErosionFlt[] = {
- BFLT_EROSION_OMNI,
- BFLT_EROSION_HORZ,
- BFLT_EROSION_VERT,
- BFLT_EROSION_DIAG,
- };
-
- static int aDilationFlt[] = {
- BFLT_DILATION_OMNI,
- BFLT_DILATION_HORZ,
- BFLT_DILATION_VERT,
- BFLT_DILATION_DIAG,
- };
-
- /////////////////////////////////////////////////////////////////////////////
- // CMfcdemoView
-
- IMPLEMENT_DYNCREATE(CMfcdemoView, CFormView)
-
- BEGIN_MESSAGE_MAP(CMfcdemoView, CFormView)
- //{{AFX_MSG_MAP(CMfcdemoView)
- ON_MESSAGE(WM_DOREALIZE, OnDoRealize)
- ON_COMMAND(ID_IMAGE_FLIP, OnImageFlip)
- ON_COMMAND(ID_IMAGE_REVERSE, OnImageReverse)
- ON_COMMAND(ID_IMAGE_ROTATE_180CLOCKWISE, OnImageRotate180clockwise)
- ON_COMMAND(ID_IMAGE_ROTATE_270CLOCKWISE, OnImageRotate270clockwise)
- ON_COMMAND(ID_IMAGE_ROTATE_90CLOCKWISE, OnImageRotate90clockwise)
- ON_COMMAND(ID_COLOR_GRAYSCALE, OnColorGrayscale)
- ON_COMMAND(ID_COLOR_GRAYSCALE12, OnColorGrayscale12)
- ON_COMMAND(ID_COLOR_GRAYSCALE16, OnColorGrayscale16)
- ON_COMMAND(ID_COLOR_HISTOGRAMEQUALIZE, OnColorHistogramequalize)
- ON_COMMAND(ID_COLOR_INVERT, OnColorInvert)
- ON_COMMAND(ID_COLOR_STRETCHINTENSITY, OnColorStretchintensity)
- ON_COMMAND(ID_IMAGE_EFFECTS_POSTERIZE, OnImageEffectsPosterize)
- ON_COMMAND(ID_COLOR_BRIGHTNESS, OnColorBrightness)
- ON_COMMAND(ID_COLOR_CONTRAST, OnColorContrast)
- ON_COMMAND(ID_COLOR_HISTOCONTRAST, OnColorHistocontrast)
- ON_COMMAND(ID_COLOR_HUE, OnColorHue)
- ON_COMMAND(ID_COLOR_SATURATION, OnColorSaturation)
- ON_COMMAND(ID_IMAGE_EFFECTS_ADDNOISE, OnImageEffectsAddnoise)
- ON_COMMAND(ID_IMAGE_EFFECTS_AVERAGE, OnImageEffectsAverage)
- ON_COMMAND(ID_IMAGE_EFFECTS_DESPECKLE, OnImageEffectsDespeckle)
- ON_COMMAND(ID_IMAGE_EFFECTS_MEDIAN, OnImageEffectsMedian)
- ON_COMMAND(ID_IMAGE_EFFECTS_MOSAIC, OnImageEffectsMosaic)
- ON_COMMAND(ID_IMAGE_EFFECTS_SHARPEN, OnImageEffectsSharpen)
- ON_COMMAND(ID_IMAGE_BINARYFILTERS_DILATION, OnImageBinaryfiltersDilation)
- ON_COMMAND(ID_IMAGE_BINARYFILTERS_EROSION, OnImageBinaryfiltersErosion)
- ON_COMMAND(ID_IMAGE_SPATIALFILTERS_GRADIENT, OnImageSpatialfiltersGradient)
- ON_COMMAND(ID_IMAGE_SPATIALFILTERS_LAPLACIAN, OnImageSpatialfiltersLaplacian)
- ON_COMMAND(ID_IMAGE_SPATIALFILTERS_LINESEGMENT, OnImageSpatialfiltersLinesegment)
- ON_COMMAND(ID_IMAGE_SPATIALFILTERS_PREWITT, OnImageSpatialfiltersPrewitt)
- ON_COMMAND(ID_IMAGE_SPATIALFILTERS_SHIFTANDDIFFERENCE, OnImageSpatialfiltersShiftanddifference)
- ON_COMMAND(ID_IMAGE_SPATIALFILTERS_SOBEL, OnImageSpatialfiltersSobel)
- ON_COMMAND(ID_COLOR_GAMMACORRECT, OnColorGammacorrect)
- ON_COMMAND(ID_COLOR_INTENSITYDETECT, OnColorIntensitydetect)
- ON_COMMAND(ID_IMAGE_RESIZE, OnImageResize)
- ON_COMMAND(ID_IMAGE_ROTATE_ANYANGLE, OnImageRotateAnyangle)
- ON_COMMAND(ID_IMAGE_SHEAR, OnImageShear)
- ON_COMMAND(ID_COLOR_COLORRESOLUTION, OnColorColorresolution)
- ON_COMMAND(ID_VIEW_ZOOM, OnViewZoom)
- ON_COMMAND(ID_VIEW_NORMAL, OnViewNormal)
- ON_COMMAND(ID_VIEW_PAINTEFFECTS, OnViewPainteffects)
- ON_COMMAND(ID_VIEW_SNAPWINDOWTOIMAGE, OnViewSnapwindowtoimage)
- ON_COMMAND(ID_VIEW_FITIMAGETOWINDOW, OnViewFitimagetowindow)
- ON_COMMAND(ID_IMAGE_EFFECTS_EMBOSS, OnImageEffectsEmboss)
- ON_COMMAND(ID_COLOR_HALFTONE, OnColorHalftone)
- ON_COMMAND(ID_COLOR_FILL, OnColorFill)
- ON_COMMAND(ID_EDIT_UNDO, OnEditUndo)
- ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
- ON_COMMAND(ID_COLOR_SEPARATION, OnColorSeparation)
- ON_COMMAND(ID_IMAGE_EFFECTS_EDGEENHANCE, OnImageEffectsEdgeenhance)
- ON_UPDATE_COMMAND_UI(ID_IMAGE_EFFECTS_EDGEENHANCE, OnUpdateImageEffectsEdgeenhance)
- ON_UPDATE_COMMAND_UI(ID_EDIT_UNDO, OnUpdateEditUndo)
- ON_COMMAND(ID_IMAGE_DESKEW, OnImageDeskew)
- ON_COMMAND(ID_IMAGE_EFFECTS_UNDERLAY, OnImageEffectsUnderlay)
- ON_UPDATE_COMMAND_UI(ID_IMAGE_DESKEW, OnUpdateImageDeskew)
- ON_UPDATE_COMMAND_UI(ID_IMAGE_BINARYFILTERS_DILATION, OnUpdateImageBinaryfiltersDilation)
- ON_UPDATE_COMMAND_UI(ID_IMAGE_BINARYFILTERS_EROSION, OnUpdateImageBinaryfiltersErosion)
- ON_UPDATE_COMMAND_UI(ID_IMAGE_EFFECTS_DESPECKLE, OnUpdateImageEffectsDespeckle)
- ON_WM_SIZE()
- ON_COMMAND(IDM_TOOLNONE, OnToolnone)
- ON_UPDATE_COMMAND_UI(IDM_TOOLNONE, OnUpdateToolnone)
- ON_COMMAND(IDM_TOOLELLIPSE, OnToolellipse)
- ON_UPDATE_COMMAND_UI(IDM_TOOLELLIPSE, OnUpdateToolellipse)
- ON_COMMAND(IDM_TOOLFREEHAND, OnToolfreehand)
- ON_UPDATE_COMMAND_UI(IDM_TOOLFREEHAND, OnUpdateToolfreehand)
- ON_COMMAND(IDM_TOOLRECT, OnToolrect)
- ON_UPDATE_COMMAND_UI(IDM_TOOLRECT, OnUpdateToolrect)
- ON_COMMAND(IDM_TOOLRNDRECT, OnToolrndrect)
- ON_UPDATE_COMMAND_UI(IDM_TOOLRNDRECT, OnUpdateToolrndrect)
- ON_UPDATE_COMMAND_UI(ID_IMAGE_REGIONTRANSFORMATIONS_CANCEL, OnUpdateImageRegiontransformationsCancel)
- ON_COMMAND(ID_IMAGE_REGIONTRANSFORMATIONS_CANCEL, OnImageRegiontransformationsCancel)
- ON_UPDATE_COMMAND_UI(ID_IMAGE_SHEAR, OnUpdateImageShear)
- ON_COMMAND(ID_COLOR_WINDOWLEVEL, OnColorWindowlevel)
- ON_UPDATE_COMMAND_UI(ID_COLOR_WINDOWLEVEL, OnUpdateColorWindowlevel)
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CMfcdemoView construction/destruction
-
- CMfcdemoView::CMfcdemoView()
- : CFormView(CMfcdemoView::IDD)
- {
- //{{AFX_DATA_INIT(CMfcdemoView)
- //}}AFX_DATA_INIT
-
- m_pPalette = NULL;
- m_nEffect = EFX_EFFECT_NONE;
- m_nRegionTool = IDM_TOOLNONE;
- m_nRegionType = 0;
- m_nZoom = 100;
-
- m_bMovingFloater = FALSE;
- }
-
- CMfcdemoView::~CMfcdemoView()
- {
- if(m_pPalette)
- delete m_pPalette;
- }
-
- void CMfcdemoView::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMfcdemoView)
- DDX_Control(pDX, IDC_LEADCTRL1, m_Lead);
- DDX_Control(pDX, IDC_LEADCTRL2, m_Lead3);
- //}}AFX_DATA_MAP
- }
-
- BOOL CMfcdemoView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
-
- return CFormView::PreCreateWindow(cs);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMfcdemoView printing
-
- BOOL CMfcdemoView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
-
- void CMfcdemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMfcdemoView diagnostics
-
- #ifdef _DEBUG
- void CMfcdemoView::AssertValid() const
- {
- CFormView::AssertValid();
- }
-
- void CMfcdemoView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
-
- CMfcdemoDoc* CMfcdemoView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMfcdemoDoc)));
- return (CMfcdemoDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CMfcdemoView message handlers
-
- /////////////////////////////////////////////////////////////////////////////
- // CMfcdemoView drawing
-
- void CMfcdemoView::OnDraw(CDC* pDC)
- {
- CRect rcClip;
- CSize winext;
- CSize viewext;
- CSize paintext;
-
- CMfcdemoDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
-
- if(pDC->IsPrinting())
- {
- pDC->SaveDC();
- ::GetWindowExtEx(pDC->m_hDC, &winext);
- ::GetViewportExtEx(pDC->m_hDC, &viewext);
- paintext.cx = MulDiv((int) m_Lead.GetBitmapWidth(), viewext.cx, winext.cx);
- paintext.cy = MulDiv((int) m_Lead.GetBitmapHeight(), viewext.cy, winext.cy);
- ::SetMapMode(pDC->m_hDC, MM_TEXT);
- m_Lead.Render((OLE_HANDLE) pDC->m_hDC, (float) 0, (float) 0, (float) paintext.cx, (float) paintext.cy);
- pDC->RestoreDC(-1);
- }
- }
-
- void CMfcdemoView::BeginProcessing()
- {
- BeginWaitCursor();
- GetUndoLead()->SetBitmap(GetDocLead()->GetBitmap());
- }
-
- void CMfcdemoView::EndProcessing(int nRet)
- {
- EndWaitCursor();
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnChanged()
- {
- CMfcdemoDoc* pDoc = GetDocument();
-
- pDoc->SetModifiedFlag();
- pDoc->UpdateAllViews(NULL, (LPARAM) 0);
- }
-
- void CMfcdemoView::SetZoom(int nZoom)
- {
- CMfcdemoDoc* pDoc = GetDocument();
- m_nZoom = nZoom;
- OnUpdate(NULL, 0, NULL);
- }
-
- CLead* CMfcdemoView::GetDocLead()
- {
- CMfcdemoDoc* pDoc = GetDocument();
- return(&pDoc->m_Lead);
- }
-
- CLead* CMfcdemoView::GetUndoLead()
- {
- CMfcdemoDoc* pDoc = GetDocument();
- return(&pDoc->m_LeadUndo);
- }
-
- void CMfcdemoView::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
-
- int xExt = (int)m_Lead.GetBitmapWidth(),
- yExt = (int)m_Lead.GetBitmapHeight();
- // Make the CLead control to fit the bitmap and disable CLead's scrolling
- // Make the form scroll if the window becomes smaller than the bitmap
- SetScrollSizes(MM_TEXT,CSize(xExt,yExt));
- // Make the window fit the image
- GetParentFrame()->RecalcLayout();
- ResizeParentToFit();
- // now disable the scroll bars
- SetScrollSizes(MM_TEXT,CSize(1,1));
-
- CMfcdemoDoc* pDoc = GetDocument();
- SetZoom(100);
-
- /* this is a hidden control, used only for floater support */
- m_Lead3.ShowWindow(SW_HIDE);
- }
-
- LRESULT CMfcdemoView::OnDoRealize(WPARAM wParam, LPARAM lParam)
- {
- if( !IsWindow(m_Lead.m_hWnd) )
- return FALSE;
- if(lParam)
- {
- return m_Lead.SendMessage(WM_PALETTECHANGED, wParam);
- }
- else
- {
- UINT nColorsChanged = 0;
- CDC* pdc;
-
- pdc = theApp.m_pMainWnd->GetDC();
- HPALETTE hpal = (HPALETTE)m_Lead.GetPalette((OLE_HANDLE) pdc->m_hDC);
- if(hpal)
- {
- CPalette pal;
-
- pal.Attach(hpal);
- CPalette* oldPalette = pdc->SelectPalette(&pal, (BOOL) lParam);
- nColorsChanged = pdc->RealizePalette();
- if (nColorsChanged > 0)
- m_Lead.InvalidateRect(NULL, FALSE);
- pdc->SelectPalette(oldPalette, TRUE);
- }
- theApp.m_pMainWnd->ReleaseDC(pdc);
- return ((LRESULT) (BOOL) (nColorsChanged > 0));
- }
- }
-
- void CMfcdemoView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
- {
- CFormView::OnActivateView(bActivate, pActivateView, pDeactiveView);
- if (bActivate)
- {
- ASSERT(pActivateView == this);
- OnDoRealize((WPARAM)theApp.m_pMainWnd->m_hWnd, (LPARAM) FALSE); // same as SendMessage(WM_DOREALIZE);
- }
- }
-
- void CMfcdemoView::OnImageFlip()
- {
- if(m_Lead.GetHasRgn())
- {
- OnImageRegiontransformationsFlip();
- }
- else
- {
- BeginProcessing();
- int nRet = GetDocLead()->Flip();
- OnChanged();
- EndProcessing(nRet);
- }
- }
-
- void CMfcdemoView::OnImageReverse()
- {
- if(m_Lead.GetHasRgn())
- {
- OnImageRegiontransformationsReverse();
- }
- else
- {
- BeginProcessing();
- int nRet = GetDocLead()->Reverse();
- OnChanged();
- EndProcessing(nRet);
- }
- }
-
- void CMfcdemoView::OnImageRotate180clockwise()
- {
- if(m_Lead.GetHasRgn())
- {
- OnImageRegiontransformationsRotate((long) 18000);
- }
- else
- {
- BeginProcessing();
- int nRet = GetDocLead()->Rotate(18000, TRUE, RGB(0, 0, 0));
- OnChanged();
- EndProcessing(nRet);
- }
- }
-
- void CMfcdemoView::OnImageRotate270clockwise()
- {
- if(m_Lead.GetHasRgn())
- {
- OnImageRegiontransformationsRotate((long) 27000);
- }
- else
- {
- BeginProcessing();
- int nRet = GetDocLead()->Rotate(27000, TRUE, RGB(0, 0, 0));
- OnChanged();
- EndProcessing(nRet);
- }
- }
-
- void CMfcdemoView::OnImageRotate90clockwise()
- {
- if(m_Lead.GetHasRgn())
- {
- OnImageRegiontransformationsRotate((long) 9000);
- }
- else
- {
- BeginProcessing();
- int nRet = GetDocLead()->Rotate(9000, TRUE, RGB(0, 0, 0));
- OnChanged();
- EndProcessing(nRet);
- }
- }
-
-
- void CMfcdemoView::OnColorGrayscale()
- {
- BeginProcessing();
- int nRet = GetDocLead()->Grayscale(8);
- OnChanged();
- EndProcessing(nRet);
- }
-
- void CMfcdemoView::OnColorGrayscale12()
- {
- BeginProcessing();
- int nRet = GetDocLead()->Grayscale(12);
- OnChanged();
- EndProcessing(nRet);
- }
-
- void CMfcdemoView::OnColorGrayscale16()
- {
- BeginProcessing();
- int nRet = GetDocLead()->Grayscale(16);
- OnChanged();
- EndProcessing(nRet);
- }
-
-
- void CMfcdemoView::OnColorHistogramequalize()
- {
- BeginProcessing();
- int nRet = GetDocLead()->HistoEqualize();
- OnChanged();
- EndProcessing(nRet);
- }
-
- void CMfcdemoView::OnColorInvert()
- {
- BeginProcessing();
- int nRet = GetDocLead()->Invert();
- OnChanged();
- EndProcessing(nRet);
- }
-
- void CMfcdemoView::OnColorStretchintensity()
- {
- BeginProcessing();
- int nRet = GetDocLead()->StretchIntensity();
- OnChanged();
- EndProcessing(nRet);
- }
-
- void CMfcdemoView::OnImageEffectsPosterize()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_POSTERIZE | DLG_IMG_SHOWPREVIEW );
- // LTCommDlg.SetChange(2);
- nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->Posterize(LTCommDlg.GetChange()/*the property*/);
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- return;
- }
-
- void CMfcdemoView::OnColorBrightness()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_BRIGHTNESS | DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->Intensity(LTCommDlg.GetChange()/*the property*/);
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnColorContrast()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_CONTRAST | DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->Contrast(LTCommDlg.GetChange()/*the property*/);
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
-
- void CMfcdemoView::OnColorHistocontrast()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_HISTOCONTRAST | DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->HistoContrast(LTCommDlg.GetChange()/*the property*/);
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnColorHue()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_HUE | DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->Hue(LTCommDlg.GetChange()/*the property*/);
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnColorSaturation()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_SATURATION | DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->Saturation(LTCommDlg.GetChange()/*the property*/);
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnImageEffectsAddnoise()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetNoise((long)this->m_hWnd);
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->AddNoise( LTCommDlg.GetRange(), /* the property */
- LTCommDlg.GetChannel() );
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnImageEffectsAverage()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_AVERAGE | DLG_IMG_SHOWPREVIEW );
- LTCommDlg.SetChange(3);
- nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->Average(LTCommDlg.GetChange()/*the property*/);
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnImageEffectsDespeckle()
- {
- BeginProcessing();
- int nRet = GetDocLead()->Despeckle();
- OnChanged();
- EndProcessing(nRet);
- }
-
- void CMfcdemoView::OnImageEffectsMedian()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_MEDIAN | DLG_IMG_SHOWPREVIEW );
- LTCommDlg.SetChange(3);
- nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->Median(LTCommDlg.GetChange()/*the property*/);
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnImageEffectsMosaic()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_MOSAIC | DLG_IMG_SHOWPREVIEW );
- LTCommDlg.SetChange(2);
- nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->Mosaic(LTCommDlg.GetChange()/*the property*/);
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnImageEffectsSharpen()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_SHARPEN | DLG_IMG_SHOWPREVIEW );
- LTCommDlg.SetChange(0);
- nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->Sharpen(LTCommDlg.GetChange()/*the property*/);
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnImageBinaryfiltersDilation()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_DILATION | DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetFilter((long)this->m_hWnd);
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->BinaryFilter( LTCommDlg.GetBinaryFilterType());
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnImageBinaryfiltersErosion()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_EROSION | DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetFilter((long)this->m_hWnd);
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->BinaryFilter( LTCommDlg.GetBinaryFilterType());
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnImageSpatialfiltersGradient()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_GRADIENT | DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetFilter((long)this->m_hWnd);
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->SpatialFilter( LTCommDlg.GetSpatialFilterType());
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnImageSpatialfiltersLaplacian()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_LAPLACIAN | DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetFilter((long)this->m_hWnd);
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->SpatialFilter( LTCommDlg.GetSpatialFilterType());
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnImageSpatialfiltersLinesegment()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_LINESEG | DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetFilter((long)this->m_hWnd);
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->SpatialFilter( LTCommDlg.GetSpatialFilterType());
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnImageSpatialfiltersPrewitt()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_PREWITT | DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetFilter((long)this->m_hWnd);
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->SpatialFilter( LTCommDlg.GetSpatialFilterType());
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnImageSpatialfiltersShiftanddifference()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_SHIFTDIFF | DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetFilter((long)this->m_hWnd);
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->SpatialFilter( LTCommDlg.GetSpatialFilterType());
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnImageSpatialfiltersSobel()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_SOBEL | DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetFilter((long)this->m_hWnd);
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->SpatialFilter( LTCommDlg.GetSpatialFilterType());
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnColorGammacorrect()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetGamma((long)this->m_hWnd);//the method
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->GammaCorrect( LTCommDlg.GetGamma() /* the property */);
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
-
-
- void CMfcdemoView::OnImageResize()
- {
- if(m_Lead.GetHasRgn())
- {
- OnImageRegiontransformationsResize();
- }
- else
- {
- CResizeDlg dlg;
-
- dlg.m_nWidth = (int) GetDocLead()->GetBitmapWidth();
- dlg.m_nHeight = (int) GetDocLead()->GetBitmapHeight();
- if(dlg.DoModal() == IDOK)
- {
- int nRet;
-
- BeginProcessing();
- if(dlg.m_fResample)
- nRet = GetDocLead()->Size((float) dlg.m_nWidth, (float) dlg.m_nHeight, RESIZE_RESAMPLE);
- else
- nRet = GetDocLead()->Size((float) dlg.m_nWidth, (float) dlg.m_nHeight, RESIZE_NORMAL);
- OnChanged();
- EndProcessing(nRet);
- }
- }
- }
-
- void CMfcdemoView::OnImageRotateAnyangle()
- {
- if(m_Lead.GetHasRgn())
- {
- OnImageRegiontransformationsRotate();
- }
- else
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetBackColor(RGB(255,255,255));
- LTCommDlg.SetUIFlags( DLG_IMG_ROTATE | DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetAngle((long)this->m_hWnd); /* the method */
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->Rotate((long) LTCommDlg.GetAngle(), /* the property */
- LTCommDlg.GetAngleFlag(),
- LTCommDlg.GetBackColor() );
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
- }
-
- void CMfcdemoView::OnImageShear()
- {
- if(m_Lead.GetHasRgn())
- {
- OnImageRegiontransformationsShear();
- }
- else
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetBackColor(RGB(255,255,255));
- LTCommDlg.SetUIFlags( DLG_IMG_SHEAR | DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetAngle((long)this->m_hWnd); /* the method */
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->Shear((short) LTCommDlg.GetAngle(), /* the property */
- LTCommDlg.GetAngleFlag(),
- RGB(255, 255, 255) );
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
- }
-
- void CMfcdemoView::OnColorColorresolution()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_CR_BITALL | DLG_CR_DITHER_ALL | DLG_CR_PAL_ALL | DLG_CR_ORDER | DLG_CR_SHOWPREVIEW );
- nRet = LTCommDlg.GetColorRes((long)this->m_hWnd);
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->ColorRes( LTCommDlg.GetBitsPerPixel(),
- LTCommDlg.GetPaletteFlags(),
- LTCommDlg.GetDitherFlags(),
- 0 );
-
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnColorIntensitydetect()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetRange((long)this->m_hWnd);//the method
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->IntensityDetect( LTCommDlg.GetLow(), LTCommDlg.GetHigh());
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnViewZoom()
- {
- CRangeDlg dlg;
-
- dlg.m_strTitle = _T("Zoom");
- dlg.m_strLabel = _T("&Amount");
- dlg.m_nValue = m_nZoom;
- dlg.m_nMin = 1;
- dlg.m_nMax = 800;
- dlg.m_nPage = 100;
-
- if(dlg.DoModal() == IDOK)
- {
- SetZoom(dlg.m_nValue);
- }
- }
-
- void CMfcdemoView::OnViewNormal()
- {
- SetZoom(100);
- }
-
- static int nEffectIndex[] =
- {
- EFX_EFFECT_WIPE_CLASS, EFX_EFFECT_WIPE_MAX,
- EFX_EFFECT_WIPE_RECTANGLE_CLASS, EFX_EFFECT_WIPE_RECTANGLE_MAX,
- EFX_EFFECT_WIPE_CIRCLE_CLASS, EFX_EFFECT_WIPE_CIRCLE_MAX,
- EFX_EFFECT_PUSH_CLASS, EFX_EFFECT_PUSH_MAX,
- EFX_EFFECT_SLIDE_CLASS, EFX_EFFECT_SLIDE_MAX,
- EFX_EFFECT_ROLL_CLASS, EFX_EFFECT_ROLL_MAX,
- EFX_EFFECT_ROTATE_CLASS, EFX_EFFECT_ROTATE_MAX,
- EFX_EFFECT_ZOOM_CLASS, EFX_EFFECT_ZOOM_MAX,
- EFX_EFFECT_DRIP_CLASS, EFX_EFFECT_DRIP_MAX,
- EFX_EFFECT_BLIND_CLASS, EFX_EFFECT_BLIND_MAX,
- EFX_EFFECT_RANDOM_CLASS, EFX_EFFECT_RANDOM_MAX,
- EFX_EFFECT_CHECKERBOARD_CLASS, EFX_EFFECT_CHECKERBOARD_MAX,
- EFX_EFFECT_BLOCKS_CLASS, EFX_EFFECT_BLOCKS_MAX,
- EFX_EFFECT_CIRCLE_CLASS, EFX_EFFECT_CIRCLE_MAX,
- EFX_EFFECT_ELLIPSE_CLASS, EFX_EFFECT_ELLIPSE_MAX,
- };
-
- void CMfcdemoView::OnViewPainteffects()
- {
- CClientDC cdc(this);
- DWORD dw;
- int i;
-
- BeginWaitCursor();
- for (i = 0; i < sizeof(nEffectIndex) / sizeof(nEffectIndex[0]); i += 2)
- {
- for (m_nEffect = nEffectIndex[i]; m_nEffect <= nEffectIndex[i+1]; m_nEffect++)
- {
- m_Lead.SetPaintEffect(m_nEffect);
- dw = GetTickCount ();
- while ((GetTickCount () - dw) < 1000);
- }
- }
- m_nEffect = EFX_EFFECT_NONE;
- m_Lead.SetPaintEffect(m_nEffect);
- EndWaitCursor();
- }
-
- void CMfcdemoView::OnViewSnapwindowtoimage()
- {
- CWnd* pFrame = GetParent();
- CRect rcWindow;
- CRect rcClient;
-
- pFrame->ShowWindow(SW_NORMAL);
- GetClientRect(&rcClient);
- pFrame->GetWindowRect(&rcWindow);
-
- pFrame->GetParent()->ScreenToClient (rcWindow);
-
- pFrame->MoveWindow (rcWindow.left, rcWindow.top,
- rcWindow.Width() + (int) m_Lead.GetDstWidth() - rcClient.Width(),
- rcWindow.Height() + (int) m_Lead.GetDstHeight() - rcClient.Height());
- }
-
- void CMfcdemoView::OnViewFitimagetowindow()
- {
- int cxZoom, cyZoom;
- cxZoom = (int) ((long) m_Lead.GetScaleWidth() * 100 / m_Lead.GetBitmapWidth());
- cyZoom = (int) ((long) m_Lead.GetScaleHeight() * 100 / m_Lead.GetBitmapHeight());
- SetZoom(max(min(cxZoom, cyZoom), 1));
- }
-
- void CMfcdemoView::OnImageEffectsEmboss()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetEmboss((long)this->m_hWnd);
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->Emboss( LTCommDlg.GetDirection(), LTCommDlg.GetDepth());
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnColorHalftone()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags( DLG_IMG_HALFTONE | DLG_IMG_SHOWPREVIEW );
- nRet = LTCommDlg.GetChange((long)this->m_hWnd); /* the method */
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- BeginProcessing();
- int nRet = GetDocLead()->Halftone(1, LTCommDlg.GetChange()/*the property*/);
- OnChanged();
- EndProcessing(nRet);
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnColorFill()
- {
- CColorDialog dlg;
-
- if(dlg.DoModal() == IDOK)
- {
- BeginProcessing();
- int nRet = GetDocLead()->Fill(dlg.GetColor());
- OnChanged();
- EndProcessing(nRet);
- }
- }
-
- void CMfcdemoView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
- {
- CMfcdemoDoc* pDoc = GetDocument();
- long hRegion;
-
- m_Lead.SetAutoRepaint(FALSE);
- m_Lead.SetBitmap(GetDocLead()->GetBitmap());
- m_Lead.SetPaintPalette(theApp.m_fAutoPalette ? PAINTPALETTE_AUTO : PAINTPALETTE_FIXED);
- m_Lead.SetPaintDither(theApp.m_fOrderedDither ? PAINTDITHER_ORDERED : PAINTDITHER_DIFFUSION);
- m_Lead.SetBitonalScaling(theApp.m_nBitonalScaling);
- m_Lead.SetDstRect(m_Lead.GetDstLeft(), m_Lead.GetDstTop(), m_Lead.GetBitmapWidth() * m_nZoom / 100, m_Lead.GetBitmapHeight() * m_nZoom / 100);
- m_Lead.SetDstClipRect(m_Lead.GetDstLeft(), m_Lead.GetDstTop(), m_Lead.GetDstWidth(), m_Lead.GetDstHeight());
- /* copy the region from the document control */
- if( GetDocLead()->GetHasRgn() )
- {
- hRegion = GetDocLead()->GetRgnHandle();
- m_Lead.SetRgnHandle(hRegion,0.0f,0.0f,L_RGN_SET);
- m_Lead.SetRgnFrameType(RGNFRAME_STATIC);
- m_Lead.DeleteRgnHandle(hRegion);
- }
- else
- {
- /* the region processing are only for express toolkits */
- if( !m_Lead.IsSupportLocked(L_SUPPORT_EXPRESS) )
- {
- m_Lead.SetRgnFrameType(RGNFRAME_NONE);
- m_Lead.FreeRgn();
- }
- }
- m_Lead.SetAutoRepaint(TRUE);
- }
-
- void CMfcdemoView::OnEditUndo()
- {
- BeginWaitCursor();
- GetDocLead()->SetBitmap(GetUndoLead()->GetBitmap());
- GetUndoLead()->SetBitmap(0);
- OnChanged();
- EndWaitCursor();
- }
-
- void CMfcdemoView::OnUpdateEditUndo(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(GetUndoLead()->GetBitmap() != 0);
- }
-
- void CMfcdemoView::OnEditCopy()
- {
- BeginWaitCursor();
- GetDocLead()->Copy(COPY_DIB | COPY_DDB | COPY_PALETTE);
- EndWaitCursor();
- }
-
- void CMfcdemoView::OnColorSeparation()
- {
- CListDlg dlg;
- int i, nPlanes;
-
- dlg.m_strTitle = _T("Separation");
- dlg.m_strLabel = _T("&Color Space");
- dlg.m_strInit = _T("RGB|CMYK|HSV|HLS|CMY|");
- if(dlg.DoModal() == IDOK)
- {
- BeginProcessing();
- int nRet = GetDocLead()->ColorSeparate(dlg.m_nValue);
- if(!nRet)
- {
- nPlanes = (dlg.m_nValue == COLORSEP_CMYK) ? 4 : 3;
- for(i = 0; i < nPlanes; i++)
- {
- theApp.m_Bitmap = GetDocLead()->GetColorPlanes(i);
- theApp.OpenDocument(OPENMODE_BITMAP);
- GetDocLead()->SetColorPlanes(i, 0);
- }
- }
- EndProcessing(nRet);
- }
- }
-
- void CMfcdemoView::OnImageEffectsEdgeenhance()
- {
- BeginProcessing();
-
- int nRet = TRUE; //m_Lead.SpatialFilter(FLT_LAPLACE_1);
- if(!nRet)
- {
- nRet = GetDocLead()->Combine(0.0f, 0.0f, m_Lead.GetBitmapWidth(), m_Lead.GetBitmapHeight(),
- m_Lead.GetBitmap(), 0.0f, 0.0f, CB_OP_ADD);
- }
- OnChanged();
- EndProcessing(nRet);
- }
-
- void CMfcdemoView::OnUpdateImageEffectsEdgeenhance(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(TRUE); //GetDocLead()->GetBitmapBits() > 8);
- }
-
-
- void CMfcdemoView::OnImageDeskew()
- {
- BeginProcessing();
- int nRet = GetDocLead()->Deskew();
- OnChanged();
- EndProcessing(nRet);
- }
-
- void CMfcdemoView::OnImageEffectsUnderlay()
- {
- CUnderLayDlg dlg;
-
- if(dlg.DoModal() == IDOK)
- {
- BeginProcessing();
- int nRet = GetDocLead()->Underlay(((CMfcdemoDoc*)dlg.m_pDocument)->m_Lead.GetBitmap(), dlg.m_fTile ? UNDERLAY_TILE : UNDERLAY_STRETCH);
- OnChanged();
- EndProcessing(nRet);
- }
- }
-
- void CMfcdemoView::OnUpdateImageDeskew(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable((GetDocLead()->GetVersionLevel() == VERSIONLEVEL_EXP||GetDocLead()->GetVersionLevel() == VERSIONLEVEL_MEDICAL)
- && !m_Lead.GetHasRgn());
- }
-
- void CMfcdemoView::OnUpdateImageShear(CCmdUI* pCmdUI)
- {
- //pCmdUI->Enable(!m_Lead.GetHasRgn());
- }
-
- void CMfcdemoView::OnUpdateImageBinaryfiltersDilation(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(GetDocLead()->GetVersionLevel() == VERSIONLEVEL_EXP||GetDocLead()->GetVersionLevel() == VERSIONLEVEL_MEDICAL);
- }
-
- void CMfcdemoView::OnUpdateImageBinaryfiltersErosion(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(GetDocLead()->GetVersionLevel() == VERSIONLEVEL_EXP||GetDocLead()->GetVersionLevel() == VERSIONLEVEL_MEDICAL);
- }
-
- void CMfcdemoView::OnUpdateImageEffectsDespeckle(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(GetDocLead()->GetVersionLevel() == VERSIONLEVEL_EXP||GetDocLead()->GetVersionLevel() == VERSIONLEVEL_MEDICAL);
- }
-
- void CMfcdemoView::OnSize(UINT nType, int cx, int cy)
- {
- CFormView::OnSize(nType, cx, cy);
-
- if( IsWindow(m_Lead.m_hWnd) )
- m_Lead.MoveWindow(0, 0, cx, cy);
- }
-
-
- void CMfcdemoView::OnToolnone()
- {
- SetRegionTool( IDM_TOOLNONE );
- }
-
- void CMfcdemoView::OnUpdateToolnone(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!m_Lead.IsSupportLocked(L_SUPPORT_EXPRESS));
- pCmdUI->SetCheck(m_nRegionTool == IDM_TOOLNONE);
- }
-
- void CMfcdemoView::OnToolellipse()
- {
- SetRegionTool( IDM_TOOLELLIPSE );
- }
-
- void CMfcdemoView::OnUpdateToolellipse(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!m_Lead.IsSupportLocked(L_SUPPORT_EXPRESS));
- pCmdUI->SetCheck(m_nRegionTool == IDM_TOOLELLIPSE);
- }
-
- void CMfcdemoView::OnToolfreehand()
- {
- SetRegionTool( IDM_TOOLFREEHAND );
- }
-
- void CMfcdemoView::OnUpdateToolfreehand(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!m_Lead.IsSupportLocked(L_SUPPORT_EXPRESS));
- pCmdUI->SetCheck(m_nRegionTool == IDM_TOOLFREEHAND);
- }
-
- void CMfcdemoView::OnToolrect()
- {
- SetRegionTool( IDM_TOOLRECT );
- }
-
- void CMfcdemoView::OnUpdateToolrect(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!m_Lead.IsSupportLocked(L_SUPPORT_EXPRESS));
- pCmdUI->SetCheck(m_nRegionTool == IDM_TOOLRECT);
- }
-
- void CMfcdemoView::OnToolrndrect()
- {
- SetRegionTool( IDM_TOOLRNDRECT );
- }
-
- void CMfcdemoView::OnUpdateToolrndrect(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!m_Lead.IsSupportLocked(L_SUPPORT_EXPRESS));
- pCmdUI->SetCheck(m_nRegionTool == IDM_TOOLRNDRECT);
- }
-
- void CMfcdemoView::SetRegionTool( int nNewRegionTool )
- {
- m_nRegionTool = nNewRegionTool;
- }
-
-
- BEGIN_EVENTSINK_MAP(CMfcdemoView, CFormView)
- //{{AFX_EVENTSINK_MAP(CMfcdemoView)
- ON_EVENT(CMfcdemoView, IDC_LEADCTRL1, -605 /* MouseDown */, OnMouseDownLeadctrl1, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
- ON_EVENT(CMfcdemoView, IDC_LEADCTRL1, -606 /* MouseMove */, OnMouseMoveLeadctrl1, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
- ON_EVENT(CMfcdemoView, IDC_LEADCTRL1, -607 /* MouseUp */, OnMouseUpLeadctrl1, VTS_I2 VTS_I2 VTS_I4 VTS_I4)
- ON_EVENT(CMfcdemoView, IDC_LEADCTRL1, 7 /* RgnChange */, OnRgnChangeLeadctrl1, VTS_NONE)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
-
- void CMfcdemoView::OnRgnChangeLeadctrl1()
- {
- if(GetDocument()->m_Lead2.GetBitmap() == NULL)
- SaveBackground();
- }
-
- void CMfcdemoView::OnMouseDownLeadctrl1(short Button, short Shift, long x, long y)
- {
- if( Button != 1 )
- return; /* nothing to do! */
-
- HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
-
- if( m_Lead.GetHasRgn() && m_Lead.IsPtInRgn((x - m_Lead.GetDstLeft()) * m_Lead.GetSrcWidth() / m_Lead.GetDstWidth(), (y - m_Lead.GetDstTop()) * m_Lead.GetSrcHeight() / m_Lead.GetDstHeight()) )
- {
- m_Lead.SetAutoRepaint(FALSE);
- m_Lead.SetRgnMarkingMode(RGNMARK_NONE);
- m_Lead.SetRgnFrameType(RGNFRAME_NONE);
- m_xStart = x;
- m_yStart = y;
- // we put the floater into the bitmap only when we select another region
- // if we have a floater at this point, it's because we clicked INSIDE the floater
- m_Lead.SetFloaterVisible(FALSE);
- m_Lead.SetFloater(m_Lead.GetBitmap());
- // the floater coordinates are relative to the window, while the
- // ocx region coordinates are relative to the bitmap. Adding m_Lead.DstLeft
- // converts m_Lead.RgnLeft to window coordinates
- m_rcFloater.left = (int) ((m_Lead.GetRgnLeft() * m_Lead.GetDstWidth() + m_Lead.GetSrcWidth() - 1) / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft());
- m_rcFloater.top = (int) (m_Lead.GetRgnTop() * m_Lead.GetDstHeight() / m_Lead.GetSrcHeight() + m_Lead.GetDstTop());
- m_rcFloater.right = (int) (((m_Lead.GetFloaterWidth() + m_Lead.GetRgnLeft()) * m_Lead.GetDstWidth() + m_Lead.GetSrcWidth() - 1) / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft());
- m_rcFloater.bottom = (int) ((m_Lead.GetFloaterHeight() + m_Lead.GetRgnTop()) * m_Lead.GetDstHeight() / m_Lead.GetSrcHeight() + m_Lead.GetDstTop());
- m_Lead.SetFloaterDstRect((float) m_rcFloater.left, (float) m_rcFloater.top,
- (float) m_rcFloater.Width(), (float) m_rcFloater.Height());
- if( GetDocument()->m_Lead2.GetBitmap() != NULL )
- {
- m_Lead.Combine(m_Lead.GetRgnLeft(),
- m_Lead.GetRgnTop(),
- m_Lead.GetFloaterWidth(),
- m_Lead.GetFloaterHeight(),
- GetDocument()->m_Lead2.GetBitmap(),
- 0.0f,
- 0.0f,
- L_SRC_COPY );
- // RepaintRect uses window coordinates like the floater bitmap
- m_Lead.RepaintRect(m_Lead.GetFloaterDstLeft(),
- m_Lead.GetFloaterDstTop(),
- m_Lead.GetFloaterDstWidth(),
- m_Lead.GetFloaterDstHeight(),
- FALSE);
- }
- m_Lead.SetFloaterVisible(TRUE);
- m_bMovingFloater = TRUE;
- }
- else if (m_nRegionTool != IDM_TOOLNONE)
- {
- m_Lead.SetRgnFrameType(RGNFRAME_NONE);
-
- switch(m_nRegionTool)
- {
- case IDM_TOOLRECT:
- m_Lead.SetRgnMarkingMode(RGNMARK_RECT);
- break;
- case IDM_TOOLELLIPSE:
- m_Lead.SetRgnMarkingMode(RGNMARK_ELLIPSE);
- break;
- case IDM_TOOLRNDRECT:
- m_Lead.SetRgnMarkingMode(RGNMARK_ROUNDRECT);
- break;
- case IDM_TOOLFREEHAND:
- m_Lead.SetRgnMarkingMode(RGNMARK_FREEHAND);
- break;
- }
- }
-
- GetDocument()->m_Lead2.SetBitmap(0); // the background bitmap is not needed anymore
-
- SetCursor(hOldCursor);
- }
-
- void CMfcdemoView::OnMouseMoveLeadctrl1(short Button, short Shift, long x, long y)
- {
- if( (Button == 1) && m_bMovingFloater )
- {
- m_Lead.SetFloaterDstRect((float) (m_rcFloater.left + x - m_xStart), (float) (m_rcFloater.top + y - m_yStart),
- m_Lead.GetFloaterDstWidth(), m_Lead.GetFloaterDstHeight());
- }
- }
-
- void CMfcdemoView::OnMouseUpLeadctrl1(short Button, short Shift, long x, long y)
- {
- HRGN hRegion;
- long dx, dy;
-
- if (Button != 1)
- return; /* nothing to do ! */
-
- HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
-
- if( m_Lead.GetRgnMarkingMode() != RGNMARK_NONE )
- {
- m_Lead.SetRgnMarkingMode(RGNMARK_NONE);
- m_Lead.SetRgnFrameType(RGNFRAME_STATIC);
-
- if( m_Lead.GetHasRgn() )
- {
- hRegion = (HRGN)m_Lead.GetRgnHandle();
- GetDocLead()->SetRgnHandle((long)hRegion,0.0f,0.0f,L_RGN_SET);
- m_Lead.DeleteRgnHandle((long)hRegion);
- }
- else
- GetDocLead()->FreeRgn();
- GetDocument()->UpdateAllViews(this, (LPARAM)0);
- }
- else if(m_bMovingFloater)
- {
- m_bMovingFloater = FALSE;
- m_Lead.SetRgnFrameType(RGNFRAME_NONE);
- hRegion = (HRGN)m_Lead.GetFloaterHandle();
-
-
- // Calculate the region offset
-
- if(x >= m_xStart)
- dx = (x - m_xStart) * (long) m_Lead.GetSrcWidth() / (long) m_Lead.GetDstWidth();
- else
- dx = ((x - m_xStart) * (long) m_Lead.GetSrcWidth() - (long) m_Lead.GetDstWidth() + 1) / (long) m_Lead.GetDstWidth();
- if(y >= m_yStart)
- dy = (y - m_yStart) * (long) m_Lead.GetSrcHeight() / (long) m_Lead.GetDstHeight();
- else
- dy = ((y - m_yStart) * (long) m_Lead.GetSrcHeight() - (long) m_Lead.GetDstHeight() + 1) / (long) m_Lead.GetDstHeight();
-
- m_Lead.OffsetRgn((float) dx, (float) dy);
-
- // save the background in case we want to move the floater again
- GetDocument()->m_Lead2.CreateBitmap(m_Lead.GetFloaterWidth(),
- m_Lead.GetFloaterHeight(),
- m_Lead.GetBitmapBits() );
- if((m_Lead.GetIsGrayscale() != GRAY_NO) && (m_Lead.GetBitmapBits()>8))
- GetDocument()->m_Lead2.Grayscale(m_Lead.GetBitmapBits());
-
- GetDocument()->m_Lead2.Combine( 0.0f,
- 0.0f,
- m_Lead.GetFloaterWidth(),
- m_Lead.GetFloaterHeight(),
- m_Lead.GetBitmap(),
- m_Lead.GetRgnLeft(),
- m_Lead.GetRgnTop(),
- L_SRC_COPY);
-
- // now blend the floater into the bitmap and make it dissapear
- // if we leave it, when we scroll, the floater won't move with the bitmap
- // that's because the floater is independent of the bitmap
- m_Lead.Combine( m_Lead.GetRgnLeft(),
- m_Lead.GetRgnTop(),
- m_Lead.GetFloaterWidth(),
- m_Lead.GetFloaterHeight(),
- m_Lead.GetFloater(),
- 0.0f,
- 0.0f,
- L_SRC_COPY);
- // free the floater
- m_Lead.SetFloater(NULL);
-
- // draw the frame
- m_Lead.SetRgnFrameType(RGNFRAME_STATIC);
- m_Lead.DeleteRgnHandle ((long)hRegion); // delete the region object
-
-
- m_Lead.SetAutoRepaint(TRUE);
- /* update the changes back into the master document and all other views */
- UpdateMasterDocument();
- }
-
- SetCursor(hOldCursor);
- }
-
- void CMfcdemoView::OnImageRegiontransformationsFlip()
- {
- long hRegion;
- float xCenter;
- float yCenter;
-
- HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
-
- m_Lead.SetAutoRepaint(FALSE);
- m_Lead.SetFloaterVisible(FALSE);
- m_Lead.SetFloater(m_Lead.GetBitmap());
- RestoreBackground();
- m_Lead3.SetBitmap(m_Lead.GetFloater());
- m_Lead.SetFloater(0);
-
- // do the transformation on the copy
- m_Lead3.Flip();
-
- m_Lead.SetRgnFrameType(RGNFRAME_NONE);
- hRegion = m_Lead3.GetRgnHandle();
- xCenter = m_Lead.GetRgnLeft() + m_Lead.GetRgnWidth() / 2;
- yCenter = m_Lead.GetRgnTop() + m_Lead.GetRgnHeight() / 2;
- /* the next two statements
- m_Lead.SetRgnHandle(hRegion,
- 0,
- 0,
- L_RGN_SET);
- m_Lead.OffsetRgn(
- xCenter - m_Lead3.GetBitmapWidth() / 2,
- yCenter - m_Lead3.GetBitmapHeight() / 2);
- do exactly the same thing as the following statement: */
- m_Lead.SetRgnHandle(hRegion,
- xCenter - m_Lead3.GetBitmapWidth() / 2,
- yCenter - m_Lead3.GetBitmapHeight() / 2,
- L_RGN_SET);
- m_Lead.DeleteRgnHandle (hRegion);
- SaveBackground();
- m_Lead.Combine(
- xCenter - m_Lead3.GetBitmapWidth() / 2,
- yCenter - m_Lead3.GetBitmapHeight() / 2,
- m_Lead3.GetBitmapWidth(),
- m_Lead3.GetBitmapHeight(),
- m_Lead3.GetBitmap(),
- 0.0f,
- 0.0f,
- L_SRC_COPY);
- m_Lead.RepaintRect(
- m_Lead.GetRgnLeft() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft(),
- m_Lead.GetRgnTop() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstTop(),
- m_Lead.GetRgnWidth() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(),
- m_Lead.GetRgnHeight() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(),
- FALSE);
- m_Lead.SetRgnFrameType(RGNFRAME_STATIC);
- m_Lead3.SetBitmap(0);
- m_Lead.SetAutoRepaint(TRUE);
-
-
- /* update the changes back into the master document and all other views */
- UpdateMasterDocument();
-
- SetCursor(hOldCursor);
- }
-
- void CMfcdemoView::OnImageRegiontransformationsResize()
- {
- CResizeDlg dlg;
-
- dlg.m_nWidth = (int) GetDocLead()->GetRgnWidth();
- dlg.m_nHeight = (int) GetDocLead()->GetRgnHeight();
- if(dlg.DoModal() == IDOK)
- {
- int nRet;
- long hRegion;
- float xCenter;
- float yCenter;
-
- HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
-
- m_Lead.SetAutoRepaint(FALSE);
- m_Lead.SetFloaterVisible(FALSE);
- m_Lead.SetFloater(m_Lead.GetBitmap());
- RestoreBackground();
- m_Lead3.SetBitmap(m_Lead.GetFloater());
- m_Lead.SetFloater(0);
-
- // do the transformation on the copy
- if(dlg.m_fResample)
- nRet = m_Lead3.Size((float) dlg.m_nWidth, (float) dlg.m_nHeight, RESIZE_RESAMPLE);
- else
- nRet = m_Lead3.Size((float) dlg.m_nWidth, (float) dlg.m_nHeight, RESIZE_NORMAL);
-
- m_Lead.SetRgnFrameType(RGNFRAME_NONE);
- hRegion = m_Lead3.GetRgnHandle();
- xCenter = m_Lead.GetRgnLeft() + m_Lead.GetRgnWidth() / 2;
- yCenter = m_Lead.GetRgnTop() + m_Lead.GetRgnHeight() / 2;
- m_Lead.SetRgnHandle(hRegion,
- xCenter - m_Lead3.GetBitmapWidth() / 2,
- yCenter - m_Lead3.GetBitmapHeight() / 2,
- L_RGN_SET);
- m_Lead.DeleteRgnHandle (hRegion);
- SaveBackground();
- m_Lead.Combine(
- xCenter - m_Lead3.GetBitmapWidth() / 2,
- yCenter - m_Lead3.GetBitmapHeight() / 2,
- m_Lead3.GetBitmapWidth(),
- m_Lead3.GetBitmapHeight(),
- m_Lead3.GetBitmap(),
- 0.0f,
- 0.0f,
- L_SRC_COPY);
- m_Lead.RepaintRect(
- m_Lead.GetRgnLeft() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft(),
- m_Lead.GetRgnTop() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstTop(),
- m_Lead.GetRgnWidth() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(),
- m_Lead.GetRgnHeight() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(),
- FALSE);
- m_Lead.SetRgnFrameType(RGNFRAME_STATIC);
- m_Lead3.SetBitmap(0);
- m_Lead.SetAutoRepaint(TRUE);
-
- /* update the changes back into the master document and all other views */
- UpdateMasterDocument();
-
- SetCursor(hOldCursor);
- }
- }
-
- void CMfcdemoView::OnImageRegiontransformationsReverse()
- {
- long hRegion;
- float xCenter;
- float yCenter;
-
- HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
-
- m_Lead.SetAutoRepaint(FALSE);
- m_Lead.SetFloaterVisible(FALSE);
- m_Lead.SetFloater(m_Lead.GetBitmap());
- RestoreBackground();
- m_Lead3.SetBitmap(m_Lead.GetFloater());
- m_Lead.SetFloater(0);
-
- // do the transformation on the copy
- m_Lead3.Reverse();
-
- m_Lead.SetRgnFrameType(RGNFRAME_NONE);
- hRegion = m_Lead3.GetRgnHandle();
- xCenter = m_Lead.GetRgnLeft() + m_Lead.GetRgnWidth() / 2;
- yCenter = m_Lead.GetRgnTop() + m_Lead.GetRgnHeight() / 2;
- m_Lead.SetRgnHandle(hRegion,
- xCenter - m_Lead3.GetBitmapWidth() / 2,
- yCenter - m_Lead3.GetBitmapHeight() / 2,
- L_RGN_SET);
- m_Lead.DeleteRgnHandle (hRegion);
- SaveBackground();
- m_Lead.Combine(
- xCenter - m_Lead3.GetBitmapWidth() / 2,
- yCenter - m_Lead3.GetBitmapHeight() / 2,
- m_Lead3.GetBitmapWidth(),
- m_Lead3.GetBitmapHeight(),
- m_Lead3.GetBitmap(),
- 0.0f,
- 0.0f,
- L_SRC_COPY);
- m_Lead.RepaintRect(
- m_Lead.GetRgnLeft() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft(),
- m_Lead.GetRgnTop() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstTop(),
- m_Lead.GetRgnWidth() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(),
- m_Lead.GetRgnHeight() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(),
- FALSE);
- m_Lead.SetRgnFrameType(RGNFRAME_STATIC);
- m_Lead3.SetBitmap(0);
- m_Lead.SetAutoRepaint(TRUE);
-
- /* update the changes back into the master document and all other views */
- UpdateMasterDocument();
-
- SetCursor(hOldCursor);
- }
-
- void CMfcdemoView::OnImageRegiontransformationsRotate()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetBackColor(RGB(255,255,255));
- LTCommDlg.SetUIFlags( DLG_IMG_ROTATE );
- nRet = LTCommDlg.GetAngle((long)this->m_hWnd); /* the method */
- if(nRet == 0)
- bContinue = TRUE;
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- OnImageRegiontransformationsRotate((long)LTCommDlg.GetAngle(),/* the property */
- LTCommDlg.GetAngleFlag() );
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnImageRegiontransformationsShear()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- int nRet;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetBackColor(RGB(255,255,255));
- LTCommDlg.SetUIFlags( DLG_IMG_SHEAR );
- nRet = LTCommDlg.GetAngle((long)this->m_hWnd); /* the method */
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- OnImageRegiontransformationsShear((long)LTCommDlg.GetAngle(),/* the property */
- LTCommDlg.GetAngleFlag() );
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
-
- void CMfcdemoView::OnImageRegiontransformationsRotate(long nAngle, BOOL fResize)
- {
- long hRegion;
- float xCenter;
- float yCenter;
-
- HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
-
- m_Lead.SetAutoRepaint(FALSE);
- m_Lead.SetFloaterVisible(FALSE);
- m_Lead.SetFloater(m_Lead.GetBitmap());
- RestoreBackground();
- m_Lead3.SetBitmap(m_Lead.GetFloater());
- m_Lead.SetFloater(0);
-
- // do the transformation on the copy
- m_Lead3.Rotate(nAngle, fResize, RGB(255, 255, 255));
-
- m_Lead.SetRgnFrameType(RGNFRAME_NONE);
- hRegion = m_Lead3.GetRgnHandle();
- xCenter = m_Lead.GetRgnLeft() + m_Lead.GetRgnWidth() / 2;
- yCenter = m_Lead.GetRgnTop() + m_Lead.GetRgnHeight() / 2;
- m_Lead.SetRgnHandle(hRegion,
- xCenter - m_Lead3.GetBitmapWidth() / 2,
- yCenter - m_Lead3.GetBitmapHeight() / 2,
- L_RGN_SET);
- m_Lead.DeleteRgnHandle (hRegion);
- SaveBackground();
- m_Lead.Combine(
- xCenter - m_Lead3.GetBitmapWidth() / 2,
- yCenter - m_Lead3.GetBitmapHeight() / 2,
- m_Lead3.GetBitmapWidth(),
- m_Lead3.GetBitmapHeight(),
- m_Lead3.GetBitmap(),
- 0.0f,
- 0.0f,
- L_SRC_COPY);
- m_Lead.RepaintRect(
- m_Lead.GetRgnLeft() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft(),
- m_Lead.GetRgnTop() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstTop(),
- m_Lead.GetRgnWidth() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(),
- m_Lead.GetRgnHeight() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(),
- FALSE);
- m_Lead.SetRgnFrameType(RGNFRAME_STATIC);
- m_Lead3.SetBitmap(0);
-
- m_Lead.SetAutoRepaint(TRUE);
- /* update the changes back into the master document and all other views */
- UpdateMasterDocument();
-
- SetCursor(hOldCursor);
- }
-
- void CMfcdemoView::OnImageRegiontransformationsShear(long nAngle, BOOL fResize)
- {
- long hRegion;
- float xCenter;
- float yCenter;
-
- HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
-
- m_Lead.SetAutoRepaint(FALSE);
- m_Lead.SetFloaterVisible(FALSE);
- m_Lead.SetFloater(m_Lead.GetBitmap());
- RestoreBackground();
- m_Lead3.SetBitmap(m_Lead.GetFloater());
- m_Lead.SetFloater(0);
-
- // do the transformation on the copy
- m_Lead3.Shear((short)nAngle, fResize, RGB(255, 255, 255));
-
- m_Lead.SetRgnFrameType(RGNFRAME_NONE);
- hRegion = m_Lead3.GetRgnHandle();
- xCenter = m_Lead.GetRgnLeft() + m_Lead.GetRgnWidth() / 2;
- yCenter = m_Lead.GetRgnTop() + m_Lead.GetRgnHeight() / 2;
- m_Lead.SetRgnHandle(hRegion,
- xCenter - m_Lead3.GetBitmapWidth() / 2,
- yCenter - m_Lead3.GetBitmapHeight() / 2,
- L_RGN_SET);
- m_Lead.DeleteRgnHandle (hRegion);
- SaveBackground();
- m_Lead.Combine(
- xCenter - m_Lead3.GetBitmapWidth() / 2,
- yCenter - m_Lead3.GetBitmapHeight() / 2,
- m_Lead3.GetBitmapWidth(),
- m_Lead3.GetBitmapHeight(),
- m_Lead3.GetBitmap(),
- 0.0f,
- 0.0f,
- L_SRC_COPY);
- m_Lead.RepaintRect(
- m_Lead.GetRgnLeft() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstLeft(),
- m_Lead.GetRgnTop() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth() + m_Lead.GetDstTop(),
- m_Lead.GetRgnWidth() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(),
- m_Lead.GetRgnHeight() * m_Lead.GetDstWidth() / m_Lead.GetSrcWidth(),
- FALSE);
- m_Lead.SetRgnFrameType(RGNFRAME_STATIC);
- m_Lead3.SetBitmap(0);
-
- m_Lead.SetAutoRepaint(TRUE);
- /* update the changes back into the master document and all other views */
- UpdateMasterDocument();
-
- SetCursor(hOldCursor);
- }
-
- void CMfcdemoView::UpdateMasterDocument()
- {
- /* merge the changes back into the master document */
- long hRegion = m_Lead.GetRgnHandle();
- GetDocLead()->SetBitmap(m_Lead.GetBitmap());
- GetDocLead()->SetRgnHandle(hRegion,0.0f,0.0f,L_RGN_SET);
- m_Lead.DeleteRgnHandle(hRegion);
- GetDocument()->UpdateAllViews(this, (LPARAM)0);
- }
-
- void CMfcdemoView::SaveBackground()
- {
- GetDocument()->m_Lead2.CreateBitmap(m_Lead.GetRgnWidth(), m_Lead.GetRgnHeight(), m_Lead.GetBitmapBits());
- if((m_Lead.GetIsGrayscale() != GRAY_NO) && (m_Lead.GetBitmapBits()>8))
- GetDocument()->m_Lead2.Grayscale(m_Lead.GetBitmapBits());
-
- GetDocument()->m_Lead2.Combine(
- 0.0f, 0.0f,
- m_Lead.GetRgnWidth(), m_Lead.GetRgnHeight(),
- m_Lead.GetBitmap(),
- m_Lead.GetRgnLeft(), m_Lead.GetRgnTop(),
- L_SRC_COPY);
- }
-
- void CMfcdemoView::RestoreBackground()
- {
- if(GetDocument()->m_Lead2.GetBitmap())
- m_Lead.Combine(
- m_Lead.GetRgnLeft(),
- m_Lead.GetRgnTop(),
- m_Lead.GetRgnWidth(),
- m_Lead.GetRgnHeight(),
- GetDocument()->m_Lead2.GetBitmap(),
- 0.0f,
- 0.0f,
- L_SRC_COPY);
- }
-
- void CMfcdemoView::OnUpdateImageRegiontransformationsCancel(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(m_Lead.GetHasRgn());
- }
-
- void CMfcdemoView::OnImageRegiontransformationsCancel()
- {
- HCURSOR hOldCursor = SetCursor(LoadCursor(NULL,IDC_WAIT));
-
- RestoreBackground();
-
- /* delete the regions from the master document and all other views */
- m_Lead.SetRgnFrameType(RGNFRAME_NONE);
- m_Lead.FreeRgn();
-
- GetDocLead()->SetBitmap(m_Lead.GetBitmap());
- GetDocLead()->FreeRgn();
- GetDocument()->UpdateAllViews(this, (LPARAM)0);
-
- SetCursor(hOldCursor);
- }
-
- void CMfcdemoView::OnColorWindowlevel()
- {
- CLeadDlg LTCommDlg;
- RECT rcWin;
- BOOL bContinue=FALSE;
- unsigned int uMid;
- int nRet;
- unsigned int uVal;
-
- ::SetRect(&rcWin, 0, 0, 1, 1);
-
- if(LTCommDlg.Create(NULL,0,rcWin,theApp.m_pMainWnd,100))
- {
- LTCommDlg.SetEnableMethodErrors(FALSE);
- GetDocLead()->GetMinMaxBits();
- GetDocLead()->GetMinMaxVal();
- LTCommDlg.SetLowBit(GetDocLead()->GetMinBit());
- LTCommDlg.SetHighBit(GetDocLead()->GetMaxBit());
-
- // now, let's set the range to somewhere in the middle
- uMid = (GetDocLead()->GetMinVal() + GetDocLead()->GetMaxVal())/2;
-
- uVal = (unsigned short)(uMid * 9 / 10);
- LTCommDlg.SetLowLevel(uVal);
- uVal = (unsigned short)(uMid + (uMid - uVal));
- LTCommDlg.SetHighLevel(uVal);
-
- //assign the bitmap for preview
- LTCommDlg.SetBitmap(GetDocLead()->GetBitmap());
- LTCommDlg.SetUIFlags(DLG_WL_SHOWPREVIEW | DLG_WL_AUTOPROCESS);
- nRet = LTCommDlg.GetWindowLevel((long)this->m_hWnd);
- if(nRet == 0)
- bContinue = TRUE;
- //release the reference
- LTCommDlg.SetBitmap(0);
- }
- if(bContinue)
- {
- OnChanged();
- GetDocLead()->ForceRepaint();
- }
- else if(nRet != ERROR_DLG_CANCELED)
- theApp.DisplayLEADError(nRet);
- }
-
- void CMfcdemoView::OnUpdateColorWindowlevel(CCmdUI* pCmdUI)
- {
- BOOL bVal;
-
- bVal = FALSE;
- if((GetDocLead()->GetBitmapBits() == 12) || (GetDocLead()->GetBitmapBits() == 16))
- bVal = TRUE;
- if(GetDocLead()->GetIsGrayscale() == GRAY_NO)
- bVal = FALSE;
- pCmdUI->Enable(bVal);
- }
-