diff --git a/src/DecoderTest/DecoderTest.csproj b/src/DecoderTest/DecoderTest.csproj
index 57ee45e..fdb63b3 100644
--- a/src/DecoderTest/DecoderTest.csproj
+++ b/src/DecoderTest/DecoderTest.csproj
@@ -14,6 +14,7 @@
all
runtime; build; native; contentfiles; analyzers; buildtransitive
+
diff --git a/src/DecoderTest/SmokeTest.cs b/src/DecoderTest/SmokeTest.cs
index 0634df4..3c9c8e9 100644
--- a/src/DecoderTest/SmokeTest.cs
+++ b/src/DecoderTest/SmokeTest.cs
@@ -20,7 +20,7 @@ public void SmokeTest()
[Test]
public void DecoderTest()
{
- QRCodeDecoderLibrary.QRDecoder decoder = new ();
+ QRCodeDecoderLibrary.QRDecoder decoder = new();
var result = decoder.ImageDecoder(SixLabors.ImageSharp.Image.Load("pass.png"));
Assert.IsNotNull(result);
diff --git a/src/QRCodeDecoderLibrary/DependencyInjection/QRCodeDecoderExtensions.cs b/src/QRCodeDecoderLibrary/DependencyInjection/QRCodeDecoderExtensions.cs
index a091a3f..041ad46 100644
--- a/src/QRCodeDecoderLibrary/DependencyInjection/QRCodeDecoderExtensions.cs
+++ b/src/QRCodeDecoderLibrary/DependencyInjection/QRCodeDecoderExtensions.cs
@@ -8,5 +8,10 @@ public static IServiceCollection AddQRCodeDecoder(this IServiceCollection servic
{
return services.AddTransient();
}
+
+ public static IServiceCollection AddQRCodeDecoderFactory(this IServiceCollection services)
+ {
+ return services.AddSingleton();
+ }
}
}
\ No newline at end of file
diff --git a/src/QRCodeDecoderLibrary/DependencyInjection/QRDecoderFactory.cs b/src/QRCodeDecoderLibrary/DependencyInjection/QRDecoderFactory.cs
new file mode 100644
index 0000000..e8448e8
--- /dev/null
+++ b/src/QRCodeDecoderLibrary/DependencyInjection/QRDecoderFactory.cs
@@ -0,0 +1,28 @@
+using System;
+
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+
+namespace QRCodeDecoderLibrary
+{
+ public interface IQRDecoderFactory
+ {
+ QRDecoder CreateQRDecoder();
+ }
+
+ public class QRDecoderFactory : IQRDecoderFactory
+ {
+ private readonly IServiceProvider _serviceProvider;
+
+ public QRDecoderFactory(IServiceProvider serviceProvider)
+ {
+ _serviceProvider = serviceProvider;
+ }
+
+ public QRDecoder CreateQRDecoder()
+ {
+ var logger = _serviceProvider.GetRequiredService>();
+ return new QRDecoder(logger);
+ }
+ }
+}
diff --git a/src/QRCodeDecoderLibrary/Finder.cs b/src/QRCodeDecoderLibrary/Finder.cs
index e5c79af..27a0c48 100644
--- a/src/QRCodeDecoderLibrary/Finder.cs
+++ b/src/QRCodeDecoderLibrary/Finder.cs
@@ -1,4 +1,4 @@
-/////////////////////////////////////////////////////////////////////
+/////////////////////////////////////////////////////////////////////
//
// QR Code Library
//
@@ -45,105 +45,105 @@
namespace QRCodeDecoderLibrary
{
-///
-/// QR code finder class
-///
-internal class Finder
- {
- // horizontal scan
- internal int Row;
- internal int Col1;
- internal int Col2;
- internal double HModule;
+ ///
+ /// QR code finder class
+ ///
+ internal class Finder
+ {
+ // horizontal scan
+ internal int Row;
+ internal int Col1;
+ internal int Col2;
+ internal double HModule;
- // vertical scan
- internal int Col;
- internal int Row1;
- internal int Row2;
- internal double VModule;
+ // vertical scan
+ internal int Col;
+ internal int Row1;
+ internal int Row2;
+ internal double VModule;
- internal double Distance;
- internal double ModuleSize;
+ internal double Distance;
+ internal double ModuleSize;
- ///
- /// Constructor during horizontal scan
- ///
- internal Finder
- (
- int Row,
- int Col1,
- int Col2,
- double HModule
- )
- {
- this.Row = Row;
- this.Col1 = Col1;
- this.Col2 = Col2;
- this.HModule = HModule;
- Distance = double.MaxValue;
- return;
- }
+ ///
+ /// Constructor during horizontal scan
+ ///
+ internal Finder
+ (
+ int Row,
+ int Col1,
+ int Col2,
+ double HModule
+ )
+ {
+ this.Row = Row;
+ this.Col1 = Col1;
+ this.Col2 = Col2;
+ this.HModule = HModule;
+ Distance = double.MaxValue;
+ return;
+ }
- ///
- /// Match during vertical scan
- ///
- internal void Match
- (
- int Col,
- int Row1,
- int Row2,
- double VModule
- )
- {
- // test if horizontal and vertical are not related
- if(Col < Col1 || Col >= Col2 || Row < Row1 || Row >= Row2) return;
+ ///
+ /// Match during vertical scan
+ ///
+ internal void Match
+ (
+ int Col,
+ int Row1,
+ int Row2,
+ double VModule
+ )
+ {
+ // test if horizontal and vertical are not related
+ if (Col < Col1 || Col >= Col2 || Row < Row1 || Row >= Row2) return;
- // Module sizes must be about the same
- if(Math.Min(HModule, VModule) < Math.Max(HModule, VModule) * QRDecoder.MODULE_SIZE_DEVIATION) return;
+ // Module sizes must be about the same
+ if (Math.Min(HModule, VModule) < Math.Max(HModule, VModule) * QRDecoder.MODULE_SIZE_DEVIATION) return;
- // calculate distance
- double DeltaX = Col - 0.5 * (Col1 + Col2);
- double DeltaY = Row - 0.5 * (Row1 + Row2);
- double Delta = Math.Sqrt(DeltaX * DeltaX + DeltaY * DeltaY);
+ // calculate distance
+ double DeltaX = Col - 0.5 * (Col1 + Col2);
+ double DeltaY = Row - 0.5 * (Row1 + Row2);
+ double Delta = Math.Sqrt(DeltaX * DeltaX + DeltaY * DeltaY);
- // distance between two points must be less than 2 pixels
- if(Delta > QRDecoder.HOR_VERT_SCAN_MAX_DISTANCE) return;
+ // distance between two points must be less than 2 pixels
+ if (Delta > QRDecoder.HOR_VERT_SCAN_MAX_DISTANCE) return;
- // new result is better than last result
- if(Delta < Distance)
- {
- this.Col = Col;
- this.Row1 = Row1;
- this.Row2 = Row2;
- this.VModule = VModule;
- ModuleSize = 0.5 * (HModule + VModule);
- Distance = Delta;
- }
- return;
- }
+ // new result is better than last result
+ if (Delta < Distance)
+ {
+ this.Col = Col;
+ this.Row1 = Row1;
+ this.Row2 = Row2;
+ this.VModule = VModule;
+ ModuleSize = 0.5 * (HModule + VModule);
+ Distance = Delta;
+ }
+ return;
+ }
- ///
- /// Horizontal and vertical scans overlap
- ///
- internal bool Overlap
- (
- Finder Other
- )
- {
- return Other.Col1 < Col2 && Other.Col2 >= Col1 && Other.Row1 < Row2 && Other.Row2 >= Row1;
- }
+ ///
+ /// Horizontal and vertical scans overlap
+ ///
+ internal bool Overlap
+ (
+ Finder Other
+ )
+ {
+ return Other.Col1 < Col2 && Other.Col2 >= Col1 && Other.Row1 < Row2 && Other.Row2 >= Row1;
+ }
- ///
- /// Finder to string
- ///
- public override string ToString()
- {
- if(Distance == double.MaxValue)
- {
- return string.Format("Finder: Row: {0}, Col1: {1}, Col2: {2}, HModule: {3:0.00}", Row, Col1, Col2, HModule);
- }
+ ///
+ /// Finder to string
+ ///
+ public override string ToString()
+ {
+ if (Distance == double.MaxValue)
+ {
+ return string.Format("Finder: Row: {0}, Col1: {1}, Col2: {2}, HModule: {3:0.00}", Row, Col1, Col2, HModule);
+ }
- return string.Format("Finder: Row: {0}, Col: {1}, Module: {2:0.00}, Distance: {3:0.00}", Row, Col, ModuleSize, Distance);
- }
- }
+ return string.Format("Finder: Row: {0}, Col: {1}, Module: {2:0.00}, Distance: {3:0.00}", Row, Col, ModuleSize, Distance);
+ }
+ }
}
diff --git a/src/QRCodeDecoderLibrary/QRCodeDecoderLibrary.csproj b/src/QRCodeDecoderLibrary/QRCodeDecoderLibrary.csproj
index 5b6396e..191dfff 100644
--- a/src/QRCodeDecoderLibrary/QRCodeDecoderLibrary.csproj
+++ b/src/QRCodeDecoderLibrary/QRCodeDecoderLibrary.csproj
@@ -23,7 +23,7 @@
-
+
diff --git a/src/QRCodeDecoderLibrary/QRDecoder.cs b/src/QRCodeDecoderLibrary/QRDecoder.cs
index a820696..dc5be1e 100644
--- a/src/QRCodeDecoderLibrary/QRDecoder.cs
+++ b/src/QRCodeDecoderLibrary/QRDecoder.cs
@@ -1,13 +1,15 @@
using System;
using System.Collections.Generic;
-using System.Drawing;
-using System.Runtime.InteropServices;
using System.Text;
+
using Microsoft.Extensions.Logging;
+
using QRCodeSharedLibrary;
-using Stef.Validation;
+
using SixLabors.ImageSharp.Processing;
+using Stef.Validation;
+
namespace QRCodeDecoderLibrary
{
public class QRDecoder : StaticTables
diff --git a/src/QRCodeDecoderLibrary/ReedSolomon.cs b/src/QRCodeDecoderLibrary/ReedSolomon.cs
index d59c59e..29e0016 100644
--- a/src/QRCodeDecoderLibrary/ReedSolomon.cs
+++ b/src/QRCodeDecoderLibrary/ReedSolomon.cs
@@ -1,4 +1,5 @@
using System;
+
using QRCodeSharedLibrary;
namespace QRCodeDecoderLibrary
diff --git a/src/QRCodeSharedLibrary/QRCodeSharedLibrary.csproj b/src/QRCodeSharedLibrary/QRCodeSharedLibrary.csproj
index d1df195..5620ad3 100644
--- a/src/QRCodeSharedLibrary/QRCodeSharedLibrary.csproj
+++ b/src/QRCodeSharedLibrary/QRCodeSharedLibrary.csproj
@@ -5,4 +5,8 @@
QRCodeShared
https://www.codeproject.com/info/cpol10.aspx
+
+
+
+
\ No newline at end of file