Skip to content

Commit eda72fc

Browse files
PlayStation: use Color.GetR/GetG/GetB extensions for byte conversion
Addresses DarthAffe's review feedback on PR DarthAffe#454 — the manual (byte)Math.Clamp((int)Math.Round(c * 255.0), 0, 255) pattern in both update queues is replaced with the project's standard Color.GetR / GetG / GetB extensions, which delegate to GetByteValueFromPercentage in RGB.NET.Core. That gives consistent rounding behaviour across the codebase and matches the convention every other provider uses. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 6dd3b99 commit eda72fc

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

RGB.NET.Devices.PlayStation/DualSense/DualSenseUpdateQueue.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,9 @@ private bool WriteBuffer()
175175

176176
private void BuildReport(Color lightbar, byte playerLedBits)
177177
{
178-
byte r = (byte)Math.Clamp((int)Math.Round(lightbar.R * 255.0), 0, 255);
179-
byte g = (byte)Math.Clamp((int)Math.Round(lightbar.G * 255.0), 0, 255);
180-
byte b = (byte)Math.Clamp((int)Math.Round(lightbar.B * 255.0), 0, 255);
178+
byte r = lightbar.GetR();
179+
byte g = lightbar.GetG();
180+
byte b = lightbar.GetB();
181181

182182
int commonOffset; // start of the 47-byte common block within _buffer
183183

RGB.NET.Devices.PlayStation/DualShock4/DualShock4UpdateQueue.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ private bool WriteBuffer()
122122

123123
private void BuildReport(Color color)
124124
{
125-
byte r = (byte)Math.Clamp((int)Math.Round(color.R * 255.0), 0, 255);
126-
byte g = (byte)Math.Clamp((int)Math.Round(color.G * 255.0), 0, 255);
127-
byte b = (byte)Math.Clamp((int)Math.Round(color.B * 255.0), 0, 255);
125+
byte r = color.GetR();
126+
byte g = color.GetG();
127+
byte b = color.GetB();
128128

129129
if (_transport == PlayStationTransport.Bluetooth)
130130
{

0 commit comments

Comments
 (0)