mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Merge branch 'Development' into DeviceSupport
This commit is contained in:
commit
62c6ad0717
@ -25,9 +25,11 @@ public class DefaultColorBehavior : IColorBehavior
|
||||
public virtual bool Equals(in Color color, object? obj)
|
||||
{
|
||||
if (obj is not Color color2) return false;
|
||||
|
||||
(float a, float r, float g, float b) = color2.GetRGB();
|
||||
return color.A.EqualsInTolerance(a) && color.R.EqualsInTolerance(r) && color.G.EqualsInTolerance(g) && color.B.EqualsInTolerance(b);
|
||||
|
||||
return color.A.EqualsInTolerance(color2.A)
|
||||
&& color.R.EqualsInTolerance(color2.R)
|
||||
&& color.G.EqualsInTolerance(color2.G)
|
||||
&& color.B.EqualsInTolerance(color2.B);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -33,22 +33,22 @@ public readonly struct Color
|
||||
/// <summary>
|
||||
/// Gets the alpha component value of this <see cref="Color"/> as percentage in the range [0..1].
|
||||
/// </summary>
|
||||
public float A { get; }
|
||||
public readonly float A;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the red component value of this <see cref="Color"/> as percentage in the range [0..1].
|
||||
/// </summary>
|
||||
public float R { get; }
|
||||
public readonly float R;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the green component value of this <see cref="Color"/> as percentage in the range [0..1].
|
||||
/// </summary>
|
||||
public float G { get; }
|
||||
public readonly float G;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the blue component value of this <see cref="Color"/> as percentage in the range [0..1].
|
||||
/// </summary>
|
||||
public float B { get; }
|
||||
public readonly float B;
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Threading;
|
||||
@ -83,7 +82,7 @@ public static class TimerHelper
|
||||
/// <param name="initialTimestamp">The initial timestamp to calculate the time from.</param>
|
||||
/// <returns>The elapsed time in ms.</returns>
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static double GetElapsedTime(long initialTimestamp) => ((Stopwatch.GetTimestamp() - initialTimestamp) / (double)TimeSpan.TicksPerMillisecond);
|
||||
public static double GetElapsedTime(long initialTimestamp) => ((Stopwatch.GetTimestamp() - initialTimestamp) / (Stopwatch.Frequency / 1000.0));
|
||||
|
||||
/// <summary>
|
||||
/// Requests to use to use High Resolution Timers if enabled.
|
||||
|
||||
@ -70,7 +70,7 @@ public class CorsairCustomRGBDeviceInfo : CorsairRGBDeviceInfo
|
||||
CorsairChannelDeviceType.FanML => RGBDeviceType.Fan,
|
||||
CorsairChannelDeviceType.DAP => RGBDeviceType.Fan,
|
||||
CorsairChannelDeviceType.FanQL => RGBDeviceType.Fan,
|
||||
CorsairChannelDeviceType.FanSPPRO => RGBDeviceType.Fan,
|
||||
CorsairChannelDeviceType.EightLedSeriesFan => RGBDeviceType.Fan,
|
||||
CorsairChannelDeviceType.Strip => RGBDeviceType.LedStripe,
|
||||
CorsairChannelDeviceType.Pump => RGBDeviceType.Cooler,
|
||||
CorsairChannelDeviceType.WaterBlock => RGBDeviceType.Cooler,
|
||||
@ -117,8 +117,8 @@ public class CorsairCustomRGBDeviceInfo : CorsairRGBDeviceInfo
|
||||
case CorsairChannelDeviceType.FanQL:
|
||||
return "QL Fan";
|
||||
|
||||
case CorsairChannelDeviceType.FanSPPRO:
|
||||
return "SP-PRO Fan";
|
||||
case CorsairChannelDeviceType.EightLedSeriesFan:
|
||||
return "8-Led-Series Fan Fan";
|
||||
|
||||
case CorsairChannelDeviceType.Strip:
|
||||
// LS100 Led Strips are reported as one big strip if configured in monitor mode in iCUE, 138 LEDs for dual monitor, 84 for single
|
||||
|
||||
@ -21,5 +21,5 @@ public enum CorsairChannelDeviceType
|
||||
Pump = 7,
|
||||
FanQL = 8,
|
||||
WaterBlock = 9,
|
||||
EightLedSeriesFan = 10
|
||||
EightLedSeriesFan = 10 // Previously called FanSPPRO
|
||||
};
|
||||
@ -4,6 +4,7 @@ using RGB.NET.HID;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
|
||||
namespace RGB.NET.Devices.Logitech.HID;
|
||||
@ -108,6 +109,7 @@ public class LightspeedHIDLoader<TLed, TData> : IEnumerable<HIDDeviceDefinition<
|
||||
yield return wirelessPid;
|
||||
}
|
||||
|
||||
[SuppressMessage("ReSharper", "MustUseReturnValue")]
|
||||
private Dictionary<int, byte> GetWirelessDevices(IReadOnlyDictionary<byte, HidDevice> deviceUsages)
|
||||
{
|
||||
const byte LOGITECH_RECEIVER_ADDRESS = 0xFF;
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using RGB.NET.Core;
|
||||
@ -14,7 +13,7 @@ public class SteelSeriesDeviceUpdateTrigger : DeviceUpdateTrigger
|
||||
{
|
||||
#region Constants
|
||||
|
||||
private const long FLUSH_TIMER = 5 * 1000 * TimeSpan.TicksPerMillisecond; // flush the device every 5 seconds to prevent timeouts
|
||||
private static readonly long FLUSH_TIMER = 5 * 1000 * (long)(Stopwatch.Frequency / 1000.0); // flush the device every 5 seconds to prevent timeouts
|
||||
|
||||
#endregion
|
||||
|
||||
@ -59,7 +58,7 @@ public class SteelSeriesDeviceUpdateTrigger : DeviceUpdateTrigger
|
||||
|
||||
if (UpdateFrequency > 0)
|
||||
{
|
||||
double lastUpdateTime = ((_lastUpdateTimestamp - preUpdateTicks) / (double)TimeSpan.TicksPerMillisecond);
|
||||
double lastUpdateTime = ((_lastUpdateTimestamp - preUpdateTicks) / (Stopwatch.Frequency / 1000.0));
|
||||
int sleep = (int)((UpdateFrequency * 1000.0) - lastUpdateTime);
|
||||
if (sleep > 0)
|
||||
Thread.Sleep(sleep);
|
||||
|
||||
11
RGB.NET.sln
11
RGB.NET.sln
@ -1,7 +1,7 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.29424.173
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.1.32407.343
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Devices", "Devices", "{D13032C6-432E-4F43-8A32-071133C22B16}"
|
||||
EndProject
|
||||
@ -43,6 +43,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RGB.NET.HID", "RGB.NET.HID\
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RGB.NET.Devices.PicoPi", "RGB.NET.Devices.PicoPi\RGB.NET.Devices.PicoPi.csproj", "{7FC5C7A8-7B27-46E7-A8E8-DB80568F49C5}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "RGB.NET.Presets.Tests", "Tests\RGB.NET.Presets.Tests\RGB.NET.Presets.Tests.csproj", "{EDBA49D6-AE96-4E96-9E6A-30154D93BD5F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -121,6 +123,10 @@ Global
|
||||
{7FC5C7A8-7B27-46E7-A8E8-DB80568F49C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7FC5C7A8-7B27-46E7-A8E8-DB80568F49C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7FC5C7A8-7B27-46E7-A8E8-DB80568F49C5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{EDBA49D6-AE96-4E96-9E6A-30154D93BD5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{EDBA49D6-AE96-4E96-9E6A-30154D93BD5F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EDBA49D6-AE96-4E96-9E6A-30154D93BD5F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EDBA49D6-AE96-4E96-9E6A-30154D93BD5F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
@ -140,6 +146,7 @@ Global
|
||||
{E0732B34-3F96-4DD9-AFD5-0E34B833AD6D} = {D13032C6-432E-4F43-8A32-071133C22B16}
|
||||
{DD46DB2D-85BE-4962-86AE-E38C9053A548} = {D13032C6-432E-4F43-8A32-071133C22B16}
|
||||
{7FC5C7A8-7B27-46E7-A8E8-DB80568F49C5} = {D13032C6-432E-4F43-8A32-071133C22B16}
|
||||
{EDBA49D6-AE96-4E96-9E6A-30154D93BD5F} = {92D7C263-D4C9-4D26-93E2-93C1F9C2CD16}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {7F222AD4-1F9E-4AAB-9D69-D62372D4C1BA}
|
||||
|
||||
85
Tests/RGB.NET.Core.Tests/Sampler/AverageColorSamplerTest.cs
Normal file
85
Tests/RGB.NET.Core.Tests/Sampler/AverageColorSamplerTest.cs
Normal file
@ -0,0 +1,85 @@
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
namespace RGB.NET.Core.Tests.Sampler;
|
||||
|
||||
[TestClass]
|
||||
public class AverageColorSamplerTest
|
||||
{
|
||||
#region Methods
|
||||
|
||||
[TestMethod]
|
||||
public void WhiteTest()
|
||||
{
|
||||
Span<Core.Color> data = new Core.Color[16 * 16];
|
||||
data.Fill(new Core.Color(1f, 1f, 1f, 1f));
|
||||
Core.Color[] result = new Core.Color[1];
|
||||
|
||||
SamplerInfo<Core.Color> info = new(2, 3, data[..6]);
|
||||
new AverageColorSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Core.Color(1f, 1f, 1f, 1f), result[0]);
|
||||
|
||||
info = new SamplerInfo<Core.Color>(16, 16, data);
|
||||
new AverageColorSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Core.Color(1f, 1f, 1f, 1f), result[0]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void BlackTest()
|
||||
{
|
||||
Span<Core.Color> data = new Core.Color[16 * 16];
|
||||
data.Fill(new Core.Color(1f, 0f, 0f, 0f));
|
||||
Core.Color[] result = new Core.Color[1];
|
||||
|
||||
SamplerInfo<Core.Color> info = new(2, 3, data[..6]);
|
||||
new AverageColorSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Core.Color(1f, 0f, 0f, 0f), result[0]);
|
||||
|
||||
info = new SamplerInfo<Core.Color>(16, 16, data);
|
||||
new AverageColorSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Core.Color(1f, 0f, 0f, 0f), result[0]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GrayTest()
|
||||
{
|
||||
Span<Core.Color> data = new Core.Color[16 * 16];
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
data[i] = (i % 2) == 0 ? new Core.Color(1f, 0f, 0f, 0f) : new Core.Color(1f, 1f, 1f, 1f);
|
||||
Core.Color[] result = new Core.Color[1];
|
||||
|
||||
SamplerInfo<Core.Color> info = new(2, 3, data[..6]);
|
||||
new AverageColorSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Core.Color(1f, 0.5f, 0.5f, 0.5f), result[0]);
|
||||
|
||||
info = new SamplerInfo<Core.Color>(16, 16, data);
|
||||
new AverageColorSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Core.Color(1f, 0.5f, 0.5f, 0.5f), result[0]);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MixedTest()
|
||||
{
|
||||
Core.Color[] data = new Core.Color[16 * 16];
|
||||
for (int i = 0; i < data.Length; i++)
|
||||
data[i] = (i % 5) switch
|
||||
{
|
||||
0 => new Core.Color(1f, 1f, 0f, 0f),
|
||||
1 => new Core.Color(1f, 0f, 0.75f, 0f),
|
||||
2 => new Core.Color(0.5f, 0f, 0f, 0.5f),
|
||||
3 => new Core.Color(0f, 1f, 1f, 1f),
|
||||
_ => new Core.Color(0f, 0f, 0f, 0f),
|
||||
};
|
||||
Core.Color[] result = new Core.Color[1];
|
||||
|
||||
SamplerInfo<Core.Color> info = new(2, 3, data[..6]);
|
||||
new AverageColorSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Core.Color(0.5833333f, 0.5f, 0.291666657f, 0.25f), result[0]);
|
||||
|
||||
info = new SamplerInfo<Core.Color>(16, 16, data);
|
||||
new AverageColorSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Core.Color(0.5019531f, 0.40234375f, 0.3486328f, 0.298828125f), result[0]);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
20
Tests/RGB.NET.Presets.Tests/RGB.NET.Presets.Tests.csproj
Normal file
20
Tests/RGB.NET.Presets.Tests/RGB.NET.Presets.Tests.csproj
Normal file
@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
|
||||
<IsPackable>false</IsPackable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.10.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="2.2.5" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="2.2.5" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\RGB.NET.Core\RGB.NET.Core.csproj" />
|
||||
<ProjectReference Include="..\..\RGB.NET.Presets\RGB.NET.Presets.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
127
Tests/RGB.NET.Presets.Tests/Sampler/AverageByteSamplerTest.cs
Normal file
127
Tests/RGB.NET.Presets.Tests/Sampler/AverageByteSamplerTest.cs
Normal file
@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Presets.Textures.Sampler;
|
||||
|
||||
namespace RGB.NET.Presets.Tests.Sampler;
|
||||
|
||||
[TestClass]
|
||||
public class AverageByteSamplerTest
|
||||
{
|
||||
#region Methods
|
||||
|
||||
[TestMethod]
|
||||
public void WhiteTest()
|
||||
{
|
||||
Span<Color> colorData = new Color[16 * 16];
|
||||
colorData.Fill(new Color(1f, 1f, 1f, 1f));
|
||||
byte[] result = new byte[4];
|
||||
|
||||
Span<byte> data = new byte[colorData.Length * 4];
|
||||
int index = 0;
|
||||
for (int i = 0; i < colorData.Length; i++)
|
||||
{
|
||||
data[index++] = colorData[i].GetA();
|
||||
data[index++] = colorData[i].GetR();
|
||||
data[index++] = colorData[i].GetG();
|
||||
data[index++] = colorData[i].GetB();
|
||||
}
|
||||
|
||||
SamplerInfo<byte> info = new(2, 3, data[..(6 * 4)]);
|
||||
new AverageByteSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Color(1f, 1f, 1f, 1f), new Color(result[0], result[1], result[2], result[3]));
|
||||
|
||||
info = new SamplerInfo<byte>(16, 16, data);
|
||||
new AverageByteSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Color(1f, 1f, 1f, 1f), new Color(result[0], result[1], result[2], result[3]));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void BlackTest()
|
||||
{
|
||||
Span<Color> colorData = new Color[16 * 16];
|
||||
colorData.Fill(new Color(1f, 0f, 0f, 0f));
|
||||
byte[] result = new byte[4];
|
||||
|
||||
Span<byte> data = new byte[colorData.Length * 4];
|
||||
int index = 0;
|
||||
for (int i = 0; i < colorData.Length; i++)
|
||||
{
|
||||
data[index++] = colorData[i].GetA();
|
||||
data[index++] = colorData[i].GetR();
|
||||
data[index++] = colorData[i].GetG();
|
||||
data[index++] = colorData[i].GetB();
|
||||
}
|
||||
|
||||
SamplerInfo<byte> info = new(2, 3, data[..(6 * 4)]);
|
||||
new AverageByteSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Color(1f, 0f, 0f, 0f), new Color(result[0], result[1], result[2], result[3]));
|
||||
|
||||
info = new SamplerInfo<byte>(16, 16, data);
|
||||
new AverageByteSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Color(1f, 0f, 0f, 0f), new Color(result[0], result[1], result[2], result[3]));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GrayTest()
|
||||
{
|
||||
Span<Color> colorData = new Color[16 * 16];
|
||||
for (int i = 0; i < colorData.Length; i++)
|
||||
colorData[i] = (i % 2) == 0 ? new Color(1f, 0f, 0f, 0f) : new Color(1f, 1f, 1f, 1f);
|
||||
byte[] result = new byte[4];
|
||||
|
||||
Span<byte> data = new byte[colorData.Length * 4];
|
||||
int index = 0;
|
||||
for (int i = 0; i < colorData.Length; i++)
|
||||
{
|
||||
data[index++] = colorData[i].GetA();
|
||||
data[index++] = colorData[i].GetR();
|
||||
data[index++] = colorData[i].GetG();
|
||||
data[index++] = colorData[i].GetB();
|
||||
}
|
||||
|
||||
SamplerInfo<byte> info = new(2, 3, data[..(6 * 4)]);
|
||||
new AverageByteSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Color(1f, 0.5f, 0.5f, 0.5f), new Color(result[0], result[1], result[2], result[3]));
|
||||
|
||||
info = new SamplerInfo<byte>(16, 16, data);
|
||||
new AverageByteSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Color(1f, 0.5f, 0.5f, 0.5f), new Color(result[0], result[1], result[2], result[3]));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MixedTest()
|
||||
{
|
||||
Color[] colorData = new Color[16 * 16];
|
||||
for (int i = 0; i < colorData.Length; i++)
|
||||
colorData[i] = (i % 5) switch
|
||||
{
|
||||
0 => new Color(1f, 1f, 0f, 0f),
|
||||
1 => new Color(1f, 0f, 0.75f, 0f),
|
||||
2 => new Color(0.5f, 0f, 0f, 0.5f),
|
||||
3 => new Color(0f, 1f, 1f, 1f),
|
||||
_ => new Color(0f, 0f, 0f, 0f),
|
||||
};
|
||||
byte[] result = new byte[4];
|
||||
|
||||
Span<byte> data = new byte[colorData.Length * 4];
|
||||
int index = 0;
|
||||
for (int i = 0; i < colorData.Length; i++)
|
||||
{
|
||||
data[index++] = colorData[i].GetA();
|
||||
data[index++] = colorData[i].GetR();
|
||||
data[index++] = colorData[i].GetG();
|
||||
data[index++] = colorData[i].GetB();
|
||||
}
|
||||
|
||||
SamplerInfo<byte> info = new(2, 3, data[..(6 * 4)]);
|
||||
new AverageByteSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Color(149, 128, 74, 64), new Color(result[0], result[1], result[2], result[3]));
|
||||
|
||||
info = new SamplerInfo<byte>(16, 16, data);
|
||||
new AverageByteSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Color(128, 103, 89, 76), new Color(result[0], result[1], result[2], result[3]));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
127
Tests/RGB.NET.Presets.Tests/Sampler/AverageFloatSamplerTest.cs
Normal file
127
Tests/RGB.NET.Presets.Tests/Sampler/AverageFloatSamplerTest.cs
Normal file
@ -0,0 +1,127 @@
|
||||
using System;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using RGB.NET.Core;
|
||||
using RGB.NET.Presets.Textures.Sampler;
|
||||
|
||||
namespace RGB.NET.Presets.Tests.Sampler;
|
||||
|
||||
[TestClass]
|
||||
public class AverageFloatSamplerTest
|
||||
{
|
||||
#region Methods
|
||||
|
||||
[TestMethod]
|
||||
public void WhiteTest()
|
||||
{
|
||||
Span<Color> colorData = new Color[16 * 16];
|
||||
colorData.Fill(new Color(1f, 1f, 1f, 1f));
|
||||
float[] result = new float[4];
|
||||
|
||||
Span<float> data = new float[colorData.Length * 4];
|
||||
int index = 0;
|
||||
for (int i = 0; i < colorData.Length; i++)
|
||||
{
|
||||
data[index++] = colorData[i].A;
|
||||
data[index++] = colorData[i].R;
|
||||
data[index++] = colorData[i].G;
|
||||
data[index++] = colorData[i].B;
|
||||
}
|
||||
|
||||
SamplerInfo<float> info = new(2, 3, data[..(6 * 4)]);
|
||||
new AverageFloatSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Color(1f, 1f, 1f, 1f), new Color(result[0], result[1], result[2], result[3]));
|
||||
|
||||
info = new SamplerInfo<float>(16, 16, data);
|
||||
new AverageFloatSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Color(1f, 1f, 1f, 1f), new Color(result[0], result[1], result[2], result[3]));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void BlackTest()
|
||||
{
|
||||
Span<Color> colorData = new Color[16 * 16];
|
||||
colorData.Fill(new Color(1f, 0f, 0f, 0f));
|
||||
float[] result = new float[4];
|
||||
|
||||
Span<float> data = new float[colorData.Length * 4];
|
||||
int index = 0;
|
||||
for (int i = 0; i < colorData.Length; i++)
|
||||
{
|
||||
data[index++] = colorData[i].A;
|
||||
data[index++] = colorData[i].R;
|
||||
data[index++] = colorData[i].G;
|
||||
data[index++] = colorData[i].B;
|
||||
}
|
||||
|
||||
SamplerInfo<float> info = new(2, 3, data[..(6 * 4)]);
|
||||
new AverageFloatSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Color(1f, 0f, 0f, 0f), new Color(result[0], result[1], result[2], result[3]));
|
||||
|
||||
info = new SamplerInfo<float>(16, 16, data);
|
||||
new AverageFloatSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Color(1f, 0f, 0f, 0f), new Color(result[0], result[1], result[2], result[3]));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void GrayTest()
|
||||
{
|
||||
Span<Color> colorData = new Color[16 * 16];
|
||||
for (int i = 0; i < colorData.Length; i++)
|
||||
colorData[i] = (i % 2) == 0 ? new Color(1f, 0f, 0f, 0f) : new Color(1f, 1f, 1f, 1f);
|
||||
float[] result = new float[4];
|
||||
|
||||
Span<float> data = new float[colorData.Length * 4];
|
||||
int index = 0;
|
||||
for (int i = 0; i < colorData.Length; i++)
|
||||
{
|
||||
data[index++] = colorData[i].A;
|
||||
data[index++] = colorData[i].R;
|
||||
data[index++] = colorData[i].G;
|
||||
data[index++] = colorData[i].B;
|
||||
}
|
||||
|
||||
SamplerInfo<float> info = new(2, 3, data[..(6 * 4)]);
|
||||
new AverageFloatSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Color(1f, 0.5f, 0.5f, 0.5f), new Color(result[0], result[1], result[2], result[3]));
|
||||
|
||||
info = new SamplerInfo<float>(16, 16, data);
|
||||
new AverageFloatSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Color(1f, 0.5f, 0.5f, 0.5f), new Color(result[0], result[1], result[2], result[3]));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void MixedTest()
|
||||
{
|
||||
Color[] colorData = new Color[16 * 16];
|
||||
for (int i = 0; i < colorData.Length; i++)
|
||||
colorData[i] = (i % 5) switch
|
||||
{
|
||||
0 => new Color(1f, 1f, 0f, 0f),
|
||||
1 => new Color(1f, 0f, 0.75f, 0f),
|
||||
2 => new Color(0.5f, 0f, 0f, 0.5f),
|
||||
3 => new Color(0f, 1f, 1f, 1f),
|
||||
_ => new Color(0f, 0f, 0f, 0f),
|
||||
};
|
||||
float[] result = new float[4];
|
||||
|
||||
Span<float> data = new float[colorData.Length * 4];
|
||||
int index = 0;
|
||||
for (int i = 0; i < colorData.Length; i++)
|
||||
{
|
||||
data[index++] = colorData[i].A;
|
||||
data[index++] = colorData[i].R;
|
||||
data[index++] = colorData[i].G;
|
||||
data[index++] = colorData[i].B;
|
||||
}
|
||||
|
||||
SamplerInfo<float> info = new(2, 3, data[..(6 * 4)]);
|
||||
new AverageFloatSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Color(0.5833333f, 0.5f, 0.291666657f, 0.25f), new Color(result[0], result[1], result[2], result[3]));
|
||||
|
||||
info = new SamplerInfo<float>(16, 16, data);
|
||||
new AverageFloatSampler().Sample(info, result);
|
||||
Assert.AreEqual(new Color(0.5019531f, 0.40234375f, 0.3486328f, 0.298828125f), new Color(result[0], result[1], result[2], result[3]));
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user