IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
ColorPalette.cs
Go to the documentation of this file.
2
11public class ColorPalette : Color
12{
13 private readonly Color[] _palette;
14 private int _index;
15
26 public ColorPalette(params Color[] colors)
27 : base(0, 0, 0)
28 {
29 if (colors == null || colors.Length == 0)
30 {
31 throw new IcvNotPossibleException(
32 "The given array is empty or null. Please provide an array with at least one element.");
33 }
34
35 ColorCode = colors[0].ColorCode;
36 _palette = colors;
37 }
38
72 public ColorPalette(ColorPaletteConstant constant, byte numBitsPerPixel = 8)
73 : base(0, 0, 0)
74 {
75 _palette = constant switch
76 {
77 ColorPaletteConstant.Colored3 => new Color[]
78 {
79 new(ColorConstant.Red, numBitsPerPixel),
80 new(ColorConstant.Green, numBitsPerPixel),
81 new(ColorConstant.Blue, numBitsPerPixel)
82 },
83 ColorPaletteConstant.Colored6 => new Color[]
84 {
85 new(ColorConstant.Red, numBitsPerPixel),
86 new(ColorConstant.Green, numBitsPerPixel),
87 new(ColorConstant.Blue, numBitsPerPixel),
88 new(ColorConstant.Yellow, numBitsPerPixel),
89 new(ColorConstant.Magenta, numBitsPerPixel),
90 new(ColorConstant.Cyan, numBitsPerPixel)
91 },
92 _ => throw new IcvNotSupportedException("The given color palette constant is not supported.")
93 };
94
95 ColorCode = _palette[0].ColorCode;
96 }
97
102 public new (int r, int g, int b) RGB
103 {
104 get
105 {
106 (ushort r, ushort g, ushort b) rgb = base.RGB;
107 NextColor();
108 return (rgb.r, rgb.g, rgb.b);
109 }
110 }
111
116 private void NextColor()
117 {
118 _index = (_index + 1) % _palette.Length;
119 ColorCode = _palette[_index].ColorCode;
120 }
121}
Occurs when a requested operation is not implemented or supported (e.g., exporting to an unsupported ...
Definition Exception.cs:62
Class holding color codes.
Definition Color.cs:9
ulong ColorCode
The color code.
Definition Color.cs:105
ushort r
The color as a tuple of red, green and blue values.
Definition Color.cs:111
ushort ushort ushort b RGB
Definition Color.cs:111
Class holding a color palette (a set of colors).
ColorPalette(ColorPaletteConstant constant, byte numBitsPerPixel=8)
Creates a color palette from a color palette constant.
ColorPalette(params Color[] colors)
Creates a color palette from the given colors.
ColorConstant
Enum class for color constants.
ColorPaletteConstant
Enum class for color palette constants.