Skip to content

Palette Colormap #2375

@swharden

Description

@swharden

If this doesn't already exist, it should be added to the list of colormaps and documented with a cookbook recipe.

Idea came from #2191

public class PaletteColormap : ScottPlot.Drawing.IColormap
{
    public string Name => "SpecialColormap";

    private readonly byte[] RedValues = new byte[256];
    private readonly byte[] GreenValues = new byte[256];
    private readonly byte[] BlueValues = new byte[256];

    public PaletteColormap(Color[] colors)
    {
        for (int i = 0; i < RedValues.Length; i++)
        {
            int colorIndex = colors.Length * i / RedValues.Length;
            RedValues[i] = colors[colorIndex].R;
            GreenValues[i] = colors[colorIndex].G;
            BlueValues[i] = colors[colorIndex].B;
        }
    }

    public (byte r, byte g, byte b) GetRGB(byte value)
    {
        return (RedValues[value], GreenValues[value], BlueValues[value]);
    }
}

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions