Skip to content

Commit 42c30cc

Browse files
authored
Only select whole camera frames if device has changed (#229)
* Only select whole camera frames if device has changed * chore: Change to var, cleanup
1 parent 371381f commit 42c30cc

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/Baballonia/ViewModels/SplitViewPane/HomePageViewModel.cs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ private void EyeImageUpdateHandler(Mat image)
243243
return;
244244

245245

246-
int channels = image.Channels();
246+
var channels = image.Channels();
247247
if (channels == 1)
248248
{
249249
var width = image.Width;
@@ -301,9 +301,9 @@ void UpdateBitmap(Mat image)
301301
{
302302
using var frameBuffer = _bitmap.Lock();
303303

304-
IntPtr srcPtr = image.Data;
305-
IntPtr destPtr = frameBuffer.Address;
306-
int size = image.Rows * image.Cols * image.ElemSize();
304+
var srcPtr = image.Data;
305+
var destPtr = frameBuffer.Address;
306+
var size = image.Rows * image.Cols * image.ElemSize();
307307

308308
unsafe
309309
{
@@ -619,7 +619,7 @@ private async Task StartCameraWithMaximization(CameraControllerModel model, bool
619619
backend = "";
620620

621621

622-
bool success = false;
622+
var success = false;
623623
switch (model.Camera)
624624
{
625625
case Camera.Face:
@@ -638,7 +638,11 @@ private async Task StartCameraWithMaximization(CameraControllerModel model, bool
638638

639639
if (success)
640640
{
641-
if (startMaximized)
641+
// Only select the entire frame if and only if
642+
// 1) This call originates from the UI, IE a user has requested it
643+
// 2) The current camera differs from the previous (IE, an existing connection was interrupted)
644+
var lastOpenedCameraName = _localSettings.ReadSetting<string>("LastOpened" + model.Name);
645+
if (startMaximized && lastOpenedCameraName != model.DisplayAddress)
642646
{
643647
model.SelectWholeFrame();
644648
}
@@ -705,7 +709,7 @@ private async Task RequestVRCalibration()
705709

706710
public Color GetBaseHighColor()
707711
{
708-
Color color = Colors.White;
712+
var color = Colors.White;
709713
switch (Application.Current!.ActualThemeVariant.ToString())
710714
{
711715
case "Light":

src/Baballonia/Views/HomePageView.axaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Baballonia.Views;
1515

1616
public partial class HomePageView : ViewBase
1717
{
18-
public static FilePickerFileType ONNXAll { get; } = new("ONNX Models")
18+
private static readonly FilePickerFileType OnnxAll = new("ONNX Models")
1919
{
2020
Patterns = ["*.onnx"],
2121
};
@@ -246,7 +246,7 @@ private async void RefreshDevices(object? sender, RoutedEventArgs e)
246246
vm.RightCamera.UpdateCameraDropDown(friendlyNames);
247247
vm.FaceCamera.UpdateCameraDropDown(friendlyNames);
248248
}
249-
catch (Exception exception)
249+
catch (Exception)
250250
{
251251
}
252252

@@ -263,7 +263,7 @@ private async void EyeModelLoad(object? sender, RoutedEventArgs e)
263263
Title = "Select ONNX Model",
264264
AllowMultiple = false,
265265
SuggestedStartLocation = suggestedStartLocation, // Falls back to desktop if Models folder hasn't been created yet
266-
FileTypeFilter = [ONNXAll]
266+
FileTypeFilter = [OnnxAll]
267267
})!;
268268

269269
if (file.Count == 0) return;

0 commit comments

Comments
 (0)