Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ported lab03/samples_old -> lab02/image_processing #19

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions labs/05/samples_win_32/sample01_blur_filter_wtl/AboutDlg.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// aboutdlg.cpp : implementation of the CAboutDlg class
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "resource.h"

#include "aboutdlg.h"

LRESULT CAboutDlg::OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CenterWindow(GetParent());
return TRUE;
}

LRESULT CAboutDlg::OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
EndDialog(wID);
return 0;
}
25 changes: 25 additions & 0 deletions labs/05/samples_win_32/sample01_blur_filter_wtl/AboutDlg.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// aboutdlg.h : interface of the CAboutDlg class
//
/////////////////////////////////////////////////////////////////////////////

#pragma once

class CAboutDlg : public CDialogImpl<CAboutDlg>
{
public:
enum { IDD = IDD_ABOUTBOX };

BEGIN_MSG_MAP(CAboutDlg)
MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
COMMAND_ID_HANDLER(IDOK, OnCloseCmd)
COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd)
END_MSG_MAP()

// Handler prototypes (uncomment arguments if needed):
// LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
// LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
// LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
};
21 changes: 21 additions & 0 deletions labs/05/samples_win_32/sample01_blur_filter_wtl/BlurFilter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "StdAfx.h"
#include "BlurFilter.h"

CBlurFilter::CBlurFilter(void)
{
/*
�������������� ���� ������� ��������� �������� 3*3
|1 3 1|
1/20 * |3 4 3|
|1 3 1|
*/
static const float blurMatrix[3][3] =
{
{1, 3, 1},
{3, 4, 3},
{1, 3, 1}
};
InitializeMatrix(3, 3, &blurMatrix[0][0], 1.0f / 20);
}


8 changes: 8 additions & 0 deletions labs/05/samples_win_32/sample01_blur_filter_wtl/BlurFilter.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#pragma once
#include "matrixfilter.h"

class CBlurFilter : public CMatrixFilter
{
public:
CBlurFilter(void);
};
83 changes: 83 additions & 0 deletions labs/05/samples_win_32/sample01_blur_filter_wtl/MainFrm.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// MainFrm.cpp : implmentation of the CMainFrame class
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "resource.h"

#include "aboutdlg.h"
#include "MainView.h"
#include "MainFrm.h"

BOOL CMainFrame::PreTranslateMessage(MSG* pMsg)
{
if(CFrameWindowImpl<CMainFrame>::PreTranslateMessage(pMsg))
return TRUE;

return m_view.PreTranslateMessage(pMsg);
}

BOOL CMainFrame::OnIdle()
{
UIUpdateToolBar();
return FALSE;
}

LRESULT CMainFrame::OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CreateSimpleToolBar();

m_hWndClient = m_view.Create(m_hWnd, rcDefault, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, WS_EX_CLIENTEDGE);

UIAddToolBar(m_hWndToolBar);
UISetCheck(ID_VIEW_TOOLBAR, 1);

// register object for message filtering and idle updates
CMessageLoop* pLoop = _Module.GetMessageLoop();
ATLASSERT(pLoop != NULL);
pLoop->AddMessageFilter(this);
pLoop->AddIdleHandler(this);

return 0;
}

LRESULT CMainFrame::OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled)
{
// unregister message filtering and idle updates
CMessageLoop* pLoop = _Module.GetMessageLoop();
ATLASSERT(pLoop != NULL);
pLoop->RemoveMessageFilter(this);
pLoop->RemoveIdleHandler(this);

bHandled = FALSE;
return 1;
}

LRESULT CMainFrame::OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
PostMessage(WM_CLOSE);
return 0;
}

LRESULT CMainFrame::OnFileNew(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
// TODO: add code to initialize document

return 0;
}

LRESULT CMainFrame::OnViewToolBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
BOOL bVisible = !::IsWindowVisible(m_hWndToolBar);
::ShowWindow(m_hWndToolBar, bVisible ? SW_SHOWNOACTIVATE : SW_HIDE);
UISetCheck(ID_VIEW_TOOLBAR, bVisible);
UpdateLayout();
return 0;
}

LRESULT CMainFrame::OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
{
CAboutDlg dlg;
dlg.DoModal();
return 0;
}
44 changes: 44 additions & 0 deletions labs/05/samples_win_32/sample01_blur_filter_wtl/MainFrm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// MainFrm.h : interface of the CMainFrame class
//
/////////////////////////////////////////////////////////////////////////////

