aboutsummaryrefslogtreecommitdiff
path: root/generic
diff options
context:
space:
mode:
Diffstat (limited to 'generic')
-rw-r--r--generic/Color.c73
1 files changed, 45 insertions, 28 deletions
diff --git a/generic/Color.c b/generic/Color.c
index 129d990..a30e01c 100644
--- a/generic/Color.c
+++ b/generic/Color.c
@@ -486,7 +486,6 @@ ZnGetColor(Tcl_Interp *interp,
ColorInit();
}
- /*printf("ZnGetColor color: %s\n", name);*/
/*
* First, check to see if there's already a mapping for this color
* name.
@@ -510,8 +509,6 @@ ZnGetColor(Tcl_Interp *interp,
*/
if (*name != '#') {
if (XAllocNamedColor(dpy, colormap, name, &screen, &color) != 0) {
- /*printf("ZnGetColor XAllocNamedColor gives: %d %d %d\n",
- color.red, color.green, color.blue);*/
DeleteStressedCmap(dpy, colormap);
}
else {
@@ -564,7 +561,7 @@ ZnGetColor(Tcl_Interp *interp,
tk_col->hash = name_hash;
Tcl_SetHashValue(name_hash, tk_col);
- /*printf("ZnGetColor created: %d %d %d\n",
+ /*printf("ZnGetColor created: %x %x %x\n",
tk_col->color.red, tk_col->color.green, tk_col->color.blue);*/
return &tk_col->color;
}
@@ -608,7 +605,9 @@ ZnGetColorByValue(Tk_Window tkwin,
ColorInit();
}
- /*
+ /*printf("ZnGetColorByValue input color: %x %x %x\n",
+ color->red, color->green, color->blue);*/
+ /*
* First, check to see if there's already a mapping for this color
* name.
*/
@@ -636,6 +635,7 @@ ZnGetColorByValue(Tk_Window tkwin,
DeleteStressedCmap(dpy, colormap);
}
else {
+ /*printf("ZnGetColorByValue XAllocColor failed\n");*/
FindClosestColor(tkwin, &tk_col->color, &tk_col->color);
}
@@ -648,6 +648,9 @@ ZnGetColorByValue(Tk_Window tkwin,
tk_col->hash = value_hash;
Tcl_SetHashValue(value_hash, tk_col);
+ /*printf("ZnGetColorByValue created: %x %x %x\n",
+ tk_col->color.red, tk_col->color.green, tk_col->color.blue);*/
+
return &tk_col->color;
}
@@ -776,7 +779,7 @@ static void
RealizeColorGradient(ColorGradient *grad,
Tk_Window tkwin)
{
- int i, num_colors;
+ int i, num_colors, num_colors_2;
XColor *base, *first, *last, color;
int red_range, green_range, blue_range;
@@ -784,7 +787,10 @@ RealizeColorGradient(ColorGradient *grad,
return;
}
+ /*printf("realizing gradient with %d(%d) colors\n",
+ grad->num_colors, BORDER_STEPS);*/
num_colors = grad->num_colors;
+ num_colors_2 = num_colors/2;
first = grad->colors[0];
last = grad->colors[num_colors-1];
@@ -796,38 +802,48 @@ RealizeColorGradient(ColorGradient *grad,
* For others gradients proceed from lightest to darkest.
*/
if ((num_colors == BORDER_STEPS) &&
- (grad->colors[BORDER_STEPS/2+1])) {
- base = grad->colors[BORDER_STEPS/2+1];
+ (grad->colors[BORDER_STEPS/2])) {
+ base = grad->colors[BORDER_STEPS/2];
red_range = (int) base->red - (int) first->red;
green_range = (int) base->green - (int) first->green;
blue_range = (int) base->blue - (int) first->blue;
- for (i = BORDER_STEPS/2; i > 0; i--) {
- color.red = (int) base->red + red_range * i / (num_colors-2);
- color.green = (int) base->green + green_range * i / (num_colors-2);
- color.blue = (int) base->blue + blue_range * i / (num_colors-2);
+ for (i = BORDER_STEPS/2-1; i > 0; i--) {
+ color.red = (int) first->red + red_range * i / (num_colors_2);
+ color.green = (int) first->green + green_range * i / (num_colors_2);
+ color.blue = (int) first->blue + blue_range * i / (num_colors_2);
grad->colors[i] = ZnGetColorByValue(tkwin, &color);
+ /*printf("getting color %x %x %x\n", color.red, color.green, color.blue);*/
}
- red_range = (int) base->red - (int) last->red;
- green_range = (int) base->green - (int) last->green;
- blue_range = (int) base->blue - (int) last->blue;
- for (i = BORDER_STEPS/2+2; i < num_colors-1; i++) {
- color.red = (int) base->red + red_range * i / (num_colors-2);
- color.green = (int) base->green + green_range * i / (num_colors-2);
- color.blue = (int) base->blue + blue_range * i / (num_colors-2);
- grad->colors[i] = ZnGetColorByValue(tkwin, &color);
+ red_range = (int) last->red - (int) base->red;
+ green_range = (int) last->green - (int) base->green;
+ blue_range = (int) last->blue - (int) base->blue;
+ for (i = BORDER_STEPS/2-1; i > 0; i--) {
+ color.red = (int) base->red + red_range * i / (num_colors_2);
+ color.green = (int) base->green + green_range * i / (num_colors_2);
+ color.blue = (int) base->blue + blue_range * i / (num_colors_2);
+ /*printf("getting color %x %x %x\n", color.red, color.green, color.blue);*/
+ grad->colors[BORDER_STEPS/2+i] = ZnGetColorByValue(tkwin, &color);
+ }
+ /*printf("base %x %x %x\n", grad->colors[BORDER_STEPS/2]->red,
+ grad->colors[BORDER_STEPS/2]->green, grad->colors[BORDER_STEPS/2]->blue);
+ printf("relief pixels: ");
+ for (i = 0; i < BORDER_STEPS; i++) {
+ printf("%d ", ZnPixel(grad->colors[i]));
}
+ printf("\n");*/
}
else {
red_range = (int) last->red - (int) first->red;
green_range = (int) last->green - (int) first->green;
blue_range = (int) last->blue - (int) first->blue;
for (i = 1; i < num_colors-1; i++) {
- color.red =(int) first->red + red_range * i / (num_colors-2);
- color.green = (int) first->green + green_range * i / (num_colors-2);
- color.blue = (int) first->blue + blue_range * i / (num_colors-2);
+ color.red =(int) first->red + red_range * i / (num_colors-1);
+ color.green = (int) first->green + green_range * i / (num_colors-1);
+ color.blue = (int) first->blue + blue_range * i / (num_colors-1);
grad->colors[i] = ZnGetColorByValue(tkwin, &color);
}
}
+ grad->realized = True;
}
@@ -862,7 +878,7 @@ ZnColorGradientPixel(ZnColorGradient gradient,
if (color_index < 0) {
color_index += grad->num_colors;
}
- else if (color_index >= grad->num_colors) {
+ if (color_index >= grad->num_colors) {
color_index = grad->num_colors-1;
}
if (!grad->realized) {
@@ -953,9 +969,10 @@ ZnGetReliefGradient(Tcl_Interp *interp,
grad->num_colors = BORDER_STEPS;
/*
* BORDER_STEPS should be odd, the base color
- * takes the center position.
+ * takes the center position (assuming that the number
+ * of colors is odd).
*/
- grad->colors[BORDER_STEPS/2+1] = base;
+ grad->colors[BORDER_STEPS/2] = base;
/*
* Compute the border gradient.
@@ -1012,10 +1029,10 @@ ZnGetReliefGradient(Tcl_Interp *interp,
* Now init the in between colors to let RealizeColorGradient know
* what it has to do.
*/
- for (i = BORDER_STEPS/2+1; i > 0; i--) {
+ for (i = BORDER_STEPS/2-1; i > 0; i--) {
grad->colors[i] = NULL;
}
- for (i = BORDER_STEPS/2+2; i < BORDER_STEPS-1; i++) {
+ for (i = BORDER_STEPS/2+1; i < BORDER_STEPS-1; i++) {
grad->colors[i] = NULL;
}
Tcl_SetHashValue(hash, grad);