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 System.Threading.Tasks;
2using SkiaSharp;
7
9{
14 {
24 {
25 }
26
30 public override string FunctionName => nameof(SmoothImage);
31
35 public override string[] DefaultArgumentNames => new string[] { "Image" };
36
44 {
45 PixelInformation Pixels;
46
47 if (Argument is Graph Graph)
48 Pixels = Graph.CreatePixels();
49 else if (Argument is SKImage Image)
50 Pixels = PixelInformation.FromImage(Image);
51 else
52 throw new ScriptRuntimeException("Expected an image or a graph.", this);
53
54 int Width = Pixels.Width;
55 int Height = Pixels.Height;
56 PixelInformationRaw Raw = Pixels.GetRaw();
57 byte[] Bin = (byte[])Raw.Binary.Clone();
58 int i, j, c = Bin.Length / 4;
59 double[] R = new double[c];
60 double[] G = new double[c];
61 double[] B = new double[c];
62 double[] A = new double[c];
63
64 for (i = j = 0; i < c; i++)
65 {
66 B[i] = Bin[j++];
67 G[i] = Bin[j++];
68 R[i] = Bin[j++];
69 A[i] = Bin[j++];
70 }
71
72 (double[] BoundaryR, double[] BoundaryG, double[] BoundaryB, double[] BoundaryA) =
73 FractalGraph.FindBoundaries(R, G, B, A, Width, Height);
74
75 FractalGraph.Smooth(R, G, B, A, BoundaryR, BoundaryG, BoundaryB, BoundaryA, Width, Height, this, Variables);
76
77 return new GraphBitmap(Variables, FractalGraph.ToPixels(R, G, B, A, Width, Height));
78 }
79
86 public override Task<IElement> EvaluateScalarAsync(IElement Argument, Variables Variables)
87 {
88 return Task.FromResult(this.EvaluateScalar(Argument, Variables));
89 }
90 }
91}
Class managing a script expression.
Definition: Expression.cs:39
Defines a clickable fractal graph in the complex plane.
Definition: FractalGraph.cs:22
static PixelInformation ToPixels(double[] ColorIndex, int Width, int Height, SKColor[] Palette)
TODO
static double[] FindBoundaries(double[] ColorIndex, int Width, int Height)
TODO
static void Smooth(double[] ColorIndex, double[] Boundary, int Width, int Height, int N, SKColor[] Palette, ScriptNode Node, Variables Variables)
TODO
Creates a smooth image from an image source.
Definition: SmoothImage.cs:14
override Task< IElement > EvaluateScalarAsync(IElement Argument, Variables Variables)
Evaluates the function on a scalar argument.
Definition: SmoothImage.cs:86
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 string[] DefaultArgumentNames
Default Argument names
Definition: SmoothImage.cs:35
override IElement EvaluateScalar(IElement Argument, Variables Variables)
Evaluates the function on a scalar argument.
Definition: SmoothImage.cs:43
Handles bitmap-based graphs.
Definition: GraphBitmap.cs:13
Base class for graphs.
Definition: Graph.cs:79
PixelInformation CreatePixels()
Creates a bitmap of the graph.
Definition: Graph.cs:362
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.
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:20