diff --git a/src/Artemis.Core/Models/Surface/ArtemisDevice.cs b/src/Artemis.Core/Models/Surface/ArtemisDevice.cs index 776eebde9..4bac85052 100644 --- a/src/Artemis.Core/Models/Surface/ArtemisDevice.cs +++ b/src/Artemis.Core/Models/Surface/ArtemisDevice.cs @@ -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,45 @@ namespace Artemis.Core } } + /// + /// Gets or sets the scale of the red color component used for calibration + /// + public double RedScale + { + get => DeviceEntity.RedScale; + set + { + DeviceEntity.RedScale = value; + OnPropertyChanged(nameof(RedScale)); + } + } + + /// + /// Gets or sets the scale of the green color component used for calibration + /// + public double GreenScale + { + get => DeviceEntity.GreenScale; + set + { + DeviceEntity.GreenScale = value; + OnPropertyChanged(nameof(GreenScale)); + } + } + + /// + /// Gets or sets the scale of the blue color component used for calibration + /// + public double BlueScale + { + get => DeviceEntity.BlueScale; + set + { + DeviceEntity.BlueScale = value; + OnPropertyChanged(nameof(BlueScale)); + } + } + /// /// Gets the path to where the layout of the device was (attempted to be) loaded from /// diff --git a/src/Artemis.Core/Models/Surface/ArtemisLed.cs b/src/Artemis.Core/Models/Surface/ArtemisLed.cs index b5915077a..8085e6e8f 100644 --- a/src/Artemis.Core/Models/Surface/ArtemisLed.cs +++ b/src/Artemis.Core/Models/Surface/ArtemisLed.cs @@ -57,5 +57,14 @@ namespace Artemis.Core { return RgbLed.ToString(); } + + /// + /// Gets the color of this led, reverting the correction done to the parent device + /// + /// + public Color GetOriginalColor() + { + return RgbLed.Color.DivideRGB(Device.RedScale, Device.GreenScale, Device.BlueScale); + } } } \ No newline at end of file diff --git a/src/Artemis.Core/RGB.NET/BitmapBrush.cs b/src/Artemis.Core/RGB.NET/BitmapBrush.cs index 3f6926c4a..3761cdfd0 100644 --- a/src/Artemis.Core/RGB.NET/BitmapBrush.cs +++ b/src/Artemis.Core/RGB.NET/BitmapBrush.cs @@ -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; } } diff --git a/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs b/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs index dc2c481d3..b4a5f7665 100644 --- a/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs +++ b/src/Artemis.Storage/Entities/Surface/DeviceEntity.cs @@ -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 InputIdentifiers { get; set; } } diff --git a/src/Artemis.Storage/Migrations/M9DeviceCalibration.cs b/src/Artemis.Storage/Migrations/M9DeviceCalibration.cs new file mode 100644 index 000000000..fdb45dd8b --- /dev/null +++ b/src/Artemis.Storage/Migrations/M9DeviceCalibration.cs @@ -0,0 +1,27 @@ +using Artemis.Storage.Migrations.Interfaces; +using LiteDB; + +namespace Artemis.Storage.Migrations +{ + public class M9DeviceCalibration : IStorageMigration + { + public int UserVersion => 9; + + /// + public void Apply(LiteRepository repository) + { + ILiteCollection collection = repository.Database.GetCollection("SurfaceEntity"); + foreach (BsonDocument bsonDocument in collection.FindAll()) + { + foreach (BsonValue bsonDevice in bsonDocument["DeviceEntities"].AsArray) + { + bsonDevice["RedScale"] = 1d; + bsonDevice["GreenScale"] = 1d; + bsonDevice["BlueScale"] = 1d; + } + + collection.Update(bsonDocument); + } + } + } +} \ No newline at end of file diff --git a/src/Artemis.UI.Shared/Controls/DeviceVisualizerLed.cs b/src/Artemis.UI.Shared/Controls/DeviceVisualizerLed.cs index 050ad68aa..88e5eb884 100644 --- a/src/Artemis.UI.Shared/Controls/DeviceVisualizerLed.cs +++ b/src/Artemis.UI.Shared/Controls/DeviceVisualizerLed.cs @@ -38,9 +38,10 @@ namespace Artemis.UI.Shared if (DisplayGeometry == null) return; - byte r = Led.RgbLed.Color.GetR(); - byte g = Led.RgbLed.Color.GetG(); - byte b = Led.RgbLed.Color.GetB(); + RGB.NET.Core.Color originalColor = Led.GetOriginalColor(); + byte r = originalColor.GetR(); + byte g = originalColor.GetG(); + byte b = originalColor.GetB(); drawingContext.DrawRectangle(isDimmed ? new SolidColorBrush(Color.FromArgb(100, r, g, b)) diff --git a/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceConfigView.xaml b/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceConfigView.xaml index 8ebca71ee..52b34bab4 100644 --- a/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceConfigView.xaml +++ b/src/Artemis.UI/Screens/SurfaceEditor/Dialogs/SurfaceDeviceConfigView.xaml @@ -1,40 +1,172 @@ - - - - + + + + + + - - - - + + + + + + + - - -