<?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='xallcolorman'>
<!-- '\" e -->
<!--  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/XAllColor.man,v 1.4 2003/04/28 22:17:54 herrb Exp $ -->

<!-- .na -->
<!-- Ds listing suppressed (not used) -->
<!-- De listing suppressed (not used) -->
<!-- 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 -->
<!-- '\" e -->
<refmeta>
<refentrytitle>XAllocColor</refentrytitle>
<manvolnum>3X11</manvolnum>
<refmiscinfo class='date'>__xorgversion__</refmiscinfo>
<refmiscinfo class='source'>XLIB FUNCTIONS</refmiscinfo>
</refmeta>
<refnamediv id='name'>
<refname>XAllocColor</refname>
<refname>XAllocNamedColor</refname>
<refname>XAllocColorCells</refname>
<refname>XAllocColorPlanes</refname>
<refname>XFreeColors</refname>
<refpurpose>allocate and free colors</refpurpose>
</refnamediv>
<!-- body begins here -->

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

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

<para>Status XAllocNamedColor&hairsp;(&hairsp;Display *<emphasis remap='I'>display</emphasis>, Colormap <emphasis remap='I'>colormap</emphasis>&hairsp;,
char *<emphasis remap='I'>color_name</emphasis>&hairsp;, XColor *<emphasis remap='I'>screen_def_return</emphasis>&hairsp;, XColor
*<emphasis remap='I'>exact_def_return</emphasis>&hairsp;);</para>

<para>Status XAllocColorCells&hairsp;(&hairsp;Display *<emphasis remap='I'>display</emphasis>, Colormap <emphasis remap='I'>colormap</emphasis>&hairsp;,
Bool <emphasis remap='I'>contig</emphasis>&hairsp;, unsigned long<emphasis remap='I'>plane_masks_return</emphasis>[&hairsp;]&hairsp;, unsigned int
<emphasis remap='I'>nplanes</emphasis>&hairsp;, unsigned long <emphasis remap='I'>pixels_return</emphasis>[&hairsp;]&hairsp;, unsigned int
<emphasis remap='I'>npixels</emphasis>&hairsp;);</para>

<para>Status XAllocColorPlanes&hairsp;(&hairsp;Display *<emphasis remap='I'>display</emphasis>, Colormap
<emphasis remap='I'>colormap</emphasis>&hairsp;, Bool <emphasis remap='I'>contig</emphasis>&hairsp;, unsigned long
<emphasis remap='I'>pixels_return</emphasis>[&hairsp;]&hairsp;, int <emphasis remap='I'>ncolors</emphasis>&hairsp;, int <emphasis remap='I'>nreds</emphasis>&hairsp;, int
<emphasis remap='I'>ngreens</emphasis>&hairsp;, int <emphasis remap='I'>nblues</emphasis>&hairsp;, unsigned long *<emphasis remap='I'>rmask_return</emphasis>&hairsp;,
unsigned long *<emphasis remap='I'>gmask_return</emphasis>&hairsp;, unsigned long *<emphasis remap='I'>bmask_return</emphasis>&hairsp;);</para>

<para>int XFreeColors&hairsp;(&hairsp;Display *<emphasis remap='I'>display</emphasis>, Colormap <emphasis remap='I'>colormap</emphasis>&hairsp;, unsigned
long <emphasis remap='I'>pixels</emphasis>&hairsp;[&hairsp;], int <emphasis remap='I'>npixels</emphasis>&hairsp;, unsigned long <emphasis remap='I'>planes</emphasis>&hairsp;);</para>
<variablelist remap='IP'>
  <varlistentry>
  <term><emphasis remap='I'>color_name</emphasis></term>
  <listitem>
<para>Specifies the color name string (for example, red) whose color 
definition structure you want returned.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>colormap</emphasis></term>
  <listitem>
<para>Specifies the colormap.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>contig</emphasis></term>
  <listitem>
<para>Specifies a Boolean value that indicates whether the planes must be contiguous.</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'>exact_def_return</emphasis></term>
  <listitem>
<para>Returns the exact RGB values.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>ncolors</emphasis></term>
  <listitem>
<para>Specifies the number of pixel values that are to be returned in the 
pixels_return array.</para> 
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>npixels</emphasis></term>
  <listitem>
<para>Specifies the number of pixels.</para> 
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>nplanes</emphasis></term>
  <listitem>
<para>Specifies the number of plane masks that are to be returned in the plane masks 
array.</para> 
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>nreds</emphasis></term>
<!-- .br -->
<!-- .ns -->
  <term><emphasis remap='I'>ngreens</emphasis></term>
<!-- .br -->
<!-- .ns -->
  <term><emphasis remap='I'>nblues</emphasis></term>
  <listitem>
