ReactOS 0.4.17-dev-243-g1369312
PaletteModel Class Reference

#include <palettemodel.h>

Public Member Functions

 PaletteModel ()
 
PAL_TYPE SelectedPalette ()
 
void SelectPalette (PAL_TYPE nPalette)
 
COLORREF GetColor (UINT nIndex) const
 
void SetColor (UINT nIndex, COLORREF newColor)
 
COLORREF GetFgColor () const
 
void SetFgColor (COLORREF newColor)
 
COLORREF GetBgColor () const
 
void SetBgColor (COLORREF newColor)
 
HBRUSH CreateColorBrush (COLORREF color)
 
HBRUSH CreateFgBrush ()
 
HBRUSH CreateBgBrush ()
 

Private Member Functions

void NotifyColorChanged ()
 
void NotifyPaletteChanged ()
 

Static Private Member Functions

static HBRUSH CreateDitherBrush (COLORREF color, COLORREF monoColor0, COLORREF monoColor1)
 

Private Attributes

COLORREF m_colors [NUM_COLORS]
 
PAL_TYPE m_nSelectedPalette
 
COLORREF m_fgColor
 
COLORREF m_bgColor
 

Detailed Description

Definition at line 22 of file palettemodel.h.

Constructor & Destructor Documentation

◆ PaletteModel()

PaletteModel::PaletteModel ( )

Definition at line 15 of file palettemodel.cpp.

16{
17 m_fgColor = RGB(0, 0, 0);
18 m_bgColor = RGB(255, 255, 255);
20}
void SelectPalette(PAL_TYPE nPalette)
COLORREF m_fgColor
Definition: palettemodel.h:27
COLORREF m_bgColor
Definition: palettemodel.h:28
#define RGB(r, g, b)
Definition: precomp.h:67
@ PAL_MODERN
Definition: palettemodel.h:14

Member Function Documentation

◆ CreateBgBrush()

HBRUSH PaletteModel::CreateBgBrush ( )
inline

Definition at line 46 of file palettemodel.h.

46{ return CreateColorBrush(m_bgColor); }
HBRUSH CreateColorBrush(COLORREF color)

Referenced by CPaletteWindow::OnPaint().

◆ CreateColorBrush()

HBRUSH PaletteModel::CreateColorBrush ( COLORREF  color)

Definition at line 191 of file palettemodel.cpp.

192{
194 return CreateDitherBrush(color, RGB(0, 0, 0), RGB(255, 255, 255));
195 else
196 return CreateSolidBrush(color);
197}
PAL_TYPE m_nSelectedPalette
Definition: palettemodel.h:26
static HBRUSH CreateDitherBrush(COLORREF color, COLORREF monoColor0, COLORREF monoColor1)
GLuint color
Definition: glext.h:6243
@ PAL_MONOCHROME
Definition: palettemodel.h:17
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)

Referenced by CreateBgBrush(), CreateFgBrush(), and CPaletteWindow::OnPaint().

◆ CreateDitherBrush()

HBRUSH PaletteModel::CreateDitherBrush ( COLORREF  color,
COLORREF  monoColor0,
COLORREF  monoColor1 
)
staticprivate

Definition at line 125 of file palettemodel.cpp.

