• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2   Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization
3   dedicated to making software imaging solutions freely available.
4 
5   You may not use this file except in compliance with the License.
6   obtain a copy of the License at
7 
8     http://www.imagemagick.org/script/license.php
9 
10   Unless required by applicable law or agreed to in writing, software
11   distributed under the License is distributed on an "AS IS" BASIS,
12   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   See the License for the specific language governing permissions and
14   limitations under the License.
15 
16   MagickCore X11 window methods.
17 */
18 #ifndef MAGICKCORE_XWINDOW_PRIVATE_H
19 #define MAGICKCORE_XWINDOW_PRIVATE_H
20 
21 #include "MagickCore/draw.h"
22 #include "MagickCore/exception.h"
23 #include "MagickCore/geometry.h"
24 #include "MagickCore/nt-base-private.h"
25 #include "MagickCore/pixel-accessor.h"
26 #include "MagickCore/quantize.h"
27 
28 #if defined(__cplusplus) || defined(c_plusplus)
29 extern "C" {
30 #endif
31 
32 #if defined(MAGICKCORE_X11_DELEGATE)
33 
34 #include <X11/Xos.h>
35 #include <X11/Xlib.h>
36 #include <X11/Xatom.h>
37 #include <X11/cursorfont.h>
38 #include <X11/keysym.h>
39 #include <X11/Xresource.h>
40 #include <X11/Xutil.h>
41 
42 #if defined(__cplusplus) || defined(c_plusplus)
43 # define klass  c_class
44 #else
45 # define klass  class
46 #endif
47 
48 #define MaxIconSize  96
49 #define MaxNumberPens  11
50 #define MaxNumberFonts  11
51 #define MaxXWindows  12
52 #undef index
53 
54 #define ThrowXWindowException(severity,tag,context) \
55 { \
56   ExceptionInfo \
57     *exception; \
58  \
59   exception=AcquireExceptionInfo(); \
60   (void) ThrowMagickException(exception,GetMagickModule(),severity, \
61     tag == (const char *) NULL ? "unknown" : tag,"'%s': %s",context, \
62     strerror(errno)); \
63   CatchException(exception); \
64   (void) DestroyExceptionInfo(exception); \
65 }
66 #define ThrowXWindowFatalException(severity,tag,context) \
67 { \
68    ThrowXWindowException(severity,tag,context); \
69   _exit(1); \
70 }
71 
72 typedef enum
73 {
74   ForegroundStencil,
75   BackgroundStencil,
76   OpaqueStencil,
77   TransparentStencil
78 } AnnotationStencil;
79 
80 typedef enum
81 {
82   UndefinedElement,
83   PointElement,
84   LineElement,
85   RectangleElement,
86   FillRectangleElement,
87   CircleElement,
88   FillCircleElement,
89   EllipseElement,
90   FillEllipseElement,
91   PolygonElement,
92   FillPolygonElement,
93   ColorElement,
94   MatteElement,
95   TextElement,
96   ImageElement
97 } ElementType;
98 
99 typedef enum
100 {
101   UndefinedColormap,
102   PrivateColormap,
103   SharedColormap
104 } XColormapType;
105 
106 typedef struct _XDrawInfo
107 {
108   int
109     x,
110     y;
111 
112   unsigned int
113     width,
114     height;
115 
116   double
117     degrees;
118 
119   AnnotationStencil
120     stencil;
121 
122   ElementType
123     element;
124 
125   Pixmap
126     stipple;
127 
128   unsigned int
129     line_width;
130 
131   XSegment
132     line_info;
133 
134   unsigned int
135     number_coordinates;
136 
137   RectangleInfo
138     rectangle_info;
139 
140   XPoint
141     *coordinate_info;
142 
143   char
144     geometry[MagickPathExtent];
145 } XDrawInfo;
146 
147 typedef enum
148 {
149   DefaultState = 0x0000,
150   EscapeState = 0x0001,
151   ExitState = 0x0002,
152   FormerImageState = 0x0004,
153   ModifierState = 0x0008,
154   MontageImageState = 0x0010,
155   NextImageState = 0x0020,
156   RetainColorsState = 0x0040,
157   SuspendTime = 50,
158   UpdateConfigurationState = 0x0080,
159   UpdateRegionState = 0x0100
160 } XState;
161 
162 typedef struct _XAnnotateInfo
163 {
164   int
165     x,
166     y;
167 
168   unsigned int
169     width,
170     height;
171 
172   double
173     degrees;
174 
175   XFontStruct
176     *font_info;
177 
178   char
179     *text;
180 
181   AnnotationStencil
182     stencil;
183 
184   char
185     geometry[MagickPathExtent];
186 
187   struct _XAnnotateInfo
188     *next,
189     *previous;
190 } XAnnotateInfo;
191 
192 typedef struct _XPixelInfo
193 {
194   ssize_t
195     colors;
196 
197   unsigned long
198     *pixels;
199 
200   XColor
201     alpha_color,
202     foreground_color,
203     background_color,
204     border_color,
205     highlight_color,
206     shadow_color,
207     depth_color,
208     trough_color,
209     box_color,
210     pen_color,
211     pen_colors[MaxNumberPens];
212 
213   GC
214     annotate_context,
215     highlight_context,
216     widget_context;
217 
218   unsigned short
219     box_index,
220     pen_index;
221 } XPixelInfo;
222 
223 typedef struct _XResourceInfo
224 {
225   XrmDatabase
226     resource_database;
227 
228   ImageInfo
229     *image_info;
230 
231   QuantizeInfo
232     *quantize_info;
233 
234   size_t
235     colors;
236 
237   MagickBooleanType
238     close_server,
239     backdrop;
240 
241   char
242     *background_color,
243     *border_color;
244 
245   char
246     *client_name;
247 
248   XColormapType
249     colormap;
250 
251   unsigned int
252     border_width;
253 
254   size_t
255     delay;
256 
257   MagickBooleanType
258     color_recovery,
259     confirm_exit,
260     confirm_edit;
261 
262   char
263     *display_gamma;
264 
265   char
266     *font,
267     *font_name[MaxNumberFonts],
268     *foreground_color;
269 
270   MagickBooleanType
271     display_warnings,
272     gamma_correct;
273 
274   char
275     *icon_geometry;
276 
277   MagickBooleanType
278     iconic,
279     immutable;
280 
281   char
282     *image_geometry;
283 
284   char
285     *alpha_color,
286     *map_type,
287     *name;
288 
289   unsigned int
290     magnify,
291     pause;
292 
293   char
294     *pen_colors[MaxNumberPens];
295 
296   char
297     *text_font,
298     *title;
299 
300   int
301     quantum;
302 
303   unsigned int
304     update;
305 
306   MagickBooleanType
307     use_pixmap,
308     use_shared_memory;
309 
310   size_t
311     undo_cache;
312 
313   char
314     *visual_type,
315     *window_group,
316     *window_id,
317     *write_filename;
318 
319   Image
320     *copy_image;
321 
322   int
323     gravity;
324 
325   char
326     home_directory[MagickPathExtent];
327 } XResourceInfo;
328 
329 typedef struct _XWindowInfo
330 {
331   Window
332     id;
333 
334   Window
335     root;
336 
337   Visual
338     *visual;
339 
340   unsigned int
341     storage_class,
342     depth;
343 
344   XVisualInfo
345     *visual_info;
346 
347   XStandardColormap
348     *map_info;
349 
350   XPixelInfo
351     *pixel_info;
352 
353   XFontStruct
354     *font_info;
355 
356   GC
357     annotate_context,
358     highlight_context,
359     widget_context;
360 
361   Cursor
362     cursor,
363     busy_cursor;
364 
365   char
366     *name,
367     *geometry,
368     *icon_name,
369     *icon_geometry,
370     *crop_geometry;
371 
372   size_t
373     data,
374     flags;
375 
376   int
377     x,
378     y;
379 
380   unsigned int
381     width,
382     height,
383     min_width,
384     min_height,
385     width_inc,
386     height_inc,
387     border_width;
388 
389   MagickBooleanType
390     use_pixmap,
391     immutable,
392     shape,
393     shared_memory;
394 
395   int
396     screen;
397 
398   XImage
399     *ximage,
400     *matte_image;
401 
402   Pixmap
403     highlight_stipple,
404     shadow_stipple,
405     pixmap,
406     *pixmaps,
407     matte_pixmap,
408     *matte_pixmaps;
409 
410   XSetWindowAttributes
411     attributes;
412 
413   XWindowChanges
414     window_changes;
415 
416   void
417     *segment_info;
418 
419   long
420     mask;
421 
422   MagickBooleanType
423     orphan,
424     mapped,
425     stasis;
426 
427   Image
428     *image;
429 
430   MagickBooleanType
431     destroy;
432 } XWindowInfo;
433 
434 typedef struct _XWindows
435 {
436   Display
437     *display;
438 
439   XStandardColormap
440     *map_info,
441     *icon_map;
442 
443   XVisualInfo
444     *visual_info,
445     *icon_visual;
446 
447   XPixelInfo
448     *pixel_info,
449     *icon_pixel;
450 
451   XFontStruct
452     *font_info;
453 
454   XResourceInfo
455     *icon_resources;
456 
457   XClassHint
458     *class_hints;
459 
460   XWMHints
461     *manager_hints;
462 
463   XWindowInfo
464     context,
465     group_leader,
466     backdrop,
467     icon,
468     image,
469     info,
470     magnify,
471     pan,
472     command,
473     widget,
474     popup;
475 
476   Atom
477     wm_protocols,
478     wm_delete_window,
479     wm_take_focus,
480     im_protocols,
481     im_remote_command,
482     im_update_widget,
483     im_update_colormap,
484     im_former_image,
485     im_retain_colors,
486     im_next_image,
487     im_exit,
488     dnd_protocols;
489 } XWindows;
490 
491 extern MagickPrivate Cursor
492   XMakeCursor(Display *,Window,Colormap,char *,char *);
493 
494 extern MagickPrivate int
495   XCheckDefineCursor(Display *,Window,Cursor);
496 
497 extern MagickPrivate MagickBooleanType
498   XAnnotateImage(Display *,const XPixelInfo *,XAnnotateInfo *,Image *,
499     ExceptionInfo *),
500   XComponentGenesis(void),
501   XDrawImage(Display *,const XPixelInfo *,XDrawInfo *,Image *,ExceptionInfo *),
502   XGetWindowColor(Display *,XWindows *,char *,ExceptionInfo *),
503   XMagickProgressMonitor(const char *,const MagickOffsetType,
504     const MagickSizeType,void *),
505   XMakeImage(Display *,const XResourceInfo *,XWindowInfo *,Image *,unsigned int,
506     unsigned int,ExceptionInfo *),
507   XQueryColorCompliance(const char *,XColor *);
508 
509 extern MagickPrivate void
510   XBestIconSize(Display *,XWindowInfo *,Image *),
511   XBestPixel(Display *,const Colormap,XColor *,unsigned int,XColor *),
512   XCheckRefreshWindows(Display *,XWindows *),
513   XClientMessage(Display *,const Window,const Atom,const Atom,const Time),
514   XComponentTerminus(void),
515   XConfigureImageColormap(Display *,XResourceInfo *,XWindows *,Image *,
516     ExceptionInfo *),
517   XConstrainWindowPosition(Display *,XWindowInfo *),
518   XDelay(Display *,const size_t),
519   XDisplayImageInfo(Display *,const XResourceInfo *,XWindows *,Image *,Image *,
520     ExceptionInfo *),
521   XDestroyWindowColors(Display *,Window),
522   XFreeResources(Display *,XVisualInfo *,XStandardColormap *,XPixelInfo *,
523     XFontStruct *,XResourceInfo *,XWindowInfo *),
524   XFreeStandardColormap(Display *,const XVisualInfo *,XStandardColormap *,
525     XPixelInfo *),
526   XHighlightEllipse(Display *,Window,GC,const RectangleInfo *),
527   XHighlightLine(Display *,Window,GC,const XSegment *),
528   XHighlightRectangle(Display *,Window,GC,const RectangleInfo *),
529   XGetAnnotateInfo(XAnnotateInfo *),
530   XGetPixelInfo(Display *,const XVisualInfo *,const XStandardColormap *,
531     const XResourceInfo *,Image *,XPixelInfo *),
532   XGetMapInfo(const XVisualInfo *,const Colormap,XStandardColormap *),
533   XGetWindowInfo(Display *,XVisualInfo *,XStandardColormap *,XPixelInfo *,
534     XFontStruct *,XResourceInfo *,XWindowInfo *),
535   XMakeMagnifyImage(Display *,XWindows *,ExceptionInfo *),
536   XMakeStandardColormap(Display *,XVisualInfo *,XResourceInfo *,Image *,
537     XStandardColormap *,XPixelInfo *,ExceptionInfo *),
538   XMakeWindow(Display *,Window,char **,int,XClassHint *,XWMHints *,
539     XWindowInfo *),
540   XQueryPosition(Display *,const Window,int *,int *),
541   XRefreshWindow(Display *,const XWindowInfo *,const XEvent *),
542   XSetCursorState(Display *,XWindows *,const MagickStatusType),
543   XUserPreferences(XResourceInfo *),
544   XWarning(const ExceptionType,const char *,const char *);
545 
546 extern MagickPrivate Window
547   XWindowByID(Display *,const Window,const size_t),
548   XWindowByName(Display *,const Window,const char *),
549   XWindowByProperty(Display *,const Window,const Atom);
550 
551 extern MagickPrivate XFontStruct
552   *XBestFont(Display *,const XResourceInfo *,const MagickBooleanType);
553 
554 extern MagickPrivate XVisualInfo
555   *XBestVisualInfo(Display *,XStandardColormap *,XResourceInfo *);
556 
557 extern MagickPrivate XWindows
558   *XInitializeWindows(Display *,XResourceInfo *),
559   *XSetWindows(XWindows *);
560 
561 extern MagickExport char
562   *XGetResourceClass(XrmDatabase,const char *,const char *,char *),
563   *XGetResourceInstance(XrmDatabase,const char *,const char *,const char *),
564   *XGetScreenDensity(Display *);
565 
566 extern MagickExport int
567   XError(Display *,XErrorEvent *);
568 
569 extern MagickExport MagickBooleanType
570   XRemoteCommand(Display *,const char *,const char *);
571 
572 extern MagickExport void
573   DestroyXResources(void),
574   XDestroyResourceInfo(XResourceInfo *),
575   XGetResourceInfo(const ImageInfo *,XrmDatabase,const char *,XResourceInfo *),
576   XRetainWindowColors(Display *,const Window);
577 
578 extern MagickExport XrmDatabase
579   XGetResourceDatabase(Display *,const char *);
580 
XPixelIntensity(const XColor * pixel)581 static inline double XPixelIntensity(const XColor *pixel)
582 {
583   double
584     intensity;
585 
586   if ((pixel->red  == pixel->green) && (pixel->green == pixel->blue))
587     return((double) pixel->red);
588   intensity=0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue;
589   return(intensity);
590 }
591 
592 #endif
593 
594 extern MagickPrivate MagickBooleanType
595   XRenderImage(Image *,const DrawInfo *,const PointInfo *,TypeMetric *,
596     ExceptionInfo *);
597 
598 #if defined(__cplusplus) || defined(c_plusplus)
599 }
600 #endif
601 
602 #endif
603