-
Notifications
You must be signed in to change notification settings - Fork 3
/
gdipluscolor.go
265 lines (239 loc) · 7.12 KB
/
gdipluscolor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
package gdiplus
import (
. "github.com/tryor/winapi"
. "github.com/tryor/winapi/gdi"
)
//----------------------------------------------------------------------------
// Color mode
//----------------------------------------------------------------------------
type ColorMode int
const (
ColorModeARGB32 ColorMode = 0
ColorModeARGB64 ColorMode = 1
)
//----------------------------------------------------------------------------
// Color Channel flags
//----------------------------------------------------------------------------
type ColorChannelFlags int
const (
ColorChannelFlagsC ColorChannelFlags = iota
ColorChannelFlagsM
ColorChannelFlagsY
ColorChannelFlagsK
ColorChannelFlagsLast
)
// Standard color constants
const (
AliceBlue = 0xFFF0F8FF
AntiqueWhite = 0xFFFAEBD7
Aqua = 0xFF00FFFF
Aquamarine = 0xFF7FFFD4
Azure = 0xFFF0FFFF
Beige = 0xFFF5F5DC
Bisque = 0xFFFFE4C4
Black = 0xFF000000
BlanchedAlmond = 0xFFFFEBCD
Blue = 0xFF0000FF
BlueViolet = 0xFF8A2BE2
Brown = 0xFFA52A2A
BurlyWood = 0xFFDEB887
CadetBlue = 0xFF5F9EA0
Chartreuse = 0xFF7FFF00
Chocolate = 0xFFD2691E
Coral = 0xFFFF7F50
CornflowerBlue = 0xFF6495ED
Cornsilk = 0xFFFFF8DC
Crimson = 0xFFDC143C
Cyan = 0xFF00FFFF
DarkBlue = 0xFF00008B
DarkCyan = 0xFF008B8B
DarkGoldenrod = 0xFFB8860B
DarkGray = 0xFFA9A9A9
DarkGreen = 0xFF006400
DarkKhaki = 0xFFBDB76B
DarkMagenta = 0xFF8B008B
DarkOliveGreen = 0xFF556B2F
DarkOrange = 0xFFFF8C00
DarkOrchid = 0xFF9932CC
DarkRed = 0xFF8B0000
DarkSalmon = 0xFFE9967A
DarkSeaGreen = 0xFF8FBC8B
DarkSlateBlue = 0xFF483D8B
DarkSlateGray = 0xFF2F4F4F
DarkTurquoise = 0xFF00CED1
DarkViolet = 0xFF9400D3
DeepPink = 0xFFFF1493
DeepSkyBlue = 0xFF00BFFF
DimGray = 0xFF696969
DodgerBlue = 0xFF1E90FF
Firebrick = 0xFFB22222
FloralWhite = 0xFFFFFAF0
ForestGreen = 0xFF228B22
Fuchsia = 0xFFFF00FF
Gainsboro = 0xFFDCDCDC
GhostWhite = 0xFFF8F8FF
Gold = 0xFFFFD700
Goldenrod = 0xFFDAA520
Gray = 0xFF808080
Green = 0xFF008000
GreenYellow = 0xFFADFF2F
Honeydew = 0xFFF0FFF0
HotPink = 0xFFFF69B4
IndianRed = 0xFFCD5C5C
Indigo = 0xFF4B0082
Ivory = 0xFFFFFFF0
Khaki = 0xFFF0E68C
Lavender = 0xFFE6E6FA
LavenderBlush = 0xFFFFF0F5
LawnGreen = 0xFF7CFC00
LemonChiffon = 0xFFFFFACD
LightBlue = 0xFFADD8E6
LightCoral = 0xFFF08080
LightCyan = 0xFFE0FFFF
LightGoldenrodYellow = 0xFFFAFAD2
LightGray = 0xFFD3D3D3
LightGreen = 0xFF90EE90
LightPink = 0xFFFFB6C1
LightSalmon = 0xFFFFA07A
LightSeaGreen = 0xFF20B2AA
LightSkyBlue = 0xFF87CEFA
LightSlateGray = 0xFF778899
LightSteelBlue = 0xFFB0C4DE
LightYellow = 0xFFFFFFE0
Lime = 0xFF00FF00
LimeGreen = 0xFF32CD32
Linen = 0xFFFAF0E6
Magenta = 0xFFFF00FF
Maroon = 0xFF800000
MediumAquamarine = 0xFF66CDAA
MediumBlue = 0xFF0000CD
MediumOrchid = 0xFFBA55D3
MediumPurple = 0xFF9370DB
MediumSeaGreen = 0xFF3CB371
MediumSlateBlue = 0xFF7B68EE
MediumSpringGreen = 0xFF00FA9A
MediumTurquoise = 0xFF48D1CC
MediumVioletRed = 0xFFC71585
MidnightBlue = 0xFF191970
MintCream = 0xFFF5FFFA
MistyRose = 0xFFFFE4E1
Moccasin = 0xFFFFE4B5
NavajoWhite = 0xFFFFDEAD
Navy = 0xFF000080
OldLace = 0xFFFDF5E6
Olive = 0xFF808000
OliveDrab = 0xFF6B8E23
Orange = 0xFFFFA500
OrangeRed = 0xFFFF4500
Orchid = 0xFFDA70D6
PaleGoldenrod = 0xFFEEE8AA
PaleGreen = 0xFF98FB98
PaleTurquoise = 0xFFAFEEEE
PaleVioletRed = 0xFFDB7093
PapayaWhip = 0xFFFFEFD5
PeachPuff = 0xFFFFDAB9
Peru = 0xFFCD853F
Pink = 0xFFFFC0CB
Plum = 0xFFDDA0DD
PowderBlue = 0xFFB0E0E6
Purple = 0xFF800080
Red = 0xFFFF0000
RosyBrown = 0xFFBC8F8F
RoyalBlue = 0xFF4169E1
SaddleBrown = 0xFF8B4513
Salmon = 0xFFFA8072
SandyBrown = 0xFFF4A460
SeaGreen = 0xFF2E8B57
SeaShell = 0xFFFFF5EE
Sienna = 0xFFA0522D
Silver = 0xFFC0C0C0
SkyBlue = 0xFF87CEEB
SlateBlue = 0xFF6A5ACD
SlateGray = 0xFF708090
Snow = 0xFFFFFAFA
SpringGreen = 0xFF00FF7F
SteelBlue = 0xFF4682B4
Tan = 0xFFD2B48C
Teal = 0xFF008080
Thistle = 0xFFD8BFD8
Tomato = 0xFFFF6347
Transparent = 0x00FFFFFF
Turquoise = 0xFF40E0D0
Violet = 0xFFEE82EE
Wheat = 0xFFF5DEB3
White = 0xFFFFFFFF
WhiteSmoke = 0xFFF5F5F5
Yellow = 0xFFFFFF00
YellowGreen = 0xFF9ACD32
)
// Shift count and bit mask for A, R, G, B components
const (
AlphaShift = 24
RedShift = 16
GreenShift = 8
BlueShift = 0
)
const (
AlphaMask = 0xff000000
RedMask = 0x00ff0000
GreenMask = 0x0000ff00
BlueMask = 0x000000ff
)
type Color struct {
Argb ARGB
}
func NewColor(argb ...ARGB) Color {
if len(argb) > 0 {
return Color{Argb: argb[0]}
} else {
return Color{Argb: Black}
}
}
func NewColor2(r, g, b BYTE) Color {
return Color{Argb: MakeARGB(255, r, g, b)}
}
func NewColor3(a, r, g, b BYTE) Color {
return Color{Argb: MakeARGB(a, r, g, b)}
}
func (this Color) GetValue() ARGB {
return this.Argb
}
func (this *Color) SetValue(argb ARGB) {
this.Argb = argb
}
func (this Color) GetAlpha() BYTE {
return BYTE(this.Argb >> AlphaShift)
}
func (this Color) GetA() BYTE {
return this.GetAlpha()
}
func (this Color) GetRed() BYTE {
return BYTE(this.Argb >> RedShift)
}
func (this Color) GetR() BYTE {
return this.GetRed()
}
func (this Color) GetGreen() BYTE {
return BYTE(this.Argb >> GreenShift)
}
func (this Color) GetG() BYTE {
return this.GetGreen()
}
func (this Color) GetBlue() BYTE {
return BYTE(this.Argb >> BlueShift)
}
func (this Color) GetB() BYTE {
return this.GetBlue()
}
func (this *Color) SetFromCOLORREF(rgb COLORREF) {
this.Argb = MakeARGB(255, GetRValue(rgb), GetGValue(rgb), GetBValue(rgb))
}
func (this *Color) ToCOLORREF() COLORREF {
return RGB(this.GetRed(), this.GetGreen(), this.GetBlue())
}
func MakeARGB(a, r, g, b BYTE) ARGB {
return ((ARGB(b) << BlueShift) |
(ARGB(g) << GreenShift) |
(ARGB(r) << RedShift) |
(ARGB(a) << AlphaShift))
}