-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathColorHelper.cs
More file actions
75 lines (61 loc) · 1.88 KB
/
Copy pathColorHelper.cs
File metadata and controls
75 lines (61 loc) · 1.88 KB
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
using System;
using System.Drawing;
namespace MW5.Shared
{
public static class ColorHelper
{
public static Color UintWithAlphaToColor(uint val)
{
int r = (int)(val & unchecked(0xFF));
int g = (int)((val & unchecked(0xFF00)) >> 8);
int b = (int)((val & unchecked(0xFF0000)) >> 16);
int a = (int)((val & unchecked(0xFF000000)) >> 24);
return Color.FromArgb(a, r, g, b);
}
public static Color UintToColor(uint val)
{
int r, g, b;
GetRgb((int)val, out r, out g, out b);
return Color.FromArgb(255, r, g, b);
}
public static Color IntToColor(int val)
{
int r, g, b;
GetRgb(val, out r, out g, out b);
return Color.FromArgb(255, r, g, b);
}
public static void GetRgb(int color, out int r, out int g, out int b)
{
if (color < 0)
color = 0;
r = color & 0xFF;
g = (color & 0xFF00) / 256; //shift right 8 bits
b = (color & 0xFF0000) / 65536; //shift right 16 bits
}
public static int ColorToInt(Color c)
{
int retval = c.B << 16;
retval += c.G << 8;
return retval + c.R;
}
public static UInt32 ColorToUInt(Color c)
{
int retval = c.B << 16;
retval += c.G << 8;
return Convert.ToUInt32(retval + c.R);
}
public static UInt32 ColorToUIntWithAlpha(Color c)
{
return (uint)(c.A << 24 | c.B << 16 | c.G << 8 | c.R);
}
public static uint ToUInt(this Color? color)
{
uint result = 16777215;
if (color != null)
{
result = ColorToUInt(color.Value);
}
return result;
}
}
}