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

Removed my 'optimisations' from LED samples and made it a lot faster 😓

Expanded settings
This commit is contained in:
Robert 2019-12-20 13:43:19 +01:00
parent b1870e9e64
commit 62a9c19ae1
5 changed files with 129 additions and 79 deletions

View File

@ -46,6 +46,7 @@ namespace Artemis.Core.RGB.NET
public Dictionary<BrushRenderTarget, Color> RenderedTargets { get; } = new Dictionary<BrushRenderTarget, Color>();
public Scale Scale { get; set; }
public Scale RenderedScale { get; private set; }
public SKBitmap Bitmap { get; private set; }
#endregion
@ -85,7 +86,6 @@ namespace Artemis.Core.RGB.NET
{
var sampleSize = _sampleSizeSetting.Value;
var sampleDepth = Math.Sqrt(sampleSize).RoundToInt();
var pixelSpan = Bitmap.GetPixelSpan();
foreach (var renderTarget in renderTargets)
{
@ -94,7 +94,8 @@ namespace Artemis.Core.RGB.NET
(float) ((renderTarget.Rectangle.Location.X + 4) * Scale.Horizontal),
(float) ((renderTarget.Rectangle.Location.Y + 4) * Scale.Vertical),
(float) ((renderTarget.Rectangle.Size.Width - 8) * Scale.Horizontal),
(float) ((renderTarget.Rectangle.Size.Height - 8) * Scale.Vertical));
(float) ((renderTarget.Rectangle.Size.Height - 8) * Scale.Vertical)
);
var verticalSteps = rect.Height / (sampleDepth - 1);
var horizontalSteps = rect.Width / (sampleDepth - 1);
@ -103,6 +104,8 @@ namespace Artemis.Core.RGB.NET
var r = 0;
var g = 0;
var b = 0;
// TODO: Compare this with LINQ, might be quicker and cleaner
for (var horizontalStep = 0; horizontalStep < sampleDepth; horizontalStep++)
{
for (var verticalStep = 0; verticalStep < sampleDepth; verticalStep++)
@ -112,11 +115,11 @@ namespace Artemis.Core.RGB.NET
if (x < 0 || x > Bitmap.Width || y < 0 || y > Bitmap.Height)
continue;
var (pixelA, pixelR, pixelG, pixelB) = GetRgbColor(pixelSpan, x, y);
a += pixelA;
r += pixelR;
g += pixelG;
b += pixelB;
var color = Bitmap.GetPixel(x, y);
a += color.Alpha;
r += color.Red;
g += color.Green;
b += color.Blue;
// Uncomment to view the sample pixels in the debugger, need a checkbox in the actual debugger but this was a quickie
// Bitmap.SetPixel(x, y, new SKColor(0, 255, 0));
@ -127,8 +130,6 @@ namespace Artemis.Core.RGB.NET
}
}
public Scale RenderedScale { get; private set; }
private void CreateBitmap(Rectangle rectangle)
{
var width = Math.Min((rectangle.Location.X + rectangle.Size.Width) * Scale.Horizontal, 4096);
@ -136,21 +137,6 @@ namespace Artemis.Core.RGB.NET
Bitmap = new SKBitmap(new SKImageInfo(width.RoundToInt(), height.RoundToInt()));
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private Tuple<int, int, int, int> GetRgbColor(in ReadOnlySpan<byte> pixelSpan, float x, float y)
{
var index = ((int) y * Bitmap.Width + (int) x) * 4;
if (index + 3 > pixelSpan.Length)
return new Tuple<int, int, int, int>(0, 0, 0, 0);
var b = pixelSpan[index];
var g = pixelSpan[index + 1];
var r = pixelSpan[index + 2];
var a = pixelSpan[index + 3];
return new Tuple<int, int, int, int>(a, r, g, b);
}
/// <inheritdoc />
public virtual void PerformFinalize()
{

View File

@ -201,6 +201,7 @@
</Compile>
<Compile Include="Screens\Module\ProfileEditor\Visualization\Tools\ViewpointMoveToolViewModel.cs" />
<Compile Include="Screens\Module\ProfileEditor\Visualization\Tools\VisualizationToolViewModel.cs" />
<Compile Include="Screens\Settings\Tabs\Plugins\PluginSettingsViewModel.cs" />
<Compile Include="Screens\Sidebar\SidebarView.xaml.cs">
<DependentUpon>SidebarView.xaml</DependentUpon>
</Compile>
@ -533,5 +534,5 @@
</Target>
<Target Name="RemoveTranslationsAfterBuild" AfterTargets="AfterBuild">
<RemoveDir Directories="@(FluentValidationExcludedCultures->'$(OutputPath)%(Filename)')" />
</Target>
</Target>
</Project>

View File

@ -78,11 +78,58 @@
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<Button Style="{StaticResource MaterialDesignOutlinedButton}" Command="{s:Action ShowDebugger}">
<Button Style="{StaticResource MaterialDesignOutlinedButton}" Command="{s:Action ShowDebugger}" Width="150">
SHOW DEBUGGER
</Button>
</StackPanel>
</Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" VerticalAlignment="Center">
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}">Logs</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}">
Opens the directory where logs are stored.
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<Button Style="{StaticResource MaterialDesignOutlinedButton}" Command="{s:Action ShowLogsFolder}" Width="150">
SHOW LOGS
</Button>
</StackPanel>
</Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0" VerticalAlignment="Center">
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}">Application files</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}">
Opens the directory where application files like plugins and settings are stored.
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<Button Style="{StaticResource MaterialDesignOutlinedButton}" Command="{s:Action ShowDataFolder}" Width="150">
SHOW APP FILES
</Button>
</StackPanel>
</Grid>
</StackPanel>
</materialDesign:Card>
@ -106,7 +153,7 @@
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<ComboBox Width="80" SelectedItem="{Binding SelectedRenderScale}" ItemsSource="{Binding RenderScales}" DisplayMemberPath="Item1"/>
<ComboBox Width="80" SelectedItem="{Binding SelectedRenderScale}" ItemsSource="{Binding RenderScales}" DisplayMemberPath="Item1" />
</StackPanel>
</Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
@ -127,7 +174,7 @@
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<ComboBox Width="80" SelectedItem="{Binding SelectedTargetFrameRate}" ItemsSource="{Binding TargetFrameRates}" DisplayMemberPath="Item1"/>
<ComboBox Width="80" SelectedItem="{Binding SelectedTargetFrameRate}" ItemsSource="{Binding TargetFrameRates}" DisplayMemberPath="Item1" />
</StackPanel>
</Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
@ -144,12 +191,11 @@
<StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}">LED sample size</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignBody1TextBlock}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" TextWrapping="Wrap">
Sets the amount of samples that is taken to determine each LEDs color.
Best you leave it on 1 but included for completeness, a higher value increases CPU-usage quite rapidly.
Sets the amount of samples that is taken to determine each LEDs color. This means a LED can be semi off if it is not completely covered by a color.
</TextBlock>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1" VerticalAlignment="Center">
<ComboBox Width="80" SelectedItem="{Binding SampleSize}" ItemsSource="{Binding SampleSizes}"/>
<ComboBox Width="80" SelectedItem="{Binding SampleSize}" ItemsSource="{Binding SampleSizes}" />
</StackPanel>
</Grid>
</StackPanel>
@ -159,64 +205,37 @@
</TabItem>
<TabItem Header="PLUGINS" TextElement.Foreground="{DynamicResource MaterialDesignBody}">
<DockPanel Margin="15">
<TextBlock DockPanel.Dock="Top">Below you view and manage your plugins. To find and install new plugins use the workshop (TODO).</TextBlock>
<TextBlock DockPanel.Dock="Top">The list below shows all loaded plugins. You can't really edit it right now. If you're missing something, view your logs folder.</TextBlock>
<ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Disabled">
<DataGrid Margin="0 8 0 0"
ItemsSource="{Binding Items3}"
ItemsSource="{Binding Plugins}"
CanUserSortColumns="True"
CanUserAddRows="False"
AutoGenerateColumns="False"
materialDesign:DataGridAssist.CellPadding="13 8 8 8"
materialDesign:DataGridAssist.ColumnHeaderPadding="8">
<DataGrid.Columns>
<DataGridCheckBoxColumn Binding="{Binding IsSelected}"
<DataGridTextColumn Binding="{Binding Type}" Header="Type" IsReadOnly="True"/>
<DataGridTextColumn Binding="{Binding Name}" Header="Name" IsReadOnly="True" Width="*"/>
<DataGridTextColumn Binding="{Binding Description}" Header="Description" IsReadOnly="True" Width="*"/>
<DataGridTextColumn Binding="{Binding Version}" Header="Version" IsReadOnly="True"/>
<DataGridCheckBoxColumn Header="Enabled"
Binding="{Binding IsEnabled}"
ElementStyle="{StaticResource MaterialDesignDataGridCheckBoxColumnStyle}"
EditingElementStyle="{StaticResource MaterialDesignDataGridCheckBoxColumnEditingStyle}">
<DataGridCheckBoxColumn.Header>
<!--padding to allow hit test to pass thru for sorting -->
<Border Background="Transparent" Padding="6 0 6 0" HorizontalAlignment="Center">
<CheckBox HorizontalAlignment="Center"
DataContext="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}, Path=DataContext}"
IsChecked="{Binding IsAllItems3Selected}" />
</Border>
</DataGridCheckBoxColumn.Header>
</DataGridCheckBoxColumn>
<DataGridTextColumn Binding="{Binding Code}" Header="Code" EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}" />
<!-- if you want to use the pop up style (MaterialDesignDataGridTextColumnPopupEditingStyle), you must use MaterialDataGridTextColumn -->
<materialDesign:MaterialDataGridTextColumn Binding="{Binding Name}"
Header="Name"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}" />
<!-- set a max length to get an indicator in the editor -->
<materialDesign:MaterialDataGridTextColumn Binding="{Binding Description}"
Header="Description"
MaxLength="255"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}" />
<materialDesign:MaterialDataGridTextColumn Binding="{Binding Numeric}"
Header="Number with long header"
Width="120"
EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}">
<DataGridTextColumn.HeaderStyle>
<DataGridCheckBoxColumn.HeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}" BasedOn="{StaticResource MaterialDesignDataGridColumnHeader}">
<Setter Property="HorizontalAlignment" Value="Right" />
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock TextWrapping="Wrap" Text="{Binding}" TextAlignment="Right" />
<TextBlock Text="{Binding}" TextAlignment="Right" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGridTextColumn.HeaderStyle>
<DataGridTextColumn.ElementStyle>
<Style TargetType="{x:Type TextBlock}">
<Setter Property="HorizontalAlignment" Value="Right" />
</Style>
</DataGridTextColumn.ElementStyle>
</materialDesign:MaterialDataGridTextColumn>
<!-- use custom combo box column to get better combos. Use ItemsSourceBinding as your binding template to be applied to each combo -->
<materialDesign:MaterialDataGridComboBoxColumn Header="Food"
SelectedValueBinding="{Binding Food}"
ItemsSourceBinding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.Foods}" />
</DataGridCheckBoxColumn.HeaderStyle>
</DataGridCheckBoxColumn>
</DataGrid.Columns>
</DataGrid>
</ScrollViewer>

