From 9d5c3a4b21e95d1d72a8c4e40e9760b9d43a2042 Mon Sep 17 00:00:00 2001 From: Nicholas Sharp Date: Mon, 30 Dec 2024 12:48:46 -0500 Subject: [PATCH] brightness reduction in colormap gen --- misc/generate_colormap_constant.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/misc/generate_colormap_constant.py b/misc/generate_colormap_constant.py index 36a37a0c..bf58fd5a 100644 --- a/misc/generate_colormap_constant.py +++ b/misc/generate_colormap_constant.py @@ -2,27 +2,38 @@ import numpy as np import matplotlib.cm +import matplotlib.pyplot as plt +import colorsys nValues = 500; # get a matplotlib colormap -# cmapName = 'Spectral' -# cmap = matplotlib.cm.get_cmap(cmapName) +cmapName = 'hsv' +cmap = plt.get_cmap(cmapName) # get a cmocean colormap -import cmocean -cmapName = 'phase' -cmap = cmocean.cm.phase +# import cmocean +# cmapName = 'phase' +# cmap = cmocean.cm.phase print("static const Colormap CM_" + cmapName.upper() + " = {") print(" \"" + cmapName + "\",") +def reduce_brightness_rgb(color, factor): + r, g, b = color + h, l, s = colorsys.rgb_to_hls(r, g, b) + l = max(0, l * factor) # Ensure lightness remains non-negative + r, g, b = colorsys.hls_to_rgb(h, l, s) + return tuple(x for x in (r, g, b)) + dataStr = "{" for i in range(nValues): floatInd = float(i) / (nValues-1) color = cmap(floatInd) + color = (color[0], color[1], color[2]) + # color = reduce_brightness_rgb(color, 0.85) # optional: dim bright colormaps a little dataStr += "{" + str(color[0]) + "," + str(color[1]) + "," + str(color[2]) + "},"