
Received: by mcvax.uucp; Fri, 7 Mar 86 10:53:20 +0100 (MET)
Received: from sdcsvax.UUCP by seismo.CSS.GOV with UUCP; Thu, 6 Mar 86 20:53
>:39 EST
Received: by sdcsvax.ucsd.edu (5.31/4.41)
	id AA12724; Wed, 5 Mar 86 12:39:46 PST hops=0
Date: Wed, 5 Mar 86 12:39:46 PST
From: hutch@sdcsvax.ucsd.edu (Jim Hutchison)
Message-Id: <8603052039.AA12724@sdcsvax.ucsd.edu>
To: mg.@ukc.ac.uk
Subject: Re:  colour maps
Status: RO

Foley & Van Dams hls_to_rgb() takes hue luminance and saturation,
and turns it into rgb values.

Here is the Foley and Van Dam thing.  I have inserted defines for
shift and spread, because the colors where not exactly how I wanted
them to look.  SPREAD controls how blended the continuum, and SHIFT
controls where on the loop it all begins.

						Jim.

/* Prepare the Transit Beam */
/*
 * Foley and Van Dam Region
 */

/*
 * Find hue value
 */
float
value(a,b,hue)
    float a,b,hue;
{
    while(hue > 360.0)
	hue -= 360.0;
    while(hue < 0.0)
	hue += 360.0;
    if (hue < 60.0)
	return(a + (b - a) * hue / 60.0);
    else if (hue < 180.0)
	return(b);
    else if (hue < 240.0)
	return(a + (b - a) * (240.0 - hue) / 60.0);
    return(a);
}

#define SHIFT		35.0
#define SPREAD		0.2

/*
 * Convert hue, luminance, saturation  intensity TO red, green, blue.
 */

hls_to_rgb(r,g,b,h,l,s)
    unsigned char *r, *g, *b;
    float h, l, s;
{
    float ma,mb;

    if ( l <= 0.5 )
	mb = l * (1.0 + s) + SPREAD;
    else
	mb = l + s - l * s + SPREAD;

    ma = 2.0 * l - mb + SPREAD;

    if (s == 0.0) /* if saturation is 0 then lumiance is how bright white */
	*r = *g = *b = (unsigned char)(255.0 * l);
    else {
	*r = (unsigned char)(255.0 * value(ma, mb, h + 120.0 + SHIFT));
	*g = (unsigned char)(255.0 * value(ma, mb, h + SHIFT));
	*b = (unsigned char)(255.0 * value(ma, mb, h - 120.0 + SHIFT));
    }
}

