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:
parent
2e859bc84c
commit
1ea2e2bee7
@ -15,7 +15,7 @@ namespace Artemis.Core
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the bitmap brush used to render this frame
|
/// Gets the texture used to render this frame
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SKTexture Texture { get; }
|
public SKTexture Texture { get; }
|
||||||
|
|
||||||
|
|||||||
@ -340,18 +340,20 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
DeviceEntity.InputIdentifiers.Clear();
|
DeviceEntity.InputIdentifiers.Clear();
|
||||||
foreach (ArtemisDeviceInputIdentifier identifier in InputIdentifiers)
|
foreach (ArtemisDeviceInputIdentifier identifier in InputIdentifiers)
|
||||||
|
{
|
||||||
DeviceEntity.InputIdentifiers.Add(new DeviceInputIdentifierEntity
|
DeviceEntity.InputIdentifiers.Add(new DeviceInputIdentifierEntity
|
||||||
{
|
{
|
||||||
InputProvider = identifier.InputProvider,
|
InputProvider = identifier.InputProvider,
|
||||||
Identifier = identifier.Identifier
|
Identifier = identifier.Identifier
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void ApplyToRgbDevice()
|
internal void ApplyToRgbDevice()
|
||||||
{
|
{
|
||||||
RgbDevice.Rotation = DeviceEntity.Rotation;
|
RgbDevice.Rotation = DeviceEntity.Rotation;
|
||||||
RgbDevice.Scale = DeviceEntity.Scale;
|
RgbDevice.Scale = DeviceEntity.Scale;
|
||||||
|
|
||||||
// Workaround for device rotation not applying
|
// Workaround for device rotation not applying
|
||||||
if (DeviceEntity.X == 0 && DeviceEntity.Y == 0)
|
if (DeviceEntity.X == 0 && DeviceEntity.Y == 0)
|
||||||
RgbDevice.Location = new Point(1, 1);
|
RgbDevice.Location = new Point(1, 1);
|
||||||
@ -361,6 +363,9 @@ namespace Artemis.Core
|
|||||||
foreach (DeviceInputIdentifierEntity identifierEntity in DeviceEntity.InputIdentifiers)
|
foreach (DeviceInputIdentifierEntity identifierEntity in DeviceEntity.InputIdentifiers)
|
||||||
InputIdentifiers.Add(new ArtemisDeviceInputIdentifier(identifierEntity.InputProvider, identifierEntity.Identifier));
|
InputIdentifiers.Add(new ArtemisDeviceInputIdentifier(identifierEntity.InputProvider, identifierEntity.Identifier));
|
||||||
|
|
||||||
|
if (!RgbDevice.ColorCorrections.Any())
|
||||||
|
RgbDevice.ColorCorrections.Add(new ScaleColorCorrection(this));
|
||||||
|
|
||||||
CalculateRenderProperties();
|
CalculateRenderProperties();
|
||||||
OnDeviceUpdated();
|
OnDeviceUpdated();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -53,16 +53,7 @@ namespace Artemis.Core
|
|||||||
{
|
{
|
||||||
return RgbLed.ToString();
|
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()
|
internal void CalculateRectangles()
|
||||||
{
|
{
|
||||||
Rectangle = RgbLed.Boundary.ToSKRect();
|
Rectangle = RgbLed.Boundary.ToSKRect();
|
||||||
|
|||||||
@ -5,23 +5,17 @@ using SkiaSharp;
|
|||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Represents a SkiaSharp-based RGB.NET PixelTexture
|
||||||
|
/// </summary>
|
||||||
public sealed class SKTexture : PixelTexture<byte>
|
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
|
#region Constructors
|
||||||
|
|
||||||
public SKTexture(SKBitmap bitmap)
|
internal SKTexture(SKBitmap bitmap)
|
||||||
: base(bitmap.Width, bitmap.Height, 4, new AverageByteSampler())
|
: base(bitmap.Width, bitmap.Height, 4, new AverageByteSampler())
|
||||||
{
|
{
|
||||||
this._bitmap = bitmap;
|
Bitmap = bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
@ -29,8 +23,25 @@ namespace Artemis.Core
|
|||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <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
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
19
src/Artemis.Core/RGB.NET/ScaleColorCorrection.cs
Normal file
19
src/Artemis.Core/RGB.NET/ScaleColorCorrection.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -27,7 +27,7 @@ namespace Artemis.UI.Shared
|
|||||||
|
|
||||||
if (Led.Layout?.Image != null && File.Exists(Led.Layout.Image.LocalPath))
|
if (Led.Layout?.Image != null && File.Exists(Led.Layout.Image.LocalPath))
|
||||||
LedImage = new BitmapImage(Led.Layout.Image);
|
LedImage = new BitmapImage(Led.Layout.Image);
|
||||||
|
|
||||||
CreateLedGeometry();
|
CreateLedGeometry();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,10 +44,9 @@ namespace Artemis.UI.Shared
|
|||||||
|
|
||||||
_renderColorBrush ??= new SolidColorBrush();
|
_renderColorBrush ??= new SolidColorBrush();
|
||||||
|
|
||||||
RGB.NET.Core.Color originalColor = Led.GetOriginalColor();
|
byte r = Led.RgbLed.Color.GetR();
|
||||||
byte r = originalColor.GetR();
|
byte g = Led.RgbLed.Color.GetG();
|
||||||
byte g = originalColor.GetG();
|
byte b = Led.RgbLed.Color.GetB();
|
||||||
byte b = originalColor.GetB();
|
|
||||||
|
|
||||||
_renderColor.A = isDimmed ? 100 : 255;
|
_renderColor.A = isDimmed ? 100 : 255;
|
||||||
_renderColor.R = r;
|
_renderColor.R = r;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user