546N/A/*
546N/A * Copyright (c) 1988-91 by Patrick J. Naughton.
546N/A *
546N/A * Permission to use, copy, modify, and distribute this software and its
546N/A * documentation for any purpose and without fee is hereby granted,
546N/A * provided that the above copyright notice appear in all copies and that
546N/A * both that copyright notice and this permission notice appear in
546N/A * supporting documentation.
546N/A *
546N/A * This file is provided AS IS with no warranties of any kind. The author
546N/A * shall have no liability with respect to the infringement of copyrights,
546N/A * trade secrets or any patents by this file or any part thereof. In no
546N/A * event will the author be liable for any lost revenue or profits or
546N/A * other special, indirect and consequential damages.
546N/A */
546N/A
546N/A/*
1233N/A * Copyright (c) 1988, 2011, Oracle and/or its affiliates. All rights reserved.
546N/A *
546N/A * Permission is hereby granted, free of charge, to any person obtaining a
919N/A * copy of this software and associated documentation files (the "Software"),
919N/A * to deal in the Software without restriction, including without limitation
919N/A * the rights to use, copy, modify, merge, publish, distribute, sublicense,
919N/A * and/or sell copies of the Software, and to permit persons to whom the
919N/A * Software is furnished to do so, subject to the following conditions:
546N/A *
919N/A * The above copyright notice and this permission notice (including the next
919N/A * paragraph) shall be included in all copies or substantial portions of the
919N/A * Software.
546N/A *
919N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
919N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
919N/A * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
919N/A * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
919N/A * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
919N/A * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
919N/A * DEALINGS IN THE SOFTWARE.
546N/A */
546N/A
546N/A/*-
546N/A * hsbramp.c - Create an HSB ramp.
546N/A *
546N/A * Copyright (c) 1991 by Patrick J. Naughton.
546N/A *
546N/A * See xlock.c for copying information.
546N/A *
546N/A * Revision History:
546N/A * 29-Jul-90: renamed hsbramp.c from HSBmap.c
546N/A * minor optimizations.
546N/A * 01-Sep-88: Written.
546N/A */
546N/A
546N/A#include <sys/types.h>
546N/A#include <math.h>
546N/A
1233N/Astatic void
1233N/Ahsb2rgb(
546N/A double H,
1233N/A double S,
1233N/A double B,
546N/A u_char *r,
1233N/A u_char *g,
1233N/A u_char *b)
546N/A{
546N/A int i;
546N/A double f;
546N/A double bb;
546N/A u_char p;
546N/A u_char q;
546N/A u_char t;
546N/A
546N/A H -= floor(H); /* remove anything over 1 */
546N/A H *= 6.0;
546N/A i = floor(H); /* 0..5 */
546N/A f = H - (float) i; /* f = fractional part of H */
546N/A bb = 255.0 * B;
546N/A p = (u_char) (bb * (1.0 - S));
546N/A q = (u_char) (bb * (1.0 - (S * f)));
546N/A t = (u_char) (bb * (1.0 - (S * (1.0 - f))));
546N/A switch (i) {
546N/A case 0:
546N/A *r = (u_char) bb;
546N/A *g = t;
546N/A *b = p;
546N/A break;
546N/A case 1:
546N/A *r = q;
546N/A *g = (u_char) bb;
546N/A *b = p;
546N/A break;
546N/A case 2:
546N/A *r = p;
546N/A *g = (u_char) bb;
546N/A *b = t;
546N/A break;
546N/A case 3:
546N/A *r = p;
546N/A *g = q;
546N/A *b = (u_char) bb;
546N/A break;
546N/A case 4:
546N/A *r = t;
546N/A *g = p;
546N/A *b = (u_char) bb;
546N/A break;
546N/A case 5:
546N/A *r = (u_char) bb;
546N/A *g = p;
546N/A *b = q;
546N/A break;
546N/A }
546N/A}
546N/A
546N/A
546N/A/*
546N/A * Input is two points in HSB color space and a count
546N/A * of how many discreet rgb space values the caller wants.
546N/A *
546N/A * Output is that many rgb triples which describe a linear
546N/A * interpolate ramp between the two input colors.
546N/A */
546N/A
546N/Avoid
1233N/Ahsbramp(
546N/A double h1,
1233N/A double s1,
1233N/A double b1,
1233N/A double h2,
1233N/A double s2,
1233N/A double b2,
1233N/A int count,
546N/A
546N/A u_char *red,
1233N/A u_char *green,
1233N/A u_char *blue)
546N/A{
546N/A double dh;
546N/A double ds;
546N/A double db;
546N/A
546N/A dh = (h2 - h1) / count;
546N/A ds = (s2 - s1) / count;
546N/A db = (b2 - b1) / count;
546N/A while (count--) {
546N/A hsb2rgb(h1, s1, b1, red++, green++, blue++);
546N/A h1 += dh;
546N/A s1 += ds;
546N/A b1 += db;
546N/A }
546N/A}