1. NAME▲
XAllocColor, XAllocNamedColor, XAllocColorCells, XAllocColorPlanes, XFreeColors - allocate and free colors
2. SYNTAX ▲
Status XAllocColor(Display *display, Colormap colormap, XColor *screen_in_out); Status XAllocNamedColor(Display *display, Colormap colormap, char *color_name, XColor *screen_def_return, XColor *exact_def_return); Status XAllocColorCells(Display *display, Colormap colormap, Bool contig, unsigned long plane_masks_return[], unsigned int nplanes, unsigned long pixels_return[], unsigned int npixels); Status XAllocColorPlanes(Display *display, Colormap colormap, Bool contig, unsigned long pixels_return[], int ncolors, int nreds, int ngreens, int nblues, unsigned long *rmask_return, unsigned long *gmask_return, unsigned long *bmask_return); int XFreeColors(Display *display, Colormap colormap, unsigned long pixels[], int npixels, unsigned long planes);
color_name 1i Specifies the color name string (for example, red) whose color definition structure you want returned.
colormap 1i Specifies the colormap.
contig 1i Specifies a Boolean value that indicates whether the planes must be contiguous.
display 1i Specifies the connection to the X server.
exact_def_return 1i Returns the exact RGB values.
ncolors 1i Specifies the number of pixel values that are to be returned in the pixels_return array.
npixels 1i Specifies the number of pixels.
nplanes 1i Specifies the number of plane masks that are to be returned in the plane masks array.
nreds 1i
ngreens 1i
nblues 1i
Specify the number of red, green, and blue planes. The value you pass must be nonnegative.
pixels 1i Specifies an array of pixel values.
pixels_return 1i Returns an array of pixel values.
plane_mask_return 1i Returns an array of plane masks.
planes 1i Specifies the planes you want to free.
rmask_return 1i
gmask_return 1i
bmask_return 1i Return bit masks for the red, green, and blue planes.
screen_def_return 1i Returns the closest RGB values provided by the hardware.
screen_in_out 1i Specifies and returns the values actually used in the colormap.
3. DESCRIPTION ▲
The .ZN XAllocColor function allocates a read-only colormap entry corresponding to the closest RGB value supported by the hardware. .ZN XAllocColor 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, .ZN XAllocColor 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. .ZN XAllocColor does not use or affect the flags in the .ZN XColor structure.
.ZN XAllocColor can generate a .ZN BadColor error.
The .ZN XAllocNamedColor 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. .ZN XAllocNamedColor returns nonzero if a cell is allocated; otherwise, it returns zero.
.ZN XAllocNamedColor can generate a .ZN BadColor error.
delim %%
The .ZN XAllocColorCells function allocates read/write color cells. The number of colors must be positive and the number of planes nonnegative, or a .ZN BadValue 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 * %2 sup nplanes% distinct pixels can be produced. All of these are allocated writable by the request. For .ZN GrayScale or .ZN PseudoColor , each mask has exactly one bit set to 1. For .ZN DirectColor , each has exactly three bits set to 1. If contig is .ZN True and if all masks are ORed together, a single contiguous set of bits set to 1 will be formed for .ZN GrayScale or .ZN PseudoColor and three contiguous sets of bits set to 1 (one within each pixel subfield) for .ZN DirectColor . The RGB values of the allocated entries are undefined. .ZN XAllocColorCells returns nonzero if it succeeded or zero if it failed.
.ZN XAllocColorCells can generate .ZN BadColor and .ZN BadValue errors.
delim %%
The specified ncolors must be positive; and nreds, ngreens, and nblues must be nonnegative, or a .ZN BadValue 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 .ZN True , 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 .ZN DirectColor , each mask will lie within the corresponding pixel subfield. By ORing together subsets of masks with each pixel value, ncolors * %2 sup (nreds+ngreens+nblues)% distinct pixel values can be produced. All of these are allocated by the request. However, in the colormap, there are only ncolors * %2 sup nreds% independent red entries, ncolors * %2 sup ngreens% independent green entries, and ncolors * %2 sup nblues% independent blue entries. This is true even for .ZN PseudoColor . When the colormap entry of a pixel value is changed (using .ZN XStoreColors , .ZN XStoreColor , or .ZN XStoreNamedColor ), the pixel is decomposed according to the masks, and the corresponding independent entries are updated. .ZN XAllocColorPlanes returns nonzero if it succeeded or zero if it failed.
.ZN XAllocColorPlanes can generate .ZN BadColor and .ZN BadValue errors.
The .ZN XFreeColors 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 .ZN XAllocColor , .ZN XAllocNamedColor , .ZN XAllocColorCells , and .ZN XAllocColorPlanes ). Note that freeing an individual pixel obtained from .ZN XAllocColorPlanes 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.
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 .ZN BadValue 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 .ZN AllocAll to .ZN XCreateColormap ), a .ZN BadAccess error results. If more than one pixel is in error, the one that gets reported is arbitrary.
.ZN XFreeColors can generate .ZN BadAccess , .ZN BadColor , and .ZN BadValue errors.
4. DIAGNOSTICS ▲
- .ZN BadAccess
A client attempted to free a color map entry that it did not already allocate. - .ZN BadAccess
A client attempted to store into a read-only color map entry. - .ZN BadColor
A value for a Colormap argument does not name a defined Colormap. - .ZN BadValue
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.
5. SEE ALSO ▲
XCreateColormap(3), XQueryColor(3), XStoreColors(3)
\*(xL