-
Notifications
You must be signed in to change notification settings - Fork 1
/
WorkColor.cs
95 lines (86 loc) · 2.42 KB
/
WorkColor.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
namespace Matt
{
public struct WorkColor
{
public double a;
public double r;
public double g;
public double b;
public bool Transparent
{
get
{
return (a < 0.001);
}
}
public static implicit operator WorkColor(Color clr)
{
WorkColor r = new WorkColor();
r.a = (double)clr.A;
r.r = (double)clr.R;
r.g = (double)clr.G;
r.b = (double)clr.B;
return r;
}
public static implicit operator Color(WorkColor clr)
{
return Color.FromArgb(
Math.Max(0, Math.Min(255, (int)Math.Round(clr.a))),
Math.Max(0, Math.Min(255, (int)Math.Round(clr.r))),
Math.Max(0, Math.Min(255, (int)Math.Round(clr.g))),
Math.Max(0, Math.Min(255, (int)Math.Round(clr.b)))
);
}
public static implicit operator WorkColor(Smith.Colormap.RGB rgb)
{
WorkColor r = new WorkColor();
r.a = 255.0;
r.r = (double)rgb.R;
r.g = (double)rgb.G;
r.b = (double)rgb.B;
return r;
}
public static WorkColor operator +(WorkColor a, WorkColor b)
{
WorkColor r = new WorkColor();
r.a = a.a + b.a;
r.r = a.r + b.r;
r.g = a.g + b.g;
r.b = a.b + b.b;
return r;
}
public static WorkColor operator -(WorkColor a, WorkColor b)
{
WorkColor r = new WorkColor();
r.a = a.a - b.a;
r.r = a.r - b.r;
r.g = a.g - b.g;
r.b = a.b - b.b;
return r;
}
public static WorkColor operator *(WorkColor a, double s)
{
WorkColor r = new WorkColor();
r.a = a.a * s;
r.r = a.r * s;
r.g = a.g * s;
r.b = a.b * s;
return r;
}
public static WorkColor operator /(WorkColor a, double s)
{
WorkColor r = new WorkColor();
r.a = a.a / s;
r.r = a.r / s;
r.g = a.g / s;
r.b = a.b / s;
return r;
}
}
}