Skip to content

Commit

Permalink
2.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
afriscic committed Nov 25, 2024
1 parent 491fcc7 commit c87a1ec
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<IsAotCompatible>true</IsAotCompatible>
<Nullable>enable</Nullable>
<Version>2.1.0</Version>
<Version>2.1.1</Version>
<Authors>Alen Friščić</Authors>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README.md</PackageReadmeFile>
Expand Down Expand Up @@ -58,8 +58,8 @@
<PackageReference Include="Xamarin.AndroidX.Collection.Ktx" Version="1.4.5.1" />
<PackageReference Include="Xamarin.AndroidX.Fragment.Ktx" Version="1.8.5.1" />

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

<ItemGroup Condition="$(TargetFramework.StartsWith('net9.0-windows'))">
Expand Down
9 changes: 6 additions & 3 deletions BarcodeScanning.Native.Maui/CameraView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,13 @@ internal void DetectionFinished(HashSet<BarcodeResult> 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);
}
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions BarcodeScanning.Native.Maui/Platform/Android/BarcodeAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<BarcodeResult> _barcodeResults;
private readonly CameraManager _cameraManager;
private readonly Lock _resultsLock;

private IBarcodeScanner? _barcodeScanner;
private CoordinateTransform? _coordinateTransform;
private IImageProxy? _proxy;
Expand All @@ -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<BarcodeResult> _barcodeResults;
private readonly CameraManager _cameraManager;
private readonly Lock _resultsLock;
private Rect _previewViewRect = new();

internal BarcodeAnalyzer(CameraManager cameraManager)
{
Expand Down
9 changes: 5 additions & 4 deletions BarcodeScanning.Native.Maui/Platform/Android/CameraManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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;
}
}

Expand Down
4 changes: 2 additions & 2 deletions BarcodeScanning.Native.Maui/Platform/Android/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down
18 changes: 7 additions & 11 deletions BarcodeScanning.Native.Maui/Platform/MaciOS/BarcodeAnalyzer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -29,9 +29,9 @@ internal BarcodeAnalyzer(CameraManager cameraManager)
_detectBarcodesRequest = new VNDetectBarcodesRequest((request, error) =>
{
if (error is null)
result = request.GetResults<VNBarcodeObservation>();
_result = request.GetResults<VNBarcodeObservation>();
else
result = [];
_result = [];
});
_sequenceRequestHandler = new VNSequenceRequestHandler();

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions BarcodeScanning.Native.Maui/Platform/MaciOS/CameraManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion BarcodeScanning.Native.Maui/Platform/MaciOS/Methods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
44 changes: 23 additions & 21 deletions BarcodeScanning.Native.Maui/Shared/BarcodeFormats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit c87a1ec

Please sign in to comment.