VisCmap.c

Go to the documentation of this file.
00001 /* $Xorg: VisCmap.c,v 1.4 2001/02/09 02:03:53 xorgcvs Exp $ */
00002 
00003 /* 
00004 
00005 Copyright 1989, 1998  The Open Group
00006 
00007 Permission to use, copy, modify, distribute, and sell this software and its
00008 documentation for any purpose is hereby granted without fee, provided that
00009 the above copyright notice appear in all copies and that both that
00010 copyright notice and this permission notice appear in supporting
00011 documentation.
00012 
00013 The above copyright notice and this permission notice shall be included in
00014 all copies or substantial portions of the Software.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
00019 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00022 
00023 Except as contained in this notice, the name of The Open Group shall not be
00024 used in advertising or otherwise to promote the sale, use or other dealings
00025 in this Software without prior written authorization from The Open Group.
00026 
00027 */
00028 /* $XFree86: xc/lib/Xmu/VisCmap.c,v 1.6 2001/01/17 19:42:57 dawes Exp $ */
00029 
00030 /*
00031  * Author:  Donna Converse, MIT X Consortium
00032  */
00033 
00034 #include <stdio.h>
00035 #include <math.h>
00036 #include <X11/Xlib.h>
00037 #include <X11/Xatom.h>
00038 #include <X11/Xutil.h>
00039 #include <X11/Xmu/StdCmap.h>
00040 
00041 /*
00042  * To create all of the appropriate standard colormaps for a given visual on
00043  * a given screen, use XmuVisualStandardColormaps.
00044  * 
00045  * Define all appropriate standard colormap properties for the given visual.
00046  * If replace is true, any previous definition will be removed.
00047  * If retain is true, new properties will be retained for the duration of
00048  * the server session.  Return 0 on failure, non-zero on success.
00049  * On failure, no new properties will be defined, and, old ones may have
00050  * been removed if replace was True.
00051  *
00052  * Not all standard colormaps are meaningful to all visual classes.  This
00053  * routine will check and define the following properties for the following
00054  * classes, provided that the size of the colormap is not too small.
00055  *
00056  *      DirectColor and PseudoColor
00057  *          RGB_DEFAULT_MAP
00058  *          RGB_BEST_MAP
00059  *          RGB_RED_MAP
00060  *          RGB_GREEN_MAP
00061  *          RGB_BLUE_MAP
00062  *          RGB_GRAY_MAP
00063  *
00064  *      TrueColor and StaticColor
00065  *          RGB_BEST_MAP
00066  *
00067  *      GrayScale and StaticGray
00068  *          RGB_GRAY_MAP
00069  */
00070 
00071 Status
00072 XmuVisualStandardColormaps(Display *dpy, int screen, VisualID visualid,
00073                            unsigned int depth, Bool replace, Bool retain)
00074      /*
00075       * dpy                     - specifies server connection
00076       * screen                  - specifies screen number
00077       * visualid                - specifies the visual
00078       * depth                   - specifies the visual
00079       * replace specifies       - whether to replace
00080       * retain                  - specifies whether to retain
00081       */
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 }

Generated on Sun Mar 4 15:03:56 2007 for Scilab [trunk] by  doxygen 1.5.1