PageRenderTime 74ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 2ms

/MagickCore/xwindow.c

https://gitlab.com/ImageMagick/ImageMagick
C | 10049 lines | 6708 code | 410 blank | 2931 comment | 1675 complexity | e4692268bb93fb48f1137ff880e30934 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  3. % %
  4. % %
  5. % %
  6. % X X W W IIIII N N DDDD OOO W W %
  7. % X X W W I NN N D D O O W W %
  8. % X W W I N N N D D O O W W %
  9. % X X W W W I N NN D D O O W W W %
  10. % X X W W IIIII N N DDDD OOO W W %
  11. % %
  12. % %
  13. % MagickCore X11 Utility Methods %
  14. % %
  15. % Software Design %
  16. % Cristy %
  17. % July 1992 %
  18. % %
  19. % %
  20. % Copyright 1999-2019 ImageMagick Studio LLC, a non-profit organization %
  21. % dedicated to making software imaging solutions freely available. %
  22. % %
  23. % You may not use this file except in compliance with the License. You may %
  24. % obtain a copy of the License at %
  25. % %
  26. % https://imagemagick.org/script/license.php %
  27. % %
  28. % Unless required by applicable law or agreed to in writing, software %
  29. % distributed under the License is distributed on an "AS IS" BASIS, %
  30. % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
  31. % See the License for the specific language governing permissions and %
  32. % limitations under the License. %
  33. % %
  34. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  35. %
  36. %
  37. */
  38. /*
  39. Include declarations.
  40. */
  41. #include "MagickCore/studio.h"
  42. #include "MagickCore/animate.h"
  43. #include "MagickCore/artifact.h"
  44. #include "MagickCore/blob.h"
  45. #include "MagickCore/cache.h"
  46. #include "MagickCore/client.h"
  47. #include "MagickCore/color.h"
  48. #include "MagickCore/color-private.h"
  49. #include "MagickCore/colormap.h"
  50. #include "MagickCore/composite.h"
  51. #include "MagickCore/constitute.h"
  52. #include "MagickCore/display.h"
  53. #include "MagickCore/distort.h"
  54. #include "MagickCore/exception.h"
  55. #include "MagickCore/exception-private.h"
  56. #include "MagickCore/geometry.h"
  57. #include "MagickCore/identify.h"
  58. #include "MagickCore/image.h"
  59. #include "MagickCore/image-private.h"
  60. #include "MagickCore/list.h"
  61. #include "MagickCore/locale_.h"
  62. #include "MagickCore/log.h"
  63. #include "MagickCore/magick.h"
  64. #include "MagickCore/memory_.h"
  65. #include "MagickCore/memory-private.h"
  66. #include "MagickCore/monitor.h"
  67. #include "MagickCore/nt-base-private.h"
  68. #include "MagickCore/option.h"
  69. #include "MagickCore/pixel-accessor.h"
  70. #include "MagickCore/quantize.h"
  71. #include "MagickCore/quantum.h"
  72. #include "MagickCore/quantum-private.h"
  73. #include "MagickCore/resource_.h"
  74. #include "MagickCore/resize.h"
  75. #include "MagickCore/statistic.h"
  76. #include "MagickCore/string_.h"
  77. #include "MagickCore/string-private.h"
  78. #include "MagickCore/transform.h"
  79. #include "MagickCore/transform-private.h"
  80. #include "MagickCore/token.h"
  81. #include "MagickCore/utility.h"
  82. #include "MagickCore/utility-private.h"
  83. #include "MagickCore/widget.h"
  84. #include "MagickCore/widget-private.h"
  85. #include "MagickCore/xwindow.h"
  86. #include "MagickCore/xwindow-private.h"
  87. #include "MagickCore/version.h"
  88. #if defined(__BEOS__)
  89. #include <OS.h>
  90. #endif
  91. #if defined(MAGICKCORE_X11_DELEGATE)
  92. #include <X11/Xproto.h>
  93. #include <X11/Xlocale.h>
  94. #if defined(MAGICK_HAVE_POLL)
  95. # include <sys/poll.h>
  96. #endif
  97. #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
  98. #if defined(MAGICKCORE_HAVE_MACHINE_PARAM_H)
  99. # include <machine/param.h>
  100. #endif
  101. #include <sys/ipc.h>
  102. #include <sys/shm.h>
  103. #include <X11/extensions/XShm.h>
  104. #endif
  105. #if defined(MAGICKCORE_HAVE_SHAPE)
  106. #include <X11/extensions/shape.h>
  107. #endif
  108. /*
  109. X defines.
  110. */
  111. #define XBlueGamma(color) ClampToQuantum(blue_gamma == 1.0 ? (double) \
  112. (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) blue_gamma)* \
  113. QuantumRange)))
  114. #define XGammaPacket(map,color) (size_t) (map->base_pixel+ \
  115. ((ScaleQuantumToShort(XRedGamma((color)->red))*map->red_max/65535L)* \
  116. map->red_mult)+ \
  117. ((ScaleQuantumToShort(XGreenGamma((color)->green))*map->green_max/65535L)* \
  118. map->green_mult)+ \
  119. ((ScaleQuantumToShort(XBlueGamma((color)->blue))*map->blue_max/65535L)* \
  120. map->blue_mult))
  121. #define XGammaPixel(image,map,color) (size_t) (map->base_pixel+ \
  122. ((ScaleQuantumToShort(XRedGamma(GetPixelRed(image,color)))*map->red_max/65535L)* \
  123. map->red_mult)+ \
  124. ((ScaleQuantumToShort(XGreenGamma(GetPixelGreen(image,color)))*map->green_max/65535L)* \
  125. map->green_mult)+ \
  126. ((ScaleQuantumToShort(XBlueGamma(GetPixelBlue(image,color)))*map->blue_max/65535L)* \
  127. map->blue_mult))
  128. #define XGreenGamma(color) ClampToQuantum(green_gamma == 1.0 ? (double) \
  129. (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) green_gamma)* \
  130. QuantumRange)))
  131. #define XRedGamma(color) ClampToQuantum(red_gamma == 1.0 ? (double) \
  132. (color) : ((pow(((double) QuantumScale*(color)),1.0/(double) red_gamma)* \
  133. QuantumRange)))
  134. #define XStandardPixel(map,color) (size_t) (map->base_pixel+ \
  135. (((color)->red*map->red_max/65535L)*map->red_mult)+ \
  136. (((color)->green*map->green_max/65535L)*map->green_mult)+ \
  137. (((color)->blue*map->blue_max/65535L)*map->blue_mult))
  138. #define AccentuateModulate ScaleCharToQuantum(80)
  139. #define HighlightModulate ScaleCharToQuantum(125)
  140. #define ShadowModulate ScaleCharToQuantum(135)
  141. #define DepthModulate ScaleCharToQuantum(185)
  142. #define TroughModulate ScaleCharToQuantum(110)
  143. #define XLIB_ILLEGAL_ACCESS 1
  144. #undef ForgetGravity
  145. #undef NorthWestGravity
  146. #undef NorthGravity
  147. #undef NorthEastGravity
  148. #undef WestGravity
  149. #undef CenterGravity
  150. #undef EastGravity
  151. #undef SouthWestGravity
  152. #undef SouthGravity
  153. #undef SouthEastGravity
  154. #undef StaticGravity
  155. #undef index
  156. #if defined(hpux9)
  157. #define XFD_SET int
  158. #else
  159. #define XFD_SET fd_set
  160. #endif
  161. /*
  162. Enumeration declarations.
  163. */
  164. typedef enum
  165. {
  166. #undef DoRed
  167. DoRed = 0x0001,
  168. #undef DoGreen
  169. DoGreen = 0x0002,
  170. #undef DoBlue
  171. DoBlue = 0x0004,
  172. DoMatte = 0x0008
  173. } XColorFlags;
  174. /*
  175. Typedef declarations.
  176. */
  177. typedef struct _DiversityPacket
  178. {
  179. Quantum
  180. red,
  181. green,
  182. blue;
  183. unsigned short
  184. index;
  185. size_t
  186. count;
  187. } DiversityPacket;
  188. /*
  189. Constant declaractions.
  190. */
  191. static MagickBooleanType
  192. xerror_alert = MagickFalse;
  193. /*
  194. Method prototypes.
  195. */
  196. static const char
  197. *XVisualClassName(const int);
  198. static double
  199. blue_gamma = 1.0,
  200. green_gamma = 1.0,
  201. red_gamma = 1.0;
  202. static MagickBooleanType
  203. XMakePixmap(Display *,const XResourceInfo *,XWindowInfo *);
  204. static void
  205. XMakeImageLSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
  206. XImage *,XImage *,ExceptionInfo *),
  207. XMakeImageMSBFirst(const XResourceInfo *,const XWindowInfo *,Image *,
  208. XImage *,XImage *,ExceptionInfo *);
  209. static Window
  210. XSelectWindow(Display *,RectangleInfo *);
  211. /*
  212. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  213. % %
  214. % %
  215. % %
  216. % D e s t r o y X R e s o u r c e s %
  217. % %
  218. % %
  219. % %
  220. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  221. %
  222. % DestroyXResources() destroys any X resources.
  223. %
  224. % The format of the DestroyXResources method is:
  225. %
  226. % void DestroyXResources()
  227. %
  228. % A description of each parameter follows:
  229. %
  230. */
  231. MagickExport void DestroyXResources(void)
  232. {
  233. register int
  234. i;
  235. unsigned int
  236. number_windows;
  237. XWindowInfo
  238. *magick_windows[MaxXWindows];
  239. XWindows
  240. *windows;
  241. DestroyXWidget();
  242. windows=XSetWindows((XWindows *) ~0);
  243. if ((windows == (XWindows *) NULL) || (windows->display == (Display *) NULL))
  244. return;
  245. number_windows=0;
  246. magick_windows[number_windows++]=(&windows->context);
  247. magick_windows[number_windows++]=(&windows->group_leader);
  248. magick_windows[number_windows++]=(&windows->backdrop);
  249. magick_windows[number_windows++]=(&windows->icon);
  250. magick_windows[number_windows++]=(&windows->image);
  251. magick_windows[number_windows++]=(&windows->info);
  252. magick_windows[number_windows++]=(&windows->magnify);
  253. magick_windows[number_windows++]=(&windows->pan);
  254. magick_windows[number_windows++]=(&windows->command);
  255. magick_windows[number_windows++]=(&windows->widget);
  256. magick_windows[number_windows++]=(&windows->popup);
  257. for (i=0; i < (int) number_windows; i++)
  258. {
  259. if (magick_windows[i]->mapped != MagickFalse)
  260. {
  261. (void) XWithdrawWindow(windows->display,magick_windows[i]->id,
  262. magick_windows[i]->screen);
  263. magick_windows[i]->mapped=MagickFalse;
  264. }
  265. if (magick_windows[i]->name != (char *) NULL)
  266. magick_windows[i]->name=(char *)
  267. RelinquishMagickMemory(magick_windows[i]->name);
  268. if (magick_windows[i]->icon_name != (char *) NULL)
  269. magick_windows[i]->icon_name=(char *)
  270. RelinquishMagickMemory(magick_windows[i]->icon_name);
  271. if (magick_windows[i]->cursor != (Cursor) NULL)
  272. {
  273. (void) XFreeCursor(windows->display,magick_windows[i]->cursor);
  274. magick_windows[i]->cursor=(Cursor) NULL;
  275. }
  276. if (magick_windows[i]->busy_cursor != (Cursor) NULL)
  277. {
  278. (void) XFreeCursor(windows->display,magick_windows[i]->busy_cursor);
  279. magick_windows[i]->busy_cursor=(Cursor) NULL;
  280. }
  281. if (magick_windows[i]->highlight_stipple != (Pixmap) NULL)
  282. {
  283. (void) XFreePixmap(windows->display,
  284. magick_windows[i]->highlight_stipple);
  285. magick_windows[i]->highlight_stipple=(Pixmap) NULL;
  286. }
  287. if (magick_windows[i]->shadow_stipple != (Pixmap) NULL)
  288. {
  289. (void) XFreePixmap(windows->display,magick_windows[i]->shadow_stipple);
  290. magick_windows[i]->shadow_stipple=(Pixmap) NULL;
  291. }
  292. if (magick_windows[i]->matte_image != (XImage *) NULL)
  293. {
  294. XDestroyImage(magick_windows[i]->matte_image);
  295. magick_windows[i]->matte_image=(XImage *) NULL;
  296. }
  297. if (magick_windows[i]->ximage != (XImage *) NULL)
  298. {
  299. XDestroyImage(magick_windows[i]->ximage);
  300. magick_windows[i]->ximage=(XImage *) NULL;
  301. }
  302. if (magick_windows[i]->pixmap != (Pixmap) NULL)
  303. {
  304. (void) XFreePixmap(windows->display,magick_windows[i]->pixmap);
  305. magick_windows[i]->pixmap=(Pixmap) NULL;
  306. }
  307. if (magick_windows[i]->id != (Window) NULL)
  308. {
  309. (void) XDestroyWindow(windows->display,magick_windows[i]->id);
  310. magick_windows[i]->id=(Window) NULL;
  311. }
  312. if (magick_windows[i]->destroy != MagickFalse)
  313. {
  314. if (magick_windows[i]->image != (Image *) NULL)
  315. {
  316. magick_windows[i]->image=DestroyImage(magick_windows[i]->image);
  317. magick_windows[i]->image=NewImageList();
  318. }
  319. if (magick_windows[i]->matte_pixmap != (Pixmap) NULL)
  320. {
  321. (void) XFreePixmap(windows->display,
  322. magick_windows[i]->matte_pixmap);
  323. magick_windows[i]->matte_pixmap=(Pixmap) NULL;
  324. }
  325. }
  326. if (magick_windows[i]->segment_info != (void *) NULL)
  327. {
  328. #if defined(MAGICKCORE_HAVE_SHARED_MEMORY)
  329. XShmSegmentInfo
  330. *segment_info;
  331. segment_info=(XShmSegmentInfo *) magick_windows[i]->segment_info;
  332. if (segment_info != (XShmSegmentInfo *) NULL)
  333. if (segment_info[0].shmid >= 0)
  334. {
  335. if (segment_info[0].shmaddr != NULL)
  336. (void) shmdt(segment_info[0].shmaddr);
  337. (void) shmctl(segment_info[0].shmid,IPC_RMID,0);
  338. segment_info[0].shmaddr=NULL;
  339. segment_info[0].shmid=(-1);
  340. }
  341. #endif
  342. magick_windows[i]->segment_info=(void *)
  343. RelinquishMagickMemory(magick_windows[i]->segment_info);
  344. }
  345. }
  346. windows->icon_resources=(XResourceInfo *)
  347. RelinquishMagickMemory(windows->icon_resources);
  348. if (windows->icon_pixel != (XPixelInfo *) NULL)
  349. {
  350. if (windows->icon_pixel->pixels != (unsigned long *) NULL)
  351. windows->icon_pixel->pixels=(unsigned long *)
  352. RelinquishMagickMemory(windows->icon_pixel->pixels);
  353. if (windows->icon_pixel->annotate_context != (GC) NULL)
  354. XFreeGC(windows->display,windows->icon_pixel->annotate_context);
  355. windows->icon_pixel=(XPixelInfo *)
  356. RelinquishMagickMemory(windows->icon_pixel);
  357. }
  358. if (windows->pixel_info != (XPixelInfo *) NULL)
  359. {
  360. if (windows->pixel_info->pixels != (unsigned long *) NULL)
  361. windows->pixel_info->pixels=(unsigned long *)
  362. RelinquishMagickMemory(windows->pixel_info->pixels);
  363. if (windows->pixel_info->annotate_context != (GC) NULL)
  364. XFreeGC(windows->display,windows->pixel_info->annotate_context);
  365. if (windows->pixel_info->widget_context != (GC) NULL)
  366. XFreeGC(windows->display,windows->pixel_info->widget_context);
  367. if (windows->pixel_info->highlight_context != (GC) NULL)
  368. XFreeGC(windows->display,windows->pixel_info->highlight_context);
  369. windows->pixel_info=(XPixelInfo *)
  370. RelinquishMagickMemory(windows->pixel_info);
  371. }
  372. if (windows->font_info != (XFontStruct *) NULL)
  373. {
  374. XFreeFont(windows->display,windows->font_info);
  375. windows->font_info=(XFontStruct *) NULL;
  376. }
  377. if (windows->class_hints != (XClassHint *) NULL)
  378. {
  379. if (windows->class_hints->res_name != (char *) NULL)
  380. windows->class_hints->res_name=DestroyString(
  381. windows->class_hints->res_name);
  382. if (windows->class_hints->res_class != (char *) NULL)
  383. windows->class_hints->res_class=DestroyString(
  384. windows->class_hints->res_class);
  385. XFree(windows->class_hints);
  386. windows->class_hints=(XClassHint *) NULL;
  387. }
  388. if (windows->manager_hints != (XWMHints *) NULL)
  389. {
  390. XFree(windows->manager_hints);
  391. windows->manager_hints=(XWMHints *) NULL;
  392. }
  393. if (windows->map_info != (XStandardColormap *) NULL)
  394. {
  395. XFree(windows->map_info);
  396. windows->map_info=(XStandardColormap *) NULL;
  397. }
  398. if (windows->icon_map != (XStandardColormap *) NULL)
  399. {
  400. XFree(windows->icon_map);
  401. windows->icon_map=(XStandardColormap *) NULL;
  402. }
  403. if (windows->visual_info != (XVisualInfo *) NULL)
  404. {
  405. XFree(windows->visual_info);
  406. windows->visual_info=(XVisualInfo *) NULL;
  407. }
  408. if (windows->icon_visual != (XVisualInfo *) NULL)
  409. {
  410. XFree(windows->icon_visual);
  411. windows->icon_visual=(XVisualInfo *) NULL;
  412. }
  413. (void) XSetWindows((XWindows *) NULL);
  414. }
  415. /*
  416. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  417. % %
  418. % %
  419. % %
  420. % X A n n o t a t e I m a g e %
  421. % %
  422. % %
  423. % %
  424. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  425. %
  426. % XAnnotateImage() annotates the image with text.
  427. %
  428. % The format of the XAnnotateImage method is:
  429. %
  430. % MagickBooleanType XAnnotateImage(Display *display,
  431. % const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image,
  432. % ExceptionInfo *exception)
  433. %
  434. % A description of each parameter follows:
  435. %
  436. % o display: Specifies a connection to an X server; returned from
  437. % XOpenDisplay.
  438. %
  439. % o pixel: Specifies a pointer to a XPixelInfo structure.
  440. %
  441. % o annotate_info: Specifies a pointer to a XAnnotateInfo structure.
  442. %
  443. % o image: the image.
  444. %
  445. % o exception: return any errors or warnings in this structure.
  446. %
  447. */
  448. MagickPrivate MagickBooleanType XAnnotateImage(Display *display,
  449. const XPixelInfo *pixel,XAnnotateInfo *annotate_info,Image *image,
  450. ExceptionInfo *exception)
  451. {
  452. CacheView
  453. *annotate_view;
  454. GC
  455. annotate_context;
  456. Image
  457. *annotate_image;
  458. int
  459. x,
  460. y;
  461. PixelTrait
  462. alpha_trait;
  463. Pixmap
  464. annotate_pixmap;
  465. unsigned int
  466. depth,
  467. height,
  468. width;
  469. Window
  470. root_window;
  471. XGCValues
  472. context_values;
  473. XImage
  474. *annotate_ximage;
  475. /*
  476. Initialize annotated image.
  477. */
  478. (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
  479. assert(display != (Display *) NULL);
  480. assert(pixel != (XPixelInfo *) NULL);
  481. assert(annotate_info != (XAnnotateInfo *) NULL);
  482. assert(image != (Image *) NULL);
  483. /*
  484. Initialize annotated pixmap.
  485. */
  486. root_window=XRootWindow(display,XDefaultScreen(display));
  487. depth=(unsigned int) XDefaultDepth(display,XDefaultScreen(display));
  488. annotate_pixmap=XCreatePixmap(display,root_window,annotate_info->width,
  489. annotate_info->height,depth);
  490. if (annotate_pixmap == (Pixmap) NULL)
  491. return(MagickFalse);
  492. /*
  493. Initialize graphics info.
  494. */
  495. context_values.background=0;
  496. context_values.foreground=(size_t) (~0);
  497. context_values.font=annotate_info->font_info->fid;
  498. annotate_context=XCreateGC(display,root_window,(unsigned long)
  499. (GCBackground | GCFont | GCForeground),&context_values);
  500. if (annotate_context == (GC) NULL)
  501. return(MagickFalse);
  502. /*
  503. Draw text to pixmap.
  504. */
  505. (void) XDrawImageString(display,annotate_pixmap,annotate_context,0,
  506. (int) annotate_info->font_info->ascent,annotate_info->text,
  507. (int) strlen(annotate_info->text));
  508. (void) XFreeGC(display,annotate_context);
  509. /*
  510. Initialize annotated X image.
  511. */
  512. annotate_ximage=XGetImage(display,annotate_pixmap,0,0,annotate_info->width,
  513. annotate_info->height,AllPlanes,ZPixmap);
  514. if (annotate_ximage == (XImage *) NULL)
  515. return(MagickFalse);
  516. (void) XFreePixmap(display,annotate_pixmap);
  517. /*
  518. Initialize annotated image.
  519. */
  520. annotate_image=AcquireImage((ImageInfo *) NULL,exception);
  521. if (annotate_image == (Image *) NULL)
  522. return(MagickFalse);
  523. annotate_image->columns=annotate_info->width;
  524. annotate_image->rows=annotate_info->height;
  525. /*
  526. Transfer annotated X image to image.
  527. */
  528. width=(unsigned int) image->columns;
  529. height=(unsigned int) image->rows;
  530. x=0;
  531. y=0;
  532. (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
  533. (void) GetOneVirtualPixelInfo(image,UndefinedVirtualPixelMethod,(ssize_t) x,
  534. (ssize_t) y,&annotate_image->background_color,exception);
  535. if (annotate_info->stencil == ForegroundStencil)
  536. annotate_image->alpha_trait=BlendPixelTrait;
  537. annotate_view=AcquireAuthenticCacheView(annotate_image,exception);
  538. for (y=0; y < (int) annotate_image->rows; y++)
  539. {
  540. register int
  541. x;
  542. register Quantum
  543. *magick_restrict q;
  544. q=GetCacheViewAuthenticPixels(annotate_view,0,(ssize_t) y,
  545. annotate_image->columns,1,exception);
  546. if (q == (Quantum *) NULL)
  547. break;
  548. for (x=0; x < (int) annotate_image->columns; x++)
  549. {
  550. SetPixelAlpha(annotate_image,OpaqueAlpha,q);
  551. if (XGetPixel(annotate_ximage,x,y) == 0)
  552. {
  553. /*
  554. Set this pixel to the background color.
  555. */
  556. SetPixelRed(annotate_image,ScaleShortToQuantum(
  557. pixel->box_color.red),q);
  558. SetPixelGreen(annotate_image,ScaleShortToQuantum(
  559. pixel->box_color.green),q);
  560. SetPixelBlue(annotate_image,ScaleShortToQuantum(
  561. pixel->box_color.blue),q);
  562. if ((annotate_info->stencil == ForegroundStencil) ||
  563. (annotate_info->stencil == OpaqueStencil))
  564. SetPixelAlpha(annotate_image,TransparentAlpha,q);
  565. }
  566. else
  567. {
  568. /*
  569. Set this pixel to the pen color.
  570. */
  571. SetPixelRed(annotate_image,ScaleShortToQuantum(
  572. pixel->pen_color.red),q);
  573. SetPixelGreen(annotate_image,ScaleShortToQuantum(
  574. pixel->pen_color.green),q);
  575. SetPixelBlue(annotate_image,ScaleShortToQuantum(
  576. pixel->pen_color.blue),q);
  577. if (annotate_info->stencil == BackgroundStencil)
  578. SetPixelAlpha(annotate_image,TransparentAlpha,q);
  579. }
  580. q+=GetPixelChannels(annotate_image);
  581. }
  582. if (SyncCacheViewAuthenticPixels(annotate_view,exception) == MagickFalse)
  583. break;
  584. }
  585. annotate_view=DestroyCacheView(annotate_view);
  586. XDestroyImage(annotate_ximage);
  587. /*
  588. Determine annotate geometry.
  589. */
  590. (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
  591. if ((width != (unsigned int) annotate_image->columns) ||
  592. (height != (unsigned int) annotate_image->rows))
  593. {
  594. char
  595. image_geometry[MagickPathExtent];
  596. /*
  597. Scale image.
  598. */
  599. (void) FormatLocaleString(image_geometry,MagickPathExtent,"%ux%u",
  600. width,height);
  601. (void) TransformImage(&annotate_image,(char *) NULL,image_geometry,
  602. exception);
  603. }
  604. if (annotate_info->degrees != 0.0)
  605. {
  606. Image
  607. *rotate_image;
  608. int
  609. rotations;
  610. double
  611. normalized_degrees;
  612. /*
  613. Rotate image.
  614. */
  615. rotate_image=RotateImage(annotate_image,annotate_info->degrees,exception);
  616. if (rotate_image == (Image *) NULL)
  617. return(MagickFalse);
  618. annotate_image=DestroyImage(annotate_image);
  619. annotate_image=rotate_image;
  620. /*
  621. Annotation is relative to the degree of rotation.
  622. */
  623. normalized_degrees=annotate_info->degrees;
  624. while (normalized_degrees < -45.0)
  625. normalized_degrees+=360.0;
  626. for (rotations=0; normalized_degrees > 45.0; rotations++)
  627. normalized_degrees-=90.0;
  628. switch (rotations % 4)
  629. {
  630. default:
  631. case 0:
  632. break;
  633. case 1:
  634. {
  635. /*
  636. Rotate 90 degrees.
  637. */
  638. x-=(int) annotate_image->columns/2;
  639. y+=(int) annotate_image->columns/2;
  640. break;
  641. }
  642. case 2:
  643. {
  644. /*
  645. Rotate 180 degrees.
  646. */
  647. x=x-(int) annotate_image->columns;
  648. break;
  649. }
  650. case 3:
  651. {
  652. /*
  653. Rotate 270 degrees.
  654. */
  655. x=x-(int) annotate_image->columns/2;
  656. y=y-(int) (annotate_image->rows-(annotate_image->columns/2));
  657. break;
  658. }
  659. }
  660. }
  661. /*
  662. Composite text onto the image.
  663. */
  664. (void) XParseGeometry(annotate_info->geometry,&x,&y,&width,&height);
  665. alpha_trait=image->alpha_trait;
  666. (void) CompositeImage(image,annotate_image,
  667. annotate_image->alpha_trait != UndefinedPixelTrait ? OverCompositeOp :
  668. CopyCompositeOp,MagickTrue,(ssize_t) x,(ssize_t) y,exception);
  669. image->alpha_trait=alpha_trait;
  670. annotate_image=DestroyImage(annotate_image);
  671. return(MagickTrue);
  672. }
  673. /*
  674. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  675. % %
  676. % %
  677. % %
  678. % X B e s t F o n t %
  679. % %
  680. % %
  681. % %
  682. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  683. %
  684. % XBestFont() returns the "best" font. "Best" is defined as a font specified
  685. % in the X resource database or a font such that the text width displayed
  686. % with the font does not exceed the specified maximum width.
  687. %
  688. % The format of the XBestFont method is:
  689. %
  690. % XFontStruct *XBestFont(Display *display,
  691. % const XResourceInfo *resource_info,const MagickBooleanType text_font)
  692. %
  693. % A description of each parameter follows:
  694. %
  695. % o font: XBestFont returns a pointer to a XFontStruct structure.
  696. %
  697. % o display: Specifies a connection to an X server; returned from
  698. % XOpenDisplay.
  699. %
  700. % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  701. %
  702. % o text_font: True is font should be mono-spaced (typewriter style).
  703. %
  704. */
  705. static char **FontToList(char *font)
  706. {
  707. char
  708. **fontlist;
  709. register char
  710. *p,
  711. *q;
  712. register int
  713. i;
  714. unsigned int
  715. fonts;
  716. if (font == (char *) NULL)
  717. return((char **) NULL);
  718. /*
  719. Convert string to an ASCII list.
  720. */
  721. fonts=1U;
  722. for (p=font; *p != '\0'; p++)
  723. if ((*p == ':') || (*p == ';') || (*p == ','))
  724. fonts++;
  725. fontlist=(char **) AcquireQuantumMemory((size_t) fonts+1UL,sizeof(*fontlist));
  726. if (fontlist == (char **) NULL)
  727. {
  728. ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",font);
  729. return((char **) NULL);
  730. }
  731. p=font;
  732. for (i=0; i < (int) fonts; i++)
  733. {
  734. for (q=p; *q != '\0'; q++)
  735. if ((*q == ':') || (*q == ';') || (*q == ','))
  736. break;
  737. fontlist[i]=(char *) AcquireQuantumMemory((size_t) (q-p)+1UL,
  738. sizeof(*fontlist[i]));
  739. if (fontlist[i] == (char *) NULL)
  740. {
  741. ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",font);
  742. return((char **) NULL);
  743. }
  744. (void) CopyMagickString(fontlist[i],p,(size_t) (q-p+1));
  745. p=q+1;
  746. }
  747. fontlist[i]=(char *) NULL;
  748. return(fontlist);
  749. }
  750. MagickPrivate XFontStruct *XBestFont(Display *display,
  751. const XResourceInfo *resource_info,const MagickBooleanType text_font)
  752. {
  753. static const char
  754. *Fonts[]=
  755. {
  756. "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-1",
  757. "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-1",
  758. "-*-helvetica-medium-r-normal--12-*-*-*-*-*-iso8859-15",
  759. "-*-arial-medium-r-normal--12-*-*-*-*-*-iso8859-15",
  760. "-*-helvetica-medium-r-normal--12-*-*-*-*-*-*-*",
  761. "-*-arial-medium-r-normal--12-*-*-*-*-*-*-*",
  762. "variable",
  763. "fixed",
  764. (char *) NULL
  765. },
  766. *TextFonts[]=
  767. {
  768. "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-1",
  769. "-*-courier-medium-r-normal-*-12-*-*-*-*-*-iso8859-15",
  770. "-*-fixed-medium-r-normal-*-12-*-*-*-*-*-*-*",
  771. "fixed",
  772. (char *) NULL
  773. };
  774. char
  775. *font_name;
  776. register const char
  777. **p;
  778. XFontStruct
  779. *font_info;
  780. font_info=(XFontStruct *) NULL;
  781. font_name=resource_info->font;
  782. if (text_font != MagickFalse)
  783. font_name=resource_info->text_font;
  784. if ((font_name != (char *) NULL) && (*font_name != '\0'))
  785. {
  786. char
  787. **fontlist;
  788. register int
  789. i;
  790. /*
  791. Load preferred font specified in the X resource database.
  792. */
  793. fontlist=FontToList(font_name);
  794. if (fontlist != (char **) NULL)
  795. {
  796. for (i=0; fontlist[i] != (char *) NULL; i++)
  797. {
  798. if (font_info == (XFontStruct *) NULL)
  799. font_info=XLoadQueryFont(display,fontlist[i]);
  800. fontlist[i]=DestroyString(fontlist[i]);
  801. }
  802. fontlist=(char **) RelinquishMagickMemory(fontlist);
  803. }
  804. if (font_info == (XFontStruct *) NULL)
  805. ThrowXWindowException(XServerError,"UnableToLoadFont",font_name);
  806. }
  807. /*
  808. Load fonts from list of fonts until one is found.
  809. */
  810. p=Fonts;
  811. if (text_font != MagickFalse)
  812. p=TextFonts;
  813. if (XDisplayHeight(display,XDefaultScreen(display)) >= 748)
  814. p++;
  815. while (*p != (char *) NULL)
  816. {
  817. if (font_info != (XFontStruct *) NULL)
  818. break;
  819. font_info=XLoadQueryFont(display,(char *) *p);
  820. p++;
  821. }
  822. return(font_info);
  823. }
  824. /*
  825. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  826. % %
  827. % %
  828. % %
  829. % X B e s t I c o n S i z e %
  830. % %
  831. % %
  832. % %
  833. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  834. %
  835. % XBestIconSize() returns the "best" icon size. "Best" is defined as an icon
  836. % size that maintains the aspect ratio of the image. If the window manager
  837. % has preferred icon sizes, one of the preferred sizes is used.
  838. %
  839. % The format of the XBestIconSize method is:
  840. %
  841. % void XBestIconSize(Display *display,XWindowInfo *window,Image *image)
  842. %
  843. % A description of each parameter follows:
  844. %
  845. % o display: Specifies a connection to an X server; returned from
  846. % XOpenDisplay.
  847. %
  848. % o image: the image.
  849. %
  850. */
  851. MagickPrivate void XBestIconSize(Display *display,XWindowInfo *window,
  852. Image *image)
  853. {
  854. int
  855. i,
  856. number_sizes;
  857. double
  858. scale_factor;
  859. unsigned int
  860. height,
  861. icon_height,
  862. icon_width,
  863. width;
  864. Window
  865. root_window;
  866. XIconSize
  867. *icon_size,
  868. *size_list;
  869. /*
  870. Determine if the window manager has specified preferred icon sizes.
  871. */
  872. (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
  873. assert(display != (Display *) NULL);
  874. assert(window != (XWindowInfo *) NULL);
  875. assert(image != (Image *) NULL);
  876. window->width=MaxIconSize;
  877. window->height=MaxIconSize;
  878. icon_size=(XIconSize *) NULL;
  879. number_sizes=0;
  880. root_window=XRootWindow(display,window->screen);
  881. if (XGetIconSizes(display,root_window,&size_list,&number_sizes) != 0)
  882. if ((number_sizes > 0) && (size_list != (XIconSize *) NULL))
  883. icon_size=size_list;
  884. if (icon_size == (XIconSize *) NULL)
  885. {
  886. /*
  887. Window manager does not restrict icon size.
  888. */
  889. icon_size=XAllocIconSize();
  890. if (icon_size == (XIconSize *) NULL)
  891. {
  892. ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
  893. image->filename);
  894. return;
  895. }
  896. icon_size->min_width=1;
  897. icon_size->max_width=MaxIconSize;
  898. icon_size->min_height=1;
  899. icon_size->max_height=MaxIconSize;
  900. icon_size->width_inc=1;
  901. icon_size->height_inc=1;
  902. }
  903. /*
  904. Determine aspect ratio of image.
  905. */
  906. width=(unsigned int) image->columns;
  907. height=(unsigned int) image->rows;
  908. i=0;
  909. if (window->crop_geometry)
  910. (void) XParseGeometry(window->crop_geometry,&i,&i,&width,&height);
  911. /*
  912. Look for an icon size that maintains the aspect ratio of image.
  913. */
  914. scale_factor=(double) icon_size->max_width/width;
  915. if (scale_factor > ((double) icon_size->max_height/height))
  916. scale_factor=(double) icon_size->max_height/height;
  917. icon_width=(unsigned int) icon_size->min_width;
  918. while ((int) icon_width < icon_size->max_width)
  919. {
  920. if (icon_width >= (unsigned int) (scale_factor*width+0.5))
  921. break;
  922. icon_width+=icon_size->width_inc;
  923. }
  924. icon_height=(unsigned int) icon_size->min_height;
  925. while ((int) icon_height < icon_size->max_height)
  926. {
  927. if (icon_height >= (unsigned int) (scale_factor*height+0.5))
  928. break;
  929. icon_height+=icon_size->height_inc;
  930. }
  931. (void) XFree((void *) icon_size);
  932. window->width=icon_width;
  933. window->height=icon_height;
  934. }
  935. /*
  936. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  937. % %
  938. % %
  939. % %
  940. % X B e s t P i x e l %
  941. % %
  942. % %
  943. % %
  944. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  945. %
  946. % XBestPixel() returns a pixel from an array of pixels that is closest to the
  947. % requested color. If the color array is NULL, the colors are obtained from
  948. % the X server.
  949. %
  950. % The format of the XBestPixel method is:
  951. %
  952. % void XBestPixel(Display *display,const Colormap colormap,XColor *colors,
  953. % unsigned int number_colors,XColor *color)
  954. %
  955. % A description of each parameter follows:
  956. %
  957. % o pixel: XBestPixel returns the pixel value closest to the requested
  958. % color.
  959. %
  960. % o display: Specifies a connection to an X server; returned from
  961. % XOpenDisplay.
  962. %
  963. % o colormap: Specifies the ID of the X server colormap.
  964. %
  965. % o colors: Specifies an array of XColor structures.
  966. %
  967. % o number_colors: Specifies the number of XColor structures in the
  968. % color definition array.
  969. %
  970. % o color: Specifies the desired RGB value to find in the colors array.
  971. %
  972. */
  973. MagickPrivate void XBestPixel(Display *display,const Colormap colormap,
  974. XColor *colors,unsigned int number_colors,XColor *color)
  975. {
  976. MagickBooleanType
  977. query_server;
  978. PixelInfo
  979. pixel;
  980. double
  981. min_distance;
  982. register double
  983. distance;
  984. register int
  985. i,
  986. j;
  987. Status
  988. status;
  989. /*
  990. Find closest representation for the requested RGB color.
  991. */
  992. (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
  993. assert(display != (Display *) NULL);
  994. assert(color != (XColor *) NULL);
  995. status=XAllocColor(display,colormap,color);
  996. if (status != False)
  997. return;
  998. query_server=colors == (XColor *) NULL ? MagickTrue : MagickFalse;
  999. if (query_server != MagickFalse)
  1000. {
  1001. /*
  1002. Read X server colormap.
  1003. */
  1004. colors=(XColor *) AcquireQuantumMemory(number_colors,sizeof(*colors));
  1005. if (colors == (XColor *) NULL)
  1006. {
  1007. ThrowXWindowException(ResourceLimitError,"MemoryAllocationFailed",
  1008. "...");
  1009. return;
  1010. }
  1011. for (i=0; i < (int) number_colors; i++)
  1012. colors[i].pixel=(size_t) i;
  1013. if (number_colors > 256)
  1014. number_colors=256;
  1015. (void) XQueryColors(display,colormap,colors,(int) number_colors);
  1016. }
  1017. min_distance=3.0*((double) QuantumRange+1.0)*((double)
  1018. QuantumRange+1.0);
  1019. j=0;
  1020. for (i=0; i < (int) number_colors; i++)
  1021. {
  1022. pixel.red=colors[i].red-(double) color->red;
  1023. distance=pixel.red*pixel.red;
  1024. if (distance > min_distance)
  1025. continue;
  1026. pixel.green=colors[i].green-(double) color->green;
  1027. distance+=pixel.green*pixel.green;
  1028. if (distance > min_distance)
  1029. continue;
  1030. pixel.blue=colors[i].blue-(double) color->blue;
  1031. distance+=pixel.blue*pixel.blue;
  1032. if (distance > min_distance)
  1033. continue;
  1034. min_distance=distance;
  1035. color->pixel=colors[i].pixel;
  1036. j=i;
  1037. }
  1038. (void) XAllocColor(display,colormap,&colors[j]);
  1039. if (query_server != MagickFalse)
  1040. colors=(XColor *) RelinquishMagickMemory(colors);
  1041. }
  1042. /*
  1043. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1044. % %
  1045. % %
  1046. % %
  1047. % X B e s t V i s u a l I n f o %
  1048. % %
  1049. % %
  1050. % %
  1051. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1052. %
  1053. % XBestVisualInfo() returns visual information for a visual that is the "best"
  1054. % the server supports. "Best" is defined as:
  1055. %
  1056. % 1. Restrict the visual list to those supported by the default screen.
  1057. %
  1058. % 2. If a visual type is specified, restrict the visual list to those of
  1059. % that type.
  1060. %
  1061. % 3. If a map type is specified, choose the visual that matches the id
  1062. % specified by the Standard Colormap.
  1063. %
  1064. % 4 From the list of visuals, choose one that can display the most
  1065. % simultaneous colors. If more than one visual can display the same
  1066. % number of simultaneous colors, one is chosen based on a rank.
  1067. %
  1068. % The format of the XBestVisualInfo method is:
  1069. %
  1070. % XVisualInfo *XBestVisualInfo(Display *display,
  1071. % XStandardColormap *map_info,XResourceInfo *resource_info)
  1072. %
  1073. % A description of each parameter follows:
  1074. %
  1075. % o visual_info: XBestVisualInfo returns a pointer to a X11 XVisualInfo
  1076. % structure.
  1077. %
  1078. % o display: Specifies a connection to an X server; returned from
  1079. % XOpenDisplay.
  1080. %
  1081. % o map_info: If map_type is specified, this structure is initialized
  1082. % with info from the Standard Colormap.
  1083. %
  1084. % o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
  1085. %
  1086. */
  1087. MagickPrivate XVisualInfo *XBestVisualInfo(Display *display,
  1088. XStandardColormap *map_info,XResourceInfo *resource_info)
  1089. {
  1090. #define MaxStandardColormaps 7
  1091. #define XVisualColormapSize(visual_info) MagickMin((unsigned int) (\
  1092. (visual_info->klass == TrueColor) || (visual_info->klass == DirectColor) ? \
  1093. visual_info->red_mask | visual_info->green_mask | visual_info->blue_mask : \
  1094. (unsigned long) visual_info->colormap_size),1UL << visual_info->depth)
  1095. char
  1096. *map_type,
  1097. *visual_type;
  1098. int
  1099. visual_mask;
  1100. register int
  1101. i;
  1102. size_t
  1103. one;
  1104. static int
  1105. number_visuals;
  1106. static XVisualInfo
  1107. visual_template;
  1108. XVisualInfo
  1109. *visual_info,
  1110. *visual_list;
  1111. /*
  1112. Restrict visual search by screen number.
  1113. */
  1114. (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
  1115. assert(display != (Display *) NULL);
  1116. assert(map_info != (XStandardColormap *) NULL);
  1117. assert(resource_info != (XResourceInfo *) NULL);
  1118. map_type=resource_info->map_type;
  1119. visual_type=resource_info->visual_type;
  1120. visual_mask=VisualScreenMask;
  1121. visual_template.screen=XDefaultScreen(display);
  1122. visual_template.depth=XDefaultDepth(display,XDefaultScreen(display));
  1123. one=1;
  1124. if ((resource_info->immutable != MagickFalse) && (resource_info->colors != 0))
  1125. if (resource_info->colors <= (one << (size_t) visual_template.depth))
  1126. visual_mask|=VisualDepthMask;
  1127. if (visual_type != (char *) NULL)
  1128. {
  1129. /*
  1130. Restrict visual search by class or visual id.
  1131. */
  1132. if (LocaleCompare("staticgray",visual_type) == 0)
  1133. {
  1134. visual_mask|=VisualClassMask;
  1135. visual_template.klass=StaticGray;
  1136. }
  1137. else
  1138. if (LocaleCompare("grayscale",visual_type) == 0)
  1139. {
  1140. visual_mask|=VisualClassMask;
  1141. visual_template.klass=GrayScale;
  1142. }
  1143. else
  1144. if (LocaleCompare("staticcolor",visual_type) == 0)
  1145. {
  1146. visual_mask|=VisualClassMask;
  1147. visual_template.klass=StaticColor;
  1148. }
  1149. else
  1150. if (LocaleCompare("pseudocolor",visual_type) == 0)
  1151. {
  1152. visual_mask|=VisualClassMask;
  1153. visual_template.klass=PseudoColor;
  1154. }
  1155. else
  1156. if (LocaleCompare("truecolor",visual_type) == 0)
  1157. {
  1158. visual_mask|=VisualClassMask;
  1159. visual_template.klass=TrueColor;
  1160. }
  1161. else
  1162. if (LocaleCompare("directcolor",visual_type) == 0)
  1163. {
  1164. visual_mask|=VisualClassMask;
  1165. visual_template.klass=DirectColor;
  1166. }
  1167. else
  1168. if (LocaleCompare("default",visual_type) == 0)
  1169. {
  1170. visual_mask|=VisualIDMask;
  1171. visual_template.visualid=XVisualIDFromVisual(
  1172. XDefaultVisual(display,XDefaultScreen(display)));
  1173. }
  1174. else
  1175. if (isdigit((int) ((unsigned char) *visual_type)) != 0)
  1176. {
  1177. visual_mask|=VisualIDMask;
  1178. visual_template.visualid=
  1179. strtol(visual_type,(char **) NULL,0);
  1180. }
  1181. else
  1182. ThrowXWindowException(XServerError,
  1183. "UnrecognizedVisualSpecifier",visual_type);
  1184. }
  1185. /*
  1186. Get all visuals that meet our criteria so far.
  1187. */
  1188. number_visuals=0;
  1189. visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
  1190. &number_visuals);
  1191. visual_mask=VisualScreenMask | VisualIDMask;
  1192. if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
  1193. {
  1194. /*
  1195. Failed to get visual; try using the default visual.
  1196. */
  1197. ThrowXWindowException(XServerWarning,"UnableToGetVisual",visual_type);
  1198. visual_template.visualid=XVisualIDFromVisual(XDefaultVisual(display,
  1199. XDefaultScreen(display)));
  1200. visual_list=XGetVisualInfo(display,visual_mask,&visual_template,
  1201. &number_visuals);
  1202. if ((number_visuals == 0) || (visual_list == (XVisualInfo *) NULL))
  1203. return((XVisualInfo *) NULL);
  1204. ThrowXWindowException(XServerWarning,"UsingDefaultVisual",
  1205. XVisualClassName(visual_list->klass));
  1206. }
  1207. resource_info->color_recovery=MagickFalse;
  1208. if ((map_info != (XStandardColormap *) NULL) && (map_type != (char *) NULL))
  1209. {
  1210. Atom
  1211. map_property;
  1212. char
  1213. map_name[MagickPathExtent];
  1214. int
  1215. j,
  1216. number_maps;
  1217. Status
  1218. status;
  1219. Window
  1220. root_window;
  1221. XStandardColormap
  1222. *map_list;
  1223. /*
  1224. Choose a visual associated with a standard colormap.
  1225. */
  1226. root_window=XRootWindow(display,XDefaultScreen(display));
  1227. status=False;
  1228. number_maps=0;
  1229. if (LocaleCompare(map_type,"list") != 0)
  1230. {
  1231. /*
  1232. User specified Standard Colormap.
  1233. */
  1234. (void) FormatLocaleString((char *) map_name,MagickPathExtent,
  1235. "RGB_%s_MAP",map_type);
  1236. LocaleUpper(map_name);
  1237. map_property=XInternAtom(display,(char *) map_name,MagickTrue);
  1238. if (map_property != (Atom) NULL)
  1239. status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
  1240. map_property);
  1241. }
  1242. else
  1243. {
  1244. static const char
  1245. *colormap[MaxStandardColormaps]=
  1246. {
  1247. "_HP_RGB_SMOOTH_MAP_LIST",
  1248. "RGB_BEST_MAP",
  1249. "RGB_DEFAULT_MAP",
  1250. "RGB_GRAY_MAP",
  1251. "RGB_RED_MAP",
  1252. "RGB_GREEN_MAP",
  1253. "RGB_BLUE_MAP",
  1254. };
  1255. /*
  1256. Choose a standard colormap from a list.
  1257. */
  1258. for (i=0; i < MaxStandardColormaps; i++)
  1259. {
  1260. map_property=XInternAtom(display,(char *) colormap[i],MagickTrue);
  1261. if (map_property == (Atom) NULL)
  1262. continue;
  1263. status=XGetRGBColormaps(display,root_window,&map_list,&number_maps,
  1264. map_property);
  1265. if (status != False)
  1266. break;
  1267. }
  1268. resource_info->color_recovery=i == 0 ? MagickTrue : MagickFalse;
  1269. }
  1270. if (status == False)
  1271. {
  1272. ThrowXWindowException(XServerError,"UnableToGetStandardColormap",
  1273. map_type);
  1274. return((XVisualInfo *) NULL);
  1275. }
  1276. /*
  1277. Search all Standard Colormaps and visuals for ids that match.
  1278. */
  1279. *map_info=map_list[0];
  1280. #if !defined(PRE_R4_ICCCM)
  1281. visual_template.visualid=XVisualIDFromVisual(visual_list[0].visual);
  1282. for (i=0; i < number_maps; i++)
  1283. for (j=0; j < number_visuals; j++)
  1284. if (map_list[i].visualid ==
  1285. XVisualIDFromVisual(visual_list[j].visual))
  1286. {
  1287. *map_info=map_list[i];
  1288. visual_template.visualid=XVisualIDFromVisual(
  1289. visual_list[j].visual);
  1290. break;
  1291. }
  1292. if (map_info->visualid != visual_template.visualid)
  1293. {
  1294. ThrowXWindowException(XServerError,
  1295. "UnableToMatchVisualToStandardColormap",map_type);
  1296. return((XVisualInfo *) NULL);
  1297. }
  1298. #endif
  1299. if (map_info->colormap == (Colormap) NULL)
  1300. {
  1301. ThrowXWindowException(XServerError,"StandardColormapIsNotInitialized",
  1302. map_type);
  1303. return((XVisualInfo *) NULL);
  1304. }
  1305. (void) XFree((void *) map_list);
  1306. }
  1307. else
  1308. {
  1309. static const unsigned int
  1310. rank[]=
  1311. {
  1312. StaticGray,
  1313. GrayScale,
  1314. StaticColor,
  1315. DirectColor,
  1316. TrueColor,
  1317. PseudoColor
  1318. };
  1319. XVisualInfo
  1320. *p;
  1321. /*
  1322. Pick one visual that displays the most simultaneous colors.
  1323. */
  1324. visual_info=visual_list;
  1325. p=visual_list;
  1326. for (i=1; i < number_visuals; i++)
  1327. {
  1328. p++;
  1329. if (XVisualColormapSize(p) > XVisualColormapSize(visual_info))
  1330. visual_info=p;
  1331. else
  1332. if (XVisualColormapSize(p) == XVisualColormapSize(visual_info))
  1333. if (rank[p->klass] > rank[visual_info->klass])
  1334. visual_info=p;
  1335. }
  1336. visual_template.visualid=XVisualIDFromVisual(visual_info->visual);
  1337. }
  1338. (void) XFree((void *) visual_list);
  1339. /*
  1340. Retrieve only one visual by its screen & id number.
  1341. */
  1342. visual_info=XGetVisualInfo(display,visual_mask,&visual_template,
  1343. &number_visuals);
  1344. if ((number_visuals == 0) || (visual_info == (XVisualInfo *) NULL))
  1345. return((XVisualInfo *) NULL);
  1346. return(visual_info);
  1347. }
  1348. /*
  1349. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1350. % %
  1351. % %
  1352. % %
  1353. % X C h e c k D e f i n e C u r s o r %
  1354. % %
  1355. % %
  1356. % %
  1357. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1358. %
  1359. % XCheckDefineCursor() prevents cursor changes on the root window.
  1360. %
  1361. % The format of the XXCheckDefineCursor method is:
  1362. %
  1363. % XCheckDefineCursor(display,window,cursor)
  1364. %
  1365. % A description of each parameter follows:
  1366. %
  1367. % o display: Specifies a connection to an X server; returned from
  1368. % XOpenDisplay.
  1369. %
  1370. % o window: the window.
  1371. %
  1372. % o cursor: the cursor.
  1373. %
  1374. */
  1375. MagickPrivate int XCheckDefineCursor(Display *display,Window window,
  1376. Cursor cursor)
  1377. {
  1378. (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
  1379. assert(display != (Display *) NULL);
  1380. if (window == XRootWindow(display,XDefaultScreen(display)))
  1381. return(0);
  1382. return(XDefineCursor(display,window,cursor));
  1383. }
  1384. /*
  1385. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1386. % %
  1387. % %
  1388. % %
  1389. % X C h e c k R e f r e s h W i n d o w s %
  1390. % %
  1391. % %
  1392. % %
  1393. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1394. %
  1395. % XCheckRefreshWindows() checks the X server for exposure events for a
  1396. % particular window and updates the areassociated with the exposure event.
  1397. %
  1398. % The format of the XCheckRefreshWindows method is:
  1399. %
  1400. % void XCheckRefreshWindows(Display *display,XWindows *windows)
  1401. %
  1402. % A description of each parameter follows:
  1403. %
  1404. % o display: Specifies a connection to an X server; returned from
  1405. % XOpenDisplay.
  1406. %
  1407. % o windows: Specifies a pointer to a XWindows structure.
  1408. %
  1409. */
  1410. MagickPrivate void XCheckRefreshWindows(Display *display,XWindows *windows)
  1411. {
  1412. Window
  1413. id;
  1414. XEvent
  1415. event;
  1416. (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
  1417. assert(display != (Display *) NULL);
  1418. assert(windows != (XWindows *) NULL);
  1419. XDelay(display,SuspendTime);
  1420. id=windows->command.id;
  1421. while (XCheckTypedWindowEvent(display,id,Expose,&event) != MagickFalse)
  1422. (void) XCommandWidget(display,windows,(char const **) NULL,&event);
  1423. id=windows->image

Large files files are truncated, but you can click here to view the full file