]> granicus.if.org Git - imagemagick/blob - wand/import.c
(no commit message)
[imagemagick] / wand / import.c
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %                                                                             %
4 %                                                                             %
5 %                                                                             %
6 %                 IIIII  M   M  PPPP    OOO   RRRR   TTTTT                    %
7 %                   I    MM MM  P   P  O   O  R   R    T                      %
8 %                   I    M M M  PPPP   O   O  RRRR     T                      %
9 %                   I    M   M  P      O   O  R R      T                      %
10 %                 IIIII  M   M  P       OOO   R  R     T                      %
11 %                                                                             %
12 %                                                                             %
13 %                       Import Image from X11 Screen                          %
14 %                                                                             %
15 %                           Software Design                                   %
16 %                             John Cristy                                     %
17 %                              July 1992                                      %
18 %                                                                             %
19 %                                                                             %
20 %  Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization      %
21 %  dedicated to making software imaging solutions freely available.           %
22 %                                                                             %
23 %  You may not use this file except in compliance with the License.  You may  %
24 %  obtain a copy of the License at                                            %
25 %                                                                             %
26 %    http://www.imagemagick.org/script/license.php                            %
27 %                                                                             %
28 %  Unless required by applicable law or agreed to in writing, software        %
29 %  distributed under the License is distributed on an "AS IS" BASIS,          %
30 %  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
31 %  See the License for the specific language governing permissions and        %
32 %  limitations under the License.                                             %
33 %                                                                             %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35 %
36 %  Use the import program to capture some or all of an X server screen and
37 %  save the image to a file.
38 %
39 */
40 \f
41 /*
42   Include declarations.
43 */
44 #include "wand/studio.h"
45 #include "wand/MagickWand.h"
46 #include "wand/mogrify-private.h"
47 #include "magick/xwindow-private.h"
48 #include "magick/string-private.h"
49 \f
50 /*
51 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52 %                                                                             %
53 %                                                                             %
54 %                                                                             %
55 +   I m p o r t I m a g e C o m m a n d                                       %
56 %                                                                             %
57 %                                                                             %
58 %                                                                             %
59 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60 %
61 %  ImportImageCommand() reads an image from any visible window on an X server
62 %  and outputs it as an image file. You can capture a single window, the
63 %  entire screen, or any rectangular portion of the screen.  You can use the
64 %  display utility for redisplay, printing, editing, formatting, archiving,
65 %  image processing, etc. of the captured image.</dd>
66 %
67 %  The target window can be specified by id, name, or may be selected by
68 %  clicking the mouse in the desired window. If you press a button and then
69 %  drag, a rectangle will form which expands and contracts as the mouse moves.
70 %  To save the portion of the screen defined by the rectangle, just release
71 %  the button. The keyboard bell is rung once at the beginning of the screen
72 %  capture and twice when it completes.
73 %
74 %  The format of the ImportImageCommand method is:
75 %
76 %      MagickBooleanType ImportImageCommand(ImageInfo *image_info,int argc,
77 %        char **argv,char **metadata,ExceptionInfo *exception)
78 %
79 %  A description of each parameter follows:
80 %
81 %    o image_info: the image info.
82 %
83 %    o argc: the number of elements in the argument vector.
84 %
85 %    o argv: A text array containing the command line arguments.
86 %
87 %    o metadata: any metadata is returned here.
88 %
89 %    o exception: return any errors or warnings in this structure.
90 %
91 */
92
93 static MagickBooleanType ImportUsage(void)
94 {
95   const char
96     **p;
97
98   static const char
99     *miscellaneous[]=
100     {
101       "-debug events        display copious debugging information",
102       "-help                print program options",
103       "-list type           print a list of supported option arguments",
104       "-log format          format of debugging information",
105       "-version             print version information",
106       (char *) NULL
107     },
108     *operators[]=
109     {
110       "-annotate geometry text",
111       "                     annotate the image with text",
112       "-colors value        preferred number of colors in the image",
113       "-crop geometry       preferred size and location of the cropped image",
114       "-encipher filename   convert plain pixels to cipher pixels",
115       "-geometry geometry   preferred size or location of the image",
116       "-help                print program options",
117       "-monochrome          transform image to black and white",
118       "-negate              replace every pixel with its complementary color ",
119       "-repage geometry     size and location of an image canvas",
120       "-quantize colorspace reduce colors in this colorspace",
121       "-resize geometry     resize the image",
122       "-rotate degrees      apply Paeth rotation to the image",
123       "-strip               strip image of all profiles and comments",
124       "-thumbnail geometry  create a thumbnail of the image",
125       "-transparent color   make this color transparent within the image",
126       "-trim                trim image edges",
127       "-type type           image type",
128       (char *) NULL
129     },
130     *settings[]=
131     {
132       "-adjoin              join images into a single multi-image file",
133       "-border              include window border in the output image",
134       "-channel type        apply option to select image channels",
135       "-colorspace type     alternate image colorspace",
136       "-comment string      annotate image with comment",
137       "-compress type       type of pixel compression when writing the image",
138       "-define format:option",
139       "                     define one or more image format options",
140       "-density geometry    horizontal and vertical density of the image",
141       "-depth value         image depth",
142       "-descend             obtain image by descending window hierarchy",
143       "-display server      X server to contact",
144       "-dispose method      layer disposal method",
145       "-dither method       apply error diffusion to image",
146       "-delay value         display the next image after pausing",
147       "-encipher filename   convert plain pixels to cipher pixels",
148       "-endian type         endianness (MSB or LSB) of the image",
149       "-encoding type       text encoding type",
150       "-filter type         use this filter when resizing an image",
151       "-format \"string\"     output formatted image characteristics",
152       "-frame               include window manager frame",
153       "-gravity direction   which direction to gravitate towards",
154       "-identify            identify the format and characteristics of the image",
155       "-interlace type      None, Line, Plane, or Partition",
156       "-interpolate method  pixel color interpolation method",
157       "-label string        assign a label to an image",
158       "-limit type value    Area, Disk, Map, or Memory resource limit",
159       "-monitor             monitor progress",
160       "-page geometry       size and location of an image canvas",
161       "-pause value         seconds delay between snapshots",
162       "-pointsize value     font point size",
163       "-quality value       JPEG/MIFF/PNG compression level",
164       "-quiet               suppress all warning messages",
165       "-regard-warnings     pay attention to warning messages",
166       "-respect-parentheses settings remain in effect until parenthesis boundary",
167       "-sampling-factor geometry",
168       "                     horizontal and vertical sampling factor",
169       "-scene value         image scene number",
170       "-screen              select image from root window",
171       "-seed value          seed a new sequence of pseudo-random numbers",
172       "-set property value  set an image property",
173       "-silent              operate silently, i.e. don't ring any bells ",
174       "-snaps value         number of screen snapshots",
175       "-synchronize         synchronize image to storage device",
176       "-taint               declare the image as modified",
177       "-transparent-color color",
178       "                     transparent color",
179       "-treedepth value     color tree depth",
180       "-verbose             print detailed information about the image",
181       "-virtual-pixel method",
182       "                     Constant, Edge, Mirror, or Tile",
183       "-window id           select window with this id or name",
184       (char *) NULL
185     };
186
187   (void) printf("Version: %s\n",GetMagickVersion((size_t *) NULL));
188   (void) printf("Copyright: %s\n",GetMagickCopyright());
189   (void) printf("Features: %s\n\n",GetMagickFeatures());
190   (void) printf("Usage: %s [options ...] [ file ]\n",
191     GetClientName());
192   (void) printf("\nImage Settings:\n");
193   for (p=settings; *p != (char *) NULL; p++)
194     (void) printf("  %s\n",*p);
195   (void) printf("\nImage Operators:\n");
196   for (p=operators; *p != (char *) NULL; p++)
197     (void) printf("  %s\n",*p);
198   (void) printf("\nMiscellaneous Options:\n");
199   for (p=miscellaneous; *p != (char *) NULL; p++)
200     (void) printf("  %s\n",*p);
201   (void) printf(
202   "\nBy default, 'file' is written in the MIFF image format.  To\n");
203   (void) printf(
204     "specify a particular image format, precede the filename with an image\n");
205   (void) printf(
206     "format name and a colon (i.e. ps:image) or specify the image type as\n");
207   (void) printf(
208     "the filename suffix (i.e. image.ps).  Specify 'file' as '-' for\n");
209   (void) printf("standard input or output.\n");
210   return(MagickFalse);
211 }
212
213 static inline ssize_t MagickMax(const ssize_t x,const ssize_t y)
214 {
215   if (x > y)
216     return(x);
217   return(y);
218 }
219
220 WandExport MagickBooleanType ImportImageCommand(ImageInfo *image_info,
221   int argc,char **argv,char **wand_unused(metadata),ExceptionInfo *exception)
222 {
223 #if defined(MAGICKCORE_X11_DELEGATE)
224 #define DestroyImport() \
225 { \
226   XDestroyResourceInfo(&resource_info); \
227   if (display != (Display *) NULL) \
228     { \
229       XCloseDisplay(display); \
230       display=(Display *) NULL; \
231     } \
232   DestroyImageStack(); \
233   if (target_window != (char *) NULL) \
234     target_window=DestroyString(target_window); \
235   for (i=0; i < (ssize_t) argc; i++) \
236     argv[i]=DestroyString(argv[i]); \
237   argv=(char **) RelinquishMagickMemory(argv); \
238 }
239 #define ThrowImportException(asperity,tag,option) \
240 { \
241   (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
242      option); \
243   DestroyImport(); \
244   return(MagickFalse); \
245 }
246 #define ThrowImportInvalidArgumentException(option,argument) \
247 { \
248   (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
249     "InvalidArgument","`%s': %s",option,argument); \
250   DestroyImport(); \
251   return(MagickFalse); \
252 }
253
254   char
255     *filename,
256     *option,
257     *resource_value,
258     *server_name,
259     *target_window;
260
261   Display
262     *display;
263
264   Image
265     *image;
266
267   ImageStack
268     image_stack[MaxImageStackDepth+1];
269
270   ssize_t
271     j,
272     k,
273     snapshots;
274
275   MagickBooleanType
276     fire,
277     pend,
278     respect_parenthesis;
279
280   MagickStatusType
281     status;
282
283   QuantizeInfo
284     *quantize_info;
285
286   register ssize_t
287     i;
288
289   XImportInfo
290     ximage_info;
291
292   XResourceInfo
293     resource_info;
294
295   XrmDatabase
296     resource_database;
297
298   /*
299     Set defaults.
300   */
301   assert(image_info != (ImageInfo *) NULL);
302   assert(image_info->signature == MagickSignature);
303   if (image_info->debug != MagickFalse)
304     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
305   assert(exception != (ExceptionInfo *) NULL);
306   if (argc == 2)
307     {
308       option=argv[1];
309       if ((LocaleCompare("version",option+1) == 0) ||
310           (LocaleCompare("-version",option+1) == 0))
311         {
312           (void) fprintf(stdout,"Version: %s\n",
313             GetMagickVersion((size_t *) NULL));
314           (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
315           (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
316           return(MagickFalse);
317         }
318     }
319   display=(Display *) NULL;
320   j=1;
321   k=0;
322   NewImageStack();
323   option=(char *) NULL;
324   pend=MagickFalse;
325   resource_database=(XrmDatabase) NULL;
326   respect_parenthesis=MagickFalse;
327   (void) ResetMagickMemory(&resource_info,0,sizeof(resource_info));
328   server_name=(char *) NULL;
329   status=MagickTrue;
330   SetNotifyHandlers;
331   target_window=(char *) NULL;
332   /*
333     Check for server name specified on the command line.
334   */
335   ReadCommandlLine(argc,&argv);
336   status=ExpandFilenames(&argc,&argv);
337   if (status == MagickFalse)
338     ThrowImportException(ResourceLimitError,"MemoryAllocationFailed",
339       GetExceptionMessage(errno));
340   for (i=1; i < (ssize_t) argc; i++)
341   {
342     /*
343       Check command line for server name.
344     */
345     option=argv[i];
346     if (LocaleCompare("display",option+1) == 0)
347       {
348         /*
349           User specified server name.
350         */
351         i++;
352         if (i == (ssize_t) argc)
353           ThrowImportException(OptionError,"MissingArgument",option);
354         server_name=argv[i];
355       }
356     if ((LocaleCompare("help",option+1) == 0) ||
357         (LocaleCompare("-help",option+1) == 0))
358       return(ImportUsage());
359   }
360   /*
361     Get user defaults from X resource database.
362   */
363   display=XOpenDisplay(server_name);
364   if (display == (Display *) NULL)
365     ThrowImportException(XServerError,"UnableToOpenXServer",
366       XDisplayName(server_name));
367   (void) XSetErrorHandler(XError);
368   resource_database=XGetResourceDatabase(display,GetClientName());
369   XGetImportInfo(&ximage_info);
370   XGetResourceInfo(image_info,resource_database,GetClientName(),
371     &resource_info);
372   quantize_info=resource_info.quantize_info;
373   resource_value=XGetResourceInstance(resource_database,GetClientName(),
374     "border","False");
375   ximage_info.borders=IsMagickTrue(resource_value);
376   resource_value=XGetResourceInstance(resource_database,GetClientName(),
377     "delay","0");
378   resource_info.delay=(unsigned int) StringToUnsignedLong(resource_value);
379   image_info->density=XGetResourceInstance(resource_database,GetClientName(),
380     "density",(char *) NULL);
381   resource_value=XGetResourceInstance(resource_database,GetClientName(),
382     "descend","True");
383   ximage_info.descend=IsMagickTrue(resource_value);
384   resource_value=XGetResourceInstance(resource_database,GetClientName(),
385     "frame","False");
386   ximage_info.frame=IsMagickTrue(resource_value);
387   resource_value=XGetResourceInstance(resource_database,GetClientName(),
388     "interlace","none");
389   image_info->interlace=UndefinedInterlace;
390   if (LocaleCompare("None",resource_value) == 0)
391     image_info->interlace=NoInterlace;
392   if (LocaleCompare("Line",resource_value) == 0)
393     image_info->interlace=LineInterlace;
394   if (LocaleCompare("Plane",resource_value) == 0)
395     image_info->interlace=PlaneInterlace;
396   if (LocaleCompare("Partition",resource_value) == 0)
397     image_info->interlace=PartitionInterlace;
398   if (image_info->interlace == UndefinedInterlace)
399     ThrowImportException(OptionError,"Unrecognized interlace type",
400       resource_value);
401   image_info->page=XGetResourceInstance(resource_database,GetClientName(),
402     "pageGeometry",(char *) NULL);
403   resource_value=XGetResourceInstance(resource_database,GetClientName(),
404     "pause","0");
405   resource_info.pause=(unsigned int) StringToUnsignedLong(resource_value);
406   resource_value=XGetResourceInstance(resource_database,GetClientName(),
407     "quality","85");
408   image_info->quality=StringToUnsignedLong(resource_value);
409   resource_value=XGetResourceInstance(resource_database,GetClientName(),
410     "screen","False");
411   ximage_info.screen=IsMagickTrue(resource_value);
412   resource_value=XGetResourceInstance(resource_database,GetClientName(),
413     "silent","False");
414   ximage_info.silent=IsMagickTrue(resource_value);
415   resource_value=XGetResourceInstance(resource_database,GetClientName(),
416     "verbose","False");
417   image_info->verbose=IsMagickTrue(resource_value);
418   resource_value=XGetResourceInstance(resource_database,GetClientName(),
419     "dither","True");
420   quantize_info->dither=IsMagickTrue(resource_value);
421   snapshots=1;
422   status=MagickTrue;
423   filename=(char *) NULL;
424   /*
425     Check command syntax.
426   */
427   for (i=1; i < (ssize_t) argc; i++)
428   {
429     option=argv[i];
430     if (LocaleCompare(option,"(") == 0)
431       {
432         FireImageStack(MagickFalse,MagickTrue,pend);
433         if (k == MaxImageStackDepth)
434           ThrowImportException(OptionError,"ParenthesisNestedTooDeeply",
435             option);
436         PushImageStack();
437         continue;
438       }
439     if (LocaleCompare(option,")") == 0)
440       {
441         FireImageStack(MagickFalse,MagickTrue,MagickTrue);
442         if (k == 0)
443           ThrowImportException(OptionError,"UnableToParseExpression",option);
444         PopImageStack();
445         continue;
446       }
447     if (IsMagickOption(option) == MagickFalse)
448       {
449         Image
450           *images;
451
452         size_t
453           scene;
454
455         /*
456           Read image from X server.
457         */
458         FireImageStack(MagickFalse,MagickFalse,pend);
459         filename=argv[i];
460         if (target_window != (char *) NULL)
461           (void) CopyMagickString(image_info->filename,target_window,
462             MaxTextExtent);
463         for (scene=0; scene < (size_t) MagickMax(snapshots,1); scene++)
464         {
465           (void) sleep(resource_info.pause);
466           images=XImportImage(image_info,&ximage_info);
467           status&=(images != (Image *) NULL) &&
468             (exception->severity < ErrorException);
469           if (images == (Image *) NULL)
470             continue;
471           (void) CopyMagickString(images->filename,filename,MaxTextExtent);
472           (void) CopyMagickString(images->magick,"PS",MaxTextExtent);
473           images->scene=scene;
474           AppendImageStack(images);
475         }
476         continue;
477       }
478     pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
479     switch(*(option+1))
480     {
481       case 'a':
482       {
483         if (LocaleCompare("adjoin",option+1) == 0)
484           break;
485         if (LocaleCompare("annotate",option+1) == 0)
486           {
487             if (*option == '+')
488               break;
489             i++;
490             if (i == (ssize_t) (argc-1))
491               ThrowImportException(OptionError,"MissingArgument",option);
492             if (IsGeometry(argv[i]) == MagickFalse)
493               ThrowImportInvalidArgumentException(option,argv[i]);
494             if (i == (ssize_t) (argc-1))
495               ThrowImportException(OptionError,"MissingArgument",option);
496             i++;
497             break;
498           }
499         ThrowImportException(OptionError,"UnrecognizedOption",option);
500       }
501       case 'b':
502       {
503         if (LocaleCompare("border",option+1) == 0)
504           {
505             (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
506             ximage_info.borders=(*option == '-') ? MagickTrue : MagickFalse;
507             break;
508           }
509         if (LocaleCompare("bordercolor",option+1) == 0)
510           {
511             if (*option == '+')
512               break;
513             i++;
514             if (i == (ssize_t) argc)
515               ThrowImportException(OptionError,"MissingArgument",option);
516             break;
517           }
518         ThrowImportException(OptionError,"UnrecognizedOption",option);
519       }
520       case 'c':
521       {
522         if (LocaleCompare("cache",option+1) == 0)
523           {
524             if (*option == '+')
525               break;
526             i++;
527             if (i == (ssize_t) argc)
528               ThrowImportException(OptionError,"MissingArgument",option);
529             if (IsGeometry(argv[i]) == MagickFalse)
530               ThrowImportInvalidArgumentException(option,argv[i]);
531             break;
532           }
533         if (LocaleCompare("channel",option+1) == 0)
534           {
535             ssize_t
536               channel;
537
538             if (*option == '+')
539               break;
540             i++;
541             if (i == (ssize_t) (argc-1))
542               ThrowImportException(OptionError,"MissingArgument",option);
543             channel=ParseChannelOption(argv[i]);
544             if (channel < 0)
545               ThrowImportException(OptionError,"UnrecognizedChannelType",
546                 argv[i]);
547             break;
548           }
549         if (LocaleCompare("colors",option+1) == 0)
550           {
551             quantize_info->number_colors=0;
552             if (*option == '+')
553               break;
554             i++;
555             if (i == (ssize_t) argc)
556               ThrowImportException(OptionError,"MissingArgument",option);
557             if (IsGeometry(argv[i]) == MagickFalse)
558               ThrowImportInvalidArgumentException(option,argv[i]);
559             quantize_info->number_colors=StringToUnsignedLong(argv[i]);
560             break;
561           }
562         if (LocaleCompare("colorspace",option+1) == 0)
563           {
564             ssize_t
565               colorspace;
566
567             if (*option == '+')
568               break;
569             i++;
570             if (i == (ssize_t) argc)
571               ThrowImportException(OptionError,"MissingArgument",option);
572             colorspace=ParseMagickOption(MagickColorspaceOptions,MagickFalse,
573               argv[i]);
574             if (colorspace < 0)
575               ThrowImportException(OptionError,"UnrecognizedColorspace",
576                 argv[i]);
577             break;
578           }
579         if (LocaleCompare("comment",option+1) == 0)
580           {
581             if (*option == '+')
582               break;
583             i++;
584             if (i == (ssize_t) argc)
585               ThrowImportException(OptionError,"MissingArgument",option);
586             status=SetImageOption(image_info,"comment",argv[i]);
587             if (status == MagickFalse)
588               ThrowImportException(OptionError,"UnrecognizedOption",argv[i]);
589             break;
590           }
591         if (LocaleCompare("compress",option+1) == 0)
592           {
593             ssize_t
594               compress;
595
596             if (*option == '+')
597               break;
598             i++;
599             if (i == (ssize_t) argc)
600               ThrowImportException(OptionError,"MissingArgument",option);
601             compress=ParseMagickOption(MagickCompressOptions,MagickFalse,
602               argv[i]);
603             if (compress < 0)
604               ThrowImportException(OptionError,"UnrecognizedImageCompression",
605                 argv[i]);
606             break;
607           }
608         if (LocaleCompare("concurrent",option+1) == 0)
609           break;
610         if (LocaleCompare("crop",option+1) == 0)
611           {
612             if (*option == '+')
613               break;
614             i++;
615             if (i == (ssize_t) argc)
616               ThrowImportException(OptionError,"MissingArgument",option);
617             if (IsGeometry(argv[i]) == MagickFalse)
618               ThrowImportInvalidArgumentException(option,argv[i]);
619             break;
620           }
621         ThrowImportException(OptionError,"UnrecognizedOption",option);
622       }
623       case 'd':
624       {
625         if (LocaleCompare("debug",option+1) == 0)
626           {
627             ssize_t
628               event;
629
630             if (*option == '+')
631               break;
632             i++;
633             if (i == (ssize_t) argc)
634               ThrowImportException(OptionError,"MissingArgument",option);
635             event=ParseMagickOption(MagickLogEventOptions,MagickFalse,argv[i]);
636             if (event < 0)
637               ThrowImportException(OptionError,"UnrecognizedEventType",argv[i]);
638             (void) SetLogEventMask(argv[i]);
639             break;
640           }
641         if (LocaleCompare("define",option+1) == 0)
642           {
643             i++;
644             if (i == (ssize_t) argc)
645               ThrowImportException(OptionError,"MissingArgument",option);
646             if (*option == '+')
647               {
648                 const char
649                   *define;
650
651                 define=GetImageOption(image_info,argv[i]);
652                 if (define == (char *) NULL)
653                   ThrowImportException(OptionError,"NoSuchOption",argv[i]);
654                 break;
655               }
656             break;
657           }
658         if (LocaleCompare("delay",option+1) == 0)
659           {
660             if (*option == '+')
661               break;
662             i++;
663             if (i == (ssize_t) argc)
664               ThrowImportException(OptionError,"MissingArgument",option);
665             if (IsGeometry(argv[i]) == MagickFalse)
666               ThrowImportInvalidArgumentException(option,argv[i]);
667             status=SetImageOption(image_info,"delay",argv[i]);
668             if (status == MagickFalse)
669               ThrowImportException(OptionError,"UnrecognizedOption",argv[i]);
670             break;
671           }
672         if (LocaleCompare("density",option+1) == 0)
673           {
674             if (*option == '+')
675               break;
676             i++;
677             if (i == (ssize_t) argc)
678               ThrowImportException(OptionError,"MissingArgument",option);
679             if (IsGeometry(argv[i]) == MagickFalse)
680               ThrowImportInvalidArgumentException(option,argv[i]);
681             break;
682           }
683         if (LocaleCompare("depth",option+1) == 0)
684           {
685             if (*option == '+')
686               break;
687             i++;
688             if (i == (ssize_t) argc)
689               ThrowImportException(OptionError,"MissingArgument",option);
690             if (IsGeometry(argv[i]) == MagickFalse)
691               ThrowImportInvalidArgumentException(option,argv[i]);
692             break;
693           }
694         if (LocaleCompare("descend",option+1) == 0)
695           {
696             ximage_info.descend=(*option == '-') ? MagickTrue : MagickFalse;
697             break;
698           }
699         if (LocaleCompare("display",option+1) == 0)
700           {
701             if (*option == '+')
702               break;
703             i++;
704             if (i == (ssize_t) argc)
705               ThrowImportException(OptionError,"MissingArgument",option);
706             break;
707           }
708         if (LocaleCompare("dispose",option+1) == 0)
709           {
710             ssize_t
711               dispose;
712
713             if (*option == '+')
714               break;
715             i++;
716             if (i == (ssize_t) argc)
717               ThrowImportException(OptionError,"MissingArgument",option);
718             dispose=ParseMagickOption(MagickDisposeOptions,MagickFalse,argv[i]);
719             if (dispose < 0)
720               ThrowImportException(OptionError,"UnrecognizedDisposeMethod",
721                 argv[i]);
722             break;
723           }
724         if (LocaleCompare("dither",option+1) == 0)
725           {
726             ssize_t
727               method;
728
729             quantize_info->dither=MagickFalse;
730             if (*option == '+')
731               break;
732             i++;
733             if (i == (ssize_t) argc)
734               ThrowImportException(OptionError,"MissingArgument",option);
735             method=ParseMagickOption(MagickDitherOptions,MagickFalse,argv[i]);
736             if (method < 0)
737               ThrowImportException(OptionError,"UnrecognizedDitherMethod",
738                 argv[i]);
739             quantize_info->dither=MagickTrue;
740             quantize_info->dither_method=(DitherMethod) method;
741             break;
742           }
743         if (LocaleCompare("duration",option+1) == 0)
744           {
745             if (*option == '+')
746               break;
747             i++;
748             if (i == (ssize_t) (argc-1))
749               ThrowImportException(OptionError,"MissingArgument",option);
750             if (IsGeometry(argv[i]) == MagickFalse)
751               ThrowImportInvalidArgumentException(option,argv[i]);
752             break;
753           }
754         ThrowImportException(OptionError,"UnrecognizedOption",option);
755       }
756       case 'e':
757       {
758         if (LocaleCompare("encipher",option+1) == 0)
759           {
760             if (*option == '+')
761               break;
762             i++;
763             if (i == (ssize_t) (argc-1))
764               ThrowImportException(OptionError,"MissingArgument",option);
765             break;
766           }
767         if (LocaleCompare("encoding",option+1) == 0)
768           {
769             if (*option == '+')
770               break;
771             i++;
772             if (i == (ssize_t) argc)
773               ThrowImportException(OptionError,"MissingArgument",option);
774             break;
775           }
776         if (LocaleCompare("endian",option+1) == 0)
777           {
778             ssize_t
779               endian;
780
781             if (*option == '+')
782               break;
783             i++;
784             if (i == (ssize_t) argc)
785               ThrowImportException(OptionError,"MissingArgument",option);
786             endian=ParseMagickOption(MagickEndianOptions,MagickFalse,
787               argv[i]);
788             if (endian < 0)
789               ThrowImportException(OptionError,"UnrecognizedEndianType",
790                 argv[i]);
791             break;
792           }
793         ThrowImportException(OptionError,"UnrecognizedOption",option);
794       }
795       case 'f':
796       {
797         if (LocaleCompare("filter",option+1) == 0)
798           {
799             ssize_t
800               filter;
801
802             if (*option == '+')
803               break;
804             i++;
805             if (i == (ssize_t) (argc-1))
806               ThrowImportException(OptionError,"MissingArgument",option);
807             filter=ParseMagickOption(MagickFilterOptions,MagickFalse,argv[i]);
808             if (filter < 0)
809               ThrowImportException(OptionError,"UnrecognizedImageFilter",
810                 argv[i]);
811             break;
812           }
813         if (LocaleCompare("frame",option+1) == 0)
814           {
815             (void) CopyMagickString(argv[i]+1,"sans0",MaxTextExtent);
816             ximage_info.frame=(*option == '-') ? MagickTrue : MagickFalse;
817             break;
818           }
819         if (LocaleCompare("format",option+1) == 0)
820           {
821             if (*option == '+')
822               break;
823             i++;
824             if (i == (ssize_t) (argc-1))
825               ThrowImportException(OptionError,"MissingArgument",option);
826             break;
827           }
828         ThrowImportException(OptionError,"UnrecognizedOption",option);
829       }
830       case 'g':
831       {
832         if (LocaleCompare("geometry",option+1) == 0)
833           {
834             if (*option == '+')
835               break;
836             i++;
837             if (i == (ssize_t) argc)
838               ThrowImportException(OptionError,"MissingArgument",option);
839             if (IsGeometry(argv[i]) == MagickFalse)
840               ThrowImportInvalidArgumentException(option,argv[i]);
841             break;
842           }
843         if (LocaleCompare("gravity",option+1) == 0)
844           {
845             ssize_t
846               gravity;
847
848             if (*option == '+')
849               break;
850             i++;
851             if (i == (ssize_t) argc)
852               ThrowImportException(OptionError,"MissingArgument",option);
853             gravity=ParseMagickOption(MagickGravityOptions,MagickFalse,argv[i]);
854             if (gravity < 0)
855               ThrowImportException(OptionError,"UnrecognizedGravityType",
856                 argv[i]);
857             break;
858           }
859         ThrowImportException(OptionError,"UnrecognizedOption",option);
860       }
861       case 'h':
862       {
863         if (LocaleCompare("help",option+1) == 0)
864           break;
865         ThrowImportException(OptionError,"UnrecognizedOption",option);
866       }
867       case 'i':
868       {
869         if (LocaleCompare("identify",option+1) == 0)
870           break;
871         if (LocaleCompare("interlace",option+1) == 0)
872           {
873             ssize_t
874               interlace;
875
876             if (*option == '+')
877               break;
878             i++;
879             if (i == (ssize_t) argc)
880               ThrowImportException(OptionError,"MissingArgument",option);
881             interlace=ParseMagickOption(MagickInterlaceOptions,MagickFalse,
882               argv[i]);
883             if (interlace < 0)
884               ThrowImportException(OptionError,"UnrecognizedInterlaceType",
885                 argv[i]);
886             break;
887           }
888         if (LocaleCompare("interpolate",option+1) == 0)
889           {
890             ssize_t
891               interpolate;
892
893             if (*option == '+')
894               break;
895             i++;
896             if (i == (ssize_t) argc)
897               ThrowImportException(OptionError,"MissingArgument",option);
898             interpolate=ParseMagickOption(MagickInterpolateOptions,MagickFalse,
899               argv[i]);
900             if (interpolate < 0)
901               ThrowImportException(OptionError,"UnrecognizedInterpolateMethod",
902                 argv[i]);
903             break;
904           }
905         ThrowImportException(OptionError,"UnrecognizedOption",option);
906       }
907       case 'l':
908       {
909         if (LocaleCompare("label",option+1) == 0)
910           {
911             if (*option == '+')
912               break;
913             i++;
914             if (i == (ssize_t) argc)
915               ThrowImportException(OptionError,"MissingArgument",option);
916             status=SetImageOption(image_info,"label",argv[i]);
917             if (status == MagickFalse)
918               ThrowImportException(OptionError,"UnrecognizedOption",argv[i]);
919             break;
920           }
921         if (LocaleCompare("limit",option+1) == 0)
922           {
923             char
924               *p;
925
926             double
927               value;
928
929             ssize_t
930               resource;
931
932             if (*option == '+')
933               break;
934             i++;
935             if (i == (ssize_t) argc)
936               ThrowImportException(OptionError,"MissingArgument",option);
937             resource=ParseMagickOption(MagickResourceOptions,MagickFalse,
938               argv[i]);
939             if (resource < 0)
940               ThrowImportException(OptionError,"UnrecognizedResourceType",
941                 argv[i]);
942             i++;
943             if (i == (ssize_t) argc)
944               ThrowImportException(OptionError,"MissingArgument",option);
945             value=strtod(argv[i],&p);
946             (void) value;
947             if ((p == argv[i]) && (LocaleCompare("unlimited",argv[i]) != 0))
948               ThrowImportInvalidArgumentException(option,argv[i]);
949             break;
950           }
951         if (LocaleCompare("list",option+1) == 0)
952           {
953             ssize_t
954               list;
955
956             if (*option == '+')
957               break;
958             i++;
959             if (i == (ssize_t) argc)
960               ThrowImportException(OptionError,"MissingArgument",option);
961             list=ParseMagickOption(MagickListOptions,MagickFalse,argv[i]);
962             if (list < 0)
963               ThrowImportException(OptionError,"UnrecognizedListType",argv[i]);
964             status=MogrifyImageInfo(image_info,(int) (i-j+1),(const char **)
965               argv+j,exception);
966             DestroyImport();
967             return(status != 0 ? MagickFalse : MagickTrue);
968           }
969         if (LocaleCompare("log",option+1) == 0)
970           {
971             if (*option == '+')
972               break;
973             i++;
974             if ((i == (ssize_t) argc) || (strchr(argv[i],'%') == (char *) NULL))
975               ThrowImportException(OptionError,"MissingArgument",option);
976             break;
977           }
978         ThrowImportException(OptionError,"UnrecognizedOption",option);
979       }
980       case 'm':
981       {
982         if (LocaleCompare("monitor",option+1) == 0)
983           break;
984         if (LocaleCompare("monochrome",option+1) == 0)
985           {
986             if (*option == '+')
987               break;
988             quantize_info->number_colors=2;
989             quantize_info->colorspace=GRAYColorspace;
990             break;
991           }
992         ThrowImportException(OptionError,"UnrecognizedOption",option);
993       }
994       case 'n':
995       {
996         if (LocaleCompare("negate",option+1) == 0)
997           break;
998         ThrowImportException(OptionError,"UnrecognizedOption",option);
999       }
1000       case 'p':
1001       {
1002         if (LocaleCompare("page",option+1) == 0)
1003           {
1004             if (*option == '+')
1005               break;
1006             i++;
1007             if (i == (ssize_t) argc)
1008               ThrowImportException(OptionError,"MissingArgument",option);
1009             status=SetImageOption(image_info,"page",argv[i]);
1010             if (status == MagickFalse)
1011               ThrowImportException(OptionError,"UnrecognizedOption",argv[i]);
1012             break;
1013           }
1014         if (LocaleCompare("pause",option+1) == 0)
1015           {
1016             resource_info.pause=0;
1017             if (*option == '+')
1018               break;
1019             i++;
1020             if (i == (ssize_t) argc)
1021               ThrowImportException(OptionError,"MissingArgument",option);
1022             if (IsGeometry(argv[i]) == MagickFalse)
1023               ThrowImportInvalidArgumentException(option,argv[i]);
1024             resource_info.pause=(unsigned int) StringToUnsignedLong(argv[i]);
1025             break;
1026           }
1027         if (LocaleCompare("ping",option+1) == 0)
1028           break;  /* deprecated option */
1029         if (LocaleCompare("pointsize",option+1) == 0)
1030           {
1031             if (*option == '+')
1032               break;
1033             i++;
1034             if (i == (ssize_t) argc)
1035               ThrowImportException(OptionError,"MissingArgument",option);
1036             if (IsGeometry(argv[i]) == MagickFalse)
1037               ThrowImportInvalidArgumentException(option,argv[i]);
1038             break;
1039           }
1040         ThrowImportException(OptionError,"UnrecognizedOption",option);
1041       }
1042       case 'q':
1043       {
1044         if (LocaleCompare("quality",option+1) == 0)
1045           {
1046             if (*option == '+')
1047               break;
1048             i++;
1049             if (i == (ssize_t) argc)
1050               ThrowImportException(OptionError,"MissingArgument",option);
1051             if (IsGeometry(argv[i]) == MagickFalse)
1052               ThrowImportInvalidArgumentException(option,argv[i]);
1053             break;
1054           }
1055         if (LocaleCompare("quantize",option+1) == 0)
1056           {
1057             ssize_t
1058               colorspace;
1059
1060             if (*option == '+')
1061               break;
1062             i++;
1063             if (i == (ssize_t) (argc-1))
1064               ThrowImportException(OptionError,"MissingArgument",option);
1065             colorspace=ParseMagickOption(MagickColorspaceOptions,
1066               MagickFalse,argv[i]);
1067             if (colorspace < 0)
1068               ThrowImportException(OptionError,"UnrecognizedColorspace",
1069                 argv[i]);
1070             break;
1071           }
1072         if (LocaleCompare("quiet",option+1) == 0)
1073           break;
1074         ThrowImportException(OptionError,"UnrecognizedOption",option);
1075       }
1076       case 'r':
1077       {
1078         if (LocaleCompare("regard-warnings",option+1) == 0)
1079           break;
1080         if (LocaleCompare("repage",option+1) == 0)
1081           {
1082             if (*option == '+')
1083               break;
1084             i++;
1085             if (i == (ssize_t) (argc-1))
1086               ThrowImportException(OptionError,"MissingArgument",option);
1087             if (IsGeometry(argv[i]) == MagickFalse)
1088               ThrowImportInvalidArgumentException(option,argv[i]);
1089             break;
1090           }
1091         if (LocaleCompare("resize",option+1) == 0)
1092           {
1093             if (*option == '+')
1094               break;
1095             i++;
1096             if (i == (ssize_t) argc)
1097               ThrowImportException(OptionError,"MissingArgument",option);
1098             if (IsGeometry(argv[i]) == MagickFalse)
1099               ThrowImportInvalidArgumentException(option,argv[i]);
1100             break;
1101           }
1102         if (LocaleNCompare("respect-parentheses",option+1,17) == 0)
1103           {
1104             respect_parenthesis=(*option == '-') ? MagickTrue : MagickFalse;
1105             break;
1106           }
1107         if (LocaleCompare("rotate",option+1) == 0)
1108           {
1109             i++;
1110             if (i == (ssize_t) argc)
1111               ThrowImportException(OptionError,"MissingArgument",option);
1112             if (IsGeometry(argv[i]) == MagickFalse)
1113               ThrowImportInvalidArgumentException(option,argv[i]);
1114             break;
1115           }
1116         ThrowImportException(OptionError,"UnrecognizedOption",option);
1117       }
1118       case 's':
1119       {
1120         if (LocaleCompare("sampling-factor",option+1) == 0)
1121           {
1122             if (*option == '+')
1123               break;
1124             i++;
1125             if (i == (ssize_t) argc)
1126               ThrowImportException(OptionError,"MissingArgument",option);
1127             if (IsGeometry(argv[i]) == MagickFalse)
1128               ThrowImportInvalidArgumentException(option,argv[i]);
1129             break;
1130           }
1131         if (LocaleCompare("scene",option+1) == 0)
1132           {
1133             if (*option == '+')
1134               break;
1135             i++;
1136             if (i == (ssize_t) argc)
1137               ThrowImportException(OptionError,"MissingArgument",option);
1138             if (IsGeometry(argv[i]) == MagickFalse)
1139               ThrowImportInvalidArgumentException(option,argv[i]);
1140             break;
1141           }
1142         if (LocaleCompare("set",option+1) == 0)
1143           {
1144             i++;
1145             if (i == (ssize_t) argc)
1146               ThrowImportException(OptionError,"MissingArgument",option);
1147             if (*option == '+')
1148               break;
1149             i++;
1150             if (i == (ssize_t) argc)
1151               ThrowImportException(OptionError,"MissingArgument",option);
1152             break;
1153           }
1154         if (LocaleCompare("screen",option+1) == 0)
1155           {
1156             ximage_info.screen=(*option == '-') ? MagickTrue : MagickFalse;
1157             break;
1158           }
1159         if (LocaleCompare("seed",option+1) == 0)
1160           {
1161             if (*option == '+')
1162               break;
1163             i++;
1164             if (i == (ssize_t) (argc-1))
1165               ThrowImportException(OptionError,"MissingArgument",option);
1166             if (IsGeometry(argv[i]) == MagickFalse)
1167               ThrowImportInvalidArgumentException(option,argv[i]);
1168             break;
1169           }
1170         if (LocaleCompare("silent",option+1) == 0)
1171           {
1172             ximage_info.silent=(*option == '-') ? MagickTrue : MagickFalse;
1173             break;
1174           }
1175         if (LocaleCompare("snaps",option+1) == 0)
1176           {
1177             (void) CopyMagickString(argv[i]+1,"sans",MaxTextExtent);
1178             i++;
1179             if (i == (ssize_t) argc)
1180               ThrowImportException(OptionError,"MissingArgument",option);
1181             if (IsGeometry(argv[i]) == MagickFalse)
1182               ThrowImportInvalidArgumentException(option,argv[i]);
1183             snapshots=(ssize_t) StringToLong(argv[i]);
1184             break;
1185           }
1186         if (LocaleCompare("strip",option+1) == 0)
1187           break;
1188         if (LocaleCompare("support",option+1) == 0)
1189           {
1190             i++;  /* deprecated */
1191             break;
1192           }
1193         if (LocaleCompare("synchronize",option+1) == 0)
1194           break;
1195         ThrowImportException(OptionError,"UnrecognizedOption",option);
1196       }
1197       case 't':
1198       {
1199         if (LocaleCompare("taint",option+1) == 0)
1200           break;
1201         if (LocaleCompare("thumnail",option+1) == 0)
1202           {
1203             if (*option == '+')
1204               break;
1205             i++;
1206             if (i == (ssize_t) argc)
1207               ThrowImportException(OptionError,"MissingArgument",option);
1208             if (IsGeometry(argv[i]) == MagickFalse)
1209               ThrowImportInvalidArgumentException(option,argv[i]);
1210             break;
1211           }
1212         if (LocaleCompare("transparent",option+1) == 0)
1213           {
1214             i++;
1215             if (i == (ssize_t) argc)
1216               ThrowImportException(OptionError,"MissingArgument",option);
1217             break;
1218           }
1219         if (LocaleCompare("transparent-color",option+1) == 0)
1220           {
1221             if (*option == '+')
1222               break;
1223             i++;
1224             if (i == (ssize_t) (argc-1))
1225               ThrowImportException(OptionError,"MissingArgument",option);
1226             break;
1227           }
1228         if (LocaleCompare("treedepth",option+1) == 0)
1229           {
1230             quantize_info->tree_depth=0;
1231             if (*option == '+')
1232               break;
1233             i++;
1234             if (i == (ssize_t) argc)
1235               ThrowImportException(OptionError,"MissingArgument",option);
1236             if (IsGeometry(argv[i]) == MagickFalse)
1237               ThrowImportInvalidArgumentException(option,argv[i]);
1238             quantize_info->tree_depth=StringToUnsignedLong(argv[i]);
1239             break;
1240           }
1241         if (LocaleCompare("trim",option+1) == 0)
1242           break;
1243         if (LocaleCompare("type",option+1) == 0)
1244           {
1245             ssize_t
1246               type;
1247
1248             if (*option == '+')
1249               break;
1250             i++;
1251             if (i == (ssize_t) argc)
1252               ThrowImportException(OptionError,"MissingArgument",option);
1253             type=ParseMagickOption(MagickTypeOptions,MagickFalse,argv[i]);
1254             if (type < 0)
1255               ThrowImportException(OptionError,"UnrecognizedImageType",argv[i]);
1256             break;
1257           }
1258         ThrowImportException(OptionError,"UnrecognizedOption",option);
1259       }
1260       case 'w':
1261       {
1262         i++;
1263         if (i == (ssize_t) argc)
1264           ThrowImportException(OptionError,"MissingArgument",option);
1265         (void) CloneString(&target_window,argv[i]);
1266         break;
1267       }
1268       case 'v':
1269       {
1270         if (LocaleCompare("verbose",option+1) == 0)
1271           break;
1272         if ((LocaleCompare("version",option+1) == 0) ||
1273             (LocaleCompare("-version",option+1) == 0))
1274           {
1275             (void) fprintf(stdout,"Version: %s\n",
1276               GetMagickVersion((size_t *) NULL));
1277             (void) fprintf(stdout,"Copyright: %s\n",GetMagickCopyright());
1278             (void) fprintf(stdout,"Features: %s\n\n",GetMagickFeatures());
1279             break;
1280           }
1281         ThrowImportException(OptionError,"UnrecognizedOption",option);
1282       }
1283       case '?':
1284         break;
1285       default:
1286         ThrowImportException(OptionError,"UnrecognizedOption",option);
1287     }
1288     fire=ParseMagickOption(MagickImageListOptions,MagickFalse,option+1) < 0 ?
1289       MagickFalse : MagickTrue;
1290     if (fire != MagickFalse)
1291       FireImageStack(MagickFalse,MagickTrue,MagickTrue);
1292   }
1293   if (k != 0)
1294     ThrowImportException(OptionError,"UnbalancedParenthesis",argv[i]);
1295   if (i-- != (ssize_t) argc)
1296     ThrowImportException(OptionError,"MissingAnImageFilename",argv[i]);
1297   if (image == (Image *) NULL)
1298     ThrowImportException(OptionError,"MissingAnImageFilename",argv[argc-1]);
1299   FinalizeImageSettings(image_info,image,MagickTrue);
1300   status&=WriteImages(image_info,image,filename,exception);
1301   DestroyImport();
1302   return(status != 0 ? MagickTrue : MagickFalse);
1303 #else
1304   (void) argc;
1305   (void) argv;
1306   (void) ThrowMagickException(exception,GetMagickModule(),MissingDelegateError,
1307     "DelegateLibrarySupportNotBuiltIn","`%s' (X11)",image_info->filename);
1308   return(ImportUsage());
1309 #endif
1310 }