Skip to content

Commit e6c2336

Browse files
authored
[MSPAINT] Support converting to black and white (reactos#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
1 parent 97f59fa commit e6c2336

36 files changed

+100
-2
lines changed

base/applications/mspaint/dialogs.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,14 @@ LRESULT CAttributesDialog::OnInitDialog(UINT nMsg, WPARAM wParam, LPARAM lParam,
103103
newHeight = imageModel.GetHeight();
104104

105105
CheckDlgButton(IDD_ATTRIBUTESRB3, BST_CHECKED);
106-
CheckDlgButton(IDD_ATTRIBUTESRB5, BST_CHECKED);
107106
SetDlgItemInt(IDD_ATTRIBUTESEDIT1, newWidth, FALSE);
108107
SetDlgItemInt(IDD_ATTRIBUTESEDIT2, newHeight, FALSE);
109108

109+
if (imageModel.IsBlackAndWhite())
110+
CheckRadioButton(IDD_ATTRIBUTESRB4, IDD_ATTRIBUTESRB5, IDD_ATTRIBUTESRB4);
111+
else
112+
CheckRadioButton(IDD_ATTRIBUTESRB4, IDD_ATTRIBUTESRB5, IDD_ATTRIBUTESRB5);
113+
110114
if (g_isAFile)
111115
{
112116
TCHAR date[100];
@@ -142,6 +146,7 @@ LRESULT CAttributesDialog::OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL
142146

143147
LRESULT CAttributesDialog::OnOk(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
144148
{
149+
m_bBlackAndWhite = (IsDlgButtonChecked(IDD_ATTRIBUTESRB4) == BST_CHECKED);
145150
EndDialog(1);
146151
return 0;
147152
}

base/applications/mspaint/dialogs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ class CAttributesDialog : public CDialogImpl<CAttributesDialog>
6464
public:
6565
int newWidth;
6666
int newHeight;
67+
BOOL m_bBlackAndWhite;
6768
};
6869

6970
class CStretchSkewDialog : public CDialogImpl<CStretchSkewDialog>

base/applications/mspaint/history.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,3 +267,47 @@ HBITMAP ImageModel::CopyBitmap()
267267
m_hbmOld = ::SelectObject(m_hDrawingDC, m_hBms[m_currInd]); // Re-select
268268
return ret;
269269
}
270+
271+
BOOL ImageModel::IsBlackAndWhite()
272+
{
273+
LONG cxWidth = GetWidth(), cyHeight = GetHeight();
274+
for (LONG y = 0; y < cyHeight; ++y)
275+
{
276+
for (LONG x = 0; x < cxWidth; ++x)
277+
{
278+
COLORREF rgbColor = ::GetPixel(m_hDrawingDC, x, y);
279+
if (rgbColor != RGB(0, 0, 0) && rgbColor != RGB(255, 255, 255))
280+
return FALSE;
281+
}
282+
}
283+
return TRUE;
284+
}
285+
286+
void ImageModel::PushBlackAndWhite()
287+
{
288+
HBITMAP hNewBitmap = CopyBitmap();
289+
if (!hNewBitmap)
290+
return;
291+
292+
HDC hdc2 = ::CreateCompatibleDC(NULL);
293+
HGDIOBJ hbm2Old = ::SelectObject(hdc2, hNewBitmap);
294+
LONG cxWidth = GetWidth(), cyHeight = GetHeight();
295+
for (LONG y = 0; y < cyHeight; ++y)
296+
{
297+
for (LONG x = 0; x < cxWidth; ++x)
298+
{
299+
COLORREF rgbColor = ::GetPixel(m_hDrawingDC, x, y);
300+
BYTE Red = GetRValue(rgbColor);
301+
BYTE Green = GetGValue(rgbColor);
302+
BYTE Blue = GetBValue(rgbColor);
303+
if ((Red + Green + Blue) / 3 >= 255 / 2)
304+
::SetPixelV(hdc2, x, y, RGB(255, 255, 255)); // White
305+
else
306+
::SetPixelV(hdc2, x, y, RGB(0, 0, 0)); // Black
307+
}
308+
}
309+
::SelectObject(hdc2, hbm2Old);
310+
::DeleteDC(hdc2);
311+
312+
PushImageForUndo(hNewBitmap);
313+
}

base/applications/mspaint/history.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ class ImageModel
3737
void RotateNTimes90Degrees(int iN);
3838
void Clamp(POINT& pt) const;
3939
void NotifyImageChanged();
40+
BOOL IsBlackAndWhite();
41+
void PushBlackAndWhite();
4042

4143
protected:
4244
HDC m_hDrawingDC; // The device context for this class

base/applications/mspaint/lang/bg-BG.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,5 @@ BEGIN
264264
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
265265
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
266266
IDS_CANTSENDMAIL "Failed to send a mail."
267+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
267268
END

base/applications/mspaint/lang/cs-CZ.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,5 @@ BEGIN
264264
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
265265
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
266266
IDS_CANTSENDMAIL "Failed to send a mail."
267+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
267268
END

base/applications/mspaint/lang/de-DE.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,5 @@ BEGIN
263263
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
264264
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
265265
IDS_CANTSENDMAIL "Failed to send a mail."
266+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
266267
END

base/applications/mspaint/lang/en-GB.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,5 @@ BEGIN
263263
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
264264
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
265265
IDS_CANTSENDMAIL "Failed to send a mail."
266+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
266267
END

base/applications/mspaint/lang/en-US.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,5 @@ BEGIN
264264
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
265265
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
266266
IDS_CANTSENDMAIL "Failed to send a mail."
267+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
267268
END

base/applications/mspaint/lang/es-ES.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,5 @@ BEGIN
266266
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
267267
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
268268
IDS_CANTSENDMAIL "Failed to send a mail."
269+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
269270
END

base/applications/mspaint/lang/et-EE.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,5 @@ BEGIN
263263
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
264264
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
265265
IDS_CANTSENDMAIL "Failed to send a mail."
266+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
266267
END

base/applications/mspaint/lang/eu-ES.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,5 @@ BEGIN
264264
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
265265
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
266266
IDS_CANTSENDMAIL "Failed to send a mail."
267+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
267268
END

base/applications/mspaint/lang/fr-FR.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,5 @@ BEGIN
264264
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
265265
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
266266
IDS_CANTSENDMAIL "Failed to send a mail."
267+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
267268
END

base/applications/mspaint/lang/he-IL.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,5 @@ BEGIN
266266
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
267267
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
268268
IDS_CANTSENDMAIL "Failed to send a mail."
269+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
269270
END

base/applications/mspaint/lang/hu-HU.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,5 @@ BEGIN
264264
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
265265
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
266266
IDS_CANTSENDMAIL "Failed to send a mail."
267+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
267268
END

base/applications/mspaint/lang/id-ID.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,5 @@ BEGIN
263263
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
264264
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
265265
IDS_CANTSENDMAIL "Failed to send a mail."
266+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
266267
END

base/applications/mspaint/lang/it-IT.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,5 @@ BEGIN
264264
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
265265
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
266266
IDS_CANTSENDMAIL "Failed to send a mail."
267+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
267268
END

base/applications/mspaint/lang/ja-JP.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,5 @@ BEGIN
265265
IDS_CANTPASTE "クリップボードからの貼り付けに失敗しました。データ形式が間違っているか、未対応です。"
266266
IDS_SAVEERROR "次のファイルとして画像を保存するのに失敗しました:\n\n%s"
267267
IDS_CANTSENDMAIL "Failed to send a mail."
268+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
268269
END

base/applications/mspaint/lang/nl-NL.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,5 @@ BEGIN
263263
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
264264
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
265265
IDS_CANTSENDMAIL "Failed to send a mail."
266+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
266267
END

base/applications/mspaint/lang/no-NO.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,5 @@ BEGIN
263263
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
264264
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
265265
IDS_CANTSENDMAIL "Failed to send a mail."
266+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
266267
END

base/applications/mspaint/lang/pl-PL.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,5 @@ BEGIN
266266
IDS_CANTPASTE "Nie można wkleić ze schowka. Format danych jest nieprawidłowy lub nieobsługiwany."
267267
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
268268
IDS_CANTSENDMAIL "Failed to send a mail."
269+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
269270
END

base/applications/mspaint/lang/pt-BR.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,5 @@ BEGIN
264264
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
265265
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
266266
IDS_CANTSENDMAIL "Failed to send a mail."
267+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
267268
END

base/applications/mspaint/lang/pt-PT.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,5 @@ BEGIN
264264
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
265265
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
266266
IDS_CANTSENDMAIL "Failed to send a mail."
267+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
267268
END

base/applications/mspaint/lang/ro-RO.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,5 @@ BEGIN
265265
IDS_CANTPASTE "Nu a putut fi lipit din clipboard. Formatul de date este fie incorect, fie nesuportat."
266266
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
267267
IDS_CANTSENDMAIL "Failed to send a mail."
268+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
268269
END

base/applications/mspaint/lang/ru-RU.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,4 +267,5 @@ BEGIN
267267
IDS_CANTPASTE "Не удалось вставить из буфера обмена. Формат данных либо некорректный, либо не поддерживается."
268268
IDS_SAVEERROR "Не удалось сохранить точечный рисунок в файл:\n\n%s"
269269
IDS_CANTSENDMAIL "Failed to send a mail."
270+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
270271
END

base/applications/mspaint/lang/sk-SK.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,5 @@ BEGIN
263263
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
264264
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
265265
IDS_CANTSENDMAIL "Failed to send a mail."
266+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
266267
END

base/applications/mspaint/lang/sq-AL.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,5 @@ BEGIN
263263
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
264264
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
265265
IDS_CANTSENDMAIL "Failed to send a mail."
266+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
266267
END

base/applications/mspaint/lang/sv-SE.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,5 @@ BEGIN
264264
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
265265
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
266266
IDS_CANTSENDMAIL "Failed to send a mail."
267+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
267268
END

base/applications/mspaint/lang/tr-TR.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,5 @@ BEGIN
264264
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
265265
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
266266
IDS_CANTSENDMAIL "Failed to send a mail."
267+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
267268
END

base/applications/mspaint/lang/uk-UA.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,5 @@ BEGIN
265265
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
266266
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
267267
IDS_CANTSENDMAIL "Failed to send a mail."
268+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
268269
END

base/applications/mspaint/lang/vi-VN.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,5 @@ BEGIN
263263
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
264264
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
265265
IDS_CANTSENDMAIL "Failed to send a mail."
266+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
266267
END

base/applications/mspaint/lang/zh-CN.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,5 @@ BEGIN
266266
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
267267
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
268268
IDS_CANTSENDMAIL "Failed to send a mail."
269+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
269270
END

base/applications/mspaint/lang/zh-HK.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,5 @@ BEGIN
264264
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
265265
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
266266
IDS_CANTSENDMAIL "Failed to send a mail."
267+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
267268
END

base/applications/mspaint/lang/zh-TW.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -264,4 +264,5 @@ BEGIN
264264
IDS_CANTPASTE "Failed to paste from the clipboard. The data format is either incorrect or not supported."
265265
IDS_SAVEERROR "Failed to save the bitmap to file:\n\n%s"
266266
IDS_CANTSENDMAIL "Failed to send a mail."
267+
IDS_LOSECOLOR "The color information will be lost in this operation. Are you sure to proceed?"
267268
END

base/applications/mspaint/resource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,4 @@
222222
#define IDS_CANTPASTE 940
223223
#define IDS_SAVEERROR 941
224224
#define IDS_CANTSENDMAIL 942
225+
#define IDS_LOSECOLOR 943

base/applications/mspaint/winproc.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,22 @@ LRESULT CMainWindow::OnCommand(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bH
949949
{
950950
if (attributesDialog.DoModal(mainWindow.m_hWnd))
951951
{
952-
imageModel.Crop(attributesDialog.newWidth, attributesDialog.newHeight, 0, 0);
952+
if (attributesDialog.m_bBlackAndWhite && !imageModel.IsBlackAndWhite())
953+
{
954+
CString strText(MAKEINTRESOURCE(IDS_LOSECOLOR));
955+
CString strTitle(MAKEINTRESOURCE(IDS_PROGRAMNAME));
956+
INT id = MessageBox(strText, strTitle, MB_ICONINFORMATION | MB_YESNOCANCEL);
957+
if (id != IDYES)
958+
break;
959+
960+
imageModel.PushBlackAndWhite();
961+
}
962+
963+
if (imageModel.GetWidth() != attributesDialog.newWidth ||
964+
imageModel.GetHeight() != attributesDialog.newHeight)
965+
{
966+
imageModel.Crop(attributesDialog.newWidth, attributesDialog.newHeight);
967+
}
953968
}
954969
break;
955970
}

0 commit comments

Comments
 (0)