X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=utils%2Fcolors.c;h=e06359c72db811738959df9bc1f733e359485a4d;hb=50be9bb40dc60130c99ffa568e6677779904ff70;hp=c961539421dd340e3b36a2e1fc0b7ed38290f9a7;hpb=cccbddbc4140cf9a06d7d95cc5c0ca36eb5d6e28;p=xscreensaver diff --git a/utils/colors.c b/utils/colors.c index c9615394..e06359c7 100644 --- a/utils/colors.c +++ b/utils/colors.c @@ -336,16 +336,11 @@ make_color_path (Display *dpy, Colormap cmap, k = 0; for (i = 0; i < npoints; i++) { - int distance, direction; - distance = h[(i+1) % npoints] - h[i]; - direction = (distance >= 0 ? -1 : 1); - - if (distance > 180) - distance = 180 - (distance - 180); - else if (distance < -180) - distance = -(180 - ((-distance) - 180)); - else - direction = -direction; + int distance = h[(i+1) % npoints] - h[i]; + int direction = (distance >= 0 ? -1 : 1); + + if (distance <= 180 && distance >= -180) + direction = -direction; #ifdef DEBUG fprintf (stderr, "point %d: %3d %.2f %.2f\n", @@ -480,6 +475,7 @@ make_smooth_colormap (Display *dpy, Visual *visual, Colormap cmap, double total_s = 0; double total_v = 0; Screen *screen = (dpy ? DefaultScreenOfDisplay(dpy) : 0); /* #### WRONG! */ + int loop = 0; if (*ncolorsP <= 0) return; @@ -495,6 +491,7 @@ make_smooth_colormap (Display *dpy, Visual *visual, Colormap cmap, for (i = 0; i < npoints; i++) { REPICK_THIS_COLOR: + if (++loop > 10000) abort(); h[i] = random() % 360; s[i] = frand(1.0); v[i] = frand(0.8) + 0.2; @@ -539,7 +536,7 @@ make_smooth_colormap (Display *dpy, Visual *visual, Colormap cmap, allocate_p, (writable_pP && *writable_pP)); /* If we tried for writable cells and got none, try for non-writable. */ - if (allocate_p && *ncolorsP == 0 && *writable_pP) + if (allocate_p && *ncolorsP == 0 && writable_pP && *writable_pP) { *writable_pP = False; goto RETRY_NON_WRITABLE;