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                               %
16de984cdc3631106b1cbbb8d3972b76a0fc27e8e8cristy%                                    Cristy                                   %
173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                  July 1992                                  %
183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
207ce65e7125a4e1df1a274ce373c537a9df9c16cdCristy%  Copyright 1999-2016 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"
672c5fc27ae5b613b7fb9fd69c12a47b99c7d4d471cristy#include "MagickCore/nt-base-private.h"
684c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/option.h"
694c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/pixel-accessor.h"
704c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/quantize.h"
714c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/quantum.h"
724c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/quantum-private.h"
734c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/resource_.h"
744c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/resize.h"
754c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/statistic.h"
764c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/string_.h"
774c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/string-private.h"
78a387934f078d2d8fa122ed62c8e6d6b6ac556060dirk#include "MagickCore/transform.h"
7906f590165f0505d42005264893fe14a9e8a79986dirk#include "MagickCore/transform-private.h"
8063a81879d3568083e4ee4f78ebcae2bc831cb764cristy#include "MagickCore/token.h"
814c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/utility.h"
82d1dd6e4fefa0810b9893e6ac9418f79c97c1b39acristy#include "MagickCore/utility-private.h"
834c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/widget.h"
84bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristy#include "MagickCore/widget-private.h"
854c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/xwindow.h"
864c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/xwindow-private.h"
874c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/version.h"
883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__BEOS__)
893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <OS.h>
903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_X11_DELEGATE)
923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <X11/Xproto.h>
933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <X11/Xlocale.h>
943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICK_HAVE_POLL)
953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy# include <sys/poll.h>
963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_MACHINE_PARAM_H)
993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy# include <machine/param.h>
1003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
1013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <sys/ipc.h>
1023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <sys/shm.h>
1033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <X11/extensions/XShm.h>
1043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
1053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHAPE)
1063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#include <X11/extensions/shape.h>
1073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
1083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
1103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  X defines.
1113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
112ce70c17bb6433add2eb069515a4f3105989e0662cristy#define XBlueGamma(color) ClampToQuantum(blue_gamma == 1.0 ? (double) \
1133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) blue_gamma)* \
1143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  QuantumRange)))
1154c08aed51c5899665ade97263692328eea4af106cristy#define XGammaPacket(map,color)  (size_t) (map->base_pixel+ \
1167e9f233e6549b1e1856c1aa85b3f4dee8e9493facristy  ((ScaleQuantumToShort(XRedGamma((color)->red))*map->red_max/65535L)* \
1177e9f233e6549b1e1856c1aa85b3f4dee8e9493facristy    map->red_mult)+ \
1187e9f233e6549b1e1856c1aa85b3f4dee8e9493facristy  ((ScaleQuantumToShort(XGreenGamma((color)->green))*map->green_max/65535L)* \
1197e9f233e6549b1e1856c1aa85b3f4dee8e9493facristy    map->green_mult)+ \
1207e9f233e6549b1e1856c1aa85b3f4dee8e9493facristy  ((ScaleQuantumToShort(XBlueGamma((color)->blue))*map->blue_max/65535L)* \
1217e9f233e6549b1e1856c1aa85b3f4dee8e9493facristy    map->blue_mult))
1224c08aed51c5899665ade97263692328eea4af106cristy#define XGammaPixel(image,map,color)  (size_t) (map->base_pixel+ \
1234c08aed51c5899665ade97263692328eea4af106cristy  ((ScaleQuantumToShort(XRedGamma(GetPixelRed(image,color)))*map->red_max/65535L)* \
1244c08aed51c5899665ade97263692328eea4af106cristy    map->red_mult)+ \
1254c08aed51c5899665ade97263692328eea4af106cristy  ((ScaleQuantumToShort(XGreenGamma(GetPixelGreen(image,color)))*map->green_max/65535L)* \
1264c08aed51c5899665ade97263692328eea4af106cristy    map->green_mult)+ \
1274c08aed51c5899665ade97263692328eea4af106cristy  ((ScaleQuantumToShort(XBlueGamma(GetPixelBlue(image,color)))*map->blue_max/65535L)* \
1284c08aed51c5899665ade97263692328eea4af106cristy    map->blue_mult))
129ce70c17bb6433add2eb069515a4f3105989e0662cristy#define XGreenGamma(color) ClampToQuantum(green_gamma == 1.0 ? (double) \
1303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) green_gamma)* \
1313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  QuantumRange)))
132ce70c17bb6433add2eb069515a4f3105989e0662cristy#define XRedGamma(color) ClampToQuantum(red_gamma == 1.0 ? (double) \
1333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) red_gamma)* \
1343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  QuantumRange)))
135bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy#define XStandardPixel(map,color)  (size_t) (map->base_pixel+ \
1367e9f233e6549b1e1856c1aa85b3f4dee8e9493facristy  (((color)->red*map->red_max/65535L)*map->red_mult)+ \
1377e9f233e6549b1e1856c1aa85b3f4dee8e9493facristy  (((color)->green*map->green_max/65535L)*map->green_mult)+ \
1387e9f233e6549b1e1856c1aa85b3f4dee8e9493facristy  (((color)->blue*map->blue_max/65535L)*map->blue_mult))
1393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define AccentuateModulate  ScaleCharToQuantum(80)
1413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define HighlightModulate  ScaleCharToQuantum(125)
1423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define ShadowModulate  ScaleCharToQuantum(135)
1433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define DepthModulate  ScaleCharToQuantum(185)
1443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define TroughModulate  ScaleCharToQuantum(110)
1453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define XLIB_ILLEGAL_ACCESS  1
1473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef ForgetGravity
1483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef NorthWestGravity
1493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef NorthGravity
1503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef NorthEastGravity
1513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef WestGravity
1523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef CenterGravity
1533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef EastGravity
1543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef SouthWestGravity
1553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef SouthGravity
1563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef SouthEastGravity
1573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef StaticGravity
1583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef index
1603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(hpux9)
1613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define XFD_SET  int
1623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else
1633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define XFD_SET  fd_set
1643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
1653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
1673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Enumeration declarations.
1683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1693ed852eea50f9d4cd633efb8c2b054b8e33c253cristytypedef enum
1703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
1713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef DoRed
1723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DoRed = 0x0001,
1733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef DoGreen
1743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DoGreen = 0x0002,
1753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#undef DoBlue
1763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DoBlue = 0x0004,
1773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DoMatte = 0x0008
1783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} XColorFlags;
1793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
1813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Typedef declarations.
1823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1833ed852eea50f9d4cd633efb8c2b054b8e33c253cristytypedef struct _DiversityPacket
1843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
1853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Quantum
1863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    red,
1873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    green,
1883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    blue;
1893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned short
1913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    index;
1923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
193bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  size_t
1943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    count;
1953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy} DiversityPacket;
1963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
1983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Constant declaractions.
1993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
2003ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType
2013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  xerror_alert = MagickFalse;
2023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
2043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Method prototypes.
2053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
2063ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic const char
2073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  *XVisualClassName(const int);
2083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
209a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristystatic double
2103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  blue_gamma = 1.0,
2113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  green_gamma = 1.0,
2123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  red_gamma = 1.0;
2133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2143ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType
2153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XMakePixmap(Display *,const XResourceInfo *,XWindowInfo *);
2163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2173ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void
2183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XMakeImageLSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
219e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy    XImage *,XImage *,ExceptionInfo *),
2203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XMakeImageMSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
221e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy    XImage *,XImage *,ExceptionInfo *);
2223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2233ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Window
2243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XSelectWindow(Display *,RectangleInfo *);
2253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
2273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   D e s t r o y X R e s o u r c e s                                         %
2323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  DestroyXResources() destroys any X resources.
2383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the DestroyXResources method is:
2403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void DestroyXResources()
2423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
2443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
2463ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport void DestroyXResources(void)
2473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
2483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
2493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
2503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
2523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_windows;
2533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XWindowInfo
2553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *magick_windows[MaxXWindows];
2563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XWindows
2583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *windows;
2593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DestroyXWidget();
2613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows=XSetWindows((XWindows *) ~0);
2623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((windows == (XWindows *) NULL) || (windows->display == (Display *) NULL))
2633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
2643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  number_windows=0;
2653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->context);
2663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->group_leader);
2673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->backdrop);
2683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->icon);
2693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->image);
2703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->info);
2713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->magnify);
2723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->pan);
2733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->command);
2743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->widget);
2753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->popup);
2763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magick_windows[number_windows++]=(&windows->context);
2773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; i < (int) number_windows; i++)
2783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
2793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->mapped != MagickFalse)
2803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
2813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XWithdrawWindow(windows->display,magick_windows[i]->id,
2823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          magick_windows[i]->screen);
2833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        magick_windows[i]->mapped=MagickFalse;
2843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
2853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->name != (char *) NULL)
2863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      magick_windows[i]->name=(char *)
2873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        RelinquishMagickMemory(magick_windows[i]->name);
2883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->icon_name != (char *) NULL)
2893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      magick_windows[i]->icon_name=(char *)
2903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        RelinquishMagickMemory(magick_windows[i]->icon_name);
2913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->cursor != (Cursor) NULL)
2923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
2933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreeCursor(windows->display,magick_windows[i]->cursor);
2943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        magick_windows[i]->cursor=(Cursor) NULL;
2953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
2963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->busy_cursor != (Cursor) NULL)
2973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
2983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreeCursor(windows->display,magick_windows[i]->busy_cursor);
2993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        magick_windows[i]->busy_cursor=(Cursor) NULL;
3003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->highlight_stipple != (Pixmap) NULL)
3023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreePixmap(windows->display,
3043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          magick_windows[i]->highlight_stipple);
3053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        magick_windows[i]->highlight_stipple=(Pixmap) NULL;
3063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->shadow_stipple != (Pixmap) NULL)
3083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreePixmap(windows->display,magick_windows[i]->shadow_stipple);
3103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        magick_windows[i]->shadow_stipple=(Pixmap) NULL;
3113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->ximage != (XImage *) NULL)
3133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XDestroyImage(magick_windows[i]->ximage);
3153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        magick_windows[i]->ximage=(XImage *) NULL;
3163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->pixmap != (Pixmap) NULL)
3183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreePixmap(windows->display,magick_windows[i]->pixmap);
3203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        magick_windows[i]->pixmap=(Pixmap) NULL;
3213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->id != (Window) NULL)
3233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XDestroyWindow(windows->display,magick_windows[i]->id);
3253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        magick_windows[i]->id=(Window) NULL;
3263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->destroy != MagickFalse)
3283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (magick_windows[i]->image != (Image *) NULL)
3303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
3313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            magick_windows[i]->image=DestroyImage(magick_windows[i]->image);
3323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            magick_windows[i]->image=NewImageList();
3333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
3343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (magick_windows[i]->matte_pixmap != (Pixmap) NULL)
3353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
3363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) XFreePixmap(windows->display,
3373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              magick_windows[i]->matte_pixmap);
3383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            magick_windows[i]->matte_pixmap=(Pixmap) NULL;
3393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
3403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (magick_windows[i]->segment_info != (void *) NULL)
3423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
3433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
3443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XShmSegmentInfo
3453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          *segment_info;
3463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
3473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        segment_info=(XShmSegmentInfo *) magick_windows[i]->segment_info;
3483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (segment_info != (XShmSegmentInfo *) NULL)
3493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (segment_info[0].shmid >= 0)
3503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
3513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (segment_info[0].shmaddr != NULL)
3523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (void) shmdt(segment_info[0].shmaddr);
3533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
3543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              segment_info[0].shmaddr=NULL;
3553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              segment_info[0].shmid=(-1);
3563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
3573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
3583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        magick_windows[i]->segment_info=(void *)
3593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          RelinquishMagickMemory(magick_windows[i]->segment_info);
3603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
3613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
3623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->icon_resources=(XResourceInfo *)
3633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    RelinquishMagickMemory(windows->icon_resources);
3643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->icon_pixel != (XPixelInfo *) NULL)
3653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
366f2faecf9facdbbb14fcba373365f9f691a9658e0cristy      if (windows->icon_pixel->pixels != (unsigned long *) NULL)
367f2faecf9facdbbb14fcba373365f9f691a9658e0cristy        windows->icon_pixel->pixels=(unsigned long *)
3683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          RelinquishMagickMemory(windows->icon_pixel->pixels);
3693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (windows->icon_pixel->annotate_context != (GC) NULL)
3703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XFreeGC(windows->display,windows->icon_pixel->annotate_context);
3713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->icon_pixel=(XPixelInfo *)
3723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        RelinquishMagickMemory(windows->icon_pixel);
3733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
3743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->pixel_info != (XPixelInfo *) NULL)
3753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
376f2faecf9facdbbb14fcba373365f9f691a9658e0cristy      if (windows->pixel_info->pixels != (unsigned long *) NULL)
377f2faecf9facdbbb14fcba373365f9f691a9658e0cristy        windows->pixel_info->pixels=(unsigned long *)
3783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          RelinquishMagickMemory(windows->pixel_info->pixels);
3793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (windows->pixel_info->annotate_context != (GC) NULL)
3803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XFreeGC(windows->display,windows->pixel_info->annotate_context);
3813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (windows->pixel_info->widget_context != (GC) NULL)
3823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XFreeGC(windows->display,windows->pixel_info->widget_context);
3833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (windows->pixel_info->highlight_context != (GC) NULL)
3843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XFreeGC(windows->display,windows->pixel_info->highlight_context);
3853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->pixel_info=(XPixelInfo *)
3863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        RelinquishMagickMemory(windows->pixel_info);
3873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
3883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->font_info != (XFontStruct *) NULL)
3893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
3903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XFreeFont(windows->display,windows->font_info);
3913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->font_info=(XFontStruct *) NULL;
3923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
3933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->class_hints != (XClassHint *) NULL)
3943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
395c9cc4a7b1dd605daff0dd2e0b0e1c42f178871ddcristy      if (windows->class_hints->res_name != (char *) NULL)
396c9cc4a7b1dd605daff0dd2e0b0e1c42f178871ddcristy        windows->class_hints->res_name=DestroyString(
397c9cc4a7b1dd605daff0dd2e0b0e1c42f178871ddcristy          windows->class_hints->res_name);
398c9cc4a7b1dd605daff0dd2e0b0e1c42f178871ddcristy      if (windows->class_hints->res_class != (char *) NULL)
399c9cc4a7b1dd605daff0dd2e0b0e1c42f178871ddcristy        windows->class_hints->res_class=DestroyString(
400c9cc4a7b1dd605daff0dd2e0b0e1c42f178871ddcristy          windows->class_hints->res_class);
4013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XFree(windows->class_hints);
4023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->class_hints=(XClassHint *) NULL;
4033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
4043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->manager_hints != (XWMHints *) NULL)
4053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
4063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XFree(windows->manager_hints);
4073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->manager_hints=(XWMHints *) NULL;
4083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
4093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->map_info != (XStandardColormap *) NULL)
4103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
4113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XFree(windows->map_info);
4123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->map_info=(XStandardColormap *) NULL;
4133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
4143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->icon_map != (XStandardColormap *) NULL)
4153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
4163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XFree(windows->icon_map);
4173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->icon_map=(XStandardColormap *) NULL;
4183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
4193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->visual_info != (XVisualInfo *) NULL)
4203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
4213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XFree(windows->visual_info);
4223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->visual_info=(XVisualInfo *) NULL;
4233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
4243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->icon_visual != (XVisualInfo *) NULL)
4253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
4263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XFree(windows->icon_visual);
4273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->icon_visual=(XVisualInfo *) NULL;
4283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
4293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSetWindows((XWindows *) NULL);
4303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
4313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
4333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X A n n o t a t e I m a g e                                               %
4383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
4413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
4423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XAnnotateImage() annotates the image with text.
4443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XAnnotateImage method is:
4463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      MagickBooleanType XAnnotateImage(Display *display,
4487c3af951210f34d3f244b31f06ee291e5be8ecb7cristy%        const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image,
4497c3af951210f34d3f244b31f06ee291e5be8ecb7cristy%        ExceptionInfo *exception)
4503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
4523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
4543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
4553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o pixel: Specifies a pointer to a XPixelInfo structure.
4573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
4593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
4613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
4627c3af951210f34d3f244b31f06ee291e5be8ecb7cristy%    o exception: return any errors or warnings in this structure.
4637c3af951210f34d3f244b31f06ee291e5be8ecb7cristy%
4643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
465bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate MagickBooleanType XAnnotateImage(Display *display,
4667c3af951210f34d3f244b31f06ee291e5be8ecb7cristy  const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image,
4677c3af951210f34d3f244b31f06ee291e5be8ecb7cristy  ExceptionInfo *exception)
4683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
469c57f694b2d04975a0e501613e34368c464708c19cristy  CacheView
470c57f694b2d04975a0e501613e34368c464708c19cristy    *annotate_view;
471c57f694b2d04975a0e501613e34368c464708c19cristy
4723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  GC
4733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    annotate_context;
4743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Image
4763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *annotate_image;
4773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
4793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x,
4803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y;
4813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
482b0a657e13c4aefba39c51292005427b47277869dcristy  PixelTrait
483b0a657e13c4aefba39c51292005427b47277869dcristy    alpha_trait;
4843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Pixmap
4863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    annotate_pixmap;
4873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
4893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    depth,
4903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    height,
4913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    width;
4923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
4943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root_window;
4953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XGCValues
4973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    context_values;
4983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XImage
5003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *annotate_ximage;
5013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
5023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
5033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize annotated image.
5043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
5053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
5063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
5073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(pixel != (XPixelInfo *) NULL);
5083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(annotate_info != (XAnnotateInfo *) NULL);
5093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image != (Image *) NULL);
5103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
5113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize annotated pixmap.
5123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
5133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  root_window=XRootWindow(display,XDefaultScreen(display));
5143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
5153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_pixmap=XCreatePixmap(display,root_window,annotate_info->width,
5163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    annotate_info->height,depth);
5173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (annotate_pixmap == (Pixmap) NULL)
5183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
5193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
5203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize graphics info.
5213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
5223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  context_values.background=0;
523bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  context_values.foreground=(size_t) (~0);
5243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  context_values.font=annotate_info->font_info->fid;
525c57f694b2d04975a0e501613e34368c464708c19cristy  annotate_context=XCreateGC(display,root_window,(unsigned long)
526c57f694b2d04975a0e501613e34368c464708c19cristy    (GCBackground | GCFont | GCForeground),&context_values);
5273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (annotate_context == (GC) NULL)
5283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
5293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
5303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Draw text to pixmap.
5313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
5323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XDrawImageString(display,annotate_pixmap,annotate_context,0,
5333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (int) annotate_info->font_info->ascent,annotate_info->text,
5343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (int) strlen(annotate_info->text));
5353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFreeGC(display,annotate_context);
5363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
5373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize annotated X image.
5383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
5393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_ximage=XGetImage(display,annotate_pixmap,0,0,annotate_info->width,
5403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    annotate_info->height,AllPlanes,ZPixmap);
5413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (annotate_ximage == (XImage *) NULL)
5423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
5433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFreePixmap(display,annotate_pixmap);
5443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
5453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize annotated image.
5463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
5476710d8414f0ed06e4eaf9346366be72e2b4719efcristy  annotate_image=AcquireImage((ImageInfo *) NULL,exception);
5483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (annotate_image == (Image *) NULL)
5493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
5503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_image->columns=annotate_info->width;
5513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_image->rows=annotate_info->height;
5523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
5533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Transfer annotated X image to image.
5543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
5553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  width=(unsigned int) image->columns;
5563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  height=(unsigned int) image->rows;
5573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=0;
5583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y=0;
5593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
560f05d4947caf1bc27fbec041eb37c474a80c83c0bcristy  (void) GetOneVirtualPixelInfo(image,UndefinedVirtualPixelMethod,(ssize_t) x,
561f05d4947caf1bc27fbec041eb37c474a80c83c0bcristy    (ssize_t) y,&annotate_image->background_color,exception);
5623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (annotate_info->stencil == ForegroundStencil)
5638a46d827a124555f0c48fb2368ec1bba8e079ab6cristy    annotate_image->alpha_trait=BlendPixelTrait;
5646f5395df39e037392db46729f9aab05f2a9a428fcristy  annotate_view=AcquireAuthenticCacheView(annotate_image,exception);
5653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (y=0; y < (int) annotate_image->rows; y++)
5663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
567c57f694b2d04975a0e501613e34368c464708c19cristy    register int
5683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      x;
5693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
5704c08aed51c5899665ade97263692328eea4af106cristy    register Quantum
57105d2ff7ebf21f659f5b11e45afb294e152f4330cdirk      *magick_restrict q;
5723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
573c57f694b2d04975a0e501613e34368c464708c19cristy    q=GetCacheViewAuthenticPixels(annotate_view,0,(ssize_t) y,
574c57f694b2d04975a0e501613e34368c464708c19cristy      annotate_image->columns,1,exception);
575acd2ed254c18c254a0ab5aafa06d1645e5d079d8cristy    if (q == (Quantum *) NULL)
5763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
577c57f694b2d04975a0e501613e34368c464708c19cristy    for (x=0; x < (int) annotate_image->columns; x++)
5783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
5794c08aed51c5899665ade97263692328eea4af106cristy      SetPixelAlpha(annotate_image,OpaqueAlpha,q);
5803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (XGetPixel(annotate_ximage,x,y) == 0)
5813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
5823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
5833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Set this pixel to the background color.
5843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
5854c08aed51c5899665ade97263692328eea4af106cristy          SetPixelRed(annotate_image,ScaleShortToQuantum(
5864c08aed51c5899665ade97263692328eea4af106cristy            pixel->box_color.red),q);
5874c08aed51c5899665ade97263692328eea4af106cristy          SetPixelGreen(annotate_image,ScaleShortToQuantum(
5884c08aed51c5899665ade97263692328eea4af106cristy            pixel->box_color.green),q);
5894c08aed51c5899665ade97263692328eea4af106cristy          SetPixelBlue(annotate_image,ScaleShortToQuantum(
5904c08aed51c5899665ade97263692328eea4af106cristy            pixel->box_color.blue),q);
5913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((annotate_info->stencil == ForegroundStencil) ||
5923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (annotate_info->stencil == OpaqueStencil))
5934c08aed51c5899665ade97263692328eea4af106cristy            SetPixelAlpha(annotate_image,TransparentAlpha,q);
5943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
5953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
5963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
5973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
5983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Set this pixel to the pen color.
5993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
6004c08aed51c5899665ade97263692328eea4af106cristy          SetPixelRed(annotate_image,ScaleShortToQuantum(
6014c08aed51c5899665ade97263692328eea4af106cristy            pixel->pen_color.red),q);
6024c08aed51c5899665ade97263692328eea4af106cristy          SetPixelGreen(annotate_image,ScaleShortToQuantum(
6034c08aed51c5899665ade97263692328eea4af106cristy            pixel->pen_color.green),q);
6044c08aed51c5899665ade97263692328eea4af106cristy          SetPixelBlue(annotate_image,ScaleShortToQuantum(
6054c08aed51c5899665ade97263692328eea4af106cristy            pixel->pen_color.blue),q);
6063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (annotate_info->stencil == BackgroundStencil)
6074c08aed51c5899665ade97263692328eea4af106cristy            SetPixelAlpha(annotate_image,TransparentAlpha,q);
6083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
609ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy      q+=GetPixelChannels(annotate_image);
6103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
611c57f694b2d04975a0e501613e34368c464708c19cristy    if (SyncCacheViewAuthenticPixels(annotate_view,exception) == MagickFalse)
6123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
6133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
614c57f694b2d04975a0e501613e34368c464708c19cristy  annotate_view=DestroyCacheView(annotate_view);
6153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XDestroyImage(annotate_ximage);
6163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
6173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Determine annotate geometry.
6183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
6193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
6203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((width != (unsigned int) annotate_image->columns) ||
6213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (height != (unsigned int) annotate_image->rows))
6223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
6233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      char
624151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy        image_geometry[MagickPathExtent];
6253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
6273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Scale image.
6283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
629151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy      (void) FormatLocaleString(image_geometry,MagickPathExtent,"%ux%u",
6303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        width,height);
631e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy      (void) TransformImage(&annotate_image,(char *) NULL,image_geometry,
632e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy        exception);
6333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
6343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (annotate_info->degrees != 0.0)
6353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
6363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Image
6373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *rotate_image;
6383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      int
6403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        rotations;
6413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
642a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy      double
6433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        normalized_degrees;
6443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
6463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Rotate image.
6473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
6486710d8414f0ed06e4eaf9346366be72e2b4719efcristy      rotate_image=RotateImage(annotate_image,annotate_info->degrees,exception);
6493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (rotate_image == (Image *) NULL)
6503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        return(MagickFalse);
6513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      annotate_image=DestroyImage(annotate_image);
6523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      annotate_image=rotate_image;
6533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
6543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Annotation is relative to the degree of rotation.
6553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
6563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      normalized_degrees=annotate_info->degrees;
6573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      while (normalized_degrees < -45.0)
6583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        normalized_degrees+=360.0;
6593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (rotations=0; normalized_degrees > 45.0; rotations++)
6603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        normalized_degrees-=90.0;
6613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      switch (rotations % 4)
6623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
6633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        default:
6643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 0:
6653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
6663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 1:
6673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
6683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
6693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Rotate 90 degrees.
6703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
6713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          x-=(int) annotate_image->columns/2;
6723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          y+=(int) annotate_image->columns/2;
6733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
6743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
6753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 2:
6763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
6773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
6783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Rotate 180 degrees.
6793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
6803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          x=x-(int) annotate_image->columns;
6813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
6823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
6833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 3:
6843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
6853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
6863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Rotate 270 degrees.
6873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
6883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          x=x-(int) annotate_image->columns/2;
6893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          y=y-(int) (annotate_image->rows-(annotate_image->columns/2));
6903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
6913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
6923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
6933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
6943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
6953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Composite text onto the image.
6963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
6973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
698b0a657e13c4aefba39c51292005427b47277869dcristy  alpha_trait=image->alpha_trait;
699feb3e9695150978a5d2372d3fe2f60466a7c8066cristy  (void) CompositeImage(image,annotate_image,
70017f11b056210f082a6d0e54ac5d68e6d72fa76b2cristy    annotate_image->alpha_trait != UndefinedPixelTrait ? OverCompositeOp :
701b0a657e13c4aefba39c51292005427b47277869dcristy    CopyCompositeOp,MagickTrue,(ssize_t) x,(ssize_t) y,exception);
702b0a657e13c4aefba39c51292005427b47277869dcristy  image->alpha_trait=alpha_trait;
7033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_image=DestroyImage(annotate_image);
7043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickTrue);
7053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
7063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
7083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X B e s t F o n t                                                         %
7133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
7163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XBestFont() returns the "best" font.  "Best" is defined as a font specified
7193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  in the X resource database or a font such that the text width displayed
7203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  with the font does not exceed the specified maximum width.
7213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XBestFont method is:
7233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XFontStruct *XBestFont(Display *display,
7253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const XResourceInfo *resource_info,const MagickBooleanType text_font)
7263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
7283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o font: XBestFont returns a pointer to a XFontStruct structure.
7303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
7323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
7333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
7353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o text_font:  True is font should be mono-spaced (typewriter style).
7373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
7383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
7393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7403ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic char **FontToList(char *font)
7413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
7423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
7433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    **fontlist;
7443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register char
7463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p,
7473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *q;
7483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
7503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
7513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
7533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    fonts;
7543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (font == (char *) NULL)
7563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return((char **) NULL);
7573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
7583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Convert string to an ASCII list.
7593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
7603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  fonts=1U;
7613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (p=font; *p != '\0'; p++)
7623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if ((*p == ':') || (*p == ';') || (*p == ','))
7633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      fonts++;
7643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  fontlist=(char **) AcquireQuantumMemory((size_t) fonts+1UL,sizeof(*fontlist));
7653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (fontlist == (char **) NULL)
7663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
767c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy      ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",font);
7683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return((char **) NULL);
7693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
7703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  p=font;
7713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; i < (int) fonts; i++)
7723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
7733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    for (q=p; *q != '\0'; q++)
7743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((*q == ':') || (*q == ';') || (*q == ','))
7753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
7763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    fontlist[i]=(char *) AcquireQuantumMemory((size_t) (q-p)+1UL,
7773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      sizeof(*fontlist[i]));
7783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (fontlist[i] == (char *) NULL)
7793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
780c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy        ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",font);
7813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        return((char **) NULL);
7823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
7833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) CopyMagickString(fontlist[i],p,(size_t) (q-p+1));
7843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    p=q+1;
7853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
7863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  fontlist[i]=(char *) NULL;
7873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(fontlist);
7883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
7893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
790bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate XFontStruct *XBestFont(Display *display,
7913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const XResourceInfo *resource_info,const MagickBooleanType text_font)
7923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
7933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static const char
7943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *Fonts[]=
7953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
7963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
7973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-1",
7983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-15",
7993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-15",
8003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
8013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "-*-arial-medium-r-normal--12-*-*-*-*-*-*-*",
8023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "variable",
8033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "fixed",
8043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (char *) NULL
8053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    },
8063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *TextFonts[]=
8073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
8083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-1",
8093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-15",
8103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "-*-fixed-medium-r-normal-*-12-*-*-*-*-*-*-*",
8113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "fixed",
8123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (char *) NULL
8133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    };
8143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
8163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *font_name;
8173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register const char
8193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    **p;
8203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XFontStruct
8223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *font_info;
8233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  font_info=(XFontStruct *) NULL;
8253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  font_name=resource_info->font;
8263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (text_font != MagickFalse)
8273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    font_name=resource_info->text_font;
8283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((font_name != (char *) NULL) && (*font_name != '\0'))
8293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
8303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      char
8313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        **fontlist;
8323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      register int
8343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        i;
8353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
8373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Load preferred font specified in the X resource database.
8383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
8393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      fontlist=FontToList(font_name);
8403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (fontlist != (char **) NULL)
8413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
8423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (i=0; fontlist[i] != (char *) NULL; i++)
8433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
8443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (font_info == (XFontStruct *) NULL)
8453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              font_info=XLoadQueryFont(display,fontlist[i]);
8463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            fontlist[i]=DestroyString(fontlist[i]);
8473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
8483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          fontlist=(char **) RelinquishMagickMemory(fontlist);
8493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
8503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (font_info == (XFontStruct *) NULL)
851c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy        ThrowXWindowException(XServerError,"UnableToLoadFont",font_name);
8523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
8533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
8543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Load fonts from list of fonts until one is found.
8553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
8563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  p=Fonts;
8573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (text_font != MagickFalse)
8583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    p=TextFonts;
8593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (XDisplayHeight(display,XDefaultScreen(display)) >= 748)
8603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    p++;
8613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while (*p != (char *) NULL)
8623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
8633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (font_info != (XFontStruct *) NULL)
8643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
8653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    font_info=XLoadQueryFont(display,(char *) *p);
8663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    p++;
8673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
8683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(font_info);
8693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
8703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
8723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X B e s t I c o n S i z e                                                 %
8773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XBestIconSize() returns the "best" icon size.  "Best" is defined as an icon
8833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  size that maintains the aspect ratio of the image.  If the window manager
8843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  has preferred icon sizes, one of the preferred sizes is used.
8853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XBestIconSize method is:
8873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XBestIconSize(Display *display,XWindowInfo *window,Image *image)
8893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
8913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
8933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
8943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
8963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
898bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XBestIconSize(Display *display,XWindowInfo *window,
8993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Image *image)
9003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
9013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
9023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i,
9033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_sizes;
9043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
905a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy  double
9063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scale_factor;
9073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
9093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    height,
9103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    icon_height,
9113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    icon_width,
9123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    width;
9133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
9153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root_window;
9163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XIconSize
9183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *icon_size,
9193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *size_list;
9203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
9223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Determine if the window manager has specified preferred icon sizes.
9233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
9243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
9253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
9263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (XWindowInfo *) NULL);
9273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image != (Image *) NULL);
9283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->width=MaxIconSize;
9293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->height=MaxIconSize;
9303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  icon_size=(XIconSize *) NULL;
9313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  number_sizes=0;
9323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  root_window=XRootWindow(display,window->screen);
9333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (XGetIconSizes(display,root_window,&size_list,&number_sizes) != 0)
9343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if ((number_sizes > 0) && (size_list != (XIconSize *) NULL))
9353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_size=size_list;
9363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (icon_size == (XIconSize *) NULL)
9373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
9383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
9393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Window manager does not restrict icon size.
9403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
9413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_size=XAllocIconSize();
9423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (icon_size == (XIconSize *) NULL)
9433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
944c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy          ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
945c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy            image->filename);
9463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          return;
9473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
9483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_size->min_width=1;
9493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_size->max_width=MaxIconSize;
9503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_size->min_height=1;
9513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_size->max_height=MaxIconSize;
9523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_size->width_inc=1;
9533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_size->height_inc=1;
9543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
9553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
9563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Determine aspect ratio of image.
9573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
9583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  width=(unsigned int) image->columns;
9593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  height=(unsigned int) image->rows;
9603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  i=0;
9613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->crop_geometry)
9623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XParseGeometry(window->crop_geometry,&i,&i,&width,&height);
9633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
9643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Look for an icon size that maintains the aspect ratio of image.
9653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
966a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy  scale_factor=(double) icon_size->max_width/width;
967a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy  if (scale_factor > ((double) icon_size->max_height/height))
968a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy    scale_factor=(double) icon_size->max_height/height;
9693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  icon_width=(unsigned int) icon_size->min_width;
9703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while ((int) icon_width < icon_size->max_width)
9713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
9723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (icon_width >= (unsigned int) (scale_factor*width+0.5))
9733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
9743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    icon_width+=icon_size->width_inc;
9753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
9763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  icon_height=(unsigned int) icon_size->min_height;
9773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while ((int) icon_height < icon_size->max_height)
9783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
9793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (icon_height >= (unsigned int) (scale_factor*height+0.5))
9803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
9813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    icon_height+=icon_size->height_inc;
9823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
9833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFree((void *) icon_size);
9843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->width=icon_width;
9853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->height=icon_height;
9863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
9873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
9893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X B e s t P i x e l                                                       %
9943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XBestPixel() returns a pixel from an array of pixels that is closest to the
10003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  requested color.  If the color array is NULL, the colors are obtained from
10013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  the X server.
10023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XBestPixel method is:
10043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XBestPixel(Display *display,const Colormap colormap,XColor *colors,
10063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        unsigned int number_colors,XColor *color)
10073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
10093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o pixel: XBestPixel returns the pixel value closest to the requested
10113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      color.
10123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
10143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
10153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o colormap: Specifies the ID of the X server colormap.
10173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o colors: Specifies an array of XColor structures.
10193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o number_colors: Specifies the number of XColor structures in the
10213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      color definition array.
10223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o color: Specifies the desired RGB value to find in the colors array.
10243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
10253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1026bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XBestPixel(Display *display,const Colormap colormap,
10273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XColor *colors,unsigned int number_colors,XColor *color)
10283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
10293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickBooleanType
10303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    query_server;
10313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10324c08aed51c5899665ade97263692328eea4af106cristy  PixelInfo
10333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel;
10343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1035a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy  double
10363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    min_distance;
10373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1038a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy  register double
10393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    distance;
10403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
10423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i,
10433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    j;
10443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
10463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
10473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
10483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
10493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Find closest representation for the requested RGB color.
10503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
10513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
10523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
10533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(color != (XColor *) NULL);
10543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XAllocColor(display,colormap,color);
10553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status != False)
10563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
10573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  query_server=colors == (XColor *) NULL ? MagickTrue : MagickFalse;
10583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (query_server != MagickFalse)
10593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
10603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
10613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Read X server colormap.
10623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
10633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
10643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (colors == (XColor *) NULL)
10653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
1066c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy          ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
1067c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy            "...");
10683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          return;
10693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
10703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (i=0; i < (int) number_colors; i++)
1071bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        colors[i].pixel=(size_t) i;
10723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (number_colors > 256)
10733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        number_colors=256;
10743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XQueryColors(display,colormap,colors,(int) number_colors);
10753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
1076a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy  min_distance=3.0*((double) QuantumRange+1.0)*((double)
10773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    QuantumRange+1.0);
10783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  j=0;
10793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; i < (int) number_colors; i++)
10803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
1081a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy    pixel.red=colors[i].red-(double) color->red;
10823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    distance=pixel.red*pixel.red;
10833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (distance > min_distance)
10843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      continue;
1085a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy    pixel.green=colors[i].green-(double) color->green;
10863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    distance+=pixel.green*pixel.green;
10873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (distance > min_distance)
10883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      continue;
1089a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy    pixel.blue=colors[i].blue-(double) color->blue;
10903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    distance+=pixel.blue*pixel.blue;
10913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (distance > min_distance)
10923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      continue;
10933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    min_distance=distance;
10943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    color->pixel=colors[i].pixel;
10953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    j=i;
10963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
10973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XAllocColor(display,colormap,&colors[j]);
10983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (query_server != MagickFalse)
10993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    colors=(XColor *) RelinquishMagickMemory(colors);
11003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
11013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
11033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
11053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
11063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
11073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X B e s t V i s u a l I n f o                                             %
11083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
11093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
11103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
11113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XBestVisualInfo() returns visual information for a visual that is the "best"
11143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  the server supports.  "Best" is defined as:
11153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    1. Restrict the visual list to those supported by the default screen.
11173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    2. If a visual type is specified, restrict the visual list to those of
11193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%       that type.
11203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    3. If a map type is specified, choose the visual that matches the id
11223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%       specified by the Standard Colormap.
11233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    4  From the list of visuals, choose one that can display the most
11253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%       simultaneous colors.  If more than one visual can display the same
11263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%       number of simultaneous colors, one is chosen based on a rank.
11273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XBestVisualInfo method is:
11293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XVisualInfo *XBestVisualInfo(Display *display,
11313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XStandardColormap *map_info,XResourceInfo *resource_info)
11323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
11343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o visual_info: XBestVisualInfo returns a pointer to a X11 XVisualInfo
11363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      structure.
11373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
11393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
11403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o map_info: If map_type is specified, this structure is initialized
11423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      with info from the Standard Colormap.
11433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
11453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
11463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1147bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate XVisualInfo *XBestVisualInfo(Display *display,
11483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XStandardColormap *map_info,XResourceInfo *resource_info)
11493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
11503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define MaxStandardColormaps  7
11513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define XVisualColormapSize(visual_info) MagickMin((unsigned int) (\
11523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (visual_info->klass == TrueColor) || (visual_info->klass == DirectColor) ? \
11533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy   visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \
1154df409586066e37b0cbc92ef3c2be565dd3fce86ecristy   (unsigned long) visual_info->colormap_size),1UL << visual_info->depth)
11553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
11573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *map_type,
11583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *visual_type;
11593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1160c57f694b2d04975a0e501613e34368c464708c19cristy  int
1161c57f694b2d04975a0e501613e34368c464708c19cristy    visual_mask;
1162c57f694b2d04975a0e501613e34368c464708c19cristy
11633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
11643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
11653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11668891f9ce489d3e61399b60436ea6c62f5ed9b887cristy  size_t
11678891f9ce489d3e61399b60436ea6c62f5ed9b887cristy    one;
11688891f9ce489d3e61399b60436ea6c62f5ed9b887cristy
11693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static int
11703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_visuals;
11713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static XVisualInfo
11733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    visual_template;
11743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XVisualInfo
11763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *visual_info,
11773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *visual_list;
11783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
11793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
11803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Restrict visual search by screen number.
11813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
11823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
11833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
11843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(map_info != (XStandardColormap *) NULL);
11853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
11863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  map_type=resource_info->map_type;
11873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  visual_type=resource_info->visual_type;
11883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  visual_mask=VisualScreenMask;
11893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  visual_template.screen=XDefaultScreen(display);
11903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  visual_template.depth=XDefaultDepth(display,XDefaultScreen(display));
11918891f9ce489d3e61399b60436ea6c62f5ed9b887cristy  one=1;
11923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((resource_info->immutable != MagickFalse) && (resource_info->colors != 0))
11938891f9ce489d3e61399b60436ea6c62f5ed9b887cristy    if (resource_info->colors <= (one << (size_t) visual_template.depth))
11943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      visual_mask|=VisualDepthMask;
11953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (visual_type != (char *) NULL)
11963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
11973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
11983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Restrict visual search by class or visual id.
11993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
12003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare("staticgray",visual_type) == 0)
12013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
12023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          visual_mask|=VisualClassMask;
12033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          visual_template.klass=StaticGray;
12043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
12053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
12063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (LocaleCompare("grayscale",visual_type) == 0)
12073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
12083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            visual_mask|=VisualClassMask;
12093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            visual_template.klass=GrayScale;
12103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
12113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        else
12123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (LocaleCompare("staticcolor",visual_type) == 0)
12133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
12143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              visual_mask|=VisualClassMask;
12153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              visual_template.klass=StaticColor;
12163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
12173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          else
12183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (LocaleCompare("pseudocolor",visual_type) == 0)
12193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
12203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                visual_mask|=VisualClassMask;
12213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                visual_template.klass=PseudoColor;
12223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
12233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            else
12243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (LocaleCompare("truecolor",visual_type) == 0)
12253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
12263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  visual_mask|=VisualClassMask;
12273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  visual_template.klass=TrueColor;
12283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
12293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              else
12303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if (LocaleCompare("directcolor",visual_type) == 0)
12313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
12323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    visual_mask|=VisualClassMask;
12333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    visual_template.klass=DirectColor;
12343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
12353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                else
12363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if (LocaleCompare("default",visual_type) == 0)
12373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
12383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      visual_mask|=VisualIDMask;
12393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      visual_template.visualid=XVisualIDFromVisual(
12403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        XDefaultVisual(display,XDefaultScreen(display)));
12413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
12423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  else
12433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    if (isdigit((int) ((unsigned char) *visual_type)) != 0)
12443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      {
12453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        visual_mask|=VisualIDMask;
12463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        visual_template.visualid=
12473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                          strtol(visual_type,(char **) NULL,0);
12483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      }
12493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    else
1250c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy                      ThrowXWindowException(XServerError,
12513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        "UnrecognizedVisualSpecifier",visual_type);
12523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
12533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
12543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Get all visuals that meet our criteria so far.
12553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
12563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  number_visuals=0;
12573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
12583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &number_visuals);
12593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  visual_mask=VisualScreenMask | VisualIDMask;
12603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
12613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
12623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
12633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Failed to get visual;  try using the default visual.
12643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
1265c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy      ThrowXWindowException(XServerWarning,"UnableToGetVisual",visual_type);
12663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      visual_template.visualid=XVisualIDFromVisual(XDefaultVisual(display,
12673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XDefaultScreen(display)));
12683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
12693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &number_visuals);
12703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
12713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        return((XVisualInfo *) NULL);
1272c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy      ThrowXWindowException(XServerWarning,"UsingDefaultVisual",
12733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XVisualClassName(visual_list->klass));
12743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
12753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->color_recovery=MagickFalse;
12763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((map_info != (XStandardColormap *) NULL) && (map_type != (char *) NULL))
12773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
12783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Atom
12793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        map_property;
12803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
12813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      char
1282151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy        map_name[MagickPathExtent];
12833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
12843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      int
12853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        j,
12863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        number_maps;
12873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
12883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Status
12893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        status;
12903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
12913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Window
12923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        root_window;
12933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
12943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XStandardColormap
12953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *map_list;
12963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
12973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
12983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Choose a visual associated with a standard colormap.
12993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
13003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      root_window=XRootWindow(display,XDefaultScreen(display));
13013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      status=False;
130253365c26d309f8817b58f203983b63333cc04029cristy      number_maps=0;
13033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare(map_type,"list") != 0)
13043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
13053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
13063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            User specified Standard Colormap.
13073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
1308151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy          (void) FormatLocaleString((char *) map_name,MagickPathExtent,
13093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            "RGB_%s_MAP",map_type);
13103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          LocaleUpper(map_name);
13113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          map_property=XInternAtom(display,(char *) map_name,MagickTrue);
13123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (map_property != (Atom) NULL)
13133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
13143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              map_property);
13153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
13163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
13173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
13183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          static const char
13193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *colormap[MaxStandardColormaps]=
13203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
13213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "_HP_RGB_SMOOTH_MAP_LIST",
13223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "RGB_BEST_MAP",
13233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "RGB_DEFAULT_MAP",
13243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "RGB_GRAY_MAP",
13253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "RGB_RED_MAP",
13263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "RGB_GREEN_MAP",
13273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "RGB_BLUE_MAP",
13283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            };
13293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
13303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
13313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Choose a standard colormap from a list.
13323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
13333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (i=0; i < MaxStandardColormaps; i++)
13343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
13353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            map_property=XInternAtom(display,(char *) colormap[i],MagickTrue);
13363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (map_property == (Atom) NULL)
13373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              continue;
13383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
13393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              map_property);
13403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (status != False)
13413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
13423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
13433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          resource_info->color_recovery=i == 0 ? MagickTrue : MagickFalse;
13443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
13453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status == False)
13463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
1347c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy          ThrowXWindowException(XServerError,"UnableToGetStandardColormap",
13483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            map_type);
13493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          return((XVisualInfo *) NULL);
13503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
13513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
13523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Search all Standard Colormaps and visuals for ids that match.
13533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
13543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      *map_info=map_list[0];
13553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if !defined(PRE_R4_ICCCM)
13563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
13573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (i=0; i < number_maps; i++)
13583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        for (j=0; j < number_visuals; j++)
13593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (map_list[i].visualid ==
13603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              XVisualIDFromVisual(visual_list[j].visual))
13613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
13623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *map_info=map_list[i];
13633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              visual_template.visualid=XVisualIDFromVisual(
13643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                visual_list[j].visual);
13653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
13663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
13673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (map_info->visualid != visual_template.visualid)
13683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
1369c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy          ThrowXWindowException(XServerError,
13703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            "UnableToMatchVisualToStandardColormap",map_type);
13713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          return((XVisualInfo *) NULL);
13723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
13733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
13743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (map_info->colormap == (Colormap) NULL)
13753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
1376c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy          ThrowXWindowException(XServerError,"StandardColormapIsNotInitialized",
1377c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy            map_type);
13783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          return((XVisualInfo *) NULL);
13793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
13803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFree((void *) map_list);
13813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
13823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
13833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
13843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      static const unsigned int
13853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        rank[]=
13863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
13873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            StaticGray,
13883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            GrayScale,
13893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            StaticColor,
13903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            DirectColor,
13913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            TrueColor,
13923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            PseudoColor
13933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          };
13943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
13953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XVisualInfo
13963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *p;
13973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
13983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
13993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Pick one visual that displays the most simultaneous colors.
14003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
14013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      visual_info=visual_list;
14023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      p=visual_list;
14033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (i=1; i < number_visuals; i++)
14043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
14053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        p++;
14063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
14073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          visual_info=p;
14083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        else
14093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
14103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (rank[p->klass] > rank[visual_info->klass])
14113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              visual_info=p;
14123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
14133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
14143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
14153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFree((void *) visual_list);
14163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
14173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Retrieve only one visual by its screen & id number.
14183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
14193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
14203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &number_visuals);
14213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
14223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return((XVisualInfo *) NULL);
14233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(visual_info);
14243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
14253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
14263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
14273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X C h e c k D e f i n e C u r s o r                                       %
14323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XCheckDefineCursor() prevents cursor changes on the root window.
14383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XXCheckDefineCursor method is:
14403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XCheckDefineCursor(display,window,cursor)
14423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
14443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
14463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
14473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: the window.
14493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o cursor: the cursor.
14513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1453bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate int XCheckDefineCursor(Display *display,Window window,
14543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Cursor cursor)
14553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
14563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
14573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
14583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window == XRootWindow(display,XDefaultScreen(display)))
14593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(0);
14603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(XDefineCursor(display,window,cursor));
14613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
14623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
14633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
14643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X C h e c k R e f r e s h W i n d o w s                                   %
14693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
14723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XCheckRefreshWindows() checks the X server for exposure events for a
14753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  particular window and updates the areassociated with the exposure event.
14763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XCheckRefreshWindows method is:
14783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XCheckRefreshWindows(Display *display,XWindows *windows)
14803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
14823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
14843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
14853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o windows: Specifies a pointer to a XWindows structure.
14873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
14883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1489bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XCheckRefreshWindows(Display *display,XWindows *windows)
14903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
14913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
14923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    id;
14933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
14943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XEvent
14953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    event;
14963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
14973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
14983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
14993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(windows != (XWindows *) NULL);
15003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XDelay(display,SuspendTime);
15013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  id=windows->command.id;
15023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
15033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XCommandWidget(display,windows,(char const **) NULL,&event);
15043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  id=windows->image.id;
15053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
15063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XRefreshWindow(display,&windows->image,&event);
15073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XDelay(display,SuspendTime << 1);
15083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  id=windows->command.id;
15093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
15103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XCommandWidget(display,windows,(char const **) NULL,&event);
15113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  id=windows->image.id;
15123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
15133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XRefreshWindow(display,&windows->image,&event);
15143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
15153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
15163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
15173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X C l i e n t M e s s a g e                                               %
15223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XClientMessage() sends a reason to a window with XSendEvent.  The reason is
15283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  initialized with a particular protocol type and atom.
15293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XClientMessage function is:
15313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XClientMessage(display,window,protocol,reason,timestamp)
15333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
15353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a pointer to the Display structure;  returned from
15373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
15383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a Window structure.
15403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o protocol: Specifies an atom value.
15423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o reason: Specifies an atom value which is the reason to send.
15443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o timestamp: Specifies a value of type Time.
15463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1548bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XClientMessage(Display *display,const Window window,
15493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const Atom protocol,const Atom reason,const Time timestamp)
15503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
15513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XClientMessageEvent
15523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    client_event;
15533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
15543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
15553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  client_event.type=ClientMessage;
15563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  client_event.window=window;
15573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  client_event.message_type=protocol;
15583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  client_event.format=32;
1559c57f694b2d04975a0e501613e34368c464708c19cristy  client_event.data.l[0]=(long) reason;
1560c57f694b2d04975a0e501613e34368c464708c19cristy  client_event.data.l[1]=(long) timestamp;
15613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSendEvent(display,window,MagickFalse,NoEventMask,(XEvent *) &client_event);
15623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
15633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
15643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
15653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy+   X C l i e n t W i n d o w                                                 %
15703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
15733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
15743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XClientWindow() finds a window, at or below the specified window, which has
15763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  a WM_STATE property.  If such a window is found, it is returned, otherwise
15773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  the argument window is returned.
15783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XClientWindow function is:
15803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      client_window=XClientWindow(display,target_window)
15823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
15843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o client_window: XClientWindow returns a window, at or below the specified
15863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      window, which has a WM_STATE property otherwise the argument
15873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      target_window is returned.
15883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a pointer to the Display structure;  returned from
15903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
15913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o target_window: Specifies the window to find a WM_STATE property.
15933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
15943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
15953ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Window XClientWindow(Display *display,Window target_window)
15963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
15973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Atom
15983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    state,
15993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    type;
16003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
16023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    format;
16033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
16053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
16063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned char
16083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *data;
16093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1610f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  unsigned long
16113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    after,
16123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_items;
16133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
16153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    client_window;
16163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
16183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
16193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  state=XInternAtom(display,"WM_STATE",MagickTrue);
16203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (state == (Atom) NULL)
16213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(target_window);
16223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  type=(Atom) NULL;
16233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XGetWindowProperty(display,target_window,state,0L,0L,MagickFalse,
16243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
16253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((status == Success) && (type != (Atom) NULL))
16263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(target_window);
16273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  client_window=XWindowByProperty(display,target_window,state);
16283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (client_window == (Window) NULL)
16293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(target_window);
16303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(client_window);
16313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
16323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
16343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
16363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
16373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
1638f34a145c545cb86152ad42a787f6d5fffea6b77ccristy+   X C o m p o n e n t T e r m i n u s                                       %
1639f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%                                                                             %
1640f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%                                                                             %
1641f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%                                                                             %
1642f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1643f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%
1644f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%  XComponentTerminus() destroys the module component.
1645f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%
1646f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%  The format of the XComponentTerminus method is:
1647f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%
1648f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%      XComponentTerminus(void)
1649f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%
1650f34a145c545cb86152ad42a787f6d5fffea6b77ccristy*/
16515ff4eaf57b3cd47d0371f204f865cbba614674a0cristyMagickPrivate void XComponentTerminus(void)
1652f34a145c545cb86152ad42a787f6d5fffea6b77ccristy{
1653f34a145c545cb86152ad42a787f6d5fffea6b77ccristy  DestroyXResources();
1654f34a145c545cb86152ad42a787f6d5fffea6b77ccristy}
1655f34a145c545cb86152ad42a787f6d5fffea6b77ccristy
1656f34a145c545cb86152ad42a787f6d5fffea6b77ccristy/*
1657f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1658f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%                                                                             %
1659f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%                                                                             %
1660f34a145c545cb86152ad42a787f6d5fffea6b77ccristy%                                                                             %
16613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X C o n f i g u r e I m a g e C o l o r m a p                             %
16623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
16633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
16643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
16653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XConfigureImageColormap() creates a new X colormap.
16683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XConfigureImageColormap method is:
16703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XConfigureImageColormap(Display *display,
16726710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        XResourceInfo *resource_info,XWindows *windows,Image *image,
16736710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        ExceptionInfo *exception)
16743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
16763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
16783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
16793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
16813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o windows: Specifies a pointer to a XWindows structure.
16833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
16853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
16866710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    o exception: return any errors or warnings in this structure.
16876710d8414f0ed06e4eaf9346366be72e2b4719efcristy%
16883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1689bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XConfigureImageColormap(Display *display,
16906710d8414f0ed06e4eaf9346366be72e2b4719efcristy  XResourceInfo *resource_info,XWindows *windows,Image *image,
16916710d8414f0ed06e4eaf9346366be72e2b4719efcristy  ExceptionInfo *exception)
16923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
16933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Colormap
16943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    colormap;
16953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
16963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
16973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Make standard colormap.
16983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
16993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XSetCursorState(display,windows,MagickTrue);
17003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XCheckRefreshWindows(display,windows);
17013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XMakeStandardColormap(display,windows->visual_info,resource_info,image,
17026710d8414f0ed06e4eaf9346366be72e2b4719efcristy    windows->map_info,windows->pixel_info,exception);
17033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  colormap=windows->map_info->colormap;
17043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSetWindowColormap(display,windows->image.id,colormap);
17053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSetWindowColormap(display,windows->command.id,colormap);
17063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSetWindowColormap(display,windows->widget.id,colormap);
17073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->magnify.mapped != MagickFalse)
17083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XSetWindowColormap(display,windows->magnify.id,colormap);
17093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->pan.mapped != MagickFalse)
17103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XSetWindowColormap(display,windows->pan.id,colormap);
17113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XSetCursorState(display,windows,MagickFalse);
17123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XClientMessage(display,windows->image.id,windows->im_protocols,
17133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    windows->im_update_colormap,CurrentTime);
17143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
17153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
17163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
17173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X C o n s t r a i n W i n d o w P o s i t i o n                           %
17223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XConstrainWindowPosition() assures a window is positioned within the X
17283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  server boundaries.
17293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XConstrainWindowPosition method is:
17313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XConstrainWindowPosition(Display *display,XWindowInfo *window_info)
17333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
17353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a pointer to the Display structure;  returned from
17373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
17383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window_info: Specifies a pointer to a XWindowInfo structure.
17403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1742bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XConstrainWindowPosition(Display *display,
17433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XWindowInfo *window_info)
17443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
17453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
17463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    limit;
17473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
17483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
17493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
17503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window_info != (XWindowInfo *) NULL);
17513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  limit=XDisplayWidth(display,window_info->screen)-window_info->width;
17523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info->x < 0)
17533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window_info->x=0;
17543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
17553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (window_info->x > (int) limit)
17563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_info->x=(int) limit;
17573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  limit=XDisplayHeight(display,window_info->screen)-window_info->height;
17583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info->y < 0)
17593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window_info->y=0;
17603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
17613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (window_info->y > limit)
17623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_info->y=limit;
17633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
17643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
17653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
17663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X D e l a y                                                               %
17713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
17743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XDelay() suspends program execution for the number of milliseconds
17773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  specified.
17783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the Delay method is:
17803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1781bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy%      void XDelay(Display *display,const size_t milliseconds)
17823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
17843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a pointer to the Display structure;  returned from
17863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
17873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o milliseconds: Specifies the number of milliseconds to delay before
17893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      returning.
17903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
17913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1792bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XDelay(Display *display,const size_t milliseconds)
17933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
17943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
17953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFlush(display);
1796a21afdefe277667f7821fa90decc1f15a167eacfcristy  MagickDelay(milliseconds);
17973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
17983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
17993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
18003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X D e s t r o y R e s o u r c e I n f o                                   %
18053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XDestroyResourceInfo() frees memory associated with the XResourceInfo
18113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  structure.
18123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XDestroyResourceInfo method is:
18143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XDestroyResourceInfo(XResourceInfo *resource_info)
18163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
18183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
18203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
18223ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport void XDestroyResourceInfo(XResourceInfo *resource_info)
18233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
18243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->image_geometry != (char *) NULL)
18253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_info->image_geometry=(char *)
18263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      RelinquishMagickMemory(resource_info->image_geometry);
18273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->quantize_info != (QuantizeInfo *) NULL)
18283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_info->quantize_info=DestroyQuantizeInfo(
18293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      resource_info->quantize_info);
18303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->client_name != (char *) NULL)
18313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_info->client_name=(char *)
18323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      RelinquishMagickMemory(resource_info->client_name);
18333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->name != (char *) NULL)
18343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_info->name=DestroyString(resource_info->name);
18353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
18363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
18373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
18383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
18393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X D e s t r o y W i n d o w C o l o r s                                   %
18443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
18473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
18483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XDestroyWindowColors() frees X11 color resources previously saved on a
18503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  window by XRetainWindowColors or programs like xsetroot.
18513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XDestroyWindowColors method is:
18533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XDestroyWindowColors(Display *display,Window window)
18553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
18573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
18593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
18603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a Window structure.
18623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
18633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1864bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XDestroyWindowColors(Display *display,Window window)
18653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
18663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Atom
18673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    property,
18683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    type;
18693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
18703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
18713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    format;
18723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
18733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
18743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
18753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
18763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned char
18773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *data;
18783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1879f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  unsigned long
18803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    after,
18813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    length;
18823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
18833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
18843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    If there are previous resources on the root window, destroy them.
18853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
18863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
18873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
18883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
18893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (property == (Atom) NULL)
18903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
1891c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy      ThrowXWindowException(XServerError,"UnableToCreateProperty",
18923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "_XSETROOT_ID");
18933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return;
18943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
18953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XGetWindowProperty(display,window,property,0L,1L,MagickTrue,
18963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (Atom) AnyPropertyType,&type,&format,&length,&after,&data);
18973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status != Success)
18983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
18993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((type == XA_PIXMAP) && (format == 32) && (length == 1) && (after == 0))
19003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
19013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XKillClient(display,(XID) (*((Pixmap *) data)));
19023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDeleteProperty(display,window,property);
19033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
19043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (type != None)
19053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XFree((void *) data);
19063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
19073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
19083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
19093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
19113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
19123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
19133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X D i s p l a y I m a g e I n f o                                         %
19143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
19153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
19163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
19173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XDisplayImageInfo() displays information about an X image.
19203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XDisplayImageInfo method is:
19223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XDisplayImageInfo(Display *display,
19243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
19256710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        Image *image,ExceptionInfo *exception)
19263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
19283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
19303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
19313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
19333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o windows: Specifies a pointer to a XWindows structure.
19353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o undo_image: the undo image.
19373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
19393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
19406710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    o exception: return any errors or warnings in this structure.
19416710d8414f0ed06e4eaf9346366be72e2b4719efcristy%
19423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1943bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XDisplayImageInfo(Display *display,
19443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const XResourceInfo *resource_info,XWindows *windows,Image *undo_image,
19456710d8414f0ed06e4eaf9346366be72e2b4719efcristy  Image *image,ExceptionInfo *exception)
19463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
19473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
1948151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    filename[MagickPathExtent],
19493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *text,
19503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    **textlist;
19513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
19523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  FILE
19533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *file;
19543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
19553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
19563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unique_file;
19573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1958bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  register ssize_t
19593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
19603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1961bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  size_t
19623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_pixels;
19633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
19649d314ff2c17a77996c05413c2013880387e50f0ecristy  ssize_t
19659d314ff2c17a77996c05413c2013880387e50f0ecristy    bytes;
19669d314ff2c17a77996c05413c2013880387e50f0ecristy
19679d314ff2c17a77996c05413c2013880387e50f0ecristy  unsigned int
19689d314ff2c17a77996c05413c2013880387e50f0ecristy    levels;
19699d314ff2c17a77996c05413c2013880387e50f0ecristy
19703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
19713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Write info about the X server to a file.
19723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
19733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
19743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
19753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(windows != (XWindows *) NULL);
19763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image != (Image *) NULL);
19773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image->debug)
19783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
19793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  file=(FILE *) NULL;
19803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unique_file=AcquireUniqueFileResource(filename);
19813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (unique_file != -1)
19823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    file=fdopen(unique_file,"w");
19833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((unique_file == -1) || (file == (FILE *) NULL))
19843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
19853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XNoticeWidget(display,windows,"Unable to display image info",filename);
19863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return;
19873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
19883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->gamma_correct != MagickFalse)
19893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (resource_info->display_gamma != (char *) NULL)
1990b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy      (void) FormatLocaleFile(file,"Display\n  gamma: %s\n\n",
19913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        resource_info->display_gamma);
19923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
19933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Write info about the X image to a file.
19943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
1995b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"X\n  visual: %s\n",
19963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XVisualClassName((int) windows->image.storage_class));
1997b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"  depth: %d\n",windows->image.ximage->depth);
19983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->visual_info->colormap_size != 0)
1999b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"  colormap size: %d\n",
20003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->visual_info->colormap_size);
20013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->colormap== SharedColormap)
2002b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"  colormap type: Shared\n");
20033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
2004b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"  colormap type: Private\n");
20051e604812fad85bb96f757a2393015ae3d061c39acristy  (void) FormatLocaleFile(file,"  geometry: %dx%d\n",
20061e604812fad85bb96f757a2393015ae3d061c39acristy    windows->image.ximage->width,windows->image.ximage->height);
20073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->image.crop_geometry != (char *) NULL)
20081e604812fad85bb96f757a2393015ae3d061c39acristy    (void) FormatLocaleFile(file,"  crop geometry: %s\n",
20091e604812fad85bb96f757a2393015ae3d061c39acristy      windows->image.crop_geometry);
20103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->image.pixmap == (Pixmap) NULL)
2011b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"  type: X Image\n");
20123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
2013b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"  type: Pixmap\n");
20143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->image.shape != MagickFalse)
2015b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"  non-rectangular shape: True\n");
20163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
2017b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"  non-rectangular shape: False\n");
20183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->image.shared_memory != MagickFalse)
2019b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"  shared memory: True\n");
20203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
2021b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"  shared memory: False\n");
2022b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"\n");
20233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->font != (char *) NULL)
2024b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"Font: %s\n\n",resource_info->font);
20253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->text_font != (char *) NULL)
2026b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy    (void) FormatLocaleFile(file,"Text font: %s\n\n",resource_info->text_font);
20273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
20283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Write info about the undo cache to a file.
20293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
20303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  bytes=0;
20313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (levels=0; undo_image != (Image *) NULL; levels++)
20323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
20333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_pixels=undo_image->list->columns*undo_image->list->rows;
2034101ab708b0574518ac5715da4d3915400e9df79acristy    bytes+=number_pixels*sizeof(PixelInfo);
20353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    undo_image=GetPreviousImageInList(undo_image);
20363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
2037b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"Undo Edit Cache\n  levels: %u\n",levels);
20381e604812fad85bb96f757a2393015ae3d061c39acristy  (void) FormatLocaleFile(file,"  bytes: %.20gmb\n",(double)
20391e604812fad85bb96f757a2393015ae3d061c39acristy    ((bytes+(1 << 19)) >> 20));
2040b51dff5c0d16a4c1b69ff683e786cb3b4c467694cristy  (void) FormatLocaleFile(file,"  limit: %.20gmb\n\n",(double)
2041f2faecf9facdbbb14fcba373365f9f691a9658e0cristy    resource_info->undo_cache);
20423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
20433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Write info about the image to a file.
20443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
20456710d8414f0ed06e4eaf9346366be72e2b4719efcristy  (void) IdentifyImage(image,file,MagickTrue,exception);
20463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) fclose(file);
20473a5987c75c361dde2b38579f05ca961927d842fecristy  text=FileToString(filename,~0UL,exception);
20483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) RelinquishUniqueFileResource(filename);
20493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (text == (char *) NULL)
20503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
20513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XNoticeWidget(display,windows,"MemoryAllocationFailed",
20523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "UnableToDisplayImageInfo");
20533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return;
20543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
20553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  textlist=StringToList(text);
20563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (textlist != (char **) NULL)
20573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
20583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      char
2059151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy        title[MagickPathExtent];
20603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
20613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
20623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Display information about the image in the Text View widget.
20633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
20643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
2065151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy      (void) FormatLocaleString(title,MagickPathExtent,"Image Info: %s",
20663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        image->filename);
20673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XTextViewWidget(display,resource_info,windows,MagickTrue,title,
20683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (char const **) textlist);
20693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (i=0; textlist[i] != (char *) NULL; i++)
20703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        textlist[i]=DestroyString(textlist[i]);
20713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      textlist=(char **) RelinquishMagickMemory(textlist);
20723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
20733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  text=DestroyString(text);
20743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
20753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
20763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
20773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
20793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
20803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
20813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy+     X D i t h e r I m a g e                                                 %
20823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
20833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
20843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
20853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
20863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
20873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XDitherImage() dithers the reference image as required by the HP Color
20883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  Recovery algorithm.  The color values are quantized to 3 bits of red and
20893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  green, and 2 bits of blue (3/3/2) and can be used as indices into a 8-bit X
20903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  standard colormap.
20913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
20923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XDitherImage method is:
20933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
20946710d8414f0ed06e4eaf9346366be72e2b4719efcristy%      void XDitherImage(Image *image,XImage *ximage,ExceptionInfo *exception)
20953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
20963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
20973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
20983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
20993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
21003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o ximage: Specifies a pointer to a XImage structure;  returned from
21013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XCreateImage.
21023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
21036710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    o exception: return any errors or warnings in this structure.
21046710d8414f0ed06e4eaf9346366be72e2b4719efcristy%
21053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
21066710d8414f0ed06e4eaf9346366be72e2b4719efcristystatic void XDitherImage(Image *image,XImage *ximage,ExceptionInfo *exception)
21073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
21083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static const short int
21093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    dither_red[2][16]=
21103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
21113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {-16,  4, -1, 11,-14,  6, -3,  9,-15,  5, -2, 10,-13,  7, -4,  8},
21123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      { 15, -5,  0,-12, 13, -7,  2,-10, 14, -6,  1,-11, 12, -8,  3, -9}
21133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    },
21143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    dither_green[2][16]=
21153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
21163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      { 11,-15,  7, -3,  8,-14,  4, -2, 10,-16,  6, -4,  9,-13,  5, -1},
21173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {-12, 14, -8,  2, -9, 13, -5,  1,-11, 15, -7,  3,-10, 12, -6,  0}
21183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    },
21193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    dither_blue[2][16]=
21203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
21213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      { -3,  9,-13,  7, -1, 11,-15,  5, -4,  8,-14,  6, -2, 10,-16,  4},
21223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {  2,-10, 12, -8,  0,-12, 14, -6,  3, -9, 13, -7,  1,-11, 15, -5}
21233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    };
21243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2125c57f694b2d04975a0e501613e34368c464708c19cristy  CacheView
2126c57f694b2d04975a0e501613e34368c464708c19cristy    *image_view;
21273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
21283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
2129c57f694b2d04975a0e501613e34368c464708c19cristy    value,
21303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y;
21313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2132101ab708b0574518ac5715da4d3915400e9df79acristy  PixelInfo
2133c57f694b2d04975a0e501613e34368c464708c19cristy    color;
21343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
21353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register char
21363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *q;
21373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
21384c08aed51c5899665ade97263692328eea4af106cristy  register const Quantum
21393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p;
21403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
21413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
21423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i,
21433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    j,
21443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x;
21453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
21463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
21473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scanline_pad;
21483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2149bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  register size_t
21503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel;
21513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
21523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned char
21533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *blue_map[2][16],
21543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *green_map[2][16],
21553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *red_map[2][16];
21563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
21573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
21583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Allocate and initialize dither maps.
21593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
21603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; i < 2; i++)
21613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    for (j=0; j < 16; j++)
21623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
21633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      red_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
21643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        sizeof(*red_map));
21653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      green_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
21663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        sizeof(*green_map));
21673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      blue_map[i][j]=(unsigned char *) AcquireQuantumMemory(256UL,
21683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        sizeof(*blue_map));
21693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((red_map[i][j] == (unsigned char *) NULL) ||
21703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (green_map[i][j] == (unsigned char *) NULL) ||
21713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (blue_map[i][j] == (unsigned char *) NULL))
21723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
2173c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy          ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
2174c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy            image->filename);
21753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          return;
21763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
21773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
21783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
21793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize dither tables.
21803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
21813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; i < 2; i++)
21823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    for (j=0; j < 16; j++)
21833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (x=0; x < 256; x++)
21843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
21853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        value=x-16;
21863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (x < 48)
21873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          value=x/2+8;
21883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        value+=dither_red[i][j];
21893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        red_map[i][j][x]=(unsigned char)
21903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ((value < 0) ? 0 : (value > 255) ? 255 : value);
21913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        value=x-16;
21923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (x < 48)
21933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          value=x/2+8;
21943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        value+=dither_green[i][j];
21953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        green_map[i][j][x]=(unsigned char)
21963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ((value < 0) ? 0 : (value > 255) ? 255 : value);
21973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        value=x-32;
21983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (x < 112)
21993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          value=x/2+24;
2200bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        value+=((size_t) dither_blue[i][j] << 1);
22013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        blue_map[i][j][x]=(unsigned char)
22023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ((value < 0) ? 0 : (value > 255) ? 255 : value);
22033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
22043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
22053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Dither image.
22063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
22073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  scanline_pad=(unsigned int) (ximage->bytes_per_line-
2208bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy    ((size_t) (ximage->width*ximage->bits_per_pixel) >> 3));
22093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  i=0;
22103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  j=0;
22113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  q=ximage->data;
221246ff2676b1044ea4101ac7a59b83289cd8f6cfdacristy  image_view=AcquireVirtualCacheView(image,exception);
22133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (y=0; y < (int) image->rows; y++)
22143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
2215c57f694b2d04975a0e501613e34368c464708c19cristy    p=GetCacheViewVirtualPixels(image_view,0,(ssize_t) y,image->columns,1,
22166710d8414f0ed06e4eaf9346366be72e2b4719efcristy      exception);
22174c08aed51c5899665ade97263692328eea4af106cristy    if (p == (const Quantum *) NULL)
22183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
22193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    for (x=0; x < (int) image->columns; x++)
22203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
2221ada285ba46bd3b79ab9321bbd1e617c6551b1e33cristy      color.red=(double) ClampToQuantum((double) (red_map[i][j][
2222e42f658533644aecb733785ffd91b286d6778deacristy        (int) ScaleQuantumToChar(GetPixelRed(image,p))] << 8));
2223ada285ba46bd3b79ab9321bbd1e617c6551b1e33cristy      color.green=(double) ClampToQuantum((double) (green_map[i][j][
2224e42f658533644aecb733785ffd91b286d6778deacristy        (int) ScaleQuantumToChar(GetPixelGreen(image,p))] << 8));
2225ada285ba46bd3b79ab9321bbd1e617c6551b1e33cristy      color.blue=(double) ClampToQuantum((double) (blue_map[i][j][
2226e42f658533644aecb733785ffd91b286d6778deacristy        (int) ScaleQuantumToChar(GetPixelBlue(image,p))] << 8));
2227bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      pixel=(size_t) (((size_t) color.red & 0xe0) |
2228bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        (((size_t) color.green & 0xe0) >> 3) |
2229bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        (((size_t) color.blue & 0xc0) >> 6));
22303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      *q++=(char) pixel;
2231ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy      p+=GetPixelChannels(image);
22323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      j++;
22333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (j == 16)
22343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        j=0;
22353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
22363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    q+=scanline_pad;
22373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i++;
22383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (i == 2)
22393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      i=0;
22403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
2241c57f694b2d04975a0e501613e34368c464708c19cristy  image_view=DestroyCacheView(image_view);
22423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
22433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Free allocated memory.
22443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
22453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; i < 2; i++)
22463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    for (j=0; j < 16; j++)
22473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
22483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      green_map[i][j]=(unsigned char *) RelinquishMagickMemory(green_map[i][j]);
22493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      blue_map[i][j]=(unsigned char *) RelinquishMagickMemory(blue_map[i][j]);
22503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      red_map[i][j]=(unsigned char *) RelinquishMagickMemory(red_map[i][j]);
22513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
22523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
22533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
22543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
22553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
22573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
22583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
22593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X D r a w I m a g e                                                       %
22603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
22613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
22623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
22633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
22643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
22653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XDrawImage() draws a line on the image.
22663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
22673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XDrawImage method is:
22683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
22696710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    MagickBooleanType XDrawImage(Display *display,const XPixelInfo *pixel,
22706710d8414f0ed06e4eaf9346366be72e2b4719efcristy%      XDrawInfo *draw_info,Image *image,ExceptionInfo *exception)
22713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
22723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
22733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
22743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
22753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
22763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
22773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o pixel: Specifies a pointer to a XPixelInfo structure.
22783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
22793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o draw_info: Specifies a pointer to a XDrawInfo structure.
22803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
22813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
22823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
22836710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    o exception: return any errors or warnings in this structure.
22846710d8414f0ed06e4eaf9346366be72e2b4719efcristy%
22853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
2286bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate MagickBooleanType XDrawImage(Display *display,
22876710d8414f0ed06e4eaf9346366be72e2b4719efcristy  const XPixelInfo *pixel,XDrawInfo *draw_info,Image *image,
22886710d8414f0ed06e4eaf9346366be72e2b4719efcristy  ExceptionInfo *exception)
22893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
2290c57f694b2d04975a0e501613e34368c464708c19cristy  CacheView
2291c57f694b2d04975a0e501613e34368c464708c19cristy    *draw_view;
2292c57f694b2d04975a0e501613e34368c464708c19cristy
22933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  GC
22943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    draw_context;
22953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
22963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Image
22973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *draw_image;
22983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
22993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
23003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x,
23013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y;
23023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2303b0a657e13c4aefba39c51292005427b47277869dcristy  PixelTrait
2304b0a657e13c4aefba39c51292005427b47277869dcristy    alpha_trait;
23053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
23063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Pixmap
23073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    draw_pixmap;
23083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
23093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
23103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    depth,
23113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    height,
23123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    width;
23133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
23143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
23153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root_window;
23163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
23173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XGCValues
23183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    context_values;
23193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
23203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XImage
23213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *draw_ximage;
23223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
23233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
23243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize drawd image.
23253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
23263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
23273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(pixel != (XPixelInfo *) NULL);
23283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(draw_info != (XDrawInfo *) NULL);
23293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image != (Image *) NULL);
23303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image->debug != MagickFalse)
23313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
23323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
23333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize drawd pixmap.
23343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
23353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  root_window=XRootWindow(display,XDefaultScreen(display));
23363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
23373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  draw_pixmap=XCreatePixmap(display,root_window,draw_info->width,
23383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    draw_info->height,depth);
23393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_pixmap == (Pixmap) NULL)
23403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
23413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
23423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize graphics info.
23433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
2344bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  context_values.background=(size_t) (~0);
23453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  context_values.foreground=0;
23463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  context_values.line_width=(int) draw_info->line_width;
2347bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  draw_context=XCreateGC(display,root_window,(size_t)
23483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (GCBackground | GCForeground | GCLineWidth),&context_values);
23493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_context == (GC) NULL)
23503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
23513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
23523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Clear pixmap.
23533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
23543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFillRectangle(display,draw_pixmap,draw_context,0,0,draw_info->width,
23553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    draw_info->height);
23563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
23573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Draw line to pixmap.
23583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
23593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSetBackground(display,draw_context,0);
2360bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  (void) XSetForeground(display,draw_context,(size_t) (~0));
2361dd05bebf92311ac0db88ae24d6a6862a4729e8a5cristy  if (draw_info->stipple !=  (Pixmap) NULL)
2362dd05bebf92311ac0db88ae24d6a6862a4729e8a5cristy    {
2363dd05bebf92311ac0db88ae24d6a6862a4729e8a5cristy      (void) XSetFillStyle(display,draw_context,FillOpaqueStippled);
2364dd05bebf92311ac0db88ae24d6a6862a4729e8a5cristy      (void) XSetStipple(display,draw_context,draw_info->stipple);
2365dd05bebf92311ac0db88ae24d6a6862a4729e8a5cristy    }
23663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  switch (draw_info->element)
23673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
23683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case PointElement:
23693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    default:
23703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
23713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDrawLines(display,draw_pixmap,draw_context,
23723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        draw_info->coordinate_info,(int) draw_info->number_coordinates,
23733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        CoordModeOrigin);
23743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
23753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
23763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case LineElement:
23773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
23783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDrawLine(display,draw_pixmap,draw_context,draw_info->line_info.x1,
23793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        draw_info->line_info.y1,draw_info->line_info.x2,
23803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        draw_info->line_info.y2);
23813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
23823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
23833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case RectangleElement:
23843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
23853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDrawRectangle(display,draw_pixmap,draw_context,
23863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
23873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) draw_info->rectangle_info.width,
23883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) draw_info->rectangle_info.height);
23893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
23903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
23913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case FillRectangleElement:
23923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
23933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFillRectangle(display,draw_pixmap,draw_context,
23943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
23953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) draw_info->rectangle_info.width,
23963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) draw_info->rectangle_info.height);
23973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
23983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
23993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case CircleElement:
24003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case EllipseElement:
24013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
24023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDrawArc(display,draw_pixmap,draw_context,
24033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
24043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) draw_info->rectangle_info.width,
24053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) draw_info->rectangle_info.height,0,360*64);
24063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
24073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
24083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case FillCircleElement:
24093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case FillEllipseElement:
24103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
24113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFillArc(display,draw_pixmap,draw_context,
24123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (int) draw_info->rectangle_info.x,(int) draw_info->rectangle_info.y,
24133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) draw_info->rectangle_info.width,
24143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) draw_info->rectangle_info.height,0,360*64);
24153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
24163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
24173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case PolygonElement:
24183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
24193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XPoint
24203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *coordinate_info;
24213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
24223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      coordinate_info=draw_info->coordinate_info;
24233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDrawLines(display,draw_pixmap,draw_context,coordinate_info,
24243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (int) draw_info->number_coordinates,CoordModeOrigin);
24253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDrawLine(display,draw_pixmap,draw_context,
24263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        coordinate_info[draw_info->number_coordinates-1].x,
24273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        coordinate_info[draw_info->number_coordinates-1].y,
24283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        coordinate_info[0].x,coordinate_info[0].y);
24293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
24303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
24313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case FillPolygonElement:
24323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
24333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFillPolygon(display,draw_pixmap,draw_context,
24343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        draw_info->coordinate_info,(int) draw_info->number_coordinates,Complex,
24353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        CoordModeOrigin);
24363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
24373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
24383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
24393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFreeGC(display,draw_context);
24403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
24413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize X image.
24423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
24433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  draw_ximage=XGetImage(display,draw_pixmap,0,0,draw_info->width,
24443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    draw_info->height,AllPlanes,ZPixmap);
24453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_ximage == (XImage *) NULL)
24463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
24473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFreePixmap(display,draw_pixmap);
24483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
24493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize draw image.
24503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
24516710d8414f0ed06e4eaf9346366be72e2b4719efcristy  draw_image=AcquireImage((ImageInfo *) NULL,exception);
24523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_image == (Image *) NULL)
24533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
24543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  draw_image->columns=draw_info->width;
24553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  draw_image->rows=draw_info->height;
24563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
24573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Transfer drawn X image to image.
24583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
24593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  width=(unsigned int) image->columns;
24603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  height=(unsigned int) image->rows;
24613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=0;
24623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y=0;
24633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
2464f05d4947caf1bc27fbec041eb37c474a80c83c0bcristy  (void) GetOneVirtualPixelInfo(image,UndefinedVirtualPixelMethod,(ssize_t) x,
2465f05d4947caf1bc27fbec041eb37c474a80c83c0bcristy    (ssize_t) y,&draw_image->background_color,exception);
24666710d8414f0ed06e4eaf9346366be72e2b4719efcristy  if (SetImageStorageClass(draw_image,DirectClass,exception) == MagickFalse)
24673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
24688a46d827a124555f0c48fb2368ec1bba8e079ab6cristy  draw_image->alpha_trait=BlendPixelTrait;
24696f5395df39e037392db46729f9aab05f2a9a428fcristy  draw_view=AcquireAuthenticCacheView(draw_image,exception);
24703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (y=0; y < (int) draw_image->rows; y++)
24713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
2472c57f694b2d04975a0e501613e34368c464708c19cristy    register int
24733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      x;
24743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
24754c08aed51c5899665ade97263692328eea4af106cristy    register Quantum
247605d2ff7ebf21f659f5b11e45afb294e152f4330cdirk      *magick_restrict q;
24773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2478c57f694b2d04975a0e501613e34368c464708c19cristy    q=QueueCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,
2479c57f694b2d04975a0e501613e34368c464708c19cristy      1,exception);
2480acd2ed254c18c254a0ab5aafa06d1645e5d079d8cristy    if (q == (Quantum *) NULL)
24813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
2482c57f694b2d04975a0e501613e34368c464708c19cristy    for (x=0; x < (int) draw_image->columns; x++)
24833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
24843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (XGetPixel(draw_ximage,x,y) == 0)
24853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
24863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
24873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Set this pixel to the background color.
24883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
248911a06d3f2cac0f17af7963e83bc6e9ebd2a377c0cristy          SetPixelViaPixelInfo(draw_image,&draw_image->background_color,q);
24907676158e6c207e287beb252c9837d565863c3328cristy          SetPixelAlpha(draw_image,(Quantum) (draw_info->stencil ==
24914c08aed51c5899665ade97263692328eea4af106cristy            OpaqueStencil ? TransparentAlpha : OpaqueAlpha),q);
24923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
24933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
24943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
24953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
24963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Set this pixel to the pen color.
24973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
24984c08aed51c5899665ade97263692328eea4af106cristy          SetPixelRed(draw_image,ScaleShortToQuantum(
24994c08aed51c5899665ade97263692328eea4af106cristy            pixel->pen_color.red),q);
25004c08aed51c5899665ade97263692328eea4af106cristy          SetPixelGreen(draw_image,ScaleShortToQuantum(
25014c08aed51c5899665ade97263692328eea4af106cristy            pixel->pen_color.green),q);
25024c08aed51c5899665ade97263692328eea4af106cristy          SetPixelBlue(draw_image,ScaleShortToQuantum(
25034c08aed51c5899665ade97263692328eea4af106cristy            pixel->pen_color.blue),q);
25044c08aed51c5899665ade97263692328eea4af106cristy          SetPixelAlpha(draw_image,(Quantum) (draw_info->stencil ==
25054c08aed51c5899665ade97263692328eea4af106cristy            OpaqueStencil ? OpaqueAlpha : TransparentAlpha),q);
25063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
2507ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy      q+=GetPixelChannels(draw_image);
25083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
2509c57f694b2d04975a0e501613e34368c464708c19cristy    if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
25103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
25113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
2512c57f694b2d04975a0e501613e34368c464708c19cristy  draw_view=DestroyCacheView(draw_view);
25133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XDestroyImage(draw_ximage);
25143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
25153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Determine draw geometry.
25163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
25173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
25183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((width != (unsigned int) draw_image->columns) ||
25193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (height != (unsigned int) draw_image->rows))
25203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
25213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      char
2522151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy        image_geometry[MagickPathExtent];
25233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
25243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
25253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Scale image.
25263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
2527151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy      (void) FormatLocaleString(image_geometry,MagickPathExtent,"%ux%u",
25283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        width,height);
2529e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy      (void) TransformImage(&draw_image,(char *) NULL,image_geometry,
2530e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy        exception);
25313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
25323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_info->degrees != 0.0)
25333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
25343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Image
25353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *rotate_image;
25363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
25373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      int
25383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        rotations;
25393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2540a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy      double
25413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        normalized_degrees;
25423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
25433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
25443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Rotate image.
25453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
25466710d8414f0ed06e4eaf9346366be72e2b4719efcristy      rotate_image=RotateImage(draw_image,draw_info->degrees,exception);
25473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (rotate_image == (Image *) NULL)
25483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        return(MagickFalse);
25493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      draw_image=DestroyImage(draw_image);
25503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      draw_image=rotate_image;
25513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
25523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Annotation is relative to the degree of rotation.
25533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
25543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      normalized_degrees=draw_info->degrees;
25553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      while (normalized_degrees < -45.0)
25563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        normalized_degrees+=360.0;
25573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (rotations=0; normalized_degrees > 45.0; rotations++)
25583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        normalized_degrees-=90.0;
25593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      switch (rotations % 4)
25603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
25613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        default:
25623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 0:
25633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
25643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 1:
25653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
25663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
25673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Rotate 90 degrees.
25683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
25693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          x=x-(int) draw_image->columns/2;
25703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          y=y+(int) draw_image->columns/2;
25713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
25723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
25733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 2:
25743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
25753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
25763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Rotate 180 degrees.
25773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
25783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          x=x-(int) draw_image->columns;
25793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
25803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
25813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 3:
25823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
25833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
25843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Rotate 270 degrees.
25853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
25863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          x=x-(int) draw_image->columns/2;
25873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          y=y-(int) (draw_image->rows-(draw_image->columns/2));
25883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
25893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
25903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
25913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
25923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
25933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Composite text onto the image.
25943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
25956f5395df39e037392db46729f9aab05f2a9a428fcristy  draw_view=AcquireAuthenticCacheView(draw_image,exception);
25963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (y=0; y < (int) draw_image->rows; y++)
25973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
2598c57f694b2d04975a0e501613e34368c464708c19cristy    register int
25993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      x;
26003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
26014c08aed51c5899665ade97263692328eea4af106cristy    register Quantum
260205d2ff7ebf21f659f5b11e45afb294e152f4330cdirk      *magick_restrict q;
26033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2604c57f694b2d04975a0e501613e34368c464708c19cristy    q=GetCacheViewAuthenticPixels(draw_view,0,(ssize_t) y,draw_image->columns,1,
2605c57f694b2d04975a0e501613e34368c464708c19cristy      exception);
2606acd2ed254c18c254a0ab5aafa06d1645e5d079d8cristy    if (q == (Quantum *) NULL)
26073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
2608c57f694b2d04975a0e501613e34368c464708c19cristy    for (x=0; x < (int) draw_image->columns; x++)
26093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
26104c08aed51c5899665ade97263692328eea4af106cristy      if (GetPixelAlpha(image,q) != TransparentAlpha)
26114c08aed51c5899665ade97263692328eea4af106cristy        SetPixelAlpha(draw_image,OpaqueAlpha,q);
2612ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy      q+=GetPixelChannels(draw_image);
26133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
2614c57f694b2d04975a0e501613e34368c464708c19cristy    if (SyncCacheViewAuthenticPixels(draw_view,exception) == MagickFalse)
26153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
26163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
2617c57f694b2d04975a0e501613e34368c464708c19cristy  draw_view=DestroyCacheView(draw_view);
26183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseGeometry(draw_info->geometry,&x,&y,&width,&height);
26193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (draw_info->stencil == TransparentStencil)
262039172408bad7ef2ef00a815fa9abf9979e7857cbcristy    (void) CompositeImage(image,draw_image,CopyAlphaCompositeOp,MagickTrue,
2621feb3e9695150978a5d2372d3fe2f60466a7c8066cristy      (ssize_t) x,(ssize_t) y,exception);
26223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
26233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
2624b0a657e13c4aefba39c51292005427b47277869dcristy      alpha_trait=image->alpha_trait;
262539172408bad7ef2ef00a815fa9abf9979e7857cbcristy      (void) CompositeImage(image,draw_image,OverCompositeOp,MagickTrue,
2626feb3e9695150978a5d2372d3fe2f60466a7c8066cristy        (ssize_t) x,(ssize_t) y,exception);
2627b0a657e13c4aefba39c51292005427b47277869dcristy      image->alpha_trait=alpha_trait;
26283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
26293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  draw_image=DestroyImage(draw_image);
26303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickTrue);
26313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
26323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
26333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
26343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
26363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
26373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
26383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X E r r o r                                                               %
26393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
26403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
26413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
26423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
26433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
26443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XError() ignores BadWindow errors for XQueryTree and XGetWindowAttributes,
26453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  and ignores BadDrawable errors for XGetGeometry, and ignores BadValue errors
2646bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristy%  for XQueryColor.  It returns MagickFalse in those cases.  Otherwise it
2647bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristy%  returns True.
26483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
26493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XError function is:
26503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2651bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristy%      int XError(display,error)
26523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
26533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
26543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
26553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a pointer to the Display structure;  returned from
26563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
26573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
26583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o error: Specifies the error event.
26593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
26603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
26613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
26623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__cplusplus) || defined(c_plusplus)
26633ed852eea50f9d4cd633efb8c2b054b8e33c253cristyextern "C" {
26643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
26653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
26663ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport int XError(Display *display,XErrorEvent *error)
26673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
26683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
26693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
26703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(error != (XErrorEvent *) NULL);
26713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  xerror_alert=MagickTrue;
26723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  switch (error->request_code)
26733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
26743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case X_GetGeometry:
26753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
26763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((int) error->error_code == BadDrawable)
26773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        return(MagickFalse);
26783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
26793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
26803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case X_GetWindowAttributes:
26813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case X_QueryTree:
26823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
26833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((int) error->error_code == BadWindow)
26843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        return(MagickFalse);
26853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
26863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
26873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case X_QueryColors:
26883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
26893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((int) error->error_code == BadValue)
26903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        return(MagickFalse);
26913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
26923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
26933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
26943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickTrue);
26953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
26963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
26973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__cplusplus) || defined(c_plusplus)
26983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
26993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
27003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
27013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
27023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
27043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
27053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
27063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X F r e e R e s o u r c e s                                               %
27073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
27083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
27093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
27103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XFreeResources() frees X11 resources.
27133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XFreeResources method is:
27153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XFreeResources(Display *display,XVisualInfo *visual_info,
27173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
27183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XResourceInfo *resource_info,XWindowInfo *window_info)
27193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        resource_info,window_info)
27203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
27223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
27243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
27253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
27273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      returned from XGetVisualInfo.
27283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o map_info: If map_type is specified, this structure is initialized
27303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      with info from the Standard Colormap.
27313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o pixel: Specifies a pointer to a XPixelInfo structure.
27333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o font_info: Specifies a pointer to a XFontStruct structure.
27353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
27373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window_info: Specifies a pointer to a X11 XWindowInfo structure.
27393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
27403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
2741bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XFreeResources(Display *display,XVisualInfo *visual_info,
27423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
27433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XResourceInfo *resource_info,XWindowInfo *window_info)
27443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
27453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
27463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
27473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
27483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info != (XWindowInfo *) NULL)
27493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
27503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
27513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Free X image.
27523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
27533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window_info->ximage != (XImage *) NULL)
27543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XDestroyImage(window_info->ximage);
27553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window_info->id != (Window) NULL)
27563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
27573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
27583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Free destroy window and free cursors.
27593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
27603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (window_info->id != XRootWindow(display,visual_info->screen))
27613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) XDestroyWindow(display,window_info->id);
27623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (window_info->annotate_context != (GC) NULL)
27633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) XFreeGC(display,window_info->annotate_context);
27643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (window_info->highlight_context != (GC) NULL)
27653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) XFreeGC(display,window_info->highlight_context);
27663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (window_info->widget_context != (GC) NULL)
27673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) XFreeGC(display,window_info->widget_context);
27683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (window_info->cursor != (Cursor) NULL)
27693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) XFreeCursor(display,window_info->cursor);
27703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window_info->cursor=(Cursor) NULL;
27713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (window_info->busy_cursor != (Cursor) NULL)
27723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) XFreeCursor(display,window_info->busy_cursor);
27733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window_info->busy_cursor=(Cursor) NULL;
27743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
27753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
27763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
27773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Free font.
27783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
27793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (font_info != (XFontStruct *) NULL)
2780aafc19213cef0b96cd237edb693a33fd1a2466eacristy    {
2781aafc19213cef0b96cd237edb693a33fd1a2466eacristy      (void) XFreeFont(display,font_info);
2782aafc19213cef0b96cd237edb693a33fd1a2466eacristy      font_info=(XFontStruct *) NULL;
2783aafc19213cef0b96cd237edb693a33fd1a2466eacristy    }
27843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (map_info != (XStandardColormap *) NULL)
27853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
27863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
27873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Free X Standard Colormap.
27883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
27893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (resource_info->map_type == (char *) NULL)
27903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
27913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFree((void *) map_info);
27923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
27933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
27943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Free X visual info.
27953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
27963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (visual_info != (XVisualInfo *) NULL)
27973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XFree((void *) visual_info);
27983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->close_server != MagickFalse)
27993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XCloseDisplay(display);
28003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
28013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
28023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
28033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
28053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
28063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
28073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X F r e e S t a n d a r d C o l o r m a p                                 %
28083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
28093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
28103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
28113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XFreeStandardColormap() frees an X11 colormap.
28143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XFreeStandardColormap method is:
28163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XFreeStandardColormap(Display *display,
28183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const XVisualInfo *visual_info,XStandardColormap *map_info,
28193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XPixelInfo *pixel)
28203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
28223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
28243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
28253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
28273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      returned from XGetVisualInfo.
28283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o map_info: If map_type is specified, this structure is initialized
28303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      with info from the Standard Colormap.
28313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o pixel: Specifies a pointer to a XPixelInfo structure.
28333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
2835bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XFreeStandardColormap(Display *display,
28363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const XVisualInfo *visual_info,XStandardColormap *map_info,XPixelInfo *pixel)
28373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
28383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
28393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Free colormap.
28403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
28413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
28423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
28433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(visual_info != (XVisualInfo *) NULL);
28443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(map_info != (XStandardColormap *) NULL);
28453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFlush(display);
28463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (map_info->colormap != (Colormap) NULL)
28473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
28483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
28493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreeColormap(display,map_info->colormap);
28503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
28513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (pixel != (XPixelInfo *) NULL)
28523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((visual_info->klass != TrueColor) &&
28533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (visual_info->klass != DirectColor))
28543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) XFreeColors(display,map_info->colormap,pixel->pixels,
28553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (int) pixel->colors,0);
28563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
28573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  map_info->colormap=(Colormap) NULL;
28583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (pixel != (XPixelInfo *) NULL)
28593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
2860f2faecf9facdbbb14fcba373365f9f691a9658e0cristy      if (pixel->pixels != (unsigned long *) NULL)
2861f2faecf9facdbbb14fcba373365f9f691a9658e0cristy        pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
2862f2faecf9facdbbb14fcba373365f9f691a9658e0cristy      pixel->pixels=(unsigned long *) NULL;
28633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
28643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
28653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
28663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
28673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
28693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
28703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
28713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t A n n o t a t e I n f o                                           %
28723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
28733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
28743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
28753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetAnnotateInfo() initializes the AnnotateInfo structure.
28783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetAnnotateInfo method is:
28803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
28823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
28843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
28863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
28873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
2888bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XGetAnnotateInfo(XAnnotateInfo *annotate_info)
28893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
28903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
28913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize annotate structure.
28923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
28933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
28943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(annotate_info != (XAnnotateInfo *) NULL);
28953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->x=0;
28963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->y=0;
28973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->width=0;
28983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->height=0;
28993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->stencil=ForegroundStencil;
29003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->degrees=0.0;
29013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->font_info=(XFontStruct *) NULL;
29023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->text=(char *) NULL;
29033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  *annotate_info->geometry='\0';
29043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->previous=(XAnnotateInfo *) NULL;
29053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  annotate_info->next=(XAnnotateInfo *) NULL;
29063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSupportsLocale();
29073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSetLocaleModifiers("");
29083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
29093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
29103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
29113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t M a p I n f o                                                     %
29163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetMapInfo() initializes the XStandardColormap structure.
29223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XStandardColormap method is:
29243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XGetMapInfo(const XVisualInfo *visual_info,const Colormap colormap,
29263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XStandardColormap *map_info)
29273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
29293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o colormap: Specifies the ID of the X server colormap.
29313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
29333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      returned from XGetVisualInfo.
29343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o map_info: Specifies a pointer to a X11 XStandardColormap structure.
29363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
2938bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XGetMapInfo(const XVisualInfo *visual_info,
29393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const Colormap colormap,XStandardColormap *map_info)
29403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
29413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
29423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize map info.
29433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
29443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
29453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(visual_info != (XVisualInfo *) NULL);
29463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(map_info != (XStandardColormap *) NULL);
29473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  map_info->colormap=colormap;
29483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  map_info->red_max=visual_info->red_mask;
2949bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  map_info->red_mult=(size_t) (map_info->red_max != 0 ? 1 : 0);
29503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (map_info->red_max != 0)
29513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    while ((map_info->red_max & 0x01) == 0)
29523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
29533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      map_info->red_max>>=1;
29543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      map_info->red_mult<<=1;
29553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
29563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  map_info->green_max=visual_info->green_mask;
2957bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  map_info->green_mult=(size_t) (map_info->green_max != 0 ? 1 : 0);
29583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (map_info->green_max != 0)
29593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    while ((map_info->green_max & 0x01) == 0)
29603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
29613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      map_info->green_max>>=1;
29623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      map_info->green_mult<<=1;
29633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
29643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  map_info->blue_max=visual_info->blue_mask;
2965bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  map_info->blue_mult=(size_t) (map_info->blue_max != 0 ? 1 : 0);
29663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (map_info->blue_max != 0)
29673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    while ((map_info->blue_max & 0x01) == 0)
29683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
29693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      map_info->blue_max>>=1;
29703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      map_info->blue_mult<<=1;
29713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
29723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  map_info->base_pixel=0;
29733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
29743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
29753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
29763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t P i x e l I n f o                                                 %
29813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
29843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2986101ab708b0574518ac5715da4d3915400e9df79acristy%  XGetPixelInfo() initializes the PixelInfo structure.
29873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29884c08aed51c5899665ade97263692328eea4af106cristy%  The format of the XGetPixelInfo method is:
29893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29904c08aed51c5899665ade97263692328eea4af106cristy%      void XGetPixelInfo(Display *display,const XVisualInfo *visual_info,
29913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const XStandardColormap *map_info,const XResourceInfo *resource_info,
29923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        Image *image,XPixelInfo *pixel)
29933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        pixel)
29943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
29963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
29973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
29983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
29993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
30003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
30013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      returned from XGetVisualInfo.
30023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
30033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o map_info: If map_type is specified, this structure is initialized
30043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      with info from the Standard Colormap.
30053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
30063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
30073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
30083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
30093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
30103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o pixel: Specifies a pointer to a XPixelInfo structure.
30113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
30123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
3013bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XGetPixelInfo(Display *display,
30143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const XVisualInfo *visual_info,const XStandardColormap *map_info,
30153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const XResourceInfo *resource_info,Image *image,XPixelInfo *pixel)
30163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
30173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static const char
30183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *PenColors[MaxNumberPens]=
30193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
30203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#000000000000",  /* black */
30213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#00000000ffff",  /* blue */
30223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#0000ffffffff",  /* cyan */
30233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#0000ffff0000",  /* green */
30243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#bdbdbdbdbdbd",  /* gray */
30253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#ffff00000000",  /* red */
30263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#ffff0000ffff",  /* magenta */
30273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#ffffffff0000",  /* yellow */
30283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#ffffffffffff",  /* white */
30293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#bdbdbdbdbdbd",  /* gray */
30303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      "#bdbdbdbdbdbd"   /* gray */
30313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    };
30323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
30333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Colormap
30343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    colormap;
30353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
3036bcdf567d7dc3c69162ca349e41d43741faed2043cristy  extern const char
3037bcdf567d7dc3c69162ca349e41d43741faed2043cristy    BorderColor[],
3038bcdf567d7dc3c69162ca349e41d43741faed2043cristy    ForegroundColor[];
3039bcdf567d7dc3c69162ca349e41d43741faed2043cristy
3040bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  register ssize_t
30413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
30423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
30433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
30443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
30453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
30463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
30473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    packets;
30483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
30493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
30503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize pixel info.
30513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
30523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
30533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
30543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(visual_info != (XVisualInfo *) NULL);
30553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(map_info != (XStandardColormap *) NULL);
30563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
30573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(pixel != (XPixelInfo *) NULL);
30583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->colors=0;
30593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image != (Image *) NULL)
30603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (image->storage_class == PseudoClass)
3061c57f694b2d04975a0e501613e34368c464708c19cristy      pixel->colors=(ssize_t) image->colors;
30623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  packets=(unsigned int)
30633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    MagickMax((int) pixel->colors,visual_info->colormap_size)+MaxNumberPens;
3064f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  if (pixel->pixels != (unsigned long *) NULL)
3065f2faecf9facdbbb14fcba373365f9f691a9658e0cristy    pixel->pixels=(unsigned long *) RelinquishMagickMemory(pixel->pixels);
3066f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  pixel->pixels=(unsigned long *) AcquireQuantumMemory(packets,
3067c330609437280fe98829f3f00f43eb711084f754cristy    sizeof(*pixel->pixels));
3068f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  if (pixel->pixels == (unsigned long *) NULL)
30693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToGetPixelInfo",
30703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image->filename);
30713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
30723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set foreground color.
30733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
30743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  colormap=map_info->colormap;
30753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseColor(display,colormap,(char *) ForegroundColor,
30763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &pixel->foreground_color);
30773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XParseColor(display,colormap,resource_info->foreground_color,
30783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &pixel->foreground_color);
30793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
3080c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy    ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
30813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      resource_info->foreground_color);
30823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->foreground_color.pixel=
30833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XStandardPixel(map_info,&pixel->foreground_color);
30843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->foreground_color.flags=(char) (DoRed | DoGreen | DoBlue);
30853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
30863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set background color.
30873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
30883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseColor(display,colormap,"#d6d6d6d6d6d6",&pixel->background_color);
30893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XParseColor(display,colormap,resource_info->background_color,
30903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &pixel->background_color);
30913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
3092c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy    ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
30933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      resource_info->background_color);
30943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->background_color.pixel=
30953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XStandardPixel(map_info,&pixel->background_color);
30963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->background_color.flags=(char) (DoRed | DoGreen | DoBlue);
30973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
30983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set border color.
30993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
31003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseColor(display,colormap,(char *) BorderColor,
31013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &pixel->border_color);
31023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XParseColor(display,colormap,resource_info->border_color,
31033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &pixel->border_color);
31043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
3105c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy    ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
31063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      resource_info->border_color);
31073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->border_color.pixel=XStandardPixel(map_info,&pixel->border_color);
31083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->border_color.flags=(char) (DoRed | DoGreen | DoBlue);
31093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
31103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set matte color.
31113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
3112b797b2c96f796f4920c9ee807dc5f47e6f160418dirk  pixel->alpha_color=pixel->background_color;
3113b797b2c96f796f4920c9ee807dc5f47e6f160418dirk  if (resource_info->alpha_color != (char *) NULL)
31143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
31153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
31163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Matte color is specified as a X resource or command line argument.
31173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
3118b797b2c96f796f4920c9ee807dc5f47e6f160418dirk      status=XParseColor(display,colormap,resource_info->alpha_color,
3119b797b2c96f796f4920c9ee807dc5f47e6f160418dirk        &pixel->alpha_color);
31203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status == False)
3121c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy        ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
3122b797b2c96f796f4920c9ee807dc5f47e6f160418dirk          resource_info->alpha_color);
3123b797b2c96f796f4920c9ee807dc5f47e6f160418dirk      pixel->alpha_color.pixel=XStandardPixel(map_info,&pixel->alpha_color);
3124b797b2c96f796f4920c9ee807dc5f47e6f160418dirk      pixel->alpha_color.flags=(char) (DoRed | DoGreen | DoBlue);
31253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
31263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
31273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set highlight color.
31283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
31295467fcf6dfee9d372efee47bb4eb1fb8f3e118b4cristy  pixel->highlight_color.red=(unsigned short) (((double)
3130b797b2c96f796f4920c9ee807dc5f47e6f160418dirk    pixel->alpha_color.red*ScaleQuantumToShort(HighlightModulate))/65535L+
31313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
31325467fcf6dfee9d372efee47bb4eb1fb8f3e118b4cristy  pixel->highlight_color.green=(unsigned short) (((double)
3133b797b2c96f796f4920c9ee807dc5f47e6f160418dirk    pixel->alpha_color.green*ScaleQuantumToShort(HighlightModulate))/65535L+
31343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
31355467fcf6dfee9d372efee47bb4eb1fb8f3e118b4cristy  pixel->highlight_color.blue=(unsigned short) (((double)
3136b797b2c96f796f4920c9ee807dc5f47e6f160418dirk    pixel->alpha_color.blue*ScaleQuantumToShort(HighlightModulate))/65535L+
31373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (ScaleQuantumToShort((Quantum) (QuantumRange-HighlightModulate))));
31385467fcf6dfee9d372efee47bb4eb1fb8f3e118b4cristy  pixel->highlight_color.pixel=XStandardPixel(map_info,&pixel->highlight_color);
31393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->highlight_color.flags=(char) (DoRed | DoGreen | DoBlue);
31403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
31413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set shadow color.
31423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
3143a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy  pixel->shadow_color.red=(unsigned short) (((double)
3144b797b2c96f796f4920c9ee807dc5f47e6f160418dirk    pixel->alpha_color.red*ScaleQuantumToShort(ShadowModulate))/65535L);
3145a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy  pixel->shadow_color.green=(unsigned short) (((double)
3146b797b2c96f796f4920c9ee807dc5f47e6f160418dirk    pixel->alpha_color.green*ScaleQuantumToShort(ShadowModulate))/65535L);
3147a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy  pixel->shadow_color.blue=(unsigned short) (((double)
3148b797b2c96f796f4920c9ee807dc5f47e6f160418dirk    pixel->alpha_color.blue*ScaleQuantumToShort(ShadowModulate))/65535L);
31493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->shadow_color.pixel=XStandardPixel(map_info,&pixel->shadow_color);
31503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->shadow_color.flags=(char) (DoRed | DoGreen | DoBlue);
31513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
31523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set depth color.
31533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
3154a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy  pixel->depth_color.red=(unsigned short) (((double)
3155b797b2c96f796f4920c9ee807dc5f47e6f160418dirk    pixel->alpha_color.red*ScaleQuantumToShort(DepthModulate))/65535L);
3156a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy  pixel->depth_color.green=(unsigned short) (((double)
3157b797b2c96f796f4920c9ee807dc5f47e6f160418dirk    pixel->alpha_color.green*ScaleQuantumToShort(DepthModulate))/65535L);
3158a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy  pixel->depth_color.blue=(unsigned short) (((double)
3159b797b2c96f796f4920c9ee807dc5f47e6f160418dirk    pixel->alpha_color.blue*ScaleQuantumToShort(DepthModulate))/65535L);
31603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->depth_color.pixel=XStandardPixel(map_info,&pixel->depth_color);
31613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->depth_color.flags=(char) (DoRed | DoGreen | DoBlue);
31623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
31633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set trough color.
31643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
3165a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy  pixel->trough_color.red=(unsigned short) (((double)
3166b797b2c96f796f4920c9ee807dc5f47e6f160418dirk    pixel->alpha_color.red*ScaleQuantumToShort(TroughModulate))/65535L);
3167a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy  pixel->trough_color.green=(unsigned short) (((double)
3168b797b2c96f796f4920c9ee807dc5f47e6f160418dirk    pixel->alpha_color.green*ScaleQuantumToShort(TroughModulate))/65535L);
3169a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy  pixel->trough_color.blue=(unsigned short) (((double)
3170b797b2c96f796f4920c9ee807dc5f47e6f160418dirk    pixel->alpha_color.blue*ScaleQuantumToShort(TroughModulate))/65535L);
31713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->trough_color.pixel=XStandardPixel(map_info,&pixel->trough_color);
31723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->trough_color.flags=(char) (DoRed | DoGreen | DoBlue);
31733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
31743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set pen color.
31753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
31763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; i < MaxNumberPens; i++)
31773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
31783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XParseColor(display,colormap,(char *) PenColors[i],
31793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      &pixel->pen_colors[i]);
31803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status=XParseColor(display,colormap,resource_info->pen_colors[i],
31813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      &pixel->pen_colors[i]);
31823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (status == False)
3183c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy      ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",
31843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        resource_info->pen_colors[i]);
31853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel->pen_colors[i].pixel=XStandardPixel(map_info,&pixel->pen_colors[i]);
31863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel->pen_colors[i].flags=(char) (DoRed | DoGreen | DoBlue);
31873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
31883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->box_color=pixel->background_color;
31893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->pen_color=pixel->foreground_color;
31903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->box_index=0;
31913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixel->pen_index=1;
31923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image != (Image *) NULL)
31933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
31943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((resource_info->gamma_correct != MagickFalse) &&
31953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (image->gamma != 0.0))
31963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
31973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          GeometryInfo
31983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            geometry_info;
31993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
32003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          MagickStatusType
32013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            flags;
32023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
32033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
32043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Initialize map relative to display and image gamma.
32053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
32063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          flags=ParseGeometry(resource_info->display_gamma,&geometry_info);
32073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          red_gamma=geometry_info.rho;
32083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          green_gamma=geometry_info.sigma;
32093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((flags & SigmaValue) == 0)
32103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            green_gamma=red_gamma;
32113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          blue_gamma=geometry_info.xi;
32123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((flags & XiValue) == 0)
32133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            blue_gamma=red_gamma;
32143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          red_gamma*=image->gamma;
32153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          green_gamma*=image->gamma;
32163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          blue_gamma*=image->gamma;
32173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
32183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (image->storage_class == PseudoClass)
32193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
32203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
32213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Initialize pixel array for images of type PseudoClass.
32223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
3223bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy          for (i=0; i < (ssize_t) image->colors; i++)
32244c08aed51c5899665ade97263692328eea4af106cristy            pixel->pixels[i]=XGammaPacket(map_info,image->colormap+i);
32253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (i=0; i < MaxNumberPens; i++)
32263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
32273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          pixel->colors+=MaxNumberPens;
32283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
32293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
32303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
32313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
32323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
32333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
32353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
32363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
32373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t R e s o u r c e C l a s s                                         %
32383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
32393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
32403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
32413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
32433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetResourceClass() queries the X server for the specified resource name or
32443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  class.  If the resource name or class is not defined in the database, the
32453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  supplied default value is returned.
32463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
32473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetResourceClass method is:
32483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
32493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      char *XGetResourceClass(XrmDatabase database,const char *client_name,
32503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *keyword,char *resource_default)
32513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
32523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
32533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
32543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o database: Specifies a resource database; returned from
32553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XrmGetStringDatabase.
32563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
32573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o client_name:  Specifies the application name used to retrieve resource
32583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      info from the X server database.
32593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
32603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o keyword: Specifies the keyword of the value being retrieved.
32613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
32623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_default: Specifies the default value to return if the query
32633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      fails to find the specified keyword/class.
32643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
32653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
32663ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport char *XGetResourceClass(XrmDatabase database,
32673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *client_name,const char *keyword,char *resource_default)
32683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
32693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
3270151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    resource_class[MagickPathExtent],
3271151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    resource_name[MagickPathExtent];
32723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
32733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static char
32743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *resource_type;
32753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
32763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
32773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
32783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
32793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmValue
32803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_value;
32813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
32823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (database == (XrmDatabase) NULL)
32833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(resource_default);
32843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  *resource_name='\0';
32853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  *resource_class='\0';
32863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (keyword != (char *) NULL)
32873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
32883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      int
32893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        c,
32903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        k;
32913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
32923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
32933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Initialize resource keyword and class.
32943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
3295151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy      (void) FormatLocaleString(resource_name,MagickPathExtent,"%s.%s",
32963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        client_name,keyword);
32973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      c=(int) (*client_name);
32983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((c >= XK_a) && (c <= XK_z))
32993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        c-=(XK_a-XK_A);
33003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
33013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if ((c >= XK_agrave) && (c <= XK_odiaeresis))
33023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          c-=(XK_agrave-XK_Agrave);
33033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        else
33043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((c >= XK_oslash) && (c <= XK_thorn))
33053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            c-=(XK_oslash-XK_Ooblique);
33063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      k=(int) (*keyword);
33073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((k >= XK_a) && (k <= XK_z))
33083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        k-=(XK_a-XK_A);
33093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
33103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if ((k >= XK_agrave) && (k <= XK_odiaeresis))
33113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          k-=(XK_agrave-XK_Agrave);
33123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        else
33133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((k >= XK_oslash) && (k <= XK_thorn))
33143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            k-=(XK_oslash-XK_Ooblique);
3315151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy      (void) FormatLocaleString(resource_class,MagickPathExtent,"%c%s.%c%s",c,
33163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        client_name+1,k,keyword+1);
33173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
33183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XrmGetResource(database,resource_name,resource_class,&resource_type,
33193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &resource_value);
33203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
33213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(resource_default);
33223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(resource_value.addr);
33233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
33243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
33253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
33263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
33283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
33293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
33303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t R e s o u r c e D a t a b a s e                                   %
33313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
33323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
33333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
33343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
33363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetResourceDatabase() creates a new resource database and initializes it.
33373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
33383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetResourceDatabase method is:
33393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
33403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XrmDatabase XGetResourceDatabase(Display *display,
33413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *client_name)
33423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
33433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
33443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
33453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o database: XGetResourceDatabase() returns the database after it is
33463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      initialized.
33473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
33483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
33493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
33503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
33513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o client_name:  Specifies the application name used to retrieve resource
33523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      info from the X server database.
33533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
33543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
33553ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport XrmDatabase XGetResourceDatabase(Display *display,
33563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *client_name)
33573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
33583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
3359151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    filename[MagickPathExtent];
33603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
33613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
33623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    c;
33633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
33643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register const char
33653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p;
33663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
33673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmDatabase
33683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_database,
33693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    server_database;
33703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
33713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (display == (Display *) NULL)
33723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return((XrmDatabase) NULL);
33733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(client_name != (char *) NULL);
33743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
33753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize resource database.
33763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
33773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmInitialize();
33783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XGetDefault(display,(char *) client_name,"dummy");
33793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_database=XrmGetDatabase(display);
33803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
33813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Combine application database.
33823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
33833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (client_name != (char *) NULL)
33843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
33853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
33863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Get basename of client.
33873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
33883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      p=client_name+(strlen(client_name)-1);
33893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      while ((p > client_name) && (*p != '/'))
33903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        p--;
33913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (*p == '/')
33923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        client_name=p+1;
33933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
33943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  c=(int) (*client_name);
33953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((c >= XK_a) && (c <= XK_z))
33963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    c-=(XK_a-XK_A);
33973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
33983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if ((c >= XK_agrave) && (c <= XK_odiaeresis))
33993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      c-=(XK_agrave-XK_Agrave);
34003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    else
34013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((c >= XK_oslash) && (c <= XK_thorn))
34023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        c-=(XK_oslash-XK_Ooblique);
34033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(X11_APPLICATION_PATH)
3404151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) FormatLocaleString(filename,MagickPathExtent,"%s%c%s",
34053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    X11_APPLICATION_PATH,c,client_name+1);
34063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
34073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
34083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (XResourceManagerString(display) != (char *) NULL)
34093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
34103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
34113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Combine server database.
34123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
34133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      server_database=XrmGetStringDatabase(XResourceManagerString(display));
34143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XrmCombineDatabase(server_database,&resource_database,MagickFalse);
34153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
34163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
34173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Merge user preferences database.
34183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
34193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(X11_PREFERENCES_PATH)
3420151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) FormatLocaleString(filename,MagickPathExtent,"%s%src",
34213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    X11_PREFERENCES_PATH,client_name);
34223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ExpandFilename(filename);
34233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XrmCombineFileDatabase(filename,&resource_database,MagickFalse);
34243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
34253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(resource_database);
34263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
34273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
34283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
34293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
34313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
34323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
34333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t R e s o u r c e I n f o                                           %
34343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
34353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
34363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
34373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
34393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetResourceInfo(image_info,) initializes the ResourceInfo structure.
34403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
34413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetResourceInfo method is:
34423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
34433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XGetResourceInfo(const ImageInfo *image_info,XrmDatabase database,
34443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *client_name,XResourceInfo *resource_info)
34453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
34463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
34473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
34483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image_info: the image info.
34493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
34503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o database: Specifies a resource database; returned from
34513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XrmGetStringDatabase.
34523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
34533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o client_name:  Specifies the application name used to retrieve
34543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      resource info from the X server database.
34553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
34563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
34573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
34583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
34593ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport void XGetResourceInfo(const ImageInfo *image_info,
34603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmDatabase database,const char *client_name,XResourceInfo *resource_info)
34613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
34623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
346300976d8abcff7a3bc7b986b8105dde8d091dee61cristy    *directory,
34643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *resource_value;
34653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
3466bcdf567d7dc3c69162ca349e41d43741faed2043cristy  extern const char
3467bcdf567d7dc3c69162ca349e41d43741faed2043cristy    BorderColor[],
3468bcdf567d7dc3c69162ca349e41d43741faed2043cristy    ForegroundColor[];
3469bcdf567d7dc3c69162ca349e41d43741faed2043cristy
34703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
34713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize resource info fields.
34723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
34733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
34743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
34753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ResetMagickMemory(resource_info,0,sizeof(*resource_info));
34763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->resource_database=database;
34773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->image_info=(ImageInfo *) image_info;
34783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) SetImageInfoProgressMonitor(resource_info->image_info,
34793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XMagickProgressMonitor,(void *) NULL);
34803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->quantize_info=CloneQuantizeInfo((QuantizeInfo *) NULL);
34813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->close_server=MagickTrue;
34823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->client_name=AcquireString(client_name);
3483b797b2c96f796f4920c9ee807dc5f47e6f160418dirk  resource_info->alpha_color=XGetResourceInstance(database,client_name,
3484b797b2c96f796f4920c9ee807dc5f47e6f160418dirk    "alpha-color",(char *) NULL);
34853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"backdrop",
34863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "False");
34876f2013165d72f7d8ef5f66bb9453126d88113809anthony  resource_info->backdrop=IsStringTrue(resource_value);
34883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->background_color=XGetResourceInstance(database,client_name,
34893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "background",(char *) "#d6d6d6d6d6d6");
34903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->border_color=XGetResourceInstance(database,client_name,
34913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "borderColor",BorderColor);
34923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"borderWidth",
34933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "2");
349400976d8abcff7a3bc7b986b8105dde8d091dee61cristy  resource_info->border_width=(unsigned int) StringToUnsignedLong(
349500976d8abcff7a3bc7b986b8105dde8d091dee61cristy    resource_value);
34963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"colormap",
34973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "shared");
34983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->colormap=UndefinedColormap;
34993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (LocaleCompare("private",resource_value) == 0)
35003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_info->colormap=PrivateColormap;
35013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (LocaleCompare("shared",resource_value) == 0)
35023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_info->colormap=SharedColormap;
35033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->colormap == UndefinedColormap)
3504c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy    ThrowXWindowException(OptionError,"UnrecognizedColormapType",
35053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      resource_value);
35063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,
35073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "colorRecovery",(char *) "False");
35086f2013165d72f7d8ef5f66bb9453126d88113809anthony  resource_info->color_recovery=IsStringTrue(resource_value);
35093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"confirmExit",
35103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "False");
35116f2013165d72f7d8ef5f66bb9453126d88113809anthony  resource_info->confirm_exit=IsStringTrue(resource_value);
35123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"confirmEdit",
35133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "False");
35146f2013165d72f7d8ef5f66bb9453126d88113809anthony  resource_info->confirm_edit=IsStringTrue(resource_value);
3515ba0c32599a8e592fffab86dd9b8ee367ca573c22cristy  resource_value=XGetResourceClass(database,client_name,"delay",(char *) "1");
3516e27293e706ca05b6b121e9512a83b16f7ad887f2cristy  resource_info->delay=(unsigned int) StringToUnsignedLong(resource_value);
35173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->display_gamma=XGetResourceClass(database,client_name,
35183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "displayGamma",(char *) "2.2");
35193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"displayWarnings",
35203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "True");
35216f2013165d72f7d8ef5f66bb9453126d88113809anthony  resource_info->display_warnings=IsStringTrue(resource_value);
35223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font=XGetResourceClass(database,client_name,"font",
35233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) NULL);
35243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font=XGetResourceClass(database,client_name,"fontList",
35253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_info->font);
35263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[0]=XGetResourceClass(database,client_name,"font1",
35273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "fixed");
35283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[1]=XGetResourceClass(database,client_name,"font2",
35293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "variable");
35303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[2]=XGetResourceClass(database,client_name,"font3",
35313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "5x8");
35323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[3]=XGetResourceClass(database,client_name,"font4",
35333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "6x10");
35343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[4]=XGetResourceClass(database,client_name,"font5",
35353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "7x13bold");
35363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[5]=XGetResourceClass(database,client_name,"font6",
35373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "8x13bold");
35383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[6]=XGetResourceClass(database,client_name,"font7",
35393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "9x15bold");
35403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[7]=XGetResourceClass(database,client_name,"font8",
35413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "10x20");
35423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[8]=XGetResourceClass(database,client_name,"font9",
35433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "12x24");
35443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[9]=XGetResourceClass(database,client_name,"font0",
35453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "fixed");
35463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->font_name[10]=XGetResourceClass(database,client_name,"font0",
35473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "fixed");
35483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->foreground_color=XGetResourceInstance(database,client_name,
35493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "foreground",ForegroundColor);
35503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"gammaCorrect",
35518bc259be59a7cde483c27474125272a7d65c5744cristy    (char *) "False");
35526f2013165d72f7d8ef5f66bb9453126d88113809anthony  resource_info->gamma_correct=IsStringTrue(resource_value);
35533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->image_geometry=ConstantString(XGetResourceClass(database,
35543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    client_name,"geometry",(char *) NULL));
35553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"gravity",
35563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "Center");
3557042ee78fa9004bf1ac6a95f09d9d1faca631dda1cristy  resource_info->gravity=(GravityType) ParseCommandOption(MagickGravityOptions,
35583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    MagickFalse,resource_value);
3559151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  directory=getcwd(resource_info->home_directory,MagickPathExtent);
356000976d8abcff7a3bc7b986b8105dde8d091dee61cristy  (void) directory;
35613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->icon_geometry=XGetResourceClass(database,client_name,
35623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "iconGeometry",(char *) NULL);
35633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"iconic",
35643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "False");
35656f2013165d72f7d8ef5f66bb9453126d88113809anthony  resource_info->iconic=IsStringTrue(resource_value);
35663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"immutable",
35673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    LocaleCompare(client_name,"PerlMagick") == 0 ? (char *) "True" :
35683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "False");
35696f2013165d72f7d8ef5f66bb9453126d88113809anthony  resource_info->immutable=IsStringTrue(resource_value);
35703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"magnify",
35713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "3");
3572e27293e706ca05b6b121e9512a83b16f7ad887f2cristy  resource_info->magnify=(unsigned int) StringToUnsignedLong(resource_value);
35733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->map_type=XGetResourceClass(database,client_name,"map",
35743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) NULL);
35753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->name=ConstantString(XGetResourceClass(database,client_name,
35763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "name",(char *) NULL));
35773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[0]=XGetResourceClass(database,client_name,"pen1",
35783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "black");
35793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[1]=XGetResourceClass(database,client_name,"pen2",
35803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "blue");
35813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[2]=XGetResourceClass(database,client_name,"pen3",
35823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "cyan");
35833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[3]=XGetResourceClass(database,client_name,"pen4",
35843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "green");
35853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[4]=XGetResourceClass(database,client_name,"pen5",
35863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "gray");
35873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[5]=XGetResourceClass(database,client_name,"pen6",
35883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "red");
35893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[6]=XGetResourceClass(database,client_name,"pen7",
35903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "magenta");
35913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[7]=XGetResourceClass(database,client_name,"pen8",
35923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "yellow");
35933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[8]=XGetResourceClass(database,client_name,"pen9",
35943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "white");
35953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[9]=XGetResourceClass(database,client_name,"pen0",
35963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "gray");
35973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->pen_colors[10]=XGetResourceClass(database,client_name,"pen0",
35983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "gray");
35993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"pause",(char *) "0");
3600e27293e706ca05b6b121e9512a83b16f7ad887f2cristy  resource_info->pause=(unsigned int) StringToUnsignedLong(resource_value);
36013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"quantum",(char *) "1");
3602f2f2727f17ecbb23d902f70bb98f81faabc92dbdcristy  resource_info->quantum=StringToLong(resource_value);
36033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->text_font=XGetResourceClass(database,client_name,(char *)
36043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "font",(char *) "fixed");
36053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->text_font=XGetResourceClass(database,client_name,
36063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "textFontList",resource_info->text_font);
36073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->title=XGetResourceClass(database,client_name,"title",
36083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) NULL);
36093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"undoCache",
361092befbd6a0f0f642bd44c58fdd32e3e073f6f141cristy    (char *) "256");
3611e27293e706ca05b6b121e9512a83b16f7ad887f2cristy  resource_info->undo_cache=(unsigned int) StringToUnsignedLong(resource_value);
36123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"update",
36133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "False");
36146f2013165d72f7d8ef5f66bb9453126d88113809anthony  resource_info->update=IsStringTrue(resource_value);
36153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"usePixmap",
36163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "True");
36176f2013165d72f7d8ef5f66bb9453126d88113809anthony  resource_info->use_pixmap=IsStringTrue(resource_value);
36183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_value=XGetResourceClass(database,client_name,"sharedMemory",
36193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) "True");
36206f2013165d72f7d8ef5f66bb9453126d88113809anthony  resource_info->use_shared_memory=IsStringTrue(resource_value);
36213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->visual_type=XGetResourceClass(database,client_name,"visual",
36223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) NULL);
36233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->window_group=XGetResourceClass(database,client_name,
36243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "windowGroup",(char *) NULL);
36253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->window_id=XGetResourceClass(database,client_name,"window",
36263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (char *) NULL);
36273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  resource_info->write_filename=XGetResourceClass(database,client_name,
36283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    "writeFilename",(char *) NULL);
36293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
36303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
36313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
36323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
36343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
36353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
36363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t R e s o u r c e I n s t a n c e                                   %
36373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
36383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
36393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
36403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
36423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetResourceInstance() queries the X server for the specified resource name.
36433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  If the resource name is not defined in the database, the supplied default
36443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  value is returned.
36453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
36463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetResourceInstance method is:
36473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
36483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      char *XGetResourceInstance(XrmDatabase database,const char *client_name,
36493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *keyword,const char *resource_default)
36503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
36513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
36523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
36533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o database: Specifies a resource database; returned from
36543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XrmGetStringDatabase.
36553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
36563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o client_name:  Specifies the application name used to retrieve
36573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      resource info from the X server database.
36583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
36593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o keyword: Specifies the keyword of the value being retrieved.
36603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
36613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_default: Specifies the default value to return if the query
36623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      fails to find the specified keyword/class.
36633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
36643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
36653ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport char *XGetResourceInstance(XrmDatabase database,
36663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *client_name,const char *keyword,const char *resource_default)
36673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
36683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
36693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *resource_type,
3670151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    resource_name[MagickPathExtent];
36713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
36723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
36733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
36743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
36753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmValue
36763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_value;
36773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
36783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (database == (XrmDatabase) NULL)
36793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return((char *) resource_default);
36803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  *resource_name='\0';
36813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (keyword != (char *) NULL)
3682151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    (void) FormatLocaleString(resource_name,MagickPathExtent,"%s.%s",client_name,
36833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      keyword);
36843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XrmGetResource(database,resource_name,"ImageMagick",&resource_type,
36853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &resource_value);
36863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
36873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return((char *) resource_default);
36883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(resource_value.addr);
36893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
36903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
36913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
36923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
36933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
36943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
36953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
36963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t S c r e e n D e n s i t y                                         %
36973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
36983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
36993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
37003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetScreenDensity() returns the density of the X server screen in
37033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  dots-per-inch.
37043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetScreenDensity method is:
37063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      char *XGetScreenDensity(Display *display)
37083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
37103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o density: XGetScreenDensity() returns the density of the X screen in
37123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      dots-per-inch.
37133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
37153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
37163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
37183ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport char *XGetScreenDensity(Display *display)
37193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
37203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
3721151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    density[MagickPathExtent];
37223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
37233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  double
37243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x_density,
37253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y_density;
37263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
37273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
37283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set density as determined by screen size.
37293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
37303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x_density=((((double) DisplayWidth(display,XDefaultScreen(display)))*25.4)/
37313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ((double) DisplayWidthMM(display,XDefaultScreen(display))));
37323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y_density=((((double) DisplayHeight(display,XDefaultScreen(display)))*25.4)/
37333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ((double) DisplayHeightMM(display,XDefaultScreen(display))));
3734151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) FormatLocaleString(density,MagickPathExtent,"%gx%g",x_density,
37358cd5b3193212b4aebce08c4e7afbb66b09778029cristy    y_density);
37363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(GetPageGeometry(density));
37373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
37383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
37393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
37403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
37423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
37433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
37443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy+   X G e t S u b w i n d o w                                                 %
37453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
37463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
37473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
37483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
37493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetSubwindow() returns the subwindow of a window chosen the user with the
37513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  pointer and a button press.
37523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetSubwindow method is:
37543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      Window XGetSubwindow(Display *display,Window window,int x,int y)
37563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
37583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o subwindow: XGetSubwindow() returns NULL if no subwindow is found
37603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      otherwise the subwindow is returned.
37613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
37633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
37643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a Window.
37663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o x: the x coordinate of the pointer relative to the origin of the
37683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      window.
37693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o y: the y coordinate of the pointer relative to the origin of the
37713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      window.
37723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
37733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
37743ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Window XGetSubwindow(Display *display,Window window,int x,int y)
37753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
37763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
37773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x_offset,
37783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y_offset;
37793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
37803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
37813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
37823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
37833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
37843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    source_window,
37853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    target_window;
37863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
37873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
37883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  source_window=XRootWindow(display,XDefaultScreen(display));
37893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window == (Window) NULL)
37903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(source_window);
37913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  target_window=window;
37923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for ( ; ; )
37933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
37943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status=XTranslateCoordinates(display,source_window,window,x,y,
37953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      &x_offset,&y_offset,&target_window);
37963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (status != True)
37973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
37983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (target_window == (Window) NULL)
37993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
38003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    source_window=window;
38013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window=target_window;
38023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x=x_offset;
38033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y=y_offset;
38043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
38053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (target_window == (Window) NULL)
38063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    target_window=window;
38073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(target_window);
38083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
38093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
38103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
38113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
38133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
38143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
38153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t W i n d o w C o l o r                                             %
38163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
38173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
38183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
38193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
38213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetWindowColor() returns the color of a pixel interactively chosen from the
38223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  X server.
38233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
38243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetWindowColor method is:
38253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
38263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      MagickBooleanType XGetWindowColor(Display *display,XWindows *windows,
38276710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        char *name,ExceptionInfo *exception)
38283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
38293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
38303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
38313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
38323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
38333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
38343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o windows: Specifies a pointer to a XWindows structure.
38353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
38363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o name: the name of the color if found in the X Color Database is
38373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      returned in this character string.
38383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
38396710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    o exception: return any errors or warnings in this structure.
38406710d8414f0ed06e4eaf9346366be72e2b4719efcristy%
38413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
3842bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate MagickBooleanType XGetWindowColor(Display *display,
38436710d8414f0ed06e4eaf9346366be72e2b4719efcristy  XWindows *windows,char *name,ExceptionInfo *exception)
38443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
38453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
38463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x,
38473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y;
38483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
3849101ab708b0574518ac5715da4d3915400e9df79acristy  PixelInfo
38503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel;
38513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
38523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  RectangleInfo
38533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    crop_info;
38543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
38553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
38563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
38573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
38583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
38593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    child,
38603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    client_window,
38613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root_window,
38623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    target_window;
38633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
38643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XColor
38653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    color;
38663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
38673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XImage
38683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *ximage;
38693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
38703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XWindowAttributes
38713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window_attributes;
38723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
38733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
38743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Choose a pixel from the X server.
38753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
38763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
38773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(name != (char *) NULL);
38783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
38793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  *name='\0';
38803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  target_window=XSelectWindow(display,&crop_info);
38813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (target_window == (Window) NULL)
38823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
38833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  root_window=XRootWindow(display,XDefaultScreen(display));
38843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  client_window=target_window;
38853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (target_window != root_window)
38863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
38873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      unsigned int
38883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        d;
38893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
38903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
38913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Get client window.
38923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
38933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      status=XGetGeometry(display,target_window,&root_window,&x,&x,&d,&d,&d,&d);
38943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status != False)
38953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
38963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          client_window=XClientWindow(display,target_window);
38973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          target_window=client_window;
38983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
38993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
39003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
39013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Verify window is viewable.
39023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
39033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XGetWindowAttributes(display,target_window,&window_attributes);
39043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((status == False) || (window_attributes.map_state != IsViewable))
39053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
39063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
39073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Get window X image.
39083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
39093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XTranslateCoordinates(display,root_window,target_window,
39103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (int) crop_info.x,(int) crop_info.y,&x,&y,&child);
39113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ximage=XGetImage(display,target_window,x,y,1,1,AllPlanes,ZPixmap);
39123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (ximage == (XImage *) NULL)
39133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
39143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  color.pixel=XGetPixel(ximage,0,0);
39153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XDestroyImage(ximage);
39163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
39173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Match color against the color database.
39183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
39193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XQueryColor(display,window_attributes.colormap,&color);
3920e42f658533644aecb733785ffd91b286d6778deacristy  pixel.red=(double) ScaleShortToQuantum(color.red);
3921e42f658533644aecb733785ffd91b286d6778deacristy  pixel.green=(double) ScaleShortToQuantum(color.green);
3922e42f658533644aecb733785ffd91b286d6778deacristy  pixel.blue=(double) ScaleShortToQuantum(color.blue);
39234c08aed51c5899665ade97263692328eea4af106cristy  pixel.alpha=OpaqueAlpha;
39243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) QueryColorname(windows->image.image,&pixel,X11Compliance,name,
39256710d8414f0ed06e4eaf9346366be72e2b4719efcristy    exception);
39263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickTrue);
39273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
39283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
39293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
39303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
39323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
39333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
39343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy+   X G e t W i n d o w I m a g e                                             %
39353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
39363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
39373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
39383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
39403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetWindowImage() reads an image from the target X window and returns it.
39413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetWindowImage() optionally descends the window hierarchy and overlays the
39423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  target image with each child image in an optimized fashion.  Any child
39433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  window that have the same visual, colormap, and are contained by its parent
39443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  are exempted.
39453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
39463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetWindowImage method is:
39473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
39483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      Image *XGetWindowImage(Display *display,const Window window,
39496710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        const unsigned int borders,const unsigned int level,
39506710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        ExceptionInfo *exception)
39513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
39523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
39533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
39543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
39553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
39563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
39573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies the window to obtain the image from.
39583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
39593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o borders: Specifies whether borders pixels are to be saved with
39603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      the image.
39613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
39623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o level: Specifies an unsigned integer representing the level of
39633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      decent in the window hierarchy.  This value must be zero or one on
39643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      the initial call to XGetWindowImage.  A value of zero returns after
39653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      one call.  A value of one causes the function to descend the window
39663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      hierarchy and overlay the target image with each subwindow image.
39673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
39686710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    o exception: return any errors or warnings in this structure.
39696710d8414f0ed06e4eaf9346366be72e2b4719efcristy%
39703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
39713ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Image *XGetWindowImage(Display *display,const Window window,
39726710d8414f0ed06e4eaf9346366be72e2b4719efcristy  const unsigned int borders,const unsigned int level,ExceptionInfo *exception)
39733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
39743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  typedef struct _ColormapInfo
39753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
39763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Colormap
39773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      colormap;
39783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
39793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XColor
39803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      *colors;
39813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
39823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    struct _ColormapInfo
39833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      *next;
39843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  } ColormapInfo;
39853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
39863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  typedef struct _WindowInfo
39873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
39883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Window
39893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window,
39903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      parent;
39913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
39923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Visual
39933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      *visual;
39943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
39953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Colormap
39963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      colormap;
39973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
39983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XSegment
39993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      bounds;
40003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    RectangleInfo
40023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      crop_info;
40033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  } WindowInfo;
40043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
40063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    display_height,
40073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    display_width,
40083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    id,
40093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x_offset,
40103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y_offset;
40113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40124c08aed51c5899665ade97263692328eea4af106cristy  Quantum
40134c08aed51c5899665ade97263692328eea4af106cristy    index;
40144c08aed51c5899665ade97263692328eea4af106cristy
40153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  RectangleInfo
40163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    crop_info;
40173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
40193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
40203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static ColormapInfo
40223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *colormap_info = (ColormapInfo *) NULL;
40233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static int
40253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    max_windows = 0,
40263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_windows = 0;
40273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static WindowInfo
40293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *window_info;
40303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
40323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
40333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
40353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    child,
40363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root_window;
40373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XWindowAttributes
40393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window_attributes;
40403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
40413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
40423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Verify window is viewable.
40433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
40443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
40453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
40463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XGetWindowAttributes(display,window,&window_attributes);
40473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((status == False) || (window_attributes.map_state != IsViewable))
40483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return((Image *) NULL);
40493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
40503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Cropping rectangle is relative to root window.
40513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
40523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  root_window=XRootWindow(display,XDefaultScreen(display));
40533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XTranslateCoordinates(display,window,root_window,0,0,&x_offset,
40543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &y_offset,&child);
4055bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  crop_info.x=(ssize_t) x_offset;
4056bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  crop_info.y=(ssize_t) y_offset;
4057bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  crop_info.width=(size_t) window_attributes.width;
4058bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  crop_info.height=(size_t) window_attributes.height;
40593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (borders != MagickFalse)
40603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
40613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
40623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Include border in image.
40633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
4064bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      crop_info.x-=(ssize_t) window_attributes.border_width;
4065bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      crop_info.y-=(ssize_t) window_attributes.border_width;
4066bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      crop_info.width+=(size_t) (window_attributes.border_width << 1);
4067bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      crop_info.height+=(size_t) (window_attributes.border_width << 1);
40683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
40693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
40703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Crop to root window.
40713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
40723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (crop_info.x < 0)
40733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
40743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      crop_info.width+=crop_info.x;
40753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      crop_info.x=0;
40763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
40773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (crop_info.y < 0)
40783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
40793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      crop_info.height+=crop_info.y;
40803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      crop_info.y=0;
40813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
40823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  display_width=XDisplayWidth(display,XDefaultScreen(display));
40833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((int) (crop_info.x+crop_info.width) > display_width)
4084bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy    crop_info.width=(size_t) (display_width-crop_info.x);
40853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  display_height=XDisplayHeight(display,XDefaultScreen(display));
40863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((int) (crop_info.y+crop_info.height) > display_height)
4087bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy    crop_info.height=(size_t) (display_height-crop_info.y);
40883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
40893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize window info attributes.
40903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
40913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (number_windows >= max_windows)
40923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
40933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
40943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Allocate or resize window info buffer.
40953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
40963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      max_windows+=1024;
40973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window_info == (WindowInfo *) NULL)
40983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window_info=(WindowInfo *) AcquireQuantumMemory((size_t) max_windows,
40993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          sizeof(*window_info));
41003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
41013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window_info=(WindowInfo *) ResizeQuantumMemory(window_info,(size_t)
41023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          max_windows,sizeof(*window_info));
41033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
41043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info == (WindowInfo *) NULL)
41053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
4106c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy      ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed","...");
41073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return((Image *) NULL);
41083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
41093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  id=number_windows++;
41103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info[id].window=window;
41113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info[id].visual=window_attributes.visual;
41123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info[id].colormap=window_attributes.colormap;
41133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info[id].bounds.x1=(short) crop_info.x;
41143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info[id].bounds.y1=(short) crop_info.y;
41153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info[id].bounds.x2=(short) (crop_info.x+(int) crop_info.width-1);
41163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info[id].bounds.y2=(short) (crop_info.y+(int) crop_info.height-1);
41173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  crop_info.x-=x_offset;
41183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  crop_info.y-=y_offset;
41193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info[id].crop_info=crop_info;
41203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (level != 0)
41213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
41223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      unsigned int
41233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        number_children;
41243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
41253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Window
41263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *children;
41273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
41283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
41293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Descend the window hierarchy.
41303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
41313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      status=XQueryTree(display,window,&root_window,&window_info[id].parent,
41323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &children,&number_children);
41333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (i=0; i < id; i++)
41343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if ((window_info[i].window == window_info[id].parent) &&
41353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (window_info[i].visual == window_info[id].visual) &&
41363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (window_info[i].colormap == window_info[id].colormap))
41373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
413864057b049640be82cf952fa3e01282917270850ecristy            if ((window_info[id].bounds.x1 < window_info[i].bounds.x1) ||
413964057b049640be82cf952fa3e01282917270850ecristy                (window_info[id].bounds.x2 > window_info[i].bounds.x2) ||
414064057b049640be82cf952fa3e01282917270850ecristy                (window_info[id].bounds.y1 < window_info[i].bounds.y1) ||
414164057b049640be82cf952fa3e01282917270850ecristy                (window_info[id].bounds.y2 > window_info[i].bounds.y2))
41423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
41433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                /*
41443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  Eliminate windows not circumscribed by their parent.
41453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                */
41463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                number_windows--;
41473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                break;
41483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
41493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
41503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((status == True) && (number_children != 0))
41513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
41523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (i=0; i < (int) number_children; i++)
41536710d8414f0ed06e4eaf9346366be72e2b4719efcristy            (void) XGetWindowImage(display,children[i],MagickFalse,level+1,
41546710d8414f0ed06e4eaf9346366be72e2b4719efcristy              exception);
41553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) XFree((void *) children);
41563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
41573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
41583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (level <= 1)
41593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
4160c57f694b2d04975a0e501613e34368c464708c19cristy      CacheView
4161c57f694b2d04975a0e501613e34368c464708c19cristy        *composite_view;
4162c57f694b2d04975a0e501613e34368c464708c19cristy
41633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ColormapInfo
41643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *next;
41653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
41663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Image
41673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *composite_image,
41683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *image;
41693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
41703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      int
41713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        y;
41723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
41733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      MagickBooleanType
41743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        import;
41753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
41763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      register int
41773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        j,
41783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        x;
41793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
41804c08aed51c5899665ade97263692328eea4af106cristy      register Quantum
418105d2ff7ebf21f659f5b11e45afb294e152f4330cdirk        *magick_restrict q;
41823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4183bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      register size_t
41843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        pixel;
41853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
41863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      unsigned int
41873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        number_colors;
41883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
41893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XColor
41903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *colors;
41913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
41923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XImage
41933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *ximage;
41943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
41953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
41963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Get X image for each window in the list.
41973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
41983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image=NewImageList();
41993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (id=0; id < number_windows; id++)
42003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
42013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
42023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Does target window intersect top level window?
42033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
4204088af958c834f0ccc50ea4d6f8746b30df77ab12cristy        import=((window_info[id].bounds.x2 >= window_info[0].bounds.x1) &&
42053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy           (window_info[id].bounds.x1 <= window_info[0].bounds.x2) &&
42063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy           (window_info[id].bounds.y2 >= window_info[0].bounds.y1) &&
42073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy           (window_info[id].bounds.y1 <= window_info[0].bounds.y2)) ?
42083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          MagickTrue : MagickFalse;
42093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
42103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Is target window contained by another window with the same colormap?
42113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
42123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        for (j=0; j < id; j++)
42133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((window_info[id].visual == window_info[j].visual) &&
42143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (window_info[id].colormap == window_info[j].colormap))
42153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
421664057b049640be82cf952fa3e01282917270850ecristy              if ((window_info[id].bounds.x1 >= window_info[j].bounds.x1) &&
421764057b049640be82cf952fa3e01282917270850ecristy                  (window_info[id].bounds.x2 <= window_info[j].bounds.x2) &&
421864057b049640be82cf952fa3e01282917270850ecristy                  (window_info[id].bounds.y1 >= window_info[j].bounds.y1) &&
421964057b049640be82cf952fa3e01282917270850ecristy                  (window_info[id].bounds.y2 <= window_info[j].bounds.y2))
4220088af958c834f0ccc50ea4d6f8746b30df77ab12cristy                import=MagickFalse;
42213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
42223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (import == MagickFalse)
42233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          continue;
42243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
42253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Get X image.
42263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
42273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage=XGetImage(display,window_info[id].window,(int)
42283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window_info[id].crop_info.x,(int) window_info[id].crop_info.y,
42293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (unsigned int) window_info[id].crop_info.width,(unsigned int)
42303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window_info[id].crop_info.height,AllPlanes,ZPixmap);
42313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (ximage == (XImage *) NULL)
42323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          continue;
42333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
42343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Initialize window colormap.
42353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
42363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        number_colors=0;
42373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        colors=(XColor *) NULL;
42383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (window_info[id].colormap != (Colormap) NULL)
42393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
42403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            ColormapInfo
42413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *p;
42423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
42433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
42443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Search colormap list for window colormap.
42453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
42463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            number_colors=(unsigned int) window_info[id].visual->map_entries;
42473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (p=colormap_info; p != (ColormapInfo *) NULL; p=p->next)
42483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (p->colormap == window_info[id].colormap)
42493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                break;
42503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (p == (ColormapInfo *) NULL)
42513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
42523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                /*
42533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  Get the window colormap.
42543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                */
42553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                colors=(XColor *) AcquireQuantumMemory(number_colors,
42563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  sizeof(*colors));
42573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if (colors == (XColor *) NULL)
42583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
42593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    XDestroyImage(ximage);
42603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    return((Image *) NULL);
42613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
42623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if ((window_info[id].visual->klass != DirectColor) &&
42633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    (window_info[id].visual->klass != TrueColor))
42643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  for (i=0; i < (int) number_colors; i++)
42653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
4266bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy                    colors[i].pixel=(size_t) i;
42673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    colors[i].pad='\0';
42683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
42693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                else
42703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
4271bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy                    size_t
42723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      blue,
42733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      blue_bit,
42743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      green,
42753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      green_bit,
42763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      red,
42773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      red_bit;
42783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
42793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    /*
42803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      DirectColor or TrueColor visual.
42813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    */
42823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    red=0;
42833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    green=0;
42843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    blue=0;
42853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    red_bit=window_info[id].visual->red_mask &
42863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      (~(window_info[id].visual->red_mask)+1);
42873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    green_bit=window_info[id].visual->green_mask &
42883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      (~(window_info[id].visual->green_mask)+1);
42893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    blue_bit=window_info[id].visual->blue_mask &
42903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      (~(window_info[id].visual->blue_mask)+1);
42913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    for (i=0; i < (int) number_colors; i++)
42923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
42938891f9ce489d3e61399b60436ea6c62f5ed9b887cristy                      colors[i].pixel=(unsigned long) (red | green | blue);
42943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      colors[i].pad='\0';
42953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      red+=red_bit;
42963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      if (red > window_info[id].visual->red_mask)
42973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        red=0;
42983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      green+=green_bit;
42993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      if (green > window_info[id].visual->green_mask)
43003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        green=0;
43013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      blue+=blue_bit;
43023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      if (blue > window_info[id].visual->blue_mask)
43033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        blue=0;
43043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
43053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
43063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (void) XQueryColors(display,window_info[id].colormap,colors,
43073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  (int) number_colors);
43083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                /*
43093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  Append colormap to colormap list.
43103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                */
431173bd4a51b419e914565bdf204bf1540dc4c8ee26cristy                p=(ColormapInfo *) AcquireMagickMemory(sizeof(*p));
43123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if (p == (ColormapInfo *) NULL)
43133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  return((Image *) NULL);
43143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                p->colormap=window_info[id].colormap;
43153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                p->colors=colors;
43163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                p->next=colormap_info;
43173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                colormap_info=p;
43183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
43193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            colors=p->colors;
43203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
43213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
43223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Allocate image structure.
43233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
43246710d8414f0ed06e4eaf9346366be72e2b4719efcristy        composite_image=AcquireImage((ImageInfo *) NULL,exception);
43253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (composite_image == (Image *) NULL)
43263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
43273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            XDestroyImage(ximage);
43283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            return((Image *) NULL);
43293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
43303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
43313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Convert X image to MIFF format.
43323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
43333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if ((window_info[id].visual->klass != TrueColor) &&
43343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (window_info[id].visual->klass != DirectColor))
43353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          composite_image->storage_class=PseudoClass;
4336bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        composite_image->columns=(size_t) ximage->width;
4337bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        composite_image->rows=(size_t) ximage->height;
433846ff2676b1044ea4101ac7a59b83289cd8f6cfdacristy        composite_view=AcquireAuthenticCacheView(composite_image,exception);
43393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        switch (composite_image->storage_class)
43403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
43413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          case DirectClass:
43423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          default:
43433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
4344bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            register size_t
43453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              color,
43463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              index;
43473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
4348bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            size_t
43493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              blue_mask,
43503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              blue_shift,
43513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              green_mask,
43523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              green_shift,
43533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              red_mask,
43543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              red_shift;
43553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
43563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
43573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Determine shift and mask for red, green, and blue.
43583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
43593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            red_mask=window_info[id].visual->red_mask;
43603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            red_shift=0;
43613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            while ((red_mask != 0) && ((red_mask & 0x01) == 0))
43623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
43633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              red_mask>>=1;
43643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              red_shift++;
43653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
43663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            green_mask=window_info[id].visual->green_mask;
43673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            green_shift=0;
43683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            while ((green_mask != 0) && ((green_mask & 0x01) == 0))
43693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
43703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              green_mask>>=1;
43713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              green_shift++;
43723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
43733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            blue_mask=window_info[id].visual->blue_mask;
43743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            blue_shift=0;
43753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            while ((blue_mask != 0) && ((blue_mask & 0x01) == 0))
43763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
43773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              blue_mask>>=1;
43783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              blue_shift++;
43793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
43803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
43813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Convert X image to DirectClass packets.
43823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
43833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if ((number_colors != 0) &&
43843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (window_info[id].visual->klass == DirectColor))
43853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (y=0; y < (int) composite_image->rows; y++)
43863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
4387c57f694b2d04975a0e501613e34368c464708c19cristy                q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
43883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  composite_image->columns,1,exception);
4389acd2ed254c18c254a0ab5aafa06d1645e5d079d8cristy                if (q == (Quantum *) NULL)
43903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
43913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (x=0; x < (int) composite_image->columns; x++)
43923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
43933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  pixel=XGetPixel(ximage,x,y);
43943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  index=(pixel >> red_shift) & red_mask;
43954c08aed51c5899665ade97263692328eea4af106cristy                  SetPixelRed(composite_image,
43964c08aed51c5899665ade97263692328eea4af106cristy                    ScaleShortToQuantum(colors[index].red),q);
43973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  index=(pixel >> green_shift) & green_mask;
43984c08aed51c5899665ade97263692328eea4af106cristy                  SetPixelGreen(composite_image,
43994c08aed51c5899665ade97263692328eea4af106cristy                    ScaleShortToQuantum(colors[index].green),q);
44003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  index=(pixel >> blue_shift) & blue_mask;
44014c08aed51c5899665ade97263692328eea4af106cristy                  SetPixelBlue(composite_image,
44024c08aed51c5899665ade97263692328eea4af106cristy                    ScaleShortToQuantum(colors[index].blue),q);
4403ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                  q+=GetPixelChannels(composite_image);
44043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
44050b1a797184d12984eb55d950fb5f532298d9fd0fcristy                status=SyncCacheViewAuthenticPixels(composite_view,exception);
44060b1a797184d12984eb55d950fb5f532298d9fd0fcristy                if (status == MagickFalse)
44073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
44083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
44093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            else
44103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (y=0; y < (int) composite_image->rows; y++)
44113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
4412c57f694b2d04975a0e501613e34368c464708c19cristy                q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
44133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  composite_image->columns,1,exception);
4414acd2ed254c18c254a0ab5aafa06d1645e5d079d8cristy                if (q == (Quantum *) NULL)
44153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
44163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (x=0; x < (int) composite_image->columns; x++)
44173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
44183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  pixel=XGetPixel(ximage,x,y);
44193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  color=(pixel >> red_shift) & red_mask;
44209a7df36bb436fe340138d7eea39c974b45c9344ccristy                  if (red_mask != 0)
44219a7df36bb436fe340138d7eea39c974b45c9344ccristy                    color=(65535UL*color)/red_mask;
44229a7df36bb436fe340138d7eea39c974b45c9344ccristy                  SetPixelRed(composite_image,ScaleShortToQuantum(
44239a7df36bb436fe340138d7eea39c974b45c9344ccristy                    (unsigned short) color),q);
44243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  color=(pixel >> green_shift) & green_mask;
44259a7df36bb436fe340138d7eea39c974b45c9344ccristy                  if (green_mask != 0)
44269a7df36bb436fe340138d7eea39c974b45c9344ccristy                    color=(65535UL*color)/green_mask;
44279a7df36bb436fe340138d7eea39c974b45c9344ccristy                  SetPixelGreen(composite_image,ScaleShortToQuantum(
44289a7df36bb436fe340138d7eea39c974b45c9344ccristy                    (unsigned short) color),q);
44293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  color=(pixel >> blue_shift) & blue_mask;
44309a7df36bb436fe340138d7eea39c974b45c9344ccristy                  if (blue_mask != 0)
44319a7df36bb436fe340138d7eea39c974b45c9344ccristy                    color=(65535UL*color)/blue_mask;
44329a7df36bb436fe340138d7eea39c974b45c9344ccristy                  SetPixelBlue(composite_image,ScaleShortToQuantum(
44339a7df36bb436fe340138d7eea39c974b45c9344ccristy                    (unsigned short) color),q);
4434ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                  q+=GetPixelChannels(composite_image);
44353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
44360b1a797184d12984eb55d950fb5f532298d9fd0fcristy                status=SyncCacheViewAuthenticPixels(composite_view,exception);
44370b1a797184d12984eb55d950fb5f532298d9fd0fcristy                if (status == MagickFalse)
44383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
44393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
44403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            break;
44413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
44423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          case PseudoClass:
44433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
44443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
44453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Create colormap.
44463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
44470b1a797184d12984eb55d950fb5f532298d9fd0fcristy            status=AcquireImageColormap(composite_image,number_colors,
44480b1a797184d12984eb55d950fb5f532298d9fd0fcristy              exception);
44490b1a797184d12984eb55d950fb5f532298d9fd0fcristy            if (status == MagickFalse)
44503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
44513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                XDestroyImage(ximage);
44523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                composite_image=DestroyImage(composite_image);
44533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                return((Image *) NULL);
44543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
44553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (i=0; i < (int) composite_image->colors; i++)
44563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
4457e42f658533644aecb733785ffd91b286d6778deacristy              composite_image->colormap[colors[i].pixel].red=(double)
44583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                ScaleShortToQuantum(colors[i].red);
4459e42f658533644aecb733785ffd91b286d6778deacristy              composite_image->colormap[colors[i].pixel].green=(double)
44603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                ScaleShortToQuantum(colors[i].green);
4461e42f658533644aecb733785ffd91b286d6778deacristy              composite_image->colormap[colors[i].pixel].blue=(double)
44623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                ScaleShortToQuantum(colors[i].blue);
44633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
44643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
44653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Convert X image to PseudoClass packets.
44663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
44673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (y=0; y < (int) composite_image->rows; y++)
44683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
4469c57f694b2d04975a0e501613e34368c464708c19cristy              q=QueueCacheViewAuthenticPixels(composite_view,0,(ssize_t) y,
4470c57f694b2d04975a0e501613e34368c464708c19cristy                composite_image->columns,1,exception);
4471acd2ed254c18c254a0ab5aafa06d1645e5d079d8cristy              if (q == (Quantum *) NULL)
44723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                break;
44733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (x=0; x < (int) composite_image->columns; x++)
44743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
44754c08aed51c5899665ade97263692328eea4af106cristy                index=(Quantum) XGetPixel(ximage,x,y);
44764c08aed51c5899665ade97263692328eea4af106cristy                SetPixelIndex(composite_image,index,q);
447711a06d3f2cac0f17af7963e83bc6e9ebd2a377c0cristy                SetPixelViaPixelInfo(composite_image,
44784c08aed51c5899665ade97263692328eea4af106cristy                  composite_image->colormap+(ssize_t) index,q);
4479ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                q+=GetPixelChannels(composite_image);
44803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
44810b1a797184d12984eb55d950fb5f532298d9fd0fcristy              status=SyncCacheViewAuthenticPixels(composite_view,exception);
44820b1a797184d12984eb55d950fb5f532298d9fd0fcristy              if (status == MagickFalse)
44833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                break;
44843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
44853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            break;
44863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
44873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
4488c57f694b2d04975a0e501613e34368c464708c19cristy        composite_view=DestroyCacheView(composite_view);
44893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XDestroyImage(ximage);
44903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (image == (Image *) NULL)
44913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
44923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            image=composite_image;
44933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            continue;
44943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
44953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
44963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Composite any children in back-to-front order.
44973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
44983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XTranslateCoordinates(display,window_info[id].window,window,0,0,
44993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          &x_offset,&y_offset,&child);
45003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        x_offset-=(int) crop_info.x;
45013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (x_offset < 0)
45023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          x_offset=0;
45033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        y_offset-=(int) crop_info.y;
45043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (y_offset < 0)
45053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          y_offset=0;
450639172408bad7ef2ef00a815fa9abf9979e7857cbcristy        (void) CompositeImage(image,composite_image,CopyCompositeOp,MagickTrue,
4507feb3e9695150978a5d2372d3fe2f60466a7c8066cristy          (ssize_t) x_offset,(ssize_t) y_offset,exception);
45085f257b2f02bdd982d9bbfe612f5bb1711608590ccristy        composite_image=DestroyImage(composite_image);
45093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
45103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
45113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Relinquish resources.
45123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
45133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      while (colormap_info != (ColormapInfo *) NULL)
45143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
45153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        next=colormap_info->next;
4516e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy        colormap_info->colors=(XColor *) RelinquishMagickMemory(
4517e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy          colormap_info->colors);
45183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        colormap_info=(ColormapInfo *) RelinquishMagickMemory(colormap_info);
45193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        colormap_info=next;
45203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
45213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
45223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Relinquish resources and restore initial state.
45233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
45243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_info=(WindowInfo *) RelinquishMagickMemory(window_info);
45253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      max_windows=0;
45263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      number_windows=0;
45273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      colormap_info=(ColormapInfo *) NULL;
45283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(image);
45293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
45303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return((Image *) NULL);
45313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
45323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
45333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
45343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
45363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
45373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
45383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t W i n d o w I n f o                                               %
45393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
45403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
45413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
45423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
45433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
45443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetWindowInfo() initializes the XWindowInfo structure.
45453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
45463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetWindowInfo method is:
45473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
45483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
45493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
45503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XResourceInfo *resource_info,XWindowInfo *window)
45513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        resource_info,window)
45523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
45533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
45543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
45553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
45563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
45573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
45583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
45593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      returned from XGetVisualInfo.
45603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
45613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o map_info: If map_type is specified, this structure is initialized
45623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      with info from the Standard Colormap.
45633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
45643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o pixel: Specifies a pointer to a XPixelInfo structure.
45653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
45663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o font_info: Specifies a pointer to a XFontStruct structure.
45673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
45683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
45693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
45703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
4571bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XGetWindowInfo(Display *display,XVisualInfo *visual_info,
45723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XStandardColormap *map_info,XPixelInfo *pixel,XFontStruct *font_info,
45733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XResourceInfo *resource_info,XWindowInfo *window)
45743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
45753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
45763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize window info.
45773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
45783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
45793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
45803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(visual_info != (XVisualInfo *) NULL);
45813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(map_info != (XStandardColormap *) NULL);
45823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(pixel != (XPixelInfo *) NULL);
45833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
45843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (XWindowInfo *) NULL);
45853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->id != (Window) NULL)
45863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
45873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->cursor != (Cursor) NULL)
45883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreeCursor(display,window->cursor);
45893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->busy_cursor != (Cursor) NULL)
45903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreeCursor(display,window->busy_cursor);
45913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->highlight_stipple != (Pixmap) NULL)
45923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreePixmap(display,window->highlight_stipple);
45933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->shadow_stipple != (Pixmap) NULL)
45943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XFreePixmap(display,window->shadow_stipple);
45953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->name == (char *) NULL)
45963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window->name=AcquireString("");
45973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->icon_name == (char *) NULL)
45983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window->icon_name=AcquireString("");
45993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
46003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
46013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
46023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
46033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Initialize these attributes just once.
46043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
46053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->id=(Window) NULL;
46063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->name == (char *) NULL)
46073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window->name=AcquireString("");
46083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->icon_name == (char *) NULL)
46093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window->icon_name=AcquireString("");
46103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->x=XDisplayWidth(display,visual_info->screen) >> 1;
46113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->y=XDisplayWidth(display,visual_info->screen) >> 1;
46123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->ximage=(XImage *) NULL;
46133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->matte_image=(XImage *) NULL;
46143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->pixmap=(Pixmap) NULL;
46153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->matte_pixmap=(Pixmap) NULL;
46163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->mapped=MagickFalse;
46173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->stasis=MagickFalse;
46183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->shared_memory=MagickTrue;
46193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->segment_info=(void *) NULL;
46203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
46213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
46223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XShmSegmentInfo
46233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          *segment_info;
46243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
46253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (window->segment_info == (void *) NULL)
46263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window->segment_info=AcquireQuantumMemory(2,sizeof(*segment_info));
46273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        segment_info=(XShmSegmentInfo *) window->segment_info;
46283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        segment_info[0].shmid=(-1);
46293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        segment_info[0].shmaddr=(char *) NULL;
46303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        segment_info[1].shmid=(-1);
46313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        segment_info[1].shmaddr=(char *) NULL;
46323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
46333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
46343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
46353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
46363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize these attributes every time function is called.
46373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
46383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->screen=visual_info->screen;
46393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->root=XRootWindow(display,visual_info->screen);
46403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->visual=visual_info->visual;
46413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->storage_class=(unsigned int) visual_info->klass;
46423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->depth=(unsigned int) visual_info->depth;
46433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->visual_info=visual_info;
46443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->map_info=map_info;
46453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->pixel_info=pixel;
46463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->font_info=font_info;
46473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->cursor=XCreateFontCursor(display,XC_left_ptr);
46483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->busy_cursor=XCreateFontCursor(display,XC_watch);
46493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->geometry=(char *) NULL;
46503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->icon_geometry=(char *) NULL;
46513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->icon_geometry != (char *) NULL)
46523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) CloneString(&window->icon_geometry,resource_info->icon_geometry);
46533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->crop_geometry=(char *) NULL;
4654bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  window->flags=(size_t) PSize;
46553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->width=1;
46563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->height=1;
46573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->min_width=1;
46583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->min_height=1;
46593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->width_inc=1;
46603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->height_inc=1;
46613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->border_width=resource_info->border_width;
46623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->annotate_context=pixel->annotate_context;
46633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->highlight_context=pixel->highlight_context;
46643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->widget_context=pixel->widget_context;
46653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->shadow_stipple=(Pixmap) NULL;
46663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->highlight_stipple=(Pixmap) NULL;
46673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->use_pixmap=MagickTrue;
46683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->immutable=MagickFalse;
46693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->shape=MagickFalse;
46703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->data=0;
4671c57f694b2d04975a0e501613e34368c464708c19cristy  window->mask=(int) (CWBackingStore | CWBackPixel | CWBackPixmap |
46723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWDontPropagate |
46733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    CWEventMask | CWOverrideRedirect | CWSaveUnder | CWWinGravity);
46743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.background_pixel=pixel->background_color.pixel;
46753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.background_pixmap=(Pixmap) NULL;
46763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.bit_gravity=ForgetGravity;
46773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.backing_store=WhenMapped;
46783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.save_under=MagickTrue;
46793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.border_pixel=pixel->border_color.pixel;
46803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.colormap=map_info->colormap;
46813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.cursor=window->cursor;
46823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.do_not_propagate_mask=NoEventMask;
46833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.event_mask=NoEventMask;
46843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.override_redirect=MagickFalse;
46853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->attributes.win_gravity=NorthWestGravity;
46863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->orphan=MagickFalse;
46873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
46883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
46893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
46903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
46923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
46933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
46943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X H i g h l i g h t E l l i p s e                                         %
46953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
46963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
46973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
46983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
46993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XHighlightEllipse() puts a border on the X server around a region defined by
47013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  highlight_info.
47023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XHighlightEllipse method is:
47043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XHighlightEllipse(Display *display,Window window,
47063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        GC annotate_context,const RectangleInfo *highlight_info)
47073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
47093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
47113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
47123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a Window structure.
47143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o annotate_context: Specifies a pointer to a GC structure.
47163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o highlight_info: Specifies a pointer to a RectangleInfo structure.  It
47183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      contains the extents of any highlighting rectangle.
47193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
4721bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XHighlightEllipse(Display *display,Window window,
47223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  GC annotate_context,const RectangleInfo *highlight_info)
47233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
47243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
47253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
47263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (Window) NULL);
47273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(annotate_context != (GC) NULL);
47283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(highlight_info != (RectangleInfo *) NULL);
47293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((highlight_info->width < 4) || (highlight_info->height < 4))
47303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
47313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x,
47323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (int) highlight_info->y,(unsigned int) highlight_info->width-1,
47333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (unsigned int) highlight_info->height-1,0,360*64);
47343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XDrawArc(display,window,annotate_context,(int) highlight_info->x+1,
47353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
47363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (unsigned int) highlight_info->height-3,0,360*64);
47373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
47383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
47393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
47403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X H i g h l i g h t L i n e                                               %
47453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XHighlightLine() puts a border on the X server around a region defined by
47513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  highlight_info.
47523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XHighlightLine method is:
47543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XHighlightLine(Display *display,Window window,GC annotate_context,
47563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const XSegment *highlight_info)
47573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
47593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
47613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
47623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a Window structure.
47643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o annotate_context: Specifies a pointer to a GC structure.
47663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o highlight_info: Specifies a pointer to a RectangleInfo structure.  It
47683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      contains the extents of any highlighting rectangle.
47693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
4771bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XHighlightLine(Display *display,Window window,
47723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  GC annotate_context,const XSegment *highlight_info)
47733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
47743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
47753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
47763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (Window) NULL);
47773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(annotate_context != (GC) NULL);
47783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(highlight_info != (XSegment *) NULL);
47793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XDrawLine(display,window,annotate_context,highlight_info->x1,
47803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    highlight_info->y1,highlight_info->x2,highlight_info->y2);
47813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
47823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
47833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
47843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X H i g h l i g h t R e c t a n g l e                                     %
47893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
47923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XHighlightRectangle() puts a border on the X server around a region defined
47953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  by highlight_info.
47963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XHighlightRectangle method is:
47983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
47993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XHighlightRectangle(Display *display,Window window,
48003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        GC annotate_context,const RectangleInfo *highlight_info)
48013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
48033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
48053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
48063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a Window structure.
48083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o annotate_context: Specifies a pointer to a GC structure.
48103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o highlight_info: Specifies a pointer to a RectangleInfo structure.  It
48123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      contains the extents of any highlighting rectangle.
48133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
4815bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XHighlightRectangle(Display *display,Window window,
48163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  GC annotate_context,const RectangleInfo *highlight_info)
48173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
48183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
48193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
48203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (Window) NULL);
48213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(annotate_context != (GC) NULL);
48223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(highlight_info != (RectangleInfo *) NULL);
48233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((highlight_info->width < 4) || (highlight_info->height < 4))
48243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
48253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x,
48263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (int) highlight_info->y,(unsigned int) highlight_info->width-1,
48273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (unsigned int) highlight_info->height-1);
48283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XDrawRectangle(display,window,annotate_context,(int) highlight_info->x+
48293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    1,(int) highlight_info->y+1,(unsigned int) highlight_info->width-3,
48303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (unsigned int) highlight_info->height-3);
48313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
48323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
48333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
48343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
48363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
48373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
48383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X I m p o r t I m a g e                                                   %
48393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
48403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
48413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
48423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
48433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XImportImage() reads an image from an X window.
48453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XImportImage method is:
48473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48486710d8414f0ed06e4eaf9346366be72e2b4719efcristy%      Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info,
48496710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        ExceptionInfo *exception)
48503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
48523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image_info: the image info.
48543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o ximage_info: Specifies a pointer to an XImportInfo structure.
48563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
48576710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    o exception: return any errors or warnings in this structure.
48586710d8414f0ed06e4eaf9346366be72e2b4719efcristy%
48593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
48603ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport Image *XImportImage(const ImageInfo *image_info,
48616710d8414f0ed06e4eaf9346366be72e2b4719efcristy  XImportInfo *ximage_info,ExceptionInfo *exception)
48623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
48633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Colormap
48643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *colormaps;
48653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
48663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Display
48673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *display;
48683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
48693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Image
48703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *image;
48713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
48723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
48733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_colormaps,
48743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_windows,
48753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x;
48763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
48773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  RectangleInfo
48783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    crop_info;
48793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
48803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
48813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
48823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
48833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
48843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *children,
48853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    client,
48863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    prior_target,
48873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root,
48883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    target;
48893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
48903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XTextProperty
48913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window_name;
48923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
48933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
48943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Open X server connection.
48953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
48963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image_info != (const ImageInfo *) NULL);
4897e1c94d9d25db6b0dd7a5028ffee31d1057855d73cristy  assert(image_info->signature == MagickCoreSignature);
48983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image_info->debug != MagickFalse)
48993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
49003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info->filename);
49013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(ximage_info != (XImportInfo *) NULL);
49023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  display=XOpenDisplay(image_info->server_name);
49033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (display == (Display *) NULL)
49043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
4905c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy      ThrowXWindowException(XServerError,"UnableToOpenXServer",
49063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XDisplayName(image_info->server_name));
49073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return((Image *) NULL);
49083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
49093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
49103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set our forgiving exception handler.
49113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
49123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSetErrorHandler(XError);
49133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
49143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Select target window.
49153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
49163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  crop_info.x=0;
49173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  crop_info.y=0;
49183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  crop_info.width=0;
49193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  crop_info.height=0;
49203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  root=XRootWindow(display,XDefaultScreen(display));
49213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  target=(Window) NULL;
49226f008fdcea6389206e36baf0f05c8999c7366f7bcristy  if (*image_info->filename != '\0')
49233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
49243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (LocaleCompare(image_info->filename,"root") == 0)
49253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        target=root;
49263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
49273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
49283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
49293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Select window by ID or name.
49303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
493102e64f85ab79992a87dd6979d4948488fec02817cristy          if (isdigit((int) ((unsigned char) *image_info->filename)) != 0)
49323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            target=XWindowByID(display,root,(Window)
49333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              strtol(image_info->filename,(char **) NULL,0));
49343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (target == (Window) NULL)
49353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            target=XWindowByName(display,root,image_info->filename);
49363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (target == (Window) NULL)
4937c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy            ThrowXWindowException(XServerError,"NoWindowWithSpecifiedIDExists",
4938c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy              image_info->filename);
49393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
49403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
49413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
49423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    If target window is not defined, interactively select one.
49433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
49443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  prior_target=target;
49453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (target == (Window) NULL)
49463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    target=XSelectWindow(display,&crop_info);
49473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (target == (Window) NULL)
4948c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy    ThrowXWindowException(XServerError,"UnableToReadXWindowImage",
49493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info->filename);
49503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  client=target;   /* obsolete */
49513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (target != root)
49523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
49533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      unsigned int
49543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        d;
49553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
49563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      status=XGetGeometry(display,target,&root,&x,&x,&d,&d,&d,&d);
49573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status != False)
49583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
49593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for ( ; ; )
49603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
49613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Window
49623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              parent;
49633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
49643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
49653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Find window manager frame.
49663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
49673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            status=XQueryTree(display,target,&root,&parent,&children,&d);
49683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if ((status != False) && (children != (Window *) NULL))
49693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) XFree((char *) children);
49703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if ((status == False) || (parent == (Window) NULL) ||
49713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (parent == root))
49723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
49733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            target=parent;
49743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
49753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
49763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Get client window.
49773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
49783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          client=XClientWindow(display,target);
49793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (ximage_info->frame == MagickFalse)
49803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            target=client;
49813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((ximage_info->frame == MagickFalse) &&
49823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (prior_target != MagickFalse))
49833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            target=prior_target;
49843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
49853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
49863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (ximage_info->screen)
49873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
49883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      int
49893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        y;
49903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
49913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Window
49923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        child;
49933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
49943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XWindowAttributes
49953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window_attributes;
49963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
49973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
49983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Obtain window image directly from screen.
49993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
50003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      status=XGetWindowAttributes(display,target,&window_attributes);
50013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status == False)
50023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
5003c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy          ThrowXWindowException(XServerError,"UnableToReadXWindowAttributes",
5004c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy            image_info->filename);
50053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) XCloseDisplay(display);
50063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          return((Image *) NULL);
50073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
50083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XTranslateCoordinates(display,target,root,0,0,&x,&y,&child);
5009c57f694b2d04975a0e501613e34368c464708c19cristy      crop_info.x=(ssize_t) x;
5010c57f694b2d04975a0e501613e34368c464708c19cristy      crop_info.y=(ssize_t) y;
5011bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      crop_info.width=(size_t) window_attributes.width;
5012bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      crop_info.height=(size_t) window_attributes.height;
5013553743c2f2d6c29405dcfab6390a1c505c79fececristy      if (ximage_info->borders != 0)
50143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
50153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
50163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Include border in image.
50173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
50183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          crop_info.x-=window_attributes.border_width;
50193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          crop_info.y-=window_attributes.border_width;
50203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          crop_info.width+=window_attributes.border_width << 1;
50213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          crop_info.height+=window_attributes.border_width << 1;
50223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
50233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      target=root;
50243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
50253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
50263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    If WM_COLORMAP_WINDOWS property is set or multiple colormaps, descend.
50273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
50283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  number_windows=0;
50293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XGetWMColormapWindows(display,target,&children,&number_windows);
50303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((status == True) && (number_windows > 0))
50313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
50323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ximage_info->descend=MagickTrue;
50333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFree ((char *) children);
50343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
50353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  colormaps=XListInstalledColormaps(display,target,&number_colormaps);
50363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (number_colormaps > 0)
50373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
50383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (number_colormaps > 1)
50393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage_info->descend=MagickTrue;
50403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFree((char *) colormaps);
50413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
50423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
50433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Alert the user not to alter the screen.
50443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
50453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (ximage_info->silent == MagickFalse)
50463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XBell(display,0);
50473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
50483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Get image by window id.
50493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
50503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XGrabServer(display);
50513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  image=XGetWindowImage(display,target,ximage_info->borders,
50526710d8414f0ed06e4eaf9346366be72e2b4719efcristy    ximage_info->descend ? 1U : 0U,exception);
50533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XUngrabServer(display);
50543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image == (Image *) NULL)
5055c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy    ThrowXWindowException(XServerError,"UnableToReadXWindowImage",
50563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info->filename)
50573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
50583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
50593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) CopyMagickString(image->filename,image_info->filename,
5060151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy        MagickPathExtent);
50613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((crop_info.width != 0) && (crop_info.height != 0))
50623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
50633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Image
50643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *clone_image,
50653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *crop_image;
50663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
50673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
50683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Crop image as defined by the cropping rectangle.
50693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
50706710d8414f0ed06e4eaf9346366be72e2b4719efcristy          clone_image=CloneImage(image,0,0,MagickTrue,exception);
50713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (clone_image != (Image *) NULL)
50723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
50736710d8414f0ed06e4eaf9346366be72e2b4719efcristy              crop_image=CropImage(clone_image,&crop_info,exception);
50743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (crop_image != (Image *) NULL)
50753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
50763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  image=DestroyImage(image);
50773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  image=crop_image;
50783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
50793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
50803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
50813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      status=XGetWMName(display,target,&window_name);
50823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status == True)
50833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
50848418c7e51974060a1c724e25d700d72fb437174bcristy          if (*image_info->filename == '\0')
50853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) CopyMagickString(image->filename,(char *) window_name.value,
50863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (size_t) window_name.nitems+1);
50873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) XFree((void *) window_name.value);
50883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
50893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
50903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (ximage_info->silent == MagickFalse)
50913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
50923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
50933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Alert the user we're done.
50943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
50953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XBell(display,0);
50963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XBell(display,0);
50973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
50983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XCloseDisplay(display);
50993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(image);
51003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
51013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
51023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
51033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
51053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
51063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
51073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X I n i t i a l i z e W i n d o w s                                       %
51083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
51093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
51103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
51113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
51133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XInitializeWindows() initializes the XWindows structure.
51143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
51153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XInitializeWindows method is:
51163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
51173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XWindows *XInitializeWindows(Display *display,
51183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XResourceInfo *resource_info)
51193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
51203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
51213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
51223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o windows: XInitializeWindows returns a pointer to a XWindows structure.
51233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
51243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
51253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
51263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
51273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
51283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
51293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
5130bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate XWindows *XInitializeWindows(Display *display,
51313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XResourceInfo *resource_info)
51323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
51333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
51343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root_window;
51353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
51363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XWindows
51373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *windows;
51383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
51393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
51403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Allocate windows structure.
51413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
514273bd4a51b419e914565bdf204bf1540dc4c8ee26cristy  windows=(XWindows *) AcquireMagickMemory(sizeof(*windows));
51433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows == (XWindows *) NULL)
51443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
51453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
51463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "...");
51473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return((XWindows *) NULL);
51483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
51493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) ResetMagickMemory(windows,0,sizeof(*windows));
51503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->pixel_info=(XPixelInfo *) AcquireMagickMemory(
51513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    sizeof(*windows->pixel_info));
51523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->icon_pixel=(XPixelInfo *) AcquireMagickMemory(
51533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    sizeof(*windows->icon_pixel));
51543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->icon_resources=(XResourceInfo *) AcquireMagickMemory(
51553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    sizeof(*windows->icon_resources));
51563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((windows->pixel_info == (XPixelInfo *) NULL) ||
51573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (windows->icon_pixel == (XPixelInfo *) NULL) ||
51583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (windows->icon_resources == (XResourceInfo *) NULL))
51593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
51603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowFatalException(XServerFatalError,"MemoryAllocationFailed",
51613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "...");
51623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return((XWindows *) NULL);
51633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
51643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
51653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize windows structure.
51663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
51673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->display=display;
51683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->wm_protocols=XInternAtom(display,"WM_PROTOCOLS",MagickFalse);
51693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->wm_delete_window=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
51703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->wm_take_focus=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
51713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->im_protocols=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
51723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->im_remote_command=
51733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
51743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->im_update_widget=XInternAtom(display,"IM_UPDATE_WIDGET",MagickFalse);
51753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->im_update_colormap=
51763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XInternAtom(display,"IM_UPDATE_COLORMAP",MagickFalse);
51773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->im_former_image=XInternAtom(display,"IM_FORMER_IMAGE",MagickFalse);
51783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->im_next_image=XInternAtom(display,"IM_NEXT_IMAGE",MagickFalse);
51793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->im_retain_colors=XInternAtom(display,"IM_RETAIN_COLORS",MagickFalse);
51803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->im_exit=XInternAtom(display,"IM_EXIT",MagickFalse);
51813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->dnd_protocols=XInternAtom(display,"DndProtocol",MagickFalse);
51820157aeadef2fce908277168097a160a8f15a6952cristy#if defined(MAGICKCORE_WINDOWS_SUPPORT)
51833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSynchronize(display,IsWindows95());
51843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
51853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (IsEventLogging())
51863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
51873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XSynchronize(display,MagickTrue);
51883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"Version: %s",
5189bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        GetMagickVersion((size_t *) NULL));
51903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"Protocols:");
51913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
51923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "  Window Manager: 0x%lx",windows->wm_protocols);
51933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
51943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "    delete window: 0x%lx",windows->wm_delete_window);
51953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"    take focus: 0x%lx",
51963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->wm_take_focus);
51973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  ImageMagick: 0x%lx",
51983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->im_protocols);
51993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
52003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "    remote command: 0x%lx",windows->im_remote_command);
52013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
52023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "    update widget: 0x%lx",windows->im_update_widget);
52033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
52043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "    update colormap: 0x%lx",windows->im_update_colormap);
52053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
52063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "    former image: 0x%lx",windows->im_former_image);
52073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"    next image: 0x%lx",
52083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->im_next_image);
52093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
52103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "    retain colors: 0x%lx",windows->im_retain_colors);
52113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"    exit: 0x%lx",
52123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->im_exit);
52133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  Drag and Drop: 0x%lx",
52143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->dnd_protocols);
52153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
52163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
52173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Allocate standard colormap.
52183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
52193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->map_info=XAllocStandardColormap();
52203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->icon_map=XAllocStandardColormap();
52213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((windows->map_info == (XStandardColormap *) NULL) ||
52223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (windows->icon_map == (XStandardColormap *) NULL))
5223c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy    ThrowXWindowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
5224c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy      "...");
52253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->map_info->colormap=(Colormap) NULL;
52263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->icon_map->colormap=(Colormap) NULL;
5227f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  windows->pixel_info->pixels=(unsigned long *) NULL;
52283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->pixel_info->annotate_context=(GC) NULL;
52293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->pixel_info->highlight_context=(GC) NULL;
52303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->pixel_info->widget_context=(GC) NULL;
52313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->font_info=(XFontStruct *) NULL;
52323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->icon_pixel->annotate_context=(GC) NULL;
5233f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  windows->icon_pixel->pixels=(unsigned long *) NULL;
52343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
52353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Allocate visual.
52363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
52373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  *windows->icon_resources=(*resource_info);
52383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->icon_resources->visual_type=(char *) "default";
52393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->icon_resources->colormap=SharedColormap;
52403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->visual_info=
52413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XBestVisualInfo(display,windows->map_info,resource_info);
52423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->icon_visual=
52433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XBestVisualInfo(display,windows->icon_map,windows->icon_resources);
52443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((windows->visual_info == (XVisualInfo *) NULL) ||
52453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (windows->icon_visual == (XVisualInfo *) NULL))
52463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(XServerFatalError,"UnableToGetVisual",
52473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      resource_info->visual_type);
52483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (IsEventLogging())
52493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
52503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"Visual:");
52513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  visual id: 0x%lx",
52523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->visual_info->visualid);
52533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  class: %s",
52543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XVisualClassName(windows->visual_info->klass));
52553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  depth: %d planes",
52563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->visual_info->depth);
52573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
52583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "  size of colormap: %d entries",windows->visual_info->colormap_size);
52593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
52603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "  red, green, blue masks: 0x%lx 0x%lx 0x%lx",
52613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->visual_info->red_mask,windows->visual_info->green_mask,
52623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->visual_info->blue_mask);
52633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
52643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "  significant bits in color: %d bits",
52653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->visual_info->bits_per_rgb);
52663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
52673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
52683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Allocate class and manager hints.
52693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
52703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->class_hints=XAllocClassHint();
52713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->manager_hints=XAllocWMHints();
52723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((windows->class_hints == (XClassHint *) NULL) ||
52733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (windows->manager_hints == (XWMHints *) NULL))
5274c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy    ThrowXWindowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed",
5275c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy      "...");
52763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
52773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Determine group leader if we have one.
52783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
52793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  root_window=XRootWindow(display,windows->visual_info->screen);
52803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->group_leader.id=(Window) NULL;
52813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->window_group != (char *) NULL)
52823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
528302e64f85ab79992a87dd6979d4948488fec02817cristy      if (isdigit((int) ((unsigned char) *resource_info->window_group)) != 0)
52843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->group_leader.id=XWindowByID(display,root_window,(Window)
52853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          strtol((char *) resource_info->window_group,(char **) NULL,0));
52863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (windows->group_leader.id == (Window) NULL)
52873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->group_leader.id=
52883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          XWindowByName(display,root_window,resource_info->window_group);
52893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
52903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(windows);
52913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
52923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
52933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
52943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
52963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
52973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
52983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X M a k e C u r s o r                                                     %
52993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XMakeCursor() creates a crosshairs X11 cursor.
53053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XMakeCursor method is:
53073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      Cursor XMakeCursor(Display *display,Window window,Colormap colormap,
53093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        char *background_color,char *foreground_color)
53103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
53123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
53143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
53153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies the ID of the window for which the cursor is
53173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      assigned.
53183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o colormap: Specifies the ID of the colormap from which the background
53203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      and foreground color will be retrieved.
53213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o background_color: Specifies the color to use for the cursor background.
53233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o foreground_color: Specifies the color to use for the cursor foreground.
53253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
5327bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate Cursor XMakeCursor(Display *display,Window window,
53283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Colormap colormap,char *background_color,char *foreground_color)
53293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
53303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define scope_height 17
53313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define scope_x_hot 8
53323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define scope_y_hot 8
53333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define scope_width 17
53343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
53353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static const unsigned char
53363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scope_bits[] =
53373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
53383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0x80, 0x03, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
53393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x7f,
53403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0xfc, 0x01, 0x01, 0x00, 0x01, 0x7f, 0xfc, 0x01, 0x80, 0x02, 0x00,
53413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02, 0x00, 0x80, 0x02,
53423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0x00, 0x80, 0x02, 0x00, 0x80, 0x03, 0x00
53433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    },
53443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scope_mask_bits[] =
53453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
53463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
53473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xff, 0xfe, 0x01, 0x7f,
53483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0xfc, 0x01, 0x03, 0x80, 0x01, 0x7f, 0xfc, 0x01, 0xff, 0xfe, 0x01,
53493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06, 0x00, 0xc0, 0x06,
53503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      0x00, 0xc0, 0x07, 0x00, 0xc0, 0x07, 0x00
53513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    };
53523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
53533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Cursor
53543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    cursor;
53553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
53563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Pixmap
53573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    mask,
53583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    source;
53593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
53603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XColor
53613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    background,
53623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    foreground;
53633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
53643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
53653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (Window) NULL);
53663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(colormap != (Colormap) NULL);
53673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(background_color != (char *) NULL);
53683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(foreground_color != (char *) NULL);
53693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",background_color);
53703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  source=XCreateBitmapFromData(display,window,(char *) scope_bits,scope_width,
53713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scope_height);
53723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  mask=XCreateBitmapFromData(display,window,(char *) scope_mask_bits,
53733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scope_width,scope_height);
53743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((source == (Pixmap) NULL) || (mask == (Pixmap) NULL))
53753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
5376c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy      ThrowXWindowException(XServerError,"UnableToCreatePixmap","...");
53773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return((Cursor) NULL);
53783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
53793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseColor(display,colormap,background_color,&background);
53803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XParseColor(display,colormap,foreground_color,&foreground);
53813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  cursor=XCreatePixmapCursor(display,source,mask,&foreground,&background,
53823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scope_x_hot,scope_y_hot);
53833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFreePixmap(display,source);
53843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFreePixmap(display,mask);
53853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(cursor);
53863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
53873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
53883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
53893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X M a k e I m a g e                                                       %
53943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
53983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
53993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XMakeImage() creates an X11 image.  If the image size differs from the X11
54003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  image size, the image is first resized.
54013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
54023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XMakeImage method is:
54033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
54043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      MagickBooleanType XMakeImage(Display *display,
54053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5406051718b74ad68f8584cdac01d0192974ec777f1bcristy%        unsigned int width,unsigned int height,ExceptionInfo *exception)
54073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
54083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
54093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
54103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
54113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
54123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
54133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
54143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
54153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a XWindowInfo structure.
54163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
54173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
54183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
54193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o width: Specifies the width in pixels of the rectangular area to
54203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      display.
54213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
54223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o height: Specifies the height in pixels of the rectangular area to
54233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      display.
54243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5425051718b74ad68f8584cdac01d0192974ec777f1bcristy%    o exception: return any errors or warnings in this structure.
5426051718b74ad68f8584cdac01d0192974ec777f1bcristy%
54273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
5428bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate MagickBooleanType XMakeImage(Display *display,
54293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const XResourceInfo *resource_info,XWindowInfo *window,Image *image,
5430051718b74ad68f8584cdac01d0192974ec777f1bcristy  unsigned int width,unsigned int height,ExceptionInfo *exception)
54313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
54323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define CheckOverflowException(length,width,height) \
54333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (((height) != 0) && ((length)/((size_t) height) != ((size_t) width)))
54343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
54353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
54363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    depth,
54373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    format;
54383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
54393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_t
54403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    length;
54413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
54423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XImage
54433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *matte_image,
54443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *ximage;
54453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
54463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
54473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
54483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
54493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (XWindowInfo *) NULL);
54503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(width != 0);
54513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(height != 0);
54523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((window->width == 0) || (window->height == 0))
54533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
54543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
54553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Apply user transforms to the image.
54563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
54573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
54583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFlush(display);
54593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  depth=(int) window->depth;
54603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->destroy)
54613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window->image=DestroyImage(window->image);
54623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->image=image;
54633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->destroy=MagickFalse;
54643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->image != (Image *) NULL)
54653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
54663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->crop_geometry != (char *) NULL)
54673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
54683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Image
54693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *crop_image;
54703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
54713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          RectangleInfo
54723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            crop_info;
54733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
54743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
54753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Crop image.
54763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
54773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window->image->page.x=0;
54783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window->image->page.y=0;
54793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) ParsePageGeometry(window->image,window->crop_geometry,
54806710d8414f0ed06e4eaf9346366be72e2b4719efcristy            &crop_info,exception);
54816710d8414f0ed06e4eaf9346366be72e2b4719efcristy          crop_image=CropImage(window->image,&crop_info,exception);
54823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (crop_image != (Image *) NULL)
54833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
54843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (window->image != image)
54853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                window->image=DestroyImage(window->image);
54863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              window->image=crop_image;
54873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              window->destroy=MagickTrue;
54883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
54893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
54903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((width != (unsigned int) window->image->columns) ||
54913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (height != (unsigned int) window->image->rows))
54923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
54933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Image
54943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *resize_image;
54953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
54963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
54973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Resize image.
54983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
54993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          resize_image=NewImageList();
5500865489bb885f6a74ebe640b3d61720fd4ea96d6acristy          if ((window->pixel_info->colors == 0) &&
5501865489bb885f6a74ebe640b3d61720fd4ea96d6acristy              (window->image->rows > (unsigned long) XDisplayHeight(display,window->screen)) &&
5502865489bb885f6a74ebe640b3d61720fd4ea96d6acristy              (window->image->columns > (unsigned long) XDisplayWidth(display,window->screen)))
5503865489bb885f6a74ebe640b3d61720fd4ea96d6acristy              resize_image=ResizeImage(window->image,width,height,
5504865489bb885f6a74ebe640b3d61720fd4ea96d6acristy                image->filter,exception);
55053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          else
5506865489bb885f6a74ebe640b3d61720fd4ea96d6acristy            {
5507865489bb885f6a74ebe640b3d61720fd4ea96d6acristy              if (window->image->storage_class == PseudoClass)
5508865489bb885f6a74ebe640b3d61720fd4ea96d6acristy                resize_image=SampleImage(window->image,width,height,
5509865489bb885f6a74ebe640b3d61720fd4ea96d6acristy                  exception);
5510865489bb885f6a74ebe640b3d61720fd4ea96d6acristy              else
5511865489bb885f6a74ebe640b3d61720fd4ea96d6acristy                resize_image=ThumbnailImage(window->image,width,height,
5512865489bb885f6a74ebe640b3d61720fd4ea96d6acristy                  exception);
5513865489bb885f6a74ebe640b3d61720fd4ea96d6acristy            }
55143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (resize_image != (Image *) NULL)
55153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
55163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (window->image != image)
55173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                window->image=DestroyImage(window->image);
55183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              window->image=resize_image;
55193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              window->destroy=MagickTrue;
55203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
55213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
55223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      width=(unsigned int) window->image->columns;
5523bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      assert((size_t) width == window->image->columns);
55243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      height=(unsigned int) window->image->rows;
5525bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      assert((size_t) height == window->image->rows);
55263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
55273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
55283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Create X image.
55293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
55303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ximage=(XImage *) NULL;
55313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  format=(depth == 1) ? XYBitmap : ZPixmap;
55323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
55333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->shared_memory != MagickFalse)
55343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
55353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XShmSegmentInfo
55363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *segment_info;
55373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
55383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      segment_info=(XShmSegmentInfo *) window->segment_info;
55393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      segment_info[1].shmid=(-1);
55403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      segment_info[1].shmaddr=(char *) NULL;
55413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ximage=XShmCreateImage(display,window->visual,(unsigned int) depth,format,
55423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (char *) NULL,&segment_info[1],width,height);
55433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (ximage == (XImage *) NULL)
55443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window->shared_memory=MagickFalse;
55459c5171c13c7186088b10ec322e199f60e455a7e1cristy      else
55469c5171c13c7186088b10ec322e199f60e455a7e1cristy        {
55479c5171c13c7186088b10ec322e199f60e455a7e1cristy          length=(size_t) ximage->bytes_per_line*ximage->height;
55489c5171c13c7186088b10ec322e199f60e455a7e1cristy          if (CheckOverflowException(length,ximage->bytes_per_line,ximage->height))
55499c5171c13c7186088b10ec322e199f60e455a7e1cristy            window->shared_memory=MagickFalse;
55509c5171c13c7186088b10ec322e199f60e455a7e1cristy        }
55513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->shared_memory != MagickFalse)
55523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        segment_info[1].shmid=shmget(IPC_PRIVATE,length,IPC_CREAT | 0777);
55533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->shared_memory != MagickFalse)
55543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        segment_info[1].shmaddr=(char *) shmat(segment_info[1].shmid,0,0);
55553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (segment_info[1].shmid < 0)
55563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window->shared_memory=MagickFalse;
55573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->shared_memory != MagickFalse)
55583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
55593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
55603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
55613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (ximage != (XImage *) NULL)
55623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            XDestroyImage(ximage);
55633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ximage=(XImage *) NULL;
55643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (segment_info[1].shmaddr)
55653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
55663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) shmdt(segment_info[1].shmaddr);
55673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              segment_info[1].shmaddr=(char *) NULL;
55683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
55693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (segment_info[1].shmid >= 0)
55703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
55713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
55723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              segment_info[1].shmid=(-1);
55733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
55743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
55753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
55763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
55773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
55783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Allocate X image pixel data.
55793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
55803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
55813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->shared_memory)
55823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
55833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Status
55843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        status;
55853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
55863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XShmSegmentInfo
55873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *segment_info;
55883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
55893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XSync(display,MagickFalse);
55903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      xerror_alert=MagickFalse;
55913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      segment_info=(XShmSegmentInfo *) window->segment_info;
55923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ximage->data=segment_info[1].shmaddr;
55933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      segment_info[1].readOnly=MagickFalse;
55943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      status=XShmAttach(display,&segment_info[1]);
55953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status != False)
55963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XSync(display,MagickFalse);
55973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((status == False) || (xerror_alert != MagickFalse))
55983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
55993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window->shared_memory=MagickFalse;
56003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (status != False)
56013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            XShmDetach(display,&segment_info[1]);
5602fa18e626bfb0f8953c8393f3252cbc3f0e07c80ccristy          ximage->data=NULL;
5603fa18e626bfb0f8953c8393f3252cbc3f0e07c80ccristy          XDestroyImage(ximage);
5604fa18e626bfb0f8953c8393f3252cbc3f0e07c80ccristy          ximage=(XImage *) NULL;
56053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (segment_info[1].shmid >= 0)
56063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
56073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (segment_info[1].shmaddr != NULL)
56083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (void) shmdt(segment_info[1].shmaddr);
56093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) shmctl(segment_info[1].shmid,IPC_RMID,0);
56103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              segment_info[1].shmid=(-1);
56113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              segment_info[1].shmaddr=(char *) NULL;
56123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
56133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
56143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
56153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
56163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->shared_memory == MagickFalse)
56173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ximage=XCreateImage(display,window->visual,(unsigned int) depth,format,0,
56183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (char *) NULL,width,height,XBitmapPad(display),0);
56193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (ximage == (XImage *) NULL)
56203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
56213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
56223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Unable to create X image.
56233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
56243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,window->id,window->cursor);
56253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(MagickFalse);
56263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
56273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  length=(size_t) ximage->bytes_per_line*ximage->height;
56283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (IsEventLogging())
56293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
56303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"XImage:");
56313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  width, height: %dx%d",
56323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage->width,ximage->height);
56333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  format: %d",
56343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage->format);
56353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  byte order: %d",
56363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage->byte_order);
56373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
56383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "  bitmap unit, bit order, pad: %d %d %d",ximage->bitmap_unit,
56393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage->bitmap_bit_order,ximage->bitmap_pad);
56403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  depth: %d",
56413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage->depth);
56423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  bytes per line: %d",
56433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage->bytes_per_line);
56443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  bits per pixel: %d",
56453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage->bits_per_pixel);
56463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
56473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "  red, green, blue masks: 0x%lx 0x%lx 0x%lx",ximage->red_mask,
56483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ximage->green_mask,ximage->blue_mask);
56493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
56503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->shared_memory == MagickFalse)
56513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
56523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (ximage->format != XYBitmap)
56539aecad6d644546db4165f5b6838d6e2b9d3433cfcristy        ximage->data=(char *) malloc((size_t) ximage->bytes_per_line*
56549aecad6d644546db4165f5b6838d6e2b9d3433cfcristy          ximage->height);
56553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
56569aecad6d644546db4165f5b6838d6e2b9d3433cfcristy        ximage->data=(char *) malloc((size_t) ximage->bytes_per_line*
56579aecad6d644546db4165f5b6838d6e2b9d3433cfcristy          ximage->depth*ximage->height);
56583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
56593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (ximage->data == (char *) NULL)
56603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
56613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
56623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Unable to allocate pixel data.
56633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
56643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XDestroyImage(ximage);
56653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ximage=(XImage *) NULL;
56663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,window->id,window->cursor);
56673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(MagickFalse);
56683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
56693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->ximage != (XImage *) NULL)
56703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
56713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
56723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Destroy previous X image.
56733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
56743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      length=(size_t) window->ximage->bytes_per_line*window->ximage->height;
56753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
56763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->segment_info != (XShmSegmentInfo *) NULL)
56773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
56783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          XShmSegmentInfo
56793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *segment_info;
56803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
56813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          segment_info=(XShmSegmentInfo *) window->segment_info;
56823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (segment_info[0].shmid >= 0)
56833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
56843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) XSync(display,MagickFalse);
56853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) XShmDetach(display,&segment_info[0]);
56863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) XSync(display,MagickFalse);
56873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (segment_info[0].shmaddr != (char *) NULL)
56883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (void) shmdt(segment_info[0].shmaddr);
56893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
56903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              segment_info[0].shmid=(-1);
56913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              segment_info[0].shmaddr=(char *) NULL;
56923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              window->ximage->data=(char *) NULL;
56933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
56943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
56953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
56963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->ximage->data != (char *) NULL)
56973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        free(window->ximage->data);
56983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->ximage->data=(char *) NULL;
56993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XDestroyImage(window->ximage);
57003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->ximage=(XImage *) NULL;
57013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
57023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
57033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->segment_info != (XShmSegmentInfo *) NULL)
57043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
57053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XShmSegmentInfo
57063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *segment_info;
57073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
57083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      segment_info=(XShmSegmentInfo *) window->segment_info;
57093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      segment_info[0]=segment_info[1];
57103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
57113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
57123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->ximage=ximage;
57133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  matte_image=(XImage *) NULL;
57143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((window->shape != MagickFalse) && (window->image != (Image *) NULL))
571517f11b056210f082a6d0e54ac5d68e6d72fa76b2cristy    if ((window->image->alpha_trait != UndefinedPixelTrait) &&
5716c57f694b2d04975a0e501613e34368c464708c19cristy        ((int) width <= XDisplayWidth(display,window->screen)) &&
5717c57f694b2d04975a0e501613e34368c464708c19cristy        ((int) height <= XDisplayHeight(display,window->screen)))
57183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
57193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
57203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Create matte image.
57213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
57223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        matte_image=XCreateImage(display,window->visual,1,XYBitmap,0,
57233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (char *) NULL,width,height,XBitmapPad(display),0);
57243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (IsEventLogging())
57253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
57263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) LogMagickEvent(X11Event,GetMagickModule(),"Matte Image:");
57273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) LogMagickEvent(X11Event,GetMagickModule(),
57283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "  width, height: %dx%d",matte_image->width,matte_image->height);
57293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
57303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (matte_image != (XImage *) NULL)
57313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
57323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
57333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Allocate matte image pixel data.
57343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
57359aecad6d644546db4165f5b6838d6e2b9d3433cfcristy            matte_image->data=(char *) malloc((size_t)
57369aecad6d644546db4165f5b6838d6e2b9d3433cfcristy              matte_image->bytes_per_line*matte_image->depth*
57379aecad6d644546db4165f5b6838d6e2b9d3433cfcristy              matte_image->height);
57383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (matte_image->data == (char *) NULL)
57393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
57403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                XDestroyImage(matte_image);
57413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                matte_image=(XImage *) NULL;
57423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
57433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
57443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
57453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->matte_image != (XImage *) NULL)
57463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
57473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
57483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Free matte image.
57493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
57503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->matte_image->data != (char *) NULL)
57513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        free(window->matte_image->data);
57523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->matte_image->data=(char *) NULL;
57533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XDestroyImage(window->matte_image);
57543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->matte_image=(XImage *) NULL;
57553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
57563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->matte_image=matte_image;
57573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->matte_pixmap != (Pixmap) NULL)
57583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
57593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFreePixmap(display,window->matte_pixmap);
57603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->matte_pixmap=(Pixmap) NULL;
57613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHAPE)
57623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->shape != MagickFalse)
57633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XShapeCombineMask(display,window->id,ShapeBounding,0,0,None,ShapeSet);
57643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
57653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
57663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->stasis=MagickFalse;
57673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
57683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Convert pixels to X image data.
57693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
57703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->image != (Image *) NULL)
57713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
57723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((ximage->byte_order == LSBFirst) || ((ximage->format == XYBitmap) &&
57733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (ximage->bitmap_bit_order == LSBFirst)))
57743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XMakeImageLSBFirst(resource_info,window,window->image,ximage,
5775e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy          matte_image,exception);
57763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
57773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XMakeImageMSBFirst(resource_info,window,window->image,ximage,
5778e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy          matte_image,exception);
57793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
57803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->matte_image != (XImage *) NULL)
57813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
57823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
57833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Create matte pixmap.
57843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
57853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->matte_pixmap=XCreatePixmap(display,window->id,width,height,1);
57863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->matte_pixmap != (Pixmap) NULL)
57873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
57883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          GC
57893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            graphics_context;
57903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
57913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          XGCValues
57923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            context_values;
57933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
57943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
57953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Copy matte image to matte pixmap.
57963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
57974c08aed51c5899665ade97263692328eea4af106cristy          context_values.background=0;
57984c08aed51c5899665ade97263692328eea4af106cristy          context_values.foreground=1;
57993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          graphics_context=XCreateGC(display,window->matte_pixmap,
5800bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            (size_t) (GCBackground | GCForeground),&context_values);
58013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) XPutImage(display,window->matte_pixmap,graphics_context,
58023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            window->matte_image,0,0,0,0,width,height);
58033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) XFreeGC(display,graphics_context);
58043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHAPE)
58053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (window->shape != MagickFalse)
58063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            XShapeCombineMask(display,window->id,ShapeBounding,0,0,
58073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              window->matte_pixmap,ShapeSet);
58083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
58093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
58103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
58113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XMakePixmap(display,resource_info,window);
58123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
58133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Restore cursor.
58143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
58153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XCheckDefineCursor(display,window->id,window->cursor);
58163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickTrue);
58173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
58183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
58193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
58203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
58223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
58233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
58243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy+   X M a k e I m a g e L S B F i r s t                                       %
58253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
58263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
58273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
58283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
58293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
58303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XMakeImageLSBFirst() initializes the pixel data of an X11 Image. The X image
58313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  pixels are copied in least-significant bit and byte first order.  The
58323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  server's scanline pad is respected.  Rather than using one or two general
58333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  cases, many special cases are found here to help speed up the image
58343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  conversion.
58353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
58363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XMakeImageLSBFirst method is:
58373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5838e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy%      void XMakeImageLSBFirst(Display *display,XWindows *windows,
5839e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy%        ExceptionInfo *exception)
58403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
58413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
58423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
58433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
58443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
58453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a XWindowInfo structure.
58463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
58473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
58483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
58493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o ximage: Specifies a pointer to a XImage structure;  returned from
58503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XCreateImage.
58513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
58523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o matte_image: Specifies a pointer to a XImage structure;  returned from
58533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XCreateImage.
58543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
5855e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy%    o exception: return any errors or warnings in this structure.
5856e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy%
58573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
58583ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void XMakeImageLSBFirst(const XResourceInfo *resource_info,
5859e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy  const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image,
5860e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy  ExceptionInfo *exception)
58613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
5862c57f694b2d04975a0e501613e34368c464708c19cristy  CacheView
5863c57f694b2d04975a0e501613e34368c464708c19cristy    *canvas_view;
5864c57f694b2d04975a0e501613e34368c464708c19cristy
58653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Image
58663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *canvas;
58673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
58683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
58693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y;
58703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
58714c08aed51c5899665ade97263692328eea4af106cristy  register const Quantum
58723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p;
58733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
58743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
58753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x;
58763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
58773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register unsigned char
58783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *q;
58793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
58803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned char
58813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    bit,
58823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    byte;
58833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
58843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
58853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scanline_pad;
58863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
5887f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  unsigned long
58883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel,
58893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *pixels;
58903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
58913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XStandardColormap
58923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *map_info;
58933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
58943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
58953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (XWindowInfo *) NULL);
58963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image != (Image *) NULL);
58973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image->debug != MagickFalse)
58983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
58993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  canvas=image;
5900bab87c3357f708174fd2d8ab87a0d7dbb3f70e31cristy  if ((window->immutable == MagickFalse) &&
590117f11b056210f082a6d0e54ac5d68e6d72fa76b2cristy      (image->storage_class == DirectClass) && (image->alpha_trait != UndefinedPixelTrait))
59023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
59033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      char
5904151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy        size[MagickPathExtent];
59053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
59063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Image
59073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *pattern;
59083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
59093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ImageInfo
59103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *image_info;
59113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
59123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info=AcquireImageInfo();
59133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) CopyMagickString(image_info->filename,
59143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        resource_info->image_info->texture != (char *) NULL ?
59153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        resource_info->image_info->texture : "pattern:checkerboard",
5916151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy        MagickPathExtent);
5917151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy      (void) FormatLocaleString(size,MagickPathExtent,"%.20gx%.20g",(double)
5918e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy        image->columns,(double) image->rows);
59193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info->size=ConstantString(size);
59206710d8414f0ed06e4eaf9346366be72e2b4719efcristy      pattern=ReadImage(image_info,exception);
59213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info=DestroyImageInfo(image_info);
59223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (pattern != (Image *) NULL)
59233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
59246710d8414f0ed06e4eaf9346366be72e2b4719efcristy          canvas=CloneImage(image,0,0,MagickTrue,exception);
59253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (canvas != (Image *) NULL)
592639172408bad7ef2ef00a815fa9abf9979e7857cbcristy            (void) CompositeImage(canvas,pattern,DstOverCompositeOp,MagickTrue,
5927feb3e9695150978a5d2372d3fe2f60466a7c8066cristy              0,0,exception);
59283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          pattern=DestroyImage(pattern);
59293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
59303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
59313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
59323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ximage->bits_per_pixel) >> 3));
59333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  map_info=window->map_info;
59343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixels=window->pixel_info->pixels;
59353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  q=(unsigned char *) ximage->data;
59363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=0;
593746ff2676b1044ea4101ac7a59b83289cd8f6cfdacristy  canvas_view=AcquireVirtualCacheView(canvas,exception);
59383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (ximage->format == XYBitmap)
59393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
59403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      register unsigned short
59413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        polarity;
59423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
59433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      unsigned char
59443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        background,
59453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        foreground;
59463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
59473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
59483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Convert canvas to big-endian bitmap.
59493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
59503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      background=(unsigned char)
59513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (XPixelIntensity(&window->pixel_info->foreground_color) <
59523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy         XPixelIntensity(&window->pixel_info->background_color) ? 0x80 : 0x00);
59533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      foreground=(unsigned char)
59543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (XPixelIntensity(&window->pixel_info->background_color) <
59553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy         XPixelIntensity(&window->pixel_info->foreground_color) ? 0x80 : 0x00);
595611a06d3f2cac0f17af7963e83bc6e9ebd2a377c0cristy      polarity=(unsigned short) ((GetPixelInfoIntensity(image,
5957c330609437280fe98829f3f00f43eb711084f754cristy        &canvas->colormap[0])) < (QuantumRange/2.0) ? 1 : 0);
59583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (canvas->colors == 2)
595911a06d3f2cac0f17af7963e83bc6e9ebd2a377c0cristy        polarity=GetPixelInfoIntensity(image,&canvas->colormap[0]) <
596011a06d3f2cac0f17af7963e83bc6e9ebd2a377c0cristy          GetPixelInfoIntensity(image,&canvas->colormap[1]);
59613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (y=0; y < (int) canvas->rows; y++)
59623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
5963c57f694b2d04975a0e501613e34368c464708c19cristy        p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
59646710d8414f0ed06e4eaf9346366be72e2b4719efcristy          exception);
59654c08aed51c5899665ade97263692328eea4af106cristy        if (p == (const Quantum *) NULL)
59663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
59673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        bit=0;
59683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        byte=0;
59693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        for (x=0; x < (int) canvas->columns; x++)
59703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
59713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          byte>>=1;
59724c08aed51c5899665ade97263692328eea4af106cristy          if (GetPixelIndex(canvas,p) == (Quantum) polarity)
59733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            byte|=foreground;
59743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          else
59753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            byte|=background;
59763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          bit++;
59773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (bit == 8)
59783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
59793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *q++=byte;
59803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              bit=0;
59813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              byte=0;
59823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
5983ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy          p+=GetPixelChannels(canvas);
59843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
59853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (bit != 0)
59863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          *q=byte >> (8-bit);
59873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        q+=scanline_pad;
59883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
59893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
59903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
59913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (window->pixel_info->colors != 0)
59923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      switch (ximage->bits_per_pixel)
59933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
59943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 2:
59953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
59963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
59973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble;
59983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
59993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
60003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 2 bit color-mapped X canvas.
60013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
60023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
60033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6004c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
60056710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
60064c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
60073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
60083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble=0;
60093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
60103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
60114c08aed51c5899665ade97263692328eea4af106cristy              pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)] & 0x0f;
60123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              switch (nibble)
60133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
60143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 0:
60153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
60163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=(unsigned char) pixel;
60173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
60183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
60193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
60203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 1:
60213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
60223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 2);
60233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
60243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
60253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
60263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 2:
60273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
60283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 4);
60293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
60303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
60313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
60323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 3:
60333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
60343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 6);
60353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q++;
60363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble=0;
60373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
60383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
60393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
6040ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
60413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
60423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
60433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
60443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
60453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
60463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 4:
60473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
60483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
60493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble;
60503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
60513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
60523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 4 bit color-mapped X canvas.
60533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
60543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
60553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6056c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
60576710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
60584c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
60593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
60603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble=0;
60613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
60623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
60634c08aed51c5899665ade97263692328eea4af106cristy              pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)] & 0xf;
60643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              switch (nibble)
60653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
60663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 0:
60673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
60683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=(unsigned char) pixel;
60693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
60703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
60713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
60723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 1:
60733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
60743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 4);
60753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q++;
60763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble=0;
60773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
60783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
60793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
6080ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
60813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
60823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
60833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
60843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
60853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
60863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 6:
60873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 8:
60883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
60893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
60903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 8 bit color-mapped X canvas.
60913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
60923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (resource_info->color_recovery &&
6093cbda611068350bf4459f2dda1951f8823702e129cristy              resource_info->quantize_info->dither_method != NoDitherMethod)
60943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
60956710d8414f0ed06e4eaf9346366be72e2b4719efcristy              XDitherImage(canvas,ximage,exception);
60963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
60973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
60983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
60993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6100c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
61016710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
61024c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
61033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
61043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
61053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
61064c08aed51c5899665ade97263692328eea4af106cristy              pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
61073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *q++=(unsigned char) pixel;
6108ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
61093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
61103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
61113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
61123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
61133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
61143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        default:
61153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
61163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register int
61173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            k;
61183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
61193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
61203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            bytes_per_pixel;
61213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
61223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
61233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to multi-byte color-mapped X canvas.
61243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
61253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
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              for (k=0; k < (int) bytes_per_pixel; k++)
61363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
613742daae1036998661b8574cbce1fa28d25c1a4f42cristy                *q++=(unsigned char) (pixel & 0xff);
61383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                pixel>>=8;
61393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
6140ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
61413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
61423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
61433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
61443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
61453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
61463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
61473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    else
61483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      switch (ximage->bits_per_pixel)
61493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
61503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 2:
61513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
61523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
61533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble;
61543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
61553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
61563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to contiguous 2 bit continuous-tone X canvas.
61573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
61583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
61593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
61603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble=0;
6161c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
61626710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
61634c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
61643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
61653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
61663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
61674c08aed51c5899665ade97263692328eea4af106cristy              pixel=XGammaPixel(canvas,map_info,p);
61683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              pixel&=0xf;
61693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              switch (nibble)
61703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
61713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 0:
61723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
61733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=(unsigned char) pixel;
61743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
61753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
61763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
61773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 1:
61783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
61793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 2);
61803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
61813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
61823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
61833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 2:
61843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
61853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 4);
61863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
61873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
61883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
61893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 3:
61903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
61913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 6);
61923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q++;
61933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble=0;
61943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
61953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
61963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
6197ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
61983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
61993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
62003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
62013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
62023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
62033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 4:
62043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
62053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
62063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble;
62073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
62083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
62093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to contiguous 4 bit continuous-tone X canvas.
62103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
62113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
62123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6213c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
62146710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
62154c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
62163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
62173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble=0;
62183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
62193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
62204c08aed51c5899665ade97263692328eea4af106cristy              pixel=XGammaPixel(canvas,map_info,p);
62213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              pixel&=0xf;
62223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              switch (nibble)
62233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
62243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 0:
62253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
62263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=(unsigned char) pixel;
62273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
62283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
62293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
62303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 1:
62313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
62323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 4);
62333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q++;
62343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble=0;
62353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
62363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
62373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
6238ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
62393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
62403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
62413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
62423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
62433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
62443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 6:
62453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 8:
62463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
62473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
62483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to contiguous 8 bit continuous-tone X canvas.
62493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
62503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (resource_info->color_recovery &&
6251cbda611068350bf4459f2dda1951f8823702e129cristy              resource_info->quantize_info->dither_method != NoDitherMethod)
62523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
62536710d8414f0ed06e4eaf9346366be72e2b4719efcristy              XDitherImage(canvas,ximage,exception);
62543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
62553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
62563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
62573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6258c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
62596710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
62604c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
62613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
62623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
62633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
62644c08aed51c5899665ade97263692328eea4af106cristy              pixel=XGammaPixel(canvas,map_info,p);
62653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *q++=(unsigned char) pixel;
6266ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
62673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
62683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
62693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
62703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
62713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
62723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        default:
62733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
62743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
62753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (map_info->green_max == 255) && (map_info->blue_max == 255) &&
62763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
62773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (map_info->blue_mult == 1))
62783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
62793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              /*
62803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                Convert to 32 bit continuous-tone X canvas.
62813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              */
62823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (y=0; y < (int) canvas->rows; y++)
62833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
6284c57f694b2d04975a0e501613e34368c464708c19cristy                p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
62856710d8414f0ed06e4eaf9346366be72e2b4719efcristy                  canvas->columns,1,exception);
62864c08aed51c5899665ade97263692328eea4af106cristy                if (p == (const Quantum *) NULL)
62873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
62883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
62893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    (blue_gamma != 1.0))
62903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
62913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    /*
62923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      Gamma correct canvas.
62933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    */
62943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    for (x=(int) canvas->columns-1; x >= 0; x--)
62953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
6296ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                      *q++=ScaleQuantumToChar(XBlueGamma(
62974c08aed51c5899665ade97263692328eea4af106cristy                        GetPixelBlue(canvas,p)));
6298ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                      *q++=ScaleQuantumToChar(XGreenGamma(
62994c08aed51c5899665ade97263692328eea4af106cristy                        GetPixelGreen(canvas,p)));
6300ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                      *q++=ScaleQuantumToChar(XRedGamma(
63014c08aed51c5899665ade97263692328eea4af106cristy                        GetPixelRed(canvas,p)));
63023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      *q++=0;
6303ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                      p+=GetPixelChannels(canvas);
63043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
63053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    continue;
63063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
63073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (x=(int) canvas->columns-1; x >= 0; x--)
63083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
63098bc259be59a7cde483c27474125272a7d65c5744cristy                  *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
63108bc259be59a7cde483c27474125272a7d65c5744cristy                  *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
63118bc259be59a7cde483c27474125272a7d65c5744cristy                  *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
63123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q++=0;
6313ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                  p+=GetPixelChannels(canvas);
63143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
63153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
63163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
63173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          else
63183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
63193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (map_info->green_max == 255) && (map_info->blue_max == 255) &&
63203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
63213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (map_info->blue_mult == 65536L))
63223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
63233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                /*
63243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  Convert to 32 bit continuous-tone X canvas.
63253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                */
63263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (y=0; y < (int) canvas->rows; y++)
63273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
6328c57f694b2d04975a0e501613e34368c464708c19cristy                  p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
63296710d8414f0ed06e4eaf9346366be72e2b4719efcristy                    canvas->columns,1,exception);
63304c08aed51c5899665ade97263692328eea4af106cristy                  if (p == (const Quantum *) NULL)
63313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    break;
63323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
63333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      (blue_gamma != 1.0))
63343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
63353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      /*
63363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        Gamma correct canvas.
63373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      */
63383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      for (x=(int) canvas->columns-1; x >= 0; x--)
63393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      {
6340ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                        *q++=ScaleQuantumToChar(XRedGamma(
63414c08aed51c5899665ade97263692328eea4af106cristy                          GetPixelRed(canvas,p)));
6342ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                        *q++=ScaleQuantumToChar(XGreenGamma(
63434c08aed51c5899665ade97263692328eea4af106cristy                          GetPixelGreen(canvas,p)));
6344ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                        *q++=ScaleQuantumToChar(XBlueGamma(
63454c08aed51c5899665ade97263692328eea4af106cristy                          GetPixelBlue(canvas,p)));
63463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        *q++=0;
6347ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                        p+=GetPixelChannels(canvas);
63483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      }
63493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      continue;
63503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
63513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  for (x=(int) canvas->columns-1; x >= 0; x--)
63523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
63538bc259be59a7cde483c27474125272a7d65c5744cristy                    *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
63548bc259be59a7cde483c27474125272a7d65c5744cristy                    *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
63558bc259be59a7cde483c27474125272a7d65c5744cristy                    *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
63563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    *q++=0;
6357ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                    p+=GetPixelChannels(canvas);
63583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
63593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
63603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
63613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            else
63623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
63633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                register int
63643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  k;
63653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
63663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                register unsigned int
63673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  bytes_per_pixel;
63683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
63693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                /*
63703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  Convert to multi-byte continuous-tone X canvas.
63713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                */
63723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
63733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (y=0; y < (int) canvas->rows; y++)
63743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
6375c57f694b2d04975a0e501613e34368c464708c19cristy                  p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
63766710d8414f0ed06e4eaf9346366be72e2b4719efcristy                    canvas->columns,1,exception);
63774c08aed51c5899665ade97263692328eea4af106cristy                  if (p == (const Quantum *) NULL)
63783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    break;
6379c57f694b2d04975a0e501613e34368c464708c19cristy                  for (x=0; x < (int) canvas->columns; x++)
63803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
63814c08aed51c5899665ade97263692328eea4af106cristy                    pixel=XGammaPixel(canvas,map_info,p);
63823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    for (k=0; k < (int) bytes_per_pixel; k++)
63833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
638442daae1036998661b8574cbce1fa28d25c1a4f42cristy                      *q++=(unsigned char) (pixel & 0xff);
63853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      pixel>>=8;
63863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
6387ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                    p+=GetPixelChannels(canvas);
63883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
63893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q+=scanline_pad;
63903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
63913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
63923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
63933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
63943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
63953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (matte_image != (XImage *) NULL)
63963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
63973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
63983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Initialize matte canvas.
63993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
64003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      scanline_pad=(unsigned int) (matte_image->bytes_per_line-
64013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ((matte_image->width*matte_image->bits_per_pixel) >> 3));
64023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      q=(unsigned char *) matte_image->data;
64033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (y=0; y < (int) canvas->rows; y++)
64043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
6405c57f694b2d04975a0e501613e34368c464708c19cristy        p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
64066710d8414f0ed06e4eaf9346366be72e2b4719efcristy          exception);
64074c08aed51c5899665ade97263692328eea4af106cristy        if (p == (const Quantum *) NULL)
64083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
64093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        bit=0;
64103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        byte=0;
64113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        for (x=(int) canvas->columns-1; x >= 0; x--)
64123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
64133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          byte>>=1;
64144c08aed51c5899665ade97263692328eea4af106cristy          if (GetPixelAlpha(canvas,p) > (QuantumRange/2))
64153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            byte|=0x80;
64163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          bit++;
64173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (bit == 8)
64183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
64193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *q++=byte;
64203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              bit=0;
64213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              byte=0;
64223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
6423ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy          p+=GetPixelChannels(canvas);
64243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
64253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (bit != 0)
64263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          *q=byte >> (8-bit);
64273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        q+=scanline_pad;
64283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
64293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
6430c57f694b2d04975a0e501613e34368c464708c19cristy  canvas_view=DestroyCacheView(canvas_view);
64313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (canvas != image)
64323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    canvas=DestroyImage(canvas);
64333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
64343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
64353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
64363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
64383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
64393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
64403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy+   X M a k e I m a g e M S B F i r s t                                       %
64413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
64423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
64433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
64443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
64463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XMakeImageMSBFirst() initializes the pixel data of an X11 Image.  The X
64473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  image pixels are copied in most-significant bit and byte first order.  The
64483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  server's scanline pad is also respected. Rather than using one or two
64493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  general cases, many special cases are found here to help speed up the image
64503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  conversion.
64513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
64523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XMakeImageMSBFirst method is:
64533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6454e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy%      XMakeImageMSBFirst(resource_info,window,image,ximage,matte_image,
6455e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy%        ExceptionInfo *exception)
64563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
64573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
64583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
64593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
64603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
64613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a XWindowInfo structure.
64623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
64633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
64643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
64653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o ximage: Specifies a pointer to a XImage structure;  returned from
64663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XCreateImage.
64673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
64683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o matte_image: Specifies a pointer to a XImage structure;  returned from
64693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XCreateImage.
64703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
6471e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy%    o exception: return any errors or warnings in this structure.
6472e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy%
64733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
64743ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void XMakeImageMSBFirst(const XResourceInfo *resource_info,
6475e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy  const XWindowInfo *window,Image *image,XImage *ximage,XImage *matte_image,
6476e941a75fe8bf344bc5c06a7f74bb5173c87db115cristy  ExceptionInfo *exception)
64773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
6478c57f694b2d04975a0e501613e34368c464708c19cristy  CacheView
6479c57f694b2d04975a0e501613e34368c464708c19cristy    *canvas_view;
6480c57f694b2d04975a0e501613e34368c464708c19cristy
64813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Image
64823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *canvas;
64833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
64843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
64853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y;
64863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
64873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
64883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x;
64893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
64904c08aed51c5899665ade97263692328eea4af106cristy  register const Quantum
64913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p;
64923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
64933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register unsigned char
64943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *q;
64953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
64963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned char
64973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    bit,
64983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    byte;
64993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
65003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
65013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scanline_pad;
65023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
6503f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  unsigned long
65043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel,
65053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *pixels;
65063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
65073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XStandardColormap
65083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *map_info;
65093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
65103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
65113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (XWindowInfo *) NULL);
65123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image != (Image *) NULL);
65133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image->debug != MagickFalse)
65143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
65153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  canvas=image;
651654666e85e8e3b0eca47d318178a186ebb2901a73cristy  if ((window->immutable != MagickFalse) &&
651711a06d3f2cac0f17af7963e83bc6e9ebd2a377c0cristy      (image->storage_class == DirectClass) &&
651811a06d3f2cac0f17af7963e83bc6e9ebd2a377c0cristy      (image->alpha_trait != UndefinedPixelTrait))
65193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
65203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      char
6521151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy        size[MagickPathExtent];
65223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
65233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Image
65243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *pattern;
65253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
65263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ImageInfo
65273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *image_info;
65283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
65293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info=AcquireImageInfo();
65303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) CopyMagickString(image_info->filename,
65313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        resource_info->image_info->texture != (char *) NULL ?
65323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        resource_info->image_info->texture : "pattern:checkerboard",
6533151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy        MagickPathExtent);
6534151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy      (void) FormatLocaleString(size,MagickPathExtent,"%.20gx%.20g",(double)
6535e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy        image->columns,(double) image->rows);
65363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info->size=ConstantString(size);
65376710d8414f0ed06e4eaf9346366be72e2b4719efcristy      pattern=ReadImage(image_info,exception);
65383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info=DestroyImageInfo(image_info);
65393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (pattern != (Image *) NULL)
65403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
65416710d8414f0ed06e4eaf9346366be72e2b4719efcristy          canvas=CloneImage(image,0,0,MagickTrue,exception);
65423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (canvas != (Image *) NULL)
6543feb3e9695150978a5d2372d3fe2f60466a7c8066cristy            (void) CompositeImage(canvas,pattern,DstOverCompositeOp,MagickFalse,
6544feb3e9695150978a5d2372d3fe2f60466a7c8066cristy              0,0,exception);
65453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          pattern=DestroyImage(pattern);
65463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
65473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
65484c08aed51c5899665ade97263692328eea4af106cristy  scanline_pad=(unsigned int) (ximage->bytes_per_line-((ximage->width*
65494c08aed51c5899665ade97263692328eea4af106cristy    ximage->bits_per_pixel) >> 3));
65503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  map_info=window->map_info;
65513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixels=window->pixel_info->pixels;
65523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  q=(unsigned char *) ximage->data;
65533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=0;
655446ff2676b1044ea4101ac7a59b83289cd8f6cfdacristy  canvas_view=AcquireVirtualCacheView(canvas,exception);
65553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (ximage->format == XYBitmap)
65563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
65573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      register unsigned short
65583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        polarity;
65593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
65603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      unsigned char
65613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        background,
65623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        foreground;
65633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
65643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
65653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Convert canvas to big-endian bitmap.
65663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
65673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      background=(unsigned char)
65683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (XPixelIntensity(&window->pixel_info->foreground_color) <
65693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy         XPixelIntensity(&window->pixel_info->background_color) ?  0x01 : 0x00);
65703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      foreground=(unsigned char)
65713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (XPixelIntensity(&window->pixel_info->background_color) <
65723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy         XPixelIntensity(&window->pixel_info->foreground_color) ?  0x01 : 0x00);
657311a06d3f2cac0f17af7963e83bc6e9ebd2a377c0cristy      polarity=(unsigned short) ((GetPixelInfoIntensity(image,
6574c330609437280fe98829f3f00f43eb711084f754cristy        &canvas->colormap[0])) < (QuantumRange/2.0) ? 1 : 0);
65753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (canvas->colors == 2)
657611a06d3f2cac0f17af7963e83bc6e9ebd2a377c0cristy        polarity=GetPixelInfoIntensity(image,&canvas->colormap[0]) <
657711a06d3f2cac0f17af7963e83bc6e9ebd2a377c0cristy          GetPixelInfoIntensity(image,&canvas->colormap[1]);
65783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (y=0; y < (int) canvas->rows; y++)
65793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
6580c57f694b2d04975a0e501613e34368c464708c19cristy        p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
65816710d8414f0ed06e4eaf9346366be72e2b4719efcristy          exception);
65824c08aed51c5899665ade97263692328eea4af106cristy        if (p == (const Quantum *) NULL)
65833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
65843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        bit=0;
65853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        byte=0;
65863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        for (x=(int) canvas->columns-1; x >= 0; x--)
65873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
65883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          byte<<=1;
65894c08aed51c5899665ade97263692328eea4af106cristy          if (GetPixelIndex(canvas,p) == (Quantum) polarity)
65903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            byte|=foreground;
65913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          else
65923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            byte|=background;
65933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          bit++;
65943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (bit == 8)
65953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
65963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *q++=byte;
65973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              bit=0;
65983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              byte=0;
65993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
6600ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy          p+=GetPixelChannels(canvas);
66013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
66023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (bit != 0)
66033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          *q=byte << (8-bit);
66043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        q+=scanline_pad;
66053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
66063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
66073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
66083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (window->pixel_info->colors != 0)
66093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      switch (ximage->bits_per_pixel)
66103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
66113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 2:
66123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
66133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
66143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble;
66153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
66163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
66173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 2 bit color-mapped X canvas.
66183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
66193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
66203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6621c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
66226710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
66234c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
66243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
66253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble=0;
66263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
66273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
66284c08aed51c5899665ade97263692328eea4af106cristy              pixel=pixels[(ssize_t)
66294c08aed51c5899665ade97263692328eea4af106cristy                GetPixelIndex(canvas,p)] & 0xf;
66303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              switch (nibble)
66313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
66323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 0:
66333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
66343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=(unsigned char) (pixel << 6);
66353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
66363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
66373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
66383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 1:
66393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
66403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 4);
66413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
66423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
66433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
66443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 2:
66453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
66463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 2);
66473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
66483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
66493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
66503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 3:
66513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
66523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) pixel;
66533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q++;
66543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble=0;
66553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
66563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
66573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
6658ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
66593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
66603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
66613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
66623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
66633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
66643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 4:
66653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
66663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
66673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble;
66683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
66693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
66703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 4 bit color-mapped X canvas.
66713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
66723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
66733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6674c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
66756710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
66764c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
66773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
66783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble=0;
66793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
66803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
66814c08aed51c5899665ade97263692328eea4af106cristy              pixel=pixels[(ssize_t)
66824c08aed51c5899665ade97263692328eea4af106cristy                GetPixelIndex(canvas,p)] & 0xf;
66833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              switch (nibble)
66843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
66853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 0:
66863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
66873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=(unsigned char) (pixel << 4);
66883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
66893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
66903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
66913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 1:
66923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
66933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) pixel;
66943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q++;
66953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble=0;
66963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
66973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
66983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
6699ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
67003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
67013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
67023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
67033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
67043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
67053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 6:
67063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 8:
67073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
67083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
67093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 8 bit color-mapped X canvas.
67103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
67113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (resource_info->color_recovery &&
6712cbda611068350bf4459f2dda1951f8823702e129cristy              resource_info->quantize_info->dither_method != NoDitherMethod)
67133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
67146710d8414f0ed06e4eaf9346366be72e2b4719efcristy              XDitherImage(canvas,ximage,exception);
67153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
67163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
67173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
67183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6719c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
67206710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
67214c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
67223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
67233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
67243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
67256710d8414f0ed06e4eaf9346366be72e2b4719efcristy              pixel=pixels[(ssize_t) GetPixelIndex(canvas,p)];
67263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *q++=(unsigned char) pixel;
6727ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
67283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
67293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
67303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
67313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
67323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
67333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        default:
67343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
67353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register int
67363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            k;
67373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
67383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
67393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            bytes_per_pixel;
67403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
67413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          unsigned char
6742bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            channel[sizeof(size_t)];
67433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
67443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
67453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 8 bit color-mapped X canvas.
67463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
67473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
67483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
67493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6750c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
67516710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
67524c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
67533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
67543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=0; x < (int) canvas->columns; x++)
67553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
67564c08aed51c5899665ade97263692328eea4af106cristy              pixel=pixels[(ssize_t)
67574c08aed51c5899665ade97263692328eea4af106cristy                GetPixelIndex(canvas,p)];
67583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (k=(int) bytes_per_pixel-1; k >= 0; k--)
67593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
67603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                channel[k]=(unsigned char) pixel;
67613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                pixel>>=8;
67623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
67633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (k=0; k < (int) bytes_per_pixel; k++)
67643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                *q++=channel[k];
6765ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
67663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
67673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
67683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
67693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
67703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
67713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
67723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    else
67733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      switch (ximage->bits_per_pixel)
67743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
67753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 2:
67763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
67773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
67783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble;
67793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
67803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
67813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 4 bit continuous-tone X canvas.
67823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
67833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
67843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6785c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
67866710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
67874c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
67883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
67893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble=0;
67903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=(int) canvas->columns-1; x >= 0; x--)
67913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
67924c08aed51c5899665ade97263692328eea4af106cristy              pixel=XGammaPixel(canvas,map_info,p);
67933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              pixel&=0xf;
67943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              switch (nibble)
67953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
67963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 0:
67973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
67983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=(unsigned char) (pixel << 6);
67993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
68003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
68013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
68023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 1:
68033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
68043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 4);
68053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
68063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
68073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
68083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 2:
68093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
68103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) (pixel << 2);
68113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
68123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
68133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
68143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 3:
68153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
68163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) pixel;
68173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q++;
68183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble=0;
68193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
68203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
68213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
6822ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
68233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
68243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
68253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
68263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
68273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
68283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 4:
68293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
68303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register unsigned int
68313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble;
68323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
68333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
68343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 4 bit continuous-tone X canvas.
68353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
68363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
68373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6838c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
68396710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
68404c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
68413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
68423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            nibble=0;
68433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=(int) canvas->columns-1; x >= 0; x--)
68443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
68454c08aed51c5899665ade97263692328eea4af106cristy              pixel=XGammaPixel(canvas,map_info,p);
68463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              pixel&=0xf;
68473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              switch (nibble)
68483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
68493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 0:
68503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
68513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=(unsigned char) (pixel << 4);
68523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble++;
68533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
68543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
68553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                case 1:
68563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
68573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q|=(unsigned char) pixel;
68583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q++;
68593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  nibble=0;
68603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
68613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
68623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
6863ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
68643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
68653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
68663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
68673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
68683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
68693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 6:
68703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case 8:
68713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
68723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
68733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Convert to 8 bit continuous-tone X canvas.
68743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
68753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (resource_info->color_recovery &&
6876cbda611068350bf4459f2dda1951f8823702e129cristy              resource_info->quantize_info->dither_method != NoDitherMethod)
68773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
68786710d8414f0ed06e4eaf9346366be72e2b4719efcristy              XDitherImage(canvas,ximage,exception);
68793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
68803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
68813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) canvas->rows; y++)
68823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
6883c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
68846710d8414f0ed06e4eaf9346366be72e2b4719efcristy              canvas->columns,1,exception);
68854c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
68863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
68873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (x=(int) canvas->columns-1; x >= 0; x--)
68883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
68894c08aed51c5899665ade97263692328eea4af106cristy              pixel=XGammaPixel(canvas,map_info,p);
68903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *q++=(unsigned char) pixel;
6891ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(canvas);
68923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
68933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
68943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
68953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
68963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
68973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        default:
68983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
68993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
69003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (map_info->green_max == 255) && (map_info->blue_max == 255) &&
69013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (map_info->red_mult == 65536L) && (map_info->green_mult == 256) &&
69023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (map_info->blue_mult == 1))
69033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
69043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              /*
69053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                Convert to 32 bit continuous-tone X canvas.
69063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              */
69073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (y=0; y < (int) canvas->rows; y++)
69083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
6909c57f694b2d04975a0e501613e34368c464708c19cristy                p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
69106710d8414f0ed06e4eaf9346366be72e2b4719efcristy                  canvas->columns,1,exception);
69114c08aed51c5899665ade97263692328eea4af106cristy                if (p == (const Quantum *) NULL)
69123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  break;
69133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
69143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    (blue_gamma != 1.0))
69153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
69163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    /*
69173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      Gamma correct canvas.
69183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    */
69193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    for (x=(int) canvas->columns-1; x >= 0; x--)
69203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
69213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      *q++=0;
6922ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                      *q++=ScaleQuantumToChar(XRedGamma(
69234c08aed51c5899665ade97263692328eea4af106cristy                        GetPixelRed(canvas,p)));
6924ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                      *q++=ScaleQuantumToChar(XGreenGamma(
69254c08aed51c5899665ade97263692328eea4af106cristy                        GetPixelGreen(canvas,p)));
6926ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                      *q++=ScaleQuantumToChar(XBlueGamma(
69274c08aed51c5899665ade97263692328eea4af106cristy                        GetPixelBlue(canvas,p)));
6928ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                      p+=GetPixelChannels(canvas);
69293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
69303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    continue;
69313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
69323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (x=(int) canvas->columns-1; x >= 0; x--)
69333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
69343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q++=0;
69358bc259be59a7cde483c27474125272a7d65c5744cristy                  *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
69368bc259be59a7cde483c27474125272a7d65c5744cristy                  *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
69378bc259be59a7cde483c27474125272a7d65c5744cristy                  *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
6938ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                  p+=GetPixelChannels(canvas);
69393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
69403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
69413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
69423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          else
69433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if ((ximage->bits_per_pixel == 32) && (map_info->red_max == 255) &&
69443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (map_info->green_max == 255) && (map_info->blue_max == 255) &&
69453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (map_info->red_mult == 1) && (map_info->green_mult == 256) &&
69463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (map_info->blue_mult == 65536L))
69473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
69483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                /*
69493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  Convert to 32 bit continuous-tone X canvas.
69503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                */
69513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (y=0; y < (int) canvas->rows; y++)
69523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
6953c57f694b2d04975a0e501613e34368c464708c19cristy                  p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
69546710d8414f0ed06e4eaf9346366be72e2b4719efcristy                    canvas->columns,1,exception);
69554c08aed51c5899665ade97263692328eea4af106cristy                  if (p == (const Quantum *) NULL)
69563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    break;
69573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if ((red_gamma != 1.0) || (green_gamma != 1.0) ||
69583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      (blue_gamma != 1.0))
69593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
69603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      /*
69613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        Gamma correct canvas.
69623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      */
69633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      for (x=(int) canvas->columns-1; x >= 0; x--)
69643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      {
69653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        *q++=0;
6966ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                        *q++=ScaleQuantumToChar(XBlueGamma(
69674c08aed51c5899665ade97263692328eea4af106cristy                          GetPixelBlue(canvas,p)));
6968ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                        *q++=ScaleQuantumToChar(XGreenGamma(
69694c08aed51c5899665ade97263692328eea4af106cristy                          GetPixelGreen(canvas,p)));
6970ccf844f01bcfb63e8c6260bc986878089bb4c85bcristy                        *q++=ScaleQuantumToChar(XRedGamma(
69714c08aed51c5899665ade97263692328eea4af106cristy                          GetPixelRed(canvas,p)));
6972ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                        p+=GetPixelChannels(canvas);
69733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      }
69743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      continue;
69753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
69763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  for (x=(int) canvas->columns-1; x >= 0; x--)
69773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
69783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    *q++=0;
69798bc259be59a7cde483c27474125272a7d65c5744cristy                    *q++=ScaleQuantumToChar((Quantum) GetPixelBlue(canvas,p));
69808bc259be59a7cde483c27474125272a7d65c5744cristy                    *q++=ScaleQuantumToChar((Quantum) GetPixelGreen(canvas,p));
69818bc259be59a7cde483c27474125272a7d65c5744cristy                    *q++=ScaleQuantumToChar((Quantum) GetPixelRed(canvas,p));
6982ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                    p+=GetPixelChannels(canvas);
69833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
69843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
69853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
69863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            else
69873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
69883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                register int
69893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  k;
69903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
69913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                register unsigned int
69923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  bytes_per_pixel;
69933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
69943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                unsigned char
6995bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy                  channel[sizeof(size_t)];
69963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
69973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                /*
69983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  Convert to multi-byte continuous-tone X canvas.
69993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                */
70003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                bytes_per_pixel=(unsigned int) (ximage->bits_per_pixel >> 3);
70013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (y=0; y < (int) canvas->rows; y++)
70023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
7003c57f694b2d04975a0e501613e34368c464708c19cristy                  p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,
70046710d8414f0ed06e4eaf9346366be72e2b4719efcristy                    canvas->columns,1,exception);
70054c08aed51c5899665ade97263692328eea4af106cristy                  if (p == (const Quantum *) NULL)
70063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    break;
70073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  for (x=(int) canvas->columns-1; x >= 0; x--)
70083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
70094c08aed51c5899665ade97263692328eea4af106cristy                    pixel=XGammaPixel(canvas,map_info,p);
70103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    for (k=(int) bytes_per_pixel-1; k >= 0; k--)
70113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    {
70123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      channel[k]=(unsigned char) pixel;
70133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      pixel>>=8;
70143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    }
70153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    for (k=0; k < (int) bytes_per_pixel; k++)
70163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      *q++=channel[k];
7017ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                    p+=GetPixelChannels(canvas);
70183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
70193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  q+=scanline_pad;
70203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
70213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
70223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
70233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
70243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
70253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (matte_image != (XImage *) NULL)
70263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
70273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
70283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Initialize matte canvas.
70293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
70303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      scanline_pad=(unsigned int) (matte_image->bytes_per_line-
70313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ((matte_image->width*matte_image->bits_per_pixel) >> 3));
70323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      q=(unsigned char *) matte_image->data;
70333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (y=0; y < (int) canvas->rows; y++)
70343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
7035c57f694b2d04975a0e501613e34368c464708c19cristy        p=GetCacheViewVirtualPixels(canvas_view,0,(ssize_t) y,canvas->columns,1,
70366710d8414f0ed06e4eaf9346366be72e2b4719efcristy          exception);
70374c08aed51c5899665ade97263692328eea4af106cristy        if (p == (const Quantum *) NULL)
70383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
70393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        bit=0;
70403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        byte=0;
70413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        for (x=(int) canvas->columns-1; x >= 0; x--)
70423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
70433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          byte<<=1;
70444c08aed51c5899665ade97263692328eea4af106cristy          if (GetPixelAlpha(canvas,p) > (QuantumRange/2))
70453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            byte|=0x01;
70463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          bit++;
70473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (bit == 8)
70483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
70493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *q++=byte;
70503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              bit=0;
70513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              byte=0;
70523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
7053ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy          p+=GetPixelChannels(canvas);
70543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
70553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (bit != 0)
70563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          *q=byte << (8-bit);
70573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        q+=scanline_pad;
70583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
70593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
7060c57f694b2d04975a0e501613e34368c464708c19cristy  canvas_view=DestroyCacheView(canvas_view);
70613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (canvas != image)
70623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    canvas=DestroyImage(canvas);
70633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
70643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
70653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
70663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
70683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
70693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
70703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X M a k e M a g n i f y I m a g e                                         %
70713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
70723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
70733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
70743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
70763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XMakeMagnifyImage() magnifies a region of an X image and displays it.
70773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
70783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XMakeMagnifyImage method is:
70793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
70806710d8414f0ed06e4eaf9346366be72e2b4719efcristy%      void XMakeMagnifyImage(Display *display,XWindows *windows,
70816710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        ExceptionInfo *exception)
70823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
70833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
70843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
70853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
70863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
70873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
70883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o windows: Specifies a pointer to a XWindows structure.
70893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
70906710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    o exception: return any errors or warnings in this structure.
70916710d8414f0ed06e4eaf9346366be72e2b4719efcristy%
70923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
70936710d8414f0ed06e4eaf9346366be72e2b4719efcristyMagickPrivate void XMakeMagnifyImage(Display *display,XWindows *windows,
70946710d8414f0ed06e4eaf9346366be72e2b4719efcristy  ExceptionInfo *exception)
70953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
70963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
7097151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    tuple[MagickPathExtent];
70983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
70993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
71003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y;
71013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71024c08aed51c5899665ade97263692328eea4af106cristy  PixelInfo
71033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixel;
71043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
71063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x;
71073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7108bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  register ssize_t
71093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
71103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register unsigned char
71123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p,
71133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *q;
71143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71159d314ff2c17a77996c05413c2013880387e50f0ecristy  ssize_t
71169d314ff2c17a77996c05413c2013880387e50f0ecristy    n;
71179d314ff2c17a77996c05413c2013880387e50f0ecristy
71183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static unsigned int
71193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    previous_magnify = 0;
71203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static XWindowInfo
71223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    magnify_window;
71233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
71253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    height,
71263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    j,
71273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    k,
71283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    l,
71293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    magnify,
71303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    scanline_pad,
71313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    width;
71323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XImage
71343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *ximage;
71353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
71373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Check boundary conditions.
71383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
71393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
71403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
71413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(windows != (XWindows *) NULL);
71423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magnify=1;
7143bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  for (n=1; n < (ssize_t) windows->magnify.data; n++)
71443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    magnify<<=1;
71453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while ((magnify*windows->image.ximage->width) < windows->magnify.width)
71463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    magnify<<=1;
71473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while ((magnify*windows->image.ximage->height) < windows->magnify.height)
71483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    magnify<<=1;
71493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while (magnify > windows->magnify.width)
71503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    magnify>>=1;
71513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  while (magnify > windows->magnify.height)
71523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    magnify>>=1;
715358a749ec1fc5d48a2ea305d892aa6004454bb5eacristy  if (magnify == 0)
715458a749ec1fc5d48a2ea305d892aa6004454bb5eacristy    magnify=1;
71553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (magnify != previous_magnify)
71563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
71573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Status
71583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        status;
71593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XTextProperty
71613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window_name;
71623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
71633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
71643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        New magnify factor:  update magnify window name.
71653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
71663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      i=0;
71673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      while ((1 << i) <= (int) magnify)
71683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        i++;
7169151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy      (void) FormatLocaleString(windows->magnify.name,MagickPathExtent,
7170e8c25f9b4c9fb72cad6db08eeda58c7c5784014ecristy        "Magnify %.20gX",(double) i);
71713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      status=XStringListToTextProperty(&windows->magnify.name,1,&window_name);
71723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status != False)
71733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
71743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          XSetWMName(display,windows->magnify.id,&window_name);
71753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          XSetWMIconName(display,windows->magnify.id,&window_name);
71763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) XFree((void *) window_name.value);
71773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
71783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
71793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  previous_magnify=magnify;
71803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ximage=windows->image.ximage;
71813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  width=(unsigned int) windows->magnify.ximage->width;
71823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  height=(unsigned int) windows->magnify.ximage->height;
71833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((windows->magnify.x < 0) ||
71843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (windows->magnify.x >= windows->image.ximage->width))
71853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    windows->magnify.x=windows->image.ximage->width >> 1;
71863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=windows->magnify.x-((width/magnify) >> 1);
71873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (x < 0)
71883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x=0;
71893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
71903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (x > (int) (ximage->width-(width/magnify)))
71913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      x=ximage->width-width/magnify;
71923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((windows->magnify.y < 0) ||
71933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (windows->magnify.y >= windows->image.ximage->height))
71943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    windows->magnify.y=windows->image.ximage->height >> 1;
71953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y=windows->magnify.y-((height/magnify) >> 1);
71963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (y < 0)
71973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y=0;
71983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
71993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (y > (int) (ximage->height-(height/magnify)))
72003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      y=ximage->height-height/magnify;
72013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  q=(unsigned char *) windows->magnify.ximage->data;
72023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  scanline_pad=(unsigned int) (windows->magnify.ximage->bytes_per_line-
72033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ((width*windows->magnify.ximage->bits_per_pixel) >> 3));
72043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (ximage->bits_per_pixel < 8)
72053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
72063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      register unsigned char
72073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        background,
72083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        byte,
72093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        foreground,
72103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        p_bit,
72113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        q_bit;
72123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
72133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      register unsigned int
72143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        plane;
72153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
72163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XPixelInfo
72173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *pixel_info;
72183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
72193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      pixel_info=windows->magnify.pixel_info;
72203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      switch (ximage->bitmap_bit_order)
72213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
72223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case LSBFirst:
72233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
72243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
72253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Magnify little-endian bitmap.
72263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
72273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          background=0x00;
72283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          foreground=0x80;
72293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (ximage->format == XYBitmap)
72303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
72313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              background=(unsigned char)
72323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (XPixelIntensity(&pixel_info->foreground_color) <
72333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                 XPixelIntensity(&pixel_info->background_color) ?  0x80 : 0x00);
72343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              foreground=(unsigned char)
72353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (XPixelIntensity(&pixel_info->background_color) <
72363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                 XPixelIntensity(&pixel_info->foreground_color) ?  0x80 : 0x00);
72373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (windows->magnify.depth > 1)
72383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                Swap(background,foreground);
72393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
7240bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy          for (i=0; i < (ssize_t) height; i+=magnify)
72413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
72423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
72433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Propogate pixel magnify rows.
72443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
72453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (j=0; j < magnify; j++)
72463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
72473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
72483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                ((x*ximage->bits_per_pixel) >> 3);
72493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
72503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              q_bit=0;
72513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              byte=0;
72523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (k=0; k < width; k+=magnify)
72533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
72543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                /*
72553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  Propogate pixel magnify columns.
72563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                */
72573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (l=0; l < magnify; l++)
72583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
72593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  /*
72603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    Propogate each bit plane.
72613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  */
72623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
72633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
72643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    byte>>=1;
72653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    if (*p & (0x01 << (p_bit+plane)))
72663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      byte|=foreground;
72673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    else
72683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      byte|=background;
72693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    q_bit++;
72703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    if (q_bit == 8)
72713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      {
72723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        *q++=byte;
72733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        q_bit=0;
72743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        byte=0;
72753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      }
72763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
72773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
72783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                p_bit+=ximage->bits_per_pixel;
72793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if (p_bit == 8)
72803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
72813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    p++;
72823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    p_bit=0;
72833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
72843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if (q_bit != 0)
72853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=byte >> (8-q_bit);
72863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                q+=scanline_pad;
72873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
72883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
72893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            y++;
72903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
72913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
72923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
72933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        case MSBFirst:
72943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        default:
72953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
72963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
72973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Magnify big-endian bitmap.
72983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
72993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          background=0x00;
73003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          foreground=0x01;
73013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (ximage->format == XYBitmap)
73023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
73033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              background=(unsigned char)
73043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (XPixelIntensity(&pixel_info->foreground_color) <
73053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                 XPixelIntensity(&pixel_info->background_color) ?  0x01 : 0x00);
73063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              foreground=(unsigned char)
73073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (XPixelIntensity(&pixel_info->background_color) <
73083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                 XPixelIntensity(&pixel_info->foreground_color) ?  0x01 : 0x00);
73093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              if (windows->magnify.depth > 1)
73103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                Swap(background,foreground);
73113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
7312bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy          for (i=0; i < (ssize_t) height; i+=magnify)
73133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
73143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
73153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Propogate pixel magnify rows.
73163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
73173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (j=0; j < magnify; j++)
73183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
73193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
73203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                ((x*ximage->bits_per_pixel) >> 3);
73213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              p_bit=(unsigned char) (x*ximage->bits_per_pixel) & 0x07;
73223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              q_bit=0;
73233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              byte=0;
73243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (k=0; k < width; k+=magnify)
73253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
73263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                /*
73273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  Propogate pixel magnify columns.
73283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                */
73293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (l=0; l < magnify; l++)
73303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
73313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  /*
73323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    Propogate each bit plane.
73333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  */
73343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  for (plane=0; (int) plane < ximage->bits_per_pixel; plane++)
73353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
73363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    byte<<=1;
73373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    if (*p & (0x80 >> (p_bit+plane)))
73383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      byte|=foreground;
73393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    else
73403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      byte|=background;
73413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    q_bit++;
73423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    if (q_bit == 8)
73433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      {
73443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        *q++=byte;
73453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        q_bit=0;
73463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                        byte=0;
73473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                      }
73483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
73493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
73503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                p_bit+=ximage->bits_per_pixel;
73513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if (p_bit == 8)
73523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  {
73533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    p++;
73543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                    p_bit=0;
73553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  }
73563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                if (q_bit != 0)
73573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q=byte << (8-q_bit);
73583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                q+=scanline_pad;
73593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
73603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
73613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            y++;
73623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
73633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
73643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
73653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
73663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
73673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
73683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    switch (ximage->bits_per_pixel)
73693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
73703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case 6:
73713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case 8:
73723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
73733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
73743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Magnify 8 bit X image.
73753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
7376bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        for (i=0; i < (ssize_t) height; i+=magnify)
73773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
73783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
73793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Propogate pixel magnify rows.
73803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
73813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (j=0; j < magnify; j++)
73823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
73833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
73843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ((x*ximage->bits_per_pixel) >> 3);
73853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (k=0; k < width; k+=magnify)
73863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
73873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              /*
73883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                Propogate pixel magnify columns.
73893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              */
73903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (l=0; l < magnify; l++)
73913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                *q++=(*p);
73923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              p++;
73933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
73943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
73953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
73963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          y++;
73973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
73983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
73993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
74003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      default:
74013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
74023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        register unsigned int
74033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          bytes_per_pixel,
74043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          m;
74053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
74063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
74073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Magnify multi-byte X image.
74083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
74093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        bytes_per_pixel=(unsigned int) ximage->bits_per_pixel >> 3;
7410bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        for (i=0; i < (ssize_t) height; i+=magnify)
74113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
74123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
74133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Propogate pixel magnify rows.
74143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
74153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (j=0; j < magnify; j++)
74163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
74173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            p=(unsigned char *) ximage->data+y*ximage->bytes_per_line+
74183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ((x*ximage->bits_per_pixel) >> 3);
74193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            for (k=0; k < width; k+=magnify)
74203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
74213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              /*
74223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                Propogate pixel magnify columns.
74233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              */
74243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              for (l=0; l < magnify; l++)
74253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                for (m=0; m < bytes_per_pixel; m++)
74263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  *q++=(*(p+m));
74273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              p+=bytes_per_pixel;
74283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
74293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q+=scanline_pad;
74303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
74313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          y++;
74323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
74333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
74343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
74353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
74363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
74373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Copy X image to magnify pixmap.
74383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
74393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=windows->magnify.x-((width/magnify) >> 1);
74403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (x < 0)
74413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x=(int) ((width >> 1)-windows->magnify.x*magnify);
74423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
74433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (x > (int) (ximage->width-(width/magnify)))
74443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      x=(int) ((ximage->width-windows->magnify.x)*magnify-(width >> 1));
74453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    else
74463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      x=0;
74473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y=windows->magnify.y-((height/magnify) >> 1);
74483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (y < 0)
74493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y=(int) ((height >> 1)-windows->magnify.y*magnify);
74503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
74513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (y > (int) (ximage->height-(height/magnify)))
74523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      y=(int) ((ximage->height-windows->magnify.y)*magnify-(height >> 1));
74533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    else
74543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      y=0;
74553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((x != 0) || (y != 0))
74563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XFillRectangle(display,windows->magnify.pixmap,
74573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows->magnify.annotate_context,0,0,width,height);
74583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XPutImage(display,windows->magnify.pixmap,
74593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    windows->magnify.annotate_context,windows->magnify.ximage,0,0,x,y,width-x,
74603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    height-y);
74613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((magnify > 1) && ((magnify <= (width >> 1)) &&
74623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (magnify <= (height >> 1))))
74633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
74643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      RectangleInfo
74653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        highlight_info;
74663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
74673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
74683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Highlight center pixel.
74693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
7470bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      highlight_info.x=(ssize_t) windows->magnify.width >> 1;
7471bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      highlight_info.y=(ssize_t) windows->magnify.height >> 1;
74723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      highlight_info.width=magnify;
74733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      highlight_info.height=magnify;
74743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDrawRectangle(display,windows->magnify.pixmap,
74753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->magnify.highlight_context,(int) highlight_info.x,
74763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (int) highlight_info.y,(unsigned int) highlight_info.width-1,
74773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) highlight_info.height-1);
74783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (magnify > 2)
74793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XDrawRectangle(display,windows->magnify.pixmap,
74803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          windows->magnify.annotate_context,(int) highlight_info.x+1,
74813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (int) highlight_info.y+1,(unsigned int) highlight_info.width-3,
74823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (unsigned int) highlight_info.height-3);
74833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
74843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
74853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Show center pixel color.
74863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
74873aa9375ebfc21a5356d6b1754bcd1b162ad666c4cristy  (void) GetOneVirtualPixelInfo(windows->image.image,TileVirtualPixelMethod,
74885201002e1ba0118594060d26142b48bdfb1320a2cristy    (ssize_t) windows->magnify.x,(ssize_t) windows->magnify.y,&pixel,exception);
7489151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) FormatLocaleString(tuple,MagickPathExtent,"%d,%d: ",
74903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    windows->magnify.x,windows->magnify.y);
7491151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) ConcatenateMagickString(tuple,"(",MagickPathExtent);
7492ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy  ConcatenateColorComponent(&pixel,RedPixelChannel,X11Compliance,tuple);
7493151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
7494ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy  ConcatenateColorComponent(&pixel,GreenPixelChannel,X11Compliance,tuple);
7495151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
7496ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy  ConcatenateColorComponent(&pixel,BluePixelChannel,X11Compliance,tuple);
74973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (pixel.colorspace == CMYKColorspace)
74983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
7499151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy      (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
7500ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy      ConcatenateColorComponent(&pixel,BlackPixelChannel,X11Compliance,tuple);
75013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
750217f11b056210f082a6d0e54ac5d68e6d72fa76b2cristy  if (pixel.alpha_trait != UndefinedPixelTrait)
75033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
7504151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy      (void) ConcatenateMagickString(tuple,",",MagickPathExtent);
7505ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy      ConcatenateColorComponent(&pixel,AlphaPixelChannel,X11Compliance,tuple);
75063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
7507151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) ConcatenateMagickString(tuple,")",MagickPathExtent);
75083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  height=(unsigned int) windows->magnify.font_info->ascent+
75093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    windows->magnify.font_info->descent;
75103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x=windows->magnify.font_info->max_bounds.width >> 1;
75113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y=windows->magnify.font_info->ascent+(height >> 2);
75123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XDrawImageString(display,windows->magnify.pixmap,
75133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
75143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  GetColorTuple(&pixel,MagickTrue,tuple);
75153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y+=height;
75163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XDrawImageString(display,windows->magnify.pixmap,
75173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
7518269c9413034627692b2a7d0a352f9dee4e8eada8cristy  (void) QueryColorname(windows->image.image,&pixel,SVGCompliance,tuple,
75196710d8414f0ed06e4eaf9346366be72e2b4719efcristy    exception);
75203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y+=height;
75213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XDrawImageString(display,windows->magnify.pixmap,
75223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    windows->magnify.annotate_context,x,y,tuple,(int) strlen(tuple));
75233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
75243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Refresh magnify window.
75253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
75263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magnify_window=windows->magnify;
75273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magnify_window.x=0;
75283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  magnify_window.y=0;
75293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XRefreshWindow(display,&magnify_window,(XEvent *) NULL);
75303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
75313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
75323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
75333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
75353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
75363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
75373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X M a k e P i x m a p                                                     %
75383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
75393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
75403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
75413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
75433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XMakePixmap() creates an X11 pixmap.
75443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
75453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XMakePixmap method is:
75463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
75473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
75483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
75493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XPixelInfo *pixel)
75503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
75513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
75523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
75533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
75543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
75553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
75563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
75573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
75583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a XWindowInfo structure.
75593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
75603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
75613ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic MagickBooleanType XMakePixmap(Display *display,
75623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const XResourceInfo *resource_info,XWindowInfo *window)
75633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
75643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
75653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    height,
75663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    width;
75673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
75683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
75693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
75703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
75713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (XWindowInfo  *) NULL);
75723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->pixmap != (Pixmap) NULL)
75733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
75743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
75753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Destroy previous X pixmap.
75763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
75773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFreePixmap(display,window->pixmap);
75783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->pixmap=(Pixmap) NULL;
75793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
75803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->use_pixmap == MagickFalse)
75813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
75823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->ximage == (XImage *) NULL)
75833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
75843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
75853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Display busy cursor.
75863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
75873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XCheckDefineCursor(display,window->id,window->busy_cursor);
75883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFlush(display);
75893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
75903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Create pixmap.
75913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
75923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  width=(unsigned int) window->ximage->width;
75933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  height=(unsigned int) window->ximage->height;
75943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window->pixmap=XCreatePixmap(display,window->id,width,height,window->depth);
75953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->pixmap == (Pixmap) NULL)
75963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
75973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
75983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Unable to allocate pixmap.
75993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
76003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,window->id,window->cursor);
76013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(MagickFalse);
76023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
76033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
76043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Copy X image to pixmap.
76053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
76063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
76073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->shared_memory)
76083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XShmPutImage(display,window->pixmap,window->annotate_context,
76093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->ximage,0,0,0,0,width,height,MagickTrue);
76103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
76113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->shared_memory == MagickFalse)
76123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XPutImage(display,window->pixmap,window->annotate_context,
76133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window->ximage,0,0,0,0,width,height);
76143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (IsEventLogging())
76153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
76163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"Pixmap:");
76173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  width, height: %ux%u",
76183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        width,height);
76193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
76203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
76213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Restore cursor.
76223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
76233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XCheckDefineCursor(display,window->id,window->cursor);
76243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickTrue);
76253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
76263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
76273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
76283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
76303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
76313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
76323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X M a k e S t a n d a r d C o l o r m a p                                 %
76333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
76343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
76353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
76363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XMakeStandardColormap() creates an X11 Standard Colormap.
76393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XMakeStandardColormap method is:
76413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76426710d8414f0ed06e4eaf9346366be72e2b4719efcristy%      void XMakeStandardColormap(Display *display,XVisualInfo *visual_info,
76436710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        XResourceInfo *resource_info,Image *image,XStandardColormap *map_info,
76446710d8414f0ed06e4eaf9346366be72e2b4719efcristy%        XPixelInfo *pixel,ExceptionInfo *exception)
76453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
76473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
76493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
76503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o visual_info: Specifies a pointer to a X11 XVisualInfo structure;
76523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      returned from XGetVisualInfo.
76533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
76553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image: the image.
76573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o map_info: If a Standard Colormap type is specified, this structure is
76593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      initialized with info from the Standard Colormap.
76603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o pixel: Specifies a pointer to a XPixelInfo structure.
76623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
76636710d8414f0ed06e4eaf9346366be72e2b4719efcristy%    o exception: return any errors or warnings in this structure.
76646710d8414f0ed06e4eaf9346366be72e2b4719efcristy%
76653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
76663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
76673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__cplusplus) || defined(c_plusplus)
76683ed852eea50f9d4cd633efb8c2b054b8e33c253cristyextern "C" {
76693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
76703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7671a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristystatic inline double DiversityPixelIntensity(
76723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const DiversityPacket *pixel)
76733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
7674a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy  double
76753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    intensity;
76763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7677d3d2a275f6aeefb07eac111782edddfa085964f9cristy  intensity=0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue;
76783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(intensity);
76793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
76803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
76813ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic int IntensityCompare(const void *x,const void *y)
76823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
76833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DiversityPacket
76843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *color_1,
76853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *color_2;
76863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
76873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
76883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    diversity;
76893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
76903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  color_1=(DiversityPacket *) x;
76913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  color_2=(DiversityPacket *) y;
76923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  diversity=(int) (DiversityPixelIntensity(color_2)-
76933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    DiversityPixelIntensity(color_1));
76943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(diversity);
76953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
76963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
76973ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic int PopularityCompare(const void *x,const void *y)
76983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
76993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  DiversityPacket
77003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *color_1,
77013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *color_2;
77023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  color_1=(DiversityPacket *) x;
77043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  color_2=(DiversityPacket *) y;
77053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return((int) color_2->count-(int) color_1->count);
77063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
77073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__cplusplus) || defined(c_plusplus)
77093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
77103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
77113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7712bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristystatic inline Quantum ScaleXToQuantum(const size_t x,
7713bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  const size_t scale)
77143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
7715a19f1d70e9a9f88279c4ecafe6dfafc1f9a09599cristy  return((Quantum) (((double) QuantumRange*x)/scale+0.5));
77163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
77173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7718bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XMakeStandardColormap(Display *display,
77193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XVisualInfo *visual_info,XResourceInfo *resource_info,Image *image,
77206710d8414f0ed06e4eaf9346366be72e2b4719efcristy  XStandardColormap *map_info,XPixelInfo *pixel,ExceptionInfo *exception)
77213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
77223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Colormap
77233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    colormap;
77243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7725bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  register ssize_t
77263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
77273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
77293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
77303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7731bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  size_t
77323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_colors,
77333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    retain_colors;
77343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned short
77363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    gray_value;
77373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XColor
77393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    color,
77403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *colors,
77413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p;
77423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
77443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
77453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(visual_info != (XVisualInfo *) NULL);
77463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(map_info != (XStandardColormap *) NULL);
77473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
77483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(pixel != (XPixelInfo *) NULL);
77493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (resource_info->map_type != (char *) NULL)
77503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
77513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
77523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Standard Colormap is already defined (i.e. xstdcmap).
77533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
77544c08aed51c5899665ade97263692328eea4af106cristy      XGetPixelInfo(display,visual_info,map_info,resource_info,image,
77553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        pixel);
77563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      number_colors=(unsigned int) (map_info->base_pixel+
77573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (map_info->red_max+1)*(map_info->green_max+1)*(map_info->blue_max+1));
77583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((map_info->red_max*map_info->green_max*map_info->blue_max) != 0)
775917f11b056210f082a6d0e54ac5d68e6d72fa76b2cristy        if ((image->alpha_trait == UndefinedPixelTrait) &&
77603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (resource_info->color_recovery == MagickFalse) &&
7761cbda611068350bf4459f2dda1951f8823702e129cristy            (resource_info->quantize_info->dither_method != NoDitherMethod) &&
77623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (number_colors < MaxColormapSize))
77633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
77643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Image
77653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              *affinity_image;
77663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77674c08aed51c5899665ade97263692328eea4af106cristy            register Quantum
776805d2ff7ebf21f659f5b11e45afb294e152f4330cdirk              *magick_restrict q;
77693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
77703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
77713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Improve image appearance with error diffusion.
77723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
77736710d8414f0ed06e4eaf9346366be72e2b4719efcristy            affinity_image=AcquireImage((ImageInfo *) NULL,exception);
77743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (affinity_image == (Image *) NULL)
77753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ThrowXWindowFatalException(ResourceLimitFatalError,
77763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                "UnableToDitherImage",image->filename);
77773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            affinity_image->columns=number_colors;
77783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            affinity_image->rows=1;
77793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            /*
77803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              Initialize colormap image.
77813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            */
77823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            q=QueueAuthenticPixels(affinity_image,0,0,affinity_image->columns,
77833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              1,exception);
77844c08aed51c5899665ade97263692328eea4af106cristy            if (q != (Quantum *) NULL)
77853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
7786bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy                for (i=0; i < (ssize_t) number_colors; i++)
77873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                {
77884c08aed51c5899665ade97263692328eea4af106cristy                  SetPixelRed(affinity_image,0,q);
77893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if (map_info->red_max != 0)
7790534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy                    SetPixelRed(affinity_image,ScaleXToQuantum((size_t)
7791534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy                      (i/map_info->red_mult),map_info->red_max),q);
77924c08aed51c5899665ade97263692328eea4af106cristy                  SetPixelGreen(affinity_image,0,q);
77933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if (map_info->green_max != 0)
7794534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy                    SetPixelGreen(affinity_image,ScaleXToQuantum((size_t)
7795534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy                      ((i/map_info->green_mult) % (map_info->green_max+1)),
7796534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy                      map_info->green_max),q);
77974c08aed51c5899665ade97263692328eea4af106cristy                  SetPixelBlue(affinity_image,0,q);
77983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                  if (map_info->blue_max != 0)
7799534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy                    SetPixelBlue(affinity_image,ScaleXToQuantum((size_t)
7800534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy                      (i % map_info->green_mult),map_info->blue_max),q);
78014c08aed51c5899665ade97263692328eea4af106cristy                  SetPixelAlpha(affinity_image,
78024c08aed51c5899665ade97263692328eea4af106cristy                    TransparentAlpha,q);
7803ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy                  q+=GetPixelChannels(affinity_image);
78043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                }
78053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (void) SyncAuthenticPixels(affinity_image,exception);
78063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (void) RemapImage(resource_info->quantize_info,image,
7807018f07f7333b25743d0afff892450cebdb905c1acristy                  affinity_image,exception);
78083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
78094c08aed51c5899665ade97263692328eea4af106cristy            XGetPixelInfo(display,visual_info,map_info,resource_info,image,
78103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              pixel);
7811574cc26500992189f637cd1cdf93d0654e7df7aecristy            (void) SetImageStorageClass(image,DirectClass,exception);
78123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            affinity_image=DestroyImage(affinity_image);
78133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
78143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (IsEventLogging())
78153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
78163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) LogMagickEvent(X11Event,GetMagickModule(),
78173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            "Standard Colormap:");
78183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) LogMagickEvent(X11Event,GetMagickModule(),
78193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            "  colormap id: 0x%lx",map_info->colormap);
78203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) LogMagickEvent(X11Event,GetMagickModule(),
78213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            "  red, green, blue max: %lu %lu %lu",map_info->red_max,
78223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            map_info->green_max,map_info->blue_max);
78233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) LogMagickEvent(X11Event,GetMagickModule(),
78243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            "  red, green, blue mult: %lu %lu %lu",map_info->red_mult,
78253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            map_info->green_mult,map_info->blue_mult);
78263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
78273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return;
78283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
78293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((visual_info->klass != DirectColor) &&
78303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (visual_info->klass != TrueColor))
78313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if ((image->storage_class == DirectClass) ||
78323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ((int) image->colors > visual_info->colormap_size))
78333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
78343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        QuantizeInfo
78353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          quantize_info;
78363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
78373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
78383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Image has more colors than the visual supports.
78393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
78403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        quantize_info=(*resource_info->quantize_info);
7841bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        quantize_info.number_colors=(size_t) visual_info->colormap_size;
7842018f07f7333b25743d0afff892450cebdb905c1acristy        (void) QuantizeImage(&quantize_info,image,exception);
78433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
78443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
78453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Free previous and create new colormap.
78463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
78473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
78483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  colormap=XDefaultColormap(display,visual_info->screen);
78493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (visual_info->visual != XDefaultVisual(display,visual_info->screen))
78503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    colormap=XCreateColormap(display,XRootWindow(display,visual_info->screen),
78513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      visual_info->visual,visual_info->klass == DirectColor ?
78523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      AllocAll : AllocNone);
78533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (colormap == (Colormap) NULL)
78543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(ResourceLimitFatalError,"UnableToCreateColormap",
78553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image->filename);
78563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
78573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize the map and pixel info structures.
78583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
78593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XGetMapInfo(visual_info,colormap,map_info);
78604c08aed51c5899665ade97263692328eea4af106cristy  XGetPixelInfo(display,visual_info,map_info,resource_info,image,pixel);
78613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
78623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Allocating colors in server colormap is based on visual class.
78633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
78643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  switch (visual_info->klass)
78653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
78663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case StaticGray:
78673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case StaticColor:
78683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
78693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
78703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Define Standard Colormap for StaticGray or StaticColor visual.
78713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
78723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      number_colors=image->colors;
78733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      colors=(XColor *) AcquireQuantumMemory((size_t)
78743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        visual_info->colormap_size,sizeof(*colors));
78753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (colors == (XColor *) NULL)
78763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ThrowXWindowFatalException(ResourceLimitFatalError,
78773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          "UnableToCreateColormap",image->filename);
78783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      p=colors;
78793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      color.flags=(char) (DoRed | DoGreen | DoBlue);
7880bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      for (i=0; i < (ssize_t) image->colors; i++)
78813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
78823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
78833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
78843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
78853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (visual_info->klass != StaticColor)
78863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
78873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            gray_value=(unsigned short) XPixelIntensity(&color);
78883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.red=gray_value;
78893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.green=gray_value;
78903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.blue=gray_value;
78913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
78923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        status=XAllocColor(display,colormap,&color);
78933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (status == False)
78943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
78953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            colormap=XCopyColormapAndFree(display,colormap);
78963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) XAllocColor(display,colormap,&color);
78973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
78983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        pixel->pixels[i]=color.pixel;
78993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *p++=color;
79003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
79013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
79023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
79033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case GrayScale:
79043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case PseudoColor:
79053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
79063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      unsigned int
79073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        colormap_type;
79083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
79093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
79103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Define Standard Colormap for GrayScale or PseudoColor visual.
79113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
79123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      number_colors=image->colors;
79133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      colors=(XColor *) AcquireQuantumMemory((size_t)
79143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        visual_info->colormap_size,sizeof(*colors));
79153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (colors == (XColor *) NULL)
79163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ThrowXWindowFatalException(ResourceLimitFatalError,
79173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          "UnableToCreateColormap",image->filename);
79183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
79193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Preallocate our GUI colors.
79203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
79213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XAllocColor(display,colormap,&pixel->foreground_color);
79223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XAllocColor(display,colormap,&pixel->background_color);
79233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XAllocColor(display,colormap,&pixel->border_color);
7924b797b2c96f796f4920c9ee807dc5f47e6f160418dirk      (void) XAllocColor(display,colormap,&pixel->alpha_color);
79253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XAllocColor(display,colormap,&pixel->highlight_color);
79263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XAllocColor(display,colormap,&pixel->shadow_color);
79273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XAllocColor(display,colormap,&pixel->depth_color);
79283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XAllocColor(display,colormap,&pixel->trough_color);
79293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (i=0; i < MaxNumberPens; i++)
79303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XAllocColor(display,colormap,&pixel->pen_colors[i]);
79313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
79323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Determine if image colors will "fit" into X server colormap.
79333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
79343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      colormap_type=resource_info->colormap;
7935f2faecf9facdbbb14fcba373365f9f691a9658e0cristy      status=XAllocColorCells(display,colormap,MagickFalse,(unsigned long *)
79363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        NULL,0,pixel->pixels,(unsigned int) image->colors);
79373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status != False)
79383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        colormap_type=PrivateColormap;
79393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (colormap_type == SharedColormap)
79403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
7941c57f694b2d04975a0e501613e34368c464708c19cristy          CacheView
7942c57f694b2d04975a0e501613e34368c464708c19cristy            *image_view;
7943c57f694b2d04975a0e501613e34368c464708c19cristy
79443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          DiversityPacket
79453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *diversity;
79463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
79473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          int
79483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            y;
79493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
79503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          register int
79513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            x;
79523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
79533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          unsigned short
79543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            index;
79553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
79563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          XColor
79573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *server_colors;
79583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
79593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
79603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Define Standard colormap for shared GrayScale or PseudoColor visual.
79613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
79623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          diversity=(DiversityPacket *) AcquireQuantumMemory(image->colors,
79633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            sizeof(*diversity));
79643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (diversity == (DiversityPacket *) NULL)
79653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            ThrowXWindowFatalException(ResourceLimitFatalError,
79663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "UnableToCreateColormap",image->filename);
7967bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy          for (i=0; i < (ssize_t) image->colors; i++)
79683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
7969e42f658533644aecb733785ffd91b286d6778deacristy            diversity[i].red=ClampToQuantum(image->colormap[i].red);
7970e42f658533644aecb733785ffd91b286d6778deacristy            diversity[i].green=ClampToQuantum(image->colormap[i].green);
7971e42f658533644aecb733785ffd91b286d6778deacristy            diversity[i].blue=ClampToQuantum(image->colormap[i].blue);
79723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            diversity[i].index=(unsigned short) i;
79733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            diversity[i].count=0;
79743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
797546ff2676b1044ea4101ac7a59b83289cd8f6cfdacristy          image_view=AcquireAuthenticCacheView(image,exception);
79763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (y=0; y < (int) image->rows; y++)
79773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
7978c57f694b2d04975a0e501613e34368c464708c19cristy            register int
79793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              x;
79803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
79814c08aed51c5899665ade97263692328eea4af106cristy            register const Quantum
798205d2ff7ebf21f659f5b11e45afb294e152f4330cdirk              *magick_restrict p;
79833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
7984c57f694b2d04975a0e501613e34368c464708c19cristy            p=GetCacheViewAuthenticPixels(image_view,0,(ssize_t) y,
7985c57f694b2d04975a0e501613e34368c464708c19cristy              image->columns,1,exception);
79864c08aed51c5899665ade97263692328eea4af106cristy            if (p == (const Quantum *) NULL)
79873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
7988c57f694b2d04975a0e501613e34368c464708c19cristy            for (x=(int) image->columns-1; x >= 0; x--)
79894c08aed51c5899665ade97263692328eea4af106cristy            {
79904c08aed51c5899665ade97263692328eea4af106cristy              diversity[(ssize_t) GetPixelIndex(image,p)].count++;
7991ed2315769b26818ed9d0c1291dc0457f0d8da0a4cristy              p+=GetPixelChannels(image);
79924c08aed51c5899665ade97263692328eea4af106cristy            }
79933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
7994c57f694b2d04975a0e501613e34368c464708c19cristy          image_view=DestroyCacheView(image_view);
79953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
79963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Sort colors by decreasing intensity.
79973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
79983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          qsort((void *) diversity,image->colors,sizeof(*diversity),
79993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            IntensityCompare);
8000bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy          for (i=0; i < (ssize_t) image->colors; )
80013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
80023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            diversity[i].count<<=4;  /* increase this colors popularity */
8003dfe2b6658f367de8f84405263f62768fb853adafcristy            i+=MagickMax((int) (image->colors >> 4),2);
80043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
80053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          diversity[image->colors-1].count<<=4;
80063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          qsort((void *) diversity,image->colors,sizeof(*diversity),
80073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            PopularityCompare);
80083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
80093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Allocate colors.
80103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
80113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          p=colors;
80123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          color.flags=(char) (DoRed | DoGreen | DoBlue);
8013bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy          for (i=0; i < (ssize_t) image->colors; i++)
80143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
80153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            index=diversity[i].index;
80163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.red=
80173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ScaleQuantumToShort(XRedGamma(image->colormap[index].red));
80183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.green=
80193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ScaleQuantumToShort(XGreenGamma(image->colormap[index].green));
80203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.blue=
80213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ScaleQuantumToShort(XBlueGamma(image->colormap[index].blue));
80223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (visual_info->klass != PseudoColor)
80233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
80243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                gray_value=(unsigned short) XPixelIntensity(&color);
80253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                color.red=gray_value;
80263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                color.green=gray_value;
80273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                color.blue=gray_value;
80283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
80293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            status=XAllocColor(display,colormap,&color);
80303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (status == False)
80313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              break;
80323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            pixel->pixels[index]=color.pixel;
80333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *p++=color;
80343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
80353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
80363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Read X server colormap.
80373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
80383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          server_colors=(XColor *) AcquireQuantumMemory((size_t)
80393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            visual_info->colormap_size,sizeof(*server_colors));
80403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (server_colors == (XColor *) NULL)
80413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            ThrowXWindowFatalException(ResourceLimitFatalError,
80423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "UnableToCreateColormap",image->filename);
80433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          for (x=visual_info->colormap_size-1; x >= 0; x--)
8044bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            server_colors[x].pixel=(size_t) x;
80453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) XQueryColors(display,colormap,server_colors,
80463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (int) MagickMin((unsigned int) visual_info->colormap_size,256));
80473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
80483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Select remaining colors from X server colormap.
80493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
8050bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy          for (; i < (ssize_t) image->colors; i++)
80513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
80523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            index=diversity[i].index;
8053534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy            color.red=ScaleQuantumToShort(
8054534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy              XRedGamma(image->colormap[index].red));
8055534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy            color.green=ScaleQuantumToShort(
8056534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy              XGreenGamma(image->colormap[index].green));
8057534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy            color.blue=ScaleQuantumToShort(
8058534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy              XBlueGamma(image->colormap[index].blue));
80593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            if (visual_info->klass != PseudoColor)
80603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
80613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                gray_value=(unsigned short) XPixelIntensity(&color);
80623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                color.red=gray_value;
80633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                color.green=gray_value;
80643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                color.blue=gray_value;
80653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
80663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            XBestPixel(display,colormap,server_colors,(unsigned int)
80673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              visual_info->colormap_size,&color);
80683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            pixel->pixels[index]=color.pixel;
80693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            *p++=color;
80703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
80713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((int) image->colors < visual_info->colormap_size)
80723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
80733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              /*
80743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                Fill up colors array-- more choices for pen colors.
80753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              */
80763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              retain_colors=MagickMin((unsigned int)
80773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy               (visual_info->colormap_size-image->colors),256);
8078bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy              for (i=0; i < (ssize_t) retain_colors; i++)
80793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                *p++=server_colors[i];
80803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              number_colors+=retain_colors;
80813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
80823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          server_colors=(XColor *) RelinquishMagickMemory(server_colors);
80833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          diversity=(DiversityPacket *) RelinquishMagickMemory(diversity);
80843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          break;
80853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
80863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
80873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Define Standard colormap for private GrayScale or PseudoColor visual.
80883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
80893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (status == False)
80903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
80913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
80923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Not enough colormap entries in the colormap-- Create a new colormap.
80933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
80943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          colormap=XCreateColormap(display,
80953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            XRootWindow(display,visual_info->screen),visual_info->visual,
80963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            AllocNone);
80973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (colormap == (Colormap) NULL)
80983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            ThrowXWindowFatalException(ResourceLimitFatalError,
80993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              "UnableToCreateColormap",image->filename);
81003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          map_info->colormap=colormap;
81013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if ((int) image->colors < visual_info->colormap_size)
81023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            {
81033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              /*
81043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                Retain colors from the default colormap to help lessens the
81053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                effects of colormap flashing.
81063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              */
81073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              retain_colors=MagickMin((unsigned int)
81083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (visual_info->colormap_size-image->colors),256);
81093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              p=colors+image->colors;
8110bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy              for (i=0; i < (ssize_t) retain_colors; i++)
81113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
8112c57f694b2d04975a0e501613e34368c464708c19cristy                p->pixel=(unsigned long) i;
81133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                p++;
81143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
81153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) XQueryColors(display,
81163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                XDefaultColormap(display,visual_info->screen),
81173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                colors+image->colors,(int) retain_colors);
81183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              /*
81193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                Transfer colors from default to private colormap.
81203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              */
81213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) XAllocColorCells(display,colormap,MagickFalse,
8122f2faecf9facdbbb14fcba373365f9f691a9658e0cristy                (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
81233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                retain_colors);
81243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              p=colors+image->colors;
8125bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy              for (i=0; i < (ssize_t) retain_colors; i++)
81263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              {
81273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                p->pixel=pixel->pixels[i];
81283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                p++;
81293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              }
81303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (void) XStoreColors(display,colormap,colors+image->colors,
81313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                (int) retain_colors);
81323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              number_colors+=retain_colors;
81333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            }
81343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) XAllocColorCells(display,colormap,MagickFalse,
8135f2faecf9facdbbb14fcba373365f9f691a9658e0cristy            (unsigned long *) NULL,0,pixel->pixels,(unsigned int)
81363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            image->colors);
81373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
81383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
81393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Store the image colormap.
81403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
81413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      p=colors;
81423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      color.flags=(char) (DoRed | DoGreen | DoBlue);
8143bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy      for (i=0; i < (ssize_t) image->colors; i++)
81443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
81453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        color.red=ScaleQuantumToShort(XRedGamma(image->colormap[i].red));
81463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        color.green=ScaleQuantumToShort(XGreenGamma(image->colormap[i].green));
81473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        color.blue=ScaleQuantumToShort(XBlueGamma(image->colormap[i].blue));
81483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (visual_info->klass != PseudoColor)
81493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
81503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            gray_value=(unsigned short) XPixelIntensity(&color);
81513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.red=gray_value;
81523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.green=gray_value;
81533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            color.blue=gray_value;
81543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
81553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        color.pixel=pixel->pixels[i];
81563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *p++=color;
81573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
81583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XStoreColors(display,colormap,colors,(int) image->colors);
81593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
81603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
81613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case TrueColor:
81623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case DirectColor:
81633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    default:
81643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
81653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      MagickBooleanType
81663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        linear_colormap;
81673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
81683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
81693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Define Standard Colormap for TrueColor or DirectColor visual.
81703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
81713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      number_colors=(unsigned int) ((map_info->red_max*map_info->red_mult)+
81723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (map_info->green_max*map_info->green_mult)+
81733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (map_info->blue_max*map_info->blue_mult)+1);
81743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      linear_colormap=(number_colors > 4096) ||
81753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (((int) (map_info->red_max+1) == visual_info->colormap_size) &&
81763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy         ((int) (map_info->green_max+1) == visual_info->colormap_size) &&
81773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy         ((int) (map_info->blue_max+1) == visual_info->colormap_size)) ?
81783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy         MagickTrue : MagickFalse;
81793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (linear_colormap != MagickFalse)
8180bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        number_colors=(size_t) visual_info->colormap_size;
81813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
81823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Allocate color array.
81833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
81843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
81853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (colors == (XColor *) NULL)
81863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        ThrowXWindowFatalException(ResourceLimitFatalError,
81873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          "UnableToCreateColormap",image->filename);
81883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
81893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Initialize linear color ramp.
81903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
81913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      p=colors;
81923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      color.flags=(char) (DoRed | DoGreen | DoBlue);
81933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (linear_colormap != MagickFalse)
8194bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        for (i=0; i < (ssize_t) number_colors; i++)
81953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
81963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          color.blue=(unsigned short) 0;
81973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (map_info->blue_max != 0)
8198bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            color.blue=(unsigned short) ((size_t)
81993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ((65535L*(i % map_info->green_mult))/map_info->blue_max));
82003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          color.green=color.blue;
82013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          color.red=color.blue;
82023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          color.pixel=XStandardPixel(map_info,&color);
82033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          *p++=color;
82043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
82053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
8206bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        for (i=0; i < (ssize_t) number_colors; i++)
82073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
82083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          color.red=(unsigned short) 0;
82093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (map_info->red_max != 0)
8210bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            color.red=(unsigned short) ((size_t)
82113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ((65535L*(i/map_info->red_mult))/map_info->red_max));
82123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          color.green=(unsigned int) 0;
82133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (map_info->green_max != 0)
8214bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            color.green=(unsigned short) ((size_t)
82153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ((65535L*((i/map_info->green_mult) % (map_info->green_max+1)))/
82163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy                map_info->green_max));
82173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          color.blue=(unsigned short) 0;
82183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (map_info->blue_max != 0)
8219bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy            color.blue=(unsigned short) ((size_t)
82203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              ((65535L*(i % map_info->green_mult))/map_info->blue_max));
82213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          color.pixel=XStandardPixel(map_info,&color);
82223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          *p++=color;
82233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
82243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((visual_info->klass == DirectColor) &&
82253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (colormap != XDefaultColormap(display,visual_info->screen)))
82263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XStoreColors(display,colormap,colors,(int) number_colors);
82273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
8228bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy        for (i=0; i < (ssize_t) number_colors; i++)
82293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) XAllocColor(display,colormap,&colors[i]);
82303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
82313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
82323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
82333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((visual_info->klass != DirectColor) &&
82343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (visual_info->klass != TrueColor))
82353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
82363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
82373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Set foreground, background, border, etc. pixels.
82383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
82393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XBestPixel(display,colormap,colors,(unsigned int) number_colors,
82403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &pixel->foreground_color);
82413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XBestPixel(display,colormap,colors,(unsigned int) number_colors,
82423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &pixel->background_color);
82433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (pixel->background_color.pixel == pixel->foreground_color.pixel)
82443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
82453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          /*
82463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            Foreground and background colors must differ.
82473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          */
82483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          pixel->background_color.red=(~pixel->foreground_color.red);
82493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          pixel->background_color.green=
82503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (~pixel->foreground_color.green);
82513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          pixel->background_color.blue=
82523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (~pixel->foreground_color.blue);
82533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          XBestPixel(display,colormap,colors,(unsigned int) number_colors,
82543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            &pixel->background_color);
82553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
82563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XBestPixel(display,colormap,colors,(unsigned int) number_colors,
82573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &pixel->border_color);
82583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XBestPixel(display,colormap,colors,(unsigned int) number_colors,
8259b797b2c96f796f4920c9ee807dc5f47e6f160418dirk        &pixel->alpha_color);
82603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XBestPixel(display,colormap,colors,(unsigned int) number_colors,
82613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &pixel->highlight_color);
82623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XBestPixel(display,colormap,colors,(unsigned int) number_colors,
82633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &pixel->shadow_color);
82643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XBestPixel(display,colormap,colors,(unsigned int) number_colors,
82653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &pixel->depth_color);
82663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XBestPixel(display,colormap,colors,(unsigned int) number_colors,
82673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &pixel->trough_color);
82683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      for (i=0; i < MaxNumberPens; i++)
82693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
82703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        XBestPixel(display,colormap,colors,(unsigned int) number_colors,
82713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          &pixel->pen_colors[i]);
82723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        pixel->pixels[image->colors+i]=pixel->pen_colors[i].pixel;
82733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
8274c57f694b2d04975a0e501613e34368c464708c19cristy      pixel->colors=(ssize_t) (image->colors+MaxNumberPens);
82753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
82763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  colors=(XColor *) RelinquishMagickMemory(colors);
82773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (IsEventLogging())
82783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
82793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"Standard Colormap:");
82803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),"  colormap id: 0x%lx",
82813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        map_info->colormap);
82823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
82833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "  red, green, blue max: %lu %lu %lu",map_info->red_max,
82843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        map_info->green_max,map_info->blue_max);
82853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) LogMagickEvent(X11Event,GetMagickModule(),
82863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "  red, green, blue mult: %lu %lu %lu",map_info->red_mult,
82873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        map_info->green_mult,map_info->blue_mult);
82883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
82893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
82903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
82913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
82923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
82943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
82953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
82963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X M a k e W i n d o w                                                     %
82973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
82983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
82993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
83003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
83013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XMakeWindow() creates an X11 window.
83033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XMakeWindow method is:
83053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XMakeWindow(Display *display,Window parent,char **argv,int argc,
83073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XClassHint *class_hint,XWMHints *manager_hints,
83083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        XWindowInfo *window_info)
83093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
83113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
83133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
83143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o parent: Specifies the parent window_info.
83163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o argv: Specifies the application's argument list.
83183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o argc: Specifies the number of arguments.
83203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o class_hint: Specifies a pointer to a X11 XClassHint structure.
83223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o manager_hints: Specifies a pointer to a X11 XWMHints structure.
83243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window_info: Specifies a pointer to a X11 XWindowInfo structure.
83263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
83273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
8328bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XMakeWindow(Display *display,Window parent,char **argv,
83293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int argc,XClassHint *class_hint,XWMHints *manager_hints,
83303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XWindowInfo *window_info)
83313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
83323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define MinWindowSize  64
83333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
83343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Atom
83353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    atom_list[2];
83363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
83373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
83383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    gravity;
83393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
83403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static XTextProperty
83413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    icon_name,
83423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window_name;
83433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
83443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
83453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
83463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
83473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XSizeHints
83483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *size_hints;
83493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
83503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
83513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Set window info hints.
83523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
83533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
83543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
83553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window_info != (XWindowInfo *) NULL);
83563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_hints=XAllocSizeHints();
83573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (size_hints == (XSizeHints *) NULL)
83583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(XServerFatalError,"UnableToMakeXWindow",argv[0]);
8359dfe2b6658f367de8f84405263f62768fb853adafcristy  size_hints->flags=(int) window_info->flags;
83603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_hints->x=window_info->x;
83613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_hints->y=window_info->y;
83623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_hints->width=(int) window_info->width;
83633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_hints->height=(int) window_info->height;
83643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info->immutable != MagickFalse)
83653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
83663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
83673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Window size cannot be changed.
83683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
83693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->min_width=size_hints->width;
83703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->min_height=size_hints->height;
83713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->max_width=size_hints->width;
83723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->max_height=size_hints->height;
83733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->flags|=PMinSize;
83743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->flags|=PMaxSize;
83753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
83763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
83773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
83783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
83793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Window size can be changed.
83803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
83813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->min_width=(int) window_info->min_width;
83823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->min_height=(int) window_info->min_height;
83833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->flags|=PResizeInc;
83843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->width_inc=(int) window_info->width_inc;
83853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->height_inc=(int) window_info->height_inc;
83863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if !defined(PRE_R4_ICCCM)
83873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->flags|=PBaseSize;
83883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->base_width=size_hints->width_inc;
83893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->base_height=size_hints->height_inc;
83903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
83913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
83923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  gravity=NorthWestGravity;
83933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info->geometry != (char *) NULL)
83943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
83953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      char
8396151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy        default_geometry[MagickPathExtent],
8397151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy        geometry[MagickPathExtent];
83983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
83993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      int
84003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        flags;
84013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
84023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      register char
84033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *p;
84043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
84053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
84063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        User specified geometry.
84073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
8408151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy      (void) FormatLocaleString(default_geometry,MagickPathExtent,"%dx%d",
84093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        size_hints->width,size_hints->height);
8410151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy      (void) CopyMagickString(geometry,window_info->geometry,MagickPathExtent);
84113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      p=geometry;
84123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      while (strlen(p) != 0)
84133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
84143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if ((isspace((int) ((unsigned char) *p)) == 0) && (*p != '%'))
84153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          p++;
84163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        else
8417151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy          (void) CopyMagickString(p,p+1,MagickPathExtent-(p-geometry));
84183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
84193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      flags=XWMGeometry(display,window_info->screen,geometry,default_geometry,
84203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window_info->border_width,size_hints,&size_hints->x,&size_hints->y,
84213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &size_hints->width,&size_hints->height,&gravity);
84223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((flags & WidthValue) && (flags & HeightValue))
84233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        size_hints->flags|=USSize;
84243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((flags & XValue) && (flags & YValue))
84253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
84263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          size_hints->flags|=USPosition;
84273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window_info->x=size_hints->x;
84283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window_info->y=size_hints->y;
84293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
84303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
84313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if !defined(PRE_R4_ICCCM)
84323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_hints->win_gravity=gravity;
84333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_hints->flags|=PWinGravity;
84343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
84353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info->id == (Window) NULL)
84363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window_info->id=XCreateWindow(display,parent,window_info->x,window_info->y,
84373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (unsigned int) size_hints->width,(unsigned int) size_hints->height,
84383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_info->border_width,(int) window_info->depth,InputOutput,
8439c57f694b2d04975a0e501613e34368c464708c19cristy      window_info->visual,(unsigned long) window_info->mask,
8440c57f694b2d04975a0e501613e34368c464708c19cristy      &window_info->attributes);
84413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
84423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
84433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      MagickStatusType
84443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        mask;
84453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
84463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XEvent
84473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        sans_event;
84483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
84493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XWindowChanges
84503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window_changes;
84513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
84523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
84533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Window already exists;  change relevant attributes.
84543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
8455c57f694b2d04975a0e501613e34368c464708c19cristy      (void) XChangeWindowAttributes(display,window_info->id,(unsigned long)
8456c57f694b2d04975a0e501613e34368c464708c19cristy        window_info->mask,&window_info->attributes);
84573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      mask=ConfigureNotify;
84583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      while (XCheckTypedWindowEvent(display,window_info->id,(int) mask,&sans_event)) ;
84593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_changes.x=window_info->x;
84603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_changes.y=window_info->y;
84613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_changes.width=(int) window_info->width;
84623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_changes.height=(int) window_info->height;
84633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      mask=(MagickStatusType) (CWWidth | CWHeight);
84643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window_info->flags & USPosition)
84653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        mask|=CWX | CWY;
84663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XReconfigureWMWindow(display,window_info->id,window_info->screen,
84673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        mask,&window_changes);
84683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
84693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info->id == (Window) NULL)
84703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(XServerFatalError,"UnableToCreateWindow",
84713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_info->name);
84723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XStringListToTextProperty(&window_info->name,1,&window_name);
84733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
84743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
84753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_info->name);
84763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XStringListToTextProperty(&window_info->icon_name,1,&icon_name);
84773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
84783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    ThrowXWindowFatalException(XServerFatalError,"UnableToCreateTextProperty",
84793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_info->icon_name);
84803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info->icon_geometry != (char *) NULL)
84813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
84823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      int
84833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        flags,
84843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        height,
84853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        width;
84863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
84873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
84883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        User specified icon geometry.
84893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
84903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      size_hints->flags|=USPosition;
84913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      flags=XWMGeometry(display,window_info->screen,window_info->icon_geometry,
84923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (char *) NULL,0,size_hints,&manager_hints->icon_x,
84933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        &manager_hints->icon_y,&width,&height,&gravity);
84943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if ((flags & XValue) && (flags & YValue))
84953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        manager_hints->flags|=IconPositionHint;
84963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
84973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XSetWMProperties(display,window_info->id,&window_name,&icon_name,argv,argc,
84983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    size_hints,manager_hints,class_hint);
84993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_name.value != (void *) NULL)
85003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
85013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFree((void *) window_name.value);
85023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_name.value=(unsigned char *) NULL;
85033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_name.nitems=0;
85043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
85053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (icon_name.value != (void *) NULL)
85063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
85073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFree((void *) icon_name.value);
85083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_name.value=(unsigned char *) NULL;
85093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      icon_name.nitems=0;
85103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
85113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  atom_list[0]=XInternAtom(display,"WM_DELETE_WINDOW",MagickFalse);
85123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  atom_list[1]=XInternAtom(display,"WM_TAKE_FOCUS",MagickFalse);
85133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSetWMProtocols(display,window_info->id,atom_list,2);
85143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFree((void *) size_hints);
85153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info->shape != MagickFalse)
85163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
85173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHAPE)
85183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      int
85193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        error_base,
85203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        event_base;
85213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
85223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
85233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Can we apply a non-rectangular shaping mask?
85243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
85253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      error_base=0;
85263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      event_base=0;
85273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (XShapeQueryExtension(display,&error_base,&event_base) == 0)
85283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window_info->shape=MagickFalse;
85293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else
85303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_info->shape=MagickFalse;
85313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
85323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
85333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window_info->shared_memory)
85343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
85353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
85363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
85373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Can we use shared memory with this window?
85383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
85393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (XShmQueryExtension(display) == 0)
85403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        window_info->shared_memory=MagickFalse;
85413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else
85423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      window_info->shared_memory=MagickFalse;
85433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
85443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
85453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info->image=NewImageList();
85463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window_info->destroy=MagickFalse;
85473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
85483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
85493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
85503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
85523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
85533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
85543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X M a g i c k P r o g r e s s M o n i t o r                               %
85553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
85563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
85573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
85583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
85603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XMagickProgressMonitor() displays the progress a task is making in
85613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  completing a task.
85623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
85633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XMagickProgressMonitor method is:
85643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
85653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XMagickProgressMonitor(const char *task,
85663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const MagickOffsetType quantum,const MagickSizeType span,
85673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        void *client_data)
85683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
85693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
85703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
85713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o task: Identifies the task in progress.
85723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
85733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o quantum: Specifies the quantum position within the span which represents
85743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      how much progress has been made in completing a task.
85753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
85763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o span: Specifies the span relative to completing a task.
85773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
85783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o client_data: Pointer to any client data.
85793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
85803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
85813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
85823ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic const char *GetLocaleMonitorMessage(const char *text)
85833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
85843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
8585151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    message[MagickPathExtent],
8586151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    tag[MagickPathExtent];
85873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
85883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char
85893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *locale_message;
85903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
85913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register char
85923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p;
85933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
85947f6351fa5f71f9fd60f7f94bc2ed667b233d8006Cristy  (void) CopyMagickString(tag,text,MagickPathExtent);
85953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  p=strrchr(tag,'/');
85963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (p != (char *) NULL)
85973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *p='\0';
8598151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) FormatLocaleString(message,MagickPathExtent,"Monitor/%s",tag);
85993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  locale_message=GetLocaleMessage(message);
86003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (locale_message == message)
86013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(text);
86023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(locale_message);
86033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
86043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
8605bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate MagickBooleanType XMagickProgressMonitor(const char *tag,
86063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const MagickOffsetType quantum,const MagickSizeType span,
86073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  void *magick_unused(client_data))
86083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
86093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XWindows
86103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *windows;
86113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
86123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows=XSetWindows((XWindows *) ~0);
86133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows == (XWindows *) NULL)
86143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickTrue);
86153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows->info.mapped != MagickFalse)
86163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XProgressMonitorWidget(windows->display,windows,
86173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      GetLocaleMonitorMessage(tag),quantum,span);
86183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickTrue);
86193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
86203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
86213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
86223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
86243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
86253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
86263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X Q u e r y C o l o r D a t a b a s e                                     %
86273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
86283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
86293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
86303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86329950d57e1124b73f684fb5946e206994cefda628cristy%  XQueryColorCompliance() looks up a RGB values for a color given in the target
86333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  string.
86343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XQueryColorDatabase method is:
86363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86379950d57e1124b73f684fb5946e206994cefda628cristy%      MagickBooleanType XQueryColorCompliance(const char *target,XColor *color)
86383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
86403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o target: Specifies the color to lookup in the X color database.
86423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
8643101ab708b0574518ac5715da4d3915400e9df79acristy%    o color: A pointer to an PixelInfo structure.  The RGB value of the target
86443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      color is returned as this value.
86453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
86463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
86479950d57e1124b73f684fb5946e206994cefda628cristyMagickPrivate MagickBooleanType XQueryColorCompliance(const char *target,
86483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XColor *color)
86493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
86503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Colormap
86513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    colormap;
86523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
86533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static Display
86543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *display = (Display *) NULL;
86553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
86563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
86573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
86583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
86593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XColor
86603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    xcolor;
86613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
86623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
86633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize color return value.
86643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
86653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(color != (XColor *) NULL);
86663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  color->red=0;
86673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  color->green=0;
86683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  color->blue=0;
86693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  color->flags=(char) (DoRed | DoGreen | DoBlue);
86703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((target == (char *) NULL) || (*target == '\0'))
86713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    target="#ffffffffffff";
86723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
86733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Let the X server define the color for us.
86743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
86753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (display == (Display *) NULL)
86763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    display=XOpenDisplay((char *) NULL);
86773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (display == (Display *) NULL)
86783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
8679c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy      ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",target);
86803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(MagickFalse);
86813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
86823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  colormap=XDefaultColormap(display,XDefaultScreen(display));
86833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XParseColor(display,colormap,(char *) target,&xcolor);
86843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
8685c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy    ThrowXWindowException(XServerError,"ColorIsNotKnownToServer",target)
86863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
86873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
86883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      color->red=xcolor.red;
86893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      color->green=xcolor.green;
86903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      color->blue=xcolor.blue;
86913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      color->flags=xcolor.flags;
86923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
86933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(status != False ? MagickTrue : MagickFalse);
86943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
86953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
86963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
86973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
86993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
87003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
87013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X Q u e r y P o s i t i o n                                               %
87023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
87033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
87043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
87053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XQueryPosition() gets the pointer coordinates relative to a window.
87083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XQueryPosition method is:
87103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XQueryPosition(Display *display,const Window window,int *x,int *y)
87123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
87143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
87163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
87173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a Window.
87193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o x: Return the x coordinate of the pointer relative to the origin of the
87213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      window.
87223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o y: Return the y coordinate of the pointer relative to the origin of the
87243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      window.
87253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
8727534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristyMagickPrivate void XQueryPosition(Display *display,const Window window,int *x,
8728534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  int *y)
87293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
87303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
87313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x_root,
87323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y_root;
87333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
87343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
87353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    mask;
87363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
87373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
87383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root_window;
87393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
87403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
87413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
87423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (Window) NULL);
87433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(x != (int *) NULL);
87443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(y != (int *) NULL);
87453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XQueryPointer(display,window,&root_window,&root_window,&x_root,&y_root,
87463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x,y,&mask);
87473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
87483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
87493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
87503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
87523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
87533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
87543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X R e f r e s h W i n d o w                                               %
87553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
87563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
87573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
87583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
87593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XRefreshWindow() refreshes an image in a X window.
87613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XRefreshWindow method is:
87633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XRefreshWindow(Display *display,const XWindowInfo *window,
87653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const XEvent *event)
87663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
87683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
87703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
87713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a XWindowInfo structure.
87733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o event: Specifies a pointer to a XEvent structure.  If it is NULL,
87753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      the entire image is refreshed.
87763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
87773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
8778bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XRefreshWindow(Display *display,const XWindowInfo *window,
87793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const XEvent *event)
87803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
87813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
87823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x,
87833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y;
87843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
87853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
87863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    height,
87873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    width;
87883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
87893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
87903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
87913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (XWindowInfo *) NULL);
87923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->ximage == (XImage *) NULL)
87933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
87943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (event != (XEvent *) NULL)
87953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
87963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
87973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Determine geometry from expose event.
87983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
87993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      x=event->xexpose.x;
88003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      y=event->xexpose.y;
88013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      width=(unsigned int) event->xexpose.width;
88023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      height=(unsigned int) event->xexpose.height;
88033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
88043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
88053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
88063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      XEvent
88073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        sans_event;
88083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
88093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
88103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Refresh entire window; discard outstanding expose events.
88113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
88123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      x=0;
88133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      y=0;
88143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      width=window->width;
88153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      height=window->height;
88163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      while (XCheckTypedWindowEvent(display,window->id,Expose,&sans_event)) ;
8817a0e5ad575fbabf93f14a3748ae501376928998fccristy      if (window->matte_pixmap != (Pixmap) NULL)
8818a0e5ad575fbabf93f14a3748ae501376928998fccristy        {
8819a0e5ad575fbabf93f14a3748ae501376928998fccristy#if defined(MAGICKCORE_HAVE_SHAPE)
8820a0e5ad575fbabf93f14a3748ae501376928998fccristy          if (window->shape != MagickFalse)
8821a0e5ad575fbabf93f14a3748ae501376928998fccristy            XShapeCombineMask(display,window->id,ShapeBounding,0,0,
8822a0e5ad575fbabf93f14a3748ae501376928998fccristy              window->matte_pixmap,ShapeSet);
8823a0e5ad575fbabf93f14a3748ae501376928998fccristy#endif
8824a0e5ad575fbabf93f14a3748ae501376928998fccristy        }
88253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
88263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
88273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Check boundary conditions.
88283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
88293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((window->ximage->width-(x+window->x)) < (int) width)
88303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    width=(unsigned int) (window->ximage->width-(x+window->x));
88313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((window->ximage->height-(y+window->y)) < (int) height)
88323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    height=(unsigned int) (window->ximage->height-(y+window->y));
88333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
88343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Refresh image.
88353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
88363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->matte_pixmap != (Pixmap) NULL)
8837a0e5ad575fbabf93f14a3748ae501376928998fccristy    (void) XSetClipMask(display,window->annotate_context,window->matte_pixmap);
88383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->pixmap != (Pixmap) NULL)
88393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
88403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->depth > 1)
88413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XCopyArea(display,window->pixmap,window->id,
88423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window->annotate_context,x+window->x,y+window->y,width,height,x,y);
88433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      else
88443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XCopyPlane(display,window->pixmap,window->id,
88453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window->highlight_context,x+window->x,y+window->y,width,height,x,y,
88463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          1L);
88473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
88483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
88493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
88503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
88513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->shared_memory)
88523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XShmPutImage(display,window->id,window->annotate_context,
88533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window->ximage,x+window->x,y+window->y,x,y,width,height,MagickTrue);
88543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
88553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (window->shared_memory == MagickFalse)
88563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (void) XPutImage(display,window->id,window->annotate_context,
88573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          window->ximage,x+window->x,y+window->y,x,y,width,height);
88583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
88593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window->matte_pixmap != (Pixmap) NULL)
88603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XSetClipMask(display,window->annotate_context,None);
88613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFlush(display);
88623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
88633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
88643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
88653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
88673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
88683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
88693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X R e m o t e C o m m a n d                                               %
88703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
88713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
88723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
88733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
88753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XRemoteCommand() forces a remote display(1) to display the specified
88763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  image filename.
88773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
88783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XRemoteCommand method is:
88793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
88803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      MagickBooleanType XRemoteCommand(Display *display,const char *window,
88813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *filename)
88823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
88833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
88843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
88853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
88863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
88873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
88883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies the name or id of an X window.
88893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
88903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o filename: the name of the image filename to display.
88913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
88923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
88933ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport MagickBooleanType XRemoteCommand(Display *display,
88943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *window,const char *filename)
88953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
88963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Atom
88973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    remote_atom;
88983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
88993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
89003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    remote_window,
89013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root_window;
89023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
89033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(filename != (char *) NULL);
89043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
89053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (display == (Display *) NULL)
89063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    display=XOpenDisplay((char *) NULL);
89073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (display == (Display *) NULL)
89083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
89093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowException(XServerError,"UnableToOpenXServer",filename);
89103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(MagickFalse);
89113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
89123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  remote_atom=XInternAtom(display,"IM_PROTOCOLS",MagickFalse);
89133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  remote_window=(Window) NULL;
89143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  root_window=XRootWindow(display,XDefaultScreen(display));
89153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (window != (char *) NULL)
89163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
89173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      /*
89183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        Search window hierarchy and identify any clients by name or ID.
89193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      */
892002e64f85ab79992a87dd6979d4948488fec02817cristy      if (isdigit((int) ((unsigned char) *window)) != 0)
89213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        remote_window=XWindowByID(display,root_window,(Window)
89223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          strtol((char *) window,(char **) NULL,0));
89233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (remote_window == (Window) NULL)
89243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        remote_window=XWindowByName(display,root_window,window);
89253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
89263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (remote_window == (Window) NULL)
89273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    remote_window=XWindowByProperty(display,root_window,remote_atom);
89283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (remote_window == (Window) NULL)
89293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
89303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowXWindowException(XServerError,"UnableToConnectToRemoteDisplay",
89313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        filename);
89323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(MagickFalse);
89333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
89343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
89353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Send remote command.
89363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
89373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  remote_atom=XInternAtom(display,"IM_REMOTE_COMMAND",MagickFalse);
89383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XChangeProperty(display,remote_window,remote_atom,XA_STRING,8,
89393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    PropModeReplace,(unsigned char *) filename,(int) strlen(filename));
89403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSync(display,MagickFalse);
89413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickTrue);
89423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
89433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
89443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
89453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
89473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
89483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
8949534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%   X R e n d e r I m a g e                                                   %
8950534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%                                                                             %
8951534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%                                                                             %
8952534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%                                                                             %
8953534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
8954534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
8955534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%  XRenderImage() renders text on the image with an X11 font.  It also returns
8956534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%  the bounding box of the text relative to the image.
8957534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
8958534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%  The format of the XRenderImage method is:
8959534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
8960534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%      MagickBooleanType XRenderImage(Image *image,DrawInfo *draw_info,
8961534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%        const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
8962534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
8963534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%  A description of each parameter follows:
8964534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
8965534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%    o image: the image.
8966534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
8967534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%    o draw_info: the draw info.
8968534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
8969534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%    o offset: (x,y) location of text relative to image.
8970534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
8971534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%    o metrics: bounding box of text.
8972534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
8973534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%    o exception: return any errors or warnings in this structure.
8974534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
8975534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy*/
8976534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristyMagickPrivate MagickBooleanType XRenderImage(Image *image,
8977534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  const DrawInfo *draw_info,const PointInfo *offset,TypeMetric *metrics,
8978534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  ExceptionInfo *exception)
8979534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy{
8980534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  const char
8981534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    *client_name;
8982534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy
8983534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  DrawInfo
8984534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    cache_info;
8985534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy
8986534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  Display
8987534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    *display;
8988534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy
8989534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  ImageInfo
8990534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    *image_info;
8991534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy
8992534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  MagickBooleanType
8993534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    status;
8994534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy
8995534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  size_t
8996534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    height,
8997534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    width;
8998534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy
8999534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  XAnnotateInfo
9000534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    annotate_info;
9001534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy
9002534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  XFontStruct
9003534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    *font_info;
9004534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy
9005534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  XPixelInfo
9006534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    pixel;
9007534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy
9008534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  XResourceInfo
9009534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    resource_info;
9010534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy
9011534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  XrmDatabase
9012534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    resource_database;
9013534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy
9014534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  XStandardColormap
9015534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    *map_info;
9016534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy
9017534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  XVisualInfo
9018534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    *visual_info;
9019534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy
9020534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  /*
9021534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    Open X server connection.
9022534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  */
9023534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  display=XOpenDisplay(draw_info->server_name);
9024534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  if (display == (Display *) NULL)
9025534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    {
9026534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy      ThrowXWindowException(XServerError,"UnableToOpenXServer",
9027534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy        draw_info->server_name);
9028534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy      return(MagickFalse);
9029534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    }
9030534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  /*
9031534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    Get user defaults from X resource database.
9032534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  */
9033534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  (void) XSetErrorHandler(XError);
9034534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  image_info=AcquireImageInfo();
9035534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  client_name=GetClientName();
9036534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  resource_database=XGetResourceDatabase(display,client_name);
9037534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  XGetResourceInfo(image_info,resource_database,client_name,&resource_info);
9038534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  resource_info.close_server=MagickFalse;
9039534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  resource_info.colormap=PrivateColormap;
9040534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  resource_info.font=AcquireString(draw_info->font);
9041534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  resource_info.background_color=AcquireString("#ffffffffffff");
9042534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  resource_info.foreground_color=AcquireString("#000000000000");
9043534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  map_info=XAllocStandardColormap();
90445da5d1e6619ecfae6a4258dae7d41fcd94b6a860cristy  visual_info=(XVisualInfo *) NULL;
90455da5d1e6619ecfae6a4258dae7d41fcd94b6a860cristy  font_info=(XFontStruct *) NULL;
90465da5d1e6619ecfae6a4258dae7d41fcd94b6a860cristy  pixel.pixels=(unsigned long *) NULL;
9047534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  if (map_info == (XStandardColormap *) NULL)
9048534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    {
9049534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy      ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
9050534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy        image->filename);
9051534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy      return(MagickFalse);
9052534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    }
9053534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  /*
9054534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    Initialize visual info.
9055534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  */
9056534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  visual_info=XBestVisualInfo(display,map_info,&resource_info);
9057534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  if (visual_info == (XVisualInfo *) NULL)
9058534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    {
90595da5d1e6619ecfae6a4258dae7d41fcd94b6a860cristy      XFreeResources(display,visual_info,map_info,&pixel,font_info,
90605da5d1e6619ecfae6a4258dae7d41fcd94b6a860cristy        &resource_info,(XWindowInfo *) NULL);
9061c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy      ThrowXWindowException(XServerError,"UnableToGetVisual",image->filename);
9062534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy      return(MagickFalse);
9063534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    }
9064534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  map_info->colormap=(Colormap) NULL;
9065534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  /*
9066534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    Initialize Standard Colormap info.
9067534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  */
9068534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  XGetMapInfo(visual_info,XDefaultColormap(display,visual_info->screen),
9069534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    map_info);
9070534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  XGetPixelInfo(display,visual_info,map_info,&resource_info,(Image *) NULL,
9071534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    &pixel);
9072534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  pixel.annotate_context=XDefaultGC(display,visual_info->screen);
9073534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  /*
9074534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    Initialize font info.
9075534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  */
9076534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  font_info=XBestFont(display,&resource_info,MagickFalse);
9077534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  if (font_info == (XFontStruct *) NULL)
9078534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    {
9079534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy      XFreeResources(display,visual_info,map_info,&pixel,font_info,
9080534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy        &resource_info,(XWindowInfo *) NULL);
90815da5d1e6619ecfae6a4258dae7d41fcd94b6a860cristy      ThrowXWindowException(XServerError,"UnableToLoadFont",draw_info->font);
9082534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy      return(MagickFalse);
9083534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    }
9084534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  cache_info=(*draw_info);
9085534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  /*
9086534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    Initialize annotate info.
9087534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  */
9088534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  XGetAnnotateInfo(&annotate_info);
9089534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  annotate_info.stencil=ForegroundStencil;
9090534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  if (cache_info.font != draw_info->font)
9091534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    {
9092534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy      /*
9093534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy        Type name has changed.
9094534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy      */
9095534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy      (void) XFreeFont(display,font_info);
9096534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy      (void) CloneString(&resource_info.font,draw_info->font);
9097534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy      font_info=XBestFont(display,&resource_info,MagickFalse);
9098534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy      if (font_info == (XFontStruct *) NULL)
9099534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy        {
9100534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy          ThrowXWindowException(XServerError,"UnableToLoadFont",
9101534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy            draw_info->font);
9102534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy          return(MagickFalse);
9103534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy        }
9104534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    }
9105534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  if (image->debug != MagickFalse)
9106534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    (void) LogMagickEvent(AnnotateEvent,GetMagickModule(),
9107534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy      "Font %s; pointsize %g",draw_info->font != (char *) NULL ?
9108534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy      draw_info->font : "none",draw_info->pointsize);
9109534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  cache_info=(*draw_info);
9110534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  annotate_info.font_info=font_info;
9111534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  annotate_info.text=(char *) draw_info->text;
9112534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  annotate_info.width=(unsigned int) XTextWidth(font_info,draw_info->text,(int)
9113534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    strlen(draw_info->text));
9114534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  annotate_info.height=(unsigned int) font_info->ascent+font_info->descent;
9115534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  metrics->pixels_per_em.x=(double) font_info->max_bounds.width;
9116534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  metrics->pixels_per_em.y=(double) font_info->ascent+font_info->descent;
9117534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  metrics->ascent=(double) font_info->ascent+4;
9118534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  metrics->descent=(double) (-font_info->descent);
9119534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  metrics->width=annotate_info.width/ExpandAffine(&draw_info->affine);
9120534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  metrics->height=font_info->ascent+font_info->descent;
9121534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  metrics->max_advance=(double) font_info->max_bounds.width;
9122534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  metrics->bounds.x1=0.0;
9123534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  metrics->bounds.y1=metrics->descent;
9124534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  metrics->bounds.x2=metrics->ascent+metrics->descent;
9125534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  metrics->bounds.y2=metrics->ascent+metrics->descent;
9126534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  metrics->underline_position=(-2.0);
9127534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  metrics->underline_thickness=1.0;
9128534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  if (draw_info->render == MagickFalse)
9129534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    return(MagickTrue);
9130534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  if (draw_info->fill.alpha == TransparentAlpha)
9131534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    return(MagickTrue);
9132534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  /*
9133534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    Render fill color.
9134534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  */
9135534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  width=annotate_info.width;
9136534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  height=annotate_info.height;
9137534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  if ((fabs(draw_info->affine.rx) >= MagickEpsilon) ||
9138534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy      (fabs(draw_info->affine.ry) >= MagickEpsilon))
9139534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    {
9140534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy      if ((fabs(draw_info->affine.sx-draw_info->affine.sy) < MagickEpsilon) &&
9141534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy          (fabs(draw_info->affine.rx+draw_info->affine.ry) < MagickEpsilon))
9142534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy        annotate_info.degrees=(double) (180.0/MagickPI)*
9143534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy          atan2(draw_info->affine.rx,draw_info->affine.sx);
9144534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    }
9145151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) FormatLocaleString(annotate_info.geometry,MagickPathExtent,
9146534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    "%.20gx%.20g%+.20g%+.20g",(double) width,(double) height,
9147534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    ceil(offset->x-0.5),ceil(offset->y-metrics->ascent-metrics->descent+
9148534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    draw_info->interline_spacing-0.5));
9149534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  pixel.pen_color.red=ScaleQuantumToShort(draw_info->fill.red);
9150534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  pixel.pen_color.green=ScaleQuantumToShort(draw_info->fill.green);
9151534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  pixel.pen_color.blue=ScaleQuantumToShort(draw_info->fill.blue);
9152534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  status=XAnnotateImage(display,&pixel,&annotate_info,image,exception);
9153534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  if (status == 0)
9154534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    {
9155534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy      ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
9156534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy        image->filename);
9157534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy      return(MagickFalse);
9158534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    }
9159534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  return(MagickTrue);
9160534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy}
9161534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy
9162534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy/*
9163534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9164534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%                                                                             %
9165534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%                                                                             %
9166534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%                                                                             %
91673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X R e t a i n W i n d o w C o l o r s                                     %
91683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
91693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
91703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
91713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
91733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XRetainWindowColors() sets X11 color resources on a window.  This preserves
91743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  the colors associated with an image displayed on the window.
91753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
91763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XRetainWindowColors method is:
91773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
91783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XRetainWindowColors(Display *display,const Window window)
91793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
91803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
91813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
91823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server; returned from
91833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
91843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
91853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: Specifies a pointer to a XWindowInfo structure.
91863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
91873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
91883ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport void XRetainWindowColors(Display *display,const Window window)
91893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
91903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Atom
91913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    property;
91923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
91933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Pixmap
91943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    pixmap;
91953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
91963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
91973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Put property on the window.
91983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
91993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
92003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
92013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (Window) NULL);
92023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  property=XInternAtom(display,"_XSETROOT_ID",MagickFalse);
92033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (property == (Atom) NULL)
92043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
9205c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy      ThrowXWindowException(XServerError,"UnableToCreateProperty",
92063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        "_XSETROOT_ID");
92073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return;
92083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
92093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  pixmap=XCreatePixmap(display,window,1,1,1);
92103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (pixmap == (Pixmap) NULL)
92113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
9212c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy      ThrowXWindowException(XServerError,"UnableToCreateBitmap","");
92133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return;
92143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
92153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XChangeProperty(display,window,property,XA_PIXMAP,32,PropModeReplace,
92163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (unsigned char *) &pixmap,1);
92173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XSetCloseDownMode(display,RetainPermanent);
92183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
92193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
92203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
92213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
92233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
92243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
92253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X S e l e c t W i n d o w                                                 %
92263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
92273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
92283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
92293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
92313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XSelectWindow() allows a user to select a window using the mouse.  If the
92323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  mouse moves, a cropping rectangle is drawn and the extents of the rectangle
92333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  is returned in the crop_info structure.
92343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
92353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XSelectWindow function is:
92363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
92373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      target_window=XSelectWindow(display,crop_info)
92383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
92393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
92403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
92413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: XSelectWindow returns the window id.
92423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
92433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a pointer to the Display structure;  returned from
92443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
92453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
92463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o crop_info: Specifies a pointer to a RectangleInfo structure.  It
92473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      contains the extents of any cropping rectangle.
92483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
92493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
92503ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Window XSelectWindow(Display *display,RectangleInfo *crop_info)
92513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
92523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define MinimumCropArea  (unsigned int) 9
92533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
92543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Cursor
92553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    target_cursor;
92563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
92573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  GC
92583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    annotate_context;
92593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
92603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
92613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    presses,
92623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    x_offset,
92633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    y_offset;
92643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
92653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
92663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
92673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
92683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
92693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root_window,
92703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    target_window;
92713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
92723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XEvent
92733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    event;
92743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
92753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XGCValues
92763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    context_values;
92773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
92783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
92793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Initialize graphic context.
92803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
92813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
92823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
92833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(crop_info != (RectangleInfo *) NULL);
92843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  root_window=XRootWindow(display,XDefaultScreen(display));
92853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  context_values.background=XBlackPixel(display,XDefaultScreen(display));
92863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  context_values.foreground=XWhitePixel(display,XDefaultScreen(display));
92873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  context_values.function=GXinvert;
92883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  context_values.plane_mask=
92893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    context_values.background ^ context_values.foreground;
92903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  context_values.subwindow_mode=IncludeInferiors;
9291bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  annotate_context=XCreateGC(display,root_window,(size_t) (GCBackground |
92923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    GCForeground | GCFunction | GCSubwindowMode),&context_values);
92933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (annotate_context == (GC) NULL)
92943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(MagickFalse);
92953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
92963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Grab the pointer using target cursor.
92973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
92983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  target_cursor=XMakeCursor(display,root_window,XDefaultColormap(display,
92993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    XDefaultScreen(display)),(char * ) "white",(char * ) "black");
93003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XGrabPointer(display,root_window,MagickFalse,(unsigned int)
93013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (ButtonPressMask | ButtonReleaseMask | ButtonMotionMask),GrabModeSync,
93023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    GrabModeAsync,root_window,target_cursor,CurrentTime);
93033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status != GrabSuccess)
93043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
9305c38fbf5b3fd6e8baf7b455793bebb7220952d70dcristy      ThrowXWindowException(XServerError,"UnableToGrabMouse","");
93063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return((Window) NULL);
93073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
93083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
93093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Select a window.
93103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
93113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  crop_info->width=0;
93123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  crop_info->height=0;
93133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  presses=0;
93143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  target_window=(Window) NULL;
93153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  x_offset=0;
93163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  y_offset=0;
93173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  do
93183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
93193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if ((crop_info->width*crop_info->height) >= MinimumCropArea)
93203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDrawRectangle(display,root_window,annotate_context,
93213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
93223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) crop_info->height-1);
93233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    /*
93243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Allow another event.
93253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    */
93263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XAllowEvents(display,SyncPointer,CurrentTime);
93273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XWindowEvent(display,root_window,ButtonPressMask |
93283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ButtonReleaseMask | ButtonMotionMask,&event);
93293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if ((crop_info->width*crop_info->height) >= MinimumCropArea)
93303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XDrawRectangle(display,root_window,annotate_context,
93313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (int) crop_info->x,(int) crop_info->y,(unsigned int) crop_info->width-1,
93323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (unsigned int) crop_info->height-1);
93333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    switch (event.type)
93343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
93353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case ButtonPress:
93363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
93373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        target_window=XGetSubwindow(display,event.xbutton.subwindow,
93383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          event.xbutton.x,event.xbutton.y);
93393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if (target_window == (Window) NULL)
93403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          target_window=root_window;
93413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        x_offset=event.xbutton.x_root;
93423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        y_offset=event.xbutton.y_root;
9343ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy        crop_info->x=(ssize_t) x_offset;
9344ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy        crop_info->y=(ssize_t) y_offset;
93453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        crop_info->width=0;
93463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        crop_info->height=0;
93473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        presses++;
93483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
93493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
93503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case ButtonRelease:
93513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
93523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        presses--;
93533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
93543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
93553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      case MotionNotify:
93563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      {
93573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
93583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Discard pending button motion events.
93593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
93603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        while (XCheckMaskEvent(display,ButtonMotionMask,&event)) ;
9361ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy        crop_info->x=(ssize_t) event.xmotion.x;
9362ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy        crop_info->y=(ssize_t) event.xmotion.y;
93633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        /*
93643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          Check boundary conditions.
93653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        */
93663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if ((int) crop_info->x < x_offset)
9367ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy          crop_info->width=(size_t) (x_offset-crop_info->x);
93683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        else
93693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
9370ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy            crop_info->width=(size_t) (crop_info->x-x_offset);
9371ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy            crop_info->x=(ssize_t) x_offset;
93723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
93733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        if ((int) crop_info->y < y_offset)
9374ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy          crop_info->height=(size_t) (y_offset-crop_info->y);
93753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        else
93763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          {
9377ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy            crop_info->height=(size_t) (crop_info->y-y_offset);
9378ecd0ab5350482e4a2ea003705e3e0b2120b66384cristy            crop_info->y=(ssize_t) y_offset;
93793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          }
93803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      }
93813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      default:
93823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        break;
93833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
93843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  } while ((target_window == (Window) NULL) || (presses > 0));
93853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XUngrabPointer(display,CurrentTime);
93863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFreeCursor(display,target_cursor);
93873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) XFreeGC(display,annotate_context);
93883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((crop_info->width*crop_info->height) < MinimumCropArea)
93893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
93903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      crop_info->width=0;
93913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      crop_info->height=0;
93923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
93933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((crop_info->width != 0) && (crop_info->height != 0))
93943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    target_window=root_window;
93953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(target_window);
93963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
93973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
93983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
93993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X S e t C u r s o r S t a t e                                             %
94043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XSetCursorState() sets the cursor state to busy, otherwise the cursor are
94103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  reset to their default.
94113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XXSetCursorState method is:
94133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XSetCursorState(display,windows,const MagickStatusType state)
94153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
94173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a connection to an X server;  returned from
94193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
94203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o windows: Specifies a pointer to a XWindows structure.
94223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o state: An unsigned integer greater than 0 sets the cursor state
94243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      to busy, otherwise the cursor are reset to their default.
94253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
9427bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XSetCursorState(Display *display,XWindows *windows,
94283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const MagickStatusType state)
94293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
94303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
94313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
94323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(windows != (XWindows *) NULL);
94333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (state)
94343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
94353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,windows->image.id,
94363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->image.busy_cursor);
94373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,windows->pan.id,
94383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->pan.busy_cursor);
94393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,windows->magnify.id,
94403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->magnify.busy_cursor);
94413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,windows->command.id,
94423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->command.busy_cursor);
94433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
94443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  else
94453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
94463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,windows->image.id,
94473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->image.cursor);
94483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
94493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,windows->magnify.id,
94503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->magnify.cursor);
94513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,windows->command.id,
94523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->command.cursor);
94533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XCheckDefineCursor(display,windows->command.id,
94543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        windows->widget.cursor);
94553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
94563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
94573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows->info.mapped=MagickFalse;
94583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
94593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
94603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
94613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X S e t W i n d o w s                                                     %
94663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XSetWindows() sets the X windows structure if the windows info is specified.
94723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  Otherwise the current windows structure is returned.
94733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XSetWindows method is:
94753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XWindows *XSetWindows(XWindows *windows_info)
94773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
94793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o windows_info: Initialize the Windows structure with this information.
94813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
94823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
9483bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate XWindows *XSetWindows(XWindows *windows_info)
94843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
94853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  static XWindows
94863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *windows = (XWindows *) NULL;
94873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
94883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (windows_info != (XWindows *) ~0)
94893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
94903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows=(XWindows *) RelinquishMagickMemory(windows);
94913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      windows=windows_info;
94923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
94933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(windows);
94943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
94953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
94963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
94973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
94993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
95003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X U s e r P r e f e r e n c e s                                           %
95013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
95023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
95033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
95043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XUserPreferences() saves the preferences in a configuration file in the
95073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  users' home directory.
95083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XUserPreferences method is:
95103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XUserPreferences(XResourceInfo *resource_info)
95123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
95143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
95163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
9518bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XUserPreferences(XResourceInfo *resource_info)
95193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
95203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(X11_PREFERENCES_PATH)
95213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
9522151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    cache[MagickPathExtent],
9523151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    filename[MagickPathExtent],
9524151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    specifier[MagickPathExtent];
95253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
95263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char
9527104cea817534e8601291610f22e496c10f8f9ddbcristy    *client_name,
95283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *value;
95293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
95303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmDatabase
95313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    preferences_database;
95323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
95333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  /*
95343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    Save user preferences to the client configuration file.
95353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  */
95363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(resource_info != (XResourceInfo *) NULL);
9537104cea817534e8601291610f22e496c10f8f9ddbcristy  client_name=GetClientName();
95383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  preferences_database=XrmGetStringDatabase("");
9539151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) FormatLocaleString(specifier,MagickPathExtent,"%s.backdrop",client_name);
95403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  value=resource_info->backdrop ? "True" : "False";
95413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutStringResource(&preferences_database,specifier,(char *) value);
9542151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) FormatLocaleString(specifier,MagickPathExtent,"%s.colormap",client_name);
95433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  value=resource_info->colormap == SharedColormap ? "Shared" : "Private";
95443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutStringResource(&preferences_database,specifier,(char *) value);
9545151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) FormatLocaleString(specifier,MagickPathExtent,"%s.confirmExit",
9546104cea817534e8601291610f22e496c10f8f9ddbcristy    client_name);
95473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  value=resource_info->confirm_exit ? "True" : "False";
95483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutStringResource(&preferences_database,specifier,(char *) value);
9549151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) FormatLocaleString(specifier,MagickPathExtent,"%s.confirmEdit",
9550104cea817534e8601291610f22e496c10f8f9ddbcristy    client_name);
95513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  value=resource_info->confirm_edit ? "True" : "False";
95523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutStringResource(&preferences_database,specifier,(char *) value);
9553151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) FormatLocaleString(specifier,MagickPathExtent,"%s.displayWarnings",
9554104cea817534e8601291610f22e496c10f8f9ddbcristy    client_name);
95553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  value=resource_info->display_warnings ? "True" : "False";
95563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutStringResource(&preferences_database,specifier,(char *) value);
9557151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) FormatLocaleString(specifier,MagickPathExtent,"%s.dither",client_name);
9558cbda611068350bf4459f2dda1951f8823702e129cristy  value=resource_info->quantize_info->dither_method != NoDitherMethod ?
9559cbda611068350bf4459f2dda1951f8823702e129cristy    "True" : "False";
95603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutStringResource(&preferences_database,specifier,(char *) value);
9561151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) FormatLocaleString(specifier,MagickPathExtent,"%s.gammaCorrect",
9562104cea817534e8601291610f22e496c10f8f9ddbcristy    client_name);
95633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  value=resource_info->gamma_correct ? "True" : "False";
95643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutStringResource(&preferences_database,specifier,(char *) value);
9565151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) FormatLocaleString(specifier,MagickPathExtent,"%s.undoCache",client_name);
9566151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) FormatLocaleString(cache,MagickPathExtent,"%.20g",(double)
95673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    resource_info->undo_cache);
95683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutStringResource(&preferences_database,specifier,cache);
9569151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) FormatLocaleString(specifier,MagickPathExtent,"%s.usePixmap",client_name);
95703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  value=resource_info->use_pixmap ? "True" : "False";
95713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutStringResource(&preferences_database,specifier,(char *) value);
9572151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) FormatLocaleString(filename,MagickPathExtent,"%s%src",
9573104cea817534e8601291610f22e496c10f8f9ddbcristy    X11_PREFERENCES_PATH,client_name);
95743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ExpandFilename(filename);
95753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XrmPutFileDatabase(preferences_database,filename);
95763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
95773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
95783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
95793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
95803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
95823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
95833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
95843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X V i s u a l C l a s s N a m e                                           %
95853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
95863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
95873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
95883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XVisualClassName() returns the visual class name as a character string.
95913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XVisualClassName method is:
95933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      char *XVisualClassName(const int visual_class)
95953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
95973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
95983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o visual_type: XVisualClassName returns the visual class as a character
95993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      string.
96003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o class: Specifies the visual class.
96023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
96043ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic const char *XVisualClassName(const int visual_class)
96053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
96063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  switch (visual_class)
96073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
96083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case StaticGray: return("StaticGray");
96093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case GrayScale: return("GrayScale");
96103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case StaticColor: return("StaticColor");
96113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case PseudoColor: return("PseudoColor");
96123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case TrueColor: return("TrueColor");
96133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    case DirectColor: return("DirectColor");
96143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
96153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return("unknown visual class");
96163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
96173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
96183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
96193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
96213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
96223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
96233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X W a r n i n g                                                           %
96243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
96253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
96263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
96273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XWarning() displays a warning reason in a Notice widget.
96303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XWarning method is:
96323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XWarning(const unsigned int warning,const char *reason,
96343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%        const char *description)
96353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
96373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o warning: Specifies the numeric warning category.
96393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o reason: Specifies the reason to display before terminating the
96413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      program.
96423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o description: Specifies any description to the reason.
96443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
9646bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate void XWarning(const ExceptionType magick_unused(warning),
96473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *reason,const char *description)
96483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
96493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
9650151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    text[MagickPathExtent];
96513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
96523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XWindows
96533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *windows;
96543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
96553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (reason == (char *) NULL)
96563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
9657151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) CopyMagickString(text,reason,MagickPathExtent);
9658151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) ConcatenateMagickString(text,":",MagickPathExtent);
96593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  windows=XSetWindows((XWindows *) ~0);
96603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XNoticeWidget(windows->display,windows,text,(char *) description);
96613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
96623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
96633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
96643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
96663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
96673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
96683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X W i n d o w B y I D                                                     %
96693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
96703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
96713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
96723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XWindowByID() locates a child window with a given ID.  If not window with
96753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  the given name is found, 0 is returned.   Only the window specified and its
96763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  subwindows are searched.
96773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XWindowByID function is:
96793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      child=XWindowByID(display,window,id)
96813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
96833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o child: XWindowByID returns the window with the specified
96853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      id.  If no windows are found, XWindowByID returns 0.
96863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a pointer to the Display structure;  returned from
96883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
96893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o id: Specifies the id of the window to locate.
96913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
96923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
9693bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate Window XWindowByID(Display *display,const Window root_window,
9694bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy  const size_t id)
96953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
96963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  RectangleInfo
96973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    rectangle_info;
96983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
96993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
97003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
97013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
97023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
97033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
97043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
97053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
97063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_children;
97073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
97083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
97093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    child,
97103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *children,
97113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window;
97123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
97133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
97143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
97153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(root_window != (Window) NULL);
97163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (id == 0)
97173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return(XSelectWindow(display,&rectangle_info));
97183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (root_window == id)
9719dfe2b6658f367de8f84405263f62768fb853adafcristy    return(root_window);
97203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XQueryTree(display,root_window,&child,&child,&children,
97213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &number_children);
97223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
97233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return((Window) NULL);
97243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window=(Window) NULL;
97253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; i < (int) number_children; i++)
97263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
97273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    /*
97283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Search each child and their children.
97293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    */
97303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window=XWindowByID(display,children[i],id);
97313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (window != (Window) NULL)
97323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
97333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
97343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (children != (Window *) NULL)
97353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XFree((void *) children);
97363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(window);
97373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
97383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
97393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
97403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
97423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
97433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
97443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X W i n d o w B y N a m e                                                 %
97453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
97463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
97473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
97483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
97493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
97503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XWindowByName() locates a window with a given name on a display.  If no
97513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  window with the given name is found, 0 is returned. If more than one window
97523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  has the given name, the first one is returned.  Only root and its children
97533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  are searched.
97543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
97553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XWindowByName function is:
97563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
97573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      window=XWindowByName(display,root_window,name)
97583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
97593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
97603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
97613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o window: XWindowByName returns the window id.
97623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
97633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a pointer to the Display structure;  returned from
97643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
97653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
97663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o root_window: Specifies the id of the root window.
97673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
97683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o name: Specifies the name of the window to locate.
97693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
97703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
9771bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate Window XWindowByName(Display *display,const Window root_window,
97723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const char *name)
97733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
97743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  register int
97753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i;
97763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
97773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
97783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
97793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
97803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
97813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_children;
97823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
97833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
97843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *children,
97853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    child,
97863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window;
97873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
97883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  XTextProperty
97893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window_name;
97903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
97913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
97923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(root_window != (Window) NULL);
97933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(name != (char *) NULL);
97943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",name);
97953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (XGetWMName(display,root_window,&window_name) != 0)
97963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (LocaleCompare((char *) window_name.value,name) == 0)
97973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return(root_window);
97983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XQueryTree(display,root_window,&child,&child,&children,
97993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    &number_children);
98003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
98013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return((Window) NULL);
98023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  window=(Window) NULL;
98033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; i < (int) number_children; i++)
98043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
98053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    /*
98063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      Search each child and their children.
98073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    */
98083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    window=XWindowByName(display,children[i],name);
98093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (window != (Window) NULL)
98103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      break;
98113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
98123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (children != (Window *) NULL)
98133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XFree((void *) children);
98143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(window);
98153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
98163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
98173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
98183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
98203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
98213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
98223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X W i n d o w B y P r o p e r y                                           %
98233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
98243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
98253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
98263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
98283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XWindowByProperty() locates a child window with a given property. If not
98293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  window with the given name is found, 0 is returned.  If more than one window
98303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  has the given property, the first one is returned.  Only the window
98313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  specified and its subwindows are searched.
98323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
98333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XWindowByProperty function is:
98343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
98353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      child=XWindowByProperty(display,window,property)
98363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
98373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
98383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
98393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o child: XWindowByProperty returns the window id with the specified
98403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      property.  If no windows are found, XWindowByProperty returns 0.
98413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
98423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o display: Specifies a pointer to the Display structure;  returned from
98433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      XOpenDisplay.
98443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
98453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o property: Specifies the property of the window to locate.
98463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
98473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
9848bcbda3fd7d9f3084869f5cebabceb0324c3b2cd7cristyMagickPrivate Window XWindowByProperty(Display *display,const Window window,
98493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  const Atom property)
98503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
98513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Atom
98523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    type;
98533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
98543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
98553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    format;
98563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
98573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Status
98583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status;
98593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
98603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned char
98613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *data;
98623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
98633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unsigned int
98643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    i,
98653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_children;
98663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
9867f2faecf9facdbbb14fcba373365f9f691a9658e0cristy  unsigned long
98683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    after,
98693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    number_items;
98703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
98713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Window
98723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    child,
98733ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *children,
98743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    parent,
98753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    root;
98763ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
98773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
98783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(display != (Display *) NULL);
98793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(window != (Window) NULL);
98803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(property != (Atom) NULL);
98813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  status=XQueryTree(display,window,&root,&parent,&children,&number_children);
98823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (status == False)
98833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return((Window) NULL);
98843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  type=(Atom) NULL;
98853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  child=(Window) NULL;
98863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; (i < number_children) && (child == (Window) NULL); i++)
98873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  {
98883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    status=XGetWindowProperty(display,children[i],property,0L,0L,MagickFalse,
98893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (Atom) AnyPropertyType,&type,&format,&number_items,&after,&data);
98903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if (data != NULL)
98913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      (void) XFree((void *) data);
98923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    if ((status == Success) && (type != (Atom) NULL))
98933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      child=children[i];
98943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  }
98953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  for (i=0; (i < number_children) && (child == (Window) NULL); i++)
98963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    child=XWindowByProperty(display,children[i],property);
98973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (children != (Window *) NULL)
98983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) XFree((void *) children);
98993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(child);
99003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
99013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#else
99023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
99033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
99043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
99063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
99073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
99083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X I m p o r t I m a g e                                                   %
99093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
99103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
99113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
99123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
99143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XImportImage() reads an image from an X window.
99153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
99163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XImportImage method is:
99173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9918a0dc96a5df0a380c9ef855cc7f2a5f264bec8af3cristy%      Image *XImportImage(const ImageInfo *image_info,XImportInfo *ximage_info,
9919a0dc96a5df0a380c9ef855cc7f2a5f264bec8af3cristy%        ExceptionInfo *exception)
99203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
99213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
99223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
99233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image_info: the image info..
99243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
99253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o ximage_info: Specifies a pointer to an XImportInfo structure.
99263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
9927a0dc96a5df0a380c9ef855cc7f2a5f264bec8af3cristy%    o exception: return any errors or warnings in this structure.
9928a0dc96a5df0a380c9ef855cc7f2a5f264bec8af3cristy%
99293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
99304bc52025ac134838f6a62b8dc8ea6cfacab91796cristyMagickExport Image *XImportImage(const ImageInfo *image_info,
9931a0dc96a5df0a380c9ef855cc7f2a5f264bec8af3cristy  XImportInfo *ximage_info,ExceptionInfo *exception)
99323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
99333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(image_info != (const ImageInfo *) NULL);
9934e1c94d9d25db6b0dd7a5028ffee31d1057855d73cristy  assert(image_info->signature == MagickCoreSignature);
99353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (image_info->debug != MagickFalse)
99363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
99373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      image_info->filename);
99383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(ximage_info != (XImportInfo *) NULL);
9939a0dc96a5df0a380c9ef855cc7f2a5f264bec8af3cristy  assert(exception != (ExceptionInfo *) NULL);
9940e1c94d9d25db6b0dd7a5028ffee31d1057855d73cristy  assert(exception->signature == MagickCoreSignature);
99413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return((Image *) NULL);
99423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
9943534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy
9944534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy/*
9945534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9946534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%                                                                             %
9947534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%                                                                             %
9948534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%                                                                             %
9949534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%   X R e n d e r X 1 1                                                       %
9950534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%                                                                             %
9951534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%                                                                             %
9952534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%                                                                             %
9953534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
9954534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
9955534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%  XRenderImage() renders text on the image with an X11 font.  It also returns
9956534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%  the bounding box of the text relative to the image.
9957534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
9958534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%  The format of the XRenderImage method is:
9959534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
9960534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%      MagickBooleanType XRenderImage(Image *image,DrawInfo *draw_info,
9961534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%        const PointInfo *offset,TypeMetric *metrics,ExceptionInfo *exception)
9962534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
9963534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%  A description of each parameter follows:
9964534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
9965534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%    o image: the image.
9966534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
9967534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%    o draw_info: the draw info.
9968534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
9969534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%    o offset: (x,y) location of text relative to image.
9970534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
9971534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%    o metrics: bounding box of text.
9972534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
9973534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%    o exception: return any errors or warnings in this structure.
9974534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy%
9975534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy*/
9976534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristyMagickPrivate MagickBooleanType XRenderImage(Image *image,
9977534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  const DrawInfo *draw_info,const PointInfo *offset,TypeMetric *metrics,
9978534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  ExceptionInfo *exception)
9979534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy{
9980534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  (void) draw_info;
9981534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  (void) offset;
9982534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  (void) metrics;
9983534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  (void) ThrowMagickException(exception,GetMagickModule(),
9984534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    MissingDelegateError,"DelegateLibrarySupportNotBuiltIn","'%s' (X11)",
9985534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy    image->filename);
9986534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy  return(MagickFalse);
9987534d0a353b31242ce2f7b26c4eb4fe53f914d0f5cristy}
99883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
99893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
99903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
99913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
99933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
99943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
9995576974eba31c1fac74b2492a74862b2fcd50f21ccristy+   X C o m p o n e n t G e n e s i s                                         %
9996576974eba31c1fac74b2492a74862b2fcd50f21ccristy%                                                                             %
9997576974eba31c1fac74b2492a74862b2fcd50f21ccristy%                                                                             %
9998576974eba31c1fac74b2492a74862b2fcd50f21ccristy%                                                                             %
9999576974eba31c1fac74b2492a74862b2fcd50f21ccristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10000576974eba31c1fac74b2492a74862b2fcd50f21ccristy%
10001576974eba31c1fac74b2492a74862b2fcd50f21ccristy%  XComponentGenesis() instantiates the X component.
10002576974eba31c1fac74b2492a74862b2fcd50f21ccristy%
10003576974eba31c1fac74b2492a74862b2fcd50f21ccristy%  The format of the XComponentGenesis method is:
10004576974eba31c1fac74b2492a74862b2fcd50f21ccristy%
10005576974eba31c1fac74b2492a74862b2fcd50f21ccristy%      MagickBooleanType XComponentGenesis(void)
10006576974eba31c1fac74b2492a74862b2fcd50f21ccristy%
10007576974eba31c1fac74b2492a74862b2fcd50f21ccristy*/
100085ff4eaf57b3cd47d0371f204f865cbba614674a0cristyMagickPrivate MagickBooleanType XComponentGenesis(void)
10009576974eba31c1fac74b2492a74862b2fcd50f21ccristy{
10010576974eba31c1fac74b2492a74862b2fcd50f21ccristy  return(MagickTrue);
10011576974eba31c1fac74b2492a74862b2fcd50f21ccristy}
10012576974eba31c1fac74b2492a74862b2fcd50f21ccristy
10013576974eba31c1fac74b2492a74862b2fcd50f21ccristy/*
10014576974eba31c1fac74b2492a74862b2fcd50f21ccristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10015576974eba31c1fac74b2492a74862b2fcd50f21ccristy%                                                                             %
10016576974eba31c1fac74b2492a74862b2fcd50f21ccristy%                                                                             %
10017576974eba31c1fac74b2492a74862b2fcd50f21ccristy%                                                                             %
100183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   X G e t I m p o r t I n f o                                               %
100193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
100203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
100213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
100223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
100243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  XGetImportInfo() initializes the XImportInfo structure.
100253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
100263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the XGetImportInfo method is:
100273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
100283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      void XGetImportInfo(XImportInfo *ximage_info)
100293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
100303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
100313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
100323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o ximage_info: Specifies a pointer to an ImageInfo structure.
100333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
100343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
100353ed852eea50f9d4cd633efb8c2b054b8e33c253cristyMagickExport void XGetImportInfo(XImportInfo *ximage_info)
100363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
100373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  assert(ximage_info != (XImportInfo *) NULL);
100383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ximage_info->frame=MagickFalse;
100393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ximage_info->borders=MagickFalse;
100403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ximage_info->screen=MagickFalse;
100413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ximage_info->descend=MagickTrue;
100423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ximage_info->silent=MagickFalse;
100433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
10044