using FrameProcessor.Domain;
using SixLabors.ImageSharp;

namespace FrameProcessor.ImagePipeline;

/// <summary>
/// Builds ImageSharp <see cref="Color"/> palettes from a frame's <see cref="PaletteEntry"/> list.
/// The display palette is what we dither *against* (what the eye sees on the panel); the device
/// palette is the set of RGB values firmware expects in the input PNG. Order is preserved in both.
/// </summary>
public static class PaletteFactory
{
    public static ReadOnlyMemory<Color> BuildDisplay(IReadOnlyList<PaletteEntry> entries)
    {
        ArgumentNullException.ThrowIfNull(entries);

        var colors = new Color[entries.Count];
        for (var i = 0; i < entries.Count; i++)
        {
            colors[i] = entries[i].DisplayColor;
        }

        return colors;
    }

    public static ReadOnlyMemory<Color> BuildDevice(IReadOnlyList<PaletteEntry> entries)
    {
        ArgumentNullException.ThrowIfNull(entries);

        var colors = new Color[entries.Count];
        for (var i = 0; i < entries.Count; i++)
        {
            colors[i] = entries[i].DeviceColor;
        }

        return colors;
    }
}
