mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-12 21:38:38 +00:00
Calibration - Initial color calibration
This commit is contained in:
parent
d5ff979cbb
commit
af99c256ab
@ -27,6 +27,9 @@ namespace Artemis.Core
|
||||
Rotation = 0;
|
||||
Scale = 1;
|
||||
ZIndex = 1;
|
||||
RedScale = 1;
|
||||
GreenScale = 1;
|
||||
BlueScale = 1;
|
||||
|
||||
deviceProvider.DeviceLayoutPaths.TryGetValue(rgbDevice, out string? layoutPath);
|
||||
LayoutPath = layoutPath;
|
||||
@ -171,6 +174,36 @@ namespace Artemis.Core
|
||||
}
|
||||
}
|
||||
|
||||
public double RedScale
|
||||
{
|
||||
get => DeviceEntity.RedScale;
|
||||
set
|
||||
{
|
||||
DeviceEntity.RedScale = value;
|
||||
OnPropertyChanged(nameof(RedScale));
|
||||
}
|
||||
}
|
||||
|
||||
public double GreenScale
|
||||
{
|
||||
get => DeviceEntity.GreenScale;
|
||||
set
|
||||
{
|
||||
DeviceEntity.GreenScale = value;
|
||||
OnPropertyChanged(nameof(GreenScale));
|
||||
}
|
||||
}
|
||||
|
||||
public double BlueScale
|
||||
{
|
||||
get => DeviceEntity.BlueScale;
|
||||
set
|
||||
{
|
||||
DeviceEntity.BlueScale = value;
|
||||
OnPropertyChanged(nameof(BlueScale));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the path to where the layout of the device was (attempted to be) loaded from
|
||||
/// </summary>
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using RGB.NET.Core;
|
||||
using SkiaSharp;
|
||||
@ -101,7 +101,13 @@ namespace Artemis.Core
|
||||
{
|
||||
Point scaledLocation = renderTarget.Point * Scale;
|
||||
if (scaledLocation.X < Bitmap.Width && scaledLocation.Y < Bitmap.Height)
|
||||
RenderedTargets[renderTarget] = Bitmap.GetPixel(scaledLocation.X.RoundToInt(), scaledLocation.Y.RoundToInt()).ToRgbColor();
|
||||
{
|
||||
var pixel = Bitmap.GetPixel(scaledLocation.X.RoundToInt(), scaledLocation.Y.RoundToInt()).ToRgbColor();
|
||||
var artemisDevice = Surface?.GetArtemisLed(renderTarget.Led)?.Device;
|
||||
if (artemisDevice is not null)
|
||||
pixel = pixel.MultiplyRGB(artemisDevice.RedScale, artemisDevice.GreenScale, artemisDevice.BlueScale);
|
||||
RenderedTargets[renderTarget] = pixel;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -148,8 +154,13 @@ namespace Artemis.Core
|
||||
// Bitmap.SetPixel(x, y, new SKColor(0, 255, 0));
|
||||
}
|
||||
}
|
||||
var pixel = new Color(a / sampleSize, r / sampleSize, g / sampleSize, b / sampleSize);
|
||||
|
||||
RenderedTargets[renderTarget] = new Color(a / sampleSize, r / sampleSize, g / sampleSize, b / sampleSize);
|
||||
var artemisDevice = Surface?.GetArtemisLed(renderTarget.Led)?.Device;
|
||||
if (artemisDevice is not null)
|
||||
pixel = pixel.MultiplyRGB(artemisDevice.RedScale, artemisDevice.GreenScale, artemisDevice.BlueScale);
|
||||
|
||||
RenderedTargets[renderTarget] = pixel;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -15,6 +15,9 @@ namespace Artemis.Storage.Entities.Surface
|
||||
public double Rotation { get; set; }
|
||||
public double Scale { get; set; }
|
||||
public int ZIndex { get; set; }
|
||||
public double RedScale { get; set; }
|
||||
public double GreenScale { get; set; }
|
||||
public double BlueScale { get; set; }
|
||||
|
||||
public List<DeviceInputIdentifierEntity> InputIdentifiers { get; set; }
|
||||
}
|
||||
|
||||
@ -4,37 +4,115 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:surfaceEditor="clr-namespace:Artemis.UI.Screens.SurfaceEditor.Dialogs"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="351.305" d:DesignWidth="262.163"
|
||||
d:DataContext="{d:DesignInstance {x:Type surfaceEditor:SurfaceDeviceConfigViewModel}}">
|
||||
<UserControl.Resources>
|
||||
<shared:SKColorToColorConverter x:Key="SKColorToColorConverter" />
|
||||
</UserControl.Resources>
|
||||
<StackPanel Margin="16">
|
||||
<TextBlock Text="{Binding Title}" Style="{StaticResource MaterialDesignHeadline6TextBlock}" />
|
||||
<TextBlock Text="Note: These are not being validated yet" Style="{StaticResource MaterialDesignSubtitle1TextBlock}" />
|
||||
<TextBlock Text="{Binding Title}"
|
||||
Style="{StaticResource MaterialDesignHeadline6TextBlock}" />
|
||||
<TextBlock Text="Note: These are not being validated yet"
|
||||
Style="{StaticResource MaterialDesignSubtitle1TextBlock}" />
|
||||
|
||||
<TextBox materialDesign:HintAssist.Hint="X-coordinate"
|
||||
materialDesign:TextFieldAssist.SuffixText="mm"
|
||||
Text="{Binding X, UpdateSourceTrigger=PropertyChanged}"
|
||||
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
|
||||
Margin="0 10" />
|
||||
<TextBox materialDesign:HintAssist.Hint="Y-coordinate"
|
||||
materialDesign:TextFieldAssist.SuffixText="mm"
|
||||
Text="{Binding Y, UpdateSourceTrigger=PropertyChanged}"
|
||||
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
|
||||
Margin="0 10" />
|
||||
<TextBox materialDesign:HintAssist.Hint="Scale"
|
||||
materialDesign:TextFieldAssist.SuffixText="times"
|
||||
Text="{Binding Scale, UpdateSourceTrigger=PropertyChanged}" Style="{StaticResource MaterialDesignFloatingHintTextBox}"
|
||||
Margin="0 10" />
|
||||
<TextBox materialDesign:HintAssist.Hint="Rotation"
|
||||
materialDesign:TextFieldAssist.SuffixText="deg"
|
||||
Text="{Binding Rotation, UpdateSourceTrigger=PropertyChanged}"
|
||||
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
|
||||
Margin="0 10" />
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<StackPanel Orientation="Vertical"
|
||||
Width="150"
|
||||
Margin="8">
|
||||
<TextBox materialDesign:HintAssist.Hint="X-coordinate"
|
||||
materialDesign:TextFieldAssist.SuffixText="mm"
|
||||
Text="{Binding X, UpdateSourceTrigger=PropertyChanged}"
|
||||
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
|
||||
Margin="0 10" />
|
||||
<TextBox materialDesign:HintAssist.Hint="Y-coordinate"
|
||||
materialDesign:TextFieldAssist.SuffixText="mm"
|
||||
Text="{Binding Y, UpdateSourceTrigger=PropertyChanged}"
|
||||
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
|
||||
Margin="0 10" />
|
||||
<TextBox materialDesign:HintAssist.Hint="Scale"
|
||||
materialDesign:TextFieldAssist.SuffixText="times"
|
||||
Text="{Binding Scale, UpdateSourceTrigger=PropertyChanged}"
|
||||
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
|
||||
Margin="0 10" />
|
||||
<TextBox materialDesign:HintAssist.Hint="Rotation"
|
||||
materialDesign:TextFieldAssist.SuffixText="deg"
|
||||
Text="{Binding Rotation, UpdateSourceTrigger=PropertyChanged}"
|
||||
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
|
||||
Margin="0 10" />
|
||||
</StackPanel>
|
||||
<StackPanel Orientation="Vertical"
|
||||
Width="250"
|
||||
Margin="8">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"
|
||||
MinWidth="41" />
|
||||
<ColumnDefinition Width="Auto"
|
||||
MinWidth="184.937" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
|
||||
<Button Style="{StaticResource MaterialDesignFlatButton}" IsCancel="True" Margin="0 8 8 0"
|
||||
<Label Grid.Column="0"
|
||||
Grid.Row="0"
|
||||
Content="Red"
|
||||
VerticalAlignment="Bottom" />
|
||||
<Slider Grid.Column="1"
|
||||
Grid.Row="0"
|
||||
Minimum="0"
|
||||
Maximum="200"
|
||||
ValueChanged="{s:Action ApplyScaling}"
|
||||
Value="{Binding RedScale, UpdateSourceTrigger=PropertyChanged}"
|
||||
Style="{StaticResource MaterialDesignDiscreteSlider}" />
|
||||
|
||||
<Label Grid.Column="0"
|
||||
Grid.Row="1"
|
||||
Content="Green"
|
||||
VerticalAlignment="Bottom" />
|
||||
<Slider Grid.Column="1"
|
||||
Grid.Row="1"
|
||||
Minimum="0"
|
||||
Maximum="200"
|
||||
ValueChanged="{s:Action ApplyScaling}"
|
||||
Value="{Binding GreenScale, UpdateSourceTrigger=PropertyChanged}"
|
||||
Style="{StaticResource MaterialDesignDiscreteSlider}" />
|
||||
|
||||
<Label Grid.Column="0"
|
||||
Grid.Row="2"
|
||||
Content="Blue"
|
||||
VerticalAlignment="Bottom" />
|
||||
<Slider Grid.Column="1"
|
||||
Grid.Row="2"
|
||||
Minimum="0"
|
||||
Maximum="200"
|
||||
ValueChanged="{s:Action ApplyScaling}"
|
||||
Value="{Binding BlueScale, UpdateSourceTrigger=PropertyChanged}"
|
||||
Style="{StaticResource MaterialDesignDiscreteSlider}" />
|
||||
</Grid>
|
||||
<DockPanel>
|
||||
<CheckBox IsChecked="{Binding DisplayOnDevices}"
|
||||
Margin="5,0,0,0"
|
||||
Content="Display on Devices"
|
||||
HorizontalAlignment="Left" />
|
||||
<shared:ColorPicker Margin="0,0,5,0"
|
||||
HorizontalAlignment="Right"
|
||||
Color="{Binding CurrentColor, Converter={StaticResource SKColorToColorConverter}}" />
|
||||
</DockPanel>
|
||||
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Orientation="Horizontal"
|
||||
HorizontalAlignment="Right">
|
||||
<Button Style="{StaticResource MaterialDesignFlatButton}"
|
||||
IsCancel="True"
|
||||
Margin="0 8 8 0"
|
||||
Command="{s:Action Cancel}">
|
||||
<Button.CommandParameter>
|
||||
<system:Boolean xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||
@ -43,7 +121,9 @@
|
||||
</Button.CommandParameter>
|
||||
CANCEL
|
||||
</Button>
|
||||
<Button Style="{StaticResource MaterialDesignFlatButton}" IsDefault="True" Margin="0 8 8 0"
|
||||
<Button Style="{StaticResource MaterialDesignFlatButton}"
|
||||
IsDefault="True"
|
||||
Margin="0 8 8 0"
|
||||
Command="{s:Action Accept}">
|
||||
<Button.CommandParameter>
|
||||
<system:Boolean xmlns:system="clr-namespace:System;assembly=mscorlib">
|
||||
@ -53,5 +133,6 @@
|
||||
APPLY
|
||||
</Button>
|
||||
</StackPanel>
|
||||
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@ -2,6 +2,7 @@
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using SkiaSharp;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
|
||||
@ -14,6 +15,11 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
|
||||
private string _title;
|
||||
private int _x;
|
||||
private int _y;
|
||||
public double _redScale;
|
||||
public double _greenScale;
|
||||
public double _blueScale;
|
||||
private SKColor _currentColor;
|
||||
private bool _displayOnDevices;
|
||||
|
||||
public SurfaceDeviceConfigViewModel(ArtemisDevice device, ICoreService coreService, IModelValidator<SurfaceDeviceConfigViewModel> validator) : base(validator)
|
||||
{
|
||||
@ -22,10 +28,27 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
|
||||
Device = device;
|
||||
Title = $"{Device.RgbDevice.DeviceInfo.DeviceName} - Properties";
|
||||
|
||||
X = (int) Device.X;
|
||||
Y = (int) Device.Y;
|
||||
X = (int)Device.X;
|
||||
Y = (int)Device.Y;
|
||||
Scale = Device.Scale;
|
||||
Rotation = (int) Device.Rotation;
|
||||
Rotation = (int)Device.Rotation;
|
||||
RedScale = Device.RedScale * 100d;
|
||||
GreenScale = Device.GreenScale * 100d;
|
||||
BlueScale = Device.BlueScale * 100d;
|
||||
CurrentColor = SKColors.White;
|
||||
_coreService.FrameRendering += OnFrameRendering;
|
||||
}
|
||||
|
||||
private void OnFrameRendering(object sender, FrameRenderingEventArgs e)
|
||||
{
|
||||
if (!_displayOnDevices)
|
||||
return;
|
||||
|
||||
using SKPaint overlayPaint = new SKPaint
|
||||
{
|
||||
Color = CurrentColor
|
||||
};
|
||||
e.Canvas.DrawRect(0, 0, e.Canvas.LocalClipBounds.Width, e.Canvas.LocalClipBounds.Height, overlayPaint);
|
||||
}
|
||||
|
||||
public ArtemisDevice Device { get; }
|
||||
@ -61,6 +84,36 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
|
||||
set => SetAndNotify(ref _rotation, value);
|
||||
}
|
||||
|
||||
public double RedScale
|
||||
{
|
||||
get => _redScale;
|
||||
set => SetAndNotify(ref _redScale, value);
|
||||
}
|
||||
|
||||
public double GreenScale
|
||||
{
|
||||
get => _greenScale;
|
||||
set => SetAndNotify(ref _greenScale, value);
|
||||
}
|
||||
|
||||
public double BlueScale
|
||||
{
|
||||
get => _blueScale;
|
||||
set => SetAndNotify(ref _blueScale, value);
|
||||
}
|
||||
|
||||
public SKColor CurrentColor
|
||||
{
|
||||
get => _currentColor;
|
||||
set => SetAndNotify(ref _currentColor, value);
|
||||
}
|
||||
|
||||
public bool DisplayOnDevices
|
||||
{
|
||||
get => _displayOnDevices;
|
||||
set => SetAndNotify(ref _displayOnDevices, value);
|
||||
}
|
||||
|
||||
public async Task Accept()
|
||||
{
|
||||
await ValidateAsync();
|
||||
@ -74,10 +127,22 @@ namespace Artemis.UI.Screens.SurfaceEditor.Dialogs
|
||||
Device.Y = Y;
|
||||
Device.Scale = Scale;
|
||||
Device.Rotation = Rotation;
|
||||
Device.RedScale = RedScale / 100d;
|
||||
Device.GreenScale = GreenScale / 100d;
|
||||
Device.BlueScale = BlueScale / 100d;
|
||||
|
||||
_coreService.ModuleRenderingDisabled = false;
|
||||
|
||||
_coreService.FrameRendering -= OnFrameRendering;
|
||||
Session.Close(true);
|
||||
}
|
||||
|
||||
public void ApplyScaling()
|
||||
{
|
||||
//TODO: we should either save or revert changes when the user clicks save or cancel.
|
||||
//we might have to revert these changes below.
|
||||
Device.RedScale = RedScale / 100d;
|
||||
Device.GreenScale = GreenScale / 100d;
|
||||
Device.BlueScale = BlueScale / 100d;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user