https://git.reactos.org/?p=reactos.git;a=commitdiff;h=764e5505a7d4fc36df8c6…
commit 764e5505a7d4fc36df8c631037ca8eb9ee67294a
Author: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Sat Nov 18 14:25:19 2023 +0900
Commit: Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
CommitDate: Sat Nov 18 14:25:19 2023 +0900
[MSPAINT] Add get/putSubImage in dib.cpp and use them
CORE-19094
---
base/applications/mspaint/dib.cpp | 33 ++++++++++++++++++++++++++++
base/applications/mspaint/dib.h | 2 ++
base/applications/mspaint/fullscreen.cpp | 2 +-
base/applications/mspaint/history.cpp | 29 ++++++++----------------
base/applications/mspaint/selectionmodel.cpp | 12 ++++------
5 files changed, 49 insertions(+), 29 deletions(-)
diff --git a/base/applications/mspaint/dib.cpp b/base/applications/mspaint/dib.cpp
index d6ea224de79..6ff4f200a5b 100644
--- a/base/applications/mspaint/dib.cpp
+++ b/base/applications/mspaint/dib.cpp
@@ -406,6 +406,39 @@ HBITMAP SkewDIB(HDC hDC1, HBITMAP hbm, INT nDegree, BOOL bVertical,
BOOL bMono)
return hbmNew;
}
+HBITMAP getSubImage(HBITMAP hbmWhole, const RECT& rcPartial)
+{
+ CRect rc = rcPartial;
+ HBITMAP hbmPart = CreateDIBWithProperties(rc.Width(), rc.Height());
+ if (!hbmPart)
+ return NULL;
+
+ HDC hDC1 = ::CreateCompatibleDC(NULL);
+ HDC hDC2 = ::CreateCompatibleDC(NULL);
+ HGDIOBJ hbm1Old = ::SelectObject(hDC1, hbmWhole);
+ HGDIOBJ hbm2Old = ::SelectObject(hDC2, hbmPart);
+ ::BitBlt(hDC2, 0, 0, rc.Width(), rc.Height(), hDC1, rc.left, rc.top, SRCCOPY);
+ ::SelectObject(hDC1, hbm1Old);
+ ::SelectObject(hDC2, hbm2Old);
+ ::DeleteDC(hDC1);
+ ::DeleteDC(hDC2);
+ return hbmPart;
+}
+
+void putSubImage(HBITMAP hbmWhole, const RECT& rcPartial, HBITMAP hbmPart)
+{
+ CRect rc = rcPartial;
+ HDC hDC1 = ::CreateCompatibleDC(NULL);
+ HDC hDC2 = ::CreateCompatibleDC(NULL);
+ HGDIOBJ hbm1Old = ::SelectObject(hDC1, hbmWhole);
+ HGDIOBJ hbm2Old = ::SelectObject(hDC2, hbmPart);
+ ::BitBlt(hDC1, rc.left, rc.top, rc.Width(), rc.Height(), hDC2, 0, 0, SRCCOPY);
+ ::SelectObject(hDC1, hbm1Old);
+ ::SelectObject(hDC2, hbm2Old);
+ ::DeleteDC(hDC1);
+ ::DeleteDC(hDC2);
+}
+
struct BITMAPINFODX : BITMAPINFO
{
RGBQUAD bmiColorsAdditional[256 - 1];
diff --git a/base/applications/mspaint/dib.h b/base/applications/mspaint/dib.h
index bb9d933a14a..9d5ab00c47c 100644
--- a/base/applications/mspaint/dib.h
+++ b/base/applications/mspaint/dib.h
@@ -44,3 +44,5 @@ float PpcmFromDpi(float dpi);
HGLOBAL BitmapToClipboardDIB(HBITMAP hBitmap);
HBITMAP BitmapFromClipboardDIB(HGLOBAL hGlobal);
HBITMAP BitmapFromHEMF(HENHMETAFILE hEMF);
+HBITMAP getSubImage(HBITMAP hbmWhole, const RECT& rcPartial);
+void putSubImage(HBITMAP hbmWhole, const RECT& rcPartial, HBITMAP hbmPart);
diff --git a/base/applications/mspaint/fullscreen.cpp
b/base/applications/mspaint/fullscreen.cpp
index 8443cedeb6c..d7ab33b0ca5 100644
--- a/base/applications/mspaint/fullscreen.cpp
+++ b/base/applications/mspaint/fullscreen.cpp
@@ -44,7 +44,7 @@ LRESULT CFullscreenWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM
lParam, BOOL
INT cyDest = imageModel.GetHeight();
INT xDest = (rcWnd.right - rcWnd.left - cxDest) / 2;
INT yDest = (rcWnd.bottom - rcWnd.top - cyDest) / 2;
- BitBlt(hDC, xDest, yDest, cxDest, cyDest, imageModel.GetDC(), 0, 0, SRCCOPY);
+ ::BitBlt(hDC, xDest, yDest, cxDest, cyDest, imageModel.GetDC(), 0, 0, SRCCOPY);
EndPaint(&ps);
return 0;
}
diff --git a/base/applications/mspaint/history.cpp
b/base/applications/mspaint/history.cpp
index f56981a2bb6..c0f347d0aa9 100644
--- a/base/applications/mspaint/history.cpp
+++ b/base/applications/mspaint/history.cpp
@@ -152,33 +152,22 @@ void ImageModel::Crop(int nWidth, int nHeight, int nOffsetX, int
nOffsetY)
if (nHeight <= 0)
nHeight = 1;
- // Create an HBITMAP
- HBITMAP hbmCropped = CreateDIBWithProperties(nWidth, nHeight);
- if (!hbmCropped)
+ // Create a white HBITMAP
+ HBITMAP hbmNew = CreateColorDIB(nWidth, nHeight, RGB(255, 255, 255));
+ if (!hbmNew)
{
ShowOutOfMemory();
return;
}
- // Select the HBITMAP by memory DC
- HDC hdcMem = ::CreateCompatibleDC(m_hDrawingDC);
- HGDIOBJ hbmOld = ::SelectObject(hdcMem, hbmCropped);
-
- // Fill background of the HBITMAP
- RECT rcBack = { 0, 0, nWidth, nHeight };
- HBRUSH hbrBack = ::CreateSolidBrush(paletteModel.GetBgColor());
- ::FillRect(hdcMem, &rcBack, hbrBack);
- ::DeleteObject(hbrBack);
-
- // Copy the old content
- ::BitBlt(hdcMem, -nOffsetX, -nOffsetY, GetWidth(), GetHeight(), m_hDrawingDC, 0, 0,
SRCCOPY);
-
- // Clean up
- ::SelectObject(hdcMem, hbmOld);
- ::DeleteDC(hdcMem);
+ // Put the master image as a sub-image
+ RECT rcPart = { -nOffsetX, -nOffsetY, GetWidth() - nOffsetX, GetHeight() - nOffsetY
};
+ HBITMAP hbmOld = imageModel.LockBitmap();
+ putSubImage(hbmNew, rcPart, hbmOld);
+ imageModel.UnlockBitmap(hbmOld);
// Push it
- PushImageForUndo(hbmCropped);
+ PushImageForUndo(hbmNew);
NotifyImageChanged();
}
diff --git a/base/applications/mspaint/selectionmodel.cpp
b/base/applications/mspaint/selectionmodel.cpp
index a9744ba2d61..76333de6f45 100644
--- a/base/applications/mspaint/selectionmodel.cpp
+++ b/base/applications/mspaint/selectionmodel.cpp
@@ -157,14 +157,10 @@ HBITMAP SelectionModel::GetSelectionContents()
if (m_hbmColor)
return CopyDIBImage(m_hbmColor, m_rc.Width(), m_rc.Height());
- HDC hMemDC = ::CreateCompatibleDC(NULL);
- HBITMAP hBitmap = CreateColorDIB(m_rc.Width(), m_rc.Height(), RGB(255, 255, 255));
- HGDIOBJ hbmOld = ::SelectObject(hMemDC, hBitmap);
- ::BitBlt(hMemDC, 0, 0, m_rc.Width(), m_rc.Height(), imageModel.GetDC(), m_rc.left,
m_rc.top, SRCCOPY);
- ::SelectObject(hMemDC, hbmOld);
- ::DeleteDC(hMemDC);
-
- return hBitmap;
+ HBITMAP hbmWhole = imageModel.LockBitmap();
+ HBITMAP hbmPart = getSubImage(hbmWhole, m_rc);
+ imageModel.UnlockBitmap(hbmWhole);
+ return hbmPart;
}
BOOL SelectionModel::IsLanded() const