1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 01:58:30 +00:00
RGB.NET/RGB.NET.Presets/Textures/Sampler/AverageFloatSampler.cs

31 lines
713 B
C#

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
}
}