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 all commits
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
51 changes: 51 additions & 0 deletions labs/02/image_processing/image_processing.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.4.33213.308
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sample01_blur_filter_wtl", "sample01_blur_filter_wtl\sample01_blur_filter_wtl.vcxproj", "{23639512-0151-4FBD-A471-AB747C88AAB4}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sample02_blur_filter_wtl_optimized", "sample02_blur_filter_wtl_optimized\sample02_blur_filter_wtl_optimized.vcxproj", "{F3CF3FAE-8AFE-4C9B-8095-1D1C077FE9F5}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "sample03_blur_filter_wtl_optimized_openmp", "sample03_blur_filter_wtl_optimized_openmp\sample02_blur_filter_wtl_optimized_openmp.vcxproj", "{DC741724-46C5-406E-BFB3-71116621C9BC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
Debug|x64 = Debug|x64
Release|Win32 = Release|Win32
Release|x64 = Release|x64
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{23639512-0151-4FBD-A471-AB747C88AAB4}.Debug|Win32.ActiveCfg = Debug|Win32
{23639512-0151-4FBD-A471-AB747C88AAB4}.Debug|Win32.Build.0 = Debug|Win32
{23639512-0151-4FBD-A471-AB747C88AAB4}.Debug|x64.ActiveCfg = Debug|x64
{23639512-0151-4FBD-A471-AB747C88AAB4}.Debug|x64.Build.0 = Debug|x64
{23639512-0151-4FBD-A471-AB747C88AAB4}.Release|Win32.ActiveCfg = Release|Win32
{23639512-0151-4FBD-A471-AB747C88AAB4}.Release|Win32.Build.0 = Release|Win32
{23639512-0151-4FBD-A471-AB747C88AAB4}.Release|x64.ActiveCfg = Release|x64
{23639512-0151-4FBD-A471-AB747C88AAB4}.Release|x64.Build.0 = Release|x64
{F3CF3FAE-8AFE-4C9B-8095-1D1C077FE9F5}.Debug|Win32.ActiveCfg = Debug|Win32
{F3CF3FAE-8AFE-4C9B-8095-1D1C077FE9F5}.Debug|Win32.Build.0 = Debug|Win32
{F3CF3FAE-8AFE-4C9B-8095-1D1C077FE9F5}.Debug|x64.ActiveCfg = Debug|x64
{F3CF3FAE-8AFE-4C9B-8095-1D1C077FE9F5}.Debug|x64.Build.0 = Debug|x64
{F3CF3FAE-8AFE-4C9B-8095-1D1C077FE9F5}.Release|Win32.ActiveCfg = Release|Win32
{F3CF3FAE-8AFE-4C9B-8095-1D1C077FE9F5}.Release|Win32.Build.0 = Release|Win32
{F3CF3FAE-8AFE-4C9B-8095-1D1C077FE9F5}.Release|x64.ActiveCfg = Release|x64
{F3CF3FAE-8AFE-4C9B-8095-1D1C077FE9F5}.Release|x64.Build.0 = Release|x64
{DC741724-46C5-406E-BFB3-71116621C9BC}.Debug|Win32.ActiveCfg = Debug|Win32
{DC741724-46C5-406E-BFB3-71116621C9BC}.Debug|Win32.Build.0 = Debug|Win32
{DC741724-46C5-406E-BFB3-71116621C9BC}.Debug|x64.ActiveCfg = Debug|x64
{DC741724-46C5-406E-BFB3-71116621C9BC}.Debug|x64.Build.0 = Debug|x64
{DC741724-46C5-406E-BFB3-71116621C9BC}.Release|Win32.ActiveCfg = Release|Win32
{DC741724-46C5-406E-BFB3-71116621C9BC}.Release|Win32.Build.0 = Release|Win32
{DC741724-46C5-406E-BFB3-71116621C9BC}.Release|x64.ActiveCfg = Release|x64
{DC741724-46C5-406E-BFB3-71116621C9BC}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7573369F-28DC-40B4-B5EC-1403C90BB376}
EndGlobalSection
EndGlobal
20 changes: 20 additions & 0 deletions labs/02/image_processing/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/02/image_processing/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/02/image_processing/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);
}


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/02/image_processing/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/02/image_processing/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/02/image_processing/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/02/image_processing/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:
// Исходное изображение
std::unique_ptr<Gdiplus::Bitmap> m_pSrcPicture;

// Обработанное изображение
std::unique_ptr<Gdiplus::Bitmap> m_pDstPicture;



};
Loading