#include <X11/Xfuncproto.h>Include dependency graph for StdCmap.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.
Functions | |
| _XFUNCPROTOBEGIN Status | XmuAllStandardColormaps (Display *dpy) |
| Status | XmuCreateColormap (Display *dpy, XStandardColormap *colormap) |
| void | XmuDeleteStandardColormap (Display *dpy, int screen, Atom property) |
| Status | XmuGetColormapAllocation (XVisualInfo *vinfo, Atom property, unsigned long *red_max_return, unsigned long *green_max_return, unsigned long *blue_max_return) |
| Status | XmuLookupStandardColormap (Display *dpy, int screen, VisualID visualid, unsigned int depth, Atom property, Bool replace, Bool retain) |
| XStandardColormap * | XmuStandardColormap (Display *dpy, int screen, VisualID visualid, unsigned int depth, Atom property, Colormap cmap, unsigned long red_max, unsigned long green_max, unsigned long blue_max) |
| Status | XmuVisualStandardColormaps (Display *dpy, int screen, VisualID visualid, unsigned int depth, Bool replace, Bool retain) |
| Bool | XmuDistinguishableColors (XColor *colors, int count) |
| Bool | XmuDistinguishablePixels (Display *dpy, Colormap cmap, unsigned long *pixels, int count) |
| _XFUNCPROTOBEGIN Status XmuAllStandardColormaps | ( | Display * | dpy | ) |
Definition at line 92 of file AllCmap.c.
References getDeepestVisual(), NULL, and XmuVisualStandardColormaps().
00093 { 00094 int nvisuals, scr; 00095 Status status; 00096 long vinfo_mask; 00097 XVisualInfo template, *vinfo, *v1, *v2; 00098 00099 status = 0; 00100 /* for each screen, determine all visuals of this server */ 00101 for (scr=0; scr < ScreenCount(dpy); scr++) 00102 { 00103 template.screen = scr; 00104 vinfo_mask = VisualScreenMask; 00105 vinfo = XGetVisualInfo(dpy, vinfo_mask, &template, &nvisuals); 00106 if (vinfo == NULL) /* unexpected: a screen with no visuals */ 00107 continue; 00108 00109 v1 = getDeepestVisual(DirectColor, vinfo, nvisuals); 00110 v2 = getDeepestVisual(PseudoColor, vinfo, nvisuals); 00111 00112 if (v2 && 00113 (!v1 || (v2->colormap_size >= 00114 ((v1->red_mask | v1->green_mask | v1->blue_mask) + 1)))) 00115 status = XmuVisualStandardColormaps(dpy, scr, v2->visualid, 00116 (unsigned) v2->depth, 1, 1); 00117 else if (v1) 00118 status = XmuVisualStandardColormaps(dpy, scr, v1->visualid, 00119 (unsigned) v1->depth, 1, 1); 00120 00121 else { 00122 if (((v1 = getDeepestVisual(TrueColor, vinfo, nvisuals)) != NULL) 00123 || ((v1 = getDeepestVisual(StaticColor, vinfo, nvisuals)) != 00124 NULL)) 00125 status = XmuVisualStandardColormaps(dpy, scr, v1->visualid, 00126 (unsigned) v1->depth, 1, 1); 00127 if (status && 00128 (((v1 = getDeepestVisual(GrayScale, vinfo, nvisuals)) != NULL) 00129 || ((v1 = getDeepestVisual(StaticGray, vinfo, nvisuals)) != 00130 NULL))) 00131 status = XmuVisualStandardColormaps(dpy, scr, v1->visualid, 00132 (unsigned) v1->depth, 1, 1); 00133 } 00134 XFree ((char *) vinfo); 00135 if (!status) break; 00136 } 00137 return status; 00138 }
Here is the call graph for this function:

