Skip to content

Commit c87a1ec

Browse files
committed
2.1.1
1 parent 491fcc7 commit c87a1ec

File tree

11 files changed

+56
-54
lines changed

11 files changed

+56
-54
lines changed

BarcodeScanning.Native.Maui/BarcodeScanning.Native.Maui.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1111
<IsAotCompatible>true</IsAotCompatible>
1212
<Nullable>enable</Nullable>
13-
<Version>2.1.0</Version>
13+
<Version>2.1.1</Version>
1414
<Authors>Alen Friščić</Authors>
1515
<PackageLicenseExpression>MIT</PackageLicenseExpression>
1616
<PackageReadmeFile>README.md</PackageReadmeFile>
@@ -58,8 +58,8 @@
5858
<PackageReference Include="Xamarin.AndroidX.Collection.Ktx" Version="1.4.5.1" />
5959
<PackageReference Include="Xamarin.AndroidX.Fragment.Ktx" Version="1.8.5.1" />
6060

61-
<AndroidNativeLibrary Include="**\Android\Native\arm64-v8a\InvertBytes.so" />
62-
<AndroidNativeLibrary Include="**\Android\Native\armeabi-v7a\InvertBytes.so" />
61+
<AndroidNativeLibrary Include="**\Android\Native\arm64-v8a\libInvertBytes.so" />
62+
<AndroidNativeLibrary Include="**\Android\Native\armeabi-v7a\libInvertBytes.so" />
6363
</ItemGroup>
6464

6565
<ItemGroup Condition="$(TargetFramework.StartsWith('net9.0-windows'))">

BarcodeScanning.Native.Maui/CameraView.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,13 @@ internal void DetectionFinished(HashSet<BarcodeResult> barCodeResults, Lock resu
335335
_poolingTimer.Start();
336336
}
337337

338-
foreach (var result in barCodeResults)
338+
lock (resultLock)
339339
{
340-
_pooledResults.Remove(result);
341-
_pooledResults.Add(result);
340+
foreach (var result in barCodeResults)
341+
{
342+
_pooledResults.Remove(result);
343+
_pooledResults.Add(result);
344+
}
342345
}
343346
}
344347
}

BarcodeScanning.Native.Maui/Platform/Android/BarcodeAnalyzer.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
using MLKitBarcodeScanning = Xamarin.Google.MLKit.Vision.BarCode.BarcodeScanning;
1313
using Point = Microsoft.Maui.Graphics.Point;
14-
using RectF = Microsoft.Maui.Graphics.RectF;
14+
using Rect = Microsoft.Maui.Graphics.Rect;
1515
using Size = Android.Util.Size;
1616

1717
namespace BarcodeScanning;
@@ -21,6 +21,10 @@ internal class BarcodeAnalyzer : Java.Lang.Object, ImageAnalysis.IAnalyzer, IOnS
2121
public Size DefaultTargetResolution => Methods.TargetResolution(null);
2222
public int TargetCoordinateSystem => ImageAnalysis.CoordinateSystemViewReferenced;
2323

24+
private readonly HashSet<BarcodeResult> _barcodeResults;
25+
private readonly CameraManager _cameraManager;
26+
private readonly Lock _resultsLock;
27+
2428
private IBarcodeScanner? _barcodeScanner;
2529
private CoordinateTransform? _coordinateTransform;
2630
private IImageProxy? _proxy;
@@ -29,11 +33,7 @@ internal class BarcodeAnalyzer : Java.Lang.Object, ImageAnalysis.IAnalyzer, IOnS
2933
private bool _updateCoordinateTransform = false;
3034
private int _transformDegrees = 0;
3135
private Point _previewViewCenter = new();
32-
private RectF _previewViewRect = new();
33-
34-
private readonly HashSet<BarcodeResult> _barcodeResults;
35-
private readonly CameraManager _cameraManager;
36-
private readonly Lock _resultsLock;
36+
private Rect _previewViewRect = new();
3737

3838
internal BarcodeAnalyzer(CameraManager cameraManager)
3939
{

BarcodeScanning.Native.Maui/Platform/Android/CameraManager.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ internal class CameraManager : IDisposable
2525

2626
internal CameraState? OpenedCameraState { get; set; }
2727

28-
private ICameraInfo? _currentCameraInfo;
29-
3028
private readonly BarcodeAnalyzer _barcodeAnalyzer;
3129
private readonly BarcodeView _barcodeView;
3230
private readonly Context _context;
@@ -40,6 +38,8 @@ internal class CameraManager : IDisposable
4038

4139
private readonly CameraView? _cameraView;
4240

41+
private ICameraInfo? _currentCameraInfo;
42+
4343
private const int aimRadius = 25;
4444

4545
internal CameraManager(CameraView cameraView, Context context)
@@ -186,8 +186,9 @@ internal void UpdateResolution()
186186
resolutionBuilder.SetAllowedResolutionMode(ResolutionSelector.PreferHigherResolutionOverCaptureRate);
187187
resolutionBuilder.SetResolutionStrategy(analysisStrategy);
188188
resolutionBuilder.SetAspectRatioStrategy(AspectRatioStrategy.Ratio169FallbackAutoStrategy);
189-
_cameraController.ImageAnalysisResolutionSelector = resolutionBuilder.Build();
190-
_cameraController.PreviewResolutionSelector = resolutionBuilder.Build();
189+
var selector = resolutionBuilder.Build();
190+
_cameraController.ImageAnalysisResolutionSelector = selector;
191+
_cameraController.PreviewResolutionSelector = selector;
191192
}
192193
}
193194

