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