3.1 PaletteFactory

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-07 14:32:36 +02:00
parent 0a936a9f04
commit 0e757e4193
3 changed files with 105 additions and 1 deletions

View File

@@ -0,0 +1,38 @@
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;
}
}