<!-- .br -->
<!-- .ns -->
<para>Specify the number of red, green, and blue planes.
The value you pass must be nonnegative.</para> 
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>pixels</emphasis></term>
  <listitem>
<para>Specifies an array of pixel values.</para> 
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>pixels_return</emphasis></term>
  <listitem>
<para>Returns an array of pixel values.</para> 
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>plane_mask_return</emphasis></term>
  <listitem>
<para>Returns an array of plane masks.</para>
<!--  *** JIM: NEED MORE INFO FOR THIS. *** -->
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>planes</emphasis></term>
  <listitem>
<para>Specifies the planes you want to free.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>rmask_return</emphasis></term>
<!-- .br -->
<!-- .ns -->
  <term><emphasis remap='I'>gmask_return</emphasis></term>
<!-- .br -->
<!-- .ns -->
  <term><emphasis remap='I'>bmask_return</emphasis></term>
  <listitem>
<para>Return bit masks for the red, green, and blue planes.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>screen_def_return</emphasis></term>
  <listitem>
<para>Returns the closest RGB values provided by the hardware.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>screen_in_out</emphasis></term>
  <listitem>
<para>Specifies and returns the values actually used in the colormap.</para>
  </listitem>
  </varlistentry>
</variablelist>
</refsect1>

<refsect1 id='description'><title>DESCRIPTION</title>
<para>The
<emphasis remap='I'>&hairsp;XAllocColor&hairsp;</emphasis>
function allocates a read-only colormap entry corresponding to the closest
RGB value supported by the hardware.
<emphasis remap='I'>&hairsp;XAllocColor&hairsp;</emphasis>
returns the pixel value of the color closest to the specified
RGB elements supported by the hardware
and returns the RGB value actually used.
The corresponding colormap cell is read-only.
In addition,
<emphasis remap='I'>&hairsp;XAllocColor&hairsp;</emphasis>
returns nonzero if it succeeded or zero if it failed.
Multiple clients that request the same effective RGB value can be assigned
the same read-only entry, thus allowing entries to be shared.
When the last client deallocates a shared cell, it is deallocated.
<emphasis remap='I'>&hairsp;XAllocColor&hairsp;</emphasis>
does not use or affect the flags in the
<emphasis remap='I'>&hairsp;XColor&hairsp;</emphasis>
structure.</para>

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

<para>The
<emphasis remap='I'>&hairsp;XAllocNamedColor&hairsp;</emphasis>
function looks up the named color with respect to the screen that is
associated with the specified colormap.
It returns both the exact database definition and
the closest color supported by the screen.
The allocated color cell is read-only.
The pixel value is returned in screen_def_return.
If the color name is not in the Host Portable Character Encoding, 
the result is implementation-dependent.
Use of uppercase or lowercase does not matter.
If screen_def_return and exact_def_return
point to the same structure, the pixel field will be set correctly,
but the color values are undefined.
<emphasis remap='I'>&hairsp;XAllocNamedColor&hairsp;</emphasis>
returns nonzero if a cell is allocated;
otherwise, it returns zero.</para>

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


<!-- eqn delimiters set to %% -->

<para>The
<emphasis remap='I'>&hairsp;XAllocColorCells&hairsp;</emphasis>
function allocates read/write color cells.
The number of colors must be positive and the number of planes nonnegative,
or a
<emphasis remap='I'>&hairsp;BadValue&hairsp;</emphasis>
error results.
If ncolors and nplanes are requested, 
then ncolors pixels
and nplane plane masks are returned.
No mask will have any bits set to 1 in common with
any other mask or with any of the pixels.
By ORing together each pixel with zero or more masks,
ncolors * <?start-eqn?>2 sup nplanes<?end-eqn?> distinct pixels can be produced.
All of these are
allocated writable by the request.
For 
<emphasis remap='I'>&hairsp;GrayScale&hairsp;</emphasis>
or 
<emphasis remap='I'>&hairsp;PseudoColor&hairsp;</emphasis>,
each mask has exactly one bit set to 1. 
For 
<emphasis remap='I'>&hairsp;DirectColor&hairsp;</emphasis>,
each has exactly three bits set to 1.
If contig is 
<emphasis remap='I'>&hairsp;True&hairsp;</emphasis>
and if all masks are ORed
together, a single contiguous set of bits set to 1 will be formed for 
<emphasis remap='I'>&hairsp;GrayScale&hairsp;</emphasis>
or 
<emphasis remap='I'>&hairsp;PseudoColor&hairsp;</emphasis>
and three contiguous sets of bits set to 1 (one within each
pixel subfield) for 
<emphasis remap='I'>&hairsp;DirectColor&hairsp;</emphasis>.
The RGB values of the allocated
entries are undefined.
<emphasis remap='I'>&hairsp;XAllocColorCells&hairsp;</emphasis>
returns nonzero if it succeeded or zero if it failed.</para>

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


