home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
MM1
/
GRAPHICS
/
ssaver.lzh
/
SRC
/
hsbramp.c
< prev
next >
Wrap
Text File
|
1995-10-31
|
3KB
|
126 lines
/*-
* hsbramp.c - Create an HSB ramp.
*
* Copyright (c) 1991 by Patrick J. Naughton.
*
* Revision History:
* 29-Oct-95: Port to OSK for the MM/1 by Blair Leduc (b.leduc@ieee.org)
* 29-Jul-90: renamed hsbramp.c from HSBmap.c
* minor optimizations.
* 01-Sep-88: Written.
*/
/*
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation.
This file is provided AS IS with no warranties of any kind. The author
shall have no liability with respect to the infringement of copyrights,
trade secrets or any patents by this file or any part thereof. In no
event will the author be liable for any lost revenue or profits or
other special, indirect and consequential damages.
*/
#include <types.h>
#include <math.h>
void
hsb2rgb(H, S, B, r, g, b)
double H,
S,
B;
unsigned char *r,
*g,
*b;
{
int i;
double f;
double bb;
unsigned char p;
unsigned char q;
unsigned char t;
H -= floor(H); /* remove anything over 1 */
H *= 6.0;
i = floor(H); /* 0..5 */
f = H - (float) i; /* f = fractional part of H */
bb = 255.0 * B;
p = (unsigned char) (bb * (1.0 - S));
q = (unsigned char) (bb * (1.0 - (S * f)));
t = (unsigned char) (bb * (1.0 - (S * (1.0 - f))));
switch (i) {
case 0:
*r = (unsigned char) bb;
*g = t;
*b = p;
break;
case 1:
*r = q;
*g = (unsigned char) bb;
*b = p;
break;
case 2:
*r = p;
*g = (unsigned char) bb;
*b = t;
break;
case 3:
*r = p;
*g = q;
*b = (unsigned char) bb;
break;
case 4:
*r = t;
*g = p;
*b = (unsigned char) bb;
break;
case 5:
*r = (unsigned char) bb;
*g = p;
*b = q;
break;
}
}
/*
* Input is two points in HSB color space and a count
* of how many discreet rgb space values the caller wants.
*
* Output is that many rgb triples which describe a linear
* interpolate ramp between the two input colors.
*/
void
hsbramp(h1, s1, b1, h2, s2, b2, count, pal)
double h1,
s1,
b1,
h2,
s2,
b2;
int count;
unsigned char *pal;
{
double dh;
double ds;
double db;
int max=count;
dh = (h2 - h1) / count;
ds = (s2 - s1) / count;
db = (b2 - b1) / count;
while (count) {
hsb2rgb(h1, s1, b1, &pal[(max-count)*3], &pal[(max-count)*3+1],
&pal[(max-count)*3+2]);
count--;
h1 += dh;
s1 += ds;
b1 += db;
}
}