blob: 4574904246bac23d747053df9e91a9a36b9884bf [file] [log] [blame]
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% DDDD IIIII SSSSS PPPP L AAA Y Y %
% D D I SS P P L A A Y Y %
% D D I SSS PPPP L AAAAA Y %
% D D I SS P L A A Y %
% DDDD IIIII SSSSS P LLLLL A A Y %
% %
% %
% MagickCore Methods to Interactively Display and Edit an Image %
% %
% Software Design %
% Cristy %
% July 1992 %
% %
% %
% Copyright 1999-2019 ImageMagick Studio LLC, a non-profit organization %
% dedicated to making software imaging solutions freely available. %
% %
% You may not use this file except in compliance with the License. You may %
% obtain a copy of the License at %
% %
% https://imagemagick.org/script/license.php %
% %
% Unless required by applicable law or agreed to in writing, software %
% distributed under the License is distributed on an "AS IS" BASIS, %
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
% See the License for the specific language governing permissions and %
% limitations under the License. %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
*/
/*
Include declarations.
*/
#include "MagickCore/studio.h"
#include "MagickCore/artifact.h"
#include "MagickCore/attribute.h"
#include "MagickCore/blob.h"
#include "MagickCore/cache.h"
#include "MagickCore/cache-private.h"
#include "MagickCore/channel.h"
#include "MagickCore/client.h"
#include "MagickCore/color.h"
#include "MagickCore/colorspace.h"
#include "MagickCore/composite.h"
#include "MagickCore/constitute.h"
#include "MagickCore/decorate.h"
#include "MagickCore/delegate.h"
#include "MagickCore/display.h"
#include "MagickCore/display-private.h"
#include "MagickCore/distort.h"
#include "MagickCore/draw.h"
#include "MagickCore/effect.h"
#include "MagickCore/enhance.h"
#include "MagickCore/exception.h"
#include "MagickCore/exception-private.h"
#include "MagickCore/fx.h"
#include "MagickCore/geometry.h"
#include "MagickCore/image.h"
#include "MagickCore/image-private.h"
#include "MagickCore/list.h"
#include "MagickCore/log.h"
#include "MagickCore/magick.h"
#include "MagickCore/memory_.h"
#include "MagickCore/monitor.h"
#include "MagickCore/monitor-private.h"
#include "MagickCore/montage.h"
#include "MagickCore/nt-base-private.h"
#include "MagickCore/option.h"
#include "MagickCore/paint.h"
#include "MagickCore/pixel.h"
#include "MagickCore/pixel-accessor.h"
#include "MagickCore/property.h"
#include "MagickCore/quantum.h"
#include "MagickCore/quantum-private.h"
#include "MagickCore/resize.h"
#include "MagickCore/resource_.h"
#include "MagickCore/shear.h"
#include "MagickCore/segment.h"
#include "MagickCore/statistic.h"
#include "MagickCore/string_.h"
#include "MagickCore/string-private.h"
#include "MagickCore/transform.h"
#include "MagickCore/transform-private.h"
#include "MagickCore/threshold.h"
#include "MagickCore/utility.h"
#include "MagickCore/utility-private.h"
#include "MagickCore/version.h"
#include "MagickCore/widget.h"
#include "MagickCore/widget-private.h"
#include "MagickCore/xwindow.h"
#include "MagickCore/xwindow-private.h"
#if defined(MAGICKCORE_X11_DELEGATE)
/*
Define declarations.
*/
#define MaxColors MagickMin((ssize_t) windows->visual_info->colormap_size,256L)
/*
Constant declarations.
*/
static const unsigned char
HighlightBitmap[8] =
{
0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55
},
OpaqueBitmap[8] =
{
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
},
ShadowBitmap[8] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};
static const char
*PageSizes[] =
{
"Letter",
"Tabloid",
"Ledger",
"Legal",
"Statement",
"Executive",
"A3",
"A4",
"A5",
"B4",
"B5",
"Folio",
"Quarto",
"10x14",
(char *) NULL
};
/*
Help widget declarations.
*/
static const char
*ImageAnnotateHelp[] =
{
"In annotate mode, the Command widget has these options:",
"",
" Font Name",
" fixed",
" variable",
" 5x8",
" 6x10",
" 7x13bold",
" 8x13bold",
" 9x15bold",
" 10x20",
" 12x24",
" Browser...",
" Font Color",
" black",
" blue",
" cyan",
" green",
" gray",
" red",
" magenta",
" yellow",
" white",
" transparent",
" Browser...",
" Font Color",
" black",
" blue",
" cyan",
" green",
" gray",
" red",
" magenta",
" yellow",
" white",
" transparent",
" Browser...",
" Rotate Text",
" -90",
" -45",
" -30",
" 0",
" 30",
" 45",
" 90",
" 180",
" Dialog...",
" Help",
" Dismiss",
"",
"Choose a font name from the Font Name sub-menu. Additional",
"font names can be specified with the font browser. You can",
"change the menu names by setting the X resources font1",
"through font9.",
"",
"Choose a font color from the Font Color sub-menu.",
"Additional font colors can be specified with the color",
"browser. You can change the menu colors by setting the X",
"resources pen1 through pen9.",
"",
"If you select the color browser and press Grab, you can",
"choose the font color by moving the pointer to the desired",
"color on the screen and press any button.",
"",
"If you choose to rotate the text, choose Rotate Text from the",
"menu and select an angle. Typically you will only want to",
"rotate one line of text at a time. Depending on the angle you",
"choose, subsequent lines may end up overwriting each other.",
"",
"Choosing a font and its color is optional. The default font",
"is fixed and the default color is black. However, you must",
"choose a location to begin entering text and press button 1.",
"An underscore character will appear at the location of the",
"pointer. The cursor changes to a pencil to indicate you are",
"in text mode. To exit immediately, press Dismiss.",
"",
"In text mode, any key presses will display the character at",
"the location of the underscore and advance the underscore",
"cursor. Enter your text and once completed press Apply to",
"finish your image annotation. To correct errors press BACK",
"SPACE. To delete an entire line of text, press DELETE. Any",
"text that exceeds the boundaries of the image window is",
"automagically continued onto the next line.",
"",
"The actual color you request for the font is saved in the",
"image. However, the color that appears in your image window",
"may be different. For example, on a monochrome screen the",
"text will appear black or white even if you choose the color",
"red as the font color. However, the image saved to a file",
"with -write is written with red lettering. To assure the",
"correct color text in the final image, any PseudoClass image",
"is promoted to DirectClass (see miff(5)). To force a",
"PseudoClass image to remain PseudoClass, use -colors.",
(char *) NULL,
},
*ImageChopHelp[] =
{
"In chop mode, the Command widget has these options:",
"",
" Direction",
" horizontal",
" vertical",
" Help",
" Dismiss",
"",
"If the you choose the horizontal direction (this the",
"default), the area of the image between the two horizontal",
"endpoints of the chop line is removed. Otherwise, the area",
"of the image between the two vertical endpoints of the chop",
"line is removed.",
"",
"Select a location within the image window to begin your chop,",
"press and hold any button. Next, move the pointer to",
"another location in the image. As you move a line will",
"connect the initial location and the pointer. When you",
"release the button, the area within the image to chop is",
"determined by which direction you choose from the Command",
"widget.",
"",
"To cancel the image chopping, move the pointer back to the",
"starting point of the line and release the button.",
(char *) NULL,
},
*ImageColorEditHelp[] =
{
"In color edit mode, the Command widget has these options:",
"",
" Method",
" point",
" replace",
" floodfill",
" filltoborder",
" reset",
" Pixel Color",
" black",
" blue",
" cyan",
" green",
" gray",
" red",
" magenta",
" yellow",
" white",
" Browser...",
" Border Color",
" black",
" blue",
" cyan",
" green",
" gray",
" red",
" magenta",
" yellow",
" white",
" Browser...",
" Fuzz",
" 0%",
" 2%",
" 5%",
" 10%",
" 15%",
" Dialog...",
" Undo",
" Help",
" Dismiss",
"",
"Choose a color editing method from the Method sub-menu",
"of the Command widget. The point method recolors any pixel",
"selected with the pointer until the button is released. The",
"replace method recolors any pixel that matches the color of",
"the pixel you select with a button press. Floodfill recolors",
"any pixel that matches the color of the pixel you select with",
"a button press and is a neighbor. Whereas filltoborder recolors",
"any neighbor pixel that is not the border color. Finally reset",
"changes the entire image to the designated color.",
"",
"Next, choose a pixel color from the Pixel Color sub-menu.",
"Additional pixel colors can be specified with the color",
"browser. You can change the menu colors by setting the X",
"resources pen1 through pen9.",
"",
"Now press button 1 to select a pixel within the image window",
"to change its color. Additional pixels may be recolored as",
"prescribed by the method you choose.",
"",
"If the Magnify widget is mapped, it can be helpful in positioning",
"your pointer within the image (refer to button 2).",
"",
"The actual color you request for the pixels is saved in the",
"image. However, the color that appears in your image window",
"may be different. For example, on a monochrome screen the",
"pixel will appear black or white even if you choose the",
"color red as the pixel color. However, the image saved to a",
"file with -write is written with red pixels. To assure the",
"correct color text in the final image, any PseudoClass image",
"is promoted to DirectClass (see miff(5)). To force a",
"PseudoClass image to remain PseudoClass, use -colors.",
(char *) NULL,
},
*ImageCompositeHelp[] =
{
"First a widget window is displayed requesting you to enter an",
"image name. Press Composite, Grab or type a file name.",
"Press Cancel if you choose not to create a composite image.",
"When you choose Grab, move the pointer to the desired window",
"and press any button.",
"",
"If the Composite image does not have any matte information,",
"you are informed and the file browser is displayed again.",
"Enter the name of a mask image. The image is typically",
"grayscale and the same size as the composite image. If the",
"image is not grayscale, it is converted to grayscale and the",
"resulting intensities are used as matte information.",
"",
"A small window appears showing the location of the cursor in",
"the image window. You are now in composite mode. To exit",
"immediately, press Dismiss. In composite mode, the Command",
"widget has these options:",
"",
" Operators",
" Over",
" In",
" Out",
" Atop",
" Xor",
" Plus",
" Minus",
" Add",
" Subtract",
" Difference",
" Multiply",
" Bumpmap",
" Copy",
" CopyRed",
" CopyGreen",
" CopyBlue",
" CopyOpacity",
" Clear",
" Dissolve",
" Displace",
" Help",
" Dismiss",
"",
"Choose a composite operation from the Operators sub-menu of",
"the Command widget. How each operator behaves is described",
"below. Image window is the image currently displayed on",
"your X server and image is the image obtained with the File",
"Browser widget.",
"",
"Over The result is the union of the two image shapes,",
" with image obscuring image window in the region of",
" overlap.",
"",
"In The result is simply image cut by the shape of",
" image window. None of the image data of image",
" window is in the result.",
"",
"Out The resulting image is image with the shape of",
" image window cut out.",
"",
"Atop The result is the same shape as image image window,",
" with image obscuring image window where the image",
" shapes overlap. Note this differs from over",
" because the portion of image outside image window's",
" shape does not appear in the result.",
"",
"Xor The result is the image data from both image and",
" image window that is outside the overlap region.",
" The overlap region is blank.",
"",
"Plus The result is just the sum of the image data.",
" Output values are cropped to QuantumRange (no overflow).",
"",
"Minus The result of image - image window, with underflow",
" cropped to zero.",
"",
"Add The result of image + image window, with overflow",
" wrapping around (mod 256).",
"",
"Subtract The result of image - image window, with underflow",
" wrapping around (mod 256). The add and subtract",
" operators can be used to perform reversible",
" transformations.",
"",
"Difference",
" The result of abs(image - image window). This",
" useful for comparing two very similar images.",
"",
"Multiply",
" The result of image * image window. This",
" useful for the creation of drop-shadows.",
"",
"Bumpmap The result of surface normals from image * image",
" window.",
"",
"Copy The resulting image is image window replaced with",
" image. Here the matte information is ignored.",
"",
"CopyRed The red layer of the image window is replace with",
" the red layer of the image. The other layers are",
" untouched.",
"",
"CopyGreen",
" The green layer of the image window is replace with",
" the green layer of the image. The other layers are",
" untouched.",
"",
"CopyBlue The blue layer of the image window is replace with",
" the blue layer of the image. The other layers are",
" untouched.",
"",
"CopyOpacity",
" The matte layer of the image window is replace with",
" the matte layer of the image. The other layers are",
" untouched.",
"",
"The image compositor requires a matte, or alpha channel in",
"the image for some operations. This extra channel usually",
"defines a mask which represents a sort of a cookie-cutter",
"for the image. This the case when matte is opaque (full",
"coverage) for pixels inside the shape, zero outside, and",
"between 0 and QuantumRange on the boundary. If image does not",
"have a matte channel, it is initialized with 0 for any pixel",
"matching in color to pixel location (0,0), otherwise QuantumRange.",
"",
"If you choose Dissolve, the composite operator becomes Over. The",
"image matte channel percent transparency is initialized to factor.",
"The image window is initialized to (100-factor). Where factor is the",
"value you specify in the Dialog widget.",
"",
"Displace shifts the image pixels as defined by a displacement",
"map. With this option, image is used as a displacement map.",
"Black, within the displacement map, is a maximum positive",
"displacement. White is a maximum negative displacement and",
"middle gray is neutral. The displacement is scaled to determine",
"the pixel shift. By default, the displacement applies in both the",
"horizontal and vertical directions. However, if you specify a mask,",
"image is the horizontal X displacement and mask the vertical Y",
"displacement.",
"",
"Note that matte information for image window is not retained",
"for colormapped X server visuals (e.g. StaticColor,",
"StaticColor, GrayScale, PseudoColor). Correct compositing",
"behavior may require a TrueColor or DirectColor visual or a",
"Standard Colormap.",
"",
"Choosing a composite operator is optional. The default",
"operator is replace. However, you must choose a location to",
"composite your image and press button 1. Press and hold the",
"button before releasing and an outline of the image will",
"appear to help you identify your location.",
"",
"The actual colors of the composite image is saved. However,",
"the color that appears in image window may be different.",
"For example, on a monochrome screen image window will appear",
"black or white even though your composited image may have",
"many colors. If the image is saved to a file it is written",
"with the correct colors. To assure the correct colors are",
"saved in the final image, any PseudoClass image is promoted",
"to DirectClass (see miff(5)). To force a PseudoClass image",
"to remain PseudoClass, use -colors.",
(char *) NULL,
},
*ImageCutHelp[] =
{
"In cut mode, the Command widget has these options:",
"",
" Help",
" Dismiss",
"",
"To define a cut region, press button 1 and drag. The",
"cut region is defined by a highlighted rectangle that",
"expands or contracts as it follows the pointer. Once you",
"are satisfied with the cut region, release the button.",
"You are now in rectify mode. In rectify mode, the Command",
"widget has these options:",
"",
" Cut",
" Help",
" Dismiss",
"",
"You can make adjustments by moving the pointer to one of the",
"cut rectangle corners, pressing a button, and dragging.",
"Finally, press Cut to commit your copy region. To",
"exit without cutting the image, press Dismiss.",
(char *) NULL,
},
*ImageCopyHelp[] =
{
"In copy mode, the Command widget has these options:",
"",
" Help",
" Dismiss",
"",
"To define a copy region, press button 1 and drag. The",
"copy region is defined by a highlighted rectangle that",
"expands or contracts as it follows the pointer. Once you",
"are satisfied with the copy region, release the button.",
"You are now in rectify mode. In rectify mode, the Command",
"widget has these options:",
"",
" Copy",
" Help",
" Dismiss",
"",
"You can make adjustments by moving the pointer to one of the",
"copy rectangle corners, pressing a button, and dragging.",
"Finally, press Copy to commit your copy region. To",
"exit without copying the image, press Dismiss.",
(char *) NULL,
},
*ImageCropHelp[] =
{
"In crop mode, the Command widget has these options:",
"",
" Help",
" Dismiss",
"",
"To define a cropping region, press button 1 and drag. The",
"cropping region is defined by a highlighted rectangle that",
"expands or contracts as it follows the pointer. Once you",
"are satisfied with the cropping region, release the button.",
"You are now in rectify mode. In rectify mode, the Command",
"widget has these options:",
"",
" Crop",
" Help",
" Dismiss",
"",
"You can make adjustments by moving the pointer to one of the",
"cropping rectangle corners, pressing a button, and dragging.",
"Finally, press Crop to commit your cropping region. To",
"exit without cropping the image, press Dismiss.",
(char *) NULL,
},
*ImageDrawHelp[] =
{
"The cursor changes to a crosshair to indicate you are in",
"draw mode. To exit immediately, press Dismiss. In draw mode,",
"the Command widget has these options:",
"",
" Element",
" point",
" line",
" rectangle",
" fill rectangle",
" circle",
" fill circle",
" ellipse",
" fill ellipse",
" polygon",
" fill polygon",
" Color",
" black",
" blue",
" cyan",
" green",
" gray",
" red",
" magenta",
" yellow",
" white",
" transparent",
" Browser...",
" Stipple",
" Brick",
" Diagonal",
" Scales",
" Vertical",
" Wavy",
" Translucent",
" Opaque",
" Open...",
" Width",
" 1",
" 2",
" 4",
" 8",
" 16",
" Dialog...",
" Undo",
" Help",
" Dismiss",
"",
"Choose a drawing primitive from the Element sub-menu.",
"",
"Choose a color from the Color sub-menu. Additional",
"colors can be specified with the color browser.",
"",
"If you choose the color browser and press Grab, you can",
"select the color by moving the pointer to the desired",
"color on the screen and press any button. The transparent",
"color updates the image matte channel and is useful for",
"image compositing.",
"",
"Choose a stipple, if appropriate, from the Stipple sub-menu.",
"Additional stipples can be specified with the file browser.",
"Stipples obtained from the file browser must be on disk in the",
"X11 bitmap format.",
"",
"Choose a width, if appropriate, from the Width sub-menu. To",
"choose a specific width select the Dialog widget.",
"",
"Choose a point in the Image window and press button 1 and",
"hold. Next, move the pointer to another location in the",
"image. As you move, a line connects the initial location and",
"the pointer. When you release the button, the image is",
"updated with the primitive you just drew. For polygons, the",
"image is updated when you press and release the button without",
"moving the pointer.",
"",
"To cancel image drawing, move the pointer back to the",
"starting point of the line and release the button.",
(char *) NULL,
},
*DisplayHelp[] =
{
"BUTTONS",
" The effects of each button press is described below. Three",
" buttons are required. If you have a two button mouse,",
" button 1 and 3 are returned. Press ALT and button 3 to",
" simulate button 2.",
"",
" 1 Press this button to map or unmap the Command widget.",
"",
" 2 Press and drag to define a region of the image to",
" magnify.",
"",
" 3 Press and drag to choose from a select set of commands.",
" This button behaves differently if the image being",
" displayed is a visual image directory. Here, choose a",
" particular tile of the directory and press this button and",
" drag to select a command from a pop-up menu. Choose from",
" these menu items:",
"",
" Open",
" Next",
" Former",
" Delete",
" Update",
"",
" If you choose Open, the image represented by the tile is",
" displayed. To return to the visual image directory, choose",
" Next from the Command widget. Next and Former moves to the",
" next or former image respectively. Choose Delete to delete",
" a particular image tile. Finally, choose Update to",
" synchronize all the image tiles with their respective",
" images.",
"",
"COMMAND WIDGET",
" The Command widget lists a number of sub-menus and commands.",
" They are",
"",
" File",
" Open...",
" Next",
" Former",
" Select...",
" Save...",
" Print...",
" Delete...",
" New...",
" Visual Directory...",
" Quit",
" Edit",
" Undo",
" Redo",
" Cut",
" Copy",
" Paste",
" View",
" Half Size",
" Original Size",
" Double Size",
" Resize...",
" Apply",
" Refresh",
" Restore",
" Transform",
" Crop",
" Chop",
" Flop",
" Flip",
" Rotate Right",
" Rotate Left",
" Rotate...",
" Shear...",
" Roll...",
" Trim Edges",
" Enhance",
" Brightness...",
" Saturation...",
" Hue...",
" Gamma...",
" Sharpen...",
" Dull",
" Contrast Stretch...",
" Sigmoidal Contrast...",
" Normalize",
" Equalize",
" Negate",
" Grayscale",
" Map...",
" Quantize...",
" Effects",
" Despeckle",
" Emboss",
" Reduce Noise",
" Add Noise",
" Sharpen...",
" Blur...",
" Threshold...",
" Edge Detect...",
" Spread...",
" Shade...",
" Painting...",
" Segment...",
" F/X",
" Solarize...",
" Sepia Tone...",
" Swirl...",
" Implode...",
" Vignette...",
" Wave...",
" Oil Painting...",
" Charcoal Drawing...",
" Image Edit",
" Annotate...",
" Draw...",
" Color...",
" Matte...",
" Composite...",
" Add Border...",
" Add Frame...",
" Comment...",
" Launch...",
" Region of Interest...",
" Miscellany",
" Image Info",
" Zoom Image",
" Show Preview...",
" Show Histogram",
" Show Matte",
" Background...",
" Slide Show",
" Preferences...",
" Help",
" Overview",
" Browse Documentation",
" About Display",
"",
" Menu items with a indented triangle have a sub-menu. They",
" are represented above as the indented items. To access a",
" sub-menu item, move the pointer to the appropriate menu and",
" press a button and drag. When you find the desired sub-menu",
" item, release the button and the command is executed. Move",
" the pointer away from the sub-menu if you decide not to",
" execute a particular command.",
"",
"KEYBOARD ACCELERATORS",
" Accelerators are one or two key presses that effect a",
" particular command. The keyboard accelerators that",
" display(1) understands is:",
"",
" Ctl+O Press to open an image from a file.",
"",
" space Press to display the next image.",
"",
" If the image is a multi-paged document such as a Postscript",
" document, you can skip ahead several pages by preceding",
" this command with a number. For example to display the",
" third page beyond the current page, press 3<space>.",
"",
" backspace Press to display the former image.",
"",
" If the image is a multi-paged document such as a Postscript",
" document, you can skip behind several pages by preceding",
" this command with a number. For example to display the",
" third page preceding the current page, press 3<backspace>.",
"",
" Ctl+S Press to write the image to a file.",
"",
" Ctl+P Press to print the image to a Postscript printer.",
"",
" Ctl+D Press to delete an image file.",
"",
" Ctl+N Press to create a blank canvas.",
"",
" Ctl+Q Press to discard all images and exit program.",
"",
" Ctl+Z Press to undo last image transformation.",
"",
" Ctl+R Press to redo last image transformation.",
"",
" Ctl+X Press to cut a region of the image.",
"",
" Ctl+C Press to copy a region of the image.",
"",
" Ctl+V Press to paste a region to the image.",
"",
" < Press to half the image size.",
"",
" - Press to return to the original image size.",
"",
" > Press to double the image size.",
"",
" % Press to resize the image to a width and height you",
" specify.",
"",
"Cmd-A Press to make any image transformations permanent."
"",
" By default, any image size transformations are applied",
" to the original image to create the image displayed on",
" the X server. However, the transformations are not",
" permanent (i.e. the original image does not change",
" size only the X image does). For example, if you",
" press > the X image will appear to double in size,",
" but the original image will in fact remain the same size.",
" To force the original image to double in size, press >",
" followed by Cmd-A.",
"",
" @ Press to refresh the image window.",
"",
" C Press to cut out a rectangular region of the image.",
"",
" [ Press to chop the image.",
"",
" H Press to flop image in the horizontal direction.",
"",
" V Press to flip image in the vertical direction.",
"",
" / Press to rotate the image 90 degrees clockwise.",
"",
" \\ Press to rotate the image 90 degrees counter-clockwise.",
"",
" * Press to rotate the image the number of degrees you",
" specify.",
"",
" S Press to shear the image the number of degrees you",
" specify.",
"",
" R Press to roll the image.",
"",
" T Press to trim the image edges.",
"",
" Shft-H Press to vary the image hue.",
"",
" Shft-S Press to vary the color saturation.",
"",
" Shft-L Press to vary the color brightness.",
"",
" Shft-G Press to gamma correct the image.",
"",
" Shft-C Press to sharpen the image contrast.",
"",
" Shft-Z Press to dull the image contrast.",
"",
" = Press to perform histogram equalization on the image.",
"",
" Shft-N Press to perform histogram normalization on the image.",
"",
" Shft-~ Press to negate the colors of the image.",
"",
" . Press to convert the image colors to gray.",
"",
" Shft-# Press to set the maximum number of unique colors in the",
" image.",
"",
" F2 Press to reduce the speckles in an image.",
"",
" F3 Press to eliminate peak noise from an image.",
"",
" F4 Press to add noise to an image.",
"",
" F5 Press to sharpen an image.",
"",
" F6 Press to delete an image file.",
"",
" F7 Press to threshold the image.",
"",
" F8 Press to detect edges within an image.",
"",
" F9 Press to emboss an image.",
"",
" F10 Press to displace pixels by a random amount.",
"",
" F11 Press to negate all pixels above the threshold level.",
"",
" F12 Press to shade the image using a distant light source.",
"",
" F13 Press to lighten or darken image edges to create a 3-D effect.",
"",
" F14 Press to segment the image by color.",
"",
" Meta-S Press to swirl image pixels about the center.",
"",
" Meta-I Press to implode image pixels about the center.",
"",
" Meta-W Press to alter an image along a sine wave.",
"",
" Meta-P Press to simulate an oil painting.",
"",
" Meta-C Press to simulate a charcoal drawing.",
"",
" Alt-A Press to annotate the image with text.",
"",
" Alt-D Press to draw on an image.",
"",
" Alt-P Press to edit an image pixel color.",
"",
" Alt-M Press to edit the image matte information.",
"",
" Alt-V Press to composite the image with another.",
"",
" Alt-B Press to add a border to the image.",
"",
" Alt-F Press to add an ornamental border to the image.",
"",
" Alt-Shft-!",
" Press to add an image comment.",
"",
" Ctl-A Press to apply image processing techniques to a region",
" of interest.",
"",
" Shft-? Press to display information about the image.",
"",
" Shft-+ Press to map the zoom image window.",
"",
" Shft-P Press to preview an image enhancement, effect, or f/x.",
"",
" F1 Press to display helpful information about display(1).",
"",
" Find Press to browse documentation about ImageMagick.",
"",
" 1-9 Press to change the level of magnification.",
"",
" Use the arrow keys to move the image one pixel up, down,",
" left, or right within the magnify window. Be sure to first",
" map the magnify window by pressing button 2.",
"",
" Press ALT and one of the arrow keys to trim off one pixel",
" from any side of the image.",
(char *) NULL,
},
*ImageMatteEditHelp[] =
{
"Matte information within an image is useful for some",
"operations such as image compositing (See IMAGE",
"COMPOSITING). This extra channel usually defines a mask",
"which represents a sort of a cookie-cutter for the image.",
"This the case when matte is opaque (full coverage) for",
"pixels inside the shape, zero outside, and between 0 and",
"QuantumRange on the boundary.",
"",
"A small window appears showing the location of the cursor in",
"the image window. You are now in matte edit mode. To exit",
"immediately, press Dismiss. In matte edit mode, the Command",
"widget has these options:",
"",
" Method",
" point",
" replace",
" floodfill",
" filltoborder",
" reset",
" Border Color",
" black",
" blue",
" cyan",
" green",
" gray",
" red",
" magenta",
" yellow",
" white",
" Browser...",
" Fuzz",
" 0%",
" 2%",
" 5%",
" 10%",
" 15%",
" Dialog...",
" Matte",
" Opaque",
" Transparent",
" Dialog...",
" Undo",
" Help",
" Dismiss",
"",
"Choose a matte editing method from the Method sub-menu of",
"the Command widget. The point method changes the matte value",
"of any pixel selected with the pointer until the button is",
"is released. The replace method changes the matte value of",
"any pixel that matches the color of the pixel you select with",
"a button press. Floodfill changes the matte value of any pixel",
"that matches the color of the pixel you select with a button",
"press and is a neighbor. Whereas filltoborder changes the matte",
"value any neighbor pixel that is not the border color. Finally",
"reset changes the entire image to the designated matte value.",
"",
"Choose Matte Value and pick Opaque or Transarent. For other values",
"select the Dialog entry. Here a dialog appears requesting a matte",
"value. The value you select is assigned as the opacity value of the",
"selected pixel or pixels.",
"",
"Now, press any button to select a pixel within the image",
"window to change its matte value.",
"",
"If the Magnify widget is mapped, it can be helpful in positioning",
"your pointer within the image (refer to button 2).",
"",
"Matte information is only valid in a DirectClass image.",
"Therefore, any PseudoClass image is promoted to DirectClass",
"(see miff(5)). Note that matte information for PseudoClass",
"is not retained for colormapped X server visuals (e.g.",
"StaticColor, StaticColor, GrayScale, PseudoColor) unless you",
"immediately save your image to a file (refer to Write).",
"Correct matte editing behavior may require a TrueColor or",
"DirectColor visual or a Standard Colormap.",
(char *) NULL,
},
*ImagePanHelp[] =
{
"When an image exceeds the width or height of the X server",
"screen, display maps a small panning icon. The rectangle",
"within the panning icon shows the area that is currently",
"displayed in the image window. To pan about the image,",
"press any button and drag the pointer within the panning",
"icon. The pan rectangle moves with the pointer and the",
"image window is updated to reflect the location of the",
"rectangle within the panning icon. When you have selected",
"the area of the image you wish to view, release the button.",
"",
"Use the arrow keys to pan the image one pixel up, down,",
"left, or right within the image window.",
"",
"The panning icon is withdrawn if the image becomes smaller",
"than the dimensions of the X server screen.",
(char *) NULL,
},
*ImagePasteHelp[] =
{
"A small window appears showing the location of the cursor in",
"the image window. You are now in paste mode. To exit",
"immediately, press Dismiss. In paste mode, the Command",
"widget has these options:",
"",
" Operators",
" over",
" in",
" out",
" atop",
" xor",
" plus",
" minus",
" add",
" subtract",
" difference",
" replace",
" Help",
" Dismiss",
"",
"Choose a composite operation from the Operators sub-menu of",
"the Command widget. How each operator behaves is described",
"below. Image window is the image currently displayed on",
"your X server and image is the image obtained with the File",
"Browser widget.",
"",
"Over The result is the union of the two image shapes,",
" with image obscuring image window in the region of",
" overlap.",
"",
"In The result is simply image cut by the shape of",
" image window. None of the image data of image",
" window is in the result.",
"",
"Out The resulting image is image with the shape of",
" image window cut out.",
"",
"Atop The result is the same shape as image image window,",
" with image obscuring image window where the image",
" shapes overlap. Note this differs from over",
" because the portion of image outside image window's",
" shape does not appear in the result.",
"",
"Xor The result is the image data from both image and",
" image window that is outside the overlap region.",
" The overlap region is blank.",
"",
"Plus The result is just the sum of the image data.",
" Output values are cropped to QuantumRange (no overflow).",
" This operation is independent of the matte",
" channels.",
"",
"Minus The result of image - image window, with underflow",
" cropped to zero.",
"",
"Add The result of image + image window, with overflow",
" wrapping around (mod 256).",
"",
"Subtract The result of image - image window, with underflow",
" wrapping around (mod 256). The add and subtract",
" operators can be used to perform reversible",
" transformations.",
"",
"Difference",
" The result of abs(image - image window). This",
" useful for comparing two very similar images.",
"",
"Copy The resulting image is image window replaced with",
" image. Here the matte information is ignored.",
"",
"CopyRed The red layer of the image window is replace with",
" the red layer of the image. The other layers are",
" untouched.",
"",
"CopyGreen",
" The green layer of the image window is replace with",
" the green layer of the image. The other layers are",
" untouched.",
"",
"CopyBlue The blue layer of the image window is replace with",
" the blue layer of the image. The other layers are",
" untouched.",
"",
"CopyOpacity",
" The matte layer of the image window is replace with",
" the matte layer of the image. The other layers are",
" untouched.",
"",
"The image compositor requires a matte, or alpha channel in",
"the image for some operations. This extra channel usually",
"defines a mask which represents a sort of a cookie-cutter",
"for the image. This the case when matte is opaque (full",
"coverage) for pixels inside the shape, zero outside, and",
"between 0 and QuantumRange on the boundary. If image does not",
"have a matte channel, it is initialized with 0 for any pixel",
"matching in color to pixel location (0,0), otherwise QuantumRange.",
"",
"Note that matte information for image window is not retained",
"for colormapped X server visuals (e.g. StaticColor,",
"StaticColor, GrayScale, PseudoColor). Correct compositing",
"behavior may require a TrueColor or DirectColor visual or a",
"Standard Colormap.",
"",
"Choosing a composite operator is optional. The default",
"operator is replace. However, you must choose a location to",
"paste your image and press button 1. Press and hold the",
"button before releasing and an outline of the image will",
"appear to help you identify your location.",
"",
"The actual colors of the pasted image is saved. However,",
"the color that appears in image window may be different.",
"For example, on a monochrome screen image window will appear",
"black or white even though your pasted image may have",
"many colors. If the image is saved to a file it is written",
"with the correct colors. To assure the correct colors are",
"saved in the final image, any PseudoClass image is promoted",
"to DirectClass (see miff(5)). To force a PseudoClass image",
"to remain PseudoClass, use -colors.",
(char *) NULL,
},
*ImageROIHelp[] =
{
"In region of interest mode, the Command widget has these",
"options:",
"",
" Help",
" Dismiss",
"",
"To define a region of interest, press button 1 and drag.",
"The region of interest is defined by a highlighted rectangle",
"that expands or contracts as it follows the pointer. Once",
"you are satisfied with the region of interest, release the",
"button. You are now in apply mode. In apply mode the",
"Command widget has these options:",
"",
" File",
" Save...",
" Print...",
" Edit",
" Undo",
" Redo",
" Transform",
" Flop",
" Flip",
" Rotate Right",
" Rotate Left",
" Enhance",
" Hue...",
" Saturation...",
" Brightness...",
" Gamma...",
" Spiff",
" Dull",
" Contrast Stretch",
" Sigmoidal Contrast...",
" Normalize",
" Equalize",
" Negate",
" Grayscale",
" Map...",
" Quantize...",
" Effects",
" Despeckle",
" Emboss",
" Reduce Noise",
" Sharpen...",
" Blur...",
" Threshold...",
" Edge Detect...",
" Spread...",
" Shade...",
" Raise...",
" Segment...",
" F/X",
" Solarize...",
" Sepia Tone...",
" Swirl...",
" Implode...",
" Vignette...",
" Wave...",
" Oil Painting...",
" Charcoal Drawing...",
" Miscellany",
" Image Info",
" Zoom Image",
" Show Preview...",
" Show Histogram",
" Show Matte",
" Help",
" Dismiss",
"",
"You can make adjustments to the region of interest by moving",
"the pointer to one of the rectangle corners, pressing a",
"button, and dragging. Finally, choose an image processing",
"technique from the Command widget. You can choose more than",
"one image processing technique to apply to an area.",
"Alternatively, you can move the region of interest before",
"applying another image processing technique. To exit, press",
"Dismiss.",
(char *) NULL,
},
*ImageRotateHelp[] =
{
"In rotate mode, the Command widget has these options:",
"",
" Pixel Color",
" black",
" blue",
" cyan",
" green",
" gray",
" red",
" magenta",
" yellow",
" white",
" Browser...",
" Direction",
" horizontal",
" vertical",
" Help",
" Dismiss",
"",
"Choose a background color from the Pixel Color sub-menu.",
"Additional background colors can be specified with the color",
"browser. You can change the menu colors by setting the X",
"resources pen1 through pen9.",
"",
"If you choose the color browser and press Grab, you can",
"select the background color by moving the pointer to the",
"desired color on the screen and press any button.",
"",
"Choose a point in the image window and press this button and",
"hold. Next, move the pointer to another location in the",
"image. As you move a line connects the initial location and",
"the pointer. When you release the button, the degree of",
"image rotation is determined by the slope of the line you",
"just drew. The slope is relative to the direction you",
"choose from the Direction sub-menu of the Command widget.",
"",
"To cancel the image rotation, move the pointer back to the",
"starting point of the line and release the button.",
(char *) NULL,
};
/*
Enumeration declarations.
*/
typedef enum
{
CopyMode,
CropMode,
CutMode
} ClipboardMode;
typedef enum
{
OpenCommand,
NextCommand,
FormerCommand,
SelectCommand,
SaveCommand,
PrintCommand,
DeleteCommand,
NewCommand,
VisualDirectoryCommand,
QuitCommand,
UndoCommand,
RedoCommand,
CutCommand,
CopyCommand,
PasteCommand,
HalfSizeCommand,
OriginalSizeCommand,
DoubleSizeCommand,
ResizeCommand,
ApplyCommand,
RefreshCommand,
RestoreCommand,
CropCommand,
ChopCommand,
FlopCommand,
FlipCommand,
RotateRightCommand,
RotateLeftCommand,
RotateCommand,
ShearCommand,
RollCommand,
TrimCommand,
HueCommand,
SaturationCommand,
BrightnessCommand,
GammaCommand,
SpiffCommand,
DullCommand,
ContrastStretchCommand,
SigmoidalContrastCommand,
NormalizeCommand,
EqualizeCommand,
NegateCommand,
GrayscaleCommand,
MapCommand,
QuantizeCommand,
DespeckleCommand,
EmbossCommand,
ReduceNoiseCommand,
AddNoiseCommand,
SharpenCommand,
BlurCommand,
ThresholdCommand,
EdgeDetectCommand,
SpreadCommand,
ShadeCommand,
RaiseCommand,
SegmentCommand,
SolarizeCommand,
SepiaToneCommand,
SwirlCommand,
ImplodeCommand,
VignetteCommand,
WaveCommand,
OilPaintCommand,
CharcoalDrawCommand,
AnnotateCommand,
DrawCommand,
ColorCommand,
MatteCommand,
CompositeCommand,
AddBorderCommand,
AddFrameCommand,
CommentCommand,
LaunchCommand,
RegionofInterestCommand,
ROIHelpCommand,
ROIDismissCommand,
InfoCommand,
ZoomCommand,
ShowPreviewCommand,
ShowHistogramCommand,
ShowMatteCommand,
BackgroundCommand,
SlideShowCommand,
PreferencesCommand,
HelpCommand,
BrowseDocumentationCommand,
VersionCommand,
SaveToUndoBufferCommand,
FreeBuffersCommand,
NullCommand
} CommandType;
typedef enum
{
AnnotateNameCommand,
AnnotateFontColorCommand,
AnnotateBackgroundColorCommand,
AnnotateRotateCommand,
AnnotateHelpCommand,
AnnotateDismissCommand,
TextHelpCommand,
TextApplyCommand,
ChopDirectionCommand,
ChopHelpCommand,
ChopDismissCommand,
HorizontalChopCommand,
VerticalChopCommand,
ColorEditMethodCommand,
ColorEditColorCommand,
ColorEditBorderCommand,
ColorEditFuzzCommand,
ColorEditUndoCommand,
ColorEditHelpCommand,
ColorEditDismissCommand,
CompositeOperatorsCommand,
CompositeDissolveCommand,
CompositeDisplaceCommand,
CompositeHelpCommand,
CompositeDismissCommand,
CropHelpCommand,
CropDismissCommand,
RectifyCopyCommand,
RectifyHelpCommand,
RectifyDismissCommand,
DrawElementCommand,
DrawColorCommand,
DrawStippleCommand,
DrawWidthCommand,
DrawUndoCommand,
DrawHelpCommand,
DrawDismissCommand,
MatteEditMethod,
MatteEditBorderCommand,
MatteEditFuzzCommand,
MatteEditValueCommand,
MatteEditUndoCommand,
MatteEditHelpCommand,
MatteEditDismissCommand,
PasteOperatorsCommand,
PasteHelpCommand,
PasteDismissCommand,
RotateColorCommand,
RotateDirectionCommand,
RotateCropCommand,
RotateSharpenCommand,
RotateHelpCommand,
RotateDismissCommand,
HorizontalRotateCommand,
VerticalRotateCommand,
TileLoadCommand,
TileNextCommand,
TileFormerCommand,
TileDeleteCommand,
TileUpdateCommand
} ModeType;
/*
Stipples.
*/
#define BricksWidth 20
#define BricksHeight 20
#define DiagonalWidth 16
#define DiagonalHeight 16
#define HighlightWidth 8
#define HighlightHeight 8
#define OpaqueWidth 8
#define OpaqueHeight 8
#define ScalesWidth 16
#define ScalesHeight 16
#define ShadowWidth 8
#define ShadowHeight 8
#define VerticalWidth 16
#define VerticalHeight 16
#define WavyWidth 16
#define WavyHeight 16
/*
Constant declaration.
*/
static const int
RoiDelta = 8;
static const unsigned char
BricksBitmap[] =
{
0xff, 0xff, 0x0f, 0x03, 0x0c, 0x00, 0x03, 0x0c, 0x00, 0x03, 0x0c, 0x00,
0x03, 0x0c, 0x00, 0xff, 0xff, 0x0f, 0x60, 0x80, 0x01, 0x60, 0x80, 0x01,
0x60, 0x80, 0x01, 0x60, 0x80, 0x01, 0xff, 0xff, 0x0f, 0x03, 0x0c, 0x00,
0x03, 0x0c, 0x00, 0x03, 0x0c, 0x00, 0x03, 0x0c, 0x00, 0xff, 0xff, 0x0f,
0x60, 0x80, 0x01, 0x60, 0x80, 0x01, 0x60, 0x80, 0x01, 0x60, 0x80, 0x01
},
DiagonalBitmap[] =
{
0x44, 0x44, 0x88, 0x88, 0x11, 0x11, 0x22, 0x22, 0x44, 0x44, 0x88, 0x88,
0x11, 0x11, 0x22, 0x22, 0x44, 0x44, 0x88, 0x88, 0x11, 0x11, 0x22, 0x22,
0x44, 0x44, 0x88, 0x88, 0x11, 0x11, 0x22, 0x22
},
ScalesBitmap[] =
{
0x08, 0x08, 0x08, 0x08, 0x14, 0x14, 0xe3, 0xe3, 0x80, 0x80, 0x80, 0x80,
0x41, 0x41, 0x3e, 0x3e, 0x08, 0x08, 0x08, 0x08, 0x14, 0x14, 0xe3, 0xe3,
0x80, 0x80, 0x80, 0x80, 0x41, 0x41, 0x3e, 0x3e
},
VerticalBitmap[] =
{
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11,
0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11
},
WavyBitmap[] =
{
0xfe, 0xff, 0xfe, 0xff, 0xfe, 0xff, 0xfd, 0xff, 0xfd, 0xff, 0xfb, 0xff,
0xe7, 0xff, 0x1f, 0xff, 0xff, 0xf8, 0xff, 0xe7, 0xff, 0xdf, 0xff, 0xbf,
0xff, 0xbf, 0xff, 0x7f, 0xff, 0x7f, 0xff, 0x7f
};
/*
Function prototypes.
*/
static CommandType
XImageWindowCommand(Display *,XResourceInfo *,XWindows *,
const MagickStatusType,KeySym,Image **,ExceptionInfo *);
static Image
*XMagickCommand(Display *,XResourceInfo *,XWindows *,const CommandType,
Image **,ExceptionInfo *),
*XOpenImage(Display *,XResourceInfo *,XWindows *,const MagickBooleanType),
*XTileImage(Display *,XResourceInfo *,XWindows *,Image *,XEvent *,
ExceptionInfo *),
*XVisualDirectoryImage(Display *,XResourceInfo *,XWindows *,
ExceptionInfo *);
static MagickBooleanType
XAnnotateEditImage(Display *,XResourceInfo *,XWindows *,Image *,
ExceptionInfo *),
XBackgroundImage(Display *,XResourceInfo *,XWindows *,Image **,
ExceptionInfo *),
XChopImage(Display *,XResourceInfo *,XWindows *,Image **,
ExceptionInfo *),
XCropImage(Display *,XResourceInfo *,XWindows *,Image *,const ClipboardMode,
ExceptionInfo *),
XColorEditImage(Display *,XResourceInfo *,XWindows *,Image **,
ExceptionInfo *),
XCompositeImage(Display *,XResourceInfo *,XWindows *,Image *,
ExceptionInfo *),
XConfigureImage(Display *,XResourceInfo *,XWindows *,Image *,ExceptionInfo *),
XDrawEditImage(Display *,XResourceInfo *,XWindows *,Image **,
ExceptionInfo *),
XMatteEditImage(Display *,XResourceInfo *,XWindows *,Image **,
ExceptionInfo *),
XPasteImage(Display *,XResourceInfo *,XWindows *,Image *,ExceptionInfo *),
XPrintImage(Display *,XResourceInfo *,XWindows *,Image *,ExceptionInfo *),
XRotateImage(Display *,XResourceInfo *,XWindows *,double,Image **,
ExceptionInfo *),
XROIImage(Display *,XResourceInfo *,XWindows *,Image **,ExceptionInfo *),
XSaveImage(Display *,XResourceInfo *,XWindows *,Image *,ExceptionInfo *),
XTrimImage(Display *,XResourceInfo *,XWindows *,Image *,ExceptionInfo *);
static void
XDrawPanRectangle(Display *,XWindows *),
XImageCache(Display *,XResourceInfo *,XWindows *,const CommandType,Image **,
ExceptionInfo *),
XMagnifyImage(Display *,XWindows *,XEvent *,ExceptionInfo *),
XMakePanImage(Display *,XResourceInfo *,XWindows *,Image *,ExceptionInfo *),
XPanImage(Display *,XWindows *,XEvent *,ExceptionInfo *),
XMagnifyWindowCommand(Display *,XWindows *,const MagickStatusType,
const KeySym,ExceptionInfo *),
XSetCropGeometry(Display *,XWindows *,RectangleInfo *,Image *),
XScreenEvent(Display *,XWindows *,XEvent *,ExceptionInfo *),
XTranslateImage(Display *,XWindows *,Image *,const KeySym);
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% D i s p l a y I m a g e s %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% DisplayImages() displays an image sequence to any X window screen. It
% returns a value other than 0 if successful. Check the exception member
% of image to determine the reason for any failure.
%
% The format of the DisplayImages method is:
%
% MagickBooleanType DisplayImages(const ImageInfo *image_info,
% Image *images,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o image_info: the image info.
%
% o image: the image.
%
% o exception: return any errors or warnings in this structure.
%
*/
MagickExport MagickBooleanType DisplayImages(const ImageInfo *image_info,
Image *images,ExceptionInfo *exception)
{
char
*argv[1];
Display
*display;
Image
*image;
register ssize_t
i;
size_t
state;
XrmDatabase
resource_database;
XResourceInfo
resource_info;
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickCoreSignature);
assert(images != (Image *) NULL);
assert(images->signature == MagickCoreSignature);
if (images->debug != MagickFalse )
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",images->filename);
display=XOpenDisplay(image_info->server_name);
if (display == (Display *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),XServerError,
"UnableToOpenXServer","`%s'",XDisplayName(image_info->server_name));
return(MagickFalse);
}
if (exception->severity != UndefinedException)
CatchException(exception);
(void) XSetErrorHandler(XError);
resource_database=XGetResourceDatabase(display,GetClientName());
(void) memset(&resource_info,0,sizeof(resource_info));
XGetResourceInfo(image_info,resource_database,GetClientName(),&resource_info);
if (image_info->page != (char *) NULL)
resource_info.image_geometry=AcquireString(image_info->page);
resource_info.immutable=MagickTrue;
argv[0]=AcquireString(GetClientName());
state=DefaultState;
for (i=0; (state & ExitState) == 0; i++)
{
if ((images->iterations != 0) && (i >= (ssize_t) images->iterations))
break;
image=GetImageFromList(images,i % GetImageListLength(images));
(void) XDisplayImage(display,&resource_info,argv,1,&image,&state,exception);
}
(void) SetErrorHandler((ErrorHandler) NULL);
(void) SetWarningHandler((WarningHandler) NULL);
argv[0]=DestroyString(argv[0]);
(void) XCloseDisplay(display);
XDestroyResourceInfo(&resource_info);
if (exception->severity != UndefinedException)
return(MagickFalse);
return(MagickTrue);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% R e m o t e D i s p l a y C o m m a n d %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% RemoteDisplayCommand() encourages a remote display program to display the
% specified image filename.
%
% The format of the RemoteDisplayCommand method is:
%
% MagickBooleanType RemoteDisplayCommand(const ImageInfo *image_info,
% const char *window,const char *filename,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o image_info: the image info.
%
% o window: Specifies the name or id of an X window.
%
% o filename: the name of the image filename to display.
%
% o exception: return any errors or warnings in this structure.
%
*/
MagickExport MagickBooleanType RemoteDisplayCommand(const ImageInfo *image_info,
const char *window,const char *filename,ExceptionInfo *exception)
{
Display
*display;
MagickStatusType
status;
assert(image_info != (const ImageInfo *) NULL);
assert(image_info->signature == MagickCoreSignature);
assert(filename != (char *) NULL);
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
display=XOpenDisplay(image_info->server_name);
if (display == (Display *) NULL)
{
(void) ThrowMagickException(exception,GetMagickModule(),XServerError,
"UnableToOpenXServer","`%s'",XDisplayName(image_info->server_name));
return(MagickFalse);
}
(void) XSetErrorHandler(XError);
status=XRemoteCommand(display,window,filename);
(void) XCloseDisplay(display);
return(status != 0 ? MagickTrue : MagickFalse);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
+ X A n n o t a t e E d i t I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% XAnnotateEditImage() annotates the image with text.
%
% The format of the XAnnotateEditImage method is:
%
% MagickBooleanType XAnnotateEditImage(Display *display,
% XResourceInfo *resource_info,XWindows *windows,Image *image,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o display: Specifies a connection to an X server; returned from
% XOpenDisplay.
%
% o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
%
% o windows: Specifies a pointer to a XWindows structure.
%
% o image: the image; returned from ReadImage.
%
*/
static MagickBooleanType XAnnotateEditImage(Display *display,
XResourceInfo *resource_info,XWindows *windows,Image *image,
ExceptionInfo *exception)
{
static const char
*AnnotateMenu[] =
{
"Font Name",
"Font Color",
"Box Color",
"Rotate Text",
"Help",
"Dismiss",
(char *) NULL
},
*TextMenu[] =
{
"Help",
"Apply",
(char *) NULL
};
static const ModeType
AnnotateCommands[] =
{
AnnotateNameCommand,
AnnotateFontColorCommand,
AnnotateBackgroundColorCommand,
AnnotateRotateCommand,
AnnotateHelpCommand,
AnnotateDismissCommand
},
TextCommands[] =
{
TextHelpCommand,
TextApplyCommand
};
static MagickBooleanType
transparent_box = MagickTrue,
transparent_pen = MagickFalse;
static double
degrees = 0.0;
static unsigned int
box_id = MaxNumberPens-2,
font_id = 0,
pen_id = 0;
char
command[MagickPathExtent],
text[MagickPathExtent];
const char
*ColorMenu[MaxNumberPens+1];
Cursor
cursor;
GC
annotate_context;
int
id,
pen_number,
status,
x,
y;
KeySym
key_symbol;
register char
*p;
register ssize_t
i;
unsigned int
height,
width;
size_t
state;
XAnnotateInfo
*annotate_info,
*previous_info;
XColor
color;
XFontStruct
*font_info;
XEvent
event,
text_event;
/*
Map Command widget.
*/
(void) CloneString(&windows->command.name,"Annotate");
windows->command.data=4;
(void) XCommandWidget(display,windows,AnnotateMenu,(XEvent *) NULL);
(void) XMapRaised(display,windows->command.id);
XClientMessage(display,windows->image.id,windows->im_protocols,
windows->im_update_widget,CurrentTime);
/*
Track pointer until button 1 is pressed.
*/
XQueryPosition(display,windows->image.id,&x,&y);
(void) XSelectInput(display,windows->image.id,
windows->image.attributes.event_mask | PointerMotionMask);
cursor=XCreateFontCursor(display,XC_left_side);
(void) XCheckDefineCursor(display,windows->image.id,cursor);
state=DefaultState;
do
{
if (windows->info.mapped != MagickFalse )
{
/*
Display pointer position.
*/
(void) FormatLocaleString(text,MagickPathExtent," %+d%+d ",
x+windows->image.x,y+windows->image.y);
XInfoWidget(display,windows,text);
}
/*
Wait for next event.
*/
XScreenEvent(display,windows,&event,exception);
if (event.xany.window == windows->command.id)
{
/*
Select a command from the Command widget.
*/
id=XCommandWidget(display,windows,AnnotateMenu,&event);
(void) XCheckDefineCursor(display,windows->image.id,cursor);
if (id < 0)
continue;
switch (AnnotateCommands[id])
{
case AnnotateNameCommand:
{
const char
*FontMenu[MaxNumberFonts];
int
font_number;
/*
Initialize menu selections.
*/
for (i=0; i < MaxNumberFonts; i++)
FontMenu[i]=resource_info->font_name[i];
FontMenu[MaxNumberFonts-2]="Browser...";
FontMenu[MaxNumberFonts-1]=(const char *) NULL;
/*
Select a font name from the pop-up menu.
*/
font_number=XMenuWidget(display,windows,AnnotateMenu[id],
(const char **) FontMenu,command);
if (font_number < 0)
break;
if (font_number == (MaxNumberFonts-2))
{
static char
font_name[MagickPathExtent] = "fixed";
/*
Select a font name from a browser.
*/
resource_info->font_name[font_number]=font_name;
XFontBrowserWidget(display,windows,"Select",font_name);
if (*font_name == '\0')
break;
}
/*
Initialize font info.
*/
font_info=XLoadQueryFont(display,resource_info->font_name[
font_number]);
if (font_info == (XFontStruct *) NULL)
{
XNoticeWidget(display,windows,"Unable to load font:",
resource_info->font_name[font_number]);
break;
}
font_id=(unsigned int) font_number;
(void) XFreeFont(display,font_info);
break;
}
case AnnotateFontColorCommand:
{
/*
Initialize menu selections.
*/
for (i=0; i < (int) (MaxNumberPens-2); i++)
ColorMenu[i]=resource_info->pen_colors[i];
ColorMenu[MaxNumberPens-2]="transparent";
ColorMenu[MaxNumberPens-1]="Browser...";
ColorMenu[MaxNumberPens]=(const char *) NULL;
/*
Select a pen color from the pop-up menu.
*/
pen_number=XMenuWidget(display,windows,AnnotateMenu[id],
(const char **) ColorMenu,command);
if (pen_number < 0)
break;
transparent_pen=pen_number == (MaxNumberPens-2) ? MagickTrue :
MagickFalse;
if (transparent_pen != MagickFalse )
break;
if (pen_number == (MaxNumberPens-1))
{
static char
color_name[MagickPathExtent] = "gray";
/*
Select a pen color from a dialog.
*/
resource_info->pen_colors[pen_number]=color_name;
XColorBrowserWidget(display,windows,"Select",color_name);
if (*color_name == '\0')
break;
}
/*
Set pen color.
*/
(void) XParseColor(display,windows->map_info->colormap,
resource_info->pen_colors[pen_number],&color);
XBestPixel(display,windows->map_info->colormap,(XColor *) NULL,
(unsigned int) MaxColors,&color);
windows->pixel_info->pen_colors[pen_number]=color;
pen_id=(unsigned int) pen_number;
break;
}
case AnnotateBackgroundColorCommand:
{
/*
Initialize menu selections.
*/
for (i=0; i < (int) (MaxNumberPens-2); i++)
ColorMenu[i]=resource_info->pen_colors[i];
ColorMenu[MaxNumberPens-2]="transparent";
ColorMenu[MaxNumberPens-1]="Browser...";
ColorMenu[MaxNumberPens]=(const char *) NULL;
/*
Select a pen color from the pop-up menu.
*/
pen_number=XMenuWidget(display,windows,AnnotateMenu[id],
(const char **) ColorMenu,command);
if (pen_number < 0)
break;
transparent_box=pen_number == (MaxNumberPens-2) ? MagickTrue :
MagickFalse;
if (transparent_box != MagickFalse )
break;
if (pen_number == (MaxNumberPens-1))
{
static char
color_name[MagickPathExtent] = "gray";
/*
Select a pen color from a dialog.
*/
resource_info->pen_colors[pen_number]=color_name;
XColorBrowserWidget(display,windows,"Select",color_name);
if (*color_name == '\0')
break;
}
/*
Set pen color.
*/
(void) XParseColor(display,windows->map_info->colormap,
resource_info->pen_colors[pen_number],&color);
XBestPixel(display,windows->map_info->colormap,(XColor *) NULL,
(unsigned int) MaxColors,&color);
windows->pixel_info->pen_colors[pen_number]=color;
box_id=(unsigned int) pen_number;
break;
}
case AnnotateRotateCommand:
{
int
entry;
static char
angle[MagickPathExtent] = "30.0";
static const char
*RotateMenu[] =
{
"-90",
"-45",
"-30",
"0",
"30",
"45",
"90",
"180",
"Dialog...",
(char *) NULL,
};
/*
Select a command from the pop-up menu.
*/
entry=XMenuWidget(display,windows,AnnotateMenu[id],RotateMenu,
command);
if (entry < 0)
break;
if (entry != 8)
{
degrees=StringToDouble(RotateMenu[entry],(char **) NULL);
break;
}
(void) XDialogWidget(display,windows,"OK","Enter rotation angle:",
angle);
if (*angle == '\0')
break;
degrees=StringToDouble(angle,(char **) NULL);
break;
}
case AnnotateHelpCommand:
{
XTextViewWidget(display,resource_info,windows,MagickFalse,
"Help Viewer - Image Annotation",ImageAnnotateHelp);
break;
}
case AnnotateDismissCommand:
{
/*
Prematurely exit.
*/
state|=EscapeState;
state|=ExitState;
break;
}
default:
break;
}
continue;
}
switch (event.type)
{
case ButtonPress:
{
if (event.xbutton.button != Button1)
break;
if (event.xbutton.window != windows->image.id)
break;
/*
Change to text entering mode.
*/
x=event.xbutton.x;
y=event.xbutton.y;
state|=ExitState;
break;
}
case ButtonRelease:
break;
case Expose:
break;
case KeyPress:
{
if (event.xkey.window != windows->image.id)
break;
/*
Respond to a user key press.
*/
(void) XLookupString((XKeyEvent *) &event.xkey,command,(int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
switch ((int) key_symbol)
{
case XK_Escape:
case XK_F20:
{
/*
Prematurely exit.
*/
state|=EscapeState;
state|=ExitState;
break;
}
case XK_F1:
case XK_Help:
{
XTextViewWidget(display,resource_info,windows,MagickFalse,
"Help Viewer - Image Annotation",ImageAnnotateHelp);
break;
}
default:
{
(void) XBell(display,0);
break;
}
}
break;
}
case MotionNotify:
{
/*
Map and unmap Info widget as cursor crosses its boundaries.
*/
x=event.xmotion.x;
y=event.xmotion.y;
if (windows->info.mapped != MagickFalse )
{
if ((x < (int) (windows->info.x+windows->info.width)) &&
(y < (int) (windows->info.y+windows->info.height)))
(void) XWithdrawWindow(display,windows->info.id,
windows->info.screen);
}
else
if ((x > (int) (windows->info.x+windows->info.width)) ||
(y > (int) (windows->info.y+windows->info.height)))
(void) XMapWindow(display,windows->info.id);
break;
}
default:
break;
}
} while ((state & ExitState) == 0);
(void) XSelectInput(display,windows->image.id,
windows->image.attributes.event_mask);
(void) XWithdrawWindow(display,windows->info.id,windows->info.screen);
if ((state & EscapeState) != 0)
return(MagickTrue);
/*
Set font info and check boundary conditions.
*/
font_info=XLoadQueryFont(display,resource_info->font_name[font_id]);
if (font_info == (XFontStruct *) NULL)
{
XNoticeWidget(display,windows,"Unable to load font:",
resource_info->font_name[font_id]);
font_info=windows->font_info;
}
if ((x+font_info->max_bounds.width) >= (int) windows->image.width)
x=(int) windows->image.width-font_info->max_bounds.width;
if (y < (int) (font_info->ascent+font_info->descent))
y=(int) font_info->ascent+font_info->descent;
if (((int) font_info->max_bounds.width > (int) windows->image.width) ||
((font_info->ascent+font_info->descent) >= (int) windows->image.height))
return(MagickFalse);
/*
Initialize annotate structure.
*/
annotate_info=(XAnnotateInfo *) AcquireMagickMemory(sizeof(*annotate_info));
if (annotate_info == (XAnnotateInfo *) NULL)
return(MagickFalse);
XGetAnnotateInfo(annotate_info);
annotate_info->x=x;
annotate_info->y=y;
if ((transparent_box == MagickFalse) && (transparent_pen == MagickFalse))
annotate_info->stencil=OpaqueStencil;
else
if (transparent_box == MagickFalse)
annotate_info->stencil=BackgroundStencil;
else
annotate_info->stencil=ForegroundStencil;
annotate_info->height=(unsigned int) font_info->ascent+font_info->descent;
annotate_info->degrees=degrees;
annotate_info->font_info=font_info;
annotate_info->text=(char *) AcquireQuantumMemory((size_t)
windows->image.width/MagickMax((ssize_t) font_info->min_bounds.width,1)+2UL,
sizeof(*annotate_info->text));
if (annotate_info->text == (char *) NULL)
return(MagickFalse);
/*
Create cursor and set graphic context.
*/
cursor=XCreateFontCursor(display,XC_pencil);
(void) XCheckDefineCursor(display,windows->image.id,cursor);
annotate_context=windows->image.annotate_context;
(void) XSetFont(display,annotate_context,font_info->fid);
(void) XSetBackground(display,annotate_context,
windows->pixel_info->pen_colors[box_id].pixel);
(void) XSetForeground(display,annotate_context,
windows->pixel_info->pen_colors[pen_id].pixel);
/*
Begin annotating the image with text.
*/
(void) CloneString(&windows->command.name,"Text");
windows->command.data=0;
(void) XCommandWidget(display,windows,TextMenu,(XEvent *) NULL);
state=DefaultState;
(void) XDrawString(display,windows->image.id,annotate_context,x,y,"_",1);
text_event.xexpose.width=(int) font_info->max_bounds.width;
text_event.xexpose.height=font_info->max_bounds.ascent+
font_info->max_bounds.descent;
p=annotate_info->text;
do
{
/*
Display text cursor.
*/
*p='\0';
(void) XDrawString(display,windows->image.id,annotate_context,x,y,"_",1);
/*
Wait for next event.
*/
XScreenEvent(display,windows,&event,exception);
if (event.xany.window == windows->command.id)
{
/*
Select a command from the Command widget.
*/
(void) XSetBackground(display,annotate_context,
windows->pixel_info->background_color.pixel);
(void) XSetForeground(display,annotate_context,
windows->pixel_info->foreground_color.pixel);
id=XCommandWidget(display,windows,AnnotateMenu,&event);
(void) XSetBackground(display,annotate_context,
windows->pixel_info->pen_colors[box_id].pixel);
(void) XSetForeground(display,annotate_context,
windows->pixel_info->pen_colors[pen_id].pixel);
if (id < 0)
continue;
switch (TextCommands[id])
{
case TextHelpCommand:
{
XTextViewWidget(display,resource_info,windows,MagickFalse,
"Help Viewer - Image Annotation",ImageAnnotateHelp);
(void) XCheckDefineCursor(display,windows->image.id,cursor);
break;
}
case TextApplyCommand:
{
/*
Finished annotating.
*/
annotate_info->width=(unsigned int) XTextWidth(font_info,
annotate_info->text,(int) strlen(annotate_info->text));
XRefreshWindow(display,&windows->image,&text_event);
state|=ExitState;
break;
}
default:
break;
}
continue;
}
/*
Erase text cursor.
*/
text_event.xexpose.x=x;
text_event.xexpose.y=y-font_info->max_bounds.ascent;
(void) XClearArea(display,windows->image.id,x,text_event.xexpose.y,
(unsigned int) text_event.xexpose.width,(unsigned int)
text_event.xexpose.height,MagickFalse);
XRefreshWindow(display,&windows->image,&text_event);
switch (event.type)
{
case ButtonPress:
{
if (event.xbutton.window != windows->image.id)
break;
if (event.xbutton.button == Button2)
{
/*
Request primary selection.
*/
(void) XConvertSelection(display,XA_PRIMARY,XA_STRING,XA_STRING,
windows->image.id,CurrentTime);
break;
}
break;
}
case Expose:
{
if (event.xexpose.count == 0)
{
XAnnotateInfo
*text_info;
/*
Refresh Image window.
*/
XRefreshWindow(display,&windows->image,(XEvent *) NULL);
text_info=annotate_info;
while (text_info != (XAnnotateInfo *) NULL)
{
if (annotate_info->stencil == ForegroundStencil)
(void) XDrawString(display,windows->image.id,annotate_context,
text_info->x,text_info->y,text_info->text,
(int) strlen(text_info->text));
else
(void) XDrawImageString(display,windows->image.id,
annotate_context,text_info->x,text_info->y,text_info->text,
(int) strlen(text_info->text));
text_info=text_info->previous;
}
(void) XDrawString(display,windows->image.id,annotate_context,
x,y,"_",1);
}
break;
}
case KeyPress:
{
int
length;
if (event.xkey.window != windows->image.id)
break;
/*
Respond to a user key press.
*/
length=XLookupString((XKeyEvent *) &event.xkey,command,(int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
*(command+length)='\0';
if (((event.xkey.state & ControlMask) != 0) ||
((event.xkey.state & Mod1Mask) != 0))
state|=ModifierState;
if ((state & ModifierState) != 0)
switch ((int) key_symbol)
{
case XK_u:
case XK_U:
{
key_symbol=DeleteCommand;
break;
}
default:
break;
}
switch ((int) key_symbol)
{
case XK_BackSpace:
{
/*
Erase one character.
*/
if (p == annotate_info->text)
{
if (annotate_info->previous == (XAnnotateInfo *) NULL)
break;
else
{
/*
Go to end of the previous line of text.
*/
annotate_info=annotate_info->previous;
p=annotate_info->text;
x=annotate_info->x+annotate_info->width;
y=annotate_info->y;
if (annotate_info->width != 0)
p+=strlen(annotate_info->text);
break;
}
}
p--;
x-=XTextWidth(font_info,p,1);
text_event.xexpose.x=x;
text_event.xexpose.y=y-font_info->max_bounds.ascent;
XRefreshWindow(display,&windows->image,&text_event);
break;
}
case XK_bracketleft:
{
key_symbol=XK_Escape;
break;
}
case DeleteCommand:
{
/*
Erase the entire line of text.
*/
while (p != annotate_info->text)
{
p--;
x-=XTextWidth(font_info,p,1);
text_event.xexpose.x=x;
XRefreshWindow(display,&windows->image,&text_event);
}
break;
}
case XK_Escape:
case XK_F20:
{
/*
Finished annotating.
*/
annotate_info->width=(unsigned int) XTextWidth(font_info,
annotate_info->text,(int) strlen(annotate_info->text));
XRefreshWindow(display,&windows->image,&text_event);
state|=ExitState;
break;
}
default:
{
/*
Draw a single character on the Image window.
*/
if ((state & ModifierState) != 0)
break;
if (*command == '\0')
break;
*p=(*command);
if (annotate_info->stencil == ForegroundStencil)
(void) XDrawString(display,windows->image.id,annotate_context,
x,y,p,1);
else
(void) XDrawImageString(display,windows->image.id,
annotate_context,x,y,p,1);
x+=XTextWidth(font_info,p,1);
p++;
if ((x+font_info->max_bounds.width) < (int) windows->image.width)
break;
}
case XK_Return:
case XK_KP_Enter:
{
/*
Advance to the next line of text.
*/
*p='\0';
annotate_info->width=(unsigned int) XTextWidth(font_info,
annotate_info->text,(int) strlen(annotate_info->text));
if (annotate_info->next != (XAnnotateInfo *) NULL)
{
/*
Line of text already exists.
*/
annotate_info=annotate_info->next;
x=annotate_info->x;
y=annotate_info->y;
p=annotate_info->text;
break;
}
annotate_info->next=(XAnnotateInfo *) AcquireMagickMemory(
sizeof(*annotate_info->next));
if (annotate_info->next == (XAnnotateInfo *) NULL)
return(MagickFalse);
*annotate_info->next=(*annotate_info);
annotate_info->next->previous=annotate_info;
annotate_info=annotate_info->next;
annotate_info->text=(char *) AcquireQuantumMemory((size_t)
windows->image.width/MagickMax((ssize_t)
font_info->min_bounds.width,1)+2UL,sizeof(*annotate_info->text));
if (annotate_info->text == (char *) NULL)
return(MagickFalse);
annotate_info->y+=annotate_info->height;
if (annotate_info->y > (int) windows->image.height)
annotate_info->y=(int) annotate_info->height;
annotate_info->next=(XAnnotateInfo *) NULL;
x=annotate_info->x;
y=annotate_info->y;
p=annotate_info->text;
break;
}
}
break;
}
case KeyRelease:
{
/*
Respond to a user key release.
*/
(void) XLookupString((XKeyEvent *) &event.xkey,command,(int)
sizeof(command),&key_symbol,(XComposeStatus *) NULL);
state&=(~ModifierState);
break;
}
case SelectionNotify:
{
Atom
type;
int
format;
unsigned char
*data;
unsigned long
after,
length;
/*
Obtain response from primary selection.
*/
if (event.xselection.property == (Atom) None)
break;
status=XGetWindowProperty(display,event.xselection.requestor,
event.xselection.property,0L,(long) MagickPathExtent,True,XA_STRING,
&type,&format,&length,&after,&data);
if ((status != Success) || (type != XA_STRING) || (format == 32) ||
(length == 0))
break;
/*
Annotate Image window with primary selection.
*/
for (i=0; i < (ssize_t) length; i++)
{
if ((char) data[i] != '\n')
{
/*
Draw a single character on the Image window.
*/
*p=(char) data[i];
(void) XDrawString(display,windows->image.id,annotate_context,
x,y,p,1);
x+=XTextWidth(font_info,p,1);
p++;
if ((x+font_info->max_bounds.width) < (int) windows->image.width)
continue;
}
/*
Advance to the next line of text.
*/
*p='\0';
annotate_info->width=(unsigned int) XTextWidth(font_info,
annotate_info->text,(int) strlen(annotate_info->text));
if (annotate_info->next != (XAnnotateInfo *) NULL)
{
/*
Line of text already exists.
*/
annotate_info=annotate_info->next;
x=annotate_info->x;
y=annotate_info->y;
p=annotate_info->text;
continue;
}
annotate_info->next=(XAnnotateInfo *) AcquireMagickMemory(
sizeof(*annotate_info->next));
if (annotate_info->next == (XAnnotateInfo *) NULL)
return(MagickFalse);
*annotate_info->next=(*annotate_info);
annotate_info->next->previous=annotate_info;
annotate_info=annotate_info->next;
annotate_info->text=(char *) AcquireQuantumMemory((size_t)
windows->image.width/MagickMax((ssize_t)
font_info->min_bounds.width,1)+2UL,sizeof(*annotate_info->text));
if (annotate_info->text == (char *) NULL)
return(MagickFalse);
annotate_info->y+=annotate_info->height;
if (annotate_info->y > (int) windows->image.height)
annotate_info->y=(int) annotate_info->height;
annotate_info->next=(XAnnotateInfo *) NULL;
x=annotate_info->x;
y=annotate_info->y;
p=annotate_info->text;
}
(void) XFree((void *) data);
break;
}
default:
break;
}
} while ((state & ExitState) == 0);
(void) XFreeCursor(display,cursor);
/*
Annotation is relative to image configuration.
*/
width=(unsigned int) image->columns;
height=(unsigned int) image->rows;
x=0;
y=0;
if (windows->image.crop_geometry != (char *) NULL)
(void) XParseGeometry(windows->image.crop_geometry,&x,&y,&width,&height);
/*
Initialize annotated image.
*/
XSetCursorState(display,windows,MagickTrue);
XCheckRefreshWindows(display,windows);
while (annotate_info != (XAnnotateInfo *) NULL)
{
if (annotate_info->width == 0)
{
/*
No text on this line-- go to the next line of text.
*/
previous_info=annotate_info->previous;
annotate_info->text=(char *)
RelinquishMagickMemory(annotate_info->text);
annotate_info=(XAnnotateInfo *) RelinquishMagickMemory(annotate_info);
annotate_info=previous_info;
continue;
}
/*
Determine pixel index for box and pen color.
*/
windows->pixel_info->box_color=windows->pixel_info->pen_colors[box_id];
if (windows->pixel_info->colors != 0)
for (i=0; i < (ssize_t) windows->pixel_info->colors; i++)
if (windows->pixel_info->pixels[i] ==
windows->pixel_info->pen_colors[box_id].pixel)
{
windows->pixel_info->box_index=(unsigned short) i;
break;
}
windows->pixel_info->pen_color=windows->pixel_info->pen_colors[pen_id];
if (windows->pixel_info->colors != 0)
for (i=0; i < (ssize_t) windows->pixel_info->colors; i++)
if (windows->pixel_info->pixels[i] ==
windows->pixel_info->pen_colors[pen_id].pixel)
{
windows->pixel_info->pen_index=(unsigned short) i;
break;
}
/*
Define the annotate geometry string.
*/
annotate_info->x=(int)
width*(annotate_info->x+windows->image.x)/windows->image.ximage->width;
annotate_info->y=(int) height*(annotate_info->y-font_info->ascent+
windows->image.y)/windows->image.ximage->height;
(void) FormatLocaleString(annotate_info->geometry,MagickPathExtent,
"%ux%u%+d%+d",width*annotate_info->width/windows->image.ximage->width,
height*annotate_info->height/windows->image.ximage->height,
annotate_info->x+x,annotate_info->y+y);
/*
Annotate image with text.
*/
status=XAnnotateImage(display,windows->pixel_info,annotate_info,image,
exception);
if (status == 0)
return(MagickFalse);
/*
Free up memory.
*/
previous_info=annotate_info->previous;
annotate_info->text=DestroyString(annotate_info->text);
annotate_info=(XAnnotateInfo *) RelinquishMagickMemory(annotate_info);
annotate_info=previous_info;
}
(void) XSetForeground(display,annotate_context,
windows->pixel_info->foreground_color.pixel);
(void) XSetBackground(display,annotate_context,
windows->pixel_info->background_color.pixel);
(void) XSetFont(display,annotate_context,windows->font_info->fid);
XSetCursorState(display,windows,MagickFalse);
(void) XFreeFont(display,font_info);
/*
Update image configuration.
*/
XConfigureImageColormap(display,resource_info,windows,image,exception);
(void) XConfigureImage(display,resource_info,windows,image,exception);
return(MagickTrue);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
+ X B a c k g r o u n d I m a g e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% XBackgroundImage() displays the image in the background of a window.
%
% The format of the XBackgroundImage method is:
%
% MagickBooleanType XBackgroundImage(Display *display,
% XResourceInfo *resource_info,XWindows *windows,Image **image,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o display: Specifies a connection to an X server; returned from
% XOpenDisplay.
%
% o resource_info: Specifies a pointer to a X11 XResourceInfo structure.
%
% o windows: Specifies a pointer to a XWindows structure.
%
% o image: the image.
%
% o exception: return any errors or warnings in this structure.
%
*/
static MagickBooleanType XBackgroundImage(Display *display,
XResourceInfo *resource_info,XWindows *windows,Image **image,
ExceptionInfo *exception)
{
#define BackgroundImageTag "Background/Image"
int
status;
static char
window_id[MagickPathExtent] = "root";
XResourceInfo