| Status XmuCreateColormap | ( | Display * | dpy, | |
| XStandardColormap * | colormap | |||
| ) |
Definition at line 98 of file CrCmap.c.
Referenced by XmuStandardColormap().
00104 { 00105 XVisualInfo vinfo_template; /* template visual information */ 00106 XVisualInfo *vinfo; /* matching visual information */ 00107 XVisualInfo *vpointer; /* for freeing the entire list */ 00108 long vinfo_mask; /* specifies the visual mask value */ 00109 int n; /* number of matching visuals */ 00110 int status; 00111 00112 vinfo_template.visualid = colormap->visualid; 00113 vinfo_mask = VisualIDMask; 00114 if ((vinfo = XGetVisualInfo(dpy, vinfo_mask, &vinfo_template, &n)) == NULL) 00115 return 0; 00116 00117 /* A visual id may be valid on multiple screens. Also, there may 00118 * be multiple visuals with identical visual ids at different depths. 00119 * If the colormap is the Default Colormap, use the Default Visual. 00120 * Otherwise, arbitrarily, use the deepest visual. 00121 */ 00122 vpointer = vinfo; 00123 if (n > 1) 00124 { 00125 register int i; 00126 register int screen_number; 00127 Bool def_cmap; 00128 00129 def_cmap = False; 00130 for (screen_number = ScreenCount(dpy); --screen_number >= 0; ) 00131 if (colormap->colormap == DefaultColormap(dpy, screen_number)) { 00132 def_cmap = True; 00133 break; 00134 } 00135 00136 if (def_cmap) { 00137 for (i=0; i < n; i++, vinfo++) { 00138 if (vinfo->visual == DefaultVisual(dpy, screen_number)) 00139 break; 00140 } 00141 } else { 00142 int maxdepth = 0; 00143 XVisualInfo *v = NULL; 00144 00145 for (i=0; i < n; i++, vinfo++) 00146 if (vinfo->depth > maxdepth) { 00147 maxdepth = vinfo->depth; 00148 v = vinfo; 00149 } 00150 vinfo = v; 00151 } 00152 } 00153 00154 if (vinfo->class == PseudoColor || vinfo->class == DirectColor || 00155 vinfo->class == GrayScale) 00156 status = readwrite_map(dpy, vinfo, colormap); 00157 else if (vinfo->class == TrueColor) 00158 status = TRUEMATCH(red_mult, red_max, red_mask) && 00159 TRUEMATCH(green_mult, green_max, green_mask) && 00160 TRUEMATCH(blue_mult, blue_max, blue_mask); 00161 else 00162 status = readonly_map(dpy, vinfo, colormap); 00163 00164 XFree((char *) vpointer); 00165 return status; 00166 }
Here is the caller graph for this function:

| void XmuDeleteStandardColormap | ( | Display * | dpy, | |
| int | screen, | |||
| Atom | property | |||
| ) |
Definition at line 45 of file DelCmap.c.
Referenced by lookup(), and XmuVisualStandardColormaps().
00050 { 00051 XStandardColormap *stdcmaps, *s; 00052 int count = 0; 00053 00054 if (XGetRGBColormaps(dpy, RootWindow(dpy, screen), &stdcmaps, &count, 00055 property)) 00056 { 00057 for (s=stdcmaps; count > 0; count--, s++) { 00058 if ((s->killid == ReleaseByFreeingColormap) && 00059 (s->colormap != None) && 00060 (s->colormap != DefaultColormap(dpy, screen))) 00061 XFreeColormap(dpy, s->colormap); 00062 else if (s->killid != None) 00063 XKillClient(dpy, s->killid); 00064 } 00065 XDeleteProperty(dpy, RootWindow(dpy, screen), property); 00066 XFree((char *) stdcmaps); 00067 XSync(dpy, False); 00068 } 00069 }
Here is the caller graph for this function:

