X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=utils%2Fhsv.c;h=cf1cc8d18e27462e229061e7c967002a75bf23fc;hb=14463b6ad1ab1ccf81f9c33350b048e410ba94cb;hp=2a88dffc3fb6cd64e4c6a0ae300d172496ccbd8f;hpb=65740e2a8dea3d6309ae6e8914a0fb79e993ada8;p=xscreensaver diff --git a/utils/hsv.c b/utils/hsv.c old mode 100755 new mode 100644 index 2a88dffc..cf1cc8d1 --- a/utils/hsv.c +++ b/utils/hsv.c @@ -1,4 +1,4 @@ -/* xscreensaver, Copyright (c) 1992 Jamie Zawinski +/* xscreensaver, Copyright (c) 1992, 1997 Jamie Zawinski * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, provided that @@ -13,23 +13,23 @@ to hack the screen with. */ -#include +#include "utils.h" +#include "hsv.h" void -#if __STDC__ hsv_to_rgb (int h, double s, double v, unsigned short *r, unsigned short *g, unsigned short *b) -#else -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 */ -#endif { 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; @@ -49,15 +49,8 @@ hsv_to_rgb (h,s,v, r,g,b) } void -#if __STDC__ rgb_to_hsv (unsigned short r, unsigned short g, unsigned short b, int *h, double *s, double *v) -#else -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 */ -#endif { double R, G, B, H, S, V; double cmax, cmin; @@ -77,44 +70,12 @@ rgb_to_hsv (r,g,b, h,s,v) 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); -}