xwindow.c revision e42f658533644aecb733785ffd91b286d6778dea
13ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
23ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
43ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
63ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%              X   X  W   W  IIIII  N   N  DDDD    OOO   W   W                %
73ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%               X X   W   W    I    NN  N  D   D  O   O  W   W                %
83ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                X    W   W    I    N N N  D   D  O   O  W   W                %
93ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%               X X   W W W    I    N  NN  D   D  O   O  W W W                %
103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%              X   X   W W   IIIII  N   N  DDDD    OOO    W W                 %
113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                       MagickCore X11 Utility Methods                        %
143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                               Software Design                               %
163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                 John Cristy                                 %
173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                  July 1992                                  %
183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
201454be7db7a897f42cd40e4165f945d77196a6f8cristy%  Copyright 1999-2012 ImageMagick Studio LLC, a non-profit organization      %
213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  dedicated to making software imaging solutions freely available.           %
223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  You may not use this file except in compliance with the License.  You may  %
243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  obtain a copy of the License at                                            %
253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    http://www.imagemagick.org/script/license.php                            %
273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  Unless required by applicable law or agreed to in writing, software        %
293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  distributed under the License is distributed on an "AS IS" BASIS,          %
303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  See the License for the specific language governing permissions and        %
323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  limitations under the License.                                             %
333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Include declarations.
413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
424c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/studio.h"
434c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/animate.h"
444c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/artifact.h"
454c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/blob.h"
464c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/cache.h"
474c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/client.h"
484c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/color.h"
494c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/color-private.h"
504c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/colormap.h"
514c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/composite.h"
52030436f8fc9854b6bb39f4d7593d9e70ff83a8cacristy#include "MagickCore/constitute.h"
534c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/display.h"
54c53413df5789700e14e1a67e6cc2716d1716a387cristy#include "MagickCore/distort.h"
554c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/exception.h"
564c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/exception-private.h"
574c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/geometry.h"
584c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/identify.h"
594c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/image.h"
604c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/image-private.h"
614c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/list.h"
624c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/locale_.h"
634c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/log.h"
644c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/magick.h"
654c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/memory_.h"
664c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/monitor.h"
670740a98dde93dcb39f6d74288c4c64b2eb036df1cristy#include "MagickCore/nt-base-private.h"
684c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/option.h"
694c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/pixel-accessor.h"
704c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/PreRvIcccm.h"
714c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/quantize.h"
724c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/quantum.h"
734c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/quantum-private.h"
744c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/resource_.h"
754c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/resize.h"
764c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/statistic.h"
774c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/string_.h"
784c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/string-private.h"
794c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/transform.h"
804c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/utility.h"
81d1dd6e4fefa0810b9893e6ac9418f79c97c1b39acristy#include "MagickCore/utility-private.h"
824c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/widget.h"
83bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristy#include "MagickCore/widget-private.h"
844c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/xwindow.h"
854c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/xwindow-private.h"
864c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/version.h"
873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__BEOS__)
883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <OS.h>
893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_X11_DELEGATE)
913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <X11/Xproto.h>
923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <X11/Xlocale.h>
933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICK_HAVE_POLL)
943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy# include <sys/poll.h>
953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_MACHINE_PARAM_H)
983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy# include <machine/param.h>
993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
1003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <sys/ipc.h>
1013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <sys/shm.h>
1023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <X11/extensions/XShm.h>
1033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
1043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHAPE)
1053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <X11/extensions/shape.h>
1063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
1073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
1093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  X defines.
1103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
111ce70c17bb6433add2eb069515a4f3105989e0662cristy#define XBlueGamma(color) ClampToQuantum(blue_gamma == 1.0 ? (double) \
1123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) blue_gamma)* \
1133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  QuantumRange)))
1144c08aed51c5899665ade97263692328eea4af106cristy#define XGammaPacket(map,color)  (size_t) (map->base_pixel+ \
1157e9f233e6549b1e1856c1aa85b3f4dee8e9493facristy  ((ScaleQuantumToShort(XRedGamma((color)->red))*map->red_max/65535L)* \
1167e9f233e6549b1e1856c1aa85b3f4dee8e9493facristy    map->red_mult)+ \
1177e9f233e6549b1e1856c1aa85b3f4dee8e9493facristy  ((ScaleQuantumToShort(XGreenGamma((color)->green))*map->green_max/65535L)* \
1187e9f233e6549b1e1856c1aa85b3f4dee8e9493facristy    map->green_mult)+ \
1197e9f233e6549b1e1856c1aa85b3f4dee8e9493facristy  ((ScaleQuantumToShort(XBlueGamma((color)->blue))*map->blue_max/65535L)* \
1207e9f233e6549b1e1856c1aa85b3f4dee8e9493facristy    map->blue_mult))
1214c08aed51c5899665ade97263692328eea4af106cristy#define XGammaPixel(image,map,color)  (size_t) (map->base_pixel+ \
1224c08aed51c5899665ade97263692328eea4af106cristy  ((ScaleQuantumToShort(XRedGamma(GetPixelRed(image,color)))*map->red_max/65535L)* \
1234c08aed51c5899665ade97263692328eea4af106cristy    map->red_mult)+ \
1244c08aed51c5899665ade97263692328eea4af106cristy  ((ScaleQuantumToShort(XGreenGamma(GetPixelGreen(image,color)))*map->green_max/65535L)* \
1254c08aed51c5899665ade97263692328eea4af106cristy    map->green_mult)+ \
1264c08aed51c5899665ade97263692328eea4af106cristy  ((ScaleQuantumToShort(XBlueGamma(GetPixelBlue(image,color)))*map->blue_max/65535L)* \
1274c08aed51c5899665ade97263692328eea4af106cristy    map->blue_mult))
128ce70c17bb6433add2eb069515a4f3105989e0662cristy#define XGreenGamma(color) ClampToQuantum(green_gamma == 1.0 ? (double) \
1293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) green_gamma)* \
1303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  QuantumRange)))
131ce70c17bb6433add2eb069515a4f3105989e0662cristy#define XRedGamma(color) ClampToQuantum(red_gamma == 1.0 ? (double) \
1323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) red_gamma)* \
1333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  QuantumRange)))
134bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy#define XStandardPixel(map,color)  (size_t) (map->base_pixel+ \
1357e9f233e6549b1e1856c1aa85b3f4dee8e9493facristy  (((color)->red*map->red_max/65535L)*map->red_mult)+ \
1367e9f233e6549b1e1856c1aa85b3f4dee8e9493facristy  (((color)->green*map->green_max/65535L)*map->green_mult)+ \
1377e9f233e6549b1e1856c1aa85b3f4dee8e9493facristy  (((color)->blue*map->blue_max/65535L)*map->blue_mult))
1383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define AccentuateModulate  ScaleCharToQuantum(80)
1403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define HighlightModulate  ScaleCharToQuantum(125)
1413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define ShadowModulate  ScaleCharToQuantum(135)
1423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define DepthModulate  ScaleCharToQuantum(185)
1433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define TroughModulate  ScaleCharToQuantum(110)
1443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define XLIB_ILLEGAL_ACCESS  1
1463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef ForgetGravity
1473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef NorthWestGravity
1483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef NorthGravity
1493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef NorthEastGravity
1503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef WestGravity
1513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef CenterGravity
1523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef EastGravity
1533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef SouthWestGravity
1543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef SouthGravity
1553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef SouthEastGravity
1563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef StaticGravity
1573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef index
1593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(hpux9)
1603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define XFD_SET  int
1613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else
1623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define XFD_SET  fd_set
1633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
1643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
1663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Enumeration declarations.
1673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1683ed852eea50f9d4cd633efb8c2b054b8e33c253cristytypedef enum
1693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
1703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef DoRed
1713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DoRed = 0x0001,
1723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef DoGreen
1733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DoGreen = 0x0002,
1743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef DoBlue
1753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DoBlue = 0x0004,
1763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DoMatte = 0x0008
1773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} XColorFlags;
1783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
1803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Typedef declarations.
1813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1823ed852eea50f9d4cd633efb8c2b054b8e33c253cristytypedef struct _DiversityPacket
1833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
1843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Quantum
1853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    red,
1863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    green,
1873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    blue;
1883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned short
1903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    index;
1913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
192bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  size_t
1933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    count;
1943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} DiversityPacket;
1953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
1973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Constant declaractions.
1983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1993ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType
2003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  xerror_alert = MagickFalse;
2013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
2033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Method prototypes.
2043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
2053ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic const char
2063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  *XVisualClassName(const int);
2073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2083ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickRealType
2093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  blue_gamma = 1.0,
2103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  green_gamma = 1.0,
2113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  red_gamma = 1.0;
2123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2133ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType
2143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XMakePixmap(Display *,const XResourceInfo *,XWindowInfo *);
2153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2163ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void
2173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XMakeImageLSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
218e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy    XImage *,XImage *,ExceptionInfo *),
2193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XMakeImageMSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
220e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy    XImage *,XImage *,ExceptionInfo *);
2213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2223ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Window
2233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XSelectWindow(Display *,RectangleInfo *);
2243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
2263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   D e s t r o y X R e s o u r c e s                                         %
2313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  DestroyXResources() destroys any X resources.
2373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the DestroyXResources method is:
2393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void DestroyXResources()
2413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
2433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
2453ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport void DestroyXResources(void)
2463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
2473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
2483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
2493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
2513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_windows;
2523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XWindowInfo
2543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *magick_windows[MaxXWindows];
2553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XWindows
2573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *windows;
2583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DestroyXWidget();
2603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows=XSetWindows((XWindows *) ~0);
2613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((windows == (XWindows *) NULL) || (windows->display == (Display *) NULL))
2623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
2633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  number_windows=0;
2643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->context);
2653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->group_leader);
2663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->backdrop);
2673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->icon);
2683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->image);
2693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->info);
2703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->magnify);
2713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->pan);
2723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->command);
2733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->widget);
2743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->popup);
2753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->context);
2763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; i < (int) number_windows; i++)
2773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
2783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->mapped != MagickFalse)
2793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
2803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XWithdrawWindow(windows->display,magick_windows[i]->id,
2813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          magick_windows[i]->screen);
2823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        magick_windows[i]->mapped=MagickFalse;
2833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
2843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->name != (char *) NULL)
2853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      magick_windows[i]->name=(char *)
2863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        RelinquishMagickMemory(magick_windows[i]->name);
2873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->icon_name != (char *) NULL)
2883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      magick_windows[i]->icon_name=(char *)
2893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        RelinquishMagickMemory(magick_windows[i]->icon_name);
2903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->cursor != (Cursor) NULL)
2913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
2923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreeCursor(windows->display,magick_windows[i]->cursor);
2933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        magick_windows[i]->cursor=(Cursor) NULL;
2943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
2953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->busy_cursor != (Cursor) NULL)
2963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
2973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreeCursor(windows->display,magick_windows[i]->busy_cursor);
2983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        magick_windows[i]->busy_cursor=(Cursor) NULL;
2993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->highlight_stipple != (Pixmap) NULL)
3013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreePixmap(windows->display,
3033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          magick_windows[i]->highlight_stipple);
3043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        magick_windows[i]->highlight_stipple=(Pixmap) NULL;
3053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->shadow_stipple != (Pixmap) NULL)
3073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreePixmap(windows->display,magick_windows[i]->shadow_stipple);
3093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        magick_windows[i]->shadow_stipple=(Pixmap) NULL;
3103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->ximage != (XImage *) NULL)
3123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XDestroyImage(magick_windows[i]->ximage);
3143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        magick_windows[i]->ximage=(XImage *) NULL;
3153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->pixmap != (Pixmap) NULL)
3173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreePixmap(windows->display,magick_windows[i]->pixmap);
3193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        magick_windows[i]->pixmap=(Pixmap) NULL;
3203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->id != (Window) NULL)
3223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XDestroyWindow(windows->display,magick_windows[i]->id);
3243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        magick_windows[i]->id=(Window) NULL;
3253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->destroy != MagickFalse)
3273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (magick_windows[i]->image != (Image *) NULL)
3293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
3303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            magick_windows[i]->image=DestroyImage(magick_windows[i]->image);
3313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            magick_windows[i]->image=NewImageList();
3323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
3333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (magick_windows[i]->matte_pixmap != (Pixmap) NULL)
3343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
3353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) XFreePixmap(windows->display,
3363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              magick_windows[i]->matte_pixmap);
3373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            magick_windows[i]->matte_pixmap=(Pixmap) NULL;
3383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
3393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->segment_info != (void *) NULL)
3413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
3433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XShmSegmentInfo
3443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          *segment_info;
3453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
3463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        segment_info=(XShmSegmentInfo *) magick_windows[i]->segment_info;
3473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (segment_info != (XShmSegmentInfo *) NULL)
3483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (segment_info[0].shmid >= 0)
3493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
3503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (segment_info[0].shmaddr != NULL)
3513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (void) shmdt(segment_info[0].shmaddr);
3523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
3533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              segment_info[0].shmaddr=NULL;
3543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              segment_info[0].shmid=(-1);
3553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
3563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
3573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        magick_windows[i]->segment_info=(void *)
3583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          RelinquishMagickMemory(magick_windows[i]->segment_info);
3593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
3613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->icon_resources=(XResourceInfo *)
3623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    RelinquishMagickMemory(windows->icon_resources);
3633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->icon_pixel != (XPixelInfo *) NULL)
3643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
365f2faecf9facdbbb14fcba373365f9f691a9658e0cristy      if (windows->icon_pixel->pixels != (unsigned long *) NULL)
366f2faecf9facdbbb14fcba373365f9f691a9658e0cristy        windows->icon_pixel->pixels=(unsigned long *)
3673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          RelinquishMagickMemory(windows->icon_pixel->pixels);
3683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (windows->icon_pixel->annotate_context != (GC) NULL)
3693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XFreeGC(windows->display,windows->icon_pixel->annotate_context);
3703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->icon_pixel=(XPixelInfo *)
3713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        RelinquishMagickMemory(windows->icon_pixel);
3723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
3733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->pixel_info != (XPixelInfo *) NULL)
3743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
375f2faecf9facdbbb14fcba373365f9f691a9658e0cristy      if (windows->pixel_info->pixels != (unsigned long *) NULL)
376f2faecf9facdbbb14fcba373365f9f691a9658e0cristy        windows->pixel_info->pixels=(unsigned long *)
3773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          RelinquishMagickMemory(windows->pixel_info->pixels);
3783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (windows->pixel_info->annotate_context != (GC) NULL)
3793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XFreeGC(windows->display,windows->pixel_info->annotate_context);
3803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (windows->pixel_info->widget_context != (GC) NULL)
3813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XFreeGC(windows->display,windows->pixel_info->widget_context);
3823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (windows->pixel_info->highlight_context != (GC) NULL)
3833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XFreeGC(windows->display,windows->pixel_info->highlight_context);
3843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->pixel_info=(XPixelInfo *)
3853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        RelinquishMagickMemory(windows->pixel_info);
3863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
3873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->font_info != (XFontStruct *) NULL)
3883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
3893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XFreeFont(windows->display,windows->font_info);
3903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->font_info=(XFontStruct *) NULL;
3913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
3923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->class_hints != (XClassHint *) NULL)
3933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
394c9cc4a7b1dd605daff0dd2e0b0e1c42f178871ddcristy      if (windows->class_hints->res_name != (char *) NULL)
395c9cc4a7b1dd605daff0dd2e0b0e1c42f178871ddcristy        windows->class_hints->res_name=DestroyString(
396c9cc4a7b1dd605daff0dd2e0b0e1c42f178871ddcristy          windows->class_hints->res_name);
397c9cc4a7b1dd605daff0dd2e0b0e1c42f178871ddcristy      if (windows->class_hints->res_class != (char *) NULL)
398c9cc4a7b1dd605daff0dd2e0b0e1c42f178871ddcristy        windows->class_hints->res_class=DestroyString(
399c9cc4a7b1dd605daff0dd2e0b0e1c42f178871ddcristy          windows->class_hints->res_class);
4003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XFree(windows->class_hints);
4013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->class_hints=(XClassHint *) NULL;
4023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
4033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->manager_hints != (XWMHints *) NULL)
4043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
4053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XFree(windows->manager_hints);
4063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->manager_hints=(XWMHints *) NULL;
4073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
4083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->map_info != (XStandardColormap *) NULL)
4093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
4103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XFree(windows->map_info);
4113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->map_info=(XStandardColormap *) NULL;
4123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
4133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->icon_map != (XStandardColormap *) NULL)
4143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
4153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XFree(windows->icon_map);
4163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->icon_map=(XStandardColormap *) NULL;
4173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
4183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->visual_info != (XVisualInfo *) NULL)
4193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
4203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XFree(windows->visual_info);
4213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->visual_info=(XVisualInfo *) NULL;
4223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
4233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->icon_visual != (XVisualInfo *) NULL)
4243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
4253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XFree(windows->icon_visual);
4263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->icon_visual=(XVisualInfo *) NULL;
4273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
4283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSetWindows((XWindows *) NULL);
4293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
4303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
4323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X A n n o t a t e I m a g e                                               %
4373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XAnnotateImage() annotates the image with text.
4433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XAnnotateImage method is:
4453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      MagickBooleanType XAnnotateImage(Display *display,
4477c3af951210f34d3f244b31f06ee291e5be8ecb7cristy%        const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image,
4487c3af951210f34d3f244b31f06ee291e5be8ecb7cristy%        ExceptionInfo *exception)
4493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
4513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
4533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
4543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o pixel: Specifies a pointer to a XPixelInfo structure.
4563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
4583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
4603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4617c3af951210f34d3f244b31f06ee291e5be8ecb7cristy%    o exception: return any errors or warnings in this structure.
4627c3af951210f34d3f244b31f06ee291e5be8ecb7cristy%
4633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
464bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate MagickBooleanType XAnnotateImage(Display *display,
4657c3af951210f34d3f244b31f06ee291e5be8ecb7cristy  const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image,
4667c3af951210f34d3f244b31f06ee291e5be8ecb7cristy  ExceptionInfo *exception)
4673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
468c57f694b2d04975a0e501613e34368c464708c19cristy  CacheView
469c57f694b2d04975a0e501613e34368c464708c19cristy    *annotate_view;
470c57f694b2d04975a0e501613e34368c464708c19cristy
4713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  GC
4723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    annotate_context;
4733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Image
4753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *annotate_image;
4763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
4783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x,
4793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y;
4803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickBooleanType
4823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    matte;
4833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Pixmap
4853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    annotate_pixmap;
4863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4872ed42f6d7c2245432767ea446742977ee87e963ccristy  Quantum
4885f95f4f77efc46ff53593d750491c8f60698c983cristy    virtual_pixel[CompositePixelChannel];
4892ed42f6d7c2245432767ea446742977ee87e963ccristy
4903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
4913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    depth,
4923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    height,
4933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    width;
4943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
4963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root_window;
4973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XGCValues
4993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    context_values;
5003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
5013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XImage
5023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *annotate_ximage;
5033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
5043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
5053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize annotated image.
5063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
5073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
5083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
5093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(pixel != (XPixelInfo *) NULL);
5103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(annotate_info != (XAnnotateInfo *) NULL);
5113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image != (Image *) NULL);
5123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
5133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize annotated pixmap.
5143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
5153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  root_window=XRootWindow(display,XDefaultScreen(display));
5163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
5173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_pixmap=XCreatePixmap(display,root_window,annotate_info->width,
5183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    annotate_info->height,depth);
5193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (annotate_pixmap == (Pixmap) NULL)
5203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
5213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
5223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize graphics info.
5233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
5243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  context_values.background=0;
525bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  context_values.foreground=(size_t) (~0);
5263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  context_values.font=annotate_info->font_info->fid;
527c57f694b2d04975a0e501613e34368c464708c19cristy  annotate_context=XCreateGC(display,root_window,(unsigned long)
528c57f694b2d04975a0e501613e34368c464708c19cristy    (GCBackground | GCFont | GCForeground),&context_values);
5293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (annotate_context == (GC) NULL)
5303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
5313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
5323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Draw text to pixmap.
5333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
5343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XDrawImageString(display,annotate_pixmap,annotate_context,0,
5353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (int) annotate_info->font_info->ascent,annotate_info->text,
5363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (int) strlen(annotate_info->text));
5373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFreeGC(display,annotate_context);
5383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
5393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize annotated X image.
5403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
5413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_ximage=XGetImage(display,annotate_pixmap,0,0,annotate_info->width,
5423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    annotate_info->height,AllPlanes,ZPixmap);
5433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (annotate_ximage == (XImage *) NULL)
5443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
5453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFreePixmap(display,annotate_pixmap);
5463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
5473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize annotated image.
5483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
5496710d8414f0ed06e4eaf9346366be72e2b4719efcristy  annotate_image=AcquireImage((ImageInfo *) NULL,exception);
5503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (annotate_image == (Image *) NULL)
5513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
5523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_image->columns=annotate_info->width;
5533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_image->rows=annotate_info->height;
5543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
5553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Transfer annotated X image to image.
5563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
5573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  width=(unsigned int) image->columns;
5583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  height=(unsigned int) image->rows;
5593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=0;
5603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y=0;
5613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
5622ed42f6d7c2245432767ea446742977ee87e963ccristy  (void) GetOneVirtualPixel(image,(ssize_t) x,(ssize_t) y,virtual_pixel,
5636710d8414f0ed06e4eaf9346366be72e2b4719efcristy    exception);
564e42f658533644aecb733785ffd91b286d6778deacristy  annotate_image->background_color.red=(double)
565e42f658533644aecb733785ffd91b286d6778deacristy    virtual_pixel[RedPixelChannel];
566e42f658533644aecb733785ffd91b286d6778deacristy  annotate_image->background_color.green=(double)
567e42f658533644aecb733785ffd91b286d6778deacristy    virtual_pixel[GreenPixelChannel];
568e42f658533644aecb733785ffd91b286d6778deacristy  annotate_image->background_color.blue=(double)
569e42f658533644aecb733785ffd91b286d6778deacristy    virtual_pixel[BluePixelChannel];
570e42f658533644aecb733785ffd91b286d6778deacristy  annotate_image->background_color.alpha=(double)
571e42f658533644aecb733785ffd91b286d6778deacristy    virtual_pixel[AlphaPixelChannel];
5723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (annotate_info->stencil == ForegroundStencil)
5733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    annotate_image->matte=MagickTrue;
574c57f694b2d04975a0e501613e34368c464708c19cristy  annotate_view=AcquireCacheView(annotate_image);
5753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (y=0; y < (int) annotate_image->rows; y++)
5763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
577c57f694b2d04975a0e501613e34368c464708c19cristy    register int
5783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      x;
5793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
5804c08aed51c5899665ade97263692328eea4af106cristy    register Quantum
581c47d1f8ecfe7d04f0f003cca0fe175658bbf0fb2cristy      *restrict q;
5823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
583c57f694b2d04975a0e501613e34368c464708c19cristy    q=GetCacheViewAuthenticPixels(annotate_view,0,(ssize_t) y,
584c57f694b2d04975a0e501613e34368c464708c19cristy      annotate_image->columns,1,exception);
585acd2ed254c18c254a0ab5aafa06d1645e5d079d8cristy    if (q == (Quantum *) NULL)
5863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
587c57f694b2d04975a0e501613e34368c464708c19cristy    for (x=0; x < (int) annotate_image->columns; x++)
5883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
5894c08aed51c5899665ade97263692328eea4af106cristy      SetPixelAlpha(annotate_image,OpaqueAlpha,q);
5903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (XGetPixel(annotate_ximage,x,y) == 0)
5913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
5923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
5933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Set this pixel to the background color.
5943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
5954c08aed51c5899665ade97263692328eea4af106cristy          SetPixelRed(annotate_image,ScaleShortToQuantum(
5964c08aed51c5899665ade97263692328eea4af106cristy            pixel->box_color.red),q);
5974c08aed51c5899665ade97263692328eea4af106cristy          SetPixelGreen(annotate_image,ScaleShortToQuantum(
5984c08aed51c5899665ade97263692328eea4af106cristy            pixel->box_color.green),q);
5994c08aed51c5899665ade97263692328eea4af106cristy          SetPixelBlue(annotate_image,ScaleShortToQuantum(
6004c08aed51c5899665ade97263692328eea4af106cristy            pixel->box_color.blue),q);
6013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((annotate_info->stencil == ForegroundStencil) ||
6023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (annotate_info->stencil == OpaqueStencil))
6034c08aed51c5899665ade97263692328eea4af106cristy            SetPixelAlpha(annotate_image,TransparentAlpha,q);
6043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
6053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
6063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
6073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
6083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Set this pixel to the pen color.
6093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
6104c08aed51c5899665ade97263692328eea4af106cristy          SetPixelRed(annotate_image,ScaleShortToQuantum(
6114c08aed51c5899665ade97263692328eea4af106cristy            pixel->pen_color.red),q);
6124c08aed51c5899665ade97263692328eea4af106cristy          SetPixelGreen(annotate_image,ScaleShortToQuantum(
6134c08aed51c5899665ade97263692328eea4af106cristy            pixel->pen_color.green),q);
6144c08aed51c5899665ade97263692328eea4af106cristy          SetPixelBlue(annotate_image,ScaleShortToQuantum(
6154c08aed51c5899665ade97263692328eea4af106cristy            pixel->pen_color.blue),q);
6163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (annotate_info->stencil == BackgroundStencil)
6174c08aed51c5899665ade97263692328eea4af106cristy            SetPixelAlpha(annotate_image,TransparentAlpha,q);
6183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
619ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy      q+=GetPixelChannels(annotate_image);
6203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
621c57f694b2d04975a0e501613e34368c464708c19cristy    if (SyncCacheViewAuthenticPixels(annotate_view,exception) == MagickFalse)
6223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
6233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
624c57f694b2d04975a0e501613e34368c464708c19cristy  annotate_view=DestroyCacheView(annotate_view);
6253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XDestroyImage(annotate_ximage);
6263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
6273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Determine annotate geometry.
6283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
6293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
6303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((width != (unsigned int) annotate_image->columns) ||
6313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (height != (unsigned int) annotate_image->rows))
6323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
6333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      char
6343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        image_geometry[MaxTextExtent];
6353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
6373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Scale image.
6383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
639b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy      (void) FormatLocaleString(image_geometry,MaxTextExtent,"%ux%u",
6403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        width,height);
641e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy      (void) TransformImage(&annotate_image,(char *) NULL,image_geometry,
642e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy        exception);
6433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
6443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (annotate_info->degrees != 0.0)
6453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
6463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Image
6473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *rotate_image;
6483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      int
6503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        rotations;
6513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      MagickRealType
6533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        normalized_degrees;
6543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
6563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Rotate image.
6573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
6586710d8414f0ed06e4eaf9346366be72e2b4719efcristy      rotate_image=RotateImage(annotate_image,annotate_info->degrees,exception);
6593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (rotate_image == (Image *) NULL)
6603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        return(MagickFalse);
6613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      annotate_image=DestroyImage(annotate_image);
6623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      annotate_image=rotate_image;
6633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
6643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Annotation is relative to the degree of rotation.
6653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
6663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      normalized_degrees=annotate_info->degrees;
6673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      while (normalized_degrees < -45.0)
6683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        normalized_degrees+=360.0;
6693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (rotations=0; normalized_degrees > 45.0; rotations++)
6703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        normalized_degrees-=90.0;
6713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      switch (rotations % 4)
6723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
6733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        default:
6743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 0:
6753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
6763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 1:
6773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
6783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
6793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Rotate 90 degrees.
6803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
6813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          x-=(int) annotate_image->columns/2;
6823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          y+=(int) annotate_image->columns/2;
6833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
6843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
6853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 2:
6863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
6873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
6883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Rotate 180 degrees.
6893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
6903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          x=x-(int) annotate_image->columns;
6913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
6923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
6933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 3:
6943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
6953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
6963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Rotate 270 degrees.
6973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
6983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          x=x-(int) annotate_image->columns/2;
6993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          y=y-(int) (annotate_image->rows-(annotate_image->columns/2));
7003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
7013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
7023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
7033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
7043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
7053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Composite text onto the image.
7063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
7073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
7083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  matte=image->matte;
7093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) CompositeImage(image,annotate_image->matte != MagickFalse ?
710e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy    OverCompositeOp : CopyCompositeOp,annotate_image,(ssize_t) x,(ssize_t) y,
711e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy    exception);
7123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  image->matte=matte;
7133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_image=DestroyImage(annotate_image);
7143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickTrue);
7153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
7163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
7183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X B e s t F o n t                                                         %
7233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XBestFont() returns the "best" font.  "Best" is defined as a font specified
7293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  in the X resource database or a font such that the text width displayed
7303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  with the font does not exceed the specified maximum width.
7313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XBestFont method is:
7333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XFontStruct *XBestFont(Display *display,
7353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const XResourceInfo *resource_info,const MagickBooleanType text_font)
7363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
7383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o font: XBestFont returns a pointer to a XFontStruct structure.
7403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
7423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
7433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o text_font:  True is font should be mono-spaced (typewriter style).
7473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
7493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7503ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic char **FontToList(char *font)
7513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
7523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
7533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    **fontlist;
7543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register char
7563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p,
7573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *q;
7583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
7603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
7613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
7633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    fonts;
7643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (font == (char *) NULL)
7663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return((char **) NULL);
7673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
7683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Convert string to an ASCII list.
7693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
7703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  fonts=1U;
7713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (p=font; *p != '\0'; p++)
7723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if ((*p == ':') || (*p == ';') || (*p == ','))
7733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      fonts++;
7743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  fontlist=(char **) AcquireQuantumMemory((size_t) fonts+1UL,sizeof(*fontlist));
7753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (fontlist == (char **) NULL)
7763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
7773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
7783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        font);
7793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return((char **) NULL);
7803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
7813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  p=font;
7823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; i < (int) fonts; i++)
7833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
7843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    for (q=p; *q != '\0'; q++)
7853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((*q == ':') || (*q == ';') || (*q == ','))
7863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
7873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    fontlist[i]=(char *) AcquireQuantumMemory((size_t) (q-p)+1UL,
7883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      sizeof(*fontlist[i]));
7893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (fontlist[i] == (char *) NULL)
7903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
7913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ThrowXWindowFatalException(ResourceLimitError,"MemoryAllocationFailed",
7923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          font);
7933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        return((char **) NULL);
7943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
7953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) CopyMagickString(fontlist[i],p,(size_t) (q-p+1));
7963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    p=q+1;
7973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
7983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  fontlist[i]=(char *) NULL;
7993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(fontlist);
8003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
8013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
802bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate XFontStruct *XBestFont(Display *display,
8033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const XResourceInfo *resource_info,const MagickBooleanType text_font)
8043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
8053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static const char
8063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *Fonts[]=
8073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
8083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
8093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-1",
8103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-15",
8113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-15",
8123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
8133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "-*-arial-medium-r-normal--12-*-*-*-*-*-*-*",
8143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "variable",
8153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "fixed",
8163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (char *) NULL
8173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    },
8183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *TextFonts[]=
8193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
8203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-1",
8213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-15",
8223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "-*-fixed-medium-r-normal-*-12-*-*-*-*-*-*-*",
8233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "fixed",
8243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (char *) NULL
8253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    };
8263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
8283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *font_name;
8293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register const char
8313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    **p;
8323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XFontStruct
8343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *font_info;
8353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  font_info=(XFontStruct *) NULL;
8373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  font_name=resource_info->font;
8383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (text_font != MagickFalse)
8393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    font_name=resource_info->text_font;
8403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((font_name != (char *) NULL) && (*font_name != '\0'))
8413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
8423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      char
8433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        **fontlist;
8443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      register int
8463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        i;
8473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
8493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Load preferred font specified in the X resource database.
8503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
8513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      fontlist=FontToList(font_name);
8523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (fontlist != (char **) NULL)
8533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
8543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (i=0; fontlist[i] != (char *) NULL; i++)
8553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
8563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (font_info == (XFontStruct *) NULL)
8573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              font_info=XLoadQueryFont(display,fontlist[i]);
8583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            fontlist[i]=DestroyString(fontlist[i]);
8593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
8603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          fontlist=(char **) RelinquishMagickMemory(fontlist);
8613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
8623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (font_info == (XFontStruct *) NULL)
8633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ThrowXWindowFatalException(XServerError,"UnableToLoadFont",font_name);
8643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
8653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
8663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Load fonts from list of fonts until one is found.
8673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
8683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  p=Fonts;
8693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (text_font != MagickFalse)
8703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    p=TextFonts;
8713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (XDisplayHeight(display,XDefaultScreen(display)) >= 748)
8723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    p++;
8733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while (*p != (char *) NULL)
8743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
8753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (font_info != (XFontStruct *) NULL)
8763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
8773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    font_info=XLoadQueryFont(display,(char *) *p);
8783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    p++;
8793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
8803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(font_info);
8813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
8823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
8843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X B e s t I c o n S i z e                                                 %
8893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XBestIconSize() returns the "best" icon size.  "Best" is defined as an icon
8953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  size that maintains the aspect ratio of the image.  If the window manager
8963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  has preferred icon sizes, one of the preferred sizes is used.
8973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XBestIconSize method is:
8993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XBestIconSize(Display *display,XWindowInfo *window,Image *image)
9013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
9033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
9053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
9063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
9083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
910bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XBestIconSize(Display *display,XWindowInfo *window,
9113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Image *image)
9123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
9133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
9143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i,
9153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_sizes;
9163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickRealType
9183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scale_factor;
9193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
9213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    height,
9223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    icon_height,
9233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    icon_width,
9243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    width;
9253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
9273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root_window;
9283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XIconSize
9303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *icon_size,
9313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *size_list;
9323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
9343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Determine if the window manager has specified preferred icon sizes.
9353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
9363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
9383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (XWindowInfo *) NULL);
9393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image != (Image *) NULL);
9403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->width=MaxIconSize;
9413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->height=MaxIconSize;
9423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  icon_size=(XIconSize *) NULL;
9433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  number_sizes=0;
9443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  root_window=XRootWindow(display,window->screen);
9453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (XGetIconSizes(display,root_window,&size_list,&number_sizes) != 0)
9463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if ((number_sizes > 0) && (size_list != (XIconSize *) NULL))
9473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_size=size_list;
9483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (icon_size == (XIconSize *) NULL)
9493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
9503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
9513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Window manager does not restrict icon size.
9523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
9533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_size=XAllocIconSize();
9543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (icon_size == (XIconSize *) NULL)
9553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
9563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ThrowXWindowFatalException(ResourceLimitError,
9573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            "MemoryAllocationFailed",image->filename);
9583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          return;
9593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
9603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_size->min_width=1;
9613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_size->max_width=MaxIconSize;
9623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_size->min_height=1;
9633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_size->max_height=MaxIconSize;
9643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_size->width_inc=1;
9653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_size->height_inc=1;
9663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
9673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
9683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Determine aspect ratio of image.
9693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
9703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  width=(unsigned int) image->columns;
9713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  height=(unsigned int) image->rows;
9723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  i=0;
9733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->crop_geometry)
9743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XParseGeometry(window->crop_geometry,&i,&i,&width,&height);
9753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
9763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Look for an icon size that maintains the aspect ratio of image.
9773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
9783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  scale_factor=(MagickRealType) icon_size->max_width/width;
9793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (scale_factor > ((MagickRealType) icon_size->max_height/height))
9803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scale_factor=(MagickRealType) icon_size->max_height/height;
9813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  icon_width=(unsigned int) icon_size->min_width;
9823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while ((int) icon_width < icon_size->max_width)
9833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
9843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (icon_width >= (unsigned int) (scale_factor*width+0.5))
9853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
9863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    icon_width+=icon_size->width_inc;
9873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
9883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  icon_height=(unsigned int) icon_size->min_height;
9893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while ((int) icon_height < icon_size->max_height)
9903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
9913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (icon_height >= (unsigned int) (scale_factor*height+0.5))
9923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
9933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    icon_height+=icon_size->height_inc;
9943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
9953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFree((void *) icon_size);
9963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->width=icon_width;
9973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->height=icon_height;
9983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
9993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
10013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
10033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
10043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
10053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X B e s t P i x e l                                                       %
10063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
10073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
10083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
10093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XBestPixel() returns a pixel from an array of pixels that is closest to the
10123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  requested color.  If the color array is NULL, the colors are obtained from
10133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  the X server.
10143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XBestPixel method is:
10163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XBestPixel(Display *display,const Colormap colormap,XColor *colors,
10183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        unsigned int number_colors,XColor *color)
10193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
10213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o pixel: XBestPixel returns the pixel value closest to the requested
10233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      color.
10243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
10263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
10273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o colormap: Specifies the ID of the X server colormap.
10293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o colors: Specifies an array of XColor structures.
10313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o number_colors: Specifies the number of XColor structures in the
10333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      color definition array.
10343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o color: Specifies the desired RGB value to find in the colors array.
10363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1038bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XBestPixel(Display *display,const Colormap colormap,
10393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XColor *colors,unsigned int number_colors,XColor *color)
10403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
10413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickBooleanType
10423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    query_server;
10433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10444c08aed51c5899665ade97263692328eea4af106cristy  PixelInfo
10453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel;
10463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickRealType
10483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    min_distance;
10493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register MagickRealType
10513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    distance;
10523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
10543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i,
10553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    j;
10563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
10583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
10593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
10613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Find closest representation for the requested RGB color.
10623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
10633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
10643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
10653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(color != (XColor *) NULL);
10663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XAllocColor(display,colormap,color);
10673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status != False)
10683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
10693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  query_server=colors == (XColor *) NULL ? MagickTrue : MagickFalse;
10703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (query_server != MagickFalse)
10713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
10723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
10733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Read X server colormap.
10743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
10753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
10763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (colors == (XColor *) NULL)
10773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
10783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ThrowXWindowFatalException(ResourceLimitError,
10793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            "MemoryAllocationFailed","...");
10803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          return;
10813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
10823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (i=0; i < (int) number_colors; i++)
1083bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        colors[i].pixel=(size_t) i;
10843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (number_colors > 256)
10853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        number_colors=256;
10863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XQueryColors(display,colormap,colors,(int) number_colors);
10873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
10883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  min_distance=3.0*((MagickRealType) QuantumRange+1.0)*((MagickRealType)
10893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    QuantumRange+1.0);
10903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  j=0;
10913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; i < (int) number_colors; i++)
10923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
10933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel.red=colors[i].red-(MagickRealType) color->red;
10943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    distance=pixel.red*pixel.red;
10953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (distance > min_distance)
10963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      continue;
10973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel.green=colors[i].green-(MagickRealType) color->green;
10983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    distance+=pixel.green*pixel.green;
10993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (distance > min_distance)
11003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      continue;
11013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel.blue=colors[i].blue-(MagickRealType) color->blue;
11023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    distance+=pixel.blue*pixel.blue;
11033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (distance > min_distance)
11043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      continue;
11053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    min_distance=distance;
11063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    color->pixel=colors[i].pixel;
11073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    j=i;
11083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
11093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XAllocColor(display,colormap,&colors[j]);
11103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (query_server != MagickFalse)
11113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    colors=(XColor *) RelinquishMagickMemory(colors);
11123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
11133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
11153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
11173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
11183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
11193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X B e s t V i s u a l I n f o                                             %
11203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
11213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
11223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
11233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XBestVisualInfo() returns visual information for a visual that is the "best"
11263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  the server supports.  "Best" is defined as:
11273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    1. Restrict the visual list to those supported by the default screen.
11293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    2. If a visual type is specified, restrict the visual list to those of
11313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%       that type.
11323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    3. If a map type is specified, choose the visual that matches the id
11343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%       specified by the Standard Colormap.
11353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    4  From the list of visuals, choose one that can display the most
11373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%       simultaneous colors.  If more than one visual can display the same
11383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%       number of simultaneous colors, one is chosen based on a rank.
11393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XBestVisualInfo method is:
11413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XVisualInfo *XBestVisualInfo(Display *display,
11433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XStandardColormap *map_info,XResourceInfo *resource_info)
11443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
11463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o visual_info: XBestVisualInfo returns a pointer to a X11 XVisualInfo
11483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      structure.
11493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
11513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
11523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o map_info: If map_type is specified, this structure is initialized
11543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      with info from the Standard Colormap.
11553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
11573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
11593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11603ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic inline int MagickMax(const int x,const int y)
11613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
11623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (x > y)
11633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(x);
11643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(y);
11653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
11663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1167bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristystatic inline size_t MagickMin(const unsigned int x,
11683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const unsigned int y)
11693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
11703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (x < y)
11713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(x);
11723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(y);
11733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
11743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1175bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate XVisualInfo *XBestVisualInfo(Display *display,
11763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XStandardColormap *map_info,XResourceInfo *resource_info)
11773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
11783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define MaxStandardColormaps  7
11793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define XVisualColormapSize(visual_info) MagickMin((unsigned int) (\
11803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (visual_info->klass == TrueColor) || (visual_info->klass == DirectColor) ? \
11813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy   visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \
11823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy   (unsigned int) visual_info->colormap_size),1U << visual_info->depth)
11833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
11853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *map_type,
11863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *visual_type;
11873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1188c57f694b2d04975a0e501613e34368c464708c19cristy  int
1189c57f694b2d04975a0e501613e34368c464708c19cristy    visual_mask;
1190c57f694b2d04975a0e501613e34368c464708c19cristy
11913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
11923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
11933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11948891f9ce489d3e61399b60436ea6c62f5ed9b887cristy  size_t
11958891f9ce489d3e61399b60436ea6c62f5ed9b887cristy    one;
11968891f9ce489d3e61399b60436ea6c62f5ed9b887cristy
11973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static int
11983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_visuals;
11993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
12003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static XVisualInfo
12013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    visual_template;
12023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
12033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XVisualInfo
12043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *visual_info,
12053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *visual_list;
12063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
12073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
12083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Restrict visual search by screen number.
12093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
12103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
12113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
12123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(map_info != (XStandardColormap *) NULL);
12133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
12143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  map_type=resource_info->map_type;
12153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  visual_type=resource_info->visual_type;
12163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  visual_mask=VisualScreenMask;
12173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  visual_template.screen=XDefaultScreen(display);
12183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  visual_template.depth=XDefaultDepth(display,XDefaultScreen(display));
12198891f9ce489d3e61399b60436ea6c62f5ed9b887cristy  one=1;
12203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((resource_info->immutable != MagickFalse) && (resource_info->colors != 0))
12218891f9ce489d3e61399b60436ea6c62f5ed9b887cristy    if (resource_info->colors <= (one << (size_t) visual_template.depth))
12223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      visual_mask|=VisualDepthMask;
12233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (visual_type != (char *) NULL)
12243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
12253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
12263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Restrict visual search by class or visual id.
12273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
12283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare("staticgray",visual_type) == 0)
12293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
12303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          visual_mask|=VisualClassMask;
12313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          visual_template.klass=StaticGray;
12323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
12333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
12343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (LocaleCompare("grayscale",visual_type) == 0)
12353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
12363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            visual_mask|=VisualClassMask;
12373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            visual_template.klass=GrayScale;
12383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
12393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        else
12403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (LocaleCompare("staticcolor",visual_type) == 0)
12413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
12423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              visual_mask|=VisualClassMask;
12433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              visual_template.klass=StaticColor;
12443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
12453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          else
12463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (LocaleCompare("pseudocolor",visual_type) == 0)
12473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
12483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                visual_mask|=VisualClassMask;
12493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                visual_template.klass=PseudoColor;
12503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
12513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            else
12523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (LocaleCompare("truecolor",visual_type) == 0)
12533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
12543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  visual_mask|=VisualClassMask;
12553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  visual_template.klass=TrueColor;
12563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
12573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              else
12583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if (LocaleCompare("directcolor",visual_type) == 0)
12593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
12603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    visual_mask|=VisualClassMask;
12613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    visual_template.klass=DirectColor;
12623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
12633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                else
12643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if (LocaleCompare("default",visual_type) == 0)
12653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
12663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      visual_mask|=VisualIDMask;
12673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      visual_template.visualid=XVisualIDFromVisual(
12683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        XDefaultVisual(display,XDefaultScreen(display)));
12693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
12703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  else
12713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    if (isdigit((int) ((unsigned char) *visual_type)) != 0)
12723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      {
12733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        visual_mask|=VisualIDMask;
12743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        visual_template.visualid=
12753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                          strtol(visual_type,(char **) NULL,0);
12763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      }
12773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    else
12783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      ThrowXWindowFatalException(XServerError,
12793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        "UnrecognizedVisualSpecifier",visual_type);
12803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
12813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
12823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Get all visuals that meet our criteria so far.
12833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
12843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  number_visuals=0;
12853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
12863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &number_visuals);
12873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  visual_mask=VisualScreenMask | VisualIDMask;
12883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
12893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
12903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
12913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Failed to get visual;  try using the default visual.
12923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
12933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowFatalException(XServerWarning,"UnableToGetVisual",
12943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        visual_type);
12953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      visual_template.visualid=XVisualIDFromVisual(XDefaultVisual(display,
12963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XDefaultScreen(display)));
12973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
12983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &number_visuals);
12993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
13003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        return((XVisualInfo *) NULL);
13013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowFatalException(XServerWarning,"UsingDefaultVisual",
13023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XVisualClassName(visual_list->klass));
13033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
13043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->color_recovery=MagickFalse;
13053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((map_info != (XStandardColormap *) NULL) && (map_type != (char *) NULL))
13063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
13073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Atom
13083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        map_property;
13093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
13103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      char
13113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        map_name[MaxTextExtent];
13123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
13133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      int
13143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        j,
13153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        number_maps;
13163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
13173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Status
13183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        status;
13193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
13203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Window
13213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        root_window;
13223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
13233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XStandardColormap
13243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *map_list;
13253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
13263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
13273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Choose a visual associated with a standard colormap.
13283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
13293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      root_window=XRootWindow(display,XDefaultScreen(display));
13303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      status=False;
13313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare(map_type,"list") != 0)
13323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
13333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
13343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            User specified Standard Colormap.
13353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
1336b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy          (void) FormatLocaleString((char *) map_name,MaxTextExtent,
13373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            "RGB_%s_MAP",map_type);
13383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          LocaleUpper(map_name);
13393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          map_property=XInternAtom(display,(char *) map_name,MagickTrue);
13403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (map_property != (Atom) NULL)
13413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
13423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              map_property);
13433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
13443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
13453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
13463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          static const char
13473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *colormap[MaxStandardColormaps]=
13483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
13493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "_HP_RGB_SMOOTH_MAP_LIST",
13503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "RGB_BEST_MAP",
13513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "RGB_DEFAULT_MAP",
13523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "RGB_GRAY_MAP",
13533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "RGB_RED_MAP",
13543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "RGB_GREEN_MAP",
13553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "RGB_BLUE_MAP",
13563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            };
13573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
13583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
13593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Choose a standard colormap from a list.
13603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
13613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (i=0; i < MaxStandardColormaps; i++)
13623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
13633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            map_property=XInternAtom(display,(char *) colormap[i],MagickTrue);
13643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (map_property == (Atom) NULL)
13653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              continue;
13663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
13673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              map_property);
13683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (status != False)
13693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
13703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
13713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          resource_info->color_recovery=i == 0 ? MagickTrue : MagickFalse;
13723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
13733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status == False)
13743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
13753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ThrowXWindowFatalException(XServerError,"UnableToGetStandardColormap",
13763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            map_type);
13773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          return((XVisualInfo *) NULL);
13783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
13793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
13803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Search all Standard Colormaps and visuals for ids that match.
13813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
13823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      *map_info=map_list[0];
13833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if !defined(PRE_R4_ICCCM)
13843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
13853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (i=0; i < number_maps; i++)
13863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        for (j=0; j < number_visuals; j++)
13873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (map_list[i].visualid ==
13883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              XVisualIDFromVisual(visual_list[j].visual))
13893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
13903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *map_info=map_list[i];
13913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              visual_template.visualid=XVisualIDFromVisual(
13923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                visual_list[j].visual);
13933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
13943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
13953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (map_info->visualid != visual_template.visualid)
13963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
13973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ThrowXWindowFatalException(XServerError,
13983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            "UnableToMatchVisualToStandardColormap",map_type);
13993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          return((XVisualInfo *) NULL);
14003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
14013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
14023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (map_info->colormap == (Colormap) NULL)
14033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
14043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ThrowXWindowFatalException(XServerError,
14053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            "StandardColormapIsNotInitialized",map_type);
14063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          return((XVisualInfo *) NULL);
14073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
14083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFree((void *) map_list);
14093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
14103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
14113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
14123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      static const unsigned int
14133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        rank[]=
14143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
14153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            StaticGray,
14163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            GrayScale,
14173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            StaticColor,
14183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            DirectColor,
14193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            TrueColor,
14203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            PseudoColor
14213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          };
14223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
14233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XVisualInfo
14243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *p;
14253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
14263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
14273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Pick one visual that displays the most simultaneous colors.
14283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
14293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      visual_info=visual_list;
14303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      p=visual_list;
14313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (i=1; i < number_visuals; i++)
14323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
14333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        p++;
14343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
14353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          visual_info=p;
14363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        else
14373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
14383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (rank[p->klass] > rank[visual_info->klass])
14393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              visual_info=p;
14403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
14413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
14423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
14433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFree((void *) visual_list);
14443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
14453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Retrieve only one visual by its screen & id number.
14463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
14473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
14483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &number_visuals);
14493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
14503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return((XVisualInfo *) NULL);
14513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(visual_info);
14523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
14533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
14543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
14553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X C h e c k D e f i n e C u r s o r                                       %
14603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XCheckDefineCursor() prevents cursor changes on the root window.
14663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XXCheckDefineCursor method is:
14683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XCheckDefineCursor(display,window,cursor)
14703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
14723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
14743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
14753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: the window.
14773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o cursor: the cursor.
14793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1481bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate int XCheckDefineCursor(Display *display,Window window,
14823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Cursor cursor)
14833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
14843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
14853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
14863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window == XRootWindow(display,XDefaultScreen(display)))
14873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(0);
14883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(XDefineCursor(display,window,cursor));
14893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
14903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
14913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
14923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X C h e c k R e f r e s h W i n d o w s                                   %
14973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XCheckRefreshWindows() checks the X server for exposure events for a
15033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  particular window and updates the areassociated with the exposure event.
15043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XCheckRefreshWindows method is:
15063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XCheckRefreshWindows(Display *display,XWindows *windows)
15083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
15103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
15123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
15133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o windows: Specifies a pointer to a XWindows structure.
15153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1517bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XCheckRefreshWindows(Display *display,XWindows *windows)
15183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
15193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
15203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    id;
15213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
15223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XEvent
15233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    event;
15243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
15253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
15263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
15273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(windows != (XWindows *) NULL);
15283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XDelay(display,SuspendTime);
15293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  id=windows->command.id;
15303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
15313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XCommandWidget(display,windows,(char const **) NULL,&event);
15323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  id=windows->image.id;
15333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
15343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XRefreshWindow(display,&windows->image,&event);
15353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XDelay(display,SuspendTime << 1);
15363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  id=windows->command.id;
15373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
15383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XCommandWidget(display,windows,(char const **) NULL,&event);
15393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  id=windows->image.id;
15403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
15413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XRefreshWindow(display,&windows->image,&event);
15423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
15433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
15443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
15453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X C l i e n t M e s s a g e                                               %
15503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XClientMessage() sends a reason to a window with XSendEvent.  The reason is
15563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  initialized with a particular protocol type and atom.
15573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XClientMessage function is:
15593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XClientMessage(display,window,protocol,reason,timestamp)
15613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
15633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a pointer to the Display structure;  returned from
15653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
15663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a Window structure.
15683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o protocol: Specifies an atom value.
15703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o reason: Specifies an atom value which is the reason to send.
15723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o timestamp: Specifies a value of type Time.
15743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1576bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XClientMessage(Display *display,const Window window,
15773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const Atom protocol,const Atom reason,const Time timestamp)
15783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
15793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XClientMessageEvent
15803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    client_event;
15813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
15823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
15833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  client_event.type=ClientMessage;
15843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  client_event.window=window;
15853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  client_event.message_type=protocol;
15863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  client_event.format=32;
1587c57f694b2d04975a0e501613e34368c464708c19cristy  client_event.data.l[0]=(long) reason;
1588c57f694b2d04975a0e501613e34368c464708c19cristy  client_event.data.l[1]=(long) timestamp;
15893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSendEvent(display,window,MagickFalse,NoEventMask,(XEvent *) &client_event);
15903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
15913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
15923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
15933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy+   X C l i e n t W i n d o w                                                 %
15983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
16003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
16013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XClientWindow() finds a window, at or below the specified window, which has
16043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  a WM_STATE property.  If such a window is found, it is returned, otherwise
16053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  the argument window is returned.
16063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XClientWindow function is:
16083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      client_window=XClientWindow(display,target_window)
16103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
16123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o client_window: XClientWindow returns a window, at or below the specified
16143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      window, which has a WM_STATE property otherwise the argument
16153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      target_window is returned.
16163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a pointer to the Display structure;  returned from
16183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
16193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o target_window: Specifies the window to find a WM_STATE property.
16213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
16233ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Window XClientWindow(Display *display,Window target_window)
16243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
16253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Atom
16263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    state,
16273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    type;
16283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
16303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    format;
16313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
16333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
16343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned char
16363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *data;
16373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1638f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  unsigned long
16393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    after,
16403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_items;
16413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
16433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    client_window;
16443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
16463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
16473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  state=XInternAtom(display,"WM_STATE",MagickTrue);
16483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (state == (Atom) NULL)
16493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(target_window);
16503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  type=(Atom) NULL;
16513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XGetWindowProperty(display,target_window,state,0L,0L,MagickFalse,
16523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
16533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((status == Success) && (type != (Atom) NULL))
16543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(target_window);
16553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  client_window=XWindowByProperty(display,target_window,state);
16563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (client_window == (Window) NULL)
16573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(target_window);
16583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(client_window);
16593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
16603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
16623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
16643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
16653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
1666f34a145c545cb86152ad42a787f6d5fffea6b77ccristy+   X C o m p o n e n t T e r m i n u s                                       %
1667f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%                                                                             %
1668f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%                                                                             %
1669f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%                                                                             %
1670f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1671f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%
1672f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%  XComponentTerminus() destroys the module component.
1673f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%
1674f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%  The format of the XComponentTerminus method is:
1675f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%
1676f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%      XComponentTerminus(void)
1677f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%
1678f34a145c545cb86152ad42a787f6d5fffea6b77ccristy*/
16795ff4eaf57b3cd47d0371f204f865cbba614674a0cristyMagickPrivate void XComponentTerminus(void)
1680f34a145c545cb86152ad42a787f6d5fffea6b77ccristy{
1681f34a145c545cb86152ad42a787f6d5fffea6b77ccristy  DestroyXResources();
1682f34a145c545cb86152ad42a787f6d5fffea6b77ccristy}
1683f34a145c545cb86152ad42a787f6d5fffea6b77ccristy
1684f34a145c545cb86152ad42a787f6d5fffea6b77ccristy/*
1685f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1686f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%                                                                             %
1687f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%                                                                             %
1688f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%                                                                             %
16893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X C o n f i g u r e I m a g e C o l o r m a p                             %
16903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
16913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
16923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
16933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XConfigureImageColormap() creates a new X colormap.
16963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XConfigureImageColormap method is:
16983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XConfigureImageColormap(Display *display,
17006710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        XResourceInfo *resource_info,XWindows *windows,Image *image,
17016710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        ExceptionInfo *exception)
17023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
17043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
17063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
17073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
17093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o windows: Specifies a pointer to a XWindows structure.
17113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
17133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17146710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    o exception: return any errors or warnings in this structure.
17156710d8414f0ed06e4eaf9346366be72e2b4719efcristy%
17163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1717bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XConfigureImageColormap(Display *display,
17186710d8414f0ed06e4eaf9346366be72e2b4719efcristy  XResourceInfo *resource_info,XWindows *windows,Image *image,
17196710d8414f0ed06e4eaf9346366be72e2b4719efcristy  ExceptionInfo *exception)
17203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
17213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Colormap
17223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    colormap;
17233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
17243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
17253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Make standard colormap.
17263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
17273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XSetCursorState(display,windows,MagickTrue);
17283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XCheckRefreshWindows(display,windows);
17293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XMakeStandardColormap(display,windows->visual_info,resource_info,image,
17306710d8414f0ed06e4eaf9346366be72e2b4719efcristy    windows->map_info,windows->pixel_info,exception);
17313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  colormap=windows->map_info->colormap;
17323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSetWindowColormap(display,windows->image.id,colormap);
17333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSetWindowColormap(display,windows->command.id,colormap);
17343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSetWindowColormap(display,windows->widget.id,colormap);
17353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->magnify.mapped != MagickFalse)
17363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XSetWindowColormap(display,windows->magnify.id,colormap);
17373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->pan.mapped != MagickFalse)
17383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XSetWindowColormap(display,windows->pan.id,colormap);
17393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XSetCursorState(display,windows,MagickFalse);
17403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XClientMessage(display,windows->image.id,windows->im_protocols,
17413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    windows->im_update_colormap,CurrentTime);
17423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
17433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
17443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
17453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X C o n s t r a i n W i n d o w P o s i t i o n                           %
17503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XConstrainWindowPosition() assures a window is positioned within the X
17563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  server boundaries.
17573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XConstrainWindowPosition method is:
17593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XConstrainWindowPosition(Display *display,XWindowInfo *window_info)
17613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
17633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a pointer to the Display structure;  returned from
17653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
17663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window_info: Specifies a pointer to a XWindowInfo structure.
17683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1770bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XConstrainWindowPosition(Display *display,
17713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XWindowInfo *window_info)
17723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
17733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
17743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    limit;
17753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
17763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
17773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
17783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window_info != (XWindowInfo *) NULL);
17793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  limit=XDisplayWidth(display,window_info->screen)-window_info->width;
17803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info->x < 0)
17813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window_info->x=0;
17823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
17833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (window_info->x > (int) limit)
17843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_info->x=(int) limit;
17853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  limit=XDisplayHeight(display,window_info->screen)-window_info->height;
17863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info->y < 0)
17873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window_info->y=0;
17883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
17893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (window_info->y > limit)
17903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_info->y=limit;
17913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
17923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
17933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
17943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X D e l a y                                                               %
17993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XDelay() suspends program execution for the number of milliseconds
18053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  specified.
18063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the Delay method is:
18083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1809bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy%      void XDelay(Display *display,const size_t milliseconds)
18103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
18123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a pointer to the Display structure;  returned from
18143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
18153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o milliseconds: Specifies the number of milliseconds to delay before
18173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      returning.
18183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1820bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XDelay(Display *display,const size_t milliseconds)
18213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
18223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
18233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFlush(display);
1824a21afdefe277667f7821fa90decc1f15a167eacfcristy  MagickDelay(milliseconds);
18253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
18263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
18273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
18283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X D e s t r o y R e s o u r c e I n f o                                   %
18333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XDestroyResourceInfo() frees memory associated with the XResourceInfo
18393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  structure.
18403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XDestroyResourceInfo method is:
18423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XDestroyResourceInfo(XResourceInfo *resource_info)
18443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
18463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
18483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
18503ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport void XDestroyResourceInfo(XResourceInfo *resource_info)
18513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
18523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->image_geometry != (char *) NULL)
18533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_info->image_geometry=(char *)
18543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      RelinquishMagickMemory(resource_info->image_geometry);
18553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->quantize_info != (QuantizeInfo *) NULL)
18563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_info->quantize_info=DestroyQuantizeInfo(
18573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      resource_info->quantize_info);
18583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->client_name != (char *) NULL)
18593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_info->client_name=(char *)
18603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      RelinquishMagickMemory(resource_info->client_name);
18613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->name != (char *) NULL)
18623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_info->name=DestroyString(resource_info->name);
18633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
18643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
18653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
18663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
18673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X D e s t r o y W i n d o w C o l o r s                                   %
18723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XDestroyWindowColors() frees X11 color resources previously saved on a
18783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  window by XRetainWindowColors or programs like xsetroot.
18793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XDestroyWindowColors method is:
18813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XDestroyWindowColors(Display *display,Window window)
18833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
18853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
18873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
18883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a Window structure.
18903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1892bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XDestroyWindowColors(Display *display,Window window)
18933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
18943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Atom
18953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    property,
18963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    type;
18973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
18983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
18993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    format;
19003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
19013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
19023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
19033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
19043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned char
19053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *data;
19063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1907f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  unsigned long
19083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    after,
19093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    length;
19103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
19113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
19123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    If there are previous resources on the root window, destroy them.
19133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
19143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
19153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
19163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
19173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (property == (Atom) NULL)
19183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
19193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
19203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "_XSETROOT_ID");
19213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return;
19223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
19233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XGetWindowProperty(display,window,property,0L,1L,MagickTrue,
19243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
19253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status != Success)
19263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
19273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
19283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
19293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XKillClient(display,(XID) (*((Pixmap *) data)));
19303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDeleteProperty(display,window,property);
19313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
19323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (type != None)
19333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XFree((void *) data);
19343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
19353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
19363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
19373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
19393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
19403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
19413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X D i s p l a y I m a g e I n f o                                         %
19423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
19433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
19443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
19453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XDisplayImageInfo() displays information about an X image.
19483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XDisplayImageInfo method is:
19503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XDisplayImageInfo(Display *display,
19523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
19536710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        Image *image,ExceptionInfo *exception)
19543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
19563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
19583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
19593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
19613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o windows: Specifies a pointer to a XWindows structure.
19633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o undo_image: the undo image.
19653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
19673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19686710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    o exception: return any errors or warnings in this structure.
19696710d8414f0ed06e4eaf9346366be72e2b4719efcristy%
19703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1971bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XDisplayImageInfo(Display *display,
19723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
19736710d8414f0ed06e4eaf9346366be72e2b4719efcristy  Image *image,ExceptionInfo *exception)
19743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
19753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
19763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    filename[MaxTextExtent],
19773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *text,
19783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    **textlist;
19793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
19803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  FILE
19813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *file;
19823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
19833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
19843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unique_file;
19853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1986bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  register ssize_t
19873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
19883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1989bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  size_t
19903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_pixels;
19913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
19929d314ff2c17a77996c05413c2013880387e50f0ecristy  ssize_t
19939d314ff2c17a77996c05413c2013880387e50f0ecristy    bytes;
19949d314ff2c17a77996c05413c2013880387e50f0ecristy
19959d314ff2c17a77996c05413c2013880387e50f0ecristy  unsigned int
19969d314ff2c17a77996c05413c2013880387e50f0ecristy    levels;
19979d314ff2c17a77996c05413c2013880387e50f0ecristy
19983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
19993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Write info about the X server to a file.
20003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
20013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
20023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
20033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(windows != (XWindows *) NULL);
20043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image != (Image *) NULL);
20053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image->debug)
20063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
20073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  file=(FILE *) NULL;
20083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unique_file=AcquireUniqueFileResource(filename);
20093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (unique_file != -1)
20103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    file=fdopen(unique_file,"w");
20113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((unique_file == -1) || (file == (FILE *) NULL))
20123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
20133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XNoticeWidget(display,windows,"Unable to display image info",filename);
20143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return;
20153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
20163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->gamma_correct != MagickFalse)
20173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (resource_info->display_gamma != (char *) NULL)
2018b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy      (void) FormatLocaleFile(file,"Display\n  gamma: %s\n\n",
20193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        resource_info->display_gamma);
20203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
20213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Write info about the X image to a file.
20223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
2023b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"X\n  visual: %s\n",
20243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XVisualClassName((int) windows->image.storage_class));
2025b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"  depth: %d\n",windows->image.ximage->depth);
20263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->visual_info->colormap_size != 0)
2027b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"  colormap size: %d\n",
20283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->visual_info->colormap_size);
20293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->colormap== SharedColormap)
2030b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"  colormap type: Shared\n");
20313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
2032b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"  colormap type: Private\n");
20331e604812fad85bb96f757a2393015ae3d061c39acristy  (void) FormatLocaleFile(file,"  geometry: %dx%d\n",
20341e604812fad85bb96f757a2393015ae3d061c39acristy    windows->image.ximage->width,windows->image.ximage->height);
20353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->image.crop_geometry != (char *) NULL)
20361e604812fad85bb96f757a2393015ae3d061c39acristy    (void) FormatLocaleFile(file,"  crop geometry: %s\n",
20371e604812fad85bb96f757a2393015ae3d061c39acristy      windows->image.crop_geometry);
20383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->image.pixmap == (Pixmap) NULL)
2039b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"  type: X Image\n");
20403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
2041b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"  type: Pixmap\n");
20423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->image.shape != MagickFalse)
2043b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"  non-rectangular shape: True\n");
20443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
2045b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"  non-rectangular shape: False\n");
20463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->image.shared_memory != MagickFalse)
2047b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"  shared memory: True\n");
20483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
2049b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"  shared memory: False\n");
2050b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"\n");
20513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->font != (char *) NULL)
2052b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"Font: %s\n\n",resource_info->font);
20533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->text_font != (char *) NULL)
2054b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"Text font: %s\n\n",resource_info->text_font);
20553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
20563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Write info about the undo cache to a file.
20573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
20583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  bytes=0;
20593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (levels=0; undo_image != (Image *) NULL; levels++)
20603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
20613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_pixels=undo_image->list->columns*undo_image->list->rows;
2062101ab708b0574518ac5715da4d3915400e9df79acristy    bytes+=number_pixels*sizeof(PixelInfo);
20633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    undo_image=GetPreviousImageInList(undo_image);
20643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
2065b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"Undo Edit Cache\n  levels: %u\n",levels);
20661e604812fad85bb96f757a2393015ae3d061c39acristy  (void) FormatLocaleFile(file,"  bytes: %.20gmb\n",(double)
20671e604812fad85bb96f757a2393015ae3d061c39acristy    ((bytes+(1 << 19)) >> 20));
2068b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"  limit: %.20gmb\n\n",(double)
2069f2faecf9facdbbb14fcba373365f9f691a9658e0cristy    resource_info->undo_cache);
20703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
20713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Write info about the image to a file.
20723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
20736710d8414f0ed06e4eaf9346366be72e2b4719efcristy  (void) IdentifyImage(image,file,MagickTrue,exception);
20743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) fclose(file);
20756710d8414f0ed06e4eaf9346366be72e2b4719efcristy  text=FileToString(filename,~0,exception);
20763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) RelinquishUniqueFileResource(filename);
20773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (text == (char *) NULL)
20783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
20793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XNoticeWidget(display,windows,"MemoryAllocationFailed",
20803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "UnableToDisplayImageInfo");
20813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return;
20823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
20833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  textlist=StringToList(text);
20843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (textlist != (char **) NULL)
20853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
20863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      char
20873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        title[MaxTextExtent];
20883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
20893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
20903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Display information about the image in the Text View widget.
20913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
20923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
2093b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy      (void) FormatLocaleString(title,MaxTextExtent,"Image Info: %s",
20943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        image->filename);
20953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XTextViewWidget(display,resource_info,windows,MagickTrue,title,
20963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (char const **) textlist);
20973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (i=0; textlist[i] != (char *) NULL; i++)
20983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        textlist[i]=DestroyString(textlist[i]);
20993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      textlist=(char **) RelinquishMagickMemory(textlist);
21003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
21013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  text=DestroyString(text);
21023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
21033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
21043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
21053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
21073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
21083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
21093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy+     X D i t h e r I m a g e                                                 %
21103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
21113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
21123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
21133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
21153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XDitherImage() dithers the reference image as required by the HP Color
21163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  Recovery algorithm.  The color values are quantized to 3 bits of red and
21173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  green, and 2 bits of blue (3/3/2) and can be used as indices into a 8-bit X
21183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  standard colormap.
21193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
21203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XDitherImage method is:
21213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
21226710d8414f0ed06e4eaf9346366be72e2b4719efcristy%      void XDitherImage(Image *image,XImage *ximage,ExceptionInfo *exception)
21233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
21243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
21253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
21263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
21273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
21283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o ximage: Specifies a pointer to a XImage structure;  returned from
21293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XCreateImage.
21303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
21316710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    o exception: return any errors or warnings in this structure.
21326710d8414f0ed06e4eaf9346366be72e2b4719efcristy%
21333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
21346710d8414f0ed06e4eaf9346366be72e2b4719efcristystatic void XDitherImage(Image *image,XImage *ximage,ExceptionInfo *exception)
21353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
21363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static const short int
21373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    dither_red[2][16]=
21383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
21393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {-16,  4, -1, 11,-14,  6, -3,  9,-15,  5, -2, 10,-13,  7, -4,  8},
21403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      { 15, -5,  0,-12, 13, -7,  2,-10, 14, -6,  1,-11, 12, -8,  3, -9}
21413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    },
21423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    dither_green[2][16]=
21433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
21443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      { 11,-15,  7, -3,  8,-14,  4, -2, 10,-16,  6, -4,  9,-13,  5, -1},
21453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {-12, 14, -8,  2, -9, 13, -5,  1,-11, 15, -7,  3,-10, 12, -6,  0}
21463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    },
21473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    dither_blue[2][16]=
21483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
21493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      { -3,  9,-13,  7, -1, 11,-15,  5, -4,  8,-14,  6, -2, 10,-16,  4},
21503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {  2,-10, 12, -8,  0,-12, 14, -6,  3, -9, 13, -7,  1,-11, 15, -5}
21513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    };
21523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2153c57f694b2d04975a0e501613e34368c464708c19cristy  CacheView
2154c57f694b2d04975a0e501613e34368c464708c19cristy    *image_view;
21553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
21563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
2157c57f694b2d04975a0e501613e34368c464708c19cristy    value,
21583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y;
21593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2160101ab708b0574518ac5715da4d3915400e9df79acristy  PixelInfo
2161c57f694b2d04975a0e501613e34368c464708c19cristy    color;
21623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
21633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register char
21643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *q;
21653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
21664c08aed51c5899665ade97263692328eea4af106cristy  register const Quantum
21673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p;
21683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
21693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
21703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i,
21713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    j,
21723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x;
21733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
21743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
21753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scanline_pad;
21763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2177bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  register size_t
21783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel;
21793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
21803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned char
21813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *blue_map[2][16],
21823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *green_map[2][16],
21833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *red_map[2][16];
21843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
21853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
21863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Allocate and initialize dither maps.
21873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
21883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; i < 2; i++)
21893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    for (j=0; j < 16; j++)
21903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
21913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      red_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
21923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        sizeof(*red_map));
21933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      green_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
21943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        sizeof(*green_map));
21953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      blue_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
21963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        sizeof(*blue_map));
21973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((red_map[i][j] == (unsigned char *) NULL) ||
21983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (green_map[i][j] == (unsigned char *) NULL) ||
21993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (blue_map[i][j] == (unsigned char *) NULL))
22003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
22013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ThrowXWindowFatalException(ResourceLimitError,
22023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            "MemoryAllocationFailed",image->filename);
22033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          return;
22043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
22053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
22063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
22073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize dither tables.
22083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
22093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; i < 2; i++)
22103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    for (j=0; j < 16; j++)
22113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (x=0; x < 256; x++)
22123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
22133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        value=x-16;
22143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (x < 48)
22153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          value=x/2+8;
22163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        value+=dither_red[i][j];
22173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        red_map[i][j][x]=(unsigned char)
22183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ((value < 0) ? 0 : (value > 255) ? 255 : value);
22193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        value=x-16;
22203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (x < 48)
22213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          value=x/2+8;
22223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        value+=dither_green[i][j];
22233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        green_map[i][j][x]=(unsigned char)
22243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ((value < 0) ? 0 : (value > 255) ? 255 : value);
22253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        value=x-32;
22263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (x < 112)
22273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          value=x/2+24;
2228bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        value+=((size_t) dither_blue[i][j] << 1);
22293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        blue_map[i][j][x]=(unsigned char)
22303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ((value < 0) ? 0 : (value > 255) ? 255 : value);
22313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
22323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
22333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Dither image.
22343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
22353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  scanline_pad=(unsigned int) (ximage->bytes_per_line-
2236bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy    ((size_t) (ximage->width*ximage->bits_per_pixel) >> 3));
22373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  i=0;
22383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  j=0;
22393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  q=ximage->data;
2240c57f694b2d04975a0e501613e34368c464708c19cristy  image_view=AcquireCacheView(image);
22413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (y=0; y < (int) image->rows; y++)
22423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
2243c57f694b2d04975a0e501613e34368c464708c19cristy    p=GetCacheViewVirtualPixels(image_view,0,(ssize_t) y,image->columns,1,
22446710d8414f0ed06e4eaf9346366be72e2b4719efcristy      exception);
22454c08aed51c5899665ade97263692328eea4af106cristy    if (p == (const Quantum *) NULL)
22463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
22473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    for (x=0; x < (int) image->columns; x++)
22483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
2249e42f658533644aecb733785ffd91b286d6778deacristy      color.red=(double) ClampToQuantum((MagickRealType) (red_map[i][j][
2250e42f658533644aecb733785ffd91b286d6778deacristy        (int) ScaleQuantumToChar(GetPixelRed(image,p))] << 8));
2251e42f658533644aecb733785ffd91b286d6778deacristy      color.green=(double) ClampToQuantum((MagickRealType) (green_map[i][j][
2252e42f658533644aecb733785ffd91b286d6778deacristy        (int) ScaleQuantumToChar(GetPixelGreen(image,p))] << 8));
2253e42f658533644aecb733785ffd91b286d6778deacristy      color.blue=(double) ClampToQuantum((MagickRealType) (blue_map[i][j][
2254e42f658533644aecb733785ffd91b286d6778deacristy        (int) ScaleQuantumToChar(GetPixelBlue(image,p))] << 8));
2255bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      pixel=(size_t) (((size_t) color.red & 0xe0) |
2256bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        (((size_t) color.green & 0xe0) >> 3) |
2257bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        (((size_t) color.blue & 0xc0) >> 6));
22583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      *q++=(char) pixel;
2259ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy      p+=GetPixelChannels(image);
22603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      j++;
22613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (j == 16)
22623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        j=0;
22633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
22643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    q+=scanline_pad;
22653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i++;
22663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (i == 2)
22673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      i=0;
22683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
2269c57f694b2d04975a0e501613e34368c464708c19cristy  image_view=DestroyCacheView(image_view);
22703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
22713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Free allocated memory.
22723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
22733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; i < 2; i++)
22743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    for (j=0; j < 16; j++)
22753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
22763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      green_map[i][j]=(unsigned char *) RelinquishMagickMemory(green_map[i][j]);
22773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      blue_map[i][j]=(unsigned char *) RelinquishMagickMemory(blue_map[i][j]);
22783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      red_map[i][j]=(unsigned char *) RelinquishMagickMemory(red_map[i][j]);
22793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
22803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
22813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
22823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
22833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
22853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
22863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
22873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X D r a w I m a g e                                                       %
22883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
22893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
22903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
22913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
22933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XDrawImage() draws a line on the image.
22943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
22953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XDrawImage method is:
22963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
22976710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    MagickBooleanType XDrawImage(Display *display,const XPixelInfo *pixel,
22986710d8414f0ed06e4eaf9346366be72e2b4719efcristy%      XDrawInfo *draw_info,Image *image,ExceptionInfo *exception)
22993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
23003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
23013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
23023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
23033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
23043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
23053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o pixel: Specifies a pointer to a XPixelInfo structure.
23063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
23073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o draw_info: Specifies a pointer to a XDrawInfo structure.
23083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
23093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
23103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
23116710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    o exception: return any errors or warnings in this structure.
23126710d8414f0ed06e4eaf9346366be72e2b4719efcristy%
23133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
2314bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate MagickBooleanType XDrawImage(Display *display,
23156710d8414f0ed06e4eaf9346366be72e2b4719efcristy  const XPixelInfo *pixel,XDrawInfo *draw_info,Image *image,
23166710d8414f0ed06e4eaf9346366be72e2b4719efcristy  ExceptionInfo *exception)
23173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
2318c57f694b2d04975a0e501613e34368c464708c19cristy  CacheView
2319c57f694b2d04975a0e501613e34368c464708c19cristy    *draw_view;
2320c57f694b2d04975a0e501613e34368c464708c19cristy
23213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  GC
23223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    draw_context;
23233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
23243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Image
23253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *draw_image;
23263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
23273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
23283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x,
23293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y;
23303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
23313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickBooleanType
23323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    matte;
23333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
23342ed42f6d7c2245432767ea446742977ee87e963ccristy  Quantum
23355f95f4f77efc46ff53593d750491c8f60698c983cristy    virtual_pixel[CompositePixelChannel];
23362ed42f6d7c2245432767ea446742977ee87e963ccristy
23373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Pixmap
23383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    draw_pixmap;
23393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
23403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
23413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    depth,
23423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    height,
23433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    width;
23443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
23453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
23463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root_window;
23473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
23483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XGCValues
23493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    context_values;
23503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
23513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XImage
23523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *draw_ximage;
23533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
23543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
23553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize drawd image.
23563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
23573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
23583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(pixel != (XPixelInfo *) NULL);
23593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(draw_info != (XDrawInfo *) NULL);
23603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image != (Image *) NULL);
23613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image->debug != MagickFalse)
23623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
23633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
23643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize drawd pixmap.
23653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
23663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  root_window=XRootWindow(display,XDefaultScreen(display));
23673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
23683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  draw_pixmap=XCreatePixmap(display,root_window,draw_info->width,
23693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    draw_info->height,depth);
23703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_pixmap == (Pixmap) NULL)
23713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
23723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
23733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize graphics info.
23743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
2375bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  context_values.background=(size_t) (~0);
23763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  context_values.foreground=0;
23773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  context_values.line_width=(int) draw_info->line_width;
2378bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  draw_context=XCreateGC(display,root_window,(size_t)
23793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (GCBackground | GCForeground | GCLineWidth),&context_values);
23803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_context == (GC) NULL)
23813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
23823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
23833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Clear pixmap.
23843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
23853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
23863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    draw_info->height);
23873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
23883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Draw line to pixmap.
23893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
23903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSetBackground(display,draw_context,0);
2391bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  (void) XSetForeground(display,draw_context,(size_t) (~0));
2392dd05bebf92311ac0db88ae24d6a6862a4729e8a5cristy  if (draw_info->stipple !=  (Pixmap) NULL)
2393dd05bebf92311ac0db88ae24d6a6862a4729e8a5cristy    {
2394dd05bebf92311ac0db88ae24d6a6862a4729e8a5cristy      (void) XSetFillStyle(display,draw_context,FillOpaqueStippled);
2395dd05bebf92311ac0db88ae24d6a6862a4729e8a5cristy      (void) XSetStipple(display,draw_context,draw_info->stipple);
2396dd05bebf92311ac0db88ae24d6a6862a4729e8a5cristy    }
23973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  switch (draw_info->element)
23983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
23993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case PointElement:
24003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    default:
24013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
24023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDrawLines(display,draw_pixmap,draw_context,
24033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        draw_info->coordinate_info,(int) draw_info->number_coordinates,
24043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        CoordModeOrigin);
24053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
24063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
24073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case LineElement:
24083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
24093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
24103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        draw_info->line_info.y1,draw_info->line_info.x2,
24113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        draw_info->line_info.y2);
24123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
24133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
24143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case RectangleElement:
24153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
24163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDrawRectangle(display,draw_pixmap,draw_context,
24173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
24183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) draw_info->rectangle_info.width,
24193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) draw_info->rectangle_info.height);
24203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
24213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
24223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case FillRectangleElement:
24233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
24243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFillRectangle(display,draw_pixmap,draw_context,
24253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
24263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) draw_info->rectangle_info.width,
24273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) draw_info->rectangle_info.height);
24283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
24293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
24303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case CircleElement:
24313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case EllipseElement:
24323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
24333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDrawArc(display,draw_pixmap,draw_context,
24343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
24353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) draw_info->rectangle_info.width,
24363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) draw_info->rectangle_info.height,0,360*64);
24373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
24383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
24393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case FillCircleElement:
24403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case FillEllipseElement:
24413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
24423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFillArc(display,draw_pixmap,draw_context,
24433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
24443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) draw_info->rectangle_info.width,
24453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) draw_info->rectangle_info.height,0,360*64);
24463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
24473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
24483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case PolygonElement:
24493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
24503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XPoint
24513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *coordinate_info;
24523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
24533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      coordinate_info=draw_info->coordinate_info;
24543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
24553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (int) draw_info->number_coordinates,CoordModeOrigin);
24563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDrawLine(display,draw_pixmap,draw_context,
24573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        coordinate_info[draw_info->number_coordinates-1].x,
24583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        coordinate_info[draw_info->number_coordinates-1].y,
24593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        coordinate_info[0].x,coordinate_info[0].y);
24603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
24613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
24623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case FillPolygonElement:
24633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
24643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFillPolygon(display,draw_pixmap,draw_context,
24653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        draw_info->coordinate_info,(int) draw_info->number_coordinates,Complex,
24663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        CoordModeOrigin);
24673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
24683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
24693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
24703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFreeGC(display,draw_context);
24713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
24723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize X image.
24733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
24743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  draw_ximage=XGetImage(display,draw_pixmap,0,0,draw_info->width,
24753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    draw_info->height,AllPlanes,ZPixmap);
24763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_ximage == (XImage *) NULL)
24773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
24783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFreePixmap(display,draw_pixmap);
24793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
24803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize draw image.
24813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
24826710d8414f0ed06e4eaf9346366be72e2b4719efcristy  draw_image=AcquireImage((ImageInfo *) NULL,exception);
24833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_image == (Image *) NULL)
24843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
24853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  draw_image->columns=draw_info->width;
24863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  draw_image->rows=draw_info->height;
24873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
24883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Transfer drawn X image to image.
24893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
24903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  width=(unsigned int) image->columns;
24913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  height=(unsigned int) image->rows;
24923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=0;
24933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y=0;
24943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
24952ed42f6d7c2245432767ea446742977ee87e963ccristy  (void) GetOneVirtualPixel(image,(ssize_t) x,(ssize_t) y,virtual_pixel,
24966710d8414f0ed06e4eaf9346366be72e2b4719efcristy    exception);
2497e42f658533644aecb733785ffd91b286d6778deacristy  draw_image->background_color.red=(double) virtual_pixel[RedPixelChannel];
2498e42f658533644aecb733785ffd91b286d6778deacristy  draw_image->background_color.green=(double) virtual_pixel[GreenPixelChannel];
2499e42f658533644aecb733785ffd91b286d6778deacristy  draw_image->background_color.blue=(double) virtual_pixel[BluePixelChannel];
2500e42f658533644aecb733785ffd91b286d6778deacristy  draw_image->background_color.alpha=(double) virtual_pixel[AlphaPixelChannel];
25016710d8414f0ed06e4eaf9346366be72e2b4719efcristy  if (SetImageStorageClass(draw_image,DirectClass,exception) == MagickFalse)
25023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
25033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  draw_image->matte=MagickTrue;
2504c57f694b2d04975a0e501613e34368c464708c19cristy  draw_view=AcquireCacheView(draw_image);
25053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (y=0; y < (int) draw_image->rows; y++)
25063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
2507c57f694b2d04975a0e501613e34368c464708c19cristy    register int
25083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      x;
25093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
25104c08aed51c5899665ade97263692328eea4af106cristy    register Quantum
2511c47d1f8ecfe7d04f0f003cca0fe175658bbf0fb2cristy      *restrict q;
25123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2513c57f694b2d04975a0e501613e34368c464708c19cristy    q=QueueCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,
2514c57f694b2d04975a0e501613e34368c464708c19cristy      1,exception);
2515acd2ed254c18c254a0ab5aafa06d1645e5d079d8cristy    if (q == (Quantum *) NULL)
25163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
2517c57f694b2d04975a0e501613e34368c464708c19cristy    for (x=0; x < (int) draw_image->columns; x++)
25183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
25193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (XGetPixel(draw_ximage,x,y) == 0)
25203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
25213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
25223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Set this pixel to the background color.
25233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
2524803640d20a6a664315eddfff6f8531d0c5e0871dcristy          SetPixelInfoPixel(draw_image,&draw_image->background_color,q);
25257676158e6c207e287beb252c9837d565863c3328cristy          SetPixelAlpha(draw_image,(Quantum) (draw_info->stencil ==
25264c08aed51c5899665ade97263692328eea4af106cristy            OpaqueStencil ? TransparentAlpha : OpaqueAlpha),q);
25273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
25283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
25293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
25303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
25313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Set this pixel to the pen color.
25323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
25334c08aed51c5899665ade97263692328eea4af106cristy          SetPixelRed(draw_image,ScaleShortToQuantum(
25344c08aed51c5899665ade97263692328eea4af106cristy            pixel->pen_color.red),q);
25354c08aed51c5899665ade97263692328eea4af106cristy          SetPixelGreen(draw_image,ScaleShortToQuantum(
25364c08aed51c5899665ade97263692328eea4af106cristy            pixel->pen_color.green),q);
25374c08aed51c5899665ade97263692328eea4af106cristy          SetPixelBlue(draw_image,ScaleShortToQuantum(
25384c08aed51c5899665ade97263692328eea4af106cristy            pixel->pen_color.blue),q);
25394c08aed51c5899665ade97263692328eea4af106cristy          SetPixelAlpha(draw_image,(Quantum) (draw_info->stencil ==
25404c08aed51c5899665ade97263692328eea4af106cristy            OpaqueStencil ? OpaqueAlpha : TransparentAlpha),q);
25413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
2542ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy      q+=GetPixelChannels(draw_image);
25433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
2544c57f694b2d04975a0e501613e34368c464708c19cristy    if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
25453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
25463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
2547c57f694b2d04975a0e501613e34368c464708c19cristy  draw_view=DestroyCacheView(draw_view);
25483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XDestroyImage(draw_ximage);
25493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
25503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Determine draw geometry.
25513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
25523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
25533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((width != (unsigned int) draw_image->columns) ||
25543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (height != (unsigned int) draw_image->rows))
25553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
25563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      char
25573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        image_geometry[MaxTextExtent];
25583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
25593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
25603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Scale image.
25613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
2562b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy      (void) FormatLocaleString(image_geometry,MaxTextExtent,"%ux%u",
25633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        width,height);
2564e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy      (void) TransformImage(&draw_image,(char *) NULL,image_geometry,
2565e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy        exception);
25663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
25673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_info->degrees != 0.0)
25683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
25693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Image
25703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *rotate_image;
25713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
25723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      int
25733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        rotations;
25743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
25753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      MagickRealType
25763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        normalized_degrees;
25773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
25783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
25793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Rotate image.
25803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
25816710d8414f0ed06e4eaf9346366be72e2b4719efcristy      rotate_image=RotateImage(draw_image,draw_info->degrees,exception);
25823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (rotate_image == (Image *) NULL)
25833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        return(MagickFalse);
25843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      draw_image=DestroyImage(draw_image);
25853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      draw_image=rotate_image;
25863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
25873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Annotation is relative to the degree of rotation.
25883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
25893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      normalized_degrees=draw_info->degrees;
25903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      while (normalized_degrees < -45.0)
25913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        normalized_degrees+=360.0;
25923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (rotations=0; normalized_degrees > 45.0; rotations++)
25933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        normalized_degrees-=90.0;
25943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      switch (rotations % 4)
25953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
25963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        default:
25973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 0:
25983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
25993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 1:
26003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
26013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
26023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Rotate 90 degrees.
26033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
26043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          x=x-(int) draw_image->columns/2;
26053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          y=y+(int) draw_image->columns/2;
26063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
26073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
26083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 2:
26093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
26103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
26113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Rotate 180 degrees.
26123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
26133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          x=x-(int) draw_image->columns;
26143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
26153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
26163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 3:
26173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
26183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
26193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Rotate 270 degrees.
26203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
26213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          x=x-(int) draw_image->columns/2;
26223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          y=y-(int) (draw_image->rows-(draw_image->columns/2));
26233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
26243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
26253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
26263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
26273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
26283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Composite text onto the image.
26293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
2630c57f694b2d04975a0e501613e34368c464708c19cristy  draw_view=AcquireCacheView(draw_image);
26313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (y=0; y < (int) draw_image->rows; y++)
26323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
2633c57f694b2d04975a0e501613e34368c464708c19cristy    register int
26343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      x;
26353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
26364c08aed51c5899665ade97263692328eea4af106cristy    register Quantum
2637c47d1f8ecfe7d04f0f003cca0fe175658bbf0fb2cristy      *restrict q;
26383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2639c57f694b2d04975a0e501613e34368c464708c19cristy    q=GetCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,1,
2640c57f694b2d04975a0e501613e34368c464708c19cristy      exception);
2641acd2ed254c18c254a0ab5aafa06d1645e5d079d8cristy    if (q == (Quantum *) NULL)
26423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
2643c57f694b2d04975a0e501613e34368c464708c19cristy    for (x=0; x < (int) draw_image->columns; x++)
26443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
26454c08aed51c5899665ade97263692328eea4af106cristy      if (GetPixelAlpha(image,q) != TransparentAlpha)
26464c08aed51c5899665ade97263692328eea4af106cristy        SetPixelAlpha(draw_image,OpaqueAlpha,q);
2647ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy      q+=GetPixelChannels(draw_image);
26483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
2649c57f694b2d04975a0e501613e34368c464708c19cristy    if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
26503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
26513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
2652c57f694b2d04975a0e501613e34368c464708c19cristy  draw_view=DestroyCacheView(draw_view);
26533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
26543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_info->stencil == TransparentStencil)
2655e4a404711bf20d9062d11ab28bc12e5acd307f9ccristy    (void) CompositeImage(image,CopyAlphaCompositeOp,draw_image,(ssize_t) x,
2656e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy      (ssize_t) y,exception);
26573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
26583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
26593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      matte=image->matte;
2660c57f694b2d04975a0e501613e34368c464708c19cristy      (void) CompositeImage(image,OverCompositeOp,draw_image,(ssize_t) x,
2661e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy        (ssize_t) y,exception);
26623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image->matte=matte;
26633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
26643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  draw_image=DestroyImage(draw_image);
26653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickTrue);
26663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
26673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
26683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
26693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
26713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
26723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
26733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X E r r o r                                                               %
26743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
26753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
26763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
26773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
26793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XError() ignores BadWindow errors for XQueryTree and XGetWindowAttributes,
26803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  and ignores BadDrawable errors for XGetGeometry, and ignores BadValue errors
2681bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristy%  for XQueryColor.  It returns MagickFalse in those cases.  Otherwise it
2682bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristy%  returns True.
26833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
26843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XError function is:
26853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2686bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristy%      int XError(display,error)
26873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
26883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
26893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
26903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a pointer to the Display structure;  returned from
26913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
26923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
26933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o error: Specifies the error event.
26943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
26953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
26963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
26973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__cplusplus) || defined(c_plusplus)
26983ed852eea50f9d4cd633efb8c2b054b8e33c253cristyextern "C" {
26993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
27003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
27013ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport int XError(Display *display,XErrorEvent *error)
27023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
27033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
27043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
27053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(error != (XErrorEvent *) NULL);
27063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  xerror_alert=MagickTrue;
27073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  switch (error->request_code)
27083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
27093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case X_GetGeometry:
27103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
27113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((int) error->error_code == BadDrawable)
27123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        return(MagickFalse);
27133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
27143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
27153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case X_GetWindowAttributes:
27163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case X_QueryTree:
27173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
27183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((int) error->error_code == BadWindow)
27193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        return(MagickFalse);
27203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
27213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
27223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case X_QueryColors:
27233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
27243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((int) error->error_code == BadValue)
27253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        return(MagickFalse);
27263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
27273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
27283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
27293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickTrue);
27303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
27313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
27323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__cplusplus) || defined(c_plusplus)
27333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
27343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
27353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
27363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
27373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
27393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
27403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
27413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X F r e e R e s o u r c e s                                               %
27423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
27433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
27443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
27453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XFreeResources() frees X11 resources.
27483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XFreeResources method is:
27503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XFreeResources(Display *display,XVisualInfo *visual_info,
27523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
27533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XResourceInfo *resource_info,XWindowInfo *window_info)
27543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        resource_info,window_info)
27553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
27573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
27593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
27603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
27623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      returned from XGetVisualInfo.
27633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o map_info: If map_type is specified, this structure is initialized
27653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      with info from the Standard Colormap.
27663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o pixel: Specifies a pointer to a XPixelInfo structure.
27683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o font_info: Specifies a pointer to a XFontStruct structure.
27703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
27723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window_info: Specifies a pointer to a X11 XWindowInfo structure.
27743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
2776bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XFreeResources(Display *display,XVisualInfo *visual_info,
27773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
27783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XResourceInfo *resource_info,XWindowInfo *window_info)
27793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
27803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
27813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
27823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
27833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info != (XWindowInfo *) NULL)
27843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
27853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
27863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Free X image.
27873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
27883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window_info->ximage != (XImage *) NULL)
27893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XDestroyImage(window_info->ximage);
27903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window_info->id != (Window) NULL)
27913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
27923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
27933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Free destroy window and free cursors.
27943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
27953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (window_info->id != XRootWindow(display,visual_info->screen))
27963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) XDestroyWindow(display,window_info->id);
27973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (window_info->annotate_context != (GC) NULL)
27983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) XFreeGC(display,window_info->annotate_context);
27993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (window_info->highlight_context != (GC) NULL)
28003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) XFreeGC(display,window_info->highlight_context);
28013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (window_info->widget_context != (GC) NULL)
28023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) XFreeGC(display,window_info->widget_context);
28033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (window_info->cursor != (Cursor) NULL)
28043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) XFreeCursor(display,window_info->cursor);
28053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window_info->cursor=(Cursor) NULL;
28063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (window_info->busy_cursor != (Cursor) NULL)
28073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) XFreeCursor(display,window_info->busy_cursor);
28083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window_info->busy_cursor=(Cursor) NULL;
28093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
28103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
28113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
28123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Free font.
28133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
28143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (font_info != (XFontStruct *) NULL)
2815aafc19213cef0b96cd237edb693a33fd1a2466eacristy    {
2816aafc19213cef0b96cd237edb693a33fd1a2466eacristy      (void) XFreeFont(display,font_info);
2817aafc19213cef0b96cd237edb693a33fd1a2466eacristy      font_info=(XFontStruct *) NULL;
2818aafc19213cef0b96cd237edb693a33fd1a2466eacristy    }
28193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (map_info != (XStandardColormap *) NULL)
28203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
28213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
28223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Free X Standard Colormap.
28233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
28243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (resource_info->map_type == (char *) NULL)
28253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
28263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFree((void *) map_info);
28273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
28283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
28293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Free X visual info.
28303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
28313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (visual_info != (XVisualInfo *) NULL)
28323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XFree((void *) visual_info);
28333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->close_server != MagickFalse)
28343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XCloseDisplay(display);
28353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
28363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
28373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
28383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
28403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
28413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
28423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X F r e e S t a n d a r d C o l o r m a p                                 %
28433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
28443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
28453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
28463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XFreeStandardColormap() frees an X11 colormap.
28493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XFreeStandardColormap method is:
28513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XFreeStandardColormap(Display *display,
28533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const XVisualInfo *visual_info,XStandardColormap *map_info,
28543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XPixelInfo *pixel)
28553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
28573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
28593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
28603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
28623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      returned from XGetVisualInfo.
28633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o map_info: If map_type is specified, this structure is initialized
28653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      with info from the Standard Colormap.
28663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o pixel: Specifies a pointer to a XPixelInfo structure.
28683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
2870bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XFreeStandardColormap(Display *display,
28713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
28723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
28733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
28743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Free colormap.
28753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
28763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
28773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
28783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(visual_info != (XVisualInfo *) NULL);
28793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(map_info != (XStandardColormap *) NULL);
28803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFlush(display);
28813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (map_info->colormap != (Colormap) NULL)
28823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
28833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
28843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreeColormap(display,map_info->colormap);
28853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
28863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (pixel != (XPixelInfo *) NULL)
28873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((visual_info->klass != TrueColor) &&
28883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (visual_info->klass != DirectColor))
28893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) XFreeColors(display,map_info->colormap,pixel->pixels,
28903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (int) pixel->colors,0);
28913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
28923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  map_info->colormap=(Colormap) NULL;
28933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (pixel != (XPixelInfo *) NULL)
28943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
2895f2faecf9facdbbb14fcba373365f9f691a9658e0cristy      if (pixel->pixels != (unsigned long *) NULL)
2896f2faecf9facdbbb14fcba373365f9f691a9658e0cristy        pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
2897f2faecf9facdbbb14fcba373365f9f691a9658e0cristy      pixel->pixels=(unsigned long *) NULL;
28983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
28993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
29003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
29013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
29023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t A n n o t a t e I n f o                                           %
29073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetAnnotateInfo() initializes the AnnotateInfo structure.
29133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetAnnotateInfo method is:
29153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
29173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
29193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
29213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
2923bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
29243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
29253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
29263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize annotate structure.
29273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
29283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
29293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(annotate_info != (XAnnotateInfo *) NULL);
29303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->x=0;
29313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->y=0;
29323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->width=0;
29333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->height=0;
29343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->stencil=ForegroundStencil;
29353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->degrees=0.0;
29363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->font_info=(XFontStruct *) NULL;
29373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->text=(char *) NULL;
29383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  *annotate_info->geometry='\0';
29393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->previous=(XAnnotateInfo *) NULL;
29403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->next=(XAnnotateInfo *) NULL;
29413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSupportsLocale();
29423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSetLocaleModifiers("");
29433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
29443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
29453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
29463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t M a p I n f o                                                     %
29513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetMapInfo() initializes the XStandardColormap structure.
29573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XStandardColormap method is:
29593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XGetMapInfo(const XVisualInfo *visual_info,const Colormap colormap,
29613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XStandardColormap *map_info)
29623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
29643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o colormap: Specifies the ID of the X server colormap.
29663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
29683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      returned from XGetVisualInfo.
29693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o map_info: Specifies a pointer to a X11 XStandardColormap structure.
29713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
2973bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XGetMapInfo(const XVisualInfo *visual_info,
29743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const Colormap colormap,XStandardColormap *map_info)
29753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
29763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
29773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize map info.
29783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
29793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
29803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(visual_info != (XVisualInfo *) NULL);
29813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(map_info != (XStandardColormap *) NULL);
29823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  map_info->colormap=colormap;
29833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  map_info->red_max=visual_info->red_mask;
2984bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  map_info->red_mult=(size_t) (map_info->red_max != 0 ? 1 : 0);
29853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (map_info->red_max != 0)
29863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    while ((map_info->red_max & 0x01) == 0)
29873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
29883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      map_info->red_max>>=1;
29893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      map_info->red_mult<<=1;
29903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
29913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  map_info->green_max=visual_info->green_mask;
2992bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  map_info->green_mult=(size_t) (map_info->green_max != 0 ? 1 : 0);
29933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (map_info->green_max != 0)
29943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    while ((map_info->green_max & 0x01) == 0)
29953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
29963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      map_info->green_max>>=1;
29973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      map_info->green_mult<<=1;
29983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
29993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  map_info->blue_max=visual_info->blue_mask;
3000bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  map_info->blue_mult=(size_t) (map_info->blue_max != 0 ? 1 : 0);
30013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (map_info->blue_max != 0)
30023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    while ((map_info->blue_max & 0x01) == 0)
30033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
30043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      map_info->blue_max>>=1;
30053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      map_info->blue_mult<<=1;
30063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
30073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  map_info->base_pixel=0;
30083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
30093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
30103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
30113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
30133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
30143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
30153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t P i x e l I n f o                                                 %
30163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
30173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
30183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
30193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
30203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3021101ab708b0574518ac5715da4d3915400e9df79acristy%  XGetPixelInfo() initializes the PixelInfo structure.
30223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
30234c08aed51c5899665ade97263692328eea4af106cristy%  The format of the XGetPixelInfo method is:
30243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
30254c08aed51c5899665ade97263692328eea4af106cristy%      void XGetPixelInfo(Display *display,const XVisualInfo *visual_info,
30263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const XStandardColormap *map_info,const XResourceInfo *resource_info,
30273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        Image *image,XPixelInfo *pixel)
30283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        pixel)
30293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
30303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
30313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
30323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
30333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
30343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
30353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
30363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      returned from XGetVisualInfo.
30373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
30383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o map_info: If map_type is specified, this structure is initialized
30393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      with info from the Standard Colormap.
30403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
30413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
30423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
30433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
30443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
30453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o pixel: Specifies a pointer to a XPixelInfo structure.
30463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
30473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
3048bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XGetPixelInfo(Display *display,
30493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const XVisualInfo *visual_info,const XStandardColormap *map_info,
30503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const XResourceInfo *resource_info,Image *image,XPixelInfo *pixel)
30513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
30523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static const char
30533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *PenColors[MaxNumberPens]=
30543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
30553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#000000000000",  /* black */
30563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#00000000ffff",  /* blue */
30573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#0000ffffffff",  /* cyan */
30583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#0000ffff0000",  /* green */
30593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#bdbdbdbdbdbd",  /* gray */
30603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#ffff00000000",  /* red */
30613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#ffff0000ffff",  /* magenta */
30623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#ffffffff0000",  /* yellow */
30633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#ffffffffffff",  /* white */
30643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#bdbdbdbdbdbd",  /* gray */
30653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#bdbdbdbdbdbd"   /* gray */
30663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    };
30673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
30683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Colormap
30693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    colormap;
30703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
3071bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  register ssize_t
30723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
30733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
30743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
30753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
30763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
30773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
30783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    packets;
30793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
30803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
30813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize pixel info.
30823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
30833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
30843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
30853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(visual_info != (XVisualInfo *) NULL);
30863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(map_info != (XStandardColormap *) NULL);
30873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
30883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(pixel != (XPixelInfo *) NULL);
30893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->colors=0;
30903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image != (Image *) NULL)
30913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (image->storage_class == PseudoClass)
3092c57f694b2d04975a0e501613e34368c464708c19cristy      pixel->colors=(ssize_t) image->colors;
30933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  packets=(unsigned int)
30943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    MagickMax((int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3095f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  if (pixel->pixels != (unsigned long *) NULL)
3096f2faecf9facdbbb14fcba373365f9f691a9658e0cristy    pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
3097f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  pixel->pixels=(unsigned long *) AcquireQuantumMemory(packets,
30983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    sizeof(pixel->pixels));
3099f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  if (pixel->pixels == (unsigned long *) NULL)
31003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToGetPixelInfo",
31013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image->filename);
31023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
31033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set foreground color.
31043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
31053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  colormap=map_info->colormap;
31063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseColor(display,colormap,(char *) ForegroundColor,
31073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &pixel->foreground_color);
31083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XParseColor(display,colormap,resource_info->foreground_color,
31093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &pixel->foreground_color);
31103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
31113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
31123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      resource_info->foreground_color);
31133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->foreground_color.pixel=
31143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XStandardPixel(map_info,&pixel->foreground_color);
31153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
31163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
31173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set background color.
31183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
31193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseColor(display,colormap,"#d6d6d6d6d6d6",&pixel->background_color);
31203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XParseColor(display,colormap,resource_info->background_color,
31213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &pixel->background_color);
31223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
31233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
31243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      resource_info->background_color);
31253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->background_color.pixel=
31263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XStandardPixel(map_info,&pixel->background_color);
31273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
31283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
31293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set border color.
31303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
31313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseColor(display,colormap,(char *) BorderColor,
31323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &pixel->border_color);
31333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XParseColor(display,colormap,resource_info->border_color,
31343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &pixel->border_color);
31353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
31363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
31373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      resource_info->border_color);
31383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
31393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
31403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
31413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set matte color.
31423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
31433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->matte_color=pixel->background_color;
31443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->matte_color != (char *) NULL)
31453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
31463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
31473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Matte color is specified as a X resource or command line argument.
31483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
31493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      status=XParseColor(display,colormap,resource_info->matte_color,
31503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &pixel->matte_color);
31513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status == False)
31523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
31533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          resource_info->matte_color);
31543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      pixel->matte_color.pixel=XStandardPixel(map_info,&pixel->matte_color);
31553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      pixel->matte_color.flags=(char) (DoRed | DoGreen | DoBlue);
31563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
31573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
31583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set highlight color.
31593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
31603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->highlight_color.red=(unsigned short) ((
31613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel->matte_color.red*ScaleQuantumToShort(HighlightModulate))/65535L+
31623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
31633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->highlight_color.green=(unsigned short) ((
31643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel->matte_color.green*ScaleQuantumToShort(HighlightModulate))/65535L+
31653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
31663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->highlight_color.blue=(unsigned short) ((
31673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel->matte_color.blue*ScaleQuantumToShort(HighlightModulate))/65535L+
31683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
31693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->highlight_color.pixel=
31703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XStandardPixel(map_info,&pixel->highlight_color);
31713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
31723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
31733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set shadow color.
31743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
31753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->shadow_color.red=(unsigned short) (((MagickRealType)
31763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel->matte_color.red*ScaleQuantumToShort(ShadowModulate))/65535L);
31773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->shadow_color.green=(unsigned short) (((MagickRealType)
31783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel->matte_color.green*ScaleQuantumToShort(ShadowModulate))/65535L);
31793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->shadow_color.blue=(unsigned short) (((MagickRealType)
31803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel->matte_color.blue*ScaleQuantumToShort(ShadowModulate))/65535L);
31813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
31823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
31833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
31843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set depth color.
31853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
31863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->depth_color.red=(unsigned short) (((MagickRealType)
31873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel->matte_color.red*ScaleQuantumToShort(DepthModulate))/65535L);
31883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->depth_color.green=(unsigned short) (((MagickRealType)
31893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel->matte_color.green*ScaleQuantumToShort(DepthModulate))/65535L);
31903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->depth_color.blue=(unsigned short) (((MagickRealType)
31913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel->matte_color.blue*ScaleQuantumToShort(DepthModulate))/65535L);
31923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
31933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
31943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
31953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set trough color.
31963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
31973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->trough_color.red=(unsigned short) (((MagickRealType)
31983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel->matte_color.red*ScaleQuantumToShort(TroughModulate))/65535L);
31993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->trough_color.green=(unsigned short) (((MagickRealType)
32003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel->matte_color.green*ScaleQuantumToShort(TroughModulate))/65535L);
32013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->trough_color.blue=(unsigned short) (((MagickRealType)
32023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel->matte_color.blue*ScaleQuantumToShort(TroughModulate))/65535L);
32033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
32043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
32053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
32063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set pen color.
32073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
32083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; i < MaxNumberPens; i++)
32093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
32103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XParseColor(display,colormap,(char *) PenColors[i],
32113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      &pixel->pen_colors[i]);
32123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status=XParseColor(display,colormap,resource_info->pen_colors[i],
32133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      &pixel->pen_colors[i]);
32143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (status == False)
32153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",
32163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        resource_info->pen_colors[i]);
32173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
32183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
32193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
32203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->box_color=pixel->background_color;
32213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->pen_color=pixel->foreground_color;
32223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->box_index=0;
32233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->pen_index=1;
32243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image != (Image *) NULL)
32253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
32263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((resource_info->gamma_correct != MagickFalse) &&
32273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (image->gamma != 0.0))
32283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
32293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          GeometryInfo
32303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            geometry_info;
32313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
32323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          MagickStatusType
32333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            flags;
32343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
32353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
32363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Initialize map relative to display and image gamma.
32373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
32383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          flags=ParseGeometry(resource_info->display_gamma,&geometry_info);
32393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          red_gamma=geometry_info.rho;
32403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          green_gamma=geometry_info.sigma;
32413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((flags & SigmaValue) == 0)
32423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            green_gamma=red_gamma;
32433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          blue_gamma=geometry_info.xi;
32443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((flags & XiValue) == 0)
32453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            blue_gamma=red_gamma;
32463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          red_gamma*=image->gamma;
32473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          green_gamma*=image->gamma;
32483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          blue_gamma*=image->gamma;
32493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
32503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (image->storage_class == PseudoClass)
32513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
32523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
32533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Initialize pixel array for images of type PseudoClass.
32543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
3255bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy          for (i=0; i < (ssize_t) image->colors; i++)
32564c08aed51c5899665ade97263692328eea4af106cristy            pixel->pixels[i]=XGammaPacket(map_info,image->colormap+i);
32573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (i=0; i < MaxNumberPens; i++)
32583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
32593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          pixel->colors+=MaxNumberPens;
32603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
32613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
32623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
32633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
32643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
32653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
32673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
32683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
32693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t R e s o u r c e C l a s s                                         %
32703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
32713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
32723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
32733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
32753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetResourceClass() queries the X server for the specified resource name or
32763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  class.  If the resource name or class is not defined in the database, the
32773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  supplied default value is returned.
32783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
32793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetResourceClass method is:
32803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
32813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      char *XGetResourceClass(XrmDatabase database,const char *client_name,
32823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *keyword,char *resource_default)
32833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
32843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
32853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
32863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o database: Specifies a resource database; returned from
32873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XrmGetStringDatabase.
32883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
32893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o client_name:  Specifies the application name used to retrieve resource
32903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      info from the X server database.
32913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
32923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o keyword: Specifies the keyword of the value being retrieved.
32933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
32943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_default: Specifies the default value to return if the query
32953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      fails to find the specified keyword/class.
32963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
32973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
32983ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport char *XGetResourceClass(XrmDatabase database,
32993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *client_name,const char *keyword,char *resource_default)
33003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
33013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
33023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_class[MaxTextExtent],
33033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_name[MaxTextExtent];
33043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
33053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static char
33063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *resource_type;
33073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
33083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
33093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
33103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
33113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmValue
33123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_value;
33133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
33143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (database == (XrmDatabase) NULL)
33153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(resource_default);
33163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  *resource_name='\0';
33173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  *resource_class='\0';
33183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (keyword != (char *) NULL)
33193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
33203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      int
33213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        c,
33223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        k;
33233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
33243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
33253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Initialize resource keyword and class.
33263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
3327b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy      (void) FormatLocaleString(resource_name,MaxTextExtent,"%s.%s",
33283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        client_name,keyword);
33293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      c=(int) (*client_name);
33303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((c >= XK_a) && (c <= XK_z))
33313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        c-=(XK_a-XK_A);
33323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
33333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if ((c >= XK_agrave) && (c <= XK_odiaeresis))
33343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          c-=(XK_agrave-XK_Agrave);
33353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        else
33363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((c >= XK_oslash) && (c <= XK_thorn))
33373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            c-=(XK_oslash-XK_Ooblique);
33383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      k=(int) (*keyword);
33393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((k >= XK_a) && (k <= XK_z))
33403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        k-=(XK_a-XK_A);
33413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
33423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if ((k >= XK_agrave) && (k <= XK_odiaeresis))
33433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          k-=(XK_agrave-XK_Agrave);
33443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        else
33453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((k >= XK_oslash) && (k <= XK_thorn))
33463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            k-=(XK_oslash-XK_Ooblique);
3347b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy      (void) FormatLocaleString(resource_class,MaxTextExtent,"%c%s.%c%s",c,
33483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        client_name+1,k,keyword+1);
33493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
33503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XrmGetResource(database,resource_name,resource_class,&resource_type,
33513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &resource_value);
33523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
33533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(resource_default);
33543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(resource_value.addr);
33553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
33563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
33573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
33583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
33603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
33613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
33623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t R e s o u r c e D a t a b a s e                                   %
33633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
33643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
33653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
33663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
33683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetResourceDatabase() creates a new resource database and initializes it.
33693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
33703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetResourceDatabase method is:
33713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
33723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XrmDatabase XGetResourceDatabase(Display *display,
33733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *client_name)
33743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
33753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
33763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
33773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o database: XGetResourceDatabase() returns the database after it is
33783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      initialized.
33793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
33803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
33813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
33823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
33833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o client_name:  Specifies the application name used to retrieve resource
33843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      info from the X server database.
33853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
33863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
33873ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport XrmDatabase XGetResourceDatabase(Display *display,
33883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *client_name)
33893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
33903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
33913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    filename[MaxTextExtent];
33923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
33933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
33943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    c;
33953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
33963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register const char
33973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p;
33983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
33993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmDatabase
34003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_database,
34013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    server_database;
34023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
34033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (display == (Display *) NULL)
34043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return((XrmDatabase) NULL);
34053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(client_name != (char *) NULL);
34063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
34073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize resource database.
34083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
34093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmInitialize();
34103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XGetDefault(display,(char *) client_name,"dummy");
34113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_database=XrmGetDatabase(display);
34123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
34133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Combine application database.
34143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
34153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (client_name != (char *) NULL)
34163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
34173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
34183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Get basename of client.
34193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
34203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      p=client_name+(strlen(client_name)-1);
34213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      while ((p > client_name) && (*p != '/'))
34223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        p--;
34233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (*p == '/')
34243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        client_name=p+1;
34253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
34263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  c=(int) (*client_name);
34273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((c >= XK_a) && (c <= XK_z))
34283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    c-=(XK_a-XK_A);
34293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
34303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if ((c >= XK_agrave) && (c <= XK_odiaeresis))
34313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      c-=(XK_agrave-XK_Agrave);
34323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    else
34333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((c >= XK_oslash) && (c <= XK_thorn))
34343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        c-=(XK_oslash-XK_Ooblique);
34353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(X11_APPLICATION_PATH)
3436b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(filename,MaxTextExtent,"%s%c%s",
34373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    X11_APPLICATION_PATH,c,client_name+1);
34383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
34393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
34403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (XResourceManagerString(display) != (char *) NULL)
34413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
34423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
34433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Combine server database.
34443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
34453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      server_database=XrmGetStringDatabase(XResourceManagerString(display));
34463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XrmCombineDatabase(server_database,&resource_database,MagickFalse);
34473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
34483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
34493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Merge user preferences database.
34503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
34513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(X11_PREFERENCES_PATH)
3452b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(filename,MaxTextExtent,"%s%src",
34533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    X11_PREFERENCES_PATH,client_name);
34543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ExpandFilename(filename);
34553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
34563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
34573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(resource_database);
34583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
34593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
34603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
34613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
34633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
34643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
34653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t R e s o u r c e I n f o                                           %
34663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
34673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
34683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
34693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
34713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetResourceInfo(image_info,) initializes the ResourceInfo structure.
34723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
34733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetResourceInfo method is:
34743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
34753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XGetResourceInfo(const ImageInfo *image_info,XrmDatabase database,
34763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *client_name,XResourceInfo *resource_info)
34773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
34783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
34793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
34803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image_info: the image info.
34813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
34823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o database: Specifies a resource database; returned from
34833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XrmGetStringDatabase.
34843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
34853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o client_name:  Specifies the application name used to retrieve
34863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      resource info from the X server database.
34873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
34883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
34893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
34903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
34913ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport void XGetResourceInfo(const ImageInfo *image_info,
34923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmDatabase database,const char *client_name,XResourceInfo *resource_info)
34933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
34943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
349500976d8abcff7a3bc7b986b8105dde8d091dee61cristy    *directory,
34963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *resource_value;
34973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
34983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
34993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize resource info fields.
35003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
35013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
35023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
35033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
35043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->resource_database=database;
35053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->image_info=(ImageInfo *) image_info;
35063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) SetImageInfoProgressMonitor(resource_info->image_info,
35073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XMagickProgressMonitor,(void *) NULL);
35083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
35093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->close_server=MagickTrue;
35103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->client_name=AcquireString(client_name);
35113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"backdrop",
35123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "False");
35133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->backdrop=IsMagickTrue(resource_value);
35143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->background_color=XGetResourceInstance(database,client_name,
35153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "background",(char *) "#d6d6d6d6d6d6");
35163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->border_color=XGetResourceInstance(database,client_name,
35173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "borderColor",BorderColor);
35183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"borderWidth",
35193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "2");
352000976d8abcff7a3bc7b986b8105dde8d091dee61cristy  resource_info->border_width=(unsigned int) StringToUnsignedLong(
352100976d8abcff7a3bc7b986b8105dde8d091dee61cristy    resource_value);
35223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"colormap",
35233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "shared");
35243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->colormap=UndefinedColormap;
35253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (LocaleCompare("private",resource_value) == 0)
35263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_info->colormap=PrivateColormap;
35273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (LocaleCompare("shared",resource_value) == 0)
35283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_info->colormap=SharedColormap;
35293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->colormap == UndefinedColormap)
35303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(OptionError,"UnrecognizedColormapType",
35313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      resource_value);
35323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,
35333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "colorRecovery",(char *) "False");
35343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->color_recovery=IsMagickTrue(resource_value);
35353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"confirmExit",
35363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "False");
35373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->confirm_exit=IsMagickTrue(resource_value);
35383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"confirmEdit",
35393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "False");
35403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->confirm_edit=IsMagickTrue(resource_value);
3541ba0c32599a8e592fffab86dd9b8ee367ca573c22cristy  resource_value=XGetResourceClass(database,client_name,"delay",(char *) "1");
3542e27293e706ca05b6b121e9512a83b16f7ad887f2cristy  resource_info->delay=(unsigned int) StringToUnsignedLong(resource_value);
35433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->display_gamma=XGetResourceClass(database,client_name,
35443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "displayGamma",(char *) "2.2");
35453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"displayWarnings",
35463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "True");
35473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->display_warnings=IsMagickTrue(resource_value);
35483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font=XGetResourceClass(database,client_name,"font",
35493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) NULL);
35503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font=XGetResourceClass(database,client_name,"fontList",
35513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_info->font);
35523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[0]=XGetResourceClass(database,client_name,"font1",
35533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "fixed");
35543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[1]=XGetResourceClass(database,client_name,"font2",
35553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "variable");
35563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[2]=XGetResourceClass(database,client_name,"font3",
35573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "5x8");
35583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[3]=XGetResourceClass(database,client_name,"font4",
35593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "6x10");
35603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[4]=XGetResourceClass(database,client_name,"font5",
35613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "7x13bold");
35623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[5]=XGetResourceClass(database,client_name,"font6",
35633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "8x13bold");
35643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[6]=XGetResourceClass(database,client_name,"font7",
35653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "9x15bold");
35663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[7]=XGetResourceClass(database,client_name,"font8",
35673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "10x20");
35683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[8]=XGetResourceClass(database,client_name,"font9",
35693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "12x24");
35703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[9]=XGetResourceClass(database,client_name,"font0",
35713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "fixed");
35723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[10]=XGetResourceClass(database,client_name,"font0",
35733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "fixed");
35743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->foreground_color=XGetResourceInstance(database,client_name,
35753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "foreground",ForegroundColor);
35763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"gammaCorrect",
35773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "True");
35783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->gamma_correct=IsMagickTrue(resource_value);
35793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->image_geometry=ConstantString(XGetResourceClass(database,
35803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    client_name,"geometry",(char *) NULL));
35813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"gravity",
35823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "Center");
3583042ee78fa9004bf1ac6a95f09d9d1faca631dda1cristy  resource_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
35843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    MagickFalse,resource_value);
358500976d8abcff7a3bc7b986b8105dde8d091dee61cristy  directory=getcwd(resource_info->home_directory,MaxTextExtent);
358600976d8abcff7a3bc7b986b8105dde8d091dee61cristy  (void) directory;
35873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->icon_geometry=XGetResourceClass(database,client_name,
35883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "iconGeometry",(char *) NULL);
35893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"iconic",
35903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "False");
35913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->iconic=IsMagickTrue(resource_value);
35923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"immutable",
35933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    LocaleCompare(client_name,"PerlMagick") == 0 ? (char *) "True" :
35943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "False");
35953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->immutable=IsMagickTrue(resource_value);
35963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"magnify",
35973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "3");
3598e27293e706ca05b6b121e9512a83b16f7ad887f2cristy  resource_info->magnify=(unsigned int) StringToUnsignedLong(resource_value);
35993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->map_type=XGetResourceClass(database,client_name,"map",
36003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) NULL);
36013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->matte_color=XGetResourceInstance(database,client_name,
36023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "mattecolor",(char *) NULL);
36033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->name=ConstantString(XGetResourceClass(database,client_name,
36043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "name",(char *) NULL));
36053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[0]=XGetResourceClass(database,client_name,"pen1",
36063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "black");
36073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[1]=XGetResourceClass(database,client_name,"pen2",
36083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "blue");
36093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[2]=XGetResourceClass(database,client_name,"pen3",
36103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "cyan");
36113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[3]=XGetResourceClass(database,client_name,"pen4",
36123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "green");
36133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[4]=XGetResourceClass(database,client_name,"pen5",
36143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "gray");
36153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[5]=XGetResourceClass(database,client_name,"pen6",
36163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "red");
36173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[6]=XGetResourceClass(database,client_name,"pen7",
36183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "magenta");
36193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[7]=XGetResourceClass(database,client_name,"pen8",
36203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "yellow");
36213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[8]=XGetResourceClass(database,client_name,"pen9",
36223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "white");
36233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[9]=XGetResourceClass(database,client_name,"pen0",
36243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "gray");
36253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[10]=XGetResourceClass(database,client_name,"pen0",
36263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "gray");
36273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"pause",(char *) "0");
3628e27293e706ca05b6b121e9512a83b16f7ad887f2cristy  resource_info->pause=(unsigned int) StringToUnsignedLong(resource_value);
36293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"quantum",(char *) "1");
3630f2f2727f17ecbb23d902f70bb98f81faabc92dbdcristy  resource_info->quantum=StringToLong(resource_value);
36313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->text_font=XGetResourceClass(database,client_name,(char *)
36323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "font",(char *) "fixed");
36333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->text_font=XGetResourceClass(database,client_name,
36343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "textFontList",resource_info->text_font);
36353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->title=XGetResourceClass(database,client_name,"title",
36363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) NULL);
36373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"undoCache",
36383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "16");
3639e27293e706ca05b6b121e9512a83b16f7ad887f2cristy  resource_info->undo_cache=(unsigned int) StringToUnsignedLong(resource_value);
36403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"update",
36413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "False");
36423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->update=IsMagickTrue(resource_value);
36433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"usePixmap",
36443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "True");
36453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->use_pixmap=IsMagickTrue(resource_value);
36463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"sharedMemory",
36473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "True");
36483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->use_shared_memory=IsMagickTrue(resource_value);
36493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->visual_type=XGetResourceClass(database,client_name,"visual",
36503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) NULL);
36513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->window_group=XGetResourceClass(database,client_name,
36523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "windowGroup",(char *) NULL);
36533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->window_id=XGetResourceClass(database,client_name,"window",
36543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) NULL);
36553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->write_filename=XGetResourceClass(database,client_name,
36563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "writeFilename",(char *) NULL);
36573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
36583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
36593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
36603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
36623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
36633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
36643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t R e s o u r c e I n s t a n c e                                   %
36653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
36663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
36673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
36683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
36703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetResourceInstance() queries the X server for the specified resource name.
36713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  If the resource name is not defined in the database, the supplied default
36723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  value is returned.
36733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
36743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetResourceInstance method is:
36753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
36763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      char *XGetResourceInstance(XrmDatabase database,const char *client_name,
36773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *keyword,const char *resource_default)
36783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
36793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
36803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
36813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o database: Specifies a resource database; returned from
36823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XrmGetStringDatabase.
36833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
36843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o client_name:  Specifies the application name used to retrieve
36853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      resource info from the X server database.
36863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
36873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o keyword: Specifies the keyword of the value being retrieved.
36883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
36893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_default: Specifies the default value to return if the query
36903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      fails to find the specified keyword/class.
36913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
36923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
36933ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport char *XGetResourceInstance(XrmDatabase database,
36943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *client_name,const char *keyword,const char *resource_default)
36953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
36963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
36973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *resource_type,
36983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_name[MaxTextExtent];
36993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
37003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
37013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
37023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
37033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmValue
37043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_value;
37053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
37063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (database == (XrmDatabase) NULL)
37073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return((char *) resource_default);
37083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  *resource_name='\0';
37093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (keyword != (char *) NULL)
3710b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleString(resource_name,MaxTextExtent,"%s.%s",client_name,
37113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      keyword);
37123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XrmGetResource(database,resource_name,"ImageMagick",&resource_type,
37133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &resource_value);
37143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
37153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return((char *) resource_default);
37163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(resource_value.addr);
37173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
37183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
37193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
37203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
37223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
37233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
37243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t S c r e e n D e n s i t y                                         %
37253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
37263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
37273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
37283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetScreenDensity() returns the density of the X server screen in
37313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  dots-per-inch.
37323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetScreenDensity method is:
37343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      char *XGetScreenDensity(Display *display)
37363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
37383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o density: XGetScreenDensity() returns the density of the X screen in
37403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      dots-per-inch.
37413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
37433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
37443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
37463ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport char *XGetScreenDensity(Display *display)
37473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
37483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
37493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    density[MaxTextExtent];
37503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
37513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  double
37523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x_density,
37533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y_density;
37543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
37553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
37563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set density as determined by screen size.
37573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
37583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x_density=((((double) DisplayWidth(display,XDefaultScreen(display)))*25.4)/
37593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ((double) DisplayWidthMM(display,XDefaultScreen(display))));
37603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y_density=((((double) DisplayHeight(display,XDefaultScreen(display)))*25.4)/
37613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ((double) DisplayHeightMM(display,XDefaultScreen(display))));
3762b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(density,MaxTextExtent,"%gx%g",x_density,
37638cd5b3193212b4aebce08c4e7afbb66b09778029cristy    y_density);
37643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(GetPageGeometry(density));
37653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
37663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
37673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
37683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
37703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
37713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
37723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy+   X G e t S u b w i n d o w                                                 %
37733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
37743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
37753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
37763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetSubwindow() returns the subwindow of a window chosen the user with the
37793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  pointer and a button press.
37803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetSubwindow method is:
37823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      Window XGetSubwindow(Display *display,Window window,int x,int y)
37843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
37863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o subwindow: XGetSubwindow() returns NULL if no subwindow is found
37883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      otherwise the subwindow is returned.
37893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
37913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
37923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a Window.
37943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o x: the x coordinate of the pointer relative to the origin of the
37963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      window.
37973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o y: the y coordinate of the pointer relative to the origin of the
37993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      window.
38003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
38013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
38023ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Window XGetSubwindow(Display *display,Window window,int x,int y)
38033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
38043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
38053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x_offset,
38063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y_offset;
38073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
38083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
38093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
38103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
38113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
38123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    source_window,
38133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    target_window;
38143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
38153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
38163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  source_window=XRootWindow(display,XDefaultScreen(display));
38173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window == (Window) NULL)
38183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(source_window);
38193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  target_window=window;
38203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for ( ; ; )
38213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
38223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status=XTranslateCoordinates(display,source_window,window,x,y,
38233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      &x_offset,&y_offset,&target_window);
38243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (status != True)
38253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
38263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (target_window == (Window) NULL)
38273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
38283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    source_window=window;
38293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window=target_window;
38303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x=x_offset;
38313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y=y_offset;
38323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
38333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (target_window == (Window) NULL)
38343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    target_window=window;
38353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(target_window);
38363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
38373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
38383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
38393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
38413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
38423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
38433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t W i n d o w C o l o r                                             %
38443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
38453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
38463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
38473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
38493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetWindowColor() returns the color of a pixel interactively chosen from the
38503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  X server.
38513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
38523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetWindowColor method is:
38533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
38543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      MagickBooleanType XGetWindowColor(Display *display,XWindows *windows,
38556710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        char *name,ExceptionInfo *exception)
38563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
38573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
38583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
38593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
38603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
38613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
38623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o windows: Specifies a pointer to a XWindows structure.
38633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
38643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o name: the name of the color if found in the X Color Database is
38653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      returned in this character string.
38663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
38676710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    o exception: return any errors or warnings in this structure.
38686710d8414f0ed06e4eaf9346366be72e2b4719efcristy%
38693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
3870bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate MagickBooleanType XGetWindowColor(Display *display,
38716710d8414f0ed06e4eaf9346366be72e2b4719efcristy  XWindows *windows,char *name,ExceptionInfo *exception)
38723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
38733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
38743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x,
38753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y;
38763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
3877101ab708b0574518ac5715da4d3915400e9df79acristy  PixelInfo
38783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel;
38793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
38803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  RectangleInfo
38813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    crop_info;
38823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
38833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
38843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
38853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
38863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
38873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    child,
38883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    client_window,
38893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root_window,
38903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    target_window;
38913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
38923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XColor
38933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    color;
38943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
38953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XImage
38963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *ximage;
38973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
38983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XWindowAttributes
38993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window_attributes;
39003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
39013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
39023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Choose a pixel from the X server.
39033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
39043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
39053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(name != (char *) NULL);
39063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
39073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  *name='\0';
39083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  target_window=XSelectWindow(display,&crop_info);
39093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (target_window == (Window) NULL)
39103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
39113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  root_window=XRootWindow(display,XDefaultScreen(display));
39123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  client_window=target_window;
39133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (target_window != root_window)
39143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
39153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      unsigned int
39163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        d;
39173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
39183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
39193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Get client window.
39203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
39213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      status=XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
39223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status != False)
39233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
39243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          client_window=XClientWindow(display,target_window);
39253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          target_window=client_window;
39263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
39273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
39283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
39293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Verify window is viewable.
39303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
39313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XGetWindowAttributes(display,target_window,&window_attributes);
39323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((status == False) || (window_attributes.map_state != IsViewable))
39333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
39343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
39353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Get window X image.
39363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
39373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XTranslateCoordinates(display,root_window,target_window,
39383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (int) crop_info.x,(int) crop_info.y,&x,&y,&child);
39393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ximage=XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
39403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (ximage == (XImage *) NULL)
39413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
39423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  color.pixel=XGetPixel(ximage,0,0);
39433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XDestroyImage(ximage);
39443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
39453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Match color against the color database.
39463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
39473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XQueryColor(display,window_attributes.colormap,&color);
3948e42f658533644aecb733785ffd91b286d6778deacristy  pixel.red=(double) ScaleShortToQuantum(color.red);
3949e42f658533644aecb733785ffd91b286d6778deacristy  pixel.green=(double) ScaleShortToQuantum(color.green);
3950e42f658533644aecb733785ffd91b286d6778deacristy  pixel.blue=(double) ScaleShortToQuantum(color.blue);
39514c08aed51c5899665ade97263692328eea4af106cristy  pixel.alpha=OpaqueAlpha;
39523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) QueryColorname(windows->image.image,&pixel,X11Compliance,name,
39536710d8414f0ed06e4eaf9346366be72e2b4719efcristy    exception);
39543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickTrue);
39553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
39563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
39573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
39583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
39603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
39613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
39623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy+   X G e t W i n d o w I m a g e                                             %
39633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
39643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
39653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
39663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
39683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetWindowImage() reads an image from the target X window and returns it.
39693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetWindowImage() optionally descends the window hierarchy and overlays the
39703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  target image with each child image in an optimized fashion.  Any child
39713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  window that have the same visual, colormap, and are contained by its parent
39723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  are exempted.
39733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
39743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetWindowImage method is:
39753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
39763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      Image *XGetWindowImage(Display *display,const Window window,
39776710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        const unsigned int borders,const unsigned int level,
39786710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        ExceptionInfo *exception)
39793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
39803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
39813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
39823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
39833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
39843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
39853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies the window to obtain the image from.
39863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
39873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o borders: Specifies whether borders pixels are to be saved with
39883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      the image.
39893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
39903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o level: Specifies an unsigned integer representing the level of
39913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      decent in the window hierarchy.  This value must be zero or one on
39923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      the initial call to XGetWindowImage.  A value of zero returns after
39933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      one call.  A value of one causes the function to descend the window
39943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      hierarchy and overlay the target image with each subwindow image.
39953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
39966710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    o exception: return any errors or warnings in this structure.
39976710d8414f0ed06e4eaf9346366be72e2b4719efcristy%
39983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
39993ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Image *XGetWindowImage(Display *display,const Window window,
40006710d8414f0ed06e4eaf9346366be72e2b4719efcristy  const unsigned int borders,const unsigned int level,ExceptionInfo *exception)
40013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
40023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  typedef struct _ColormapInfo
40033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
40043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Colormap
40053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      colormap;
40063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XColor
40083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      *colors;
40093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    struct _ColormapInfo
40113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      *next;
40123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  } ColormapInfo;
40133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  typedef struct _WindowInfo
40153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
40163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Window
40173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window,
40183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      parent;
40193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Visual
40213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      *visual;
40223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Colormap
40243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      colormap;
40253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XSegment
40273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      bounds;
40283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    RectangleInfo
40303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      crop_info;
40313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  } WindowInfo;
40323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
40343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    display_height,
40353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    display_width,
40363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    id,
40373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x_offset,
40383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y_offset;
40393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40404c08aed51c5899665ade97263692328eea4af106cristy  Quantum
40414c08aed51c5899665ade97263692328eea4af106cristy    index;
40424c08aed51c5899665ade97263692328eea4af106cristy
40433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  RectangleInfo
40443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    crop_info;
40453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
40473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
40483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static ColormapInfo
40503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *colormap_info = (ColormapInfo *) NULL;
40513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static int
40533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    max_windows = 0,
40543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_windows = 0;
40553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static WindowInfo
40573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *window_info;
40583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
40603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
40613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
40633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    child,
40643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root_window;
40653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XWindowAttributes
40673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window_attributes;
40683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
40703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Verify window is viewable.
40713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
40723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
40733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
40743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XGetWindowAttributes(display,window,&window_attributes);
40753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((status == False) || (window_attributes.map_state != IsViewable))
40763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return((Image *) NULL);
40773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
40783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Cropping rectangle is relative to root window.
40793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
40803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  root_window=XRootWindow(display,XDefaultScreen(display));
40813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XTranslateCoordinates(display,window,root_window,0,0,&x_offset,
40823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &y_offset,&child);
4083bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  crop_info.x=(ssize_t) x_offset;
4084bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  crop_info.y=(ssize_t) y_offset;
4085bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  crop_info.width=(size_t) window_attributes.width;
4086bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  crop_info.height=(size_t) window_attributes.height;
40873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (borders != MagickFalse)
40883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
40893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
40903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Include border in image.
40913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
4092bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      crop_info.x-=(ssize_t) window_attributes.border_width;
4093bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      crop_info.y-=(ssize_t) window_attributes.border_width;
4094bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      crop_info.width+=(size_t) (window_attributes.border_width << 1);
4095bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      crop_info.height+=(size_t) (window_attributes.border_width << 1);
40963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
40973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
40983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Crop to root window.
40993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
41003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (crop_info.x < 0)
41013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
41023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      crop_info.width+=crop_info.x;
41033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      crop_info.x=0;
41043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
41053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (crop_info.y < 0)
41063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
41073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      crop_info.height+=crop_info.y;
41083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      crop_info.y=0;
41093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
41103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  display_width=XDisplayWidth(display,XDefaultScreen(display));
41113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((int) (crop_info.x+crop_info.width) > display_width)
4112bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy    crop_info.width=(size_t) (display_width-crop_info.x);
41133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  display_height=XDisplayHeight(display,XDefaultScreen(display));
41143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((int) (crop_info.y+crop_info.height) > display_height)
4115bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy    crop_info.height=(size_t) (display_height-crop_info.y);
41163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
41173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize window info attributes.
41183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
41193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (number_windows >= max_windows)
41203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
41213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
41223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Allocate or resize window info buffer.
41233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
41243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      max_windows+=1024;
41253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window_info == (WindowInfo *) NULL)
41263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window_info=(WindowInfo *) AcquireQuantumMemory((size_t) max_windows,
41273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          sizeof(*window_info));
41283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
41293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window_info=(WindowInfo *) ResizeQuantumMemory(window_info,(size_t)
41303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          max_windows,sizeof(*window_info));
41313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
41323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info == (WindowInfo *) NULL)
41333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
41343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowFatalException(ResourceLimitError,
41353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "MemoryAllocationFailed","...");
41363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return((Image *) NULL);
41373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
41383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  id=number_windows++;
41393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info[id].window=window;
41403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info[id].visual=window_attributes.visual;
41413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info[id].colormap=window_attributes.colormap;
41423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info[id].bounds.x1=(short) crop_info.x;
41433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info[id].bounds.y1=(short) crop_info.y;
41443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info[id].bounds.x2=(short) (crop_info.x+(int) crop_info.width-1);
41453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info[id].bounds.y2=(short) (crop_info.y+(int) crop_info.height-1);
41463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  crop_info.x-=x_offset;
41473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  crop_info.y-=y_offset;
41483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info[id].crop_info=crop_info;
41493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (level != 0)
41503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
41513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      unsigned int
41523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        number_children;
41533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
41543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Window
41553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *children;
41563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
41573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
41583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Descend the window hierarchy.
41593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
41603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      status=XQueryTree(display,window,&root_window,&window_info[id].parent,
41613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &children,&number_children);
41623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (i=0; i < id; i++)
41633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if ((window_info[i].window == window_info[id].parent) &&
41643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (window_info[i].visual == window_info[id].visual) &&
41653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (window_info[i].colormap == window_info[id].colormap))
41663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
41673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if ((window_info[id].bounds.x1 <= window_info[i].bounds.x1) ||
41683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (window_info[id].bounds.x1 >= window_info[i].bounds.x2) ||
41693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (window_info[id].bounds.y1 <= window_info[i].bounds.y1) ||
41703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (window_info[id].bounds.y1 >= window_info[i].bounds.y2))
41713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
41723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                /*
41733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  Eliminate windows not circumscribed by their parent.
41743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                */
41753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                number_windows--;
41763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                break;
41773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
41783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
41793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((status == True) && (number_children != 0))
41803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
41813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (i=0; i < (int) number_children; i++)
41826710d8414f0ed06e4eaf9346366be72e2b4719efcristy            (void) XGetWindowImage(display,children[i],MagickFalse,level+1,
41836710d8414f0ed06e4eaf9346366be72e2b4719efcristy              exception);
41843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) XFree((void *) children);
41853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
41863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
41873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (level <= 1)
41883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
4189c57f694b2d04975a0e501613e34368c464708c19cristy      CacheView
4190c57f694b2d04975a0e501613e34368c464708c19cristy        *composite_view;
4191c57f694b2d04975a0e501613e34368c464708c19cristy
41923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ColormapInfo
41933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *next;
41943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
41953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Image
41963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *composite_image,
41973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *image;
41983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
41993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      int
42003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        y;
42013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
42023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      MagickBooleanType
42033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        import;
42043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
42053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      register int
42063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        j,
42073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        x;
42083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
42094c08aed51c5899665ade97263692328eea4af106cristy      register Quantum
4210c47d1f8ecfe7d04f0f003cca0fe175658bbf0fb2cristy        *restrict q;
42113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4212bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      register size_t
42133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        pixel;
42143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
42153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      unsigned int
42163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        number_colors;
42173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
42183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XColor
42193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *colors;
42203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
42213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XImage
42223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *ximage;
42233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
42243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
42253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Get X image for each window in the list.
42263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
42273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image=NewImageList();
42283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (id=0; id < number_windows; id++)
42293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
42303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
42313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Does target window intersect top level window?
42323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
42333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        import=
42343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
42353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy           (window_info[id].bounds.x1 <= window_info[0].bounds.x2) &&
42363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy           (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
42373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy           (window_info[id].bounds.y1 <= window_info[0].bounds.y2)) ?
42383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          MagickTrue : MagickFalse;
42393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
42403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Is target window contained by another window with the same colormap?
42413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
42423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        for (j=0; j < id; j++)
42433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((window_info[id].visual == window_info[j].visual) &&
42443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (window_info[id].colormap == window_info[j].colormap))
42453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
42463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if ((window_info[id].bounds.x1 <= window_info[j].bounds.x1) ||
42473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  (window_info[id].bounds.x1 >= window_info[j].bounds.x2) ||
42483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  (window_info[id].bounds.y1 <= window_info[j].bounds.y1) ||
42493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  (window_info[id].bounds.y1 >= window_info[j].bounds.y2))
42503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  import=MagickFalse;
42513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
42523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          else
42533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if ((window_info[id].visual != window_info[j].visual) ||
42543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (window_info[id].colormap != window_info[j].colormap))
42553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
42563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if ((window_info[id].bounds.x2 > window_info[j].bounds.x1) &&
42573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    (window_info[id].bounds.x1 < window_info[j].bounds.x2) &&
42583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    (window_info[id].bounds.y2 > window_info[j].bounds.y1) &&
42593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    (window_info[id].bounds.y1 < window_info[j].bounds.y2))
42603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  import=MagickTrue;
42613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
42623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (import == MagickFalse)
42633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          continue;
42643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
42653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Get X image.
42663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
42673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage=XGetImage(display,window_info[id].window,(int)
42683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window_info[id].crop_info.x,(int) window_info[id].crop_info.y,
42693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (unsigned int) window_info[id].crop_info.width,(unsigned int)
42703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window_info[id].crop_info.height,AllPlanes,ZPixmap);
42713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (ximage == (XImage *) NULL)
42723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          continue;
42733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
42743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Initialize window colormap.
42753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
42763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        number_colors=0;
42773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        colors=(XColor *) NULL;
42783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (window_info[id].colormap != (Colormap) NULL)
42793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
42803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            ColormapInfo
42813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *p;
42823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
42833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
42843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Search colormap list for window colormap.
42853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
42863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            number_colors=(unsigned int) window_info[id].visual->map_entries;
42873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (p=colormap_info; p != (ColormapInfo *) NULL; p=p->next)
42883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (p->colormap == window_info[id].colormap)
42893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                break;
42903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (p == (ColormapInfo *) NULL)
42913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
42923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                /*
42933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  Get the window colormap.
42943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                */
42953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                colors=(XColor *) AcquireQuantumMemory(number_colors,
42963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  sizeof(*colors));
42973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if (colors == (XColor *) NULL)
42983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
42993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    XDestroyImage(ximage);
43003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    return((Image *) NULL);
43013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
43023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if ((window_info[id].visual->klass != DirectColor) &&
43033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    (window_info[id].visual->klass != TrueColor))
43043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  for (i=0; i < (int) number_colors; i++)
43053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
4306bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy                    colors[i].pixel=(size_t) i;
43073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    colors[i].pad='\0';
43083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
43093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                else
43103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
4311bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy                    size_t
43123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      blue,
43133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      blue_bit,
43143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      green,
43153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      green_bit,
43163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      red,
43173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      red_bit;
43183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
43193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    /*
43203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      DirectColor or TrueColor visual.
43213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    */
43223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    red=0;
43233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    green=0;
43243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    blue=0;
43253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    red_bit=window_info[id].visual->red_mask &
43263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      (~(window_info[id].visual->red_mask)+1);
43273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    green_bit=window_info[id].visual->green_mask &
43283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      (~(window_info[id].visual->green_mask)+1);
43293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    blue_bit=window_info[id].visual->blue_mask &
43303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      (~(window_info[id].visual->blue_mask)+1);
43313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    for (i=0; i < (int) number_colors; i++)
43323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
43338891f9ce489d3e61399b60436ea6c62f5ed9b887cristy                      colors[i].pixel=(unsigned long) (red | green | blue);
43343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      colors[i].pad='\0';
43353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      red+=red_bit;
43363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      if (red > window_info[id].visual->red_mask)
43373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        red=0;
43383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      green+=green_bit;
43393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      if (green > window_info[id].visual->green_mask)
43403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        green=0;
43413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      blue+=blue_bit;
43423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      if (blue > window_info[id].visual->blue_mask)
43433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        blue=0;
43443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
43453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
43463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (void) XQueryColors(display,window_info[id].colormap,colors,
43473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  (int) number_colors);
43483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                /*
43493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  Append colormap to colormap list.
43503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                */
435173bd4a51b419e914565bdf204bf1540dc4c8ee26cristy                p=(ColormapInfo *) AcquireMagickMemory(sizeof(*p));
43523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if (p == (ColormapInfo *) NULL)
43533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  return((Image *) NULL);
43543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                p->colormap=window_info[id].colormap;
43553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                p->colors=colors;
43563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                p->next=colormap_info;
43573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                colormap_info=p;
43583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
43593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            colors=p->colors;
43603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
43613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
43623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Allocate image structure.
43633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
43646710d8414f0ed06e4eaf9346366be72e2b4719efcristy        composite_image=AcquireImage((ImageInfo *) NULL,exception);
43653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (composite_image == (Image *) NULL)
43663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
43673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            XDestroyImage(ximage);
43683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            return((Image *) NULL);
43693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
43703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
43713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Convert X image to MIFF format.
43723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
43733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if ((window_info[id].visual->klass != TrueColor) &&
43743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (window_info[id].visual->klass != DirectColor))
43753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          composite_image->storage_class=PseudoClass;
4376bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        composite_image->columns=(size_t) ximage->width;
4377bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        composite_image->rows=(size_t) ximage->height;
4378c57f694b2d04975a0e501613e34368c464708c19cristy        composite_view=AcquireCacheView(composite_image);
43793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        switch (composite_image->storage_class)
43803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
43813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          case DirectClass:
43823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          default:
43833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
4384bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            register size_t
43853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              color,
43863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              index;
43873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4388bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            size_t
43893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              blue_mask,
43903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              blue_shift,
43913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              green_mask,
43923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              green_shift,
43933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              red_mask,
43943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              red_shift;
43953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
43963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
43973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Determine shift and mask for red, green, and blue.
43983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
43993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            red_mask=window_info[id].visual->red_mask;
44003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            red_shift=0;
44013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            while ((red_mask != 0) && ((red_mask & 0x01) == 0))
44023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
44033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              red_mask>>=1;
44043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              red_shift++;
44053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
44063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            green_mask=window_info[id].visual->green_mask;
44073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            green_shift=0;
44083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            while ((green_mask != 0) && ((green_mask & 0x01) == 0))
44093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
44103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              green_mask>>=1;
44113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              green_shift++;
44123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
44133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            blue_mask=window_info[id].visual->blue_mask;
44143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            blue_shift=0;
44153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
44163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
44173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              blue_mask>>=1;
44183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              blue_shift++;
44193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
44203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
44213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Convert X image to DirectClass packets.
44223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
44233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if ((number_colors != 0) &&
44243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (window_info[id].visual->klass == DirectColor))
44253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (y=0; y < (int) composite_image->rows; y++)
44263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
4427c57f694b2d04975a0e501613e34368c464708c19cristy                q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
44283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  composite_image->columns,1,exception);
4429acd2ed254c18c254a0ab5aafa06d1645e5d079d8cristy                if (q == (Quantum *) NULL)
44303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
44313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (x=0; x < (int) composite_image->columns; x++)
44323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
44333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  pixel=XGetPixel(ximage,x,y);
44343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  index=(pixel >> red_shift) & red_mask;
44354c08aed51c5899665ade97263692328eea4af106cristy                  SetPixelRed(composite_image,
44364c08aed51c5899665ade97263692328eea4af106cristy                    ScaleShortToQuantum(colors[index].red),q);
44373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  index=(pixel >> green_shift) & green_mask;
44384c08aed51c5899665ade97263692328eea4af106cristy                  SetPixelGreen(composite_image,
44394c08aed51c5899665ade97263692328eea4af106cristy                    ScaleShortToQuantum(colors[index].green),q);
44403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  index=(pixel >> blue_shift) & blue_mask;
44414c08aed51c5899665ade97263692328eea4af106cristy                  SetPixelBlue(composite_image,
44424c08aed51c5899665ade97263692328eea4af106cristy                    ScaleShortToQuantum(colors[index].blue),q);
4443ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                  q+=GetPixelChannels(composite_image);
44443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
44450b1a797184d12984eb55d950fb5f532298d9fd0fcristy                status=SyncCacheViewAuthenticPixels(composite_view,exception);
44460b1a797184d12984eb55d950fb5f532298d9fd0fcristy                if (status == MagickFalse)
44473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
44483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
44493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            else
44503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (y=0; y < (int) composite_image->rows; y++)
44513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
4452c57f694b2d04975a0e501613e34368c464708c19cristy                q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
44533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  composite_image->columns,1,exception);
4454acd2ed254c18c254a0ab5aafa06d1645e5d079d8cristy                if (q == (Quantum *) NULL)
44553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
44563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (x=0; x < (int) composite_image->columns; x++)
44573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
44583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  pixel=XGetPixel(ximage,x,y);
44593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  color=(pixel >> red_shift) & red_mask;
44603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  color=(65535UL*color)/red_mask;
44614c08aed51c5899665ade97263692328eea4af106cristy                  SetPixelRed(composite_image,
44624c08aed51c5899665ade97263692328eea4af106cristy                    ScaleShortToQuantum((unsigned short) color),q);
44633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  color=(pixel >> green_shift) & green_mask;
44643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  color=(65535UL*color)/green_mask;
44654c08aed51c5899665ade97263692328eea4af106cristy                  SetPixelGreen(composite_image,
44664c08aed51c5899665ade97263692328eea4af106cristy                    ScaleShortToQuantum((unsigned short) color),q);
44673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  color=(pixel >> blue_shift) & blue_mask;
44683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  color=(65535UL*color)/blue_mask;
44694c08aed51c5899665ade97263692328eea4af106cristy                  SetPixelBlue(composite_image,
44704c08aed51c5899665ade97263692328eea4af106cristy                    ScaleShortToQuantum((unsigned short) color),q);
4471ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                  q+=GetPixelChannels(composite_image);
44723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
44730b1a797184d12984eb55d950fb5f532298d9fd0fcristy                status=SyncCacheViewAuthenticPixels(composite_view,exception);
44740b1a797184d12984eb55d950fb5f532298d9fd0fcristy                if (status == MagickFalse)
44753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
44763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
44773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            break;
44783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
44793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          case PseudoClass:
44803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
44813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
44823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Create colormap.
44833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
44840b1a797184d12984eb55d950fb5f532298d9fd0fcristy            status=AcquireImageColormap(composite_image,number_colors,
44850b1a797184d12984eb55d950fb5f532298d9fd0fcristy              exception);
44860b1a797184d12984eb55d950fb5f532298d9fd0fcristy            if (status == MagickFalse)
44873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
44883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                XDestroyImage(ximage);
44893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                composite_image=DestroyImage(composite_image);
44903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                return((Image *) NULL);
44913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
44923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (i=0; i < (int) composite_image->colors; i++)
44933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
4494e42f658533644aecb733785ffd91b286d6778deacristy              composite_image->colormap[colors[i].pixel].red=(double)
44953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                ScaleShortToQuantum(colors[i].red);
4496e42f658533644aecb733785ffd91b286d6778deacristy              composite_image->colormap[colors[i].pixel].green=(double)
44973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                ScaleShortToQuantum(colors[i].green);
4498e42f658533644aecb733785ffd91b286d6778deacristy              composite_image->colormap[colors[i].pixel].blue=(double)
44993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                ScaleShortToQuantum(colors[i].blue);
45003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
45013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
45023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Convert X image to PseudoClass packets.
45033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
45043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (y=0; y < (int) composite_image->rows; y++)
45053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
4506c57f694b2d04975a0e501613e34368c464708c19cristy              q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4507c57f694b2d04975a0e501613e34368c464708c19cristy                composite_image->columns,1,exception);
4508acd2ed254c18c254a0ab5aafa06d1645e5d079d8cristy              if (q == (Quantum *) NULL)
45093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                break;
45103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (x=0; x < (int) composite_image->columns; x++)
45113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
45124c08aed51c5899665ade97263692328eea4af106cristy                index=(Quantum) XGetPixel(ximage,x,y);
45134c08aed51c5899665ade97263692328eea4af106cristy                SetPixelIndex(composite_image,index,q);
4514803640d20a6a664315eddfff6f8531d0c5e0871dcristy                SetPixelInfoPixel(composite_image,
45154c08aed51c5899665ade97263692328eea4af106cristy                  composite_image->colormap+(ssize_t) index,q);
4516ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                q+=GetPixelChannels(composite_image);
45173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
45180b1a797184d12984eb55d950fb5f532298d9fd0fcristy              status=SyncCacheViewAuthenticPixels(composite_view,exception);
45190b1a797184d12984eb55d950fb5f532298d9fd0fcristy              if (status == MagickFalse)
45203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                break;
45213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
45223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            break;
45233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
45243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
4525c57f694b2d04975a0e501613e34368c464708c19cristy        composite_view=DestroyCacheView(composite_view);
45263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XDestroyImage(ximage);
45273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (image == (Image *) NULL)
45283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
45293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            image=composite_image;
45303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            continue;
45313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
45323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
45333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Composite any children in back-to-front order.
45343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
45353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XTranslateCoordinates(display,window_info[id].window,window,0,0,
45363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          &x_offset,&y_offset,&child);
45373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        x_offset-=(int) crop_info.x;
45383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (x_offset < 0)
45393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          x_offset=0;
45403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        y_offset-=(int) crop_info.y;
45413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (y_offset < 0)
45423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          y_offset=0;
4543c57f694b2d04975a0e501613e34368c464708c19cristy        (void) CompositeImage(image,CopyCompositeOp,composite_image,(ssize_t)
4544e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy          x_offset,(ssize_t) y_offset,exception);
45453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
45463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
45473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Relinquish resources.
45483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
45493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      while (colormap_info != (ColormapInfo *) NULL)
45503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
45513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        next=colormap_info->next;
4552e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy        colormap_info->colors=(XColor *) RelinquishMagickMemory(
4553e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy          colormap_info->colors);
45543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        colormap_info=(ColormapInfo *) RelinquishMagickMemory(colormap_info);
45553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        colormap_info=next;
45563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
45573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
45583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Relinquish resources and restore initial state.
45593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
45603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_info=(WindowInfo *) RelinquishMagickMemory(window_info);
45613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      max_windows=0;
45623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      number_windows=0;
45633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      colormap_info=(ColormapInfo *) NULL;
45643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(image);
45653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
45663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return((Image *) NULL);
45673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
45683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
45693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
45703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
45723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
45733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
45743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t W i n d o w I n f o                                               %
45753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
45763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
45773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
45783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
45803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetWindowInfo() initializes the XWindowInfo structure.
45813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
45823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetWindowInfo method is:
45833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
45843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
45853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
45863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XResourceInfo *resource_info,XWindowInfo *window)
45873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        resource_info,window)
45883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
45893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
45903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
45913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
45923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
45933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
45943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
45953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      returned from XGetVisualInfo.
45963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
45973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o map_info: If map_type is specified, this structure is initialized
45983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      with info from the Standard Colormap.
45993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
46003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o pixel: Specifies a pointer to a XPixelInfo structure.
46013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
46023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o font_info: Specifies a pointer to a XFontStruct structure.
46033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
46043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
46053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
46063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
4607bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
46083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
46093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XResourceInfo *resource_info,XWindowInfo *window)
46103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
46113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
46123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize window info.
46133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
46143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
46153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
46163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(visual_info != (XVisualInfo *) NULL);
46173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(map_info != (XStandardColormap *) NULL);
46183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(pixel != (XPixelInfo *) NULL);
46193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
46203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (XWindowInfo *) NULL);
46213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->id != (Window) NULL)
46223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
46233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->cursor != (Cursor) NULL)
46243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreeCursor(display,window->cursor);
46253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->busy_cursor != (Cursor) NULL)
46263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreeCursor(display,window->busy_cursor);
46273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->highlight_stipple != (Pixmap) NULL)
46283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreePixmap(display,window->highlight_stipple);
46293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->shadow_stipple != (Pixmap) NULL)
46303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreePixmap(display,window->shadow_stipple);
46313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->name == (char *) NULL)
46323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window->name=AcquireString("");
46333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->icon_name == (char *) NULL)
46343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window->icon_name=AcquireString("");
46353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
46363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
46373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
46383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
46393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Initialize these attributes just once.
46403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
46413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->id=(Window) NULL;
46423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->name == (char *) NULL)
46433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window->name=AcquireString("");
46443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->icon_name == (char *) NULL)
46453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window->icon_name=AcquireString("");
46463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->x=XDisplayWidth(display,visual_info->screen) >> 1;
46473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->y=XDisplayWidth(display,visual_info->screen) >> 1;
46483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->ximage=(XImage *) NULL;
46493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->matte_image=(XImage *) NULL;
46503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->pixmap=(Pixmap) NULL;
46513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->matte_pixmap=(Pixmap) NULL;
46523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->mapped=MagickFalse;
46533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->stasis=MagickFalse;
46543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->shared_memory=MagickTrue;
46553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->segment_info=(void *) NULL;
46563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
46573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
46583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XShmSegmentInfo
46593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          *segment_info;
46603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
46613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (window->segment_info == (void *) NULL)
46623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window->segment_info=AcquireQuantumMemory(2,sizeof(*segment_info));
46633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        segment_info=(XShmSegmentInfo *) window->segment_info;
46643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        segment_info[0].shmid=(-1);
46653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        segment_info[0].shmaddr=(char *) NULL;
46663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        segment_info[1].shmid=(-1);
46673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        segment_info[1].shmaddr=(char *) NULL;
46683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
46693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
46703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
46713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
46723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize these attributes every time function is called.
46733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
46743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->screen=visual_info->screen;
46753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->root=XRootWindow(display,visual_info->screen);
46763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->visual=visual_info->visual;
46773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->storage_class=(unsigned int) visual_info->klass;
46783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->depth=(unsigned int) visual_info->depth;
46793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->visual_info=visual_info;
46803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->map_info=map_info;
46813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->pixel_info=pixel;
46823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->font_info=font_info;
46833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->cursor=XCreateFontCursor(display,XC_left_ptr);
46843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->busy_cursor=XCreateFontCursor(display,XC_watch);
46853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->geometry=(char *) NULL;
46863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->icon_geometry=(char *) NULL;
46873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->icon_geometry != (char *) NULL)
46883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) CloneString(&window->icon_geometry,resource_info->icon_geometry);
46893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->crop_geometry=(char *) NULL;
4690bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  window->flags=(size_t) PSize;
46913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->width=1;
46923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->height=1;
46933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->min_width=1;
46943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->min_height=1;
46953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->width_inc=1;
46963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->height_inc=1;
46973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->border_width=resource_info->border_width;
46983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->annotate_context=pixel->annotate_context;
46993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->highlight_context=pixel->highlight_context;
47003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->widget_context=pixel->widget_context;
47013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->shadow_stipple=(Pixmap) NULL;
47023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->highlight_stipple=(Pixmap) NULL;
47033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->use_pixmap=MagickTrue;
47043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->immutable=MagickFalse;
47053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->shape=MagickFalse;
47063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->data=0;
4707c57f694b2d04975a0e501613e34368c464708c19cristy  window->mask=(int) (CWBackingStore | CWBackPixel | CWBackPixmap |
47083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
47093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
47103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.background_pixel=pixel->background_color.pixel;
47113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.background_pixmap=(Pixmap) NULL;
47123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.bit_gravity=ForgetGravity;
47133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.backing_store=WhenMapped;
47143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.save_under=MagickTrue;
47153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.border_pixel=pixel->border_color.pixel;
47163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.colormap=map_info->colormap;
47173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.cursor=window->cursor;
47183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.do_not_propagate_mask=NoEventMask;
47193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.event_mask=NoEventMask;
47203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.override_redirect=MagickFalse;
47213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.win_gravity=NorthWestGravity;
47223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->orphan=MagickFalse;
47233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
47243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
47253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
47263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X H i g h l i g h t E l l i p s e                                         %
47313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XHighlightEllipse() puts a border on the X server around a region defined by
47373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  highlight_info.
47383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XHighlightEllipse method is:
47403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XHighlightEllipse(Display *display,Window window,
47423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        GC annotate_context,const RectangleInfo *highlight_info)
47433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
47453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
47473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
47483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a Window structure.
47503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o annotate_context: Specifies a pointer to a GC structure.
47523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o highlight_info: Specifies a pointer to a RectangleInfo structure.  It
47543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      contains the extents of any highlighting rectangle.
47553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
4757bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XHighlightEllipse(Display *display,Window window,
47583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  GC annotate_context,const RectangleInfo *highlight_info)
47593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
47603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
47613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
47623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (Window) NULL);
47633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(annotate_context != (GC) NULL);
47643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(highlight_info != (RectangleInfo *) NULL);
47653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((highlight_info->width < 4) || (highlight_info->height < 4))
47663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
47673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x,
47683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (int) highlight_info->y,(unsigned int) highlight_info->width-1,
47693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (unsigned int) highlight_info->height-1,0,360*64);
47703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x+1,
47713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
47723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (unsigned int) highlight_info->height-3,0,360*64);
47733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
47743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
47753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
47763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X H i g h l i g h t L i n e                                               %
47813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XHighlightLine() puts a border on the X server around a region defined by
47873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  highlight_info.
47883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XHighlightLine method is:
47903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XHighlightLine(Display *display,Window window,GC annotate_context,
47923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const XSegment *highlight_info)
47933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
47953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
47973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
47983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a Window structure.
48003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o annotate_context: Specifies a pointer to a GC structure.
48023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o highlight_info: Specifies a pointer to a RectangleInfo structure.  It
48043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      contains the extents of any highlighting rectangle.
48053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
4807bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XHighlightLine(Display *display,Window window,
48083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  GC annotate_context,const XSegment *highlight_info)
48093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
48103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
48113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
48123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (Window) NULL);
48133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(annotate_context != (GC) NULL);
48143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(highlight_info != (XSegment *) NULL);
48153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XDrawLine(display,window,annotate_context,highlight_info->x1,
48163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    highlight_info->y1,highlight_info->x2,highlight_info->y2);
48173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
48183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
48193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
48203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
48223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
48233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
48243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X H i g h l i g h t R e c t a n g l e                                     %
48253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
48263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
48273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
48283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XHighlightRectangle() puts a border on the X server around a region defined
48313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  by highlight_info.
48323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XHighlightRectangle method is:
48343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XHighlightRectangle(Display *display,Window window,
48363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        GC annotate_context,const RectangleInfo *highlight_info)
48373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
48393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
48413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
48423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a Window structure.
48443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o annotate_context: Specifies a pointer to a GC structure.
48463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o highlight_info: Specifies a pointer to a RectangleInfo structure.  It
48483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      contains the extents of any highlighting rectangle.
48493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
4851bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XHighlightRectangle(Display *display,Window window,
48523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  GC annotate_context,const RectangleInfo *highlight_info)
48533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
48543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
48553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
48563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (Window) NULL);
48573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(annotate_context != (GC) NULL);
48583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(highlight_info != (RectangleInfo *) NULL);
48593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((highlight_info->width < 4) || (highlight_info->height < 4))
48603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
48613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x,
48623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (int) highlight_info->y,(unsigned int) highlight_info->width-1,
48633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (unsigned int) highlight_info->height-1);
48643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x+
48653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    1,(int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
48663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (unsigned int) highlight_info->height-3);
48673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
48683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
48693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
48703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
48723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
48733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
48743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X I m p o r t I m a g e                                                   %
48753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
48763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
48773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
48783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XImportImage() reads an image from an X window.
48813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XImportImage method is:
48833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48846710d8414f0ed06e4eaf9346366be72e2b4719efcristy%      Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info,
48856710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        ExceptionInfo *exception)
48863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
48883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image_info: the image info.
48903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o ximage_info: Specifies a pointer to an XImportInfo structure.
48923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48936710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    o exception: return any errors or warnings in this structure.
48946710d8414f0ed06e4eaf9346366be72e2b4719efcristy%
48953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
48963ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport Image *XImportImage(const ImageInfo *image_info,
48976710d8414f0ed06e4eaf9346366be72e2b4719efcristy  XImportInfo *ximage_info,ExceptionInfo *exception)
48983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
48993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Colormap
49003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *colormaps;
49013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
49023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Display
49033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *display;
49043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
49053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Image
49063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *image;
49073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
49083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
49093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_colormaps,
49103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_windows,
49113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x;
49123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
49133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  RectangleInfo
49143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    crop_info;
49153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
49163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
49173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
49183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
49193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
49203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *children,
49213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    client,
49223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    prior_target,
49233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root,
49243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    target;
49253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
49263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XTextProperty
49273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window_name;
49283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
49293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
49303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Open X server connection.
49313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
49323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image_info != (const ImageInfo *) NULL);
49333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image_info->signature == MagickSignature);
49343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image_info->debug != MagickFalse)
49353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
49363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info->filename);
49373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(ximage_info != (XImportInfo *) NULL);
49383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  display=XOpenDisplay(image_info->server_name);
49393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (display == (Display *) NULL)
49403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
49413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowFatalException(XServerError,"UnableToOpenXServer",
49423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XDisplayName(image_info->server_name));
49433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return((Image *) NULL);
49443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
49453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
49463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set our forgiving exception handler.
49473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
49483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSetErrorHandler(XError);
49493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
49503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Select target window.
49513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
49523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  crop_info.x=0;
49533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  crop_info.y=0;
49543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  crop_info.width=0;
49553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  crop_info.height=0;
49563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  root=XRootWindow(display,XDefaultScreen(display));
49573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  target=(Window) NULL;
49583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((image_info->filename != (char *) NULL) &&
49593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (*image_info->filename != '\0'))
49603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
49613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare(image_info->filename,"root") == 0)
49623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        target=root;
49633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
49643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
49653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
49663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Select window by ID or name.
49673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
49683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (isdigit((unsigned char) *image_info->filename) != 0)
49693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            target=XWindowByID(display,root,(Window)
49703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              strtol(image_info->filename,(char **) NULL,0));
49713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (target == (Window) NULL)
49723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            target=XWindowByName(display,root,image_info->filename);
49733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (target == (Window) NULL)
49743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            ThrowXWindowFatalException(XServerError,
49753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "NoWindowWithSpecifiedIDExists",image_info->filename);
49763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
49773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
49783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
49793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    If target window is not defined, interactively select one.
49803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
49813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  prior_target=target;
49823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (target == (Window) NULL)
49833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    target=XSelectWindow(display,&crop_info);
49843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (target == (Window) NULL)
49853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
49863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info->filename);
49873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  client=target;   /* obsolete */
49883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (target != root)
49893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
49903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      unsigned int
49913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        d;
49923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
49933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      status=XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
49943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status != False)
49953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
49963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for ( ; ; )
49973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
49983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Window
49993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              parent;
50003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
50013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
50023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Find window manager frame.
50033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
50043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            status=XQueryTree(display,target,&root,&parent,&children,&d);
50053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if ((status != False) && (children != (Window *) NULL))
50063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) XFree((char *) children);
50073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if ((status == False) || (parent == (Window) NULL) ||
50083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (parent == root))
50093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
50103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            target=parent;
50113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
50123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
50133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Get client window.
50143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
50153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          client=XClientWindow(display,target);
50163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (ximage_info->frame == MagickFalse)
50173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            target=client;
50183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((ximage_info->frame == MagickFalse) &&
50193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (prior_target != MagickFalse))
50203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            target=prior_target;
50213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
50223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
50233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (ximage_info->screen)
50243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
50253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      int
50263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        y;
50273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
50283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Window
50293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        child;
50303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
50313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XWindowAttributes
50323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window_attributes;
50333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
50343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
50353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Obtain window image directly from screen.
50363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
50373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      status=XGetWindowAttributes(display,target,&window_attributes);
50383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status == False)
50393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
50403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ThrowXWindowFatalException(XServerError,
50413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            "UnableToReadXWindowAttributes",image_info->filename);
50423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) XCloseDisplay(display);
50433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          return((Image *) NULL);
50443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
50453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XTranslateCoordinates(display,target,root,0,0,&x,&y,&child);
5046c57f694b2d04975a0e501613e34368c464708c19cristy      crop_info.x=(ssize_t) x;
5047c57f694b2d04975a0e501613e34368c464708c19cristy      crop_info.y=(ssize_t) y;
5048bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      crop_info.width=(size_t) window_attributes.width;
5049bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      crop_info.height=(size_t) window_attributes.height;
5050553743c2f2d6c29405dcfab6390a1c505c79fececristy      if (ximage_info->borders != 0)
50513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
50523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
50533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Include border in image.
50543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
50553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          crop_info.x-=window_attributes.border_width;
50563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          crop_info.y-=window_attributes.border_width;
50573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          crop_info.width+=window_attributes.border_width << 1;
50583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          crop_info.height+=window_attributes.border_width << 1;
50593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
50603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      target=root;
50613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
50623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
50633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    If WM_COLORMAP_WINDOWS property is set or multiple colormaps, descend.
50643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
50653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  number_windows=0;
50663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XGetWMColormapWindows(display,target,&children,&number_windows);
50673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((status == True) && (number_windows > 0))
50683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
50693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ximage_info->descend=MagickTrue;
50703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFree ((char *) children);
50713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
50723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  colormaps=XListInstalledColormaps(display,target,&number_colormaps);
50733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (number_colormaps > 0)
50743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
50753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (number_colormaps > 1)
50763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage_info->descend=MagickTrue;
50773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFree((char *) colormaps);
50783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
50793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
50803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Alert the user not to alter the screen.
50813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
50823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (ximage_info->silent == MagickFalse)
50833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XBell(display,0);
50843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
50853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Get image by window id.
50863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
50873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XGrabServer(display);
50883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  image=XGetWindowImage(display,target,ximage_info->borders,
50896710d8414f0ed06e4eaf9346366be72e2b4719efcristy    ximage_info->descend ? 1U : 0U,exception);
50903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XUngrabServer(display);
50913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image == (Image *) NULL)
50923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(XServerError,"UnableToReadXWindowImage",
50933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info->filename)
50943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
50953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
50963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) CopyMagickString(image->filename,image_info->filename,
50973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        MaxTextExtent);
50983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((crop_info.width != 0) && (crop_info.height != 0))
50993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
51003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Image
51013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *clone_image,
51023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *crop_image;
51033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
51043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
51053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Crop image as defined by the cropping rectangle.
51063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
51076710d8414f0ed06e4eaf9346366be72e2b4719efcristy          clone_image=CloneImage(image,0,0,MagickTrue,exception);
51083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (clone_image != (Image *) NULL)
51093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
51106710d8414f0ed06e4eaf9346366be72e2b4719efcristy              crop_image=CropImage(clone_image,&crop_info,exception);
51113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (crop_image != (Image *) NULL)
51123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
51133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  image=DestroyImage(image);
51143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  image=crop_image;
51153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
51163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
51173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
51183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      status=XGetWMName(display,target,&window_name);
51193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status == True)
51203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
51213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((image_info->filename != (char *) NULL) &&
51223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (*image_info->filename == '\0'))
51233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) CopyMagickString(image->filename,(char *) window_name.value,
51243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (size_t) window_name.nitems+1);
51253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) XFree((void *) window_name.value);
51263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
51273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
51283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (ximage_info->silent == MagickFalse)
51293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
51303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
51313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Alert the user we're done.
51323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
51333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XBell(display,0);
51343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XBell(display,0);
51353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
51363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XCloseDisplay(display);
51373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(image);
51383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
51393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
51403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
51413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
51433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
51443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
51453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X I n i t i a l i z e W i n d o w s                                       %
51463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
51473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
51483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
51493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
51513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XInitializeWindows() initializes the XWindows structure.
51523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
51533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XInitializeWindows method is:
51543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
51553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XWindows *XInitializeWindows(Display *display,
51563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XResourceInfo *resource_info)
51573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
51583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
51593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
51603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o windows: XInitializeWindows returns a pointer to a XWindows structure.
51613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
51623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
51633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
51643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
51653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
51663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
51673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
5168bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate XWindows *XInitializeWindows(Display *display,
51693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XResourceInfo *resource_info)
51703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
51713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
51723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root_window;
51733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
51743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XWindows
51753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *windows;
51763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
51773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
51783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Allocate windows structure.
51793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
518073bd4a51b419e914565bdf204bf1540dc4c8ee26cristy  windows=(XWindows *) AcquireMagickMemory(sizeof(*windows));
51813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows == (XWindows *) NULL)
51823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
51833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
51843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "...");
51853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return((XWindows *) NULL);
51863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
51873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ResetMagickMemory(windows,0,sizeof(*windows));
51883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->pixel_info=(XPixelInfo *) AcquireMagickMemory(
51893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    sizeof(*windows->pixel_info));
51903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->icon_pixel=(XPixelInfo *) AcquireMagickMemory(
51913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    sizeof(*windows->icon_pixel));
51923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->icon_resources=(XResourceInfo *) AcquireMagickMemory(
51933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    sizeof(*windows->icon_resources));
51943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((windows->pixel_info == (XPixelInfo *) NULL) ||
51953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (windows->icon_pixel == (XPixelInfo *) NULL) ||
51963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (windows->icon_resources == (XResourceInfo *) NULL))
51973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
51983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
51993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "...");
52003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return((XWindows *) NULL);
52013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
52023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
52033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize windows structure.
52043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
52053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->display=display;
52063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->wm_protocols=XInternAtom(display,"WM_PROTOCOLS",MagickFalse);
52073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->wm_delete_window=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
52083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->wm_take_focus=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
52093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->im_protocols=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
52103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->im_remote_command=
52113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
52123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->im_update_widget=XInternAtom(display,"IM_UPDATE_WIDGET",MagickFalse);
52133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->im_update_colormap=
52143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XInternAtom(display,"IM_UPDATE_COLORMAP",MagickFalse);
52153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->im_former_image=XInternAtom(display,"IM_FORMER_IMAGE",MagickFalse);
52163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->im_next_image=XInternAtom(display,"IM_NEXT_IMAGE",MagickFalse);
52173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->im_retain_colors=XInternAtom(display,"IM_RETAIN_COLORS",MagickFalse);
52183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->im_exit=XInternAtom(display,"IM_EXIT",MagickFalse);
52193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->dnd_protocols=XInternAtom(display,"DndProtocol",MagickFalse);
52200157aeadef2fce908277168097a160a8f15a6952cristy#if defined(MAGICKCORE_WINDOWS_SUPPORT)
52213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSynchronize(display,IsWindows95());
52223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
52233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (IsEventLogging())
52243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
52253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XSynchronize(display,MagickTrue);
52263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"Version: %s",
5227bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        GetMagickVersion((size_t *) NULL));
52283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"Protocols:");
52293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
52303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "  Window Manager: 0x%lx",windows->wm_protocols);
52313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
52323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "    delete window: 0x%lx",windows->wm_delete_window);
52333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"    take focus: 0x%lx",
52343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->wm_take_focus);
52353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  ImageMagick: 0x%lx",
52363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->im_protocols);
52373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
52383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "    remote command: 0x%lx",windows->im_remote_command);
52393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
52403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "    update widget: 0x%lx",windows->im_update_widget);
52413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
52423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "    update colormap: 0x%lx",windows->im_update_colormap);
52433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
52443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "    former image: 0x%lx",windows->im_former_image);
52453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"    next image: 0x%lx",
52463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->im_next_image);
52473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
52483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "    retain colors: 0x%lx",windows->im_retain_colors);
52493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"    exit: 0x%lx",
52503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->im_exit);
52513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  Drag and Drop: 0x%lx",
52523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->dnd_protocols);
52533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
52543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
52553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Allocate standard colormap.
52563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
52573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->map_info=XAllocStandardColormap();
52583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->icon_map=XAllocStandardColormap();
52593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((windows->map_info == (XStandardColormap *) NULL) ||
52603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (windows->icon_map == (XStandardColormap *) NULL))
52613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(ResourceLimitFatalError,
52623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "MemoryAllocationFailed","...");
52633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->map_info->colormap=(Colormap) NULL;
52643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->icon_map->colormap=(Colormap) NULL;
5265f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  windows->pixel_info->pixels=(unsigned long *) NULL;
52663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->pixel_info->annotate_context=(GC) NULL;
52673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->pixel_info->highlight_context=(GC) NULL;
52683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->pixel_info->widget_context=(GC) NULL;
52693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->font_info=(XFontStruct *) NULL;
52703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->icon_pixel->annotate_context=(GC) NULL;
5271f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  windows->icon_pixel->pixels=(unsigned long *) NULL;
52723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
52733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Allocate visual.
52743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
52753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  *windows->icon_resources=(*resource_info);
52763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->icon_resources->visual_type=(char *) "default";
52773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->icon_resources->colormap=SharedColormap;
52783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->visual_info=
52793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XBestVisualInfo(display,windows->map_info,resource_info);
52803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->icon_visual=
52813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
52823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((windows->visual_info == (XVisualInfo *) NULL) ||
52833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (windows->icon_visual == (XVisualInfo *) NULL))
52843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(XServerFatalError,"UnableToGetVisual",
52853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      resource_info->visual_type);
52863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (IsEventLogging())
52873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
52883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"Visual:");
52893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  visual id: 0x%lx",
52903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->visual_info->visualid);
52913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  class: %s",
52923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XVisualClassName(windows->visual_info->klass));
52933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  depth: %d planes",
52943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->visual_info->depth);
52953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
52963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "  size of colormap: %d entries",windows->visual_info->colormap_size);
52973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
52983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "  red, green, blue masks: 0x%lx 0x%lx 0x%lx",
52993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->visual_info->red_mask,windows->visual_info->green_mask,
53003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->visual_info->blue_mask);
53013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
53023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "  significant bits in color: %d bits",
53033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->visual_info->bits_per_rgb);
53043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
53053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
53063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Allocate class and manager hints.
53073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
53083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->class_hints=XAllocClassHint();
53093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->manager_hints=XAllocWMHints();
53103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((windows->class_hints == (XClassHint *) NULL) ||
53113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (windows->manager_hints == (XWMHints *) NULL))
53123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(ResourceLimitFatalError,
53133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "MemoryAllocationFailed","...");
53143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
53153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Determine group leader if we have one.
53163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
53173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  root_window=XRootWindow(display,windows->visual_info->screen);
53183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->group_leader.id=(Window) NULL;
53193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->window_group != (char *) NULL)
53203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
53213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (isdigit((unsigned char) *resource_info->window_group) != 0)
53223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->group_leader.id=XWindowByID(display,root_window,(Window)
53233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          strtol((char *) resource_info->window_group,(char **) NULL,0));
53243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (windows->group_leader.id == (Window) NULL)
53253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->group_leader.id=
53263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          XWindowByName(display,root_window,resource_info->window_group);
53273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
53283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(windows);
53293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
53303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
53313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
53323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X M a k e C u r s o r                                                     %
53373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XMakeCursor() creates a crosshairs X11 cursor.
53433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XMakeCursor method is:
53453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      Cursor XMakeCursor(Display *display,Window window,Colormap colormap,
53473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        char *background_color,char *foreground_color)
53483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
53503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
53523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
53533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies the ID of the window for which the cursor is
53553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      assigned.
53563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o colormap: Specifies the ID of the colormap from which the background
53583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      and foreground color will be retrieved.
53593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o background_color: Specifies the color to use for the cursor background.
53613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o foreground_color: Specifies the color to use for the cursor foreground.
53633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
5365bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate Cursor XMakeCursor(Display *display,Window window,
53663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Colormap colormap,char *background_color,char *foreground_color)
53673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
53683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define scope_height 17
53693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define scope_x_hot 8
53703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define scope_y_hot 8
53713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define scope_width 17
53723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
53733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static const unsigned char
53743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scope_bits[] =
53753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
53763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
53773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
53783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
53793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
53803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
53813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    },
53823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scope_mask_bits[] =
53833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
53843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
53853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
53863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
53873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
53883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
53893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    };
53903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
53913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Cursor
53923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    cursor;
53933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
53943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Pixmap
53953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    mask,
53963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    source;
53973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
53983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XColor
53993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    background,
54003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    foreground;
54013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
54023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
54033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (Window) NULL);
54043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(colormap != (Colormap) NULL);
54053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(background_color != (char *) NULL);
54063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(foreground_color != (char *) NULL);
54073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",background_color);
54083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  source=XCreateBitmapFromData(display,window,(char *) scope_bits,scope_width,
54093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scope_height);
54103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  mask=XCreateBitmapFromData(display,window,(char *) scope_mask_bits,
54113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scope_width,scope_height);
54123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
54133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
54143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowFatalException(XServerError,"UnableToCreatePixmap","...");
54153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return((Cursor) NULL);
54163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
54173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseColor(display,colormap,background_color,&background);
54183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseColor(display,colormap,foreground_color,&foreground);
54193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
54203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scope_x_hot,scope_y_hot);
54213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFreePixmap(display,source);
54223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFreePixmap(display,mask);
54233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(cursor);
54243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
54253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
54263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
54273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
54293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
54303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
54313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X M a k e I m a g e                                                       %
54323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
54333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
54343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
54353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
54373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XMakeImage() creates an X11 image.  If the image size differs from the X11
54383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  image size, the image is first resized.
54393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
54403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XMakeImage method is:
54413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
54423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      MagickBooleanType XMakeImage(Display *display,
54433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5444051718b74ad68f8584cdac01d0192974ec777f1bcristy%        unsigned int width,unsigned int height,ExceptionInfo *exception)
54453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
54463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
54473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
54483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
54493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
54503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
54513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
54523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
54533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a XWindowInfo structure.
54543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
54553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
54563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
54573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o width: Specifies the width in pixels of the rectangular area to
54583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      display.
54593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
54603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o height: Specifies the height in pixels of the rectangular area to
54613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      display.
54623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5463051718b74ad68f8584cdac01d0192974ec777f1bcristy%    o exception: return any errors or warnings in this structure.
5464051718b74ad68f8584cdac01d0192974ec777f1bcristy%
54653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
5466bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate MagickBooleanType XMakeImage(Display *display,
54673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5468051718b74ad68f8584cdac01d0192974ec777f1bcristy  unsigned int width,unsigned int height,ExceptionInfo *exception)
54693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
54703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define CheckOverflowException(length,width,height) \
54713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
54723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
54733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
54743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    depth,
54753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    format;
54763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
54773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_t
54783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    length;
54793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
54803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XImage
54813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *matte_image,
54823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *ximage;
54833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
54843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
54853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
54863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
54873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (XWindowInfo *) NULL);
54883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(width != 0);
54893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(height != 0);
54903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((window->width == 0) || (window->height == 0))
54913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
54923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
54933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Apply user transforms to the image.
54943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
54953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
54963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFlush(display);
54973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  depth=(int) window->depth;
54983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->destroy)
54993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window->image=DestroyImage(window->image);
55003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->image=image;
55013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->destroy=MagickFalse;
55023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->image != (Image *) NULL)
55033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
55043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->crop_geometry != (char *) NULL)
55053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
55063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Image
55073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *crop_image;
55083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
55093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          RectangleInfo
55103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            crop_info;
55113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
55123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
55133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Crop image.
55143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
55153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window->image->page.x=0;
55163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window->image->page.y=0;
55173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) ParsePageGeometry(window->image,window->crop_geometry,
55186710d8414f0ed06e4eaf9346366be72e2b4719efcristy            &crop_info,exception);
55196710d8414f0ed06e4eaf9346366be72e2b4719efcristy          crop_image=CropImage(window->image,&crop_info,exception);
55203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (crop_image != (Image *) NULL)
55213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
55223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (window->image != image)
55233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                window->image=DestroyImage(window->image);
55243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              window->image=crop_image;
55253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              window->destroy=MagickTrue;
55263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
55273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
55283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((width != (unsigned int) window->image->columns) ||
55293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (height != (unsigned int) window->image->rows))
55303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
55313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Image
55323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *resize_image;
55333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
55343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
55353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Resize image.
55363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
55373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          resize_image=NewImageList();
55383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (window->pixel_info->colors != 0)
55396710d8414f0ed06e4eaf9346366be72e2b4719efcristy            resize_image=SampleImage(window->image,width,height,exception);
55403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          else
55416710d8414f0ed06e4eaf9346366be72e2b4719efcristy            resize_image=ThumbnailImage(window->image,width,height,exception);
55423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (resize_image != (Image *) NULL)
55433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
55443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (window->image != image)
55453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                window->image=DestroyImage(window->image);
55463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              window->image=resize_image;
55473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              window->destroy=MagickTrue;
55483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
55493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
55503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      width=(unsigned int) window->image->columns;
5551bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      assert((size_t) width == window->image->columns);
55523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      height=(unsigned int) window->image->rows;
5553bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      assert((size_t) height == window->image->rows);
55543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
55553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
55563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Create X image.
55573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
55583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ximage=(XImage *) NULL;
55593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  format=(depth == 1) ? XYBitmap : ZPixmap;
55603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
55613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->shared_memory != MagickFalse)
55623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
55633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XShmSegmentInfo
55643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *segment_info;
55653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
55663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      segment_info=(XShmSegmentInfo *) window->segment_info;
55673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      segment_info[1].shmid=(-1);
55683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      segment_info[1].shmaddr=(char *) NULL;
55693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ximage=XShmCreateImage(display,window->visual,(unsigned int) depth,format,
55703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (char *) NULL,&segment_info[1],width,height);
55713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (ximage == (XImage *) NULL)
55723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window->shared_memory=MagickFalse;
55733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      length=(size_t) ximage->bytes_per_line*ximage->height;
55743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
55753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window->shared_memory=MagickFalse;
55763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->shared_memory != MagickFalse)
55773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
55783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->shared_memory != MagickFalse)
55793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        segment_info[1].shmaddr=(char *) shmat(segment_info[1].shmid,0,0);
55803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (segment_info[1].shmid < 0)
55813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window->shared_memory=MagickFalse;
55823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->shared_memory != MagickFalse)
55833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
55843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
55853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
55863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (ximage != (XImage *) NULL)
55873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            XDestroyImage(ximage);
55883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ximage=(XImage *) NULL;
55893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (segment_info[1].shmaddr)
55903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
55913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) shmdt(segment_info[1].shmaddr);
55923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              segment_info[1].shmaddr=(char *) NULL;
55933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
55943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (segment_info[1].shmid >= 0)
55953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
55963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
55973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              segment_info[1].shmid=(-1);
55983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
55993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
56003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
56013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
56023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
56033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Allocate X image pixel data.
56043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
56053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
56063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->shared_memory)
56073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
56083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Status
56093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        status;
56103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
56113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XShmSegmentInfo
56123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *segment_info;
56133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
56143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XSync(display,MagickFalse);
56153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      xerror_alert=MagickFalse;
56163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      segment_info=(XShmSegmentInfo *) window->segment_info;
56173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ximage->data=segment_info[1].shmaddr;
56183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      segment_info[1].readOnly=MagickFalse;
56193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      status=XShmAttach(display,&segment_info[1]);
56203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status != False)
56213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XSync(display,MagickFalse);
56223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((status == False) || (xerror_alert != MagickFalse))
56233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
56243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window->shared_memory=MagickFalse;
56253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (status != False)
56263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            XShmDetach(display,&segment_info[1]);
56273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (ximage != (XImage *) NULL)
56283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
56293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ximage->data=NULL;
56303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              XDestroyImage(ximage);
56313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ximage=(XImage *) NULL;
56323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
56333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (segment_info[1].shmid >= 0)
56343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
56353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (segment_info[1].shmaddr != NULL)
56363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (void) shmdt(segment_info[1].shmaddr);
56373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
56383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              segment_info[1].shmid=(-1);
56393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              segment_info[1].shmaddr=(char *) NULL;
56403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
56413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
56423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
56433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
56443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->shared_memory == MagickFalse)
56453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ximage=XCreateImage(display,window->visual,(unsigned int) depth,format,0,
56463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (char *) NULL,width,height,XBitmapPad(display),0);
56473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (ximage == (XImage *) NULL)
56483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
56493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
56503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Unable to create X image.
56513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
56523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,window->id,window->cursor);
56533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(MagickFalse);
56543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
56553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  length=(size_t) ximage->bytes_per_line*ximage->height;
56563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (IsEventLogging())
56573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
56583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"XImage:");
56593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  width, height: %dx%d",
56603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage->width,ximage->height);
56613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  format: %d",
56623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage->format);
56633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  byte order: %d",
56643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage->byte_order);
56653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
56663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "  bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
56673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage->bitmap_bit_order,ximage->bitmap_pad);
56683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  depth: %d",
56693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage->depth);
56703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  bytes per line: %d",
56713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage->bytes_per_line);
56723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  bits per pixel: %d",
56733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage->bits_per_pixel);
56743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
56753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "  red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
56763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage->green_mask,ximage->blue_mask);
56773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
56783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->shared_memory == MagickFalse)
56793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
56803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (ximage->format != XYBitmap)
56813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage->data=(char *) AcquireQuantumMemory((size_t)
56823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ximage->bytes_per_line,(size_t) ximage->height);
56833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
56843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage->data=(char *) AcquireQuantumMemory((size_t)
56853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ximage->bytes_per_line*ximage->depth,(size_t) ximage->height);
56863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
56873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (ximage->data == (char *) NULL)
56883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
56893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
56903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Unable to allocate pixel data.
56913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
56923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XDestroyImage(ximage);
56933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ximage=(XImage *) NULL;
56943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,window->id,window->cursor);
56953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(MagickFalse);
56963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
56973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->ximage != (XImage *) NULL)
56983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
56993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
57003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Destroy previous X image.
57013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
57023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      length=(size_t) window->ximage->bytes_per_line*window->ximage->height;
57033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
57043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->segment_info != (XShmSegmentInfo *) NULL)
57053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
57063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          XShmSegmentInfo
57073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *segment_info;
57083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
57093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          segment_info=(XShmSegmentInfo *) window->segment_info;
57103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (segment_info[0].shmid >= 0)
57113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
57123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) XSync(display,MagickFalse);
57133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) XShmDetach(display,&segment_info[0]);
57143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) XSync(display,MagickFalse);
57153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (segment_info[0].shmaddr != (char *) NULL)
57163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (void) shmdt(segment_info[0].shmaddr);
57173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
57183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              segment_info[0].shmid=(-1);
57193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              segment_info[0].shmaddr=(char *) NULL;
57203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              window->ximage->data=(char *) NULL;
57213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
57223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
57233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
57243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->ximage->data != (char *) NULL)
57253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        free(window->ximage->data);
57263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->ximage->data=(char *) NULL;
57273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XDestroyImage(window->ximage);
57283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->ximage=(XImage *) NULL;
57293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
57303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
57313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->segment_info != (XShmSegmentInfo *) NULL)
57323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
57333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XShmSegmentInfo
57343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *segment_info;
57353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
57363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      segment_info=(XShmSegmentInfo *) window->segment_info;
57373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      segment_info[0]=segment_info[1];
57383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
57393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
57403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->ximage=ximage;
57413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  matte_image=(XImage *) NULL;
57423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((window->shape != MagickFalse) && (window->image != (Image *) NULL))
57433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if ((window->image->matte != MagickFalse) &&
5744c57f694b2d04975a0e501613e34368c464708c19cristy        ((int) width <= XDisplayWidth(display,window->screen)) &&
5745c57f694b2d04975a0e501613e34368c464708c19cristy        ((int) height <= XDisplayHeight(display,window->screen)))
57463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
57473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
57483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Create matte image.
57493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
57503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        matte_image=XCreateImage(display,window->visual,1,XYBitmap,0,
57513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (char *) NULL,width,height,XBitmapPad(display),0);
57523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (IsEventLogging())
57533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
57543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) LogMagickEvent(X11Event,GetMagickModule(),"Matte Image:");
57553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) LogMagickEvent(X11Event,GetMagickModule(),
57563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "  width, height: %dx%d",matte_image->width,matte_image->height);
57573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
57583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (matte_image != (XImage *) NULL)
57593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
57603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
57613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Allocate matte image pixel data.
57623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
57633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            matte_image->data=(char *) AcquireQuantumMemory((size_t)
57643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              matte_image->bytes_per_line*matte_image->depth,
57653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (size_t) matte_image->height);
57663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (matte_image->data == (char *) NULL)
57673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
57683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                XDestroyImage(matte_image);
57693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                matte_image=(XImage *) NULL;
57703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
57713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
57723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
57733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->matte_image != (XImage *) NULL)
57743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
57753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
57763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Free matte image.
57773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
57783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->matte_image->data != (char *) NULL)
57793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        free(window->matte_image->data);
57803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->matte_image->data=(char *) NULL;
57813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XDestroyImage(window->matte_image);
57823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->matte_image=(XImage *) NULL;
57833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
57843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->matte_image=matte_image;
57853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->matte_pixmap != (Pixmap) NULL)
57863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
57873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFreePixmap(display,window->matte_pixmap);
57883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->matte_pixmap=(Pixmap) NULL;
57893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHAPE)
57903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->shape != MagickFalse)
57913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XShapeCombineMask(display,window->id,ShapeBounding,0,0,None,ShapeSet);
57923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
57933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
57943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->stasis=MagickFalse;
57953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
57963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Convert pixels to X image data.
57973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
57983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->image != (Image *) NULL)
57993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
58003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
58013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (ximage->bitmap_bit_order == LSBFirst)))
58023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XMakeImageLSBFirst(resource_info,window,window->image,ximage,
5803e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy          matte_image,exception);
58043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
58053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XMakeImageMSBFirst(resource_info,window,window->image,ximage,
5806e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy          matte_image,exception);
58073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
58083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->matte_image != (XImage *) NULL)
58093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
58103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
58113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Create matte pixmap.
58123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
58133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->matte_pixmap=XCreatePixmap(display,window->id,width,height,1);
58143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->matte_pixmap != (Pixmap) NULL)
58153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
58163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          GC
58173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            graphics_context;
58183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
58193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          XGCValues
58203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            context_values;
58213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
58223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
58233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Copy matte image to matte pixmap.
58243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
58254c08aed51c5899665ade97263692328eea4af106cristy          context_values.background=0;
58264c08aed51c5899665ade97263692328eea4af106cristy          context_values.foreground=1;
58273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          graphics_context=XCreateGC(display,window->matte_pixmap,
5828bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            (size_t) (GCBackground | GCForeground),&context_values);
58293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) XPutImage(display,window->matte_pixmap,graphics_context,
58303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            window->matte_image,0,0,0,0,width,height);
58313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) XFreeGC(display,graphics_context);
58323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHAPE)
58333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (window->shape != MagickFalse)
58343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            XShapeCombineMask(display,window->id,ShapeBounding,0,0,
58353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              window->matte_pixmap,ShapeSet);
58363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
58373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
58383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
58393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XMakePixmap(display,resource_info,window);
58403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
58413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Restore cursor.
58423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
58433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XCheckDefineCursor(display,window->id,window->cursor);
58443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickTrue);
58453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
58463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
58473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
58483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
58503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
58513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
58523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy+   X M a k e I m a g e L S B F i r s t                                       %
58533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
58543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
58553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
58563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
58583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XMakeImageLSBFirst() initializes the pixel data of an X11 Image. The X image
58593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  pixels are copied in least-significant bit and byte first order.  The
58603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  server's scanline pad is respected.  Rather than using one or two general
58613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  cases, many special cases are found here to help speed up the image
58623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  conversion.
58633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
58643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XMakeImageLSBFirst method is:
58653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5866e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy%      void XMakeImageLSBFirst(Display *display,XWindows *windows,
5867e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy%        ExceptionInfo *exception)
58683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
58693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
58703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
58713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
58723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
58733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a XWindowInfo structure.
58743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
58753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
58763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
58773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o ximage: Specifies a pointer to a XImage structure;  returned from
58783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XCreateImage.
58793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
58803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o matte_image: Specifies a pointer to a XImage structure;  returned from
58813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XCreateImage.
58823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5883e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy%    o exception: return any errors or warnings in this structure.
5884e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy%
58853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
58863ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void XMakeImageLSBFirst(const XResourceInfo *resource_info,
5887e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy  const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image,
5888e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy  ExceptionInfo *exception)
58893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
5890c57f694b2d04975a0e501613e34368c464708c19cristy  CacheView
5891c57f694b2d04975a0e501613e34368c464708c19cristy    *canvas_view;
5892c57f694b2d04975a0e501613e34368c464708c19cristy
58933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Image
58943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *canvas;
58953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
58963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
58973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y;
58983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
58994c08aed51c5899665ade97263692328eea4af106cristy  register const Quantum
59003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p;
59013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
59023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
59033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x;
59043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
59053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register unsigned char
59063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *q;
59073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
59083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned char
59093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    bit,
59103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    byte;
59113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
59123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
59133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scanline_pad;
59143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
5915f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  unsigned long
59163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel,
59173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *pixels;
59183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
59193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XStandardColormap
59203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *map_info;
59213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
59223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
59233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (XWindowInfo *) NULL);
59243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image != (Image *) NULL);
59253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image->debug != MagickFalse)
59263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
59273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  canvas=image;
5928bab87c3357f708174fd2d8ab87a0d7dbb3f70e31cristy  if ((window->immutable == MagickFalse) &&
592954666e85e8e3b0eca47d318178a186ebb2901a73cristy      (image->storage_class == DirectClass) && (image->matte != MagickFalse))
59303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
59313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      char
59323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        size[MaxTextExtent];
59333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
59343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Image
59353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *pattern;
59363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
59373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ImageInfo
59383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *image_info;
59393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
59403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info=AcquireImageInfo();
59413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) CopyMagickString(image_info->filename,
59423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        resource_info->image_info->texture != (char *) NULL ?
59433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        resource_info->image_info->texture : "pattern:checkerboard",
59443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        MaxTextExtent);
5945b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy      (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",(double)
5946e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy        image->columns,(double) image->rows);
59473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info->size=ConstantString(size);
59486710d8414f0ed06e4eaf9346366be72e2b4719efcristy      pattern=ReadImage(image_info,exception);
59493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info=DestroyImageInfo(image_info);
59503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (pattern != (Image *) NULL)
59513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
59526710d8414f0ed06e4eaf9346366be72e2b4719efcristy          canvas=CloneImage(image,0,0,MagickTrue,exception);
59533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (canvas != (Image *) NULL)
5954e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy            (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0,
5955e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy              exception);
59563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          pattern=DestroyImage(pattern);
59573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
59583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
59593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
59603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ximage->bits_per_pixel) >> 3));
59613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  map_info=window->map_info;
59623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixels=window->pixel_info->pixels;
59633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  q=(unsigned char *) ximage->data;
59643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=0;
5965c57f694b2d04975a0e501613e34368c464708c19cristy  canvas_view=AcquireCacheView(canvas);
59663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (ximage->format == XYBitmap)
59673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
59683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      register unsigned short
59693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        polarity;
59703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
59713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      unsigned char
59723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        background,
59733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        foreground;
59743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
59753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
59763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Convert canvas to big-endian bitmap.
59773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
59783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      background=(unsigned char)
59793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (XPixelIntensity(&window->pixel_info->foreground_color) <
59803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy         XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
59813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      foreground=(unsigned char)
59823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (XPixelIntensity(&window->pixel_info->background_color) <
59833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy         XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
5984101ab708b0574518ac5715da4d3915400e9df79acristy      polarity=(unsigned short) ((GetPixelInfoIntensity(
59853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
59863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (canvas->colors == 2)
5987101ab708b0574518ac5715da4d3915400e9df79acristy        polarity=GetPixelInfoIntensity(&canvas->colormap[0]) <
5988101ab708b0574518ac5715da4d3915400e9df79acristy          GetPixelInfoIntensity(&canvas->colormap[1]);
59893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (y=0; y < (int) canvas->rows; y++)
59903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
5991c57f694b2d04975a0e501613e34368c464708c19cristy        p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
59926710d8414f0ed06e4eaf9346366be72e2b4719efcristy          exception);
59934c08aed51c5899665ade97263692328eea4af106cristy        if (p == (const Quantum *) NULL)
59943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
59953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        bit=0;
59963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        byte=0;
59973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        for (x=0; x < (int) canvas->columns; x++)
59983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
59993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          byte>>=1;
60004c08aed51c5899665ade97263692328eea4af106cristy          if (GetPixelIndex(canvas,p) == (Quantum) polarity)
60013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            byte|=foreground;
60023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          else
60033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            byte|=background;
60043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          bit++;
60053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (bit == 8)
60063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
60073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *q++=byte;
60083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              bit=0;
60093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              byte=0;
60103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
6011ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy          p+=GetPixelChannels(canvas);
60123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
60133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (bit != 0)
60143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          *q=byte >> (8-bit);
60153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        q+=scanline_pad;
60163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
60173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
60183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
60193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (window->pixel_info->colors != 0)
60203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      switch (ximage->bits_per_pixel)
60213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
60223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 2:
60233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
60243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
60253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble;
60263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
60273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
60283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 2 bit color-mapped X canvas.
60293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
60303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
60313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6032c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
60336710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
60344c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
60353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
60363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble=0;
60373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
60383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
60394c08aed51c5899665ade97263692328eea4af106cristy              pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)] & 0x0f;
60403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              switch (nibble)
60413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
60423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 0:
60433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
60443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=(unsigned char) pixel;
60453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
60463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
60473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
60483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 1:
60493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
60503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 2);
60513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
60523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
60533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
60543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 2:
60553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
60563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 4);
60573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
60583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
60593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
60603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 3:
60613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
60623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 6);
60633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q++;
60643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble=0;
60653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
60663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
60673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
6068ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
60693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
60703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
60713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
60723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
60733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
60743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 4:
60753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
60763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
60773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble;
60783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
60793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
60803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 4 bit color-mapped X canvas.
60813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
60823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
60833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6084c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
60856710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
60864c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
60873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
60883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble=0;
60893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
60903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
60914c08aed51c5899665ade97263692328eea4af106cristy              pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)] & 0xf;
60923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              switch (nibble)
60933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
60943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 0:
60953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
60963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=(unsigned char) pixel;
60973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
60983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
60993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
61003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 1:
61013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
61023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 4);
61033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q++;
61043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble=0;
61053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
61063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
61073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
6108ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
61093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
61103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
61113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
61123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
61133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
61143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 6:
61153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 8:
61163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
61173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
61183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 8 bit color-mapped X canvas.
61193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
61203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (resource_info->color_recovery &&
61213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              resource_info->quantize_info->dither)
61223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
61236710d8414f0ed06e4eaf9346366be72e2b4719efcristy              XDitherImage(canvas,ximage,exception);
61243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
61253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
61263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
61273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6128c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
61296710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
61304c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
61313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
61323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
61333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
61344c08aed51c5899665ade97263692328eea4af106cristy              pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
61353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *q++=(unsigned char) pixel;
6136ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
61373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
61383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
61393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
61403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
61413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
61423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        default:
61433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
61443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register int
61453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            k;
61463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
61473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
61483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            bytes_per_pixel;
61493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
61503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          unsigned char
6151bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            channel[sizeof(size_t)];
61523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
61533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
61543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to multi-byte color-mapped X canvas.
61553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
61563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
61573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
61583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6159c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
61606710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
61614c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
61623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
61633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
61643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
61654c08aed51c5899665ade97263692328eea4af106cristy              pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
61663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (k=0; k < (int) bytes_per_pixel; k++)
61673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
61683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                channel[k]=(unsigned char) pixel;
61693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                pixel>>=8;
61703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
61713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (k=0; k < (int) bytes_per_pixel; k++)
61723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                *q++=channel[k];
6173ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
61743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
61753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
61763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
61773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
61783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
61793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
61803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    else
61813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      switch (ximage->bits_per_pixel)
61823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
61833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 2:
61843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
61853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
61863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble;
61873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
61883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
61893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to contiguous 2 bit continuous-tone X canvas.
61903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
61913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
61923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
61933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble=0;
6194c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
61956710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
61964c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
61973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
61983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
61993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
62004c08aed51c5899665ade97263692328eea4af106cristy              pixel=XGammaPixel(canvas,map_info,p);
62013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              pixel&=0xf;
62023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              switch (nibble)
62033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
62043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 0:
62053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
62063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=(unsigned char) pixel;
62073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
62083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
62093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
62103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 1:
62113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
62123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 2);
62133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
62143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
62153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
62163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 2:
62173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
62183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 4);
62193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
62203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
62213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
62223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 3:
62233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
62243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 6);
62253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q++;
62263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble=0;
62273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
62283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
62293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
6230ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
62313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
62323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
62333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
62343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
62353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
62363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 4:
62373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
62383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
62393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble;
62403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
62413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
62423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to contiguous 4 bit continuous-tone X canvas.
62433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
62443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
62453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6246c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
62476710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
62484c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
62493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
62503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble=0;
62513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
62523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
62534c08aed51c5899665ade97263692328eea4af106cristy              pixel=XGammaPixel(canvas,map_info,p);
62543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              pixel&=0xf;
62553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              switch (nibble)
62563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
62573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 0:
62583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
62593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=(unsigned char) pixel;
62603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
62613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
62623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
62633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 1:
62643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
62653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 4);
62663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q++;
62673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble=0;
62683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
62693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
62703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
6271ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
62723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
62733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
62743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
62753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
62763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
62773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 6:
62783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 8:
62793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
62803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
62813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to contiguous 8 bit continuous-tone X canvas.
62823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
62833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (resource_info->color_recovery &&
62843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              resource_info->quantize_info->dither)
62853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
62866710d8414f0ed06e4eaf9346366be72e2b4719efcristy              XDitherImage(canvas,ximage,exception);
62873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
62883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
62893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
62903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6291c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
62926710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
62934c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
62943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
62953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
62963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
62974c08aed51c5899665ade97263692328eea4af106cristy              pixel=XGammaPixel(canvas,map_info,p);
62983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *q++=(unsigned char) pixel;
6299ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
63003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
63013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
63023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
63033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
63043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
63053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        default:
63063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
63073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
63083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (map_info->green_max == 255) && (map_info->blue_max == 255) &&
63093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
63103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (map_info->blue_mult == 1))
63113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
63123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              /*
63133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                Convert to 32 bit continuous-tone X canvas.
63143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              */
63153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (y=0; y < (int) canvas->rows; y++)
63163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
6317c57f694b2d04975a0e501613e34368c464708c19cristy                p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
63186710d8414f0ed06e4eaf9346366be72e2b4719efcristy                  canvas->columns,1,exception);
63194c08aed51c5899665ade97263692328eea4af106cristy                if (p == (const Quantum *) NULL)
63203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
63213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
63223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    (blue_gamma != 1.0))
63233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
63243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    /*
63253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      Gamma correct canvas.
63263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    */
63273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    for (x=(int) canvas->columns-1; x >= 0; x--)
63283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
6329ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                      *q++=ScaleQuantumToChar(XBlueGamma(
63304c08aed51c5899665ade97263692328eea4af106cristy                        GetPixelBlue(canvas,p)));
6331ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                      *q++=ScaleQuantumToChar(XGreenGamma(
63324c08aed51c5899665ade97263692328eea4af106cristy                        GetPixelGreen(canvas,p)));
6333ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                      *q++=ScaleQuantumToChar(XRedGamma(
63344c08aed51c5899665ade97263692328eea4af106cristy                        GetPixelRed(canvas,p)));
63353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      *q++=0;
6336ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                      p+=GetPixelChannels(canvas);
63373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
63383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    continue;
63393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
63403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (x=(int) canvas->columns-1; x >= 0; x--)
63413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
63424c08aed51c5899665ade97263692328eea4af106cristy                  *q++=ScaleQuantumToChar((Quantum)
63434c08aed51c5899665ade97263692328eea4af106cristy                    GetPixelBlue(canvas,p));
63444c08aed51c5899665ade97263692328eea4af106cristy                  *q++=ScaleQuantumToChar((Quantum)
63454c08aed51c5899665ade97263692328eea4af106cristy                    GetPixelGreen(canvas,p));
63464c08aed51c5899665ade97263692328eea4af106cristy                  *q++=ScaleQuantumToChar((Quantum)
63474c08aed51c5899665ade97263692328eea4af106cristy                    GetPixelRed(canvas,p));
63483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q++=0;
6349ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                  p+=GetPixelChannels(canvas);
63503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
63513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
63523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
63533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          else
63543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
63553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (map_info->green_max == 255) && (map_info->blue_max == 255) &&
63563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
63573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (map_info->blue_mult == 65536L))
63583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
63593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                /*
63603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  Convert to 32 bit continuous-tone X canvas.
63613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                */
63623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (y=0; y < (int) canvas->rows; y++)
63633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
6364c57f694b2d04975a0e501613e34368c464708c19cristy                  p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
63656710d8414f0ed06e4eaf9346366be72e2b4719efcristy                    canvas->columns,1,exception);
63664c08aed51c5899665ade97263692328eea4af106cristy                  if (p == (const Quantum *) NULL)
63673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    break;
63683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
63693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      (blue_gamma != 1.0))
63703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
63713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      /*
63723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        Gamma correct canvas.
63733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      */
63743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      for (x=(int) canvas->columns-1; x >= 0; x--)
63753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      {
6376ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                        *q++=ScaleQuantumToChar(XRedGamma(
63774c08aed51c5899665ade97263692328eea4af106cristy                          GetPixelRed(canvas,p)));
6378ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                        *q++=ScaleQuantumToChar(XGreenGamma(
63794c08aed51c5899665ade97263692328eea4af106cristy                          GetPixelGreen(canvas,p)));
6380ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                        *q++=ScaleQuantumToChar(XBlueGamma(
63814c08aed51c5899665ade97263692328eea4af106cristy                          GetPixelBlue(canvas,p)));
63823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        *q++=0;
6383ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                        p+=GetPixelChannels(canvas);
63843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      }
63853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      continue;
63863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
63873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  for (x=(int) canvas->columns-1; x >= 0; x--)
63883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
6389ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                    *q++=ScaleQuantumToChar((Quantum)
63904c08aed51c5899665ade97263692328eea4af106cristy                      GetPixelRed(canvas,p));
6391ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                    *q++=ScaleQuantumToChar((Quantum)
63924c08aed51c5899665ade97263692328eea4af106cristy                      GetPixelGreen(canvas,p));
6393ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                    *q++=ScaleQuantumToChar((Quantum)
63944c08aed51c5899665ade97263692328eea4af106cristy                      GetPixelBlue(canvas,p));
63953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    *q++=0;
6396ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                    p+=GetPixelChannels(canvas);
63973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
63983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
63993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
64003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            else
64013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
64023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                register int
64033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  k;
64043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
64053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                register unsigned int
64063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  bytes_per_pixel;
64073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
64083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                unsigned char
6409bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy                  channel[sizeof(size_t)];
64103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
64113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                /*
64123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  Convert to multi-byte continuous-tone X canvas.
64133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                */
64143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
64153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (y=0; y < (int) canvas->rows; y++)
64163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
6417c57f694b2d04975a0e501613e34368c464708c19cristy                  p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
64186710d8414f0ed06e4eaf9346366be72e2b4719efcristy                    canvas->columns,1,exception);
64194c08aed51c5899665ade97263692328eea4af106cristy                  if (p == (const Quantum *) NULL)
64203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    break;
6421c57f694b2d04975a0e501613e34368c464708c19cristy                  for (x=0; x < (int) canvas->columns; x++)
64223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
64234c08aed51c5899665ade97263692328eea4af106cristy                    pixel=XGammaPixel(canvas,map_info,p);
64243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    for (k=0; k < (int) bytes_per_pixel; k++)
64253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
64263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      channel[k]=(unsigned char) pixel;
64273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      pixel>>=8;
64283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
64293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    for (k=0; k < (int) bytes_per_pixel; k++)
64303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      *q++=channel[k];
6431ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                    p+=GetPixelChannels(canvas);
64323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
64333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q+=scanline_pad;
64343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
64353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
64363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
64373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
64383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
64393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (matte_image != (XImage *) NULL)
64403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
64413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
64423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Initialize matte canvas.
64433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
64443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      scanline_pad=(unsigned int) (matte_image->bytes_per_line-
64453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ((matte_image->width*matte_image->bits_per_pixel) >> 3));
64463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      q=(unsigned char *) matte_image->data;
64473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (y=0; y < (int) canvas->rows; y++)
64483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
6449c57f694b2d04975a0e501613e34368c464708c19cristy        p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
64506710d8414f0ed06e4eaf9346366be72e2b4719efcristy          exception);
64514c08aed51c5899665ade97263692328eea4af106cristy        if (p == (const Quantum *) NULL)
64523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
64533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        bit=0;
64543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        byte=0;
64553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        for (x=(int) canvas->columns-1; x >= 0; x--)
64563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
64573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          byte>>=1;
64584c08aed51c5899665ade97263692328eea4af106cristy          if (GetPixelAlpha(canvas,p) > (QuantumRange/2))
64593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            byte|=0x80;
64603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          bit++;
64613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (bit == 8)
64623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
64633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *q++=byte;
64643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              bit=0;
64653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              byte=0;
64663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
6467ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy          p+=GetPixelChannels(canvas);
64683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
64693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (bit != 0)
64703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          *q=byte >> (8-bit);
64713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        q+=scanline_pad;
64723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
64733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
6474c57f694b2d04975a0e501613e34368c464708c19cristy  canvas_view=DestroyCacheView(canvas_view);
64753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (canvas != image)
64763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    canvas=DestroyImage(canvas);
64773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
64783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
64793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
64803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
64823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
64833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
64843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy+   X M a k e I m a g e M S B F i r s t                                       %
64853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
64863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
64873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
64883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
64903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XMakeImageMSBFirst() initializes the pixel data of an X11 Image.  The X
64913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  image pixels are copied in most-significant bit and byte first order.  The
64923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  server's scanline pad is also respected. Rather than using one or two
64933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  general cases, many special cases are found here to help speed up the image
64943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  conversion.
64953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
64963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XMakeImageMSBFirst method is:
64973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6498e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy%      XMakeImageMSBFirst(resource_info,window,image,ximage,matte_image,
6499e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy%        ExceptionInfo *exception)
65003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
65013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
65023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
65033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
65043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
65053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a XWindowInfo structure.
65063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
65073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
65083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
65093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o ximage: Specifies a pointer to a XImage structure;  returned from
65103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XCreateImage.
65113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
65123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o matte_image: Specifies a pointer to a XImage structure;  returned from
65133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XCreateImage.
65143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6515e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy%    o exception: return any errors or warnings in this structure.
6516e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy%
65173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
65183ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void XMakeImageMSBFirst(const XResourceInfo *resource_info,
6519e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy  const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image,
6520e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy  ExceptionInfo *exception)
65213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
6522c57f694b2d04975a0e501613e34368c464708c19cristy  CacheView
6523c57f694b2d04975a0e501613e34368c464708c19cristy    *canvas_view;
6524c57f694b2d04975a0e501613e34368c464708c19cristy
65253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Image
65263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *canvas;
65273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
65283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
65293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y;
65303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
65313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
65323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x;
65333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
65344c08aed51c5899665ade97263692328eea4af106cristy  register const Quantum
65353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p;
65363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
65373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register unsigned char
65383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *q;
65393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
65403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned char
65413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    bit,
65423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    byte;
65433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
65443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
65453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scanline_pad;
65463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6547f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  unsigned long
65483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel,
65493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *pixels;
65503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
65513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XStandardColormap
65523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *map_info;
65533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
65543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
65553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (XWindowInfo *) NULL);
65563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image != (Image *) NULL);
65573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image->debug != MagickFalse)
65583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
65593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  canvas=image;
656054666e85e8e3b0eca47d318178a186ebb2901a73cristy  if ((window->immutable != MagickFalse) &&
656154666e85e8e3b0eca47d318178a186ebb2901a73cristy      (image->storage_class == DirectClass) && (image->matte != MagickFalse))
65623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
65633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      char
65643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        size[MaxTextExtent];
65653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
65663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Image
65673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *pattern;
65683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
65693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ImageInfo
65703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *image_info;
65713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
65723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info=AcquireImageInfo();
65733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) CopyMagickString(image_info->filename,
65743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        resource_info->image_info->texture != (char *) NULL ?
65753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        resource_info->image_info->texture : "pattern:checkerboard",
65763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        MaxTextExtent);
6577b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy      (void) FormatLocaleString(size,MaxTextExtent,"%.20gx%.20g",(double)
6578e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy        image->columns,(double) image->rows);
65793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info->size=ConstantString(size);
65806710d8414f0ed06e4eaf9346366be72e2b4719efcristy      pattern=ReadImage(image_info,exception);
65813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info=DestroyImageInfo(image_info);
65823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (pattern != (Image *) NULL)
65833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
65846710d8414f0ed06e4eaf9346366be72e2b4719efcristy          canvas=CloneImage(image,0,0,MagickTrue,exception);
65853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (canvas != (Image *) NULL)
6586e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy            (void) CompositeImage(canvas,DstOverCompositeOp,pattern,0,0,
6587e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy              exception);
65883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          pattern=DestroyImage(pattern);
65893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
65903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
65914c08aed51c5899665ade97263692328eea4af106cristy  scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
65924c08aed51c5899665ade97263692328eea4af106cristy    ximage->bits_per_pixel) >> 3));
65933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  map_info=window->map_info;
65943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixels=window->pixel_info->pixels;
65953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  q=(unsigned char *) ximage->data;
65963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=0;
6597c57f694b2d04975a0e501613e34368c464708c19cristy  canvas_view=AcquireCacheView(canvas);
65983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (ximage->format == XYBitmap)
65993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
66003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      register unsigned short
66013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        polarity;
66023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
66033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      unsigned char
66043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        background,
66053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        foreground;
66063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
66073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
66083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Convert canvas to big-endian bitmap.
66093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
66103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      background=(unsigned char)
66113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (XPixelIntensity(&window->pixel_info->foreground_color) <
66123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy         XPixelIntensity(&window->pixel_info->background_color) ?  0x01 : 0x00);
66133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      foreground=(unsigned char)
66143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (XPixelIntensity(&window->pixel_info->background_color) <
66153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy         XPixelIntensity(&window->pixel_info->foreground_color) ?  0x01 : 0x00);
6616101ab708b0574518ac5715da4d3915400e9df79acristy      polarity=(unsigned short) ((GetPixelInfoIntensity(
66173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &canvas->colormap[0])) < ((Quantum) QuantumRange/2) ? 1 : 0);
66183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (canvas->colors == 2)
6619101ab708b0574518ac5715da4d3915400e9df79acristy        polarity=GetPixelInfoIntensity(&canvas->colormap[0]) <
6620101ab708b0574518ac5715da4d3915400e9df79acristy          GetPixelInfoIntensity(&canvas->colormap[1]);
66213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (y=0; y < (int) canvas->rows; y++)
66223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
6623c57f694b2d04975a0e501613e34368c464708c19cristy        p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
66246710d8414f0ed06e4eaf9346366be72e2b4719efcristy          exception);
66254c08aed51c5899665ade97263692328eea4af106cristy        if (p == (const Quantum *) NULL)
66263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
66273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        bit=0;
66283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        byte=0;
66293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        for (x=(int) canvas->columns-1; x >= 0; x--)
66303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
66313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          byte<<=1;
66324c08aed51c5899665ade97263692328eea4af106cristy          if (GetPixelIndex(canvas,p) == (Quantum) polarity)
66333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            byte|=foreground;
66343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          else
66353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            byte|=background;
66363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          bit++;
66373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (bit == 8)
66383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
66393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *q++=byte;
66403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              bit=0;
66413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              byte=0;
66423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
6643ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy          p+=GetPixelChannels(canvas);
66443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
66453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (bit != 0)
66463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          *q=byte << (8-bit);
66473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        q+=scanline_pad;
66483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
66493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
66503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
66513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (window->pixel_info->colors != 0)
66523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      switch (ximage->bits_per_pixel)
66533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
66543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 2:
66553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
66563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
66573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble;
66583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
66593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
66603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 2 bit color-mapped X canvas.
66613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
66623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
66633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6664c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
66656710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
66664c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
66673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
66683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble=0;
66693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
66703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
66714c08aed51c5899665ade97263692328eea4af106cristy              pixel=pixels[(ssize_t)
66724c08aed51c5899665ade97263692328eea4af106cristy                GetPixelIndex(canvas,p)] & 0xf;
66733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              switch (nibble)
66743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
66753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 0:
66763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
66773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=(unsigned char) (pixel << 6);
66783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
66793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
66803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
66813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 1:
66823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
66833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 4);
66843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
66853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
66863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
66873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 2:
66883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
66893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 2);
66903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
66913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
66923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
66933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 3:
66943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
66953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) pixel;
66963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q++;
66973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble=0;
66983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
66993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
67003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
6701ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
67023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
67033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
67043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
67053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
67063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
67073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 4:
67083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
67093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
67103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble;
67113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
67123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
67133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 4 bit color-mapped X canvas.
67143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
67153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
67163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6717c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
67186710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
67194c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
67203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
67213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble=0;
67223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
67233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
67244c08aed51c5899665ade97263692328eea4af106cristy              pixel=pixels[(ssize_t)
67254c08aed51c5899665ade97263692328eea4af106cristy                GetPixelIndex(canvas,p)] & 0xf;
67263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              switch (nibble)
67273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
67283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 0:
67293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
67303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=(unsigned char) (pixel << 4);
67313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
67323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
67333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
67343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 1:
67353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
67363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) pixel;
67373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q++;
67383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble=0;
67393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
67403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
67413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
6742ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
67433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
67443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
67453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
67463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
67473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
67483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 6:
67493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 8:
67503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
67513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
67523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 8 bit color-mapped X canvas.
67533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
67543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (resource_info->color_recovery &&
67553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              resource_info->quantize_info->dither)
67563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
67576710d8414f0ed06e4eaf9346366be72e2b4719efcristy              XDitherImage(canvas,ximage,exception);
67583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
67593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
67603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
67613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6762c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
67636710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
67644c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
67653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
67663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
67673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
67686710d8414f0ed06e4eaf9346366be72e2b4719efcristy              pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
67693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *q++=(unsigned char) pixel;
6770ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
67713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
67723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
67733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
67743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
67753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
67763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        default:
67773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
67783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register int
67793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            k;
67803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
67813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
67823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            bytes_per_pixel;
67833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
67843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          unsigned char
6785bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            channel[sizeof(size_t)];
67863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
67873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
67883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 8 bit color-mapped X canvas.
67893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
67903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
67913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
67923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6793c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
67946710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
67954c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
67963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
67973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
67983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
67994c08aed51c5899665ade97263692328eea4af106cristy              pixel=pixels[(ssize_t)
68004c08aed51c5899665ade97263692328eea4af106cristy                GetPixelIndex(canvas,p)];
68013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (k=(int) bytes_per_pixel-1; k >= 0; k--)
68023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
68033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                channel[k]=(unsigned char) pixel;
68043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                pixel>>=8;
68053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
68063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (k=0; k < (int) bytes_per_pixel; k++)
68073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                *q++=channel[k];
6808ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
68093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
68103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
68113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
68123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
68133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
68143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
68153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    else
68163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      switch (ximage->bits_per_pixel)
68173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
68183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 2:
68193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
68203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
68213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble;
68223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
68233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
68243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 4 bit continuous-tone X canvas.
68253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
68263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
68273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6828c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
68296710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
68304c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
68313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
68323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble=0;
68333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=(int) canvas->columns-1; x >= 0; x--)
68343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
68354c08aed51c5899665ade97263692328eea4af106cristy              pixel=XGammaPixel(canvas,map_info,p);
68363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              pixel&=0xf;
68373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              switch (nibble)
68383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
68393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 0:
68403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
68413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=(unsigned char) (pixel << 6);
68423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
68433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
68443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
68453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 1:
68463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
68473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 4);
68483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
68493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
68503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
68513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 2:
68523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
68533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 2);
68543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
68553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
68563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
68573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 3:
68583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
68593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) pixel;
68603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q++;
68613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble=0;
68623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
68633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
68643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
6865ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
68663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
68673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
68683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
68693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
68703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
68713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 4:
68723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
68733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
68743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble;
68753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
68763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
68773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 4 bit continuous-tone X canvas.
68783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
68793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
68803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6881c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
68826710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
68834c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
68843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
68853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble=0;
68863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=(int) canvas->columns-1; x >= 0; x--)
68873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
68884c08aed51c5899665ade97263692328eea4af106cristy              pixel=XGammaPixel(canvas,map_info,p);
68893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              pixel&=0xf;
68903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              switch (nibble)
68913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
68923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 0:
68933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
68943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=(unsigned char) (pixel << 4);
68953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
68963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
68973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
68983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 1:
68993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
69003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) pixel;
69013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q++;
69023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble=0;
69033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
69043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
69053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
6906ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
69073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
69083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
69093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
69103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
69113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
69123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 6:
69133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 8:
69143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
69153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
69163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 8 bit continuous-tone X canvas.
69173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
69183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (resource_info->color_recovery &&
69193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              resource_info->quantize_info->dither)
69203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
69216710d8414f0ed06e4eaf9346366be72e2b4719efcristy              XDitherImage(canvas,ximage,exception);
69223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
69233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
69243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
69253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6926c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
69276710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
69284c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
69293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
69303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=(int) canvas->columns-1; x >= 0; x--)
69313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
69324c08aed51c5899665ade97263692328eea4af106cristy              pixel=XGammaPixel(canvas,map_info,p);
69333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *q++=(unsigned char) pixel;
6934ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
69353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
69363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
69373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
69383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
69393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
69403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        default:
69413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
69423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
69433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (map_info->green_max == 255) && (map_info->blue_max == 255) &&
69443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
69453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (map_info->blue_mult == 1))
69463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
69473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              /*
69483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                Convert to 32 bit continuous-tone X canvas.
69493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              */
69503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (y=0; y < (int) canvas->rows; y++)
69513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
6952c57f694b2d04975a0e501613e34368c464708c19cristy                p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
69536710d8414f0ed06e4eaf9346366be72e2b4719efcristy                  canvas->columns,1,exception);
69544c08aed51c5899665ade97263692328eea4af106cristy                if (p == (const Quantum *) NULL)
69553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
69563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
69573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    (blue_gamma != 1.0))
69583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
69593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    /*
69603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      Gamma correct canvas.
69613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    */
69623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    for (x=(int) canvas->columns-1; x >= 0; x--)
69633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
69643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      *q++=0;
6965ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                      *q++=ScaleQuantumToChar(XRedGamma(
69664c08aed51c5899665ade97263692328eea4af106cristy                        GetPixelRed(canvas,p)));
6967ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                      *q++=ScaleQuantumToChar(XGreenGamma(
69684c08aed51c5899665ade97263692328eea4af106cristy                        GetPixelGreen(canvas,p)));
6969ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                      *q++=ScaleQuantumToChar(XBlueGamma(
69704c08aed51c5899665ade97263692328eea4af106cristy                        GetPixelBlue(canvas,p)));
6971ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                      p+=GetPixelChannels(canvas);
69723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
69733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    continue;
69743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
69753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (x=(int) canvas->columns-1; x >= 0; x--)
69763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
69773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q++=0;
69784c08aed51c5899665ade97263692328eea4af106cristy                  *q++=ScaleQuantumToChar((Quantum)
69794c08aed51c5899665ade97263692328eea4af106cristy                    GetPixelRed(canvas,p));
69804c08aed51c5899665ade97263692328eea4af106cristy                  *q++=ScaleQuantumToChar((Quantum)
69814c08aed51c5899665ade97263692328eea4af106cristy                    GetPixelGreen(canvas,p));
69824c08aed51c5899665ade97263692328eea4af106cristy                  *q++=ScaleQuantumToChar((Quantum)
69834c08aed51c5899665ade97263692328eea4af106cristy                    GetPixelBlue(canvas,p));
6984ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                  p+=GetPixelChannels(canvas);
69853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
69863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
69873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
69883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          else
69893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
69903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (map_info->green_max == 255) && (map_info->blue_max == 255) &&
69913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
69923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (map_info->blue_mult == 65536L))
69933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
69943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                /*
69953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  Convert to 32 bit continuous-tone X canvas.
69963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                */
69973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (y=0; y < (int) canvas->rows; y++)
69983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
6999c57f694b2d04975a0e501613e34368c464708c19cristy                  p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
70006710d8414f0ed06e4eaf9346366be72e2b4719efcristy                    canvas->columns,1,exception);
70014c08aed51c5899665ade97263692328eea4af106cristy                  if (p == (const Quantum *) NULL)
70023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    break;
70033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
70043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      (blue_gamma != 1.0))
70053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
70063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      /*
70073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        Gamma correct canvas.
70083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      */
70093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      for (x=(int) canvas->columns-1; x >= 0; x--)
70103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      {
70113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        *q++=0;
7012ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                        *q++=ScaleQuantumToChar(XBlueGamma(
70134c08aed51c5899665ade97263692328eea4af106cristy                          GetPixelBlue(canvas,p)));
7014ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                        *q++=ScaleQuantumToChar(XGreenGamma(
70154c08aed51c5899665ade97263692328eea4af106cristy                          GetPixelGreen(canvas,p)));
7016ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                        *q++=ScaleQuantumToChar(XRedGamma(
70174c08aed51c5899665ade97263692328eea4af106cristy                          GetPixelRed(canvas,p)));
7018ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                        p+=GetPixelChannels(canvas);
70193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      }
70203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      continue;
70213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
70223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  for (x=(int) canvas->columns-1; x >= 0; x--)
70233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
70243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    *q++=0;
7025ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                    *q++=ScaleQuantumToChar((Quantum)
70264c08aed51c5899665ade97263692328eea4af106cristy                      GetPixelBlue(canvas,p));
7027ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                    *q++=ScaleQuantumToChar((Quantum)
70284c08aed51c5899665ade97263692328eea4af106cristy                      GetPixelGreen(canvas,p));
7029ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                    *q++=ScaleQuantumToChar((Quantum)
70304c08aed51c5899665ade97263692328eea4af106cristy                      GetPixelRed(canvas,p));
7031ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                    p+=GetPixelChannels(canvas);
70323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
70333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
70343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
70353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            else
70363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
70373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                register int
70383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  k;
70393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
70403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                register unsigned int
70413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  bytes_per_pixel;
70423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
70433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                unsigned char
7044bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy                  channel[sizeof(size_t)];
70453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
70463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                /*
70473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  Convert to multi-byte continuous-tone X canvas.
70483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                */
70493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
70503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (y=0; y < (int) canvas->rows; y++)
70513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
7052c57f694b2d04975a0e501613e34368c464708c19cristy                  p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
70536710d8414f0ed06e4eaf9346366be72e2b4719efcristy                    canvas->columns,1,exception);
70544c08aed51c5899665ade97263692328eea4af106cristy                  if (p == (const Quantum *) NULL)
70553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    break;
70563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  for (x=(int) canvas->columns-1; x >= 0; x--)
70573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
70584c08aed51c5899665ade97263692328eea4af106cristy                    pixel=XGammaPixel(canvas,map_info,p);
70593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    for (k=(int) bytes_per_pixel-1; k >= 0; k--)
70603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
70613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      channel[k]=(unsigned char) pixel;
70623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      pixel>>=8;
70633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
70643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    for (k=0; k < (int) bytes_per_pixel; k++)
70653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      *q++=channel[k];
7066ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                    p+=GetPixelChannels(canvas);
70673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
70683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q+=scanline_pad;
70693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
70703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
70713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
70723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
70733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
70743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (matte_image != (XImage *) NULL)
70753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
70763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
70773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Initialize matte canvas.
70783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
70793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      scanline_pad=(unsigned int) (matte_image->bytes_per_line-
70803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ((matte_image->width*matte_image->bits_per_pixel) >> 3));
70813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      q=(unsigned char *) matte_image->data;
70823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (y=0; y < (int) canvas->rows; y++)
70833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
7084c57f694b2d04975a0e501613e34368c464708c19cristy        p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
70856710d8414f0ed06e4eaf9346366be72e2b4719efcristy          exception);
70864c08aed51c5899665ade97263692328eea4af106cristy        if (p == (const Quantum *) NULL)
70873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
70883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        bit=0;
70893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        byte=0;
70903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        for (x=(int) canvas->columns-1; x >= 0; x--)
70913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
70923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          byte<<=1;
70934c08aed51c5899665ade97263692328eea4af106cristy          if (GetPixelAlpha(canvas,p) > (QuantumRange/2))
70943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            byte|=0x01;
70953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          bit++;
70963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (bit == 8)
70973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
70983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *q++=byte;
70993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              bit=0;
71003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              byte=0;
71013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
7102ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy          p+=GetPixelChannels(canvas);
71033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
71043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (bit != 0)
71053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          *q=byte << (8-bit);
71063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        q+=scanline_pad;
71073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
71083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
7109c57f694b2d04975a0e501613e34368c464708c19cristy  canvas_view=DestroyCacheView(canvas_view);
71103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (canvas != image)
71113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    canvas=DestroyImage(canvas);
71123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
71133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
71153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
71173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
71183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
71193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X M a k e M a g n i f y I m a g e                                         %
71203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
71213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
71223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
71233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
71253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XMakeMagnifyImage() magnifies a region of an X image and displays it.
71263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
71273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XMakeMagnifyImage method is:
71283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
71296710d8414f0ed06e4eaf9346366be72e2b4719efcristy%      void XMakeMagnifyImage(Display *display,XWindows *windows,
71306710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        ExceptionInfo *exception)
71313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
71323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
71333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
71343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
71353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
71363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
71373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o windows: Specifies a pointer to a XWindows structure.
71383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
71396710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    o exception: return any errors or warnings in this structure.
71406710d8414f0ed06e4eaf9346366be72e2b4719efcristy%
71413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
71426710d8414f0ed06e4eaf9346366be72e2b4719efcristyMagickPrivate void XMakeMagnifyImage(Display *display,XWindows *windows,
71436710d8414f0ed06e4eaf9346366be72e2b4719efcristy  ExceptionInfo *exception)
71443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
71453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
71463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    tuple[MaxTextExtent];
71473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
71493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y;
71503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71514c08aed51c5899665ade97263692328eea4af106cristy  PixelInfo
71523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel;
71533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
71553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x;
71563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7157bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  register ssize_t
71583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
71593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register unsigned char
71613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p,
71623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *q;
71633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71649d314ff2c17a77996c05413c2013880387e50f0ecristy  ssize_t
71659d314ff2c17a77996c05413c2013880387e50f0ecristy    n;
71669d314ff2c17a77996c05413c2013880387e50f0ecristy
71673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static unsigned int
71683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    previous_magnify = 0;
71693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static XWindowInfo
71713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    magnify_window;
71723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
71743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    height,
71753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    j,
71763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    k,
71773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    l,
71783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    magnify,
71793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scanline_pad,
71803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    width;
71813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XImage
71833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *ximage;
71843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
71863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Check boundary conditions.
71873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
71883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
71893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
71903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(windows != (XWindows *) NULL);
71913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magnify=1;
7192bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  for (n=1; n < (ssize_t) windows->magnify.data; n++)
71933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    magnify<<=1;
71943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while ((magnify*windows->image.ximage->width) < windows->magnify.width)
71953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    magnify<<=1;
71963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while ((magnify*windows->image.ximage->height) < windows->magnify.height)
71973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    magnify<<=1;
71983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while (magnify > windows->magnify.width)
71993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    magnify>>=1;
72003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while (magnify > windows->magnify.height)
72013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    magnify>>=1;
72023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (magnify != previous_magnify)
72033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
72043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Status
72053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        status;
72063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
72073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XTextProperty
72083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window_name;
72093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
72103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
72113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        New magnify factor:  update magnify window name.
72123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
72133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      i=0;
72143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      while ((1 << i) <= (int) magnify)
72153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        i++;
7216b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy      (void) FormatLocaleString(windows->magnify.name,MaxTextExtent,
7217e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy        "Magnify %.20gX",(double) i);
72183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
72193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status != False)
72203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
72213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          XSetWMName(display,windows->magnify.id,&window_name);
72223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          XSetWMIconName(display,windows->magnify.id,&window_name);
72233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) XFree((void *) window_name.value);
72243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
72253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
72263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  previous_magnify=magnify;
72273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ximage=windows->image.ximage;
72283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  width=(unsigned int) windows->magnify.ximage->width;
72293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  height=(unsigned int) windows->magnify.ximage->height;
72303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((windows->magnify.x < 0) ||
72313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (windows->magnify.x >= windows->image.ximage->width))
72323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    windows->magnify.x=windows->image.ximage->width >> 1;
72333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=windows->magnify.x-((width/magnify) >> 1);
72343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (x < 0)
72353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x=0;
72363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
72373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (x > (int) (ximage->width-(width/magnify)))
72383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      x=ximage->width-width/magnify;
72393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((windows->magnify.y < 0) ||
72403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (windows->magnify.y >= windows->image.ximage->height))
72413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    windows->magnify.y=windows->image.ximage->height >> 1;
72423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y=windows->magnify.y-((height/magnify) >> 1);
72433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (y < 0)
72443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y=0;
72453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
72463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (y > (int) (ximage->height-(height/magnify)))
72473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      y=ximage->height-height/magnify;
72483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  q=(unsigned char *) windows->magnify.ximage->data;
72493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  scanline_pad=(unsigned int) (windows->magnify.ximage->bytes_per_line-
72503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ((width*windows->magnify.ximage->bits_per_pixel) >> 3));
72513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (ximage->bits_per_pixel < 8)
72523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
72533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      register unsigned char
72543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        background,
72553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        byte,
72563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        foreground,
72573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        p_bit,
72583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        q_bit;
72593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
72603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      register unsigned int
72613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        plane;
72623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
72633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XPixelInfo
72643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *pixel_info;
72653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
72663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      pixel_info=windows->magnify.pixel_info;
72673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      switch (ximage->bitmap_bit_order)
72683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
72693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case LSBFirst:
72703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
72713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
72723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Magnify little-endian bitmap.
72733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
72743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          background=0x00;
72753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          foreground=0x80;
72763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (ximage->format == XYBitmap)
72773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
72783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              background=(unsigned char)
72793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (XPixelIntensity(&pixel_info->foreground_color) <
72803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                 XPixelIntensity(&pixel_info->background_color) ?  0x80 : 0x00);
72813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              foreground=(unsigned char)
72823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (XPixelIntensity(&pixel_info->background_color) <
72833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                 XPixelIntensity(&pixel_info->foreground_color) ?  0x80 : 0x00);
72843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (windows->magnify.depth > 1)
72853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                Swap(background,foreground);
72863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
7287bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy          for (i=0; i < (ssize_t) height; i+=magnify)
72883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
72893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
72903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Propogate pixel magnify rows.
72913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
72923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (j=0; j < magnify; j++)
72933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
72943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
72953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                ((x*ximage->bits_per_pixel) >> 3);
72963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
72973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              q_bit=0;
72983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              byte=0;
72993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (k=0; k < width; k+=magnify)
73003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
73013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                /*
73023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  Propogate pixel magnify columns.
73033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                */
73043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (l=0; l < magnify; l++)
73053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
73063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  /*
73073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    Propogate each bit plane.
73083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  */
73093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
73103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
73113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    byte>>=1;
73123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    if (*p & (0x01 << (p_bit+plane)))
73133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      byte|=foreground;
73143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    else
73153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      byte|=background;
73163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    q_bit++;
73173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    if (q_bit == 8)
73183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      {
73193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        *q++=byte;
73203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        q_bit=0;
73213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        byte=0;
73223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      }
73233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
73243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
73253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                p_bit+=ximage->bits_per_pixel;
73263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if (p_bit == 8)
73273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
73283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    p++;
73293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    p_bit=0;
73303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
73313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if (q_bit != 0)
73323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=byte >> (8-q_bit);
73333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                q+=scanline_pad;
73343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
73353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
73363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            y++;
73373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
73383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
73393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
73403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case MSBFirst:
73413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        default:
73423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
73433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
73443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Magnify big-endian bitmap.
73453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
73463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          background=0x00;
73473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          foreground=0x01;
73483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (ximage->format == XYBitmap)
73493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
73503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              background=(unsigned char)
73513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (XPixelIntensity(&pixel_info->foreground_color) <
73523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                 XPixelIntensity(&pixel_info->background_color) ?  0x01 : 0x00);
73533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              foreground=(unsigned char)
73543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (XPixelIntensity(&pixel_info->background_color) <
73553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                 XPixelIntensity(&pixel_info->foreground_color) ?  0x01 : 0x00);
73563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (windows->magnify.depth > 1)
73573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                Swap(background,foreground);
73583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
7359bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy          for (i=0; i < (ssize_t) height; i+=magnify)
73603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
73613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
73623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Propogate pixel magnify rows.
73633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
73643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (j=0; j < magnify; j++)
73653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
73663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
73673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                ((x*ximage->bits_per_pixel) >> 3);
73683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
73693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              q_bit=0;
73703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              byte=0;
73713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (k=0; k < width; k+=magnify)
73723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
73733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                /*
73743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  Propogate pixel magnify columns.
73753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                */
73763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (l=0; l < magnify; l++)
73773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
73783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  /*
73793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    Propogate each bit plane.
73803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  */
73813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
73823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
73833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    byte<<=1;
73843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    if (*p & (0x80 >> (p_bit+plane)))
73853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      byte|=foreground;
73863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    else
73873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      byte|=background;
73883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    q_bit++;
73893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    if (q_bit == 8)
73903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      {
73913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        *q++=byte;
73923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        q_bit=0;
73933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        byte=0;
73943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      }
73953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
73963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
73973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                p_bit+=ximage->bits_per_pixel;
73983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if (p_bit == 8)
73993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
74003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    p++;
74013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    p_bit=0;
74023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
74033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if (q_bit != 0)
74043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=byte << (8-q_bit);
74053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                q+=scanline_pad;
74063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
74073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
74083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            y++;
74093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
74103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
74113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
74123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
74133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
74143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
74153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    switch (ximage->bits_per_pixel)
74163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
74173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case 6:
74183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case 8:
74193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
74203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
74213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Magnify 8 bit X image.
74223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
7423bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        for (i=0; i < (ssize_t) height; i+=magnify)
74243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
74253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
74263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Propogate pixel magnify rows.
74273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
74283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (j=0; j < magnify; j++)
74293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
74303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
74313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ((x*ximage->bits_per_pixel) >> 3);
74323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (k=0; k < width; k+=magnify)
74333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
74343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              /*
74353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                Propogate pixel magnify columns.
74363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              */
74373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (l=0; l < magnify; l++)
74383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                *q++=(*p);
74393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              p++;
74403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
74413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
74423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
74433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          y++;
74443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
74453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
74463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
74473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      default:
74483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
74493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        register unsigned int
74503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          bytes_per_pixel,
74513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          m;
74523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
74533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
74543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Magnify multi-byte X image.
74553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
74563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        bytes_per_pixel=(unsigned int) ximage->bits_per_pixel >> 3;
7457bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        for (i=0; i < (ssize_t) height; i+=magnify)
74583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
74593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
74603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Propogate pixel magnify rows.
74613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
74623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (j=0; j < magnify; j++)
74633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
74643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
74653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ((x*ximage->bits_per_pixel) >> 3);
74663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (k=0; k < width; k+=magnify)
74673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
74683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              /*
74693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                Propogate pixel magnify columns.
74703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              */
74713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (l=0; l < magnify; l++)
74723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (m=0; m < bytes_per_pixel; m++)
74733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q++=(*(p+m));
74743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              p+=bytes_per_pixel;
74753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
74763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
74773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
74783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          y++;
74793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
74803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
74813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
74823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
74833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
74843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Copy X image to magnify pixmap.
74853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
74863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=windows->magnify.x-((width/magnify) >> 1);
74873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (x < 0)
74883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x=(int) ((width >> 1)-windows->magnify.x*magnify);
74893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
74903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (x > (int) (ximage->width-(width/magnify)))
74913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      x=(int) ((ximage->width-windows->magnify.x)*magnify-(width >> 1));
74923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    else
74933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      x=0;
74943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y=windows->magnify.y-((height/magnify) >> 1);
74953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (y < 0)
74963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y=(int) ((height >> 1)-windows->magnify.y*magnify);
74973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
74983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (y > (int) (ximage->height-(height/magnify)))
74993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      y=(int) ((ximage->height-windows->magnify.y)*magnify-(height >> 1));
75003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    else
75013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      y=0;
75023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((x != 0) || (y != 0))
75033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XFillRectangle(display,windows->magnify.pixmap,
75043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->magnify.annotate_context,0,0,width,height);
75053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XPutImage(display,windows->magnify.pixmap,
75063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,width-x,
75073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    height-y);
75083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((magnify > 1) && ((magnify <= (width >> 1)) &&
75093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (magnify <= (height >> 1))))
75103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
75113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      RectangleInfo
75123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        highlight_info;
75133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
75143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
75153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Highlight center pixel.
75163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
7517bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      highlight_info.x=(ssize_t) windows->magnify.width >> 1;
7518bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      highlight_info.y=(ssize_t) windows->magnify.height >> 1;
75193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      highlight_info.width=magnify;
75203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      highlight_info.height=magnify;
75213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDrawRectangle(display,windows->magnify.pixmap,
75223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->magnify.highlight_context,(int) highlight_info.x,
75233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (int) highlight_info.y,(unsigned int) highlight_info.width-1,
75243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) highlight_info.height-1);
75253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (magnify > 2)
75263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XDrawRectangle(display,windows->magnify.pixmap,
75273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          windows->magnify.annotate_context,(int) highlight_info.x+1,
75283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (int) highlight_info.y+1,(unsigned int) highlight_info.width-3,
75293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (unsigned int) highlight_info.height-3);
75303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
75313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
75323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Show center pixel color.
75333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
75343aa9375ebfc21a5356d6b1754bcd1b162ad666c4cristy  (void) GetOneVirtualPixelInfo(windows->image.image,TileVirtualPixelMethod,
75355201002e1ba0118594060d26142b48bdfb1320a2cristy    (ssize_t) windows->magnify.x,(ssize_t) windows->magnify.y,&pixel,exception);
7536b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(tuple,MaxTextExtent,"%d,%d: ",
75373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    windows->magnify.x,windows->magnify.y);
75383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ConcatenateMagickString(tuple,"(",MaxTextExtent);
7539ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy  ConcatenateColorComponent(&pixel,RedPixelChannel,X11Compliance,tuple);
75403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7541ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy  ConcatenateColorComponent(&pixel,GreenPixelChannel,X11Compliance,tuple);
75423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7543ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy  ConcatenateColorComponent(&pixel,BluePixelChannel,X11Compliance,tuple);
75443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (pixel.colorspace == CMYKColorspace)
75453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
75463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7547ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy      ConcatenateColorComponent(&pixel,BlackPixelChannel,X11Compliance,tuple);
75483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
75493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (pixel.matte != MagickFalse)
75503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
75513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) ConcatenateMagickString(tuple,",",MaxTextExtent);
7552ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy      ConcatenateColorComponent(&pixel,AlphaPixelChannel,X11Compliance,tuple);
75533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
75543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ConcatenateMagickString(tuple,")",MaxTextExtent);
75553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  height=(unsigned int) windows->magnify.font_info->ascent+
75563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    windows->magnify.font_info->descent;
75573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=windows->magnify.font_info->max_bounds.width >> 1;
75583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y=windows->magnify.font_info->ascent+(height >> 2);
75593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XDrawImageString(display,windows->magnify.pixmap,
75603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
75613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  GetColorTuple(&pixel,MagickTrue,tuple);
75623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y+=height;
75633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XDrawImageString(display,windows->magnify.pixmap,
75643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7565269c9413034627692b2a7d0a352f9dee4e8eada8cristy  (void) QueryColorname(windows->image.image,&pixel,SVGCompliance,tuple,
75666710d8414f0ed06e4eaf9346366be72e2b4719efcristy    exception);
75673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y+=height;
75683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XDrawImageString(display,windows->magnify.pixmap,
75693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
75703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
75713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Refresh magnify window.
75723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
75733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magnify_window=windows->magnify;
75743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magnify_window.x=0;
75753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magnify_window.y=0;
75763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
75773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
75783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
75793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
75803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
75823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
75833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
75843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X M a k e P i x m a p                                                     %
75853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
75863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
75873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
75883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
75903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XMakePixmap() creates an X11 pixmap.
75913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
75923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XMakePixmap method is:
75933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
75943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
75953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
75963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XPixelInfo *pixel)
75973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
75983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
75993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
76013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
76033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
76043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a XWindowInfo structure.
76063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
76083ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType XMakePixmap(Display *display,
76093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const XResourceInfo *resource_info,XWindowInfo *window)
76103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
76113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
76123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    height,
76133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    width;
76143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
76153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
76163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
76173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
76183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (XWindowInfo  *) NULL);
76193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->pixmap != (Pixmap) NULL)
76203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
76213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
76223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Destroy previous X pixmap.
76233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
76243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFreePixmap(display,window->pixmap);
76253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->pixmap=(Pixmap) NULL;
76263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
76273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->use_pixmap == MagickFalse)
76283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
76293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->ximage == (XImage *) NULL)
76303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
76313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
76323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Display busy cursor.
76333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
76343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
76353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFlush(display);
76363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
76373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Create pixmap.
76383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
76393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  width=(unsigned int) window->ximage->width;
76403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  height=(unsigned int) window->ximage->height;
76413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
76423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->pixmap == (Pixmap) NULL)
76433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
76443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
76453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Unable to allocate pixmap.
76463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
76473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,window->id,window->cursor);
76483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(MagickFalse);
76493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
76503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
76513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Copy X image to pixmap.
76523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
76533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
76543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->shared_memory)
76553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XShmPutImage(display,window->pixmap,window->annotate_context,
76563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->ximage,0,0,0,0,width,height,MagickTrue);
76573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
76583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->shared_memory == MagickFalse)
76593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XPutImage(display,window->pixmap,window->annotate_context,
76603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->ximage,0,0,0,0,width,height);
76613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (IsEventLogging())
76623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
76633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"Pixmap:");
76643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  width, height: %ux%u",
76653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        width,height);
76663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
76673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
76683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Restore cursor.
76693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
76703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XCheckDefineCursor(display,window->id,window->cursor);
76713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickTrue);
76723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
76733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
76743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
76753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
76773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
76783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
76793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X M a k e S t a n d a r d C o l o r m a p                                 %
76803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
76813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
76823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
76833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XMakeStandardColormap() creates an X11 Standard Colormap.
76863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XMakeStandardColormap method is:
76883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76896710d8414f0ed06e4eaf9346366be72e2b4719efcristy%      void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
76906710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
76916710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        XPixelInfo *pixel,ExceptionInfo *exception)
76923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
76943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
76963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
76973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
76993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      returned from XGetVisualInfo.
77003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
77013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
77023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
77033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
77043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
77053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o map_info: If a Standard Colormap type is specified, this structure is
77063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      initialized with info from the Standard Colormap.
77073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
77083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o pixel: Specifies a pointer to a XPixelInfo structure.
77093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
77106710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    o exception: return any errors or warnings in this structure.
77116710d8414f0ed06e4eaf9346366be72e2b4719efcristy%
77123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
77133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__cplusplus) || defined(c_plusplus)
77153ed852eea50f9d4cd633efb8c2b054b8e33c253cristyextern "C" {
77163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
77173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77183ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic inline MagickRealType DiversityPixelIntensity(
77193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const DiversityPacket *pixel)
77203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
77213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickRealType
77223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    intensity;
77233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  intensity=0.299*pixel->red+0.587*pixel->green+0.114*pixel->blue;
77253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(intensity);
77263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
77273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77283ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic int IntensityCompare(const void *x,const void *y)
77293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
77303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DiversityPacket
77313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *color_1,
77323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *color_2;
77333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
77353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    diversity;
77363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  color_1=(DiversityPacket *) x;
77383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  color_2=(DiversityPacket *) y;
77393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  diversity=(int) (DiversityPixelIntensity(color_2)-
77403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    DiversityPixelIntensity(color_1));
77413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(diversity);
77423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
77433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77443ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic int PopularityCompare(const void *x,const void *y)
77453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
77463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DiversityPacket
77473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *color_1,
77483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *color_2;
77493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  color_1=(DiversityPacket *) x;
77513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  color_2=(DiversityPacket *) y;
77523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return((int) color_2->count-(int) color_1->count);
77533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
77543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__cplusplus) || defined(c_plusplus)
77563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
77573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
77583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7759bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristystatic inline Quantum ScaleXToQuantum(const size_t x,
7760bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  const size_t scale)
77613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
77623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return((Quantum) (((MagickRealType) QuantumRange*x)/scale+0.5));
77633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
77643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7765bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XMakeStandardColormap(Display *display,
77663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XVisualInfo *visual_info,XResourceInfo *resource_info,Image *image,
77676710d8414f0ed06e4eaf9346366be72e2b4719efcristy  XStandardColormap *map_info,XPixelInfo *pixel,ExceptionInfo *exception)
77683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
77693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Colormap
77703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    colormap;
77713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7772bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  register ssize_t
77733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
77743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
77763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
77773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7778bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  size_t
77793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_colors,
77803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    retain_colors;
77813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned short
77833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    gray_value;
77843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XColor
77863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    color,
77873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *colors,
77883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p;
77893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
77913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
77923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(visual_info != (XVisualInfo *) NULL);
77933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(map_info != (XStandardColormap *) NULL);
77943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
77953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(pixel != (XPixelInfo *) NULL);
77963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->map_type != (char *) NULL)
77973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
77983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
77993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Standard Colormap is already defined (i.e. xstdcmap).
78003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
78014c08aed51c5899665ade97263692328eea4af106cristy      XGetPixelInfo(display,visual_info,map_info,resource_info,image,
78023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        pixel);
78033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      number_colors=(unsigned int) (map_info->base_pixel+
78043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
78053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
78063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if ((image->matte == MagickFalse) &&
78073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (resource_info->color_recovery == MagickFalse) &&
78083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            resource_info->quantize_info->dither &&
78093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (number_colors < MaxColormapSize))
78103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
78113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Image
78123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *affinity_image;
78133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
78144c08aed51c5899665ade97263692328eea4af106cristy            register Quantum
7815c47d1f8ecfe7d04f0f003cca0fe175658bbf0fb2cristy              *restrict q;
78163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
78173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
78183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Improve image appearance with error diffusion.
78193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
78206710d8414f0ed06e4eaf9346366be72e2b4719efcristy            affinity_image=AcquireImage((ImageInfo *) NULL,exception);
78213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (affinity_image == (Image *) NULL)
78223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ThrowXWindowFatalException(ResourceLimitFatalError,
78233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                "UnableToDitherImage",image->filename);
78243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            affinity_image->columns=number_colors;
78253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            affinity_image->rows=1;
78263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
78273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Initialize colormap image.
78283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
78293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
78303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              1,exception);
78314c08aed51c5899665ade97263692328eea4af106cristy            if (q != (Quantum *) NULL)
78323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
7833bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy                for (i=0; i < (ssize_t) number_colors; i++)
78343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
78354c08aed51c5899665ade97263692328eea4af106cristy                  SetPixelRed(affinity_image,0,q);
78363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if (map_info->red_max != 0)
78374c08aed51c5899665ade97263692328eea4af106cristy                    SetPixelRed(affinity_image,
78384c08aed51c5899665ade97263692328eea4af106cristy                      ScaleXToQuantum((size_t) (i/map_info->red_mult),
78394c08aed51c5899665ade97263692328eea4af106cristy                      map_info->red_max),q);
78404c08aed51c5899665ade97263692328eea4af106cristy                  SetPixelGreen(affinity_image,0,q);
78413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if (map_info->green_max != 0)
78424c08aed51c5899665ade97263692328eea4af106cristy                    SetPixelGreen(affinity_image,
78434c08aed51c5899665ade97263692328eea4af106cristy                      ScaleXToQuantum((size_t) ((i/map_info->green_mult) %
78444c08aed51c5899665ade97263692328eea4af106cristy                      (map_info->green_max+1)),map_info->green_max),q);
78454c08aed51c5899665ade97263692328eea4af106cristy                  SetPixelBlue(affinity_image,0,q);
78463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if (map_info->blue_max != 0)
78474c08aed51c5899665ade97263692328eea4af106cristy                    SetPixelBlue(affinity_image,
78484c08aed51c5899665ade97263692328eea4af106cristy                      ScaleXToQuantum((size_t) (i % map_info->green_mult),
78494c08aed51c5899665ade97263692328eea4af106cristy                      map_info->blue_max),q);
78504c08aed51c5899665ade97263692328eea4af106cristy                  SetPixelAlpha(affinity_image,
78514c08aed51c5899665ade97263692328eea4af106cristy                    TransparentAlpha,q);
7852ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                  q+=GetPixelChannels(affinity_image);
78533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
78543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (void) SyncAuthenticPixels(affinity_image,exception);
78553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (void) RemapImage(resource_info->quantize_info,image,
7856018f07f7333b25743d0afff892450cebdb905c1acristy                  affinity_image,exception);
78573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
78584c08aed51c5899665ade97263692328eea4af106cristy            XGetPixelInfo(display,visual_info,map_info,resource_info,image,
78593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              pixel);
7860574cc26500992189f637cd1cdf93d0654e7df7aecristy            (void) SetImageStorageClass(image,DirectClass,exception);
78613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            affinity_image=DestroyImage(affinity_image);
78623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
78633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (IsEventLogging())
78643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
78653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) LogMagickEvent(X11Event,GetMagickModule(),
78663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            "Standard Colormap:");
78673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) LogMagickEvent(X11Event,GetMagickModule(),
78683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            "  colormap id: 0x%lx",map_info->colormap);
78693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) LogMagickEvent(X11Event,GetMagickModule(),
78703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            "  red, green, blue max: %lu %lu %lu",map_info->red_max,
78713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            map_info->green_max,map_info->blue_max);
78723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) LogMagickEvent(X11Event,GetMagickModule(),
78733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            "  red, green, blue mult: %lu %lu %lu",map_info->red_mult,
78743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            map_info->green_mult,map_info->blue_mult);
78753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
78763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return;
78773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
78783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((visual_info->klass != DirectColor) &&
78793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (visual_info->klass != TrueColor))
78803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if ((image->storage_class == DirectClass) ||
78813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ((int) image->colors > visual_info->colormap_size))
78823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
78833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        QuantizeInfo
78843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          quantize_info;
78853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
78863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
78873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Image has more colors than the visual supports.
78883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
78893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        quantize_info=(*resource_info->quantize_info);
7890bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        quantize_info.number_colors=(size_t) visual_info->colormap_size;
7891018f07f7333b25743d0afff892450cebdb905c1acristy        (void) QuantizeImage(&quantize_info,image,exception);
78923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
78933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
78943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Free previous and create new colormap.
78953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
78963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
78973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  colormap=XDefaultColormap(display,visual_info->screen);
78983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
78993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
79003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      visual_info->visual,visual_info->klass == DirectColor ?
79013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      AllocAll : AllocNone);
79023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (colormap == (Colormap) NULL)
79033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToCreateColormap",
79043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image->filename);
79053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
79063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize the map and pixel info structures.
79073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
79083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XGetMapInfo(visual_info,colormap,map_info);
79094c08aed51c5899665ade97263692328eea4af106cristy  XGetPixelInfo(display,visual_info,map_info,resource_info,image,pixel);
79103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
79113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Allocating colors in server colormap is based on visual class.
79123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
79133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  switch (visual_info->klass)
79143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
79153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case StaticGray:
79163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case StaticColor:
79173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
79183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
79193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Define Standard Colormap for StaticGray or StaticColor visual.
79203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
79213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      number_colors=image->colors;
79223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      colors=(XColor *) AcquireQuantumMemory((size_t)
79233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        visual_info->colormap_size,sizeof(*colors));
79243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (colors == (XColor *) NULL)
79253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ThrowXWindowFatalException(ResourceLimitFatalError,
79263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          "UnableToCreateColormap",image->filename);
79273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      p=colors;
79283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      color.flags=(char) (DoRed | DoGreen | DoBlue);
7929bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      for (i=0; i < (ssize_t) image->colors; i++)
79303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
79313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
79323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
79333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
79343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (visual_info->klass != StaticColor)
79353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
79363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            gray_value=(unsigned short) XPixelIntensity(&color);
79373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.red=gray_value;
79383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.green=gray_value;
79393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.blue=gray_value;
79403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
79413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        status=XAllocColor(display,colormap,&color);
79423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (status == False)
79433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
79443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            colormap=XCopyColormapAndFree(display,colormap);
79453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) XAllocColor(display,colormap,&color);
79463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
79473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        pixel->pixels[i]=color.pixel;
79483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *p++=color;
79493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
79503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
79513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
79523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case GrayScale:
79533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case PseudoColor:
79543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
79553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      unsigned int
79563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        colormap_type;
79573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
79583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
79593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Define Standard Colormap for GrayScale or PseudoColor visual.
79603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
79613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      number_colors=image->colors;
79623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      colors=(XColor *) AcquireQuantumMemory((size_t)
79633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        visual_info->colormap_size,sizeof(*colors));
79643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (colors == (XColor *) NULL)
79653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ThrowXWindowFatalException(ResourceLimitFatalError,
79663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          "UnableToCreateColormap",image->filename);
79673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
79683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Preallocate our GUI colors.
79693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
79703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XAllocColor(display,colormap,&pixel->foreground_color);
79713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XAllocColor(display,colormap,&pixel->background_color);
79723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XAllocColor(display,colormap,&pixel->border_color);
79733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XAllocColor(display,colormap,&pixel->matte_color);
79743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XAllocColor(display,colormap,&pixel->highlight_color);
79753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XAllocColor(display,colormap,&pixel->shadow_color);
79763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XAllocColor(display,colormap,&pixel->depth_color);
79773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XAllocColor(display,colormap,&pixel->trough_color);
79783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (i=0; i < MaxNumberPens; i++)
79793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
79803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
79813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Determine if image colors will "fit" into X server colormap.
79823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
79833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      colormap_type=resource_info->colormap;
7984f2faecf9facdbbb14fcba373365f9f691a9658e0cristy      status=XAllocColorCells(display,colormap,MagickFalse,(unsigned long *)
79853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        NULL,0,pixel->pixels,(unsigned int) image->colors);
79863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status != False)
79873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        colormap_type=PrivateColormap;
79883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (colormap_type == SharedColormap)
79893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
7990c57f694b2d04975a0e501613e34368c464708c19cristy          CacheView
7991c57f694b2d04975a0e501613e34368c464708c19cristy            *image_view;
7992c57f694b2d04975a0e501613e34368c464708c19cristy
79933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          DiversityPacket
79943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *diversity;
79953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
79963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          int
79973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            y;
79983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
79993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register int
80003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            x;
80013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
80023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          unsigned short
80033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            index;
80043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
80053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          XColor
80063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *server_colors;
80073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
80083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
80093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Define Standard colormap for shared GrayScale or PseudoColor visual.
80103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
80113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
80123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            sizeof(*diversity));
80133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (diversity == (DiversityPacket *) NULL)
80143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            ThrowXWindowFatalException(ResourceLimitFatalError,
80153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "UnableToCreateColormap",image->filename);
8016bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy          for (i=0; i < (ssize_t) image->colors; i++)
80173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
8018e42f658533644aecb733785ffd91b286d6778deacristy            diversity[i].red=ClampToQuantum(image->colormap[i].red);
8019e42f658533644aecb733785ffd91b286d6778deacristy            diversity[i].green=ClampToQuantum(image->colormap[i].green);
8020e42f658533644aecb733785ffd91b286d6778deacristy            diversity[i].blue=ClampToQuantum(image->colormap[i].blue);
80213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            diversity[i].index=(unsigned short) i;
80223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            diversity[i].count=0;
80233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
8024c57f694b2d04975a0e501613e34368c464708c19cristy          image_view=AcquireCacheView(image);
80253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) image->rows; y++)
80263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
8027c57f694b2d04975a0e501613e34368c464708c19cristy            register int
80283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              x;
80293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
80304c08aed51c5899665ade97263692328eea4af106cristy            register const Quantum
8031c57f694b2d04975a0e501613e34368c464708c19cristy              *restrict p;
80323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8033c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewAuthenticPixels(image_view,0,(ssize_t) y,
8034c57f694b2d04975a0e501613e34368c464708c19cristy              image->columns,1,exception);
80354c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
80363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
8037c57f694b2d04975a0e501613e34368c464708c19cristy            for (x=(int) image->columns-1; x >= 0; x--)
80384c08aed51c5899665ade97263692328eea4af106cristy            {
80394c08aed51c5899665ade97263692328eea4af106cristy              diversity[(ssize_t) GetPixelIndex(image,p)].count++;
8040ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(image);
80414c08aed51c5899665ade97263692328eea4af106cristy            }
80423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
8043c57f694b2d04975a0e501613e34368c464708c19cristy          image_view=DestroyCacheView(image_view);
80443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
80453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Sort colors by decreasing intensity.
80463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
80473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          qsort((void *) diversity,image->colors,sizeof(*diversity),
80483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            IntensityCompare);
8049bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy          for (i=0; i < (ssize_t) image->colors; )
80503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
80513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            diversity[i].count<<=4;  /* increase this colors popularity */
8052dfe2b6658f367de8f84405263f62768fb853adafcristy            i+=MagickMax((int) (image->colors >> 4),2);
80533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
80543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          diversity[image->colors-1].count<<=4;
80553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          qsort((void *) diversity,image->colors,sizeof(*diversity),
80563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            PopularityCompare);
80573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
80583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Allocate colors.
80593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
80603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          p=colors;
80613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          color.flags=(char) (DoRed | DoGreen | DoBlue);
8062bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy          for (i=0; i < (ssize_t) image->colors; i++)
80633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
80643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            index=diversity[i].index;
80653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.red=
80663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
80673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.green=
80683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
80693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.blue=
80703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
80713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (visual_info->klass != PseudoColor)
80723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
80733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                gray_value=(unsigned short) XPixelIntensity(&color);
80743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                color.red=gray_value;
80753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                color.green=gray_value;
80763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                color.blue=gray_value;
80773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
80783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            status=XAllocColor(display,colormap,&color);
80793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (status == False)
80803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
80813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            pixel->pixels[index]=color.pixel;
80823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *p++=color;
80833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
80843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
80853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Read X server colormap.
80863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
80873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          server_colors=(XColor *) AcquireQuantumMemory((size_t)
80883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            visual_info->colormap_size,sizeof(*server_colors));
80893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (server_colors == (XColor *) NULL)
80903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            ThrowXWindowFatalException(ResourceLimitFatalError,
80913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "UnableToCreateColormap",image->filename);
80923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (x=visual_info->colormap_size-1; x >= 0; x--)
8093bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            server_colors[x].pixel=(size_t) x;
80943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) XQueryColors(display,colormap,server_colors,
80953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (int) MagickMin((unsigned int) visual_info->colormap_size,256));
80963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
80973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Select remaining colors from X server colormap.
80983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
8099bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy          for (; i < (ssize_t) image->colors; i++)
81003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
81013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            index=diversity[i].index;
81023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.red=
81033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
81043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.green=
81053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
81063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.blue=
81073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
81083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (visual_info->klass != PseudoColor)
81093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
81103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                gray_value=(unsigned short) XPixelIntensity(&color);
81113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                color.red=gray_value;
81123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                color.green=gray_value;
81133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                color.blue=gray_value;
81143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
81153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            XBestPixel(display,colormap,server_colors,(unsigned int)
81163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              visual_info->colormap_size,&color);
81173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            pixel->pixels[index]=color.pixel;
81183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *p++=color;
81193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
81203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((int) image->colors < visual_info->colormap_size)
81213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
81223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              /*
81233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                Fill up colors array-- more choices for pen colors.
81243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              */
81253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              retain_colors=MagickMin((unsigned int)
81263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy               (visual_info->colormap_size-image->colors),256);
8127bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy              for (i=0; i < (ssize_t) retain_colors; i++)
81283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                *p++=server_colors[i];
81293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              number_colors+=retain_colors;
81303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
81313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          server_colors=(XColor *) RelinquishMagickMemory(server_colors);
81323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
81333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
81343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
81353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
81363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Define Standard colormap for private GrayScale or PseudoColor visual.
81373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
81383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status == False)
81393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
81403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
81413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Not enough colormap entries in the colormap-- Create a new colormap.
81423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
81433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          colormap=XCreateColormap(display,
81443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            XRootWindow(display,visual_info->screen),visual_info->visual,
81453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            AllocNone);
81463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (colormap == (Colormap) NULL)
81473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            ThrowXWindowFatalException(ResourceLimitFatalError,
81483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "UnableToCreateColormap",image->filename);
81493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          map_info->colormap=colormap;
81503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((int) image->colors < visual_info->colormap_size)
81513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
81523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              /*
81533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                Retain colors from the default colormap to help lessens the
81543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                effects of colormap flashing.
81553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              */
81563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              retain_colors=MagickMin((unsigned int)
81573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (visual_info->colormap_size-image->colors),256);
81583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              p=colors+image->colors;
8159bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy              for (i=0; i < (ssize_t) retain_colors; i++)
81603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
8161c57f694b2d04975a0e501613e34368c464708c19cristy                p->pixel=(unsigned long) i;
81623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                p++;
81633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
81643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) XQueryColors(display,
81653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                XDefaultColormap(display,visual_info->screen),
81663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                colors+image->colors,(int) retain_colors);
81673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              /*
81683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                Transfer colors from default to private colormap.
81693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              */
81703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) XAllocColorCells(display,colormap,MagickFalse,
8171f2faecf9facdbbb14fcba373365f9f691a9658e0cristy                (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
81723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                retain_colors);
81733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              p=colors+image->colors;
8174bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy              for (i=0; i < (ssize_t) retain_colors; i++)
81753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
81763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                p->pixel=pixel->pixels[i];
81773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                p++;
81783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
81793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) XStoreColors(display,colormap,colors+image->colors,
81803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (int) retain_colors);
81813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              number_colors+=retain_colors;
81823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
81833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) XAllocColorCells(display,colormap,MagickFalse,
8184f2faecf9facdbbb14fcba373365f9f691a9658e0cristy            (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
81853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            image->colors);
81863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
81873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
81883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Store the image colormap.
81893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
81903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      p=colors;
81913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      color.flags=(char) (DoRed | DoGreen | DoBlue);
8192bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      for (i=0; i < (ssize_t) image->colors; i++)
81933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
81943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
81953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
81963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
81973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (visual_info->klass != PseudoColor)
81983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
81993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            gray_value=(unsigned short) XPixelIntensity(&color);
82003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.red=gray_value;
82013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.green=gray_value;
82023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.blue=gray_value;
82033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
82043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        color.pixel=pixel->pixels[i];
82053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *p++=color;
82063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
82073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XStoreColors(display,colormap,colors,(int) image->colors);
82083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
82093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
82103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case TrueColor:
82113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case DirectColor:
82123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    default:
82133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
82143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      MagickBooleanType
82153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        linear_colormap;
82163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
82173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
82183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Define Standard Colormap for TrueColor or DirectColor visual.
82193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
82203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      number_colors=(unsigned int) ((map_info->red_max*map_info->red_mult)+
82213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (map_info->green_max*map_info->green_mult)+
82223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (map_info->blue_max*map_info->blue_mult)+1);
82233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      linear_colormap=(number_colors > 4096) ||
82243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (((int) (map_info->red_max+1) == visual_info->colormap_size) &&
82253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy         ((int) (map_info->green_max+1) == visual_info->colormap_size) &&
82263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy         ((int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
82273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy         MagickTrue : MagickFalse;
82283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (linear_colormap != MagickFalse)
8229bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        number_colors=(size_t) visual_info->colormap_size;
82303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
82313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Allocate color array.
82323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
82333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
82343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (colors == (XColor *) NULL)
82353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ThrowXWindowFatalException(ResourceLimitFatalError,
82363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          "UnableToCreateColormap",image->filename);
82373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
82383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Initialize linear color ramp.
82393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
82403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      p=colors;
82413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      color.flags=(char) (DoRed | DoGreen | DoBlue);
82423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (linear_colormap != MagickFalse)
8243bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        for (i=0; i < (ssize_t) number_colors; i++)
82443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
82453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          color.blue=(unsigned short) 0;
82463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (map_info->blue_max != 0)
8247bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            color.blue=(unsigned short) ((size_t)
82483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ((65535L*(i % map_info->green_mult))/map_info->blue_max));
82493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          color.green=color.blue;
82503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          color.red=color.blue;
82513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          color.pixel=XStandardPixel(map_info,&color);
82523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          *p++=color;
82533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
82543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
8255bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        for (i=0; i < (ssize_t) number_colors; i++)
82563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
82573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          color.red=(unsigned short) 0;
82583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (map_info->red_max != 0)
8259bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            color.red=(unsigned short) ((size_t)
82603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ((65535L*(i/map_info->red_mult))/map_info->red_max));
82613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          color.green=(unsigned int) 0;
82623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (map_info->green_max != 0)
8263bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            color.green=(unsigned short) ((size_t)
82643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ((65535L*((i/map_info->green_mult) % (map_info->green_max+1)))/
82653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                map_info->green_max));
82663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          color.blue=(unsigned short) 0;
82673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (map_info->blue_max != 0)
8268bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            color.blue=(unsigned short) ((size_t)
82693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ((65535L*(i % map_info->green_mult))/map_info->blue_max));
82703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          color.pixel=XStandardPixel(map_info,&color);
82713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          *p++=color;
82723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
82733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((visual_info->klass == DirectColor) &&
82743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (colormap != XDefaultColormap(display,visual_info->screen)))
82753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XStoreColors(display,colormap,colors,(int) number_colors);
82763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
8277bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        for (i=0; i < (ssize_t) number_colors; i++)
82783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) XAllocColor(display,colormap,&colors[i]);
82793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
82803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
82813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
82823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((visual_info->klass != DirectColor) &&
82833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (visual_info->klass != TrueColor))
82843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
82853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
82863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Set foreground, background, border, etc. pixels.
82873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
82883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XBestPixel(display,colormap,colors,(unsigned int) number_colors,
82893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &pixel->foreground_color);
82903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XBestPixel(display,colormap,colors,(unsigned int) number_colors,
82913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &pixel->background_color);
82923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (pixel->background_color.pixel == pixel->foreground_color.pixel)
82933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
82943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
82953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Foreground and background colors must differ.
82963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
82973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          pixel->background_color.red=(~pixel->foreground_color.red);
82983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          pixel->background_color.green=
82993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (~pixel->foreground_color.green);
83003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          pixel->background_color.blue=
83013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (~pixel->foreground_color.blue);
83023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          XBestPixel(display,colormap,colors,(unsigned int) number_colors,
83033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            &pixel->background_color);
83043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
83053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XBestPixel(display,colormap,colors,(unsigned int) number_colors,
83063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &pixel->border_color);
83073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XBestPixel(display,colormap,colors,(unsigned int) number_colors,
83083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &pixel->matte_color);
83093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XBestPixel(display,colormap,colors,(unsigned int) number_colors,
83103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &pixel->highlight_color);
83113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XBestPixel(display,colormap,colors,(unsigned int) number_colors,
83123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &pixel->shadow_color);
83133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XBestPixel(display,colormap,colors,(unsigned int) number_colors,
83143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &pixel->depth_color);
83153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XBestPixel(display,colormap,colors,(unsigned int) number_colors,
83163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &pixel->trough_color);
83173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (i=0; i < MaxNumberPens; i++)
83183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
83193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XBestPixel(display,colormap,colors,(unsigned int) number_colors,
83203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          &pixel->pen_colors[i]);
83213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
83223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
8323c57f694b2d04975a0e501613e34368c464708c19cristy      pixel->colors=(ssize_t) (image->colors+MaxNumberPens);
83243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
83253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  colors=(XColor *) RelinquishMagickMemory(colors);
83263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (IsEventLogging())
83273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
83283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"Standard Colormap:");
83293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  colormap id: 0x%lx",
83303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        map_info->colormap);
83313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
83323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "  red, green, blue max: %lu %lu %lu",map_info->red_max,
83333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        map_info->green_max,map_info->blue_max);
83343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
83353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "  red, green, blue mult: %lu %lu %lu",map_info->red_mult,
83363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        map_info->green_mult,map_info->blue_mult);
83373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
83383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
83393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
83403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
83413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
83433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
83443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
83453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X M a k e W i n d o w                                                     %
83463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
83473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
83483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
83493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XMakeWindow() creates an X11 window.
83523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XMakeWindow method is:
83543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XMakeWindow(Display *display,Window parent,char **argv,int argc,
83563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XClassHint *class_hint,XWMHints *manager_hints,
83573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XWindowInfo *window_info)
83583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
83603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
83623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
83633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o parent: Specifies the parent window_info.
83653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o argv: Specifies the application's argument list.
83673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o argc: Specifies the number of arguments.
83693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o class_hint: Specifies a pointer to a X11 XClassHint structure.
83713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o manager_hints: Specifies a pointer to a X11 XWMHints structure.
83733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window_info: Specifies a pointer to a X11 XWindowInfo structure.
83753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
8377bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XMakeWindow(Display *display,Window parent,char **argv,
83783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int argc,XClassHint *class_hint,XWMHints *manager_hints,
83793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XWindowInfo *window_info)
83803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
83813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define MinWindowSize  64
83823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
83833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Atom
83843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    atom_list[2];
83853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
83863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
83873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    gravity;
83883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
83893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static XTextProperty
83903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    icon_name,
83913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window_name;
83923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
83933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
83943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
83953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
83963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XSizeHints
83973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *size_hints;
83983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
83993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
84003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set window info hints.
84013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
84023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
84033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
84043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window_info != (XWindowInfo *) NULL);
84053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_hints=XAllocSizeHints();
84063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (size_hints == (XSizeHints *) NULL)
84073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(XServerFatalError,"UnableToMakeXWindow",argv[0]);
8408dfe2b6658f367de8f84405263f62768fb853adafcristy  size_hints->flags=(int) window_info->flags;
84093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_hints->x=window_info->x;
84103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_hints->y=window_info->y;
84113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_hints->width=(int) window_info->width;
84123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_hints->height=(int) window_info->height;
84133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info->immutable != MagickFalse)
84143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
84153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
84163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Window size cannot be changed.
84173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
84183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->min_width=size_hints->width;
84193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->min_height=size_hints->height;
84203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->max_width=size_hints->width;
84213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->max_height=size_hints->height;
84223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->flags|=PMinSize;
84233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->flags|=PMaxSize;
84243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
84253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
84263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
84273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
84283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Window size can be changed.
84293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
84303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->min_width=(int) window_info->min_width;
84313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->min_height=(int) window_info->min_height;
84323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->flags|=PResizeInc;
84333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->width_inc=(int) window_info->width_inc;
84343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->height_inc=(int) window_info->height_inc;
84353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if !defined(PRE_R4_ICCCM)
84363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->flags|=PBaseSize;
84373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->base_width=size_hints->width_inc;
84383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->base_height=size_hints->height_inc;
84393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
84403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
84413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  gravity=NorthWestGravity;
84423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info->geometry != (char *) NULL)
84433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
84443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      char
84453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        default_geometry[MaxTextExtent],
84463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        geometry[MaxTextExtent];
84473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
84483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      int
84493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        flags;
84503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
84513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      register char
84523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *p;
84533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
84543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
84553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        User specified geometry.
84563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
8457b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy      (void) FormatLocaleString(default_geometry,MaxTextExtent,"%dx%d",
84583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        size_hints->width,size_hints->height);
84593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) CopyMagickString(geometry,window_info->geometry,MaxTextExtent);
84603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      p=geometry;
84613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      while (strlen(p) != 0)
84623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
84633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '%'))
84643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          p++;
84653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        else
84663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) CopyMagickString(p,p+1,MaxTextExtent);
84673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
84683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
84693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
84703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &size_hints->width,&size_hints->height,&gravity);
84713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((flags & WidthValue) && (flags & HeightValue))
84723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        size_hints->flags|=USSize;
84733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((flags & XValue) && (flags & YValue))
84743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
84753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          size_hints->flags|=USPosition;
84763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window_info->x=size_hints->x;
84773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window_info->y=size_hints->y;
84783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
84793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
84803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if !defined(PRE_R4_ICCCM)
84813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_hints->win_gravity=gravity;
84823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_hints->flags|=PWinGravity;
84833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
84843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info->id == (Window) NULL)
84853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
84863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (unsigned int) size_hints->width,(unsigned int) size_hints->height,
84873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_info->border_width,(int) window_info->depth,InputOutput,
8488c57f694b2d04975a0e501613e34368c464708c19cristy      window_info->visual,(unsigned long) window_info->mask,
8489c57f694b2d04975a0e501613e34368c464708c19cristy      &window_info->attributes);
84903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
84913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
84923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      MagickStatusType
84933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        mask;
84943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
84953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XEvent
84963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        sans_event;
84973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
84983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XWindowChanges
84993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window_changes;
85003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
85013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
85023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Window already exists;  change relevant attributes.
85033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
8504c57f694b2d04975a0e501613e34368c464708c19cristy      (void) XChangeWindowAttributes(display,window_info->id,(unsigned long)
8505c57f694b2d04975a0e501613e34368c464708c19cristy        window_info->mask,&window_info->attributes);
85063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      mask=ConfigureNotify;
85073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      while (XCheckTypedWindowEvent(display,window_info->id,(int) mask,&sans_event)) ;
85083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_changes.x=window_info->x;
85093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_changes.y=window_info->y;
85103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_changes.width=(int) window_info->width;
85113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_changes.height=(int) window_info->height;
85123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      mask=(MagickStatusType) (CWWidth | CWHeight);
85133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window_info->flags & USPosition)
85143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        mask|=CWX | CWY;
85153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
85163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        mask,&window_changes);
85173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
85183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info->id == (Window) NULL)
85193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(XServerFatalError,"UnableToCreateWindow",
85203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_info->name);
85213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XStringListToTextProperty(&window_info->name,1,&window_name);
85223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
85233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
85243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_info->name);
85253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
85263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
85273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
85283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_info->icon_name);
85293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info->icon_geometry != (char *) NULL)
85303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
85313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      int
85323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        flags,
85333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        height,
85343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        width;
85353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
85363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
85373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        User specified icon geometry.
85383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
85393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->flags|=USPosition;
85403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
85413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (char *) NULL,0,size_hints,&manager_hints->icon_x,
85423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &manager_hints->icon_y,&width,&height,&gravity);
85433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((flags & XValue) && (flags & YValue))
85443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        manager_hints->flags|=IconPositionHint;
85453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
85463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
85473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    size_hints,manager_hints,class_hint);
85483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_name.value != (void *) NULL)
85493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
85503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFree((void *) window_name.value);
85513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_name.value=(unsigned char *) NULL;
85523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_name.nitems=0;
85533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
85543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (icon_name.value != (void *) NULL)
85553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
85563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFree((void *) icon_name.value);
85573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_name.value=(unsigned char *) NULL;
85583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_name.nitems=0;
85593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
85603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  atom_list[0]=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
85613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  atom_list[1]=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
85623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSetWMProtocols(display,window_info->id,atom_list,2);
85633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFree((void *) size_hints);
85643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info->shape != MagickFalse)
85653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
85663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHAPE)
85673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      int
85683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        error_base,
85693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        event_base;
85703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
85713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
85723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Can we apply a non-rectangular shaping mask?
85733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
85743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      error_base=0;
85753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      event_base=0;
85763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
85773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window_info->shape=MagickFalse;
85783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else
85793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_info->shape=MagickFalse;
85803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
85813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
85823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info->shared_memory)
85833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
85843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
85853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
85863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Can we use shared memory with this window?
85873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
85883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (XShmQueryExtension(display) == 0)
85893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window_info->shared_memory=MagickFalse;
85903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else
85913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_info->shared_memory=MagickFalse;
85923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
85933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
85943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info->image=NewImageList();
85953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info->destroy=MagickFalse;
85963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
85973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
85983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
85993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
86013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
86023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
86033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X M a g i c k P r o g r e s s M o n i t o r                               %
86043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
86053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
86063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
86073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XMagickProgressMonitor() displays the progress a task is making in
86103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  completing a task.
86113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XMagickProgressMonitor method is:
86133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XMagickProgressMonitor(const char *task,
86153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const MagickOffsetType quantum,const MagickSizeType span,
86163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        void *client_data)
86173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
86193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o task: Identifies the task in progress.
86213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o quantum: Specifies the quantum position within the span which represents
86233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      how much progress has been made in completing a task.
86243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o span: Specifies the span relative to completing a task.
86263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o client_data: Pointer to any client data.
86283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
86303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
86313ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic const char *GetLocaleMonitorMessage(const char *text)
86323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
86333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
86343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    message[MaxTextExtent],
86353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    tag[MaxTextExtent];
86363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
86373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char
86383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *locale_message;
86393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
86403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register char
86413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p;
86423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
86433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) CopyMagickMemory(tag,text,MaxTextExtent);
86443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  p=strrchr(tag,'/');
86453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (p != (char *) NULL)
86463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p='\0';
8647b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(message,MaxTextExtent,"Monitor/%s",tag);
86483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  locale_message=GetLocaleMessage(message);
86493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (locale_message == message)
86503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(text);
86513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(locale_message);
86523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
86533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8654bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate MagickBooleanType XMagickProgressMonitor(const char *tag,
86553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const MagickOffsetType quantum,const MagickSizeType span,
86563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  void *magick_unused(client_data))
86573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
86583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XWindows
86593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *windows;
86603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
86613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows=XSetWindows((XWindows *) ~0);
86623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows == (XWindows *) NULL)
86633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickTrue);
86643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->info.mapped != MagickFalse)
86653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XProgressMonitorWidget(windows->display,windows,
86663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      GetLocaleMonitorMessage(tag),quantum,span);
86673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickTrue);
86683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
86693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
86703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
86713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
86733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
86743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
86753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X Q u e r y C o l o r D a t a b a s e                                     %
86763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
86773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
86783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
86793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86819950d57e1124b73f684fb5946e206994cefda628cristy%  XQueryColorCompliance() looks up a RGB values for a color given in the target
86823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  string.
86833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XQueryColorDatabase method is:
86853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86869950d57e1124b73f684fb5946e206994cefda628cristy%      MagickBooleanType XQueryColorCompliance(const char *target,XColor *color)
86873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
86893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o target: Specifies the color to lookup in the X color database.
86913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8692101ab708b0574518ac5715da4d3915400e9df79acristy%    o color: A pointer to an PixelInfo structure.  The RGB value of the target
86933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      color is returned as this value.
86943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
86969950d57e1124b73f684fb5946e206994cefda628cristyMagickPrivate MagickBooleanType XQueryColorCompliance(const char *target,
86973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XColor *color)
86983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
86993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Colormap
87003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    colormap;
87013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
87023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static Display
87033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *display = (Display *) NULL;
87043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
87053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
87063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
87073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
87083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XColor
87093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    xcolor;
87103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
87113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
87123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize color return value.
87133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
87143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(color != (XColor *) NULL);
87153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  color->red=0;
87163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  color->green=0;
87173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  color->blue=0;
87183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  color->flags=(char) (DoRed | DoGreen | DoBlue);
87193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((target == (char *) NULL) || (*target == '\0'))
87203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    target="#ffffffffffff";
87213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
87223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Let the X server define the color for us.
87233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
87243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (display == (Display *) NULL)
87253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    display=XOpenDisplay((char *) NULL);
87263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (display == (Display *) NULL)
87273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
87283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target);
87293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(MagickFalse);
87303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
87313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  colormap=XDefaultColormap(display,XDefaultScreen(display));
87323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XParseColor(display,colormap,(char *) target,&xcolor);
87333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
87343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(XServerError,"ColorIsNotKnownToServer",target)
87353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
87363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
87373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      color->red=xcolor.red;
87383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      color->green=xcolor.green;
87393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      color->blue=xcolor.blue;
87403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      color->flags=xcolor.flags;
87413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
87423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(status != False ? MagickTrue : MagickFalse);
87433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
87443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
87453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
87463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
87483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
87493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
87503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X Q u e r y P o s i t i o n                                               %
87513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
87523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
87533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
87543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XQueryPosition() gets the pointer coordinates relative to a window.
87573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XQueryPosition method is:
87593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XQueryPosition(Display *display,const Window window,int *x,int *y)
87613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
87633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
87653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
87663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a Window.
87683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o x: Return the x coordinate of the pointer relative to the origin of the
87703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      window.
87713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o y: Return the y coordinate of the pointer relative to the origin of the
87733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      window.
87743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
8776bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XQueryPosition(Display *display,const Window window,int *x,int *y)
87773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
87783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
87793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x_root,
87803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y_root;
87813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
87823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
87833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    mask;
87843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
87853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
87863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root_window;
87873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
87883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
87893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
87903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (Window) NULL);
87913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(x != (int *) NULL);
87923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(y != (int *) NULL);
87933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
87943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x,y,&mask);
87953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
87963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
87973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
87983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
88003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
88013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
88023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X R e f r e s h W i n d o w                                               %
88033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
88043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
88053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
88063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
88083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XRefreshWindow() refreshes an image in a X window.
88093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
88103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XRefreshWindow method is:
88113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
88123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XRefreshWindow(Display *display,const XWindowInfo *window,
88133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const XEvent *event)
88143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
88153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
88163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
88173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
88183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
88193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
88203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a XWindowInfo structure.
88213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
88223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o event: Specifies a pointer to a XEvent structure.  If it is NULL,
88233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      the entire image is refreshed.
88243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
88253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
8826bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XRefreshWindow(Display *display,const XWindowInfo *window,
88273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const XEvent *event)
88283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
88293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
88303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x,
88313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y;
88323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
88333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
88343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    height,
88353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    width;
88363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
88373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
88383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
88393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (XWindowInfo *) NULL);
88403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->ximage == (XImage *) NULL)
88413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
88423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (event != (XEvent *) NULL)
88433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
88443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
88453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Determine geometry from expose event.
88463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
88473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      x=event->xexpose.x;
88483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      y=event->xexpose.y;
88493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      width=(unsigned int) event->xexpose.width;
88503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      height=(unsigned int) event->xexpose.height;
88513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
88523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
88533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
88543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XEvent
88553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        sans_event;
88563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
88573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
88583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Refresh entire window; discard outstanding expose events.
88593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
88603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      x=0;
88613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      y=0;
88623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      width=window->width;
88633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      height=window->height;
88643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8865a0e5ad575fbabf93f14a3748ae501376928998fccristy      if (window->matte_pixmap != (Pixmap) NULL)
8866a0e5ad575fbabf93f14a3748ae501376928998fccristy        {
8867a0e5ad575fbabf93f14a3748ae501376928998fccristy#if defined(MAGICKCORE_HAVE_SHAPE)
8868a0e5ad575fbabf93f14a3748ae501376928998fccristy          if (window->shape != MagickFalse)
8869a0e5ad575fbabf93f14a3748ae501376928998fccristy            XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8870a0e5ad575fbabf93f14a3748ae501376928998fccristy              window->matte_pixmap,ShapeSet);
8871a0e5ad575fbabf93f14a3748ae501376928998fccristy#endif
8872a0e5ad575fbabf93f14a3748ae501376928998fccristy        }
88733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
88743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
88753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Check boundary conditions.
88763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
88773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((window->ximage->width-(x+window->x)) < (int) width)
88783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    width=(unsigned int) (window->ximage->width-(x+window->x));
88793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((window->ximage->height-(y+window->y)) < (int) height)
88803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    height=(unsigned int) (window->ximage->height-(y+window->y));
88813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
88823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Refresh image.
88833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
88843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->matte_pixmap != (Pixmap) NULL)
8885a0e5ad575fbabf93f14a3748ae501376928998fccristy    (void) XSetClipMask(display,window->annotate_context,window->matte_pixmap);
88863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->pixmap != (Pixmap) NULL)
88873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
88883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->depth > 1)
88893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XCopyArea(display,window->pixmap,window->id,
88903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window->annotate_context,x+window->x,y+window->y,width,height,x,y);
88913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
88923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XCopyPlane(display,window->pixmap,window->id,
88933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window->highlight_context,x+window->x,y+window->y,width,height,x,y,
88943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          1L);
88953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
88963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
88973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
88983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
88993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->shared_memory)
89003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XShmPutImage(display,window->id,window->annotate_context,
89013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
89023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
89033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->shared_memory == MagickFalse)
89043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XPutImage(display,window->id,window->annotate_context,
89053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window->ximage,x+window->x,y+window->y,x,y,width,height);
89063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
89073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->matte_pixmap != (Pixmap) NULL)
89083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XSetClipMask(display,window->annotate_context,None);
89093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFlush(display);
89103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
89113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
89123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
89133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
89153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
89163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
89173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X R e m o t e C o m m a n d                                               %
89183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
89193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
89203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
89213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
89233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XRemoteCommand() forces a remote display(1) to display the specified
89243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  image filename.
89253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
89263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XRemoteCommand method is:
89273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
89283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      MagickBooleanType XRemoteCommand(Display *display,const char *window,
89293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *filename)
89303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
89313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
89323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
89333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
89343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
89353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
89363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies the name or id of an X window.
89373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
89383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o filename: the name of the image filename to display.
89393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
89403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
89413ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport MagickBooleanType XRemoteCommand(Display *display,
89423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *window,const char *filename)
89433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
89443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Atom
89453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    remote_atom;
89463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
89473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
89483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    remote_window,
89493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root_window;
89503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
89513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(filename != (char *) NULL);
89523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
89533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (display == (Display *) NULL)
89543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    display=XOpenDisplay((char *) NULL);
89553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (display == (Display *) NULL)
89563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
89573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowException(XServerError,"UnableToOpenXServer",filename);
89583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(MagickFalse);
89593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
89603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  remote_atom=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
89613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  remote_window=(Window) NULL;
89623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  root_window=XRootWindow(display,XDefaultScreen(display));
89633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window != (char *) NULL)
89643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
89653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
89663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Search window hierarchy and identify any clients by name or ID.
89673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
89683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (isdigit((unsigned char) *window) != 0)
89693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        remote_window=XWindowByID(display,root_window,(Window)
89703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          strtol((char *) window,(char **) NULL,0));
89713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (remote_window == (Window) NULL)
89723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        remote_window=XWindowByName(display,root_window,window);
89733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
89743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (remote_window == (Window) NULL)
89753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    remote_window=XWindowByProperty(display,root_window,remote_atom);
89763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (remote_window == (Window) NULL)
89773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
89783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowException(XServerError,"UnableToConnectToRemoteDisplay",
89793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        filename);
89803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(MagickFalse);
89813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
89823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
89833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Send remote command.
89843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
89853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  remote_atom=XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
89863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
89873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    PropModeReplace,(unsigned char *) filename,(int) strlen(filename));
89883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSync(display,MagickFalse);
89893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickTrue);
89903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
89913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
89923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
89933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
89953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
89963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
89973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X R e t a i n W i n d o w C o l o r s                                     %
89983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
89993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
90003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
90013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
90033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XRetainWindowColors() sets X11 color resources on a window.  This preserves
90043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  the colors associated with an image displayed on the window.
90053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
90063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XRetainWindowColors method is:
90073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
90083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XRetainWindowColors(Display *display,const Window window)
90093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
90103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
90113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
90123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
90133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
90143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
90153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a XWindowInfo structure.
90163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
90173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
90183ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport void XRetainWindowColors(Display *display,const Window window)
90193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
90203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Atom
90213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    property;
90223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
90233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Pixmap
90243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixmap;
90253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
90263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
90273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Put property on the window.
90283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
90293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
90303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
90313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (Window) NULL);
90323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
90333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (property == (Atom) NULL)
90343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
90353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowFatalException(XServerError,"UnableToCreateProperty",
90363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "_XSETROOT_ID");
90373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return;
90383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
90393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixmap=XCreatePixmap(display,window,1,1,1);
90403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (pixmap == (Pixmap) NULL)
90413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
90423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowFatalException(XServerError,"UnableToCreateBitmap","");
90433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return;
90443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
90453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
90463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (unsigned char *) &pixmap,1);
90473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSetCloseDownMode(display,RetainPermanent);
90483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
90493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
90503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
90513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
90533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
90543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
90553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X S e l e c t W i n d o w                                                 %
90563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
90573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
90583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
90593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
90613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XSelectWindow() allows a user to select a window using the mouse.  If the
90623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  mouse moves, a cropping rectangle is drawn and the extents of the rectangle
90633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  is returned in the crop_info structure.
90643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
90653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XSelectWindow function is:
90663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
90673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      target_window=XSelectWindow(display,crop_info)
90683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
90693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
90703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
90713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: XSelectWindow returns the window id.
90723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
90733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a pointer to the Display structure;  returned from
90743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
90753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
90763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o crop_info: Specifies a pointer to a RectangleInfo structure.  It
90773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      contains the extents of any cropping rectangle.
90783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
90793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
90803ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Window XSelectWindow(Display *display,RectangleInfo *crop_info)
90813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
90823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define MinimumCropArea  (unsigned int) 9
90833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
90843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Cursor
90853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    target_cursor;
90863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
90873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  GC
90883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    annotate_context;
90893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
90903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
90913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    presses,
90923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x_offset,
90933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y_offset;
90943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
90953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
90963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
90973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
90983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
90993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root_window,
91003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    target_window;
91013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
91023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XEvent
91033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    event;
91043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
91053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XGCValues
91063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    context_values;
91073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
91083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
91093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize graphic context.
91103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
91113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
91123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
91133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(crop_info != (RectangleInfo *) NULL);
91143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  root_window=XRootWindow(display,XDefaultScreen(display));
91153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  context_values.background=XBlackPixel(display,XDefaultScreen(display));
91163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
91173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  context_values.function=GXinvert;
91183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  context_values.plane_mask=
91193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    context_values.background ^ context_values.foreground;
91203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  context_values.subwindow_mode=IncludeInferiors;
9121bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  annotate_context=XCreateGC(display,root_window,(size_t) (GCBackground |
91223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    GCForeground | GCFunction | GCSubwindowMode),&context_values);
91233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (annotate_context == (GC) NULL)
91243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
91253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
91263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Grab the pointer using target cursor.
91273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
91283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
91293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XDefaultScreen(display)),(char * ) "white",(char * ) "black");
91303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XGrabPointer(display,root_window,MagickFalse,(unsigned int)
91313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
91323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    GrabModeAsync,root_window,target_cursor,CurrentTime);
91333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status != GrabSuccess)
91343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
91353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowFatalException(XServerError,"UnableToGrabMouse","");
91363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return((Window) NULL);
91373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
91383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
91393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Select a window.
91403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
91413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  crop_info->width=0;
91423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  crop_info->height=0;
91433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  presses=0;
91443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  target_window=(Window) NULL;
91453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x_offset=0;
91463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y_offset=0;
91473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  do
91483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
91493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if ((crop_info->width*crop_info->height) >= MinimumCropArea)
91503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDrawRectangle(display,root_window,annotate_context,
91513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
91523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) crop_info->height-1);
91533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    /*
91543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Allow another event.
91553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    */
91563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XAllowEvents(display,SyncPointer,CurrentTime);
91573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XWindowEvent(display,root_window,ButtonPressMask |
91583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ButtonReleaseMask | ButtonMotionMask,&event);
91593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if ((crop_info->width*crop_info->height) >= MinimumCropArea)
91603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDrawRectangle(display,root_window,annotate_context,
91613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
91623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) crop_info->height-1);
91633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    switch (event.type)
91643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
91653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case ButtonPress:
91663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
91673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        target_window=XGetSubwindow(display,event.xbutton.subwindow,
91683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          event.xbutton.x,event.xbutton.y);
91693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (target_window == (Window) NULL)
91703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          target_window=root_window;
91713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        x_offset=event.xbutton.x_root;
91723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        y_offset=event.xbutton.y_root;
9173ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy        crop_info->x=(ssize_t) x_offset;
9174ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy        crop_info->y=(ssize_t) y_offset;
91753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        crop_info->width=0;
91763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        crop_info->height=0;
91773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        presses++;
91783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
91793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
91803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case ButtonRelease:
91813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
91823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        presses--;
91833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
91843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
91853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case MotionNotify:
91863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
91873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
91883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Discard pending button motion events.
91893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
91903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9191ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy        crop_info->x=(ssize_t) event.xmotion.x;
9192ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy        crop_info->y=(ssize_t) event.xmotion.y;
91933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
91943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Check boundary conditions.
91953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
91963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if ((int) crop_info->x < x_offset)
9197ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy          crop_info->width=(size_t) (x_offset-crop_info->x);
91983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        else
91993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
9200ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy            crop_info->width=(size_t) (crop_info->x-x_offset);
9201ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy            crop_info->x=(ssize_t) x_offset;
92023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
92033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if ((int) crop_info->y < y_offset)
9204ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy          crop_info->height=(size_t) (y_offset-crop_info->y);
92053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        else
92063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
9207ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy            crop_info->height=(size_t) (crop_info->y-y_offset);
9208ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy            crop_info->y=(ssize_t) y_offset;
92093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
92103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
92113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      default:
92123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
92133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
92143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  } while ((target_window == (Window) NULL) || (presses > 0));
92153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XUngrabPointer(display,CurrentTime);
92163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFreeCursor(display,target_cursor);
92173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFreeGC(display,annotate_context);
92183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((crop_info->width*crop_info->height) < MinimumCropArea)
92193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
92203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      crop_info->width=0;
92213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      crop_info->height=0;
92223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
92233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((crop_info->width != 0) && (crop_info->height != 0))
92243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    target_window=root_window;
92253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(target_window);
92263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
92273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
92283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
92293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
92313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
92323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
92333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X S e t C u r s o r S t a t e                                             %
92343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
92353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
92363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
92373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
92393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XSetCursorState() sets the cursor state to busy, otherwise the cursor are
92403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  reset to their default.
92413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
92423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XXSetCursorState method is:
92433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
92443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XSetCursorState(display,windows,const MagickStatusType state)
92453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
92463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
92473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
92483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
92493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
92503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
92513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o windows: Specifies a pointer to a XWindows structure.
92523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
92533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o state: An unsigned integer greater than 0 sets the cursor state
92543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      to busy, otherwise the cursor are reset to their default.
92553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
92563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
9257bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XSetCursorState(Display *display,XWindows *windows,
92583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const MagickStatusType state)
92593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
92603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
92613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
92623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(windows != (XWindows *) NULL);
92633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (state)
92643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
92653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,windows->image.id,
92663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->image.busy_cursor);
92673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,windows->pan.id,
92683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->pan.busy_cursor);
92693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,windows->magnify.id,
92703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->magnify.busy_cursor);
92713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,windows->command.id,
92723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->command.busy_cursor);
92733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
92743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
92753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
92763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,windows->image.id,
92773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->image.cursor);
92783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
92793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,windows->magnify.id,
92803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->magnify.cursor);
92813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,windows->command.id,
92823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->command.cursor);
92833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,windows->command.id,
92843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->widget.cursor);
92853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
92863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
92873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->info.mapped=MagickFalse;
92883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
92893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
92903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
92913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
92933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
92943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
92953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X S e t W i n d o w s                                                     %
92963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
92973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
92983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
92993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
93013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XSetWindows() sets the X windows structure if the windows info is specified.
93023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  Otherwise the current windows structure is returned.
93033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
93043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XSetWindows method is:
93053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
93063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XWindows *XSetWindows(XWindows *windows_info)
93073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
93083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
93093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
93103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o windows_info: Initialize the Windows structure with this information.
93113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
93123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
9313bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate XWindows *XSetWindows(XWindows *windows_info)
93143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
93153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static XWindows
93163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *windows = (XWindows *) NULL;
93173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
93183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows_info != (XWindows *) ~0)
93193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
93203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows=(XWindows *) RelinquishMagickMemory(windows);
93213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows=windows_info;
93223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
93233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(windows);
93243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
93253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
93263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
93283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
93293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
93303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X U s e r P r e f e r e n c e s                                           %
93313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
93323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
93333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
93343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
93363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XUserPreferences() saves the preferences in a configuration file in the
93373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  users' home directory.
93383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
93393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XUserPreferences method is:
93403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
93413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XUserPreferences(XResourceInfo *resource_info)
93423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
93433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
93443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
93453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
93463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
93473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
9348bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XUserPreferences(XResourceInfo *resource_info)
93493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
93503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(X11_PREFERENCES_PATH)
93513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
93523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    cache[MaxTextExtent],
93533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    filename[MaxTextExtent],
93543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    specifier[MaxTextExtent];
93553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
93563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char
9357104cea817534e8601291610f22e496c10f8f9ddbcristy    *client_name,
93583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *value;
93593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
93603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmDatabase
93613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    preferences_database;
93623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
93633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
93643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Save user preferences to the client configuration file.
93653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
93663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
9367104cea817534e8601291610f22e496c10f8f9ddbcristy  client_name=GetClientName();
93683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  preferences_database=XrmGetStringDatabase("");
9369b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(specifier,MaxTextExtent,"%s.backdrop",client_name);
93703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  value=resource_info->backdrop ? "True" : "False";
93713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutStringResource(&preferences_database,specifier,(char *) value);
9372b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(specifier,MaxTextExtent,"%s.colormap",client_name);
93733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  value=resource_info->colormap == SharedColormap ? "Shared" : "Private";
93743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutStringResource(&preferences_database,specifier,(char *) value);
9375b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(specifier,MaxTextExtent,"%s.confirmExit",
9376104cea817534e8601291610f22e496c10f8f9ddbcristy    client_name);
93773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  value=resource_info->confirm_exit ? "True" : "False";
93783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutStringResource(&preferences_database,specifier,(char *) value);
9379b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(specifier,MaxTextExtent,"%s.confirmEdit",
9380104cea817534e8601291610f22e496c10f8f9ddbcristy    client_name);
93813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  value=resource_info->confirm_edit ? "True" : "False";
93823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutStringResource(&preferences_database,specifier,(char *) value);
9383b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(specifier,MaxTextExtent,"%s.displayWarnings",
9384104cea817534e8601291610f22e496c10f8f9ddbcristy    client_name);
93853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  value=resource_info->display_warnings ? "True" : "False";
93863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutStringResource(&preferences_database,specifier,(char *) value);
9387b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(specifier,MaxTextExtent,"%s.dither",client_name);
93883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  value=resource_info->quantize_info->dither ? "True" : "False";
93893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutStringResource(&preferences_database,specifier,(char *) value);
9390b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(specifier,MaxTextExtent,"%s.gammaCorrect",
9391104cea817534e8601291610f22e496c10f8f9ddbcristy    client_name);
93923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  value=resource_info->gamma_correct ? "True" : "False";
93933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutStringResource(&preferences_database,specifier,(char *) value);
9394b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(specifier,MaxTextExtent,"%s.undoCache",client_name);
9395b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(cache,MaxTextExtent,"%.20g",(double)
93963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_info->undo_cache);
93973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutStringResource(&preferences_database,specifier,cache);
9398b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(specifier,MaxTextExtent,"%s.usePixmap",client_name);
93993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  value=resource_info->use_pixmap ? "True" : "False";
94003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutStringResource(&preferences_database,specifier,(char *) value);
9401b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleString(filename,MaxTextExtent,"%s%src",
9402104cea817534e8601291610f22e496c10f8f9ddbcristy    X11_PREFERENCES_PATH,client_name);
94033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ExpandFilename(filename);
94043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutFileDatabase(preferences_database,filename);
94053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
94063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
94073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
94083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
94093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X V i s u a l C l a s s N a m e                                           %
94143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XVisualClassName() returns the visual class name as a character string.
94203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XVisualClassName method is:
94223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      char *XVisualClassName(const int visual_class)
94243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
94263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o visual_type: XVisualClassName returns the visual class as a character
94283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      string.
94293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o class: Specifies the visual class.
94313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
94333ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic const char *XVisualClassName(const int visual_class)
94343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
94353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  switch (visual_class)
94363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
94373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case StaticGray: return("StaticGray");
94383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case GrayScale: return("GrayScale");
94393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case StaticColor: return("StaticColor");
94403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case PseudoColor: return("PseudoColor");
94413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case TrueColor: return("TrueColor");
94423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case DirectColor: return("DirectColor");
94433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
94443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return("unknown visual class");
94453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
94463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
94473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
94483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X W a r n i n g                                                           %
94533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XWarning() displays a warning reason in a Notice widget.
94593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XWarning method is:
94613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XWarning(const unsigned int warning,const char *reason,
94633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *description)
94643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
94663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o warning: Specifies the numeric warning category.
94683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o reason: Specifies the reason to display before terminating the
94703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      program.
94713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o description: Specifies any description to the reason.
94733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
9475bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XWarning(const ExceptionType magick_unused(warning),
94763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *reason,const char *description)
94773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
94783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
94793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    text[MaxTextExtent];
94803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
94813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XWindows
94823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *windows;
94833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
94843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (reason == (char *) NULL)
94853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
94863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) CopyMagickString(text,reason,MaxTextExtent);
94873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ConcatenateMagickString(text,":",MaxTextExtent);
94883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows=XSetWindows((XWindows *) ~0);
94893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XNoticeWidget(windows->display,windows,text,(char *) description);
94903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
94913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
94923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
94933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X W i n d o w B y I D                                                     %
94983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
95003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
95013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XWindowByID() locates a child window with a given ID.  If not window with
95043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  the given name is found, 0 is returned.   Only the window specified and its
95053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  subwindows are searched.
95063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XWindowByID function is:
95083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      child=XWindowByID(display,window,id)
95103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
95123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o child: XWindowByID returns the window with the specified
95143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      id.  If no windows are found, XWindowByID returns 0.
95153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a pointer to the Display structure;  returned from
95173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
95183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o id: Specifies the id of the window to locate.
95203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
9522bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate Window XWindowByID(Display *display,const Window root_window,
9523bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  const size_t id)
95243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
95253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  RectangleInfo
95263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    rectangle_info;
95273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
95283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
95293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
95303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
95313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
95323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
95333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
95343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
95353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_children;
95363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
95373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
95383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    child,
95393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *children,
95403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window;
95413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
95423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
95433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
95443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(root_window != (Window) NULL);
95453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (id == 0)
95463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(XSelectWindow(display,&rectangle_info));
95473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (root_window == id)
9548dfe2b6658f367de8f84405263f62768fb853adafcristy    return(root_window);
95493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XQueryTree(display,root_window,&child,&child,&children,
95503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &number_children);
95513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
95523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return((Window) NULL);
95533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window=(Window) NULL;
95543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; i < (int) number_children; i++)
95553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
95563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    /*
95573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Search each child and their children.
95583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    */
95593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window=XWindowByID(display,children[i],id);
95603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (window != (Window) NULL)
95613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
95623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
95633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (children != (Window *) NULL)
95643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XFree((void *) children);
95653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(window);
95663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
95673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
95683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
95693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
95713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
95723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
95733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X W i n d o w B y N a m e                                                 %
95743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
95753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
95763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
95773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XWindowByName() locates a window with a given name on a display.  If no
95803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  window with the given name is found, 0 is returned. If more than one window
95813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  has the given name, the first one is returned.  Only root and its children
95823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  are searched.
95833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XWindowByName function is:
95853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      window=XWindowByName(display,root_window,name)
95873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
95893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: XWindowByName returns the window id.
95913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a pointer to the Display structure;  returned from
95933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
95943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o root_window: Specifies the id of the root window.
95963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o name: Specifies the name of the window to locate.
95983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
9600bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate Window XWindowByName(Display *display,const Window root_window,
96013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *name)
96023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
96033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
96043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
96053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
96063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
96073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
96083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
96093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
96103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_children;
96113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
96123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
96133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *children,
96143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    child,
96153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window;
96163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
96173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XTextProperty
96183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window_name;
96193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
96203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
96213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(root_window != (Window) NULL);
96223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(name != (char *) NULL);
96233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
96243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (XGetWMName(display,root_window,&window_name) != 0)
96253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (LocaleCompare((char *) window_name.value,name) == 0)
96263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(root_window);
96273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XQueryTree(display,root_window,&child,&child,&children,
96283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &number_children);
96293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
96303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return((Window) NULL);
96313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window=(Window) NULL;
96323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; i < (int) number_children; i++)
96333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
96343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    /*
96353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Search each child and their children.
96363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    */
96373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window=XWindowByName(display,children[i],name);
96383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (window != (Window) NULL)
96393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
96403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
96413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (children != (Window *) NULL)
96423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XFree((void *) children);
96433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(window);
96443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
96453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
96463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
96473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
96493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
96503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
96513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X W i n d o w B y P r o p e r y                                           %
96523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
96533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
96543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
96553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XWindowByProperty() locates a child window with a given property. If not
96583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  window with the given name is found, 0 is returned.  If more than one window
96593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  has the given property, the first one is returned.  Only the window
96603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  specified and its subwindows are searched.
96613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XWindowByProperty function is:
96633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      child=XWindowByProperty(display,window,property)
96653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
96673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o child: XWindowByProperty returns the window id with the specified
96693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      property.  If no windows are found, XWindowByProperty returns 0.
96703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a pointer to the Display structure;  returned from
96723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
96733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o property: Specifies the property of the window to locate.
96753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
9677bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate Window XWindowByProperty(Display *display,const Window window,
96783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const Atom property)
96793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
96803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Atom
96813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    type;
96823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
96833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
96843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    format;
96853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
96863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
96873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
96883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
96893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned char
96903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *data;
96913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
96923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
96933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i,
96943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_children;
96953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9696f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  unsigned long
96973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    after,
96983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_items;
96993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
97003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
97013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    child,
97023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *children,
97033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    parent,
97043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root;
97053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
97063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
97073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
97083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (Window) NULL);
97093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(property != (Atom) NULL);
97103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XQueryTree(display,window,&root,&parent,&children,&number_children);
97113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
97123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return((Window) NULL);
97133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  type=(Atom) NULL;
97143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  child=(Window) NULL;
97153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; (i < number_children) && (child == (Window) NULL); i++)
97163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
97173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
97183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
97193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (data != NULL)
97203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFree((void *) data);
97213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if ((status == Success) && (type != (Atom) NULL))
97223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      child=children[i];
97233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
97243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; (i < number_children) && (child == (Window) NULL); i++)
97253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    child=XWindowByProperty(display,children[i],property);
97263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (children != (Window *) NULL)
97273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XFree((void *) children);
97283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(child);
97293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
97303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else
97313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
97323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
97333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
97353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
97363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
97373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X I m p o r t I m a g e                                                   %
97383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
97393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
97403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
97413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
97433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XImportImage() reads an image from an X window.
97443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
97453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XImportImage method is:
97463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9747a0dc96a5df0a380c9ef855cc7f2a5f264bec8af3cristy%      Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info,
9748a0dc96a5df0a380c9ef855cc7f2a5f264bec8af3cristy%        ExceptionInfo *exception)
97493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
97503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
97513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
97523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image_info: the image info..
97533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
97543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o ximage_info: Specifies a pointer to an XImportInfo structure.
97553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9756a0dc96a5df0a380c9ef855cc7f2a5f264bec8af3cristy%    o exception: return any errors or warnings in this structure.
9757a0dc96a5df0a380c9ef855cc7f2a5f264bec8af3cristy%
97583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
9759bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate Image *XImportImage(const ImageInfo *image_info,
9760a0dc96a5df0a380c9ef855cc7f2a5f264bec8af3cristy  XImportInfo *ximage_info,ExceptionInfo *exception)
97613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
97623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image_info != (const ImageInfo *) NULL);
97633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image_info->signature == MagickSignature);
97643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image_info->debug != MagickFalse)
97653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
97663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info->filename);
97673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(ximage_info != (XImportInfo *) NULL);
9768a0dc96a5df0a380c9ef855cc7f2a5f264bec8af3cristy  assert(exception != (ExceptionInfo *) NULL);
9769a0dc96a5df0a380c9ef855cc7f2a5f264bec8af3cristy  assert(exception->signature == MagickSignature);
97703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return((Image *) NULL);
97713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
97723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
97733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
97743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
97753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
97773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
97783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9779576974eba31c1fac74b2492a74862b2fcd50f21ccristy+   X C o m p o n e n t G e n e s i s                                         %
9780576974eba31c1fac74b2492a74862b2fcd50f21ccristy%                                                                             %
9781576974eba31c1fac74b2492a74862b2fcd50f21ccristy%                                                                             %
9782576974eba31c1fac74b2492a74862b2fcd50f21ccristy%                                                                             %
9783576974eba31c1fac74b2492a74862b2fcd50f21ccristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9784576974eba31c1fac74b2492a74862b2fcd50f21ccristy%
9785576974eba31c1fac74b2492a74862b2fcd50f21ccristy%  XComponentGenesis() instantiates the X component.
9786576974eba31c1fac74b2492a74862b2fcd50f21ccristy%
9787576974eba31c1fac74b2492a74862b2fcd50f21ccristy%  The format of the XComponentGenesis method is:
9788576974eba31c1fac74b2492a74862b2fcd50f21ccristy%
9789576974eba31c1fac74b2492a74862b2fcd50f21ccristy%      MagickBooleanType XComponentGenesis(void)
9790576974eba31c1fac74b2492a74862b2fcd50f21ccristy%
9791576974eba31c1fac74b2492a74862b2fcd50f21ccristy*/
97925ff4eaf57b3cd47d0371f204f865cbba614674a0cristyMagickPrivate MagickBooleanType XComponentGenesis(void)
9793576974eba31c1fac74b2492a74862b2fcd50f21ccristy{
9794576974eba31c1fac74b2492a74862b2fcd50f21ccristy  return(MagickTrue);
9795576974eba31c1fac74b2492a74862b2fcd50f21ccristy}
9796576974eba31c1fac74b2492a74862b2fcd50f21ccristy
9797576974eba31c1fac74b2492a74862b2fcd50f21ccristy/*
9798576974eba31c1fac74b2492a74862b2fcd50f21ccristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9799576974eba31c1fac74b2492a74862b2fcd50f21ccristy%                                                                             %
9800576974eba31c1fac74b2492a74862b2fcd50f21ccristy%                                                                             %
9801576974eba31c1fac74b2492a74862b2fcd50f21ccristy%                                                                             %
98023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t I m p o r t I n f o                                               %
98033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
98043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
98053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
98063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
98083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetImportInfo() initializes the XImportInfo structure.
98093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
98103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetImportInfo method is:
98113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
98123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XGetImportInfo(XImportInfo *ximage_info)
98133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
98143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
98153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
98163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o ximage_info: Specifies a pointer to an ImageInfo structure.
98173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
98183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
98193ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport void XGetImportInfo(XImportInfo *ximage_info)
98203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
98213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(ximage_info != (XImportInfo *) NULL);
98223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ximage_info->frame=MagickFalse;
98233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ximage_info->borders=MagickFalse;
98243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ximage_info->screen=MagickFalse;
98253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ximage_info->descend=MagickTrue;
98263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ximage_info->silent=MagickFalse;
98273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
9828