<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
                   "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd">
<!-- lifted from troff+man by doclifter -->
<refentry id='xcrecmapman'>
<!--  Copyright \(co 1985, 1986, 1987, 1988, 1989, 1990, 1991, 1994, 1996 X Consortium -->

<!--  Permission is hereby granted, free of charge, to any person obtaining -->
<!--  a copy of this software and associated documentation files (the -->
<!--  "Software"), to deal in the Software without restriction, including -->
<!--  without limitation the rights to use, copy, modify, merge, publish, -->
<!--  distribute, sublicense, and/or sell copies of the Software, and to -->
<!--  permit persons to whom the Software is furnished to do so, subject to -->
<!--  the following conditions: -->

<!--  The above copyright notice and this permission notice shall be included -->
<!--  in all copies or substantial portions of the Software. -->

<!--  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -->
<!--  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -->
<!--  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -->
<!--  IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR -->
<!--  OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -->
<!--  ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -->
<!--  OTHER DEALINGS IN THE SOFTWARE. -->

<!--  Except as contained in this notice, the name of the X Consortium shall -->
<!--  not be used in advertising or otherwise to promote the sale, use or -->
<!--  other dealings in this Software without prior written authorization -->
<!--  from the X Consortium. -->

<!--  Copyright \(co 1985, 1986, 1987, 1988, 1989, 1990, 1991 by -->
<!--  Digital Equipment Corporation -->

<!--  Portions Copyright \(co 1990, 1991 by -->
<!--  Tektronix, Inc. -->

<!--  Permission to use, copy, modify and distribute this documentation for -->
<!--  any purpose and without fee is hereby granted, provided that the above -->
<!--  copyright notice appears in all copies and that both that copyright notice -->
<!--  and this permission notice appear in all copies, and that the names of -->
<!--  Digital and Tektronix not be used in in advertising or publicity pertaining -->
<!--  to this documentation without specific, written prior permission. -->
<!--  Digital and Tektronix makes no representations about the suitability -->
<!--  of this documentation for any purpose. -->
<!--  It is provided ``as is'' without express or implied warranty. -->
<!--   -->
<!--  $XFree86: xc/doc/man/X11/XCreCmap.man,v 1.5 2003/11/23 05:40:33 dawes Exp $ -->

<!-- .na -->
<!-- FD listing suppressed (not used) -->
<!-- FN listing suppressed (not used) -->
<!-- C{ listing suppressed (not used) -->
<!-- C} listing suppressed (not used) -->
<!-- Pn listing suppressed (not used) -->
<!-- hN listing suppressed (not used) -->
<!-- NT listing suppressed (not used) -->
<!-- .		\" Note End \-\- doug kraft 3/85 -->
<!-- NE listing suppressed (not used) -->
<!-- .ny0 -->
<refmeta>
<refentrytitle>XCreateColormap</refentrytitle>
<manvolnum>3X11</manvolnum>
<refmiscinfo class='date'>__xorgversion__</refmiscinfo>
<refmiscinfo class='source'>XLIB FUNCTIONS</refmiscinfo>
</refmeta>
<refnamediv id='name'>
<refname>XCreateColormap</refname>
<refname>XCopyColormapAndFree</refname>
<refname>XFreeColormap</refname>
<refname>XColor</refname>
<refpurpose>create, copy, or destroy colormaps and color structure</refpurpose>
</refnamediv>
<!-- body begins here -->

<refsect1 id='syntax'><title>SYNTAX</title>

<para>Colormap XCreateColormap&hairsp;(&hairsp;Display *<emphasis remap='I'>display</emphasis>&hairsp;, Window <emphasis remap='I'>w</emphasis>&hairsp;,
Visual *<emphasis remap='I'>visual</emphasis>&hairsp;, int <emphasis remap='I'>alloc</emphasis>&hairsp;,);</para> 

<para>Colormap XCopyColormapAndFree&hairsp;(&hairsp;Display *<emphasis remap='I'>display</emphasis>&hairsp;, Colormap
<emphasis remap='I'>colormap</emphasis>&hairsp;);</para> 

<para>int XFreeColormap&hairsp;(&hairsp;Display *<emphasis remap='I'>display</emphasis>&hairsp;, Colormap <emphasis remap='I'>colormap</emphasis>&hairsp;);</para> 
</refsect1>

<refsect1 id='arguments'><title>ARGUMENTS</title>
<variablelist remap='IP'>
  <varlistentry>
  <term><emphasis remap='I'>alloc</emphasis></term>
  <listitem>
<para>Specifies the colormap entries to be allocated.
You can pass 
<emphasis remap='I'>&hairsp;AllocNone&hairsp;</emphasis>
or 
<emphasis remap='I'>&hairsp;AllocAll&hairsp;</emphasis>.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>colormap</emphasis></term>
  <listitem>
<para>Specifies the colormap that you want to create, copy, set, or destroy.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>display</emphasis></term>
  <listitem>
<para>Specifies the connection to the X server.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>visual</emphasis></term>
  <listitem>
<para>Specifies a visual type supported on the screen.
If the visual type is not one supported by the screen, 
a
<emphasis remap='I'>&hairsp;BadMatch&hairsp;</emphasis>
error results.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>w</emphasis></term>
  <listitem>
<para>Specifies the window on whose screen you want to create a colormap.</para>
  </listitem>
  </varlistentry>
</variablelist>
</refsect1>

<refsect1 id='description'><title>DESCRIPTION</title>
<para>The
<emphasis remap='I'>&hairsp;XCreateColormap&hairsp;</emphasis>
function creates a colormap of the specified visual type for the screen 
on which the specified window resides and returns the colormap ID 
associated with it.
Note that the specified window is only used to determine the screen.</para>

<para>The initial values of the colormap entries are undefined for the 
visual classes
<emphasis remap='I'>&hairsp;GrayScale&hairsp;</emphasis>,
<emphasis remap='I'>&hairsp;PseudoColor&hairsp;</emphasis>,
and
<emphasis remap='I'>&hairsp;DirectColor&hairsp;</emphasis>.
For
<emphasis remap='I'>&hairsp;StaticGray&hairsp;</emphasis>,
<emphasis remap='I'>&hairsp;StaticColor&hairsp;</emphasis>,
and
<emphasis remap='I'>&hairsp;TrueColor&hairsp;</emphasis>,
the entries have defined values,
but those values are specific to the visual and are not defined by X.
For
<emphasis remap='I'>&hairsp;StaticGray&hairsp;</emphasis>,
<emphasis remap='I'>&hairsp;StaticColor&hairsp;</emphasis>,
and
<emphasis remap='I'>&hairsp;TrueColor&hairsp;</emphasis>,
alloc must be
<emphasis remap='I'>&hairsp;AllocNone&hairsp;</emphasis>,
or a
<emphasis remap='I'>&hairsp;BadMatch&hairsp;</emphasis>
error results.
For the other visual classes,
if alloc is
<emphasis remap='I'>&hairsp;AllocNone&hairsp;</emphasis>,
the colormap initially has no allocated entries,
and clients can allocate them.
For information about the visual types,
see section 3.1.</para>

<para>If alloc is
<emphasis remap='I'>&hairsp;AllocAll&hairsp;</emphasis>,
the entire colormap is allocated writable.
The initial values of all allocated entries are undefined.
For
<emphasis remap='I'>&hairsp;GrayScale&hairsp;</emphasis>
and
<emphasis remap='I'>&hairsp;PseudoColor&hairsp;</emphasis>,
the effect is as if an
<emphasis remap='I'>&hairsp;XAllocColorCells&hairsp;</emphasis>
call returned all pixel values from zero to N - 1,
where N is the colormap entries value in the specified visual.
For
<emphasis remap='I'>&hairsp;DirectColor&hairsp;</emphasis>,
the effect is as if an
<emphasis remap='I'>&hairsp;XAllocColorPlanes&hairsp;</emphasis>
call returned a pixel value of zero and red_mask, green_mask, 
and blue_mask values containing the same bits as the corresponding
masks in the specified visual.
However, in all cases,
none of these entries can be freed by using
<emphasis remap='I'>&hairsp;XFreeColors&hairsp;</emphasis>.</para>

<para><emphasis remap='I'>&hairsp;XCreateColormap&hairsp;</emphasis>
can generate
<emphasis remap='I'>&hairsp;BadAlloc&hairsp;</emphasis>,
<emphasis remap='I'>&hairsp;BadMatch&hairsp;</emphasis>,
<emphasis remap='I'>&hairsp;BadValue&hairsp;</emphasis>,
and
<emphasis remap='I'>&hairsp;BadWindow&hairsp;</emphasis>
errors.</para>

<para>The
<emphasis remap='I'>&hairsp;XCopyColormapAndFree&hairsp;</emphasis>
function creates a colormap of the same visual type and for the same screen
as the specified colormap and returns the new colormap ID.
It also moves all of the client's existing allocation from the specified
colormap to the new colormap with their color values intact 
and their read-only or writable characteristics intact and frees those entries 
in the specified colormap.
Color values in other entries in the new colormap are undefined.
If the specified colormap was created by the client with alloc set to
<emphasis remap='I'>&hairsp;AllocAll&hairsp;</emphasis>,
the new colormap is also created with 
<emphasis remap='I'>&hairsp;AllocAll&hairsp;</emphasis>,
all color values for all entries are copied from the specified colormap,
and then all entries in the specified colormap are freed.
If the specified colormap was not created by the client with
<emphasis remap='I'>&hairsp;AllocAll&hairsp;</emphasis>,
the allocations to be moved are all those pixels and planes
that have been allocated by the client using
<emphasis remap='I'>&hairsp;XAllocColor&hairsp;</emphasis>,
<emphasis remap='I'>&hairsp;XAllocNamedColor&hairsp;</emphasis>,
<emphasis remap='I'>&hairsp;XAllocColorCells&hairsp;</emphasis>,
or
<emphasis remap='I'>&hairsp;XAllocColorPlanes&hairsp;</emphasis>
and that have not been freed since they were allocated.</para>

<para><emphasis remap='I'>&hairsp;XCopyColormapAndFree&hairsp;</emphasis>
can generate
<emphasis remap='I'>&hairsp;BadAlloc&hairsp;</emphasis>
and
<emphasis remap='I'>&hairsp;BadColor&hairsp;</emphasis>
errors.</para>

<para>The
<emphasis remap='I'>&hairsp;XFreeColormap&hairsp;</emphasis>
function deletes the association between the colormap resource ID 
and the colormap and frees the colormap storage.
However, this function has no effect on the default colormap for a screen.
If the specified colormap is an installed map for a screen,
it is uninstalled (see
<emphasis remap='I'>&hairsp;XUninstallColormap&hairsp;</emphasis>).
If the specified colormap is defined as the colormap for a window (by
<emphasis remap='I'>&hairsp;XCreateWindow&hairsp;</emphasis>,
<emphasis remap='I'>&hairsp;XSetWindowColormap&hairsp;</emphasis>,
or
<emphasis remap='I'>&hairsp;XChangeWindowAttributes&hairsp;</emphasis>),
<emphasis remap='I'>&hairsp;XFreeColormap&hairsp;</emphasis>
changes the colormap associated with the window to
<emphasis remap='I'>&hairsp;None&hairsp;</emphasis>
and generates a
<emphasis remap='I'>&hairsp;ColormapNotify&hairsp;</emphasis>
event.
X does not define the colors displayed for a window with a colormap of
<emphasis remap='I'>&hairsp;None&hairsp;</emphasis>.</para>

<para><emphasis remap='I'>&hairsp;XFreeColormap&hairsp;</emphasis>
can generate a
<emphasis remap='I'>&hairsp;BadColor&hairsp;</emphasis>
error.</para>
</refsect1>

<refsect1 id='structures'><title>STRUCTURES</title>
<para>The
<emphasis remap='I'>&hairsp;XColor&hairsp;</emphasis>
structure contains:</para>

<literallayout remap='.nf'>
<!-- .0D  0 -->

<!-- .ps \n(PS -->
<!-- .if \n(VS&gt;=40 .vs \n(VSu -->
<!-- .if \n(VS&lt;=39 .vs \n(VSp -->
<!-- .TA .5i 2.5i -->
<!-- .ta .5i 2.5i -->
typedef struct {
	unsigned long pixel;	/&lowast; pixel value */
	unsigned short red, green, blue;	/&lowast; rgb values */
	char flags;	/&lowast; DoRed, DoGreen, DoBlue */	
	char pad;
} XColor;
<!-- .ce 0  IGNORED -->
<!-- .in \n(OIu  IGNORED -->

</literallayout> <!-- .fi -->

<para>The red, green, and blue values are always in the range 0 to 65535
inclusive, independent of the number of bits actually used in the
display hardware.
The server scales these values down to the range used by the hardware.
Black is represented by (0,0,0), 
and white is represented by (65535,65535,65535).
In some functions,
the flags member controls which of the red, green, and blue members is used 
and can be the inclusive OR of zero or more of
<emphasis remap='I'>&hairsp;DoRed&hairsp;</emphasis>,
<emphasis remap='I'>&hairsp;DoGreen&hairsp;</emphasis>,
and 
<emphasis remap='I'>&hairsp;DoBlue&hairsp;</emphasis>.</para>
</refsect1>

<refsect1 id='diagnostics'><title>DIAGNOSTICS</title>
<variablelist remap='TP'>
  <varlistentry>
  <term><emphasis remap='I'>&hairsp;BadAlloc&hairsp;</emphasis></term>
  <listitem>
<para>The server failed to allocate the requested resource or server memory.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>&hairsp;BadColor&hairsp;</emphasis></term>
  <listitem>
<para>A value for a Colormap argument does not name a defined Colormap.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>&hairsp;BadMatch&hairsp;</emphasis></term>
  <listitem>
<para>An
<emphasis remap='I'>&hairsp;InputOnly&hairsp;</emphasis>
window is used as a Drawable.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>&hairsp;BadMatch&hairsp;</emphasis></term>
  <listitem>
<para>Some argument or pair of arguments has the correct type and range but fails
to match in some other way required by the request.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>&hairsp;BadValue&hairsp;</emphasis></term>
  <listitem>
<para>Some numeric value falls outside the range of values accepted by the request.
Unless a specific range is specified for an argument, the full range defined
by the argument's type is accepted.  Any argument defined as a set of
alternatives can generate this error.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>&hairsp;BadWindow&hairsp;</emphasis></term>
  <listitem>
<para>A value for a Window argument does not name a defined Window.</para>
  </listitem>
  </varlistentry>
</variablelist>
</refsect1>

<refsect1 id='see_also'><title>SEE ALSO</title>
<para>XAllocColor(3X11),
XChangeWindowAttributes(3X11),
XCreateWindow(3X11),
XQueryColor(3X11),
XStoreColors(3X11)
<!-- .br -->
<userinput>Xlib - C Language X Interface</userinput></para>
</refsect1>
</refentry>

