Skip to content

Commit 9d5c3a4

Browse files
committed
brightness reduction in colormap gen
1 parent a3a9a81 commit 9d5c3a4

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

misc/generate_colormap_constant.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,38 @@
22

33
import numpy as np
44
import matplotlib.cm
5+
import matplotlib.pyplot as plt
6+
import colorsys
57

68
nValues = 500;
79

810
# get a matplotlib colormap
9-
# cmapName = 'Spectral'
10-
# cmap = matplotlib.cm.get_cmap(cmapName)
11+
cmapName = 'hsv'
12+
cmap = plt.get_cmap(cmapName)
1113

1214
# get a cmocean colormap
13-
import cmocean
14-
cmapName = 'phase'
15-
cmap = cmocean.cm.phase
15+
# import cmocean
16+
# cmapName = 'phase'
17+
# cmap = cmocean.cm.phase
1618

1719

1820
print("static const Colormap CM_" + cmapName.upper() + " = {")
1921
print(" \"" + cmapName + "\",")
2022

23+
def reduce_brightness_rgb(color, factor):
24+
r, g, b = color
25+
h, l, s = colorsys.rgb_to_hls(r, g, b)
26+
l = max(0, l * factor) # Ensure lightness remains non-negative
27+
r, g, b = colorsys.hls_to_rgb(h, l, s)
28+
return tuple(x for x in (r, g, b))
29+
2130
dataStr = "{"
2231
for i in range(nValues):
2332

2433
floatInd = float(i) / (nValues-1)
2534
color = cmap(floatInd)
35+
color = (color[0], color[1], color[2])
36+
# color = reduce_brightness_rgb(color, 0.85) # optional: dim bright colormaps a little
2637

2738
dataStr += "{" + str(color[0]) + "," + str(color[1]) + "," + str(color[2]) + "},"
2839

0 commit comments

Comments
 (0)