Mercurial > hg > svgui
comparison layer/ColourMapper.cpp @ 944:78c152e4db95
Merge from branch tonioni
author | Chris Cannam |
---|---|
date | Mon, 20 Apr 2015 09:12:17 +0100 |
parents | 6e2a034f7117 |
children | 2a85ab180d08 |
comparison
equal
deleted
inserted
replaced
896:78e041e45ff0 | 944:78c152e4db95 |
---|---|
19 | 19 |
20 #include <cmath> | 20 #include <cmath> |
21 | 21 |
22 #include "base/Debug.h" | 22 #include "base/Debug.h" |
23 | 23 |
24 ColourMapper::ColourMapper(int map, float min, float max) : | 24 ColourMapper::ColourMapper(int map, double min, double max) : |
25 QObject(), | 25 QObject(), |
26 m_map(map), | 26 m_map(map), |
27 m_min(min), | 27 m_min(min), |
28 m_max(max) | 28 m_max(max) |
29 { | 29 { |
67 | 67 |
68 return tr("<unknown>"); | 68 return tr("<unknown>"); |
69 } | 69 } |
70 | 70 |
71 QColor | 71 QColor |
72 ColourMapper::map(float value) const | 72 ColourMapper::map(double value) const |
73 { | 73 { |
74 float norm = (value - m_min) / (m_max - m_min); | 74 double norm = (value - m_min) / (m_max - m_min); |
75 if (norm < 0.f) norm = 0.f; | 75 if (norm < 0.0) norm = 0.0; |
76 if (norm > 1.f) norm = 1.f; | 76 if (norm > 1.0) norm = 1.0; |
77 | 77 |
78 float h = 0.f, s = 0.f, v = 0.f, r = 0.f, g = 0.f, b = 0.f; | 78 double h = 0.0, s = 0.0, v = 0.0, r = 0.0, g = 0.0, b = 0.0; |
79 bool hsv = true; | 79 bool hsv = true; |
80 | 80 |
81 // float red = 0.f, green = 0.3333f; | 81 double blue = 0.6666, pieslice = 0.3333; |
82 float blue = 0.6666f, pieslice = 0.3333f; | |
83 | 82 |
84 if (m_map >= getColourMapCount()) return Qt::black; | 83 if (m_map >= getColourMapCount()) return Qt::black; |
85 StandardMap map = (StandardMap)m_map; | 84 StandardMap map = (StandardMap)m_map; |
86 | 85 |
87 switch (map) { | 86 switch (map) { |
88 | 87 |
89 case DefaultColours: | 88 case DefaultColours: |
90 h = blue - norm * 2.f * pieslice; | 89 h = blue - norm * 2.0 * pieslice; |
91 s = 0.5f + norm/2.f; | 90 s = 0.5f + norm/2.0; |
92 v = norm; | 91 v = norm; |
93 break; | 92 break; |
94 | 93 |
95 case WhiteOnBlack: | 94 case WhiteOnBlack: |
96 r = g = b = norm; | 95 r = g = b = norm; |
97 hsv = false; | 96 hsv = false; |
98 break; | 97 break; |
99 | 98 |
100 case BlackOnWhite: | 99 case BlackOnWhite: |
101 r = g = b = 1.f - norm; | 100 r = g = b = 1.0 - norm; |
102 hsv = false; | 101 hsv = false; |
103 break; | 102 break; |
104 | 103 |
105 case RedOnBlue: | 104 case RedOnBlue: |
106 h = blue - pieslice/4.f + norm * (pieslice + pieslice/4.f); | 105 h = blue - pieslice/4.0 + norm * (pieslice + pieslice/4.0); |
107 s = 1.f; | 106 s = 1.0; |
108 v = norm; | 107 v = norm; |
109 break; | 108 break; |
110 | 109 |
111 case YellowOnBlack: | 110 case YellowOnBlack: |
112 h = 0.15f; | 111 h = 0.15; |
113 s = 1.f; | 112 s = 1.0; |
114 v = norm; | 113 v = norm; |
115 break; | 114 break; |
116 | 115 |
117 case BlueOnBlack: | 116 case BlueOnBlack: |
118 h = blue; | 117 h = blue; |
119 s = 1.f; | 118 s = 1.0; |
120 v = norm * 2.f; | 119 v = norm * 2.0; |
121 if (v > 1.f) { | 120 if (v > 1.0) { |
122 v = 1.f; | 121 v = 1.0; |
123 s = 1.f - (sqrtf(norm) - 0.707f) * 3.413f; | 122 s = 1.0 - (sqrt(norm) - 0.707) * 3.413; |
124 if (s < 0.f) s = 0.f; | 123 if (s < 0.0) s = 0.0; |
125 if (s > 1.f) s = 1.f; | 124 if (s > 1.0) s = 1.0; |
126 } | 125 } |
127 break; | 126 break; |
128 | 127 |
129 case Sunset: | 128 case Sunset: |
130 r = (norm - 0.24f) * 2.38f; | 129 r = (norm - 0.24) * 2.38; |
131 if (r > 1.f) r = 1.f; | 130 if (r > 1.0) r = 1.0; |
132 if (r < 0.f) r = 0.f; | 131 if (r < 0.0) r = 0.0; |
133 g = (norm - 0.64f) * 2.777f; | 132 g = (norm - 0.64) * 2.777; |
134 if (g > 1.f) g = 1.f; | 133 if (g > 1.0) g = 1.0; |
135 if (g < 0.f) g = 0.f; | 134 if (g < 0.0) g = 0.0; |
136 b = (3.6f * norm); | 135 b = (3.6f * norm); |
137 if (norm > 0.277f) b = 2.f - b; | 136 if (norm > 0.277) b = 2.0 - b; |
138 if (b > 1.f) b = 1.f; | 137 if (b > 1.0) b = 1.0; |
139 if (b < 0.f) b = 0.f; | 138 if (b < 0.0) b = 0.0; |
140 hsv = false; | 139 hsv = false; |
141 break; | 140 break; |
142 | 141 |
143 case FruitSalad: | 142 case FruitSalad: |
144 h = blue + (pieslice/6.f) - norm; | 143 h = blue + (pieslice/6.0) - norm; |
145 if (h < 0.f) h += 1.f; | 144 if (h < 0.0) h += 1.0; |
146 s = 1.f; | 145 s = 1.0; |
147 v = 1.f; | 146 v = 1.0; |
148 break; | 147 break; |
149 | 148 |
150 case Banded: | 149 case Banded: |
151 if (norm < 0.125) return Qt::darkGreen; | 150 if (norm < 0.125) return Qt::darkGreen; |
152 else if (norm < 0.25) return Qt::green; | 151 else if (norm < 0.25) return Qt::green; |
162 if (norm > 0.99) return Qt::white; | 161 if (norm > 0.99) return Qt::white; |
163 else return Qt::darkBlue; | 162 else return Qt::darkBlue; |
164 | 163 |
165 case Printer: | 164 case Printer: |
166 if (norm > 0.8) { | 165 if (norm > 0.8) { |
167 r = 1.f; | 166 r = 1.0; |
168 } else if (norm > 0.7) { | 167 } else if (norm > 0.7) { |
169 r = 0.9f; | 168 r = 0.9; |
170 } else if (norm > 0.6) { | 169 } else if (norm > 0.6) { |
171 r = 0.8f; | 170 r = 0.8; |
172 } else if (norm > 0.5) { | 171 } else if (norm > 0.5) { |
173 r = 0.7f; | 172 r = 0.7; |
174 } else if (norm > 0.4) { | 173 } else if (norm > 0.4) { |
175 r = 0.6f; | 174 r = 0.6; |
176 } else if (norm > 0.3) { | 175 } else if (norm > 0.3) { |
177 r = 0.5f; | 176 r = 0.5; |
178 } else if (norm > 0.2) { | 177 } else if (norm > 0.2) { |
179 r = 0.4f; | 178 r = 0.4; |
180 } else { | 179 } else { |
181 r = 0.f; | 180 r = 0.0; |
182 } | 181 } |
183 r = g = b = 1.f - r; | 182 r = g = b = 1.0 - r; |
184 hsv = false; | 183 hsv = false; |
185 break; | 184 break; |
186 | 185 |
187 case HighGain: | 186 case HighGain: |
188 if (norm <= 1.f / 256.f) { | 187 if (norm <= 1.0 / 256.0) { |
189 norm = 0.f; | 188 norm = 0.0; |
190 } else { | 189 } else { |
191 norm = 0.1f + (powf(((norm - 0.5f) * 2.f), 3.f) + 1.f) / 2.081f; | 190 norm = 0.1f + (pow(((norm - 0.5) * 2.0), 3.0) + 1.0) / 2.081; |
192 } | 191 } |
193 // now as for Sunset | 192 // now as for Sunset |
194 r = (norm - 0.24f) * 2.38f; | 193 r = (norm - 0.24) * 2.38; |
195 if (r > 1.f) r = 1.f; | 194 if (r > 1.0) r = 1.0; |
196 if (r < 0.f) r = 0.f; | 195 if (r < 0.0) r = 0.0; |
197 g = (norm - 0.64f) * 2.777f; | 196 g = (norm - 0.64) * 2.777; |
198 if (g > 1.f) g = 1.f; | 197 if (g > 1.0) g = 1.0; |
199 if (g < 0.f) g = 0.f; | 198 if (g < 0.0) g = 0.0; |
200 b = (3.6f * norm); | 199 b = (3.6f * norm); |
201 if (norm > 0.277f) b = 2.f - b; | 200 if (norm > 0.277) b = 2.0 - b; |
202 if (b > 1.f) b = 1.f; | 201 if (b > 1.0) b = 1.0; |
203 if (b < 0.f) b = 0.f; | 202 if (b < 0.0) b = 0.0; |
204 hsv = false; | 203 hsv = false; |
205 /* | 204 /* |
206 if (r > 1.f) r = 1.f; | 205 if (r > 1.0) r = 1.0; |
207 r = g = b = 1.f - r; | 206 r = g = b = 1.0 - r; |
208 hsv = false; | 207 hsv = false; |
209 */ | 208 */ |
210 break; | 209 break; |
211 } | 210 } |
212 | 211 |