BarcodeScanning.Native.Maui/Platform/Android/Methods.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ private static void ProcessBarcodeResult(Java.Lang.Object? inputResults, HashSet
8585
}
8686
}
8787

88-
[LibraryImport("InvertBytes.so")]
88+
[LibraryImport("libInvertBytes.so")]
8989
private static partial int InvertBytes(IntPtr data, int length);
9090

9191
internal static void InvertLuminance(Image image)
@@ -182,7 +182,7 @@ internal static Size TargetResolution(CaptureQuality? captureQuality)
182182
{
183183
return captureQuality switch
184184
{
185-
CaptureQuality.Low => new Size(640, 480),
185+
CaptureQuality.Low => new Size(854, 480),
186186
CaptureQuality.Medium => new Size(1280, 720),
187187
CaptureQuality.High => new Size(1920, 1080),
188188
CaptureQuality.Highest => new Size(3840, 2160),

BarcodeScanning.Native.Maui/Platform/Android/Native/arm64-v8a/InvertBytes.so renamed to BarcodeScanning.Native.Maui/Platform/Android/Native/arm64-v8a/libInvertBytes.so

File renamed without changes.

BarcodeScanning.Native.Maui/Platform/Android/Native/armeabi-v7a/InvertBytes.so renamed to BarcodeScanning.Native.Maui/Platform/Android/Native/armeabi-v7a/libInvertBytes.so

File renamed without changes.

BarcodeScanning.Native.Maui/Platform/MaciOS/BarcodeAnalyzer.cs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ internal class BarcodeAnalyzer : AVCaptureVideoDataOutputSampleBufferDelegate
1818
private readonly VNSequenceRequestHandler _sequenceRequestHandler;
1919

2020
private Point _previewCenter = new();
21-
private RectF _previewRect = new();
22-
private VNBarcodeObservation[] result = [];
21+
private Rect _previewRect = new();
22+
private VNBarcodeObservation[] _result = [];
2323

2424
internal BarcodeAnalyzer(CameraManager cameraManager)
2525
{
@@ -29,9 +29,9 @@ internal BarcodeAnalyzer(CameraManager cameraManager)
2929
_detectBarcodesRequest = new VNDetectBarcodesRequest((request, error) =>
3030
{
3131
if (error is null)
32-
result = request.GetResults<VNBarcodeObservation>();
32+
_result = request.GetResults<VNBarcodeObservation>();
3333
else
34-
result = [];
34+
_result = [];
3535
});
3636
_sequenceRequestHandler = new VNSequenceRequestHandler();
3737

@@ -69,16 +69,12 @@ public override void DidOutputSampleBuffer(AVCaptureOutput captureOutput, CMSamp
6969
}
7070
}
7171

72-
7372
_sequenceRequestHandler?.Perform([_detectBarcodesRequest], sampleBuffer, out _);
7473

75-
if (result is null)
76-
return;
77-
7874
lock (_resultsLock)
7975
{
8076
_barcodeResults.Clear();
81-
foreach (var barcode in result)
77+
foreach (var barcode in _result)
8278
{
8379
if (string.IsNullOrEmpty(barcode.PayloadStringValue))
8480
continue;
@@ -96,8 +92,8 @@ public override void DidOutputSampleBuffer(AVCaptureOutput captureOutput, CMSamp
9692

9793
if (_cameraManager?.CameraView?.ViewfinderMode ?? false)
9894
{
99-
_previewRect.Width = (float)_cameraManager.PreviewLayer.Bounds.Width;
100-
_previewRect.Height = (float)_cameraManager.PreviewLayer.Bounds.Height;
95+
_previewRect.Width = _cameraManager.PreviewLayer.Bounds.Width;
96+
_previewRect.Height = _cameraManager.PreviewLayer.Bounds.Height;
10197

10298
if (!_previewRect.Contains(barcodeResult.PreviewBoundingBox))
10399
continue;

BarcodeScanning.Native.Maui/Platform/MaciOS/CameraManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ internal class CameraManager : IDisposable
1515
internal BarcodeView BarcodeView { get => _barcodeView; }
1616
internal CameraView? CameraView { get => _cameraView; }
1717

18-
private AVCaptureDevice? _captureDevice;
19-
private AVCaptureInput? _captureInput;
20-
2118
private readonly AVCaptureVideoDataOutput _videoDataOutput;
2219
private readonly AVCaptureVideoPreviewLayer _previewLayer;
2320
private readonly AVCaptureSession _captureSession;
@@ -30,6 +27,9 @@ internal class CameraManager : IDisposable
3027

3128
private readonly CameraView? _cameraView;
3229

30+
private AVCaptureDevice? _captureDevice;
31+
private AVCaptureInput? _captureInput;
32+
3333
private const int aimRadius = 8;
3434

3535
internal CameraManager(CameraView cameraView)

BarcodeScanning.Native.Maui/Platform/MaciOS/Methods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ internal static BarcodeFormats ConvertFromIOSFormats(VNBarcodeSymbology symbolog
150150
};
151151
}
152152

153-
private static NSString SessionPresetTranslator(CaptureQuality quality)
153+
private static NSString SessionPresetTranslator(CaptureQuality? quality)
154154
{
155155
return quality switch
156156
{

0 commit comments

Comments
 (0)