comparison layer/ColourMapper.cpp @ 902:a1226b3b7925 cxx11

Toward building with new sv types
author Chris Cannam
date Wed, 04 Mar 2015 19:11:32 +0000
parents 1d526ba11a24
children e0f08e108064
comparison
equal deleted inserted replaced
901:0fe1f4407261 902:a1226b3b7925
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 red = 0.0, green = 0.3333;
82 float blue = 0.6666f, pieslice = 0.3333f; 82 double blue = 0.6666f, pieslice = 0.3333;
83 83
84 if (m_map >= getColourMapCount()) return Qt::black; 84 if (m_map >= getColourMapCount()) return Qt::black;
85 StandardMap map = (StandardMap)m_map; 85 StandardMap map = (StandardMap)m_map;
86 86
87 switch (map) { 87 switch (map) {
88 88
89 case DefaultColours: 89 case DefaultColours:
90 h = blue - norm * 2.f * pieslice; 90 h = blue - norm * 2.0 * pieslice;
91 s = 0.5f + norm/2.f; 91 s = 0.5f + norm/2.0;
92 v = norm; 92 v = norm;
93 break; 93 break;
94 94
95 case WhiteOnBlack: 95 case WhiteOnBlack:
96 r = g = b = norm; 96 r = g = b = norm;
97 hsv = false; 97 hsv = false;
98 break; 98 break;
99 99
100 case BlackOnWhite: 100 case BlackOnWhite:
101 r = g = b = 1.f - norm; 101 r = g = b = 1.0 - norm;
102 hsv = false; 102 hsv = false;
103 break; 103 break;
104 104
105 case RedOnBlue: 105 case RedOnBlue:
106 h = blue - pieslice/4.f + norm * (pieslice + pieslice/4.f); 106 h = blue - pieslice/4.0 + norm * (pieslice + pieslice/4.0);
107 s = 1.f; 107 s = 1.0;
108 v = norm; 108 v = norm;
109 break; 109 break;
110 110
111 case YellowOnBlack: 111 case YellowOnBlack:
112 h = 0.15f; 112 h = 0.15;
113 s = 1.f; 113 s = 1.0;
114 v = norm; 114 v = norm;
115 break; 115 break;
116 116
117 case BlueOnBlack: 117 case BlueOnBlack:
118 h = blue; 118 h = blue;
119 s = 1.f; 119 s = 1.0;
120 v = norm * 2.f; 120 v = norm * 2.0;
121 if (v > 1.f) { 121 if (v > 1.0) {
122 v = 1.f; 122 v = 1.0;
123 s = 1.f - (sqrtf(norm) - 0.707f) * 3.413f; 123 s = 1.0 - (sqrtf(norm) - 0.707) * 3.413;
124 if (s < 0.f) s = 0.f; 124 if (s < 0.0) s = 0.0;
125 if (s > 1.f) s = 1.f; 125 if (s > 1.0) s = 1.0;
126 } 126 }
127 break; 127 break;
128 128
129 case Sunset: 129 case Sunset:
130 r = (norm - 0.24f) * 2.38f; 130 r = (norm - 0.24) * 2.38;
131 if (r > 1.f) r = 1.f; 131 if (r > 1.0) r = 1.0;
132 if (r < 0.f) r = 0.f; 132 if (r < 0.0) r = 0.0;
133 g = (norm - 0.64f) * 2.777f; 133 g = (norm - 0.64) * 2.777;
134 if (g > 1.f) g = 1.f; 134 if (g > 1.0) g = 1.0;
135 if (g < 0.f) g = 0.f; 135 if (g < 0.0) g = 0.0;
136 b = (3.6f * norm); 136 b = (3.6f * norm);
137 if (norm > 0.277f) b = 2.f - b; 137 if (norm > 0.277) b = 2.0 - b;
138 if (b > 1.f) b = 1.f; 138 if (b > 1.0) b = 1.0;
139 if (b < 0.f) b = 0.f; 139 if (b < 0.0) b = 0.0;
140 hsv = false; 140 hsv = false;
141 break; 141 break;
142 142
143 case FruitSalad: 143 case FruitSalad:
144 h = blue + (pieslice/6.f) - norm; 144 h = blue + (pieslice/6.0) - norm;
145 if (h < 0.f) h += 1.f; 145 if (h < 0.0) h += 1.0;
146 s = 1.f; 146 s = 1.0;
147 v = 1.f; 147 v = 1.0;
148 break; 148 break;
149 149
150 case Banded: 150 case Banded:
151 if (norm < 0.125) return Qt::darkGreen; 151 if (norm < 0.125) return Qt::darkGreen;
152 else if (norm < 0.25) return Qt::green; 152 else if (norm < 0.25) return Qt::green;
162 if (norm > 0.99) return Qt::white; 162 if (norm > 0.99) return Qt::white;
163 else return Qt::darkBlue; 163 else return Qt::darkBlue;
164 164
165 case Printer: 165 case Printer:
166 if (norm > 0.8) { 166 if (norm > 0.8) {
167 r = 1.f; 167 r = 1.0;
168 } else if (norm > 0.7) { 168 } else if (norm > 0.7) {
169 r = 0.9f; 169 r = 0.9;
170 } else if (norm > 0.6) { 170 } else if (norm > 0.6) {
171 r = 0.8f; 171 r = 0.8;
172 } else if (norm > 0.5) { 172 } else if (norm > 0.5) {
173 r = 0.7f; 173 r = 0.7;
174 } else if (norm > 0.4) { 174 } else if (norm > 0.4) {
175 r = 0.6f; 175 r = 0.6;
176 } else if (norm > 0.3) { 176 } else if (norm > 0.3) {
177 r = 0.5f; 177 r = 0.5;
178 } else if (norm > 0.2) { 178 } else if (norm > 0.2) {
179 r = 0.4f; 179 r = 0.4;
180 } else { 180 } else {
181 r = 0.f; 181 r = 0.0;
182 } 182 }
183 r = g = b = 1.f - r; 183 r = g = b = 1.0 - r;
184 hsv = false; 184 hsv = false;
185 break; 185 break;
186 186
187 case HighGain: 187 case HighGain:
188 if (norm <= 1.f / 256.f) { 188 if (norm <= 1.0 / 256.0) {
189 norm = 0.f; 189 norm = 0.0;
190 } else { 190 } else {
191 norm = 0.1f + (powf(((norm - 0.5f) * 2.f), 3.f) + 1.f) / 2.081f; 191 norm = 0.1f + (powf(((norm - 0.5) * 2.0), 3.0) + 1.0) / 2.081;
192 } 192 }
193 // now as for Sunset 193 // now as for Sunset
194 r = (norm - 0.24f) * 2.38f; 194 r = (norm - 0.24) * 2.38;
195 if (r > 1.f) r = 1.f; 195 if (r > 1.0) r = 1.0;
196 if (r < 0.f) r = 0.f; 196 if (r < 0.0) r = 0.0;
197 g = (norm - 0.64f) * 2.777f; 197 g = (norm - 0.64) * 2.777;
198 if (g > 1.f) g = 1.f; 198 if (g > 1.0) g = 1.0;
199 if (g < 0.f) g = 0.f; 199 if (g < 0.0) g = 0.0;
200 b = (3.6f * norm); 200 b = (3.6f * norm);
201 if (norm > 0.277f) b = 2.f - b; 201 if (norm > 0.277) b = 2.0 - b;
202 if (b > 1.f) b = 1.f; 202 if (b > 1.0) b = 1.0;
203 if (b < 0.f) b = 0.f; 203 if (b < 0.0) b = 0.0;
204 hsv = false; 204 hsv = false;
205 /* 205 /*
206 if (r > 1.f) r = 1.f; 206 if (r > 1.0) r = 1.0;
207 r = g = b = 1.f - r; 207 r = g = b = 1.0 - r;
208 hsv = false; 208 hsv = false;
209 */ 209 */
210 break; 210 break;
211 } 211 }
212 212