Viewing is open to everyone. Downloading and starring need a GitHub sign-in. Sign in with GitHub

CKeyCertification.cs

v0.1.0-build.85 Latest Commit ede38f5

Size
4.1 KB
Lines
86
Language
csharp
SHA-256
72cd110370b6…
View on GitHub

Sign in with GitHub to download. Each download is recorded with your GitHub username.

1using OpenCKey.Interop;
2
3namespace OpenCKey
4{
5 /// <summary>
6 /// The modelled acquisition used by <see cref="CKeySymbol.Certify"/>
7 /// (<c>ckey_scan_model</c>). Unset properties keep the core's defaults: a
8 /// phone camera at about 8 pixels per module with mild defocus, sensor
9 /// noise and glare. It is a model, not a measurement.
10 /// </summary>
11 public sealed class CKeyScanModel
12 {
13 /// <summary>Camera sampling in pixels per module (default 8).</summary>
14 public double? PxPerModule { get; set; }
15 /// <summary>Gaussian defocus sigma in camera pixels (default 0.9).</summary>
16 public double? BlurPx { get; set; }
17 /// <summary>Sensor noise sigma as a fraction of full scale (default 0.03).</summary>
18 public double? Noise { get; set; }
19 /// <summary>Contrast compression 0..0.9 (default 0.2).</summary>
20 public double? Glare { get; set; }
21 /// <summary>Noise seeds per backdrop, 1..16 (default 3).</summary>
22 public int? Trials { get; set; }
23
24 internal void Apply(ref NativeScanModel m)
25 {
26 if (PxPerModule.HasValue) m.PxPerModule = PxPerModule.Value;
27 if (BlurPx.HasValue) m.BlurPx = BlurPx.Value;
28 if (Noise.HasValue) m.Noise = Noise.Value;
29 if (Glare.HasValue) m.Glare = Glare.Value;
30 if (Trials.HasValue) m.Trials = (uint)System.Math.Max(0, Trials.Value);
31 }
32 }
33
34 /// <summary>The outcome of <see cref="CKeySymbol.Certify"/> (<c>ckey_certification</c>).</summary>
35 public sealed class CKeyCertification
36 {
37 internal CKeyCertification(CKeyStatus status, bool certified, StylePolicy policy, StyleAdjustments adjustments,
38 int trials, int trialsPassed, double minContrast, double featureSeparation,
39 double logoLoad, string message, CKeyStyle? adjustedStyle)
40 {
41 Status = status;
42 IsCertified = certified;
43 Policy = policy;
44 Adjustments = adjustments;
45 Trials = trials;
46 TrialsPassed = trialsPassed;
47 MinContrast = minContrast;
48 FeatureSeparation = featureSeparation;
49 LogoLoad = logoLoad;
50 Message = message;
51 AdjustedStyle = adjustedStyle;
52 }
53
54 /// <summary>
55 /// The core's status. Under <see cref="StylePolicy.Strict"/> it is
56 /// <see cref="CKeyStatus.InvalidArgument"/> unless the style is certified;
57 /// under <see cref="StylePolicy.Override"/> it is <see cref="CKeyStatus.Ok"/> whatever happens.
58 /// </summary>
59 public CKeyStatus Status { get; }
60 /// <summary>True when the policy accepted the style (Status is Ok).</summary>
61 public bool IsAccepted => Status == CKeyStatus.Ok;
62 /// <summary>The symbol decoded in every modelled trial on every backdrop.</summary>
63 public bool IsCertified { get; }
64 /// <summary>The policy that was applied.</summary>
65 public StylePolicy Policy { get; }
66 /// <summary>Changes made by the adaptive policy.</summary>
67 public StyleAdjustments Adjustments { get; }
68 /// <summary>Trials run.</summary>
69 public int Trials { get; }
70 /// <summary>Trials that decoded the payload exactly.</summary>
71 public int TrialsPassed { get; }
72 /// <summary>Informative WCAG-style contrast ratio over all ink/background pairs.</summary>
73 public double MinContrast { get; }
74 /// <summary>Luma separation of mark vs gap pixels after compositing (0..1; &lt;= 0 overlaps).</summary>
75 public double FeatureSeparation { get; }
76 /// <summary>Share of the worst block's correction hidden by the logo.</summary>
77 public double LogoLoad { get; }
78 /// <summary>The reason for refusal, or the list of changes and warnings.</summary>
79 public string Message { get; }
80 /// <summary>Under the adaptive policy, the repaired style to render; otherwise null.</summary>
81 public CKeyStyle? AdjustedStyle { get; }
82
83 /// <inheritdoc />
84 public override string ToString() => Message;
85 }
86}