Skip to content

Commit 0a4c7d9

Browse files
committed
bring old colormaps
1 parent f8e5a6d commit 0a4c7d9

7 files changed

Lines changed: 1497 additions & 0 deletions

File tree

Lines changed: 292 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,292 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Drawing;
4+
using System.Drawing.Imaging;
5+
using System.Text;
6+
7+
namespace Spectrogram.Colormaps
8+
{
9+
public class Cividis : IColormap
10+
{
11+
public string GetName()
12+
{
13+
return "Cividis"; // TODO: use reflection
14+
}
15+
16+
public void Apply(Bitmap bmp)
17+
{
18+
ColorPalette pal = bmp.Palette;
19+
for (int i = 0; i < 256; i++)
20+
pal.Entries[i] = Color.FromArgb(255, RGB[i, 0], RGB[i, 1], RGB[i, 2]);
21+
bmp.Palette = pal;
22+
}
23+
24+
public (byte r, byte g, byte b) Lookup(int value)
25+
{
26+
value = Math.Max(value, 0);
27+
value = Math.Min(value, 255);
28+
return (RGB[value, 0], RGB[value, 1], RGB[value, 2]);
29+
}
30+
31+
// cividis
32+
public readonly byte[,] RGB =
33+
{
34+
{0, 34, 78},
35+
{0, 35, 79},
36+
{0, 36, 81},
37+
{0, 36, 82},
38+
{0, 37, 84},
39+
{0, 38, 86},
40+
{0, 39, 87},
41+
{0, 39, 89},
42+
{0, 40, 91},
43+
{0, 41, 93},
44+
{0, 41, 95},
45+
{0, 42, 96},
46+
{0, 43, 98},
47+
{0, 43, 100},
48+
{0, 44, 102},
49+
{0, 45, 104},
50+
{0, 45, 106},
51+
{0, 46, 107},
52+
{0, 47, 109},
53+
{0, 47, 111},
54+
{0, 48, 112},
55+
{0, 48, 112},
56+
{0, 49, 113},
57+
{0, 50, 113},
58+
{4, 50, 112},
59+
{8, 51, 112},
60+
{11, 52, 112},
61+
{14, 52, 112},
62+
{17, 53, 112},
63+
{20, 54, 112},
64+
{22, 55, 111},
65+
{24, 55, 111},
66+
{26, 56, 111},
67+
{28, 57, 111},
68+
{30, 57, 111},
69+
{31, 58, 110},
70+
{33, 59, 110},
71+
{35, 59, 110},
72+
{36, 60, 110},
73+
{38, 61, 110},
74+
{39, 62, 110},
75+
{40, 62, 109},
76+
{42, 63, 109},
77+
{43, 64, 109},
78+
{44, 64, 109},
79+
{46, 65, 109},
80+
{47, 66, 109},
81+
{48, 66, 109},
82+
{49, 67, 109},
83+
{51, 68, 108},
84+
{52, 69, 108},
85+
{53, 69, 108},
86+
{54, 70, 108},
87+
{55, 71, 108},
88+
{56, 71, 108},
89+
{58, 72, 108},
90+
{59, 73, 108},
91+
{60, 73, 108},
92+
{61, 74, 108},
93+
{62, 75, 108},
94+
{63, 76, 108},
95+
{64, 76, 108},
96+
{65, 77, 108},
97+
{66, 78, 108},
98+
{67, 78, 108},
99+
{68, 79, 108},
100+
{69, 80, 108},
101+
{70, 80, 108},
102+
{71, 81, 108},
103+
{72, 82, 108},
104+
{73, 82, 108},
105+
{74, 83, 108},
106+
{75, 84, 108},
107+
{76, 85, 108},
108+
{77, 85, 108},
109+
{78, 86, 108},
110+
{79, 87, 108},
111+
{80, 87, 108},
112+
{81, 88, 108},
113+
{82, 89, 109},
114+
{83, 89, 109},
115+
{83, 90, 109},
116+
{84, 91, 109},
117+
{85, 92, 109},
118+
{86, 92, 109},
119+
{87, 93, 109},
120+
{88, 94, 109},
121+
{89, 94, 109},
122+
{90, 95, 110},
123+
{91, 96, 110},
124+
{92, 96, 110},
125+
{93, 97, 110},
126+
{93, 98, 110},
127+
{94, 99, 110},
128+
{95, 99, 111},
129+
{96, 100, 111},
130+
{97, 101, 111},
131+
{98, 101, 111},
132+
{99, 102, 111},
133+
{100, 103, 112},
134+
{101, 103, 112},
135+
{101, 104, 112},
136+
{102, 105, 112},
137+
{103, 106, 113},
138+
{104, 106, 113},
139+
{105, 107, 113},
140+
{106, 108, 113},
141+
{107, 108, 114},
142+
{107, 109, 114},
143+
{108, 110, 114},
144+
{109, 111, 114},
145+
{110, 111, 115},
146+
{111, 112, 115},
147+
{112, 113, 115},
148+
{113, 114, 116},
149+
{113, 114, 116},
150+
{114, 115, 116},
151+
{115, 116, 117},
152+
{116, 116, 117},
153+
{117, 117, 117},
154+
{118, 118, 118},
155+
{119, 119, 118},
156+
{119, 119, 119},
157+
{120, 120, 119},
158+
{121, 121, 119},
159+
{122, 122, 120},
160+
{123, 122, 120},
161+
{124, 123, 120},
162+
{125, 124, 120},
163+
{126, 124, 120},
164+
{126, 125, 120},
165+
{127, 126, 120},
166+
{128, 127, 120},
167+
{129, 127, 120},
168+
{130, 128, 120},
169+
{131, 129, 120},
170+
{132, 130, 121},
171+
{133, 130, 120},
172+
{134, 131, 121},
173+
{135, 132, 120},
174+
{136, 133, 120},
175+
{137, 133, 120},
176+
{138, 134, 120},
177+
{139, 135, 120},
178+
{140, 136, 120},
179+
{141, 136, 120},
180+
{142, 137, 120},
181+
{143, 138, 120},
182+
{144, 139, 120},
183+
{145, 139, 120},
184+
{146, 140, 120},
185+
{147, 141, 120},
186+
{148, 142, 119},
187+
{149, 143, 119},
188+
{149, 143, 119},
189+
{150, 144, 119},
190+
{151, 145, 119},
191+
{152, 146, 119},
192+
{153, 146, 119},
193+
{154, 147, 118},
194+
{155, 148, 118},
195+
{156, 149, 118},
196+
{157, 149, 118},
197+
{158, 150, 118},
198+
{159, 151, 117},
199+
{160, 152, 117},
200+
{161, 153, 117},
201+
{162, 153, 117},
202+
{163, 154, 116},
203+
{164, 155, 116},
204+
{165, 156, 116},
205+
{166, 157, 116},
206+
{167, 157, 115},
207+
{168, 158, 115},
208+
{169, 159, 115},
209+
{171, 160, 115},
210+
{172, 161, 114},
211+
{173, 161, 114},
212+
{174, 162, 114},
213+
{175, 163, 113},
214+
{176, 164, 113},
215+
{177, 165, 113},
216+
{178, 165, 112},
217+
{179, 166, 112},
218+
{180, 167, 111},
219+
{181, 168, 111},
220+
{182, 169, 111},
221+
{183, 170, 110},
222+
{184, 170, 110},
223+
{185, 171, 109},
224+
{186, 172, 109},
225+
{187, 173, 108},
226+
{188, 174, 108},
227+
{189, 175, 108},
228+
{190, 175, 107},
229+
{191, 176, 107},
230+
{192, 177, 106},
231+
{193, 178, 106},
232+
{194, 179, 105},
233+
{195, 180, 105},
234+
{196, 181, 104},
235+
{198, 181, 104},
236+
{199, 182, 103},
237+
{200, 183, 102},
238+
{201, 184, 102},
239+
{202, 185, 101},
240+
{203, 186, 101},
241+
{204, 187, 100},
242+
{205, 187, 99},
243+
{206, 188, 99},
244+
{207, 189, 98},
245+
{208, 190, 97},
246+
{209, 191, 97},
247+
{210, 192, 96},
248+
{211, 193, 95},
249+
{213, 194, 95},
250+
{214, 194, 94},
251+
{215, 195, 93},
252+
{216, 196, 92},
253+
{217, 197, 92},
254+
{218, 198, 91},
255+
{219, 199, 90},
256+
{220, 200, 89},
257+
{221, 201, 88},
258+
{222, 202, 87},
259+
{224, 203, 86},
260+
{225, 203, 86},
261+
{226, 204, 85},
262+
{227, 205, 84},
263+
{228, 206, 83},
264+
{229, 207, 82},
265+
{230, 208, 81},
266+
{231, 209, 80},
267+
{232, 210, 79},
268+
{234, 211, 77},
269+
{235, 212, 76},
270+
{236, 213, 75},
271+
{237, 214, 74},
272+
{238, 215, 73},
273+
{239, 216, 71},
274+
{240, 216, 70},
275+
{242, 217, 69},
276+
{243, 218, 67},
277+
{244, 219, 66},
278+
{245, 220, 64},
279+
{246, 221, 63},
280+
{247, 222, 61},
281+
{249, 223, 60},
282+
{250, 224, 58},
283+
{251, 225, 56},
284+
{252, 226, 54},
285+
{254, 227, 52},
286+
{254, 228, 52},
287+
{254, 229, 53},
288+
{254, 231, 54},
289+
{254, 232, 55},
290+
};
291+
}
292+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Drawing;
4+
using System.Drawing.Imaging;
5+
using System.Text;
6+
7+
namespace Spectrogram.Colormaps
8+
{
9+
public class Grayscale : IColormap
10+
{
11+
public void Apply(Bitmap bmp)
12+
{
13+
ColorPalette pal = bmp.Palette;
14+
for (int i = 0; i < 256; i++)
15+
pal.Entries[i] = Color.FromArgb(255, i, i, i);
16+
bmp.Palette = pal;
17+
}
18+
19+
public string GetName()
20+
{
21+
return "Grayscale";
22+
}
23+
24+
public (byte r, byte g, byte b) Lookup(int value)
25+
{
26+
return ((byte)value, (byte)value, (byte)value);
27+
}
28+
}
29+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Spectrogram.Colormaps
2+
{
3+
public interface IColormap
4+
{
5+
string GetName();
6+
void Apply(System.Drawing.Bitmap bmp);
7+
(byte r, byte g, byte b) Lookup(int value);
8+
}
9+
}

0 commit comments

Comments
 (0)