StdCmap.c File Reference

#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/Xutil.h>
#include <X11/Xmu/StdCmap.h>

Include dependency graph for StdCmap.c:

Go to the source code of this file.

Defines

#define lowbit(x)   ((x) & (~(x) + 1))

Functions

static Status valid_args (XVisualInfo *, unsigned long, unsigned long, unsigned long, Atom)
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)


Define Documentation

#define lowbit ( x   )     ((x) & (~(x) + 1))

Definition at line 40 of file StdCmap.c.


Function Documentation

static Status valid_args ( XVisualInfo *  ,
unsigned  long,
unsigned  long,
unsigned  long,
Atom   
) [static]

Definition at line 161 of file StdCmap.c.

Referenced by XmuStandardColormap().

00168 {
00169     unsigned long       ncolors;        /* number of colors requested */
00170 
00171     /* Determine that the number of colors requested is <= map size */
00172 
00173     if ((vinfo->class == DirectColor) || (vinfo->class == TrueColor)) {
00174         unsigned long mask;
00175 
00176         mask = vinfo->red_mask;
00177         while (!(mask & 1))
00178             mask >>= 1;
00179         if (red_max > mask)
00180             return 0;
00181         mask = vinfo->green_mask;
00182         while (!(mask & 1))
00183             mask >>= 1;
00184         if (green_max > mask)
00185             return 0;
00186         mask = vinfo->blue_mask;
00187         while (!(mask & 1))
00188             mask >>= 1;
00189         if (blue_max > mask)
00190             return 0;
00191     } else if (property == XA_RGB_GRAY_MAP) {
00192         ncolors = red_max + green_max + blue_max + 1;
00193         if (ncolors > vinfo->colormap_size)
00194             return 0;
00195     } else {
00196         ncolors = (red_max + 1) * (green_max + 1) * (blue_max + 1);
00197         if (ncolors > vinfo->colormap_size)
00198             return 0;
00199     }
00200     
00201     /* Determine that the allocation and visual make sense for the property */
00202 
00203     switch (property)
00204     {
00205       case XA_RGB_DEFAULT_MAP:
00206         if (red_max == 0 || green_max == 0 || blue_max == 0)
00207             return 0;
00208         break;
00209       case XA_RGB_RED_MAP:
00210         if (red_max == 0)
00211             return 0;
00212         break;
00213       case XA_RGB_GREEN_MAP:
00214         if (green_max == 0)
00215             return 0;
00216         break;
00217       case XA_RGB_BLUE_MAP:     
00218         if (blue_max == 0)
00219             return 0;
00220         break;
00221       case XA_RGB_BEST_MAP:
00222         if (red_max == 0 || green_max == 0 || blue_max == 0)
00223             return 0;
00224         break;
00225       case XA_RGB_GRAY_MAP:
00226         if (red_max == 0 || blue_max == 0 || green_max == 0)
00227             return 0;
00228         break;
00229       default:
00230         return 0;
00231     }
00232     return 1;
00233 }

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:


Generated on Sun Mar 4 16:04:19 2007 for Scilab [trunk] by  doxygen 1.5.1