/* xscreensaver, Copyright (c) 1992, 1997 Jamie Zawinski <jwz@jwz.org>
* Permission to use, copy, modify, distribute, and sell this software and its
* documentation for any purpose is hereby granted without fee, provided that
* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation. No representations are made about the suitability of this
* software for any purpose. It is provided "as is" without express or
/* This file contains some utility routines for randomly picking the colors
hsv_to_rgb (int h
, double s
, double v
,
unsigned short *r
, unsigned short *g
, unsigned short *b
)
p3
= V
* (1 - (S
* (1 - f
)));
if (i
== 0) { R
= V
; G
= p3
; B
= p1
; }
else if (i
== 1) { R
= p2
; G
= V
; B
= p1
; }
else if (i
== 2) { R
= p1
; G
= V
; B
= p3
; }
else if (i
== 3) { R
= p1
; G
= p2
; B
= V
; }
else if (i
== 4) { R
= p3
; G
= p1
; B
= V
; }
else { R
= V
; G
= p1
; B
= p2
; }
rgb_to_hsv (unsigned short r
, unsigned short g
, unsigned short b
,
int *h
, double *s
, double *v
)
R
= ((double) r
) / 65535.0;
G
= ((double) g
) / 65535.0;
B
= ((double) b
) / 65535.0;
cmax
= R
; cmin
= G
; imax
= 1;
if ( cmax
< G
) { cmax
= G
; cmin
= R
; imax
= 2; }
if ( cmax
< B
) { cmax
= B
; imax
= 3; }
if ( cmin
> B
) { cmin
= B
; }
if (imax
== 1) H
= (G
- B
) / cmm
;
else if (imax
== 2) H
= 2.0 + (B
- R
) / cmm
;
else /*if (imax == 3)*/ H
= 4.0 + (R
- G
) / cmm
;