Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
QrEncode.cs
1using SkiaSharp;
2using System;
9
11{
16 {
17 private static readonly QrEncoder encoder = new QrEncoder();
18
28 : base(new ScriptNode[] { Text, Level }, argumentTypes2Scalar, Start, Length, Expression)
29 {
30 }
31
42 : base(new ScriptNode[] { Text, Level, Width }, argumentTypes3Scalar, Start, Length, Expression)
43 {
44 }
45
56 public QrEncode(ScriptNode Text, ScriptNode Level, ScriptNode Width, ScriptNode Height, int Start, int Length, Expression Expression)
57 : base(new ScriptNode[] { Text, Level, Width, Height }, argumentTypes4Scalar, Start, Length, Expression)
58 {
59 }
60
64 public override string FunctionName => nameof(QrEncode);
65
69 public override string[] DefaultArgumentNames => new string[] { "Text", "Level", "Width" };
70
78 {
79 string Text = Arguments[0].AssociatedObjectValue?.ToString();
80 CorrectionLevel Level = this.ToEnum<CorrectionLevel>(Arguments[1]);
81
82 if (Arguments.Length == 2)
83 return new StringValue(encoder.GenerateMatrix(Level, Text).ToHalfBlockText());
84
85 int Width = (int)(Expression.ToDouble(Arguments[2].AssociatedObjectValue) + 0.5);
86 int Height;
87
88 if (Arguments.Length == 3)
89 Height = Width;
90 else
91 Height = (int)(Expression.ToDouble(Arguments[3].AssociatedObjectValue) + 0.5);
92
93 QrMatrix M = encoder.GenerateMatrix(Level, Text);
94 byte[] Rgba;
95
96 EventHandler<ColorFunctionEventArgs> h = CustomColorFunction;
97 if (h is null)
98 Rgba = M.ToRGBA(Width, Height);
99 else
100 {
102 h(this, e);
103
104 if (e.Function is null)
105 Rgba = M.ToRGBA(Width, Height);
106 else
107 Rgba = M.ToRGBA(Width, Height, e.Function, e.AntiAlias);
108 }
109
110 return new GraphBitmap(Variables, PixelInformation.FromRaw(SKColorType.Rgba8888, Rgba, Width, Height, Width << 2));
111 }
112
116 public static event EventHandler<ColorFunctionEventArgs> CustomColorFunction;
117
118 }
119}
Class used to compute a QR code matrix.
Definition: QrMatrix.cs:29
byte[] ToRGBA()
Converts the matrix to pixels, each pixel represented by 4 bytes in the order Red,...
Definition: QrMatrix.cs:867
QR Code encoder.
Definition: QrEncoder.cs:12
Event arguments for events determoning if custom color coding of a QR code is to be applied.
QrEncode(Text,Level[,Width[,Height]])
Definition: QrEncode.cs:16
QrEncode(ScriptNode Text, ScriptNode Level, ScriptNode Width, ScriptNode Height, int Start, int Length, Expression Expression)
QrEncode(Text, Level, Width, Height)
Definition: QrEncode.cs:56
static EventHandler< ColorFunctionEventArgs > CustomColorFunction
Event raised to determine if a custom color function is to be applied.
Definition: QrEncode.cs:116
QrEncode(ScriptNode Text, ScriptNode Level, int Start, int Length, Expression Expression)
QrEncode(Text, Level)
Definition: QrEncode.cs:27
override string[] DefaultArgumentNames
Default Argument names
Definition: QrEncode.cs:69
override IElement Evaluate(IElement[] Arguments, Variables Variables)
Evaluates the function.
Definition: QrEncode.cs:77
override string FunctionName
Name of the function
Definition: QrEncode.cs:64
QrEncode(ScriptNode Text, ScriptNode Level, ScriptNode Width, int Start, int Length, Expression Expression)
QrEncode(Text, Level, Width)
Definition: QrEncode.cs:41
Class managing a script expression.
Definition: Expression.cs:39
static double ToDouble(object Object)
Converts an object to a double value.
Definition: Expression.cs:4824
Handles bitmap-based graphs.
Definition: GraphBitmap.cs:13
Contains pixel information
static PixelInformation FromRaw(SKColorType ColorType, byte[] Binary, int Width, int Height, int BytesPerRow)
Gets the pixel information object from raw pixel data.
Base class for multivariate funcions.
ScriptNode[] Arguments
Function arguments.
static readonly ArgumentType[] argumentTypes2Scalar
Two scalar parameters.
static readonly ArgumentType[] argumentTypes3Scalar
Three scalar parameters.
static readonly ArgumentType[] argumentTypes4Scalar
Four scalar parameters.
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
override string ToString()
Definition: ScriptNode.cs:359
Expression Expression
Expression of which the node is a part.
Definition: ScriptNode.cs:177
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
CorrectionLevel
QR Code correction level.
Definition: Enumerations.cs:7