From f6f3e9185c760fdd461585251b47e641a3cc51eb Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Wed, 3 Mar 2021 23:29:31 +0100 Subject: [PATCH] Moved color-correction logic deeper down to the device --- RGB.NET.Core/Devices/AbstractRGBDevice.cs | 28 ++++++++++++++++++- RGB.NET.Core/RGBSurface.cs | 8 +----- RGB.NET.Core/Update/Devices/UpdateQueue.cs | 10 ------- RGB.NET.Devices.Asus/Generic/AsusRGBDevice.cs | 4 +-- .../Generic/CoolerMasterRGBDevice.cs | 2 +- .../Generic/CorsairRGBDevice.cs | 2 +- RGB.NET.Devices.DMX/E131/E131Device.cs | 2 +- .../PerDevice/LogitechPerDeviceRGBDevice.cs | 2 +- .../PerKey/LogitechPerKeyRGBDevice.cs | 2 +- .../Zone/LogitechZoneRGBDevice.cs | 2 +- RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs | 2 +- .../Generic/NovationRGBDevice.cs | 2 +- .../Generic/RazerRGBDevice.cs | 2 +- .../Generic/SteelSeriesRGBDevice.cs | 2 +- .../Arduino/ArduinoWS2812USBDevice.cs | 2 +- .../Bitwizard/BitwizardWS2812USBDevice.cs | 2 +- .../NodeMCU/NodeMCUWS2812USBDevice.cs | 2 +- .../Keyboard/WootingKeyboardRGBDevice.cs | 2 +- 18 files changed, 44 insertions(+), 34 deletions(-) diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs index 0b6fe09..7046139 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDevice.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs @@ -84,7 +84,33 @@ namespace RGB.NET.Core UpdateLeds(ledsToUpdate); } - protected virtual IEnumerable GetLedsToUpdate(bool flushLeds) => ((RequiresFlush || flushLeds) ? LedMapping.Values : LedMapping.Values.Where(x => x.IsDirty)); + protected virtual IEnumerable GetLedsToUpdate(bool flushLeds) => ((RequiresFlush || flushLeds) ? LedMapping.Values : LedMapping.Values.Where(x => x.IsDirty)).Where(led => led.Color.A > 0); + protected virtual IEnumerable<(object key, Color color)> GetUpdateData(IEnumerable leds) + { + if (ColorCorrections.Count > 0) + { + foreach (Led led in leds) + { + Color color = led.Color; + object key = led.CustomData ?? led.Id; + + foreach (IColorCorrection colorCorrection in ColorCorrections) + colorCorrection.ApplyTo(ref color); + + yield return (key, color); + } + } + else + { + foreach (Led led in leds) + { + Color color = led.Color; + object key = led.CustomData ?? led.Id; + + yield return (key, color); + } + } + } /// public virtual void Dispose() diff --git a/RGB.NET.Core/RGBSurface.cs b/RGB.NET.Core/RGBSurface.cs index a6c346f..94169b5 100644 --- a/RGB.NET.Core/RGBSurface.cs +++ b/RGB.NET.Core/RGBSurface.cs @@ -226,13 +226,7 @@ namespace RGB.NET.Core } foreach ((RenderTarget renderTarget, Color c) in render) - { - Color color = c; - for (int i = 0; i < renderTarget.Led.Device.ColorCorrections.Count; i++) - renderTarget.Led.Device.ColorCorrections[i].ApplyTo(ref color); - - renderTarget.Led.Color = color; - } + renderTarget.Led.Color = c; } /// diff --git a/RGB.NET.Core/Update/Devices/UpdateQueue.cs b/RGB.NET.Core/Update/Devices/UpdateQueue.cs index 76e6180..4b48593 100644 --- a/RGB.NET.Core/Update/Devices/UpdateQueue.cs +++ b/RGB.NET.Core/Update/Devices/UpdateQueue.cs @@ -133,15 +133,5 @@ namespace RGB.NET.Core { } #endregion - - #region Methods - - /// - /// Calls for a data set created out of the provided list of . - /// - /// - public void SetData(IEnumerable leds) => SetData(leds.Select(x => (x.CustomData ?? x.Id, x.Color))); - - #endregion } } diff --git a/RGB.NET.Devices.Asus/Generic/AsusRGBDevice.cs b/RGB.NET.Devices.Asus/Generic/AsusRGBDevice.cs index f0fc1bc..3973048 100644 --- a/RGB.NET.Devices.Asus/Generic/AsusRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Generic/AsusRGBDevice.cs @@ -49,7 +49,7 @@ namespace RGB.NET.Devices.Asus public void Initialize(IDeviceUpdateTrigger updateTrigger) { InitializeLayout(); - + UpdateQueue = new AsusUpdateQueue(updateTrigger); UpdateQueue.Initialize(DeviceInfo.Device); } @@ -60,7 +60,7 @@ namespace RGB.NET.Devices.Asus protected abstract void InitializeLayout(); /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); + protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(GetUpdateData(ledsToUpdate)); /// public override void Dispose() diff --git a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDevice.cs b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDevice.cs index b176bc7..ac17daa 100644 --- a/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDevice.cs +++ b/RGB.NET.Devices.CoolerMaster/Generic/CoolerMasterRGBDevice.cs @@ -62,7 +62,7 @@ namespace RGB.NET.Devices.CoolerMaster protected abstract void InitializeLayout(); /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); + protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(GetUpdateData(ledsToUpdate)); /// /// diff --git a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs index d573ba2..ef2a854 100644 --- a/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs @@ -84,7 +84,7 @@ namespace RGB.NET.Devices.Corsair /// protected override void UpdateLeds(IEnumerable ledsToUpdate) - => DeviceUpdateQueue?.SetData(ledsToUpdate.Where(x => (x.Color.A > 0) && (x.CustomData is CorsairLedId ledId && (ledId != CorsairLedId.Invalid)))); + => DeviceUpdateQueue?.SetData(GetUpdateData(ledsToUpdate.Where(x => (x.Color.A > 0) && (x.CustomData is CorsairLedId ledId && (ledId != CorsairLedId.Invalid))))); /// public override void Dispose() diff --git a/RGB.NET.Devices.DMX/E131/E131Device.cs b/RGB.NET.Devices.DMX/E131/E131Device.cs index 3a8c4fe..9b18d01 100644 --- a/RGB.NET.Devices.DMX/E131/E131Device.cs +++ b/RGB.NET.Devices.DMX/E131/E131Device.cs @@ -50,7 +50,7 @@ namespace RGB.NET.Devices.DMX.E131 /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => _updateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); + protected override void UpdateLeds(IEnumerable ledsToUpdate) => _updateQueue?.SetData(GetUpdateData(ledsToUpdate)); /// public override void Dispose() diff --git a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs index 416e18e..8855e6b 100644 --- a/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs +++ b/RGB.NET.Devices.Logitech/PerDevice/LogitechPerDeviceRGBDevice.cs @@ -36,7 +36,7 @@ namespace RGB.NET.Devices.Logitech protected override object GetLedCustomData(LedId ledId) => (ledId, LogitechLedId.DEVICE); /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0).Take(1)); + protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(GetUpdateData(ledsToUpdate.Take(1))); #endregion } diff --git a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs index 2b5a85d..1fbec2d 100644 --- a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs +++ b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs @@ -29,7 +29,7 @@ namespace RGB.NET.Devices.Logitech protected override object GetLedCustomData(LedId ledId) => (ledId, PerKeyIdMapping.DEFAULT.TryGetValue(ledId, out LogitechLedId logitechLedId) ? logitechLedId : LogitechLedId.Invalid); /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); + protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(GetUpdateData(ledsToUpdate)); #endregion } diff --git a/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs b/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs index 4b0da4f..5e7b8c9 100644 --- a/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs +++ b/RGB.NET.Devices.Logitech/Zone/LogitechZoneRGBDevice.cs @@ -59,7 +59,7 @@ namespace RGB.NET.Devices.Logitech protected override object? GetLedCustomData(LedId ledId) => (int)(ledId - _baseLedId); /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); + protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(GetUpdateData(ledsToUpdate)); #endregion } diff --git a/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs b/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs index 3da1d27..44b52eb 100644 --- a/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs +++ b/RGB.NET.Devices.Msi/Generic/MsiRGBDevice.cs @@ -60,7 +60,7 @@ namespace RGB.NET.Devices.Msi /// protected override void UpdateLeds(IEnumerable ledsToUpdate) - => DeviceUpdateQueue?.SetData(ledsToUpdate.Where(x => (x.Color.A > 0) && (x.CustomData is int))); + => DeviceUpdateQueue?.SetData(GetUpdateData(ledsToUpdate.Where(x => (x.Color.A > 0) && (x.CustomData is int)))); /// public override void Dispose() diff --git a/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs b/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs index 2976355..d6669ce 100644 --- a/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs +++ b/RGB.NET.Devices.Novation/Generic/NovationRGBDevice.cs @@ -65,7 +65,7 @@ namespace RGB.NET.Devices.Novation protected abstract void InitializeLayout(); /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); + protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(GetUpdateData(ledsToUpdate)); /// /// Resets the back to default. diff --git a/RGB.NET.Devices.Razer/Generic/RazerRGBDevice.cs b/RGB.NET.Devices.Razer/Generic/RazerRGBDevice.cs index afab079..6e7c61a 100644 --- a/RGB.NET.Devices.Razer/Generic/RazerRGBDevice.cs +++ b/RGB.NET.Devices.Razer/Generic/RazerRGBDevice.cs @@ -68,7 +68,7 @@ namespace RGB.NET.Devices.Razer protected abstract void InitializeLayout(); /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); + protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(GetUpdateData(ledsToUpdate)); /// /// Resets the device. diff --git a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs index 1f31857..9cc5f39 100644 --- a/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs +++ b/RGB.NET.Devices.SteelSeries/Generic/SteelSeriesRGBDevice.cs @@ -62,7 +62,7 @@ namespace RGB.NET.Devices.SteelSeries protected override object GetLedCustomData(LedId ledId) => _ledMapping[ledId]; /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); + protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(GetUpdateData(ledsToUpdate)); /// public override void Dispose() diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs index 1a9f186..ab658e5 100644 --- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs +++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs @@ -63,7 +63,7 @@ namespace RGB.NET.Devices.WS281X.Arduino protected override IEnumerable GetLedsToUpdate(bool flushLeds) => (flushLeds || LedMapping.Values.Any(x => x.IsDirty)) ? LedMapping.Values : Enumerable.Empty(); /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); + protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate)); /// public override void Dispose() diff --git a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs index 6e2d813..5bb6bcc 100644 --- a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs +++ b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs @@ -57,7 +57,7 @@ namespace RGB.NET.Devices.WS281X.Bitwizard protected override object GetLedCustomData(LedId ledId) => _ledOffset + ((int)ledId - (int)LedId.LedStripe1); /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); + protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate)); /// public override void Dispose() diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs index b471e17..635d61b 100644 --- a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs @@ -63,7 +63,7 @@ namespace RGB.NET.Devices.WS281X.NodeMCU protected override IEnumerable GetLedsToUpdate(bool flushLeds) => (flushLeds || LedMapping.Values.Any(x => x.IsDirty)) ? LedMapping.Values : Enumerable.Empty(); /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); + protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(GetUpdateData(ledsToUpdate)); /// public override void Dispose() diff --git a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs index 7994145..bd8edea 100644 --- a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDevice.cs @@ -47,7 +47,7 @@ namespace RGB.NET.Devices.Wooting.Keyboard protected override object GetLedCustomData(LedId ledId) => WootingKeyboardLedMappings.Mapping[DeviceInfo.DeviceIndex][WootingPhysicalKeyboardLayout.US][ledId]; /// - protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); + protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(GetUpdateData(ledsToUpdate)); #endregion }