| Bool XmuDistinguishableColors | ( | XColor * | colors, | |
| int | count | |||
| ) |
Definition at line 47 of file Distinct.c.
References i, j, and MIN_DISTINGUISH.
Referenced by XmuDistinguishablePixels().
00048 { 00049 double deltaRed, deltaGreen, deltaBlue; 00050 double dist; 00051 int i, j; 00052 00053 for (i = 0; i < count - 1; i++) 00054 for (j = i + 1; j < count; j++) 00055 { 00056 deltaRed = (double)colors[i].red - (double)colors[j].red; 00057 deltaGreen = (double)colors[i].green - (double)colors[j].green; 00058 deltaBlue = (double)colors[i].blue - (double)colors[j].blue; 00059 dist = deltaRed * deltaRed + 00060 deltaGreen * deltaGreen + 00061 deltaBlue * deltaBlue; 00062 if (dist <= MIN_DISTINGUISH * MIN_DISTINGUISH) 00063 return False; 00064 } 00065 return True; 00066 }
Here is the caller graph for this function:

Definition at line 69 of file Distinct.c.
References free(), i, j, malloc(), and XmuDistinguishableColors().
00071 { 00072 XColor *defs; 00073 int i, j; 00074 Bool ret; 00075 00076 for (i = 0; i < count - 1; i++) 00077 for (j = i + 1; j < count; j++) 00078 if (pixels[i] == pixels[j]) 00079 return False; 00080 defs = (XColor *) malloc (count * sizeof (XColor)); 00081 if (!defs) 00082 return False; 00083 for (i = 0; i < count; i++) 00084 defs[i].pixel = pixels[i]; 00085 XQueryColors (dpy, cmap, defs, count); 00086 ret = XmuDistinguishableColors (defs, count); 00087 free ((char *) defs); 00088 return ret; 00089 }
Here is the call graph for this function:

| Status XmuGetColormapAllocation | ( | XVisualInfo * | vinfo, | |
| Atom | property, | |||
| unsigned long * | red_max_return, | |||
| unsigned long * | green_max_return, | |||
| unsigned long * | blue_max_return | |||
| ) |
Definition at line 68 of file CmapAlloc.c.
References best_allocation(), default_allocation(), and gray_allocation().
Referenced by XmuLookupStandardColormap().
00072 { 00073 Status status = 1; 00074 00075 if (vinfo->colormap_size <= 2) 00076 return 0; 00077 00078 switch (property) 00079 { 00080 case XA_RGB_DEFAULT_MAP: 00081 status = default_allocation(vinfo, red_max, green_max, blue_max); 00082 break; 00083 case XA_RGB_BEST_MAP: 00084 best_allocation(vinfo, red_max, green_max, blue_max); 00085 break; 00086 case XA_RGB_GRAY_MAP: 00087 gray_allocation(vinfo->colormap_size, red_max, green_max, blue_max); 00088 break; 00089 case XA_RGB_RED_MAP: 00090 *red_max = vinfo->colormap_size - 1; 00091 *green_max = *blue_max = 0; 00092 break; 00093 case XA_RGB_GREEN_MAP: 00094 *green_max = vinfo->colormap_size - 1; 00095 *red_max = *blue_max = 0; 00096 break; 00097 case XA_RGB_BLUE_MAP: 00098 *blue_max = vinfo->colormap_size - 1; 00099 *red_max = *green_max = 0; 00100 break; 00101 default: 00102 status = 0; 00103 } 00104 return status; 00105 }
Here is the call graph for this function:

Here is the caller graph for this function:

