mirror of
https://github.com/reactos/reactos.git
synced 2025-05-29 05:58:13 +00:00
[MSPAINT] Add get/putSubImage in dib.cpp and use them
CORE-19094
This commit is contained in:
parent
a65ebc8a71
commit
764e5505a7
5 changed files with 49 additions and 29 deletions
|
@ -406,6 +406,39 @@ HBITMAP SkewDIB(HDC hDC1, HBITMAP hbm, INT nDegree, BOOL bVertical, BOOL bMono)
|
||||||
return hbmNew;
|
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
|
struct BITMAPINFODX : BITMAPINFO
|
||||||
{
|
{
|
||||||
RGBQUAD bmiColorsAdditional[256 - 1];
|
RGBQUAD bmiColorsAdditional[256 - 1];
|
||||||
|
|
|
@ -44,3 +44,5 @@ float PpcmFromDpi(float dpi);
|
||||||
HGLOBAL BitmapToClipboardDIB(HBITMAP hBitmap);
|
HGLOBAL BitmapToClipboardDIB(HBITMAP hBitmap);
|
||||||
HBITMAP BitmapFromClipboardDIB(HGLOBAL hGlobal);
|
HBITMAP BitmapFromClipboardDIB(HGLOBAL hGlobal);
|
||||||
HBITMAP BitmapFromHEMF(HENHMETAFILE hEMF);
|
HBITMAP BitmapFromHEMF(HENHMETAFILE hEMF);
|
||||||
|
HBITMAP getSubImage(HBITMAP hbmWhole, const RECT& rcPartial);
|
||||||
|
void putSubImage(HBITMAP hbmWhole, const RECT& rcPartial, HBITMAP hbmPart);
|
||||||
|
|
|
@ -44,7 +44,7 @@ LRESULT CFullscreenWindow::OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL
|
||||||
INT cyDest = imageModel.GetHeight();
|
INT cyDest = imageModel.GetHeight();
|
||||||
INT xDest = (rcWnd.right - rcWnd.left - cxDest) / 2;
|
INT xDest = (rcWnd.right - rcWnd.left - cxDest) / 2;
|
||||||
INT yDest = (rcWnd.bottom - rcWnd.top - cyDest) / 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);
|
EndPaint(&ps);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -152,33 +152,22 @@ void ImageModel::Crop(int nWidth, int nHeight, int nOffsetX, int nOffsetY)
|
||||||
if (nHeight <= 0)
|
if (nHeight <= 0)
|
||||||
nHeight = 1;
|
nHeight = 1;
|
||||||
|
|
||||||
// Create an HBITMAP
|
// Create a white HBITMAP
|
||||||
HBITMAP hbmCropped = CreateDIBWithProperties(nWidth, nHeight);
|
HBITMAP hbmNew = CreateColorDIB(nWidth, nHeight, RGB(255, 255, 255));
|
||||||
if (!hbmCropped)
|
if (!hbmNew)
|
||||||
{
|
{
|
||||||
ShowOutOfMemory();
|
ShowOutOfMemory();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Select the HBITMAP by memory DC
|
// Put the master image as a sub-image
|
||||||
HDC hdcMem = ::CreateCompatibleDC(m_hDrawingDC);
|
RECT rcPart = { -nOffsetX, -nOffsetY, GetWidth() - nOffsetX, GetHeight() - nOffsetY };
|
||||||
HGDIOBJ hbmOld = ::SelectObject(hdcMem, hbmCropped);
|
HBITMAP hbmOld = imageModel.LockBitmap();
|
||||||
|
putSubImage(hbmNew, rcPart, hbmOld);
|
||||||
// Fill background of the HBITMAP
|
imageModel.UnlockBitmap(hbmOld);
|
||||||
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);
|
|
||||||
|
|
||||||
// Push it
|
// Push it
|
||||||
PushImageForUndo(hbmCropped);
|
PushImageForUndo(hbmNew);
|
||||||
|
|
||||||
NotifyImageChanged();
|
NotifyImageChanged();
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,14 +157,10 @@ HBITMAP SelectionModel::GetSelectionContents()
|
||||||
if (m_hbmColor)
|
if (m_hbmColor)
|
||||||
return CopyDIBImage(m_hbmColor, m_rc.Width(), m_rc.Height());
|
return CopyDIBImage(m_hbmColor, m_rc.Width(), m_rc.Height());
|
||||||
|
|
||||||
HDC hMemDC = ::CreateCompatibleDC(NULL);
|
HBITMAP hbmWhole = imageModel.LockBitmap();
|
||||||
HBITMAP hBitmap = CreateColorDIB(m_rc.Width(), m_rc.Height(), RGB(255, 255, 255));
|
HBITMAP hbmPart = getSubImage(hbmWhole, m_rc);
|
||||||
HGDIOBJ hbmOld = ::SelectObject(hMemDC, hBitmap);
|
imageModel.UnlockBitmap(hbmWhole);
|
||||||
::BitBlt(hMemDC, 0, 0, m_rc.Width(), m_rc.Height(), imageModel.GetDC(), m_rc.left, m_rc.top, SRCCOPY);
|
return hbmPart;
|
||||||
::SelectObject(hMemDC, hbmOld);
|
|
||||||
::DeleteDC(hMemDC);
|
|
||||||
|
|
||||||
return hBitmap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL SelectionModel::IsLanded() const
|
BOOL SelectionModel::IsLanded() const
|
||||||
|
|
Loading…
Reference in a new issue