47#include "MagickWand/studio.h"
48#include "MagickWand/MagickWand.h"
49#include "MagickWand/mogrify-private.h"
50#include "MagickCore/stream-private.h"
51#include "MagickCore/string-private.h"
87static MagickBooleanType StreamUsage(
void)
91 " -channel mask set the image channel mask\n"
92 " -debug events display copious debugging information\n"
93 " -help print program options\n"
94 " -list type print a list of supported option arguments\n"
95 " -log format format of debugging information\n"
96 " -version print version information",
98 " -authenticate password\n"
99 " decipher image with this password\n"
100 " -colorspace type alternate image colorspace\n"
101 " -compress type type of pixel compression when writing the image\n"
102 " -define format:option\n"
103 " define one or more image format options\n"
104 " -density geometry horizontal and vertical density of the image\n"
105 " -depth value image depth\n"
106 " -extract geometry extract area from image\n"
107 " -identify identify the format and characteristics of the image\n"
108 " -interlace type type of image interlacing scheme\n"
109 " -interpolate method pixel color interpolation method\n"
110 " -limit type value pixel cache resource limit\n"
111 " -map components one or more pixel components\n"
112 " -monitor monitor progress\n"
113 " -quantize colorspace reduce colors in this colorspace\n"
114 " -quiet suppress all warning messages\n"
115 " -regard-warnings pay attention to warning messages\n"
116 " -respect-parentheses settings remain in effect until parenthesis boundary\n"
117 " -sampling-factor geometry\n"
118 " horizontal and vertical sampling factor\n"
119 " -seed value seed a new sequence of pseudo-random numbers\n"
120 " -set attribute value set an image attribute\n"
121 " -size geometry width and height of image\n"
122 " -storage-type type pixel storage type\n"
123 " -synchronize synchronize image to storage device\n"
124 " -taint declare the image as modified\n"
125 " -transparent-color color\n"
126 " transparent color\n"
127 " -verbose print detailed information about the image\n"
128 " -virtual-pixel method\n"
129 " virtual pixel access method";
131 ListMagickVersion(stdout);
132 (void) printf(
"Usage: %s [options ...] input-image raw-image\n",
134 (void) printf(
"\nImage Settings:\n");
135 (void) puts(settings);
136 (void) printf(
"\nMiscellaneous Options:\n");
137 (void) puts(miscellaneous);
139 "\nBy default, the image format of 'file' is determined by its magic\n");
141 "number. To specify a particular image format, precede the filename\n");
143 "with an image format name and a colon (i.e. ps:image) or specify the\n");
145 "image type as the filename suffix (i.e. image.ps). Specify 'file' as\n");
146 (void) printf(
"'-' for standard input or output.\n");
150WandExport MagickBooleanType StreamImageCommand(ImageInfo *image_info,
151 int argc,
char **argv,
char **metadata,ExceptionInfo *exception)
153#define DestroyStream() \
155 DestroyImageStack(); \
156 stream_info=DestroyStreamInfo(stream_info); \
157 for (i=0; i < (ssize_t) argc; i++) \
158 argv[i]=DestroyString(argv[i]); \
159 argv=(char **) RelinquishMagickMemory(argv); \
161#define ThrowStreamException(asperity,tag,option) \
163 (void) ThrowMagickException(exception,GetMagickModule(),asperity,tag,"`%s'", \
166 return(MagickFalse); \
168#define ThrowStreamInvalidArgumentException(option,argument) \
170 (void) ThrowMagickException(exception,GetMagickModule(),OptionError, \
171 "InvalidArgument","'%s': %s",option,argument); \
173 return(MagickFalse); \
184 *image = (Image *) NULL;
187 image_stack[MaxImageStackDepth+1];
210 assert(image_info != (ImageInfo *) NULL);
211 assert(image_info->signature == MagickCoreSignature);
212 assert(exception != (ExceptionInfo *) NULL);
213 if (IsEventLogging() != MagickFalse)
214 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
219 if ((LocaleCompare(
"help",option+1) == 0) ||
220 (LocaleCompare(
"-help",option+1) == 0))
221 return(StreamUsage());
222 if ((LocaleCompare(
"version",option+1) == 0) ||
223 (LocaleCompare(
"-version",option+1) == 0))
225 ListMagickVersion(stdout);
231 (void) ThrowMagickException(exception,GetMagickModule(),OptionError,
232 "MissingArgument",
"%s",
"");
233 (void) StreamUsage();
241 option=(
char *) NULL;
243 respect_parentheses=MagickFalse;
244 stream_info=AcquireStreamInfo(image_info,exception);
249 ReadCommandlLine(argc,&argv);
250 status=ExpandFilenames(&argc,&argv);
251 if (status == MagickFalse)
252 ThrowStreamException(ResourceLimitError,
"MemoryAllocationFailed",
253 GetExceptionMessage(errno));
254 status=OpenStream(image_info,stream_info,argv[argc-1],exception);
255 if (status == MagickFalse)
260 for (i=1; i < (ssize_t) (argc-1); i++)
263 if (LocaleCompare(option,
"(") == 0)
265 FireImageStack(MagickFalse,MagickTrue,pend);
266 if (k == MaxImageStackDepth)
267 ThrowStreamException(OptionError,
"ParenthesisNestedTooDeeply",option);
271 if (LocaleCompare(option,
")") == 0)
273 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
275 ThrowStreamException(OptionError,
"UnableToParseExpression",option);
279 if (IsCommandOption(option) == MagickFalse)
287 FireImageStack(MagickFalse,MagickFalse,pend);
289 if ((LocaleCompare(filename,
"--") == 0) && (i < (ssize_t) (argc-1)))
291 (void) CopyMagickString(image_info->filename,filename,MagickPathExtent);
292 images=StreamImage(image_info,stream_info,exception);
293 status&=(MagickStatusType) (images != (Image *) NULL) &&
294 (exception->severity < ErrorException);
295 if (images == (Image *) NULL)
297 AppendImageStack(images);
300 pend=image != (Image *) NULL ? MagickTrue : MagickFalse;
305 if (LocaleCompare(
"authenticate",option+1) == 0)
310 if (i == (ssize_t) argc)
311 ThrowStreamException(OptionError,
"MissingArgument",option);
314 ThrowStreamException(OptionError,
"UnrecognizedOption",option)
318 if (LocaleCompare(
"cache",option+1) == 0)
323 if (i == (ssize_t) argc)
324 ThrowStreamException(OptionError,
"MissingArgument",option);
325 if (IsGeometry(argv[i]) == MagickFalse)
326 ThrowStreamInvalidArgumentException(option,argv[i]);
329 if (LocaleCompare(
"channel",option+1) == 0)
337 if (i == (ssize_t) argc)
338 ThrowStreamException(OptionError,
"MissingArgument",option);
339 channel=ParseChannelOption(argv[i]);
341 ThrowStreamException(OptionError,
"UnrecognizedChannelType",
345 if (LocaleCompare(
"colorspace",option+1) == 0)
353 if (i == (ssize_t) argc)
354 ThrowStreamException(OptionError,
"MissingArgument",option);
355 colorspace=ParseCommandOption(MagickColorspaceOptions,MagickFalse,
358 ThrowStreamException(OptionError,
"UnrecognizedColorspace",
362 if (LocaleCompare(
"compress",option+1) == 0)
370 if (i == (ssize_t) argc)
371 ThrowStreamException(OptionError,
"MissingArgument",option);
372 compress=ParseCommandOption(MagickCompressOptions,MagickFalse,
375 ThrowStreamException(OptionError,
"UnrecognizedImageCompression",
379 if (LocaleCompare(
"concurrent",option+1) == 0)
381 ThrowStreamException(OptionError,
"UnrecognizedOption",option)
385 if (LocaleCompare(
"debug",option+1) == 0)
393 if (i == (ssize_t) argc)
394 ThrowStreamException(OptionError,
"MissingArgument",option);
395 event=ParseCommandOption(MagickLogEventOptions,MagickFalse,argv[i]);
397 ThrowStreamException(OptionError,
"UnrecognizedEventType",argv[i]);
398 (void) SetLogEventMask(argv[i]);
401 if (LocaleCompare(
"define",option+1) == 0)
404 if (i == (ssize_t) argc)
405 ThrowStreamException(OptionError,
"MissingArgument",option);
411 define=GetImageOption(image_info,argv[i]);
412 if (define == (
const char *) NULL)
413 ThrowStreamException(OptionError,
"NoSuchOption",argv[i]);
418 if (LocaleCompare(
"density",option+1) == 0)
423 if (i == (ssize_t) argc)
424 ThrowStreamException(OptionError,
"MissingArgument",option);
425 if (IsGeometry(argv[i]) == MagickFalse)
426 ThrowStreamInvalidArgumentException(option,argv[i]);
429 if (LocaleCompare(
"depth",option+1) == 0)
434 if (i == (ssize_t) argc)
435 ThrowStreamException(OptionError,
"MissingArgument",option);
436 if (IsGeometry(argv[i]) == MagickFalse)
437 ThrowStreamInvalidArgumentException(option,argv[i]);
440 if (LocaleCompare(
"duration",option+1) == 0)
445 if (i == (ssize_t) argc)
446 ThrowStreamException(OptionError,
"MissingArgument",option);
447 if (IsGeometry(argv[i]) == MagickFalse)
448 ThrowStreamInvalidArgumentException(option,argv[i]);
451 ThrowStreamException(OptionError,
"UnrecognizedOption",option)
455 if (LocaleCompare(
"extract",option+1) == 0)
460 if (i == (ssize_t) argc)
461 ThrowStreamException(OptionError,
"MissingArgument",option);
462 if (IsGeometry(argv[i]) == MagickFalse)
463 ThrowStreamInvalidArgumentException(option,argv[i]);
466 ThrowStreamException(OptionError,
"UnrecognizedOption",option)
470 if ((LocaleCompare(
"help",option+1) == 0) ||
471 (LocaleCompare(
"-help",option+1) == 0))
474 return(StreamUsage());
476 ThrowStreamException(OptionError,
"UnrecognizedOption",option)
480 if (LocaleCompare(
"identify",option+1) == 0)
482 if (LocaleCompare(
"interlace",option+1) == 0)
490 if (i == (ssize_t) argc)
491 ThrowStreamException(OptionError,
"MissingArgument",option);
492 interlace=ParseCommandOption(MagickInterlaceOptions,MagickFalse,
495 ThrowStreamException(OptionError,
"UnrecognizedInterlaceType",
499 if (LocaleCompare(
"interpolate",option+1) == 0)
507 if (i == (ssize_t) argc)
508 ThrowStreamException(OptionError,
"MissingArgument",option);
509 interpolate=ParseCommandOption(MagickInterpolateOptions,MagickFalse,
512 ThrowStreamException(OptionError,
"UnrecognizedInterpolateMethod",
516 ThrowStreamException(OptionError,
"UnrecognizedOption",option)
520 if (LocaleCompare(
"limit",option+1) == 0)
534 if (i == (ssize_t) argc)
535 ThrowStreamException(OptionError,
"MissingArgument",option);
536 resource=ParseCommandOption(MagickResourceOptions,MagickFalse,
539 ThrowStreamException(OptionError,
"UnrecognizedResourceType",
542 if (i == (ssize_t) argc)
543 ThrowStreamException(OptionError,
"MissingArgument",option);
544 value=StringToDouble(argv[i],&p);
546 if ((p == argv[i]) && (LocaleCompare(
"unlimited",argv[i]) != 0))
547 ThrowStreamInvalidArgumentException(option,argv[i]);
550 if (LocaleCompare(
"list",option+1) == 0)
558 if (i == (ssize_t) argc)
559 ThrowStreamException(OptionError,
"MissingArgument",option);
560 list=ParseCommandOption(MagickListOptions,MagickFalse,argv[i]);
562 ThrowStreamException(OptionError,
"UnrecognizedListType",argv[i]);
563 status=MogrifyImageInfo(image_info,(
int) (i-j+1),(
const char **)
566 return(status == 0 ? MagickFalse : MagickTrue);
568 if (LocaleCompare(
"log",option+1) == 0)
573 if ((i == (ssize_t) argc) || (strchr(argv[i],
'%') == (
char *) NULL))
574 ThrowStreamException(OptionError,
"MissingArgument",option);
577 ThrowStreamException(OptionError,
"UnrecognizedOption",option)
581 if (LocaleCompare(
"map",option+1) == 0)
583 (void) CopyMagickString(argv[i]+1,
"san",MagickPathExtent);
587 SetStreamInfoMap(stream_info,argv[i]);
590 if (LocaleCompare(
"monitor",option+1) == 0)
592 ThrowStreamException(OptionError,
"UnrecognizedOption",option)
596 if (LocaleCompare(
"quantize",option+1) == 0)
604 if (i == (ssize_t) argc)
605 ThrowStreamException(OptionError,
"MissingArgument",option);
606 colorspace=ParseCommandOption(MagickColorspaceOptions,
607 MagickFalse,argv[i]);
609 ThrowStreamException(OptionError,
"UnrecognizedColorspace",
613 if (LocaleCompare(
"quiet",option+1) == 0)
615 ThrowStreamException(OptionError,
"UnrecognizedOption",option)
619 if (LocaleCompare(
"regard-warnings",option+1) == 0)
621 if (LocaleNCompare(
"respect-parentheses",option+1,17) == 0)
623 respect_parentheses=(*option ==
'-') ? MagickTrue : MagickFalse;
626 ThrowStreamException(OptionError,
"UnrecognizedOption",option)
630 if (LocaleCompare(
"sampling-factor",option+1) == 0)
635 if (i == (ssize_t) argc)
636 ThrowStreamException(OptionError,
"MissingArgument",option);
637 if (IsGeometry(argv[i]) == MagickFalse)
638 ThrowStreamInvalidArgumentException(option,argv[i]);
641 if (LocaleCompare(
"seed",option+1) == 0)
646 if (i == (ssize_t) argc)
647 ThrowStreamException(OptionError,
"MissingArgument",option);
648 if (IsGeometry(argv[i]) == MagickFalse)
649 ThrowStreamInvalidArgumentException(option,argv[i]);
652 if (LocaleCompare(
"set",option+1) == 0)
655 if (i == (ssize_t) argc)
656 ThrowStreamException(OptionError,
"MissingArgument",option);
660 if (i == (ssize_t) argc)
661 ThrowStreamException(OptionError,
"MissingArgument",option);
664 if (LocaleCompare(
"size",option+1) == 0)
669 if (i == (ssize_t) argc)
670 ThrowStreamException(OptionError,
"MissingArgument",option);
671 if (IsGeometry(argv[i]) == MagickFalse)
672 ThrowStreamInvalidArgumentException(option,argv[i]);
675 if (LocaleCompare(
"storage-type",option+1) == 0)
683 if (i == (ssize_t) argc)
684 ThrowStreamException(OptionError,
"MissingArgument",option);
685 type=ParseCommandOption(MagickStorageOptions,MagickFalse,argv[i]);
687 ThrowStreamException(OptionError,
"UnrecognizedStorageType",
689 SetStreamInfoStorageType(stream_info,(StorageType) type);
692 if (LocaleCompare(
"synchronize",option+1) == 0)
694 ThrowStreamException(OptionError,
"UnrecognizedOption",option)
698 if (LocaleCompare(
"taint",option+1) == 0)
700 if (LocaleCompare(
"transparent-color",option+1) == 0)
705 if (i == (ssize_t) argc)
706 ThrowStreamException(OptionError,
"MissingArgument",option);
709 ThrowStreamException(OptionError,
"UnrecognizedOption",option)
713 if (LocaleCompare(
"verbose",option+1) == 0)
715 if ((LocaleCompare(
"version",option+1) == 0) ||
716 (LocaleCompare(
"-version",option+1) == 0))
718 ListMagickVersion(stdout);
721 if (LocaleCompare(
"virtual-pixel",option+1) == 0)
729 if (i == (ssize_t) argc)
730 ThrowStreamException(OptionError,
"MissingArgument",option);
731 method=ParseCommandOption(MagickVirtualPixelOptions,MagickFalse,
734 ThrowStreamException(OptionError,
"UnrecognizedVirtualPixelMethod",
738 ThrowStreamException(OptionError,
"UnrecognizedOption",option)
743 ThrowStreamException(OptionError,
"UnrecognizedOption",option)
745 fire=(GetCommandOptionFlags(MagickCommandOptions,MagickFalse,option) &
746 FireOptionFlag) == 0 ? MagickFalse : MagickTrue;
747 if (fire != MagickFalse)
748 FireImageStack(MagickFalse,MagickTrue,MagickTrue);
751 ThrowStreamException(OptionError,
"UnbalancedParenthesis",argv[i]);
752 if (i-- != (ssize_t) (argc-1))
753 ThrowStreamException(OptionError,
"MissingAnImageFilename",argv[i]);
754 if (image == (Image *) NULL)
755 ThrowStreamException(OptionError,
"MissingAnImageFilename",argv[i]);
756 FinalizeImageSettings(image_info,image,MagickTrue);
757 if (image == (Image *) NULL)
758 ThrowStreamException(OptionError,
"MissingAnImageFilename",argv[i]);
760 return(status != 0 ? MagickTrue : MagickFalse);