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