#pragma once

class CMainFrame : public CFrameWindowImpl<CMainFrame>, public CUpdateUI<CMainFrame>,
public CMessageFilter, public CIdleHandler
{
public:
DECLARE_FRAME_WND_CLASS(NULL, IDR_MAINFRAME)

CMainView m_view;

virtual BOOL PreTranslateMessage(MSG* pMsg);
virtual BOOL OnIdle();

BEGIN_UPDATE_UI_MAP(CMainFrame)
UPDATE_ELEMENT(ID_VIEW_TOOLBAR, UPDUI_MENUPOPUP)
END_UPDATE_UI_MAP()

BEGIN_MSG_MAP(CMainFrame)
MESSAGE_HANDLER(WM_CREATE, OnCreate)
MESSAGE_HANDLER(WM_DESTROY, OnDestroy)
COMMAND_ID_HANDLER(ID_APP_EXIT, OnFileExit)
COMMAND_ID_HANDLER(ID_FILE_NEW, OnFileNew)
COMMAND_ID_HANDLER(ID_VIEW_TOOLBAR, OnViewToolBar)
COMMAND_ID_HANDLER(ID_APP_ABOUT, OnAppAbout)
CHAIN_MSG_MAP(CUpdateUI<CMainFrame>)
CHAIN_MSG_MAP(CFrameWindowImpl<CMainFrame>)
END_MSG_MAP()

// Handler prototypes (uncomment arguments if needed):
// LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
// LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
// LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
LRESULT OnDestroy(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& bHandled);
LRESULT OnFileExit(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnFileNew(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnViewToolBar(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
LRESULT OnAppAbout(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/);
};
49 changes: 49 additions & 0 deletions labs/05/samples_win_32/sample01_blur_filter_wtl/MainView.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// sample01_blur_filter_wtlView.cpp : implementation of the CMainView class
//
/////////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "resource.h"

#include "MainView.h"
#include "BlurFilter.h"

using namespace Gdiplus;

CMainView::CMainView()
{
Image img(L"car.jpg");
if (img.GetLastStatus() == Ok)
{
m_pSrcPicture.reset(new Bitmap(img.GetWidth(), img.GetHeight(), img.GetPixelFormat()));

Graphics g(m_pSrcPicture.get());
g.DrawImage(&img, 0, 0, img.GetWidth(), img.GetHeight());

CBlurFilter blur;

m_pDstPicture = blur.ApplyFilter(*m_pSrcPicture.get());
}
}

BOOL CMainView::PreTranslateMessage(MSG* pMsg)
{
pMsg;
return FALSE;
}

LRESULT CMainView::OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
{
CPaintDC dc(m_hWnd);

// ���� �������� � ������������ ����������� ������, �� �������� �� ����� ���� � ������
if ((m_pSrcPicture.get() != NULL) && (m_pDstPicture.get() != NULL))
{
Graphics g(dc);
g.DrawImage(m_pSrcPicture.get(), 0, 0, m_pSrcPicture->GetWidth(), m_pSrcPicture->GetHeight());

g.DrawImage(m_pDstPicture.get(), m_pSrcPicture->GetWidth(), 0, m_pDstPicture->GetWidth(), m_pDstPicture->GetHeight());
}

return 0;
}
35 changes: 35 additions & 0 deletions labs/05/samples_win_32/sample01_blur_filter_wtl/MainView.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// sample01_blur_filter_wtlView.h : interface of the CMainView class
//
/////////////////////////////////////////////////////////////////////////////

#pragma once

class CMainView : public CWindowImpl<CMainView>
{
public:
CMainView();

DECLARE_WND_CLASS(NULL)

BOOL PreTranslateMessage(MSG* pMsg);

BEGIN_MSG_MAP(CMainView)
MESSAGE_HANDLER(WM_PAINT, OnPaint)
END_MSG_MAP()

// Handler prototypes (uncomment arguments if needed):
// LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
// LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
// LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/);
private:
// �������� �����������
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Этот и другие файлы .h/.cpp следует сохранить в кодировке UTF-8 without BOM

std::auto_ptr<Gdiplus::Bitmap> m_pSrcPicture;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auto_ptr был удалён в C++17. При переходе на новый стандарт C++ код не будет компилироваться. Нужно во всех местах заменить auto_ptr на unique_ptr


// ������������ �����������
std::auto_ptr<Gdiplus::Bitmap> m_pDstPicture;



};
Loading