-/* xscreensaver, Copyright (c) 1997 Jamie Zawinski <jwz@netscape.com>
+/* xscreensaver, Copyright (c) 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
while (got < desired
&& requested > 0)
{
- if (desired - got > requested)
+ if (desired - got < requested)
requested = desired - got;
if (XAllocColorCells (dpy, cmap, False, 0, 0, new_pixels, requested))
}
+static void
+complain (int wanted_colors, int got_colors,
+ Bool wanted_writable, Bool got_writable)
+{
+ if (wanted_writable && !got_writable)
+ fprintf(stderr,
+ "%s: wanted %d writable colors; got %d read-only colors.\n",
+ progname, wanted_colors, got_colors);
+
+ else if (wanted_colors > (got_colors + 10))
+ /* don't bother complaining if we're within ten pixels. */
+ fprintf(stderr, "%s: wanted %d%s colors; got %d.\n",
+ progname, wanted_colors, (got_writable ? " writable" : ""),
+ got_colors);
+}
+
+
void
make_color_ramp (Display *dpy, Colormap cmap,
Bool allocate_p,
Bool writable_p)
{
+ Bool verbose_p = True; /* argh. */
int i;
int ncolors = *ncolorsP;
+ int wanted = ncolors;
+ Bool wanted_writable = (allocate_p && writable_p);
double dh, ds, dv; /* deltas */
AGAIN:
}
}
- return;
+ goto WARN;
FAIL:
/* we weren't able to allocate all the colors we wanted;
*ncolorsP = ncolors;
if (ncolors > 0)
goto AGAIN;
+
+ WARN:
+
+ if (verbose_p)
+ complain (wanted, ncolors, wanted_writable, wanted_writable && writable_p);
}
}
-static void
-complain (int wanted_colors, int got_colors,
- Bool wanted_writable, Bool got_writable)
-{
- if (wanted_writable && !got_writable)
- fprintf(stderr,
- "%s: wanted %d writable colors; got %d read-only colors.\n",
- progname, wanted_colors, got_colors);
-
- else if (wanted_colors > (got_colors + 10))
- /* don't bother complaining if we're within ten pixels. */
- fprintf(stderr, "%s: wanted %d%s colors; got %d.\n",
- progname, wanted_colors, (got_writable ? " writable" : ""),
- got_colors);
-}
-
-
void
make_smooth_colormap (Display *dpy, Visual *visual, Colormap cmap,
XColor *colors, int *ncolorsP,
if (dh < 0) dh = -dh;
if (dh > 0.5) dh = 0.5 - (dh - 0.5);
distance = sqrt ((dh * dh) +
- ((s[j] - s[i]) * (s[j] - v[i])) +
+ ((s[j] - s[i]) * (s[j] - s[i])) +
((v[j] - v[i]) * (v[j] - v[i])));
if (distance < 0.2)
goto REPICK_THIS_COLOR;
0, S, V,
359, S, V,
colors, &ncolors,
- False, True, wanted_writable);
+ False, True,
+ (writable_pP && *writable_pP));
/* If we tried for writable cells and got none, try for non-writable. */
if (allocate_p && *ncolorsP == 0 && writable_pP && *writable_pP)