SetRGBCMap.c revision 818534a1
11ab64890Smrg/*
21ab64890Smrg
31ab64890SmrgCopyright 1989, 1998  The Open Group
41ab64890Smrg
51ab64890SmrgPermission to use, copy, modify, distribute, and sell this software and its
61ab64890Smrgdocumentation for any purpose is hereby granted without fee, provided that
71ab64890Smrgthe above copyright notice appear in all copies and that both that
81ab64890Smrgcopyright notice and this permission notice appear in supporting
91ab64890Smrgdocumentation.
101ab64890Smrg
111ab64890SmrgThe above copyright notice and this permission notice shall be included
121ab64890Smrgin all copies or substantial portions of the Software.
131ab64890Smrg
141ab64890SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
151ab64890SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
161ab64890SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
171ab64890SmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
181ab64890SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
191ab64890SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
201ab64890SmrgOTHER DEALINGS IN THE SOFTWARE.
211ab64890Smrg
221ab64890SmrgExcept as contained in this notice, the name of The Open Group shall
231ab64890Smrgnot be used in advertising or otherwise to promote the sale, use or
241ab64890Smrgother dealings in this Software without prior written authorization
251ab64890Smrgfrom The Open Group.
261ab64890Smrg
271ab64890Smrg*/
281ab64890Smrg
291ab64890Smrg
301ab64890Smrg#ifdef HAVE_CONFIG_H
311ab64890Smrg#include <config.h>
321ab64890Smrg#endif
331ab64890Smrg#include <X11/Xlibint.h>
341ab64890Smrg#include <X11/Xutil.h>
351ab64890Smrg#include "Xatomtype.h"
361ab64890Smrg#include <X11/Xatom.h>
371ab64890Smrg
381ab64890Smrgvoid XSetRGBColormaps (
391ab64890Smrg    Display *dpy,
401ab64890Smrg    Window w,
411ab64890Smrg    XStandardColormap *cmaps,
421ab64890Smrg    int count,
431ab64890Smrg    Atom property)			/* XA_RGB_BEST_MAP, etc. */
441ab64890Smrg{
451ab64890Smrg    register int i;			/* iterator variable */
461ab64890Smrg    register xPropStandardColormap *map;  /* tmp variable, data in prop */
471ab64890Smrg    register XStandardColormap *cmap;	/* tmp variable, user data */
481ab64890Smrg    xPropStandardColormap *data, tmpdata;  /* scratch data */
491ab64890Smrg    int mode = PropModeReplace;		/* for partial writes */
501ab64890Smrg    Bool alloced_scratch_space;		/* do we need to free? */
5161b2299dSmrg
521ab64890Smrg
531ab64890Smrg    if (count < 1) return;
541ab64890Smrg
551ab64890Smrg    /*
561ab64890Smrg     * if doing more than one, allocate scratch space for it
571ab64890Smrg     */
581ab64890Smrg    if ((count > 1) && ((data = ((xPropStandardColormap *)
591ab64890Smrg				 Xmalloc(count*sizeof(xPropStandardColormap))))
601ab64890Smrg			 != NULL)) {
611ab64890Smrg	alloced_scratch_space = True;
621ab64890Smrg    } else {
631ab64890Smrg	data = &tmpdata;
641ab64890Smrg	alloced_scratch_space = False;
651ab64890Smrg    }
661ab64890Smrg
671ab64890Smrg
681ab64890Smrg    /*
691ab64890Smrg     * Do the iteration.  If using temp space put out each part of the prop;
701ab64890Smrg     * otherwise, wait until the end and blast it all at once.
711ab64890Smrg     */
721ab64890Smrg    for (i = count, map = data, cmap = cmaps; i > 0; i--, cmap++) {
731ab64890Smrg	map->colormap	= cmap->colormap;
741ab64890Smrg	map->red_max	= cmap->red_max;
751ab64890Smrg	map->red_mult	= cmap->red_mult;
761ab64890Smrg	map->green_max	= cmap->green_max;
771ab64890Smrg	map->green_mult	= cmap->green_mult;
781ab64890Smrg	map->blue_max	= cmap->blue_max;
791ab64890Smrg	map->blue_mult	= cmap->blue_mult;
801ab64890Smrg	map->base_pixel	= cmap->base_pixel;
811ab64890Smrg	map->visualid	= cmap->visualid;
821ab64890Smrg	map->killid	= cmap->killid;
831ab64890Smrg
841ab64890Smrg	if (alloced_scratch_space) {
851ab64890Smrg	    map++;
861ab64890Smrg	} else {
871ab64890Smrg	    XChangeProperty (dpy, w, property, XA_RGB_COLOR_MAP, 32, mode,
881ab64890Smrg			     (unsigned char *) data,
891ab64890Smrg			     NumPropStandardColormapElements);
901ab64890Smrg	    mode = PropModeAppend;
911ab64890Smrg	}
921ab64890Smrg    }
931ab64890Smrg
941ab64890Smrg    if (alloced_scratch_space) {
951ab64890Smrg	XChangeProperty (dpy, w, property, XA_RGB_COLOR_MAP, 32,
961ab64890Smrg			 PropModeReplace, (unsigned char *) data,
971ab64890Smrg			 (int) (count * NumPropStandardColormapElements));
98818534a1Smrg	Xfree (data);
991ab64890Smrg    }
1001ab64890Smrg}
101