ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/hsv_rgb.cal
Revision: 2.1
Committed: Wed Jun 1 17:22:31 2022 UTC (3 months, 4 weeks ago) by greg
Branch: MAIN
CVS Tags: HEAD
Log Message:
chore: Moved hsv_rgb.cal to build directory with dependency, where it belongs

File Contents

# Content
1 { RCSid $Id: hsv_rgb.cal,v 1.1 2019/07/24 21:36:28 greg Exp $ }
2 {
3 Convert between HSV (hue, saturation, value) and RGB
4 Hue angles are in degrees, from 0 to 360.
5
6 From Wikipedia July 2019
7 }
8
9 eq(a,b) : if(a-b+1e-6, b-a+1e-6, -1);
10 mod(n,d) : n - floor(n/d)*d;
11
12 Hprime(M,m, R,G,B) : if(m-M+.001, 0,
13 if(eq(M,R), mod((G-B)/(M-m),6),
14 if(eq(M,G), (B-R)/(M-m) + 2,
15 (R-G)/(M-m) + 4)));
16
17 Sprime(M,m) : if(M-1e-4, (M-m)/M, 0);
18
19 H(R,G,B) : 60*Hprime(max(R,G,B),min(R,G,B), R,G,B);
20 S(R,G,B) : Sprime(max(R,G,B),min(R,G,B));
21 V(R,G,B) : max(R,G,B);
22
23 frevprime(S,V,k) : V - V*S*max(min(k,4-k,1),0);
24 frev(H,S,V, n) : frevprime(S,V, mod(n+H/60,6));
25
26 R(H,S,V) : frev(H,S,V,5);
27 G(H,S,V) : frev(H,S,V,3);
28 B(H,S,V) : frev(H,S,V,1);