using System.Collections.Generic; using System.Collections.Immutable; namespace HPPH.Generators; internal class Average : IGeneratorFeature { public IEnumerable<(string name, string source)> GenerateFor(ColorFormatData colorFormat) { yield return ($"ColorFormat{colorFormat.Format}.Average", GenerateColorFormatAverage(colorFormat)); } public IEnumerable<(string name, string source)> GenerateFor(ImmutableArray colorFormats) { yield return ("IColorFormat.Average", GenerateColorFormatInterfaceAverage()); } private static string GenerateColorFormatAverage(ColorFormatData colorFormat) { return $$""" using System.Runtime.InteropServices; namespace HPPH; public sealed partial class ColorFormat{{colorFormat.Format}} { #region Methods unsafe IColor IColorFormat.Average(ReadOnlySpan data) => PixelHelper.Average(MemoryMarshal.Cast(data)); #endregion } """; } private static string GenerateColorFormatInterfaceAverage() { return """ namespace HPPH; public partial interface IColorFormat { internal IColor Average(ReadOnlySpan data); } """; } }