55
56
static double hot_r(double s)
57
return s < 0. ? 0. : (s < 3./8. ? 8./3. * s : 1.);
58
return s < 0. ? 0. : (s < 3. / 8. ? 8. / 3. * s : 1.);
60
61
static double hot_g(double s)
62
return s < 3./8. ? 0. : (s < 6./8. ? 8./3. * (s - 3./8.) : 1.);
63
return s < 3. / 8. ? 0. : (s < 6. / 8. ? 8. / 3. * (s - 3. / 8.) : 1.);
65
66
static double hot_b(double s)
67
return s < 6./8. ? 0. : (s < 1. ? 8./2. * (s - 6./8.) : 1.);
68
return s < 6. / 8. ? 0. : (s < 1. ? 8. / 2. * (s - 6. / 8.) : 1.);
70
71
static double cubic(double a, double b, double c, double d, double x)
110
111
case 2: // matlab "jet"
112
double ii = (double)(s-bias)*128.;
114
if(ii > 128) ii = 128;
117
ii >= 111 ? -0.03125*(ii - 111) + 1. :
121
ii <= 14 || ii >= 111 ? 0. :
122
ii >= 79 ? -0.03125*(ii - 111) :
123
ii <= 46 ? 0.03125*(ii - 14) :
127
ii >= 47 ? -0.03125*(ii - 79) :
128
ii <= 14 ? 0.03125*(ii - 14) + 1.:
113
double ii = (double)(s - bias) * 128.;
115
if(ii > 128) ii = 128;
118
ii >= 111 ? -0.03125 * (ii - 111) + 1. :
122
ii <= 14 || ii >= 111 ? 0. :
123
ii >= 79 ? -0.03125 * (ii - 111) :
124
ii <= 46 ? 0.03125 * (ii - 14) :
128
ii >= 47 ? -0.03125 * (ii - 79) :
129
ii <= 14 ? 0.03125 * (ii - 14) + 1.:
131
r = (int)(rr * 255.);
132
g = (int)(gg * 255.);
133
b = (int)(bb * 255.);
135
136
case 3: // lucie, samcef (?)
136
137
if(s - bias <= 0.) {
141
142
else if(s - bias <= 0.40) {
143
g = (int)((s - bias) * 637.5);
144
b = (int)(255. - (s - bias) * 637.5);
144
g = (int)((s - bias) * 637.5);
145
b = (int)(255. - (s - bias) * 637.5);
146
147
else if(s - bias <= 0.60) {
147
r = (int)(1275. * (s - bias - 0.4));
148
r = (int)(1275. * (s - bias - 0.4));
151
152
else if(s - bias <= 1.) {
153
g = (int)(255. - 637.5 * (s - bias - 0.6));
154
g = (int)(255. - 637.5 * (s - bias - 0.6));
162
163
case 4: // rainbow
163
164
if(s - bias <= 0.) {
168
169
else if(s - bias <= 0.25 + curvature) {
169
curvature = (curvature == -0.25) ? -0.26 : curvature;
171
g = (int)((s - bias) * (255. / (0.25 + curvature)));
170
curvature = (curvature == -0.25) ? -0.26 : curvature;
172
g = (int)((s - bias) * (255. / (0.25 + curvature)));
174
175
else if(s - bias <= 0.50) {
175
curvature = (curvature == 0.25) ? 0.26 : curvature;
178
b = (int)(255. - (255. / (0.25 - curvature)) * (s - bias - 0.25 - curvature));
176
curvature = (curvature == 0.25) ? 0.26 : curvature;
179
b = (int)(255. - (255. / (0.25 - curvature)) * (s - bias - 0.25 - curvature));
180
181
else if(s - bias <= 0.75 - curvature) {
181
curvature = (curvature == 0.25) ? 0.26 : curvature;
182
r = (int)((s - bias - 0.5) * (255. / (0.25 - curvature)));
182
curvature = (curvature == 0.25) ? 0.26 : curvature;
183
r = (int)((s - bias - 0.5) * (255. / (0.25 - curvature)));
186
187
else if(s - bias <= 1.) {
187
curvature = (curvature == -0.25) ? -0.26 : curvature;
189
g = (int)(255. - (255. / (0.25 + curvature)) * (s - bias - 0.75 + curvature));
188
curvature = (curvature == -0.25) ? -0.26 : curvature;
190
g = (int)(255. - (255. / (0.25 + curvature)) * (s - bias - 0.75 + curvature));
198
199
case 5: // emc2000 (rainbow with black and white)
199
200
if(s - bias <= 0.) {
204
205
else if(s - bias <= 0.2) {
205
r = (int)(57 * (1 - 100 * ((s - bias) - 0.1) * ((s - bias) - 0.1)));
207
b = (int)((s - bias) * (255. / 0.2));
206
r = (int)(57 * (1 - 100 * ((s - bias) - 0.1) * ((s - bias) - 0.1)));
208
b = (int)((s - bias) * (255. / 0.2));
209
210
else if(s - bias <= 0.3624) {
211
g = (int)((s - bias - 0.2) * (255. / 0.1624));
212
g = (int)((s - bias - 0.2) * (255. / 0.1624));
214
215
else if(s - bias <= 0.50) {
217
b = (int)(255. - (255. / 0.1376) * (s - bias - 0.3624));
218
b = (int)(255. - (255. / 0.1376) * (s - bias - 0.3624));
219
220
else if(s - bias <= 0.6376) {
220
r = (int)((s - bias - 0.5) * (255. / 0.1376));
221
r = (int)((s - bias - 0.5) * (255. / 0.1376));
224
225
else if(s - bias <= 0.8) {
226
g = (int)(255. - (255. / 0.1624) * (s - bias - 0.6376));
227
g = (int)(255. - (255. / 0.1624) * (s - bias - 0.6376));
229
230
else if(s - bias <= 1.0) {
231
g = (int)((255. / 0.2) * (s - bias - 0.8));
232
b = (int)(-3187.66 * (s - bias) * (s - bias) + 7012.76 * (s - bias) - 3570.61);
232
g = (int)((255. / 0.2) * (s - bias - 0.8));
233
b = (int)(-3187.66 * (s - bias) * (s - bias) + 7012.76 * (s - bias) - 3570.61);
240
241
case 6: // darkblue->red->yellow->white
248
249
b = (int)(255. * hot_b(s-bias));
250
251
case 8: // matlab "pink"
251
r = (int)(255. * sqrt((2.*gray(s-bias) + hot_r(s-bias))/3.));
252
g = (int)(255. * sqrt((2.*gray(s-bias) + hot_g(s-bias))/3.));
253
b = (int)(255. * sqrt((2.*gray(s-bias) + hot_b(s-bias))/3.));
252
r = (int)(255. * sqrt((2. * gray(s - bias) + hot_r(s - bias)) / 3.));
253
g = (int)(255. * sqrt((2. * gray(s - bias) + hot_g(s - bias)) / 3.));
254
b = (int)(255. * sqrt((2. * gray(s - bias) + hot_b(s - bias)) / 3.));
255
256
case 9: // grayscale
256
257
if(s - bias <= 0.) {
259
260
else if(s - bias <= 1.) {
260
r = g = b = (int)(255 * (1. - curvature) * (s - bias));
261
r = g = b = (int)(255 * (1. - curvature) * (s - bias));
263
r = g = b = (int)(255 * (1. - curvature));
264
r = g = b = (int)(255 * (1. - curvature));
266
267
case 10: // all white
269
270
case 11: // matlab "hsv"
271
double H = 6. * s + 1.e-10, R, G, B;
272
HSV_to_RGB(H, 1., 1., &R, &G, &B);
272
double H = 6. * s + 1.e-10, R, G, B;
273
HSV_to_RGB(H, 1., 1., &R, &G, &B);
278
279
case 12: // spectrum (truncated hsv)
280
double H = 5. * s + 1.e-10, R, G, B;
281
HSV_to_RGB(H, 1., 1., &R, &G, &B);
281
double H = 5. * s + 1.e-10, R, G, B;
282
HSV_to_RGB(H, 1., 1., &R, &G, &B);
287
288
case 13: // matlab "bone"
288
r = (int)(255. * (7.*gray(s-bias) + hot_b(s-bias))/8.);
289
g = (int)(255. * (7.*gray(s-bias) + hot_g(s-bias))/8.);
290
b = (int)(255. * (7.*gray(s-bias) + hot_r(s-bias))/8.);
289
r = (int)(255. * (7. * gray(s-bias) + hot_b(s - bias)) / 8.);
290
g = (int)(255. * (7. * gray(s-bias) + hot_g(s - bias)) / 8.);
291
b = (int)(255. * (7. * gray(s-bias) + hot_r(s - bias)) / 8.);
292
293
case 14: // matlab "spring"
293
294
r = (int)(255. * 1.);
294
g = (int)(255. * gray(s-bias));
295
b = (int)(255. * (1. - gray(s-bias)));
295
g = (int)(255. * gray(s - bias));
296
b = (int)(255. * (1. - gray(s - bias)));
297
298
case 15: // matlab "summer"
298
r = (int)(255. * gray(s-bias));
299
g = (int)(255. * (0.5+gray(s-bias)/2.));
299
r = (int)(255. * gray(s - bias));
300
g = (int)(255. * (0.5 + gray(s - bias) / 2.));
300
301
b = (int)(255. * 0.4);
302
303
case 16: // matlab "autumn"
303
304
r = (int)(255. * 1.);
304
g = (int)(255. * gray(s-bias));
305
g = (int)(255. * gray(s - bias));
305
306
b = (int)(255. * 0.);
307
308
case 17: // matlab "winter"
308
309
r = (int)(255. * 0.);
309
g = (int)(255. * gray(s-bias));
310
b = (int)(255. * (0.5+(1.-gray(s-bias))/2.));
310
g = (int)(255. * gray(s - bias));
311
b = (int)(255. * (0.5 + (1. - gray(s - bias)) / 2.));
312
313
case 18: // matlab "cool"
313
r = (int)(255. * gray(s-bias));
314
g = (int)(255. * (1.-gray(s-bias)));
314
r = (int)(255. * gray(s - bias));
315
g = (int)(255. * (1. - gray(s - bias)));
315
316
b = (int)(255. * 1.);
317
318
case 19: // matlab "copper"
318
r = (int)(255. * DMIN(1., gray(s-bias) * 1.25));
319
g = (int)(255. * DMIN(1., gray(s-bias) * 0.7812));
320
b = (int)(255. * DMIN(1., gray(s-bias) * 0.4975));
319
r = (int)(255. * DMIN(1., gray(s - bias) * 1.25));
320
g = (int)(255. * DMIN(1., gray(s - bias) * 0.7812));
321
b = (int)(255. * DMIN(1., gray(s - bias) * 0.4975));
332
333
if(ct->dpar[COLORTABLE_BETA]) {
333
334
if(ct->dpar[COLORTABLE_BETA] > 0.0)
334
gamma = 1. - ct->dpar[COLORTABLE_BETA];
335
gamma = 1. - ct->dpar[COLORTABLE_BETA];
336
gamma = 1. / (1.001 + ct->dpar[COLORTABLE_BETA]); // beta is thresholded to [-1,1]
337
gamma = 1. / (1.001 + ct->dpar[COLORTABLE_BETA]); // beta is thresholded to [-1,1]
337
338
r = (int)(255. * pow((double)r / 255., gamma));
338
339
g = (int)(255. * pow((double)g / 255., gamma));
339
340
b = (int)(255. * pow((double)b / 255., gamma));
450
451
void RGB_to_HSV(double R, double G, double B,
451
double *H, double *S, double *V)
452
double *H, double *S, double *V)
453
454
double maxv = R > G ? R : G; if(B > maxv) maxv = B;
456
457
double minv = R < G ? R : G; if(B < minv) minv = B;
457
458
*S = 1.0 - double(minv)/maxv;
459
460
if(maxv == R){ *H = (G-B)/double(maxv-minv); if (*H<0) *H += 6.0; }
460
else if(maxv == G) *H = 2.0+(B-R)/double(maxv-minv);
461
else *H = 4.0+(R-G)/double(maxv-minv);
461
else if(maxv == G) *H = 2.0 + (B - R) / double(maxv - minv);
462
else *H = 4.0 + (R - G) / double(maxv - minv);