Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
SmoothImage.cs
1using SkiaSharp;
2using System.Threading.Tasks;
7
9{
14 {
24 {
25 }
26
30 public override string FunctionName => nameof(SmoothImage);
31
35 public override string[] DefaultArgumentNames => new string[] { "Image" };
36
41 public override bool IsAsynchronous => true;
42
50 {
51 return this.EvaluateAsync(Argument, Variables).Result;
52 }
53
60 public override async Task<IElement> EvaluateScalarAsync(IElement Argument, Variables Variables)
61 {
62 PixelInformation Pixels;
63
64 if (Argument is Graph Graph)
65 Pixels = Graph.CreatePixels();
66 else if (Argument is SKImage Image)
67 Pixels = PixelInformation.FromImage(Image);
68 else
69 throw new ScriptRuntimeException("Expected an image or a graph.", this);
70
71 int Width = Pixels.Width;
72 int Height = Pixels.Height;
73 PixelInformationRaw Raw = Pixels.GetRaw();
74 byte[] Bin = (byte[])Raw.Binary.Clone();
75 int i, j, c = Bin.Length / 4;
76 double[] R = new double[c];
77 double[] G = new double[c];
78 double[] B = new double[c];
79 double[] A = new double[c];
80
81 for (i = j = 0; i < c; i++)
82 {
83 B[i] = Bin[j++];
84 G[i] = Bin[j++];
85 R[i] = Bin[j++];
86 A[i] = Bin[j++];
87 }
88
89 (double[] BoundaryR, double[] BoundaryG, double[] BoundaryB, double[] BoundaryA) =
90 FractalGraph.FindBoundaries(R, G, B, A, Width, Height);
91
92 await FractalGraph.Smooth(R, G, B, A, BoundaryR, BoundaryG, BoundaryB, BoundaryA, Width, Height, this, Variables);
93
94 return new GraphBitmap(Variables, FractalGraph.ToPixels(R, G, B, A, Width, Height));
95 }
96 }
97}
Class managing a script expression.
Definition: Expression.cs:41
Defines a clickable fractal graph in the complex plane.
Definition: FractalGraph.cs:23
static async Task Smooth(double[] ColorIndex, double[] Boundary, int Width, int Height, int N, SKColor[] Palette, ScriptNode Node, Variables Variables)
TODO
static PixelInformation ToPixels(double[] ColorIndex, int Width, int Height, SKColor[] Palette)
TODO
static double[] FindBoundaries(double[] ColorIndex, int Width, int Height)
TODO
Creates a smooth image from an image source.
Definition: SmoothImage.cs:14
override string FunctionName
Name of the function
Definition: SmoothImage.cs:30
SmoothImage(ScriptNode Argument, int Start, int Length, Expression Expression)
Creates a smooth image from an image source.
Definition: SmoothImage.cs:22
override IElement Evaluate(IElement Argument, Variables Variables)
Evaluates the function on a scalar argument.
Definition: SmoothImage.cs:49
override bool IsAsynchronous
If the node (or its decendants) include asynchronous evaluation. Asynchronous nodes should be evaluat...
Definition: SmoothImage.cs:41
override string[] DefaultArgumentNames
Default Argument names
Definition: SmoothImage.cs:35
override async Task< IElement > EvaluateScalarAsync(IElement Argument, Variables Variables)
Evaluates the function on a scalar argument.
Definition: SmoothImage.cs:60
Handles bitmap-based graphs.
Definition: GraphBitmap.cs:13
Base class for graphs.
Definition: Graph.cs:88
PixelInformation CreatePixels()
Creates a bitmap of the graph.
Definition: Graph.cs:379
Contains pixel information
abstract PixelInformationRaw GetRaw()
Gets raw pixel data.
byte[] Binary
Binary representation of pixels
static PixelInformation FromImage(SKImage Image)
Gets the pixel information from an SKImage.
Contains pixel information in a raw unencoded format.
Base class for funcions of one scalar variable.
override async Task< IElement > EvaluateAsync(IElement Argument, Variables Variables)
Evaluates the function.
ScriptNode Argument
Function argument.
Base class for all nodes in a parsed script tree.
Definition: ScriptNode.cs:69
int Length
Length of expression covered by node.
Definition: ScriptNode.cs:101
int Start
Start position in script expression.
Definition: ScriptNode.cs:92
Collection of variables.
Definition: Variables.cs:25
Basic interface for all types of elements.
Definition: IElement.cs:21