View File

@ -1,11 +1,17 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using Artemis.Core;
using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Services;
using Artemis.Core.Services.Interfaces;
using Artemis.Core.Services.Storage.Interfaces;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.Settings.Debug;
using Artemis.UI.Screens.Settings.Tabs.Devices;
using Artemis.UI.Screens.Settings.Tabs.Plugins;
using MaterialDesignThemes.Wpf;
using Ninject;
using Stylet;
@ -18,10 +24,12 @@ namespace Artemis.UI.Screens.Settings
private readonly IKernel _kernel;
private readonly ISettingsService _settingsService;
private readonly ISurfaceService _surfaceService;
private readonly IPluginService _pluginService;
private readonly IWindowManager _windowManager;
public SettingsViewModel(IKernel kernel,
ISurfaceService surfaceService,
IPluginService pluginService,
IWindowManager windowManager,
ISettingsService settingsService,
IDeviceSettingsViewModelFactory deviceSettingsViewModelFactory)
@ -32,12 +40,13 @@ namespace Artemis.UI.Screens.Settings
_kernel = kernel;
_surfaceService = surfaceService;
_pluginService = pluginService;
_windowManager = windowManager;
_settingsService = settingsService;
_deviceSettingsViewModelFactory = deviceSettingsViewModelFactory;
DeviceSettingsViewModels = new BindableCollection<DeviceSettingsViewModel>();
Plugins = new BindableCollection<PluginSettingsViewModel>();
RenderScales = new List<Tuple<string, double>> {new Tuple<string, double>("10%", 0.1)};
for (var i = 25; i <= 100; i += 25)
RenderScales.Add(new Tuple<string, double>(i + "%", i / 100.0));
@ -50,11 +59,11 @@ namespace Artemis.UI.Screens.Settings
SampleSizes = new List<int> {1, 9};
}
public List<int> SampleSizes { get; set; }
public BindableCollection<DeviceSettingsViewModel> DeviceSettingsViewModels { get; set; }
public List<Tuple<string, int>> TargetFrameRates { get; set; }
public List<Tuple<string, double>> RenderScales { get; set; }
public List<int> SampleSizes { get; set; }
public BindableCollection<DeviceSettingsViewModel> DeviceSettingsViewModels { get; set; }
public BindableCollection<PluginSettingsViewModel> Plugins { get; set; }
public Tuple<string, double> SelectedRenderScale
{
@ -66,7 +75,7 @@ namespace Artemis.UI.Screens.Settings
{
get => TargetFrameRates.FirstOrDefault(t => Math.Abs(t.Item2 - TargetFrameRate) < 0.01);
set => TargetFrameRate = value.Item2;
}
}
public double RenderScale
{
@ -78,7 +87,6 @@ namespace Artemis.UI.Screens.Settings
}
}
public List<Tuple<string, int>> TargetFrameRates { get; set; }
public int TargetFrameRate
{
@ -100,14 +108,17 @@ namespace Artemis.UI.Screens.Settings
}
}
public string Title => "Settings";
protected override void OnActivate()
{
DeviceSettingsViewModels.Clear();
foreach (var device in _surfaceService.ActiveSurface.Devices)
DeviceSettingsViewModels.Add(_deviceSettingsViewModelFactory.Create(device));
// TODO: GetPluginsOfType isn't ideal here as it doesn't include disabled plugins
Plugins.Clear();
foreach (var plugin in _pluginService.GetPluginsOfType<Plugin>())
Plugins.Add(new PluginSettingsViewModel(plugin));
base.OnActivate();
}
@ -115,5 +126,15 @@ namespace Artemis.UI.Screens.Settings
{
_windowManager.ShowWindow(_kernel.Get<DebugViewModel>());
}
public void ShowLogsFolder()
{
Process.Start(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Logs"));
}
public void ShowDataFolder()
{
Process.Start(Constants.DataFolder);
}
}
}

View File

@ -0,0 +1,23 @@
using System;
using Artemis.Core.Plugins.Abstract;
using Stylet;
namespace Artemis.UI.Screens.Settings.Tabs.Plugins
{
public class PluginSettingsViewModel : PropertyChangedBase
{
private readonly Plugin _plugin;
public PluginSettingsViewModel(Plugin plugin)
{
_plugin = plugin;
IsEnabled = true;
}
public string Type => _plugin.GetType().BaseType?.Name ?? _plugin.GetType().Name;
public string Name => _plugin.PluginInfo.Name;
public string Description => "N.Y.I.";
public Version Version => _plugin.PluginInfo.Version;
public bool IsEnabled { get; set; }
}
}