using System; using RGB.NET.Core; namespace RGB.NET.Presets.Textures.Sampler { /// /// Represents a sampled that averages multiple byte-data entries. /// public class AverageByteSampler : 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 uint[dataLength]; for (int i = 0; i < data.Length; i += dataLength) for (int j = 0; j < sums.Length; j++) sums[j] += data[i + j]; float divisor = count * byte.MaxValue; for (int i = 0; i < pixelData.Length; i++) pixelData[i] = (sums[i] / divisor).GetByteValueFromPercentage(); } #endregion } }