Skip to content

Commit cf57893

Browse files
committed
colormaps in ImU32 format
1 parent 6cb6ef9 commit cf57893

File tree

4 files changed

+371
-667
lines changed

4 files changed

+371
-667
lines changed

resources/sample-colormap.py

+12-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def main(arguments):
2525
parser.add_argument("-n", "--num-samples", type=int, default=256, help="The number of samples to generate.")
2626
parser.add_argument("-a", "--include-alpha", action="store_true", help="Include the alpha channel in the output.")
2727
parser.add_argument("-l", "--linearize", action="store_true", help="Output linear (instead of sRGB encoded) values.")
28+
parser.add_argument("-b", "--bit-depth", type=int, choices=[8, 16, 32], default=32, help="Bit depth of the output values.")
2829

2930
args = parser.parse_args(arguments)
3031

@@ -40,9 +41,17 @@ def main(arguments):
4041
if args.include_alpha:
4142
values = np.column_stack((values, alpha))
4243

43-
values = ",\n ".join(["{" + ", ".join([str(y) + "f" for y in x]) + "}" for x in values]) + ","
44-
print(f"static const std::vector<float4> data = {{\n {values}\n}};")
45-
44+
if args.bit_depth == 8:
45+
values = (values * 255).astype(int)
46+
values = ",\n ".join(["IM_COL32(" + ", ".join([str(y) for y in x]) + ")" for x in values]) + ","
47+
print(f"static const std::vector<ImU32> data = {{\n {values}\n}};")
48+
elif args.bit_depth == 16:
49+
values = (values * 65535).astype(int)
50+
values = ",\n ".join(["{" + ", ".join([str(y) for y in x]) + "}" for x in values]) + ","
51+
print(f"static const std::vector<ushort4> data = {{\n {values}\n}};")
52+
else:
53+
values = ",\n ".join(["{" + ", ".join([f"{y:.6f}f" for y in x]) + "}" for x in values]) + ","
54+
print(f"static const std::vector<float4> data = {{\n {values}\n}};")
4655

4756
if __name__ == "__main__":
4857
sys.exit(main(sys.argv[1:]))

src/app.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -2727,8 +2727,7 @@ void HDRViewApp::draw_top_toolbar()
27272727
ImGui::PopStyleVar();
27282728
if (tmp)
27292729
{
2730-
auto maps = {Colormap_Viridis, Colormap_Plasma, Colormap_Inferno,
2731-
Colormap_Turbo, Colormap_IceFire, Colormap_CoolWarm};
2730+
auto maps = {Colormap_Viridis, Colormap_Inferno, Colormap_Turbo, Colormap_IceFire, Colormap_CoolWarm};
27322731
for (auto n : maps)
27332732
{
27342733
const bool is_selected = (m_colormap == n);

0 commit comments

Comments
 (0)