-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoadColorImage.cs
104 lines (91 loc) · 3.57 KB
/
LoadColorImage.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
102
103
104
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using MetaphysicsIndustries.Solus;
using MetaphysicsIndustries.Epiphany;
using MetaphysicsIndustries.Acuity;
using MetaphysicsIndustries.Utilities;
namespace MetaphysicsIndustries.Amethyst
{
[Serializable]
public class LoadColorImageElement : AmethystElement
{
public LoadColorImageElement()
: base(new LoadColorImageNode(), new SizeV(120, 80))
{
}
public new LoadColorImageNode Node
{
get { return (LoadColorImageNode)base.Node; }
}
protected override void InitTerminals()
{
base.InitTerminals();
TerminalsByConnection[Node.RedChannel].DisplayText = "r";
TerminalsByConnection[Node.GreenChannel].DisplayText = "g";
TerminalsByConnection[Node.BlueChannel].DisplayText = "b";
}
[Serializable]
public class LoadColorImageNode : Node
{
protected static SolusEngine _engine = new SolusEngine();
public LoadColorImageNode()
: base("Load Color Image")
{
}
protected override void InitConnections()
{
InputConnectionBases.Add(Filename);
OutputConnectionBases.Add(RedChannel);
OutputConnectionBases.Add(GreenChannel);
OutputConnectionBases.Add(BlueChannel);
}
private InputConnectionBase _filename = new InputConnection<string>("Filename");
public InputConnectionBase Filename
{
get { return _filename; }
}
private OutputConnectionBase _redChannel = new OutputConnection<Matrix>("Red Channel");
public OutputConnectionBase RedChannel
{
get { return _redChannel; }
}
private OutputConnectionBase _greenChannel = new OutputConnection<Matrix>("Green Channel");
public OutputConnectionBase GreenChannel
{
get { return _greenChannel; }
}
private OutputConnectionBase _blueChannel = new OutputConnection<Matrix>("Blue Channel");
public OutputConnectionBase BlueChannel
{
get { return _blueChannel; }
}
public override void Execute(Dictionary<InputConnectionBase, object> inputs, Dictionary<OutputConnectionBase, object> outputs)
{
string filename = (string)inputs[Filename];
Matrix image = AcuityEngine.LoadImage2(filename);
Matrix r = image.CloneSize();
Matrix g = image.CloneSize();
Matrix b = image.CloneSize();
int i;
int j;
for (i = 0; i < image.RowCount; i++)
{
for (j = 0; j < image.ColumnCount; j++)
{
int rr = ((int)(image[i, j]) & 0xFF0000) >> 16;
int gg = ((int)(image[i, j]) & 0xFF00) >> 8;
int bb = ((int)(image[i, j]) & 0xFF);
r[i, j] = rr / 255.0f;
g[i, j] = gg / 255.0f;
b[i, j] = bb / 255.0f;
}
}
outputs[RedChannel] = r;
outputs[GreenChannel] = g;
outputs[BlueChannel] = b;
}
}
}
}