https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b5335fb90b9ca59aa015c…
commit b5335fb90b9ca59aa015c5de71df7d305ea1d441
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Mon Jun 19 14:11:16 2023 +0900
Commit: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
CommitDate: Mon Jun 19 14:11:16 2023 +0900
[MSPAINT] Simplify SelectionModel::StretchSkew
...and omit cloning HBITMAP in SelectionModel::InsertFromHBITMAP. CORE-18867
---
base/applications/mspaint/selectionmodel.cpp | 54 ++++++++++++++--------------
base/applications/mspaint/winproc.cpp | 1 -
2 files changed, 27 insertions(+), 28 deletions(-)
diff --git a/base/applications/mspaint/selectionmodel.cpp
b/base/applications/mspaint/selectionmodel.cpp
index e14adddc0c2..13546bc790c 100644
--- a/base/applications/mspaint/selectionmodel.cpp
+++ b/base/applications/mspaint/selectionmodel.cpp
@@ -212,7 +212,7 @@ void SelectionModel::Landing()
void SelectionModel::InsertFromHBITMAP(HBITMAP hbmColor, INT x, INT y, HBITMAP hbmMask)
{
::DeleteObject(m_hbmColor);
- m_hbmColor = CopyDIBImage(hbmColor);
+ m_hbmColor = hbmColor;
m_rc.left = x;
m_rc.top = y;
@@ -222,7 +222,7 @@ void SelectionModel::InsertFromHBITMAP(HBITMAP hbmColor, INT x, INT y,
HBITMAP h
if (hbmMask)
{
::DeleteObject(m_hbmMask);
- m_hbmMask = CopyMonoImage(hbmMask);
+ m_hbmMask = hbmMask;
}
else
{
@@ -332,6 +332,14 @@ void SelectionModel::RotateNTimes90Degrees(int iN)
NotifyContentChanged();
}
+static void AttachHBITMAP(HBITMAP *phbm, HBITMAP hbmNew)
+{
+ if (hbmNew == NULL)
+ return;
+ ::DeleteObject(*phbm);
+ *phbm = hbmNew;
+}
+
void SelectionModel::StretchSkew(int nStretchPercentX, int nStretchPercentY, int
nSkewDegX, int nSkewDegY)
{
if (nStretchPercentX == 100 && nStretchPercentY == 100 && nSkewDegX
== 0 && nSkewDegY == 0)
@@ -339,54 +347,46 @@ void SelectionModel::StretchSkew(int nStretchPercentX, int
nStretchPercentY, int
TakeOff();
- INT oldWidth = m_rc.Width();
- INT oldHeight = m_rc.Height();
+ INT oldWidth = m_rc.Width(), oldHeight = m_rc.Height();
INT newWidth = oldWidth * nStretchPercentX / 100;
INT newHeight = oldHeight * nStretchPercentY / 100;
- HBITMAP hbmColor, hbmMask;
- HGDIOBJ hbmOld;
+ HBITMAP hbmColor = m_hbmColor, hbmMask = m_hbmMask;
- if (m_hbmMask == NULL)
- m_hbmMask = CreateMonoBitmap(newWidth, newHeight, TRUE);
+ if (hbmMask == NULL)
+ hbmMask = CreateMonoBitmap(oldWidth, oldHeight, TRUE);
if (oldWidth != newWidth || oldHeight != newHeight)
{
- hbmColor = CopyDIBImage(m_hbmColor, newWidth, newHeight);
- hbmMask = CopyMonoImage(m_hbmMask, newWidth, newHeight);
- InsertFromHBITMAP(hbmColor, m_rc.left, m_rc.top, hbmMask);
- ::DeleteObject(hbmColor);
- ::DeleteObject(hbmMask);
+ AttachHBITMAP(&hbmColor, CopyDIBImage(hbmColor, newWidth, newHeight));
+ AttachHBITMAP(&hbmMask, CopyMonoImage(hbmMask, newWidth, newHeight));
}
+ HGDIOBJ hbmOld;
HDC hDC = ::CreateCompatibleDC(NULL);
if (nSkewDegX)
{
- hbmOld = ::SelectObject(hDC, m_hbmColor);
- hbmColor = SkewDIB(hDC, m_hbmColor, nSkewDegX, FALSE);
- ::SelectObject(hDC, m_hbmMask);
- hbmMask = SkewDIB(hDC, m_hbmMask, nSkewDegX, FALSE, TRUE);
+ hbmOld = ::SelectObject(hDC, hbmColor);
+ AttachHBITMAP(&hbmColor, SkewDIB(hDC, hbmColor, nSkewDegX, FALSE));
+ ::SelectObject(hDC, hbmMask);
+ AttachHBITMAP(&hbmMask, SkewDIB(hDC, hbmMask, nSkewDegX, FALSE, TRUE));
::SelectObject(hDC, hbmOld);
- InsertFromHBITMAP(hbmColor, m_rc.left, m_rc.top, hbmMask);
- ::DeleteObject(hbmColor);
- ::DeleteObject(hbmMask);
}
if (nSkewDegY)
{
- hbmOld = ::SelectObject(hDC, m_hbmColor);
- hbmColor = SkewDIB(hDC, m_hbmColor, nSkewDegY, TRUE);
- ::SelectObject(hDC, m_hbmMask);
- hbmMask = SkewDIB(hDC, m_hbmMask, nSkewDegY, TRUE, TRUE);
+ hbmOld = ::SelectObject(hDC, hbmColor);
+ AttachHBITMAP(&hbmColor, SkewDIB(hDC, hbmColor, nSkewDegY, TRUE));
+ ::SelectObject(hDC, hbmMask);
+ AttachHBITMAP(&hbmMask, SkewDIB(hDC, hbmMask, nSkewDegY, TRUE, TRUE));
::SelectObject(hDC, hbmOld);
- InsertFromHBITMAP(hbmColor, m_rc.left, m_rc.top, hbmMask);
- ::DeleteObject(hbmColor);
- ::DeleteObject(hbmMask);
}
::DeleteDC(hDC);
+ InsertFromHBITMAP(hbmColor, m_rc.left, m_rc.top, hbmMask);
+
m_bShow = TRUE;
NotifyContentChanged();
}
diff --git a/base/applications/mspaint/winproc.cpp
b/base/applications/mspaint/winproc.cpp
index 7a22b153794..3ac4b5b60d8 100644
--- a/base/applications/mspaint/winproc.cpp
+++ b/base/applications/mspaint/winproc.cpp
@@ -844,7 +844,6 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL& bH
if (hbmNew)
{
InsertSelectionFromHBITMAP(hbmNew, m_hWnd);
- DeleteObject(hbmNew);
}
}
break;