Debian Codegraph @

packages/seacas/applications/blot/rainbow.f

raw
1 C The author of this software is Eric Grosse.
2 C Permission to use, copy, modify, and distribute this software for any
3 C purpose without fee is hereby granted, provided that this entire notice
4 C is included in all copies of any software which is or includes a copy
5 C or modification of this software and in all copies of the supporting
6 C documentation for such software.
7
8 C Copyright(C) 1999-2020 National Technology & Engineering Solutions
9 C of Sandia, LLC (NTESS). Under the terms of Contract DE-NA0003525 with
10 C NTESS, the U.S. Government retains certain rights in this software.
11 C
12 C See packages/seacas/LICENSE for details
13
14 C This routine computes colors suitable for use in color level plots.
15 C Typically s=v=1 and h varies from 0 (red) to 1 (blue) in
16 C equally spaced steps. (h=.5 gives green; 1<h<1.5 gives magenta.)
17 C To convert for frame buffer, use R = floor(255.999*pow(*r,1/gamma)) etc.
18 C To get tables calibrated for other devices or to report complaints,
19 C contact [email protected].
20
21 subroutine rainbow(h, s, v, r, g, b)
22 real h, s, v
23 real r, g, b
24
25 INTEGER i
26 REAL huettab(0:60)
27 DATA huettab /0.0000, 0.0062, 0.0130, 0.0202, 0.0280,
28 * 0.0365, 0.0457, 0.0559, 0.0671, 0.0796,
29 * 0.0936, 0.1095, 0.1275, 0.1482, 0.1806,
30 * 0.2113, 0.2393, 0.2652, 0.2892, 0.3119,
31 * 0.3333, 0.3556, 0.3815, 0.4129, 0.4526,
32 * 0.5060, 0.5296, 0.5501, 0.5679, 0.5834,
33 * 0.5970, 0.6088, 0.6191, 0.6281, 0.6361,
34 * 0.6430, 0.6490, 0.6544, 0.6590, 0.6631,
35 * 0.6667, 0.6713, 0.6763, 0.6815, 0.6873,
36 * 0.6937, 0.7009, 0.7092, 0.7190, 0.7308,
37 * 0.7452, 0.7631, 0.7856, 0.8142, 0.8621,
38 * 0.9029, 0.9344, 0.9580, 0.9755, 0.9889, 1.0000/
39
40 C computed from the FMC-1 color difference formula
41 C Barco monitor, max(r,g,b)=1, n=61 magenta, 2 Jan 1986
42
43 H = 60.0 * MOD(H / 1.5, 1.)
44 I = INT(H)
45 H = huettab(i) + (huettab(i+1) - huettab(i)) * (h - i)
46 CALL dhsv2rgb(h, s, v, r, g, b)
47 RETURN
48 END
49
50 SUBROUTINE dhsv2rgb(h, s, v, r, g, b)
51 C...hexcone model...
52 REAL h, s, v
53 REAL r, g, b
54 C...all variables in range [0,1[
55 C...here, h=.667 gives blue, h=0 or 1 gives red.
56 C...see Alvy Ray Smith, Color Gamut Transform Pairs, SIGGRAPH '78
57
58 INTEGER i
59 REAL f, m, n, k
60
61 h = 6 * mod(h, 1.)
62 i = int(h)
63 f = h - i
64 m = (1 - s)
65 n = (1 - s * f)
66 k = (1 - (s * (1 - f)))
67
68 if (i .eq. 0) then
69 r = 1
70 g = k
71 b = m
72 else if (i .eq. 1) then
73 r = n
74 g = 1
75 b = m
76 else if (i .eq. 2) then
77 r = m
78 g = 1
79 b = k
80 else if (i .eq. 3) then
81 r = m
82 g = n
83 b = 1
84 else if (i .eq. 4) then
85 r = k
86 g = m
87 b = 1
88 else if (i .eq. 5) then
89 r = 1
90 g = m
91 b = n
92 end if
93 f = max(r, g, b)
94 f = v / f
95 r = r * f
96 g = g * f
97 b = b * f
98
99 return
100 end