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