-/* xscreensaver, Copyright (c) 1992 Jamie Zawinski <jwz@lucid.com>
+/* 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
to hack the screen with.
*/
-#include <X11/Xlib.h>
+#include "utils.h"
+#include "hsv.h"
void
-hsv_to_rgb (h,s,v, r,g,b)
- int h; /* 0 - 360 */
- double s, v; /* 0.0 - 1.0 */
- unsigned short *r, *g, *b; /* 0 - 65535 */
+hsv_to_rgb (int h, double s, double v,
+ unsigned short *r, unsigned short *g, unsigned short *b)
{
double H, S, V, R, G, B;
double p1, p2, p3;
double f;
int i;
+
+ if (s < 0) s = 0;
+ if (v < 0) v = 0;
+ if (s > 1) s = 1;
+ if (v > 1) v = 1;
+
S = s; V = v;
H = (h % 360) / 60.0;
i = H;
}
void
-rgb_to_hsv (r,g,b, h,s,v)
- unsigned short r, g, b; /* 0 - 65535 */
- int *h; /* 0 - 360 */
- double *s, *v; /* 0.0 - 1.0 */
+rgb_to_hsv (unsigned short r, unsigned short g, unsigned short b,
+ int *h, double *s, double *v)
{
double R, G, B, H, S, V;
double cmax, cmin;
else
{
S = cmm / cmax;
- 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;
+ 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;
if (H < 0) H += 6.0;
}
*h = (H * 60.0);
*s = S;
*v = V;
}
-
-
-void
-make_color_ramp (h1, s1, v1, h2, s2, v2,
- pixels, npixels)
- int h1, h2; /* 0 - 360 */
- double s1, s2, v1, v2; /* 0.0 - 1.0 */
- XColor *pixels;
- int npixels;
-{
- int dh = (h2 - h1) / npixels;
- double ds = (s2 - s1) / npixels;
- double dv = (v2 - v1) / npixels;
- int i;
- for (i = 0; i < npixels; i++)
- hsv_to_rgb ((h1 += dh), (s1 += ds), (v1 += dv),
- &pixels [i].red, &pixels [i].green, &pixels [i].blue);
-}
-
-
-void
-cycle_hue (color, degrees)
- XColor *color;
- int degrees;
-{
- int h;
- double s, v;
- rgb_to_hsv (color->red, color->green, color->blue,
- &h, &s, &v);
- h = (h + degrees) % 360;
- hsv_to_rgb (h, s, v, &color->red, &color->green, &color->blue);
-}