| Status XmuLookupStandardColormap | ( | Display * | dpy, | |
| int | screen, | |||
| VisualID | visualid, | |||
| unsigned int | depth, | |||
| Atom | property, | |||
| Bool | replace, | |||
| Bool | retain | |||
| ) |
Definition at line 72 of file LookupCmap.c.
References count, lookup(), NULL, XmuGetColormapAllocation(), and XmuStandardColormap().
Referenced by XmuVisualStandardColormaps().
00084 { 00085 Display *odpy; /* original display connection */ 00086 XStandardColormap *colormap; 00087 XVisualInfo vinfo_template, *vinfo; /* visual */ 00088 long vinfo_mask; 00089 unsigned long r_max, g_max, b_max; /* allocation */ 00090 int count; 00091 Colormap cmap; /* colormap ID */ 00092 Status status = 0; 00093 00094 00095 /* Match the requested visual */ 00096 00097 vinfo_template.visualid = visualid; 00098 vinfo_template.screen = screen; 00099 vinfo_template.depth = depth; 00100 vinfo_mask = VisualIDMask | VisualScreenMask | VisualDepthMask; 00101 if ((vinfo = XGetVisualInfo(dpy, vinfo_mask, &vinfo_template, &count)) == 00102 NULL) 00103 return 0; 00104 00105 /* Monochrome visuals have no standard maps */ 00106 00107 if (vinfo->colormap_size <= 2) { 00108 XFree((char *) vinfo); 00109 return 0; 00110 } 00111 00112 /* If the requested property already exists on this screen, and, 00113 * if the replace flag has not been set to true, return success. 00114 * lookup() will remove a pre-existing map if replace is true. 00115 */ 00116 00117 if (lookup(dpy, screen, visualid, property, (XStandardColormap *) NULL, 00118 replace) && !replace) { 00119 XFree((char *) vinfo); 00120 return 1; 00121 } 00122 00123 /* Determine the best allocation for this property under the requested 00124 * visualid and depth, and determine whether or not to use the default 00125 * colormap of the screen. 00126 */ 00127 00128 if (!XmuGetColormapAllocation(vinfo, property, &r_max, &g_max, &b_max)) { 00129 XFree((char *) vinfo); 00130 return 0; 00131 } 00132 00133 cmap = (property == XA_RGB_DEFAULT_MAP && 00134 visualid == XVisualIDFromVisual(DefaultVisual(dpy, screen))) 00135 ? DefaultColormap(dpy, screen) : None; 00136 00137 /* If retaining resources, open a new connection to the same server */ 00138 00139 if (retain) { 00140 odpy = dpy; 00141 if ((dpy = XOpenDisplay(XDisplayString(odpy))) == NULL) { 00142 XFree((char *) vinfo); 00143 return 0; 00144 } 00145 } 00146 00147 /* Create the standard colormap */ 00148 00149 colormap = XmuStandardColormap(dpy, screen, visualid, depth, property, 00150 cmap, r_max, g_max, b_max); 00151 00152 /* Set the standard colormap property */ 00153 00154 if (colormap) { 00155 XGrabServer(dpy); 00156 00157 if (lookup(dpy, screen, visualid, property, colormap, replace) && 00158 !replace) { 00159 /* Someone has defined the property since we last looked. 00160 * Since we will not replace it, release our own resources. 00161 * If this is the default map, our allocations will be freed 00162 * when this connection closes. 00163 */ 00164 if (colormap->killid == ReleaseByFreeingColormap) 00165 XFreeColormap(dpy, colormap->colormap); 00166 } 00167 else if (retain) { 00168 XSetCloseDownMode(dpy, RetainPermanent); 00169 } 00170 XUngrabServer(dpy); 00171 XFree((char *) colormap); 00172 status = 1; 00173 } 00174 00175 if (retain) 00176 XCloseDisplay(dpy); 00177 XFree((char *) vinfo); 00178 return status; 00179 }
Here is the call graph for this function:

Here is the caller graph for this function:

