• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2   Copyright 1999-2019 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.  You may
6   obtain a copy of the License at
7 
8     https://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,  /* deprecated */
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 
222   XColor
223     matte_color;
224 } XPixelInfo;
225 
226 typedef struct _XResourceInfo
227 {
228   XrmDatabase
229     resource_database;
230 
231   ImageInfo
232     *image_info;
233 
234   QuantizeInfo
235     *quantize_info;
236 
237   size_t
238     colors;
239 
240   MagickBooleanType
241     close_server,
242     backdrop;
243 
244   char
245     *background_color,
246     *border_color;
247 
248   char
249     *client_name;
250 
251   XColormapType
252     colormap;
253 
254   unsigned int
255     border_width;
256 
257   size_t
258     delay;
259 
260   MagickBooleanType
261     color_recovery,
262     confirm_exit,
263     confirm_edit;
264 
265   char
266     *display_gamma;
267 
268   char
269     *font,
270     *font_name[MaxNumberFonts],
271     *foreground_color;
272 
273   MagickBooleanType
274     display_warnings,
275     gamma_correct;
276 
277   char
278     *icon_geometry;
279 
280   MagickBooleanType
281     iconic,
282     immutable;
283 
284   char
285     *image_geometry;
286 
287   char
288     *alpha_color,  /* deprecated */
289     *map_type,
290     *name;
291 
292   unsigned int
293     magnify,
294     pause;
295 
296   char
297     *pen_colors[MaxNumberPens];
298 
299   char
300     *text_font,
301     *title;
302 
303   int
304     quantum;
305 
306   unsigned int
307     update;
308 
309   MagickBooleanType
310     use_pixmap,
311     use_shared_memory;
312 
313   size_t
314     undo_cache;
315 
316   char
317     *visual_type,
318     *window_group,
319     *window_id,
320     *write_filename;
321 
322   Image
323     *copy_image;
324 
325   int
326     gravity;
327 
328   char
329     home_directory[MagickPathExtent];
330 
331   char
332     *matte_color;
333 } XResourceInfo;
334 
335 typedef struct _XWindowInfo
336 {
337   Window
338     id;
339 
340   Window
341     root;
342 
343   Visual
344     *visual;
345 
346   unsigned int
347     storage_class,
348     depth;
349 
350   XVisualInfo
351     *visual_info;
352 
353   XStandardColormap
354     *map_info;
355 
356   XPixelInfo
357     *pixel_info;
358 
359   XFontStruct
360     *font_info;
361 
362   GC
363     annotate_context,
364     highlight_context,
365     widget_context;
366 
367   Cursor
368     cursor,
369     busy_cursor;
370 
371   char
372     *name,
373     *geometry,
374     *icon_name,
375     *icon_geometry,
376     *crop_geometry;
377 
378   size_t
379     data,
380     flags;
381 
382   int
383     x,
384     y;
385 
386   unsigned int
387     width,
388     height,
389     min_width,
390     min_height,
391     width_inc,
392     height_inc,
393     border_width;
394 
395   MagickBooleanType
396     use_pixmap,
397     immutable,
398     shape,
399     shared_memory;
400 
401   int
402     screen;
403 
404   XImage
405     *ximage,
406     *matte_image;
407 
408   Pixmap
409     highlight_stipple,
410     shadow_stipple,
411     pixmap,
412     *pixmaps,
413     matte_pixmap,
414     *matte_pixmaps;
415 
416   XSetWindowAttributes
417     attributes;
418 
419   XWindowChanges
420     window_changes;
421 
422   void
423     *segment_info;
424 
425   long
426     mask;
427 
428   MagickBooleanType
429     orphan,
430     mapped,
431     stasis;
432 
433   Image
434     *image;
435 
436   MagickBooleanType
437     destroy;
438 } XWindowInfo;
439 
440 typedef struct _XWindows
441 {
442   Display
443     *display;
444 
445   XStandardColormap
446     *map_info,
447     *icon_map;
448 
449   XVisualInfo
450     *visual_info,
451     *icon_visual;
452 
453   XPixelInfo
454     *pixel_info,
455     *icon_pixel;
456 
457   XFontStruct
458     *font_info;
459 
460   XResourceInfo
461     *icon_resources;
462 
463   XClassHint
464     *class_hints;
465 
466   XWMHints
467     *manager_hints;
468 
469   XWindowInfo
470     context,
471     group_leader,
472     backdrop,
473     icon,
474     image,
475     info,
476     magnify,
477     pan,
478     command,
479     widget,
480     popup;
481 
482   Atom
483     wm_protocols,
484     wm_delete_window,
485     wm_take_focus,
486     im_protocols,
487     im_remote_command,
488     im_update_widget,
489     im_update_colormap,
490     im_former_image,
491     im_retain_colors,
492     im_next_image,
493     im_exit,
494     dnd_protocols;
495 } XWindows;
496 
497 extern MagickPrivate Cursor
498   XMakeCursor(Display *,Window,Colormap,char *,char *);
499 
500 extern MagickPrivate int
501   XCheckDefineCursor(Display *,Window,Cursor);
502 
503 extern MagickPrivate MagickBooleanType
504   XAnnotateImage(Display *,const XPixelInfo *,XAnnotateInfo *,Image *,
505     ExceptionInfo *),
506   XComponentGenesis(void),
507   XDrawImage(Display *,const XPixelInfo *,XDrawInfo *,Image *,ExceptionInfo *),
508   XGetWindowColor(Display *,XWindows *,char *,ExceptionInfo *),
509   XMagickProgressMonitor(const char *,const MagickOffsetType,
510     const MagickSizeType,void *),
511   XMakeImage(Display *,const XResourceInfo *,XWindowInfo *,Image *,unsigned int,
512     unsigned int,ExceptionInfo *),
513   XQueryColorCompliance(const char *,XColor *);
514 
515 extern MagickPrivate void
516   XBestIconSize(Display *,XWindowInfo *,Image *),
517   XBestPixel(Display *,const Colormap,XColor *,unsigned int,XColor *),
518   XCheckRefreshWindows(Display *,XWindows *),
519   XClientMessage(Display *,const Window,const Atom,const Atom,const Time),
520   XComponentTerminus(void),
521   XConfigureImageColormap(Display *,XResourceInfo *,XWindows *,Image *,
522     ExceptionInfo *),
523   XConstrainWindowPosition(Display *,XWindowInfo *),
524   XDelay(Display *,const size_t),
525   XDisplayImageInfo(Display *,const XResourceInfo *,XWindows *,Image *,Image *,
526     ExceptionInfo *),
527   XDestroyWindowColors(Display *,Window),
528   XFreeResources(Display *,XVisualInfo *,XStandardColormap *,XPixelInfo *,
529     XFontStruct *,XResourceInfo *,XWindowInfo *),
530   XFreeStandardColormap(Display *,const XVisualInfo *,XStandardColormap *,
531     XPixelInfo *),
532   XHighlightEllipse(Display *,Window,GC,const RectangleInfo *),
533   XHighlightLine(Display *,Window,GC,const XSegment *),
534   XHighlightRectangle(Display *,Window,GC,const RectangleInfo *),
535   XGetAnnotateInfo(XAnnotateInfo *),
536   XGetPixelInfo(Display *,const XVisualInfo *,const XStandardColormap *,
537     const XResourceInfo *,Image *,XPixelInfo *),
538   XGetMapInfo(const XVisualInfo *,const Colormap,XStandardColormap *),
539   XGetWindowInfo(Display *,XVisualInfo *,XStandardColormap *,XPixelInfo *,
540     XFontStruct *,XResourceInfo *,XWindowInfo *),
541   XMakeMagnifyImage(Display *,XWindows *,ExceptionInfo *),
542   XMakeStandardColormap(Display *,XVisualInfo *,XResourceInfo *,Image *,
543     XStandardColormap *,XPixelInfo *,ExceptionInfo *),
544   XMakeWindow(Display *,Window,char **,int,XClassHint *,XWMHints *,
545     XWindowInfo *),
546   XQueryPosition(Display *,const Window,int *,int *),
547   XRefreshWindow(Display *,const XWindowInfo *,const XEvent *),
548   XSetCursorState(Display *,XWindows *,const MagickStatusType),
549   XUserPreferences(XResourceInfo *),
550   XWarning(const ExceptionType,const char *,const char *);
551 
552 extern MagickPrivate Window
553   XWindowByID(Display *,const Window,const size_t),
554   XWindowByName(Display *,const Window,const char *),
555   XWindowByProperty(Display *,const Window,const Atom);
556 
557 extern MagickPrivate XFontStruct
558   *XBestFont(Display *,const XResourceInfo *,const MagickBooleanType);
559 
560 extern MagickPrivate XVisualInfo
561   *XBestVisualInfo(Display *,XStandardColormap *,XResourceInfo *);
562 
563 extern MagickPrivate XWindows
564   *XInitializeWindows(Display *,XResourceInfo *),
565   *XSetWindows(XWindows *);
566 
567 extern MagickExport char
568   *XGetResourceClass(XrmDatabase,const char *,const char *,char *),
569   *XGetResourceInstance(XrmDatabase,const char *,const char *,const char *),
570   *XGetScreenDensity(Display *);
571 
572 extern MagickExport int
573   XError(Display *,XErrorEvent *);
574 
575 extern MagickExport MagickBooleanType
576   XRemoteCommand(Display *,const char *,const char *);
577 
578 extern MagickExport void
579   DestroyXResources(void),
580   XDestroyResourceInfo(XResourceInfo *),
581   XGetResourceInfo(const ImageInfo *,XrmDatabase,const char *,XResourceInfo *),
582   XRetainWindowColors(Display *,const Window);
583 
584 extern MagickExport XrmDatabase
585   XGetResourceDatabase(Display *,const char *);
586 
XPixelIntensity(const XColor * pixel)587 static inline double XPixelIntensity(const XColor *pixel)
588 {
589   double
590     intensity;
591 
592   if ((pixel->red  == pixel->green) && (pixel->green == pixel->blue))
593     return((double) pixel->red);
594   intensity=0.212656*pixel->red+0.715158*pixel->green+0.072186*pixel->blue;
595   return(intensity);
596 }
597 
598 #endif
599 
600 extern MagickPrivate MagickBooleanType
601   XRenderImage(Image *,const DrawInfo *,const PointInfo *,TypeMetric *,
602     ExceptionInfo *);
603 
604 #if defined(__cplusplus) || defined(c_plusplus)
605 }
606 #endif
607 
608 #endif
609