Blame src/SetRGBCMap.c

Packit Service dc579d
/*
Packit Service dc579d
Packit Service dc579d
Copyright 1989, 1998  The Open Group
Packit Service dc579d
Packit Service dc579d
Permission to use, copy, modify, distribute, and sell this software and its
Packit Service dc579d
documentation for any purpose is hereby granted without fee, provided that
Packit Service dc579d
the above copyright notice appear in all copies and that both that
Packit Service dc579d
copyright notice and this permission notice appear in supporting
Packit Service dc579d
documentation.
Packit Service dc579d
Packit Service dc579d
The above copyright notice and this permission notice shall be included
Packit Service dc579d
in all copies or substantial portions of the Software.
Packit Service dc579d
Packit Service dc579d
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
Packit Service dc579d
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
Packit Service dc579d
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
Packit Service dc579d
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
Packit Service dc579d
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
Packit Service dc579d
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
Packit Service dc579d
OTHER DEALINGS IN THE SOFTWARE.
Packit Service dc579d
Packit Service dc579d
Except as contained in this notice, the name of The Open Group shall
Packit Service dc579d
not be used in advertising or otherwise to promote the sale, use or
Packit Service dc579d
other dealings in this Software without prior written authorization
Packit Service dc579d
from The Open Group.
Packit Service dc579d
Packit Service dc579d
*/
Packit Service dc579d
Packit Service dc579d
Packit Service dc579d
#ifdef HAVE_CONFIG_H
Packit Service dc579d
#include <config.h>
Packit Service dc579d
#endif
Packit Service dc579d
#include <X11/Xlibint.h>
Packit Service dc579d
#include <X11/Xutil.h>
Packit Service dc579d
#include "Xatomtype.h"
Packit Service dc579d
#include <X11/Xatom.h>
Packit Service dc579d
#include "reallocarray.h"
Packit Service dc579d
Packit Service dc579d
void XSetRGBColormaps (
Packit Service dc579d
    Display *dpy,
Packit Service dc579d
    Window w,
Packit Service dc579d
    XStandardColormap *cmaps,
Packit Service dc579d
    int count,
Packit Service dc579d
    Atom property)			/* XA_RGB_BEST_MAP, etc. */
Packit Service dc579d
{
Packit Service dc579d
    register int i;			/* iterator variable */
Packit Service dc579d
    register xPropStandardColormap *map;  /* tmp variable, data in prop */
Packit Service dc579d
    register XStandardColormap *cmap;	/* tmp variable, user data */
Packit Service dc579d
    xPropStandardColormap *data, tmpdata;  /* scratch data */
Packit Service dc579d
    int mode = PropModeReplace;		/* for partial writes */
Packit Service dc579d
    Bool alloced_scratch_space;		/* do we need to free? */
Packit Service dc579d
Packit Service dc579d
Packit Service dc579d
    if (count < 1) return;
Packit Service dc579d
Packit Service dc579d
    /*
Packit Service dc579d
     * if doing more than one, allocate scratch space for it
Packit Service dc579d
     */
Packit Service dc579d
    if ((count > 1) &&
Packit Service dc579d
        ((data = (Xmallocarray(count,
Packit Service dc579d
                               sizeof(xPropStandardColormap)))) != NULL)) {
Packit Service dc579d
	alloced_scratch_space = True;
Packit Service dc579d
    } else {
Packit Service dc579d
	data = &tmpdata;
Packit Service dc579d
	alloced_scratch_space = False;
Packit Service dc579d
    }
Packit Service dc579d
Packit Service dc579d
Packit Service dc579d
    /*
Packit Service dc579d
     * Do the iteration.  If using temp space put out each part of the prop;
Packit Service dc579d
     * otherwise, wait until the end and blast it all at once.
Packit Service dc579d
     */
Packit Service dc579d
    for (i = count, map = data, cmap = cmaps; i > 0; i--, cmap++) {
Packit Service dc579d
	map->colormap	= cmap->colormap;
Packit Service dc579d
	map->red_max	= cmap->red_max;
Packit Service dc579d
	map->red_mult	= cmap->red_mult;
Packit Service dc579d
	map->green_max	= cmap->green_max;
Packit Service dc579d
	map->green_mult	= cmap->green_mult;
Packit Service dc579d
	map->blue_max	= cmap->blue_max;
Packit Service dc579d
	map->blue_mult	= cmap->blue_mult;
Packit Service dc579d
	map->base_pixel	= cmap->base_pixel;
Packit Service dc579d
	map->visualid	= cmap->visualid;
Packit Service dc579d
	map->killid	= cmap->killid;
Packit Service dc579d
Packit Service dc579d
	if (alloced_scratch_space) {
Packit Service dc579d
	    map++;
Packit Service dc579d
	} else {
Packit Service dc579d
	    XChangeProperty (dpy, w, property, XA_RGB_COLOR_MAP, 32, mode,
Packit Service dc579d
			     (unsigned char *) data,
Packit Service dc579d
			     NumPropStandardColormapElements);
Packit Service dc579d
	    mode = PropModeAppend;
Packit Service dc579d
	}
Packit Service dc579d
    }
Packit Service dc579d
Packit Service dc579d
    if (alloced_scratch_space) {
Packit Service dc579d
	XChangeProperty (dpy, w, property, XA_RGB_COLOR_MAP, 32,
Packit Service dc579d
			 PropModeReplace, (unsigned char *) data,
Packit Service dc579d
			 (int) (count * NumPropStandardColormapElements));
Packit Service dc579d
	Xfree (data);
Packit Service dc579d
    }
Packit Service dc579d
}