Compare commits

..

No commits in common. "a971ceff2c3e60cd11ba5d8bdb7daa3b8e984f75" and "593d845b54ec7e608719d09289c348391512ccd2" have entirely different histories.

8 changed files with 70 additions and 74 deletions

View File

@ -1,9 +0,0 @@
<Project>
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
</Project>

View File

@ -1,22 +0,0 @@
<Project>
<PropertyGroup>
<ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Avalonia" Version="12.1.2" />
<PackageVersion Include="Avalonia.Controls.DataGrid" Version="12.1.2" />
<PackageVersion Include="Avalonia.Desktop" Version="12.1.2" />
<PackageVersion Include="Avalonia.Fonts.Inter" Version="12.1.2" />
<PackageVersion Include="Avalonia.Themes.Fluent" Version="12.1.2" />
<PackageVersion Include="AvaloniaUI.DiagnosticsSupport" Version="2.2.3" />
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.4.2" />
<PackageVersion Include="FFmpeg.AutoGen" Version="9.0.1.1" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="10.0.12" />
<PackageVersion Include="Microsoft.ML.OnnxRuntime.DirectML" Version="1.24.4" />
<PackageVersion Include="Onnxify" Version="0.3.11" />
<PackageVersion Include="OpenCvSharp4" Version="4.13.0.20260627" />
<PackageVersion Include="OpenCvSharp4.runtime.win" Version="4.13.0.20260627" />
<PackageVersion Include="Spectre.Console" Version="0.57.2" />
<PackageVersion Include="UltraFaceDotNet" Version="1.0.0.2" />
</ItemGroup>
</Project>

View File

