pre-allocated colors (a patch)
Olivier Chapuis <[email protected]> Thu, 5 Sep 2002 22:19:14 +0200
| Newsgroups | gmane.comp.xfree86.render |
|---|---|
| Message-ID | <[email protected]> |
Hello, When I rewrite the color limitation code in fvwm I've noted that when I run my X server in depth 8 (PseudoColor) it pre-allocates some colors: 244 colors (a 6x6x6 colors cube + 28 grey) with XFree 4.2 and 85 colors (the 4x4x4 color cube + 21 grey's) with the current cvs. After some times I discover that it is the XRender extension which does that and I take a look at the code: xc/programs/Xserver/render/miindex.c. There is something strange in the code: too many colors are allocated with a PseudoColor visual class, only the color cube is used but some greys are also allocated (in depth 8, 28/21 colors "lost"). Attached to this message a patch which fixes this. BTW, switching from a 6x6x6 cc to a 4x4x4 cc has strange consequence with Gtk-2.0/1.2. If you Start Xfree-4.3 with gnome I think that gtk will be able to choose a 6x6x4 cc: 85 + 144 - 2 = 227 (with the patch gtk will probably be able to choose a 6x6x5 cc). So ok no real problems (but with 4.2 XRender, gtk and qt all use the 6x6x6 cc). Now if you use gtk apps with XFree 4.3 in an other environement than gnome, there is a lot of chance that gtk apps will install private colormap as its minimal cc is the 5x5x5 cc (of course this is configurable, but as a simple gtk user I do not know how). I think that private colormaps may disturbe some users. Any way, I've no solution as I do not know why some users need to run a server with depth 8. In a perfect world the cc used by XRender should be an option in the XF86Config file (with "DisableXRender" as an extremal option) and application should be able to auto detecte allocated cc's (as fvwm do now). Note that Qt does not really care as qt use approximation in the colormap. Regards, Olivier Chapuis
patch_render_miindex.txt
(text/plain, 1.8 KB)
? Makefile
? miindex.c.my
? patch.txt
Index: miindex.c
===================================================================
RCS file: /cvs/xc/programs/Xserver/render/miindex.c,v
retrieving revision 1.5
diff -u -r1.5 miindex.c
--- miindex.c 2002/05/13 05:25:11 1.5
+++ miindex.c 2002/09/05 20:03:54
@@ -57,31 +57,40 @@
ramp = num - (cube * cube * cube);
*first = MI_MAX_INDEXED;
*last = 0;
- for (r = 0; r < cube; r++)
- for (g = 0; g < cube; g++)
- for (b = 0; b < cube; b++)
- {
- red = r * 65535 / (cube - 1);
- green = g * 65535 / (cube - 1);
- blue = b * 65535 / (cube - 1);
- if (AllocColor (pColormap, &red, &green, &blue, &pix, 0) != Success)
- return FALSE;
- if (pix < *first)
- *first = pix;
- if (pix > *last)
- *last = pix;
- }
- for (g = 0; g < ramp; g++)
- {
- red =
- green =
- blue = g * 65535 / (ramp - 1);
- if (AllocColor (pColormap, &red, &green, &blue, &pix, 0) != Success)
- return FALSE;
- if (pix < *first)
- *first = pix;
- if (pix > *last)
- *last = pix;
+
+ switch (pColormap->pVisual->class | DynamicClass) {
+ case PseudoColor:
+ for (r = 0; r < cube; r++)
+ for (g = 0; g < cube; g++)
+ for (b = 0; b < cube; b++)
+ {
+ red = r * 65535 / (cube - 1);
+ green = g * 65535 / (cube - 1);
+ blue = b * 65535 / (cube - 1);
+ if (AllocColor (pColormap, &red, &green, &blue, &pix, 0) != Success)
+ return FALSE;
+ if (pix < *first)
+ *first = pix;
+ if (pix > *last)
+ *last = pix;
+ }
+ break;
+ case GrayScale:
+ for (g = 0; g < ramp; g++)
+ {
+ red =
+ green =
+ blue = g * 65535 / (ramp - 1);
+ if (AllocColor (pColormap, &red, &green, &blue, &pix, 0) != Success)
+ return FALSE;
+ if (pix < *first)
+ *first = pix;
+ if (pix > *last)
+ *last = pix;
+ }
+ break;
+ default:
+ break;
}
return TRUE;