42#include "magick/studio.h"
43#include "magick/artifact.h"
44#include "magick/attribute.h"
45#include "magick/blob.h"
46#include "magick/cache.h"
47#include "magick/channel.h"
48#include "magick/client.h"
49#include "magick/color.h"
50#include "magick/colorspace.h"
51#include "magick/composite.h"
52#include "magick/constitute.h"
53#include "magick/decorate.h"
54#include "magick/delegate.h"
55#include "magick/display.h"
56#include "magick/display-private.h"
57#include "magick/distort.h"
58#include "magick/draw.h"
59#include "magick/effect.h"
60#include "magick/enhance.h"
61#include "magick/exception.h"
62#include "magick/exception-private.h"
64#include "magick/geometry.h"
65#include "magick/image.h"
66#include "magick/image-private.h"
67#include "magick/list.h"
68#include "magick/locale-private.h"
69#include "magick/log.h"
70#include "magick/magick.h"
71#include "magick/memory_.h"
72#include "magick/monitor.h"
73#include "magick/monitor-private.h"
74#include "magick/montage.h"
75#include "magick/nt-base-private.h"
76#include "magick/option.h"
77#include "magick/paint.h"
78#include "magick/pixel.h"
79#include "magick/pixel-private.h"
80#include "magick/property.h"
81#include "magick/quantum.h"
82#include "magick/resize.h"
83#include "magick/resource_.h"
84#include "magick/shear.h"
85#include "magick/segment.h"
86#include "magick/statistic.h"
87#include "magick/string_.h"
88#include "magick/string-private.h"
89#include "magick/timer-private.h"
90#include "magick/transform.h"
91#include "magick/threshold.h"
92#include "magick/utility.h"
93#include "magick/utility-private.h"
94#include "magick/version.h"
95#include "magick/visual-effects.h"
96#include "magick/widget.h"
97#include "magick/xwindow-private.h"
99#if defined(MAGICKCORE_X11_DELEGATE)
103#define MaxColors MagickMin((ssize_t) windows->visual_info->colormap_size,256L)
108static const unsigned char
111 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55
115 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
119 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
126 ImageAnnotateHelp[] =
128 "In annotate mode, the Command widget has these options:\n"
178 "Choose a font name from the Font Name sub-menu. Additional\n"
179 "font names can be specified with the font browser. You can\n"
180 "change the menu names by setting the X resources font1\n"
183 "Choose a font color from the Font Color sub-menu.\n"
184 "Additional font colors can be specified with the color\n"
185 "browser. You can change the menu colors by setting the X\n"
186 "resources pen1 through pen9.\n"
188 "If you select the color browser and press Grab, you can\n"
189 "choose the font color by moving the pointer to the desired\n"
190 "color on the screen and press any button.\n"
192 "If you choose to rotate the text, choose Rotate Text from the\n"
193 "menu and select an angle. Typically you will only want to\n"
194 "rotate one line of text at a time. Depending on the angle you\n"
195 "choose, subsequent lines may end up overwriting each other.\n"
197 "Choosing a font and its color is optional. The default font\n"
198 "is fixed and the default color is black. However, you must\n"
199 "choose a location to begin entering text and press button 1.\n"
200 "An underscore character will appear at the location of the\n"
201 "pointer. The cursor changes to a pencil to indicate you are\n"
202 "in text mode. To exit immediately, press Dismiss.\n"
204 "In text mode, any key presses will display the character at\n"
205 "the location of the underscore and advance the underscore\n"
206 "cursor. Enter your text and once completed press Apply to\n"
207 "finish your image annotation. To correct errors press BACK\n"
208 "SPACE. To delete an entire line of text, press DELETE. Any\n"
209 "text that exceeds the boundaries of the image window is\n"
210 "automagically continued onto the next line.\n"
212 "The actual color you request for the font is saved in the\n"
213 "image. However, the color that appears in your image window\n"
214 "may be different. For example, on a monochrome screen the\n"
215 "text will appear black or white even if you choose the color\n"
216 "red as the font color. However, the image saved to a file\n"
217 "with -write is written with red lettering. To assure the\n"
218 "correct color text in the final image, any PseudoClass image\n"
219 "is promoted to DirectClass (see miff(5)). To force a\n"
220 "PseudoClass image to remain PseudoClass, use -colors.\n"
224 "In chop mode, the Command widget has these options:\n"
232 "If the you choose the horizontal direction (this the\n"
233 "default), the area of the image between the two horizontal\n"
234 "endpoints of the chop line is removed. Otherwise, the area\n"
235 "of the image between the two vertical endpoints of the chop\n"
238 "Select a location within the image window to begin your chop,\n"
239 "press and hold any button. Next, move the pointer to\n"
240 "another location in the image. As you move a line will\n"
241 "connect the initial location and the pointer. When you\n"
242 "release the button, the area within the image to chop is\n"
243 "determined by which direction you choose from the Command\n"
246 "To cancel the image chopping, move the pointer back to the\n"
247 "starting point of the line and release the button.\n"
249 ImageColorEditHelp[] =
251 "In color edit mode, the Command widget has these options:\n"
292 "Choose a color editing method from the Method sub-menu\n"
293 "of the Command widget. The point method recolors any pixel\n"
294 "selected with the pointer until the button is released. The\n"
295 "replace method recolors any pixel that matches the color of\n"
296 "the pixel you select with a button press. Floodfill recolors\n"
297 "any pixel that matches the color of the pixel you select with\n"
298 "a button press and is a neighbor. Whereas filltoborder recolors\n"
299 "any neighbor pixel that is not the border color. Finally reset\n"
300 "changes the entire image to the designated color.\n"
302 "Next, choose a pixel color from the Pixel Color sub-menu.\n"
303 "Additional pixel colors can be specified with the color\n"
304 "browser. You can change the menu colors by setting the X\n"
305 "resources pen1 through pen9.\n"
307 "Now press button 1 to select a pixel within the image window\n"
308 "to change its color. Additional pixels may be recolored as\n"
309 "prescribed by the method you choose.\n"
311 "If the Magnify widget is mapped, it can be helpful in positioning\n"
312 "your pointer within the image (refer to button 2).\n"
314 "The actual color you request for the pixels is saved in the\n"
315 "image. However, the color that appears in your image window\n"
316 "may be different. For example, on a monochrome screen the\n"
317 "pixel will appear black or white even if you choose the\n"
318 "color red as the pixel color. However, the image saved to a\n"
319 "file with -write is written with red pixels. To assure the\n"
320 "correct color text in the final image, any PseudoClass image\n"
321 "is promoted to DirectClass (see miff(5)). To force a\n"
322 "PseudoClass image to remain PseudoClass, use -colors.\n"
324 ImageCompositeHelp[] =
326 "First a widget window is displayed requesting you to enter an\n"
327 "image name. Press Composite, Grab or type a file name.\n"
328 "Press Cancel if you choose not to create a composite image.\n"
329 "When you choose Grab, move the pointer to the desired window\n"
330 "and press any button.\n"
332 "If the Composite image does not have any matte information,\n"
333 "you are informed and the file browser is displayed again.\n"
334 "Enter the name of a mask image. The image is typically\n"
335 "grayscale and the same size as the composite image. If the\n"
336 "image is not grayscale, it is converted to grayscale and the\n"
337 "resulting intensities are used as matte information.\n"
339 "A small window appears showing the location of the cursor in\n"
340 "the image window. You are now in composite mode. To exit\n"
341 "immediately, press Dismiss. In composite mode, the Command\n"
342 "widget has these options:\n"
368 "Choose a composite operation from the Operators sub-menu of\n"
369 "the Command widget. How each operator behaves is described\n"
370 "below. Image window is the image currently displayed on\n"
371 "your X server and image is the image obtained with the File\n"
374 "Over The result is the union of the two image shapes,\n"
375 " with image obscuring image window in the region of\n"
378 "In The result is simply image cut by the shape of\n"
379 " image window. None of the image data of image\n"
380 " window is in the result.\n"
382 "Out The resulting image is image with the shape of\n"
383 " image window cut out.\n"
385 "Atop The result is the same shape as the image window,\n"
386 " with image obscuring image window where the image\n"
387 " shapes overlap. Note this differs from over\n"
388 " because the portion of image outside image window's\n"
389 " shape does not appear in the result.\n"
391 "Xor The result is the image data from both image and\n"
392 " image window that is outside the overlap region.\n"
393 " The overlap region is blank.\n"
395 "Plus The result is just the sum of the image data.\n"
396 " Output values are cropped to QuantumRange (no overflow).\n"
398 "Minus The result of image - image window, with underflow\n"
399 " cropped to zero.\n"
401 "Add The result of image + image window, with overflow\n"
402 " wrapping around (mod 256).\n"
404 "Subtract The result of image - image window, with underflow\n"
405 " wrapping around (mod 256). The add and subtract\n"
406 " operators can be used to perform reversible\n"
407 " transformations.\n"
410 " The result of abs(image - image window). This\n"
411 " useful for comparing two very similar images.\n"
414 " The result of image * image window. This\n"
415 " useful for the creation of drop-shadows.\n"
417 "Bumpmap The result of surface normals from image * image\n"
420 "Copy The resulting image is image window replaced with\n"
421 " image. Here the matte information is ignored.\n"
423 "CopyRed The red layer of the image window is replace with\n"
424 " the red layer of the image. The other layers are\n"
428 " The green layer of the image window is replace with\n"
429 " the green layer of the image. The other layers are\n"
432 "CopyBlue The blue layer of the image window is replace with\n"
433 " the blue layer of the image. The other layers are\n"
437 " The matte layer of the image window is replace with\n"
438 " the matte layer of the image. The other layers are\n"
441 "The image compositor requires a matte, or alpha channel in\n"
442 "the image for some operations. This extra channel usually\n"
443 "defines a mask which represents a sort of a cookie-cutter\n"
444 "for the image. This the case when matte is opaque (full\n"
445 "coverage) for pixels inside the shape, zero outside, and\n"
446 "between 0 and QuantumRange on the boundary. If image does not\n"
447 "have a matte channel, it is initialized with 0 for any pixel\n"
448 "matching in color to pixel location (0,0), otherwise QuantumRange.\n"
450 "If you choose Dissolve, the composite operator becomes Over. The\n"
451 "image matte channel percent transparency is initialized to factor.\n"
452 "The image window is initialized to (100-factor). Where factor is the\n"
453 "value you specify in the Dialog widget.\n"
455 "Displace shifts the image pixels as defined by a displacement\n"
456 "map. With this option, image is used as a displacement map.\n"
457 "Black, within the displacement map, is a maximum positive\n"
458 "displacement. White is a maximum negative displacement and\n"
459 "middle gray is neutral. The displacement is scaled to determine\n"
460 "the pixel shift. By default, the displacement applies in both the\n"
461 "horizontal and vertical directions. However, if you specify a mask,\n"
462 "image is the horizontal X displacement and mask the vertical Y\n"
465 "Note that matte information for image window is not retained\n"
466 "for colormapped X server visuals (e.g. StaticColor,\n"
467 "StaticColor, GrayScale, PseudoColor). Correct compositing\n"
468 "behavior may require a TrueColor or DirectColor visual or a\n"
469 "Standard Colormap.\n"
471 "Choosing a composite operator is optional. The default\n"
472 "operator is replace. However, you must choose a location to\n"
473 "composite your image and press button 1. Press and hold the\n"
474 "button before releasing and an outline of the image will\n"
475 "appear to help you identify your location.\n"
477 "The actual colors of the composite image is saved. However,\n"
478 "the color that appears in image window may be different.\n"
479 "For example, on a monochrome screen image window will appear\n"
480 "black or white even though your composited image may have\n"
481 "many colors. If the image is saved to a file it is written\n"
482 "with the correct colors. To assure the correct colors are\n"
483 "saved in the final image, any PseudoClass image is promoted\n"
484 "to DirectClass (see miff(5)). To force a PseudoClass image\n"
485 "to remain PseudoClass, use -colors.\n"
489 "In cut mode, the Command widget has these options:\n"
494 "To define a cut region, press button 1 and drag. The\n"
495 "cut region is defined by a highlighted rectangle that\n"
496 "expands or contracts as it follows the pointer. Once you\n"
497 "are satisfied with the cut region, release the button.\n"
498 "You are now in rectify mode. In rectify mode, the Command\n"
499 "widget has these options:\n"
505 "You can make adjustments by moving the pointer to one of the\n"
506 "cut rectangle corners, pressing a button, and dragging.\n"
507 "Finally, press Cut to commit your copy region. To\n"
508 "exit without cutting the image, press Dismiss.\n"
512 "In copy mode, the Command widget has these options:\n"
517 "To define a copy region, press button 1 and drag. The\n"
518 "copy region is defined by a highlighted rectangle that\n"
519 "expands or contracts as it follows the pointer. Once you\n"
520 "are satisfied with the copy region, release the button.\n"
521 "You are now in rectify mode. In rectify mode, the Command\n"
522 "widget has these options:\n"
528 "You can make adjustments by moving the pointer to one of the\n"
529 "copy rectangle corners, pressing a button, and dragging.\n"
530 "Finally, press Copy to commit your copy region. To\n"
531 "exit without copying the image, press Dismiss.\n"
535 "In crop mode, the Command widget has these options:\n"
540 "To define a cropping region, press button 1 and drag. The\n"
541 "cropping region is defined by a highlighted rectangle that\n"
542 "expands or contracts as it follows the pointer. Once you\n"
543 "are satisfied with the cropping region, release the button.\n"
544 "You are now in rectify mode. In rectify mode, the Command\n"
545 "widget has these options:\n"
551 "You can make adjustments by moving the pointer to one of the\n"
552 "cropping rectangle corners, pressing a button, and dragging.\n"
553 "Finally, press Crop to commit your cropping region. To\n"
554 "exit without cropping the image, press Dismiss.\n"
558 "The cursor changes to a crosshair to indicate you are in\n"
559 "draw mode. To exit immediately, press Dismiss. In draw mode,\n"
560 "the Command widget has these options:\n"
605 "Choose a drawing primitive from the Element sub-menu.\n"
607 "Choose a color from the Color sub-menu. Additional\n"
608 "colors can be specified with the color browser.\n"
610 "If you choose the color browser and press Grab, you can\n"
611 "select the color by moving the pointer to the desired\n"
612 "color on the screen and press any button. The transparent\n"
613 "color updates the image matte channel and is useful for\n"
614 "image compositing.\n"
616 "Choose a stipple, if appropriate, from the Stipple sub-menu.\n"
617 "Additional stipples can be specified with the file browser.\n"
618 "Stipples obtained from the file browser must be on disk in the\n"
619 "X11 bitmap format.\n"
621 "Choose a width, if appropriate, from the Width sub-menu. To\n"
622 "choose a specific width select the Dialog widget.\n"
624 "Choose a point in the Image window and press button 1 and\n"
625 "hold. Next, move the pointer to another location in the\n"
626 "image. As you move, a line connects the initial location and\n"
627 "the pointer. When you release the button, the image is\n"
628 "updated with the primitive you just drew. For polygons, the\n"
629 "image is updated when you press and release the button without\n"
630 "moving the pointer.\n"
632 "To cancel image drawing, move the pointer back to the\n"
633 "starting point of the line and release the button.\n"
638 " The effects of each button press is described below. Three\n"
639 " buttons are required. If you have a two button mouse,\n"
640 " button 1 and 3 are returned. Press ALT and button 3 to\n"
641 " simulate button 2.\n"
643 " 1 Press this button to map or unmap the Command widget.\n"
645 " 2 Press and drag to define a region of the image to\n"
648 " 3 Press and drag to choose from a select set of commands.\n"
649 " This button behaves differently if the image being\n"
650 " displayed is a visual image directory. Here, choose a\n"
651 " particular tile of the directory and press this button and\n"
652 " drag to select a command from a pop-up menu. Choose from\n"
653 " these menu items:\n"
661 " If you choose Open, the image represented by the tile is\n"
662 " displayed. To return to the visual image directory, choose\n"
663 " Next from the Command widget. Next and Former moves to the\n"
664 " next or former image respectively. Choose Delete to delete\n"
665 " a particular image tile. Finally, choose Update to\n"
666 " synchronize all the image tiles with their respective\n"
670 " The Command widget lists a number of sub-menus and commands.\n"
682 " Visual Directory...\n"
716 " Contrast Stretch...\n"
717 " Sigmoidal Contrast...\n"
745 " Charcoal Drawing...\n"
756 " Region of Interest...\n"
768 " Browse Documentation\n"
771 " Menu items with a indented triangle have a sub-menu. They\n"
772 " are represented above as the indented items. To access a\n"
773 " sub-menu item, move the pointer to the appropriate menu and\n"
774 " press a button and drag. When you find the desired sub-menu\n"
775 " item, release the button and the command is executed. Move\n"
776 " the pointer away from the sub-menu if you decide not to\n"
777 " execute a particular command.\n"
779 "KEYBOARD ACCELERATORS\n"
780 " Accelerators are one or two key presses that effect a\n"
781 " particular command. The keyboard accelerators that\n"
782 " display(1) understands is:\n"
784 " Ctl+O Press to open an image from a file.\n"
786 " space Press to display the next image.\n"
788 " If the image is a multi-paged document such as a Postscript\n"
789 " document, you can skip ahead several pages by preceding\n"
790 " this command with a number. For example to display the\n"
791 " third page beyond the current page, press 3<space>.\n"
793 " backspace Press to display the former image.\n"
795 " If the image is a multi-paged document such as a Postscript\n"
796 " document, you can skip behind several pages by preceding\n"
797 " this command with a number. For example to display the\n"
798 " third page preceding the current page, press 3<backspace>.\n"
800 " Ctl+S Press to write the image to a file.\n"
802 " Ctl+P Press to print the image to a Postscript printer.\n"
804 " Ctl+D Press to delete an image file.\n"
806 " Ctl+N Press to create a blank canvas.\n"
808 " Ctl+Q Press to discard all images and exit program.\n"
810 " Ctl+Z Press to undo last image transformation.\n"
812 " Ctl+R Press to redo last image transformation.\n"
814 " Ctl+X Press to cut a region of the image.\n"
816 " Ctl+C Press to copy a region of the image.\n"
818 " Ctl+V Press to paste a region to the image.\n"
820 " < Press to half the image size.\n"
822 " - Press to return to the original image size.\n"
824 " > Press to double the image size.\n"
826 " % Press to resize the image to a width and height you\n"
829 "Cmd-A Press to make any image transformations permanent."
831 " By default, any image size transformations are applied\n"
832 " to the original image to create the image displayed on\n"
833 " the X server. However, the transformations are not\n"
834 " permanent (i.e. the original image does not change\n"
835 " size only the X image does). For example, if you\n"
836 " press > the X image will appear to double in size,\n"
837 " but the original image will in fact remain the same size.\n"
838 " To force the original image to double in size, press >\n"
839 " followed by Cmd-A.\n"
841 " @ Press to refresh the image window.\n"
843 " C Press to cut out a rectangular region of the image.\n"
845 " [ Press to chop the image.\n"
847 " H Press to flop image in the horizontal direction.\n"
849 " V Press to flip image in the vertical direction.\n"
851 " / Press to rotate the image 90 degrees clockwise.\n"
853 " \\ Press to rotate the image 90 degrees counter-clockwise.\n"
855 " * Press to rotate the image the number of degrees you\n"
858 " S Press to shear the image the number of degrees you\n"
861 " R Press to roll the image.\n"
863 " T Press to trim the image edges.\n"
865 " Shft-H Press to vary the image hue.\n"
867 " Shft-S Press to vary the color saturation.\n"
869 " Shft-L Press to vary the color brightness.\n"
871 " Shft-G Press to gamma correct the image.\n"
873 " Shft-C Press to sharpen the image contrast.\n"
875 " Shft-Z Press to dull the image contrast.\n"
877 " = Press to perform histogram equalization on the image.\n"
879 " Shft-N Press to perform histogram normalization on the image.\n"
881 " Shft-~ Press to negate the colors of the image.\n"
883 " . Press to convert the image colors to gray.\n"
885 " Shft-# Press to set the maximum number of unique colors in the\n"
888 " F2 Press to reduce the speckles in an image.\n"
890 " F3 Press to eliminate peak noise from an image.\n"
892 " F4 Press to add noise to an image.\n"
894 " F5 Press to sharpen an image.\n"
896 " F6 Press to delete an image file.\n"
898 " F7 Press to threshold the image.\n"
900 " F8 Press to detect edges within an image.\n"
902 " F9 Press to emboss an image.\n"
904 " F10 Press to displace pixels by a random amount.\n"
906 " F11 Press to negate all pixels above the threshold level.\n"
908 " F12 Press to shade the image using a distant light source.\n"
910 " F13 Press to lighten or darken image edges to create a 3-D effect.\n"
912 " F14 Press to segment the image by color.\n"
914 " Meta-S Press to swirl image pixels about the center.\n"
916 " Meta-I Press to implode image pixels about the center.\n"
918 " Meta-W Press to alter an image along a sine wave.\n"
920 " Meta-P Press to simulate an oil painting.\n"
922 " Meta-C Press to simulate a charcoal drawing.\n"
924 " Alt-A Press to annotate the image with text.\n"
926 " Alt-D Press to draw on an image.\n"
928 " Alt-P Press to edit an image pixel color.\n"
930 " Alt-M Press to edit the image matte information.\n"
932 " Alt-V Press to composite the image with another.\n"
934 " Alt-B Press to add a border to the image.\n"
936 " Alt-F Press to add an ornamental border to the image.\n"
939 " Press to add an image comment.\n"
941 " Ctl-A Press to apply image processing techniques to a region\n"
944 " Shft-? Press to display information about the image.\n"
946 " Shft-+ Press to map the zoom image window.\n"
948 " Shft-P Press to preview an image enhancement, effect, or f/x.\n"
950 " F1 Press to display helpful information about display(1).\n"
952 " Find Press to browse documentation about ImageMagick.\n"
954 " 1-9 Press to change the level of magnification.\n"
956 " Use the arrow keys to move the image one pixel up, down,\n"
957 " left, or right within the magnify window. Be sure to first\n"
958 " map the magnify window by pressing button 2.\n"
960 " Press ALT and one of the arrow keys to trim off one pixel\n"
961 " from any side of the image.\n"
963 ImageMatteEditHelp[] =
965 "Matte information within an image is useful for some\n"
966 "operations such as image compositing (See IMAGE\n"
967 "COMPOSITING). This extra channel usually defines a mask\n"
968 "which represents a sort of a cookie-cutter for the image.\n"
969 "This the case when matte is opaque (full coverage) for\n"
970 "pixels inside the shape, zero outside, and between 0 and\n"
971 "QuantumRange on the boundary.\n"
973 "A small window appears showing the location of the cursor in\n"
974 "the image window. You are now in matte edit mode. To exit\n"
975 "immediately, press Dismiss. In matte edit mode, the Command\n"
976 "widget has these options:\n"
1010 "Choose a matte editing method from the Method sub-menu of\n"
1011 "the Command widget. The point method changes the matte value\n"
1012 "of any pixel selected with the pointer until the button is\n"
1013 "is released. The replace method changes the matte value of\n"
1014 "any pixel that matches the color of the pixel you select with\n"
1015 "a button press. Floodfill changes the matte value of any pixel\n"
1016 "that matches the color of the pixel you select with a button\n"
1017 "press and is a neighbor. Whereas filltoborder changes the matte\n"
1018 "value any neighbor pixel that is not the border color. Finally\n"
1019 "reset changes the entire image to the designated matte value.\n"
1021 "Choose Matte Value and pick Opaque or Transparent. For other values\n"
1022 "select the Dialog entry. Here a dialog appears requesting a matte\n"
1023 "value. The value you select is assigned as the opacity value of the\n"
1024 "selected pixel or pixels.\n"
1026 "Now, press any button to select a pixel within the image\n"
1027 "window to change its matte value.\n"
1029 "If the Magnify widget is mapped, it can be helpful in positioning\n"
1030 "your pointer within the image (refer to button 2).\n"
1032 "Matte information is only valid in a DirectClass image.\n"
1033 "Therefore, any PseudoClass image is promoted to DirectClass\n"
1034 "(see miff(5)). Note that matte information for PseudoClass\n"
1035 "is not retained for colormapped X server visuals (e.g.\n"
1036 "StaticColor, StaticColor, GrayScale, PseudoColor) unless you\n"
1037 "immediately save your image to a file (refer to Write).\n"
1038 "Correct matte editing behavior may require a TrueColor or\n"
1039 "DirectColor visual or a Standard Colormap.\n"
1043 "When an image exceeds the width or height of the X server\n"
1044 "screen, display maps a small panning icon. The rectangle\n"
1045 "within the panning icon shows the area that is currently\n"
1046 "displayed in the image window. To pan about the image,\n"
1047 "press any button and drag the pointer within the panning\n"
1048 "icon. The pan rectangle moves with the pointer and the\n"
1049 "image window is updated to reflect the location of the\n"
1050 "rectangle within the panning icon. When you have selected\n"
1051 "the area of the image you wish to view, release the button.\n"
1053 "Use the arrow keys to pan the image one pixel up, down,\n"
1054 "left, or right within the image window.\n"
1056 "The panning icon is withdrawn if the image becomes smaller\n"
1057 "than the dimensions of the X server screen.\n"
1061 "A small window appears showing the location of the cursor in\n"
1062 "the image window. You are now in paste mode. To exit\n"
1063 "immediately, press Dismiss. In paste mode, the Command\n"
1064 "widget has these options:\n"
1081 "Choose a composite operation from the Operators sub-menu of\n"
1082 "the Command widget. How each operator behaves is described\n"
1083 "below. Image window is the image currently displayed on\n"
1084 "your X server and image is the image obtained with the File\n"
1087 "Over The result is the union of the two image shapes,\n"
1088 " with image obscuring image window in the region of\n"
1091 "In The result is simply image cut by the shape of\n"
1092 " image window. None of the image data of image\n"
1093 " window is in the result.\n"
1095 "Out The resulting image is image with the shape of\n"
1096 " image window cut out.\n"
1098 "Atop The result is the same shape as the image window,\n"
1099 " with image obscuring image window where the image\n"
1100 " shapes overlap. Note this differs from over\n"
1101 " because the portion of image outside image window's\n"
1102 " shape does not appear in the result.\n"
1104 "Xor The result is the image data from both image and\n"
1105 " image window that is outside the overlap region.\n"
1106 " The overlap region is blank.\n"
1108 "Plus The result is just the sum of the image data.\n"
1109 " Output values are cropped to QuantumRange (no overflow).\n"
1110 " This operation is independent of the matte\n"
1113 "Minus The result of image - image window, with underflow\n"
1114 " cropped to zero.\n"
1116 "Add The result of image + image window, with overflow\n"
1117 " wrapping around (mod 256).\n"
1119 "Subtract The result of image - image window, with underflow\n"
1120 " wrapping around (mod 256). The add and subtract\n"
1121 " operators can be used to perform reversible\n"
1122 " transformations.\n"
1125 " The result of abs(image - image window). This\n"
1126 " useful for comparing two very similar images.\n"
1128 "Copy The resulting image is image window replaced with\n"
1129 " image. Here the matte information is ignored.\n"
1131 "CopyRed The red layer of the image window is replace with\n"
1132 " the red layer of the image. The other layers are\n"
1136 " The green layer of the image window is replace with\n"
1137 " the green layer of the image. The other layers are\n"
1140 "CopyBlue The blue layer of the image window is replace with\n"
1141 " the blue layer of the image. The other layers are\n"
1145 " The matte layer of the image window is replace with\n"
1146 " the matte layer of the image. The other layers are\n"
1149 "The image compositor requires a matte, or alpha channel in\n"
1150 "the image for some operations. This extra channel usually\n"
1151 "defines a mask which represents a sort of a cookie-cutter\n"
1152 "for the image. This the case when matte is opaque (full\n"
1153 "coverage) for pixels inside the shape, zero outside, and\n"
1154 "between 0 and QuantumRange on the boundary. If image does not\n"
1155 "have a matte channel, it is initialized with 0 for any pixel\n"
1156 "matching in color to pixel location (0,0), otherwise QuantumRange.\n"
1158 "Note that matte information for image window is not retained\n"
1159 "for colormapped X server visuals (e.g. StaticColor,\n"
1160 "StaticColor, GrayScale, PseudoColor). Correct compositing\n"
1161 "behavior may require a TrueColor or DirectColor visual or a\n"
1162 "Standard Colormap.\n"
1164 "Choosing a composite operator is optional. The default\n"
1165 "operator is replace. However, you must choose a location to\n"
1166 "paste your image and press button 1. Press and hold the\n"
1167 "button before releasing and an outline of the image will\n"
1168 "appear to help you identify your location.\n"
1170 "The actual colors of the pasted image is saved. However,\n"
1171 "the color that appears in image window may be different.\n"
1172 "For example, on a monochrome screen image window will appear\n"
1173 "black or white even though your pasted image may have\n"
1174 "many colors. If the image is saved to a file it is written\n"
1175 "with the correct colors. To assure the correct colors are\n"
1176 "saved in the final image, any PseudoClass image is promoted\n"
1177 "to DirectClass (see miff(5)). To force a PseudoClass image\n"
1178 "to remain PseudoClass, use -colors.\n"
1182 "In region of interest mode, the Command widget has these\n"
1188 "To define a region of interest, press button 1 and drag.\n"
1189 "The region of interest is defined by a highlighted rectangle\n"
1190 "that expands or contracts as it follows the pointer. Once\n"
1191 "you are satisfied with the region of interest, release the\n"
1192 "button. You are now in apply mode. In apply mode the\n"
1193 "Command widget has these options:\n"
1213 " Contrast Stretch\n"
1214 " Sigmoidal Contrast...\n"
1240 " Oil Painting...\n"
1241 " Charcoal Drawing...\n"
1245 " Show Preview...\n"
1251 "You can make adjustments to the region of interest by moving\n"
1252 "the pointer to one of the rectangle corners, pressing a\n"
1253 "button, and dragging. Finally, choose an image processing\n"
1254 "technique from the Command widget. You can choose more than\n"
1255 "one image processing technique to apply to an area.\n"
1256 "Alternatively, you can move the region of interest before\n"
1257 "applying another image processing technique. To exit, press\n"
1262 "In rotate mode, the Command widget has these options:\n"
1281 "Choose a background color from the Pixel Color sub-menu.\n"
1282 "Additional background colors can be specified with the color\n"
1283 "browser. You can change the menu colors by setting the X\n"
1284 "resources pen1 through pen9.\n"
1286 "If you choose the color browser and press Grab, you can\n"
1287 "select the background color by moving the pointer to the\n"
1288 "desired color on the screen and press any button.\n"
1290 "Choose a point in the image window and press this button and\n"
1291 "hold. Next, move the pointer to another location in the\n"
1292 "image. As you move a line connects the initial location and\n"
1293 "the pointer. When you release the button, the degree of\n"
1294 "image rotation is determined by the slope of the line you\n"
1295 "just drew. The slope is relative to the direction you\n"
1296 "choose from the Direction sub-menu of the Command widget.\n"
1298 "To cancel the image rotation, move the pointer back to the\n"
1299 "starting point of the line and release the button.\n"
1322 VisualDirectoryCommand,
1330 OriginalSizeCommand,
1352 ContrastStretchCommand,
1353 SigmoidalContrastCommand,
1379 CharcoalDrawCommand,
1389 RegionOfInterestCommand,
1395 ShowHistogramCommand,
1401 BrowseDocumentationCommand,
1403 SaveToUndoBufferCommand,
1410 AnnotateNameCommand,
1411 AnnotateFontColorCommand,
1412 AnnotateBackgroundColorCommand,
1413 AnnotateRotateCommand,
1414 AnnotateHelpCommand,
1415 AnnotateDismissCommand,
1418 ChopDirectionCommand,
1421 HorizontalChopCommand,
1422 VerticalChopCommand,
1423 ColorEditMethodCommand,
1424 ColorEditColorCommand,
1425 ColorEditBorderCommand,
1426 ColorEditFuzzCommand,
1427 ColorEditUndoCommand,
1428 ColorEditHelpCommand,
1429 ColorEditDismissCommand,
1430 CompositeOperatorsCommand,
1431 CompositeDissolveCommand,
1432 CompositeDisplaceCommand,
1433 CompositeHelpCommand,
1434 CompositeDismissCommand,
1439 RectifyDismissCommand,
1448 MatteEditBorderCommand,
1449 MatteEditFuzzCommand,
1450 MatteEditValueCommand,
1451 MatteEditUndoCommand,
1452 MatteEditHelpCommand,
1453 MatteEditDismissCommand,
1454 PasteOperatorsCommand,
1456 PasteDismissCommand,
1458 RotateDirectionCommand,
1460 RotateSharpenCommand,
1462 RotateDismissCommand,
1463 HorizontalRotateCommand,
1464 VerticalRotateCommand,
1475#define BricksWidth 20
1476#define BricksHeight 20
1477#define DiagonalWidth 16
1478#define DiagonalHeight 16
1479#define HighlightWidth 8
1480#define HighlightHeight 8
1481#define OpaqueWidth 8
1482#define OpaqueHeight 8
1483#define ScalesWidth 16
1484#define ScalesHeight 16
1485#define ShadowWidth 8
1486#define ShadowHeight 8
1487#define VerticalWidth 16
1488#define VerticalHeight 16
1490#define WavyHeight 16
1498static const unsigned char
1501 0xff, 0xff, 0x0f, 0x03, 0x0c, 0x00, 0x03, 0x0c, 0x00, 0x03, 0x0c, 0x00,
1502 0x03, 0x0c, 0x00, 0xff, 0xff, 0x0f, 0x60, 0x80, 0x01, 0x60, 0x80, 0x01,
1503 0x60, 0x80, 0x01, 0x60, 0x80, 0x01, 0xff, 0xff, 0x0f, 0x03, 0x0c, 0x00,
1504 0x03, 0x0c, 0x00, 0x03, 0x0c, 0x00, 0x03, 0x0c, 0x00, 0xff, 0xff, 0x0f,
1505 0x60, 0x80, 0x01, 0x60, 0x80, 0x01, 0x60, 0x80, 0x01, 0x60, 0x80, 0x01
1509 0x44, 0x44, 0x88, 0x88, 0x11, 0x11, 0x22, 0x22, 0x44, 0x44, 0x88, 0x88,
1510 0x11, 0x11, 0x22, 0x22, 0x44, 0x44, 0x88, 0x88, 0x11, 0x11, 0x22, 0x22,
1511 0x44, 0x44, 0x88, 0x88, 0x11, 0x11, 0x22, 0x22
1515 0x08, 0x08, 0x08, 0x08, 0x14, 0x14, 0xe3, 0xe3, 0x80, 0x80, 0x80, 0x80,
1516 0x41, 0x41, 0x3e, 0x3e, 0x08, 0x08, 0x08, 0x08, 0x14, 0x14, 0xe3, 0xe3,
1517 0x80, 0x80, 0x80, 0x80, 0x41, 0x41, 0x3e, 0x3e
1521 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
1522 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
1523 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11
1527 0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfd, 0xff, 0xfd, 0xff, 0xfb, 0xff,
1528 0xe7, 0xff, 0x1f, 0xff, 0xff, 0xf8, 0xff, 0xe7, 0xff, 0xdf, 0xff, 0xbf,
1529 0xff, 0xbf, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f
1535static DisplayCommand
1536 XImageWindowCommand(Display *,XResourceInfo *,XWindows *,
1537 const MagickStatusType,KeySym,Image **);
1540 *XMagickCommand(Display *,XResourceInfo *,XWindows *,
const DisplayCommand,
1542 *XOpenImage(Display *,XResourceInfo *,XWindows *,
const MagickBooleanType),
1543 *XTileImage(Display *,XResourceInfo *,XWindows *,Image *,XEvent *),
1544 *XVisualDirectoryImage(Display *,XResourceInfo *,XWindows *);
1546static MagickBooleanType
1547 XAnnotateEditImage(Display *,XResourceInfo *,XWindows *,Image *),
1548 XDrawEditImage(Display *,XResourceInfo *,XWindows *,Image **),
1549 XChopImage(Display *,XResourceInfo *,XWindows *,Image **),
1550 XCropImage(Display *,XResourceInfo *,XWindows *,Image *,
const ClipboardMode),
1551 XBackgroundImage(Display *,XResourceInfo *,XWindows *,Image **),
1552 XColorEditImage(Display *,XResourceInfo *,XWindows *,Image **),
1553 XCompositeImage(Display *,XResourceInfo *,XWindows *,Image *),
1554 XConfigureImage(Display *,XResourceInfo *,XWindows *,Image *),
1555 XMatteEditImage(Display *,XResourceInfo *,XWindows *,Image **),
1556 XPasteImage(Display *,XResourceInfo *,XWindows *,Image *),
1557 XPrintImage(Display *,XResourceInfo *,XWindows *,Image *),
1558 XRotateImage(Display *,XResourceInfo *,XWindows *,
double,Image **),
1559 XROIImage(Display *,XResourceInfo *,XWindows *,Image **),
1560 XSaveImage(Display *,XResourceInfo *,XWindows *,Image *),
1561 XTrimImage(Display *,XResourceInfo *,XWindows *,Image *);
1564 XDrawPanRectangle(Display *,XWindows *),
1565 XImageCache(Display *,XResourceInfo *,XWindows *,
const DisplayCommand,Image **),
1566 XMagnifyImage(Display *,XWindows *,XEvent *),
1567 XMakePanImage(Display *,XResourceInfo *,XWindows *,Image *),
1568 XPanImage(Display *,XWindows *,XEvent *),
1569 XMagnifyWindowCommand(Display *,XWindows *,
const MagickStatusType,
1571 XSetCropGeometry(Display *,XWindows *,RectangleInfo *,Image *),
1572 XScreenEvent(Display *,XWindows *,XEvent *),
1573 XTranslateImage(Display *,XWindows *,Image *,
const KeySym);
1602MagickExport MagickBooleanType DisplayImages(
const ImageInfo *image_info,
1626 assert(image_info != (
const ImageInfo *) NULL);
1627 assert(image_info->signature == MagickCoreSignature);
1628 assert(images != (Image *) NULL);
1629 assert(images->signature == MagickCoreSignature);
1630 if (IsEventLogging() != MagickFalse)
1631 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",images->filename);
1632 display=XOpenDisplay(image_info->server_name);
1633 if (display == (Display *) NULL)
1635 (void) ThrowMagickException(&images->exception,GetMagickModule(),
1636 XServerError,
"UnableToOpenXServer",
"`%s'",XDisplayName(
1637 image_info->server_name));
1638 return(MagickFalse);
1640 if (images->exception.severity != UndefinedException)
1641 CatchException(&images->exception);
1642 (void) XSetErrorHandler(XError);
1643 resource_database=XGetResourceDatabase(display,GetClientName());
1644 (void) memset(&resource_info,0,
sizeof(resource_info));
1645 XGetResourceInfo(image_info,resource_database,GetClientName(),&resource_info);
1646 if (image_info->page != (
char *) NULL)
1647 resource_info.image_geometry=AcquireString(image_info->page);
1648 resource_info.immutable=MagickTrue;
1649 argv[0]=AcquireString(GetClientName());
1651 for (i=0; (state & ExitState) == 0; i++)
1653 if ((images->iterations != 0) && (i >= (ssize_t) images->iterations))
1655 image=GetImageFromList(images,i % GetImageListLength(images));
1656 (void) XDisplayImage(display,&resource_info,argv,1,&image,&state);
1658 (void) SetErrorHandler((ErrorHandler) NULL);
1659 (void) SetWarningHandler((WarningHandler) NULL);
1660 argv[0]=DestroyString(argv[0]);
1661 XDestroyResourceInfo(&resource_info);
1662 if (images->exception.severity != UndefinedException)
1663 return(MagickFalse);
1697MagickExport MagickBooleanType RemoteDisplayCommand(
const ImageInfo *image_info,
1698 const char *window,
const char *filename,ExceptionInfo *exception)
1706 assert(image_info != (
const ImageInfo *) NULL);
1707 assert(image_info->signature == MagickCoreSignature);
1708 assert(filename != (
char *) NULL);
1709 if (IsEventLogging() != MagickFalse)
1710 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",filename);
1711 display=XOpenDisplay(image_info->server_name);
1712 if (display == (Display *) NULL)
1714 (void) ThrowMagickException(exception,GetMagickModule(),XServerError,
1715 "UnableToOpenXServer",
"`%s'",XDisplayName(image_info->server_name));
1716 return(MagickFalse);
1718 (void) XSetErrorHandler(XError);
1719 status=XRemoteCommand(display,window,filename);
1720 (void) XCloseDisplay(display);
1721 return(status != 0 ? MagickTrue : MagickFalse);
1755static MagickBooleanType XAnnotateEditImage(Display *display,
1756 XResourceInfo *resource_info,XWindows *windows,Image *image)
1759 *
const AnnotateMenu[] =
1776 static const ModeType
1777 AnnotateCommands[] =
1779 AnnotateNameCommand,
1780 AnnotateFontColorCommand,
1781 AnnotateBackgroundColorCommand,
1782 AnnotateRotateCommand,
1783 AnnotateHelpCommand,
1784 AnnotateDismissCommand
1792 static MagickBooleanType
1793 transparent_box = MagickTrue,
1794 transparent_pen = MagickFalse;
1796 static MagickRealType
1800 box_id = MaxNumberPens-2,
1805 command[MaxTextExtent],
1807 text[MaxTextExtent];
1810 *ColorMenu[MaxNumberPens+1];
1855 (void) CloneString(&windows->command.name,
"Annotate");
1856 windows->command.data=4;
1857 (void) XCommandWidget(display,windows,AnnotateMenu,(XEvent *) NULL);
1858 (void) XMapRaised(display,windows->command.id);
1859 XClientMessage(display,windows->image.id,windows->im_protocols,
1860 windows->im_update_widget,CurrentTime);
1864 XQueryPosition(display,windows->image.id,&x,&y);
1865 (void) XSelectInput(display,windows->image.id,
1866 windows->image.attributes.event_mask | PointerMotionMask);
1867 cursor=XCreateFontCursor(display,XC_left_side);
1868 (void) XCheckDefineCursor(display,windows->image.id,cursor);
1872 if (windows->info.mapped != MagickFalse)
1877 (void) FormatLocaleString(text,MaxTextExtent,
" %+d%+d ",
1878 x+windows->image.x,y+windows->image.y);
1879 XInfoWidget(display,windows,text);
1884 XScreenEvent(display,windows,&event);
1885 if (event.xany.window == windows->command.id)
1890 id=XCommandWidget(display,windows,AnnotateMenu,&event);
1891 (void) XCheckDefineCursor(display,windows->image.id,cursor);
1894 switch (AnnotateCommands[
id])
1896 case AnnotateNameCommand:
1899 *FontMenu[MaxNumberFonts];
1907 for (i=0; i < MaxNumberFonts; i++)
1908 FontMenu[i]=resource_info->font_name[i];
1909 FontMenu[MaxNumberFonts-2]=
"Browser...";
1910 FontMenu[MaxNumberFonts-1]=(
const char *) NULL;
1914 font_number=XMenuWidget(display,windows,AnnotateMenu[
id],
1915 (
const char **) FontMenu,command);
1916 if (font_number < 0)
1918 if (font_number == (MaxNumberFonts-2))
1921 font_name[MaxTextExtent] =
"fixed";
1926 resource_info->font_name[font_number]=font_name;
1927 XFontBrowserWidget(display,windows,
"Select",font_name);
1928 if (*font_name ==
'\0')
1934 font_info=XLoadQueryFont(display,resource_info->font_name[
1936 if (font_info == (XFontStruct *) NULL)
1938 XNoticeWidget(display,windows,
"Unable to load font:",
1939 resource_info->font_name[font_number]);
1942 font_id=(
unsigned int) font_number;
1943 (void) XFreeFont(display,font_info);
1946 case AnnotateFontColorCommand:
1951 for (i=0; i < (int) (MaxNumberPens-2); i++)
1952 ColorMenu[i]=resource_info->pen_colors[i];
1953 ColorMenu[MaxNumberPens-2]=
"transparent";
1954 ColorMenu[MaxNumberPens-1]=
"Browser...";
1955 ColorMenu[MaxNumberPens]=(
const char *) NULL;
1959 pen_number=XMenuWidget(display,windows,AnnotateMenu[
id],
1960 (
const char **) ColorMenu,command);
1963 transparent_pen=pen_number == (MaxNumberPens-2) ? MagickTrue :
1965 if (transparent_pen != MagickFalse)
1967 if (pen_number == (MaxNumberPens-1))
1970 color_name[MaxTextExtent] =
"gray";
1975 resource_info->pen_colors[pen_number]=color_name;
1976 XColorBrowserWidget(display,windows,
"Select",color_name);
1977 if (*color_name ==
'\0')
1983 (void) XParseColor(display,windows->map_info->colormap,
1984 resource_info->pen_colors[pen_number],&color);
1985 XBestPixel(display,windows->map_info->colormap,(XColor *) NULL,
1986 (
unsigned int) MaxColors,&color);
1987 windows->pixel_info->pen_colors[pen_number]=color;
1988 pen_id=(
unsigned int) pen_number;
1991 case AnnotateBackgroundColorCommand:
1996 for (i=0; i < (int) (MaxNumberPens-2); i++)
1997 ColorMenu[i]=resource_info->pen_colors[i];
1998 ColorMenu[MaxNumberPens-2]=
"transparent";
1999 ColorMenu[MaxNumberPens-1]=
"Browser...";
2000 ColorMenu[MaxNumberPens]=(
const char *) NULL;
2004 pen_number=XMenuWidget(display,windows,AnnotateMenu[
id],
2005 (
const char **) ColorMenu,command);
2008 transparent_box=pen_number == (MaxNumberPens-2) ? MagickTrue :
2010 if (transparent_box != MagickFalse)
2012 if (pen_number == (MaxNumberPens-1))
2015 color_name[MaxTextExtent] =
"gray";
2020 resource_info->pen_colors[pen_number]=color_name;
2021 XColorBrowserWidget(display,windows,
"Select",color_name);
2022 if (*color_name ==
'\0')
2028 (void) XParseColor(display,windows->map_info->colormap,
2029 resource_info->pen_colors[pen_number],&color);
2030 XBestPixel(display,windows->map_info->colormap,(XColor *) NULL,
2031 (
unsigned int) MaxColors,&color);
2032 windows->pixel_info->pen_colors[pen_number]=color;
2033 box_id=(
unsigned int) pen_number;
2036 case AnnotateRotateCommand:
2042 *
const RotateMenu[] =
2057 angle[MaxTextExtent] =
"30.0";
2062 entry=XMenuWidget(display,windows,AnnotateMenu[
id],RotateMenu,
2068 degrees=StringToDouble(RotateMenu[entry],(
char **) NULL);
2071 (void) XDialogWidget(display,windows,
"OK",
"Enter rotation angle:",
2075 degrees=StringToDouble(angle,(
char **) NULL);
2078 case AnnotateHelpCommand:
2080 XTextViewHelp(display,resource_info,windows,MagickFalse,
2081 "Help Viewer - Image Annotation",ImageAnnotateHelp);
2084 case AnnotateDismissCommand:
2102 if (event.xbutton.button != Button1)
2104 if (event.xbutton.window != windows->image.id)
2120 if (event.xkey.window != windows->image.id)
2125 (void) XLookupString((XKeyEvent *) &event.xkey,command,(
int)
2126 sizeof(command),&key_symbol,(XComposeStatus *) NULL);
2127 switch ((
int) key_symbol)
2142 XTextViewHelp(display,resource_info,windows,MagickFalse,
2143 "Help Viewer - Image Annotation",ImageAnnotateHelp);
2148 (void) XBell(display,0);
2161 if (windows->info.mapped != MagickFalse)
2163 if ((x < (
int) (windows->info.x+windows->info.width)) &&
2164 (y < (
int) (windows->info.y+windows->info.height)))
2165 (void) XWithdrawWindow(display,windows->info.id,
2166 windows->info.screen);
2169 if ((x > (
int) (windows->info.x+windows->info.width)) ||
2170 (y > (
int) (windows->info.y+windows->info.height)))
2171 (void) XMapWindow(display,windows->info.id);
2177 }
while ((state & ExitState) == 0);
2178 (void) XSelectInput(display,windows->image.id,
2179 windows->image.attributes.event_mask);
2180 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
2181 if ((state & EscapeState) != 0)
2186 font_info=XLoadQueryFont(display,resource_info->font_name[font_id]);
2187 if (font_info == (XFontStruct *) NULL)
2189 XNoticeWidget(display,windows,
"Unable to load font:",
2190 resource_info->font_name[font_id]);
2191 font_info=windows->font_info;
2193 if ((x+font_info->max_bounds.width) >= (
int) windows->image.width)
2194 x=(int) windows->image.width-font_info->max_bounds.width;
2195 if (y < (
int) (font_info->ascent+font_info->descent))
2196 y=(int) font_info->ascent+font_info->descent;
2197 if (((
int) font_info->max_bounds.width > (
int) windows->image.width) ||
2198 ((font_info->ascent+font_info->descent) >= (
int) windows->image.height))
2199 return(MagickFalse);
2203 annotate_info=(XAnnotateInfo *) AcquireMagickMemory(
sizeof(*annotate_info));
2204 if (annotate_info == (XAnnotateInfo *) NULL)
2205 return(MagickFalse);
2206 XGetAnnotateInfo(annotate_info);
2209 if ((transparent_box == MagickFalse) && (transparent_pen == MagickFalse))
2210 annotate_info->stencil=OpaqueStencil;
2212 if (transparent_box == MagickFalse)
2213 annotate_info->stencil=BackgroundStencil;
2215 annotate_info->stencil=ForegroundStencil;
2216 annotate_info->height=(
unsigned int) font_info->ascent+font_info->descent;
2217 annotate_info->degrees=degrees;
2218 annotate_info->font_info=font_info;
2219 annotate_info->text=(
char *) AcquireQuantumMemory((
size_t)
2220 windows->image.width/MagickMax((ssize_t) font_info->min_bounds.width,1)+2UL,
2221 sizeof(*annotate_info->text));
2222 if (annotate_info->text == (
char *) NULL)
2223 return(MagickFalse);
2227 cursor=XCreateFontCursor(display,XC_pencil);
2228 (void) XCheckDefineCursor(display,windows->image.id,cursor);
2229 annotate_context=windows->image.annotate_context;
2230 (void) XSetFont(display,annotate_context,font_info->fid);
2231 (void) XSetBackground(display,annotate_context,
2232 windows->pixel_info->pen_colors[box_id].pixel);
2233 (void) XSetForeground(display,annotate_context,
2234 windows->pixel_info->pen_colors[pen_id].pixel);
2238 (void) CloneString(&windows->command.name,
"Text");
2239 windows->command.data=0;
2240 (void) XCommandWidget(display,windows,TextMenu,(XEvent *) NULL);
2242 (void) XDrawString(display,windows->image.id,annotate_context,x,y,
"_",1);
2243 text_event.xexpose.width=(int) font_info->max_bounds.width;
2244 text_event.xexpose.height=font_info->max_bounds.ascent+
2245 font_info->max_bounds.descent;
2246 p=annotate_info->text;
2253 (void) XDrawString(display,windows->image.id,annotate_context,x,y,
"_",1);
2257 XScreenEvent(display,windows,&event);
2258 if (event.xany.window == windows->command.id)
2263 (void) XSetBackground(display,annotate_context,
2264 windows->pixel_info->background_color.pixel);
2265 (void) XSetForeground(display,annotate_context,
2266 windows->pixel_info->foreground_color.pixel);
2267 id=XCommandWidget(display,windows,AnnotateMenu,&event);
2268 (void) XSetBackground(display,annotate_context,
2269 windows->pixel_info->pen_colors[box_id].pixel);
2270 (void) XSetForeground(display,annotate_context,
2271 windows->pixel_info->pen_colors[pen_id].pixel);
2274 switch (TextCommands[
id])
2276 case TextHelpCommand:
2278 XTextViewHelp(display,resource_info,windows,MagickFalse,
2279 "Help Viewer - Image Annotation",ImageAnnotateHelp);
2280 (void) XCheckDefineCursor(display,windows->image.id,cursor);
2283 case TextApplyCommand:
2288 annotate_info->width=(
unsigned int) XTextWidth(font_info,
2289 annotate_info->text,(
int) strlen(annotate_info->text));
2290 XRefreshWindow(display,&windows->image,&text_event);
2302 text_event.xexpose.x=x;
2303 text_event.xexpose.y=y-font_info->max_bounds.ascent;
2304 (void) XClearArea(display,windows->image.id,x,text_event.xexpose.y,
2305 (
unsigned int) text_event.xexpose.width,(
unsigned int)
2306 text_event.xexpose.height,MagickFalse);
2307 XRefreshWindow(display,&windows->image,&text_event);
2312 if (event.xbutton.window != windows->image.id)
2314 if (event.xbutton.button == Button2)
2319 (void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
2320 windows->image.id,CurrentTime);
2327 if (event.xexpose.count == 0)
2335 XRefreshWindow(display,&windows->image,(XEvent *) NULL);
2336 text_info=annotate_info;
2337 while (text_info != (XAnnotateInfo *) NULL)
2339 if (annotate_info->stencil == ForegroundStencil)
2340 (void) XDrawString(display,windows->image.id,annotate_context,
2341 text_info->x,text_info->y,text_info->text,
2342 (
int) strlen(text_info->text));
2344 (
void) XDrawImageString(display,windows->image.id,
2345 annotate_context,text_info->x,text_info->y,text_info->text,
2346 (
int) strlen(text_info->text));
2347 text_info=text_info->previous;
2349 (void) XDrawString(display,windows->image.id,annotate_context,
2359 if (event.xkey.window != windows->image.id)
2364 length=XLookupString((XKeyEvent *) &event.xkey,command,(
int)
2365 sizeof(command),&key_symbol,(XComposeStatus *) NULL);
2366 *(command+length)=
'\0';
2367 if (((event.xkey.state & ControlMask) != 0) ||
2368 ((event.xkey.state & Mod1Mask) != 0))
2369 state|=ModifierState;
2370 if ((state & ModifierState) != 0)
2371 switch ((
int) key_symbol)
2376 key_symbol=DeleteCommand;
2382 switch ((
int) key_symbol)
2389 if (p == annotate_info->text)
2391 if (annotate_info->previous == (XAnnotateInfo *) NULL)
2398 annotate_info=annotate_info->previous;
2399 p=annotate_info->text;
2400 x=annotate_info->x+annotate_info->width;
2402 if (annotate_info->width != 0)
2403 p+=(ptrdiff_t) strlen(annotate_info->text);
2408 x-=XTextWidth(font_info,p,1);
2409 text_event.xexpose.x=x;
2410 text_event.xexpose.y=y-font_info->max_bounds.ascent;
2411 XRefreshWindow(display,&windows->image,&text_event);
2414 case XK_bracketleft:
2416 key_symbol=XK_Escape;
2424 while (p != annotate_info->text)
2427 x-=XTextWidth(font_info,p,1);
2428 text_event.xexpose.x=x;
2429 XRefreshWindow(display,&windows->image,&text_event);
2439 annotate_info->width=(
unsigned int) XTextWidth(font_info,
2440 annotate_info->text,(
int) strlen(annotate_info->text));
2441 XRefreshWindow(display,&windows->image,&text_event);
2450 if ((state & ModifierState) != 0)
2452 if (*command ==
'\0')
2455 if (annotate_info->stencil == ForegroundStencil)
2456 (void) XDrawString(display,windows->image.id,annotate_context,
2459 (
void) XDrawImageString(display,windows->image.id,
2460 annotate_context,x,y,p,1);
2461 x+=XTextWidth(font_info,p,1);
2463 if ((x+font_info->max_bounds.width) < (
int) windows->image.width)
2474 annotate_info->width=(
unsigned int) XTextWidth(font_info,
2475 annotate_info->text,(
int) strlen(annotate_info->text));
2476 if (annotate_info->next != (XAnnotateInfo *) NULL)
2481 annotate_info=annotate_info->next;
2484 p=annotate_info->text;
2487 annotate_info->next=(XAnnotateInfo *) AcquireQuantumMemory(1,
2488 sizeof(*annotate_info->next));
2489 if (annotate_info->next == (XAnnotateInfo *) NULL)
2490 return(MagickFalse);
2491 *annotate_info->next=(*annotate_info);
2492 annotate_info->next->previous=annotate_info;
2493 annotate_info=annotate_info->next;
2494 annotate_info->text=(
char *) AcquireQuantumMemory((
size_t)
2495 windows->image.width/MagickMax((ssize_t)
2496 font_info->min_bounds.width,1)+2UL,
sizeof(*annotate_info->text));
2497 if (annotate_info->text == (
char *) NULL)
2498 return(MagickFalse);
2499 annotate_info->y+=annotate_info->height;
2500 if (annotate_info->y > (
int) windows->image.height)
2501 annotate_info->y=(int) annotate_info->height;
2502 annotate_info->next=(XAnnotateInfo *) NULL;
2505 p=annotate_info->text;
2516 (void) XLookupString((XKeyEvent *) &event.xkey,command,(
int)
2517 sizeof(command),&key_symbol,(XComposeStatus *) NULL);
2518 state&=(~ModifierState);
2521 case SelectionNotify:
2539 if (event.xselection.property == (Atom) None)
2541 status=XGetWindowProperty(display,event.xselection.requestor,
2542 event.xselection.property,0L,(
long) MaxTextExtent,True,XA_STRING,
2543 &type,&format,&length,&after,&data);
2544 if ((status != Success) || (type != XA_STRING) || (format == 32) ||
2550 for (i=0; i < (ssize_t) length; i++)
2552 if ((
char) data[i] !=
'\n')
2558 (void) XDrawString(display,windows->image.id,annotate_context,
2560 x+=XTextWidth(font_info,p,1);
2562 if ((x+font_info->max_bounds.width) < (
int) windows->image.width)
2569 annotate_info->width=(
unsigned int) XTextWidth(font_info,
2570 annotate_info->text,(
int) strlen(annotate_info->text));
2571 if (annotate_info->next != (XAnnotateInfo *) NULL)
2576 annotate_info=annotate_info->next;
2579 p=annotate_info->text;
2582 annotate_info->next=(XAnnotateInfo *) AcquireQuantumMemory(1,
2583 sizeof(*annotate_info->next));
2584 if (annotate_info->next == (XAnnotateInfo *) NULL)
2585 return(MagickFalse);
2586 *annotate_info->next=(*annotate_info);
2587 annotate_info->next->previous=annotate_info;
2588 annotate_info=annotate_info->next;
2589 annotate_info->text=(
char *) AcquireQuantumMemory((
size_t)
2590 windows->image.width/MagickMax((ssize_t)
2591 font_info->min_bounds.width,1)+2UL,
sizeof(*annotate_info->text));
2592 if (annotate_info->text == (
char *) NULL)
2593 return(MagickFalse);
2594 annotate_info->y+=annotate_info->height;
2595 if (annotate_info->y > (
int) windows->image.height)
2596 annotate_info->y=(int) annotate_info->height;
2597 annotate_info->next=(XAnnotateInfo *) NULL;
2600 p=annotate_info->text;
2602 (void) XFree((
void *) data);
2608 }
while ((state & ExitState) == 0);
2609 (void) XFreeCursor(display,cursor);
2613 width=(
unsigned int) image->columns;
2614 height=(
unsigned int) image->rows;
2617 if (windows->image.crop_geometry != (
char *) NULL)
2618 (void) XParseGeometry(windows->image.crop_geometry,&x,&y,&width,&height);
2622 XSetCursorState(display,windows,MagickTrue);
2623 XCheckRefreshWindows(display,windows);
2624 while (annotate_info != (XAnnotateInfo *) NULL)
2626 if (annotate_info->width == 0)
2631 previous_info=annotate_info->previous;
2632 annotate_info->text=(
char *)
2633 RelinquishMagickMemory(annotate_info->text);
2634 annotate_info=(XAnnotateInfo *) RelinquishMagickMemory(annotate_info);
2635 annotate_info=previous_info;
2641 windows->pixel_info->box_color=windows->pixel_info->pen_colors[box_id];
2642 if (windows->pixel_info->colors != 0)
2643 for (i=0; i < (ssize_t) windows->pixel_info->colors; i++)
2644 if (windows->pixel_info->pixels[i] ==
2645 windows->pixel_info->pen_colors[box_id].pixel)
2647 windows->pixel_info->box_index=(
unsigned short) i;
2650 windows->pixel_info->pen_color=windows->pixel_info->pen_colors[pen_id];
2651 if (windows->pixel_info->colors != 0)
2652 for (i=0; i < (ssize_t) windows->pixel_info->colors; i++)
2653 if (windows->pixel_info->pixels[i] ==
2654 windows->pixel_info->pen_colors[pen_id].pixel)
2656 windows->pixel_info->pen_index=(
unsigned short) i;
2662 annotate_info->x=(int)
2663 width*(annotate_info->x+windows->image.x)/windows->image.ximage->width;
2664 annotate_info->y=(int) height*(annotate_info->y-font_info->ascent+
2665 windows->image.y)/windows->image.ximage->height;
2666 (void) FormatLocaleString(annotate_info->geometry,MaxTextExtent,
2667 "%ux%u%+d%+d",width*annotate_info->width/windows->image.ximage->width,
2668 height*annotate_info->height/windows->image.ximage->height,
2669 annotate_info->x+x,annotate_info->y+y);
2673 status=XAnnotateImage(display,windows->pixel_info,annotate_info,image);
2675 return(MagickFalse);
2679 previous_info=annotate_info->previous;
2680 annotate_info->text=DestroyString(annotate_info->text);
2681 annotate_info=(XAnnotateInfo *) RelinquishMagickMemory(annotate_info);
2682 annotate_info=previous_info;
2684 (void) XSetForeground(display,annotate_context,
2685 windows->pixel_info->foreground_color.pixel);
2686 (void) XSetBackground(display,annotate_context,
2687 windows->pixel_info->background_color.pixel);
2688 (void) XSetFont(display,annotate_context,windows->font_info->fid);
2689 XSetCursorState(display,windows,MagickFalse);
2690 (void) XFreeFont(display,font_info);
2694 XConfigureImageColormap(display,resource_info,windows,image);
2695 (void) XConfigureImage(display,resource_info,windows,image);
2729static MagickBooleanType XBackgroundImage(Display *display,
2730 XResourceInfo *resource_info,XWindows *windows,Image **image)
2732#define BackgroundImageTag "Background/Image"
2738 window_id[MaxTextExtent] =
"root";
2741 background_resources;
2746 status=XDialogWidget(display,windows,
"Background",
2747 "Enter window id (id 0x00 selects window with pointer):",window_id);
2748 if (*window_id ==
'\0')
2749 return(MagickFalse);
2750 (void) XMagickCommand(display,resource_info,windows,ApplyCommand,image);
2751 XInfoWidget(display,windows,BackgroundImageTag);
2752 XSetCursorState(display,windows,MagickTrue);
2753 XCheckRefreshWindows(display,windows);
2754 background_resources=(*resource_info);
2755 background_resources.window_id=window_id;
2756 background_resources.backdrop=status != 0 ? MagickTrue : MagickFalse;
2757 status=XDisplayBackgroundImage(display,&background_resources,*image);
2758 if (status != MagickFalse)
2759 XClientMessage(display,windows->image.id,windows->im_protocols,
2760 windows->im_retain_colors,CurrentTime);
2761 XSetCursorState(display,windows,MagickFalse);
2762 (void) XMagickCommand(display,resource_info,windows,UndoCommand,image);
2796static MagickBooleanType XChopImage(Display *display,
2797 XResourceInfo *resource_info,XWindows *windows,Image **image)
2809 direction = HorizontalChopCommand;
2811 static const ModeType
2814 ChopDirectionCommand,
2818 DirectionCommands[] =
2820 HorizontalChopCommand,
2825 text[MaxTextExtent];
2858 (void) CloneString(&windows->command.name,
"Chop");
2859 windows->command.data=1;
2860 (void) XCommandWidget(display,windows,ChopMenu,(XEvent *) NULL);
2861 (void) XMapRaised(display,windows->command.id);
2862 XClientMessage(display,windows->image.id,windows->im_protocols,
2863 windows->im_update_widget,CurrentTime);
2867 XQueryPosition(display,windows->image.id,&x,&y);
2868 (void) XSelectInput(display,windows->image.id,
2869 windows->image.attributes.event_mask | PointerMotionMask);
2871 (void) memset(&segment_info,0,
sizeof(segment_info));
2874 if (windows->info.mapped != MagickFalse)
2879 (void) FormatLocaleString(text,MaxTextExtent,
" %+d%+d ",
2880 x+windows->image.x,y+windows->image.y);
2881 XInfoWidget(display,windows,text);
2886 XScreenEvent(display,windows,&event);
2887 if (event.xany.window == windows->command.id)
2892 id=XCommandWidget(display,windows,ChopMenu,&event);
2895 switch (ChopCommands[
id])
2897 case ChopDirectionCommand:
2900 command[MaxTextExtent];
2903 *
const Directions[] =
2913 id=XMenuWidget(display,windows,ChopMenu[
id],Directions,command);
2915 direction=DirectionCommands[id];
2918 case ChopHelpCommand:
2920 XTextViewHelp(display,resource_info,windows,MagickFalse,
2921 "Help Viewer - Image Chop",ImageChopHelp);
2924 case ChopDismissCommand:
2942 if (event.xbutton.button != Button1)
2944 if (event.xbutton.window != windows->image.id)
2949 segment_info.x1=(
short int) event.xbutton.x;
2950 segment_info.x2=(
short int) event.xbutton.x;
2951 segment_info.y1=(
short int) event.xbutton.y;
2952 segment_info.y2=(
short int) event.xbutton.y;
2963 command[MaxTextExtent];
2968 if (event.xkey.window != windows->image.id)
2973 (void) XLookupString((XKeyEvent *) &event.xkey,command,(
int)
2974 sizeof(command),&key_symbol,(XComposeStatus *) NULL);
2975 switch ((
int) key_symbol)
2990 (void) XSetFunction(display,windows->image.highlight_context,
2992 XTextViewHelp(display,resource_info,windows,MagickFalse,
2993 "Help Viewer - Image Chop",ImageChopHelp);
2994 (void) XSetFunction(display,windows->image.highlight_context,
3000 (void) XBell(display,0);
3013 if (windows->info.mapped != MagickFalse)
3015 if ((x < (
int) (windows->info.x+windows->info.width)) &&
3016 (y < (
int) (windows->info.y+windows->info.height)))
3017 (void) XWithdrawWindow(display,windows->info.id,
3018 windows->info.screen);
3021 if ((x > (
int) (windows->info.x+windows->info.width)) ||
3022 (y > (
int) (windows->info.y+windows->info.height)))
3023 (void) XMapWindow(display,windows->info.id);
3026 }
while ((state & ExitState) == 0);
3027 (void) XSelectInput(display,windows->image.id,
3028 windows->image.attributes.event_mask);
3029 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
3030 if ((state & EscapeState) != 0)
3040 (void) XSetFunction(display,windows->image.highlight_context,GXinvert);
3049 if (windows->info.mapped == MagickFalse)
3050 (void) XMapWindow(display,windows->info.id);
3051 (void) FormatLocaleString(text,MaxTextExtent,
3052 " %.20gx%.20g%+.20g%+.20g",(
double) chop_info.width,(
double)
3053 chop_info.height,(
double) chop_info.x,(
double) chop_info.y);
3054 XInfoWidget(display,windows,text);
3055 XHighlightLine(display,windows->image.id,
3056 windows->image.highlight_context,&segment_info);
3059 if (windows->info.mapped != MagickFalse)
3060 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
3064 XScreenEvent(display,windows,&event);
3066 XHighlightLine(display,windows->image.id,
3067 windows->image.highlight_context,&segment_info);
3072 segment_info.x2=(
short int) event.xmotion.x;
3073 segment_info.y2=(
short int) event.xmotion.y;
3081 segment_info.x2=(
short int) event.xbutton.x;
3082 segment_info.y2=(
short int) event.xbutton.y;
3090 segment_info.x2=(
short int) event.xmotion.x;
3091 segment_info.y2=(
short int) event.xmotion.y;
3099 if (segment_info.x2 < 0)
3102 if (segment_info.x2 > windows->image.ximage->width)
3103 segment_info.x2=windows->image.ximage->width;
3104 if (segment_info.y2 < 0)
3107 if (segment_info.y2 > windows->image.ximage->height)
3108 segment_info.y2=windows->image.ximage->height;
3109 distance=(
unsigned int)
3110 (((segment_info.x2-segment_info.x1)*(segment_info.x2-segment_info.x1))+
3111 ((segment_info.y2-segment_info.y1)*(segment_info.y2-segment_info.y1)));
3115 if (direction == HorizontalChopCommand)
3117 chop_info.width=(size_t) (segment_info.x2-segment_info.x1+1);
3118 chop_info.x=(ssize_t) windows->image.x+segment_info.x1;
3121 if (segment_info.x1 > (
int) segment_info.x2)
3123 chop_info.width=(size_t) (segment_info.x1-segment_info.x2+1);
3124 chop_info.x=(ssize_t) windows->image.x+segment_info.x2;
3130 chop_info.height=(size_t) (segment_info.y2-segment_info.y1+1);
3132 chop_info.y=(ssize_t) windows->image.y+segment_info.y1;
3133 if (segment_info.y1 > segment_info.y2)
3135 chop_info.height=(size_t) (segment_info.y1-segment_info.y2+1);
3136 chop_info.y=(ssize_t) windows->image.y+segment_info.y2;
3139 }
while ((state & ExitState) == 0);
3140 (void) XSetFunction(display,windows->image.highlight_context,GXcopy);
3141 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
3147 (void) XMagickCommand(display,resource_info,windows,ApplyCommand,image);
3148 XSetCursorState(display,windows,MagickTrue);
3149 XCheckRefreshWindows(display,windows);
3150 windows->image.window_changes.width=windows->image.ximage->width-
3151 (
unsigned int) chop_info.width;
3152 windows->image.window_changes.height=windows->image.ximage->height-
3153 (
unsigned int) chop_info.height;
3154 width=(
unsigned int) (*image)->columns;
3155 height=(
unsigned int) (*image)->rows;
3158 if (windows->image.crop_geometry != (
char *) NULL)
3159 (void) XParseGeometry(windows->image.crop_geometry,&x,&y,&width,&height);
3160 scale_factor=(MagickRealType) width/windows->image.ximage->width;
3162 chop_info.x=(ssize_t) (scale_factor*chop_info.x+0.5);
3163 chop_info.width=(
unsigned int) (scale_factor*chop_info.width+0.5);
3164 scale_factor=(MagickRealType) height/windows->image.ximage->height;
3166 chop_info.y=(ssize_t) (scale_factor*chop_info.y+0.5);
3167 chop_info.height=(
unsigned int) (scale_factor*chop_info.height+0.5);
3171 chop_image=ChopImage(*image,&chop_info,&(*image)->exception);
3172 XSetCursorState(display,windows,MagickFalse);
3173 if (chop_image == (Image *) NULL)
3174 return(MagickFalse);
3175 *image=DestroyImage(*image);
3180 XConfigureImageColormap(display,resource_info,windows,*image);
3181 (void) XConfigureImage(display,resource_info,windows,*image);
3218static MagickBooleanType XColorEditImage(Display *display,
3219 XResourceInfo *resource_info,XWindows *windows,Image **image)
3222 *
const ColorEditMenu[] =
3234 static const ModeType
3235 ColorEditCommands[] =
3237 ColorEditMethodCommand,
3238 ColorEditColorCommand,
3239 ColorEditBorderCommand,
3240 ColorEditFuzzCommand,
3241 ColorEditUndoCommand,
3242 ColorEditHelpCommand,
3243 ColorEditDismissCommand
3247 method = PointMethod;
3253 border_color = { 0, 0, 0, 0, 0, 0 };
3256 command[MaxTextExtent] =
"",
3257 text[MaxTextExtent] =
"";
3295 (void) CloneString(&windows->command.name,
"Color Edit");
3296 windows->command.data=4;
3297 (void) XCommandWidget(display,windows,ColorEditMenu,(XEvent *) NULL);
3298 (void) XMapRaised(display,windows->command.id);
3299 XClientMessage(display,windows->image.id,windows->im_protocols,
3300 windows->im_update_widget,CurrentTime);
3304 cursor=XMakeCursor(display,windows->image.id,windows->map_info->colormap,
3305 resource_info->background_color,resource_info->foreground_color);
3306 (void) XCheckDefineCursor(display,windows->image.id,cursor);
3310 XQueryPosition(display,windows->image.id,&x,&y);
3311 (void) XSelectInput(display,windows->image.id,
3312 windows->image.attributes.event_mask | PointerMotionMask);
3316 if (windows->info.mapped != MagickFalse)
3321 (void) FormatLocaleString(text,MaxTextExtent,
" %+d%+d ",
3322 x+windows->image.x,y+windows->image.y);
3323 XInfoWidget(display,windows,text);
3328 XScreenEvent(display,windows,&event);
3329 if (event.xany.window == windows->command.id)
3334 id=XCommandWidget(display,windows,ColorEditMenu,&event);
3337 (void) XCheckDefineCursor(display,windows->image.id,cursor);
3340 switch (ColorEditCommands[
id])
3342 case ColorEditMethodCommand:
3350 methods=(
char **) GetCommandOptions(MagickMethodOptions);
3351 if (methods == (
char **) NULL)
3353 entry=XMenuWidget(display,windows,ColorEditMenu[
id],
3354 (
const char **) methods,command);
3356 method=(PaintMethod) ParseCommandOption(MagickMethodOptions,
3357 MagickFalse,methods[entry]);
3358 methods=DestroyStringList(methods);
3361 case ColorEditColorCommand:
3364 *ColorMenu[MaxNumberPens];
3372 for (i=0; i < (int) (MaxNumberPens-2); i++)
3373 ColorMenu[i]=resource_info->pen_colors[i];
3374 ColorMenu[MaxNumberPens-2]=
"Browser...";
3375 ColorMenu[MaxNumberPens-1]=(
const char *) NULL;
3379 pen_number=XMenuWidget(display,windows,ColorEditMenu[
id],
3380 (
const char **) ColorMenu,command);
3383 if (pen_number == (MaxNumberPens-2))
3386 color_name[MaxTextExtent] =
"gray";
3391 resource_info->pen_colors[pen_number]=color_name;
3392 XColorBrowserWidget(display,windows,
"Select",color_name);
3393 if (*color_name ==
'\0')
3399 (void) XParseColor(display,windows->map_info->colormap,
3400 resource_info->pen_colors[pen_number],&color);
3401 XBestPixel(display,windows->map_info->colormap,(XColor *) NULL,
3402 (
unsigned int) MaxColors,&color);
3403 windows->pixel_info->pen_colors[pen_number]=color;
3404 pen_id=(
unsigned int) pen_number;
3407 case ColorEditBorderCommand:
3410 *ColorMenu[MaxNumberPens];
3418 for (i=0; i < (int) (MaxNumberPens-2); i++)
3419 ColorMenu[i]=resource_info->pen_colors[i];
3420 ColorMenu[MaxNumberPens-2]=
"Browser...";
3421 ColorMenu[MaxNumberPens-1]=(
const char *) NULL;
3425 pen_number=XMenuWidget(display,windows,ColorEditMenu[
id],
3426 (
const char **) ColorMenu,command);
3429 if (pen_number == (MaxNumberPens-2))
3432 color_name[MaxTextExtent] =
"gray";
3437 resource_info->pen_colors[pen_number]=color_name;
3438 XColorBrowserWidget(display,windows,
"Select",color_name);
3439 if (*color_name ==
'\0')
3445 (void) XParseColor(display,windows->map_info->colormap,
3446 resource_info->pen_colors[pen_number],&border_color);
3449 case ColorEditFuzzCommand:
3452 fuzz[MaxTextExtent];
3469 entry=XMenuWidget(display,windows,ColorEditMenu[
id],FuzzMenu,
3475 (*image)->fuzz=StringToDoubleInterval(FuzzMenu[entry],(
double)
3479 (void) (
void) CopyMagickString(fuzz,
"20%",MaxTextExtent);
3480 (void) XDialogWidget(display,windows,
"Ok",
3481 "Enter fuzz factor (0.0 - 99.9%):",fuzz);
3484 (void) ConcatenateMagickString(fuzz,
"%",MaxTextExtent);
3485 (*image)->fuzz=StringToDoubleInterval(fuzz,(
double) QuantumRange+
3489 case ColorEditUndoCommand:
3491 (void) XMagickCommand(display,resource_info,windows,UndoCommand,
3495 case ColorEditHelpCommand:
3498 XTextViewHelp(display,resource_info,windows,MagickFalse,
3499 "Help Viewer - Image Annotation",ImageColorEditHelp);
3502 case ColorEditDismissCommand:
3512 (void) XCheckDefineCursor(display,windows->image.id,cursor);
3519 if (event.xbutton.button != Button1)
3521 if ((event.xbutton.window != windows->image.id) &&
3522 (event.xbutton.window != windows->magnify.id))
3529 (void) XMagickCommand(display,resource_info,windows,
3530 SaveToUndoBufferCommand,image);
3531 state|=UpdateConfigurationState;
3536 if (event.xbutton.button != Button1)
3538 if ((event.xbutton.window != windows->image.id) &&
3539 (event.xbutton.window != windows->magnify.id))
3546 XConfigureImageColormap(display,resource_info,windows,*image);
3547 (void) XConfigureImage(display,resource_info,windows,*image);
3548 XInfoWidget(display,windows,text);
3549 (void) XCheckDefineCursor(display,windows->image.id,cursor);
3550 state&=(~UpdateConfigurationState);
3560 if (event.xkey.window == windows->magnify.id)
3565 window=windows->magnify.id;
3566 while (XCheckWindowEvent(display,window,KeyPressMask,&event)) ;
3568 if (event.xkey.window != windows->image.id)
3573 (void) XLookupString((XKeyEvent *) &event.xkey,command,(
int)
3574 sizeof(command),&key_symbol,(XComposeStatus *) NULL);
3575 switch ((
int) key_symbol)
3589 XTextViewHelp(display,resource_info,windows,MagickFalse,
3590 "Help Viewer - Image Annotation",ImageColorEditHelp);
3595 (void) XBell(display,0);
3608 if (windows->info.mapped != MagickFalse)
3610 if ((x < (
int) (windows->info.x+windows->info.width)) &&
3611 (y < (
int) (windows->info.y+windows->info.height)))
3612 (void) XWithdrawWindow(display,windows->info.id,
3613 windows->info.screen);
3616 if ((x > (
int) (windows->info.x+windows->info.width)) ||
3617 (y > (
int) (windows->info.y+windows->info.height)))
3618 (void) XMapWindow(display,windows->info.id);
3624 if (event.xany.window == windows->magnify.id)
3626 x=windows->magnify.x-windows->image.x;
3627 y=windows->magnify.y-windows->image.y;
3631 if ((state & UpdateConfigurationState) != 0)
3643 (void) XClearArea(display,windows->image.id,x_offset,y_offset,1,1,
3645 color=windows->pixel_info->pen_colors[pen_id];
3646 XPutPixel(windows->image.ximage,x_offset,y_offset,color.pixel);
3647 width=(
unsigned int) (*image)->columns;
3648 height=(
unsigned int) (*image)->rows;
3651 if (windows->image.crop_geometry != (
char *) NULL)
3652 (void) XParseGeometry(windows->image.crop_geometry,&x,&y,
3655 (width*(windows->image.x+x_offset)/windows->image.ximage->width+x);
3657 (height*(windows->image.y+y_offset)/windows->image.ximage->height+y);
3658 if ((x_offset < 0) || (y_offset < 0))
3660 if ((x_offset >= (
int) (*image)->columns) ||
3661 (y_offset >= (
int) (*image)->rows))
3663 exception=(&(*image)->exception);
3664 image_view=AcquireAuthenticCacheView(*image,exception);
3673 if (SetImageStorageClass(*image,DirectClass) == MagickFalse)
3674 return(MagickFalse);
3675 q=GetCacheViewAuthenticPixels(image_view,(ssize_t)x_offset,
3676 (ssize_t)y_offset,1,1,exception);
3677 if (q == (PixelPacket *) NULL)
3679 q->red=ScaleShortToQuantum(color.red);
3680 q->green=ScaleShortToQuantum(color.green);
3681 q->blue=ScaleShortToQuantum(color.blue);
3682 (void) SyncCacheViewAuthenticPixels(image_view,
3683 &(*image)->exception);
3694 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t) x_offset,
3695 (ssize_t) y_offset,&target,&(*image)->exception);
3696 if ((*image)->storage_class == DirectClass)
3698 for (y=0; y < (int) (*image)->rows; y++)
3700 q=GetCacheViewAuthenticPixels(image_view,0,(ssize_t) y,
3701 (*image)->columns,1,exception);
3702 if (q == (PixelPacket *) NULL)
3704 for (x=0; x < (int) (*image)->columns; x++)
3706 if (IsColorSimilar(*image,q,&target) != MagickFalse)
3708 q->red=ScaleShortToQuantum(color.red);
3709 q->green=ScaleShortToQuantum(color.green);
3710 q->blue=ScaleShortToQuantum(color.blue);
3714 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3720 for (i=0; i < (ssize_t) (*image)->colors; i++)
3721 if (IsColorSimilar(*image,(*image)->colormap+i,&target) != MagickFalse)
3723 (*image)->colormap[i].red=ScaleShortToQuantum(color.red);
3724 (*image)->colormap[i].green=ScaleShortToQuantum(
3726 (*image)->colormap[i].blue=ScaleShortToQuantum(
3729 (void) SyncImage(*image);
3733 case FloodfillMethod:
3734 case FillToBorderMethod:
3745 (void) GetOneVirtualMagickPixel(*image,(ssize_t) x_offset,
3746 (ssize_t) y_offset,&target,exception);
3747 if (method == FillToBorderMethod)
3749 target.red=(MagickRealType)
3750 ScaleShortToQuantum(border_color.red);
3751 target.green=(MagickRealType)
3752 ScaleShortToQuantum(border_color.green);
3753 target.blue=(MagickRealType)
3754 ScaleShortToQuantum(border_color.blue);
3756 draw_info=CloneDrawInfo(resource_info->image_info,
3758 (void) QueryColorDatabase(resource_info->pen_colors[pen_id],
3759 &draw_info->fill,exception);
3760 (void) FloodfillPaintImage(*image,DefaultChannels,draw_info,&target,
3761 (ssize_t) x_offset,(ssize_t) y_offset,
3762 method == FloodfillMethod ? MagickFalse : MagickTrue);
3763 draw_info=DestroyDrawInfo(draw_info);
3771 if (SetImageStorageClass(*image,DirectClass) == MagickFalse)
3772 return(MagickFalse);
3773 for (y=0; y < (int) (*image)->rows; y++)
3775 q=QueueCacheViewAuthenticPixels(image_view,0,(ssize_t) y,
3776 (*image)->columns,1,exception);
3777 if (q == (PixelPacket *) NULL)
3779 for (x=0; x < (int) (*image)->columns; x++)
3781 q->red=ScaleShortToQuantum(color.red);
3782 q->green=ScaleShortToQuantum(color.green);
3783 q->blue=ScaleShortToQuantum(color.blue);
3786 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
3792 image_view=DestroyCacheView(image_view);
3793 state&=(~UpdateConfigurationState);
3795 }
while ((state & ExitState) == 0);
3796 (void) XSelectInput(display,windows->image.id,
3797 windows->image.attributes.event_mask);
3798 XSetCursorState(display,windows,MagickFalse);
3799 (void) XFreeCursor(display,cursor);
3835static MagickBooleanType XCompositeImage(Display *display,
3836 XResourceInfo *resource_info,XWindows *windows,Image *image)
3839 *
const CompositeMenu[] =
3850 displacement_geometry[MaxTextExtent] =
"30x30",
3851 filename[MaxTextExtent] =
"\0";
3853 static CompositeOperator
3854 compose = CopyCompositeOp;
3856 static const ModeType
3857 CompositeCommands[] =
3859 CompositeOperatorsCommand,
3860 CompositeDissolveCommand,
3861 CompositeDisplaceCommand,
3862 CompositeHelpCommand,
3863 CompositeDismissCommand
3867 text[MaxTextExtent];
3902 XFileBrowserWidget(display,windows,
"Composite",filename);
3903 if (*filename ==
'\0')
3908 XSetCursorState(display,windows,MagickTrue);
3909 XCheckRefreshWindows(display,windows);
3910 (void) CopyMagickString(resource_info->image_info->filename,filename,
3912 composite_image=ReadImage(resource_info->image_info,&image->exception);
3913 CatchException(&image->exception);
3914 XSetCursorState(display,windows,MagickFalse);
3915 if (composite_image == (Image *) NULL)
3916 return(MagickFalse);
3920 (void) CloneString(&windows->command.name,
"Composite");
3921 windows->command.data=1;
3922 (void) XCommandWidget(display,windows,CompositeMenu,(XEvent *) NULL);
3923 (void) XMapRaised(display,windows->command.id);
3924 XClientMessage(display,windows->image.id,windows->im_protocols,
3925 windows->im_update_widget,CurrentTime);
3929 XQueryPosition(display,windows->image.id,&x,&y);
3930 (void) XSelectInput(display,windows->image.id,
3931 windows->image.attributes.event_mask | PointerMotionMask);
3932 composite_info.x=(ssize_t) windows->image.x+x;
3933 composite_info.y=(ssize_t) windows->image.y+y;
3934 composite_info.width=0;
3935 composite_info.height=0;
3936 cursor=XCreateFontCursor(display,XC_ul_angle);
3937 (void) XSetFunction(display,windows->image.highlight_context,GXinvert);
3942 if (windows->info.mapped != MagickFalse)
3947 (void) FormatLocaleString(text,MaxTextExtent,
" %+ld%+ld ",
3948 (
long) composite_info.x,(
long) composite_info.y);
3949 XInfoWidget(display,windows,text);
3951 highlight_info=composite_info;
3952 highlight_info.x=composite_info.x-windows->image.x;
3953 highlight_info.y=composite_info.y-windows->image.y;
3954 XHighlightRectangle(display,windows->image.id,
3955 windows->image.highlight_context,&highlight_info);
3959 XScreenEvent(display,windows,&event);
3960 XHighlightRectangle(display,windows->image.id,
3961 windows->image.highlight_context,&highlight_info);
3962 if (event.xany.window == windows->command.id)
3967 id=XCommandWidget(display,windows,CompositeMenu,&event);
3970 switch (CompositeCommands[
id])
3972 case CompositeOperatorsCommand:
3975 command[MaxTextExtent],
3981 operators=GetCommandOptions(MagickComposeOptions);
3982 if (operators == (
char **) NULL)
3984 entry=XMenuWidget(display,windows,CompositeMenu[
id],
3985 (
const char **) operators,command);
3987 compose=(CompositeOperator) ParseCommandOption(
3988 MagickComposeOptions,MagickFalse,operators[entry]);
3989 operators=DestroyStringList(operators);
3992 case CompositeDissolveCommand:
3995 factor[MaxTextExtent] =
"20.0";
4000 (void) XSetFunction(display,windows->image.highlight_context,
4002 (void) XDialogWidget(display,windows,
"Dissolve",
4003 "Enter the blend factor (0.0 - 99.9%):",factor);
4004 (void) XSetFunction(display,windows->image.highlight_context,
4006 if (*factor ==
'\0')
4008 blend=StringToDouble(factor,(
char **) NULL);
4009 compose=DissolveCompositeOp;
4012 case CompositeDisplaceCommand:
4017 (void) XSetFunction(display,windows->image.highlight_context,
4019 (void) XDialogWidget(display,windows,
"Displace",
4020 "Enter the horizontal and vertical scale:",displacement_geometry);
4021 (void) XSetFunction(display,windows->image.highlight_context,
4023 if (*displacement_geometry ==
'\0')
4025 compose=DisplaceCompositeOp;
4028 case CompositeHelpCommand:
4030 (void) XSetFunction(display,windows->image.highlight_context,
4032 XTextViewHelp(display,resource_info,windows,MagickFalse,
4033 "Help Viewer - Image Composite",ImageCompositeHelp);
4034 (void) XSetFunction(display,windows->image.highlight_context,
4038 case CompositeDismissCommand:
4056 if (resource_info->debug != MagickFalse)
4057 (void) LogMagickEvent(X11Event,GetMagickModule(),
4058 "Button Press: 0x%lx %u +%d+%d",event.xbutton.window,
4059 event.xbutton.button,event.xbutton.x,event.xbutton.y);
4060 if (event.xbutton.button != Button1)
4062 if (event.xbutton.window != windows->image.id)
4067 composite_info.width=composite_image->columns;
4068 composite_info.height=composite_image->rows;
4069 (void) XCheckDefineCursor(display,windows->image.id,cursor);
4070 composite_info.x=(ssize_t) windows->image.x+event.xbutton.x;
4071 composite_info.y=(ssize_t) windows->image.y+event.xbutton.y;
4076 if (resource_info->debug != MagickFalse)
4077 (void) LogMagickEvent(X11Event,GetMagickModule(),
4078 "Button Release: 0x%lx %u +%d+%d",event.xbutton.window,
4079 event.xbutton.button,event.xbutton.x,event.xbutton.y);
4080 if (event.xbutton.button != Button1)
4082 if (event.xbutton.window != windows->image.id)
4084 if ((composite_info.width != 0) && (composite_info.height != 0))
4089 composite_info.x=(ssize_t) windows->image.x+event.xbutton.x;
4090 composite_info.y=(ssize_t) windows->image.y+event.xbutton.y;
4100 command[MaxTextExtent];
4108 if (event.xkey.window != windows->image.id)
4113 length=XLookupString((XKeyEvent *) &event.xkey,command,(
int)
4114 sizeof(command),&key_symbol,(XComposeStatus *) NULL);
4115 *(command+length)=
'\0';
4116 if (resource_info->debug != MagickFalse)
4117 (void) LogMagickEvent(X11Event,GetMagickModule(),
4118 "Key press: 0x%lx (%s)",(
unsigned long) key_symbol,command);
4119 switch ((
int) key_symbol)
4127 composite_image=DestroyImage(composite_image);
4135 (void) XSetFunction(display,windows->image.highlight_context,
4137 XTextViewHelp(display,resource_info,windows,MagickFalse,
4138 "Help Viewer - Image Composite",ImageCompositeHelp);
4139 (void) XSetFunction(display,windows->image.highlight_context,
4145 (void) XBell(display,0);
4158 if (windows->info.mapped != MagickFalse)
4160 if ((x < (
int) (windows->info.x+windows->info.width)) &&
4161 (y < (
int) (windows->info.y+windows->info.height)))
4162 (void) XWithdrawWindow(display,windows->info.id,
4163 windows->info.screen);
4166 if ((x > (
int) (windows->info.x+windows->info.width)) ||
4167 (y > (
int) (windows->info.y+windows->info.height)))
4168 (void) XMapWindow(display,windows->info.id);
4169 composite_info.x=(ssize_t) windows->image.x+x;
4170 composite_info.y=(ssize_t) windows->image.y+y;
4175 if (resource_info->debug != MagickFalse)
4176 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Event type: %d",
4181 }
while ((state & ExitState) == 0);
4182 (void) XSelectInput(display,windows->image.id,
4183 windows->image.attributes.event_mask);
4184 (void) XSetFunction(display,windows->image.highlight_context,GXcopy);
4185 XSetCursorState(display,windows,MagickFalse);
4186 (void) XFreeCursor(display,cursor);
4187 if ((state & EscapeState) != 0)
4192 XSetCursorState(display,windows,MagickTrue);
4193 XCheckRefreshWindows(display,windows);
4194 width=(
unsigned int) image->columns;
4195 height=(
unsigned int) image->rows;
4198 if (windows->image.crop_geometry != (
char *) NULL)
4199 (void) XParseGeometry(windows->image.crop_geometry,&x,&y,&width,&height);
4200 scale_factor=(MagickRealType) width/windows->image.ximage->width;
4201 composite_info.x+=x;
4202 composite_info.x=(ssize_t) (scale_factor*composite_info.x+0.5);
4203 composite_info.width=(
unsigned int) (scale_factor*composite_info.width+0.5);
4204 scale_factor=(MagickRealType) height/windows->image.ximage->height;
4205 composite_info.y+=y;
4206 composite_info.y=(ssize_t) (scale_factor*composite_info.y+0.5);
4207 composite_info.height=(
unsigned int) (scale_factor*composite_info.height+0.5);
4208 if ((composite_info.width != composite_image->columns) ||
4209 (composite_info.height != composite_image->rows))
4217 resize_image=ResizeImage(composite_image,composite_info.width,
4218 composite_info.height,composite_image->filter,composite_image->blur,
4220 composite_image=DestroyImage(composite_image);
4221 if (resize_image == (Image *) NULL)
4223 XSetCursorState(display,windows,MagickFalse);
4224 return(MagickFalse);
4226 composite_image=resize_image;
4228 if (compose == DisplaceCompositeOp)
4229 (void) SetImageArtifact(composite_image,
"compose:args",
4230 displacement_geometry);
4254 (void) SetImageAlphaChannel(composite_image,OpaqueAlphaChannel);
4255 opacity=(Quantum) (ScaleQuantumToChar(QuantumRange)-
4256 ((ssize_t) ScaleQuantumToChar(QuantumRange)*blend)/100);
4257 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
4258 return(MagickFalse);
4259 image->matte=MagickTrue;
4260 exception=(&image->exception);
4261 image_view=AcquireAuthenticCacheView(image,exception);
4262 for (y=0; y < (int) image->rows; y++)
4264 q=GetCacheViewAuthenticPixels(image_view,0,(ssize_t) y,image->columns,1,
4266 if (q == (PixelPacket *) NULL)
4268 for (x=0; x < (int) image->columns; x++)
4273 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
4276 image_view=DestroyCacheView(image_view);
4281 (void) CompositeImage(image,compose,composite_image,composite_info.x,
4283 composite_image=DestroyImage(composite_image);
4284 XSetCursorState(display,windows,MagickFalse);
4288 XConfigureImageColormap(display,resource_info,windows,image);
4289 (void) XConfigureImage(display,resource_info,windows,image);
4325static MagickBooleanType XConfigureImage(Display *display,
4326 XResourceInfo *resource_info,XWindows *windows,Image *image)
4329 geometry[MaxTextExtent];
4352 width=(
unsigned int) windows->image.window_changes.width;
4353 height=(
unsigned int) windows->image.window_changes.height;
4354 if (resource_info->debug != MagickFalse)
4355 (void) LogMagickEvent(X11Event,GetMagickModule(),
4356 "Configure Image: %dx%d=>%.20gx%.20g",windows->image.ximage->width,
4357 windows->image.ximage->height,(
double) width,(
double) height);
4358 if ((width*height) == 0)
4365 XSetCursorState(display,windows,MagickTrue);
4366 (void) XFlush(display);
4367 if (((
int) width != windows->image.ximage->width) ||
4368 ((
int) height != windows->image.ximage->height))
4369 image->taint=MagickTrue;
4370 windows->magnify.x=(int)
4371 width*windows->magnify.x/windows->image.ximage->width;
4372 windows->magnify.y=(int)
4373 height*windows->magnify.y/windows->image.ximage->height;
4374 windows->image.x=(int) (width*windows->image.x/windows->image.ximage->width);
4375 windows->image.y=(int)
4376 (height*windows->image.y/windows->image.ximage->height);
4377 status=XMakeImage(display,resource_info,&windows->image,image,
4378 (
unsigned int) width,(
unsigned int) height);
4379 if (status == MagickFalse)
4380 XNoticeWidget(display,windows,
"Unable to configure X image:",
4381 windows->image.name);
4385 if (resource_info->image_geometry != (
char *) NULL)
4386 (void) FormatLocaleString(geometry,MaxTextExtent,
"%s>!",
4387 resource_info->image_geometry);
4389 (
void) FormatLocaleString(geometry,MaxTextExtent,
"%ux%u+0+0>!",
4390 XDisplayWidth(display,windows->image.screen),
4391 XDisplayHeight(display,windows->image.screen));
4392 (void) ParseMetaGeometry(geometry,&x,&y,&width,&height);
4393 window_changes.width=(int) width;
4394 if (window_changes.width > XDisplayWidth(display,windows->image.screen))
4395 window_changes.width=XDisplayWidth(display,windows->image.screen);
4396 window_changes.height=(int) height;
4397 if (window_changes.height > XDisplayHeight(display,windows->image.screen))
4398 window_changes.height=XDisplayHeight(display,windows->image.screen);
4399 mask=(size_t) (CWWidth | CWHeight);
4400 if (resource_info->backdrop)
4403 window_changes.x=(int)
4404 ((XDisplayWidth(display,windows->image.screen)/2)-(width/2));
4405 window_changes.y=(int)
4406 ((XDisplayHeight(display,windows->image.screen)/2)-(height/2));
4408 (void) XReconfigureWMWindow(display,windows->image.id,windows->image.screen,
4409 (
unsigned int) mask,&window_changes);
4410 (void) XClearWindow(display,windows->image.id);
4411 XRefreshWindow(display,&windows->image,(XEvent *) NULL);
4415 if (windows->magnify.mapped != MagickFalse)
4416 XMakeMagnifyImage(display,windows);
4417 windows->pan.crop_geometry=windows->image.crop_geometry;
4418 XBestIconSize(display,&windows->pan,image);
4419 while (((windows->pan.width << 1) < MaxIconSize) &&
4420 ((windows->pan.height << 1) < MaxIconSize))
4422 windows->pan.width<<=1;
4423 windows->pan.height<<=1;
4425 if (windows->pan.geometry != (
char *) NULL)
4426 (void) XParseGeometry(windows->pan.geometry,&windows->pan.x,&windows->pan.y,
4427 &windows->pan.width,&windows->pan.height);
4428 window_changes.width=(int) windows->pan.width;
4429 window_changes.height=(int) windows->pan.height;
4430 size_hints=XAllocSizeHints();
4431 if (size_hints != (XSizeHints *) NULL)
4436 size_hints->flags=PSize | PMinSize | PMaxSize;
4437 size_hints->width=window_changes.width;
4438 size_hints->height=window_changes.height;
4439 size_hints->min_width=size_hints->width;
4440 size_hints->min_height=size_hints->height;
4441 size_hints->max_width=size_hints->width;
4442 size_hints->max_height=size_hints->height;
4443 (void) XSetNormalHints(display,windows->pan.id,size_hints);
4444 (void) XFree((
void *) size_hints);
4446 (void) XReconfigureWMWindow(display,windows->pan.id,windows->pan.screen,
4447 (
unsigned int) (CWWidth | CWHeight),&window_changes);
4451 windows->icon.crop_geometry=windows->image.crop_geometry;
4452 XBestIconSize(display,&windows->icon,image);
4453 window_changes.width=(int) windows->icon.width;
4454 window_changes.height=(int) windows->icon.height;
4455 (void) XReconfigureWMWindow(display,windows->icon.id,windows->icon.screen,
4456 (
unsigned int) (CWWidth | CWHeight),&window_changes);
4457 XSetCursorState(display,windows,MagickFalse);
4458 return(status != 0 ? MagickTrue : MagickFalse);
4497static MagickBooleanType XCropImage(Display *display,
4498 XResourceInfo *resource_info,XWindows *windows,Image *image,
4499 const ClipboardMode mode)
4508 *RectifyModeMenu[] =
4516 static const ModeType
4526 RectifyDismissCommand
4533 command[MaxTextExtent],
4534 text[MaxTextExtent];
4580 (void) CloneString(&windows->command.name,
"Copy");
4585 (void) CloneString(&windows->command.name,
"Crop");
4590 (void) CloneString(&windows->command.name,
"Cut");
4594 RectifyModeMenu[0]=windows->command.name;
4595 windows->command.data=0;
4596 (void) XCommandWidget(display,windows,CropModeMenu,(XEvent *) NULL);
4597 (void) XMapRaised(display,windows->command.id);
4598 XClientMessage(display,windows->image.id,windows->im_protocols,
4599 windows->im_update_widget,CurrentTime);
4603 XQueryPosition(display,windows->image.id,&x,&y);
4604 (void) XSelectInput(display,windows->image.id,
4605 windows->image.attributes.event_mask | PointerMotionMask);
4606 crop_info.x=(ssize_t) windows->image.x+x;
4607 crop_info.y=(ssize_t) windows->image.y+y;
4610 cursor=XCreateFontCursor(display,XC_fleur);
4614 if (windows->info.mapped != MagickFalse)
4619 (void) FormatLocaleString(text,MaxTextExtent,
" %+ld%+ld ",
4620 (
long) crop_info.x,(
long) crop_info.y);
4621 XInfoWidget(display,windows,text);
4626 XScreenEvent(display,windows,&event);
4627 if (event.xany.window == windows->command.id)
4632 id=XCommandWidget(display,windows,CropModeMenu,&event);
4635 switch (CropCommands[
id])
4637 case CropHelpCommand:
4643 XTextViewHelp(display,resource_info,windows,MagickFalse,
4644 "Help Viewer - Image Copy",ImageCopyHelp);
4649 XTextViewHelp(display,resource_info,windows,MagickFalse,
4650 "Help Viewer - Image Crop",ImageCropHelp);
4655 XTextViewHelp(display,resource_info,windows,MagickFalse,
4656 "Help Viewer - Image Cut",ImageCutHelp);
4662 case CropDismissCommand:
4680 if (event.xbutton.button != Button1)
4682 if (event.xbutton.window != windows->image.id)
4687 (void) XCheckDefineCursor(display,windows->image.id,cursor);
4688 crop_info.x=(ssize_t) windows->image.x+event.xbutton.x;
4689 crop_info.y=(ssize_t) windows->image.y+event.xbutton.y;
4699 if (event.xkey.window != windows->image.id)
4704 (void) XLookupString((XKeyEvent *) &event.xkey,command,(
int)
4705 sizeof(command),&key_symbol,(XComposeStatus *) NULL);
4706 switch ((
int) key_symbol)
4725 XTextViewHelp(display,resource_info,windows,MagickFalse,
4726 "Help Viewer - Image Copy",ImageCopyHelp);
4731 XTextViewHelp(display,resource_info,windows,MagickFalse,
4732 "Help Viewer - Image Crop",ImageCropHelp);
4737 XTextViewHelp(display,resource_info,windows,MagickFalse,
4738 "Help Viewer - Image Cut",ImageCutHelp);
4746 (void) XBell(display,0);
4754 if (event.xmotion.window != windows->image.id)
4761 if (windows->info.mapped != MagickFalse)
4763 if ((x < (
int) (windows->info.x+windows->info.width)) &&
4764 (y < (
int) (windows->info.y+windows->info.height)))
4765 (void) XWithdrawWindow(display,windows->info.id,
4766 windows->info.screen);
4769 if ((x > (
int) (windows->info.x+windows->info.width)) ||
4770 (y > (
int) (windows->info.y+windows->info.height)))
4771 (void) XMapWindow(display,windows->info.id);
4772 crop_info.x=(ssize_t) windows->image.x+x;
4773 crop_info.y=(ssize_t) windows->image.y+y;
4779 }
while ((state & ExitState) == 0);
4780 (void) XSelectInput(display,windows->image.id,
4781 windows->image.attributes.event_mask);
4782 if ((state & EscapeState) != 0)
4787 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
4788 (void) XFreeCursor(display,cursor);
4791 (void) XSetFunction(display,windows->image.highlight_context,GXinvert);
4797 x=(int) crop_info.x;
4798 y=(int) crop_info.y;
4804 highlight_info=crop_info;
4805 highlight_info.x=crop_info.x-windows->image.x;
4806 highlight_info.y=crop_info.y-windows->image.y;
4807 if ((highlight_info.width > 3) && (highlight_info.height > 3))
4812 if (windows->info.mapped == MagickFalse)
4813 (void) XMapWindow(display,windows->info.id);
4814 (void) FormatLocaleString(text,MaxTextExtent,
4815 " %.20gx%.20g%+.20g%+.20g",(
double) crop_info.width,(
double)
4816 crop_info.height,(
double) crop_info.x,(
double) crop_info.y);
4817 XInfoWidget(display,windows,text);
4818 XHighlightRectangle(display,windows->image.id,
4819 windows->image.highlight_context,&highlight_info);
4822 if (windows->info.mapped != MagickFalse)
4823 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
4827 XScreenEvent(display,windows,&event);
4828 if ((highlight_info.width > 3) && (highlight_info.height > 3))
4829 XHighlightRectangle(display,windows->image.id,
4830 windows->image.highlight_context,&highlight_info);
4835 crop_info.x=(ssize_t) windows->image.x+event.xbutton.x;
4836 crop_info.y=(ssize_t) windows->image.y+event.xbutton.y;
4844 crop_info.x=(ssize_t) windows->image.x+event.xbutton.x;
4845 crop_info.y=(ssize_t) windows->image.y+event.xbutton.y;
4846 XSetCursorState(display,windows,MagickFalse);
4848 windows->command.data=0;
4849 (void) XCommandWidget(display,windows,RectifyModeMenu,
4857 crop_info.x=(ssize_t) windows->image.x+event.xmotion.x;
4858 crop_info.y=(ssize_t) windows->image.y+event.xmotion.y;
4863 if ((((
int) crop_info.x != x) && ((
int) crop_info.y != y)) ||
4864 ((state & ExitState) != 0))
4869 if (crop_info.x < 0)
4872 if (crop_info.x > (ssize_t) windows->image.ximage->width)
4873 crop_info.x=(ssize_t) windows->image.ximage->width;
4874 if ((
int) crop_info.x < x)
4875 crop_info.width=(
unsigned int) (x-crop_info.x);
4878 crop_info.width=(
unsigned int) (crop_info.x-x);
4879 crop_info.x=(ssize_t) x;
4881 if (crop_info.y < 0)
4884 if (crop_info.y > (ssize_t) windows->image.ximage->height)
4885 crop_info.y=(ssize_t) windows->image.ximage->height;
4886 if ((
int) crop_info.y < y)
4887 crop_info.height=(
unsigned int) (y-crop_info.y);
4890 crop_info.height=(
unsigned int) (crop_info.y-y);
4891 crop_info.y=(ssize_t) y;
4894 }
while ((state & ExitState) == 0);
4899 (void) XMapWindow(display,windows->info.id);
4902 if (windows->info.mapped != MagickFalse)
4907 (void) FormatLocaleString(text,MaxTextExtent,
4908 " %.20gx%.20g%+.20g%+.20g",(
double) crop_info.width,(
double)
4909 crop_info.height,(
double) crop_info.x,(
double) crop_info.y);
4910 XInfoWidget(display,windows,text);
4912 highlight_info=crop_info;
4913 highlight_info.x=crop_info.x-windows->image.x;
4914 highlight_info.y=crop_info.y-windows->image.y;
4915 if ((highlight_info.width <= 3) || (highlight_info.height <= 3))
4921 XHighlightRectangle(display,windows->image.id,
4922 windows->image.highlight_context,&highlight_info);
4923 XScreenEvent(display,windows,&event);
4924 if (event.xany.window == windows->command.id)
4929 (void) XSetFunction(display,windows->image.highlight_context,GXcopy);
4930 id=XCommandWidget(display,windows,RectifyModeMenu,&event);
4931 (void) XSetFunction(display,windows->image.highlight_context,
4933 XHighlightRectangle(display,windows->image.id,
4934 windows->image.highlight_context,&highlight_info);
4936 switch (RectifyCommands[
id])
4938 case RectifyCopyCommand:
4943 case RectifyHelpCommand:
4945 (void) XSetFunction(display,windows->image.highlight_context,
4951 XTextViewHelp(display,resource_info,windows,MagickFalse,
4952 "Help Viewer - Image Copy",ImageCopyHelp);
4957 XTextViewHelp(display,resource_info,windows,MagickFalse,
4958 "Help Viewer - Image Crop",ImageCropHelp);
4963 XTextViewHelp(display,resource_info,windows,MagickFalse,
4964 "Help Viewer - Image Cut",ImageCutHelp);
4968 (void) XSetFunction(display,windows->image.highlight_context,
4972 case RectifyDismissCommand:
4986 XHighlightRectangle(display,windows->image.id,
4987 windows->image.highlight_context,&highlight_info);
4992 if (event.xbutton.button != Button1)
4994 if (event.xbutton.window != windows->image.id)
4996 x=windows->image.x+
event.xbutton.x;
4997 y=windows->image.y+
event.xbutton.y;
4998 if ((x < (
int) (crop_info.x+RoiDelta)) &&
4999 (x > (
int) (crop_info.x-RoiDelta)) &&
5000 (y < (
int) (crop_info.y+RoiDelta)) &&
5001 (y > (
int) (crop_info.y-RoiDelta)))
5003 crop_info.x=(ssize_t) (crop_info.x+crop_info.width);
5004 crop_info.y=(ssize_t) (crop_info.y+crop_info.height);
5005 state|=UpdateConfigurationState;
5008 if ((x < (
int) (crop_info.x+RoiDelta)) &&
5009 (x > (
int) (crop_info.x-RoiDelta)) &&
5010 (y < (
int) (crop_info.y+crop_info.height+RoiDelta)) &&
5011 (y > (
int) (crop_info.y+crop_info.height-RoiDelta)))
5013 crop_info.x=(ssize_t) (crop_info.x+crop_info.width);
5014 state|=UpdateConfigurationState;
5017 if ((x < (
int) (crop_info.x+crop_info.width+RoiDelta)) &&
5018 (x > (
int) (crop_info.x+crop_info.width-RoiDelta)) &&
5019 (y < (
int) (crop_info.y+RoiDelta)) &&
5020 (y > (
int) (crop_info.y-RoiDelta)))
5022 crop_info.y=(ssize_t) (crop_info.y+crop_info.height);
5023 state|=UpdateConfigurationState;
5026 if ((x < (
int) (crop_info.x+crop_info.width+RoiDelta)) &&
5027 (x > (
int) (crop_info.x+crop_info.width-RoiDelta)) &&
5028 (y < (
int) (crop_info.y+crop_info.height+RoiDelta)) &&
5029 (y > (
int) (crop_info.y+crop_info.height-RoiDelta)))
5031 state|=UpdateConfigurationState;
5038 if (event.xbutton.window == windows->pan.id)
5039 if ((highlight_info.x != crop_info.x-windows->image.x) ||
5040 (highlight_info.y != crop_info.y-windows->image.y))
5041 XHighlightRectangle(display,windows->image.id,
5042 windows->image.highlight_context,&highlight_info);
5043 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->image.id,
5044 event.xbutton.time);
5049 if (event.xexpose.window == windows->image.id)
5050 if (event.xexpose.count == 0)
5052 event.xexpose.x=(int) highlight_info.x;
5053 event.xexpose.y=(int) highlight_info.y;
5054 event.xexpose.width=(int) highlight_info.width;
5055 event.xexpose.height=(int) highlight_info.height;
5056 XRefreshWindow(display,&windows->image,&event);
5058 if (event.xexpose.window == windows->info.id)
5059 if (event.xexpose.count == 0)
5060 XInfoWidget(display,windows,text);
5065 if (event.xkey.window != windows->image.id)
5070 (void) XLookupString((XKeyEvent *) &event.xkey,command,(
int)
5071 sizeof(command),&key_symbol,(XComposeStatus *) NULL);
5072 switch ((
int) key_symbol)
5088 crop_info.x=(ssize_t) (windows->image.width/2L-crop_info.width/
5090 crop_info.y=(ssize_t) (windows->image.height/2L-crop_info.height/
5123 (void) XSetFunction(display,windows->image.highlight_context,
5129 XTextViewHelp(display,resource_info,windows,MagickFalse,
5130 "Help Viewer - Image Copy",ImageCopyHelp);
5135 XTextViewHelp(display,resource_info,windows,MagickFalse,
5136 "Help Viewer - Image Cropg",ImageCropHelp);
5141 XTextViewHelp(display,resource_info,windows,MagickFalse,
5142 "Help Viewer - Image Cutg",ImageCutHelp);
5146 (void) XSetFunction(display,windows->image.highlight_context,
5152 (void) XBell(display,0);
5156 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->image.id,
5164 if (event.xmotion.window != windows->image.id)
5171 if (windows->info.mapped != MagickFalse)
5173 if ((x < (
int) (windows->info.x+windows->info.width)) &&
5174 (y < (
int) (windows->info.y+windows->info.height)))
5175 (void) XWithdrawWindow(display,windows->info.id,
5176 windows->info.screen);
5179 if ((x > (
int) (windows->info.x+windows->info.width)) ||
5180 (y > (
int) (windows->info.y+windows->info.height)))
5181 (void) XMapWindow(display,windows->info.id);
5182 crop_info.x=(ssize_t) windows->image.x+event.xmotion.x;
5183 crop_info.y=(ssize_t) windows->image.y+event.xmotion.y;
5186 case SelectionRequest:
5191 XSelectionRequestEvent
5197 (void) FormatLocaleString(text,MaxTextExtent,
5198 "%.20gx%.20g%+.20g%+.20g",(
double) crop_info.width,(
double)
5199 crop_info.height,(
double) crop_info.x,(
double) crop_info.y);
5200 request=(&(
event.xselectionrequest));
5201 (void) XChangeProperty(request->display,request->requestor,
5202 request->property,request->target,8,PropModeReplace,
5203 (
unsigned char *) text,(
int) strlen(text));
5204 notify.type=SelectionNotify;
5205 notify.display=request->display;
5206 notify.requestor=request->requestor;
5207 notify.selection=request->selection;
5208 notify.target=request->target;
5209 notify.time=request->time;
5210 if (request->property == None)
5211 notify.property=request->target;
5213 notify.property=request->property;
5214 (void) XSendEvent(request->display,request->requestor,False,0,
5215 (XEvent *) ¬ify);
5220 if ((state & UpdateConfigurationState) != 0)
5222 (void) XPutBackEvent(display,&event);
5223 (void) XCheckDefineCursor(display,windows->image.id,cursor);
5226 }
while ((state & ExitState) == 0);
5227 }
while ((state & ExitState) == 0);
5228 (void) XSetFunction(display,windows->image.highlight_context,GXcopy);
5229 XSetCursorState(display,windows,MagickFalse);
5230 if ((state & EscapeState) != 0)
5232 if (mode == CropMode)
5233 if (((
int) crop_info.width != windows->image.ximage->width) ||
5234 ((
int) crop_info.height != windows->image.ximage->height))
5239 XSetCropGeometry(display,windows,&crop_info,image);
5240 windows->image.window_changes.width=(int) crop_info.width;
5241 windows->image.window_changes.height=(int) crop_info.height;
5242 (void) XConfigureImage(display,resource_info,windows,image);
5248 XSetCursorState(display,windows,MagickTrue);
5249 XCheckRefreshWindows(display,windows);
5250 width=(
unsigned int) image->columns;
5251 height=(
unsigned int) image->rows;
5254 if (windows->image.crop_geometry != (
char *) NULL)
5255 (void) XParseGeometry(windows->image.crop_geometry,&x,&y,&width,&height);
5256 scale_factor=(MagickRealType) width/windows->image.ximage->width;
5258 crop_info.x=(ssize_t) (scale_factor*crop_info.x+0.5);
5259 crop_info.x+=image->page.x;
5260 crop_info.width=(
unsigned int) (scale_factor*crop_info.width+0.5);
5261 scale_factor=(MagickRealType) height/windows->image.ximage->height;
5263 crop_info.y=(ssize_t) (scale_factor*crop_info.y+0.5);
5264 crop_info.y+=image->page.y;
5265 crop_info.height=(
unsigned int) (scale_factor*crop_info.height+0.5);
5266 crop_image=CropImage(image,&crop_info,&image->exception);
5267 XSetCursorState(display,windows,MagickFalse);
5268 if (crop_image == (Image *) NULL)
5269 return(MagickFalse);
5270 if (resource_info->copy_image != (Image *) NULL)
5271 resource_info->copy_image=DestroyImage(resource_info->copy_image);
5272 resource_info->copy_image=crop_image;
5273 if (mode == CopyMode)
5275 (void) XConfigureImage(display,resource_info,windows,image);
5281 if (SetImageStorageClass(image,DirectClass) == MagickFalse)
5282 return(MagickFalse);
5283 image->matte=MagickTrue;
5284 exception=(&image->exception);
5285 image_view=AcquireAuthenticCacheView(image,exception);
5286 for (y=0; y < (int) crop_info.height; y++)
5288 q=GetCacheViewAuthenticPixels(image_view,crop_info.x,y+crop_info.y,
5289 crop_info.width,1,exception);
5290 if (q == (PixelPacket *) NULL)
5292 for (x=0; x < (int) crop_info.width; x++)
5294 q->opacity=(Quantum) TransparentOpacity;
5297 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
5300 image_view=DestroyCacheView(image_view);
5304 XConfigureImageColormap(display,resource_info,windows,image);
5305 (void) XConfigureImage(display,resource_info,windows,image);
5340static MagickBooleanType XDrawEditImage(Display *display,
5341 XResourceInfo *resource_info,XWindows *windows,Image **image)
5357 element = PointElement;
5359 static const ModeType
5372 stipple = (Pixmap) NULL;
5379 command[MaxTextExtent],
5380 text[MaxTextExtent];
5431 max_coordinates=2048;
5432 coordinate_info=(XPoint *) AcquireQuantumMemory((
size_t) max_coordinates,
5433 sizeof(*coordinate_info));
5434 if (coordinate_info == (XPoint *) NULL)
5436 (void) ThrowMagickException(&(*image)->exception,GetMagickModule(),
5437 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"...");
5438 return(MagickFalse);
5443 (void) CloneString(&windows->command.name,
"Draw");
5444 windows->command.data=4;
5445 (void) XCommandWidget(display,windows,DrawMenu,(XEvent *) NULL);
5446 (void) XMapRaised(display,windows->command.id);
5447 XClientMessage(display,windows->image.id,windows->im_protocols,
5448 windows->im_update_widget,CurrentTime);
5452 root_window=XRootWindow(display,XDefaultScreen(display));
5453 draw_info.stencil=OpaqueStencil;
5455 cursor=XCreateFontCursor(display,XC_tcross);
5458 XQueryPosition(display,windows->image.id,&x,&y);
5459 (void) XSelectInput(display,windows->image.id,
5460 windows->image.attributes.event_mask | PointerMotionMask);
5461 (void) XCheckDefineCursor(display,windows->image.id,cursor);
5465 if (windows->info.mapped != MagickFalse)
5470 (void) FormatLocaleString(text,MaxTextExtent,
" %+d%+d ",
5471 x+windows->image.x,y+windows->image.y);
5472 XInfoWidget(display,windows,text);
5477 XScreenEvent(display,windows,&event);
5478 if (event.xany.window == windows->command.id)
5483 id=XCommandWidget(display,windows,DrawMenu,&event);
5486 switch (DrawCommands[
id])
5488 case DrawElementCommand:
5509 element=(ElementType) (XMenuWidget(display,windows,
5510 DrawMenu[
id],Elements,command)+1);
5513 case DrawColorCommand:
5516 *ColorMenu[MaxNumberPens+1];
5530 for (i=0; i < (int) (MaxNumberPens-2); i++)
5531 ColorMenu[i]=resource_info->pen_colors[i];
5532 ColorMenu[MaxNumberPens-2]=
"transparent";
5533 ColorMenu[MaxNumberPens-1]=
"Browser...";
5534 ColorMenu[MaxNumberPens]=(
char *) NULL;
5538 pen_number=XMenuWidget(display,windows,DrawMenu[
id],
5539 (
const char **) ColorMenu,command);
5542 transparent=pen_number == (MaxNumberPens-2) ? MagickTrue :
5544 if (transparent != MagickFalse)
5546 draw_info.stencil=TransparentStencil;
5549 if (pen_number == (MaxNumberPens-1))
5552 color_name[MaxTextExtent] =
"gray";
5557 resource_info->pen_colors[pen_number]=color_name;
5558 XColorBrowserWidget(display,windows,
"Select",color_name);
5559 if (*color_name ==
'\0')
5565 (void) XParseColor(display,windows->map_info->colormap,
5566 resource_info->pen_colors[pen_number],&color);
5567 XBestPixel(display,windows->map_info->colormap,(XColor *) NULL,
5568 (
unsigned int) MaxColors,&color);
5569 windows->pixel_info->pen_colors[pen_number]=color;
5570 pen_id=(
unsigned int) pen_number;
5571 draw_info.stencil=OpaqueStencil;
5574 case DrawStippleCommand:
5600 filename[MaxTextExtent] =
"\0";
5605 StipplesMenu[7]=
"Open...";
5606 entry=XMenuWidget(display,windows,DrawMenu[
id],StipplesMenu,
5610 if (stipple != (Pixmap) NULL)
5611 (void) XFreePixmap(display,stipple);
5612 stipple=(Pixmap) NULL;
5619 stipple=XCreateBitmapFromData(display,root_window,
5620 (
char *) BricksBitmap,BricksWidth,BricksHeight);
5625 stipple=XCreateBitmapFromData(display,root_window,
5626 (
char *) DiagonalBitmap,DiagonalWidth,DiagonalHeight);
5631 stipple=XCreateBitmapFromData(display,root_window,
5632 (
char *) ScalesBitmap,ScalesWidth,ScalesHeight);
5637 stipple=XCreateBitmapFromData(display,root_window,
5638 (
char *) VerticalBitmap,VerticalWidth,VerticalHeight);
5643 stipple=XCreateBitmapFromData(display,root_window,
5644 (
char *) WavyBitmap,WavyWidth,WavyHeight);
5649 stipple=XCreateBitmapFromData(display,root_window,
5650 (
char *) HighlightBitmap,HighlightWidth,
5657 stipple=XCreateBitmapFromData(display,root_window,
5658 (
char *) OpaqueBitmap,OpaqueWidth,OpaqueHeight);
5664 XFileBrowserWidget(display,windows,
"Stipple",filename);
5665 if (*filename ==
'\0')
5670 XSetCursorState(display,windows,MagickTrue);
5671 XCheckRefreshWindows(display,windows);
5672 image_info=AcquireImageInfo();
5673 (void) CopyMagickString(image_info->filename,filename,
5675 stipple_image=ReadImage(image_info,&(*image)->exception);
5676 CatchException(&(*image)->exception);
5677 XSetCursorState(display,windows,MagickFalse);
5678 if (stipple_image == (Image *) NULL)
5680 (void) AcquireUniqueFileResource(filename);
5681 (void) FormatLocaleString(stipple_image->filename,MaxTextExtent,
5683 (void) WriteImage(image_info,stipple_image);
5684 stipple_image=DestroyImage(stipple_image);
5685 image_info=DestroyImageInfo(image_info);
5686 status=XReadBitmapFile(display,root_window,filename,&width,
5687 &height,&stipple,&x,&y);
5688 (void) RelinquishUniqueFileResource(filename);
5689 if ((status != BitmapSuccess) != 0)
5690 XNoticeWidget(display,windows,
"Unable to read X bitmap image:",
5694 case DrawWidthCommand:
5697 *
const WidthsMenu[] =
5709 width[MaxTextExtent] =
"0";
5714 entry=XMenuWidget(display,windows,DrawMenu[
id],WidthsMenu,
5720 line_width=(
unsigned int) StringToUnsignedLong(
5724 (void) XDialogWidget(display,windows,
"Ok",
"Enter line width:",
5728 line_width=(
unsigned int) StringToUnsignedLong(width);
5731 case DrawUndoCommand:
5733 (void) XMagickCommand(display,resource_info,windows,UndoCommand,
5737 case DrawHelpCommand:
5739 XTextViewHelp(display,resource_info,windows,MagickFalse,
5740 "Help Viewer - Image Rotation",ImageDrawHelp);
5741 (void) XCheckDefineCursor(display,windows->image.id,cursor);
5744 case DrawDismissCommand:
5756 (void) XCheckDefineCursor(display,windows->image.id,cursor);
5763 if (event.xbutton.button != Button1)
5765 if (event.xbutton.window != windows->image.id)
5784 if (event.xkey.window != windows->image.id)
5789 (void) XLookupString((XKeyEvent *) &event.xkey,command,(
int)
5790 sizeof(command),&key_symbol,(XComposeStatus *) NULL);
5791 switch ((
int) key_symbol)
5806 XTextViewHelp(display,resource_info,windows,MagickFalse,
5807 "Help Viewer - Image Rotation",ImageDrawHelp);
5812 (void) XBell(display,0);
5825 if (windows->info.mapped != MagickFalse)
5827 if ((x < (
int) (windows->info.x+windows->info.width)) &&
5828 (y < (
int) (windows->info.y+windows->info.height)))
5829 (void) XWithdrawWindow(display,windows->info.id,
5830 windows->info.screen);
5833 if ((x > (
int) (windows->info.x+windows->info.width)) ||
5834 (y > (
int) (windows->info.y+windows->info.height)))
5835 (void) XMapWindow(display,windows->info.id);
5839 }
while ((state & ExitState) == 0);
5840 (void) XSelectInput(display,windows->image.id,
5841 windows->image.attributes.event_mask);
5842 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
5843 if ((state & EscapeState) != 0)
5854 rectangle_info.x=(ssize_t) x;
5855 rectangle_info.y=(ssize_t) y;
5856 rectangle_info.width=0;
5857 rectangle_info.height=0;
5858 number_coordinates=1;
5859 coordinate_info->x=x;
5860 coordinate_info->y=y;
5861 (void) XSetFunction(display,windows->image.highlight_context,GXinvert);
5870 if (number_coordinates > 1)
5872 (void) XDrawLines(display,windows->image.id,
5873 windows->image.highlight_context,coordinate_info,
5874 number_coordinates,CoordModeOrigin);
5875 (void) FormatLocaleString(text,MaxTextExtent,
" %+d%+d",
5876 coordinate_info[number_coordinates-1].x,
5877 coordinate_info[number_coordinates-1].y);
5878 XInfoWidget(display,windows,text);
5889 degrees=RadiansToDegrees(-atan2((
double) (line_info.y2-
5890 line_info.y1),(
double) (line_info.x2-line_info.x1)));
5891 (void) FormatLocaleString(text,MaxTextExtent,
" %g",
5893 XInfoWidget(display,windows,text);
5894 XHighlightLine(display,windows->image.id,
5895 windows->image.highlight_context,&line_info);
5898 if (windows->info.mapped != MagickFalse)
5899 (void) XWithdrawWindow(display,windows->info.id,
5900 windows->info.screen);
5903 case RectangleElement:
5904 case FillRectangleElement:
5906 if ((rectangle_info.width > 3) && (rectangle_info.height > 3))
5911 (void) FormatLocaleString(text,MaxTextExtent,
5912 " %.20gx%.20g%+.20g%+.20g",(
double) rectangle_info.width,
5913 (
double) rectangle_info.height,(
double) rectangle_info.x,
5914 (
double) rectangle_info.y);
5915 XInfoWidget(display,windows,text);
5916 XHighlightRectangle(display,windows->image.id,
5917 windows->image.highlight_context,&rectangle_info);
5920 if (windows->info.mapped != MagickFalse)
5921 (void) XWithdrawWindow(display,windows->info.id,
5922 windows->info.screen);
5926 case FillCircleElement:
5927 case EllipseElement:
5928 case FillEllipseElement:
5930 if ((rectangle_info.width > 3) && (rectangle_info.height > 3))
5935 (void) FormatLocaleString(text,MaxTextExtent,
5936 " %.20gx%.20g%+.20g%+.20g",(
double) rectangle_info.width,
5937 (
double) rectangle_info.height,(
double) rectangle_info.x,
5938 (
double) rectangle_info.y);
5939 XInfoWidget(display,windows,text);
5940 XHighlightEllipse(display,windows->image.id,
5941 windows->image.highlight_context,&rectangle_info);
5944 if (windows->info.mapped != MagickFalse)
5945 (void) XWithdrawWindow(display,windows->info.id,
5946 windows->info.screen);
5949 case PolygonElement:
5950 case FillPolygonElement:
5952 if (number_coordinates > 1)
5953 (void) XDrawLines(display,windows->image.id,
5954 windows->image.highlight_context,coordinate_info,
5955 number_coordinates,CoordModeOrigin);
5961 degrees=RadiansToDegrees(-atan2((
double) (line_info.y2-
5962 line_info.y1),(
double) (line_info.x2-line_info.x1)));
5963 (void) FormatLocaleString(text,MaxTextExtent,
" %g",
5965 XInfoWidget(display,windows,text);
5966 XHighlightLine(display,windows->image.id,
5967 windows->image.highlight_context,&line_info);
5970 if (windows->info.mapped != MagickFalse)
5971 (void) XWithdrawWindow(display,windows->info.id,
5972 windows->info.screen);
5979 XScreenEvent(display,windows,&event);
5985 if (number_coordinates > 1)
5986 (void) XDrawLines(display,windows->image.id,
5987 windows->image.highlight_context,coordinate_info,
5988 number_coordinates,CoordModeOrigin);
5994 XHighlightLine(display,windows->image.id,
5995 windows->image.highlight_context,&line_info);
5998 case RectangleElement:
5999 case FillRectangleElement:
6001 if ((rectangle_info.width > 3) && (rectangle_info.height > 3))
6002 XHighlightRectangle(display,windows->image.id,
6003 windows->image.highlight_context,&rectangle_info);
6007 case FillCircleElement:
6008 case EllipseElement:
6009 case FillEllipseElement:
6011 if ((rectangle_info.width > 3) && (rectangle_info.height > 3))
6012 XHighlightEllipse(display,windows->image.id,
6013 windows->image.highlight_context,&rectangle_info);
6016 case PolygonElement:
6017 case FillPolygonElement:
6019 if (number_coordinates > 1)
6020 (void) XDrawLines(display,windows->image.id,
6021 windows->image.highlight_context,coordinate_info,
6022 number_coordinates,CoordModeOrigin);
6024 XHighlightLine(display,windows->image.id,
6025 windows->image.highlight_context,&line_info);
6038 line_info.x2=
event.xbutton.x;
6039 line_info.y2=
event.xbutton.y;
6040 rectangle_info.x=(ssize_t) event.xbutton.x;
6041 rectangle_info.y=(ssize_t) event.xbutton.y;
6042 coordinate_info[number_coordinates].x=
event.xbutton.x;
6043 coordinate_info[number_coordinates].y=
event.xbutton.y;
6044 if (((element != PolygonElement) &&
6045 (element != FillPolygonElement)) || (distance <= 9))
6050 number_coordinates++;
6051 if (number_coordinates < (
int) max_coordinates)
6053 line_info.x1=
event.xbutton.x;
6054 line_info.y1=
event.xbutton.y;
6057 max_coordinates<<=1;
6058 coordinate_info=(XPoint *) ResizeQuantumMemory(coordinate_info,
6059 max_coordinates,
sizeof(*coordinate_info));
6060 if (coordinate_info == (XPoint *) NULL)
6061 (void) ThrowMagickException(&(*image)->exception,GetMagickModule(),
6062 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"...");
6069 if (event.xmotion.window != windows->image.id)
6071 if (element != PointElement)
6073 line_info.x2=
event.xmotion.x;
6074 line_info.y2=
event.xmotion.y;
6075 rectangle_info.x=(ssize_t) event.xmotion.x;
6076 rectangle_info.y=(ssize_t) event.xmotion.y;
6079 coordinate_info[number_coordinates].x=
event.xbutton.x;
6080 coordinate_info[number_coordinates].y=
event.xbutton.y;
6081 number_coordinates++;
6082 if (number_coordinates < (
int) max_coordinates)
6084 max_coordinates<<=1;
6085 coordinate_info=(XPoint *) ResizeQuantumMemory(coordinate_info,
6086 max_coordinates,
sizeof(*coordinate_info));
6087 if (coordinate_info == (XPoint *) NULL)
6088 (void) ThrowMagickException(&(*image)->exception,GetMagickModule(),
6089 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
"...");
6098 if (line_info.x2 < 0)
6101 if (line_info.x2 > (
int) windows->image.width)
6102 line_info.x2=(short) windows->image.width;
6103 if (line_info.y2 < 0)
6106 if (line_info.y2 > (
int) windows->image.height)
6107 line_info.y2=(short) windows->image.height;
6108 distance=(
unsigned int)
6109 (((line_info.x2-line_info.x1+1)*(line_info.x2-line_info.x1+1))+
6110 ((line_info.y2-line_info.y1+1)*(line_info.y2-line_info.y1+1)));
6111 if ((((
int) rectangle_info.x != x) && ((
int) rectangle_info.y != y)) ||
6112 ((state & ExitState) != 0))
6114 if (rectangle_info.x < 0)
6117 if (rectangle_info.x > (ssize_t) windows->image.width)
6118 rectangle_info.x=(ssize_t) windows->image.width;
6119 if ((
int) rectangle_info.x < x)
6120 rectangle_info.width=(
unsigned int) (x-rectangle_info.x);
6123 rectangle_info.width=(
unsigned int) (rectangle_info.x-x);
6124 rectangle_info.x=(ssize_t) x;
6126 if (rectangle_info.y < 0)
6129 if (rectangle_info.y > (ssize_t) windows->image.height)
6130 rectangle_info.y=(ssize_t) windows->image.height;
6131 if ((
int) rectangle_info.y < y)
6132 rectangle_info.height=(
unsigned int) (y-rectangle_info.y);
6135 rectangle_info.height=(
unsigned int) (rectangle_info.y-y);
6136 rectangle_info.y=(ssize_t) y;
6139 }
while ((state & ExitState) == 0);
6140 (void) XSetFunction(display,windows->image.highlight_context,GXcopy);
6141 if ((element == PointElement) || (element == PolygonElement) ||
6142 (element == FillPolygonElement))
6147 rectangle_info.x=(ssize_t) coordinate_info->x;
6148 rectangle_info.y=(ssize_t) coordinate_info->y;
6149 x=coordinate_info->x;
6150 y=coordinate_info->y;
6151 for (i=1; i < number_coordinates; i++)
6153 if (coordinate_info[i].x > x)
6154 x=coordinate_info[i].x;
6155 if (coordinate_info[i].y > y)
6156 y=coordinate_info[i].y;
6157 if ((ssize_t) coordinate_info[i].x < rectangle_info.x)
6158 rectangle_info.x=MagickMax((ssize_t) coordinate_info[i].x,0);
6159 if ((ssize_t) coordinate_info[i].y < rectangle_info.y)
6160 rectangle_info.y=MagickMax((ssize_t) coordinate_info[i].y,0);
6162 rectangle_info.width=(size_t) (x-rectangle_info.x);
6163 rectangle_info.height=(size_t) (y-rectangle_info.y);
6164 for (i=0; i < number_coordinates; i++)
6166 coordinate_info[i].x-=rectangle_info.x;
6167 coordinate_info[i].y-=rectangle_info.y;
6174 if ((element == RectangleElement) ||
6175 (element == CircleElement) || (element == EllipseElement))
6177 rectangle_info.width--;
6178 rectangle_info.height--;
6183 draw_info.x=(int) rectangle_info.x;
6184 draw_info.y=(int) rectangle_info.y;
6185 (void) XMagickCommand(display,resource_info,windows,SaveToUndoBufferCommand,
6187 width=(
unsigned int) (*image)->columns;
6188 height=(
unsigned int) (*image)->rows;
6191 if (windows->image.crop_geometry != (
char *) NULL)
6192 (void) XParseGeometry(windows->image.crop_geometry,&x,&y,&width,&height);
6193 draw_info.x+=windows->image.x-(line_width/2);
6194 if (draw_info.x < 0)
6196 draw_info.x=(int) (width*draw_info.x/windows->image.ximage->width);
6197 draw_info.y+=windows->image.y-(line_width/2);
6198 if (draw_info.y < 0)
6200 draw_info.y=(int) height*draw_info.y/windows->image.ximage->height;
6201 draw_info.width=(
unsigned int) rectangle_info.width+(line_width << 1);
6202 if (draw_info.width > (
unsigned int) (*image)->columns)
6203 draw_info.width=(
unsigned int) (*image)->columns;
6204 draw_info.height=(
unsigned int) rectangle_info.height+(line_width << 1);
6205 if (draw_info.height > (
unsigned int) (*image)->rows)
6206 draw_info.height=(
unsigned int) (*image)->rows;
6207 (void) FormatLocaleString(draw_info.geometry,MaxTextExtent,
"%ux%u%+d%+d",
6208 width*draw_info.width/windows->image.ximage->width,
6209 height*draw_info.height/windows->image.ximage->height,
6210 draw_info.x+x,draw_info.y+y);
6214 draw_info.degrees=0.0;
6215 draw_info.element=element;
6216 draw_info.stipple=stipple;
6217 draw_info.line_width=line_width;
6218 draw_info.line_info=line_info;
6219 if (line_info.x1 > (
int) (line_width/2))
6220 draw_info.line_info.x1=(short) line_width/2;
6221 if (line_info.y1 > (
int) (line_width/2))
6222 draw_info.line_info.y1=(short) line_width/2;
6223 draw_info.line_info.x2=(short) (line_info.x2-line_info.x1+(line_width/2));
6224 draw_info.line_info.y2=(short) (line_info.y2-line_info.y1+(line_width/2));
6225 if ((draw_info.line_info.x2 < 0) && (draw_info.line_info.y2 < 0))
6227 draw_info.line_info.x2=(-draw_info.line_info.x2);
6228 draw_info.line_info.y2=(-draw_info.line_info.y2);
6230 if (draw_info.line_info.x2 < 0)
6232 draw_info.line_info.x2=(-draw_info.line_info.x2);
6233 Swap(draw_info.line_info.x1,draw_info.line_info.x2);
6235 if (draw_info.line_info.y2 < 0)
6237 draw_info.line_info.y2=(-draw_info.line_info.y2);
6238 Swap(draw_info.line_info.y1,draw_info.line_info.y2);
6240 draw_info.rectangle_info=rectangle_info;
6241 if (draw_info.rectangle_info.x > (ssize_t) (line_width/2))
6242 draw_info.rectangle_info.x=(ssize_t) line_width/2;
6243 if (draw_info.rectangle_info.y > (ssize_t) (line_width/2))
6244 draw_info.rectangle_info.y=(ssize_t) line_width/2;
6245 draw_info.number_coordinates=(
unsigned int) number_coordinates;
6246 draw_info.coordinate_info=coordinate_info;
6247 windows->pixel_info->pen_color=windows->pixel_info->pen_colors[pen_id];
6251 XSetCursorState(display,windows,MagickTrue);
6252 XCheckRefreshWindows(display,windows);
6253 status=XDrawImage(display,windows->pixel_info,&draw_info,*image);
6254 XSetCursorState(display,windows,MagickFalse);
6258 XConfigureImageColormap(display,resource_info,windows,*image);
6259 (void) XConfigureImage(display,resource_info,windows,*image);
6261 XSetCursorState(display,windows,MagickFalse);
6262 coordinate_info=(XPoint *) RelinquishMagickMemory(coordinate_info);
6263 return(status != 0 ? MagickTrue : MagickFalse);
6293static void XDrawPanRectangle(Display *display,XWindows *windows)
6304 scale_factor=(MagickRealType) windows->pan.width/windows->image.ximage->width;
6305 highlight_info.x=(ssize_t) (scale_factor*windows->image.x+0.5);
6306 highlight_info.width=(
unsigned int) (scale_factor*windows->image.width+0.5);
6307 scale_factor=(MagickRealType)
6308 windows->pan.height/windows->image.ximage->height;
6309 highlight_info.y=(ssize_t) (scale_factor*windows->image.y+0.5);
6310 highlight_info.height=(
unsigned int) (scale_factor*windows->image.height+0.5);
6314 (void) XClearWindow(display,windows->pan.id);
6315 XHighlightRectangle(display,windows->pan.id,windows->pan.annotate_context,
6353static void XImageCache(Display *display,XResourceInfo *resource_info,
6354 XWindows *windows,
const DisplayCommand command,Image **image)
6360 *redo_image = (Image *) NULL,
6361 *undo_image = (Image *) NULL;
6365 case FreeBuffersCommand:
6370 while (undo_image != (Image *) NULL)
6372 cache_image=undo_image;
6373 undo_image=GetPreviousImageInList(undo_image);
6374 cache_image->list=DestroyImage(cache_image->list);
6375 cache_image=DestroyImage(cache_image);
6377 undo_image=NewImageList();
6378 if (redo_image != (Image *) NULL)
6379 redo_image=DestroyImage(redo_image);
6380 redo_image=NewImageList();
6386 image_geometry[MaxTextExtent];
6391 if (undo_image == (Image *) NULL)
6393 (void) XBell(display,0);
6394 ThrowXWindowException(ImageError,
"NoImagesWereFound",
6395 (*image)->filename);
6398 cache_image=undo_image;
6399 undo_image=GetPreviousImageInList(undo_image);
6400 windows->image.window_changes.width=(int) cache_image->columns;
6401 windows->image.window_changes.height=(int) cache_image->rows;
6402 (void) FormatLocaleString(image_geometry,MaxTextExtent,
"%dx%d!",
6403 windows->image.ximage->width,windows->image.ximage->height);
6404 (void) TransformImage(image,windows->image.crop_geometry,image_geometry);
6405 if (windows->image.crop_geometry != (
char *) NULL)
6406 windows->image.crop_geometry=(
char *)
6407 RelinquishMagickMemory(windows->image.crop_geometry);
6408 windows->image.crop_geometry=cache_image->geometry;
6409 if (redo_image != (Image *) NULL)
6410 redo_image=DestroyImage(redo_image);
6411 redo_image=(*image);
6412 *image=cache_image->list;
6413 cache_image=DestroyImage(cache_image);
6414 if (windows->image.orphan != MagickFalse)
6416 XConfigureImageColormap(display,resource_info,windows,*image);
6417 (void) XConfigureImage(display,resource_info,windows,*image);
6423 case HalfSizeCommand:
6424 case OriginalSizeCommand:
6425 case DoubleSizeCommand:
6432 case RotateRightCommand:
6433 case RotateLeftCommand:
6438 case ContrastStretchCommand:
6439 case SigmoidalContrastCommand:
6440 case NormalizeCommand:
6441 case EqualizeCommand:
6443 case SaturationCommand:
6444 case BrightnessCommand:
6448 case GrayscaleCommand:
6450 case QuantizeCommand:
6451 case DespeckleCommand:
6453 case ReduceNoiseCommand:
6454 case AddNoiseCommand:
6455 case SharpenCommand:
6457 case ThresholdCommand:
6458 case EdgeDetectCommand:
6462 case SegmentCommand:
6463 case SolarizeCommand:
6464 case SepiaToneCommand:
6466 case ImplodeCommand:
6467 case VignetteCommand:
6469 case OilPaintCommand:
6470 case CharcoalDrawCommand:
6471 case AnnotateCommand:
6472 case AddBorderCommand:
6473 case AddFrameCommand:
6474 case CompositeCommand:
6475 case CommentCommand:
6477 case RegionOfInterestCommand:
6478 case SaveToUndoBufferCommand:
6487 bytes=(ssize_t) ((*image)->columns*(*image)->rows*
sizeof(PixelPacket));
6488 if (undo_image != (Image *) NULL)
6493 previous_image=undo_image;
6494 while (previous_image != (Image *) NULL)
6496 bytes+=previous_image->list->columns*previous_image->list->rows*
6497 sizeof(PixelPacket);
6498 if (bytes <= (ssize_t) (resource_info->undo_cache << 20))
6500 previous_image=GetPreviousImageInList(previous_image);
6503 bytes-=previous_image->list->columns*previous_image->list->rows*
6504 sizeof(PixelPacket);
6505 if (previous_image == undo_image)
6506 undo_image=NewImageList();
6508 previous_image->next->previous=NewImageList();
6511 while (previous_image != (Image *) NULL)
6516 cache_image=previous_image;
6517 previous_image=GetPreviousImageInList(previous_image);
6518 cache_image->list=DestroyImage(cache_image->list);
6519 cache_image=DestroyImage(cache_image);
6522 if (bytes > (ssize_t) (resource_info->undo_cache << 20))
6527 cache_image=AcquireImage((ImageInfo *) NULL);
6528 if (cache_image == (Image *) NULL)
6530 XSetCursorState(display,windows,MagickTrue);
6531 XCheckRefreshWindows(display,windows);
6532 cache_image->list=CloneImage(*image,0,0,MagickTrue,&(*image)->exception);
6533 XSetCursorState(display,windows,MagickFalse);
6534 if (cache_image->list == (Image *) NULL)
6536 cache_image=DestroyImage(cache_image);
6539 cache_image->columns=(size_t) windows->image.ximage->width;
6540 cache_image->rows=(size_t) windows->image.ximage->height;
6541 cache_image->geometry=windows->image.crop_geometry;
6542 if (windows->image.crop_geometry != (
char *) NULL)
6544 cache_image->geometry=AcquireString((
char *) NULL);
6545 (void) CopyMagickString(cache_image->geometry,
6546 windows->image.crop_geometry,MaxTextExtent);
6548 if (undo_image == (Image *) NULL)
6550 undo_image=cache_image;
6553 undo_image->next=cache_image;
6554 undo_image->next->previous=undo_image;
6555 undo_image=undo_image->next;
6561 if (command == RedoCommand)
6566 if (redo_image == (Image *) NULL)
6568 (void) XBell(display,0);
6571 windows->image.window_changes.width=(int) redo_image->columns;
6572 windows->image.window_changes.height=(int) redo_image->rows;
6573 if (windows->image.crop_geometry != (
char *) NULL)
6574 windows->image.crop_geometry=(
char *)
6575 RelinquishMagickMemory(windows->image.crop_geometry);
6576 windows->image.crop_geometry=redo_image->geometry;
6577 *image=DestroyImage(*image);
6579 redo_image=NewImageList();
6580 if (windows->image.orphan != MagickFalse)
6582 XConfigureImageColormap(display,resource_info,windows,*image);
6583 (void) XConfigureImage(display,resource_info,windows,*image);
6586 if (command != InfoCommand)
6591 XSetCursorState(display,windows,MagickTrue);
6592 XCheckRefreshWindows(display,windows);
6593 XDisplayImageInfo(display,resource_info,windows,undo_image,*image);
6594 XSetCursorState(display,windows,MagickFalse);
6638static DisplayCommand XImageWindowCommand(Display *display,
6639 XResourceInfo *resource_info,XWindows *windows,
const MagickStatusType state,
6640 KeySym key_symbol,Image **image)
6643 delta[MaxTextExtent+1] =
"";
6646 Digits[] =
"01234567890";
6651 if ((key_symbol >= XK_0) && (key_symbol <= XK_9))
6656 if (((last_symbol < XK_0) || (last_symbol > XK_9)))
6659 resource_info->quantum=1;
6661 last_symbol=key_symbol;
6662 length=strlen(delta);
6663 if (length < MagickPathExtent)
6665 delta[length]=Digits[key_symbol-XK_0];
6666 delta[length+1]=
'\0';
6668 resource_info->quantum=StringToLong(delta);
6669 return(NullCommand);
6671 last_symbol=key_symbol;
6672 if (resource_info->immutable)
6680 return(InfoCommand);
6683 return(PrintCommand);
6685 return(NextCommand);
6688 return(QuitCommand);
6692 return(NullCommand);
6694 switch ((
int) key_symbol)
6698 if ((state & ControlMask) == 0)
6700 return(OpenCommand);
6703 return(NextCommand);
6705 return(FormerCommand);
6708 if ((state & Mod1Mask) != 0)
6709 return(SwirlCommand);
6710 if ((state & ControlMask) == 0)
6711 return(ShearCommand);
6712 return(SaveCommand);
6717 if ((state & Mod1Mask) != 0)
6718 return(OilPaintCommand);
6719 if ((state & Mod4Mask) != 0)
6720 return(ColorCommand);
6721 if ((state & ControlMask) == 0)
6722 return(NullCommand);
6723 return(PrintCommand);
6727 if ((state & Mod4Mask) != 0)
6728 return(DrawCommand);
6729 if ((state & ControlMask) == 0)
6730 return(NullCommand);
6731 return(DeleteCommand);
6735 if ((state & ControlMask) == 0)
6736 return(NullCommand);
6737 return(SelectCommand);
6741 if ((state & ControlMask) == 0)
6742 return(NullCommand);
6747 return(QuitCommand);
6751 if ((state & ControlMask) == 0)
6752 return(NullCommand);
6753 return(UndoCommand);
6758 if ((state & ControlMask) == 0)
6759 return(RollCommand);
6760 return(RedoCommand);
6764 if ((state & ControlMask) == 0)
6765 return(NullCommand);
6770 if ((state & Mod1Mask) != 0)
6771 return(CharcoalDrawCommand);
6772 if ((state & ControlMask) == 0)
6773 return(CropCommand);
6774 return(CopyCommand);
6779 if ((state & Mod4Mask) != 0)
6780 return(CompositeCommand);
6781 if ((state & ControlMask) == 0)
6782 return(FlipCommand);
6783 return(PasteCommand);
6786 return(HalfSizeCommand);
6788 return(OriginalSizeCommand);
6790 return(DoubleSizeCommand);
6792 return(ResizeCommand);
6794 return(RefreshCommand);
6795 case XK_bracketleft:
6796 return(ChopCommand);
6798 return(FlopCommand);
6800 return(RotateRightCommand);
6802 return(RotateLeftCommand);
6804 return(RotateCommand);
6806 return(TrimCommand);
6810 return(SaturationCommand);
6812 return(BrightnessCommand);
6814 return(GammaCommand);
6816 return(SpiffCommand);
6818 return(DullCommand);
6820 return(NormalizeCommand);
6822 return(EqualizeCommand);
6824 return(NegateCommand);
6826 return(GrayscaleCommand);
6828 return(QuantizeCommand);
6830 return(DespeckleCommand);
6832 return(EmbossCommand);
6834 return(ReduceNoiseCommand);
6836 return(AddNoiseCommand);
6838 return(SharpenCommand);
6840 return(BlurCommand);
6842 return(ThresholdCommand);
6844 return(EdgeDetectCommand);
6846 return(SpreadCommand);
6848 return(ShadeCommand);
6850 return(RaiseCommand);
6852 return(SegmentCommand);
6855 if ((state & Mod1Mask) == 0)
6856 return(NullCommand);
6857 return(ImplodeCommand);
6861 if ((state & Mod1Mask) == 0)
6862 return(NullCommand);
6863 return(WaveCommand);
6867 if ((state & Mod4Mask) == 0)
6868 return(NullCommand);
6869 return(MatteCommand);
6873 if ((state & Mod4Mask) == 0)
6874 return(NullCommand);
6875 return(AddBorderCommand);
6879 if ((state & Mod4Mask) == 0)
6880 return(NullCommand);
6881 return(AddFrameCommand);
6885 if ((state & Mod4Mask) == 0)
6886 return(NullCommand);
6887 return(CommentCommand);
6891 if ((state & Mod1Mask) != 0)
6892 return(ApplyCommand);
6893 if ((state & Mod4Mask) != 0)
6894 return(AnnotateCommand);
6895 if ((state & ControlMask) == 0)
6896 return(NullCommand);
6897 return(RegionOfInterestCommand);
6900 return(InfoCommand);
6902 return(ZoomCommand);
6905 if ((state & ShiftMask) == 0)
6906 return(NullCommand);
6907 return(ShowPreviewCommand);
6910 return(LaunchCommand);
6912 return(HelpCommand);
6914 return(BrowseDocumentationCommand);
6917 (void) XMapRaised(display,windows->command.id);
6918 return(NullCommand);
6925 XTranslateImage(display,windows,*image,key_symbol);
6926 return(NullCommand);
6937 if ((state & Mod1Mask) != 0)
6947 crop_info.width=(size_t) windows->image.ximage->width;
6948 crop_info.height=(size_t) windows->image.ximage->height;
6949 if ((key_symbol == XK_Up) || (key_symbol == XK_KP_Up))
6951 if (resource_info->quantum >= (
int) crop_info.height)
6952 resource_info->quantum=(int) crop_info.height-1;
6953 crop_info.height-=resource_info->quantum;
6955 if ((key_symbol == XK_Down) || (key_symbol == XK_KP_Down))
6957 if (resource_info->quantum >= (
int) (crop_info.height-crop_info.y))
6958 resource_info->quantum=(int) (crop_info.height-crop_info.y-1);
6959 crop_info.y+=resource_info->quantum;
6960 crop_info.height-=resource_info->quantum;
6962 if ((key_symbol == XK_Left) || (key_symbol == XK_KP_Left))
6964 if (resource_info->quantum >= (
int) crop_info.width)
6965 resource_info->quantum=(int) crop_info.width-1;
6966 crop_info.width-=resource_info->quantum;
6968 if ((key_symbol == XK_Right) || (key_symbol == XK_KP_Right))
6970 if (resource_info->quantum >= (
int) (crop_info.width-crop_info.x))
6971 resource_info->quantum=(int) (crop_info.width-crop_info.x-1);
6972 crop_info.x+=resource_info->quantum;
6973 crop_info.width-=resource_info->quantum;
6975 if ((
int) (windows->image.x+windows->image.width) >
6976 (
int) crop_info.width)
6977 windows->image.x=(int) (crop_info.width-windows->image.width);
6978 if ((
int) (windows->image.y+windows->image.height) >
6979 (
int) crop_info.height)
6980 windows->image.y=(int) (crop_info.height-windows->image.height);
6981 XSetCropGeometry(display,windows,&crop_info,*image);
6982 windows->image.window_changes.width=(int) crop_info.width;
6983 windows->image.window_changes.height=(int) crop_info.height;
6984 (void) XSetWindowBackgroundPixmap(display,windows->image.id,None);
6985 (void) XConfigureImage(display,resource_info,windows,*image);
6986 return(NullCommand);
6988 XTranslateImage(display,windows,*image,key_symbol);
6989 return(NullCommand);
6992 return(NullCommand);
6994 return(NullCommand);
7035static Image *XMagickCommand(Display *display,XResourceInfo *resource_info,
7036 XWindows *windows,
const DisplayCommand command,Image **image)
7039 filename[MaxTextExtent],
7040 geometry[MaxTextExtent],
7041 modulate_factors[MaxTextExtent];
7070 color[MaxTextExtent] =
"gray";
7079 XCheckRefreshWindows(display,windows);
7080 XImageCache(display,resource_info,windows,command,image);
7081 nexus=NewImageList();
7082 windows->image.window_changes.width=windows->image.ximage->width;
7083 windows->image.window_changes.height=windows->image.ximage->height;
7084 image_info=CloneImageInfo(resource_info->image_info);
7085 SetGeometryInfo(&geometry_info);
7086 GetQuantizeInfo(&quantize_info);
7094 nexus=XOpenImage(display,resource_info,windows,MagickFalse);
7102 for (i=0; i < resource_info->quantum; i++)
7103 XClientMessage(display,windows->image.id,windows->im_protocols,
7104 windows->im_next_image,CurrentTime);
7112 for (i=0; i < resource_info->quantum; i++)
7113 XClientMessage(display,windows->image.id,windows->im_protocols,
7114 windows->im_former_image,CurrentTime);
7125 if (*resource_info->home_directory ==
'\0')
7126 (void) CopyMagickString(resource_info->home_directory,
".",
7128 status=chdir(resource_info->home_directory);
7130 (void) ThrowMagickException(&(*image)->exception,GetMagickModule(),
7131 FileOpenError,
"UnableToOpenFile",
"%s",resource_info->home_directory);
7132 nexus=XOpenImage(display,resource_info,windows,MagickTrue);
7140 status=XSaveImage(display,resource_info,windows,*image);
7141 if (status == MagickFalse)
7144 message[MaxTextExtent];
7146 (void) FormatLocaleString(message,MaxTextExtent,
"%s:%s",
7147 (*image)->exception.reason != (
char *) NULL ?
7148 (*image)->exception.reason :
"",
7149 (*image)->exception.description != (
char *) NULL ?
7150 (*image)->exception.description :
"");
7151 XNoticeWidget(display,windows,
"Unable to save file:",message);
7161 status=XPrintImage(display,resource_info,windows,*image);
7162 if (status == MagickFalse)
7165 message[MaxTextExtent];
7167 (void) FormatLocaleString(message,MaxTextExtent,
"%s:%s",
7168 (*image)->exception.reason != (
char *) NULL ?
7169 (*image)->exception.reason :
"",
7170 (*image)->exception.description != (
char *) NULL ?
7171 (*image)->exception.description :
"");
7172 XNoticeWidget(display,windows,
"Unable to print file:",message);
7180 filename[MaxTextExtent] =
"\0";
7185 XFileBrowserWidget(display,windows,
"Delete",filename);
7186 if (*filename ==
'\0')
7188 status=ShredFile(filename);
7189 status|=remove_utf8(filename);
7190 if (status != MagickFalse)
7191 XNoticeWidget(display,windows,
"Unable to delete image file:",filename);
7200 color[MaxTextExtent] =
"gray",
7201 geometry[MaxTextExtent] =
"640x480";
7204 *format =
"gradient";
7209 status=XDialogWidget(display,windows,
"New",
"Enter image geometry:",
7211 if (*geometry ==
'\0')
7215 XColorBrowserWidget(display,windows,
"Select",color);
7221 (void) FormatLocaleString(image_info->filename,MaxTextExtent,
7222 "%s:%s",format,color);
7223 (void) CloneString(&image_info->size,geometry);
7224 nexus=ReadImage(image_info,&(*image)->exception);
7225 CatchException(&(*image)->exception);
7226 XClientMessage(display,windows->image.id,windows->im_protocols,
7227 windows->im_next_image,CurrentTime);
7230 case VisualDirectoryCommand:
7235 nexus=XVisualDirectoryImage(display,resource_info,windows);
7243 if (resource_info->confirm_exit == MagickFalse)
7244 XClientMessage(display,windows->image.id,windows->im_protocols,
7245 windows->im_exit,CurrentTime);
7254 status=XConfirmWidget(display,windows,
"Do you really want to exit",
7255 resource_info->client_name);
7257 XClientMessage(display,windows->image.id,windows->im_protocols,
7258 windows->im_exit,CurrentTime);
7267 (void) XCropImage(display,resource_info,windows,*image,CutMode);
7275 (void) XCropImage(display,resource_info,windows,*image,CopyMode);
7283 status=XPasteImage(display,resource_info,windows,*image);
7284 if (status == MagickFalse)
7286 XNoticeWidget(display,windows,
"Unable to paste X image",
7287 (*image)->filename);
7292 case HalfSizeCommand:
7297 windows->image.window_changes.width=windows->image.ximage->width/2;
7298 windows->image.window_changes.height=windows->image.ximage->height/2;
7299 (void) XConfigureImage(display,resource_info,windows,*image);
7302 case OriginalSizeCommand:
7307 windows->image.window_changes.width=(int) (*image)->columns;
7308 windows->image.window_changes.height=(int) (*image)->rows;
7309 (void) XConfigureImage(display,resource_info,windows,*image);
7312 case DoubleSizeCommand:
7317 windows->image.window_changes.width=windows->image.ximage->width << 1;
7318 windows->image.window_changes.height=windows->image.ximage->height << 1;
7319 (void) XConfigureImage(display,resource_info,windows,*image);
7338 width=(size_t) windows->image.ximage->width;
7339 height=(size_t) windows->image.ximage->height;
7342 (void) FormatLocaleString(geometry,MaxTextExtent,
"%.20gx%.20g+0+0",
7343 (
double) width,(
double) height);
7344 status=XDialogWidget(display,windows,
"Resize",
7345 "Enter resize geometry (e.g. 640x480, 200%):",geometry);
7346 if (*geometry ==
'\0')
7349 (void) ConcatenateMagickString(geometry,
"!",MaxTextExtent);
7350 (void) ParseMetaGeometry(geometry,&x,&y,&width,&height);
7351 windows->image.window_changes.width=(int) width;
7352 windows->image.window_changes.height=(int) height;
7353 (void) XConfigureImage(display,resource_info,windows,*image);
7359 image_geometry[MaxTextExtent];
7361 if ((windows->image.crop_geometry == (
char *) NULL) &&
7362 ((
int) (*image)->columns == windows->image.ximage->width) &&
7363 ((
int) (*image)->rows == windows->image.ximage->height))
7368 XSetCursorState(display,windows,MagickTrue);
7369 XCheckRefreshWindows(display,windows);
7373 (void) FormatLocaleString(image_geometry,MaxTextExtent,
"%dx%d!",
7374 windows->image.ximage->width,windows->image.ximage->height);
7375 (void) TransformImage(image,windows->image.crop_geometry,image_geometry);
7376 if (windows->image.crop_geometry != (
char *) NULL)
7377 windows->image.crop_geometry=(
char *)
7378 RelinquishMagickMemory(windows->image.crop_geometry);
7381 XConfigureImageColormap(display,resource_info,windows,*image);
7382 (void) XConfigureImage(display,resource_info,windows,*image);
7385 case RefreshCommand:
7387 (void) XConfigureImage(display,resource_info,windows,*image);
7390 case RestoreCommand:
7395 if ((windows->image.width == (
unsigned int) (*image)->columns) &&
7396 (windows->image.height == (
unsigned int) (*image)->rows) &&
7397 (windows->image.crop_geometry == (
char *) NULL))
7399 (void) XBell(display,0);
7402 windows->image.window_changes.width=(int) (*image)->columns;
7403 windows->image.window_changes.height=(int) (*image)->rows;
7404 if (windows->image.crop_geometry != (
char *) NULL)
7406 windows->image.crop_geometry=(
char *)
7407 RelinquishMagickMemory(windows->image.crop_geometry);
7408 windows->image.crop_geometry=(
char *) NULL;
7412 XConfigureImageColormap(display,resource_info,windows,*image);
7413 (void) XConfigureImage(display,resource_info,windows,*image);
7421 (void) XCropImage(display,resource_info,windows,*image,CropMode);
7429 status=XChopImage(display,resource_info,windows,image);
7430 if (status == MagickFalse)
7432 XNoticeWidget(display,windows,
"Unable to cut X image",
7433 (*image)->filename);
7446 XSetCursorState(display,windows,MagickTrue);
7447 XCheckRefreshWindows(display,windows);
7448 flop_image=FlopImage(*image,&(*image)->exception);
7449 if (flop_image != (Image *) NULL)
7451 *image=DestroyImage(*image);
7454 CatchException(&(*image)->exception);
7455 XSetCursorState(display,windows,MagickFalse);
7456 if (windows->image.crop_geometry != (
char *) NULL)
7461 width=(
unsigned int) (*image)->columns;
7462 height=(
unsigned int) (*image)->rows;
7463 (void) XParseGeometry(windows->image.crop_geometry,&x,&y,
7465 (void) FormatLocaleString(windows->image.crop_geometry,MaxTextExtent,
7466 "%ux%u%+d%+d",width,height,(
int) (*image)->columns-(
int) width-x,y);
7468 if (windows->image.orphan != MagickFalse)
7470 (void) XConfigureImage(display,resource_info,windows,*image);
7481 XSetCursorState(display,windows,MagickTrue);
7482 XCheckRefreshWindows(display,windows);
7483 flip_image=FlipImage(*image,&(*image)->exception);
7484 if (flip_image != (Image *) NULL)
7486 *image=DestroyImage(*image);
7489 CatchException(&(*image)->exception);
7490 XSetCursorState(display,windows,MagickFalse);
7491 if (windows->image.crop_geometry != (
char *) NULL)
7496 width=(
unsigned int) (*image)->columns;
7497 height=(
unsigned int) (*image)->rows;
7498 (void) XParseGeometry(windows->image.crop_geometry,&x,&y,
7500 (void) FormatLocaleString(windows->image.crop_geometry,MaxTextExtent,
7501 "%ux%u%+d%+d",width,height,x,(
int) (*image)->rows-(
int) height-y);
7503 if (windows->image.orphan != MagickFalse)
7505 (void) XConfigureImage(display,resource_info,windows,*image);
7508 case RotateRightCommand:
7513 status=XRotateImage(display,resource_info,windows,90.0,image);
7514 if (status == MagickFalse)
7516 XNoticeWidget(display,windows,
"Unable to rotate X image",
7517 (*image)->filename);
7522 case RotateLeftCommand:
7527 status=XRotateImage(display,resource_info,windows,-90.0,image);
7528 if (status == MagickFalse)
7530 XNoticeWidget(display,windows,
"Unable to rotate X image",
7531 (*image)->filename);
7541 status=XRotateImage(display,resource_info,windows,0.0,image);
7542 if (status == MagickFalse)
7544 XNoticeWidget(display,windows,
"Unable to rotate X image",
7545 (*image)->filename);
7556 geometry[MaxTextExtent] =
"45.0x45.0";
7561 XColorBrowserWidget(display,windows,
"Select",color);
7564 (void) XDialogWidget(display,windows,
"Shear",
"Enter shear geometry:",
7566 if (*geometry ==
'\0')
7571 (void) XMagickCommand(display,resource_info,windows,ApplyCommand,image);
7572 XSetCursorState(display,windows,MagickTrue);
7573 XCheckRefreshWindows(display,windows);
7574 (void) QueryColorDatabase(color,&(*image)->background_color,
7575 &(*image)->exception);
7576 flags=ParseGeometry(geometry,&geometry_info);
7577 if ((flags & SigmaValue) == 0)
7578 geometry_info.sigma=geometry_info.rho;
7579 shear_image=ShearImage(*image,geometry_info.rho,geometry_info.sigma,
7580 &(*image)->exception);
7581 if (shear_image != (Image *) NULL)
7583 *image=DestroyImage(*image);
7586 CatchException(&(*image)->exception);
7587 XSetCursorState(display,windows,MagickFalse);
7588 if (windows->image.orphan != MagickFalse)
7590 windows->image.window_changes.width=(int) (*image)->columns;
7591 windows->image.window_changes.height=(int) (*image)->rows;
7592 XConfigureImageColormap(display,resource_info,windows,*image);
7593 (void) XConfigureImage(display,resource_info,windows,*image);
7602 geometry[MaxTextExtent] =
"+2+2";
7607 (void) XDialogWidget(display,windows,
"Roll",
"Enter roll geometry:",
7609 if (*geometry ==
'\0')
7614 (void) XMagickCommand(display,resource_info,windows,ApplyCommand,image);
7615 XSetCursorState(display,windows,MagickTrue);
7616 XCheckRefreshWindows(display,windows);
7617 (void) ParsePageGeometry(*image,geometry,&page_geometry,
7618 &(*image)->exception);
7619 roll_image=RollImage(*image,page_geometry.x,page_geometry.y,
7620 &(*image)->exception);
7621 if (roll_image != (Image *) NULL)
7623 *image=DestroyImage(*image);
7626 CatchException(&(*image)->exception);
7627 XSetCursorState(display,windows,MagickFalse);
7628 if (windows->image.orphan != MagickFalse)
7630 windows->image.window_changes.width=(int) (*image)->columns;
7631 windows->image.window_changes.height=(int) (*image)->rows;
7632 XConfigureImageColormap(display,resource_info,windows,*image);
7633 (void) XConfigureImage(display,resource_info,windows,*image);
7639 fuzz[MaxTextExtent];
7644 (void) FormatLocaleString(fuzz,MaxTextExtent,
"%g%%",100.0*
7645 (*image)->fuzz/((
double) QuantumRange+1.0));
7646 (void) XDialogWidget(display,windows,
"Trim",
"Enter fuzz factor:",fuzz);
7649 (*image)->fuzz=StringToDoubleInterval(fuzz,(
double) QuantumRange+1.0);
7653 status=XTrimImage(display,resource_info,windows,*image);
7654 if (status == MagickFalse)
7656 XNoticeWidget(display,windows,
"Unable to trim X image",
7657 (*image)->filename);
7665 hue_percent[MaxTextExtent] =
"110";
7670 (void) XDialogWidget(display,windows,
"Apply",
7671 "Enter percent change in image hue (0-200):",hue_percent);
7672 if (*hue_percent ==
'\0')
7677 XSetCursorState(display,windows,MagickTrue);
7678 XCheckRefreshWindows(display,windows);
7679 (void) CopyMagickString(modulate_factors,
"100.0/100.0/",MaxTextExtent);
7680 (void) ConcatenateMagickString(modulate_factors,hue_percent,
7682 (void) ModulateImage(*image,modulate_factors);
7683 XSetCursorState(display,windows,MagickFalse);
7684 if (windows->image.orphan != MagickFalse)
7686 XConfigureImageColormap(display,resource_info,windows,*image);
7687 (void) XConfigureImage(display,resource_info,windows,*image);
7690 case SaturationCommand:
7693 saturation_percent[MaxTextExtent] =
"110";
7698 (void) XDialogWidget(display,windows,
"Apply",
7699 "Enter percent change in color saturation (0-200):",saturation_percent);
7700 if (*saturation_percent ==
'\0')
7705 XSetCursorState(display,windows,MagickTrue);
7706 XCheckRefreshWindows(display,windows);
7707 (void) CopyMagickString(modulate_factors,
"100.0/",MaxTextExtent);
7708 (void) ConcatenateMagickString(modulate_factors,saturation_percent,
7710 (void) ModulateImage(*image,modulate_factors);
7711 XSetCursorState(display,windows,MagickFalse);
7712 if (windows->image.orphan != MagickFalse)
7714 XConfigureImageColormap(display,resource_info,windows,*image);
7715 (void) XConfigureImage(display,resource_info,windows,*image);
7718 case BrightnessCommand:
7721 brightness_percent[MaxTextExtent] =
"110";
7726 (void) XDialogWidget(display,windows,
"Apply",
7727 "Enter percent change in color brightness (0-200):",brightness_percent);
7728 if (*brightness_percent ==
'\0')
7733 XSetCursorState(display,windows,MagickTrue);
7734 XCheckRefreshWindows(display,windows);
7735 (void) CopyMagickString(modulate_factors,brightness_percent,
7737 (void) ModulateImage(*image,modulate_factors);
7738 XSetCursorState(display,windows,MagickFalse);
7739 if (windows->image.orphan != MagickFalse)
7741 XConfigureImageColormap(display,resource_info,windows,*image);
7742 (void) XConfigureImage(display,resource_info,windows,*image);
7748 factor[MaxTextExtent] =
"1.6";
7753 (void) XDialogWidget(display,windows,
"Gamma",
7754 "Enter gamma value (e.g. 1.0,1.0,1.6):",factor);
7755 if (*factor ==
'\0')
7760 XSetCursorState(display,windows,MagickTrue);
7761 XCheckRefreshWindows(display,windows);
7762 (void) GammaImage(*image,factor);
7763 XSetCursorState(display,windows,MagickFalse);
7764 if (windows->image.orphan != MagickFalse)
7766 XConfigureImageColormap(display,resource_info,windows,*image);
7767 (void) XConfigureImage(display,resource_info,windows,*image);
7775 XSetCursorState(display,windows,MagickTrue);
7776 XCheckRefreshWindows(display,windows);
7777 (void) ContrastImage(*image,MagickTrue);
7778 XSetCursorState(display,windows,MagickFalse);
7779 if (windows->image.orphan != MagickFalse)
7781 XConfigureImageColormap(display,resource_info,windows,*image);
7782 (void) XConfigureImage(display,resource_info,windows,*image);
7790 XSetCursorState(display,windows,MagickTrue);
7791 XCheckRefreshWindows(display,windows);
7792 (void) ContrastImage(*image,MagickFalse);
7793 XSetCursorState(display,windows,MagickFalse);
7794 if (windows->image.orphan != MagickFalse)
7796 XConfigureImageColormap(display,resource_info,windows,*image);
7797 (void) XConfigureImage(display,resource_info,windows,*image);
7800 case ContrastStretchCommand:
7807 levels[MaxTextExtent] =
"1%";
7812 (void) XDialogWidget(display,windows,
"Contrast Stretch",
7813 "Enter black and white points:",levels);
7814 if (*levels ==
'\0')
7819 XSetCursorState(display,windows,MagickTrue);
7820 XCheckRefreshWindows(display,windows);
7821 flags=ParseGeometry(levels,&geometry_info);
7822 black_point=geometry_info.rho;
7823 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma : black_point;
7824 if ((flags & PercentValue) != 0)
7826 black_point*=(double) (*image)->columns*(*image)->rows/100.0;
7827 white_point*=(double) (*image)->columns*(*image)->rows/100.0;
7829 white_point=(MagickRealType) (*image)->columns*(*image)->rows-white_point;
7830 (void) ContrastStretchImageChannel(*image,DefaultChannels,black_point,
7832 XSetCursorState(display,windows,MagickFalse);
7833 if (windows->image.orphan != MagickFalse)
7835 XConfigureImageColormap(display,resource_info,windows,*image);
7836 (void) XConfigureImage(display,resource_info,windows,*image);
7839 case SigmoidalContrastCommand:
7842 levels[MaxTextExtent] =
"3x50%";
7847 (void) XDialogWidget(display,windows,
"Sigmoidal Contrast",
7848 "Enter contrast and midpoint:",levels);
7849 if (*levels ==
'\0')
7854 XSetCursorState(display,windows,MagickTrue);
7855 XCheckRefreshWindows(display,windows);
7856 (void) SigmoidalContrastImage(*image,MagickTrue,levels);
7857 XSetCursorState(display,windows,MagickFalse);
7858 if (windows->image.orphan != MagickFalse)
7860 XConfigureImageColormap(display,resource_info,windows,*image);
7861 (void) XConfigureImage(display,resource_info,windows,*image);
7864 case NormalizeCommand:
7869 XSetCursorState(display,windows,MagickTrue);
7870 XCheckRefreshWindows(display,windows);
7871 (void) NormalizeImage(*image);
7872 XSetCursorState(display,windows,MagickFalse);
7873 if (windows->image.orphan != MagickFalse)
7875 XConfigureImageColormap(display,resource_info,windows,*image);
7876 (void) XConfigureImage(display,resource_info,windows,*image);
7879 case EqualizeCommand:
7884 XSetCursorState(display,windows,MagickTrue);
7885 XCheckRefreshWindows(display,windows);
7886 (void) EqualizeImage(*image);
7887 XSetCursorState(display,windows,MagickFalse);
7888 if (windows->image.orphan != MagickFalse)
7890 XConfigureImageColormap(display,resource_info,windows,*image);
7891 (void) XConfigureImage(display,resource_info,windows,*image);
7899 XSetCursorState(display,windows,MagickTrue);
7900 XCheckRefreshWindows(display,windows);
7901 (void) NegateImage(*image,MagickFalse);
7902 XSetCursorState(display,windows,MagickFalse);
7903 if (windows->image.orphan != MagickFalse)
7905 XConfigureImageColormap(display,resource_info,windows,*image);
7906 (void) XConfigureImage(display,resource_info,windows,*image);
7909 case GrayscaleCommand:
7914 XSetCursorState(display,windows,MagickTrue);
7915 XCheckRefreshWindows(display,windows);
7916 (void) SetImageType(*image,(*image)->matte == MagickFalse ?
7917 GrayscaleType : GrayscaleMatteType);
7918 XSetCursorState(display,windows,MagickFalse);
7919 if (windows->image.orphan != MagickFalse)
7921 XConfigureImageColormap(display,resource_info,windows,*image);
7922 (void) XConfigureImage(display,resource_info,windows,*image);
7931 filename[MaxTextExtent] =
"\0";
7936 XFileBrowserWidget(display,windows,
"Map",filename);
7937 if (*filename ==
'\0')
7942 XSetCursorState(display,windows,MagickTrue);
7943 XCheckRefreshWindows(display,windows);
7944 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
7945 affinity_image=ReadImage(image_info,&(*image)->exception);
7946 if (affinity_image != (Image *) NULL)
7948 (void) RemapImage(&quantize_info,*image,affinity_image);
7949 affinity_image=DestroyImage(affinity_image);
7951 CatchException(&(*image)->exception);
7952 XSetCursorState(display,windows,MagickFalse);
7953 if (windows->image.orphan != MagickFalse)
7955 XConfigureImageColormap(display,resource_info,windows,*image);
7956 (void) XConfigureImage(display,resource_info,windows,*image);
7959 case QuantizeCommand:
7965 colors[MaxTextExtent] =
"256";
7970 status=XDialogWidget(display,windows,
"Quantize",
7971 "Maximum number of colors:",colors);
7972 if (*colors ==
'\0')
7977 XSetCursorState(display,windows,MagickTrue);
7978 XCheckRefreshWindows(display,windows);
7979 quantize_info.number_colors=StringToUnsignedLong(colors);
7980 quantize_info.dither=status != 0 ? MagickTrue : MagickFalse;
7981 (void) QuantizeImage(&quantize_info,*image);
7982 XSetCursorState(display,windows,MagickFalse);
7983 if (windows->image.orphan != MagickFalse)
7985 XConfigureImageColormap(display,resource_info,windows,*image);
7986 (void) XConfigureImage(display,resource_info,windows,*image);
7989 case DespeckleCommand:
7997 XSetCursorState(display,windows,MagickTrue);
7998 XCheckRefreshWindows(display,windows);
7999 despeckle_image=DespeckleImage(*image,&(*image)->exception);
8000 if (despeckle_image != (Image *) NULL)
8002 *image=DestroyImage(*image);
8003 *image=despeckle_image;
8005 CatchException(&(*image)->exception);
8006 XSetCursorState(display,windows,MagickFalse);
8007 if (windows->image.orphan != MagickFalse)
8009 XConfigureImageColormap(display,resource_info,windows,*image);
8010 (void) XConfigureImage(display,resource_info,windows,*image);
8019 radius[MaxTextExtent] =
"0.0x1.0";
8024 (void) XDialogWidget(display,windows,
"Emboss",
8025 "Enter the emboss radius and standard deviation:",radius);
8026 if (*radius ==
'\0')
8031 XSetCursorState(display,windows,MagickTrue);
8032 XCheckRefreshWindows(display,windows);
8033 flags=ParseGeometry(radius,&geometry_info);
8034 if ((flags & SigmaValue) == 0)
8035 geometry_info.sigma=1.0;
8036 emboss_image=EmbossImage(*image,geometry_info.rho,geometry_info.sigma,
8037 &(*image)->exception);
8038 if (emboss_image != (Image *) NULL)
8040 *image=DestroyImage(*image);
8041 *image=emboss_image;
8043 CatchException(&(*image)->exception);
8044 XSetCursorState(display,windows,MagickFalse);
8045 if (windows->image.orphan != MagickFalse)
8047 XConfigureImageColormap(display,resource_info,windows,*image);
8048 (void) XConfigureImage(display,resource_info,windows,*image);
8051 case ReduceNoiseCommand:
8057 radius[MaxTextExtent] =
"0";
8062 (void) XDialogWidget(display,windows,
"Reduce Noise",
8063 "Enter the noise radius:",radius);
8064 if (*radius ==
'\0')
8069 XSetCursorState(display,windows,MagickTrue);
8070 XCheckRefreshWindows(display,windows);
8071 flags=ParseGeometry(radius,&geometry_info);
8072 noise_image=StatisticImage(*image,NonpeakStatistic,(
size_t)
8073 geometry_info.rho,(
size_t) geometry_info.rho,&(*image)->exception);
8074 if (noise_image != (Image *) NULL)
8076 *image=DestroyImage(*image);
8079 CatchException(&(*image)->exception);
8080 XSetCursorState(display,windows,MagickFalse);
8081 if (windows->image.orphan != MagickFalse)
8083 XConfigureImageColormap(display,resource_info,windows,*image);
8084 (void) XConfigureImage(display,resource_info,windows,*image);
8087 case AddNoiseCommand:
8096 noise_type[MaxTextExtent] =
"Gaussian";
8101 noises=GetCommandOptions(MagickNoiseOptions);
8102 if (noises == (
char **) NULL)
8104 XListBrowserWidget(display,windows,&windows->widget,
8105 (
const char **) noises,
"Add Noise",
8106 "Select a type of noise to add to your image:",noise_type);
8107 noises=DestroyStringList(noises);
8108 if (*noise_type ==
'\0')
8110 XSetCursorState(display,windows,MagickTrue);
8111 XCheckRefreshWindows(display,windows);
8112 noise_image=AddNoiseImage(*image,(NoiseType) ParseCommandOption(
8113 MagickNoiseOptions,MagickFalse,noise_type),&(*image)->exception);
8114 if (noise_image != (Image *) NULL)
8116 *image=DestroyImage(*image);
8119 CatchException(&(*image)->exception);
8120 XSetCursorState(display,windows,MagickFalse);
8121 if (windows->image.orphan != MagickFalse)
8123 XConfigureImageColormap(display,resource_info,windows,*image);
8124 (void) XConfigureImage(display,resource_info,windows,*image);
8127 case SharpenCommand:
8133 radius[MaxTextExtent] =
"0.0x1.0";
8138 (void) XDialogWidget(display,windows,
"Sharpen",
8139 "Enter the sharpen radius and standard deviation:",radius);
8140 if (*radius ==
'\0')
8145 XSetCursorState(display,windows,MagickTrue);
8146 XCheckRefreshWindows(display,windows);
8147 flags=ParseGeometry(radius,&geometry_info);
8148 sharp_image=SharpenImage(*image,geometry_info.rho,geometry_info.sigma,
8149 &(*image)->exception);
8150 if (sharp_image != (Image *) NULL)
8152 *image=DestroyImage(*image);
8155 CatchException(&(*image)->exception);
8156 XSetCursorState(display,windows,MagickFalse);
8157 if (windows->image.orphan != MagickFalse)
8159 XConfigureImageColormap(display,resource_info,windows,*image);
8160 (void) XConfigureImage(display,resource_info,windows,*image);
8169 radius[MaxTextExtent] =
"0.0x1.0";
8174 (void) XDialogWidget(display,windows,
"Blur",
8175 "Enter the blur radius and standard deviation:",radius);
8176 if (*radius ==
'\0')
8181 XSetCursorState(display,windows,MagickTrue);
8182 XCheckRefreshWindows(display,windows);
8183 flags=ParseGeometry(radius,&geometry_info);
8184 blur_image=BlurImage(*image,geometry_info.rho,geometry_info.sigma,
8185 &(*image)->exception);
8186 if (blur_image != (Image *) NULL)
8188 *image=DestroyImage(*image);
8191 CatchException(&(*image)->exception);
8192 XSetCursorState(display,windows,MagickFalse);
8193 if (windows->image.orphan != MagickFalse)
8195 XConfigureImageColormap(display,resource_info,windows,*image);
8196 (void) XConfigureImage(display,resource_info,windows,*image);
8199 case ThresholdCommand:
8205 factor[MaxTextExtent] =
"128";
8210 (void) XDialogWidget(display,windows,
"Threshold",
8211 "Enter threshold value:",factor);
8212 if (*factor ==
'\0')
8217 XSetCursorState(display,windows,MagickTrue);
8218 XCheckRefreshWindows(display,windows);
8219 threshold=StringToDoubleInterval(factor,(
double) QuantumRange+1.0);
8220 (void) BilevelImage(*image,threshold);
8221 XSetCursorState(display,windows,MagickFalse);
8222 if (windows->image.orphan != MagickFalse)
8224 XConfigureImageColormap(display,resource_info,windows,*image);
8225 (void) XConfigureImage(display,resource_info,windows,*image);
8228 case EdgeDetectCommand:
8234 radius[MaxTextExtent] =
"0";
8239 (void) XDialogWidget(display,windows,
"Detect Edges",
8240 "Enter the edge detect radius:",radius);
8241 if (*radius ==
'\0')
8246 XSetCursorState(display,windows,MagickTrue);
8247 XCheckRefreshWindows(display,windows);
8248 flags=ParseGeometry(radius,&geometry_info);
8249 edge_image=EdgeImage(*image,geometry_info.rho,&(*image)->exception);
8250 if (edge_image != (Image *) NULL)
8252 *image=DestroyImage(*image);
8255 CatchException(&(*image)->exception);
8256 XSetCursorState(display,windows,MagickFalse);
8257 if (windows->image.orphan != MagickFalse)
8259 XConfigureImageColormap(display,resource_info,windows,*image);
8260 (void) XConfigureImage(display,resource_info,windows,*image);
8269 amount[MaxTextExtent] =
"2";
8274 (void) XDialogWidget(display,windows,
"Spread",
8275 "Enter the displacement amount:",amount);
8276 if (*amount ==
'\0')
8281 XSetCursorState(display,windows,MagickTrue);
8282 XCheckRefreshWindows(display,windows);
8283 flags=ParseGeometry(amount,&geometry_info);
8284 spread_image=EdgeImage(*image,geometry_info.rho,&(*image)->exception);
8285 if (spread_image != (Image *) NULL)
8287 *image=DestroyImage(*image);
8288 *image=spread_image;
8290 CatchException(&(*image)->exception);
8291 XSetCursorState(display,windows,MagickFalse);
8292 if (windows->image.orphan != MagickFalse)
8294 XConfigureImageColormap(display,resource_info,windows,*image);
8295 (void) XConfigureImage(display,resource_info,windows,*image);
8307 geometry[MaxTextExtent] =
"30x30";
8312 status=XDialogWidget(display,windows,
"Shade",
8313 "Enter the azimuth and elevation of the light source:",geometry);
8314 if (*geometry ==
'\0')
8319 XSetCursorState(display,windows,MagickTrue);
8320 XCheckRefreshWindows(display,windows);
8321 flags=ParseGeometry(geometry,&geometry_info);
8322 if ((flags & SigmaValue) == 0)
8323 geometry_info.sigma=1.0;
8324 shade_image=ShadeImage(*image,status != 0 ? MagickFalse : MagickTrue,
8325 geometry_info.rho,geometry_info.sigma,&(*image)->exception);
8326 if (shade_image != (Image *) NULL)
8328 *image=DestroyImage(*image);
8331 CatchException(&(*image)->exception);
8332 XSetCursorState(display,windows,MagickFalse);
8333 if (windows->image.orphan != MagickFalse)
8335 XConfigureImageColormap(display,resource_info,windows,*image);
8336 (void) XConfigureImage(display,resource_info,windows,*image);
8342 bevel_width[MaxTextExtent] =
"10";
8347 (void) XDialogWidget(display,windows,
"Raise",
"Bevel width:",bevel_width);
8348 if (*bevel_width ==
'\0')
8353 (void) XMagickCommand(display,resource_info,windows,ApplyCommand,image);
8354 XSetCursorState(display,windows,MagickTrue);
8355 XCheckRefreshWindows(display,windows);
8356 (void) ParsePageGeometry(*image,bevel_width,&page_geometry,
8357 &(*image)->exception);
8358 (void) RaiseImage(*image,&page_geometry,MagickTrue);
8359 XSetCursorState(display,windows,MagickFalse);
8360 if (windows->image.orphan != MagickFalse)
8362 XConfigureImageColormap(display,resource_info,windows,*image);
8363 (void) XConfigureImage(display,resource_info,windows,*image);
8366 case SegmentCommand:
8369 threshold[MaxTextExtent] =
"1.0x1.5";
8374 (void) XDialogWidget(display,windows,
"Segment",
"Smooth threshold:",
8376 if (*threshold ==
'\0')
8381 XSetCursorState(display,windows,MagickTrue);
8382 XCheckRefreshWindows(display,windows);
8383 flags=ParseGeometry(threshold,&geometry_info);
8384 if ((flags & SigmaValue) == 0)
8385 geometry_info.sigma=1.0;
8386 (void) SegmentImage(*image,sRGBColorspace,MagickFalse,geometry_info.rho,
8387 geometry_info.sigma);
8388 XSetCursorState(display,windows,MagickFalse);
8389 if (windows->image.orphan != MagickFalse)
8391 XConfigureImageColormap(display,resource_info,windows,*image);
8392 (void) XConfigureImage(display,resource_info,windows,*image);
8395 case SepiaToneCommand:
8404 factor[MaxTextExtent] =
"80%";
8409 (void) XDialogWidget(display,windows,
"Sepia Tone",
8410 "Enter the sepia tone factor (0 - 99.9%):",factor);
8411 if (*factor ==
'\0')
8416 XSetCursorState(display,windows,MagickTrue);
8417 XCheckRefreshWindows(display,windows);
8418 threshold=StringToDoubleInterval(factor,(
double) QuantumRange+1.0);
8419 sepia_image=SepiaToneImage(*image,threshold,&(*image)->exception);
8420 if (sepia_image != (Image *) NULL)
8422 *image=DestroyImage(*image);
8425 CatchException(&(*image)->exception);
8426 XSetCursorState(display,windows,MagickFalse);
8427 if (windows->image.orphan != MagickFalse)
8429 XConfigureImageColormap(display,resource_info,windows,*image);
8430 (void) XConfigureImage(display,resource_info,windows,*image);
8433 case SolarizeCommand:
8439 factor[MaxTextExtent] =
"60%";
8444 (void) XDialogWidget(display,windows,
"Solarize",
8445 "Enter the solarize factor (0 - 99.9%):",factor);
8446 if (*factor ==
'\0')
8451 XSetCursorState(display,windows,MagickTrue);
8452 XCheckRefreshWindows(display,windows);
8453 threshold=StringToDoubleInterval(factor,(
double) QuantumRange+1.0);
8454 (void) SolarizeImage(*image,threshold);
8455 XSetCursorState(display,windows,MagickFalse);
8456 if (windows->image.orphan != MagickFalse)
8458 XConfigureImageColormap(display,resource_info,windows,*image);
8459 (void) XConfigureImage(display,resource_info,windows,*image);
8468 degrees[MaxTextExtent] =
"60";
8473 (void) XDialogWidget(display,windows,
"Swirl",
"Enter the swirl angle:",
8475 if (*degrees ==
'\0')
8480 XSetCursorState(display,windows,MagickTrue);
8481 XCheckRefreshWindows(display,windows);
8482 flags=ParseGeometry(degrees,&geometry_info);
8483 swirl_image=SwirlImage(*image,geometry_info.rho,&(*image)->exception);
8484 if (swirl_image != (Image *) NULL)
8486 *image=DestroyImage(*image);
8489 CatchException(&(*image)->exception);
8490 XSetCursorState(display,windows,MagickFalse);
8491 if (windows->image.orphan != MagickFalse)
8493 XConfigureImageColormap(display,resource_info,windows,*image);
8494 (void) XConfigureImage(display,resource_info,windows,*image);
8497 case ImplodeCommand:
8503 factor[MaxTextExtent] =
"0.3";
8508 (void) XDialogWidget(display,windows,
"Implode",
8509 "Enter the implosion/explosion factor (-1.0 - 1.0):",factor);
8510 if (*factor ==
'\0')
8515 XSetCursorState(display,windows,MagickTrue);
8516 XCheckRefreshWindows(display,windows);
8517 flags=ParseGeometry(factor,&geometry_info);
8518 implode_image=ImplodeImage(*image,geometry_info.rho,&(*image)->exception);
8519 if (implode_image != (Image *) NULL)
8521 *image=DestroyImage(*image);
8522 *image=implode_image;
8524 CatchException(&(*image)->exception);
8525 XSetCursorState(display,windows,MagickFalse);
8526 if (windows->image.orphan != MagickFalse)
8528 XConfigureImageColormap(display,resource_info,windows,*image);
8529 (void) XConfigureImage(display,resource_info,windows,*image);
8532 case VignetteCommand:
8538 geometry[MaxTextExtent] =
"0x20";
8543 (void) XDialogWidget(display,windows,
"Vignette",
8544 "Enter the radius, sigma, and x and y offsets:",geometry);
8545 if (*geometry ==
'\0')
8550 XSetCursorState(display,windows,MagickTrue);
8551 XCheckRefreshWindows(display,windows);
8552 flags=ParseGeometry(geometry,&geometry_info);
8553 if ((flags & SigmaValue) == 0)
8554 geometry_info.sigma=1.0;
8555 if ((flags & XiValue) == 0)
8556 geometry_info.xi=0.1*(*image)->columns;
8557 if ((flags & PsiValue) == 0)
8558 geometry_info.psi=0.1*(*image)->rows;
8559 vignette_image=VignetteImage(*image,geometry_info.rho,geometry_info.sigma,
8560 (ssize_t) ceil(geometry_info.xi-0.5),(ssize_t) ceil(geometry_info.psi-
8561 0.5),&(*image)->exception);
8562 if (vignette_image != (Image *) NULL)
8564 *image=DestroyImage(*image);
8565 *image=vignette_image;
8567 CatchException(&(*image)->exception);
8568 XSetCursorState(display,windows,MagickFalse);
8569 if (windows->image.orphan != MagickFalse)
8571 XConfigureImageColormap(display,resource_info,windows,*image);
8572 (void) XConfigureImage(display,resource_info,windows,*image);
8581 geometry[MaxTextExtent] =
"25x150";
8586 (void) XDialogWidget(display,windows,
"Wave",
8587 "Enter the amplitude and length of the wave:",geometry);
8588 if (*geometry ==
'\0')
8593 XSetCursorState(display,windows,MagickTrue);
8594 XCheckRefreshWindows(display,windows);
8595 flags=ParseGeometry(geometry,&geometry_info);
8596 if ((flags & SigmaValue) == 0)
8597 geometry_info.sigma=1.0;
8598 wave_image=WaveImage(*image,geometry_info.rho,geometry_info.sigma,
8599 &(*image)->exception);
8600 if (wave_image != (Image *) NULL)
8602 *image=DestroyImage(*image);
8605 CatchException(&(*image)->exception);
8606 XSetCursorState(display,windows,MagickFalse);
8607 if (windows->image.orphan != MagickFalse)
8609 XConfigureImageColormap(display,resource_info,windows,*image);
8610 (void) XConfigureImage(display,resource_info,windows,*image);
8613 case OilPaintCommand:
8619 radius[MaxTextExtent] =
"0";
8624 (void) XDialogWidget(display,windows,
"Oil Paint",
8625 "Enter the mask radius:",radius);
8626 if (*radius ==
'\0')
8631 XSetCursorState(display,windows,MagickTrue);
8632 XCheckRefreshWindows(display,windows);
8633 flags=ParseGeometry(radius,&geometry_info);
8634 paint_image=OilPaintImage(*image,geometry_info.rho,&(*image)->exception);
8635 if (paint_image != (Image *) NULL)
8637 *image=DestroyImage(*image);
8640 CatchException(&(*image)->exception);
8641 XSetCursorState(display,windows,MagickFalse);
8642 if (windows->image.orphan != MagickFalse)
8644 XConfigureImageColormap(display,resource_info,windows,*image);
8645 (void) XConfigureImage(display,resource_info,windows,*image);
8648 case CharcoalDrawCommand:
8654 radius[MaxTextExtent] =
"0x1";
8659 (void) XDialogWidget(display,windows,
"Charcoal Draw",
8660 "Enter the charcoal radius and sigma:",radius);
8661 if (*radius ==
'\0')
8666 (void) XMagickCommand(display,resource_info,windows,ApplyCommand,image);
8667 XSetCursorState(display,windows,MagickTrue);
8668 XCheckRefreshWindows(display,windows);
8669 flags=ParseGeometry(radius,&geometry_info);
8670 if ((flags & SigmaValue) == 0)
8671 geometry_info.sigma=geometry_info.rho;
8672 charcoal_image=CharcoalImage(*image,geometry_info.rho,geometry_info.sigma,
8673 &(*image)->exception);
8674 if (charcoal_image != (Image *) NULL)
8676 *image=DestroyImage(*image);
8677 *image=charcoal_image;
8679 CatchException(&(*image)->exception);
8680 XSetCursorState(display,windows,MagickFalse);
8681 if (windows->image.orphan != MagickFalse)
8683 XConfigureImageColormap(display,resource_info,windows,*image);
8684 (void) XConfigureImage(display,resource_info,windows,*image);
8687 case AnnotateCommand:
8692 status=XAnnotateEditImage(display,resource_info,windows,*image);
8693 if (status == MagickFalse)
8695 XNoticeWidget(display,windows,
"Unable to annotate X image",
8696 (*image)->filename);
8706 status=XDrawEditImage(display,resource_info,windows,image);
8707 if (status == MagickFalse)
8709 XNoticeWidget(display,windows,
"Unable to draw on the X image",
8710 (*image)->filename);
8720 status=XColorEditImage(display,resource_info,windows,image);
8721 if (status == MagickFalse)
8723 XNoticeWidget(display,windows,
"Unable to pixel edit X image",
8724 (*image)->filename);
8734 status=XMatteEditImage(display,resource_info,windows,image);
8735 if (status == MagickFalse)
8737 XNoticeWidget(display,windows,
"Unable to matte edit X image",
8738 (*image)->filename);
8743 case CompositeCommand:
8748 status=XCompositeImage(display,resource_info,windows,*image);
8749 if (status == MagickFalse)
8751 XNoticeWidget(display,windows,
"Unable to composite X image",
8752 (*image)->filename);
8757 case AddBorderCommand:
8763 geometry[MaxTextExtent] =
"6x6";
8768 XColorBrowserWidget(display,windows,
"Select",color);
8771 (void) XDialogWidget(display,windows,
"Add Border",
8772 "Enter border geometry:",geometry);
8773 if (*geometry ==
'\0')
8778 (void) XMagickCommand(display,resource_info,windows,ApplyCommand,image);
8779 XSetCursorState(display,windows,MagickTrue);
8780 XCheckRefreshWindows(display,windows);
8781 (void) QueryColorDatabase(color,&(*image)->border_color,
8782 &(*image)->exception);
8783 (void) ParsePageGeometry(*image,geometry,&page_geometry,
8784 &(*image)->exception);
8785 border_image=BorderImage(*image,&page_geometry,&(*image)->exception);
8786 if (border_image != (Image *) NULL)
8788 *image=DestroyImage(*image);
8789 *image=border_image;
8791 CatchException(&(*image)->exception);
8792 XSetCursorState(display,windows,MagickFalse);
8793 if (windows->image.orphan != MagickFalse)
8795 windows->image.window_changes.width=(int) (*image)->columns;
8796 windows->image.window_changes.height=(int) (*image)->rows;
8797 XConfigureImageColormap(display,resource_info,windows,*image);
8798 (void) XConfigureImage(display,resource_info,windows,*image);
8801 case AddFrameCommand:
8810 geometry[MaxTextExtent] =
"6x6";
8815 XColorBrowserWidget(display,windows,
"Select",color);
8818 (void) XDialogWidget(display,windows,
"Add Frame",
"Enter frame geometry:",
8820 if (*geometry ==
'\0')
8825 (void) XMagickCommand(display,resource_info,windows,ApplyCommand,image);
8826 XSetCursorState(display,windows,MagickTrue);
8827 XCheckRefreshWindows(display,windows);
8828 (void) QueryColorDatabase(color,&(*image)->matte_color,
8829 &(*image)->exception);
8830 (void) ParsePageGeometry(*image,geometry,&page_geometry,
8831 &(*image)->exception);
8832 frame_info.width=page_geometry.width;
8833 frame_info.height=page_geometry.height;
8834 frame_info.outer_bevel=page_geometry.x;
8835 frame_info.inner_bevel=page_geometry.y;
8836 frame_info.x=(ssize_t) frame_info.width;
8837 frame_info.y=(ssize_t) frame_info.height;
8838 frame_info.width=(*image)->columns+2*frame_info.width;
8839 frame_info.height=(*image)->rows+2*frame_info.height;
8840 frame_image=FrameImage(*image,&frame_info,&(*image)->exception);
8841 if (frame_image != (Image *) NULL)
8843 *image=DestroyImage(*image);
8846 CatchException(&(*image)->exception);
8847 XSetCursorState(display,windows,MagickFalse);
8848 if (windows->image.orphan != MagickFalse)
8850 windows->image.window_changes.width=(int) (*image)->columns;
8851 windows->image.window_changes.height=(int) (*image)->rows;
8852 XConfigureImageColormap(display,resource_info,windows,*image);
8853 (void) XConfigureImage(display,resource_info,windows,*image);
8856 case CommentCommand:
8870 unique_file=AcquireUniqueFileResource(image_info->filename);
8871 if (unique_file == -1)
8873 XNoticeWidget(display,windows,
"Unable to edit image comment",
8874 image_info->filename);
8877 value=GetImageProperty(*image,
"comment");
8878 if (value == (
char *) NULL)
8879 unique_file=close_utf8(unique_file)-1;
8885 file=fdopen(unique_file,
"w");
8886 if (file == (FILE *) NULL)
8888 XNoticeWidget(display,windows,
"Unable to edit image comment",
8889 image_info->filename);
8892 for (p=value; *p !=
'\0'; p++)
8893 (
void) fputc((
int) *p,file);
8894 (void) fputc(
'\n',file);
8895 (void) fclose(file);
8897 XSetCursorState(display,windows,MagickTrue);
8898 XCheckRefreshWindows(display,windows);
8899 status=InvokeDelegate(image_info,*image,
"edit",(
char *) NULL,
8900 &(*image)->exception);
8901 if (status == MagickFalse)
8902 XNoticeWidget(display,windows,
"Unable to edit image comment",
8909 comment=FileToString(image_info->filename,~0UL,&(*image)->exception);
8910 if (comment != (
char *) NULL)
8912 (void) SetImageProperty(*image,
"comment",comment);
8913 (*image)->taint=MagickTrue;
8916 (void) RelinquishUniqueFileResource(image_info->filename);
8917 XSetCursorState(display,windows,MagickFalse);
8925 XSetCursorState(display,windows,MagickTrue);
8926 XCheckRefreshWindows(display,windows);
8927 (void) AcquireUniqueFilename(filename);
8928 (void) FormatLocaleString((*image)->filename,MaxTextExtent,
"launch:%s",
8930 status=WriteImage(image_info,*image);
8931 if (status == MagickFalse)
8932 XNoticeWidget(display,windows,
"Unable to launch image editor",
8936 nexus=ReadImage(resource_info->image_info,&(*image)->exception);
8937 CatchException(&(*image)->exception);
8938 XClientMessage(display,windows->image.id,windows->im_protocols,
8939 windows->im_next_image,CurrentTime);
8941 (void) RelinquishUniqueFileResource(filename);
8942 XSetCursorState(display,windows,MagickFalse);
8945 case RegionOfInterestCommand:
8950 (void) XROIImage(display,resource_info,windows,image);
8960 if (windows->magnify.mapped != MagickFalse)
8961 (void) XRaiseWindow(display,windows->magnify.id);
8967 XSetCursorState(display,windows,MagickTrue);
8968 (void) XMapRaised(display,windows->magnify.id);
8969 XSetCursorState(display,windows,MagickFalse);
8973 case ShowPreviewCommand:
8982 preview_type[MaxTextExtent] =
"Gamma";
8987 previews=GetCommandOptions(MagickPreviewOptions);
8988 if (previews == (
char **) NULL)
8990 XListBrowserWidget(display,windows,&windows->widget,
8991 (
const char **) previews,
"Preview",
8992 "Select an enhancement, effect, or F/X:",preview_type);
8993 previews=DestroyStringList(previews);
8994 if (*preview_type ==
'\0')
8999 XSetCursorState(display,windows,MagickTrue);
9000 XCheckRefreshWindows(display,windows);
9001 image_info->preview_type=(PreviewType)
9002 ParseCommandOption(MagickPreviewOptions,MagickFalse,preview_type);
9003 image_info->group=(ssize_t) windows->image.id;
9004 (void) DeleteImageProperty(*image,
"label");
9005 (void) SetImageProperty(*image,
"label",
"Preview");
9006 (void) AcquireUniqueFilename(filename);
9007 (void) FormatLocaleString((*image)->filename,MaxTextExtent,
"preview:%s",
9009 status=WriteImage(image_info,*image);
9010 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
9011 preview_image=ReadImage(image_info,&(*image)->exception);
9012 (void) RelinquishUniqueFileResource(filename);
9013 if (preview_image == (Image *) NULL)
9015 (void) FormatLocaleString(preview_image->filename,MaxTextExtent,
"show:%s",
9017 status=WriteImage(image_info,preview_image);
9018 preview_image=DestroyImage(preview_image);
9019 if (status == MagickFalse)
9020 XNoticeWidget(display,windows,
"Unable to show image preview",
9021 (*image)->filename);
9022 XDelay(display,1500);
9023 XSetCursorState(display,windows,MagickFalse);
9026 case ShowHistogramCommand:
9034 XSetCursorState(display,windows,MagickTrue);
9035 XCheckRefreshWindows(display,windows);
9036 image_info->group=(ssize_t) windows->image.id;
9037 (void) DeleteImageProperty(*image,
"label");
9038 (void) SetImageProperty(*image,
"label",
"Histogram");
9039 (void) AcquireUniqueFilename(filename);
9040 (void) FormatLocaleString((*image)->filename,MaxTextExtent,
"histogram:%s",
9042 status=WriteImage(image_info,*image);
9043 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
9044 histogram_image=ReadImage(image_info,&(*image)->exception);
9045 (void) RelinquishUniqueFileResource(filename);
9046 if (histogram_image == (Image *) NULL)
9048 (void) FormatLocaleString(histogram_image->filename,MaxTextExtent,
9049 "show:%s",filename);
9050 status=WriteImage(image_info,histogram_image);
9051 histogram_image=DestroyImage(histogram_image);
9052 if (status == MagickFalse)
9053 XNoticeWidget(display,windows,
"Unable to show histogram",
9054 (*image)->filename);
9055 XDelay(display,1500);
9056 XSetCursorState(display,windows,MagickFalse);
9059 case ShowMatteCommand:
9064 if ((*image)->matte == MagickFalse)
9066 XNoticeWidget(display,windows,
9067 "Image does not have any matte information",(*image)->filename);
9073 XSetCursorState(display,windows,MagickTrue);
9074 XCheckRefreshWindows(display,windows);
9075 image_info->group=(ssize_t) windows->image.id;
9076 (void) DeleteImageProperty(*image,
"label");
9077 (void) SetImageProperty(*image,
"label",
"Matte");
9078 (void) AcquireUniqueFilename(filename);
9079 (void) FormatLocaleString((*image)->filename,MaxTextExtent,
"matte:%s",
9081 status=WriteImage(image_info,*image);
9082 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
9083 matte_image=ReadImage(image_info,&(*image)->exception);
9084 (void) RelinquishUniqueFileResource(filename);
9085 if (matte_image == (Image *) NULL)
9087 (void) FormatLocaleString(matte_image->filename,MaxTextExtent,
"show:%s",
9089 status=WriteImage(image_info,matte_image);
9090 matte_image=DestroyImage(matte_image);
9091 if (status == MagickFalse)
9092 XNoticeWidget(display,windows,
"Unable to show matte",
9093 (*image)->filename);
9094 XDelay(display,1500);
9095 XSetCursorState(display,windows,MagickFalse);
9098 case BackgroundCommand:
9103 status=XBackgroundImage(display,resource_info,windows,image);
9104 if (status == MagickFalse)
9106 nexus=CloneImage(*image,0,0,MagickTrue,&(*image)->exception);
9107 if (nexus != (Image *) NULL)
9108 XClientMessage(display,windows->image.id,windows->im_protocols,
9109 windows->im_next_image,CurrentTime);
9112 case SlideShowCommand:
9115 delay[MaxTextExtent] =
"5";
9120 (void) XDialogWidget(display,windows,
"Slide Show",
9121 "Pause how many 1/100ths of a second between images:",delay);
9124 resource_info->delay=StringToUnsignedLong(delay);
9125 XClientMessage(display,windows->image.id,windows->im_protocols,
9126 windows->im_next_image,CurrentTime);
9129 case PreferencesCommand:
9134 status=XPreferencesWidget(display,resource_info,windows);
9135 if (status == MagickFalse)
9137 nexus=CloneImage(*image,0,0,MagickTrue,&(*image)->exception);
9138 if (nexus != (Image *) NULL)
9139 XClientMessage(display,windows->image.id,windows->im_protocols,
9140 windows->im_next_image,CurrentTime);
9148 XTextViewHelp(display,resource_info,windows,MagickFalse,
9149 "Help Viewer - Display",DisplayHelp);
9152 case BrowseDocumentationCommand:
9164 root_window=XRootWindow(display,XDefaultScreen(display));
9165 mozilla_atom=XInternAtom(display,
"_MOZILLA_VERSION",MagickFalse);
9166 mozilla_window=XWindowByProperty(display,root_window,mozilla_atom);
9167 if (mozilla_window != (Window) NULL)
9170 command[MaxTextExtent];
9175 (void) FormatLocaleString(command,MaxTextExtent,
9176 "openurl(%s,new-tab)",MagickAuthoritativeURL);
9177 mozilla_atom=XInternAtom(display,
"_MOZILLA_COMMAND",MagickFalse);
9178 (void) XChangeProperty(display,mozilla_window,mozilla_atom,XA_STRING,
9179 8,PropModeReplace,(
unsigned char *) command,(
int) strlen(command));
9180 XSetCursorState(display,windows,MagickFalse);
9183 XSetCursorState(display,windows,MagickTrue);
9184 XCheckRefreshWindows(display,windows);
9185 status=InvokeDelegate(image_info,*image,
"browse",(
char *) NULL,
9186 &(*image)->exception);
9187 if (status == MagickFalse)
9188 XNoticeWidget(display,windows,
"Unable to browse documentation",
9190 XDelay(display,1500);
9191 XSetCursorState(display,windows,MagickFalse);
9194 case VersionCommand:
9196 XNoticeWidget(display,windows,GetMagickVersion((
size_t *) NULL),
9197 GetMagickCopyright());
9200 case SaveToUndoBufferCommand:
9204 (void) XBell(display,0);
9208 image_info=DestroyImageInfo(image_info);
9241static void XMagnifyImage(Display *display,XWindows *windows,XEvent *event)
9244 text[MaxTextExtent];
9256 (void) XCheckDefineCursor(display,windows->image.id,windows->magnify.cursor);
9260 windows->magnify.x=(int) windows->image.x+x;
9261 windows->magnify.y=(int) windows->image.y+y;
9267 if (windows->info.mapped != MagickFalse)
9269 if ((x < (
int) (windows->info.x+windows->info.width)) &&
9270 (y < (
int) (windows->info.y+windows->info.height)))
9271 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
9274 if ((x > (
int) (windows->info.x+windows->info.width)) ||
9275 (y > (
int) (windows->info.y+windows->info.height)))
9276 (void) XMapWindow(display,windows->info.id);
9277 if (windows->info.mapped != MagickFalse)
9282 (void) FormatLocaleString(text,MaxTextExtent,
" %+d%+d ",
9283 windows->magnify.x,windows->magnify.y);
9284 XInfoWidget(display,windows,text);
9289 XScreenEvent(display,windows,event);
9290 switch (event->type)
9321 if (x >= (
int) windows->image.width)
9322 x=(int) windows->image.width-1;
9326 if (y >= (
int) windows->image.height)
9327 y=(int) windows->image.height-1;
9328 }
while ((state & ExitState) == 0);
9332 XSetCursorState(display,windows,MagickFalse);
9367static void XMagnifyWindowCommand(Display *display,XWindows *windows,
9368 const MagickStatusType state,
const KeySym key_symbol)
9377 if ((state & Mod1Mask) != 0)
9379 switch ((
int) key_symbol)
9383 (void) XWithdrawWindow(display,windows->magnify.id,
9384 windows->magnify.screen);
9390 windows->magnify.x=(int) windows->image.width/2;
9391 windows->magnify.y=(int) windows->image.height/2;
9397 if (windows->magnify.x > 0)
9398 windows->magnify.x-=quantum;
9404 if (windows->magnify.y > 0)
9405 windows->magnify.y-=quantum;
9411 if (windows->magnify.x < (
int) (windows->image.ximage->width-1))
9412 windows->magnify.x+=quantum;
9418 if (windows->magnify.y < (
int) (windows->image.ximage->height-1))
9419 windows->magnify.y+=quantum;
9433 windows->magnify.data=(key_symbol-XK_0);
9447 windows->magnify.data=(key_symbol-XK_KP_0);
9453 XMakeMagnifyImage(display,windows);
9487static void XMakePanImage(Display *display,XResourceInfo *resource_info,
9488 XWindows *windows,Image *image)
9496 XSetCursorState(display,windows,MagickTrue);
9497 XCheckRefreshWindows(display,windows);
9498 windows->pan.x=(int) windows->image.x;
9499 windows->pan.y=(int) windows->image.y;
9500 status=XMakeImage(display,resource_info,&windows->pan,image,
9501 windows->pan.width,windows->pan.height);
9502 if (status == MagickFalse)
9503 ThrowXWindowFatalException(XServerFatalError,image->exception.reason,
9504 image->exception.description);
9505 (void) XSetWindowBackgroundPixmap(display,windows->pan.id,
9506 windows->pan.pixmap);
9507 (void) XClearWindow(display,windows->pan.id);
9508 XDrawPanRectangle(display,windows);
9509 XSetCursorState(display,windows,MagickFalse);
9544static MagickBooleanType XMatteEditImage(Display *display,
9545 XResourceInfo *resource_info,XWindows *windows,Image **image)
9548 *
const MatteEditMenu[] =
9561 matte[MaxTextExtent] =
"0";
9563 static const ModeType
9564 MatteEditCommands[] =
9567 MatteEditBorderCommand,
9568 MatteEditFuzzCommand,
9569 MatteEditValueCommand,
9570 MatteEditUndoCommand,
9571 MatteEditHelpCommand,
9572 MatteEditDismissCommand
9576 method = PointMethod;
9579 border_color = { 0, 0, 0, 0, 0, 0 };
9582 command[MaxTextExtent],
9583 text[MaxTextExtent] =
"";
9615 (void) CloneString(&windows->command.name,
"Matte Edit");
9616 windows->command.data=4;
9617 (void) XCommandWidget(display,windows,MatteEditMenu,(XEvent *) NULL);
9618 (void) XMapRaised(display,windows->command.id);
9619 XClientMessage(display,windows->image.id,windows->im_protocols,
9620 windows->im_update_widget,CurrentTime);
9624 cursor=XMakeCursor(display,windows->image.id,windows->map_info->colormap,
9625 resource_info->background_color,resource_info->foreground_color);
9626 (void) XCheckDefineCursor(display,windows->image.id,cursor);
9630 XQueryPosition(display,windows->image.id,&x,&y);
9631 (void) XSelectInput(display,windows->image.id,
9632 windows->image.attributes.event_mask | PointerMotionMask);
9636 if (windows->info.mapped != MagickFalse)
9641 (void) FormatLocaleString(text,MaxTextExtent,
" %+d%+d ",
9642 x+windows->image.x,y+windows->image.y);
9643 XInfoWidget(display,windows,text);
9648 XScreenEvent(display,windows,&event);
9649 if (event.xany.window == windows->command.id)
9654 id=XCommandWidget(display,windows,MatteEditMenu,&event);
9657 (void) XCheckDefineCursor(display,windows->image.id,cursor);
9660 switch (MatteEditCommands[
id])
9662 case MatteEditMethod:
9670 methods=GetCommandOptions(MagickMethodOptions);
9671 if (methods == (
char **) NULL)
9673 entry=XMenuWidget(display,windows,MatteEditMenu[
id],
9674 (
const char **) methods,command);
9676 method=(PaintMethod) ParseCommandOption(MagickMethodOptions,
9677 MagickFalse,methods[entry]);
9678 methods=DestroyStringList(methods);
9681 case MatteEditBorderCommand:
9684 *ColorMenu[MaxNumberPens];
9692 for (i=0; i < (int) (MaxNumberPens-2); i++)
9693 ColorMenu[i]=resource_info->pen_colors[i];
9694 ColorMenu[MaxNumberPens-2]=
"Browser...";
9695 ColorMenu[MaxNumberPens-1]=(
const char *) NULL;
9699 pen_number=XMenuWidget(display,windows,MatteEditMenu[
id],
9700 (
const char **) ColorMenu,command);
9703 if (pen_number == (MaxNumberPens-2))
9706 color_name[MaxTextExtent] =
"gray";
9711 resource_info->pen_colors[pen_number]=color_name;
9712 XColorBrowserWidget(display,windows,
"Select",color_name);
9713 if (*color_name ==
'\0')
9719 (void) XParseColor(display,windows->map_info->colormap,
9720 resource_info->pen_colors[pen_number],&border_color);
9723 case MatteEditFuzzCommand:
9738 fuzz[MaxTextExtent];
9743 entry=XMenuWidget(display,windows,MatteEditMenu[
id],FuzzMenu,
9749 (*image)->fuzz=StringToDoubleInterval(FuzzMenu[entry],(
double)
9753 (void) CopyMagickString(fuzz,
"20%",MaxTextExtent);
9754 (void) XDialogWidget(display,windows,
"Ok",
9755 "Enter fuzz factor (0.0 - 99.9%):",fuzz);
9758 (void) ConcatenateMagickString(fuzz,
"%",MaxTextExtent);
9759 (*image)->fuzz=StringToDoubleInterval(fuzz,(
double) QuantumRange+
9763 case MatteEditValueCommand:
9766 *
const MatteMenu[] =
9775 message[MaxTextExtent];
9780 entry=XMenuWidget(display,windows,MatteEditMenu[
id],MatteMenu,
9786 (void) FormatLocaleString(matte,MaxTextExtent,
"%g",
9787 (
double) OpaqueOpacity);
9788 if (LocaleCompare(MatteMenu[entry],
"Transparent") == 0)
9789 (void) FormatLocaleString(matte,MaxTextExtent,
"%g",
9790 (
double) TransparentOpacity);
9793 (void) FormatLocaleString(message,MaxTextExtent,
9794 "Enter matte value (0 - " "%g" "):",(
double) QuantumRange);
9795 (void) XDialogWidget(display,windows,
"Matte",message,matte);
9800 case MatteEditUndoCommand:
9802 (void) XMagickCommand(display,resource_info,windows,UndoCommand,
9806 case MatteEditHelpCommand:
9808 XTextViewHelp(display,resource_info,windows,MagickFalse,
9809 "Help Viewer - Matte Edit",ImageMatteEditHelp);
9812 case MatteEditDismissCommand:
9824 (void) XCheckDefineCursor(display,windows->image.id,cursor);
9831 if (event.xbutton.button != Button1)
9833 if ((event.xbutton.window != windows->image.id) &&
9834 (event.xbutton.window != windows->magnify.id))
9841 (void) XMagickCommand(display,resource_info,windows,
9842 SaveToUndoBufferCommand,image);
9843 state|=UpdateConfigurationState;
9848 if (event.xbutton.button != Button1)
9850 if ((event.xbutton.window != windows->image.id) &&
9851 (event.xbutton.window != windows->magnify.id))
9858 XConfigureImageColormap(display,resource_info,windows,*image);
9859 (void) XConfigureImage(display,resource_info,windows,*image);
9860 XInfoWidget(display,windows,text);
9861 (void) XCheckDefineCursor(display,windows->image.id,cursor);
9862 state&=(~UpdateConfigurationState);
9870 command[MaxTextExtent];
9875 if (event.xkey.window == windows->magnify.id)
9880 window=windows->magnify.id;
9881 while (XCheckWindowEvent(display,window,KeyPressMask,&event)) ;
9883 if (event.xkey.window != windows->image.id)
9888 (void) XLookupString((XKeyEvent *) &event.xkey,command,(
int)
9889 sizeof(command),&key_symbol,(XComposeStatus *) NULL);
9890 switch ((
int) key_symbol)
9904 XTextViewHelp(display,resource_info,windows,MagickFalse,
9905 "Help Viewer - Matte Edit",ImageMatteEditHelp);
9910 (void) XBell(display,0);
9923 if (windows->info.mapped != MagickFalse)
9925 if ((x < (
int) (windows->info.x+windows->info.width)) &&
9926 (y < (
int) (windows->info.y+windows->info.height)))
9927 (void) XWithdrawWindow(display,windows->info.id,
9928 windows->info.screen);
9931 if ((x > (
int) (windows->info.x+windows->info.width)) ||
9932 (y > (
int) (windows->info.y+windows->info.height)))
9933 (void) XMapWindow(display,windows->info.id);
9939 if (event.xany.window == windows->magnify.id)
9941 x=windows->magnify.x-windows->image.x;
9942 y=windows->magnify.y-windows->image.y;
9946 if ((state & UpdateConfigurationState) != 0)
9961 (void) XClearArea(display,windows->image.id,x_offset,y_offset,1,1,
9963 XPutPixel(windows->image.ximage,x_offset,y_offset,
9964 windows->pixel_info->background_color.pixel);
9965 width=(
unsigned int) (*image)->columns;
9966 height=(
unsigned int) (*image)->rows;
9969 if (windows->image.crop_geometry != (
char *) NULL)
9970 (void) XParseGeometry(windows->image.crop_geometry,&x,&y,
9973 (width*(windows->image.x+x_offset)/windows->image.ximage->width+x);
9975 (height*(windows->image.y+y_offset)/windows->image.ximage->height+y);
9976 if ((x_offset < 0) || (y_offset < 0))
9978 if ((x_offset >= (
int) (*image)->columns) ||
9979 (y_offset >= (
int) (*image)->rows))
9981 if (SetImageStorageClass(*image,DirectClass) == MagickFalse)
9982 return(MagickFalse);
9983 (*image)->matte=MagickTrue;
9984 exception=(&(*image)->exception);
9985 image_view=AcquireAuthenticCacheView(*image,exception);
9994 q=GetCacheViewAuthenticPixels(image_view,(ssize_t) x_offset,
9995 (ssize_t) y_offset,1,1,exception);
9996 if (q == (PixelPacket *) NULL)
9998 q->opacity=(Quantum) StringToLong(matte);
9999 (void) SyncCacheViewAuthenticPixels(image_view,exception);
10002 case ReplaceMethod:
10010 (void) GetOneCacheViewVirtualPixel(image_view,(ssize_t) x_offset,
10011 (ssize_t) y_offset,&target,exception);
10012 for (y=0; y < (int) (*image)->rows; y++)
10014 q=GetCacheViewAuthenticPixels(image_view,0,(ssize_t) y,
10015 (*image)->columns,1,&(*image)->exception);
10016 if (q == (PixelPacket *) NULL)
10018 for (x=0; x < (int) (*image)->columns; x++)
10020 if (IsColorSimilar(*image,q,&target))
10021 q->opacity=(Quantum) StringToLong(matte);
10024 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
10029 case FloodfillMethod:
10030 case FillToBorderMethod:
10041 (void) GetOneVirtualMagickPixel(*image,(ssize_t) x_offset,
10042 (ssize_t) y_offset,&target,exception);
10043 if (method == FillToBorderMethod)
10045 target.red=(MagickRealType)
10046 ScaleShortToQuantum(border_color.red);
10047 target.green=(MagickRealType)
10048 ScaleShortToQuantum(border_color.green);
10049 target.blue=(MagickRealType)
10050 ScaleShortToQuantum(border_color.blue);
10052 draw_info=CloneDrawInfo(resource_info->image_info,
10053 (DrawInfo *) NULL);
10054 draw_info->fill.opacity=ClampToQuantum(StringToDouble(matte,
10056 (void) FloodfillPaintImage(*image,OpacityChannel,draw_info,&target,
10057 (ssize_t) x_offset,(ssize_t) y_offset,
10058 method == FloodfillMethod ? MagickFalse : MagickTrue);
10059 draw_info=DestroyDrawInfo(draw_info);
10067 if (SetImageStorageClass(*image,DirectClass) == MagickFalse)
10068 return(MagickFalse);
10069 for (y=0; y < (int) (*image)->rows; y++)
10071 q=QueueCacheViewAuthenticPixels(image_view,0,(ssize_t) y,
10072 (*image)->columns,1,exception);
10073 if (q == (PixelPacket *) NULL)
10075 for (x=0; x < (int) (*image)->columns; x++)
10077 q->opacity=(Quantum) StringToLong(matte);
10080 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
10083 if (StringToLong(matte) == OpaqueOpacity)
10084 (*image)->matte=MagickFalse;
10088 image_view=DestroyCacheView(image_view);
10089 state&=(~UpdateConfigurationState);
10091 }
while ((state & ExitState) == 0);
10092 (void) XSelectInput(display,windows->image.id,
10093 windows->image.attributes.event_mask);
10094 XSetCursorState(display,windows,MagickFalse);
10095 (void) XFreeCursor(display,cursor);
10096 return(MagickTrue);
10130static Image *XOpenImage(Display *display,XResourceInfo *resource_info,
10131 XWindows *windows,
const MagickBooleanType command)
10146 filename[MaxTextExtent] =
"\0";
10151 if (command == MagickFalse)
10152 XFileBrowserWidget(display,windows,
"Open",filename);
10170 status=XGetCommand(display,windows->image.id,&files,&count);
10172 ThrowXWindowException(XServerError,
"UnableToGetProperty",
"...");
10173 filelist=(
char **) AcquireQuantumMemory((
size_t) count,
sizeof(*filelist));
10174 if (filelist == (
char **) NULL)
10176 (void) XFreeStringList(files);
10177 ThrowXWindowException(ResourceLimitError,
"MemoryAllocationFailed",
10179 return((Image *) NULL);
10182 for (i=1; i < count; i++)
10183 if (*files[i] !=
'-')
10184 filelist[j++]=files[i];
10185 filelist[j]=(
char *) NULL;
10186 XListBrowserWidget(display,windows,&windows->widget,
10187 (
const char **) filelist,
"Load",
"Select Image to Load:",filename);
10188 filelist=(
char **) RelinquishMagickMemory(filelist);
10189 (void) XFreeStringList(files);
10191 if (*filename ==
'\0')
10192 return((Image *) NULL);
10193 image_info=CloneImageInfo(resource_info->image_info);
10194 (void) SetImageInfoProgressMonitor(image_info,(MagickProgressMonitor) NULL,
10196 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
10197 exception=AcquireExceptionInfo();
10198 (void) SetImageInfo(image_info,0,exception);
10199 if (LocaleCompare(image_info->magick,
"X") == 0)
10202 seconds[MaxTextExtent];
10207 (void) CopyMagickString(seconds,
"0",MaxTextExtent);
10208 (void) XDialogWidget(display,windows,
"Grab",
"Enter any delay in seconds:",
10210 if (*seconds ==
'\0')
10211 return((Image *) NULL);
10212 XDelay(display,(
size_t) (1000*StringToLong(seconds)));
10214 magick_info=GetMagickInfo(image_info->magick,exception);
10215 if ((magick_info != (
const MagickInfo *) NULL) &&
10216 (magick_info->raw != MagickFalse))
10219 geometry[MaxTextExtent];
10224 (void) CopyMagickString(geometry,
"512x512",MaxTextExtent);
10225 if (image_info->size != (
char *) NULL)
10226 (void) CopyMagickString(geometry,image_info->size,MaxTextExtent);
10227 (void) XDialogWidget(display,windows,
"Load",
"Enter the image geometry:",
10229 (void) CloneString(&image_info->size,geometry);
10234 XSetCursorState(display,windows,MagickTrue);
10235 XCheckRefreshWindows(display,windows);
10236 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
10237 nexus=ReadImage(image_info,exception);
10238 CatchException(exception);
10239 XSetCursorState(display,windows,MagickFalse);
10240 if (nexus != (Image *) NULL)
10241 XClientMessage(display,windows->image.id,windows->im_protocols,
10242 windows->im_next_image,CurrentTime);
10252 text=FileToString(filename,~0UL,exception);
10253 if (text == (
char *) NULL)
10254 return((Image *) NULL);
10255 textlist=StringToList(text);
10256 if (textlist != (
char **) NULL)
10259 title[MaxTextExtent];
10264 (void) FormatLocaleString(title,MaxTextExtent,
10265 "Unknown format: %s",filename);
10266 XTextViewWidget(display,resource_info,windows,MagickTrue,title,
10267 (
const char **) textlist);
10268 for (i=0; textlist[i] != (
char *) NULL; i++)
10269 textlist[i]=DestroyString(textlist[i]);
10270 textlist=(
char **) RelinquishMagickMemory(textlist);
10272 text=DestroyString(text);
10274 exception=DestroyExceptionInfo(exception);
10275 image_info=DestroyImageInfo(image_info);
10307static void XPanImage(Display *display,XWindows *windows,XEvent *event)
10310 text[MaxTextExtent];
10328 if ((windows->image.ximage->width > (
int) windows->image.width) &&
10329 (windows->image.ximage->height > (
int) windows->image.height))
10330 cursor=XCreateFontCursor(display,XC_fleur);
10332 if (windows->image.ximage->width > (
int) windows->image.width)
10333 cursor=XCreateFontCursor(display,XC_sb_h_double_arrow);
10335 if (windows->image.ximage->height > (
int) windows->image.height)
10336 cursor=XCreateFontCursor(display,XC_sb_v_double_arrow);
10338 cursor=XCreateFontCursor(display,XC_arrow);
10339 (void) XCheckDefineCursor(display,windows->pan.id,cursor);
10343 x_factor=(MagickRealType) windows->image.ximage->width/windows->pan.width;
10344 y_factor=(MagickRealType) windows->image.ximage->height/windows->pan.height;
10345 pan_info.width=windows->pan.width*windows->image.width/
10346 windows->image.ximage->width;
10347 pan_info.height=windows->pan.height*windows->image.height/
10348 windows->image.ximage->height;
10351 state=UpdateConfigurationState;
10354 switch (event->type)
10361 pan_info.x=(ssize_t) event->xbutton.x;
10362 pan_info.y=(ssize_t) event->xbutton.y;
10363 state|=UpdateConfigurationState;
10366 case ButtonRelease:
10371 pan_info.x=(ssize_t) event->xbutton.x;
10372 pan_info.y=(ssize_t) event->xbutton.y;
10373 state|=UpdateConfigurationState | ExitState;
10378 pan_info.x=(ssize_t) event->xmotion.x;
10379 pan_info.y=(ssize_t) event->xmotion.y;
10380 state|=UpdateConfigurationState;
10385 if ((state & UpdateConfigurationState) != 0)
10390 if (pan_info.x < (ssize_t) (pan_info.width/2))
10393 pan_info.x=(ssize_t) (x_factor*(pan_info.x-(pan_info.width/2)));
10394 if (pan_info.x < 0)
10397 if ((
int) (pan_info.x+windows->image.width) >
10398 windows->image.ximage->width)
10399 pan_info.x=(ssize_t)
10400 (windows->image.ximage->width-windows->image.width);
10401 if (pan_info.y < (ssize_t) (pan_info.height/2))
10404 pan_info.y=(ssize_t) (y_factor*(pan_info.y-(pan_info.height/2)));
10405 if (pan_info.y < 0)
10408 if ((
int) (pan_info.y+windows->image.height) >
10409 windows->image.ximage->height)
10410 pan_info.y=(ssize_t)
10411 (windows->image.ximage->height-windows->image.height);
10412 if ((windows->image.x != (
int) pan_info.x) ||
10413 (windows->image.y != (
int) pan_info.y))
10418 windows->image.x=(int) pan_info.x;
10419 windows->image.y=(int) pan_info.y;
10420 (void) FormatLocaleString(text,MaxTextExtent,
" %ux%u%+d%+d ",
10421 windows->image.width,windows->image.height,windows->image.x,
10423 XInfoWidget(display,windows,text);
10427 XDrawPanRectangle(display,windows);
10428 XRefreshWindow(display,&windows->image,(XEvent *) NULL);
10430 state&=(~UpdateConfigurationState);
10435 if ((state & ExitState) == 0)
10436 XScreenEvent(display,windows,event);
10437 }
while ((state & ExitState) == 0);
10441 (void) XCheckDefineCursor(display,windows->pan.id,windows->pan.cursor);
10442 (void) XFreeCursor(display,cursor);
10443 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
10477static MagickBooleanType XPasteImage(Display *display,
10478 XResourceInfo *resource_info,XWindows *windows,Image *image)
10481 *
const PasteMenu[] =
10489 static const ModeType
10492 PasteOperatorsCommand,
10494 PasteDismissCommand
10497 static CompositeOperator
10498 compose = CopyCompositeOp;
10501 text[MaxTextExtent];
10535 if (resource_info->copy_image == (Image *) NULL)
10536 return(MagickFalse);
10537 paste_image=CloneImage(resource_info->copy_image,0,0,MagickTrue,
10538 &image->exception);
10539 if (paste_image == (Image *) NULL)
10540 return(MagickFalse);
10544 (void) CloneString(&windows->command.name,
"Paste");
10545 windows->command.data=1;
10546 (void) XCommandWidget(display,windows,PasteMenu,(XEvent *) NULL);
10547 (void) XMapRaised(display,windows->command.id);
10548 XClientMessage(display,windows->image.id,windows->im_protocols,
10549 windows->im_update_widget,CurrentTime);
10553 XSetCursorState(display,windows,MagickFalse);
10554 XQueryPosition(display,windows->image.id,&x,&y);
10555 (void) XSelectInput(display,windows->image.id,
10556 windows->image.attributes.event_mask | PointerMotionMask);
10557 paste_info.x=(ssize_t) windows->image.x+x;
10558 paste_info.y=(ssize_t) windows->image.y+y;
10559 paste_info.width=0;
10560 paste_info.height=0;
10561 cursor=XCreateFontCursor(display,XC_ul_angle);
10562 (void) XSetFunction(display,windows->image.highlight_context,GXinvert);
10563 state=DefaultState;
10566 if (windows->info.mapped != MagickFalse)
10571 (void) FormatLocaleString(text,MaxTextExtent,
" %+ld%+ld ",
10572 (
long) paste_info.x,(
long) paste_info.y);
10573 XInfoWidget(display,windows,text);
10575 highlight_info=paste_info;
10576 highlight_info.x=paste_info.x-windows->image.x;
10577 highlight_info.y=paste_info.y-windows->image.y;
10578 XHighlightRectangle(display,windows->image.id,
10579 windows->image.highlight_context,&highlight_info);
10583 XScreenEvent(display,windows,&event);
10584 XHighlightRectangle(display,windows->image.id,
10585 windows->image.highlight_context,&highlight_info);
10586 if (event.xany.window == windows->command.id)
10591 id=XCommandWidget(display,windows,PasteMenu,&event);
10594 switch (PasteCommands[
id])
10596 case PasteOperatorsCommand:
10599 command[MaxTextExtent],
10605 operators=GetCommandOptions(MagickComposeOptions);
10606 if (operators == (
char **) NULL)
10608 entry=XMenuWidget(display,windows,PasteMenu[
id],
10609 (
const char **) operators,command);
10611 compose=(CompositeOperator) ParseCommandOption(
10612 MagickComposeOptions,MagickFalse,operators[entry]);
10613 operators=DestroyStringList(operators);
10616 case PasteHelpCommand:
10618 XTextViewHelp(display,resource_info,windows,MagickFalse,
10619 "Help Viewer - Image Composite",ImagePasteHelp);
10622 case PasteDismissCommand:
10627 state|=EscapeState;
10636 switch (event.type)
10640 if (resource_info->debug != MagickFalse)
10641 (void) LogMagickEvent(X11Event,GetMagickModule(),
10642 "Button Press: 0x%lx %u +%d+%d",event.xbutton.window,
10643 event.xbutton.button,event.xbutton.x,event.xbutton.y);
10644 if (event.xbutton.button != Button1)
10646 if (event.xbutton.window != windows->image.id)
10651 width=(
unsigned int) image->columns;
10652 height=(
unsigned int) image->rows;
10655 if (windows->image.crop_geometry != (
char *) NULL)
10656 (void) XParseGeometry(windows->image.crop_geometry,&x,&y,
10658 scale_factor=(MagickRealType) windows->image.ximage->width/width;
10659 paste_info.width=(
unsigned int) (scale_factor*paste_image->columns+0.5);
10660 scale_factor=(MagickRealType) windows->image.ximage->height/height;
10661 paste_info.height=(
unsigned int) (scale_factor*paste_image->rows+0.5);
10662 (void) XCheckDefineCursor(display,windows->image.id,cursor);
10663 paste_info.x=(ssize_t) windows->image.x+event.xbutton.x;
10664 paste_info.y=(ssize_t) windows->image.y+event.xbutton.y;
10667 case ButtonRelease:
10669 if (resource_info->debug != MagickFalse)
10670 (void) LogMagickEvent(X11Event,GetMagickModule(),
10671 "Button Release: 0x%lx %u +%d+%d",event.xbutton.window,
10672 event.xbutton.button,event.xbutton.x,event.xbutton.y);
10673 if (event.xbutton.button != Button1)
10675 if (event.xbutton.window != windows->image.id)
10677 if ((paste_info.width != 0) && (paste_info.height != 0))
10682 paste_info.x=(ssize_t) windows->image.x+event.xbutton.x;
10683 paste_info.y=(ssize_t) windows->image.y+event.xbutton.y;
10693 command[MaxTextExtent];
10701 if (event.xkey.window != windows->image.id)
10706 length=XLookupString((XKeyEvent *) &event.xkey,command,(
int)
10707 sizeof(command),&key_symbol,(XComposeStatus *) NULL);
10708 *(command+length)=
'\0';
10709 if (resource_info->debug != MagickFalse)
10710 (void) LogMagickEvent(X11Event,GetMagickModule(),
10711 "Key press: 0x%lx (%s)",(
long) key_symbol,command);
10712 switch ((
int) key_symbol)
10720 paste_image=DestroyImage(paste_image);
10721 state|=EscapeState;
10728 (void) XSetFunction(display,windows->image.highlight_context,
10730 XTextViewHelp(display,resource_info,windows,MagickFalse,
10731 "Help Viewer - Image Composite",ImagePasteHelp);
10732 (void) XSetFunction(display,windows->image.highlight_context,
10738 (void) XBell(display,0);
10751 if (windows->info.mapped != MagickFalse)
10753 if ((x < (
int) (windows->info.x+windows->info.width)) &&
10754 (y < (
int) (windows->info.y+windows->info.height)))
10755 (void) XWithdrawWindow(display,windows->info.id,
10756 windows->info.screen);
10759 if ((x > (
int) (windows->info.x+windows->info.width)) ||
10760 (y > (
int) (windows->info.y+windows->info.height)))
10761 (void) XMapWindow(display,windows->info.id);
10762 paste_info.x=(ssize_t) windows->image.x+x;
10763 paste_info.y=(ssize_t) windows->image.y+y;
10768 if (resource_info->debug != MagickFalse)
10769 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Event type: %d",
10774 }
while ((state & ExitState) == 0);
10775 (void) XSelectInput(display,windows->image.id,
10776 windows->image.attributes.event_mask);
10777 (void) XSetFunction(display,windows->image.highlight_context,GXcopy);
10778 XSetCursorState(display,windows,MagickFalse);
10779 (void) XFreeCursor(display,cursor);
10780 if ((state & EscapeState) != 0)
10781 return(MagickTrue);
10785 XSetCursorState(display,windows,MagickTrue);
10786 XCheckRefreshWindows(display,windows);
10787 width=(
unsigned int) image->columns;
10788 height=(
unsigned int) image->rows;
10791 if (windows->image.crop_geometry != (
char *) NULL)
10792 (void) XParseGeometry(windows->image.crop_geometry,&x,&y,&width,&height);
10793 scale_factor=(MagickRealType) width/windows->image.ximage->width;
10795 paste_info.x=(ssize_t) (scale_factor*paste_info.x+0.5);
10796 paste_info.width=(
unsigned int) (scale_factor*paste_info.width+0.5);
10797 scale_factor=(MagickRealType) height/windows->image.ximage->height;
10799 paste_info.y=(ssize_t) (scale_factor*paste_info.y*scale_factor+0.5);
10800 paste_info.height=(
unsigned int) (scale_factor*paste_info.height+0.5);
10804 (void) CompositeImage(image,compose,paste_image,paste_info.x,paste_info.y);
10805 paste_image=DestroyImage(paste_image);
10806 XSetCursorState(display,windows,MagickFalse);
10810 XConfigureImageColormap(display,resource_info,windows,image);
10811 (void) XConfigureImage(display,resource_info,windows,image);
10812 return(MagickTrue);
10845static MagickBooleanType XPrintImage(Display *display,
10846 XResourceInfo *resource_info,XWindows *windows,Image *image)
10849 filename[MaxTextExtent],
10850 geometry[MaxTextExtent];
10853 *
const PageSizes[] =
10884 image_info=CloneImageInfo(resource_info->image_info);
10885 (void) FormatLocaleString(geometry,MaxTextExtent,
"Letter");
10886 if (image_info->page != (
char *) NULL)
10887 (void) CopyMagickString(geometry,image_info->page,MaxTextExtent);
10888 XListBrowserWidget(display,windows,&windows->widget,PageSizes,
"Select",
10889 "Select Postscript Page Geometry:",geometry);
10890 if (*geometry ==
'\0')
10891 return(MagickTrue);
10892 image_info->page=GetPageGeometry(geometry);
10896 XSetCursorState(display,windows,MagickTrue);
10897 XCheckRefreshWindows(display,windows);
10898 print_image=CloneImage(image,0,0,MagickTrue,&image->exception);
10899 if (print_image == (Image *) NULL)
10900 return(MagickFalse);
10901 (void) FormatLocaleString(geometry,MaxTextExtent,
"%dx%d!",
10902 windows->image.ximage->width,windows->image.ximage->height);
10903 (void) TransformImage(&print_image,windows->image.crop_geometry,geometry);
10907 (void) AcquireUniqueFilename(filename);
10908 (void) FormatLocaleString(print_image->filename,MaxTextExtent,
"print:%s",
10910 status=WriteImage(image_info,print_image);
10911 (void) RelinquishUniqueFileResource(filename);
10912 print_image=DestroyImage(print_image);
10913 image_info=DestroyImageInfo(image_info);
10914 XSetCursorState(display,windows,MagickFalse);
10915 return(status != 0 ? MagickTrue : MagickFalse);
10948static MagickBooleanType XROIImage(Display *display,
10949 XResourceInfo *resource_info,XWindows *windows,Image **image)
10951#define ApplyMenus 7
10960 *
const ApplyMenu[] =
10973 *
const FileMenu[] =
10979 *
const EditMenu[] =
10985 *
const TransformMenu[] =
10993 *
const EnhanceMenu[] =
11001 "Contrast Stretch...",
11002 "Sigmoidal Contrast...",
11011 *
const EffectsMenu[] =
11036 "Charcoal Draw...",
11039 *
const MiscellanyMenu[] =
11050 *
const *Menus[ApplyMenus] =
11061 static const DisplayCommand
11084 TransformCommands[] =
11088 RotateRightCommand,
11091 EnhanceCommands[] =
11099 ContrastStretchCommand,
11100 SigmoidalContrastCommand,
11108 EffectsCommands[] =
11112 ReduceNoiseCommand,
11132 CharcoalDrawCommand
11134 MiscellanyCommands[] =
11138 ShowPreviewCommand,
11139 ShowHistogramCommand,
11148 static const DisplayCommand
11149 *Commands[ApplyMenus] =
11161 command[MaxTextExtent],
11162 text[MaxTextExtent];
11182 MagickProgressMonitor
11203 (void) CloneString(&windows->command.name,
"ROI");
11204 windows->command.data=0;
11205 (void) XCommandWidget(display,windows,ROIMenu,(XEvent *) NULL);
11206 (void) XMapRaised(display,windows->command.id);
11207 XClientMessage(display,windows->image.id,windows->im_protocols,
11208 windows->im_update_widget,CurrentTime);
11212 XQueryPosition(display,windows->image.id,&x,&y);
11213 (void) XSelectInput(display,windows->image.id,
11214 windows->image.attributes.event_mask | PointerMotionMask);
11216 crop_info.height=0;
11219 roi_info.x=(ssize_t) windows->image.x+x;
11220 roi_info.y=(ssize_t) windows->image.y+y;
11223 cursor=XCreateFontCursor(display,XC_fleur);
11224 state=DefaultState;
11227 if (windows->info.mapped != MagickFalse)
11232 (void) FormatLocaleString(text,MaxTextExtent,
" %+ld%+ld ",
11233 (
long) roi_info.x,(
long) roi_info.y);
11234 XInfoWidget(display,windows,text);
11239 XScreenEvent(display,windows,&event);
11240 if (event.xany.window == windows->command.id)
11245 id=XCommandWidget(display,windows,ROIMenu,&event);
11248 switch (ROICommands[
id])
11250 case ROIHelpCommand:
11252 XTextViewHelp(display,resource_info,windows,MagickFalse,
11253 "Help Viewer - Region of Interest",ImageROIHelp);
11256 case ROIDismissCommand:
11261 state|=EscapeState;
11270 switch (event.type)
11274 if (event.xbutton.button != Button1)
11276 if (event.xbutton.window != windows->image.id)
11281 (void) XCheckDefineCursor(display,windows->image.id,cursor);
11282 roi_info.x=(ssize_t) windows->image.x+event.xbutton.x;
11283 roi_info.y=(ssize_t) windows->image.y+event.xbutton.y;
11287 case ButtonRelease:
11296 if (event.xkey.window != windows->image.id)
11301 (void) XLookupString((XKeyEvent *) &event.xkey,command,(
int)
11302 sizeof(command),&key_symbol,(XComposeStatus *) NULL);
11303 switch ((
int) key_symbol)
11311 state|=EscapeState;
11318 XTextViewHelp(display,resource_info,windows,MagickFalse,
11319 "Help Viewer - Region of Interest",ImageROIHelp);
11324 (void) XBell(display,0);
11337 if (windows->info.mapped != MagickFalse)
11339 if ((x < (
int) (windows->info.x+windows->info.width)) &&
11340 (y < (
int) (windows->info.y+windows->info.height)))
11341 (void) XWithdrawWindow(display,windows->info.id,
11342 windows->info.screen);
11345 if ((x > (
int) (windows->info.x+windows->info.width)) ||
11346 (y > (
int) (windows->info.y+windows->info.height)))
11347 (void) XMapWindow(display,windows->info.id);
11348 roi_info.x=(ssize_t) windows->image.x+x;
11349 roi_info.y=(ssize_t) windows->image.y+y;
11355 }
while ((state & ExitState) == 0);
11356 (void) XSelectInput(display,windows->image.id,
11357 windows->image.attributes.event_mask);
11358 if ((state & EscapeState) != 0)
11363 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
11364 (void) XFreeCursor(display,cursor);
11365 return(MagickTrue);
11367 (void) XSetFunction(display,windows->image.highlight_context,GXinvert);
11373 x=(int) roi_info.x;
11374 y=(int) roi_info.y;
11377 state=DefaultState;
11380 highlight_info=roi_info;
11381 highlight_info.x=roi_info.x-windows->image.x;
11382 highlight_info.y=roi_info.y-windows->image.y;
11383 if ((highlight_info.width > 3) && (highlight_info.height > 3))
11388 if (windows->info.mapped == MagickFalse)
11389 (void) XMapWindow(display,windows->info.id);
11390 (void) FormatLocaleString(text,MaxTextExtent,
11391 " %.20gx%.20g%+.20g%+.20g",(
double) roi_info.width,(
double)
11392 roi_info.height,(
double) roi_info.x,(
double) roi_info.y);
11393 XInfoWidget(display,windows,text);
11394 XHighlightRectangle(display,windows->image.id,
11395 windows->image.highlight_context,&highlight_info);
11398 if (windows->info.mapped != MagickFalse)
11399 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
11403 XScreenEvent(display,windows,&event);
11404 if ((highlight_info.width > 3) && (highlight_info.height > 3))
11405 XHighlightRectangle(display,windows->image.id,
11406 windows->image.highlight_context,&highlight_info);
11407 switch (event.type)
11411 roi_info.x=(ssize_t) windows->image.x+event.xbutton.x;
11412 roi_info.y=(ssize_t) windows->image.y+event.xbutton.y;
11415 case ButtonRelease:
11420 roi_info.x=(ssize_t) windows->image.x+event.xbutton.x;
11421 roi_info.y=(ssize_t) windows->image.y+event.xbutton.y;
11422 XSetCursorState(display,windows,MagickFalse);
11424 if (LocaleCompare(windows->command.name,
"Apply") == 0)
11426 (void) CloneString(&windows->command.name,
"Apply");
11427 windows->command.data=ApplyMenus;
11428 (void) XCommandWidget(display,windows,ApplyMenu,(XEvent *) NULL);
11435 roi_info.x=(ssize_t) windows->image.x+event.xmotion.x;
11436 roi_info.y=(ssize_t) windows->image.y+event.xmotion.y;
11441 if ((((
int) roi_info.x != x) && ((
int) roi_info.y != y)) ||
11442 ((state & ExitState) != 0))
11447 if (roi_info.x < 0)
11450 if (roi_info.x > (ssize_t) windows->image.ximage->width)
11451 roi_info.x=(ssize_t) windows->image.ximage->width;
11452 if ((
int) roi_info.x < x)
11453 roi_info.width=(
unsigned int) (x-roi_info.x);
11456 roi_info.width=(
unsigned int) (roi_info.x-x);
11457 roi_info.x=(ssize_t) x;
11459 if (roi_info.y < 0)
11462 if (roi_info.y > (ssize_t) windows->image.ximage->height)
11463 roi_info.y=(ssize_t) windows->image.ximage->height;
11464 if ((
int) roi_info.y < y)
11465 roi_info.height=(
unsigned int) (y-roi_info.y);
11468 roi_info.height=(
unsigned int) (roi_info.y-y);
11469 roi_info.y=(ssize_t) y;
11472 }
while ((state & ExitState) == 0);
11476 state=DefaultState;
11477 display_command=NullCommand;
11478 (void) XMapWindow(display,windows->info.id);
11481 if (windows->info.mapped != MagickFalse)
11486 (void) FormatLocaleString(text,MaxTextExtent,
11487 " %.20gx%.20g%+.20g%+.20g",(
double) roi_info.width,(
double)
11488 roi_info.height,(
double) roi_info.x,(
double) roi_info.y);
11489 XInfoWidget(display,windows,text);
11491 highlight_info=roi_info;
11492 highlight_info.x=roi_info.x-windows->image.x;
11493 highlight_info.y=roi_info.y-windows->image.y;
11494 if ((highlight_info.width <= 3) || (highlight_info.height <= 3))
11496 state|=EscapeState;
11500 if ((state & UpdateRegionState) != 0)
11502 (void) XSetFunction(display,windows->image.highlight_context,GXcopy);
11503 switch (display_command)
11508 (void) XMagickCommand(display,resource_info,windows,
11509 display_command,image);
11517 progress_monitor=SetImageProgressMonitor(*image,
11518 (MagickProgressMonitor) NULL,(*image)->client_data);
11519 crop_info=roi_info;
11520 width=(
unsigned int) (*image)->columns;
11521 height=(
unsigned int) (*image)->rows;
11524 if (windows->image.crop_geometry != (
char *) NULL)
11525 (void) XParseGeometry(windows->image.crop_geometry,&x,&y,
11527 scale_factor=(MagickRealType) width/windows->image.ximage->width;
11529 crop_info.x=(ssize_t) (scale_factor*crop_info.x+0.5);
11530 crop_info.width=(
unsigned int) (scale_factor*crop_info.width+0.5);
11531 scale_factor=(MagickRealType)
11532 height/windows->image.ximage->height;
11534 crop_info.y=(ssize_t) (scale_factor*crop_info.y+0.5);
11535 crop_info.height=(
unsigned int)
11536 (scale_factor*crop_info.height+0.5);
11537 roi_image=CropImage(*image,&crop_info,&(*image)->exception);
11538 (void) SetImageProgressMonitor(*image,progress_monitor,
11539 (*image)->client_data);
11540 if (roi_image == (Image *) NULL)
11545 windows->image.orphan=MagickTrue;
11546 (void) XMagickCommand(display,resource_info,windows,
11547 display_command,&roi_image);
11548 progress_monitor=SetImageProgressMonitor(*image,
11549 (MagickProgressMonitor) NULL,(*image)->client_data);
11550 (void) XMagickCommand(display,resource_info,windows,
11551 SaveToUndoBufferCommand,image);
11552 windows->image.orphan=MagickFalse;
11553 (void) CompositeImage(*image,CopyCompositeOp,roi_image,
11554 crop_info.x,crop_info.y);
11555 roi_image=DestroyImage(roi_image);
11556 (void) SetImageProgressMonitor(*image,progress_monitor,
11557 (*image)->client_data);
11561 if (display_command != InfoCommand)
11563 XConfigureImageColormap(display,resource_info,windows,*image);
11564 (void) XConfigureImage(display,resource_info,windows,*image);
11566 XCheckRefreshWindows(display,windows);
11567 XInfoWidget(display,windows,text);
11568 (void) XSetFunction(display,windows->image.highlight_context,
11570 state&=(~UpdateRegionState);
11572 XHighlightRectangle(display,windows->image.id,
11573 windows->image.highlight_context,&highlight_info);
11574 XScreenEvent(display,windows,&event);
11575 if (event.xany.window == windows->command.id)
11580 (void) XSetFunction(display,windows->image.highlight_context,GXcopy);
11581 display_command=NullCommand;
11582 id=XCommandWidget(display,windows,ApplyMenu,&event);
11585 (void) CopyMagickString(command,ApplyMenu[
id],MaxTextExtent);
11586 display_command=ApplyCommands[id];
11587 if (
id < ApplyMenus)
11592 entry=XMenuWidget(display,windows,ApplyMenu[
id],
11593 (
const char **) Menus[
id],command);
11596 (void) CopyMagickString(command,Menus[
id][entry],
11598 display_command=Commands[id][entry];
11602 (void) XSetFunction(display,windows->image.highlight_context,
11604 XHighlightRectangle(display,windows->image.id,
11605 windows->image.highlight_context,&highlight_info);
11606 if (display_command == HelpCommand)
11608 (void) XSetFunction(display,windows->image.highlight_context,
11610 XTextViewHelp(display,resource_info,windows,MagickFalse,
11611 "Help Viewer - Region of Interest",ImageROIHelp);
11612 (void) XSetFunction(display,windows->image.highlight_context,
11616 if (display_command == QuitCommand)
11621 state|=EscapeState;
11625 if (display_command != NullCommand)
11626 state|=UpdateRegionState;
11629 XHighlightRectangle(display,windows->image.id,
11630 windows->image.highlight_context,&highlight_info);
11631 switch (event.type)
11635 x=windows->image.x;
11636 y=windows->image.y;
11637 if (event.xbutton.button != Button1)
11639 if (event.xbutton.window != windows->image.id)
11641 x=windows->image.x+
event.xbutton.x;
11642 y=windows->image.y+
event.xbutton.y;
11643 if ((x < (
int) (roi_info.x+RoiDelta)) &&
11644 (x > (
int) (roi_info.x-RoiDelta)) &&
11645 (y < (
int) (roi_info.y+RoiDelta)) &&
11646 (y > (
int) (roi_info.y-RoiDelta)))
11648 roi_info.x=(ssize_t) (roi_info.x+roi_info.width);
11649 roi_info.y=(ssize_t) (roi_info.y+roi_info.height);
11650 state|=UpdateConfigurationState;
11653 if ((x < (
int) (roi_info.x+RoiDelta)) &&
11654 (x > (
int) (roi_info.x-RoiDelta)) &&
11655 (y < (
int) (roi_info.y+roi_info.height+RoiDelta)) &&
11656 (y > (
int) (roi_info.y+roi_info.height-RoiDelta)))
11658 roi_info.x=(ssize_t) (roi_info.x+roi_info.width);
11659 state|=UpdateConfigurationState;
11662 if ((x < (
int) (roi_info.x+roi_info.width+RoiDelta)) &&
11663 (x > (
int) (roi_info.x+roi_info.width-RoiDelta)) &&
11664 (y < (
int) (roi_info.y+RoiDelta)) &&
11665 (y > (
int) (roi_info.y-RoiDelta)))
11667 roi_info.y=(ssize_t) (roi_info.y+roi_info.height);
11668 state|=UpdateConfigurationState;
11671 if ((x < (
int) (roi_info.x+roi_info.width+RoiDelta)) &&
11672 (x > (
int) (roi_info.x+roi_info.width-RoiDelta)) &&
11673 (y < (
int) (roi_info.y+roi_info.height+RoiDelta)) &&
11674 (y > (
int) (roi_info.y+roi_info.height-RoiDelta)))
11676 state|=UpdateConfigurationState;
11679 magick_fallthrough;
11681 case ButtonRelease:
11683 if (event.xbutton.window == windows->pan.id)
11684 if ((highlight_info.x != crop_info.x-windows->image.x) ||
11685 (highlight_info.y != crop_info.y-windows->image.y))
11686 XHighlightRectangle(display,windows->image.id,
11687 windows->image.highlight_context,&highlight_info);
11688 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->image.id,
11689 event.xbutton.time);
11694 if (event.xexpose.window == windows->image.id)
11695 if (event.xexpose.count == 0)
11697 event.xexpose.x=(int) highlight_info.x;
11698 event.xexpose.y=(int) highlight_info.y;
11699 event.xexpose.width=(int) highlight_info.width;
11700 event.xexpose.height=(int) highlight_info.height;
11701 XRefreshWindow(display,&windows->image,&event);
11703 if (event.xexpose.window == windows->info.id)
11704 if (event.xexpose.count == 0)
11705 XInfoWidget(display,windows,text);
11713 if (event.xkey.window != windows->image.id)
11718 (void) XLookupString((XKeyEvent *) &event.xkey,command,(
int)
11719 sizeof(command),&key_symbol,(XComposeStatus *) NULL);
11720 switch ((
int) key_symbol)
11728 state|=EscapeState;
11729 magick_fallthrough;
11739 roi_info.x=(ssize_t) (windows->image.width/2L-roi_info.width/2L);
11740 roi_info.y=(ssize_t) (windows->image.height/2L-
11741 roi_info.height/2L);
11773 (void) XSetFunction(display,windows->image.highlight_context,
11775 XTextViewHelp(display,resource_info,windows,MagickFalse,
11776 "Help Viewer - Region of Interest",ImageROIHelp);
11777 (void) XSetFunction(display,windows->image.highlight_context,
11783 display_command=XImageWindowCommand(display,resource_info,windows,
11784 event.xkey.state,key_symbol,image);
11785 if (display_command != NullCommand)
11786 state|=UpdateRegionState;
11790 (void) XSetSelectionOwner(display,XA_PRIMARY,windows->image.id,
11798 if (event.xbutton.window != windows->image.id)
11805 if (windows->info.mapped != MagickFalse)
11807 if ((x < (
int) (windows->info.x+windows->info.width)) &&
11808 (y < (
int) (windows->info.y+windows->info.height)))
11809 (void) XWithdrawWindow(display,windows->info.id,
11810 windows->info.screen);
11813 if ((x > (
int) (windows->info.x+windows->info.width)) ||
11814 (y > (
int) (windows->info.y+windows->info.height)))
11815 (void) XMapWindow(display,windows->info.id);
11816 roi_info.x=(ssize_t) windows->image.x+event.xmotion.x;
11817 roi_info.y=(ssize_t) windows->image.y+event.xmotion.y;
11820 case SelectionRequest:
11825 XSelectionRequestEvent
11831 (void) FormatLocaleString(text,MaxTextExtent,
11832 "%.20gx%.20g%+.20g%+.20g",(
double) roi_info.width,(
double)
11833 roi_info.height,(
double) roi_info.x,(
double) roi_info.y);
11834 request=(&(
event.xselectionrequest));
11835 (void) XChangeProperty(request->display,request->requestor,
11836 request->property,request->target,8,PropModeReplace,
11837 (
unsigned char *) text,(
int) strlen(text));
11838 notify.type=SelectionNotify;
11839 notify.display=request->display;
11840 notify.requestor=request->requestor;
11841 notify.selection=request->selection;
11842 notify.target=request->target;
11843 notify.time=request->time;
11844 if (request->property == None)
11845 notify.property=request->target;
11847 notify.property=request->property;
11848 (void) XSendEvent(request->display,request->requestor,False,0,
11849 (XEvent *) ¬ify);
11854 if ((state & UpdateConfigurationState) != 0)
11856 (void) XPutBackEvent(display,&event);
11857 (void) XCheckDefineCursor(display,windows->image.id,cursor);
11860 }
while ((state & ExitState) == 0);
11861 }
while ((state & ExitState) == 0);
11862 (void) XSetFunction(display,windows->image.highlight_context,GXcopy);
11863 XSetCursorState(display,windows,MagickFalse);
11864 if ((state & EscapeState) != 0)
11865 return(MagickTrue);
11866 return(MagickTrue);
11903static MagickBooleanType XRotateImage(Display *display,
11904 XResourceInfo *resource_info,XWindows *windows,
double degrees,Image **image)
11907 *
const RotateMenu[] =
11917 direction = HorizontalRotateCommand;
11919 static const ModeType
11920 DirectionCommands[] =
11922 HorizontalRotateCommand,
11923 VerticalRotateCommand
11927 RotateColorCommand,
11928 RotateDirectionCommand,
11930 RotateDismissCommand
11933 static unsigned int
11937 command[MaxTextExtent],
11938 text[MaxTextExtent];
11949 normalized_degrees;
11959 if (degrees == 0.0)
11976 (void) CloneString(&windows->command.name,
"Rotate");
11977 windows->command.data=2;
11978 (void) XCommandWidget(display,windows,RotateMenu,(XEvent *) NULL);
11979 (void) XMapRaised(display,windows->command.id);
11980 XClientMessage(display,windows->image.id,windows->im_protocols,
11981 windows->im_update_widget,CurrentTime);
11985 (void) XSetFunction(display,windows->image.highlight_context,GXinvert);
11986 XQueryPosition(display,windows->image.id,&x,&y);
11991 state=DefaultState;
11994 XHighlightLine(display,windows->image.id,
11995 windows->image.highlight_context,&rotate_info);
11999 XScreenEvent(display,windows,&event);
12000 XHighlightLine(display,windows->image.id,
12001 windows->image.highlight_context,&rotate_info);
12002 if (event.xany.window == windows->command.id)
12007 id=XCommandWidget(display,windows,RotateMenu,&event);
12010 (void) XSetFunction(display,windows->image.highlight_context,
12012 switch (RotateCommands[
id])
12014 case RotateColorCommand:
12017 *ColorMenu[MaxNumberPens];
12028 for (i=0; i < (int) (MaxNumberPens-2); i++)
12029 ColorMenu[i]=resource_info->pen_colors[i];
12030 ColorMenu[MaxNumberPens-2]=
"Browser...";
12031 ColorMenu[MaxNumberPens-1]=(
const char *) NULL;
12035 pen_number=XMenuWidget(display,windows,RotateMenu[
id],
12036 (
const char **) ColorMenu,command);
12037 if (pen_number < 0)
12039 if (pen_number == (MaxNumberPens-2))
12042 color_name[MaxTextExtent] =
"gray";
12047 resource_info->pen_colors[pen_number]=color_name;
12048 XColorBrowserWidget(display,windows,
"Select",color_name);
12049 if (*color_name ==
'\0')
12055 (void) XParseColor(display,windows->map_info->colormap,
12056 resource_info->pen_colors[pen_number],&color);
12057 XBestPixel(display,windows->map_info->colormap,(XColor *) NULL,
12058 (
unsigned int) MaxColors,&color);
12059 windows->pixel_info->pen_colors[pen_number]=color;
12060 pen_id=(
unsigned int) pen_number;
12063 case RotateDirectionCommand:
12066 *
const Directions[] =
12076 id=XMenuWidget(display,windows,RotateMenu[
id],
12077 Directions,command);
12079 direction=DirectionCommands[id];
12082 case RotateHelpCommand:
12084 XTextViewHelp(display,resource_info,windows,MagickFalse,
12085 "Help Viewer - Image Rotation",ImageRotateHelp);
12088 case RotateDismissCommand:
12093 state|=EscapeState;
12100 (void) XSetFunction(display,windows->image.highlight_context,
12104 switch (event.type)
12108 if (event.xbutton.button != Button1)
12110 if (event.xbutton.window != windows->image.id)
12115 (void) XSetFunction(display,windows->image.highlight_context,
12117 rotate_info.x1=
event.xbutton.x;
12118 rotate_info.y1=
event.xbutton.y;
12122 case ButtonRelease:
12129 command[MaxTextExtent];
12134 if (event.xkey.window != windows->image.id)
12139 (void) XLookupString((XKeyEvent *) &event.xkey,command,(
int)
12140 sizeof(command),&key_symbol,(XComposeStatus *) NULL);
12141 switch ((
int) key_symbol)
12149 state|=EscapeState;
12156 (void) XSetFunction(display,windows->image.highlight_context,
12158 XTextViewHelp(display,resource_info,windows,MagickFalse,
12159 "Help Viewer - Image Rotation",ImageRotateHelp);
12160 (void) XSetFunction(display,windows->image.highlight_context,
12166 (void) XBell(display,0);
12174 rotate_info.x1=
event.xmotion.x;
12175 rotate_info.y1=
event.xmotion.y;
12178 rotate_info.x2=rotate_info.x1;
12179 rotate_info.y2=rotate_info.y1;
12180 if (direction == HorizontalRotateCommand)
12181 rotate_info.x2+=32;
12183 rotate_info.y2-=32;
12184 }
while ((state & ExitState) == 0);
12185 (void) XSetFunction(display,windows->image.highlight_context,GXcopy);
12186 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
12187 if ((state & EscapeState) != 0)
12188 return(MagickTrue);
12193 (void) XSetFunction(display,windows->image.highlight_context,GXinvert);
12194 state=DefaultState;
12202 if (windows->info.mapped == MagickFalse)
12203 (void) XMapWindow(display,windows->info.id);
12204 (void) FormatLocaleString(text,MaxTextExtent,
" %g",
12205 direction == VerticalRotateCommand ? degrees-90.0 : degrees);
12206 XInfoWidget(display,windows,text);
12207 XHighlightLine(display,windows->image.id,
12208 windows->image.highlight_context,&rotate_info);
12211 if (windows->info.mapped != MagickFalse)
12212 (void) XWithdrawWindow(display,windows->info.id,
12213 windows->info.screen);
12217 XScreenEvent(display,windows,&event);
12219 XHighlightLine(display,windows->image.id,
12220 windows->image.highlight_context,&rotate_info);
12221 switch (event.type)
12225 case ButtonRelease:
12230 rotate_info.x2=
event.xbutton.x;
12231 rotate_info.y2=
event.xbutton.y;
12239 rotate_info.x2=
event.xmotion.x;
12240 rotate_info.y2=
event.xmotion.y;
12248 if (rotate_info.x2 < 0)
12251 if (rotate_info.x2 > (
int) windows->image.width)
12252 rotate_info.x2=(short) windows->image.width;
12253 if (rotate_info.y2 < 0)
12256 if (rotate_info.y2 > (
int) windows->image.height)
12257 rotate_info.y2=(short) windows->image.height;
12262 distance=(
unsigned int)
12263 ((rotate_info.x2-rotate_info.x1+1)*(rotate_info.x2-rotate_info.x1+1))+
12264 ((rotate_info.y2-rotate_info.y1+1)*(rotate_info.y2-rotate_info.y1+1));
12266 degrees=RadiansToDegrees(-atan2((
double) (rotate_info.y2-
12267 rotate_info.y1),(
double) (rotate_info.x2-rotate_info.x1)));
12268 }
while ((state & ExitState) == 0);
12269 (void) XSetFunction(display,windows->image.highlight_context,GXcopy);
12270 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
12272 return(MagickTrue);
12274 if (direction == VerticalRotateCommand)
12276 if (degrees == 0.0)
12277 return(MagickTrue);
12281 normalized_degrees=degrees;
12282 while (normalized_degrees < -45.0)
12283 normalized_degrees+=360.0;
12284 for (rotations=0; normalized_degrees > 45.0; rotations++)
12285 normalized_degrees-=90.0;
12286 if (normalized_degrees != 0.0)
12287 (void) XMagickCommand(display,resource_info,windows,ApplyCommand,image);
12288 XSetCursorState(display,windows,MagickTrue);
12289 XCheckRefreshWindows(display,windows);
12290 (*image)->background_color.red=ScaleShortToQuantum(
12291 windows->pixel_info->pen_colors[pen_id].red);
12292 (*image)->background_color.green=ScaleShortToQuantum(
12293 windows->pixel_info->pen_colors[pen_id].green);
12294 (*image)->background_color.blue=ScaleShortToQuantum(
12295 windows->pixel_info->pen_colors[pen_id].blue);
12296 rotate_image=RotateImage(*image,degrees,&(*image)->exception);
12297 XSetCursorState(display,windows,MagickFalse);
12298 if (rotate_image == (Image *) NULL)
12299 return(MagickFalse);
12300 *image=DestroyImage(*image);
12301 *image=rotate_image;
12302 if (windows->image.crop_geometry != (
char *) NULL)
12307 width=(
unsigned int) (*image)->columns;
12308 height=(
unsigned int) (*image)->rows;
12309 (void) XParseGeometry(windows->image.crop_geometry,&x,&y,&width,&height);
12310 switch (rotations % 4)
12320 (void) FormatLocaleString(windows->image.crop_geometry,MaxTextExtent,
12321 "%ux%u%+d%+d",height,width,(
int) (*image)->columns-
12330 (void) FormatLocaleString(windows->image.crop_geometry,MaxTextExtent,
12331 "%ux%u%+d%+d",width,height,(
int) width-x,(
int) height-y);
12339 (void) FormatLocaleString(windows->image.crop_geometry,MaxTextExtent,
12340 "%ux%u%+d%+d",height,width,y,(
int) (*image)->rows-(
int) width-x);
12345 if (windows->image.orphan != MagickFalse)
12346 return(MagickTrue);
12347 if (normalized_degrees != 0.0)
12352 windows->image.window_changes.width=(int) (*image)->columns;
12353 windows->image.window_changes.height=(int) (*image)->rows;
12354 if (windows->image.crop_geometry != (
char *) NULL)
12359 (void) XParseGeometry(windows->image.crop_geometry,&x,&y,
12361 windows->image.window_changes.width=(int) width;
12362 windows->image.window_changes.height=(int) height;
12364 XConfigureImageColormap(display,resource_info,windows,*image);
12367 if (((rotations % 4) == 1) || ((rotations % 4) == 3))
12369 windows->image.window_changes.width=windows->image.ximage->height;
12370 windows->image.window_changes.height=windows->image.ximage->width;
12375 (void) XConfigureImage(display,resource_info,windows,*image);
12376 return(MagickTrue);
12409static MagickBooleanType XSaveImage(Display *display,
12410 XResourceInfo *resource_info,XWindows *windows,Image *image)
12413 filename[MaxTextExtent],
12414 geometry[MaxTextExtent];
12428 if (resource_info->write_filename != (
char *) NULL)
12429 (void) CopyMagickString(filename,resource_info->write_filename,
12434 path[MaxTextExtent];
12439 GetPathComponent(image->filename,HeadPath,path);
12440 GetPathComponent(image->filename,TailPath,filename);
12443 status=chdir(path);
12445 (void) ThrowMagickException(&image->exception,GetMagickModule(),
12446 FileOpenError,
"UnableToOpenFile",
"%s",path);
12449 XFileBrowserWidget(display,windows,
"Save",filename);
12450 if (*filename ==
'\0')
12451 return(MagickTrue);
12452 if (IsPathAccessible(filename) != MagickFalse)
12460 status=XConfirmWidget(display,windows,
"Overwrite",filename);
12462 return(MagickTrue);
12464 image_info=CloneImageInfo(resource_info->image_info);
12465 (void) CopyMagickString(image_info->filename,filename,MaxTextExtent);
12466 (void) SetImageInfo(image_info,1,&image->exception);
12467 if ((LocaleCompare(image_info->magick,
"JPEG") == 0) ||
12468 (LocaleCompare(image_info->magick,
"JPG") == 0))
12471 quality[MaxTextExtent];
12479 (void) FormatLocaleString(quality,MaxTextExtent,
"%.20g",(
double)
12481 status=XDialogWidget(display,windows,
"Save",
"Enter JPEG quality:",
12483 if (*quality ==
'\0')
12484 return(MagickTrue);
12485 image->quality=StringToUnsignedLong(quality);
12486 image_info->interlace=status != 0 ? NoInterlace : PlaneInterlace;
12488 if ((LocaleCompare(image_info->magick,
"EPS") == 0) ||
12489 (LocaleCompare(image_info->magick,
"PDF") == 0) ||
12490 (LocaleCompare(image_info->magick,
"PS") == 0) ||
12491 (LocaleCompare(image_info->magick,
"PS2") == 0))
12494 geometry[MaxTextExtent];
12497 *
const PageSizes[] =
12519 (void) CopyMagickString(geometry,PSPageGeometry,MaxTextExtent);
12520 if (LocaleCompare(image_info->magick,
"PDF") == 0)
12521 (void) CopyMagickString(geometry,PSPageGeometry,MaxTextExtent);
12522 if (image_info->page != (
char *) NULL)
12523 (void) CopyMagickString(geometry,image_info->page,MaxTextExtent);
12524 XListBrowserWidget(display,windows,&windows->widget,PageSizes,
"Select",
12525 "Select page geometry:",geometry);
12526 if (*geometry !=
'\0')
12527 image_info->page=GetPageGeometry(geometry);
12532 XSetCursorState(display,windows,MagickTrue);
12533 XCheckRefreshWindows(display,windows);
12534 save_image=CloneImage(image,0,0,MagickTrue,&image->exception);
12535 if (save_image == (Image *) NULL)
12536 return(MagickFalse);
12537 (void) FormatLocaleString(geometry,MaxTextExtent,
"%dx%d!",
12538 windows->image.ximage->width,windows->image.ximage->height);
12539 (void) TransformImage(&save_image,windows->image.crop_geometry,geometry);
12543 (void) CopyMagickString(save_image->filename,filename,MaxTextExtent);
12544 status=WriteImage(image_info,save_image);
12545 if (status != MagickFalse)
12546 image->taint=MagickFalse;
12547 save_image=DestroyImage(save_image);
12548 image_info=DestroyImageInfo(image_info);
12549 XSetCursorState(display,windows,MagickFalse);
12550 return(status != 0 ? MagickTrue : MagickFalse);
12583#if defined(__cplusplus) || defined(c_plusplus)
12587static int XPredicate(Display *magick_unused(display),XEvent *event,
char *data)
12592 magick_unreferenced(display);
12594 windows=(XWindows *) data;
12595 if ((event->type == ClientMessage) &&
12596 (event->xclient.window == windows->image.id))
12597 return(MagickFalse);
12598 return(MagickTrue);
12601#if defined(__cplusplus) || defined(c_plusplus)
12605static void XScreenEvent(Display *display,XWindows *windows,XEvent *event)
12611 (void) XIfEvent(display,event,XPredicate,(
char *) windows);
12612 if (event->xany.window == windows->command.id)
12614 switch (event->type)
12617 case ButtonRelease:
12619 if ((event->xbutton.button == Button3) &&
12620 (event->xbutton.state & Mod1Mask))
12625 event->xbutton.button=Button2;
12626 event->xbutton.state&=(~Mod1Mask);
12628 if (event->xbutton.window == windows->backdrop.id)
12630 (void) XSetInputFocus(display,event->xbutton.window,RevertToParent,
12631 event->xbutton.time);
12634 if (event->xbutton.window == windows->pan.id)
12636 XPanImage(display,windows,event);
12639 if (event->xbutton.window == windows->image.id)
12640 if (event->xbutton.button == Button2)
12645 x=
event->xbutton.x;
12646 y=
event->xbutton.y;
12650 if (x >= (
int) windows->image.width)
12651 x=(int) (windows->image.width-1);
12652 windows->magnify.x=(int) windows->image.x+x;
12656 if (y >= (
int) windows->image.height)
12657 y=(int) (windows->image.height-1);
12658 windows->magnify.y=windows->image.y+y;
12659 if (windows->magnify.mapped == MagickFalse)
12660 (void) XMapRaised(display,windows->magnify.id);
12661 XMakeMagnifyImage(display,windows);
12662 if (event->type == ButtonRelease)
12663 (void) XWithdrawWindow(display,windows->info.id,
12664 windows->info.screen);
12669 case ClientMessage:
12674 if (event->xclient.message_type != windows->wm_protocols)
12676 if (*event->xclient.data.l != (
long) windows->wm_delete_window)
12678 if (event->xclient.window == windows->magnify.id)
12680 (void) XWithdrawWindow(display,windows->magnify.id,
12681 windows->magnify.screen);
12686 case ConfigureNotify:
12688 if (event->xconfigure.window == windows->magnify.id)
12696 windows->magnify.width=(
unsigned int) event->xconfigure.width;
12697 windows->magnify.height=(
unsigned int) event->xconfigure.height;
12698 if (windows->magnify.mapped == MagickFalse)
12701 while ((
int) magnify <= event->xconfigure.width)
12703 while ((
int) magnify <= event->xconfigure.height)
12706 if (((
int) magnify != event->xconfigure.width) ||
12707 ((
int) magnify != event->xconfigure.height))
12712 window_changes.width=(int) magnify;
12713 window_changes.height=(int) magnify;
12714 (void) XReconfigureWMWindow(display,windows->magnify.id,
12715 windows->magnify.screen,(
unsigned int) (CWWidth | CWHeight),
12719 XMakeMagnifyImage(display,windows);
12726 if (event->xexpose.window == windows->image.id)
12728 XRefreshWindow(display,&windows->image,event);
12731 if (event->xexpose.window == windows->pan.id)
12732 if (event->xexpose.count == 0)
12734 XDrawPanRectangle(display,windows);
12737 if (event->xexpose.window == windows->magnify.id)
12738 if (event->xexpose.count == 0)
12740 XMakeMagnifyImage(display,windows);
12748 command[MaxTextExtent];
12753 if (event->xkey.window != windows->magnify.id)
12758 (void) XLookupString((XKeyEvent *) &event->xkey,command,(
int)
12759 sizeof(command),&key_symbol,(XComposeStatus *) NULL);
12760 XMagnifyWindowCommand(display,windows,event->xkey.state,key_symbol);
12765 if (event->xmap.window == windows->magnify.id)
12767 windows->magnify.mapped=MagickTrue;
12768 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
12771 if (event->xmap.window == windows->info.id)
12773 windows->info.mapped=MagickTrue;
12780 while (XCheckMaskEvent(display,ButtonMotionMask,event)) ;
12781 if (event->xmotion.window == windows->image.id)
12782 if (windows->magnify.mapped != MagickFalse)
12787 x=
event->xmotion.x;
12788 y=
event->xmotion.y;
12792 if (x >= (
int) windows->image.width)
12793 x=(int) (windows->image.width-1);
12794 windows->magnify.x=(int) windows->image.x+x;
12798 if (y >= (
int) windows->image.height)
12799 y=(int) (windows->image.height-1);
12800 windows->magnify.y=windows->image.y+y;
12801 XMakeMagnifyImage(display,windows);
12807 if (event->xunmap.window == windows->magnify.id)
12809 windows->magnify.mapped=MagickFalse;
12812 if (event->xunmap.window == windows->info.id)
12814 windows->info.mapped=MagickFalse;
12856static void XSetCropGeometry(Display *display,XWindows *windows,
12857 RectangleInfo *crop_info,Image *image)
12860 text[MaxTextExtent];
12873 if (windows->info.mapped != MagickFalse)
12878 (void) FormatLocaleString(text,MaxTextExtent,
" %.20gx%.20g%+.20g%+.20g",
12879 (
double) crop_info->width,(
double) crop_info->height,(
double)
12880 crop_info->x,(
double) crop_info->y);
12881 XInfoWidget(display,windows,text);
12888 width=(
unsigned int) image->columns;
12889 height=(
unsigned int) image->rows;
12890 if (windows->image.crop_geometry != (
char *) NULL)
12891 (void) XParseGeometry(windows->image.crop_geometry,&x,&y,&width,&height);
12893 windows->image.crop_geometry=AcquireString((
char *) NULL);
12897 scale_factor=(MagickRealType) width/windows->image.ximage->width;
12898 if (crop_info->x > 0)
12899 x+=(int) (scale_factor*crop_info->x+0.5);
12900 width=(
unsigned int) (scale_factor*crop_info->width+0.5);
12903 scale_factor=(MagickRealType) height/windows->image.ximage->height;
12904 if (crop_info->y > 0)
12905 y+=(int) (scale_factor*crop_info->y+0.5);
12906 height=(
unsigned int) (scale_factor*crop_info->height+0.5);
12909 (void) FormatLocaleString(windows->image.crop_geometry,MaxTextExtent,
12910 "%ux%u%+d%+d",width,height,x,y);
12950static Image *XTileImage(Display *display,XResourceInfo *resource_info,
12951 XWindows *windows,Image *image,XEvent *event)
12954 *
const VerbMenu[] =
12964 static const ModeType
12975 command[MaxTextExtent],
12976 filename[MaxTextExtent];
13007 width=(
unsigned int) image->columns;
13008 height=(
unsigned int) image->rows;
13009 if (windows->image.crop_geometry != (
char *) NULL)
13010 (void) XParseGeometry(windows->image.crop_geometry,&x,&y,&width,&height);
13011 scale_factor=(MagickRealType) width/windows->image.ximage->width;
13012 event->xbutton.x+=windows->image.x;
13013 event->xbutton.x=(int) (scale_factor*event->xbutton.x+x+0.5);
13014 scale_factor=(MagickRealType) height/windows->image.ximage->height;
13015 event->xbutton.y+=windows->image.y;
13016 event->xbutton.y=(int) (scale_factor*event->xbutton.y+y+0.5);
13020 width=(
unsigned int) image->columns;
13021 height=(
unsigned int) image->rows;
13024 (void) XParseGeometry(image->montage,&x,&y,&width,&height);
13025 tile=((
event->xbutton.y-y)/height)*(((
int) image->columns-x)/width)+
13026 (
event->xbutton.x-x)/width;
13032 (void) XBell(display,0);
13033 return((Image *) NULL);
13038 p=image->directory;
13039 for (i=tile; (i != 0) && (*p !=
'\0'); )
13050 (void) XBell(display,0);
13051 return((Image *) NULL);
13056 id=XMenuWidget(display,windows,
"Tile Verb",VerbMenu,command);
13058 return((Image *) NULL);
13060 while ((*q !=
'\xff') && (*q !=
'\0'))
13062 (void) CopyMagickString(filename,p,(
size_t) (q-p+1));
13066 XSetCursorState(display,windows,MagickTrue);
13067 XCheckRefreshWindows(display,windows);
13068 tile_image=NewImageList();
13069 switch (TileCommands[
id])
13071 case TileLoadCommand:
13076 XCheckRefreshWindows(display,windows);
13077 (void) CopyMagickString(resource_info->image_info->magick,
"MIFF",
13079 (void) CopyMagickString(resource_info->image_info->filename,filename,
13081 tile_image=ReadImage(resource_info->image_info,&image->exception);
13082 CatchException(&image->exception);
13083 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
13086 case TileNextCommand:
13091 XClientMessage(display,windows->image.id,windows->im_protocols,
13092 windows->im_next_image,CurrentTime);
13095 case TileFormerCommand:
13100 XClientMessage(display,windows->image.id,windows->im_protocols,
13101 windows->im_former_image,CurrentTime);
13104 case TileDeleteCommand:
13109 if (IsPathAccessible(filename) == MagickFalse)
13111 XNoticeWidget(display,windows,
"Image file does not exist:",filename);
13114 status=XConfirmWidget(display,windows,
"Really delete tile",filename);
13117 status=ShredFile(filename);
13118 status|=remove_utf8(filename);
13119 if (status != MagickFalse)
13121 XNoticeWidget(display,windows,
"Unable to delete image file:",
13125 magick_fallthrough;
13127 case TileUpdateCommand:
13149 for (p=image->directory; *p !=
'\0'; p++)
13155 while ((*q !=
'\xff') && (*q !=
'\0'))
13157 (void) CopyMagickString(filename,p,(
size_t) (q-p+1));
13159 if (IsPathAccessible(filename) != MagickFalse)
13167 x_offset=(int) (width*(tile % (((
int) image->columns-x)/width))+x);
13168 y_offset=(int) (height*(tile/(((
int) image->columns-x)/width))+y);
13169 exception=(&image->exception);
13170 image_view=AcquireAuthenticCacheView(image,exception);
13171 (void) GetOneCacheViewVirtualPixel(image_view,0,0,&pixel,exception);
13172 for (i=0; i < (int) height; i++)
13174 s=GetCacheViewAuthenticPixels(image_view,(ssize_t) x_offset,(ssize_t)
13175 y_offset+i,width,1,exception);
13176 if (s == (PixelPacket *) NULL)
13178 for (j=0; j < (int) width; j++)
13180 if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse)
13183 image_view=DestroyCacheView(image_view);
13186 windows->image.window_changes.width=(int) image->columns;
13187 windows->image.window_changes.height=(int) image->rows;
13188 XConfigureImageColormap(display,resource_info,windows,image);
13189 (void) XConfigureImage(display,resource_info,windows,image);
13195 XSetCursorState(display,windows,MagickFalse);
13196 return(tile_image);
13232static void XTranslateImage(Display *display,XWindows *windows,
13233 Image *image,
const KeySym key_symbol)
13236 text[MaxTextExtent];
13249 x_offset=windows->image.width;
13250 y_offset=windows->image.height;
13251 if (image->montage != (
char *) NULL)
13252 (void) XParseGeometry(image->montage,&x,&y,&x_offset,&y_offset);
13253 switch ((
int) key_symbol)
13258 windows->image.x=(int) windows->image.width/2;
13259 windows->image.y=(int) windows->image.height/2;
13265 windows->image.x-=x_offset;
13272 windows->image.y-=y_offset;
13278 windows->image.x+=x_offset;
13285 windows->image.y+=y_offset;
13294 if (windows->image.x < 0)
13295 windows->image.x=0;
13297 if ((
int) (windows->image.x+windows->image.width) >
13298 windows->image.ximage->width)
13299 windows->image.x=(int) windows->image.ximage->width-windows->image.width;
13300 if (windows->image.y < 0)
13301 windows->image.y=0;
13303 if ((
int) (windows->image.y+windows->image.height) >
13304 windows->image.ximage->height)
13305 windows->image.y=(int) windows->image.ximage->height-windows->image.height;
13309 (void) FormatLocaleString(text,MaxTextExtent,
" %ux%u%+d%+d ",
13310 windows->image.width,windows->image.height,windows->image.x,
13312 XInfoWidget(display,windows,text);
13313 XCheckRefreshWindows(display,windows);
13314 XDrawPanRectangle(display,windows);
13315 XRefreshWindow(display,&windows->image,(XEvent *) NULL);
13316 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
13349static MagickBooleanType XTrimImage(Display *display,
13350 XResourceInfo *resource_info,XWindows *windows,Image *image)
13366 XSetCursorState(display,windows,MagickTrue);
13367 XCheckRefreshWindows(display,windows);
13371 background=XGetPixel(windows->image.ximage,0,0);
13372 trim_info.width=(size_t) windows->image.ximage->width;
13373 for (x=0; x < windows->image.ximage->width; x++)
13375 for (y=0; y < windows->image.ximage->height; y++)
13377 pixel=XGetPixel(windows->image.ximage,x,y);
13378 if (pixel != background)
13381 if (y < windows->image.ximage->height)
13384 trim_info.x=(ssize_t) x;
13385 if (trim_info.x == (ssize_t) windows->image.ximage->width)
13387 XSetCursorState(display,windows,MagickFalse);
13388 return(MagickFalse);
13393 background=XGetPixel(windows->image.ximage,windows->image.ximage->width-1,0);
13394 for (x=windows->image.ximage->width-1; x != 0; x--)
13396 for (y=0; y < windows->image.ximage->height; y++)
13398 pixel=XGetPixel(windows->image.ximage,x,y);
13399 if (pixel != background)
13402 if (y < windows->image.ximage->height)
13405 trim_info.width=(size_t) (x-trim_info.x+1);
13409 background=XGetPixel(windows->image.ximage,0,0);
13410 trim_info.height=(size_t) windows->image.ximage->height;
13411 for (y=0; y < windows->image.ximage->height; y++)
13413 for (x=0; x < windows->image.ximage->width; x++)
13415 pixel=XGetPixel(windows->image.ximage,x,y);
13416 if (pixel != background)
13419 if (x < windows->image.ximage->width)
13422 trim_info.y=(ssize_t) y;
13426 background=XGetPixel(windows->image.ximage,0,windows->image.ximage->height-1);
13427 for (y=windows->image.ximage->height-1; y != 0; y--)
13429 for (x=0; x < windows->image.ximage->width; x++)
13431 pixel=XGetPixel(windows->image.ximage,x,y);
13432 if (pixel != background)
13435 if (x < windows->image.ximage->width)
13438 trim_info.height=(size_t) y-trim_info.y+1;
13439 if (((
unsigned int) trim_info.width != windows->image.width) ||
13440 ((
unsigned int) trim_info.height != windows->image.height))
13445 XSetCropGeometry(display,windows,&trim_info,image);
13446 windows->image.window_changes.width=(int) trim_info.width;
13447 windows->image.window_changes.height=(int) trim_info.height;
13448 (void) XConfigureImage(display,resource_info,windows,image);
13450 XSetCursorState(display,windows,MagickFalse);
13451 return(MagickTrue);
13486static Image *XVisualDirectoryImage(Display *display,
13487 XResourceInfo *resource_info,XWindows *windows)
13489#define TileImageTag "Scale/Image"
13490#define XClientName "montage"
13526 filename[MaxTextExtent] =
"\0",
13527 filenames[MaxTextExtent] =
"*";
13530 background_resources;
13535 XFileBrowserWidget(display,windows,
"Directory",filenames);
13536 if (*filenames ==
'\0')
13537 return((Image *) NULL);
13541 filelist=(
char **) AcquireMagickMemory(
sizeof(*filelist));
13542 if (filelist == (
char **) NULL)
13544 ThrowXWindowException(ResourceLimitError,
"MemoryAllocationFailed",
13546 return((Image *) NULL);
13549 filelist[0]=filenames;
13550 status=ExpandFilenames(&number_files,&filelist);
13551 if ((status == MagickFalse) || (number_files == 0))
13553 if (number_files == 0)
13554 ThrowXWindowException(ImageError,
"NoImagesWereFound",filenames)
13556 ThrowXWindowException(ResourceLimitError,
"MemoryAllocationFailed",
13558 return((Image *) NULL);
13563 background_resources=(*resource_info);
13564 background_resources.window_id=AcquireString(
"");
13565 (void) FormatLocaleString(background_resources.window_id,MaxTextExtent,
13566 "0x%lx",windows->image.id);
13567 background_resources.backdrop=MagickTrue;
13571 backdrop=(windows->visual_info->klass == TrueColor) ||
13572 (windows->visual_info->klass == DirectColor) ? MagickTrue : MagickFalse;
13573 read_info=CloneImageInfo(resource_info->image_info);
13574 (void) SetImageOption(read_info,
"jpeg:size",
"120x120");
13575 (void) CloneString(&read_info->size,DefaultTileGeometry);
13576 (void) SetImageInfoProgressMonitor(read_info,(MagickProgressMonitor) NULL,
13578 images=NewImageList();
13579 exception=AcquireExceptionInfo();
13580 XSetCursorState(display,windows,MagickTrue);
13581 XCheckRefreshWindows(display,windows);
13582 for (i=0; i < (int) number_files; i++)
13584 (void) CopyMagickString(read_info->filename,filelist[i],MaxTextExtent);
13585 filelist[i]=DestroyString(filelist[i]);
13586 *read_info->magick=
'\0';
13587 next_image=ReadImage(read_info,exception);
13588 CatchException(exception);
13589 if (next_image != (Image *) NULL)
13591 (void) DeleteImageProperty(next_image,
"label");
13592 (void) SetImageProperty(next_image,
"label",InterpretImageProperties(
13593 read_info,next_image,DefaultTileLabel));
13594 (void) ParseRegionGeometry(next_image,read_info->size,&geometry,
13596 thumbnail_image=ThumbnailImage(next_image,geometry.width,
13597 geometry.height,exception);
13598 if (thumbnail_image != (Image *) NULL)
13600 next_image=DestroyImage(next_image);
13601 next_image=thumbnail_image;
13605 (void) XDisplayBackgroundImage(display,&background_resources,
13607 XSetCursorState(display,windows,MagickTrue);
13609 AppendImageToList(&images,next_image);
13610 if (images->progress_monitor != (MagickProgressMonitor) NULL)
13615 proceed=SetImageProgress(images,LoadImageTag,(MagickOffsetType) i,
13616 (MagickSizeType) number_files);
13617 if (proceed == MagickFalse)
13622 exception=DestroyExceptionInfo(exception);
13623 filelist=(
char **) RelinquishMagickMemory(filelist);
13624 if (images == (Image *) NULL)
13626 read_info=DestroyImageInfo(read_info);
13627 XSetCursorState(display,windows,MagickFalse);
13628 ThrowXWindowException(ImageError,
"NoImagesWereLoaded",filenames);
13629 return((Image *) NULL);
13634 montage_info=CloneMontageInfo(read_info,(MontageInfo *) NULL);
13635 montage_info->pointsize=10;
13636 if (resource_info->font != (
char *) NULL)
13637 (void) CloneString(&montage_info->font,resource_info->font);
13638 (void) CopyMagickString(montage_info->filename,filename,MaxTextExtent);
13639 montage_image=MontageImageList(read_info,montage_info,GetFirstImageInList(
13640 images),&images->exception);
13641 images=DestroyImageList(images);
13642 montage_info=DestroyMontageInfo(montage_info);
13643 read_info=DestroyImageInfo(read_info);
13644 XSetCursorState(display,windows,MagickFalse);
13645 if (montage_image == (Image *) NULL)
13646 return(montage_image);
13647 XClientMessage(display,windows->image.id,windows->im_protocols,
13648 windows->im_next_image,CurrentTime);
13649 return(montage_image);
13680MagickExport MagickBooleanType XDisplayBackgroundImage(Display *display,
13681 XResourceInfo *resource_info,Image *image)
13684 geometry[MaxTextExtent],
13685 visual_type[MaxTextExtent];
13698 static XStandardColormap
13702 *visual_info = (XVisualInfo *) NULL;
13725 assert(image != (Image *) NULL);
13726 assert(image->signature == MagickCoreSignature);
13727 if (IsEventLogging() != MagickFalse)
13728 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
13729 resources=(*resource_info);
13730 window_info.id=(Window) NULL;
13731 root_window=XRootWindow(display,XDefaultScreen(display));
13732 if (LocaleCompare(resources.window_id,
"root") == 0)
13733 window_info.id=root_window;
13736 if (isdigit((
int) ((
unsigned char) *resources.window_id)) != 0)
13737 window_info.id=XWindowByID(display,root_window,
13738 (Window) strtol((
char *) resources.window_id,(
char **) NULL,0));
13739 if (window_info.id == (Window) NULL)
13740 window_info.id=XWindowByName(display,root_window,resources.window_id);
13742 if (window_info.id == (Window) NULL)
13744 ThrowXWindowException(XServerError,
"NoWindowWithSpecifiedIDExists",
13745 resources.window_id);
13750 window_attributes.width=XDisplayWidth(display,XDefaultScreen(display));
13751 window_attributes.height=XDisplayHeight(display,XDefaultScreen(display));
13752 (void) CopyMagickString(visual_type,
"default",MaxTextExtent);
13753 status=XGetWindowAttributes(display,window_info.id,&window_attributes);
13755 (void) FormatLocaleString(visual_type,MaxTextExtent,
"0x%lx",
13756 XVisualIDFromVisual(window_attributes.visual));
13757 if (visual_info == (XVisualInfo *) NULL)
13762 map_info=XAllocStandardColormap();
13763 if (map_info == (XStandardColormap *) NULL)
13764 ThrowXWindowFatalException(XServerFatalError,
"MemoryAllocationFailed",
13766 map_info->colormap=(Colormap) NULL;
13767 pixel.pixels=(
unsigned long *) NULL;
13771 resources.map_type=(
char *) NULL;
13772 resources.visual_type=visual_type;
13773 visual_info=XBestVisualInfo(display,map_info,&resources);
13774 if (visual_info == (XVisualInfo *) NULL)
13775 ThrowXWindowFatalException(XServerFatalError,
"UnableToGetVisual",
13776 resources.visual_type);
13780 window_info.ximage=(XImage *) NULL;
13781 window_info.matte_image=(XImage *) NULL;
13782 window_info.pixmap=(Pixmap) NULL;
13783 window_info.matte_pixmap=(Pixmap) NULL;
13788 if (window_info.id == root_window)
13789 (void) XDestroyWindowColors(display,root_window);
13793 resources.colormap=SharedColormap;
13794 XMakeStandardColormap(display,visual_info,&resources,image,map_info,&pixel);
13798 context_values.background=pixel.foreground_color.pixel;
13799 context_values.foreground=pixel.background_color.pixel;
13800 pixel.annotate_context=XCreateGC(display,window_info.id,
13801 (
size_t) (GCBackground | GCForeground),&context_values);
13802 if (pixel.annotate_context == (GC) NULL)
13803 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateGraphicContext",
13808 window_info.name=AcquireString(
"\0");
13809 window_info.icon_name=AcquireString(
"\0");
13810 XGetWindowInfo(display,visual_info,map_info,&pixel,(XFontStruct *) NULL,
13811 &resources,&window_info);
13815 window_info.width=(
unsigned int) image->columns;
13816 window_info.height=(
unsigned int) image->rows;
13817 if ((image->columns != window_info.width) ||
13818 (image->rows != window_info.height))
13819 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateXImage",
13821 (void) FormatLocaleString(geometry,MaxTextExtent,
"%ux%u+0+0>",
13822 window_attributes.width,window_attributes.height);
13823 geometry_info.width=window_info.width;
13824 geometry_info.height=window_info.height;
13825 geometry_info.x=(ssize_t) window_info.x;
13826 geometry_info.y=(ssize_t) window_info.y;
13827 (void) ParseMetaGeometry(geometry,&geometry_info.x,&geometry_info.y,
13828 &geometry_info.width,&geometry_info.height);
13829 window_info.width=(
unsigned int) geometry_info.width;
13830 window_info.height=(
unsigned int) geometry_info.height;
13831 window_info.x=(int) geometry_info.x;
13832 window_info.y=(int) geometry_info.y;
13833 status=XMakeImage(display,&resources,&window_info,image,window_info.width,
13834 window_info.height);
13835 if (status == MagickFalse)
13836 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateXImage",
13840 if (resource_info->debug != MagickFalse)
13842 (void) LogMagickEvent(X11Event,GetMagickModule(),
13843 "Image: %s[%.20g] %.20gx%.20g ",image->filename,(
double) image->scene,
13844 (
double) image->columns,(
double) image->rows);
13845 if (image->colors != 0)
13846 (void) LogMagickEvent(X11Event,GetMagickModule(),
"%.20gc ",(
double)
13848 (void) LogMagickEvent(X11Event,GetMagickModule(),
"%s",image->magick);
13853 width=(int) window_info.width;
13854 height=(int) window_info.height;
13855 if (resources.backdrop != MagickFalse)
13860 window_info.x=(window_attributes.width/2)-(window_info.ximage->width/2);
13861 window_info.y=(window_attributes.height/2)-(window_info.ximage->height/2);
13862 width=window_attributes.width;
13863 height=window_attributes.height;
13865 if ((resources.image_geometry != (
char *) NULL) &&
13866 (*resources.image_geometry !=
'\0'))
13869 default_geometry[MaxTextExtent];
13881 size_hints=XAllocSizeHints();
13882 if (size_hints == (XSizeHints *) NULL)
13883 ThrowXWindowFatalException(ResourceLimitFatalError,
13884 "MemoryAllocationFailed",image->filename);
13885 size_hints->flags=0L;
13886 (void) FormatLocaleString(default_geometry,MaxTextExtent,
"%dx%d",
13888 flags=XWMGeometry(display,visual_info->screen,resources.image_geometry,
13889 default_geometry,window_info.border_width,size_hints,&window_info.x,
13890 &window_info.y,&width,&height,&gravity);
13891 if (flags & (XValue | YValue))
13893 width=window_attributes.width;
13894 height=window_attributes.height;
13896 (void) XFree((
void *) size_hints);
13901 window_info.pixmap=XCreatePixmap(display,window_info.id,(
unsigned int) width,
13902 (
unsigned int) height,window_info.depth);
13903 if (window_info.pixmap == (Pixmap) NULL)
13904 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateXPixmap",
13909 if (((
unsigned int) width > window_info.width) ||
13910 ((
unsigned int) height > window_info.height))
13911 (void) XFillRectangle(display,window_info.pixmap,
13912 window_info.annotate_context,0,0,(
unsigned int) width,
13913 (
unsigned int) height);
13914 (void) XPutImage(display,window_info.pixmap,window_info.annotate_context,
13915 window_info.ximage,0,0,window_info.x,window_info.y,(
unsigned int)
13916 window_info.width,(
unsigned int) window_info.height);
13917 (void) XSetWindowBackgroundPixmap(display,window_info.id,window_info.pixmap);
13918 (void) XClearWindow(display,window_info.id);
13919 delay=1000*image->delay/MagickMax(image->ticks_per_second,1L);
13920 XDelay(display,delay == 0UL ? 10UL : delay);
13921 (void) XSync(display,MagickFalse);
13922 return(window_info.id == root_window ? MagickTrue : MagickFalse);
13962MagickExport Image *XDisplayImage(Display *display,XResourceInfo *resource_info,
13963 char **argv,
int argc,Image **image,
size_t *state)
13965#define MagnifySize 256
13966#define MagickMenus 10
13967#define MagickTitle "Commands"
13970 *
const CommandMenu[] =
13984 *
const FileMenu[] =
13994 "Visual Directory...",
13998 *
const EditMenu[] =
14007 *
const ViewMenu[] =
14018 *
const TransformMenu[] =
14032 *
const EnhanceMenu[] =
14040 "Contrast Stretch...",
14041 "Sigmoidal Contrast...",
14050 *
const EffectsMenu[] =
14075 "Charcoal Draw...",
14078 *
const ImageEditMenu[] =
14089 "Region of Interest...",
14092 *
const MiscellanyMenu[] =
14104 *
const HelpMenu[] =
14107 "Browse Documentation",
14111 *
const ShortCutsMenu[] =
14124 *
const VirtualMenu[] =
14134 *
const *Menus[MagickMenus] =
14148 static DisplayCommand
14172 VisualDirectoryCommand,
14186 OriginalSizeCommand,
14193 TransformCommands[] =
14199 RotateRightCommand,
14206 EnhanceCommands[] =
14214 ContrastStretchCommand,
14215 SigmoidalContrastCommand,
14223 EffectsCommands[] =
14227 ReduceNoiseCommand,
14247 CharcoalDrawCommand
14249 ImageEditCommands[] =
14260 RegionOfInterestCommand
14262 MiscellanyCommands[] =
14266 ShowPreviewCommand,
14267 ShowHistogramCommand,
14276 BrowseDocumentationCommand,
14279 ShortCutsCommands[] =
14291 VirtualCommands[] =
14299 static DisplayCommand
14300 *Commands[MagickMenus] =
14310 MiscellanyCommands,
14315 command[MaxTextExtent],
14317 geometry[MaxTextExtent],
14318 resource_name[MaxTextExtent];
14345 working_directory[MaxTextExtent];
14351 *magick_windows[MaxXWindows];
14353 static unsigned int
14413 assert(image != (Image **) NULL);
14414 assert((*image)->signature == MagickCoreSignature);
14415 if (IsEventLogging() != MagickFalse)
14416 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",(*image)->filename);
14417 display_image=(*image);
14418 warning_handler=(WarningHandler) NULL;
14419 windows=XSetWindows((XWindows *) ~0);
14420 if (windows != (XWindows *) NULL)
14425 if (*working_directory ==
'\0')
14426 (void) CopyMagickString(working_directory,
".",MaxTextExtent);
14427 status=chdir(working_directory);
14429 (void) ThrowMagickException(&(*image)->exception,GetMagickModule(),
14430 FileOpenError,
"UnableToOpenFile",
"%s",working_directory);
14431 warning_handler=resource_info->display_warnings ?
14432 SetErrorHandler(XWarning) : SetErrorHandler((ErrorHandler) NULL);
14433 warning_handler=resource_info->display_warnings ?
14434 SetWarningHandler(XWarning) : SetWarningHandler((WarningHandler) NULL);
14441 resource_info->colors=display_image->colors;
14442 windows=XSetWindows(XInitializeWindows(display,resource_info));
14443 if (windows == (XWindows *) NULL)
14444 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateWindow",
14445 (*image)->filename);
14450 magick_windows[number_windows++]=(&windows->icon);
14451 magick_windows[number_windows++]=(&windows->backdrop);
14452 magick_windows[number_windows++]=(&windows->image);
14453 magick_windows[number_windows++]=(&windows->info);
14454 magick_windows[number_windows++]=(&windows->command);
14455 magick_windows[number_windows++]=(&windows->widget);
14456 magick_windows[number_windows++]=(&windows->popup);
14457 magick_windows[number_windows++]=(&windows->magnify);
14458 magick_windows[number_windows++]=(&windows->pan);
14459 for (i=0; i < (int) number_windows; i++)
14460 magick_windows[i]->
id=(Window) NULL;
14467 if (windows->font_info != (XFontStruct *) NULL)
14468 (void) XFreeFont(display,windows->font_info);
14469 windows->font_info=XBestFont(display,resource_info,MagickFalse);
14470 if (windows->font_info == (XFontStruct *) NULL)
14471 ThrowXWindowFatalException(XServerFatalError,
"UnableToLoadFont",
14472 resource_info->font);
14476 map_info=windows->map_info;
14477 icon_map=windows->icon_map;
14478 visual_info=windows->visual_info;
14479 icon_visual=windows->icon_visual;
14480 pixel=windows->pixel_info;
14481 icon_pixel=windows->icon_pixel;
14482 font_info=windows->font_info;
14483 icon_resources=windows->icon_resources;
14484 class_hints=windows->class_hints;
14485 manager_hints=windows->manager_hints;
14486 root_window=XRootWindow(display,visual_info->screen);
14487 nexus=NewImageList();
14488 if (resource_info->debug != MagickFalse)
14490 (void) LogMagickEvent(X11Event,GetMagickModule(),
14491 "Image: %s[%.20g] %.20gx%.20g ",display_image->filename,
14492 (
double) display_image->scene,(
double) display_image->columns,
14493 (
double) display_image->rows);
14494 if (display_image->colors != 0)
14495 (void) LogMagickEvent(X11Event,GetMagickModule(),
"%.20gc ",(
double)
14496 display_image->colors);
14497 (void) LogMagickEvent(X11Event,GetMagickModule(),
"%s",
14498 display_image->magick);
14500 XMakeStandardColormap(display,visual_info,resource_info,display_image,
14502 display_image->taint=MagickFalse;
14506 windows->context.id=(Window) NULL;
14507 XGetWindowInfo(display,visual_info,map_info,pixel,font_info,
14508 resource_info,&windows->context);
14509 (void) CloneString(&class_hints->res_name,resource_info->client_name);
14510 (void) CloneString(&class_hints->res_class,resource_info->client_name);
14511 class_hints->res_class[0]=(char) LocaleToUppercase((
int)
14512 class_hints->res_class[0]);
14513 manager_hints->flags=InputHint | StateHint;
14514 manager_hints->input=MagickFalse;
14515 manager_hints->initial_state=WithdrawnState;
14516 XMakeWindow(display,root_window,argv,argc,class_hints,manager_hints,
14517 &windows->context);
14518 if (resource_info->debug != MagickFalse)
14519 (void) LogMagickEvent(X11Event,GetMagickModule(),
14520 "Window id: 0x%lx (context)",windows->context.id);
14521 context_values.background=pixel->background_color.pixel;
14522 context_values.font=font_info->fid;
14523 context_values.foreground=pixel->foreground_color.pixel;
14524 context_values.graphics_exposures=MagickFalse;
14525 context_mask=(MagickStatusType)
14526 (GCBackground | GCFont | GCForeground | GCGraphicsExposures);
14527 if (pixel->annotate_context != (GC) NULL)
14528 (void) XFreeGC(display,pixel->annotate_context);
14529 pixel->annotate_context=XCreateGC(display,windows->context.id,
14530 context_mask,&context_values);
14531 if (pixel->annotate_context == (GC) NULL)
14532 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateGraphicContext",
14533 display_image->filename);
14534 context_values.background=pixel->depth_color.pixel;
14535 if (pixel->widget_context != (GC) NULL)
14536 (void) XFreeGC(display,pixel->widget_context);
14537 pixel->widget_context=XCreateGC(display,windows->context.id,context_mask,
14539 if (pixel->widget_context == (GC) NULL)
14540 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateGraphicContext",
14541 display_image->filename);
14542 context_values.background=pixel->foreground_color.pixel;
14543 context_values.foreground=pixel->background_color.pixel;
14544 context_values.plane_mask=context_values.background ^
14545 context_values.foreground;
14546 if (pixel->highlight_context != (GC) NULL)
14547 (void) XFreeGC(display,pixel->highlight_context);
14548 pixel->highlight_context=XCreateGC(display,windows->context.id,
14549 (
size_t) (context_mask | GCPlaneMask),&context_values);
14550 if (pixel->highlight_context == (GC) NULL)
14551 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateGraphicContext",
14552 display_image->filename);
14553 (void) XDestroyWindow(display,windows->context.id);
14557 XGetWindowInfo(display,icon_visual,icon_map,icon_pixel,(XFontStruct *) NULL,
14558 icon_resources,&windows->icon);
14559 windows->icon.geometry=resource_info->icon_geometry;
14560 XBestIconSize(display,&windows->icon,display_image);
14561 windows->icon.attributes.colormap=XDefaultColormap(display,
14562 icon_visual->screen);
14563 windows->icon.attributes.event_mask=ExposureMask | StructureNotifyMask;
14564 manager_hints->flags=InputHint | StateHint;
14565 manager_hints->input=MagickFalse;
14566 manager_hints->initial_state=IconicState;
14567 XMakeWindow(display,root_window,argv,argc,class_hints,manager_hints,
14569 if (resource_info->debug != MagickFalse)
14570 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Window id: 0x%lx (icon)",
14575 if (icon_pixel->annotate_context != (GC) NULL)
14576 (void) XFreeGC(display,icon_pixel->annotate_context);
14577 context_values.background=icon_pixel->background_color.pixel;
14578 context_values.foreground=icon_pixel->foreground_color.pixel;
14579 icon_pixel->annotate_context=XCreateGC(display,windows->icon.id,
14580 (
size_t) (GCBackground | GCForeground),&context_values);
14581 if (icon_pixel->annotate_context == (GC) NULL)
14582 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateGraphicContext",
14583 display_image->filename);
14584 windows->icon.annotate_context=icon_pixel->annotate_context;
14588 XGetWindowInfo(display,visual_info,map_info,pixel,font_info,resource_info,
14590 windows->image.shape=MagickTrue;
14591 if (resource_info->use_shared_memory == MagickFalse)
14592 windows->image.shared_memory=MagickFalse;
14593 if ((resource_info->title != (
char *) NULL) && !(*state & MontageImageState))
14598 title=InterpretImageProperties(resource_info->image_info,display_image,
14599 resource_info->title);
14600 (void) CloneString(&windows->image.name,title);
14601 (void) CloneString(&windows->image.icon_name,title);
14602 title=DestroyString(title);
14607 filename[MaxTextExtent],
14608 window_name[MaxTextExtent];
14613 GetPathComponent(display_image->magick_filename,TailPath,filename);
14614 if (display_image->scene == 0)
14615 (void) FormatLocaleString(window_name,MaxTextExtent,
"%s: %s",
14616 MagickPackageName,filename);
14618 (
void) FormatLocaleString(window_name,MaxTextExtent,
14619 "%s: %s[scene: %.20g frames: %.20g]",MagickPackageName,filename,
14620 (
double) display_image->scene,(
double) GetImageListLength(
14622 (void) CloneString(&windows->image.name,window_name);
14623 (void) CloneString(&windows->image.icon_name,filename);
14625 if (resource_info->immutable)
14626 windows->image.immutable=MagickTrue;
14627 windows->image.use_pixmap=resource_info->use_pixmap;
14628 windows->image.geometry=resource_info->image_geometry;
14629 (void) FormatLocaleString(geometry,MaxTextExtent,
"%ux%u+0+0>!",
14630 XDisplayWidth(display,visual_info->screen),
14631 XDisplayHeight(display,visual_info->screen));
14632 geometry_info.width=display_image->columns;
14633 geometry_info.height=display_image->rows;
14636 (void) ParseMetaGeometry(geometry,&geometry_info.x,&geometry_info.y,
14637 &geometry_info.width,&geometry_info.height);
14638 windows->image.width=(
unsigned int) geometry_info.width;
14639 windows->image.height=(
unsigned int) geometry_info.height;
14640 windows->image.attributes.event_mask=ButtonMotionMask | ButtonPressMask |
14641 ButtonReleaseMask | EnterWindowMask | ExposureMask | KeyPressMask |
14642 KeyReleaseMask | LeaveWindowMask | OwnerGrabButtonMask |
14643 PropertyChangeMask | StructureNotifyMask | SubstructureNotifyMask;
14644 XGetWindowInfo(display,visual_info,map_info,pixel,font_info,
14645 resource_info,&windows->backdrop);
14646 if ((resource_info->backdrop) || (windows->backdrop.id != (Window) NULL))
14651 windows->backdrop.x=0;
14652 windows->backdrop.y=0;
14653 (void) CloneString(&windows->backdrop.name,
"Backdrop");
14654 windows->backdrop.flags=(size_t) (USSize | USPosition);
14655 windows->backdrop.width=(
unsigned int)
14656 XDisplayWidth(display,visual_info->screen);
14657 windows->backdrop.height=(
unsigned int)
14658 XDisplayHeight(display,visual_info->screen);
14659 windows->backdrop.border_width=0;
14660 windows->backdrop.immutable=MagickTrue;
14661 windows->backdrop.attributes.do_not_propagate_mask=ButtonPressMask |
14663 windows->backdrop.attributes.event_mask=ButtonPressMask | KeyPressMask |
14664 StructureNotifyMask;
14665 manager_hints->flags=IconWindowHint | InputHint | StateHint;
14666 manager_hints->icon_window=windows->icon.id;
14667 manager_hints->input=MagickTrue;
14668 manager_hints->initial_state=resource_info->iconic ? IconicState :
14670 XMakeWindow(display,root_window,argv,argc,class_hints,manager_hints,
14671 &windows->backdrop);
14672 if (resource_info->debug != MagickFalse)
14673 (void) LogMagickEvent(X11Event,GetMagickModule(),
14674 "Window id: 0x%lx (backdrop)",windows->backdrop.id);
14675 (void) XMapWindow(display,windows->backdrop.id);
14676 (void) XClearWindow(display,windows->backdrop.id);
14677 if (windows->image.id != (Window) NULL)
14679 (void) XDestroyWindow(display,windows->image.id);
14680 windows->image.id=(Window) NULL;
14685 windows->image.flags|=USPosition;
14686 windows->image.x=(XDisplayWidth(display,visual_info->screen)/2)-
14687 (windows->image.width/2);
14688 windows->image.y=(XDisplayHeight(display,visual_info->screen)/2)-
14689 (windows->image.height/2);
14691 manager_hints->flags=IconWindowHint | InputHint | StateHint;
14692 manager_hints->icon_window=windows->icon.id;
14693 manager_hints->input=MagickTrue;
14694 manager_hints->initial_state=resource_info->iconic ? IconicState :
14696 if (windows->group_leader.id != (Window) NULL)
14701 manager_hints->flags|=WindowGroupHint;
14702 manager_hints->window_group=windows->group_leader.id;
14703 (void) XSelectInput(display,windows->group_leader.id,StructureNotifyMask);
14704 if (resource_info->debug != MagickFalse)
14705 (void) LogMagickEvent(X11Event,GetMagickModule(),
14706 "Window id: 0x%lx (group leader)",windows->group_leader.id);
14708 XMakeWindow(display,
14709 (Window) (resource_info->backdrop ? windows->backdrop.id : root_window),
14710 argv,argc,class_hints,manager_hints,&windows->image);
14711 (void) XChangeProperty(display,windows->image.id,windows->im_protocols,
14712 XA_STRING,8,PropModeReplace,(
unsigned char *) NULL,0);
14713 if (windows->group_leader.id != (Window) NULL)
14714 (void) XSetTransientForHint(display,windows->image.id,
14715 windows->group_leader.id);
14716 if (resource_info->debug != MagickFalse)
14717 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Window id: 0x%lx (image)",
14718 windows->image.id);
14722 XGetWindowInfo(display,visual_info,map_info,pixel,font_info,resource_info,
14724 (void) CloneString(&windows->info.name,
"Info");
14725 (void) CloneString(&windows->info.icon_name,
"Info");
14726 windows->info.border_width=1;
14729 windows->info.flags|=PPosition;
14730 windows->info.attributes.win_gravity=UnmapGravity;
14731 windows->info.attributes.event_mask=ButtonPressMask | ExposureMask |
14732 StructureNotifyMask;
14733 manager_hints->flags=InputHint | StateHint | WindowGroupHint;
14734 manager_hints->input=MagickFalse;
14735 manager_hints->initial_state=NormalState;
14736 manager_hints->window_group=windows->image.id;
14737 XMakeWindow(display,windows->image.id,argv,argc,class_hints,manager_hints,
14739 windows->info.highlight_stipple=XCreateBitmapFromData(display,
14740 windows->info.id,(
char *) HighlightBitmap,HighlightWidth,HighlightHeight);
14741 windows->info.shadow_stipple=XCreateBitmapFromData(display,
14742 windows->info.id,(
char *) ShadowBitmap,ShadowWidth,ShadowHeight);
14743 (void) XSetTransientForHint(display,windows->info.id,windows->image.id);
14744 if (windows->image.mapped != MagickFalse)
14745 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
14746 if (resource_info->debug != MagickFalse)
14747 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Window id: 0x%lx (info)",
14752 XGetWindowInfo(display,visual_info,map_info,pixel,font_info,
14753 resource_info,&windows->command);
14754 windows->command.data=MagickMenus;
14755 (void) XCommandWidget(display,windows,CommandMenu,(XEvent *) NULL);
14756 (void) FormatLocaleString(resource_name,MaxTextExtent,
"%s.command",
14757 resource_info->client_name);
14758 windows->command.geometry=XGetResourceClass(resource_info->resource_database,
14759 resource_name,
"geometry",(
char *) NULL);
14760 (void) CloneString(&windows->command.name,MagickTitle);
14761 windows->command.border_width=0;
14762 windows->command.flags|=PPosition;
14763 windows->command.attributes.event_mask=ButtonMotionMask | ButtonPressMask |
14764 ButtonReleaseMask | EnterWindowMask | ExposureMask | LeaveWindowMask |
14765 OwnerGrabButtonMask | StructureNotifyMask;
14766 manager_hints->flags=InputHint | StateHint | WindowGroupHint;
14767 manager_hints->input=MagickTrue;
14768 manager_hints->initial_state=NormalState;
14769 manager_hints->window_group=windows->image.id;
14770 XMakeWindow(display,root_window,argv,argc,class_hints,manager_hints,
14771 &windows->command);
14772 windows->command.highlight_stipple=XCreateBitmapFromData(display,
14773 windows->command.id,(
char *) HighlightBitmap,HighlightWidth,
14775 windows->command.shadow_stipple=XCreateBitmapFromData(display,
14776 windows->command.id,(
char *) ShadowBitmap,ShadowWidth,ShadowHeight);
14777 (void) XSetTransientForHint(display,windows->command.id,windows->image.id);
14778 if (windows->command.mapped != MagickFalse)
14779 (void) XMapRaised(display,windows->command.id);
14780 if (resource_info->debug != MagickFalse)
14781 (void) LogMagickEvent(X11Event,GetMagickModule(),
14782 "Window id: 0x%lx (command)",windows->command.id);
14786 XGetWindowInfo(display,visual_info,map_info,pixel,font_info,
14787 resource_info,&windows->widget);
14788 (void) FormatLocaleString(resource_name,MaxTextExtent,
"%s.widget",
14789 resource_info->client_name);
14790 windows->widget.geometry=XGetResourceClass(resource_info->resource_database,
14791 resource_name,
"geometry",(
char *) NULL);
14792 windows->widget.border_width=0;
14793 windows->widget.flags|=PPosition;
14794 windows->widget.attributes.event_mask=ButtonMotionMask | ButtonPressMask |
14795 ButtonReleaseMask | EnterWindowMask | ExposureMask | KeyPressMask |
14796 KeyReleaseMask | LeaveWindowMask | OwnerGrabButtonMask |
14797 StructureNotifyMask;
14798 manager_hints->flags=InputHint | StateHint | WindowGroupHint;
14799 manager_hints->input=MagickTrue;
14800 manager_hints->initial_state=NormalState;
14801 manager_hints->window_group=windows->image.id;
14802 XMakeWindow(display,root_window,argv,argc,class_hints,manager_hints,
14804 windows->widget.highlight_stipple=XCreateBitmapFromData(display,
14805 windows->widget.id,(
char *) HighlightBitmap,HighlightWidth,HighlightHeight);
14806 windows->widget.shadow_stipple=XCreateBitmapFromData(display,
14807 windows->widget.id,(
char *) ShadowBitmap,ShadowWidth,ShadowHeight);
14808 (void) XSetTransientForHint(display,windows->widget.id,windows->image.id);
14809 if (resource_info->debug != MagickFalse)
14810 (void) LogMagickEvent(X11Event,GetMagickModule(),
14811 "Window id: 0x%lx (widget)",windows->widget.id);
14815 XGetWindowInfo(display,visual_info,map_info,pixel,font_info,
14816 resource_info,&windows->popup);
14817 windows->popup.border_width=0;
14818 windows->popup.flags|=PPosition;
14819 windows->popup.attributes.event_mask=ButtonMotionMask | ButtonPressMask |
14820 ButtonReleaseMask | EnterWindowMask | ExposureMask | KeyPressMask |
14821 KeyReleaseMask | LeaveWindowMask | StructureNotifyMask;
14822 manager_hints->flags=InputHint | StateHint | WindowGroupHint;
14823 manager_hints->input=MagickTrue;
14824 manager_hints->initial_state=NormalState;
14825 manager_hints->window_group=windows->image.id;
14826 XMakeWindow(display,root_window,argv,argc,class_hints,manager_hints,
14828 windows->popup.highlight_stipple=XCreateBitmapFromData(display,
14829 windows->popup.id,(
char *) HighlightBitmap,HighlightWidth,HighlightHeight);
14830 windows->popup.shadow_stipple=XCreateBitmapFromData(display,
14831 windows->popup.id,(
char *) ShadowBitmap,ShadowWidth,ShadowHeight);
14832 (void) XSetTransientForHint(display,windows->popup.id,windows->image.id);
14833 if (resource_info->debug != MagickFalse)
14834 (void) LogMagickEvent(X11Event,GetMagickModule(),
14835 "Window id: 0x%lx (pop up)",windows->popup.id);
14839 XGetWindowInfo(display,visual_info,map_info,pixel,font_info,
14840 resource_info,&windows->magnify);
14841 if (resource_info->use_shared_memory == MagickFalse)
14842 windows->magnify.shared_memory=MagickFalse;
14843 (void) FormatLocaleString(resource_name,MaxTextExtent,
"%s.magnify",
14844 resource_info->client_name);
14845 windows->magnify.geometry=XGetResourceClass(resource_info->resource_database,
14846 resource_name,
"geometry",(
char *) NULL);
14847 (void) FormatLocaleString(windows->magnify.name,MaxTextExtent,
"Magnify %uX",
14848 resource_info->magnify);
14849 if (windows->magnify.cursor != (Cursor) NULL)
14850 (void) XFreeCursor(display,windows->magnify.cursor);
14851 windows->magnify.cursor=XMakeCursor(display,windows->image.id,
14852 map_info->colormap,resource_info->background_color,
14853 resource_info->foreground_color);
14854 if (windows->magnify.cursor == (Cursor) NULL)
14855 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateCursor",
14856 display_image->filename);
14857 windows->magnify.width=MagnifySize;
14858 windows->magnify.height=MagnifySize;
14859 windows->magnify.flags|=PPosition;
14860 windows->magnify.min_width=MagnifySize;
14861 windows->magnify.min_height=MagnifySize;
14862 windows->magnify.width_inc=MagnifySize;
14863 windows->magnify.height_inc=MagnifySize;
14864 windows->magnify.data=resource_info->magnify;
14865 windows->magnify.attributes.cursor=windows->magnify.cursor;
14866 windows->magnify.attributes.event_mask=ButtonPressMask | ButtonReleaseMask |
14867 ExposureMask | KeyPressMask | KeyReleaseMask | OwnerGrabButtonMask |
14868 StructureNotifyMask;
14869 manager_hints->flags=InputHint | StateHint | WindowGroupHint;
14870 manager_hints->input=MagickTrue;
14871 manager_hints->initial_state=NormalState;
14872 manager_hints->window_group=windows->image.id;
14873 XMakeWindow(display,root_window,argv,argc,class_hints,manager_hints,
14874 &windows->magnify);
14875 if (resource_info->debug != MagickFalse)
14876 (void) LogMagickEvent(X11Event,GetMagickModule(),
14877 "Window id: 0x%lx (magnify)",windows->magnify.id);
14878 (void) XSetTransientForHint(display,windows->magnify.id,windows->image.id);
14882 XGetWindowInfo(display,visual_info,map_info,pixel,font_info,
14883 resource_info,&windows->pan);
14884 (void) CloneString(&windows->pan.name,
"Pan Icon");
14885 windows->pan.width=windows->icon.width;
14886 windows->pan.height=windows->icon.height;
14887 (void) FormatLocaleString(resource_name,MaxTextExtent,
"%s.pan",
14888 resource_info->client_name);
14889 windows->pan.geometry=XGetResourceClass(resource_info->resource_database,
14890 resource_name,
"geometry",(
char *) NULL);
14891 (void) XParseGeometry(windows->pan.geometry,&windows->pan.x,&windows->pan.y,
14892 &windows->pan.width,&windows->pan.height);
14893 windows->pan.flags|=PPosition;
14894 windows->pan.immutable=MagickTrue;
14895 windows->pan.attributes.event_mask=ButtonMotionMask | ButtonPressMask |
14896 ButtonReleaseMask | ExposureMask | KeyPressMask | KeyReleaseMask |
14897 StructureNotifyMask;
14898 manager_hints->flags=InputHint | StateHint | WindowGroupHint;
14899 manager_hints->input=MagickFalse;
14900 manager_hints->initial_state=NormalState;
14901 manager_hints->window_group=windows->image.id;
14902 XMakeWindow(display,root_window,argv,argc,class_hints,manager_hints,
14904 if (resource_info->debug != MagickFalse)
14905 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Window id: 0x%lx (pan)",
14907 (void) XSetTransientForHint(display,windows->pan.id,windows->image.id);
14908 if (windows->info.mapped != MagickFalse)
14909 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
14910 if ((windows->image.mapped == MagickFalse) ||
14911 (windows->backdrop.id != (Window) NULL))
14912 (void) XMapWindow(display,windows->image.id);
14916 if (warning_handler == (WarningHandler) NULL)
14918 warning_handler=resource_info->display_warnings ?
14919 SetErrorHandler(XWarning) : SetErrorHandler((ErrorHandler) NULL);
14920 warning_handler=resource_info->display_warnings ?
14921 SetWarningHandler(XWarning) : SetWarningHandler((WarningHandler) NULL);
14926 windows->image.x=0;
14927 windows->image.y=0;
14928 windows->magnify.shape=MagickFalse;
14929 width=(
unsigned int) display_image->columns;
14930 height=(
unsigned int) display_image->rows;
14931 if ((display_image->columns != width) || (display_image->rows != height))
14932 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateXImage",
14933 display_image->filename);
14934 status=XMakeImage(display,resource_info,&windows->image,display_image,
14936 if (status == MagickFalse)
14937 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateXImage",
14938 display_image->filename);
14939 status=XMakeImage(display,resource_info,&windows->magnify,(Image *) NULL,
14940 windows->magnify.width,windows->magnify.height);
14941 if (status == MagickFalse)
14942 ThrowXWindowFatalException(XServerFatalError,
"UnableToCreateXImage",
14943 display_image->filename);
14944 if (windows->magnify.mapped != MagickFalse)
14945 (void) XMapRaised(display,windows->magnify.id);
14946 if (windows->pan.mapped != MagickFalse)
14947 (void) XMapRaised(display,windows->pan.id);
14948 windows->image.window_changes.width=(int) display_image->columns;
14949 windows->image.window_changes.height=(int) display_image->rows;
14950 (void) XConfigureImage(display,resource_info,windows,display_image);
14951 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
14952 (void) XSync(display,MagickFalse);
14956 delay=display_image->delay/MagickMax(display_image->ticks_per_second,1L);
14957 timer=GetMagickTime()+(delay == 0 ? 1 : delay)+1;
14959 if (resource_info->update != MagickFalse)
14967 status=GetPathAttributes(display_image->filename,&attributes);
14968 if (status != MagickFalse)
14969 update_time=attributes.st_mtime;
14971 *state&=(~FormerImageState);
14972 *state&=(~MontageImageState);
14973 *state&=(~NextImageState);
14979 if (windows->image.mapped != MagickFalse)
14980 if ((display_image->delay != 0) || (resource_info->update != 0))
14982 if (timer < GetMagickTime())
14984 if (resource_info->update == MagickFalse)
14985 *state|=NextImageState | ExitState;
14994 status=GetPathAttributes(display_image->filename,&attributes);
14995 if (status != MagickFalse)
14996 if (update_time != attributes.st_mtime)
15001 (void) FormatLocaleString(
15002 resource_info->image_info->filename,MaxTextExtent,
15003 "%s:%s",display_image->magick,
15004 display_image->filename);
15005 nexus=ReadImage(resource_info->image_info,
15006 &display_image->exception);
15007 if (nexus != (Image *) NULL)
15008 *state|=NextImageState | ExitState;
15010 delay=display_image->delay/MagickMax(
15011 display_image->ticks_per_second,1L);
15012 timer=GetMagickTime()+(delay == 0 ? 1 : delay)+1;
15015 if (XEventsQueued(display,QueuedAfterFlush) == 0)
15020 XDelay(display,SuspendTime << 2);
15024 timestamp=GetMagickTime();
15025 (void) XNextEvent(display,&event);
15026 if (windows->image.stasis == MagickFalse)
15027 windows->image.stasis=(GetMagickTime()-timestamp) > 0 ?
15028 MagickTrue : MagickFalse;
15029 if (windows->magnify.stasis == MagickFalse)
15030 windows->magnify.stasis=(GetMagickTime()-timestamp) > 0 ?
15031 MagickTrue : MagickFalse;
15032 if (event.xany.window == windows->command.id)
15037 id=XCommandWidget(display,windows,CommandMenu,&event);
15040 (void) CopyMagickString(command,CommandMenu[
id],MaxTextExtent);
15041 display_command=CommandMenus[id];
15042 if (
id < MagickMenus)
15047 entry=XMenuWidget(display,windows,CommandMenu[
id],Menus[
id],
15051 (void) CopyMagickString(command,Menus[
id][entry],MaxTextExtent);
15052 display_command=Commands[id][entry];
15054 if (display_command != NullCommand)
15055 nexus=XMagickCommand(display,resource_info,windows,display_command,
15059 switch (event.type)
15063 if (resource_info->debug != MagickFalse)
15064 (void) LogMagickEvent(X11Event,GetMagickModule(),
15065 "Button Press: 0x%lx %u +%d+%d",event.xbutton.window,
15066 event.xbutton.button,event.xbutton.x,event.xbutton.y);
15067 if ((event.xbutton.button == Button3) &&
15068 (event.xbutton.state & Mod1Mask))
15073 event.xbutton.button=Button2;
15074 event.xbutton.state&=(~Mod1Mask);
15076 if (event.xbutton.window == windows->backdrop.id)
15078 (void) XSetInputFocus(display,event.xbutton.window,RevertToParent,
15079 event.xbutton.time);
15082 if (event.xbutton.window == windows->image.id)
15084 switch (event.xbutton.button)
15088 if (resource_info->immutable)
15093 entry=XMenuWidget(display,windows,
"Commands",VirtualMenu,
15096 nexus=XMagickCommand(display,resource_info,windows,
15097 VirtualCommands[entry],&display_image);
15103 if (windows->command.mapped != MagickFalse)
15104 (void) XWithdrawWindow(display,windows->command.id,
15105 windows->command.screen);
15108 (void) XCommandWidget(display,windows,CommandMenu,
15110 (void) XMapRaised(display,windows->command.id);
15119 (void) XMagickCommand(display,resource_info,windows,ZoomCommand,
15121 XMagnifyImage(display,windows,&event);
15126 if (resource_info->immutable)
15131 entry=XMenuWidget(display,windows,
"Commands",VirtualMenu,
15134 nexus=XMagickCommand(display,resource_info,windows,
15135 VirtualCommands[entry],&display_image);
15138 if (display_image->montage != (
char *) NULL)
15143 nexus=XTileImage(display,resource_info,windows,
15144 display_image,&event);
15145 if (nexus != (Image *) NULL)
15146 *state|=MontageImageState | NextImageState | ExitState;
15147 vid_info.x=(
short int) windows->image.x;
15148 vid_info.y=(
short int) windows->image.y;
15154 entry=XMenuWidget(display,windows,
"Short Cuts",ShortCutsMenu,
15157 nexus=XMagickCommand(display,resource_info,windows,
15158 ShortCutsCommands[entry],&display_image);
15166 XTranslateImage(display,windows,*image,XK_Up);
15174 XTranslateImage(display,windows,*image,XK_Down);
15182 if (event.xbutton.window == windows->magnify.id)
15185 *
const MagnifyMenu[] =
15202 MagnifyCommands[] =
15217 factor=XMenuWidget(display,windows,
"Magnify",MagnifyMenu,command);
15219 XMagnifyWindowCommand(display,windows,0,MagnifyCommands[factor]);
15222 if (event.xbutton.window == windows->pan.id)
15224 switch (event.xbutton.button)
15231 XTranslateImage(display,windows,*image,XK_Up);
15239 XTranslateImage(display,windows,*image,XK_Down);
15244 XPanImage(display,windows,&event);
15250 delay=display_image->delay/MagickMax(display_image->ticks_per_second,
15252 timer=GetMagickTime()+(delay == 0 ? 1 : delay)+1;
15255 case ButtonRelease:
15257 if (resource_info->debug != MagickFalse)
15258 (void) LogMagickEvent(X11Event,GetMagickModule(),
15259 "Button Release: 0x%lx %u +%d+%d",event.xbutton.window,
15260 event.xbutton.button,event.xbutton.x,event.xbutton.y);
15263 case ClientMessage:
15265 if (resource_info->debug != MagickFalse)
15266 (void) LogMagickEvent(X11Event,GetMagickModule(),
15267 "Client Message: 0x%lx 0x%lx %d 0x%lx",event.xclient.window,
15268 event.xclient.message_type,event.xclient.format,(
unsigned long)
15269 event.xclient.data.l[0]);
15270 if (event.xclient.message_type == windows->im_protocols)
15272 if (*event.xclient.data.l == (
long) windows->im_update_widget)
15274 (void) CloneString(&windows->command.name,MagickTitle);
15275 windows->command.data=MagickMenus;
15276 (void) XCommandWidget(display,windows,CommandMenu,
15280 if (*event.xclient.data.l == (
long) windows->im_update_colormap)
15285 for (i=0; i < (int) number_windows; i++)
15287 if (magick_windows[i]->
id == windows->icon.id)
15289 context_values.background=pixel->background_color.pixel;
15290 context_values.foreground=pixel->foreground_color.pixel;
15291 (void) XChangeGC(display,magick_windows[i]->annotate_context,
15292 context_mask,&context_values);
15293 (void) XChangeGC(display,magick_windows[i]->widget_context,
15294 context_mask,&context_values);
15295 context_values.background=pixel->foreground_color.pixel;
15296 context_values.foreground=pixel->background_color.pixel;
15297 context_values.plane_mask=context_values.background ^
15298 context_values.foreground;
15299 (void) XChangeGC(display,magick_windows[i]->highlight_context,
15300 (
size_t) (context_mask | GCPlaneMask),
15302 magick_windows[i]->attributes.background_pixel=
15303 pixel->background_color.pixel;
15304 magick_windows[i]->attributes.border_pixel=
15305 pixel->border_color.pixel;
15306 magick_windows[i]->attributes.colormap=map_info->colormap;
15307 (void) XChangeWindowAttributes(display,magick_windows[i]->
id,
15308 (
unsigned long) magick_windows[i]->mask,
15309 &magick_windows[i]->attributes);
15311 if (windows->pan.mapped != MagickFalse)
15313 (void) XSetWindowBackgroundPixmap(display,windows->pan.id,
15314 windows->pan.pixmap);
15315 (void) XClearWindow(display,windows->pan.id);
15316 XDrawPanRectangle(display,windows);
15318 if (windows->backdrop.id != (Window) NULL)
15319 (void) XInstallColormap(display,map_info->colormap);
15322 if (*event.xclient.data.l == (
long) windows->im_former_image)
15324 *state|=FormerImageState | ExitState;
15327 if (*event.xclient.data.l == (
long) windows->im_next_image)
15329 *state|=NextImageState | ExitState;
15332 if (*event.xclient.data.l == (
long) windows->im_retain_colors)
15334 *state|=RetainColorsState;
15337 if (*event.xclient.data.l == (
long) windows->im_exit)
15344 if (event.xclient.message_type == windows->dnd_protocols)
15364 if ((*event.xclient.data.l != 2) && (*event.xclient.data.l != 128))
15366 selection=XInternAtom(display,
"DndSelection",MagickFalse);
15367 status=XGetWindowProperty(display,root_window,selection,0L,(
long)
15368 MaxTextExtent,MagickFalse,(Atom) AnyPropertyType,&type,&format,
15369 &length,&after,&data);
15370 if ((status != Success) || (length == 0))
15372 if (*event.xclient.data.l == 2)
15377 (void) CopyMagickString(resource_info->image_info->filename,
15378 (
char *) data,MaxTextExtent);
15385 if (strncmp((
char *) data,
"file:", 5) != 0)
15387 (void) XFree((
void *) data);
15390 (void) CopyMagickString(resource_info->image_info->filename,
15391 ((
char *) data)+5,MaxTextExtent);
15393 nexus=ReadImage(resource_info->image_info,
15394 &display_image->exception);
15395 CatchException(&display_image->exception);
15396 if (nexus != (Image *) NULL)
15397 *state|=NextImageState | ExitState;
15398 (void) XFree((
void *) data);
15404 if (event.xclient.message_type != windows->wm_protocols)
15406 if (*event.xclient.data.l != (
long) windows->wm_delete_window)
15408 (void) XWithdrawWindow(display,event.xclient.window,
15409 visual_info->screen);
15410 if (event.xclient.window == windows->image.id)
15415 if (event.xclient.window == windows->pan.id)
15420 windows->image.window_changes.width=windows->image.ximage->width;
15421 windows->image.window_changes.height=windows->image.ximage->height;
15422 (void) XConfigureImage(display,resource_info,windows,
15427 case ConfigureNotify:
15429 if (resource_info->debug != MagickFalse)
15430 (void) LogMagickEvent(X11Event,GetMagickModule(),
15431 "Configure Notify: 0x%lx %dx%d+%d+%d %d",event.xconfigure.window,
15432 event.xconfigure.width,event.xconfigure.height,event.xconfigure.x,
15433 event.xconfigure.y,event.xconfigure.send_event);
15434 if (event.xconfigure.window == windows->image.id)
15439 if (event.xconfigure.send_event != 0)
15447 if (windows->command.geometry == (
char *) NULL)
15448 if (windows->command.mapped == MagickFalse)
15450 windows->command.x=
event.xconfigure.x-
15451 windows->command.width-25;
15452 windows->command.y=
event.xconfigure.y;
15453 XConstrainWindowPosition(display,&windows->command);
15454 window_changes.x=windows->command.x;
15455 window_changes.y=windows->command.y;
15456 (void) XReconfigureWMWindow(display,windows->command.id,
15457 windows->command.screen,(
unsigned int) (CWX | CWY),
15460 if (windows->widget.geometry == (
char *) NULL)
15461 if (windows->widget.mapped == MagickFalse)
15463 windows->widget.x=
event.xconfigure.x+
15464 event.xconfigure.width/10;
15465 windows->widget.y=
event.xconfigure.y+
15466 event.xconfigure.height/10;
15467 XConstrainWindowPosition(display,&windows->widget);
15468 window_changes.x=windows->widget.x;
15469 window_changes.y=windows->widget.y;
15470 (void) XReconfigureWMWindow(display,windows->widget.id,
15471 windows->widget.screen,(
unsigned int) (CWX | CWY),
15474 if (windows->magnify.geometry == (
char *) NULL)
15475 if (windows->magnify.mapped == MagickFalse)
15477 windows->magnify.x=
event.xconfigure.x+
15478 event.xconfigure.width+25;
15479 windows->magnify.y=
event.xconfigure.y;
15480 XConstrainWindowPosition(display,&windows->magnify);
15481 window_changes.x=windows->magnify.x;
15482 window_changes.y=windows->magnify.y;
15483 (void) XReconfigureWMWindow(display,windows->magnify.id,
15484 windows->magnify.screen,(
unsigned int) (CWX | CWY),
15487 if (windows->pan.geometry == (
char *) NULL)
15488 if (windows->pan.mapped == MagickFalse)
15490 windows->pan.x=
event.xconfigure.x+
15491 event.xconfigure.width+25;
15492 windows->pan.y=
event.xconfigure.y+
15493 windows->magnify.height+50;
15494 XConstrainWindowPosition(display,&windows->pan);
15495 window_changes.x=windows->pan.x;
15496 window_changes.y=windows->pan.y;
15497 (void) XReconfigureWMWindow(display,windows->pan.id,
15498 windows->pan.screen,(
unsigned int) (CWX | CWY),
15502 if ((event.xconfigure.width == (
int) windows->image.width) &&
15503 (event.xconfigure.height == (
int) windows->image.height))
15505 windows->image.width=(
unsigned int) event.xconfigure.width;
15506 windows->image.height=(
unsigned int) event.xconfigure.height;
15507 windows->image.x=0;
15508 windows->image.y=0;
15509 if (display_image->montage != (
char *) NULL)
15511 windows->image.x=vid_info.x;
15512 windows->image.y=vid_info.y;
15514 if ((windows->image.mapped != MagickFalse) &&
15515 (windows->image.stasis != MagickFalse))
15520 windows->image.window_changes.width=
event.xconfigure.width;
15521 windows->image.window_changes.height=
event.xconfigure.height;
15522 (void) XConfigureImage(display,resource_info,windows,
15528 if ((event.xconfigure.width < windows->image.ximage->width) ||
15529 (event.xconfigure.height < windows->image.ximage->height))
15531 (void) XMapRaised(display,windows->pan.id);
15532 XDrawPanRectangle(display,windows);
15535 if (windows->pan.mapped != MagickFalse)
15536 (void) XWithdrawWindow(display,windows->pan.id,
15537 windows->pan.screen);
15540 if (event.xconfigure.window == windows->magnify.id)
15548 windows->magnify.width=(
unsigned int) event.xconfigure.width;
15549 windows->magnify.height=(
unsigned int) event.xconfigure.height;
15550 if (windows->magnify.mapped == MagickFalse)
15553 while ((
int) magnify <= event.xconfigure.width)
15555 while ((
int) magnify <= event.xconfigure.height)
15558 if (((
int) magnify != event.xconfigure.width) ||
15559 ((
int) magnify != event.xconfigure.height))
15561 window_changes.width=(int) magnify;
15562 window_changes.height=(int) magnify;
15563 (void) XReconfigureWMWindow(display,windows->magnify.id,
15564 windows->magnify.screen,(
unsigned int) (CWWidth | CWHeight),
15568 if ((windows->magnify.mapped != MagickFalse) &&
15569 (windows->magnify.stasis != MagickFalse))
15571 status=XMakeImage(display,resource_info,&windows->magnify,
15572 display_image,windows->magnify.width,windows->magnify.height);
15573 XMakeMagnifyImage(display,windows);
15577 if ((windows->magnify.mapped != MagickFalse) &&
15578 (event.xconfigure.window == windows->pan.id))
15583 if (event.xconfigure.send_event != 0)
15585 windows->pan.x=
event.xconfigure.x;
15586 windows->pan.y=
event.xconfigure.y;
15588 windows->pan.width=(
unsigned int) event.xconfigure.width;
15589 windows->pan.height=(
unsigned int) event.xconfigure.height;
15592 if (event.xconfigure.window == windows->icon.id)
15597 windows->icon.width=(
unsigned int) event.xconfigure.width;
15598 windows->icon.height=(
unsigned int) event.xconfigure.height;
15603 case DestroyNotify:
15608 if (resource_info->debug != MagickFalse)
15609 (void) LogMagickEvent(X11Event,GetMagickModule(),
15610 "Destroy Notify: 0x%lx",event.xdestroywindow.window);
15611 if (event.xdestroywindow.window == windows->group_leader.id)
15623 if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
15624 if (event.xcrossing.mode != NotifyUngrab)
15625 XInstallColormap(display,map_info->colormap);
15630 if (resource_info->debug != MagickFalse)
15631 (void) LogMagickEvent(X11Event,GetMagickModule(),
15632 "Expose: 0x%lx %dx%d+%d+%d",event.xexpose.window,
15633 event.xexpose.width,event.xexpose.height,event.xexpose.x,
15638 if ((event.xexpose.window == windows->image.id) &&
15639 (windows->image.mapped != MagickFalse))
15641 XRefreshWindow(display,&windows->image,&event);
15642 delay=display_image->delay/MagickMax(
15643 display_image->ticks_per_second,1L);
15644 timer=GetMagickTime()+(delay == 0 ? 1 : delay)+1;
15647 if ((event.xexpose.window == windows->magnify.id) &&
15648 (windows->magnify.mapped != MagickFalse))
15650 XMakeMagnifyImage(display,windows);
15653 if (event.xexpose.window == windows->pan.id)
15655 XDrawPanRectangle(display,windows);
15658 if (event.xexpose.window == windows->icon.id)
15660 XRefreshWindow(display,&windows->icon,&event);
15673 length=XLookupString((XKeyEvent *) &event.xkey,command,(
int)
15674 sizeof(command),&key_symbol,(XComposeStatus *) NULL);
15675 *(command+length)=
'\0';
15676 if (resource_info->debug != MagickFalse)
15677 (void) LogMagickEvent(X11Event,GetMagickModule(),
15678 "Key press: %d 0x%lx (%s)",event.xkey.state,(
unsigned long)
15679 key_symbol,command);
15680 if (event.xkey.window == windows->image.id)
15682 display_command=XImageWindowCommand(display,resource_info,windows,
15683 event.xkey.state,key_symbol,&display_image);
15684 if (display_command != NullCommand)
15685 nexus=XMagickCommand(display,resource_info,windows,display_command,
15688 if (event.xkey.window == windows->magnify.id)
15689 XMagnifyWindowCommand(display,windows,event.xkey.state,key_symbol);
15690 if (event.xkey.window == windows->pan.id)
15692 if ((key_symbol == XK_q) || (key_symbol == XK_Escape))
15693 (void) XWithdrawWindow(display,windows->pan.id,
15694 windows->pan.screen);
15696 if ((key_symbol == XK_F1) || (key_symbol == XK_Help))
15697 XTextViewHelp(display,resource_info,windows,MagickFalse,
15698 "Help Viewer - Image Pan",ImagePanHelp);
15700 XTranslateImage(display,windows,*image,key_symbol);
15702 delay=display_image->delay/MagickMax(
15703 display_image->ticks_per_second,1L);
15704 timer=GetMagickTime()+(delay == 0 ? 1 : delay)+1;
15712 (void) XLookupString((XKeyEvent *) &event.xkey,command,(
int)
15713 sizeof(command),&key_symbol,(XComposeStatus *) NULL);
15714 if (resource_info->debug != MagickFalse)
15715 (void) LogMagickEvent(X11Event,GetMagickModule(),
15716 "Key release: 0x%lx (%c)",(
unsigned long) key_symbol,*command);
15724 if (map_info->colormap != XDefaultColormap(display,visual_info->screen))
15725 if (event.xcrossing.mode != NotifyUngrab)
15726 XUninstallColormap(display,map_info->colormap);
15731 if (resource_info->debug != MagickFalse)
15732 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Map Notify: 0x%lx",
15733 event.xmap.window);
15734 if (event.xmap.window == windows->backdrop.id)
15736 (void) XSetInputFocus(display,event.xmap.window,RevertToParent,
15738 windows->backdrop.mapped=MagickTrue;
15741 if (event.xmap.window == windows->image.id)
15743 if (windows->backdrop.id != (Window) NULL)
15744 (void) XInstallColormap(display,map_info->colormap);
15745 if (LocaleCompare(display_image->magick,
"LOGO") == 0)
15747 if (LocaleCompare(display_image->filename,
"LOGO") == 0)
15748 nexus=XOpenImage(display,resource_info,windows,MagickFalse);
15750 if (((
int) windows->image.width < windows->image.ximage->width) ||
15751 ((
int) windows->image.height < windows->image.ximage->height))
15752 (void) XMapRaised(display,windows->pan.id);
15753 windows->image.mapped=MagickTrue;
15756 if (event.xmap.window == windows->magnify.id)
15758 XMakeMagnifyImage(display,windows);
15759 windows->magnify.mapped=MagickTrue;
15760 (void) XWithdrawWindow(display,windows->info.id,
15761 windows->info.screen);
15764 if (event.xmap.window == windows->pan.id)
15766 XMakePanImage(display,resource_info,windows,display_image);
15767 windows->pan.mapped=MagickTrue;
15770 if (event.xmap.window == windows->info.id)
15772 windows->info.mapped=MagickTrue;
15775 if (event.xmap.window == windows->icon.id)
15783 taint=display_image->taint;
15784 XMakeStandardColormap(display,icon_visual,icon_resources,
15785 display_image,icon_map,icon_pixel);
15786 (void) XMakeImage(display,icon_resources,&windows->icon,
15787 display_image,windows->icon.width,windows->icon.height);
15788 display_image->taint=taint;
15789 (void) XSetWindowBackgroundPixmap(display,windows->icon.id,
15790 windows->icon.pixmap);
15791 (void) XClearWindow(display,windows->icon.id);
15792 (void) XWithdrawWindow(display,windows->info.id,
15793 windows->info.screen);
15794 windows->icon.mapped=MagickTrue;
15797 if (event.xmap.window == windows->command.id)
15799 windows->command.mapped=MagickTrue;
15802 if (event.xmap.window == windows->popup.id)
15804 windows->popup.mapped=MagickTrue;
15807 if (event.xmap.window == windows->widget.id)
15809 windows->widget.mapped=MagickTrue;
15814 case MappingNotify:
15816 (void) XRefreshKeyboardMapping(&event.xmapping);
15821 case PropertyNotify:
15837 if (resource_info->debug != MagickFalse)
15838 (void) LogMagickEvent(X11Event,GetMagickModule(),
15839 "Property Notify: 0x%lx 0x%lx %d",event.xproperty.window,
15840 event.xproperty.atom,event.xproperty.state);
15841 if (event.xproperty.atom != windows->im_remote_command)
15846 status=XGetWindowProperty(display,event.xproperty.window,
15847 event.xproperty.atom,0L,(
long) MaxTextExtent,MagickFalse,(Atom)
15848 AnyPropertyType,&type,&format,&length,&after,&data);
15849 if ((status != Success) || (length == 0))
15851 if (LocaleCompare((
char *) data,
"-quit") == 0)
15853 XClientMessage(display,windows->image.id,windows->im_protocols,
15854 windows->im_exit,CurrentTime);
15855 (void) XFree((
void *) data);
15858 (void) CopyMagickString(resource_info->image_info->filename,
15859 (
char *) data,MaxTextExtent);
15860 (void) XFree((
void *) data);
15861 nexus=ReadImage(resource_info->image_info,&display_image->exception);
15862 CatchException(&display_image->exception);
15863 if (nexus != (Image *) NULL)
15864 *state|=NextImageState | ExitState;
15867 case ReparentNotify:
15869 if (resource_info->debug != MagickFalse)
15870 (void) LogMagickEvent(X11Event,GetMagickModule(),
15871 "Reparent Notify: 0x%lx=>0x%lx",event.xreparent.parent,
15872 event.xreparent.window);
15877 if (resource_info->debug != MagickFalse)
15878 (void) LogMagickEvent(X11Event,GetMagickModule(),
15879 "Unmap Notify: 0x%lx",event.xunmap.window);
15880 if (event.xunmap.window == windows->backdrop.id)
15882 windows->backdrop.mapped=MagickFalse;
15885 if (event.xunmap.window == windows->image.id)
15887 windows->image.mapped=MagickFalse;
15890 if (event.xunmap.window == windows->magnify.id)
15892 windows->magnify.mapped=MagickFalse;
15895 if (event.xunmap.window == windows->pan.id)
15897 windows->pan.mapped=MagickFalse;
15900 if (event.xunmap.window == windows->info.id)
15902 windows->info.mapped=MagickFalse;
15905 if (event.xunmap.window == windows->icon.id)
15907 if (map_info->colormap == icon_map->colormap)
15908 XConfigureImageColormap(display,resource_info,windows,
15910 (void) XFreeStandardColormap(display,icon_visual,icon_map,
15912 windows->icon.mapped=MagickFalse;
15915 if (event.xunmap.window == windows->command.id)
15917 windows->command.mapped=MagickFalse;
15920 if (event.xunmap.window == windows->popup.id)
15922 if (windows->backdrop.id != (Window) NULL)
15923 (void) XSetInputFocus(display,windows->image.id,RevertToParent,
15925 windows->popup.mapped=MagickFalse;
15928 if (event.xunmap.window == windows->widget.id)
15930 if (windows->backdrop.id != (Window) NULL)
15931 (void) XSetInputFocus(display,windows->image.id,RevertToParent,
15933 windows->widget.mapped=MagickFalse;
15940 if (resource_info->debug != MagickFalse)
15941 (void) LogMagickEvent(X11Event,GetMagickModule(),
"Event type: %d",
15946 }
while (!(*state & ExitState));
15947 if ((*state & ExitState) == 0)
15948 (void) XMagickCommand(display,resource_info,windows,FreeBuffersCommand,
15951 if (resource_info->confirm_edit != MagickFalse)
15956 if ((resource_info->immutable == MagickFalse) &&
15957 (display_image->taint != MagickFalse))
15962 status=XConfirmWidget(display,windows,
"Your image changed.",
15963 "Do you want to save it");
15965 *state&=(~ExitState);
15968 (void) XMagickCommand(display,resource_info,windows,SaveCommand,
15972 if ((windows->visual_info->klass == GrayScale) ||
15973 (windows->visual_info->klass == PseudoColor) ||
15974 (windows->visual_info->klass == DirectColor))
15979 if (windows->info.mapped != MagickFalse)
15980 (void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
15981 if (windows->magnify.mapped != MagickFalse)
15982 (void) XWithdrawWindow(display,windows->magnify.id,
15983 windows->magnify.screen);
15984 if (windows->command.mapped != MagickFalse)
15985 (void) XWithdrawWindow(display,windows->command.id,
15986 windows->command.screen);
15988 if (windows->pan.mapped != MagickFalse)
15989 (void) XWithdrawWindow(display,windows->pan.id,windows->pan.screen);
15990 if (resource_info->backdrop == MagickFalse)
15991 if (windows->backdrop.mapped)
15993 (void) XWithdrawWindow(display,windows->backdrop.id,
15994 windows->backdrop.screen);
15995 (void) XDestroyWindow(display,windows->backdrop.id);
15996 windows->backdrop.id=(Window) NULL;
15997 (void) XWithdrawWindow(display,windows->image.id,
15998 windows->image.screen);
15999 (void) XDestroyWindow(display,windows->image.id);
16000 windows->image.id=(Window) NULL;
16002 XSetCursorState(display,windows,MagickTrue);
16003 XCheckRefreshWindows(display,windows);
16004 if (((*state & FormerImageState) != 0) || ((*state & NextImageState) != 0))
16005 *state&=(~ExitState);
16006 if (*state & ExitState)
16011 (void) XFreeStandardColormap(display,icon_visual,icon_map,icon_pixel);
16012 if (resource_info->map_type == (
char *) NULL)
16013 (void) XFreeStandardColormap(display,visual_info,map_info,pixel);
16017 if (resource_info->copy_image != (Image *) NULL)
16018 resource_info->copy_image=DestroyImage(resource_info->copy_image);
16019 DestroyXResources();
16021 (void) XSync(display,MagickFalse);
16025 (void) SetErrorHandler(warning_handler);
16026 (void) SetWarningHandler(warning_handler);
16030 directory=getcwd(working_directory,MaxTextExtent);
16036 if (*resource_info->home_directory ==
'\0')
16037 (void) CopyMagickString(resource_info->home_directory,
".",MaxTextExtent);
16038 status=chdir(resource_info->home_directory);
16040 (void) ThrowMagickException(&display_image->exception,GetMagickModule(),
16041 FileOpenError,
"UnableToOpenFile",
"%s",resource_info->home_directory);
16043 *image=display_image;
16075MagickExport MagickBooleanType DisplayImages(
const ImageInfo *image_info,
16078 assert(image_info != (
const ImageInfo *) NULL);
16079 assert(image_info->signature == MagickCoreSignature);
16080 assert(image != (Image *) NULL);
16081 assert(image->signature == MagickCoreSignature);
16082 if (IsEventLogging() != MagickFalse)
16083 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
16085 (void) ThrowMagickException(&image->exception,GetMagickModule(),
16086 MissingDelegateError,
"DelegateLibrarySupportNotBuiltIn",
"`%s' (X11)",
16088 return(MagickFalse);
16121MagickExport MagickBooleanType RemoteDisplayCommand(
const ImageInfo *image_info,
16122 const char *window,
const char *filename,ExceptionInfo *exception)
16124 assert(image_info != (
const ImageInfo *) NULL);
16125 assert(image_info->signature == MagickCoreSignature);
16126 assert(filename != (
char *) NULL);
16127 if (IsEventLogging() != MagickFalse)
16128 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",filename);
16130 (void) ThrowMagickException(exception,GetMagickModule(),MissingDelegateError,
16131 "DelegateLibrarySupportNotBuiltIn",
"`%s' (X11)",image_info->filename);
16132 return(MagickFalse);