| XStandardColormap* XmuStandardColormap | ( | Display * | dpy, | |
| int | screen, | |||
| VisualID | visualid, | |||
| unsigned int | depth, | |||
| Atom | property, | |||
| Colormap | cmap, | |||
| unsigned long | red_max, | |||
| unsigned long | green_max, | |||
| unsigned long | blue_max | |||
| ) |
Definition at line 65 of file StdCmap.c.
References lowbit, n, NULL, valid_args(), and XmuCreateColormap().
Referenced by XmuLookupStandardColormap().
00078 { 00079 XStandardColormap *stdcmap; 00080 Status status; 00081 XVisualInfo vinfo_template, *vinfo; 00082 long vinfo_mask; 00083 int n; 00084 00085 /* Match the required visual information to an actual visual */ 00086 vinfo_template.visualid = visualid; 00087 vinfo_template.screen = screen; 00088 vinfo_template.depth = depth; 00089 vinfo_mask = VisualIDMask | VisualScreenMask | VisualDepthMask; 00090 if ((vinfo = XGetVisualInfo(dpy, vinfo_mask, &vinfo_template, &n)) == NULL) 00091 return 0; 00092 00093 /* Check the validity of the combination of visual characteristics, 00094 * allocation, and colormap property. Create an XStandardColormap 00095 * structure. 00096 */ 00097 00098 if (! valid_args(vinfo, red_max, green_max, blue_max, property) 00099 || ((stdcmap = XAllocStandardColormap()) == NULL)) { 00100 XFree((char *) vinfo); 00101 return 0; 00102 } 00103 00104 /* Fill in the XStandardColormap structure */ 00105 00106 if (cmap == DefaultColormap(dpy, screen)) { 00107 /* Allocating out of the default map, cannot use XFreeColormap() */ 00108 Window win = XCreateWindow(dpy, RootWindow(dpy, screen), 1, 1, 1, 1, 00109 0, 0, InputOnly, vinfo->visual, 00110 (unsigned long) 0, 00111 (XSetWindowAttributes *)NULL); 00112 stdcmap->killid = (XID) XCreatePixmap(dpy, win, 1, 1, depth); 00113 XDestroyWindow(dpy, win); 00114 stdcmap->colormap = cmap; 00115 } else { 00116 stdcmap->killid = ReleaseByFreeingColormap; 00117 stdcmap->colormap = XCreateColormap(dpy, RootWindow(dpy, screen), 00118 vinfo->visual, AllocNone); 00119 } 00120 stdcmap->red_max = red_max; 00121 stdcmap->green_max = green_max; 00122 stdcmap->blue_max = blue_max; 00123 if (property == XA_RGB_GRAY_MAP) 00124 stdcmap->red_mult = stdcmap->green_mult = stdcmap->blue_mult = 1; 00125 else if (vinfo->class == TrueColor || vinfo->class == DirectColor) { 00126 stdcmap->red_mult = lowbit(vinfo->red_mask); 00127 stdcmap->green_mult = lowbit(vinfo->green_mask); 00128 stdcmap->blue_mult = lowbit(vinfo->blue_mask); 00129 } else { 00130 stdcmap->red_mult = (red_max > 0) 00131 ? (green_max + 1) * (blue_max + 1) : 0; 00132 stdcmap->green_mult = (green_max > 0) ? blue_max + 1 : 0; 00133 stdcmap->blue_mult = (blue_max > 0) ? 1 : 0; 00134 } 00135 stdcmap->base_pixel = 0; /* base pixel may change */ 00136 stdcmap->visualid = vinfo->visualid; 00137 00138 /* Make the colormap */ 00139 00140 status = XmuCreateColormap(dpy, stdcmap); 00141 00142 /* Clean up */ 00143 00144 XFree((char *) vinfo); 00145 if (!status) { 00146 00147 /* Free the colormap or the pixmap, if we created one */ 00148 if (stdcmap->killid == ReleaseByFreeingColormap) 00149 XFreeColormap(dpy, stdcmap->colormap); 00150 else if (stdcmap->killid != None) 00151 XFreePixmap(dpy, stdcmap->killid); 00152 00153 XFree((char *) stdcmap); 00154 return (XStandardColormap *) NULL; 00155 } 00156 return stdcmap; 00157 }
Here is the call graph for this function:

Here is the caller graph for this function:

