3.1 PaletteFactory
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
38
src/FrameProcessor/ImagePipeline/PaletteFactory.cs
Normal file
38
src/FrameProcessor/ImagePipeline/PaletteFactory.cs
Normal 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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user