126{
127 // 8x8 Bayer ordered dithering matrix (0 to 63)
128 static const BYTE s_bayerMatrix[8][8] =
129 {
130 { 0, 32, 8, 40, 2, 34, 10, 42 },
131 { 48, 16, 56, 24, 50, 18, 58, 26 },
132 { 12, 44, 4, 36, 14, 46, 6, 38 },
133 { 60, 28, 52, 20, 62, 30, 54, 22 },
134 { 3, 35, 11, 43, 1, 33, 9, 41 },
135 { 51, 19, 59, 27, 49, 17, 57, 25 },
136 { 15, 47, 7, 39, 13, 45, 5, 37 },
137 { 63, 31, 55, 23, 61, 29, 53, 21 },
138 };
140 INT brightness = sum / 3;
141 if (brightness < 0)
142 brightness = 0;
143 if (brightness >= 255)
144 brightness = 256; // White out
145
146 BITMAPINFO bmi = {};
147 bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
148 bmi.bmiHeader.biWidth = 8;
149 bmi.bmiHeader.biHeight = -8; // Top-down
150 bmi.bmiHeader.biPlanes = 1;
151 bmi.bmiHeader.biBitCount = 24;
152
153 const BYTE b0 = GetBValue(monoColor0), g0 = GetGValue(monoColor0), r0 = GetRValue(monoColor0);
154 const BYTE b1 = GetBValue(monoColor1), g1 = GetGValue(monoColor1), r1 = GetRValue(monoColor1);
155
156 BYTE pixels[8 * 8 * 3];
157 for (INT y = 0; y < 8; ++y)
158 {
159 INT index = y * (3 * CHAR_BIT);
160 for (INT x = 0; x < 8; ++x)
161 {
162 const INT threshold = s_bayerMatrix[y][x] * 255 / 63;
163 if (brightness > threshold)
164 {
165 pixels[index++] = b1; // Blue
166 pixels[index++] = g1; // Green
167 pixels[index++] = r1; // Red
168 }
169 else
170 {
171 pixels[index++] = b0; // Blue
172 pixels[index++] = g0; // Green
173 pixels[index++] = r0; // Red
174 }
175 }
176 }
177
178 HDC hdc = GetDC(NULL);
181
182 if (!hBitmap)
183 return NULL;
184
185 HBRUSH hBrush = CreatePatternBrush(hBitmap);
187
188 return hBrush;
189}
#define NULL
Definition: types.h:112
static HBITMAP hBitmap
Definition: timezone.c:26
#define CHAR_BIT
Definition: limits.h:6
#define GetBValue(quad)
Definition: precomp.h:71
#define GetGValue(quad)
Definition: precomp.h:70
#define GetRValue(quad)
Definition: precomp.h:69
pKey DeleteObject()
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
Definition: gl.h:1546
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
GLuint index
Definition: glext.h:6031
HDC hdc
Definition: main.c:9
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
static CRYPT_DATA_BLOB b1[]
Definition: msg.c:529
static DNS_RECORDW r1
Definition: record.c:37
static int sum(int x_, int y_)
Definition: ptr2_test.cpp:35
USHORT biBitCount
Definition: precomp.h:34
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1922
int32_t INT
Definition: typedefs.h:58
#define DIB_RGB_COLORS
Definition: wingdi.h:367
#define CBM_INIT
Definition: wingdi.h:365
HBITMAP WINAPI CreateDIBitmap(_In_ HDC hdc, _In_opt_ const BITMAPINFOHEADER *pbmih, _In_ DWORD fdwInit, _In_opt_ const VOID *pvInit, _In_opt_ const BITMAPINFO *pbmi, _In_ UINT uUsage)
HBRUSH WINAPI CreatePatternBrush(_In_ HBITMAP)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
HDC WINAPI GetDC(_In_opt_ HWND)
unsigned char BYTE
Definition: xxhash.c:193

Referenced by CreateColorBrush().

◆ CreateFgBrush()

HBRUSH PaletteModel::CreateFgBrush ( )
inline

Definition at line 45 of file palettemodel.h.

45{ return CreateColorBrush(m_fgColor); }

Referenced by CPaletteWindow::OnPaint().

◆ GetBgColor()

◆ GetColor()

COLORREF PaletteModel::GetColor ( UINT  nIndex) const

Definition at line 69 of file palettemodel.cpp.

70{
71 if (nIndex < NUM_COLORS)
72 return m_colors[nIndex];
73 else
74 return 0;
75}
COLORREF m_colors[NUM_COLORS]
Definition: palettemodel.h:25
#define NUM_COLORS
Definition: palettemodel.h:10

Referenced by CPaletteWindow::OnLButtonDown(), CPaletteWindow::OnPaint(), and CPaletteWindow::OnRButtonDown().

◆ GetFgColor()

◆ NotifyColorChanged()

void PaletteModel::NotifyColorChanged ( )
private

Definition at line 108 of file palettemodel.cpp.

109{
110 if (paletteWindow.IsWindow())
112 if (canvasWindow.IsWindow())
114 if (textEditWindow.IsWindow())
116}
#define WM_PALETTEMODELCOLORCHANGED
Definition: precomp.h:52
CTextEditWindow textEditWindow
Definition: textedit.cpp:12
CCanvasWindow canvasWindow
Definition: canvas.cpp:11
CPaletteWindow paletteWindow
Definition: palette.cpp:19

Referenced by SetBgColor(), and SetFgColor().

◆ NotifyPaletteChanged()

void PaletteModel::NotifyPaletteChanged ( )
private

Definition at line 118 of file palettemodel.cpp.

119{
120 if (paletteWindow.IsWindow())
121 paletteWindow.Invalidate(FALSE);
122}
#define FALSE
Definition: types.h:117

Referenced by SelectPalette(), and SetColor().

◆ SelectedPalette()

PAL_TYPE PaletteModel::SelectedPalette ( )

Definition at line 22 of file palettemodel.cpp.

23{
24 return m_nSelectedPalette;
25}

Referenced by CMainWindow::OnInitMenuPopup().

◆ SelectPalette()

void PaletteModel::SelectPalette ( PAL_TYPE  nPalette)

Definition at line 27 of file palettemodel.cpp.

