mirror of
https://github.com/reactos/reactos.git
synced 2025-08-06 09:33:20 +00:00
[MSPAINT] Support converting to black and white (#5554)
- Add ImageModel::IsBlackAndWhite and ImageModel::PushBlackAndWhite helper functions. - Add CAttributesDialog::m_bBlackAndWhite. - If IDD_ATTRIBUTESRB4 is checked, then make the bitmap black and white. - Add IDS_LOSECOLOR to show message. CORE-19094
This commit is contained in:
parent
97f59fa545
commit
e6c23361a1
36 changed files with 100 additions and 2 deletions
|
@ -267,3 +267,47 @@ HBITMAP ImageModel::CopyBitmap()
|
|||
m_hbmOld = ::SelectObject(m_hDrawingDC, m_hBms[m_currInd]); // Re-select
|
||||
return ret;
|
||||
}
|
||||
|
||||
BOOL ImageModel::IsBlackAndWhite()
|
||||
{
|
||||
LONG cxWidth = GetWidth(), cyHeight = GetHeight();
|
||||
for (LONG y = 0; y < cyHeight; ++y)
|
||||
{
|
||||
for (LONG x = 0; x < cxWidth; ++x)
|
||||
{
|
||||
COLORREF rgbColor = ::GetPixel(m_hDrawingDC, x, y);
|
||||
if (rgbColor != RGB(0, 0, 0) && rgbColor != RGB(255, 255, 255))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void ImageModel::PushBlackAndWhite()
|
||||
{
|
||||
HBITMAP hNewBitmap = CopyBitmap();
|
||||
if (!hNewBitmap)
|
||||
return;
|
||||
|
||||
HDC hdc2 = ::CreateCompatibleDC(NULL);
|
||||
HGDIOBJ hbm2Old = ::SelectObject(hdc2, hNewBitmap);
|
||||
LONG cxWidth = GetWidth(), cyHeight = GetHeight();
|
||||
for (LONG y = 0; y < cyHeight; ++y)
|
||||
{
|
||||
for (LONG x = 0; x < cxWidth; ++x)
|
||||
{
|
||||
COLORREF rgbColor = ::GetPixel(m_hDrawingDC, x, y);
|
||||
BYTE Red = GetRValue(rgbColor);
|
||||
BYTE Green = GetGValue(rgbColor);
|
||||
BYTE Blue = GetBValue(rgbColor);
|
||||
if ((Red + Green + Blue) / 3 >= 255 / 2)
|
||||
::SetPixelV(hdc2, x, y, RGB(255, 255, 255)); // White
|
||||
else
|
||||
::SetPixelV(hdc2, x, y, RGB(0, 0, 0)); // Black
|
||||
}
|
||||
}
|
||||
::SelectObject(hdc2, hbm2Old);
|
||||
::DeleteDC(hdc2);
|
||||
|
||||
PushImageForUndo(hNewBitmap);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue