[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:
Katayama Hirofumi MZ 2023-08-11 20:27:12 +09:00 committed by GitHub
parent 97f59fa545
commit e6c23361a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
36 changed files with 100 additions and 2 deletions

View file

@ -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);
}