28{
29 static const COLORREF modernColors[NUM_COLORS] =
30 {
31 0x000000, 0x464646, 0x787878, 0x300099, 0x241ced, 0x0078ff, 0x0ec2ff,
32 0x00f2ff, 0x1de6a8, 0x4cb122, 0xefb700, 0xf36d4d, 0x99362f, 0x98316f,
33 0xffffff, 0xdcdcdc, 0xb4b4b4, 0x3c5a9c, 0xb1a3ff, 0x7aaae5, 0x9ce4f5,
34 0xbdf9ff, 0xbcf9d3, 0x61bb9d, 0xead999, 0xd19a70, 0x8e6d54, 0xd5a5b5
35 };
36 static const COLORREF oldColors[NUM_COLORS] =
37 {
38 0x000000, 0x808080, 0x000080, 0x008080, 0x008000, 0x808000, 0x800000,
39 0x800080, 0x408080, 0x404000, 0xff8000, 0x804000, 0xff0040, 0x004080,
40 0xffffff, 0xc0c0c0, 0x0000ff, 0x00ffff, 0x00ff00, 0xffff00, 0xff0000,
41 0xff00ff, 0x80ffff, 0x80ff00, 0xffff80, 0xff8080, 0x8000ff, 0x4080ff
42 };
43 static const COLORREF grayscale[NUM_COLORS] =
44 {
45 0x000000, 0x090909, 0x121212, 0x1C1C1C, 0x252525, 0x2F2F2F, 0x383838,
46 0x424242, 0x4B4B4B, 0x555555, 0x5E5E5E, 0x676767, 0x717171, 0x7B7B7B,
47 0xFFFFFF, 0xF6F6F6, 0xEDEDED, 0xE3E3E3, 0xD9D9D9, 0xD0D0D0, 0xC7C7C7,
48 0xBDBDBD, 0xB4B4B4, 0xAAAAAA, 0xA1A1A1, 0x979797, 0x8E8E8E, 0x848484
49 };
50 switch (nPalette)
51 {
52 case PAL_MODERN:
53 CopyMemory(m_colors, modernColors, sizeof(m_colors));
54 break;
55 case PAL_OLDTYPE:
56 CopyMemory(m_colors, oldColors, sizeof(m_colors));
57 break;
58 case PAL_GRAYSCALE:
59 case PAL_MONOCHROME:
60 CopyMemory(m_colors, grayscale, sizeof(m_colors));
61 break;
62 }
63 m_nSelectedPalette = nPalette;
64 m_fgColor = RGB(0, 0, 0);
65 m_bgColor = RGB(255, 255, 255);
67}
void NotifyPaletteChanged()
#define CopyMemory
Definition: minwinbase.h:29
@ PAL_GRAYSCALE
Definition: palettemodel.h:16
@ PAL_OLDTYPE
Definition: palettemodel.h:15
DWORD COLORREF
Definition: windef.h:100

Referenced by CMainWindow::OnCommand(), and PaletteModel().

◆ SetBgColor()

void PaletteModel::SetBgColor ( COLORREF  newColor)

Definition at line 102 of file palettemodel.cpp.

103{
104 m_bgColor = newColor;
106}
void NotifyColorChanged()

Referenced by ColorTool::fetchColor(), CPaletteWindow::OnRButtonDblClk(), and CPaletteWindow::OnRButtonDown().

◆ SetColor()

void PaletteModel::SetColor ( UINT  nIndex,
COLORREF  newColor 
)

Definition at line 77 of file palettemodel.cpp.

78{
79 if (nIndex < NUM_COLORS)
80 {
81 m_colors[nIndex] = newColor;
83 }
84}

Referenced by CPaletteWindow::OnLButtonDblClk(), and CPaletteWindow::OnRButtonDblClk().

◆ SetFgColor()

void PaletteModel::SetFgColor ( COLORREF  newColor)

Member Data Documentation

◆ m_bgColor

COLORREF PaletteModel::m_bgColor
private

Definition at line 28 of file palettemodel.h.

Referenced by CreateBgBrush(), GetBgColor(), PaletteModel(), SelectPalette(), and SetBgColor().

◆ m_colors

COLORREF PaletteModel::m_colors[NUM_COLORS]
private

Definition at line 25 of file palettemodel.h.

Referenced by GetColor(), SelectPalette(), and SetColor().

◆ m_fgColor

COLORREF PaletteModel::m_fgColor
private

Definition at line 27 of file palettemodel.h.

Referenced by CreateFgBrush(), GetFgColor(), PaletteModel(), SelectPalette(), and SetFgColor().

◆ m_nSelectedPalette

PAL_TYPE PaletteModel::m_nSelectedPalette
private

Definition at line 26 of file palettemodel.h.

Referenced by CreateColorBrush(), SelectedPalette(), and SelectPalette().


The documentation for this class was generated from the following files: