-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHslToRgbConverterElement.cs
101 lines (86 loc) · 3.22 KB
/
HslToRgbConverterElement.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
96
97
98
99
100
101
using System;
using System.Collections.Generic;
using System.Text;
using MetaphysicsIndustries.Epiphany;
using MetaphysicsIndustries.Acuity;
namespace MetaphysicsIndustries.Amethyst
{
[Serializable]
public class HslToRgbConverterElement : AmethystElement
{
public HslToRgbConverterElement()
: base(new HslToRgbConverterNode())
{
}
[Serializable]
public class HslToRgbConverterNode : Node
{
public HslToRgbConverterNode()
: base("HSL --> RGB")
{
}
private OutputConnection<Matrix> _red = new OutputConnection<Matrix>("Red");
public OutputConnection<Matrix> Red
{
get { return _red; }
}
private OutputConnection<Matrix> _green = new OutputConnection<Matrix>("Green");
public OutputConnection<Matrix> Green
{
get { return _green; }
}
private OutputConnection<Matrix> _blue = new OutputConnection<Matrix>("Blue");
public OutputConnection<Matrix> Blue
{
get { return _blue; }
}
private InputConnection<Matrix> _hue = new InputConnection<Matrix>("Hue");
public InputConnection<Matrix> Hue
{
get { return _hue; }
}
private InputConnection<Matrix> _saturation = new InputConnection<Matrix>("Saturation");
public InputConnection<Matrix> Saturation
{
get { return _saturation; }
}
private InputConnection<Matrix> _luminance = new InputConnection<Matrix>("Luminance");
public InputConnection<Matrix> Luminance
{
get { return _luminance; }
}
protected override void InitConnections()
{
InputConnectionBases.AddRange(Hue, Saturation, Luminance);
OutputConnectionBases.AddRange(Red, Green, Blue);
}
public override void Execute(Dictionary<InputConnectionBase, object> inputs, Dictionary<OutputConnectionBase, object> outputs)
{
Matrix h = (Matrix)inputs[Hue];
Matrix s = (Matrix)inputs[Saturation];
Matrix l = (Matrix)inputs[Luminance];
Matrix r = h.CloneSize();
Matrix g = h.CloneSize();
Matrix b = h.CloneSize();
int i;
int j;
for (i = 0; i < h.RowCount; i++)
{
for (j = 0; j < h.ColumnCount; j++)
{
float rr;
float gg;
float bb;
AcuityEngine.ConvertHslToRgb(h[i, j], s[i, j], l[i, j], out rr, out gg, out bb);
r[i, j] = rr;
g[i, j] = gg;
b[i, j] = bb;
}
}
outputs[Red] = r;
outputs[Green] = g;
outputs[Blue] = b;
}
}
}
}