<!-- eqn delimiters set to %% -->

<para>The specified ncolors must be positive; 
and nreds, ngreens, and nblues must be nonnegative,
or a
<emphasis remap='I'>&hairsp;BadValue&hairsp;</emphasis>
error results.
If ncolors colors, nreds reds, ngreens greens, and nblues blues are requested, 
ncolors pixels are returned; and the masks have nreds, ngreens, and 
nblues bits set to 1, respectively.
If contig is 
<emphasis remap='I'>&hairsp;True&hairsp;</emphasis>,
each mask will have
a contiguous set of bits set to 1.
No mask will have any bits set to 1 in common with
any other mask or with any of the pixels.
For 
<emphasis remap='I'>&hairsp;DirectColor&hairsp;</emphasis>,
each mask
will lie within the corresponding pixel subfield.
By ORing together
subsets of masks with each pixel value, 
ncolors * <?start-eqn?>2 sup (nreds+ngreens+nblues)<?end-eqn?> distinct pixel values can be produced. 
All of these are allocated by the request.
However, in the
colormap, there are only ncolors * <?start-eqn?>2 sup nreds<?end-eqn?> independent red entries, 
ncolors * <?start-eqn?>2 sup ngreens<?end-eqn?> independent green entries, 
and ncolors * <?start-eqn?>2 sup nblues<?end-eqn?> independent blue entries. 
This is true even for 
<emphasis remap='I'>&hairsp;PseudoColor&hairsp;</emphasis>.
When the colormap entry of a pixel
value is changed (using 
<emphasis remap='I'>&hairsp;XStoreColors&hairsp;</emphasis>,
<emphasis remap='I'>&hairsp;XStoreColor&hairsp;</emphasis>,
or 
<emphasis remap='I'>&hairsp;XStoreNamedColor&hairsp;</emphasis>),
the pixel is decomposed according to the masks, 
and the corresponding independent entries are updated.
<emphasis remap='I'>&hairsp;XAllocColorPlanes&hairsp;</emphasis>
returns nonzero if it succeeded or zero if it failed.</para>

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

<para>The
<emphasis remap='I'>&hairsp;XFreeColors&hairsp;</emphasis>
function frees the cells represented by pixels whose values are in the
pixels array.
The planes argument should not have any bits set to 1 in common with any of the
pixels. 
The set of all pixels is produced by ORing together subsets of
the planes argument with the pixels.
The request frees all of these pixels that
were 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>,
and 
<emphasis remap='I'>&hairsp;XAllocColorPlanes&hairsp;</emphasis>).
Note that freeing an
individual pixel obtained from 
<emphasis remap='I'>&hairsp;XAllocColorPlanes&hairsp;</emphasis>
may not actually allow
it to be reused until all of its related pixels are also freed.
Similarly,
a read-only entry is not actually freed until it has been freed by all clients,
and if a client allocates the same read-only entry multiple times,
it must free the entry that many times before the entry is actually freed.</para>

<para>All specified pixels that are allocated by the client in the colormap are
freed, even if one or more pixels produce an error. 
If a specified pixel is not a valid index into the colormap, a 
<emphasis remap='I'>&hairsp;BadValue&hairsp;</emphasis>
error results.
If a specified pixel is not allocated by the
client (that is, is unallocated or is only allocated by another client)
or if the colormap was created with all entries writable (by passing
<emphasis remap='I'>&hairsp;AllocAll&hairsp;</emphasis>
to
<emphasis remap='I'>&hairsp;XCreateColormap&hairsp;</emphasis>),
a
<emphasis remap='I'>&hairsp;BadAccess&hairsp;</emphasis>
error results. 
If more than one pixel is in error, 
the one that gets reported is arbitrary.</para>

<para><emphasis remap='I'>&hairsp;XFreeColors&hairsp;</emphasis>
can generate
<emphasis remap='I'>&hairsp;BadAccess&hairsp;</emphasis>,
<emphasis remap='I'>&hairsp;BadColor&hairsp;</emphasis>,
and
<emphasis remap='I'>&hairsp;BadValue&hairsp;</emphasis>
errors.</para>
</refsect1>

<refsect1 id='diagnostics'><title>DIAGNOSTICS</title>
<variablelist remap='TP'>
  <varlistentry>
  <term><emphasis remap='I'>&hairsp;BadAccess&hairsp;</emphasis></term>
  <listitem>
<para>A client attempted
to free a color map entry that it did not already allocate.</para>
  </listitem>
  </varlistentry>
  <varlistentry>
  <term><emphasis remap='I'>&hairsp;BadAccess&hairsp;</emphasis></term>
  <listitem>
<para>A client attempted
to store into a read-only color map entry.</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;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>
</variablelist>
</refsect1>

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

