2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these libraries and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: hsbramp.c /main/3 1995/11/02 16:07:23 rswiston $ */
27 * (c) Copyright 1993, 1994 Hewlett-Packard Company *
28 * (c) Copyright 1993, 1994 International Business Machines Corp. *
29 * (c) Copyright 1993, 1994 Sun Microsystems, Inc. *
30 * (c) Copyright 1993, 1994 Novell, Inc. *
33 * hsbramp.c - Create an HSB ramp.
35 * Copyright (c) 1991 by Patrick J. Naughton.
37 * See dtscreen.c for copying information.
40 * 29-Jul-90: renamed hsbramp.c from HSBmap.c
41 * minor optimizations.
45 #include <sys/types.h>
49 hsb2rgb(H, S, B, r, g, b)
64 H -= floor(H); /* remove anything over 1 */
66 i = floor(H); /* 0..5 */
67 f = H - (float) i; /* f = fractional part of H */
69 p = (u_char) (bb * (1.0 - S));
70 q = (u_char) (bb * (1.0 - (S * f)));
71 t = (u_char) (bb * (1.0 - (S * (1.0 - f))));
108 * Input is two points in HSB color space and a count
109 * of how many discreet rgb space values the caller wants.
111 * Output is that many rgb triples which describe a linear
112 * interpolate ramp between the two input colors.
116 hsbramp(double h1, double s1, double b1,
117 double h2, double s2, double b2,
119 u_char *red, u_char *green, u_char *blue)
125 dh = (h2 - h1) / count;
126 ds = (s2 - s1) / count;
127 db = (b2 - b1) / count;
129 hsb2rgb(h1, s1, b1, red++, green++, blue++);