Optimized Textures and Sampler

This commit is contained in:
DarthAffe committed 2021-02-23 01:38:53 +01:00
1 parent 34a2acc6c4
commit c9634f3913
11 files changed
+325 -52

No files matched your search

@@ -0,0 +1,31 @@
using System;
using RGB.NET.Core;
namespace RGB.NET.Presets.Textures.Sampler
{
public class AverageByteSampler : ISampler<byte>
{
#region Methods
public Color SampleColor(SamplerInfo<byte> info)
{
int count = info.Width * info.Height;
if (count == 0) return Color.Transparent;
ReadOnlySpan<byte> data = info.Data;
uint r = 0, g = 0, b = 0;
for (int i = 0; i < data.Length; i += 3)
{
r += data[i];
g += data[i + 1];
b += data[i + 2];
}
float divisor = count * byte.MaxValue;
return new Color(r / divisor, g / divisor, b / divisor);
}
#endregion
}
}
@@ -0,0 +1,30 @@
using System;
using RGB.NET.Core;
namespace RGB.NET.Presets.Textures.Sampler
{
public class AverageFloatSampler : ISampler<float>
{
#region Methods
public Color SampleColor(SamplerInfo<float> info)
{
int count = info.Width * info.Height;
if (count == 0) return Color.Transparent;
ReadOnlySpan<float> data = info.Data;
float r = 0, g = 0, b = 0;
for (int i = 0; i < data.Length; i += 3)
{
r += data[i];
g += data[i + 1];
b += data[i + 2];
}
return new Color(r / count, g / count, b / count);
}
#endregion
}
}