diff --git a/BarcodeScanning.Native.Maui/BarcodeScanning.Native.Maui.csproj b/BarcodeScanning.Native.Maui/BarcodeScanning.Native.Maui.csproj
index ff206f4..1de5db9 100644
--- a/BarcodeScanning.Native.Maui/BarcodeScanning.Native.Maui.csproj
+++ b/BarcodeScanning.Native.Maui/BarcodeScanning.Native.Maui.csproj
@@ -10,7 +10,7 @@
true
true
enable
- 2.1.0
+ 2.1.1
Alen Friščić
MIT
README.md
@@ -58,8 +58,8 @@
-
-
+
+
diff --git a/BarcodeScanning.Native.Maui/CameraView.cs b/BarcodeScanning.Native.Maui/CameraView.cs
index c8147fe..3288584 100644
--- a/BarcodeScanning.Native.Maui/CameraView.cs
+++ b/BarcodeScanning.Native.Maui/CameraView.cs
@@ -335,10 +335,13 @@ internal void DetectionFinished(HashSet barCodeResults, Lock resu
_poolingTimer.Start();
}
- foreach (var result in barCodeResults)
+ lock (resultLock)
{
- _pooledResults.Remove(result);
- _pooledResults.Add(result);
+ foreach (var result in barCodeResults)
+ {
+ _pooledResults.Remove(result);
+ _pooledResults.Add(result);
+ }
}
}
}
diff --git a/BarcodeScanning.Native.Maui/Platform/Android/BarcodeAnalyzer.cs b/BarcodeScanning.Native.Maui/Platform/Android/BarcodeAnalyzer.cs
index 144052b..301ba5e 100644
--- a/BarcodeScanning.Native.Maui/Platform/Android/BarcodeAnalyzer.cs
+++ b/BarcodeScanning.Native.Maui/Platform/Android/BarcodeAnalyzer.cs
@@ -11,7 +11,7 @@
using MLKitBarcodeScanning = Xamarin.Google.MLKit.Vision.BarCode.BarcodeScanning;
using Point = Microsoft.Maui.Graphics.Point;
-using RectF = Microsoft.Maui.Graphics.RectF;
+using Rect = Microsoft.Maui.Graphics.Rect;
using Size = Android.Util.Size;
namespace BarcodeScanning;
@@ -21,6 +21,10 @@ internal class BarcodeAnalyzer : Java.Lang.Object, ImageAnalysis.IAnalyzer, IOnS
public Size DefaultTargetResolution => Methods.TargetResolution(null);
public int TargetCoordinateSystem => ImageAnalysis.CoordinateSystemViewReferenced;
+ private readonly HashSet _barcodeResults;
+ private readonly CameraManager _cameraManager;
+ private readonly Lock _resultsLock;
+
private IBarcodeScanner? _barcodeScanner;
private CoordinateTransform? _coordinateTransform;
private IImageProxy? _proxy;
@@ -29,11 +33,7 @@ internal class BarcodeAnalyzer : Java.Lang.Object, ImageAnalysis.IAnalyzer, IOnS
private bool _updateCoordinateTransform = false;
private int _transformDegrees = 0;
private Point _previewViewCenter = new();
- private RectF _previewViewRect = new();
-
- private readonly HashSet _barcodeResults;
- private readonly CameraManager _cameraManager;
- private readonly Lock _resultsLock;
+ private Rect _previewViewRect = new();
internal BarcodeAnalyzer(CameraManager cameraManager)
{
diff --git a/BarcodeScanning.Native.Maui/Platform/Android/CameraManager.cs b/BarcodeScanning.Native.Maui/Platform/Android/CameraManager.cs
index 1e82b4a..c7aacb2 100644
--- a/BarcodeScanning.Native.Maui/Platform/Android/CameraManager.cs
+++ b/BarcodeScanning.Native.Maui/Platform/Android/CameraManager.cs
@@ -25,8 +25,6 @@ internal class CameraManager : IDisposable
internal CameraState? OpenedCameraState { get; set; }
- private ICameraInfo? _currentCameraInfo;
-
private readonly BarcodeAnalyzer _barcodeAnalyzer;
private readonly BarcodeView _barcodeView;
private readonly Context _context;
@@ -40,6 +38,8 @@ internal class CameraManager : IDisposable
private readonly CameraView? _cameraView;
+ private ICameraInfo? _currentCameraInfo;
+
private const int aimRadius = 25;
internal CameraManager(CameraView cameraView, Context context)
@@ -186,8 +186,9 @@ internal void UpdateResolution()
resolutionBuilder.SetAllowedResolutionMode(ResolutionSelector.PreferHigherResolutionOverCaptureRate);
resolutionBuilder.SetResolutionStrategy(analysisStrategy);
resolutionBuilder.SetAspectRatioStrategy(AspectRatioStrategy.Ratio169FallbackAutoStrategy);
- _cameraController.ImageAnalysisResolutionSelector = resolutionBuilder.Build();
- _cameraController.PreviewResolutionSelector = resolutionBuilder.Build();
+ var selector = resolutionBuilder.Build();
+ _cameraController.ImageAnalysisResolutionSelector = selector;
+ _cameraController.PreviewResolutionSelector = selector;
}
}
diff --git a/BarcodeScanning.Native.Maui/Platform/Android/Methods.cs b/BarcodeScanning.Native.Maui/Platform/Android/Methods.cs
index 3e49814..c51aeb2 100644
--- a/BarcodeScanning.Native.Maui/Platform/Android/Methods.cs
+++ b/BarcodeScanning.Native.Maui/Platform/Android/Methods.cs
@@ -85,7 +85,7 @@ private static void ProcessBarcodeResult(Java.Lang.Object? inputResults, HashSet
}
}
- [LibraryImport("InvertBytes.so")]
+ [LibraryImport("libInvertBytes.so")]
private static partial int InvertBytes(IntPtr data, int length);
internal static void InvertLuminance(Image image)
@@ -182,7 +182,7 @@ internal static Size TargetResolution(CaptureQuality? captureQuality)
{
return captureQuality switch
{
- CaptureQuality.Low => new Size(640, 480),
+ CaptureQuality.Low => new Size(854, 480),
CaptureQuality.Medium => new Size(1280, 720),
CaptureQuality.High => new Size(1920, 1080),
CaptureQuality.Highest => new Size(3840, 2160),
diff --git a/BarcodeScanning.Native.Maui/Platform/Android/Native/arm64-v8a/InvertBytes.so b/BarcodeScanning.Native.Maui/Platform/Android/Native/arm64-v8a/libInvertBytes.so
similarity index 100%
rename from BarcodeScanning.Native.Maui/Platform/Android/Native/arm64-v8a/InvertBytes.so
rename to BarcodeScanning.Native.Maui/Platform/Android/Native/arm64-v8a/libInvertBytes.so
diff --git a/BarcodeScanning.Native.Maui/Platform/Android/Native/armeabi-v7a/InvertBytes.so b/BarcodeScanning.Native.Maui/Platform/Android/Native/armeabi-v7a/libInvertBytes.so
similarity index 100%
rename from BarcodeScanning.Native.Maui/Platform/Android/Native/armeabi-v7a/InvertBytes.so
rename to BarcodeScanning.Native.Maui/Platform/Android/Native/armeabi-v7a/libInvertBytes.so
diff --git a/BarcodeScanning.Native.Maui/Platform/MaciOS/BarcodeAnalyzer.cs b/BarcodeScanning.Native.Maui/Platform/MaciOS/BarcodeAnalyzer.cs
index 7248fff..5287024 100644
--- a/BarcodeScanning.Native.Maui/Platform/MaciOS/BarcodeAnalyzer.cs
+++ b/BarcodeScanning.Native.Maui/Platform/MaciOS/BarcodeAnalyzer.cs
@@ -18,8 +18,8 @@ internal class BarcodeAnalyzer : AVCaptureVideoDataOutputSampleBufferDelegate
private readonly VNSequenceRequestHandler _sequenceRequestHandler;
private Point _previewCenter = new();
- private RectF _previewRect = new();
- private VNBarcodeObservation[] result = [];
+ private Rect _previewRect = new();
+ private VNBarcodeObservation[] _result = [];
internal BarcodeAnalyzer(CameraManager cameraManager)
{
@@ -29,9 +29,9 @@ internal BarcodeAnalyzer(CameraManager cameraManager)
_detectBarcodesRequest = new VNDetectBarcodesRequest((request, error) =>
{
if (error is null)
- result = request.GetResults();
+ _result = request.GetResults();
else
- result = [];
+ _result = [];
});
_sequenceRequestHandler = new VNSequenceRequestHandler();
@@ -69,16 +69,12 @@ public override void DidOutputSampleBuffer(AVCaptureOutput captureOutput, CMSamp
}
}
-
_sequenceRequestHandler?.Perform([_detectBarcodesRequest], sampleBuffer, out _);
- if (result is null)
- return;
-
lock (_resultsLock)
{
_barcodeResults.Clear();
- foreach (var barcode in result)
+ foreach (var barcode in _result)
{
if (string.IsNullOrEmpty(barcode.PayloadStringValue))
continue;
@@ -96,8 +92,8 @@ public override void DidOutputSampleBuffer(AVCaptureOutput captureOutput, CMSamp
if (_cameraManager?.CameraView?.ViewfinderMode ?? false)
{
- _previewRect.Width = (float)_cameraManager.PreviewLayer.Bounds.Width;
- _previewRect.Height = (float)_cameraManager.PreviewLayer.Bounds.Height;
+ _previewRect.Width = _cameraManager.PreviewLayer.Bounds.Width;
+ _previewRect.Height = _cameraManager.PreviewLayer.Bounds.Height;
if (!_previewRect.Contains(barcodeResult.PreviewBoundingBox))
continue;
diff --git a/BarcodeScanning.Native.Maui/Platform/MaciOS/CameraManager.cs b/BarcodeScanning.Native.Maui/Platform/MaciOS/CameraManager.cs
index f53d21f..d1680b7 100644
--- a/BarcodeScanning.Native.Maui/Platform/MaciOS/CameraManager.cs
+++ b/BarcodeScanning.Native.Maui/Platform/MaciOS/CameraManager.cs
@@ -15,9 +15,6 @@ internal class CameraManager : IDisposable
internal BarcodeView BarcodeView { get => _barcodeView; }
internal CameraView? CameraView { get => _cameraView; }
- private AVCaptureDevice? _captureDevice;
- private AVCaptureInput? _captureInput;
-
private readonly AVCaptureVideoDataOutput _videoDataOutput;
private readonly AVCaptureVideoPreviewLayer _previewLayer;
private readonly AVCaptureSession _captureSession;
@@ -30,6 +27,9 @@ internal class CameraManager : IDisposable
private readonly CameraView? _cameraView;
+ private AVCaptureDevice? _captureDevice;
+ private AVCaptureInput? _captureInput;
+
private const int aimRadius = 8;
internal CameraManager(CameraView cameraView)
diff --git a/BarcodeScanning.Native.Maui/Platform/MaciOS/Methods.cs b/BarcodeScanning.Native.Maui/Platform/MaciOS/Methods.cs
index 714606a..5367335 100644
--- a/BarcodeScanning.Native.Maui/Platform/MaciOS/Methods.cs
+++ b/BarcodeScanning.Native.Maui/Platform/MaciOS/Methods.cs
@@ -150,7 +150,7 @@ internal static BarcodeFormats ConvertFromIOSFormats(VNBarcodeSymbology symbolog
};
}
- private static NSString SessionPresetTranslator(CaptureQuality quality)
+ private static NSString SessionPresetTranslator(CaptureQuality? quality)
{
return quality switch
{
diff --git a/BarcodeScanning.Native.Maui/Shared/BarcodeFormats.cs b/BarcodeScanning.Native.Maui/Shared/BarcodeFormats.cs
index db29c81..30ab688 100644
--- a/BarcodeScanning.Native.Maui/Shared/BarcodeFormats.cs
+++ b/BarcodeScanning.Native.Maui/Shared/BarcodeFormats.cs
@@ -4,24 +4,26 @@
public enum BarcodeFormats
{
None = 0,
- Code128 = 1,
- Code39 = 2,
- Code93 = 4,
- CodaBar = 8,
- DataMatrix = 16,
- Ean13 = 32,
- Ean8 = 64,
- Itf = 128,
- QRCode = 256,
- Upca = 512,
- Upce = 1024,
- Pdf417 = 2048,
- Aztec = 4096,
- MicroQR = 8192,
- MicroPdf417 = 16384,
- I2OF5 = 32768,
- GS1DataBar = 65536,
- MaxiCode = 131072,
- DXFilmEdge = 262144,
- All = 524288
-}
+
+ Code128 = 1 << 0,
+ Code39 = 1 << 1,
+ Code93 = 1 << 2,
+ CodaBar = 1 << 3,
+ DataMatrix = 1 << 4,
+ Ean13 = 1 << 5,
+ Ean8 = 1 << 6,
+ Itf = 1 << 7,
+ QRCode = 1 << 8,
+ Upca = 1 << 9,
+ Upce = 1 << 10,
+ Pdf417 = 1 << 11,
+ Aztec = 1 << 12,
+ MicroQR = 1 << 13,
+ MicroPdf417 = 1 << 14,
+ I2OF5 = 1 << 15,
+ GS1DataBar = 1 << 16,
+ MaxiCode = 1 << 17,
+ DXFilmEdge = 1 << 18,
+
+ All = ~0
+}
\ No newline at end of file