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

Devices - Ported color correction code to RGB.NET

This commit is contained in:
Robert 2021-02-25 19:58:40 +01:00
parent 2e859bc84c
commit 1ea2e2bee7
6 changed files with 55 additions and 30 deletions

View File

@ -15,7 +15,7 @@ namespace Artemis.Core
}
/// <summary>
/// Gets the bitmap brush used to render this frame
/// Gets the texture used to render this frame
/// </summary>
public SKTexture Texture { get; }

View File

@ -340,11 +340,13 @@ namespace Artemis.Core
DeviceEntity.InputIdentifiers.Clear();
foreach (ArtemisDeviceInputIdentifier identifier in InputIdentifiers)
{
DeviceEntity.InputIdentifiers.Add(new DeviceInputIdentifierEntity
{
InputProvider = identifier.InputProvider,
Identifier = identifier.Identifier
});
}
}
internal void ApplyToRgbDevice()
@ -361,6 +363,9 @@ namespace Artemis.Core
foreach (DeviceInputIdentifierEntity identifierEntity in DeviceEntity.InputIdentifiers)
InputIdentifiers.Add(new ArtemisDeviceInputIdentifier(identifierEntity.InputProvider, identifierEntity.Identifier));
if (!RgbDevice.ColorCorrections.Any())
RgbDevice.ColorCorrections.Add(new ScaleColorCorrection(this));
CalculateRenderProperties();
OnDeviceUpdated();
}

View File

@ -54,15 +54,6 @@ namespace Artemis.Core
return RgbLed.ToString();
}
/// <summary>
/// Gets the color of this led, reverting the correction done to the parent device
/// </summary>
/// <returns></returns>
public Color GetOriginalColor()
{
return RgbLed.Color.DivideRGB(Device.RedScale, Device.GreenScale, Device.BlueScale);
}
internal void CalculateRectangles()
{
Rectangle = RgbLed.Boundary.ToSKRect();

View File

@ -5,23 +5,17 @@ using SkiaSharp;
namespace Artemis.Core
{
/// <summary>
/// Represents a SkiaSharp-based RGB.NET PixelTexture
/// </summary>
public sealed class SKTexture : PixelTexture<byte>
{
#region Properties & Fields
private readonly SKBitmap _bitmap;
public SKBitmap Bitmap => _bitmap;
protected override ReadOnlySpan<byte> Data => _bitmap.GetPixelSpan();
#endregion
#region Constructors
public SKTexture(SKBitmap bitmap)
internal SKTexture(SKBitmap bitmap)
: base(bitmap.Width, bitmap.Height, 4, new AverageByteSampler())
{
this._bitmap = bitmap;
Bitmap = bitmap;
}
#endregion
@ -29,7 +23,24 @@ namespace Artemis.Core
#region Methods
/// <inheritdoc />
protected override Color GetColor(in ReadOnlySpan<byte> pixel) => new(pixel[0], pixel[1], pixel[2]);
protected override Color GetColor(in ReadOnlySpan<byte> pixel)
{
return new(pixel[0], pixel[1], pixel[2]);
}
#endregion
#region Properties & Fields
/// <summary>
/// Gets the SKBitmap backing this texture
/// </summary>
public SKBitmap Bitmap { get; }
/// <summary>
/// Gets the color data in RGB format
/// </summary>
protected override ReadOnlySpan<byte> Data => Bitmap.GetPixelSpan();
#endregion
}

View File

@ -0,0 +1,19 @@
using RGB.NET.Core;
namespace Artemis.Core
{
internal class ScaleColorCorrection : IColorCorrection
{
private readonly ArtemisDevice _device;
public ScaleColorCorrection(ArtemisDevice device)
{
_device = device;
}
public void ApplyTo(ref Color color)
{
color = color.MultiplyRGB(_device.RedScale, _device.GreenScale, _device.BlueScale);
}
}
}

View File

@ -44,10 +44,9 @@ namespace Artemis.UI.Shared
_renderColorBrush ??= new SolidColorBrush();
RGB.NET.Core.Color originalColor = Led.GetOriginalColor();
byte r = originalColor.GetR();
byte g = originalColor.GetG();
byte b = originalColor.GetB();
byte r = Led.RgbLed.Color.GetR();
byte g = Led.RgbLed.Color.GetG();
byte b = Led.RgbLed.Color.GetB();
_renderColor.A = isDimmed ? 100 : 255;
_renderColor.R = r;