| Status XmuVisualStandardColormaps | ( | Display * | dpy, | |
| int | screen, | |||
| VisualID | visualid, | |||
| unsigned int | depth, | |||
| Bool | replace, | |||
| Bool | retain | |||
| ) |
Definition at line 72 of file VisCmap.c.
References n, NULL, XmuDeleteStandardColormap(), and XmuLookupStandardColormap().
Referenced by XmuAllStandardColormaps().
00082 { 00083 Status status; 00084 int n; 00085 long vinfo_mask; 00086 XVisualInfo vinfo_template, *vinfo; 00087 00088 status = 0; 00089 vinfo_template.screen = screen; 00090 vinfo_template.visualid = visualid; 00091 vinfo_template.depth = depth; 00092 vinfo_mask = VisualScreenMask | VisualIDMask | VisualDepthMask; 00093 if ((vinfo = XGetVisualInfo(dpy, vinfo_mask, &vinfo_template, &n)) == NULL) 00094 return 0; 00095 00096 if (vinfo->colormap_size <= 2) { 00097 /* Monochrome visuals have no standard maps; considered successful */ 00098 XFree((char *) vinfo); 00099 return 1; 00100 } 00101 00102 switch (vinfo->class) 00103 { 00104 case PseudoColor: 00105 case DirectColor: 00106 status = XmuLookupStandardColormap(dpy, screen, visualid, depth, 00107 XA_RGB_DEFAULT_MAP, replace,retain); 00108 if (!status) break; 00109 00110 status = XmuLookupStandardColormap(dpy, screen, visualid, depth, 00111 XA_RGB_GRAY_MAP, replace, retain); 00112 if (!status) { 00113 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP); 00114 break; 00115 } 00116 00117 status = XmuLookupStandardColormap(dpy, screen, visualid, depth, 00118 XA_RGB_RED_MAP, replace, retain); 00119 if (!status) { 00120 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP); 00121 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GRAY_MAP); 00122 break; 00123 } 00124 00125 status = XmuLookupStandardColormap(dpy, screen, visualid, depth, 00126 XA_RGB_GREEN_MAP, replace, retain); 00127 if (!status) { 00128 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP); 00129 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GRAY_MAP); 00130 XmuDeleteStandardColormap(dpy, screen, XA_RGB_RED_MAP); 00131 break; 00132 } 00133 00134 status = XmuLookupStandardColormap(dpy, screen, visualid, depth, 00135 XA_RGB_BLUE_MAP, replace, retain); 00136 if (!status) { 00137 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP); 00138 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GRAY_MAP); 00139 XmuDeleteStandardColormap(dpy, screen, XA_RGB_RED_MAP); 00140 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GREEN_MAP); 00141 break; 00142 } 00143 /* fall through */ 00144 00145 case StaticColor: 00146 case TrueColor: 00147 00148 status = XmuLookupStandardColormap(dpy, screen, visualid, depth, 00149 XA_RGB_BEST_MAP, replace, retain); 00150 if (!status && (vinfo->class == PseudoColor || 00151 vinfo->class == DirectColor)) { 00152 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP); 00153 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GRAY_MAP); 00154 XmuDeleteStandardColormap(dpy, screen, XA_RGB_RED_MAP); 00155 XmuDeleteStandardColormap(dpy, screen, XA_RGB_GREEN_MAP); 00156 XmuDeleteStandardColormap(dpy, screen, XA_RGB_BLUE_MAP); 00157 } 00158 break; 00159 /* the end for PseudoColor, DirectColor, StaticColor, and TrueColor */ 00160 00161 case GrayScale: 00162 status = XmuLookupStandardColormap(dpy, screen, visualid, depth, 00163 XA_RGB_DEFAULT_MAP, replace, 00164 retain); 00165 if (! status) break; 00166 /*FALLTHROUGH*/ 00167 00168 case StaticGray: 00169 00170 status = XmuLookupStandardColormap(dpy, screen, visualid, depth, 00171 XA_RGB_GRAY_MAP, replace, retain); 00172 if (! status && vinfo->class == GrayScale) { 00173 XmuDeleteStandardColormap(dpy, screen, XA_RGB_DEFAULT_MAP); 00174 break; 00175 } 00176 } 00177 00178 XFree((char *) vinfo); 00179 return status; 00180 }
Here is the call graph for this function:

Here is the caller graph for this function:

1.5.1