annotate tools/llvm-xray/xray-color-helper.cc @ 148:63bd29f05246

merged
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Wed, 14 Aug 2019 19:46:37 +0900
parents 3a76565eade5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
121
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
1 //===-- xray-graph.cc - XRay Function Call Graph Renderer -----------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
2 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
3 // The LLVM Compiler Infrastructure
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
4 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
5 // This file is distributed under the University of Illinois Open Source
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
6 // License. See LICENSE.TXT for details.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
7 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
8 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
9 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
10 // A class to get a color from a specified gradient.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
11 //
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
12 //===----------------------------------------------------------------------===//
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
13
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
14 #include "xray-color-helper.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
15 #include "llvm/Support/FormatVariadic.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
16 #include "llvm/Support/raw_ostream.h"
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
17
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
18 using namespace llvm;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
19 using namespace xray;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
20
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
21 // Sequential ColorMaps, which are used to represent information
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
22 // from some minimum to some maximum.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
23
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
24 static const std::tuple<uint8_t, uint8_t, uint8_t> SequentialMaps[][9] = {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
25 {// The greys color scheme from http://colorbrewer2.org/
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
26 std::make_tuple(255, 255, 255), std::make_tuple(240, 240, 240),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
27 std::make_tuple(217, 217, 217), std::make_tuple(189, 189, 189),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
28 std::make_tuple(150, 150, 150), std::make_tuple(115, 115, 115),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
29 std::make_tuple(82, 82, 82), std::make_tuple(37, 37, 37),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
30 std::make_tuple(0, 0, 0)},
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
31 {// The OrRd color scheme from http://colorbrewer2.org/
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
32 std::make_tuple(255, 247, 236), std::make_tuple(254, 232, 200),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
33 std::make_tuple(253, 212, 158), std::make_tuple(253, 187, 132),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
34 std::make_tuple(252, 141, 89), std::make_tuple(239, 101, 72),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
35 std::make_tuple(215, 48, 31), std::make_tuple(179, 0, 0),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
36 std::make_tuple(127, 0, 0)},
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
37 {// The PuBu color scheme from http://colorbrewer2.org/
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
38 std::make_tuple(255, 247, 251), std::make_tuple(236, 231, 242),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
39 std::make_tuple(208, 209, 230), std::make_tuple(166, 189, 219),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
40 std::make_tuple(116, 169, 207), std::make_tuple(54, 144, 192),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
41 std::make_tuple(5, 112, 176), std::make_tuple(4, 90, 141),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
42 std::make_tuple(2, 56, 88)}};
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
43
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
44 // Sequential Maps extend the last colors given out of range inputs.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
45 static const std::tuple<uint8_t, uint8_t, uint8_t> SequentialBounds[][2] = {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
46 {// The Bounds for the greys color scheme
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
47 std::make_tuple(255, 255, 255), std::make_tuple(0, 0, 0)},
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
48 {// The Bounds for the OrRd color Scheme
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
49 std::make_tuple(255, 247, 236), std::make_tuple(127, 0, 0)},
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
50 {// The Bounds for the PuBu color Scheme
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
51 std::make_tuple(255, 247, 251), std::make_tuple(2, 56, 88)}};
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
52
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
53 ColorHelper::ColorHelper(ColorHelper::SequentialScheme S)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
54 : MinIn(0.0), MaxIn(1.0), ColorMap(SequentialMaps[static_cast<int>(S)]),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
55 BoundMap(SequentialBounds[static_cast<int>(S)]) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
56
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
57 // Diverging ColorMaps, which are used to represent information
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
58 // representing differenes, or a range that goes from negative to positive.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
59 // These take an input in the range [-1,1].
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
60
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
61 static const std::tuple<uint8_t, uint8_t, uint8_t> DivergingCoeffs[][11] = {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
62 {// The PiYG color scheme from http://colorbrewer2.org/
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
63 std::make_tuple(142, 1, 82), std::make_tuple(197, 27, 125),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
64 std::make_tuple(222, 119, 174), std::make_tuple(241, 182, 218),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
65 std::make_tuple(253, 224, 239), std::make_tuple(247, 247, 247),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
66 std::make_tuple(230, 245, 208), std::make_tuple(184, 225, 134),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
67 std::make_tuple(127, 188, 65), std::make_tuple(77, 146, 33),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
68 std::make_tuple(39, 100, 25)}};
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
69
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
70 // Diverging maps use out of bounds ranges to show missing data. Missing Right
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
71 // Being below min, and missing left being above max.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
72 static const std::tuple<uint8_t, uint8_t, uint8_t> DivergingBounds[][2] = {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
73 {// The PiYG color scheme has green and red for missing right and left
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
74 // respectively.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
75 std::make_tuple(255, 0, 0), std::make_tuple(0, 255, 0)}};
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
76
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
77 ColorHelper::ColorHelper(ColorHelper::DivergingScheme S)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
78 : MinIn(-1.0), MaxIn(1.0), ColorMap(DivergingCoeffs[static_cast<int>(S)]),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
79 BoundMap(DivergingBounds[static_cast<int>(S)]) {}
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
80
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
81 // Takes a tuple of uint8_ts representing a color in RGB and converts them to
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
82 // HSV represented by a tuple of doubles
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
83 static std::tuple<double, double, double>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
84 convertToHSV(const std::tuple<uint8_t, uint8_t, uint8_t> &Color) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
85 double Scaled[3] = {std::get<0>(Color) / 255.0, std::get<1>(Color) / 255.0,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
86 std::get<2>(Color) / 255.0};
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
87 int Min = 0;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
88 int Max = 0;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
89 for (int i = 1; i < 3; ++i) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
90 if (Scaled[i] < Scaled[Min])
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
91 Min = i;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
92 if (Scaled[i] > Scaled[Max])
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
93 Max = i;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
94 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
95
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
96 double C = Scaled[Max] - Scaled[Min];
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
97
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
98 double HPrime =
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
99 (C == 0) ? 0 : (Scaled[(Max + 1) % 3] - Scaled[(Max + 2) % 3]) / C;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
100 HPrime = HPrime + 2.0 * Max;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
101
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
102 double H = (HPrime < 0) ? (HPrime + 6.0) * 60
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
103 : HPrime * 60; // Scale to between 0 and 360
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
104 double V = Scaled[Max];
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
105
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
106 double S = (V == 0.0) ? 0.0 : C / V;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
107
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
108 return std::make_tuple(H, S, V);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
109 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
110
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
111 // Takes a double precision number, clips it between 0 and 1 and then converts
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
112 // that to an integer between 0x00 and 0xFF with proxpper rounding.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
113 static uint8_t unitIntervalTo8BitChar(double B) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
114 double n = std::max(std::min(B, 1.0), 0.0);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
115 return static_cast<uint8_t>(255 * n + 0.5);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
116 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
117
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
118 // Takes a typle of doubles representing a color in HSV and converts them to
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
119 // RGB represented as a tuple of uint8_ts
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
120 static std::tuple<uint8_t, uint8_t, uint8_t>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
121 convertToRGB(const std::tuple<double, double, double> &Color) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
122 const double &H = std::get<0>(Color);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
123 const double &S = std::get<1>(Color);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
124 const double &V = std::get<2>(Color);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
125
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
126 double C = V * S;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
127
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
128 double HPrime = H / 60;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
129 double X = C * (1 - std::abs(std::fmod(HPrime, 2.0) - 1));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
130
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
131 double RGB1[3];
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
132 int HPrimeInt = static_cast<int>(HPrime);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
133 if (HPrimeInt % 2 == 0) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
134 RGB1[(HPrimeInt / 2) % 3] = C;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
135 RGB1[(HPrimeInt / 2 + 1) % 3] = X;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
136 RGB1[(HPrimeInt / 2 + 2) % 3] = 0.0;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
137 } else {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
138 RGB1[(HPrimeInt / 2) % 3] = X;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
139 RGB1[(HPrimeInt / 2 + 1) % 3] = C;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
140 RGB1[(HPrimeInt / 2 + 2) % 3] = 0.0;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
141 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
142
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
143 double Min = V - C;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
144 double RGB2[3] = {RGB1[0] + Min, RGB1[1] + Min, RGB1[2] + Min};
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
145
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
146 return std::make_tuple(unitIntervalTo8BitChar(RGB2[0]),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
147 unitIntervalTo8BitChar(RGB2[1]),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
148 unitIntervalTo8BitChar(RGB2[2]));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
149 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
150
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
151 // The Hue component of the HSV interpolation Routine
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
152 static double interpolateHue(double H0, double H1, double T) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
153 double D = H1 - H0;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
154 if (H0 > H1) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
155 std::swap(H0, H1);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
156
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
157 D = -D;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
158 T = 1 - T;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
159 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
160
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
161 if (D <= 180) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
162 return H0 + T * (H1 - H0);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
163 } else {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
164 H0 = H0 + 360;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
165 return std::fmod(H0 + T * (H1 - H0) + 720, 360);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
166 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
167 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
168
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
169 // Interpolates between two HSV Colors both represented as a tuple of doubles
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
170 // Returns an HSV Color represented as a tuple of doubles
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
171 static std::tuple<double, double, double>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
172 interpolateHSV(const std::tuple<double, double, double> &C0,
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
173 const std::tuple<double, double, double> &C1, double T) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
174 double H = interpolateHue(std::get<0>(C0), std::get<0>(C1), T);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
175 double S = std::get<1>(C0) + T * (std::get<1>(C1) - std::get<1>(C0));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
176 double V = std::get<2>(C0) + T * (std::get<2>(C1) - std::get<2>(C0));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
177 return std::make_tuple(H, S, V);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
178 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
179
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
180 // Get the Color as a tuple of uint8_ts
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
181 std::tuple<uint8_t, uint8_t, uint8_t>
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
182 ColorHelper::getColorTuple(double Point) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
183 assert(!ColorMap.empty() && "ColorMap must not be empty!");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
184 assert(!BoundMap.empty() && "BoundMap must not be empty!");
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
185
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
186 if (Point < MinIn)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
187 return BoundMap[0];
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
188 if (Point > MaxIn)
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
189 return BoundMap[1];
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
190
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
191 size_t MaxIndex = ColorMap.size() - 1;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
192 double IntervalWidth = MaxIn - MinIn;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
193 double OffsetP = Point - MinIn;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
194 double SectionWidth = IntervalWidth / static_cast<double>(MaxIndex);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
195 size_t SectionNo = std::floor(OffsetP / SectionWidth);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
196 double T = (OffsetP - SectionNo * SectionWidth) / SectionWidth;
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
197
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
198 auto &RGBColor0 = ColorMap[SectionNo];
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
199 auto &RGBColor1 = ColorMap[std::min(SectionNo + 1, MaxIndex)];
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
200
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
201 auto HSVColor0 = convertToHSV(RGBColor0);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
202 auto HSVColor1 = convertToHSV(RGBColor1);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
203
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
204 auto InterpolatedHSVColor = interpolateHSV(HSVColor0, HSVColor1, T);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
205 return convertToRGB(InterpolatedHSVColor);
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
206 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
207
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
208 // A helper method to convert a color represented as tuple of uint8s to a hex
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
209 // string.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
210 std::string
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
211 ColorHelper::getColorString(std::tuple<uint8_t, uint8_t, uint8_t> t) {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
212 return llvm::formatv("#{0:X-2}{1:X-2}{2:X-2}", std::get<0>(t), std::get<1>(t),
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
213 std::get<2>(t));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
214 }
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
215
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
216 // Gets a color in a gradient given a number in the interval [0,1], it does this
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
217 // by evaluating a polynomial which maps [0, 1] -> [0, 1] for each of the R G
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
218 // and B values in the color. It then converts this [0,1] colors to a 24 bit
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
219 // color as a hex string.
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
220 std::string ColorHelper::getColorString(double Point) const {
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
221 return getColorString(getColorTuple(Point));
803732b1fca8 LLVM 5.0
kono
parents:
diff changeset
222 }