From: Daniel J S. <dan...@ie...> - 2004-09-17 15:05:28
|
Petr Mikulik wrote: >>The complete color map needs to be stored as part of the structure. >> That is, plot->cmap needs to point at something that is dynamically >>allocated independent of the current color map. I'll work on that fix, >>but if this doesn't sound correct, let me know. Also, maybe think if >>what I've added in this patch is adequate to fix the problem when I have >>the plot->cmap problem fixed. That is, are there any other details >>about the GC that also must be updated? >> >> > >I have just tried the patch, but it was rejected. Don't you have an >up-to-date version? > Why would that patch be rejected? I don't think anyone has altered that bit of code in CVS... Anyway, that patch was just a lame alteration to illustrate where the problem lies. Basically, search for this line of code in gplt_x11.c if (plot->cmap->allocated < min_colors && !recursion) { and replace it with the following if (!recursion) { That fixes the problem of keeping track of the color map, but it also results in an incorrect color map. It looks like a tricky bit of code because it is recursive. I'm not exactly sure why it is recursive, as opposed to calling a subroutine twice. In fact, I'm looking at some code there and wondering what in fact it does. Here is the code in question: if (plot->cmap->allocated < min_colors && !recursion) { ReleaseColormap(plot); /* create a private colormap. */ fprintf(stderr, "switching to private colormap\n"); plot->cmap = (cmap_t *) malloc(sizeof(cmap_t)); assert(plot->cmap); CmapClear(plot->cmap); plot->cmap->colormap = XCreateColormap(dpy, root, vis, AllocNone); assert(plot->cmap->colormap); pr_color(plot->cmap); /* set default colors for lines */ RecolorWindow(plot); recursion = 1; PaletteMake(plot, (t_sm_palette *) 0); } else { /* this is just for calculating the number of unique colors */ int i; unsigned long previous = plot->cmap->allocated ? plot->cmap->pixels[0] : 0; int unique_colors = 1; for (i = 0; i < plot->cmap->allocated; i++) { if (plot->cmap->pixels[i] != previous) { previous = plot->cmap->pixels[i]; unique_colors++; } } } Notice that the second portion of the if/else statement alters two local variables, previous and unique_colors, and that is all. That's a useless bit of code, as I see it. I wish there were a short note explaining why this is recursive, i.e., on the second time through, what portion of the code is important? Dan |