using System;
using RGB.NET.Core;
namespace RGB.NET.Presets.Textures.Sampler;
///
/// Represents a sampled that averages multiple float-data entries.
///
public class AverageFloatSampler : ISampler
{
#region Methods
///
public void Sample(in SamplerInfo info, in Span pixelData)
{
int count = info.Width * info.Height;
if (count == 0) return;
ReadOnlySpan data = info.Data;
int dataLength = pixelData.Length;
Span sums = stackalloc float[dataLength];
for (int i = 0; i < data.Length; i += dataLength)
for (int j = 0; j < sums.Length; j++)
sums[j] += data[i + j];
for (int i = 0; i < pixelData.Length; i++)
pixelData[i] = sums[i] / count;
}
#endregion
}