@ -1,42 +1,62 @@
using System.Buffers;
namespace Splitter_UI.Services;
namespace Splitter_UI.Services;
public sealed class BufferPool : IBufferPool
{
public sealed class Entry : IDisposable
{
private bool _disposed;
public sealed class Entry
{
public readonly int Width;
public readonly int Height;
public readonly byte[] Bgr;
public readonly byte[] Bgra;
public byte[] Bgr;
public byte[] Bgra;
internal Entry(int w, int h)
public Entry(int w, int h)
{
Width = w;
Height = h;
Bgr = ArrayPool<byte>.Shared.Rent(w * h * 3);
Bgra = ArrayPool<byte>.Shared.Rent(w * h * 4);
Bgr = new byte[w * h * 3];
Bgra = new byte[w * h * 4];
}
public void Dispose()
{
if (_disposed) return;
_disposed = true;
override public string ToString() => $"Entry({Width}x{Height})";
}
ArrayPool<byte>.Shared.Return(Bgr);
ArrayPool<byte>.Shared.Return(Bgra);
}
private readonly Dictionary<(int w, int h), LinkedListNode<Entry>> _map;
private readonly LinkedList<Entry> _lru;
private readonly int _capacity;
private readonly Lock _lock = new();
public override string ToString() => $"Entry({Width}x{Height})";
public BufferPool()
{
_capacity = 8;
_map = new Dictionary<(int w, int h), LinkedListNode<Entry>>(_capacity);
_lru = new LinkedList<Entry>();
}
public Entry Get(int w, int h)
{
return new Entry(w, h);
var key = (w, h);
if (_map.TryGetValue(key, out var node))
{
_lru.Remove(node);
_lru.AddLast(node);
return node.Value;
}
var created = new Entry(w, h);
var newNode = new LinkedListNode<Entry>(created);
_lru.AddLast(newNode);
_map[key] = newNode;
if (_lru.Count > _capacity)
{
var first = _lru.First!;
_lru.RemoveFirst();
_map.Remove((first.Value.Width, first.Value.Height));
}
return created;
}
}

View File

@ -22,7 +22,7 @@ public sealed class MatToBitmapConverter(IBufferPool _pool) : IMatToBitmapConver
lock (_sync)
{
using var entry = _pool.Get(w, h);
var entry = _pool.Get(w, h);
var src = mat;
if (!src.IsContinuous())
@ -65,7 +65,7 @@ public sealed class MatToBitmapConverter(IBufferPool _pool) : IMatToBitmapConver
public Bitmap Convert(byte[] bgr, int width, int height, Bitmap? existing = null)
{
using var entry = _pool.Get(width, height);
var entry = _pool.Get(width, height);
ConvertBgrToBgra(bgr, entry.Bgra, width, height);
if (existing is WriteableBitmap wb &&

View File

@ -59,7 +59,7 @@ public sealed class ThumbnailService : IThumbnailService
height ??= ThumbHeight;
skip ??= TimeSpan.Zero;
using var entry = _pool.Get(width.Value, height.Value);
var entry = _pool.Get(width.Value, height.Value);
var ok = await DecodeFrameAsync(
entry.Bgr,

View File

@ -1,6 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>x64</PlatformTarget>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
@ -14,17 +18,17 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Avalonia" />
<PackageReference Include="Avalonia.Controls.DataGrid" />
<PackageReference Include="Avalonia.Desktop" />
<PackageReference Include="Avalonia.Themes.Fluent" />
<PackageReference Include="Avalonia.Fonts.Inter" />
<PackageReference Include="AvaloniaUI.DiagnosticsSupport">
<PackageReference Include="Avalonia" Version="12.0.4" />
<PackageReference Include="Avalonia.Controls.DataGrid" Version="12.0.0" />
<PackageReference Include="Avalonia.Desktop" Version="12.0.4" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="12.0.4" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="12.0.4" />
<PackageReference Include="AvaloniaUI.DiagnosticsSupport" Version="2.2.3">
<IncludeAssets Condition="'$(Configuration)' != 'Debug'">None</IncludeAssets>
<PrivateAssets Condition="'$(Configuration)' != 'Debug'">All</PrivateAssets>
</PackageReference>
<PackageReference Include="CommunityToolkit.Mvvm" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.4.2" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.9" />
</ItemGroup>
<ItemGroup>

View File

@ -47,7 +47,6 @@ public sealed class CameraController
_cropHeight = cropHeight;
_kalman = kalman;
_cmd = cmd;
DefaultCenter = new Point2f(videoWidth * _cmd.GravitateTo.X, videoHeight * _cmd.GravitateTo.Y);
_cameraCenter = DefaultCenter;
_state = TrackState.Tracking;
@ -59,7 +58,7 @@ public sealed class CameraController
_kalman.Reset(_cameraCenter);
}
private Point2f DefaultCenter { get; set; }
private Point2f DefaultCenter => _cmd.GravitateTo;
public int LostFrames => _lostFrames;
public Point2f CameraCenter => _cameraCenter;
@ -149,7 +148,7 @@ public sealed class CameraController
smoothedCenter = _kalman.Update(objectCenter);
var driftEasing = 0.01f;
var fallbackCenter = DefaultCenter;
var fallbackCenter = new Point2f(_videoWidth / 2f, _videoHeight / 2f);
_cameraCenter = new Point2f(
_cameraCenter.X + (fallbackCenter.X - _cameraCenter.X) * driftEasing,

View File

@ -2,6 +2,10 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<PlatformTarget>x64</PlatformTarget>
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
@ -53,13 +57,13 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="FFmpeg.AutoGen" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.DirectML" />
<PackageReference Include="Onnxify" />
<PackageReference Include="OpenCvSharp4" />
<PackageReference Include="OpenCvSharp4.runtime.win" />
<PackageReference Include="Spectre.Console" />
<PackageReference Include="UltraFaceDotNet" />
<PackageReference Include="FFmpeg.AutoGen" Version="8.1.0" />
<PackageReference Include="Microsoft.ML.OnnxRuntime.DirectML" Version="1.24.4" />
<PackageReference Include="Onnxify" Version="0.3.4" />
<PackageReference Include="OpenCvSharp4" Version="4.13.0.20260602" />
<PackageReference Include="OpenCvSharp4.runtime.win" Version="4.13.0.20260602" />
<PackageReference Include="Spectre.Console" Version="0.57.0" />
<PackageReference Include="UltraFaceDotNet" Version="1.0.0.2" />
</ItemGroup>
</Project>