1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Rendering - Fixed render scale not applying until reboot

Debugger - Added button to save the next frame
Device visualizer - Fixed LED positioning on some devices
This commit is contained in:
Robert 2021-03-17 19:55:49 +01:00
parent 456af693b0
commit 11535508bc
4 changed files with 44 additions and 2 deletions

View File

@ -44,6 +44,7 @@ namespace Artemis.Core.Services
Surface.Exception += SurfaceOnException;
Surface.SurfaceLayoutChanged += SurfaceOnLayoutChanged;
_targetFrameRateSetting.SettingChanged += TargetFrameRateSettingOnSettingChanged;
_renderScaleSetting.SettingChanged += RenderScaleSettingOnSettingChanged;
_enabledDevices = new List<ArtemisDevice>();
_devices = new List<ArtemisDevice>();
_ledMap = new Dictionary<Led, ArtemisLed>();
@ -196,6 +197,10 @@ namespace Artemis.Core.Services
}
}
private void RenderScaleSettingOnSettingChanged(object? sender, EventArgs e)
{
_texture?.Invalidate();
}
public void Dispose()
{

View File

@ -78,7 +78,7 @@ namespace Artemis.UI.Shared
penBrush.Freeze();
// Create transparent pixels covering the entire LedRect so the image size matched the LedRect size
drawingContext.DrawRectangle(new SolidColorBrush(Colors.Transparent), null, LedRect);
drawingContext.DrawRectangle(new SolidColorBrush(Colors.Transparent), new Pen(new SolidColorBrush(Colors.Transparent), 1), LedRect);
// Translate to the top-left of the LedRect
drawingContext.PushTransform(new TranslateTransform(LedRect.X, LedRect.Y));
// Render the LED geometry

View File

@ -5,6 +5,7 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Artemis.UI.Screens.Settings.Debug.Tabs"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:s="https://github.com/canton7/Stylet"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800" d:DataContext="{d:DesignInstance local:RenderDebugViewModel}">
<Grid>
@ -12,6 +13,7 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Grid.Row="0" TextWrapping="Wrap">
In this window you can view the inner workings of Artemis.
@ -38,5 +40,9 @@
<materialDesign:Card Grid.Row="2" Margin="0,5,0,0" Background="{StaticResource Checkerboard}">
<Image Source="{Binding CurrentFrame}" />
</materialDesign:Card>
<StackPanel Grid.Row="3" Margin="0 5 0 0">
<Button HorizontalAlignment="Left" Command="{s:Action SaveFrame}">SAVE FRAME</Button>
</StackPanel>
</Grid>
</UserControl>

View File

@ -1,9 +1,11 @@
using System;
using System.IO;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using Artemis.Core;
using Artemis.Core.Services;
using Ookii.Dialogs.Wpf;
using SkiaSharp;
using SkiaSharp.Views.WPF;
using Stylet;
@ -17,6 +19,7 @@ namespace Artemis.UI.Screens.Settings.Debug.Tabs
private ImageSource _currentFrame;
private int _renderWidth;
private int _renderHeight;
private string _frameTargetPath;
public RenderDebugViewModel(ICoreService coreService)
{
@ -48,6 +51,20 @@ namespace Artemis.UI.Screens.Settings.Debug.Tabs
set => SetAndNotify(ref _renderHeight, value);
}
public void SaveFrame()
{
VistaSaveFileDialog dialog = new VistaSaveFileDialog {Filter = "Portable network graphic (*.png)|*.png", Title = "Save render frame"};
dialog.FileName = $"Artemis frame {DateTime.Now:yyyy-dd-M--HH-mm-ss}.png";
bool? result = dialog.ShowDialog();
if (result == true)
{
if (dialog.FileName.EndsWith(".png"))
_frameTargetPath = dialog.FileName;
else
_frameTargetPath = dialog.FileName + ".png";
}
}
protected override void OnActivate()
{
_coreService.FrameRendered += CoreServiceOnFrameRendered;
@ -76,8 +93,22 @@ namespace Artemis.UI.Screens.Settings.Debug.Tabs
CurrentFrame = e.Texture.Bitmap.ToWriteableBitmap();
return;
}
using SKImage skImage = SKImage.FromPixels(e.Texture.Bitmap.PeekPixels());
if (_frameTargetPath != null)
{
using (SKData data = skImage.Encode(SKEncodedImageFormat.Png, 100))
{
using (FileStream stream = File.OpenWrite(_frameTargetPath))
{
data.SaveTo(stream);
}
}
_frameTargetPath = null;
}
SKImageInfo info = new(skImage.Width, skImage.Height);
writable.Lock();
using (SKPixmap pixmap = new(info, writable.BackBuffer, writable.BackBufferStride))